mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-21 10:49:14 +00:00
GLSL: fix textureGather() and textureGatherOffset() with depth textures.
Unlike other texture functions in GLSL, textureGather() and textureGatherOffset() do not expect the refZ value to be appended to the texture coordinates. It is passed as a regular argument. So append refZ to coordinates by default, and pass as a regular parameter only for the gather functions. Bug: tint:1459 Change-Id: Iad1255be3de5915aeff4adb9054479b9e92c45cb Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/82340 Reviewed-by: Ben Clayton <bclayton@google.com> Commit-Queue: Stephen White <senorblanco@chromium.org> Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
committed by
Tint LUCI CQ
parent
17601930e4
commit
93f686617e
@@ -1357,6 +1357,7 @@ bool GeneratorImpl::EmitTextureCall(std::ostream& out,
|
||||
}
|
||||
|
||||
uint32_t glsl_ret_width = 4u;
|
||||
bool append_depth_ref_to_coords = true;
|
||||
bool is_depth = texture_type->Is<sem::DepthTexture>();
|
||||
|
||||
switch (builtin->Type()) {
|
||||
@@ -1376,6 +1377,7 @@ bool GeneratorImpl::EmitTextureCall(std::ostream& out,
|
||||
case sem::BuiltinType::kTextureGather:
|
||||
case sem::BuiltinType::kTextureGatherCompare:
|
||||
out << "textureGather";
|
||||
append_depth_ref_to_coords = false;
|
||||
break;
|
||||
case sem::BuiltinType::kTextureSampleGrad:
|
||||
out << "textureGrad";
|
||||
@@ -1421,17 +1423,19 @@ bool GeneratorImpl::EmitTextureCall(std::ostream& out,
|
||||
param_coords =
|
||||
AppendVector(&builder_, param_coords, array_index)->Declaration();
|
||||
}
|
||||
bool is_cube_array = texture_type->dim() == ast::TextureDimension::kCubeArray;
|
||||
|
||||
// GLSL requires Dref to be appended to the coordinates, *unless* it's
|
||||
// samplerCubeArrayShadow, in which case it will be handled as a separate
|
||||
// parameter [1].
|
||||
if (is_depth && !is_cube_array) {
|
||||
// parameter.
|
||||
if (texture_type->dim() == ast::TextureDimension::kCubeArray) {
|
||||
append_depth_ref_to_coords = false;
|
||||
}
|
||||
|
||||
if (is_depth && append_depth_ref_to_coords) {
|
||||
if (auto* depth_ref = arg(Usage::kDepthRef)) {
|
||||
param_coords =
|
||||
AppendVector(&builder_, param_coords, depth_ref)->Declaration();
|
||||
} else if (builtin->Type() == sem::BuiltinType::kTextureSample ||
|
||||
builtin->Type() == sem::BuiltinType::kTextureSampleLevel) {
|
||||
} else {
|
||||
// Sampling a depth texture in GLSL always requires a depth reference, so
|
||||
// append zero here.
|
||||
auto* f32 = builder_.create<sem::F32>();
|
||||
@@ -1471,17 +1475,8 @@ bool GeneratorImpl::EmitTextureCall(std::ostream& out,
|
||||
out << ", 0.0";
|
||||
}
|
||||
|
||||
for (auto usage : {Usage::kOffset, Usage::kComponent, Usage::kBias}) {
|
||||
if (auto* e = arg(usage)) {
|
||||
out << ", ";
|
||||
if (!EmitExpression(out, e)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// [1] samplerCubeArrayShadow requires a separate depthRef parameter
|
||||
if (is_depth && is_cube_array) {
|
||||
if (is_depth && !append_depth_ref_to_coords) {
|
||||
if (auto* e = arg(Usage::kDepthRef)) {
|
||||
out << ", ";
|
||||
if (!EmitExpression(out, e)) {
|
||||
@@ -1492,6 +1487,15 @@ bool GeneratorImpl::EmitTextureCall(std::ostream& out,
|
||||
}
|
||||
}
|
||||
|
||||
for (auto usage : {Usage::kOffset, Usage::kComponent, Usage::kBias}) {
|
||||
if (auto* e = arg(usage)) {
|
||||
out << ", ";
|
||||
if (!EmitExpression(out, e)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
out << ")";
|
||||
|
||||
if (builtin->ReturnType()->Is<sem::Void>()) {
|
||||
|
||||
@@ -88,15 +88,15 @@ ExpectedResult expected_texture_overload(
|
||||
case ValidTextureOverload::kGatherDepthCubeArrayF32:
|
||||
return R"(textureGather(tint_symbol_sampler, vec4(1.0f, 2.0f, 3.0f, float(4)), 0.0))";
|
||||
case ValidTextureOverload::kGatherCompareDepth2dF32:
|
||||
return R"(textureGather(tint_symbol_sampler, vec3(1.0f, 2.0f, 3.0f))";
|
||||
return R"(textureGather(tint_symbol_sampler, vec2(1.0f, 2.0f), 3.0f))";
|
||||
case ValidTextureOverload::kGatherCompareDepth2dOffsetF32:
|
||||
return R"(textureGatherOffset(tint_symbol_sampler, vec3(1.0f, 2.0f, 3.0f), ivec2(4, 5)))";
|
||||
return R"(textureGatherOffset(tint_symbol_sampler, vec2(1.0f, 2.0f), 3.0f, ivec2(4, 5)))";
|
||||
case ValidTextureOverload::kGatherCompareDepth2dArrayF32:
|
||||
return R"(textureGather(tint_symbol_sampler, vec4(1.0f, 2.0f, float(3), 4.0f)))";
|
||||
return R"(textureGather(tint_symbol_sampler, vec3(1.0f, 2.0f, float(3)), 4.0f))";
|
||||
case ValidTextureOverload::kGatherCompareDepth2dArrayOffsetF32:
|
||||
return R"(textureGatherOffset(tint_symbol_sampler, vec4(1.0f, 2.0f, float(3), 4.0f), ivec2(5, 6)))";
|
||||
return R"(textureGatherOffset(tint_symbol_sampler, vec3(1.0f, 2.0f, float(3)), 4.0f, ivec2(5, 6)))";
|
||||
case ValidTextureOverload::kGatherCompareDepthCubeF32:
|
||||
return R"(textureGather(tint_symbol_sampler, vec4(1.0f, 2.0f, 3.0f, 4.0f)))";
|
||||
return R"(textureGather(tint_symbol_sampler, vec3(1.0f, 2.0f, 3.0f), 4.0f))";
|
||||
case ValidTextureOverload::kGatherCompareDepthCubeArrayF32:
|
||||
return R"(textureGather(tint_symbol_sampler, vec4(1.0f, 2.0f, 3.0f, float(4)), 5.0f))";
|
||||
case ValidTextureOverload::kNumLayers2dArray:
|
||||
|
||||
Reference in New Issue
Block a user