direct3d11: only give initialized resource views to the shader
authorSteve Lhomme <robux4@ycbcr.xyz>
Tue, 13 Feb 2018 12:03:59 +0000 (13:03 +0100)
committerSteve Lhomme <robux4@ycbcr.xyz>
Tue, 13 Feb 2018 14:57:00 +0000 (15:57 +0100)
May help solving 394ea0e5-7f32-4463-86d4-5a30f65ae243

modules/video_chroma/dxgi_fmt.c
modules/video_chroma/dxgi_fmt.h
modules/video_output/win32/direct3d11.c

index 384c6b5..e156642 100644 (file)
@@ -147,3 +147,13 @@ const char *DxgiVendorStr(int gpu_vendor)
     }
     return vendors[i].name;
 }
+
+UINT DxgiResourceCount(const d3d_format_t *d3d_fmt)
+{
+    for (UINT count=0; count<D3D11_MAX_SHADER_VIEW; count++)
+    {
+        if (d3d_fmt->resourceFormat[count] == DXGI_FORMAT_UNKNOWN)
+            return count;
+    }
+    return D3D11_MAX_SHADER_VIEW;
+}
index 7128265..d9fb8d7 100644 (file)
@@ -54,5 +54,6 @@ vlc_fourcc_t DxgiFormatFourcc(DXGI_FORMAT format);
 const d3d_format_t *GetRenderFormatList(void);
 void DxgiFormatMask(DXGI_FORMAT format, video_format_t *);
 const char *DxgiVendorStr(int gpu_vendor);
+UINT DxgiResourceCount(const d3d_format_t *);
 
 #endif /* include-guard */
index 5be75a5..f3643d7 100644 (file)
@@ -103,6 +103,7 @@ typedef struct {
 typedef struct
 {
     picture_sys_t             picSys;
+    UINT                      resourceCount;
     ID3D11Buffer              *pVertexBuffer;
     UINT                      vertexCount;
     ID3D11VertexShader        *d3dvertexShader;
@@ -647,6 +648,7 @@ static picture_pool_t *Pool(vout_display_t *vd, unsigned pool_size)
         if (is_d3d11_opaque(surface_fmt.i_chroma) && !sys->legacy_shader)
 #endif
         {
+            sys->picQuad.resourceCount = DxgiResourceCount(sys->picQuadConfig);
             for (picture_count = 0; picture_count < pool_size; picture_count++) {
                 if (AllocateShaderView(VLC_OBJECT(vd), sys->d3d_dev.d3ddevice, sys->picQuadConfig,
                                        pictures[picture_count]->p_sys->texture, picture_count,
@@ -1079,7 +1081,7 @@ static void DisplayD3DPicture(vout_display_sys_t *sys, d3d_quad_t *quad, ID3D11S
     ID3D11DeviceContext_PSSetShader(sys->d3d_dev.d3dcontext, quad->d3dpixelShader, NULL, 0);
 
     ID3D11DeviceContext_PSSetConstantBuffers(sys->d3d_dev.d3dcontext, 0, quad->PSConstantsCount, quad->pPixelShaderConstants);
-    ID3D11DeviceContext_PSSetShaderResources(sys->d3d_dev.d3dcontext, 0, D3D11_MAX_SHADER_VIEW, resourceView);
+    ID3D11DeviceContext_PSSetShaderResources(sys->d3d_dev.d3dcontext, 0, quad->resourceCount, resourceView);
 
     ID3D11DeviceContext_RSSetViewports(sys->d3d_dev.d3dcontext, 1, &quad->cropViewport);
 
@@ -2061,6 +2063,7 @@ static int Direct3D11CreateFormatResources(vout_display_t *vd, const video_forma
             return VLC_EGENERIC;
         }
 
+        sys->picQuad.resourceCount = DxgiResourceCount(sys->picQuadConfig);
         if (AllocateShaderView(VLC_OBJECT(vd), sys->d3d_dev.d3ddevice, sys->picQuadConfig,
                                textures, 0, sys->stagingSys.resourceView))
         {
@@ -2944,6 +2947,7 @@ static int Direct3D11MapSubpicture(vout_display_t *vd, int *subpicture_region_co
                 continue;
             }
 
+            d3dquad->resourceCount = DxgiResourceCount(sys->d3dregion_format);
             if (AllocateShaderView(VLC_OBJECT(vd), sys->d3d_dev.d3ddevice, sys->d3dregion_format,
                                    d3dquad->picSys.texture, 0,
                                    d3dquad->picSys.resourceView)) {