diff --git a/app/shaders/d3d11_ayuv_pixel.fxc b/app/shaders/d3d11_ayuv_pixel.fxc index 5fdf17a9..0c1033a5 100644 Binary files a/app/shaders/d3d11_ayuv_pixel.fxc and b/app/shaders/d3d11_ayuv_pixel.fxc differ diff --git a/app/shaders/d3d11_y410_pixel.fxc b/app/shaders/d3d11_y410_pixel.fxc index d12d690d..9a020b17 100644 Binary files a/app/shaders/d3d11_y410_pixel.fxc and b/app/shaders/d3d11_y410_pixel.fxc differ diff --git a/app/shaders/d3d11_yuv420_pixel.fxc b/app/shaders/d3d11_yuv420_pixel.fxc index 4285c1a9..793c1c27 100644 Binary files a/app/shaders/d3d11_yuv420_pixel.fxc and b/app/shaders/d3d11_yuv420_pixel.fxc differ diff --git a/app/shaders/d3d11_yuv420_pixel.hlsl b/app/shaders/d3d11_yuv420_pixel.hlsl index 9b68b400..487a1f08 100644 --- a/app/shaders/d3d11_yuv420_pixel.hlsl +++ b/app/shaders/d3d11_yuv420_pixel.hlsl @@ -8,16 +8,12 @@ struct ShaderInput float2 tex : TEXCOORD0; }; -cbuffer ChromaLimitBuf : register(b0) -{ - min16float3 chromaTexMax; -}; - -cbuffer CSC_CONST_BUF : register(b1) +cbuffer CSC_CONST_BUF : register(b0) { min16float3x3 cscMatrix; min16float3 offsets; min16float2 chromaOffset; + min16float2 chromaTexMax; }; min16float4 main(ShaderInput input) : SV_TARGET diff --git a/app/shaders/d3d11_yuv444_pixel_end.hlsli b/app/shaders/d3d11_yuv444_pixel_end.hlsli index 163109ce..961c01a9 100644 --- a/app/shaders/d3d11_yuv444_pixel_end.hlsli +++ b/app/shaders/d3d11_yuv444_pixel_end.hlsli @@ -1,7 +1,6 @@ min16float4 main(ShaderInput input) : SV_TARGET { - // Clamp the texcoords to avoid sampling the row of texels adjacent to the alignment padding - min16float3 yuv = swizzle(videoTex.Sample(theSampler, min(input.tex, chromaTexMax.rg))); + min16float3 yuv = swizzle(videoTex.Sample(theSampler, input.tex)); // Subtract the YUV offset for limited vs full range yuv -= offsets; diff --git a/app/shaders/d3d11_yuv444_pixel_start.hlsli b/app/shaders/d3d11_yuv444_pixel_start.hlsli index 5697526c..a34e00b3 100644 --- a/app/shaders/d3d11_yuv444_pixel_start.hlsli +++ b/app/shaders/d3d11_yuv444_pixel_start.hlsli @@ -7,14 +7,10 @@ struct ShaderInput float2 tex : TEXCOORD0; }; -cbuffer ChromaLimitBuf : register(b0) -{ - min16float3 chromaTexMax; -}; - -cbuffer CSC_CONST_BUF : register(b1) +cbuffer CSC_CONST_BUF : register(b0) { min16float3x3 cscMatrix; min16float3 offsets; min16float2 chromaOffset; // Unused for 4:4:4 + min16float2 chromaTexMax; // Unused for 4:4:4 }; \ No newline at end of file diff --git a/app/streaming/video/ffmpeg-renderers/d3d11va.cpp b/app/streaming/video/ffmpeg-renderers/d3d11va.cpp index 773ec023..c8401c23 100644 --- a/app/streaming/video/ffmpeg-renderers/d3d11va.cpp +++ b/app/streaming/video/ffmpeg-renderers/d3d11va.cpp @@ -43,8 +43,8 @@ typedef struct _CSC_CONST_BUF // Chroma offset values float chromaOffset[2]; - // Padding to final 16-byte boundary - float padding2[2]; + // Max UV coordinates to avoid sampling alignment padding + float chromaUVMax[2]; } CSC_CONST_BUF, *PCSC_CONST_BUF; static_assert(sizeof(CSC_CONST_BUF) % 16 == 0, "Constant buffer sizes must be a multiple of 16"); @@ -740,13 +740,19 @@ void D3D11VARenderer::bindColorConversion(AVFrame* frame) constBuf.chromaOffset[0] = chromaOffset[0] / m_TextureWidth; constBuf.chromaOffset[1] = chromaOffset[1] / m_TextureHeight; + // Limit chroma texcoords to avoid sampling from alignment texels + constBuf.chromaUVMax[0] = m_DecoderParams.width != (int)m_TextureWidth ? + ((float)(m_DecoderParams.width - 1) / m_TextureWidth) : 1.0f; + constBuf.chromaUVMax[1] = m_DecoderParams.height != (int)m_TextureHeight ? + ((float)(m_DecoderParams.height - 1) / m_TextureHeight) : 1.0f; + D3D11_SUBRESOURCE_DATA constData = {}; constData.pSysMem = &constBuf; ComPtr constantBuffer; HRESULT hr = m_Device->CreateBuffer(&constDesc, &constData, &constantBuffer); if (SUCCEEDED(hr)) { - m_DeviceContext->PSSetConstantBuffers(1, 1, constantBuffer.GetAddressOf()); + m_DeviceContext->PSSetConstantBuffers(0, 1, constantBuffer.GetAddressOf()); } else { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, @@ -1371,35 +1377,6 @@ bool D3D11VARenderer::setupRenderingResources() } } - // Create our fixed constant buffer to limit chroma texcoords and avoid sampling from alignment texels. - { - D3D11_BUFFER_DESC constDesc = {}; - constDesc.ByteWidth = sizeof(CSC_CONST_BUF); - constDesc.Usage = D3D11_USAGE_IMMUTABLE; - constDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER; - constDesc.CPUAccessFlags = 0; - constDesc.MiscFlags = 0; - - float chromaUVMax[3] = {}; - chromaUVMax[0] = m_DecoderParams.width != (int)m_TextureWidth ? ((float)(m_DecoderParams.width - 1) / m_TextureWidth) : 1.0f; - chromaUVMax[1] = m_DecoderParams.height != (int)m_TextureHeight ? ((float)(m_DecoderParams.height - 1) / m_TextureHeight) : 1.0f; - - D3D11_SUBRESOURCE_DATA constData = {}; - constData.pSysMem = chromaUVMax; - - ComPtr constantBuffer; - HRESULT hr = m_Device->CreateBuffer(&constDesc, &constData, &constantBuffer); - if (SUCCEEDED(hr)) { - m_DeviceContext->PSSetConstantBuffers(0, 1, constantBuffer.GetAddressOf()); - } - else { - SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, - "ID3D11Device::CreateBuffer() failed: %x", - hr); - return false; - } - } - // Create our blend state { D3D11_BLEND_DESC blendDesc = {};