GLSL: fix textureSampleLevel() on depth textures.
Multiple bugs here: 1) Like texture(), GLSL's textureLod() on depth textures returns a scalar, and does not need to be swizzled. So set glsl_ret_width to 1 in that case. 2) Like texture(), GLSL's textureLod() always requires a Dref parameter, so append a zero if not present. 3) GLSL's "lod" parameter to textureLod() is always a float, unlike WGSL's textureSampleLevel() which is an i32 for depth textures, so cast it. Along the way, I discovered that textureLod() is not supported on samplerCubeShadow or sampler2DArrayShadow (even on Desktop GL). So some tests will never pass. Logged as https://crbug.com/dawn/1313 Bug: tint:1456 Change-Id: If67d8d288704142278d7a4e52b46e8010776f381 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/82300 Kokoro: Kokoro <noreply+kokoro@google.com> Reviewed-by: Ben Clayton <bclayton@google.com> Commit-Queue: Stephen White <senorblanco@chromium.org>
This commit is contained in:
parent
4acf466ff9
commit
17601930e4
|
@ -1369,6 +1369,9 @@ bool GeneratorImpl::EmitTextureCall(std::ostream& out,
|
|||
break;
|
||||
case sem::BuiltinType::kTextureSampleLevel:
|
||||
out << "textureLod";
|
||||
if (is_depth) {
|
||||
glsl_ret_width = 1u;
|
||||
}
|
||||
break;
|
||||
case sem::BuiltinType::kTextureGather:
|
||||
case sem::BuiltinType::kTextureGatherCompare:
|
||||
|
@ -1427,7 +1430,8 @@ bool GeneratorImpl::EmitTextureCall(std::ostream& out,
|
|||
if (auto* depth_ref = arg(Usage::kDepthRef)) {
|
||||
param_coords =
|
||||
AppendVector(&builder_, param_coords, depth_ref)->Declaration();
|
||||
} else if (builtin->Type() == sem::BuiltinType::kTextureSample) {
|
||||
} else if (builtin->Type() == sem::BuiltinType::kTextureSample ||
|
||||
builtin->Type() == sem::BuiltinType::kTextureSampleLevel) {
|
||||
// Sampling a depth texture in GLSL always requires a depth reference, so
|
||||
// append zero here.
|
||||
auto* f32 = builder_.create<sem::F32>();
|
||||
|
@ -1448,7 +1452,15 @@ bool GeneratorImpl::EmitTextureCall(std::ostream& out,
|
|||
Usage::kSampleIndex, Usage::kValue}) {
|
||||
if (auto* e = arg(usage)) {
|
||||
out << ", ";
|
||||
if (!EmitExpression(out, e)) {
|
||||
if (usage == Usage::kLevel && is_depth) {
|
||||
// WGSL's textureSampleLevel() "level" param is i32 for depth textures,
|
||||
// whereas GLSL's textureLod() "lod" param is always float, so cast it.
|
||||
out << "float(";
|
||||
if (!EmitExpression(out, e)) {
|
||||
return false;
|
||||
}
|
||||
out << ")";
|
||||
} else if (!EmitExpression(out, e)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -182,17 +182,17 @@ ExpectedResult expected_texture_overload(
|
|||
case ValidTextureOverload::kSampleLevelCubeArrayF32:
|
||||
return R"(textureLod(tint_symbol_sampler, vec4(1.0f, 2.0f, 3.0f, float(4)), 5.0f);)";
|
||||
case ValidTextureOverload::kSampleLevelDepth2dF32:
|
||||
return R"(textureLod(tint_symbol_sampler, vec2(1.0f, 2.0f), 3).x;)";
|
||||
return R"(textureLod(tint_symbol_sampler, vec3(1.0f, 2.0f, 0.0f), float(3));)";
|
||||
case ValidTextureOverload::kSampleLevelDepth2dOffsetF32:
|
||||
return R"(textureLodOffset(tint_symbol_sampler, vec2(1.0f, 2.0f), 3, ivec2(4, 5)).x;)";
|
||||
return R"(textureLodOffset(tint_symbol_sampler, vec3(1.0f, 2.0f, 0.0f), float(3), ivec2(4, 5));)";
|
||||
case ValidTextureOverload::kSampleLevelDepth2dArrayF32:
|
||||
return R"(textureLod(tint_symbol_sampler, vec3(1.0f, 2.0f, float(3)), 4).x;)";
|
||||
return R"(textureLod(tint_symbol_sampler, vec4(1.0f, 2.0f, float(3), 0.0f), float(4));)";
|
||||
case ValidTextureOverload::kSampleLevelDepth2dArrayOffsetF32:
|
||||
return R"(textureLodOffset(tint_symbol_sampler, vec3(1.0f, 2.0f, float(3)), 4, ivec2(5, 6)).x;)";
|
||||
return R"(textureLodOffset(tint_symbol_sampler, vec4(1.0f, 2.0f, float(3), 0.0f), float(4), ivec2(5, 6));)";
|
||||
case ValidTextureOverload::kSampleLevelDepthCubeF32:
|
||||
return R"(textureLod(tint_symbol_sampler, vec3(1.0f, 2.0f, 3.0f), 4).x;)";
|
||||
return R"(textureLod(tint_symbol_sampler, vec4(1.0f, 2.0f, 3.0f, 0.0f), float(4)))";
|
||||
case ValidTextureOverload::kSampleLevelDepthCubeArrayF32:
|
||||
return R"(textureLod(tint_symbol_sampler, vec4(1.0f, 2.0f, 3.0f, float(4)), 5).x;)";
|
||||
return R"(textureLod(tint_symbol_sampler, vec4(1.0f, 2.0f, 3.0f, float(4)), float(5));)";
|
||||
case ValidTextureOverload::kSampleGrad2dF32:
|
||||
return R"(textureGrad(tint_symbol_sampler, vec2(1.0f, 2.0f), vec2(3.0f, 4.0f), vec2(5.0f, 6.0f));)";
|
||||
case ValidTextureOverload::kSampleGrad2dOffsetF32:
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
SKIP: FAILED
|
||||
|
||||
../../src/tint/writer/glsl/generator_impl.cc:2553 internal compiler error: Multiplanar external texture transform was not run.
|
||||
../../src/tint/writer/glsl/generator_impl.cc:2563 internal compiler error: Multiplanar external texture transform was not run.
|
||||
|
||||
|
||||
********************************************************************
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
SKIP: FAILED
|
||||
|
||||
../../src/tint/writer/glsl/generator_impl.cc:2553 internal compiler error: Multiplanar external texture transform was not run.
|
||||
../../src/tint/writer/glsl/generator_impl.cc:2563 internal compiler error: Multiplanar external texture transform was not run.
|
||||
|
||||
|
||||
********************************************************************
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
SKIP: FAILED
|
||||
|
||||
#version 310 es
|
||||
|
||||
uniform highp sampler2DShadow arg_0_arg_1;
|
||||
|
||||
void textureSampleLevel_02be59() {
|
||||
float res = textureLod(arg_0_arg_1, vec2(0.0f, 0.0f), 0).x;
|
||||
float res = textureLod(arg_0_arg_1, vec3(0.0f, 0.0f, 0.0f), float(0));
|
||||
}
|
||||
|
||||
vec4 vertex_main() {
|
||||
|
@ -20,20 +18,13 @@ void main() {
|
|||
gl_Position.z = ((2.0f * gl_Position.z) - gl_Position.w);
|
||||
return;
|
||||
}
|
||||
Error parsing GLSL shader:
|
||||
ERROR: 0:6: 'textureLod' : no matching overloaded function found
|
||||
ERROR: 0:6: '' : compilation terminated
|
||||
ERROR: 2 compilation errors. No code generated.
|
||||
|
||||
|
||||
|
||||
#version 310 es
|
||||
precision mediump float;
|
||||
|
||||
uniform highp sampler2DShadow arg_0_arg_1;
|
||||
|
||||
void textureSampleLevel_02be59() {
|
||||
float res = textureLod(arg_0_arg_1, vec2(0.0f, 0.0f), 0).x;
|
||||
float res = textureLod(arg_0_arg_1, vec3(0.0f, 0.0f, 0.0f), float(0));
|
||||
}
|
||||
|
||||
void fragment_main() {
|
||||
|
@ -44,19 +35,12 @@ void main() {
|
|||
fragment_main();
|
||||
return;
|
||||
}
|
||||
Error parsing GLSL shader:
|
||||
ERROR: 0:7: 'textureLod' : no matching overloaded function found
|
||||
ERROR: 0:7: '' : compilation terminated
|
||||
ERROR: 2 compilation errors. No code generated.
|
||||
|
||||
|
||||
|
||||
#version 310 es
|
||||
|
||||
uniform highp sampler2DShadow arg_0_arg_1;
|
||||
|
||||
void textureSampleLevel_02be59() {
|
||||
float res = textureLod(arg_0_arg_1, vec2(0.0f, 0.0f), 0).x;
|
||||
float res = textureLod(arg_0_arg_1, vec3(0.0f, 0.0f, 0.0f), float(0));
|
||||
}
|
||||
|
||||
void compute_main() {
|
||||
|
@ -68,10 +52,3 @@ void main() {
|
|||
compute_main();
|
||||
return;
|
||||
}
|
||||
Error parsing GLSL shader:
|
||||
ERROR: 0:6: 'textureLod' : no matching overloaded function found
|
||||
ERROR: 0:6: '' : compilation terminated
|
||||
ERROR: 2 compilation errors. No code generated.
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ SKIP: FAILED
|
|||
uniform highp samplerCubeShadow arg_0_arg_1;
|
||||
|
||||
void textureSampleLevel_1b0291() {
|
||||
float res = textureLod(arg_0_arg_1, vec3(0.0f, 0.0f, 0.0f), 0).x;
|
||||
float res = textureLod(arg_0_arg_1, vec4(0.0f, 0.0f, 0.0f, 0.0f), float(0));
|
||||
}
|
||||
|
||||
vec4 vertex_main() {
|
||||
|
@ -33,7 +33,7 @@ precision mediump float;
|
|||
uniform highp samplerCubeShadow arg_0_arg_1;
|
||||
|
||||
void textureSampleLevel_1b0291() {
|
||||
float res = textureLod(arg_0_arg_1, vec3(0.0f, 0.0f, 0.0f), 0).x;
|
||||
float res = textureLod(arg_0_arg_1, vec4(0.0f, 0.0f, 0.0f, 0.0f), float(0));
|
||||
}
|
||||
|
||||
void fragment_main() {
|
||||
|
@ -56,7 +56,7 @@ ERROR: 2 compilation errors. No code generated.
|
|||
uniform highp samplerCubeShadow arg_0_arg_1;
|
||||
|
||||
void textureSampleLevel_1b0291() {
|
||||
float res = textureLod(arg_0_arg_1, vec3(0.0f, 0.0f, 0.0f), 0).x;
|
||||
float res = textureLod(arg_0_arg_1, vec4(0.0f, 0.0f, 0.0f, 0.0f), float(0));
|
||||
}
|
||||
|
||||
void compute_main() {
|
||||
|
|
|
@ -5,7 +5,7 @@ SKIP: FAILED
|
|||
uniform highp sampler2DArrayShadow arg_0_arg_1;
|
||||
|
||||
void textureSampleLevel_1bf73e() {
|
||||
float res = textureLod(arg_0_arg_1, vec3(0.0f, 0.0f, float(1)), 0).x;
|
||||
float res = textureLod(arg_0_arg_1, vec4(0.0f, 0.0f, float(1), 0.0f), float(0));
|
||||
}
|
||||
|
||||
vec4 vertex_main() {
|
||||
|
@ -33,7 +33,7 @@ precision mediump float;
|
|||
uniform highp sampler2DArrayShadow arg_0_arg_1;
|
||||
|
||||
void textureSampleLevel_1bf73e() {
|
||||
float res = textureLod(arg_0_arg_1, vec3(0.0f, 0.0f, float(1)), 0).x;
|
||||
float res = textureLod(arg_0_arg_1, vec4(0.0f, 0.0f, float(1), 0.0f), float(0));
|
||||
}
|
||||
|
||||
void fragment_main() {
|
||||
|
@ -56,7 +56,7 @@ ERROR: 2 compilation errors. No code generated.
|
|||
uniform highp sampler2DArrayShadow arg_0_arg_1;
|
||||
|
||||
void textureSampleLevel_1bf73e() {
|
||||
float res = textureLod(arg_0_arg_1, vec3(0.0f, 0.0f, float(1)), 0).x;
|
||||
float res = textureLod(arg_0_arg_1, vec4(0.0f, 0.0f, float(1), 0.0f), float(0));
|
||||
}
|
||||
|
||||
void compute_main() {
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
SKIP: FAILED
|
||||
|
||||
#version 310 es
|
||||
|
||||
uniform highp sampler2DShadow arg_0_arg_1;
|
||||
|
||||
void textureSampleLevel_47daa4() {
|
||||
float res = textureLodOffset(arg_0_arg_1, vec2(0.0f, 0.0f), 0, ivec2(0, 0)).x;
|
||||
float res = textureLodOffset(arg_0_arg_1, vec3(0.0f, 0.0f, 0.0f), float(0), ivec2(0, 0));
|
||||
}
|
||||
|
||||
vec4 vertex_main() {
|
||||
|
@ -20,20 +18,13 @@ void main() {
|
|||
gl_Position.z = ((2.0f * gl_Position.z) - gl_Position.w);
|
||||
return;
|
||||
}
|
||||
Error parsing GLSL shader:
|
||||
ERROR: 0:6: 'textureLodOffset' : no matching overloaded function found
|
||||
ERROR: 0:6: '' : compilation terminated
|
||||
ERROR: 2 compilation errors. No code generated.
|
||||
|
||||
|
||||
|
||||
#version 310 es
|
||||
precision mediump float;
|
||||
|
||||
uniform highp sampler2DShadow arg_0_arg_1;
|
||||
|
||||
void textureSampleLevel_47daa4() {
|
||||
float res = textureLodOffset(arg_0_arg_1, vec2(0.0f, 0.0f), 0, ivec2(0, 0)).x;
|
||||
float res = textureLodOffset(arg_0_arg_1, vec3(0.0f, 0.0f, 0.0f), float(0), ivec2(0, 0));
|
||||
}
|
||||
|
||||
void fragment_main() {
|
||||
|
@ -44,19 +35,12 @@ void main() {
|
|||
fragment_main();
|
||||
return;
|
||||
}
|
||||
Error parsing GLSL shader:
|
||||
ERROR: 0:7: 'textureLodOffset' : no matching overloaded function found
|
||||
ERROR: 0:7: '' : compilation terminated
|
||||
ERROR: 2 compilation errors. No code generated.
|
||||
|
||||
|
||||
|
||||
#version 310 es
|
||||
|
||||
uniform highp sampler2DShadow arg_0_arg_1;
|
||||
|
||||
void textureSampleLevel_47daa4() {
|
||||
float res = textureLodOffset(arg_0_arg_1, vec2(0.0f, 0.0f), 0, ivec2(0, 0)).x;
|
||||
float res = textureLodOffset(arg_0_arg_1, vec3(0.0f, 0.0f, 0.0f), float(0), ivec2(0, 0));
|
||||
}
|
||||
|
||||
void compute_main() {
|
||||
|
@ -68,10 +52,3 @@ void main() {
|
|||
compute_main();
|
||||
return;
|
||||
}
|
||||
Error parsing GLSL shader:
|
||||
ERROR: 0:6: 'textureLodOffset' : no matching overloaded function found
|
||||
ERROR: 0:6: '' : compilation terminated
|
||||
ERROR: 2 compilation errors. No code generated.
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
SKIP: FAILED
|
||||
|
||||
../../src/tint/writer/glsl/generator_impl.cc:2553 internal compiler error: Multiplanar external texture transform was not run.
|
||||
../../src/tint/writer/glsl/generator_impl.cc:2563 internal compiler error: Multiplanar external texture transform was not run.
|
||||
|
||||
|
||||
********************************************************************
|
||||
|
|
|
@ -5,7 +5,7 @@ SKIP: FAILED
|
|||
uniform highp samplerCubeArrayShadow arg_0_arg_1;
|
||||
|
||||
void textureSampleLevel_ae5e39() {
|
||||
float res = textureLod(arg_0_arg_1, vec4(0.0f, 0.0f, 0.0f, float(1)), 0).x;
|
||||
float res = textureLod(arg_0_arg_1, vec4(0.0f, 0.0f, 0.0f, float(1)), float(0));
|
||||
}
|
||||
|
||||
vec4 vertex_main() {
|
||||
|
@ -33,7 +33,7 @@ precision mediump float;
|
|||
uniform highp samplerCubeArrayShadow arg_0_arg_1;
|
||||
|
||||
void textureSampleLevel_ae5e39() {
|
||||
float res = textureLod(arg_0_arg_1, vec4(0.0f, 0.0f, 0.0f, float(1)), 0).x;
|
||||
float res = textureLod(arg_0_arg_1, vec4(0.0f, 0.0f, 0.0f, float(1)), float(0));
|
||||
}
|
||||
|
||||
void fragment_main() {
|
||||
|
@ -56,7 +56,7 @@ ERROR: 2 compilation errors. No code generated.
|
|||
uniform highp samplerCubeArrayShadow arg_0_arg_1;
|
||||
|
||||
void textureSampleLevel_ae5e39() {
|
||||
float res = textureLod(arg_0_arg_1, vec4(0.0f, 0.0f, 0.0f, float(1)), 0).x;
|
||||
float res = textureLod(arg_0_arg_1, vec4(0.0f, 0.0f, 0.0f, float(1)), float(0));
|
||||
}
|
||||
|
||||
void compute_main() {
|
||||
|
|
|
@ -5,7 +5,7 @@ SKIP: FAILED
|
|||
uniform highp sampler2DArrayShadow arg_0_arg_1;
|
||||
|
||||
void textureSampleLevel_ba93b3() {
|
||||
float res = textureLodOffset(arg_0_arg_1, vec3(0.0f, 0.0f, float(1)), 0, ivec2(0, 0)).x;
|
||||
float res = textureLodOffset(arg_0_arg_1, vec4(0.0f, 0.0f, float(1), 0.0f), float(0), ivec2(0, 0));
|
||||
}
|
||||
|
||||
vec4 vertex_main() {
|
||||
|
@ -33,7 +33,7 @@ precision mediump float;
|
|||
uniform highp sampler2DArrayShadow arg_0_arg_1;
|
||||
|
||||
void textureSampleLevel_ba93b3() {
|
||||
float res = textureLodOffset(arg_0_arg_1, vec3(0.0f, 0.0f, float(1)), 0, ivec2(0, 0)).x;
|
||||
float res = textureLodOffset(arg_0_arg_1, vec4(0.0f, 0.0f, float(1), 0.0f), float(0), ivec2(0, 0));
|
||||
}
|
||||
|
||||
void fragment_main() {
|
||||
|
@ -56,7 +56,7 @@ ERROR: 2 compilation errors. No code generated.
|
|||
uniform highp sampler2DArrayShadow arg_0_arg_1;
|
||||
|
||||
void textureSampleLevel_ba93b3() {
|
||||
float res = textureLodOffset(arg_0_arg_1, vec3(0.0f, 0.0f, float(1)), 0, ivec2(0, 0)).x;
|
||||
float res = textureLodOffset(arg_0_arg_1, vec4(0.0f, 0.0f, float(1), 0.0f), float(0), ivec2(0, 0));
|
||||
}
|
||||
|
||||
void compute_main() {
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
SKIP: FAILED
|
||||
|
||||
#version 310 es
|
||||
precision mediump float;
|
||||
|
||||
|
@ -23,7 +21,7 @@ void main_1() {
|
|||
vec2 coords12 = vf12;
|
||||
vec3 coords123 = vf123;
|
||||
vec4 coords1234 = vf1234;
|
||||
vec4 x_79 = vec4(textureLod(x_20_x_10, vf12, int(f1)).x, 0.0f, 0.0f, 0.0f);
|
||||
vec4 x_79 = vec4(textureLod(x_20_x_10, vec3(vf12, 0.0f), float(int(f1))), 0.0f, 0.0f, 0.0f);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -35,10 +33,3 @@ void main() {
|
|||
tint_symbol();
|
||||
return;
|
||||
}
|
||||
Error parsing GLSL shader:
|
||||
ERROR: 0:24: 'textureLod' : no matching overloaded function found
|
||||
ERROR: 0:24: '' : compilation terminated
|
||||
ERROR: 2 compilation errors. No code generated.
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue