Handle chroma co-siting in the Metal shaders

This commit is contained in:
Cameron Gutman
2025-11-01 21:57:13 -05:00
parent 2c12ad297f
commit 9b3050514b
2 changed files with 47 additions and 3 deletions
+10 -3
View File
@@ -10,6 +10,7 @@ struct CscParams
{
float3 matrix[3];
float3 offsets;
float2 chromaOffset;
float bitnessScaleFactor;
};
@@ -25,8 +26,10 @@ fragment float4 ps_draw_biplanar(Vertex v [[ stage_in ]],
texture2d<float> luminancePlane [[ texture(0) ]],
texture2d<float> chrominancePlane [[ texture(1) ]])
{
float2 chromaOffset = float2(cscParams.chromaOffset.x / chrominancePlane.get_width(),
cscParams.chromaOffset.y / chrominancePlane.get_height());
float3 yuv = float3(luminancePlane.sample(s, v.texCoords).r,
chrominancePlane.sample(s, v.texCoords).rg);
chrominancePlane.sample(s, v.texCoords + chromaOffset).rg);
yuv *= cscParams.bitnessScaleFactor;
yuv -= cscParams.offsets;
@@ -43,9 +46,13 @@ fragment float4 ps_draw_triplanar(Vertex v [[ stage_in ]],
texture2d<float> chrominancePlaneU [[ texture(1) ]],
texture2d<float> chrominancePlaneV [[ texture(2) ]])
{
float2 chromaOffsetU = float2(cscParams.chromaOffset.x / chrominancePlaneU.get_width(),
cscParams.chromaOffset.y / chrominancePlaneU.get_height());
float2 chromaOffsetV = float2(cscParams.chromaOffset.x / chrominancePlaneV.get_width(),
cscParams.chromaOffset.y / chrominancePlaneV.get_height());
float3 yuv = float3(luminancePlane.sample(s, v.texCoords).r,
chrominancePlaneU.sample(s, v.texCoords).r,
chrominancePlaneV.sample(s, v.texCoords).r);
chrominancePlaneU.sample(s, v.texCoords + chromaOffsetU).r,
chrominancePlaneV.sample(s, v.texCoords + chromaOffsetV).r);
yuv *= cscParams.bitnessScaleFactor;
yuv -= cscParams.offsets;