GLSL: clean up appending of depth reference.

Just a minor cleanup; no functional change.

Change-Id: Iac4f97c2b5507f7665024885a81f6ccf8e5ab269
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/82440
Reviewed-by: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Stephen White <senorblanco@chromium.org>
This commit is contained in:
Stephen White 2022-03-02 19:15:03 +00:00 committed by Tint LUCI CQ
parent ecb570ff64
commit 80fa1bbd56
5 changed files with 23 additions and 14 deletions

View File

@ -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<sem::F32>();
auto* sem_zero = builder_.create<sem::Expression>(
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<sem::F32>();
auto* zero = builder_.Expr(0.0f);
auto* stmt = builder_.Sem().Get(param_coords)->Stmt();
auto* sem_zero = builder_.create<sem::Expression>(
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)) {

View File

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

View File

@ -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.
********************************************************************

View File

@ -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.
********************************************************************

View File

@ -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.
********************************************************************