diff options
author | Anton Fedchin <afedchin@ruswizards.com> | 2015-04-22 18:08:15 +0300 |
---|---|---|
committer | Anton Fedchin <afedchin@ruswizards.com> | 2015-07-04 10:25:09 +0300 |
commit | 557bc0c362b43ab24439d2cf8149f87885162ff6 (patch) | |
tree | 95e733b5bf1d8c3c3e37f070ffe5fd9ca775f580 /system | |
parent | ec543ddedbfb323ff7042b4e5f74430ff9cd2095 (diff) |
[WinVideoFilter] Rework to DirectX11.
Diffstat (limited to 'system')
-rw-r--r-- | system/shaders/convolution-4x4_d3d.fx | 113 | ||||
-rw-r--r-- | system/shaders/convolution-6x6_d3d.fx | 120 | ||||
-rw-r--r-- | system/shaders/convolutionsep-4x4_d3d.fx | 174 | ||||
-rw-r--r-- | system/shaders/convolutionsep-6x6_d3d.fx | 189 | ||||
-rw-r--r-- | system/shaders/yuv2rgb_d3d.fx | 124 |
5 files changed, 348 insertions, 372 deletions
diff --git a/system/shaders/convolution-4x4_d3d.fx b/system/shaders/convolution-4x4_d3d.fx index c33e315a3b..e1bec786c7 100644 --- a/system/shaders/convolution-4x4_d3d.fx +++ b/system/shaders/convolution-4x4_d3d.fx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2010-2013 Team XBMC + * Copyright (C) 2005-2015 Team XBMC * http://xbmc.org * * This Program is free software; you can redistribute it and/or modify @@ -18,78 +18,82 @@ * */ -texture g_Texture; -texture g_KernelTexture; -float2 g_StepXY; - -sampler RGBSampler = - sampler_state { - Texture = <g_Texture>; - AddressU = CLAMP; - AddressV = CLAMP; - MinFilter = POINT; - MagFilter = POINT; - }; - -sampler KernelSampler = - sampler_state - { - Texture = <g_KernelTexture>; - AddressU = CLAMP; - AddressV = CLAMP; - MinFilter = LINEAR; - MagFilter = LINEAR; - }; +texture2D g_Texture; +texture2D g_KernelTexture; +float2 g_StepXY; +float g_viewportWidth; +float g_viewportHeight; -struct VS_OUTPUT +SamplerState RGBSampler : IMMUTABLE +{ + AddressU = CLAMP; + AddressV = CLAMP; + Filter = MIN_MAG_MIP_POINT; +}; + +SamplerState KernelSampler : IMMUTABLE +{ + AddressU = CLAMP; + AddressV = CLAMP; + Filter = MIN_MAG_MIP_LINEAR; +}; + +struct VS_INPUT { float4 Position : POSITION; float2 TextureUV : TEXCOORD0; }; -struct PS_OUTPUT +struct VS_OUTPUT { - float4 RGBColor : COLOR0; + float4 Position : SV_POSITION; + float2 TextureUV : TEXCOORD0; }; -half4 weight(float pos) +// +// VS for rendering in screen space +// +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.z = output.Position.z; + output.Position.w = 1.0; + output.TextureUV = In.TextureUV; + + return output; +} + +inline half4 weight(float pos) { - half4 w; #ifdef HAS_RGBA - w = tex1D(KernelSampler, pos); + half4 w = g_KernelTexture.Sample(KernelSampler, pos); #else - w = tex1D(KernelSampler, pos).bgra; + half4 w = g_KernelTexture.Sample(KernelSampler, pos).bgra; #endif -#ifdef HAS_FLOAT_TEXTURE - return w; -#else - return w * 2.0 - 1.0; +#ifndef HAS_FLOAT_TEXTURE + w = w * 2.0 - 1.0; #endif + return w; } -half3 pixel(float xpos, float ypos) -{ - return tex2D(RGBSampler, float2(xpos, ypos)).rgb; -} - -half3 getLine(float ypos, float4 xpos, half4 linetaps) +inline half3 getLine(float ypos, float4 xpos, half4 linetaps) { return - pixel(xpos.r, ypos) * linetaps.r + - pixel(xpos.g, ypos) * linetaps.g + - pixel(xpos.b, ypos) * linetaps.b + - pixel(xpos.a, ypos) * linetaps.a; + 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; } -PS_OUTPUT CONVOLUTION4x4(VS_OUTPUT In) +float4 CONVOLUTION4x4(VS_OUTPUT In) : SV_TARGET { - PS_OUTPUT OUT; - float2 pos = In.TextureUV + g_StepXY * 0.5; float2 f = frac(pos / g_StepXY); - half4 linetaps = weight(1.0 - f.x); + 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. @@ -101,23 +105,20 @@ PS_OUTPUT CONVOLUTION4x4(VS_OUTPUT In) xystart.x + g_StepXY.x * 2.0, xystart.x + g_StepXY.x * 3.0); - OUT.RGBColor.rgb = + 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; - OUT.RGBColor.a = 1.0; - return OUT; + return float4(rgb, 1.0); } -technique SCALER_T +technique10 SCALER_T { pass P0 { - PixelShader = compile ps_3_0 CONVOLUTION4x4(); - ZEnable = False; - FillMode = Solid; - FogEnable = False; + SetVertexShader( CompileShader( vs_4_0_level_9_3, VS() ) ); + SetPixelShader( CompileShader( ps_4_0_level_9_3, CONVOLUTION4x4() ) ); } }; diff --git a/system/shaders/convolution-6x6_d3d.fx b/system/shaders/convolution-6x6_d3d.fx index 06cec53d29..a773a01855 100644 --- a/system/shaders/convolution-6x6_d3d.fx +++ b/system/shaders/convolution-6x6_d3d.fx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2010-2013 Team XBMC + * Copyright (C) 2005-2015 Team XBMC * http://xbmc.org * * This Program is free software; you can redistribute it and/or modify @@ -18,76 +18,74 @@ * */ -texture g_Texture; -texture g_KernelTexture; -float2 g_StepXY; - -sampler RGBSampler = - sampler_state { - Texture = <g_Texture>; - AddressU = CLAMP; - AddressV = CLAMP; - MinFilter = POINT; - MagFilter = POINT; - }; - -sampler KernelSampler = - sampler_state - { - Texture = <g_KernelTexture>; - AddressU = CLAMP; - AddressV = CLAMP; - MinFilter = LINEAR; - MagFilter = LINEAR; - }; +texture2D g_Texture; +texture2D g_KernelTexture; +float2 g_StepXY; +float g_viewportWidth; +float g_viewportHeight; + +SamplerState RGBSampler : IMMUTABLE +{ + AddressU = CLAMP; + AddressV = CLAMP; + Filter = MIN_MAG_MIP_POINT; +}; + +SamplerState KernelSampler : IMMUTABLE +{ + AddressU = CLAMP; + AddressV = CLAMP; + Filter = MIN_MAG_MIP_LINEAR; +}; struct VS_OUTPUT { - float4 Position : POSITION; + float4 Position : SV_POSITION; float2 TextureUV : TEXCOORD0; }; -struct PS_OUTPUT +// +// VS for rendering in screen space +// +VS_OUTPUT VS(VS_OUTPUT In) { - float4 RGBColor : COLOR0; -}; + 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.z = output.Position.z; + output.Position.w = 1.0; + output.TextureUV = In.TextureUV; + + return output; +} half3 weight(float pos) { - half3 w; #ifdef HAS_RGBA - w = tex1D(KernelSampler, pos).rgb; + half3 w = g_KernelTexture.Sample(KernelSampler, pos).rgb; #else - w = tex1D(KernelSampler, pos).bgr; + half3 w = g_KernelTexture.Sample(KernelSampler, pos).bgr; #endif -#ifdef HAS_FLOAT_TEXTURE - return w; -#else - return w * 2.0 - 1.0; +#ifndef HAS_FLOAT_TEXTURE + w = w * 2.0 - 1.0; #endif + return w; } -half3 pixel(float xpos, float ypos) -{ - return tex2D(RGBSampler, float2(xpos, ypos)).rgb; -} - -half3 getLine(float ypos, float3 xpos1, float3 xpos2, half3 linetaps1, half3 linetaps2) +inline half3 getLine(float ypos, float3 xpos1, float3 xpos2, half3 linetaps1, half3 linetaps2) { return - 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; + 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; } -PS_OUTPUT CONVOLUTION6x6(VS_OUTPUT In) +float4 CONVOLUTION6x6(VS_OUTPUT In) : SV_TARGET { - PS_OUTPUT OUT; - float2 pos = In.TextureUV + g_StepXY * 0.5; float2 f = frac(pos / g_StepXY); @@ -108,24 +106,22 @@ PS_OUTPUT CONVOLUTION6x6(VS_OUTPUT In) xystart.x + g_StepXY.x * 4.0, xystart.x + g_StepXY.x * 5.0); - OUT.RGBColor.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; + 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; - OUT.RGBColor.a = 1.0; - return OUT; + return float4(rgb, 1.0f); } -technique SCALER_T +technique10 SCALER_T { pass P0 { - PixelShader = compile ps_3_0 CONVOLUTION6x6(); - ZEnable = False; - FillMode = Solid; - FogEnable = False; + SetVertexShader( CompileShader( vs_4_0_level_9_3, VS() ) ); + SetPixelShader( CompileShader( ps_4_0_level_9_3, CONVOLUTION6x6() ) ); } }; diff --git a/system/shaders/convolutionsep-4x4_d3d.fx b/system/shaders/convolutionsep-4x4_d3d.fx index e572f9b02c..2816e7bbc2 100644 --- a/system/shaders/convolutionsep-4x4_d3d.fx +++ b/system/shaders/convolutionsep-4x4_d3d.fx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2013 Team XBMC + * Copyright (C) 2005-2015 Team XBMC * http://xbmc.org * * This Program is free software; you can redistribute it and/or modify @@ -18,90 +18,86 @@ * */ -texture g_Texture; -texture g_KernelTexture; -texture g_IntermediateTexture; -float2 g_StepXY_P0; -float2 g_StepXY_P1; - -sampler RGBSampler = - sampler_state { - Texture = <g_Texture>; - AddressU = CLAMP; - AddressV = CLAMP; - MipFilter = LINEAR; - MinFilter = POINT; - MagFilter = POINT; - }; - -sampler KernelSampler = - sampler_state - { - Texture = <g_KernelTexture>; - AddressU = CLAMP; - AddressV = CLAMP; - MipFilter = LINEAR; - MinFilter = LINEAR; - MagFilter = LINEAR; - }; - -sampler IntermediateSampler = - sampler_state { - Texture = <g_IntermediateTexture>; - AddressU = CLAMP; - AddressV = CLAMP; - MipFilter = LINEAR; - MinFilter = POINT; - MagFilter = POINT; - }; +texture2D g_Texture; +texture2D g_KernelTexture; +float2 g_StepXY_P0; +float2 g_StepXY_P1; +float g_viewportWidth; +float g_viewportHeight; -struct VS_OUTPUT +SamplerState RGBSampler : IMMUTABLE +{ + AddressU = CLAMP; + AddressV = CLAMP; + Filter = MIN_MAG_POINT_MIP_LINEAR; +}; + +SamplerState KernelSampler : IMMUTABLE +{ + AddressU = CLAMP; + AddressV = CLAMP; + Filter = MIN_MAG_MIP_LINEAR; +}; + +struct VS_INPUT { float4 Position : POSITION; float2 TextureUV : TEXCOORD0; }; -struct PS_OUTPUT +struct VS_OUTPUT { - float4 RGBColor : COLOR0; + float4 Position : SV_POSITION; + float2 TextureUV : TEXCOORD0; }; -half4 weight(float pos) +// +// VS for rendering in screen space +// +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.z = output.Position.z; + output.Position.w = 1.0; + output.TextureUV = In.TextureUV; + + return output; +} + +inline half4 weight(float pos) { - half4 w; #ifdef HAS_RGBA - w = tex1D(KernelSampler, pos); + half4 w = g_KernelTexture.Sample(KernelSampler, pos); #else - w = tex1D(KernelSampler, pos).bgra; + half4 w = g_KernelTexture.Sample(KernelSampler, pos).bgra; #endif -#ifdef HAS_FLOAT_TEXTURE - return w; -#else - return w * 2.0 - 1.0; +#ifndef HAS_FLOAT_TEXTURE + w = w * 2.0 - 1.0; #endif + return w; } -half3 pixel(sampler samp, float xpos, float ypos) +inline half3 pixel(texture2D tex, float xpos, float ypos) { - return tex2D(samp, float2(xpos, ypos)).rgb; + return tex.Sample(RGBSampler, float2(xpos, ypos)).rgb; } // Code for first pass - horizontal -half3 getLine(float ypos, float4 xpos, half4 linetaps) +inline half3 getLine(float ypos, float4 xpos, half4 linetaps) { return - pixel(RGBSampler, xpos.r, ypos) * linetaps.r + - pixel(RGBSampler, xpos.g, ypos) * linetaps.g + - pixel(RGBSampler, xpos.b, ypos) * linetaps.b + - pixel(RGBSampler, xpos.a, ypos) * linetaps.a; + 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; } -PS_OUTPUT CONVOLUTION4x4Horiz(VS_OUTPUT In) +float4 CONVOLUTION4x4Horiz(VS_OUTPUT In) : SV_TARGET { - PS_OUTPUT OUT; - float2 pos = In.TextureUV + g_StepXY_P0 * 0.5; float2 f = frac(pos / g_StepXY_P0); @@ -109,37 +105,30 @@ PS_OUTPUT CONVOLUTION4x4Horiz(VS_OUTPUT In) // kernel generation code made sure taps add up to 1, no need to adjust here. - float2 xystart; - xystart.x = (-1.0 - f.x) * g_StepXY_P0.x + In.TextureUV.x; - xystart.y = In.TextureUV.y; + float xystart = (-1.0 - f.x) * g_StepXY_P0.x + In.TextureUV.x; float4 xpos = float4( - xystart.x, - xystart.x + g_StepXY_P0.x, - xystart.x + g_StepXY_P0.x * 2.0, - xystart.x + g_StepXY_P0.x * 3.0); - - OUT.RGBColor.rgb = getLine(xystart.y, xpos, linetaps); - OUT.RGBColor.a = 1.0; + xystart, + xystart + g_StepXY_P0.x, + xystart + g_StepXY_P0.x * 2.0, + xystart + g_StepXY_P0.x * 3.0); - return OUT; + return float4(getLine(In.TextureUV.y, xpos, linetaps), 1.0f); } // Code for second pass - vertical -half3 getRow(float xpos, float4 ypos, half4 columntaps) +inline half3 getRow(float xpos, float4 ypos, half4 columntaps) { return - pixel(IntermediateSampler, xpos, ypos.r) * columntaps.r + - pixel(IntermediateSampler, xpos, ypos.g) * columntaps.g + - pixel(IntermediateSampler, xpos, ypos.b) * columntaps.b + - pixel(IntermediateSampler, xpos, ypos.a) * columntaps.a; + 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; } -PS_OUTPUT CONVOLUTION4x4Vert(VS_OUTPUT In) +float4 CONVOLUTION4x4Vert(VS_OUTPUT In) : SV_TARGET { - PS_OUTPUT OUT; - float2 pos = In.TextureUV + g_StepXY_P1 * 0.5; float2 f = frac(pos / g_StepXY_P1); @@ -147,37 +136,28 @@ PS_OUTPUT CONVOLUTION4x4Vert(VS_OUTPUT In) // kernel generation code made sure taps add up to 1, no need to adjust here. - float2 xystart; - xystart.x = In.TextureUV.x; - xystart.y = (-1.0 - f.y) * g_StepXY_P1.y + In.TextureUV.y; + float xystart = (-1.0 - f.y) * g_StepXY_P1.y + In.TextureUV.y; float4 ypos = float4( - xystart.y, - xystart.y + g_StepXY_P1.y, - xystart.y + g_StepXY_P1.y * 2.0, - xystart.y + g_StepXY_P1.y * 3.0); - - OUT.RGBColor.rgb = getRow(xystart.x, ypos, columntaps); - OUT.RGBColor.a = 1.0; + xystart, + xystart + g_StepXY_P1.y, + xystart + g_StepXY_P1.y * 2.0, + xystart + g_StepXY_P1.y * 3.0); - return OUT; + return float4(getRow(In.TextureUV.x, ypos, columntaps), 1.0f); } -technique SCALER_T +technique10 SCALER_T { pass P0 { - PixelShader = compile ps_3_0 CONVOLUTION4x4Horiz(); - ZEnable = False; - FillMode = Solid; - FogEnable = False; + SetVertexShader( CompileShader( vs_4_0_level_9_3, VS() ) ); + SetPixelShader( CompileShader( ps_4_0_level_9_3, CONVOLUTION4x4Horiz() ) ); } pass P1 { - PixelShader = compile ps_3_0 CONVOLUTION4x4Vert(); - ZEnable = False; - FillMode = Solid; - FogEnable = False; + SetVertexShader( CompileShader( vs_4_0_level_9_3, VS() ) ); + SetPixelShader( CompileShader( ps_4_0_level_9_3, CONVOLUTION4x4Vert() ) ); } }; diff --git a/system/shaders/convolutionsep-6x6_d3d.fx b/system/shaders/convolutionsep-6x6_d3d.fx index db106e62e8..9a5f27f8d3 100644 --- a/system/shaders/convolutionsep-6x6_d3d.fx +++ b/system/shaders/convolutionsep-6x6_d3d.fx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2013 Team XBMC + * Copyright (C) 2005-2015 Team XBMC * http://xbmc.org * * This Program is free software; you can redistribute it and/or modify @@ -18,92 +18,87 @@ * */ -texture g_Texture; -texture g_KernelTexture; -texture g_IntermediateTexture; -float2 g_StepXY_P0; -float2 g_StepXY_P1; - -sampler RGBSampler = - sampler_state { - Texture = <g_Texture>; - AddressU = CLAMP; - AddressV = CLAMP; - MipFilter = LINEAR; - MinFilter = POINT; - MagFilter = POINT; - }; - -sampler KernelSampler = - sampler_state - { - Texture = <g_KernelTexture>; - AddressU = CLAMP; - AddressV = CLAMP; - MipFilter = LINEAR; - MinFilter = LINEAR; - MagFilter = LINEAR; - }; - -sampler IntermediateSampler = - sampler_state { - Texture = <g_IntermediateTexture>; - AddressU = CLAMP; - AddressV = CLAMP; - MipFilter = LINEAR; - MinFilter = POINT; - MagFilter = POINT; - }; +texture2D g_Texture; +texture2D g_KernelTexture; +float2 g_StepXY_P0; +float2 g_StepXY_P1; +float g_viewportWidth; +float g_viewportHeight; -struct VS_OUTPUT +SamplerState RGBSampler : IMMUTABLE +{ + AddressU = CLAMP; + AddressV = CLAMP; + Filter = MIN_MAG_POINT_MIP_LINEAR; +}; + +SamplerState KernelSampler : IMMUTABLE +{ + AddressU = CLAMP; + AddressV = CLAMP; + Filter = MIN_MAG_MIP_LINEAR; +}; + +struct VS_INPUT { float4 Position : POSITION; float2 TextureUV : TEXCOORD0; }; -struct PS_OUTPUT +struct VS_OUTPUT { - float4 RGBColor : COLOR0; + float4 Position : SV_POSITION; + float2 TextureUV : TEXCOORD0; }; -half3 weight(float pos) +// +// VS for rendering in screen space +// +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.z = output.Position.z; + output.Position.w = 1.0; + output.TextureUV = In.TextureUV; + + return output; +} + +inline half3 weight(float pos) { - half3 w; #ifdef HAS_RGBA - w = tex1D(KernelSampler, pos).rgb; + half3 w = g_KernelTexture.Sample(KernelSampler, pos).rgb; #else - w = tex1D(KernelSampler, pos).bgr; + half3 w = g_KernelTexture.Sample(KernelSampler, pos).bgr; #endif -#ifdef HAS_FLOAT_TEXTURE - return w; -#else - return w * 2.0 - 1.0; +#ifndef HAS_FLOAT_TEXTURE + w = w * 2.0 - 1.0; #endif + return w; } -half3 pixel(sampler samp, float xpos, float ypos) +inline half3 pixel(texture2D tex, float xpos, float ypos) { - return tex2D(samp, float2(xpos, ypos)).rgb; + return tex.Sample(RGBSampler, float2(xpos, ypos)).rgb; } -// Code for first pass - horizontal - half3 getLine(float ypos, float3 xpos1, float3 xpos2, half3 linetaps1, half3 linetaps2) { return - pixel(RGBSampler, xpos1.r, ypos) * linetaps1.r + - pixel(RGBSampler, xpos1.g, ypos) * linetaps2.r + - pixel(RGBSampler, xpos1.b, ypos) * linetaps1.g + - pixel(RGBSampler, xpos2.r, ypos) * linetaps2.g + - pixel(RGBSampler, xpos2.g, ypos) * linetaps1.b + - pixel(RGBSampler, xpos2.b, ypos) * linetaps2.b; + 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; } -PS_OUTPUT CONVOLUTION6x6Horiz(VS_OUTPUT In) +// Code for first pass - horizontal +float4 CONVOLUTION6x6Horiz(VS_OUTPUT In) : SV_TARGET { - PS_OUTPUT OUT; - float2 pos = In.TextureUV + g_StepXY_P0 * 0.5; float2 f = frac(pos / g_StepXY_P0); @@ -112,23 +107,18 @@ PS_OUTPUT CONVOLUTION6x6Horiz(VS_OUTPUT In) // kernel generation code made sure taps add up to 1, no need to adjust here. - float2 xystart; - xystart.x = (-2.0 - f.x) * g_StepXY_P0.x + In.TextureUV.x; - xystart.y = In.TextureUV.y; + float xstart = (-2.0 - f.x) * g_StepXY_P0.x + In.TextureUV.x; float3 xpos1 = float3( - xystart.x, - xystart.x + g_StepXY_P0.x, - xystart.x + g_StepXY_P0.x * 2.0); + xstart, + xstart + g_StepXY_P0.x, + xstart + g_StepXY_P0.x * 2.0); float3 xpos2 = half3( - xystart.x + g_StepXY_P0.x * 3.0, - xystart.x + g_StepXY_P0.x * 4.0, - xystart.x + g_StepXY_P0.x * 5.0); - - OUT.RGBColor.rgb = getLine(xystart.y, xpos1, xpos2, linetaps1, linetaps2); - OUT.RGBColor.a = 1.0; + xstart + g_StepXY_P0.x * 3.0, + xstart + g_StepXY_P0.x * 4.0, + xstart + g_StepXY_P0.x * 5.0); - return OUT; + return float4(getLine(In.TextureUV.y, xpos1, xpos2, linetaps1, linetaps2), 1.0); } // Code for second pass - vertical @@ -136,18 +126,16 @@ PS_OUTPUT CONVOLUTION6x6Horiz(VS_OUTPUT In) half3 getRow(float xpos, float3 ypos1, float3 ypos2, half3 columntaps1, half3 columntaps2) { return - pixel(IntermediateSampler, xpos, ypos1.r) * columntaps1.r + - pixel(IntermediateSampler, xpos, ypos1.g) * columntaps2.r + - pixel(IntermediateSampler, xpos, ypos1.b) * columntaps1.g + - pixel(IntermediateSampler, xpos, ypos2.r) * columntaps2.g + - pixel(IntermediateSampler, xpos, ypos2.g) * columntaps1.b + - pixel(IntermediateSampler, xpos, ypos2.b) * columntaps2.b; + 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; } -PS_OUTPUT CONVOLUTION6x6Vert(VS_OUTPUT In) +float4 CONVOLUTION6x6Vert(VS_OUTPUT In) : SV_TARGET { - PS_OUTPUT OUT; - float2 pos = In.TextureUV + g_StepXY_P1 * 0.5; float2 f = frac(pos / g_StepXY_P1); @@ -156,39 +144,30 @@ PS_OUTPUT CONVOLUTION6x6Vert(VS_OUTPUT In) // kernel generation code made sure taps add up to 1, no need to adjust here. - float2 xystart; - xystart.x = In.TextureUV.x; - xystart.y = (-2.0 - f.y) * g_StepXY_P1.y + In.TextureUV.y; + float ystart = (-2.0 - f.y) * g_StepXY_P1.y + In.TextureUV.y; float3 ypos1 = float3( - xystart.y, - xystart.y + g_StepXY_P1.y, - xystart.y + g_StepXY_P1.y * 2.0); + ystart, + ystart + g_StepXY_P1.y, + ystart + g_StepXY_P1.y * 2.0); float3 ypos2 = half3( - xystart.y + g_StepXY_P1.y * 3.0, - xystart.y + g_StepXY_P1.y * 4.0, - xystart.y + g_StepXY_P1.y * 5.0); - - OUT.RGBColor.rgb = getRow(xystart.x, ypos1, ypos2, columntaps1, columntaps2); - OUT.RGBColor.a = 1.0; + ystart + g_StepXY_P1.y * 3.0, + ystart + g_StepXY_P1.y * 4.0, + ystart + g_StepXY_P1.y * 5.0); - return OUT; + return float4(getRow(In.TextureUV.x, ypos1, ypos2, columntaps1, columntaps2), 1.0); } -technique SCALER_T +technique10 SCALER_T { pass P0 { - PixelShader = compile ps_3_0 CONVOLUTION6x6Horiz(); - ZEnable = False; - FillMode = Solid; - FogEnable = False; + SetVertexShader( CompileShader( vs_4_0_level_9_3, VS() ) ); + SetPixelShader( CompileShader( ps_4_0_level_9_3, CONVOLUTION6x6Horiz() ) ); } pass P1 { - PixelShader = compile ps_3_0 CONVOLUTION6x6Vert(); - ZEnable = False; - FillMode = Solid; - FogEnable = False; + SetVertexShader( CompileShader( vs_4_0_level_9_3, VS() ) ); + SetPixelShader( CompileShader( ps_4_0_level_9_3, CONVOLUTION6x6Vert() ) ); } }; diff --git a/system/shaders/yuv2rgb_d3d.fx b/system/shaders/yuv2rgb_d3d.fx index 133745edd0..7621c60b7e 100644 --- a/system/shaders/yuv2rgb_d3d.fx +++ b/system/shaders/yuv2rgb_d3d.fx @@ -18,41 +18,31 @@ * */ -texture g_YTexture; -texture g_UTexture; -texture g_VTexture; -float4x4 g_ColorMatrix; -float2 g_StepXY; +texture2D g_YTexture; +texture2D g_UTexture; +texture2D g_VTexture; +float4x4 g_ColorMatrix; +float2 g_StepXY; +float g_viewportWidth; +float g_viewportHeight; -sampler YSampler = - sampler_state { - Texture = <g_YTexture>; - AddressU = CLAMP; - AddressV = CLAMP; - MinFilter = LINEAR; - MagFilter = LINEAR; - }; -sampler USampler = - sampler_state { - Texture = <g_UTexture>; - AddressU = CLAMP; - AddressV = CLAMP; - MinFilter = LINEAR; - MagFilter = LINEAR; - }; - -sampler VSampler = - sampler_state - { - Texture = <g_VTexture>; - AddressU = CLAMP; - AddressV = CLAMP; - MinFilter = LINEAR; - MagFilter = LINEAR; - }; +SamplerState YUVSampler : IMMUTABLE +{ + AddressU = CLAMP; + AddressV = CLAMP; + Filter = MIN_MAG_MIP_LINEAR; +}; +#ifdef NV12_SNORM_UV +SamplerState UVSamplerSNORM : IMMUTABLE +{ + AddressU = CLAMP; + AddressV = CLAMP; + Filter = MIN_MAG_MIP_POINT; +}; +#endif -struct VS_OUTPUT +struct VS_INPUT { float4 Position : POSITION; float2 TextureY : TEXCOORD0; @@ -60,22 +50,55 @@ struct VS_OUTPUT float2 TextureV : TEXCOORD2; }; -struct PS_OUTPUT +struct VS_OUTPUT { - float4 RGBColor : COLOR0; + float4 Position : SV_POSITION; + float2 TextureY : TEXCOORD0; + float2 TextureU : TEXCOORD1; + float2 TextureV : TEXCOORD2; }; -PS_OUTPUT YUV2RGB( VS_OUTPUT In) +VS_OUTPUT VS(VS_INPUT In) { - PS_OUTPUT OUT; -#if defined(XBMC_YV12) - float4 YUV = float4(tex2D (YSampler, In.TextureY).x - , tex2D (USampler, In.TextureU).x - , tex2D (VSampler, In.TextureV).x + 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.z = output.Position.z; + output.Position.w = 1.0; + output.TextureY = In.TextureY; + output.TextureU = In.TextureU; + output.TextureV = In.TextureV; + + return output; +} + +#ifdef NV12_SNORM_UV +inline float unormU(float c) +{ + c *= 0.5; + if (c < 0.0) c += 1.0; + return saturate(c); +} +inline float2 unormUV(float2 rg) +{ + return float2(unormU(rg.x), unormU(rg.y)); +} +#endif + +float4 YUV2RGB(VS_OUTPUT In) : SV_TARGET +{ +#if defined(XBMC_YV12) //|| defined(XBMC_NV12) + float4 YUV = float4(g_YTexture.Sample(YUVSampler, In.TextureY).r + , g_UTexture.Sample(YUVSampler, In.TextureU).r + , g_VTexture.Sample(YUVSampler, In.TextureV).r , 1.0); #elif defined(XBMC_NV12) - float4 YUV = float4(tex2D (YSampler, In.TextureY).x - , tex2D (USampler, In.TextureU).ra + float4 YUV = float4(g_YTexture.Sample(YUVSampler, In.TextureY).r + #if defined(NV12_SNORM_UV) + , unormUV(g_UTexture.Sample(UVSamplerSNORM, In.TextureU).rg) + #else + , g_UTexture.Sample(YUVSampler, In.TextureU).rg + #endif , 1.0); #elif defined(XBMC_YUY2) || defined(XBMC_UYVY) // The HLSL compiler is smart enough to optimize away these redundant assignments. @@ -87,8 +110,8 @@ PS_OUTPUT YUV2RGB( VS_OUTPUT In) //y axis will be correctly interpolated by opengl //x axis will not, so we grab two pixels at the center of two columns and interpolate ourselves - float4 c1 = tex2D(YSampler, float2(pos.x + ((0.5 - f.x) * stepxy.x), pos.y)); - float4 c2 = tex2D(YSampler, float2(pos.x + ((1.5 - f.x) * stepxy.x), pos.y)); + float4 c1 = g_YTexture.Sample(YUVSampler, float2(pos.x + ((0.5 - f.x) * stepxy.x), pos.y)); + float4 c2 = g_YTexture.Sample(YUVSampler, float2(pos.x + ((1.5 - f.x) * stepxy.x), pos.y)); /* each pixel has two Y subpixels and one UV subpixel YUV Y YUV @@ -106,18 +129,15 @@ PS_OUTPUT YUV2RGB( VS_OUTPUT In) float4 YUV = float4(outY, outUV, 1.0); #endif - OUT.RGBColor = mul(YUV, g_ColorMatrix); - OUT.RGBColor.a = 1.0; - return OUT; + return float4(mul(YUV, g_ColorMatrix).rgb, 1.0); } -technique YUV2RGB_T +technique10 YUV2RGB_T { pass P0 { - PixelShader = compile ps_2_0 YUV2RGB(); - ZEnable = False; - FillMode = Solid; - FogEnable = False; + SetVertexShader( CompileShader( vs_4_0_level_9_1, VS() ) ); + SetGeometryShader( NULL ); + SetPixelShader( CompileShader( ps_4_0_level_9_1, YUV2RGB() ) ); } }; |