[vlc-commits] d3d_dynamic_shader: tighten the number of textures needed per shader

Steve Lhomme git at videolan.org
Fri Feb 26 14:34:22 UTC 2021


vlc | branch: master | Steve Lhomme <robux4 at ycbcr.xyz> | Wed Feb 24 06:55:58 2021 +0100| [96064d3c7940487561848c3b1fbc164658983e25] | committer: Steve Lhomme

d3d_dynamic_shader: tighten the number of textures needed per shader

We rarely use 4 textures on input but we have to artificially set some input
texture (Share Resource View) in the shader to match the shader signature.
Now we set exactly the number of textures that will be used.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=96064d3c7940487561848c3b1fbc164658983e25
---

 modules/video_output/win32/d3d11_shaders.c      |  3 ++-
 modules/video_output/win32/d3d_dynamic_shader.c | 28 +++++++++++++++++++++----
 modules/video_output/win32/d3d_dynamic_shader.h |  3 ++-
 3 files changed, 28 insertions(+), 6 deletions(-)

diff --git a/modules/video_output/win32/d3d11_shaders.c b/modules/video_output/win32/d3d11_shaders.c
index 3c5ab832c8..1a23dfa92c 100644
--- a/modules/video_output/win32/d3d11_shaders.c
+++ b/modules/video_output/win32/d3d11_shaders.c
@@ -46,9 +46,10 @@ HRESULT (D3D11_CompilePixelShaderBlob)(vlc_object_t *o, const d3d_shader_compile
                                    bool src_full_range,
                                    const d3d11_quad_t *quad, d3d_shader_blob pPSBlob[DXGI_MAX_RENDER_TARGET])
 {
+    size_t shader_views[DXGI_MAX_RENDER_TARGET];
     return D3D_CompilePixelShader(o, compiler, d3d_dev->feature_level,
                                   display, transfer,
-                                  src_full_range, quad->generic.textureFormat, pPSBlob);
+                                  src_full_range, quad->generic.textureFormat, pPSBlob, shader_views);
 }
 
 HRESULT D3D11_SetQuadPixelShader(vlc_object_t *o, d3d11_device_t *d3d_dev,
diff --git a/modules/video_output/win32/d3d_dynamic_shader.c b/modules/video_output/win32/d3d_dynamic_shader.c
index c1b3862565..e4f73518ed 100644
--- a/modules/video_output/win32/d3d_dynamic_shader.c
+++ b/modules/video_output/win32/d3d_dynamic_shader.c
@@ -43,7 +43,7 @@ cbuffer PS_CONSTANT_BUFFER : register(b0)\n\
     float LuminanceScale;\n\
     float2 Boundary;\n\
 };\n\
-Texture2D shaderTexture[4];\n\
+Texture2D shaderTexture[TEXTURE_RESOURCES];\n\
 SamplerState normalSampler : register(s0);\n\
 SamplerState borderSampler : register(s1);\n\
 \n\
