diff --git a/src/tint/writer/glsl/generator_impl.cc b/src/tint/writer/glsl/generator_impl.cc index 8091e37b07..fe42ee33ea 100644 --- a/src/tint/writer/glsl/generator_impl.cc +++ b/src/tint/writer/glsl/generator_impl.cc @@ -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(); 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(); @@ -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()) { 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 9735ee87c3..78d7267458 100644 --- a/src/tint/writer/glsl/generator_impl_builtin_texture_test.cc +++ b/src/tint/writer/glsl/generator_impl_builtin_texture_test.cc @@ -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: diff --git a/test/tint/builtins/gen/textureDimensions/ba1481.wgsl.expected.glsl b/test/tint/builtins/gen/textureDimensions/ba1481.wgsl.expected.glsl index 52dc125a27..31b244c822 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: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. ******************************************************************** diff --git a/test/tint/builtins/gen/textureGatherCompare/182fd4.wgsl.expected.glsl b/test/tint/builtins/gen/textureGatherCompare/182fd4.wgsl.expected.glsl index 703dc75603..c7830e501a 100644 --- a/test/tint/builtins/gen/textureGatherCompare/182fd4.wgsl.expected.glsl +++ b/test/tint/builtins/gen/textureGatherCompare/182fd4.wgsl.expected.glsl @@ -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. - - - diff --git a/test/tint/builtins/gen/textureGatherCompare/6d9352.wgsl.expected.glsl b/test/tint/builtins/gen/textureGatherCompare/6d9352.wgsl.expected.glsl index 723f83e4c9..48a5176a14 100644 --- a/test/tint/builtins/gen/textureGatherCompare/6d9352.wgsl.expected.glsl +++ b/test/tint/builtins/gen/textureGatherCompare/6d9352.wgsl.expected.glsl @@ -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. - - - diff --git a/test/tint/builtins/gen/textureGatherCompare/6f1267.wgsl.expected.glsl b/test/tint/builtins/gen/textureGatherCompare/6f1267.wgsl.expected.glsl index 4012e128fe..cd264dc7a7 100644 --- a/test/tint/builtins/gen/textureGatherCompare/6f1267.wgsl.expected.glsl +++ b/test/tint/builtins/gen/textureGatherCompare/6f1267.wgsl.expected.glsl @@ -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. - - - diff --git a/test/tint/builtins/gen/textureGatherCompare/783e65.wgsl.expected.glsl b/test/tint/builtins/gen/textureGatherCompare/783e65.wgsl.expected.glsl index 07f87a2795..7567fcd6d6 100644 --- a/test/tint/builtins/gen/textureGatherCompare/783e65.wgsl.expected.glsl +++ b/test/tint/builtins/gen/textureGatherCompare/783e65.wgsl.expected.glsl @@ -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. - - - diff --git a/test/tint/builtins/gen/textureGatherCompare/a5f587.wgsl.expected.glsl b/test/tint/builtins/gen/textureGatherCompare/a5f587.wgsl.expected.glsl index 890c346ef4..9cf8c889d5 100644 --- a/test/tint/builtins/gen/textureGatherCompare/a5f587.wgsl.expected.glsl +++ b/test/tint/builtins/gen/textureGatherCompare/a5f587.wgsl.expected.glsl @@ -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. - - - diff --git a/test/tint/builtins/gen/textureLoad/8acf41.wgsl.expected.glsl b/test/tint/builtins/gen/textureLoad/8acf41.wgsl.expected.glsl index 52dc125a27..31b244c822 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: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. ******************************************************************** diff --git a/test/tint/builtins/gen/textureSampleLevel/979816.wgsl.expected.glsl b/test/tint/builtins/gen/textureSampleLevel/979816.wgsl.expected.glsl index 52dc125a27..31b244c822 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: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. ********************************************************************