diff --git a/src/tint/writer/glsl/generator_impl.cc b/src/tint/writer/glsl/generator_impl.cc index 0df3c2cfec..8091e37b07 100644 --- a/src/tint/writer/glsl/generator_impl.cc +++ b/src/tint/writer/glsl/generator_impl.cc @@ -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(); @@ -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; } } diff --git a/src/tint/writer/glsl/generator_impl_builtin_texture_test.cc b/src/tint/writer/glsl/generator_impl_builtin_texture_test.cc index f06aee7d78..9735ee87c3 100644 --- a/src/tint/writer/glsl/generator_impl_builtin_texture_test.cc +++ b/src/tint/writer/glsl/generator_impl_builtin_texture_test.cc @@ -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: diff --git a/test/tint/builtins/gen/textureDimensions/ba1481.wgsl.expected.glsl b/test/tint/builtins/gen/textureDimensions/ba1481.wgsl.expected.glsl index d158448065..52dc125a27 100644 --- a/test/tint/builtins/gen/textureDimensions/ba1481.wgsl.expected.glsl +++ b/test/tint/builtins/gen/textureDimensions/ba1481.wgsl.expected.glsl @@ -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. ******************************************************************** diff --git a/test/tint/builtins/gen/textureLoad/8acf41.wgsl.expected.glsl b/test/tint/builtins/gen/textureLoad/8acf41.wgsl.expected.glsl index d158448065..52dc125a27 100644 --- a/test/tint/builtins/gen/textureLoad/8acf41.wgsl.expected.glsl +++ b/test/tint/builtins/gen/textureLoad/8acf41.wgsl.expected.glsl @@ -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. ******************************************************************** diff --git a/test/tint/builtins/gen/textureSampleLevel/02be59.wgsl.expected.glsl b/test/tint/builtins/gen/textureSampleLevel/02be59.wgsl.expected.glsl index 73e17ed535..cd1f4da812 100644 --- a/test/tint/builtins/gen/textureSampleLevel/02be59.wgsl.expected.glsl +++ b/test/tint/builtins/gen/textureSampleLevel/02be59.wgsl.expected.glsl @@ -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. - - - diff --git a/test/tint/builtins/gen/textureSampleLevel/1b0291.wgsl.expected.glsl b/test/tint/builtins/gen/textureSampleLevel/1b0291.wgsl.expected.glsl index 09bec155ec..b6aa9de4cf 100644 --- a/test/tint/builtins/gen/textureSampleLevel/1b0291.wgsl.expected.glsl +++ b/test/tint/builtins/gen/textureSampleLevel/1b0291.wgsl.expected.glsl @@ -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() { diff --git a/test/tint/builtins/gen/textureSampleLevel/1bf73e.wgsl.expected.glsl b/test/tint/builtins/gen/textureSampleLevel/1bf73e.wgsl.expected.glsl index 64e0b8328e..277310c62f 100644 --- a/test/tint/builtins/gen/textureSampleLevel/1bf73e.wgsl.expected.glsl +++ b/test/tint/builtins/gen/textureSampleLevel/1bf73e.wgsl.expected.glsl @@ -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() { diff --git a/test/tint/builtins/gen/textureSampleLevel/47daa4.wgsl.expected.glsl b/test/tint/builtins/gen/textureSampleLevel/47daa4.wgsl.expected.glsl index f5f4d2dbd2..bd35b5427b 100644 --- a/test/tint/builtins/gen/textureSampleLevel/47daa4.wgsl.expected.glsl +++ b/test/tint/builtins/gen/textureSampleLevel/47daa4.wgsl.expected.glsl @@ -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. - - - diff --git a/test/tint/builtins/gen/textureSampleLevel/979816.wgsl.expected.glsl b/test/tint/builtins/gen/textureSampleLevel/979816.wgsl.expected.glsl index d158448065..52dc125a27 100644 --- a/test/tint/builtins/gen/textureSampleLevel/979816.wgsl.expected.glsl +++ b/test/tint/builtins/gen/textureSampleLevel/979816.wgsl.expected.glsl @@ -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. ******************************************************************** diff --git a/test/tint/builtins/gen/textureSampleLevel/ae5e39.wgsl.expected.glsl b/test/tint/builtins/gen/textureSampleLevel/ae5e39.wgsl.expected.glsl index eea7343cf1..e36edf6a0b 100644 --- a/test/tint/builtins/gen/textureSampleLevel/ae5e39.wgsl.expected.glsl +++ b/test/tint/builtins/gen/textureSampleLevel/ae5e39.wgsl.expected.glsl @@ -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() { diff --git a/test/tint/builtins/gen/textureSampleLevel/ba93b3.wgsl.expected.glsl b/test/tint/builtins/gen/textureSampleLevel/ba93b3.wgsl.expected.glsl index 53360a26c2..5547d35086 100644 --- a/test/tint/builtins/gen/textureSampleLevel/ba93b3.wgsl.expected.glsl +++ b/test/tint/builtins/gen/textureSampleLevel/ba93b3.wgsl.expected.glsl @@ -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() { diff --git a/test/tint/unittest/reader/spirv/ImageSampleExplicitLod_DepthTexture_SpvParserHandleTest_SampledImageAccessTest_Variable_1.spvasm.expected.glsl b/test/tint/unittest/reader/spirv/ImageSampleExplicitLod_DepthTexture_SpvParserHandleTest_SampledImageAccessTest_Variable_1.spvasm.expected.glsl index b8afb19fca..946f2cd3de 100644 --- a/test/tint/unittest/reader/spirv/ImageSampleExplicitLod_DepthTexture_SpvParserHandleTest_SampledImageAccessTest_Variable_1.spvasm.expected.glsl +++ b/test/tint/unittest/reader/spirv/ImageSampleExplicitLod_DepthTexture_SpvParserHandleTest_SampledImageAccessTest_Variable_1.spvasm.expected.glsl @@ -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. - - -