diff --git a/src/tint/writer/glsl/generator_impl.cc b/src/tint/writer/glsl/generator_impl.cc index 4adbbc76d0..3c22dba5ad 100644 --- a/src/tint/writer/glsl/generator_impl.cc +++ b/src/tint/writer/glsl/generator_impl.cc @@ -1265,6 +1265,16 @@ bool GeneratorImpl::EmitBarrierCall(std::ostream& out, return true; } +const ast::Expression* GeneratorImpl::CreateF32Zero( + const sem::Statement* stmt) { + auto* zero = builder_.Expr(0.0f); + auto* f32 = builder_.create(); + auto* sem_zero = builder_.create( + zero, f32, stmt, sem::Constant{}, /* has_side_effects */ false); + builder_.Sem().Add(zero, sem_zero); + return zero; +} + bool GeneratorImpl::EmitTextureCall(std::ostream& out, const sem::Call* call, const sem::Builtin* builtin) { @@ -1446,20 +1456,14 @@ bool GeneratorImpl::EmitTextureCall(std::ostream& out, } 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 { + auto* depth_ref = arg(Usage::kDepthRef); + if (!depth_ref) { // Sampling a depth texture in GLSL always requires a depth reference, so // append zero here. - auto* f32 = builder_.create(); - auto* zero = builder_.Expr(0.0f); - auto* stmt = builder_.Sem().Get(param_coords)->Stmt(); - auto* sem_zero = builder_.create( - zero, f32, stmt, sem::Constant{}, /* has_side_effects */ false); - builder_.Sem().Add(zero, sem_zero); - param_coords = AppendVector(&builder_, param_coords, zero)->Declaration(); + depth_ref = CreateF32Zero(builder_.Sem().Get(param_coords)->Stmt()); } + param_coords = + AppendVector(&builder_, param_coords, depth_ref)->Declaration(); } if (!EmitExpression(out, param_coords)) { diff --git a/src/tint/writer/glsl/generator_impl.h b/src/tint/writer/glsl/generator_impl.h index 1a591a4651..791e54e802 100644 --- a/src/tint/writer/glsl/generator_impl.h +++ b/src/tint/writer/glsl/generator_impl.h @@ -191,6 +191,11 @@ class GeneratorImpl : public TextGenerator { /// @param expr the fma() expression /// @returns true if the expression is emitted bool EmitEmulatedFMA(std::ostream& out, const ast::CallExpression* expr); + /// Create a float literal zero AST node, and associated semantic nodes. + /// @param stmt the statement which will own the semantic expression node + /// @returns an AST expression representing 0.0f + const ast::Expression* CreateF32Zero(const sem::Statement* stmt); + /// Handles generating a call to a texture function (`textureSample`, /// `textureSampleGrad`, etc) /// @param out the output of the expression stream diff --git a/test/tint/builtins/gen/textureDimensions/ba1481.wgsl.expected.glsl b/test/tint/builtins/gen/textureDimensions/ba1481.wgsl.expected.glsl index 4b0b14516c..d14ef3cd8e 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:2582 internal compiler error: Multiplanar external texture transform was not run. +../../src/tint/writer/glsl/generator_impl.cc:2587 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 4b0b14516c..d14ef3cd8e 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:2582 internal compiler error: Multiplanar external texture transform was not run. +../../src/tint/writer/glsl/generator_impl.cc:2587 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 4b0b14516c..d14ef3cd8e 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:2582 internal compiler error: Multiplanar external texture transform was not run. +../../src/tint/writer/glsl/generator_impl.cc:2587 internal compiler error: Multiplanar external texture transform was not run. ********************************************************************