@@ -376,6 +376,7 @@ static HRESULT CompileShader(vlc_object_t *obj, const d3d_shader_compiler_t *com
 static HRESULT CompilePixelShaderBlob(vlc_object_t *o, const d3d_shader_compiler_t *compiler,
                                    D3D_FEATURE_LEVEL feature_level,
                                    const char *psz_sampler,
+                                   const char *psz_shader_resource_views,
                                    const char *psz_src_to_linear,
                                    const char *psz_linear_to_display,
                                    const char *psz_tone_mapping,
@@ -390,6 +391,7 @@ static HRESULT CompilePixelShaderBlob(vlc_object_t *o, const d3d_shader_compiler
         msg_Dbg(o, "shader %s", globPixelShaderDefault);
 
     D3D_SHADER_MACRO defines[] = {
+         { "TEXTURE_RESOURCES", psz_shader_resource_views },
          { "TONE_MAPPING",      psz_tone_mapping },
          { "SRC_TO_LINEAR",     psz_src_to_linear },
          { "LINEAR_TO_DST",     psz_linear_to_display },
@@ -421,14 +423,17 @@ HRESULT (D3D_CompilePixelShader)(vlc_object_t *o, const d3d_shader_compiler_t *c
                                  video_transfer_func_t transfer,
                                  bool src_full_range,
                                  const d3d_format_t *dxgi_fmt,
-                                 d3d_shader_blob pPSBlob[DXGI_MAX_RENDER_TARGET])
+                                 d3d_shader_blob pPSBlob[DXGI_MAX_RENDER_TARGET],
+                                 size_t shader_views[DXGI_MAX_RENDER_TARGET])
 {
     static const char *DEFAULT_NOOP = "0";
     const char *psz_sampler[DXGI_MAX_RENDER_TARGET] = {NULL, NULL};
+    const char *psz_shader_resource_views[DXGI_MAX_RENDER_TARGET] = { NULL, NULL };
     const char *psz_src_to_linear     = DEFAULT_NOOP;
     const char *psz_linear_to_display = DEFAULT_NOOP;
     const char *psz_tone_mapping      = DEFAULT_NOOP;
     const char *psz_src_range, *psz_dst_range;
+    shader_views[1] = 0;
 
     if ( display->pixelFormat->formatTexture == DXGI_FORMAT_NV12 ||
          display->pixelFormat->formatTexture == DXGI_FORMAT_P010 )
@@ -439,7 +444,9 @@ HRESULT (D3D_CompilePixelShader)(vlc_object_t *o, const d3d_shader_compiler_t *c
         case DXGI_FORMAT_NV12:
         case DXGI_FORMAT_P010:
             psz_sampler[0] = "SAMPLE_NV12_TO_NV_Y";
+            psz_shader_resource_views[0] = "1"; shader_views[0] = 1;
             psz_sampler[1] = "SAMPLE_NV12_TO_NV_UV";
+            psz_shader_resource_views[1] = "2"; shader_views[1] = 2; // TODO should be 1 ?
             break;
         case DXGI_FORMAT_R8G8B8A8_UNORM:
         case DXGI_FORMAT_B8G8R8A8_UNORM:
@@ -449,8 +456,10 @@ HRESULT (D3D_CompilePixelShader)(vlc_object_t *o, const d3d_shader_compiler_t *c
         case DXGI_FORMAT_B5G6R5_UNORM:
             /* Y */
             psz_sampler[0] = "SAMPLE_RGBA_TO_NV_R";
+            psz_shader_resource_views[0] = "1"; shader_views[0] = 1;
             /* UV */
             psz_sampler[1] = "SAMPLE_RGBA_TO_NV_GB";
+            psz_shader_resource_views[1] = "1"; shader_views[1] = 1;
             break;
         case DXGI_FORMAT_UNKNOWN:
             switch (dxgi_fmt->fourcc)
@@ -458,8 +467,10 @@ HRESULT (D3D_CompilePixelShader)(vlc_object_t *o, const d3d_shader_compiler_t *c
             case VLC_CODEC_YUVA:
                 /* Y */
                 psz_sampler[0] = "SAMPLE_PLANAR_YUVA_TO_NV_Y";
+                psz_shader_resource_views[0] = "4"; shader_views[0] = 4;
                 /* UV */
                 psz_sampler[1] = "SAMPLE_PLANAR_YUVA_TO_NV_UV";
+                psz_shader_resource_views[1] = "4"; shader_views[1] = 4;
                 break;
             default:
                 vlc_assert_unreachable();
@@ -476,18 +487,23 @@ HRESULT (D3D_CompilePixelShader)(vlc_object_t *o, const d3d_shader_compiler_t *c
         case DXGI_FORMAT_NV12:
         case DXGI_FORMAT_P010:
             psz_sampler[0] = "SAMPLE_NV12_TO_YUVA";
+            psz_shader_resource_views[0] = "2"; shader_views[0] = 2;
             break;
         case DXGI_FORMAT_YUY2:
             psz_sampler[0] = "SAMPLE_YUY2_TO_YUVA";
+            psz_shader_resource_views[0] = "1"; shader_views[0] = 1;
             break;
         case DXGI_FORMAT_Y210:
             psz_sampler[0] = "SAMPLE_Y210_TO_YUVA";
+            psz_shader_resource_views[0] = "1"; shader_views[0] = 1;
             break;
         case DXGI_FORMAT_Y410:
             psz_sampler[0] = "SAMPLE_Y410_TO_YUVA";
+            psz_shader_resource_views[0] = "1"; shader_views[0] = 1;
             break;
         case DXGI_FORMAT_AYUV:
             psz_sampler[0] = "SAMPLE_AYUV_TO_YUVA";
+            psz_shader_resource_views[0] = "1"; shader_views[0] = 1;
             break;
         case DXGI_FORMAT_R8G8B8A8_UNORM:
         case DXGI_FORMAT_B8G8R8A8_UNORM:
@@ -496,19 +512,23 @@ HRESULT (D3D_CompilePixelShader)(vlc_object_t *o, const d3d_shader_compiler_t *c
         case DXGI_FORMAT_R16G16B16A16_UNORM:
         case DXGI_FORMAT_B5G6R5_UNORM:
             psz_sampler[0] = "SAMPLE_RGBA_TO_RGBA";
+            psz_shader_resource_views[0] = "1"; shader_views[0] = 1;
             break;
         case DXGI_FORMAT_UNKNOWN:
             switch (dxgi_fmt->fourcc)
             {
             case VLC_CODEC_I420_10L:
                 psz_sampler[0] = "SAMPLE_TRIPLANAR10_TO_YUVA";
+                psz_shader_resource_views[0] = "3"; shader_views[0] = 3;
                 break;
             case VLC_CODEC_I444_16L:
             case VLC_CODEC_I420:
                 psz_sampler[0] = "SAMPLE_TRIPLANAR_TO_YUVA";
+                psz_shader_resource_views[0] = "3"; shader_views[0] = 3;
                 break;
             case VLC_CODEC_YUVA:
                 psz_sampler[0] = "SAMPLE_PLANAR_YUVA_TO_YUVA";
+                psz_shader_resource_views[0] = "4"; shader_views[0] = 4;
                 break;
             default:
                 vlc_assert_unreachable();
@@ -670,7 +690,7 @@ HRESULT (D3D_CompilePixelShader)(vlc_object_t *o, const d3d_shader_compiler_t *c
 
     HRESULT hr;
     hr = CompilePixelShaderBlob(o, compiler, feature_level,
-                                psz_sampler[0],
+                                psz_sampler[0], psz_shader_resource_views[0],
                                 psz_src_to_linear,
                                 psz_linear_to_display,
                                 psz_tone_mapping,
@@ -680,7 +700,7 @@ HRESULT (D3D_CompilePixelShader)(vlc_object_t *o, const d3d_shader_compiler_t *c
     if (SUCCEEDED(hr) && psz_sampler[1])
     {
         hr = CompilePixelShaderBlob(o, compiler, feature_level,
-                                    psz_sampler[1],
+                                    psz_sampler[1],  psz_shader_resource_views[1],
                                     psz_src_to_linear,
                                     psz_linear_to_display,
                                     psz_tone_mapping,
diff --git a/modules/video_output/win32/d3d_dynamic_shader.h b/modules/video_output/win32/d3d_dynamic_shader.h
index 2863371d47..32e157b7bb 100644
--- a/modules/video_output/win32/d3d_dynamic_shader.h
+++ b/modules/video_output/win32/d3d_dynamic_shader.h
@@ -38,7 +38,8 @@ HRESULT D3D_CompilePixelShader(vlc_object_t *, const d3d_shader_compiler_t *,
                                video_transfer_func_t,
                                bool src_full_range,
                                const d3d_format_t *dxgi_fmt,
-                               d3d_shader_blob pPSBlob[DXGI_MAX_RENDER_TARGET]);
+                               d3d_shader_blob pPSBlob[DXGI_MAX_RENDER_TARGET],
+                               size_t shader_views[DXGI_MAX_RENDER_TARGET]);
 
 HRESULT D3D_CompileVertexShader(vlc_object_t *, const d3d_shader_compiler_t *,
                                 D3D_FEATURE_LEVEL, bool flat,



More information about the vlc-commits mailing list