[dx11] WinVideoFilter: a little shaders optimizations.
authorAnton Fedchin <afedchin@ruswizards.com>
Tue, 7 Jul 2015 09:23:57 +0000 (12:23 +0300)
committerAnton Fedchin <afedchin@ruswizards.com>
Sat, 11 Jul 2015 08:12:24 +0000 (11:12 +0300)
system/shaders/convolution-4x4_d3d.fx
system/shaders/convolution-6x6_d3d.fx
system/shaders/convolutionsep-4x4_d3d.fx
system/shaders/convolutionsep-6x6_d3d.fx
system/shaders/testshader.fx
system/shaders/yuv2rgb_d3d.fx
xbmc/cores/VideoRenderers/VideoShaders/WinVideoFilter.cpp
xbmc/cores/VideoRenderers/VideoShaders/WinVideoFilter.h

index e1bec78..9d92b12 100644 (file)
@@ -21,8 +21,7 @@
 texture2D g_Texture;
 texture2D g_KernelTexture;
 float2    g_StepXY;
-float     g_viewportWidth;
-float     g_viewportHeight;
+float2    g_viewPort;
 
 SamplerState RGBSampler : IMMUTABLE
 {
@@ -46,8 +45,8 @@ struct VS_INPUT
 
 struct VS_OUTPUT
 {
-  float4 Position   : SV_POSITION;
   float2 TextureUV  : TEXCOORD0;
+  float4 Position   : SV_POSITION;
 };
 
 //
@@ -56,8 +55,8 @@ struct VS_OUTPUT
 VS_OUTPUT VS(VS_INPUT In)
 {
   VS_OUTPUT output  = (VS_OUTPUT)0;
-  output.Position.x =  (In.Position.x / (g_viewportWidth  / 2.0)) - 1;
-  output.Position.y = -(In.Position.y / (g_viewportHeight / 2.0)) + 1;
+  output.Position.x =  (In.Position.x / (g_viewPort.x  / 2.0)) - 1;
+  output.Position.y = -(In.Position.y / (g_viewPort.y / 2.0)) + 1;
   output.Position.z = output.Position.z;
   output.Position.w = 1.0;
   output.TextureUV  = In.TextureUV;
@@ -79,46 +78,47 @@ inline half4 weight(float pos)
   return w;
 }
 
+inline half3 pixel(float xpos, float ypos)
+{
+  return g_Texture.Sample(RGBSampler, float2(xpos, ypos)).rgb;
+}
+
 inline half3 getLine(float ypos, float4 xpos, half4 linetaps)
 {
   return
-    g_Texture.Sample(RGBSampler, float2(xpos.r, ypos)).rgb * linetaps.r +
-    g_Texture.Sample(RGBSampler, float2(xpos.g, ypos)).rgb * linetaps.g +
-    g_Texture.Sample(RGBSampler, float2(xpos.b, ypos)).rgb * linetaps.b +
-    g_Texture.Sample(RGBSampler, float2(xpos.a, ypos)).rgb * linetaps.a;
+    pixel(xpos.r, ypos) * linetaps.r +
+    pixel(xpos.g, ypos) * linetaps.g +
+    pixel(xpos.b, ypos) * linetaps.b +
+    pixel(xpos.a, ypos) * linetaps.a;
 }
 
-float4 CONVOLUTION4x4(VS_OUTPUT In) : SV_TARGET
+float4 CONVOLUTION4x4(float2 TextureUV : TEXCOORD0) : SV_TARGET
 {
-  float2 pos = In.TextureUV + g_StepXY * 0.5;
-  float2 f = frac(pos / g_StepXY);
+  float2 f = frac(TextureUV / g_StepXY + float2(0.5, 0.5));
 
   half4 linetaps = weight(1.0 - f.x);
   half4 columntaps = weight(1.0 - f.y);
 
   // kernel generation code made sure taps add up to 1, no need to adjust here.
 
-  float2 xystart = (-1.0 - f) * g_StepXY + In.TextureUV;
-  float4 xpos = float4(
-      xystart.x,
-      xystart.x + g_StepXY.x,
-      xystart.x + g_StepXY.x * 2.0,
-      xystart.x + g_StepXY.x * 3.0);
+  float2 xystart = (-1.0 - f) * g_StepXY + TextureUV;
+  float4 xpos = xystart.x + g_StepXY.x * float4(0.0, 1.0, 2.0, 3.0);
+  float4 ypos = xystart.y + g_StepXY.y * float4(0.0, 1.0, 2.0, 3.0);
 
   float3 rgb =
-    getLine(xystart.y                   , xpos, linetaps) * columntaps.r +
-    getLine(xystart.y + g_StepXY.y      , xpos, linetaps) * columntaps.g +
-    getLine(xystart.y + g_StepXY.y * 2.0, xpos, linetaps) * columntaps.b +
-    getLine(xystart.y + g_StepXY.y * 3.0, xpos, linetaps) * columntaps.a;
+    getLine(ypos.x, xpos, linetaps) * columntaps.r +
+    getLine(ypos.y, xpos, linetaps) * columntaps.g +
+    getLine(ypos.z, xpos, linetaps) * columntaps.b +
+    getLine(ypos.w, xpos, linetaps) * columntaps.a;
 
   return float4(rgb, 1.0);
 }
 
-technique10 SCALER_T
+technique11 SCALER_T
 {
   pass P0
   {
-    SetVertexShader( CompileShader( vs_4_0_level_9_3, VS() ) );
+    SetVertexShader( CompileShader( vs_4_0_level_9_1, VS() ) );
     SetPixelShader( CompileShader( ps_4_0_level_9_3, CONVOLUTION4x4() ) );
   }
 };
index a773a01..d6f1210 100644 (file)
@@ -21,8 +21,7 @@
 texture2D g_Texture;
 texture2D g_KernelTexture;
 float2    g_StepXY;
-float     g_viewportWidth;
-float     g_viewportHeight;
+float2    g_viewPort;
 
 SamplerState RGBSampler : IMMUTABLE
 {
@@ -40,8 +39,8 @@ SamplerState KernelSampler : IMMUTABLE
 
 struct VS_OUTPUT
 {
-  float4 Position   : SV_POSITION;
   float2 TextureUV  : TEXCOORD0;
+  float4 Position   : SV_POSITION;
 };
 
 //
@@ -50,8 +49,8 @@ struct VS_OUTPUT
 VS_OUTPUT VS(VS_OUTPUT In)
 {
   VS_OUTPUT output  = (VS_OUTPUT)0;
-  output.Position.x =  (In.Position.x / (g_viewportWidth  / 2.0)) - 1;
-  output.Position.y = -(In.Position.y / (g_viewportHeight / 2.0)) + 1;
+  output.Position.x =  (In.Position.x / (g_viewPort.x  / 2.0)) - 1;
+  output.Position.y = -(In.Position.y / (g_viewPort.y / 2.0)) + 1;
   output.Position.z = output.Position.z;
   output.Position.w = 1.0;
   output.TextureUV  = In.TextureUV;
@@ -73,21 +72,25 @@ half3 weight(float pos)
   return w;
 }
 
+inline half3 pixel(float xpos, float ypos)
+{
+  return g_Texture.Sample(RGBSampler, float2(xpos, ypos)).rgb;
+}
+
 inline half3 getLine(float ypos, float3 xpos1, float3 xpos2, half3 linetaps1, half3 linetaps2)
 {
   return
-    g_Texture.Sample(RGBSampler, float2(xpos1.r, ypos)).rgb * linetaps1.r +
-    g_Texture.Sample(RGBSampler, float2(xpos1.g, ypos)).rgb * linetaps2.r +
-    g_Texture.Sample(RGBSampler, float2(xpos1.b, ypos)).rgb * linetaps1.g +
-    g_Texture.Sample(RGBSampler, float2(xpos2.r, ypos)).rgb * linetaps2.g +
-    g_Texture.Sample(RGBSampler, float2(xpos2.g, ypos)).rgb * linetaps1.b +
-    g_Texture.Sample(RGBSampler, float2(xpos2.b, ypos)).rgb * linetaps2.b;
+    pixel(xpos1.r, ypos) * linetaps1.r +
+    pixel(xpos1.g, ypos) * linetaps2.r +
+    pixel(xpos1.b, ypos) * linetaps1.g +
+    pixel(xpos2.r, ypos) * linetaps2.g +
+    pixel(xpos2.g, ypos) * linetaps1.b +
+    pixel(xpos2.b, ypos) * linetaps2.b;
 }
 
-float4 CONVOLUTION6x6(VS_OUTPUT In) : SV_TARGET
+float4 CONVOLUTION6x6(in float2 TextureUV  : TEXCOORD0) : SV_TARGET
 {
-  float2 pos = In.TextureUV + g_StepXY * 0.5;
-  float2 f = frac(pos / g_StepXY);
+  float2 f = frac(TextureUV / g_StepXY + 0.5);
 
   half3 linetaps1   = weight((1.0 - f.x) / 2.0);
   half3 linetaps2   = weight((1.0 - f.x) / 2.0 + 0.5);
@@ -96,32 +99,28 @@ float4 CONVOLUTION6x6(VS_OUTPUT In) : SV_TARGET
 
   // kernel generation code made sure taps add up to 1, no need to adjust here.
 
-  float2 xystart = (-2.0 - f) * g_StepXY + In.TextureUV;
-  float3 xpos1 = float3(
-      xystart.x,
-      xystart.x + g_StepXY.x,
-      xystart.x + g_StepXY.x * 2.0);
-  float3 xpos2 = half3(
-      xystart.x + g_StepXY.x * 3.0,
-      xystart.x + g_StepXY.x * 4.0,
-      xystart.x + g_StepXY.x * 5.0);
+  float2 xystart = (-2.0 - f) * g_StepXY + TextureUV;
+  float3 xpos1 = xystart.x + g_StepXY.x * float3(0.0, 1.0, 2.0);
+  float3 xpos2 = xystart.x + g_StepXY.x * float3(3.0, 4.0, 5.0);
+  float3 ypos1 = xystart.y + g_StepXY.y * float3(0.0, 1.0, 2.0);
+  float3 ypos2 = xystart.y + g_StepXY.y * float3(3.0, 4.0, 5.0);
 
   float3 rgb =  
-        getLine(xystart.y                   , xpos1, xpos2, linetaps1, linetaps2) * columntaps1.r +
-                               getLine(xystart.y + g_StepXY.y      , xpos1, xpos2, linetaps1, linetaps2) * columntaps2.r +
-                               getLine(xystart.y + g_StepXY.y * 2.0, xpos1, xpos2, linetaps1, linetaps2) * columntaps1.g +
-                               getLine(xystart.y + g_StepXY.y * 3.0, xpos1, xpos2, linetaps1, linetaps2) * columntaps2.g +
-                               getLine(xystart.y + g_StepXY.y * 4.0, xpos1, xpos2, linetaps1, linetaps2) * columntaps1.b +
-                               getLine(xystart.y + g_StepXY.y * 5.0, xpos1, xpos2, linetaps1, linetaps2) * columntaps2.b;
+        getLine(ypos1.x, xpos1, xpos2, linetaps1, linetaps2) * columntaps1.r +
+               getLine(ypos1.y, xpos1, xpos2, linetaps1, linetaps2) * columntaps2.r +
+               getLine(ypos1.z, xpos1, xpos2, linetaps1, linetaps2) * columntaps1.g +
+               getLine(ypos2.x, xpos1, xpos2, linetaps1, linetaps2) * columntaps2.g +
+               getLine(ypos2.y, xpos1, xpos2, linetaps1, linetaps2) * columntaps1.b +
+               getLine(ypos2.z, xpos1, xpos2, linetaps1, linetaps2) * columntaps2.b;
 
   return float4(rgb, 1.0f);
 }
 
-technique10 SCALER_T
+technique11 SCALER_T
 {
   pass P0
   {
-    SetVertexShader( CompileShader( vs_4_0_level_9_3, VS() ) );
+    SetVertexShader( CompileShader( vs_4_0_level_9_1, VS() ) );
     SetPixelShader( CompileShader( ps_4_0_level_9_3, CONVOLUTION6x6() ) );
   }
 };
index 2816e7b..a778987 100644 (file)
 
 texture2D g_Texture;
 texture2D g_KernelTexture;
-float2    g_StepXY_P0;
-float2    g_StepXY_P1;
-float     g_viewportWidth;
-float     g_viewportHeight;
+float4    g_StepXY;
+float2    g_viewPort;
 
 SamplerState RGBSampler : IMMUTABLE
 {
@@ -47,8 +45,8 @@ struct VS_INPUT
 
 struct VS_OUTPUT
 {
-  float4 Position   : SV_POSITION;
   float2 TextureUV  : TEXCOORD0;
+  float4 Position   : SV_POSITION;
 };
 
 //
@@ -57,8 +55,8 @@ struct VS_OUTPUT
 VS_OUTPUT VS(VS_INPUT In)
 {
   VS_OUTPUT output  = (VS_OUTPUT)0;
-  output.Position.x =  (In.Position.x / (g_viewportWidth  / 2.0)) - 1;
-  output.Position.y = -(In.Position.y / (g_viewportHeight / 2.0)) + 1;
+  output.Position.x =  (In.Position.x / (g_viewPort.x  / 2.0)) - 1;
+  output.Position.y = -(In.Position.y / (g_viewPort.y / 2.0)) + 1;
   output.Position.z = output.Position.z;
   output.Position.w = 1.0;
   output.TextureUV  = In.TextureUV;
@@ -80,9 +78,9 @@ inline half4 weight(float pos)
   return w;
 }
 
-inline half3 pixel(texture2D tex, float xpos, float ypos)
+inline half3 pixel(float xpos, float ypos)
 {
-  return tex.Sample(RGBSampler, float2(xpos, ypos)).rgb;
+  return g_Texture.Sample(RGBSampler, float2(xpos, ypos)).rgb;
 }
 
 // Code for first pass - horizontal
@@ -90,30 +88,22 @@ inline half3 pixel(texture2D tex, float xpos, float ypos)
 inline half3 getLine(float ypos, float4 xpos, half4 linetaps)
 {
   return
-    pixel(g_Texture, xpos.r, ypos) * linetaps.r +
-    pixel(g_Texture, xpos.g, ypos) * linetaps.g +
-    pixel(g_Texture, xpos.b, ypos) * linetaps.b +
-    pixel(g_Texture, xpos.a, ypos) * linetaps.a;
+    pixel(xpos.r, ypos) * linetaps.r +
+    pixel(xpos.g, ypos) * linetaps.g +
+    pixel(xpos.b, ypos) * linetaps.b +
+    pixel(xpos.a, ypos) * linetaps.a;
 }
 
-float4 CONVOLUTION4x4Horiz(VS_OUTPUT In) : SV_TARGET
+float4 CONVOLUTION4x4Horiz(in float2 TextureUV : TEXCOORD0) : SV_TARGET
 {
-  float2 pos = In.TextureUV + g_StepXY_P0 * 0.5;
-  float2 f = frac(pos / g_StepXY_P0);
-
+  float2 f = frac(TextureUV / g_StepXY.xy + 0.5);
   half4 linetaps = weight(1.0 - f.x);
 
   // kernel generation code made sure taps add up to 1, no need to adjust here.
+  float xystart = (-1.0 - f.x) * g_StepXY.x + TextureUV.x;
 
-  float xystart = (-1.0 - f.x) * g_StepXY_P0.x + In.TextureUV.x;
-
-  float4 xpos = float4(
-      xystart,
-      xystart + g_StepXY_P0.x,
-      xystart + g_StepXY_P0.x * 2.0,
-      xystart + g_StepXY_P0.x * 3.0);
-
-  return float4(getLine(In.TextureUV.y, xpos, linetaps), 1.0f);
+  float4 xpos = xystart + g_StepXY.x * float4(0.0, 1.0, 2.0, 3.0);
+  return float4(getLine(TextureUV.y, xpos, linetaps), 1.0f);
 }
 
 // Code for second pass - vertical
@@ -121,42 +111,34 @@ float4 CONVOLUTION4x4Horiz(VS_OUTPUT In) : SV_TARGET
 inline half3 getRow(float xpos, float4 ypos, half4 columntaps)
 {
   return
-    pixel(g_Texture, xpos, ypos.r) * columntaps.r +
-    pixel(g_Texture, xpos, ypos.g) * columntaps.g +
-    pixel(g_Texture, xpos, ypos.b) * columntaps.b +
-    pixel(g_Texture, xpos, ypos.a) * columntaps.a;
+    pixel(xpos, ypos.r) * columntaps.r +
+    pixel(xpos, ypos.g) * columntaps.g +
+    pixel(xpos, ypos.b) * columntaps.b +
+    pixel(xpos, ypos.a) * columntaps.a;
 }
 
-float4 CONVOLUTION4x4Vert(VS_OUTPUT In) : SV_TARGET
+float4 CONVOLUTION4x4Vert(in float2 TextureUV : TEXCOORD0) : SV_TARGET
 {
-  float2 pos = In.TextureUV + g_StepXY_P1 * 0.5;
-  float2 f = frac(pos / g_StepXY_P1);
-
+  float2 f = frac(TextureUV / g_StepXY.zw + 0.5);
   half4 columntaps = weight(1.0 - f.y);
 
   // kernel generation code made sure taps add up to 1, no need to adjust here.
+  float xystart = (-1.0 - f.y) * g_StepXY.w + TextureUV.y;
 
-  float xystart = (-1.0 - f.y) * g_StepXY_P1.y + In.TextureUV.y;
-
-  float4 ypos = float4(
-      xystart,
-      xystart + g_StepXY_P1.y,
-      xystart + g_StepXY_P1.y * 2.0,
-      xystart + g_StepXY_P1.y * 3.0);
-
-  return float4(getRow(In.TextureUV.x, ypos, columntaps), 1.0f);
+  float4 ypos = xystart + g_StepXY.w * float4(0.0, 1.0, 2.0, 3.0);
+  return float4(getRow(TextureUV.x, ypos, columntaps), 1.0f);
 }
 
-technique10 SCALER_T
+technique11 SCALER_T
 {
   pass P0
   {
-    SetVertexShader( CompileShader( vs_4_0_level_9_3, VS() ) );
+    SetVertexShader( CompileShader( vs_4_0_level_9_1, VS() ) );
     SetPixelShader( CompileShader( ps_4_0_level_9_3, CONVOLUTION4x4Horiz() ) );
   }
   pass P1
   {
-    SetVertexShader( CompileShader( vs_4_0_level_9_3, VS() ) );
+    SetVertexShader( CompileShader( vs_4_0_level_9_1, VS() ) );
     SetPixelShader( CompileShader( ps_4_0_level_9_3, CONVOLUTION4x4Vert() ) );
   }
 
index 9a5f27f..bf31f31 100644 (file)
 
 texture2D g_Texture;
 texture2D g_KernelTexture;
-float2    g_StepXY_P0;
-float2    g_StepXY_P1;
-float     g_viewportWidth;
-float     g_viewportHeight;
+float4    g_StepXY;
+float2    g_viewPort;
 
 SamplerState RGBSampler : IMMUTABLE
 {
@@ -47,8 +45,8 @@ struct VS_INPUT
 
 struct VS_OUTPUT
 {
-  float4 Position   : SV_POSITION;
   float2 TextureUV  : TEXCOORD0;
+  float4 Position   : SV_POSITION;
 };
 
 //
@@ -57,8 +55,8 @@ struct VS_OUTPUT
 VS_OUTPUT VS(VS_INPUT In)
 {
   VS_OUTPUT output  = (VS_OUTPUT)0;
-  output.Position.x =  (In.Position.x / (g_viewportWidth  / 2.0)) - 1;
-  output.Position.y = -(In.Position.y / (g_viewportHeight / 2.0)) + 1;
+  output.Position.x =  (In.Position.x / (g_viewPort.x  / 2.0)) - 1;
+  output.Position.y = -(In.Position.y / (g_viewPort.y / 2.0)) + 1;
   output.Position.z = output.Position.z;
   output.Position.w = 1.0;
   output.TextureUV  = In.TextureUV;
@@ -80,45 +78,38 @@ inline half3 weight(float pos)
   return w;
 }
 
-inline half3 pixel(texture2D tex, float xpos, float ypos)
+inline half3 pixel(float xpos, float ypos)
 {
-  return tex.Sample(RGBSampler, float2(xpos, ypos)).rgb;
+  return g_Texture.Sample(RGBSampler, float2(xpos, ypos)).rgb;
 }
 
 half3 getLine(float ypos, float3 xpos1, float3 xpos2, half3 linetaps1, half3 linetaps2)
 {
   return
-    g_Texture.Sample(RGBSampler, float2(xpos1.r, ypos)).rgb * linetaps1.r +
-    g_Texture.Sample(RGBSampler, float2(xpos1.g, ypos)).rgb * linetaps2.r +
-    g_Texture.Sample(RGBSampler, float2(xpos1.b, ypos)).rgb * linetaps1.g +
-    g_Texture.Sample(RGBSampler, float2(xpos2.r, ypos)).rgb * linetaps2.g +
-    g_Texture.Sample(RGBSampler, float2(xpos2.g, ypos)).rgb * linetaps1.b +
-    g_Texture.Sample(RGBSampler, float2(xpos2.b, ypos)).rgb * linetaps2.b;
+    pixel(xpos1.r, ypos) * linetaps1.r +
+    pixel(xpos1.g, ypos) * linetaps2.r +
+    pixel(xpos1.b, ypos) * linetaps1.g +
+    pixel(xpos2.r, ypos) * linetaps2.g +
+    pixel(xpos2.g, ypos) * linetaps1.b +
+    pixel(xpos2.b, ypos) * linetaps2.b;
 }
 
 // Code for first pass - horizontal
-float4 CONVOLUTION6x6Horiz(VS_OUTPUT In) : SV_TARGET
+float4 CONVOLUTION6x6Horiz(in float2 TextureUV : TEXCOORD0) : SV_TARGET
 {
-  float2 pos = In.TextureUV + g_StepXY_P0 * 0.5;
-  float2 f = frac(pos / g_StepXY_P0);
+  float2 f = frac(TextureUV / g_StepXY.xy + 0.5);
 
   half3 linetaps1 = weight((1.0 - f.x) / 2.0);
   half3 linetaps2 = weight((1.0 - f.x) / 2.0 + 0.5);
 
   // kernel generation code made sure taps add up to 1, no need to adjust here.
 
-  float xstart = (-2.0 - f.x) * g_StepXY_P0.x + In.TextureUV.x;
+  float xstart = (-2.0 - f.x) * g_StepXY.x + TextureUV.x;
 
-  float3 xpos1 = float3(
-      xstart,
-      xstart + g_StepXY_P0.x,
-      xstart + g_StepXY_P0.x * 2.0);
-  float3 xpos2 = half3(
-      xstart + g_StepXY_P0.x * 3.0,
-      xstart + g_StepXY_P0.x * 4.0,
-      xstart + g_StepXY_P0.x * 5.0);
+  float3 xpos1 = xstart + g_StepXY.x * float3(0.0, 1.0, 2.0);
+  float3 xpos2 = xstart + g_StepXY.x * float3(3.0, 4.0, 5.0);
 
-  return float4(getLine(In.TextureUV.y, xpos1, xpos2, linetaps1, linetaps2), 1.0);
+  return float4(getLine(TextureUV.y, xpos1, xpos2, linetaps1, linetaps2), 1.0);
 }
 
 // Code for second pass - vertical
@@ -126,48 +117,41 @@ float4 CONVOLUTION6x6Horiz(VS_OUTPUT In) : SV_TARGET
 half3 getRow(float xpos, float3 ypos1, float3 ypos2, half3 columntaps1, half3 columntaps2)
 {
   return
-    g_Texture.Sample(RGBSampler, float2(xpos, ypos1.r)).rgb * columntaps1.r +
-    g_Texture.Sample(RGBSampler, float2(xpos, ypos1.g)).rgb * columntaps2.r +
-    g_Texture.Sample(RGBSampler, float2(xpos, ypos1.b)).rgb * columntaps1.g +
-    g_Texture.Sample(RGBSampler, float2(xpos, ypos2.r)).rgb * columntaps2.g +
-    g_Texture.Sample(RGBSampler, float2(xpos, ypos2.g)).rgb * columntaps1.b +
-    g_Texture.Sample(RGBSampler, float2(xpos, ypos2.b)).rgb * columntaps2.b;
+    pixel(xpos, ypos1.r) * columntaps1.r +
+    pixel(xpos, ypos1.g) * columntaps2.r +
+    pixel(xpos, ypos1.b) * columntaps1.g +
+    pixel(xpos, ypos2.r) * columntaps2.g +
+    pixel(xpos, ypos2.g) * columntaps1.b +
+    pixel(xpos, ypos2.b) * columntaps2.b;
 }
 
-float4 CONVOLUTION6x6Vert(VS_OUTPUT In) : SV_TARGET
+float4 CONVOLUTION6x6Vert(in float2 TextureUV : TEXCOORD0) : SV_TARGET
 {
-  float2 pos = In.TextureUV + g_StepXY_P1 * 0.5;
-  float2 f = frac(pos / g_StepXY_P1);
+  float2 f = frac(TextureUV / g_StepXY.zw + 0.5);
 
   half3 columntaps1 = weight((1.0 - f.y) / 2.0);
   half3 columntaps2 = weight((1.0 - f.y) / 2.0 + 0.5);
 
   // kernel generation code made sure taps add up to 1, no need to adjust here.
 
-  float ystart = (-2.0 - f.y) * g_StepXY_P1.y + In.TextureUV.y;
+  float ystart = (-2.0 - f.y) * g_StepXY.w + TextureUV.y;
 
-  float3 ypos1 = float3(
-      ystart,
-      ystart + g_StepXY_P1.y,
-      ystart + g_StepXY_P1.y * 2.0);
-  float3 ypos2 = half3(
-      ystart + g_StepXY_P1.y * 3.0,
-      ystart + g_StepXY_P1.y * 4.0,
-      ystart + g_StepXY_P1.y * 5.0);
+  float3 ypos1 = ystart + g_StepXY.w * float3(0.0, 1.0, 2.0);
+  float3 ypos2 = ystart + g_StepXY.w * float3(3.0, 4.0, 5.0);
 
-  return float4(getRow(In.TextureUV.x, ypos1, ypos2, columntaps1, columntaps2), 1.0);
+  return float4(getRow(TextureUV.x, ypos1, ypos2, columntaps1, columntaps2), 1.0);
 }
 
-technique10 SCALER_T
+technique11 SCALER_T
 {
   pass P0
   {
-    SetVertexShader( CompileShader( vs_4_0_level_9_3, VS() ) );
+    SetVertexShader( CompileShader( vs_4_0_level_9_1, VS() ) );
     SetPixelShader( CompileShader( ps_4_0_level_9_3, CONVOLUTION6x6Horiz() ) );
   }
   pass P1
   {
-    SetVertexShader( CompileShader( vs_4_0_level_9_3, VS() ) );
+    SetVertexShader( CompileShader( vs_4_0_level_9_1, VS() ) );
     SetPixelShader( CompileShader( ps_4_0_level_9_3, CONVOLUTION6x6Vert() ) );
   }
 };
index ffe46ad..8c41ee7 100644 (file)
  *
  */
 
-float4 TEST() : COLOR
+float4 TEST() : SV_TARGET
 {
   return float4(0.0, 0.0, 0.0, 0.0);
 }
 
-technique TEST_T
+technique11 TEST_T
 {
   pass P0
   {
-    PixelShader  = compile ps_2_0 TEST();
+    SetPixelShader( CompileShader( ps_4_0_level_9_3, TEST() ) );
   }
 };
index 7621c60..6fb9cf3 100644 (file)
@@ -23,8 +23,7 @@ texture2D  g_UTexture;
 texture2D  g_VTexture;
 float4x4   g_ColorMatrix;
 float2     g_StepXY;
-float      g_viewportWidth;
-float      g_viewportHeight;
+float2     g_viewPort;
 
 
 SamplerState YUVSampler : IMMUTABLE
@@ -52,17 +51,17 @@ struct VS_INPUT
 
 struct VS_OUTPUT
 {
-  float4 Position   : SV_POSITION;
   float2 TextureY   : TEXCOORD0;
   float2 TextureU   : TEXCOORD1;
   float2 TextureV   : TEXCOORD2;
+  float4 Position   : SV_POSITION;
 };
 
 VS_OUTPUT VS(VS_INPUT In)
 {
   VS_OUTPUT output = (VS_OUTPUT)0;
-  output.Position.x =  (In.Position.x / (g_viewportWidth  / 2.0)) - 1;
-  output.Position.y = -(In.Position.y / (g_viewportHeight / 2.0)) + 1;
+  output.Position.x =  (In.Position.x / (g_viewPort.x  / 2.0)) - 1;
+  output.Position.y = -(In.Position.y / (g_viewPort.y / 2.0)) + 1;
   output.Position.z = output.Position.z;
   output.Position.w = 1.0;
   output.TextureY   = In.TextureY;
@@ -132,12 +131,11 @@ float4 YUV2RGB(VS_OUTPUT In) : SV_TARGET
   return float4(mul(YUV, g_ColorMatrix).rgb, 1.0);
 }
 
-technique10 YUV2RGB_T
+technique11 YUV2RGB_T
 {
   pass P0
   {
     SetVertexShader( CompileShader( vs_4_0_level_9_1, VS() ) );
-    SetGeometryShader( NULL );
     SetPixelShader( CompileShader( ps_4_0_level_9_1, YUV2RGB() ) );
   }
 };
index 26b60c1..133a593 100644 (file)
@@ -113,8 +113,8 @@ bool CWinShader::CreateVertexBuffer(unsigned int vertCount, unsigned int vertSiz
   if (!m_vb.Create(D3D11_BIND_VERTEX_BUFFER, vertCount, vertSize, DXGI_FORMAT_UNKNOWN, D3D11_USAGE_DYNAMIC))
     return false;
 
-  uint16_t id[6] = { 0, 1, 2, 2, 3, 0 };
-  if (!m_ib.Create(D3D11_BIND_INDEX_BUFFER, 6, sizeof(uint16_t), DXGI_FORMAT_R16_UINT, D3D11_USAGE_IMMUTABLE, id))
+  uint16_t id[4] = { 3, 0, 2, 1 };
+  if (!m_ib.Create(D3D11_BIND_INDEX_BUFFER, ARRAYSIZE(id), sizeof(uint16_t), DXGI_FORMAT_R16_UINT, D3D11_USAGE_IMMUTABLE, id))
     return false;
 
   m_vbsize = vertCount * vertSize;
@@ -201,7 +201,7 @@ bool CWinShader::Execute(std::vector<ID3D11RenderTargetView*> *vecRT, unsigned i
   pContext->IASetVertexBuffers(0, 1, &vertexBuffer, &stride, &offset);
   pContext->IASetIndexBuffer(indexBuffer, m_ib.GetFormat(), 0);
   pContext->IASetInputLayout(m_inputLayout);
-  pContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
+  pContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
 
   for (iPass = 0; iPass < cPasses; iPass++)
   {
@@ -216,7 +216,7 @@ bool CWinShader::Execute(std::vector<ID3D11RenderTargetView*> *vecRT, unsigned i
       break;
     }
 
-    pContext->DrawIndexed(6, 0, iPass * vertexIndexStep);
+    pContext->DrawIndexed(4, 0, iPass * vertexIndexStep);
 
     if (!m_effect.EndPass())
       CLog::Log(LOGERROR, __FUNCTION__" - failed to end d3d effect pass");
@@ -330,9 +330,6 @@ void CYUV2RGBShader::PrepareParameters(CRect sourceRect,
                                        float brightness,
                                        unsigned int flags)
 {
-  //See RGB renderer for comment on this
-  #define CHROMAOFFSET_HORIZ 0.25f
-
   if (m_sourceRect != sourceRect || m_destRect != destRect)
   {
     m_sourceRect = sourceRect;
@@ -346,32 +343,32 @@ void CYUV2RGBShader::PrepareParameters(CRect sourceRect,
     v[0].z = 0.0f;
     v[0].tu = sourceRect.x1 / m_sourceWidth;
     v[0].tv = sourceRect.y1 / m_sourceHeight;
-    v[0].tu2 = v[0].tu3 = (sourceRect.x1 / 2.0f + CHROMAOFFSET_HORIZ) / (m_sourceWidth>>1);
-    v[0].tv2 = v[0].tv3 = (sourceRect.y1 / 2.0f + CHROMAOFFSET_HORIZ) / (m_sourceHeight>>1);
+    v[0].tu2 = v[0].tu3 = (sourceRect.x1 / 2.0f) / (m_sourceWidth>>1);
+    v[0].tv2 = v[0].tv3 = (sourceRect.y1 / 2.0f) / (m_sourceHeight>>1);
 
     v[1].x = destRect.x2;
     v[1].y = destRect.y1;
     v[1].z = 0.0f;
     v[1].tu = sourceRect.x2 / m_sourceWidth;
     v[1].tv = sourceRect.y1 / m_sourceHeight;
-    v[1].tu2 = v[1].tu3 = (sourceRect.x2 / 2.0f + CHROMAOFFSET_HORIZ) / (m_sourceWidth>>1);
-    v[1].tv2 = v[1].tv3 = (sourceRect.y1 / 2.0f + CHROMAOFFSET_HORIZ) / (m_sourceHeight>>1);
+    v[1].tu2 = v[1].tu3 = (sourceRect.x2 / 2.0f) / (m_sourceWidth>>1);
+    v[1].tv2 = v[1].tv3 = (sourceRect.y1 / 2.0f) / (m_sourceHeight>>1);
 
     v[2].x = destRect.x2;
     v[2].y = destRect.y2;
     v[2].z = 0.0f;
     v[2].tu = sourceRect.x2 / m_sourceWidth;
     v[2].tv = sourceRect.y2 / m_sourceHeight;
-    v[2].tu2 = v[2].tu3 = (sourceRect.x2 / 2.0f + CHROMAOFFSET_HORIZ) / (m_sourceWidth>>1);
-    v[2].tv2 = v[2].tv3 = (sourceRect.y2 / 2.0f + CHROMAOFFSET_HORIZ) / (m_sourceHeight>>1);
+    v[2].tu2 = v[2].tu3 = (sourceRect.x2 / 2.0f) / (m_sourceWidth>>1);
+    v[2].tv2 = v[2].tv3 = (sourceRect.y2 / 2.0f) / (m_sourceHeight>>1);
 
     v[3].x = destRect.x1;
     v[3].y = destRect.y2;
     v[3].z = 0.0f;
     v[3].tu = sourceRect.x1 / m_sourceWidth;
     v[3].tv = sourceRect.y2 / m_sourceHeight;
-    v[3].tu2 = v[3].tu3 = (sourceRect.x1 / 2.0f + CHROMAOFFSET_HORIZ) / (m_sourceWidth>>1);
-    v[3].tv2 = v[3].tv3 = (sourceRect.y2 / 2.0f + CHROMAOFFSET_HORIZ) / (m_sourceHeight>>1);
+    v[3].tu2 = v[3].tu3 = (sourceRect.x1 / 2.0f) / (m_sourceWidth>>1);
+    v[3].tv2 = v[3].tv3 = (sourceRect.y2 / 2.0f) / (m_sourceHeight>>1);
 
     CWinShader::UnlockVertexBuffer();
   }
@@ -409,8 +406,8 @@ void CYUV2RGBShader::SetShaderParameters(YUVBuffer* YUVbuf)
   {
     D3D11_TEXTURE2D_DESC rtDescr = {};
     rtTexture->GetDesc(&rtDescr);
-    viewPortWidth = rtDescr.Width;
-    viewPortHeight = rtDescr.Height;
+    viewPortWidth = static_cast<float>(rtDescr.Width);
+    viewPortHeight = static_cast<float>(rtDescr.Height);
   }
 
   SAFE_RELEASE(rtTexture);
@@ -419,9 +416,7 @@ void CYUV2RGBShader::SetShaderParameters(YUVBuffer* YUVbuf)
 
   D3D11_VIEWPORT viewPort = { 0.0f, 0.0f, viewPortWidth, viewPortHeight, 0.0, 1.0f };
   g_Windowing.Get3D11Context()->RSSetViewports(1, &viewPort);
-
-  m_effect.SetScalar("g_viewportWidth", viewPortWidth);
-  m_effect.SetScalar("g_viewportHeight", viewPortHeight);
+  m_effect.SetFloatArray("g_viewPort", &viewPort.Width, 2);
 }
 
 //==================================================================================
@@ -609,8 +604,7 @@ void CConvolutionShader1Pass::SetShaderParameters(CD3DTexture &sourceTexture, fl
   UINT numVP = 1;
   D3D11_VIEWPORT viewPort = {};
   g_Windowing.Get3D11Context()->RSGetViewports(&numVP, &viewPort);
-  m_effect.SetScalar("g_viewportWidth", viewPort.Width);
-  m_effect.SetScalar("g_viewportHeight", viewPort.Height);
+  m_effect.SetFloatArray("g_viewPort", &viewPort.Width, 2);
 }
 
 //==================================================================================
@@ -691,9 +685,14 @@ void CConvolutionShaderSeparable::Render(CD3DTexture &sourceTexture,
     CreateIntermediateRenderTarget(destWidth, sourceHeight);
 
   PrepareParameters(sourceWidth, sourceHeight, destWidth, destHeight, sourceRect, destRect);
-  float texSteps1[] = { 1.0f/(float)sourceWidth, 1.0f/(float)sourceHeight};
-  float texSteps2[] = { 1.0f/(float)destWidth, 1.0f/(float)(sourceHeight)};
-  SetShaderParameters(sourceTexture, &texSteps1[0], ARRAY_SIZE(texSteps1), &texSteps2[0], ARRAY_SIZE(texSteps2));
+  float texSteps[] = 
+  { 
+    1.0f / static_cast<float>(sourceWidth), 
+    1.0f / static_cast<float>(sourceHeight), 
+    1.0f / static_cast<float>(destWidth), 
+    1.0f / static_cast<float>(sourceHeight)
+  };
+  SetShaderParameters(sourceTexture, texSteps, 4);
 
   Execute(nullptr, 4);
 
@@ -756,10 +755,6 @@ void CConvolutionShaderSeparable::PrepareParameters(unsigned int sourceWidth, un
   || m_destWidth != destWidth || m_destHeight != destHeight
   || m_sourceRect != sourceRect || m_destRect != destRect)
   {
-    // fixme better: clearing the whole render target when changing the source/dest rect is not optimal.
-    // Problem is that the edges of the final picture may retain content when the rects change.
-    // For example when changing zoom value, the edges can retain content from the previous zoom value.
-    // Playing with coordinates was unsuccessful so far, this is a quick fix for release.
     ClearIntermediateRenderTarget();
 
     m_sourceWidth = sourceWidth;
@@ -774,7 +769,7 @@ void CConvolutionShaderSeparable::PrepareParameters(unsigned int sourceWidth, un
 
     // Alter rectangles the destination rectangle exceeds the intermediate target width when zooming and causes artifacts.
     // Work on the parameters rather than the members to avoid disturbing the parameter change detection the next time the function is called
-    CRect tgtRect(0, 0, destWidth, destHeight);
+    CRect tgtRect(0, 0, static_cast<float>(destWidth), static_cast<float>(destHeight));
     CWIN32Util::CropSource(sourceRect, destRect, tgtRect);
 
     // Manipulate the coordinates to work only on the active parts of the textures,
@@ -839,13 +834,12 @@ void CConvolutionShaderSeparable::PrepareParameters(unsigned int sourceWidth, un
   }
 }
 
-void CConvolutionShaderSeparable::SetShaderParameters(CD3DTexture &sourceTexture, float* texSteps1, int texStepsCount1, float* texSteps2, int texStepsCount2)
+void CConvolutionShaderSeparable::SetShaderParameters(CD3DTexture &sourceTexture, float* texSteps, int texStepsCount)
 {
   m_effect.SetTechnique( "SCALER_T" );
   m_effect.SetTexture( "g_Texture",  sourceTexture );
   m_effect.SetTexture( "g_KernelTexture", m_HQKernelTexture );
-  m_effect.SetFloatArray("g_StepXY_P0", texSteps1, texStepsCount1);
-  m_effect.SetFloatArray("g_StepXY_P1", texSteps2, texStepsCount2);
+  m_effect.SetFloatArray("g_StepXY", texSteps, texStepsCount);
 }
 
 void CConvolutionShaderSeparable::SetStepParams(UINT iPass)
@@ -876,8 +870,8 @@ void CConvolutionShaderSeparable::SetStepParams(UINT iPass)
     {
       D3D11_TEXTURE2D_DESC rtDescr = {};
       rtTexture->GetDesc(&rtDescr);
-      viewPortWidth = rtDescr.Width;
-      viewPortHeight = rtDescr.Height;
+      viewPortWidth = static_cast<float>(rtDescr.Width);
+      viewPortHeight = static_cast<float>(rtDescr.Height);
     }
 
     SAFE_RELEASE(rtTexture);
@@ -894,8 +888,7 @@ void CConvolutionShaderSeparable::SetStepParams(UINT iPass)
   CD3D11_VIEWPORT viewPort(0.0f, 0.0f, viewPortWidth, viewPortHeight);
   pContext->RSSetViewports(1, &viewPort);
   // pass viewport dimention to the shaders
-  m_effect.SetScalar("g_viewportWidth", viewPort.Width);
-  m_effect.SetScalar("g_viewportHeight", viewPort.Height);
+  m_effect.SetFloatArray("g_viewPort", &viewPort.Width, 2);
 }
 
 //==========================================================
index 4abd882..e6bbd44 100644 (file)
@@ -184,7 +184,7 @@ protected:
                                unsigned int destWidth, unsigned int destHeight,
                                CRect sourceRect,
                                CRect destRect);
-  virtual void SetShaderParameters(CD3DTexture &sourceTexture, float* texSteps1, int texStepsCount1, float* texSteps2, int texStepsCount2);
+  virtual void SetShaderParameters(CD3DTexture &sourceTexture, float* texSteps, int texStepsCount);
   virtual void SetStepParams(UINT stepIndex);
 
 private: