Skip Gamma and Gamut conversions for BT.709->SRGB

This introduces a new field 'doYuvToRgbConversionOnly' in
ExternalTextureParams to have the WGSL only do yuv->rgb conversion for
better performance. User studies shows that users don't really care
about the Gamma difference between 2.4 and 2.2.
https://source.chromium.org/chromium/chromium/src/+/main:ui/gfx/color_space.cc;l=1022;drc=a1dbb594a6741a400db35fe3678e77bad2504ea4

Bug: dawn:1082
Bug: dawn:1466
Change-Id: I61c0fe65c5969d8a61c267c202c8dd64c259ed8a
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/92901
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Jie A Chen <jie.a.chen@intel.com>
This commit is contained in:
jchen10
2022-06-22 03:14:26 +00:00
committed by Dawn LUCI CQ
parent 797f0f82e0
commit ef62b58cf9
27 changed files with 586 additions and 413 deletions

View File

@@ -10,6 +10,7 @@ struct GammaTransferParams {
};
struct ExternalTextureParams {
uint numPlanes;
uint doYuvToRgbConversionOnly;
float3x4 yuvToRgbConversionMatrix;
GammaTransferParams gammaDecodeParams;
GammaTransferParams gammaEncodeParams;
@@ -37,9 +38,11 @@ float4 textureSampleExternal(Texture2D<float4> plane0, Texture2D<float4> plane1,
} else {
color = mul(params.yuvToRgbConversionMatrix, float4(plane0.SampleLevel(smp, coord, 0.0f).r, plane1.SampleLevel(smp, coord, 0.0f).rg, 1.0f));
}
color = gammaCorrection(color, params.gammaDecodeParams);
color = mul(color, params.gamutConversionMatrix);
color = gammaCorrection(color, params.gammaEncodeParams);
if ((params.doYuvToRgbConversionOnly == 0u)) {
color = gammaCorrection(color, params.gammaDecodeParams);
color = mul(color, params.gamutConversionMatrix);
color = gammaCorrection(color, params.gammaEncodeParams);
}
return float4(color, 1.0f);
}
@@ -72,7 +75,8 @@ float3x3 tint_symbol_7(uint4 buffer[11], uint offset) {
ExternalTextureParams tint_symbol_1(uint4 buffer[11], uint offset) {
const uint scalar_offset_14 = ((offset + 0u)) / 4;
const ExternalTextureParams tint_symbol_10 = {buffer[scalar_offset_14 / 4][scalar_offset_14 % 4], tint_symbol_3(buffer, (offset + 16u)), tint_symbol_5(buffer, (offset + 64u)), tint_symbol_5(buffer, (offset + 96u)), tint_symbol_7(buffer, (offset + 128u))};
const uint scalar_offset_15 = ((offset + 4u)) / 4;
const ExternalTextureParams tint_symbol_10 = {buffer[scalar_offset_14 / 4][scalar_offset_14 % 4], buffer[scalar_offset_15 / 4][scalar_offset_15 % 4], tint_symbol_3(buffer, (offset + 16u)), tint_symbol_5(buffer, (offset + 64u)), tint_symbol_5(buffer, (offset + 96u)), tint_symbol_7(buffer, (offset + 128u))};
return tint_symbol_10;
}

View File

@@ -14,7 +14,8 @@ struct GammaTransferParams {
struct ExternalTextureParams {
/* 0x0000 */ uint numPlanes;
/* 0x0004 */ int8_t tint_pad[12];
/* 0x0004 */ uint doYuvToRgbConversionOnly;
/* 0x0008 */ int8_t tint_pad[8];
/* 0x0010 */ float3x4 yuvToRgbConversionMatrix;
/* 0x0040 */ GammaTransferParams gammaDecodeParams;
/* 0x0060 */ GammaTransferParams gammaEncodeParams;
@@ -35,9 +36,11 @@ float4 textureSampleExternal(texture2d<float, access::sample> plane0, texture2d<
} else {
color = (float4(plane0.sample(smp, coord, level(0.0f))[0], float4(plane1.sample(smp, coord, level(0.0f))).rg, 1.0f) * params.yuvToRgbConversionMatrix);
}
color = gammaCorrection(color, params.gammaDecodeParams);
color = (params.gamutConversionMatrix * color);
color = gammaCorrection(color, params.gammaEncodeParams);
if ((params.doYuvToRgbConversionOnly == 0u)) {
color = gammaCorrection(color, params.gammaDecodeParams);
color = (params.gamutConversionMatrix * color);
color = gammaCorrection(color, params.gammaEncodeParams);
}
return float4(color, 1.0f);
}

View File

@@ -1,7 +1,7 @@
; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0
; Bound: 135
; Bound: 140
; Schema: 0
OpCapability Shader
%30 = OpExtInstImport "GLSL.std.450"
@@ -16,8 +16,9 @@
OpName %ext_tex_plane_1 "ext_tex_plane_1"
OpName %ExternalTextureParams "ExternalTextureParams"
OpMemberName %ExternalTextureParams 0 "numPlanes"
OpMemberName %ExternalTextureParams 1 "yuvToRgbConversionMatrix"
OpMemberName %ExternalTextureParams 2 "gammaDecodeParams"
OpMemberName %ExternalTextureParams 1 "doYuvToRgbConversionOnly"
OpMemberName %ExternalTextureParams 2 "yuvToRgbConversionMatrix"
OpMemberName %ExternalTextureParams 3 "gammaDecodeParams"
OpName %GammaTransferParams "GammaTransferParams"
OpMemberName %GammaTransferParams 0 "G"
OpMemberName %GammaTransferParams 1 "A"
@@ -27,8 +28,8 @@
OpMemberName %GammaTransferParams 5 "E"
OpMemberName %GammaTransferParams 6 "F"
OpMemberName %GammaTransferParams 7 "padding"
OpMemberName %ExternalTextureParams 3 "gammaEncodeParams"
OpMemberName %ExternalTextureParams 4 "gamutConversionMatrix"
OpMemberName %ExternalTextureParams 4 "gammaEncodeParams"
OpMemberName %ExternalTextureParams 5 "gamutConversionMatrix"
OpName %ext_tex_params "ext_tex_params"
OpName %arg_0 "arg_0"
OpName %arg_1 "arg_1"
@@ -54,10 +55,11 @@
OpDecorate %ext_tex_plane_1 Binding 2
OpDecorate %ExternalTextureParams Block
OpMemberDecorate %ExternalTextureParams 0 Offset 0
OpMemberDecorate %ExternalTextureParams 1 Offset 16
OpMemberDecorate %ExternalTextureParams 1 ColMajor
OpMemberDecorate %ExternalTextureParams 1 MatrixStride 16
OpMemberDecorate %ExternalTextureParams 2 Offset 64
OpMemberDecorate %ExternalTextureParams 1 Offset 4
OpMemberDecorate %ExternalTextureParams 2 Offset 16
OpMemberDecorate %ExternalTextureParams 2 ColMajor
OpMemberDecorate %ExternalTextureParams 2 MatrixStride 16
OpMemberDecorate %ExternalTextureParams 3 Offset 64
OpMemberDecorate %GammaTransferParams 0 Offset 0
OpMemberDecorate %GammaTransferParams 1 Offset 4
OpMemberDecorate %GammaTransferParams 2 Offset 8
@@ -66,10 +68,10 @@
OpMemberDecorate %GammaTransferParams 5 Offset 20
OpMemberDecorate %GammaTransferParams 6 Offset 24
OpMemberDecorate %GammaTransferParams 7 Offset 28
OpMemberDecorate %ExternalTextureParams 3 Offset 96
OpMemberDecorate %ExternalTextureParams 4 Offset 128
OpMemberDecorate %ExternalTextureParams 4 ColMajor
OpMemberDecorate %ExternalTextureParams 4 MatrixStride 16
OpMemberDecorate %ExternalTextureParams 4 Offset 96
OpMemberDecorate %ExternalTextureParams 5 Offset 128
OpMemberDecorate %ExternalTextureParams 5 ColMajor
OpMemberDecorate %ExternalTextureParams 5 MatrixStride 16
OpDecorate %ext_tex_params NonWritable
OpDecorate %ext_tex_params DescriptorSet 1
OpDecorate %ext_tex_params Binding 3
@@ -93,7 +95,7 @@
%GammaTransferParams = OpTypeStruct %float %float %float %float %float %float %float %uint
%v3float = OpTypeVector %float 3
%mat3v3float = OpTypeMatrix %v3float 3
%ExternalTextureParams = OpTypeStruct %uint %mat3v4float %GammaTransferParams %GammaTransferParams %mat3v3float
%ExternalTextureParams = OpTypeStruct %uint %uint %mat3v4float %GammaTransferParams %GammaTransferParams %mat3v3float
%_ptr_Uniform_ExternalTextureParams = OpTypePointer Uniform %ExternalTextureParams
%ext_tex_params = OpVariable %_ptr_Uniform_ExternalTextureParams Uniform
%arg_0 = OpVariable %_ptr_UniformConstant_11 UniformConstant
@@ -110,11 +112,12 @@
%uint_1 = OpConstant %uint 1
%81 = OpTypeSampledImage %11
%float_1 = OpConstant %float 1
%97 = OpConstantNull %uint
%void = OpTypeVoid
%110 = OpTypeFunction %void
%118 = OpConstantNull %v2float
%115 = OpTypeFunction %void
%123 = OpConstantNull %v2float
%_ptr_Function_v4float = OpTypePointer Function %v4float
%122 = OpTypeFunction %v4float
%127 = OpTypeFunction %v4float
%gammaCorrection = OpFunction %v3float None %24
%v = OpFunctionParameter %v3float
%params = OpFunctionParameter %GammaTransferParams
@@ -179,60 +182,67 @@
%90 = OpCompositeExtract %float %89 0
%91 = OpCompositeExtract %float %89 1
%93 = OpCompositeConstruct %v4float %86 %90 %91 %float_1
%94 = OpCompositeExtract %mat3v4float %params_0 1
%94 = OpCompositeExtract %mat3v4float %params_0 2
%95 = OpVectorTimesMatrix %v3float %93 %94
OpStore %color %95
OpBranch %77
%77 = OpLabel
%97 = OpLoad %v3float %color
%98 = OpCompositeExtract %GammaTransferParams %params_0 2
%96 = OpFunctionCall %v3float %gammaCorrection %97 %98
OpStore %color %96
%99 = OpCompositeExtract %mat3v3float %params_0 4
%100 = OpLoad %v3float %color
%101 = OpMatrixTimesVector %v3float %99 %100
%96 = OpCompositeExtract %uint %params_0 1
%98 = OpIEqual %bool %96 %97
OpSelectionMerge %99 None
OpBranchConditional %98 %100 %99
%100 = OpLabel
%102 = OpLoad %v3float %color
%103 = OpCompositeExtract %GammaTransferParams %params_0 3
%101 = OpFunctionCall %v3float %gammaCorrection %102 %103
OpStore %color %101
%103 = OpLoad %v3float %color
%104 = OpCompositeExtract %GammaTransferParams %params_0 3
%102 = OpFunctionCall %v3float %gammaCorrection %103 %104
OpStore %color %102
%104 = OpCompositeExtract %mat3v3float %params_0 5
%105 = OpLoad %v3float %color
%106 = OpCompositeExtract %float %105 0
%107 = OpCompositeExtract %float %105 1
%108 = OpCompositeExtract %float %105 2
%109 = OpCompositeConstruct %v4float %106 %107 %108 %float_1
OpReturnValue %109
%106 = OpMatrixTimesVector %v3float %104 %105
OpStore %color %106
%108 = OpLoad %v3float %color
%109 = OpCompositeExtract %GammaTransferParams %params_0 4
%107 = OpFunctionCall %v3float %gammaCorrection %108 %109
OpStore %color %107
OpBranch %99
%99 = OpLabel
%110 = OpLoad %v3float %color
%111 = OpCompositeExtract %float %110 0
%112 = OpCompositeExtract %float %110 1
%113 = OpCompositeExtract %float %110 2
%114 = OpCompositeConstruct %v4float %111 %112 %113 %float_1
OpReturnValue %114
OpFunctionEnd
%textureSampleLevel_979816 = OpFunction %void None %110
%113 = OpLabel
%textureSampleLevel_979816 = OpFunction %void None %115
%118 = OpLabel
%res = OpVariable %_ptr_Function_v4float Function %5
%115 = OpLoad %11 %arg_0
%116 = OpLoad %11 %ext_tex_plane_1
%117 = OpLoad %23 %arg_1
%119 = OpLoad %ExternalTextureParams %ext_tex_params
%114 = OpFunctionCall %v4float %textureSampleExternal %115 %116 %117 %118 %119
OpStore %res %114
%120 = OpLoad %11 %arg_0
%121 = OpLoad %11 %ext_tex_plane_1
%122 = OpLoad %23 %arg_1
%124 = OpLoad %ExternalTextureParams %ext_tex_params
%119 = OpFunctionCall %v4float %textureSampleExternal %120 %121 %122 %123 %124
OpStore %res %119
OpReturn
OpFunctionEnd
%vertex_main_inner = OpFunction %v4float None %122
%124 = OpLabel
%125 = OpFunctionCall %void %textureSampleLevel_979816
%vertex_main_inner = OpFunction %v4float None %127
%129 = OpLabel
%130 = OpFunctionCall %void %textureSampleLevel_979816
OpReturnValue %5
OpFunctionEnd
%vertex_main = OpFunction %void None %110
%127 = OpLabel
%128 = OpFunctionCall %v4float %vertex_main_inner
OpStore %value %128
%vertex_main = OpFunction %void None %115
%132 = OpLabel
%133 = OpFunctionCall %v4float %vertex_main_inner
OpStore %value %133
OpStore %vertex_point_size %float_1
OpReturn
OpFunctionEnd
%fragment_main = OpFunction %void None %110
%130 = OpLabel
%131 = OpFunctionCall %void %textureSampleLevel_979816
%fragment_main = OpFunction %void None %115
%135 = OpLabel
%136 = OpFunctionCall %void %textureSampleLevel_979816
OpReturn
OpFunctionEnd
%compute_main = OpFunction %void None %110
%133 = OpLabel
%134 = OpFunctionCall %void %textureSampleLevel_979816
%compute_main = OpFunction %void None %115
%138 = OpLabel
%139 = OpFunctionCall %void %textureSampleLevel_979816
OpReturn
OpFunctionEnd