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:
Stephen White 2022-03-02 14:07:02 +00:00 committed by Tint LUCI CQ
parent 17601930e4
commit 93f686617e
10 changed files with 42 additions and 168 deletions

View File

@ -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>()) {

View File

@ -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:

View File

@ -1,6 +1,6 @@
SKIP: FAILED
../../src/tint/writer/glsl/generator_impl.cc:2563 internal compiler error: Multiplanar external texture transform was not run.
../../src/tint/writer/glsl/generator_impl.cc:2569 internal compiler error: Multiplanar external texture transform was not run.
********************************************************************

View File

@ -1,11 +1,9 @@
SKIP: FAILED
#version 310 es
uniform highp samplerCubeShadow arg_0_arg_1;
void textureGatherCompare_182fd4() {
vec4 res = textureGather(arg_0_arg_1, vec4(0.0f, 0.0f, 0.0f, 1.0f));
vec4 res = textureGather(arg_0_arg_1, vec3(0.0f, 0.0f, 0.0f), 1.0f);
}
vec4 vertex_main() {
@ -20,21 +18,13 @@ void main() {
gl_Position.z = ((2.0f * gl_Position.z) - gl_Position.w);
return;
}
Error parsing GLSL shader:
ERROR: 0:6: 'textureGather' : no matching overloaded function found
ERROR: 0:6: '=' : cannot convert from ' const float' to ' temp highp 4-component vector of float'
ERROR: 0:6: '' : compilation terminated
ERROR: 3 compilation errors. No code generated.
#version 310 es
precision mediump float;
uniform highp samplerCubeShadow arg_0_arg_1;
void textureGatherCompare_182fd4() {
vec4 res = textureGather(arg_0_arg_1, vec4(0.0f, 0.0f, 0.0f, 1.0f));
vec4 res = textureGather(arg_0_arg_1, vec3(0.0f, 0.0f, 0.0f), 1.0f);
}
void fragment_main() {
@ -45,20 +35,12 @@ void main() {
fragment_main();
return;
}
Error parsing GLSL shader:
ERROR: 0:7: 'textureGather' : no matching overloaded function found
ERROR: 0:7: '=' : cannot convert from ' const float' to ' temp mediump 4-component vector of float'
ERROR: 0:7: '' : compilation terminated
ERROR: 3 compilation errors. No code generated.
#version 310 es
uniform highp samplerCubeShadow arg_0_arg_1;
void textureGatherCompare_182fd4() {
vec4 res = textureGather(arg_0_arg_1, vec4(0.0f, 0.0f, 0.0f, 1.0f));
vec4 res = textureGather(arg_0_arg_1, vec3(0.0f, 0.0f, 0.0f), 1.0f);
}
void compute_main() {
@ -70,11 +52,3 @@ void main() {
compute_main();
return;
}
Error parsing GLSL shader:
ERROR: 0:6: 'textureGather' : no matching overloaded function found
ERROR: 0:6: '=' : cannot convert from ' const float' to ' temp highp 4-component vector of float'
ERROR: 0:6: '' : compilation terminated
ERROR: 3 compilation errors. No code generated.

View File

@ -1,11 +1,9 @@
SKIP: FAILED
#version 310 es
uniform highp sampler2DShadow arg_0_arg_1;
void textureGatherCompare_6d9352() {
vec4 res = textureGather(arg_0_arg_1, vec3(0.0f, 0.0f, 1.0f));
vec4 res = textureGather(arg_0_arg_1, vec2(0.0f, 0.0f), 1.0f);
}
vec4 vertex_main() {
@ -20,21 +18,13 @@ void main() {
gl_Position.z = ((2.0f * gl_Position.z) - gl_Position.w);
return;
}
Error parsing GLSL shader:
ERROR: 0:6: 'textureGather' : no matching overloaded function found
ERROR: 0:6: '=' : cannot convert from ' const float' to ' temp highp 4-component vector of float'
ERROR: 0:6: '' : compilation terminated
ERROR: 3 compilation errors. No code generated.
#version 310 es
precision mediump float;
uniform highp sampler2DShadow arg_0_arg_1;
void textureGatherCompare_6d9352() {
vec4 res = textureGather(arg_0_arg_1, vec3(0.0f, 0.0f, 1.0f));
vec4 res = textureGather(arg_0_arg_1, vec2(0.0f, 0.0f), 1.0f);
}
void fragment_main() {
@ -45,20 +35,12 @@ void main() {
fragment_main();
return;
}
Error parsing GLSL shader:
ERROR: 0:7: 'textureGather' : no matching overloaded function found
ERROR: 0:7: '=' : cannot convert from ' const float' to ' temp mediump 4-component vector of float'
ERROR: 0:7: '' : compilation terminated
ERROR: 3 compilation errors. No code generated.
#version 310 es
uniform highp sampler2DShadow arg_0_arg_1;
void textureGatherCompare_6d9352() {
vec4 res = textureGather(arg_0_arg_1, vec3(0.0f, 0.0f, 1.0f));
vec4 res = textureGather(arg_0_arg_1, vec2(0.0f, 0.0f), 1.0f);
}
void compute_main() {
@ -70,11 +52,3 @@ void main() {
compute_main();
return;
}
Error parsing GLSL shader:
ERROR: 0:6: 'textureGather' : no matching overloaded function found
ERROR: 0:6: '=' : cannot convert from ' const float' to ' temp highp 4-component vector of float'
ERROR: 0:6: '' : compilation terminated
ERROR: 3 compilation errors. No code generated.

View File

@ -1,11 +1,9 @@
SKIP: FAILED
#version 310 es
uniform highp sampler2DArrayShadow arg_0_arg_1;
void textureGatherCompare_6f1267() {
vec4 res = textureGatherOffset(arg_0_arg_1, vec4(0.0f, 0.0f, float(1), 1.0f), ivec2(0, 0));
vec4 res = textureGatherOffset(arg_0_arg_1, vec3(0.0f, 0.0f, float(1)), 1.0f, ivec2(0, 0));
}
vec4 vertex_main() {
@ -20,21 +18,13 @@ void main() {
gl_Position.z = ((2.0f * gl_Position.z) - gl_Position.w);
return;
}
Error parsing GLSL shader:
ERROR: 0:6: 'textureGatherOffset' : no matching overloaded function found
ERROR: 0:6: '=' : cannot convert from ' const float' to ' temp highp 4-component vector of float'
ERROR: 0:6: '' : compilation terminated
ERROR: 3 compilation errors. No code generated.
#version 310 es
precision mediump float;
uniform highp sampler2DArrayShadow arg_0_arg_1;
void textureGatherCompare_6f1267() {
vec4 res = textureGatherOffset(arg_0_arg_1, vec4(0.0f, 0.0f, float(1), 1.0f), ivec2(0, 0));
vec4 res = textureGatherOffset(arg_0_arg_1, vec3(0.0f, 0.0f, float(1)), 1.0f, ivec2(0, 0));
}
void fragment_main() {
@ -45,20 +35,12 @@ void main() {
fragment_main();
return;
}
Error parsing GLSL shader:
ERROR: 0:7: 'textureGatherOffset' : no matching overloaded function found
ERROR: 0:7: '=' : cannot convert from ' const float' to ' temp mediump 4-component vector of float'
ERROR: 0:7: '' : compilation terminated
ERROR: 3 compilation errors. No code generated.
#version 310 es
uniform highp sampler2DArrayShadow arg_0_arg_1;
void textureGatherCompare_6f1267() {
vec4 res = textureGatherOffset(arg_0_arg_1, vec4(0.0f, 0.0f, float(1), 1.0f), ivec2(0, 0));
vec4 res = textureGatherOffset(arg_0_arg_1, vec3(0.0f, 0.0f, float(1)), 1.0f, ivec2(0, 0));
}
void compute_main() {
@ -70,11 +52,3 @@ void main() {
compute_main();
return;
}
Error parsing GLSL shader:
ERROR: 0:6: 'textureGatherOffset' : no matching overloaded function found
ERROR: 0:6: '=' : cannot convert from ' const float' to ' temp highp 4-component vector of float'
ERROR: 0:6: '' : compilation terminated
ERROR: 3 compilation errors. No code generated.

View File

@ -1,11 +1,9 @@
SKIP: FAILED
#version 310 es
uniform highp sampler2DArrayShadow arg_0_arg_1;
void textureGatherCompare_783e65() {
vec4 res = textureGather(arg_0_arg_1, vec4(0.0f, 0.0f, float(1), 1.0f));
vec4 res = textureGather(arg_0_arg_1, vec3(0.0f, 0.0f, float(1)), 1.0f);
}
vec4 vertex_main() {
@ -20,21 +18,13 @@ void main() {
gl_Position.z = ((2.0f * gl_Position.z) - gl_Position.w);
return;
}
Error parsing GLSL shader:
ERROR: 0:6: 'textureGather' : no matching overloaded function found
ERROR: 0:6: '=' : cannot convert from ' const float' to ' temp highp 4-component vector of float'
ERROR: 0:6: '' : compilation terminated
ERROR: 3 compilation errors. No code generated.
#version 310 es
precision mediump float;
uniform highp sampler2DArrayShadow arg_0_arg_1;
void textureGatherCompare_783e65() {
vec4 res = textureGather(arg_0_arg_1, vec4(0.0f, 0.0f, float(1), 1.0f));
vec4 res = textureGather(arg_0_arg_1, vec3(0.0f, 0.0f, float(1)), 1.0f);
}
void fragment_main() {
@ -45,20 +35,12 @@ void main() {
fragment_main();
return;
}
Error parsing GLSL shader:
ERROR: 0:7: 'textureGather' : no matching overloaded function found
ERROR: 0:7: '=' : cannot convert from ' const float' to ' temp mediump 4-component vector of float'
ERROR: 0:7: '' : compilation terminated
ERROR: 3 compilation errors. No code generated.
#version 310 es
uniform highp sampler2DArrayShadow arg_0_arg_1;
void textureGatherCompare_783e65() {
vec4 res = textureGather(arg_0_arg_1, vec4(0.0f, 0.0f, float(1), 1.0f));
vec4 res = textureGather(arg_0_arg_1, vec3(0.0f, 0.0f, float(1)), 1.0f);
}
void compute_main() {
@ -70,11 +52,3 @@ void main() {
compute_main();
return;
}
Error parsing GLSL shader:
ERROR: 0:6: 'textureGather' : no matching overloaded function found
ERROR: 0:6: '=' : cannot convert from ' const float' to ' temp highp 4-component vector of float'
ERROR: 0:6: '' : compilation terminated
ERROR: 3 compilation errors. No code generated.

View File

@ -1,11 +1,9 @@
SKIP: FAILED
#version 310 es
uniform highp sampler2DShadow arg_0_arg_1;
void textureGatherCompare_a5f587() {
vec4 res = textureGatherOffset(arg_0_arg_1, vec3(0.0f, 0.0f, 1.0f), ivec2(0, 0));
vec4 res = textureGatherOffset(arg_0_arg_1, vec2(0.0f, 0.0f), 1.0f, ivec2(0, 0));
}
vec4 vertex_main() {
@ -20,21 +18,13 @@ void main() {
gl_Position.z = ((2.0f * gl_Position.z) - gl_Position.w);
return;
}
Error parsing GLSL shader:
ERROR: 0:6: 'textureGatherOffset' : no matching overloaded function found
ERROR: 0:6: '=' : cannot convert from ' const float' to ' temp highp 4-component vector of float'
ERROR: 0:6: '' : compilation terminated
ERROR: 3 compilation errors. No code generated.
#version 310 es
precision mediump float;
uniform highp sampler2DShadow arg_0_arg_1;
void textureGatherCompare_a5f587() {
vec4 res = textureGatherOffset(arg_0_arg_1, vec3(0.0f, 0.0f, 1.0f), ivec2(0, 0));
vec4 res = textureGatherOffset(arg_0_arg_1, vec2(0.0f, 0.0f), 1.0f, ivec2(0, 0));
}
void fragment_main() {
@ -45,20 +35,12 @@ void main() {
fragment_main();
return;
}
Error parsing GLSL shader:
ERROR: 0:7: 'textureGatherOffset' : no matching overloaded function found
ERROR: 0:7: '=' : cannot convert from ' const float' to ' temp mediump 4-component vector of float'
ERROR: 0:7: '' : compilation terminated
ERROR: 3 compilation errors. No code generated.
#version 310 es
uniform highp sampler2DShadow arg_0_arg_1;
void textureGatherCompare_a5f587() {
vec4 res = textureGatherOffset(arg_0_arg_1, vec3(0.0f, 0.0f, 1.0f), ivec2(0, 0));
vec4 res = textureGatherOffset(arg_0_arg_1, vec2(0.0f, 0.0f), 1.0f, ivec2(0, 0));
}
void compute_main() {
@ -70,11 +52,3 @@ void main() {
compute_main();
return;
}
Error parsing GLSL shader:
ERROR: 0:6: 'textureGatherOffset' : no matching overloaded function found
ERROR: 0:6: '=' : cannot convert from ' const float' to ' temp highp 4-component vector of float'
ERROR: 0:6: '' : compilation terminated
ERROR: 3 compilation errors. No code generated.

View File

@ -1,6 +1,6 @@
SKIP: FAILED
../../src/tint/writer/glsl/generator_impl.cc:2563 internal compiler error: Multiplanar external texture transform was not run.
../../src/tint/writer/glsl/generator_impl.cc:2569 internal compiler error: Multiplanar external texture transform was not run.
********************************************************************

View File

@ -1,6 +1,6 @@
SKIP: FAILED
../../src/tint/writer/glsl/generator_impl.cc:2563 internal compiler error: Multiplanar external texture transform was not run.
../../src/tint/writer/glsl/generator_impl.cc:2569 internal compiler error: Multiplanar external texture transform was not run.
********************************************************************