mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-10 05:57:51 +00:00
Reland ExternalTexture Gamma/Gamut Correction
Adds configurable gamma and gamut correction in Tint's external texture transform. Adds constants in Dawn to perform correct conversion from BT.709 to sRGB. Bug: dawn:1082 Change-Id: I68b7ad7ccec29977c637a0a0d4f526cd47fe73d4 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/88367 Commit-Queue: Brandon1 Jones <brandon1.jones@intel.com> Kokoro: Kokoro <noreply+kokoro@google.com> Reviewed-by: Ben Clayton <bclayton@google.com> Reviewed-by: Austin Eng <enga@chromium.org>
This commit is contained in:
committed by
Dawn LUCI CQ
parent
446166c81b
commit
41cbf0279c
@@ -150,16 +150,38 @@ namespace dawn::native {
|
||||
ExternalTextureParams params;
|
||||
params.numPlanes = descriptor->plane1 == nullptr ? 1 : 2;
|
||||
|
||||
// TODO(dawn:1082): Make this field configurable from outside of Dawn.
|
||||
// Conversion matrix for BT.709 limited range. Columns 1, 2 and 3 are copied
|
||||
// directly from the corresponding matrix in SkYUVMath.cpp. Column 4 is the range
|
||||
// bias (for RGB) found in column 5 of the same SkYUVMath.cpp matrix.
|
||||
params.yuvToRgbConversionMatrix = {1.164384f, 0.0f, 1.792741f, -0.972945f,
|
||||
1.164384f, -0.213249f, -0.532909f, 0.301483f,
|
||||
1.164384f, 2.112402f, 0.0f, -1.133402f};
|
||||
|
||||
// TODO(dawn:1082): Make this field configurable from outside of Dawn.
|
||||
// Use an identity matrix when converting BT.709 to sRGB because they shared the
|
||||
// same primaries.
|
||||
params.gamutConversionMatrix = {1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f,
|
||||
0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f};
|
||||
|
||||
switch (descriptor->colorSpace) {
|
||||
case wgpu::PredefinedColorSpace::Srgb:
|
||||
// Conversion matrix for BT.709 limited range. Columns 1, 2 and 3 are copied
|
||||
// directly from the corresponding matrix in SkYUVMath.cpp. Column 4 is the range
|
||||
// bias (for RGB) found in column 5 of the same SkYUVMath.cpp matrix.
|
||||
params.yuvToRgbConversion = {1.164384f, 0.0f, 1.792741f, -0.972945f,
|
||||
1.164384f, -0.213249f, -0.532909f, 0.301483f,
|
||||
1.164384f, 2.112402f, 0.0f, -1.133402f};
|
||||
break;
|
||||
case wgpu::PredefinedColorSpace::Undefined:
|
||||
// Undefined color space should eventually produce an error. For now, these
|
||||
// constants will effectively perform no gamma correction so tests can continue
|
||||
// passing.
|
||||
params.gammaDecodingParams = {1.0, 1.0, 0.0, 1.0, 1.0, 0.0, 0.0};
|
||||
params.gammaEncodingParams = {1.0, 1.0, 0.0, 1.0, 1.0, 0.0, 0.0};
|
||||
break;
|
||||
case wgpu::PredefinedColorSpace::Srgb:
|
||||
// TODO(dawn:1082): Make this field configurable from outside of Dawn.
|
||||
// These are the inverted parameters as specified by Rec. ITU-R BT.1886 for BT.709
|
||||
params.gammaDecodingParams = {2.2, 1.0 / 1.099, 0.099 / 1.099, 1 / 4.5, 0.081,
|
||||
0.0, 0.0};
|
||||
|
||||
// Constants for sRGB transfer function pulled from
|
||||
// https://en.wikipedia.org/wiki/SRGB
|
||||
params.gammaEncodingParams = {
|
||||
1 / 2.4, 1.137119 /*1.055^2.4*/, 0.0, 12.92, 0.0031308, -0.055, 0.0};
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -26,10 +26,24 @@ namespace dawn::native {
|
||||
|
||||
class TextureViewBase;
|
||||
|
||||
struct GammaTransferParams {
|
||||
float G = 0.0;
|
||||
float A = 0.0;
|
||||
float B = 0.0;
|
||||
float C = 0.0;
|
||||
float D = 0.0;
|
||||
float E = 0.0;
|
||||
float F = 0.0;
|
||||
uint32_t padding = 0;
|
||||
};
|
||||
|
||||
struct ExternalTextureParams {
|
||||
uint32_t numPlanes;
|
||||
std::array<uint32_t, 3> padding;
|
||||
std::array<float, 12> yuvToRgbConversion;
|
||||
std::array<float, 12> yuvToRgbConversionMatrix;
|
||||
GammaTransferParams gammaDecodingParams = {};
|
||||
GammaTransferParams gammaEncodingParams = {};
|
||||
std::array<float, 12> gamutConversionMatrix = {};
|
||||
};
|
||||
|
||||
MaybeError ValidateExternalTextureDescriptor(const DeviceBase* device,
|
||||
|
||||
@@ -191,10 +191,15 @@ TEST_P(ExternalTextureTests, SampleMultiplanarExternalTexture) {
|
||||
RGBA8 rgba;
|
||||
};
|
||||
|
||||
std::array<ConversionExpectation, 4> expectations = {{{0.0, .5, .5, RGBA8::kBlack},
|
||||
{0.2126, 0.4172, 1.0, RGBA8::kRed},
|
||||
{0.7152, 0.1402, 0.0175, RGBA8::kGreen},
|
||||
{0.0722, 1.0, 0.4937, RGBA8::kBlue}}};
|
||||
// Conversion expectations for BT.709 YUV source and sRGB destination.
|
||||
std::array<ConversionExpectation, 7> expectations = {
|
||||
{{0.0, .5, .5, RGBA8::kBlack},
|
||||
{0.2126, 0.4172, 1.0, RGBA8::kRed},
|
||||
{0.7152, 0.1402, 0.0175, RGBA8::kGreen},
|
||||
{0.0722, 1.0, 0.4937, RGBA8::kBlue},
|
||||
{0.6382, 0.3232, 0.6644, {246, 169, 90, 255}},
|
||||
{0.5423, 0.5323, 0.4222, {120, 162, 169, 255}},
|
||||
{0.2345, 0.4383, 0.6342, {126, 53, 33, 255}}}};
|
||||
|
||||
for (ConversionExpectation expectation : expectations) {
|
||||
// Initialize the texture planes with YUV data
|
||||
|
||||
@@ -51,6 +51,9 @@ struct MultiplanarExternalTexture::State {
|
||||
/// as input into the transform.
|
||||
const NewBindingPoints* new_binding_points;
|
||||
|
||||
/// Symbol for the GammaTransferParams
|
||||
Symbol gamma_transfer_struct_sym;
|
||||
|
||||
/// Symbol for the ExternalTextureParams struct
|
||||
Symbol params_struct_sym;
|
||||
|
||||
@@ -60,6 +63,9 @@ struct MultiplanarExternalTexture::State {
|
||||
/// Symbol for the textureSampleExternal function
|
||||
Symbol texture_sample_external_sym;
|
||||
|
||||
/// Symbol for the gammaCorrection function
|
||||
Symbol gamma_correction_sym;
|
||||
|
||||
/// Storage for new bindings that have been created corresponding to an
|
||||
/// original texture_external binding.
|
||||
std::unordered_map<const sem::Variable*, NewBindingSymbols>
|
||||
@@ -96,7 +102,7 @@ struct MultiplanarExternalTexture::State {
|
||||
// If we find a texture_external binding, we know we must emit the
|
||||
// ExternalTextureParams struct.
|
||||
if (!params_struct_sym.IsValid()) {
|
||||
createExtTexParamsStruct();
|
||||
createExtTexParamsStructs();
|
||||
}
|
||||
|
||||
// The binding points for the newly introduced bindings must have been
|
||||
@@ -158,7 +164,7 @@ struct MultiplanarExternalTexture::State {
|
||||
// If we find a texture_external, we must ensure the
|
||||
// ExternalTextureParams struct exists.
|
||||
if (!params_struct_sym.IsValid()) {
|
||||
createExtTexParamsStruct();
|
||||
createExtTexParamsStructs();
|
||||
}
|
||||
// When a texture_external is found, we insert all components
|
||||
// the texture_external into the parameter list. We must also place
|
||||
@@ -236,15 +242,68 @@ struct MultiplanarExternalTexture::State {
|
||||
});
|
||||
}
|
||||
|
||||
/// Creates the ExternalTextureParams struct.
|
||||
void createExtTexParamsStruct() {
|
||||
ast::StructMemberList member_list = {
|
||||
/// Creates the parameter structs associated with the transform.
|
||||
void createExtTexParamsStructs() {
|
||||
// Create GammaTransferParams struct.
|
||||
ast::StructMemberList gamma_transfer_member_list = {
|
||||
b.Member("G", b.ty.f32()), b.Member("A", b.ty.f32()),
|
||||
b.Member("B", b.ty.f32()), b.Member("C", b.ty.f32()),
|
||||
b.Member("D", b.ty.f32()), b.Member("E", b.ty.f32()),
|
||||
b.Member("F", b.ty.f32()), b.Member("padding", b.ty.u32())};
|
||||
|
||||
gamma_transfer_struct_sym = b.Symbols().New("GammaTransferParams");
|
||||
|
||||
b.Structure(gamma_transfer_struct_sym, gamma_transfer_member_list);
|
||||
|
||||
// Create ExternalTextureParams struct.
|
||||
ast::StructMemberList ext_tex_params_member_list = {
|
||||
b.Member("numPlanes", b.ty.u32()),
|
||||
b.Member("yuvToRgbConversionMatrix", b.ty.mat3x4(b.ty.f32()))};
|
||||
b.Member("yuvToRgbConversionMatrix", b.ty.mat3x4(b.ty.f32())),
|
||||
b.Member("gammaDecodeParams", b.ty.type_name("GammaTransferParams")),
|
||||
b.Member("gammaEncodeParams", b.ty.type_name("GammaTransferParams")),
|
||||
b.Member("gamutConversionMatrix", b.ty.mat3x3(b.ty.f32()))};
|
||||
|
||||
params_struct_sym = b.Symbols().New("ExternalTextureParams");
|
||||
|
||||
b.Structure(params_struct_sym, member_list);
|
||||
b.Structure(params_struct_sym, ext_tex_params_member_list);
|
||||
}
|
||||
|
||||
/// Creates the gammaCorrection function if needed and returns a call
|
||||
/// expression to it.
|
||||
void createGammaCorrectionFn() {
|
||||
using f32 = ProgramBuilder::f32;
|
||||
ast::VariableList varList = {
|
||||
b.Param("v", b.ty.vec3<f32>()),
|
||||
b.Param("params", b.ty.type_name(gamma_transfer_struct_sym))};
|
||||
|
||||
ast::StatementList statementList = {
|
||||
// let cond = abs(v) < vec3(params.D);
|
||||
b.Decl(b.Let("cond", nullptr,
|
||||
b.LessThan(b.Call("abs", "v"),
|
||||
b.vec3<f32>(b.MemberAccessor("params", "D"))))),
|
||||
// let t = sign(v) * ((params.C * abs(v)) + params.F);
|
||||
b.Decl(b.Let("t", nullptr,
|
||||
b.Mul(b.Call("sign", "v"),
|
||||
b.Add(b.Mul(b.MemberAccessor("params", "C"),
|
||||
b.Call("abs", "v")),
|
||||
b.MemberAccessor("params", "F"))))),
|
||||
// let f = (sign(v) * pow(((params.A * abs(v)) + params.B),
|
||||
// vec3(params.G))) + params.E;
|
||||
b.Decl(b.Let(
|
||||
"f", nullptr,
|
||||
b.Mul(b.Call("sign", "v"),
|
||||
b.Add(b.Call("pow",
|
||||
b.Add(b.Mul(b.MemberAccessor("params", "A"),
|
||||
b.Call("abs", "v")),
|
||||
b.MemberAccessor("params", "B")),
|
||||
b.vec3<f32>(b.MemberAccessor("params", "G"))),
|
||||
b.MemberAccessor("params", "E"))))),
|
||||
// return select(f, t, cond);
|
||||
b.Return(b.Call("select", "f", "t", "cond"))};
|
||||
|
||||
gamma_correction_sym = b.Symbols().New("gammaCorrection");
|
||||
|
||||
b.Func(gamma_correction_sym, varList, b.ty.vec3<f32>(), statementList, {});
|
||||
}
|
||||
|
||||
/// Constructs a StatementList containing all the statements making up the
|
||||
@@ -297,6 +356,18 @@ struct MultiplanarExternalTexture::State {
|
||||
b.MemberAccessor(plane_1_call, "rg"), 1.0f),
|
||||
b.MemberAccessor(
|
||||
"params", "yuvToRgbConversionMatrix"))))),
|
||||
// color = gammaConversion(color, gammaDecodeParams);
|
||||
b.Assign("color",
|
||||
b.Call("gammaCorrection", "color",
|
||||
b.MemberAccessor("params", "gammaDecodeParams"))),
|
||||
// color = (params.gamutConversionMatrix * color);
|
||||
b.Assign("color",
|
||||
b.Mul(b.MemberAccessor("params", "gamutConversionMatrix"),
|
||||
"color")),
|
||||
// color = gammaConversion(color, gammaEncodeParams);
|
||||
b.Assign("color",
|
||||
b.Call("gammaCorrection", "color",
|
||||
b.MemberAccessor("params", "gammaEncodeParams"))),
|
||||
// return vec4<f32>(color, 1.0f);
|
||||
b.Return(b.vec4<f32>("color", 1.0f))};
|
||||
}
|
||||
@@ -318,6 +389,12 @@ struct MultiplanarExternalTexture::State {
|
||||
<< expr->args.size() << " parameters";
|
||||
}
|
||||
|
||||
// TextureSampleExternal calls the gammaCorrection function, so ensure it
|
||||
// exists.
|
||||
if (!gamma_correction_sym.IsValid()) {
|
||||
createGammaCorrectionFn();
|
||||
}
|
||||
|
||||
if (!texture_sample_external_sym.IsValid()) {
|
||||
texture_sample_external_sym = b.Symbols().New("textureSampleExternal");
|
||||
|
||||
@@ -362,6 +439,12 @@ struct MultiplanarExternalTexture::State {
|
||||
<< expr->args.size() << " parameters";
|
||||
}
|
||||
|
||||
// TextureLoadExternal calls the gammaCorrection function, so ensure it
|
||||
// exists.
|
||||
if (!gamma_correction_sym.IsValid()) {
|
||||
createGammaCorrectionFn();
|
||||
}
|
||||
|
||||
if (!texture_load_external_sym.IsValid()) {
|
||||
texture_load_external_sym = b.Symbols().New("textureLoadExternal");
|
||||
|
||||
|
||||
@@ -106,9 +106,23 @@ fn main(@builtin(position) coord : vec4<f32>) -> @location(0) vec4<f32> {
|
||||
)";
|
||||
|
||||
auto* expect = R"(
|
||||
struct GammaTransferParams {
|
||||
G : f32,
|
||||
A : f32,
|
||||
B : f32,
|
||||
C : f32,
|
||||
D : f32,
|
||||
E : f32,
|
||||
F : f32,
|
||||
padding : u32,
|
||||
}
|
||||
|
||||
struct ExternalTextureParams {
|
||||
numPlanes : u32,
|
||||
yuvToRgbConversionMatrix : mat3x4<f32>,
|
||||
gammaDecodeParams : GammaTransferParams,
|
||||
gammaEncodeParams : GammaTransferParams,
|
||||
gamutConversionMatrix : mat3x3<f32>,
|
||||
}
|
||||
|
||||
@group(0) @binding(1) var ext_tex_plane_1 : texture_2d<f32>;
|
||||
@@ -146,9 +160,23 @@ fn main(@builtin(position) coord : vec4<f32>) -> @location(0) vec4<f32> {
|
||||
)";
|
||||
|
||||
auto* expect = R"(
|
||||
struct GammaTransferParams {
|
||||
G : f32,
|
||||
A : f32,
|
||||
B : f32,
|
||||
C : f32,
|
||||
D : f32,
|
||||
E : f32,
|
||||
F : f32,
|
||||
padding : u32,
|
||||
}
|
||||
|
||||
struct ExternalTextureParams {
|
||||
numPlanes : u32,
|
||||
yuvToRgbConversionMatrix : mat3x4<f32>,
|
||||
gammaDecodeParams : GammaTransferParams,
|
||||
gammaEncodeParams : GammaTransferParams,
|
||||
gamutConversionMatrix : mat3x3<f32>,
|
||||
}
|
||||
|
||||
@group(0) @binding(1) var ext_tex_plane_1 : texture_2d<f32>;
|
||||
@@ -185,9 +213,23 @@ fn main(@builtin(position) coord : vec4<f32>) -> @location(0) vec4<f32> {
|
||||
)";
|
||||
|
||||
auto* expect = R"(
|
||||
struct GammaTransferParams {
|
||||
G : f32,
|
||||
A : f32,
|
||||
B : f32,
|
||||
C : f32,
|
||||
D : f32,
|
||||
E : f32,
|
||||
F : f32,
|
||||
padding : u32,
|
||||
}
|
||||
|
||||
struct ExternalTextureParams {
|
||||
numPlanes : u32,
|
||||
yuvToRgbConversionMatrix : mat3x4<f32>,
|
||||
gammaDecodeParams : GammaTransferParams,
|
||||
gammaEncodeParams : GammaTransferParams,
|
||||
gamutConversionMatrix : mat3x3<f32>,
|
||||
}
|
||||
|
||||
@group(0) @binding(2) var ext_tex_plane_1 : texture_2d<f32>;
|
||||
@@ -198,6 +240,13 @@ struct ExternalTextureParams {
|
||||
|
||||
@group(0) @binding(1) var ext_tex : texture_2d<f32>;
|
||||
|
||||
fn gammaCorrection(v : vec3<f32>, params : GammaTransferParams) -> vec3<f32> {
|
||||
let cond = (abs(v) < vec3<f32>(params.D));
|
||||
let t = (sign(v) * ((params.C * abs(v)) + params.F));
|
||||
let f = (sign(v) * (pow(((params.A * abs(v)) + params.B), vec3<f32>(params.G)) + params.E));
|
||||
return select(f, t, cond);
|
||||
}
|
||||
|
||||
fn textureSampleExternal(plane0 : texture_2d<f32>, plane1 : texture_2d<f32>, smp : sampler, coord : vec2<f32>, params : ExternalTextureParams) -> vec4<f32> {
|
||||
var color : vec3<f32>;
|
||||
if ((params.numPlanes == 1u)) {
|
||||
@@ -205,6 +254,9 @@ fn textureSampleExternal(plane0 : texture_2d<f32>, plane1 : texture_2d<f32>, smp
|
||||
} else {
|
||||
color = (vec4<f32>(textureSampleLevel(plane0, smp, coord, 0.0).r, textureSampleLevel(plane1, smp, coord, 0.0).rg, 1.0) * params.yuvToRgbConversionMatrix);
|
||||
}
|
||||
color = gammaCorrection(color, params.gammaDecodeParams);
|
||||
color = (params.gamutConversionMatrix * color);
|
||||
color = gammaCorrection(color, params.gammaEncodeParams);
|
||||
return vec4<f32>(color, 1.0);
|
||||
}
|
||||
|
||||
@@ -234,15 +286,36 @@ fn main(@builtin(position) coord : vec4<f32>) -> @location(0) vec4<f32> {
|
||||
)";
|
||||
|
||||
auto* expect = R"(
|
||||
struct GammaTransferParams {
|
||||
G : f32,
|
||||
A : f32,
|
||||
B : f32,
|
||||
C : f32,
|
||||
D : f32,
|
||||
E : f32,
|
||||
F : f32,
|
||||
padding : u32,
|
||||
}
|
||||
|
||||
struct ExternalTextureParams {
|
||||
numPlanes : u32,
|
||||
yuvToRgbConversionMatrix : mat3x4<f32>,
|
||||
gammaDecodeParams : GammaTransferParams,
|
||||
gammaEncodeParams : GammaTransferParams,
|
||||
gamutConversionMatrix : mat3x3<f32>,
|
||||
}
|
||||
|
||||
@group(0) @binding(2) var ext_tex_plane_1 : texture_2d<f32>;
|
||||
|
||||
@group(0) @binding(3) var<uniform> ext_tex_params : ExternalTextureParams;
|
||||
|
||||
fn gammaCorrection(v : vec3<f32>, params : GammaTransferParams) -> vec3<f32> {
|
||||
let cond = (abs(v) < vec3<f32>(params.D));
|
||||
let t = (sign(v) * ((params.C * abs(v)) + params.F));
|
||||
let f = (sign(v) * (pow(((params.A * abs(v)) + params.B), vec3<f32>(params.G)) + params.E));
|
||||
return select(f, t, cond);
|
||||
}
|
||||
|
||||
fn textureSampleExternal(plane0 : texture_2d<f32>, plane1 : texture_2d<f32>, smp : sampler, coord : vec2<f32>, params : ExternalTextureParams) -> vec4<f32> {
|
||||
var color : vec3<f32>;
|
||||
if ((params.numPlanes == 1u)) {
|
||||
@@ -250,6 +323,9 @@ fn textureSampleExternal(plane0 : texture_2d<f32>, plane1 : texture_2d<f32>, smp
|
||||
} else {
|
||||
color = (vec4<f32>(textureSampleLevel(plane0, smp, coord, 0.0).r, textureSampleLevel(plane1, smp, coord, 0.0).rg, 1.0) * params.yuvToRgbConversionMatrix);
|
||||
}
|
||||
color = gammaCorrection(color, params.gammaDecodeParams);
|
||||
color = (params.gamutConversionMatrix * color);
|
||||
color = gammaCorrection(color, params.gammaEncodeParams);
|
||||
return vec4<f32>(color, 1.0);
|
||||
}
|
||||
|
||||
@@ -282,9 +358,23 @@ fn main(@builtin(position) coord : vec4<f32>) -> @location(0) vec4<f32> {
|
||||
)";
|
||||
|
||||
auto* expect = R"(
|
||||
struct GammaTransferParams {
|
||||
G : f32,
|
||||
A : f32,
|
||||
B : f32,
|
||||
C : f32,
|
||||
D : f32,
|
||||
E : f32,
|
||||
F : f32,
|
||||
padding : u32,
|
||||
}
|
||||
|
||||
struct ExternalTextureParams {
|
||||
numPlanes : u32,
|
||||
yuvToRgbConversionMatrix : mat3x4<f32>,
|
||||
gammaDecodeParams : GammaTransferParams,
|
||||
gammaEncodeParams : GammaTransferParams,
|
||||
gamutConversionMatrix : mat3x3<f32>,
|
||||
}
|
||||
|
||||
@group(0) @binding(1) var ext_tex_plane_1 : texture_2d<f32>;
|
||||
@@ -293,6 +383,13 @@ struct ExternalTextureParams {
|
||||
|
||||
@group(0) @binding(0) var ext_tex : texture_2d<f32>;
|
||||
|
||||
fn gammaCorrection(v : vec3<f32>, params : GammaTransferParams) -> vec3<f32> {
|
||||
let cond = (abs(v) < vec3<f32>(params.D));
|
||||
let t = (sign(v) * ((params.C * abs(v)) + params.F));
|
||||
let f = (sign(v) * (pow(((params.A * abs(v)) + params.B), vec3<f32>(params.G)) + params.E));
|
||||
return select(f, t, cond);
|
||||
}
|
||||
|
||||
fn textureLoadExternal(plane0 : texture_2d<f32>, plane1 : texture_2d<f32>, coord : vec2<i32>, params : ExternalTextureParams) -> vec4<f32> {
|
||||
var color : vec3<f32>;
|
||||
if ((params.numPlanes == 1u)) {
|
||||
@@ -300,6 +397,9 @@ fn textureLoadExternal(plane0 : texture_2d<f32>, plane1 : texture_2d<f32>, coord
|
||||
} else {
|
||||
color = (vec4<f32>(textureLoad(plane0, coord, 0).r, textureLoad(plane1, coord, 0).rg, 1.0) * params.yuvToRgbConversionMatrix);
|
||||
}
|
||||
color = gammaCorrection(color, params.gammaDecodeParams);
|
||||
color = (params.gamutConversionMatrix * color);
|
||||
color = gammaCorrection(color, params.gammaEncodeParams);
|
||||
return vec4<f32>(color, 1.0);
|
||||
}
|
||||
|
||||
@@ -328,15 +428,36 @@ fn main(@builtin(position) coord : vec4<f32>) -> @location(0) vec4<f32> {
|
||||
)";
|
||||
|
||||
auto* expect = R"(
|
||||
struct GammaTransferParams {
|
||||
G : f32,
|
||||
A : f32,
|
||||
B : f32,
|
||||
C : f32,
|
||||
D : f32,
|
||||
E : f32,
|
||||
F : f32,
|
||||
padding : u32,
|
||||
}
|
||||
|
||||
struct ExternalTextureParams {
|
||||
numPlanes : u32,
|
||||
yuvToRgbConversionMatrix : mat3x4<f32>,
|
||||
gammaDecodeParams : GammaTransferParams,
|
||||
gammaEncodeParams : GammaTransferParams,
|
||||
gamutConversionMatrix : mat3x3<f32>,
|
||||
}
|
||||
|
||||
@group(0) @binding(1) var ext_tex_plane_1 : texture_2d<f32>;
|
||||
|
||||
@group(0) @binding(2) var<uniform> ext_tex_params : ExternalTextureParams;
|
||||
|
||||
fn gammaCorrection(v : vec3<f32>, params : GammaTransferParams) -> vec3<f32> {
|
||||
let cond = (abs(v) < vec3<f32>(params.D));
|
||||
let t = (sign(v) * ((params.C * abs(v)) + params.F));
|
||||
let f = (sign(v) * (pow(((params.A * abs(v)) + params.B), vec3<f32>(params.G)) + params.E));
|
||||
return select(f, t, cond);
|
||||
}
|
||||
|
||||
fn textureLoadExternal(plane0 : texture_2d<f32>, plane1 : texture_2d<f32>, coord : vec2<i32>, params : ExternalTextureParams) -> vec4<f32> {
|
||||
var color : vec3<f32>;
|
||||
if ((params.numPlanes == 1u)) {
|
||||
@@ -344,6 +465,9 @@ fn textureLoadExternal(plane0 : texture_2d<f32>, plane1 : texture_2d<f32>, coord
|
||||
} else {
|
||||
color = (vec4<f32>(textureLoad(plane0, coord, 0).r, textureLoad(plane1, coord, 0).rg, 1.0) * params.yuvToRgbConversionMatrix);
|
||||
}
|
||||
color = gammaCorrection(color, params.gammaDecodeParams);
|
||||
color = (params.gamutConversionMatrix * color);
|
||||
color = gammaCorrection(color, params.gammaEncodeParams);
|
||||
return vec4<f32>(color, 1.0);
|
||||
}
|
||||
|
||||
@@ -376,9 +500,23 @@ fn main(@builtin(position) coord : vec4<f32>) -> @location(0) vec4<f32> {
|
||||
)";
|
||||
|
||||
auto* expect = R"(
|
||||
struct GammaTransferParams {
|
||||
G : f32,
|
||||
A : f32,
|
||||
B : f32,
|
||||
C : f32,
|
||||
D : f32,
|
||||
E : f32,
|
||||
F : f32,
|
||||
padding : u32,
|
||||
}
|
||||
|
||||
struct ExternalTextureParams {
|
||||
numPlanes : u32,
|
||||
yuvToRgbConversionMatrix : mat3x4<f32>,
|
||||
gammaDecodeParams : GammaTransferParams,
|
||||
gammaEncodeParams : GammaTransferParams,
|
||||
gamutConversionMatrix : mat3x3<f32>,
|
||||
}
|
||||
|
||||
@group(0) @binding(2) var ext_tex_plane_1 : texture_2d<f32>;
|
||||
@@ -389,6 +527,13 @@ struct ExternalTextureParams {
|
||||
|
||||
@group(0) @binding(1) var ext_tex : texture_2d<f32>;
|
||||
|
||||
fn gammaCorrection(v : vec3<f32>, params : GammaTransferParams) -> vec3<f32> {
|
||||
let cond = (abs(v) < vec3<f32>(params.D));
|
||||
let t = (sign(v) * ((params.C * abs(v)) + params.F));
|
||||
let f = (sign(v) * (pow(((params.A * abs(v)) + params.B), vec3<f32>(params.G)) + params.E));
|
||||
return select(f, t, cond);
|
||||
}
|
||||
|
||||
fn textureSampleExternal(plane0 : texture_2d<f32>, plane1 : texture_2d<f32>, smp : sampler, coord : vec2<f32>, params : ExternalTextureParams) -> vec4<f32> {
|
||||
var color : vec3<f32>;
|
||||
if ((params.numPlanes == 1u)) {
|
||||
@@ -396,6 +541,9 @@ fn textureSampleExternal(plane0 : texture_2d<f32>, plane1 : texture_2d<f32>, smp
|
||||
} else {
|
||||
color = (vec4<f32>(textureSampleLevel(plane0, smp, coord, 0.0).r, textureSampleLevel(plane1, smp, coord, 0.0).rg, 1.0) * params.yuvToRgbConversionMatrix);
|
||||
}
|
||||
color = gammaCorrection(color, params.gammaDecodeParams);
|
||||
color = (params.gamutConversionMatrix * color);
|
||||
color = gammaCorrection(color, params.gammaEncodeParams);
|
||||
return vec4<f32>(color, 1.0);
|
||||
}
|
||||
|
||||
@@ -406,6 +554,9 @@ fn textureLoadExternal(plane0 : texture_2d<f32>, plane1 : texture_2d<f32>, coord
|
||||
} else {
|
||||
color = (vec4<f32>(textureLoad(plane0, coord, 0).r, textureLoad(plane1, coord, 0).rg, 1.0) * params.yuvToRgbConversionMatrix);
|
||||
}
|
||||
color = gammaCorrection(color, params.gammaDecodeParams);
|
||||
color = (params.gamutConversionMatrix * color);
|
||||
color = gammaCorrection(color, params.gammaEncodeParams);
|
||||
return vec4<f32>(color, 1.0);
|
||||
}
|
||||
|
||||
@@ -436,15 +587,36 @@ fn main(@builtin(position) coord : vec4<f32>) -> @location(0) vec4<f32> {
|
||||
)";
|
||||
|
||||
auto* expect = R"(
|
||||
struct GammaTransferParams {
|
||||
G : f32,
|
||||
A : f32,
|
||||
B : f32,
|
||||
C : f32,
|
||||
D : f32,
|
||||
E : f32,
|
||||
F : f32,
|
||||
padding : u32,
|
||||
}
|
||||
|
||||
struct ExternalTextureParams {
|
||||
numPlanes : u32,
|
||||
yuvToRgbConversionMatrix : mat3x4<f32>,
|
||||
gammaDecodeParams : GammaTransferParams,
|
||||
gammaEncodeParams : GammaTransferParams,
|
||||
gamutConversionMatrix : mat3x3<f32>,
|
||||
}
|
||||
|
||||
@group(0) @binding(2) var ext_tex_plane_1 : texture_2d<f32>;
|
||||
|
||||
@group(0) @binding(3) var<uniform> ext_tex_params : ExternalTextureParams;
|
||||
|
||||
fn gammaCorrection(v : vec3<f32>, params : GammaTransferParams) -> vec3<f32> {
|
||||
let cond = (abs(v) < vec3<f32>(params.D));
|
||||
let t = (sign(v) * ((params.C * abs(v)) + params.F));
|
||||
let f = (sign(v) * (pow(((params.A * abs(v)) + params.B), vec3<f32>(params.G)) + params.E));
|
||||
return select(f, t, cond);
|
||||
}
|
||||
|
||||
fn textureSampleExternal(plane0 : texture_2d<f32>, plane1 : texture_2d<f32>, smp : sampler, coord : vec2<f32>, params : ExternalTextureParams) -> vec4<f32> {
|
||||
var color : vec3<f32>;
|
||||
if ((params.numPlanes == 1u)) {
|
||||
@@ -452,6 +624,9 @@ fn textureSampleExternal(plane0 : texture_2d<f32>, plane1 : texture_2d<f32>, smp
|
||||
} else {
|
||||
color = (vec4<f32>(textureSampleLevel(plane0, smp, coord, 0.0).r, textureSampleLevel(plane1, smp, coord, 0.0).rg, 1.0) * params.yuvToRgbConversionMatrix);
|
||||
}
|
||||
color = gammaCorrection(color, params.gammaDecodeParams);
|
||||
color = (params.gamutConversionMatrix * color);
|
||||
color = gammaCorrection(color, params.gammaEncodeParams);
|
||||
return vec4<f32>(color, 1.0);
|
||||
}
|
||||
|
||||
@@ -462,6 +637,9 @@ fn textureLoadExternal(plane0 : texture_2d<f32>, plane1 : texture_2d<f32>, coord
|
||||
} else {
|
||||
color = (vec4<f32>(textureLoad(plane0, coord, 0).r, textureLoad(plane1, coord, 0).rg, 1.0) * params.yuvToRgbConversionMatrix);
|
||||
}
|
||||
color = gammaCorrection(color, params.gammaDecodeParams);
|
||||
color = (params.gamutConversionMatrix * color);
|
||||
color = gammaCorrection(color, params.gammaEncodeParams);
|
||||
return vec4<f32>(color, 1.0);
|
||||
}
|
||||
|
||||
@@ -498,9 +676,23 @@ fn main(@builtin(position) coord : vec4<f32>) -> @location(0) vec4<f32> {
|
||||
)";
|
||||
|
||||
auto* expect = R"(
|
||||
struct GammaTransferParams {
|
||||
G : f32,
|
||||
A : f32,
|
||||
B : f32,
|
||||
C : f32,
|
||||
D : f32,
|
||||
E : f32,
|
||||
F : f32,
|
||||
padding : u32,
|
||||
}
|
||||
|
||||
struct ExternalTextureParams {
|
||||
numPlanes : u32,
|
||||
yuvToRgbConversionMatrix : mat3x4<f32>,
|
||||
gammaDecodeParams : GammaTransferParams,
|
||||
gammaEncodeParams : GammaTransferParams,
|
||||
gamutConversionMatrix : mat3x3<f32>,
|
||||
}
|
||||
|
||||
@group(0) @binding(4) var ext_tex_plane_1 : texture_2d<f32>;
|
||||
@@ -529,6 +721,13 @@ struct ExternalTextureParams {
|
||||
|
||||
@group(1) @binding(0) var ext_tex_3 : texture_2d<f32>;
|
||||
|
||||
fn gammaCorrection(v : vec3<f32>, params : GammaTransferParams) -> vec3<f32> {
|
||||
let cond = (abs(v) < vec3<f32>(params.D));
|
||||
let t = (sign(v) * ((params.C * abs(v)) + params.F));
|
||||
let f = (sign(v) * (pow(((params.A * abs(v)) + params.B), vec3<f32>(params.G)) + params.E));
|
||||
return select(f, t, cond);
|
||||
}
|
||||
|
||||
fn textureSampleExternal(plane0 : texture_2d<f32>, plane1 : texture_2d<f32>, smp : sampler, coord : vec2<f32>, params : ExternalTextureParams) -> vec4<f32> {
|
||||
var color : vec3<f32>;
|
||||
if ((params.numPlanes == 1u)) {
|
||||
@@ -536,6 +735,9 @@ fn textureSampleExternal(plane0 : texture_2d<f32>, plane1 : texture_2d<f32>, smp
|
||||
} else {
|
||||
color = (vec4<f32>(textureSampleLevel(plane0, smp, coord, 0.0).r, textureSampleLevel(plane1, smp, coord, 0.0).rg, 1.0) * params.yuvToRgbConversionMatrix);
|
||||
}
|
||||
color = gammaCorrection(color, params.gammaDecodeParams);
|
||||
color = (params.gamutConversionMatrix * color);
|
||||
color = gammaCorrection(color, params.gammaEncodeParams);
|
||||
return vec4<f32>(color, 1.0);
|
||||
}
|
||||
|
||||
@@ -575,15 +777,36 @@ fn main() {
|
||||
)";
|
||||
|
||||
auto* expect = R"(
|
||||
struct GammaTransferParams {
|
||||
G : f32,
|
||||
A : f32,
|
||||
B : f32,
|
||||
C : f32,
|
||||
D : f32,
|
||||
E : f32,
|
||||
F : f32,
|
||||
padding : u32,
|
||||
}
|
||||
|
||||
struct ExternalTextureParams {
|
||||
numPlanes : u32,
|
||||
yuvToRgbConversionMatrix : mat3x4<f32>,
|
||||
gammaDecodeParams : GammaTransferParams,
|
||||
gammaEncodeParams : GammaTransferParams,
|
||||
gamutConversionMatrix : mat3x3<f32>,
|
||||
}
|
||||
|
||||
@group(0) @binding(2) var ext_tex_plane_1 : texture_2d<f32>;
|
||||
|
||||
@group(0) @binding(3) var<uniform> ext_tex_params : ExternalTextureParams;
|
||||
|
||||
fn gammaCorrection(v : vec3<f32>, params : GammaTransferParams) -> vec3<f32> {
|
||||
let cond = (abs(v) < vec3<f32>(params.D));
|
||||
let t = (sign(v) * ((params.C * abs(v)) + params.F));
|
||||
let f = (sign(v) * (pow(((params.A * abs(v)) + params.B), vec3<f32>(params.G)) + params.E));
|
||||
return select(f, t, cond);
|
||||
}
|
||||
|
||||
fn textureSampleExternal(plane0 : texture_2d<f32>, plane1 : texture_2d<f32>, smp : sampler, coord : vec2<f32>, params : ExternalTextureParams) -> vec4<f32> {
|
||||
var color : vec3<f32>;
|
||||
if ((params.numPlanes == 1u)) {
|
||||
@@ -591,6 +814,9 @@ fn textureSampleExternal(plane0 : texture_2d<f32>, plane1 : texture_2d<f32>, smp
|
||||
} else {
|
||||
color = (vec4<f32>(textureSampleLevel(plane0, smp, coord, 0.0).r, textureSampleLevel(plane1, smp, coord, 0.0).rg, 1.0) * params.yuvToRgbConversionMatrix);
|
||||
}
|
||||
color = gammaCorrection(color, params.gammaDecodeParams);
|
||||
color = (params.gamutConversionMatrix * color);
|
||||
color = gammaCorrection(color, params.gammaEncodeParams);
|
||||
return vec4<f32>(color, 1.0);
|
||||
}
|
||||
|
||||
@@ -635,9 +861,23 @@ fn f(t : texture_external, s : sampler) {
|
||||
)";
|
||||
|
||||
auto* expect = R"(
|
||||
struct GammaTransferParams {
|
||||
G : f32,
|
||||
A : f32,
|
||||
B : f32,
|
||||
C : f32,
|
||||
D : f32,
|
||||
E : f32,
|
||||
F : f32,
|
||||
padding : u32,
|
||||
}
|
||||
|
||||
struct ExternalTextureParams {
|
||||
numPlanes : u32,
|
||||
yuvToRgbConversionMatrix : mat3x4<f32>,
|
||||
gammaDecodeParams : GammaTransferParams,
|
||||
gammaEncodeParams : GammaTransferParams,
|
||||
gamutConversionMatrix : mat3x3<f32>,
|
||||
}
|
||||
|
||||
@group(0) @binding(2) var ext_tex_plane_1 : texture_2d<f32>;
|
||||
@@ -649,6 +889,13 @@ fn main() {
|
||||
f(ext_tex, ext_tex_plane_1, ext_tex_params, smp);
|
||||
}
|
||||
|
||||
fn gammaCorrection(v : vec3<f32>, params : GammaTransferParams) -> vec3<f32> {
|
||||
let cond = (abs(v) < vec3<f32>(params.D));
|
||||
let t = (sign(v) * ((params.C * abs(v)) + params.F));
|
||||
let f = (sign(v) * (pow(((params.A * abs(v)) + params.B), vec3<f32>(params.G)) + params.E));
|
||||
return select(f, t, cond);
|
||||
}
|
||||
|
||||
fn textureSampleExternal(plane0 : texture_2d<f32>, plane1 : texture_2d<f32>, smp : sampler, coord : vec2<f32>, params : ExternalTextureParams) -> vec4<f32> {
|
||||
var color : vec3<f32>;
|
||||
if ((params.numPlanes == 1u)) {
|
||||
@@ -656,6 +903,9 @@ fn textureSampleExternal(plane0 : texture_2d<f32>, plane1 : texture_2d<f32>, smp
|
||||
} else {
|
||||
color = (vec4<f32>(textureSampleLevel(plane0, smp, coord, 0.0).r, textureSampleLevel(plane1, smp, coord, 0.0).rg, 1.0) * params.yuvToRgbConversionMatrix);
|
||||
}
|
||||
color = gammaCorrection(color, params.gammaDecodeParams);
|
||||
color = (params.gamutConversionMatrix * color);
|
||||
color = gammaCorrection(color, params.gammaEncodeParams);
|
||||
return vec4<f32>(color, 1.0);
|
||||
}
|
||||
|
||||
@@ -694,15 +944,36 @@ fn main() {
|
||||
)";
|
||||
|
||||
auto* expect = R"(
|
||||
struct GammaTransferParams {
|
||||
G : f32,
|
||||
A : f32,
|
||||
B : f32,
|
||||
C : f32,
|
||||
D : f32,
|
||||
E : f32,
|
||||
F : f32,
|
||||
padding : u32,
|
||||
}
|
||||
|
||||
struct ExternalTextureParams {
|
||||
numPlanes : u32,
|
||||
yuvToRgbConversionMatrix : mat3x4<f32>,
|
||||
gammaDecodeParams : GammaTransferParams,
|
||||
gammaEncodeParams : GammaTransferParams,
|
||||
gamutConversionMatrix : mat3x3<f32>,
|
||||
}
|
||||
|
||||
@group(0) @binding(2) var ext_tex_plane_1 : texture_2d<f32>;
|
||||
|
||||
@group(0) @binding(3) var<uniform> ext_tex_params : ExternalTextureParams;
|
||||
|
||||
fn gammaCorrection(v : vec3<f32>, params : GammaTransferParams) -> vec3<f32> {
|
||||
let cond = (abs(v) < vec3<f32>(params.D));
|
||||
let t = (sign(v) * ((params.C * abs(v)) + params.F));
|
||||
let f = (sign(v) * (pow(((params.A * abs(v)) + params.B), vec3<f32>(params.G)) + params.E));
|
||||
return select(f, t, cond);
|
||||
}
|
||||
|
||||
fn textureSampleExternal(plane0 : texture_2d<f32>, plane1 : texture_2d<f32>, smp : sampler, coord : vec2<f32>, params : ExternalTextureParams) -> vec4<f32> {
|
||||
var color : vec3<f32>;
|
||||
if ((params.numPlanes == 1u)) {
|
||||
@@ -710,6 +981,9 @@ fn textureSampleExternal(plane0 : texture_2d<f32>, plane1 : texture_2d<f32>, smp
|
||||
} else {
|
||||
color = (vec4<f32>(textureSampleLevel(plane0, smp, coord, 0.0).r, textureSampleLevel(plane1, smp, coord, 0.0).rg, 1.0) * params.yuvToRgbConversionMatrix);
|
||||
}
|
||||
color = gammaCorrection(color, params.gammaDecodeParams);
|
||||
color = (params.gamutConversionMatrix * color);
|
||||
color = gammaCorrection(color, params.gammaEncodeParams);
|
||||
return vec4<f32>(color, 1.0);
|
||||
}
|
||||
|
||||
@@ -755,9 +1029,23 @@ fn main() {
|
||||
)";
|
||||
|
||||
auto* expect = R"(
|
||||
struct GammaTransferParams {
|
||||
G : f32,
|
||||
A : f32,
|
||||
B : f32,
|
||||
C : f32,
|
||||
D : f32,
|
||||
E : f32,
|
||||
F : f32,
|
||||
padding : u32,
|
||||
}
|
||||
|
||||
struct ExternalTextureParams {
|
||||
numPlanes : u32,
|
||||
yuvToRgbConversionMatrix : mat3x4<f32>,
|
||||
gammaDecodeParams : GammaTransferParams,
|
||||
gammaEncodeParams : GammaTransferParams,
|
||||
gamutConversionMatrix : mat3x3<f32>,
|
||||
}
|
||||
|
||||
@group(0) @binding(3) var ext_tex_plane_1 : texture_2d<f32>;
|
||||
@@ -768,6 +1056,13 @@ struct ExternalTextureParams {
|
||||
|
||||
@group(0) @binding(6) var<uniform> ext_tex_params_1 : ExternalTextureParams;
|
||||
|
||||
fn gammaCorrection(v : vec3<f32>, params : GammaTransferParams) -> vec3<f32> {
|
||||
let cond = (abs(v) < vec3<f32>(params.D));
|
||||
let t = (sign(v) * ((params.C * abs(v)) + params.F));
|
||||
let f = (sign(v) * (pow(((params.A * abs(v)) + params.B), vec3<f32>(params.G)) + params.E));
|
||||
return select(f, t, cond);
|
||||
}
|
||||
|
||||
fn textureSampleExternal(plane0 : texture_2d<f32>, plane1 : texture_2d<f32>, smp : sampler, coord : vec2<f32>, params : ExternalTextureParams) -> vec4<f32> {
|
||||
var color : vec3<f32>;
|
||||
if ((params.numPlanes == 1u)) {
|
||||
@@ -775,6 +1070,9 @@ fn textureSampleExternal(plane0 : texture_2d<f32>, plane1 : texture_2d<f32>, smp
|
||||
} else {
|
||||
color = (vec4<f32>(textureSampleLevel(plane0, smp, coord, 0.0).r, textureSampleLevel(plane1, smp, coord, 0.0).rg, 1.0) * params.yuvToRgbConversionMatrix);
|
||||
}
|
||||
color = gammaCorrection(color, params.gammaDecodeParams);
|
||||
color = (params.gamutConversionMatrix * color);
|
||||
color = gammaCorrection(color, params.gammaEncodeParams);
|
||||
return vec4<f32>(color, 1.0);
|
||||
}
|
||||
|
||||
@@ -826,9 +1124,23 @@ fn f(t : texture_external, s : sampler, t2 : texture_external) {
|
||||
)";
|
||||
|
||||
auto* expect = R"(
|
||||
struct GammaTransferParams {
|
||||
G : f32,
|
||||
A : f32,
|
||||
B : f32,
|
||||
C : f32,
|
||||
D : f32,
|
||||
E : f32,
|
||||
F : f32,
|
||||
padding : u32,
|
||||
}
|
||||
|
||||
struct ExternalTextureParams {
|
||||
numPlanes : u32,
|
||||
yuvToRgbConversionMatrix : mat3x4<f32>,
|
||||
gammaDecodeParams : GammaTransferParams,
|
||||
gammaEncodeParams : GammaTransferParams,
|
||||
gamutConversionMatrix : mat3x3<f32>,
|
||||
}
|
||||
|
||||
@group(0) @binding(3) var ext_tex_plane_1 : texture_2d<f32>;
|
||||
@@ -844,6 +1156,13 @@ fn main() {
|
||||
f(ext_tex, ext_tex_plane_1, ext_tex_params, smp, ext_tex2, ext_tex_plane_1_1, ext_tex_params_1);
|
||||
}
|
||||
|
||||
fn gammaCorrection(v : vec3<f32>, params : GammaTransferParams) -> vec3<f32> {
|
||||
let cond = (abs(v) < vec3<f32>(params.D));
|
||||
let t = (sign(v) * ((params.C * abs(v)) + params.F));
|
||||
let f = (sign(v) * (pow(((params.A * abs(v)) + params.B), vec3<f32>(params.G)) + params.E));
|
||||
return select(f, t, cond);
|
||||
}
|
||||
|
||||
fn textureSampleExternal(plane0 : texture_2d<f32>, plane1 : texture_2d<f32>, smp : sampler, coord : vec2<f32>, params : ExternalTextureParams) -> vec4<f32> {
|
||||
var color : vec3<f32>;
|
||||
if ((params.numPlanes == 1u)) {
|
||||
@@ -851,6 +1170,9 @@ fn textureSampleExternal(plane0 : texture_2d<f32>, plane1 : texture_2d<f32>, smp
|
||||
} else {
|
||||
color = (vec4<f32>(textureSampleLevel(plane0, smp, coord, 0.0).r, textureSampleLevel(plane1, smp, coord, 0.0).rg, 1.0) * params.yuvToRgbConversionMatrix);
|
||||
}
|
||||
color = gammaCorrection(color, params.gammaDecodeParams);
|
||||
color = (params.gamutConversionMatrix * color);
|
||||
color = gammaCorrection(color, params.gammaEncodeParams);
|
||||
return vec4<f32>(color, 1.0);
|
||||
}
|
||||
|
||||
@@ -897,15 +1219,36 @@ fn main() {
|
||||
)";
|
||||
|
||||
auto* expect = R"(
|
||||
struct GammaTransferParams {
|
||||
G : f32,
|
||||
A : f32,
|
||||
B : f32,
|
||||
C : f32,
|
||||
D : f32,
|
||||
E : f32,
|
||||
F : f32,
|
||||
padding : u32,
|
||||
}
|
||||
|
||||
struct ExternalTextureParams {
|
||||
numPlanes : u32,
|
||||
yuvToRgbConversionMatrix : mat3x4<f32>,
|
||||
gammaDecodeParams : GammaTransferParams,
|
||||
gammaEncodeParams : GammaTransferParams,
|
||||
gamutConversionMatrix : mat3x3<f32>,
|
||||
}
|
||||
|
||||
@group(0) @binding(2) var ext_tex_plane_1 : texture_2d<f32>;
|
||||
|
||||
@group(0) @binding(3) var<uniform> ext_tex_params : ExternalTextureParams;
|
||||
|
||||
fn gammaCorrection(v : vec3<f32>, params : GammaTransferParams) -> vec3<f32> {
|
||||
let cond = (abs(v) < vec3<f32>(params.D));
|
||||
let t = (sign(v) * ((params.C * abs(v)) + params.F));
|
||||
let f = (sign(v) * (pow(((params.A * abs(v)) + params.B), vec3<f32>(params.G)) + params.E));
|
||||
return select(f, t, cond);
|
||||
}
|
||||
|
||||
fn textureSampleExternal(plane0 : texture_2d<f32>, plane1 : texture_2d<f32>, smp : sampler, coord : vec2<f32>, params : ExternalTextureParams) -> vec4<f32> {
|
||||
var color : vec3<f32>;
|
||||
if ((params.numPlanes == 1u)) {
|
||||
@@ -913,6 +1256,9 @@ fn textureSampleExternal(plane0 : texture_2d<f32>, plane1 : texture_2d<f32>, smp
|
||||
} else {
|
||||
color = (vec4<f32>(textureSampleLevel(plane0, smp, coord, 0.0).r, textureSampleLevel(plane1, smp, coord, 0.0).rg, 1.0) * params.yuvToRgbConversionMatrix);
|
||||
}
|
||||
color = gammaCorrection(color, params.gammaDecodeParams);
|
||||
color = (params.gamutConversionMatrix * color);
|
||||
color = gammaCorrection(color, params.gammaEncodeParams);
|
||||
return vec4<f32>(color, 1.0);
|
||||
}
|
||||
|
||||
@@ -965,15 +1311,36 @@ fn main() {
|
||||
)";
|
||||
|
||||
auto* expect = R"(
|
||||
struct GammaTransferParams {
|
||||
G : f32,
|
||||
A : f32,
|
||||
B : f32,
|
||||
C : f32,
|
||||
D : f32,
|
||||
E : f32,
|
||||
F : f32,
|
||||
padding : u32,
|
||||
}
|
||||
|
||||
struct ExternalTextureParams {
|
||||
numPlanes : u32,
|
||||
yuvToRgbConversionMatrix : mat3x4<f32>,
|
||||
gammaDecodeParams : GammaTransferParams,
|
||||
gammaEncodeParams : GammaTransferParams,
|
||||
gamutConversionMatrix : mat3x3<f32>,
|
||||
}
|
||||
|
||||
@group(0) @binding(2) var ext_tex_plane_1 : texture_2d<f32>;
|
||||
|
||||
@group(0) @binding(3) var<uniform> ext_tex_params : ExternalTextureParams;
|
||||
|
||||
fn gammaCorrection(v : vec3<f32>, params : GammaTransferParams) -> vec3<f32> {
|
||||
let cond = (abs(v) < vec3<f32>(params.D));
|
||||
let t = (sign(v) * ((params.C * abs(v)) + params.F));
|
||||
let f = (sign(v) * (pow(((params.A * abs(v)) + params.B), vec3<f32>(params.G)) + params.E));
|
||||
return select(f, t, cond);
|
||||
}
|
||||
|
||||
fn textureSampleExternal(plane0 : texture_2d<f32>, plane1 : texture_2d<f32>, smp : sampler, coord : vec2<f32>, params : ExternalTextureParams) -> vec4<f32> {
|
||||
var color : vec3<f32>;
|
||||
if ((params.numPlanes == 1u)) {
|
||||
@@ -981,6 +1348,9 @@ fn textureSampleExternal(plane0 : texture_2d<f32>, plane1 : texture_2d<f32>, smp
|
||||
} else {
|
||||
color = (vec4<f32>(textureSampleLevel(plane0, smp, coord, 0.0).r, textureSampleLevel(plane1, smp, coord, 0.0).rg, 1.0) * params.yuvToRgbConversionMatrix);
|
||||
}
|
||||
color = gammaCorrection(color, params.gammaDecodeParams);
|
||||
color = (params.gamutConversionMatrix * color);
|
||||
color = gammaCorrection(color, params.gammaEncodeParams);
|
||||
return vec4<f32>(color, 1.0);
|
||||
}
|
||||
|
||||
@@ -1021,9 +1391,23 @@ fn f(ext_tex : texture_external) -> vec2<i32> {
|
||||
)";
|
||||
|
||||
auto* expect = R"(
|
||||
struct GammaTransferParams {
|
||||
G : f32,
|
||||
A : f32,
|
||||
B : f32,
|
||||
C : f32,
|
||||
D : f32,
|
||||
E : f32,
|
||||
F : f32,
|
||||
padding : u32,
|
||||
}
|
||||
|
||||
struct ExternalTextureParams {
|
||||
numPlanes : u32,
|
||||
yuvToRgbConversionMatrix : mat3x4<f32>,
|
||||
gammaDecodeParams : GammaTransferParams,
|
||||
gammaEncodeParams : GammaTransferParams,
|
||||
gamutConversionMatrix : mat3x3<f32>,
|
||||
}
|
||||
|
||||
fn f(ext_tex : texture_2d<f32>, ext_tex_plane_1 : texture_2d<f32>, ext_tex_params : ExternalTextureParams) -> vec2<i32> {
|
||||
@@ -1057,9 +1441,23 @@ fn main() {
|
||||
)";
|
||||
|
||||
auto* expect = R"(
|
||||
struct GammaTransferParams {
|
||||
G : f32,
|
||||
A : f32,
|
||||
B : f32,
|
||||
C : f32,
|
||||
D : f32,
|
||||
E : f32,
|
||||
F : f32,
|
||||
padding : u32,
|
||||
}
|
||||
|
||||
struct ExternalTextureParams {
|
||||
numPlanes : u32,
|
||||
yuvToRgbConversionMatrix : mat3x4<f32>,
|
||||
gammaDecodeParams : GammaTransferParams,
|
||||
gammaEncodeParams : GammaTransferParams,
|
||||
gamutConversionMatrix : mat3x3<f32>,
|
||||
}
|
||||
|
||||
@group(0) @binding(2) var ext_tex_plane_1 : texture_2d<f32>;
|
||||
@@ -1068,6 +1466,13 @@ struct ExternalTextureParams {
|
||||
|
||||
type ET = texture_external;
|
||||
|
||||
fn gammaCorrection(v : vec3<f32>, params : GammaTransferParams) -> vec3<f32> {
|
||||
let cond = (abs(v) < vec3<f32>(params.D));
|
||||
let t = (sign(v) * ((params.C * abs(v)) + params.F));
|
||||
let f = (sign(v) * (pow(((params.A * abs(v)) + params.B), vec3<f32>(params.G)) + params.E));
|
||||
return select(f, t, cond);
|
||||
}
|
||||
|
||||
fn textureSampleExternal(plane0 : texture_2d<f32>, plane1 : texture_2d<f32>, smp : sampler, coord : vec2<f32>, params : ExternalTextureParams) -> vec4<f32> {
|
||||
var color : vec3<f32>;
|
||||
if ((params.numPlanes == 1u)) {
|
||||
@@ -1075,6 +1480,9 @@ fn textureSampleExternal(plane0 : texture_2d<f32>, plane1 : texture_2d<f32>, smp
|
||||
} else {
|
||||
color = (vec4<f32>(textureSampleLevel(plane0, smp, coord, 0.0).r, textureSampleLevel(plane1, smp, coord, 0.0).rg, 1.0) * params.yuvToRgbConversionMatrix);
|
||||
}
|
||||
color = gammaCorrection(color, params.gammaDecodeParams);
|
||||
color = (params.gamutConversionMatrix * color);
|
||||
color = gammaCorrection(color, params.gammaEncodeParams);
|
||||
return vec4<f32>(color, 1.0);
|
||||
}
|
||||
|
||||
@@ -1119,9 +1527,23 @@ type ET = texture_external;
|
||||
)";
|
||||
|
||||
auto* expect = R"(
|
||||
struct GammaTransferParams {
|
||||
G : f32,
|
||||
A : f32,
|
||||
B : f32,
|
||||
C : f32,
|
||||
D : f32,
|
||||
E : f32,
|
||||
F : f32,
|
||||
padding : u32,
|
||||
}
|
||||
|
||||
struct ExternalTextureParams {
|
||||
numPlanes : u32,
|
||||
yuvToRgbConversionMatrix : mat3x4<f32>,
|
||||
gammaDecodeParams : GammaTransferParams,
|
||||
gammaEncodeParams : GammaTransferParams,
|
||||
gamutConversionMatrix : mat3x3<f32>,
|
||||
}
|
||||
|
||||
@group(0) @binding(2) var ext_tex_plane_1 : texture_2d<f32>;
|
||||
@@ -1133,6 +1555,13 @@ fn main() {
|
||||
f(ext_tex, ext_tex_plane_1, ext_tex_params, smp);
|
||||
}
|
||||
|
||||
fn gammaCorrection(v : vec3<f32>, params : GammaTransferParams) -> vec3<f32> {
|
||||
let cond = (abs(v) < vec3<f32>(params.D));
|
||||
let t = (sign(v) * ((params.C * abs(v)) + params.F));
|
||||
let f = (sign(v) * (pow(((params.A * abs(v)) + params.B), vec3<f32>(params.G)) + params.E));
|
||||
return select(f, t, cond);
|
||||
}
|
||||
|
||||
fn textureSampleExternal(plane0 : texture_2d<f32>, plane1 : texture_2d<f32>, smp : sampler, coord : vec2<f32>, params : ExternalTextureParams) -> vec4<f32> {
|
||||
var color : vec3<f32>;
|
||||
if ((params.numPlanes == 1u)) {
|
||||
@@ -1140,6 +1569,9 @@ fn textureSampleExternal(plane0 : texture_2d<f32>, plane1 : texture_2d<f32>, smp
|
||||
} else {
|
||||
color = (vec4<f32>(textureSampleLevel(plane0, smp, coord, 0.0).r, textureSampleLevel(plane1, smp, coord, 0.0).rg, 1.0) * params.yuvToRgbConversionMatrix);
|
||||
}
|
||||
color = gammaCorrection(color, params.gammaDecodeParams);
|
||||
color = (params.gamutConversionMatrix * color);
|
||||
color = gammaCorrection(color, params.gammaEncodeParams);
|
||||
return vec4<f32>(color, 1.0);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user