Browse Source

Use a more concise representation of YUV -> RGB conversion

Sam Lantinga 1 year ago
parent
commit
985da79d73

+ 5 - 19
src/render/metal/SDL_shaders_metal.metal

@@ -162,9 +162,7 @@ fragment float4 SDL_Copy_fragment(CopyVertexOutput vert [[stage_in]],
 struct YUVDecode
 {
     float3 offset;
-    float3 Rcoeff;
-    float3 Gcoeff;
-    float3 Bcoeff;
+    float3x3 matrix;
 };
 
 fragment float4 SDL_YUV_fragment(CopyVertexOutput vert [[stage_in]],
@@ -180,10 +178,7 @@ fragment float4 SDL_YUV_fragment(CopyVertexOutput vert [[stage_in]],
     yuv.z = texUV.sample(s, vert.texcoord, 1).r;
 
     float3 rgb;
-    yuv += decode.offset;
-    rgb.r = dot(yuv, decode.Rcoeff);
-    rgb.g = dot(yuv, decode.Gcoeff);
-    rgb.b = dot(yuv, decode.Bcoeff);
+    rgb = (yuv + decode.offset) * decode.matrix;
 
     return GetOutputColorFromSRGB(rgb, c.scRGB_output, c.color_scale) * vert.color;
 }
@@ -200,10 +195,7 @@ fragment float4 SDL_NV12_fragment(CopyVertexOutput vert [[stage_in]],
     yuv.yz = texUV.sample(s, vert.texcoord).rg;
 
     float3 rgb;
-    yuv += decode.offset;
-    rgb.r = dot(yuv, decode.Rcoeff);
-    rgb.g = dot(yuv, decode.Gcoeff);
-    rgb.b = dot(yuv, decode.Bcoeff);
+    rgb = (yuv + decode.offset) * decode.matrix;
 
     return GetOutputColorFromSRGB(rgb, c.scRGB_output, c.color_scale) * vert.color;
 }
@@ -220,10 +212,7 @@ fragment float4 SDL_NV21_fragment(CopyVertexOutput vert [[stage_in]],
     yuv.yz = texUV.sample(s, vert.texcoord).gr;
 
     float3 rgb;
-    yuv += decode.offset;
-    rgb.r = dot(yuv, decode.Rcoeff);
-    rgb.g = dot(yuv, decode.Gcoeff);
-    rgb.b = dot(yuv, decode.Bcoeff);
+    rgb = (yuv + decode.offset) * decode.matrix;
 
     return GetOutputColorFromSRGB(rgb, c.scRGB_output, c.color_scale) * vert.color;
 }
@@ -246,10 +235,7 @@ fragment float4 SDL_HDR10_fragment(CopyVertexOutput vert [[stage_in]],
     yuv.yz = texUV.sample(s, vert.texcoord).rg;
 
     float3 rgb;
-    yuv += decode.offset;
-    rgb.r = dot(yuv, decode.Rcoeff);
-    rgb.g = dot(yuv, decode.Gcoeff);
-    rgb.b = dot(yuv, decode.Bcoeff);
+    rgb = (yuv + decode.offset) * decode.matrix;
 
     rgb = PQtoNits(rgb);
 

File diff suppressed because it is too large
+ 401 - 747
src/render/metal/SDL_shaders_metal_ios.h


File diff suppressed because it is too large
+ 631 - 1040
src/render/metal/SDL_shaders_metal_iphonesimulator.h


File diff suppressed because it is too large
+ 328 - 658
src/render/metal/SDL_shaders_metal_macos.h


File diff suppressed because it is too large
+ 401 - 747
src/render/metal/SDL_shaders_metal_tvos.h


File diff suppressed because it is too large
+ 61 - 894
src/render/metal/SDL_shaders_metal_tvsimulator.h


Some files were not shown because too many files changed in this diff