Refactor D3D11 shaders to reduce duplicated code

This commit is contained in:
Cameron Gutman 2022-02-16 19:38:18 -06:00
parent b1f980c216
commit 36db791516
9 changed files with 25 additions and 63 deletions

View File

@ -61,7 +61,7 @@
<file alias="egl_overlay.vert">shaders/egl_overlay.vert</file>
<file alias="d3d11_vertex.fxc">shaders/d3d11_vertex.fxc</file>
<file alias="d3d11_overlay_pixel.fxc">shaders/d3d11_overlay_pixel.fxc</file>
<file alias="d3d11_video_pixel.fxc">shaders/d3d11_video_pixel.fxc</file>
<file alias="d3d11_genyuv_pixel.fxc">shaders/d3d11_genyuv_pixel.fxc</file>
<file alias="d3d11_bt601lim_pixel.fxc">shaders/d3d11_bt601lim_pixel.fxc</file>
<file alias="d3d11_bt2020lim_pixel.fxc">shaders/d3d11_bt2020lim_pixel.fxc</file>
</qresource>

View File

@ -1,6 +1,6 @@
fxc /T vs_4_0_level_9_3 /Fo d3d11_vertex.fxc d3d11_vertex.hlsl
fxc /T ps_4_0_level_9_3 /Fo d3d11_overlay_pixel.fxc d3d11_overlay_pixel.hlsl
fxc /T ps_4_0_level_9_3 /Fo d3d11_video_pixel.fxc d3d11_video_pixel.hlsl
fxc /T ps_4_0_level_9_3 /Fo d3d11_genyuv_pixel.fxc d3d11_genyuv_pixel.hlsl
fxc /T ps_4_0_level_9_3 /Fo d3d11_bt601lim_pixel.fxc d3d11_bt601lim_pixel.hlsl
fxc /T ps_4_0_level_9_3 /Fo d3d11_bt2020lim_pixel.fxc d3d11_bt2020lim_pixel.hlsl

View File

@ -1,6 +1,4 @@
Texture2D<min16float> luminancePlane : register(t0);
Texture2D<min16float2> chrominancePlane : register(t1);
SamplerState theSampler : register(s0);
#include "d3d11_video_pixel_start.hlsli"
static const min16float3x3 cscMatrix =
{
@ -14,22 +12,4 @@ static const min16float3 offsets =
16.0 / 255.0, 128.0 / 255.0, 128.0 / 255.0
};
struct ShaderInput
{
float4 pos : SV_POSITION;
float2 tex : TEXCOORD0;
};
min16float4 main(ShaderInput input) : SV_TARGET
{
min16float3 yuv = min16float3(luminancePlane.Sample(theSampler, input.tex),
chrominancePlane.Sample(theSampler, input.tex));
// Subtract the YUV offset for limited vs full range
yuv -= offsets;
// Multiply by the conversion matrix for this colorspace
yuv = mul(yuv, cscMatrix);
return min16float4(yuv, 1.0);
}
#include "d3d11_video_pixel_end.hlsli"

View File

@ -1,6 +1,4 @@
Texture2D<min16float> luminancePlane : register(t0);
Texture2D<min16float2> chrominancePlane : register(t1);
SamplerState theSampler : register(s0);
#include "d3d11_video_pixel_start.hlsli"
static const min16float3x3 cscMatrix =
{
@ -14,22 +12,4 @@ static const min16float3 offsets =
16.0 / 255.0, 128.0 / 255.0, 128.0 / 255.0
};
struct ShaderInput
{
float4 pos : SV_POSITION;
float2 tex : TEXCOORD0;
};
min16float4 main(ShaderInput input) : SV_TARGET
{
min16float3 yuv = min16float3(luminancePlane.Sample(theSampler, input.tex),
chrominancePlane.Sample(theSampler, input.tex));
// Subtract the YUV offset for limited vs full range
yuv -= offsets;
// Multiply by the conversion matrix for this colorspace
yuv = mul(yuv, cscMatrix);
return min16float4(yuv, 1.0);
}
#include "d3d11_video_pixel_end.hlsli"

View File

@ -0,0 +1,9 @@
#include "d3d11_video_pixel_start.hlsli"
cbuffer CSC_CONST_BUF : register(b0)
{
min16float3x3 cscMatrix;
min16float3 offsets;
};
#include "d3d11_video_pixel_end.hlsli"

View File

@ -1,19 +1,3 @@
Texture2D<min16float> luminancePlane : register(t0);
Texture2D<min16float2> chrominancePlane : register(t1);
SamplerState theSampler : register(s0);
cbuffer CSC_CONST_BUF : register(b0)
{
min16float3x3 cscMatrix;
min16float3 offsets;
};
struct ShaderInput
{
float4 pos : SV_POSITION;
float2 tex : TEXCOORD0;
};
min16float4 main(ShaderInput input) : SV_TARGET
{
min16float3 yuv = min16float3(luminancePlane.Sample(theSampler, input.tex),

View File

@ -0,0 +1,9 @@
Texture2D<min16float> luminancePlane : register(t0);
Texture2D<min16float2> chrominancePlane : register(t1);
SamplerState theSampler : register(s0);
struct ShaderInput
{
float4 pos : SV_POSITION;
float2 tex : TEXCOORD0;
};

View File

@ -1158,7 +1158,7 @@ bool D3D11VARenderer::setupRenderingResources()
}
{
QByteArray videoPixelShaderBytecode = Path::readDataFile("d3d11_video_pixel.fxc");
QByteArray videoPixelShaderBytecode = Path::readDataFile("d3d11_genyuv_pixel.fxc");
hr = m_Device->CreatePixelShader(videoPixelShaderBytecode.constData(), videoPixelShaderBytecode.length(), nullptr, &m_VideoGenericPixelShader);
if (FAILED(hr)) {