EmitVertexPointSize: Don't share expressions between functions
AST nodes are syntax tree nodes, not semantic tree nodes.
The pointsize IdentifierExpression was being created once and used in multiple functions.
The type determiner assumes that expressions are not shared between functions (otherwise the same IdentifierExpression may end up resolving to two different types / semantic nodes based on scope).
Bug: tint:469
Fixed: tint:468
Change-Id: I4c85d25ee3fd333d14739b519d5ee6cda767d52e
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/39880
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
diff --git a/src/transform/emit_vertex_point_size.cc b/src/transform/emit_vertex_point_size.cc
index 67267e0..319d144 100644
--- a/src/transform/emit_vertex_point_size.cc
+++ b/src/transform/emit_vertex_point_size.cc
@@ -64,14 +64,6 @@
});
out.AST().AddGlobalVariable(pointsize_var);
- // Build the AST expression & statement for assigning pointsize one.
- auto* one = out.create<ast::ScalarConstructorExpression>(
- Source{}, out.create<ast::FloatLiteral>(Source{}, f32, 1.0f));
- auto* pointsize_ident = out.create<ast::IdentifierExpression>(
- Source{}, out.Symbols().Register(kPointSizeVar));
- auto* pointsize_assign =
- out.create<ast::AssignmentStatement>(Source{}, pointsize_ident, one);
-
// Add the pointsize assignment statement to the front of all vertex stages.
CloneContext(&out, in)
.ReplaceAll(
@@ -79,6 +71,15 @@
if (func->pipeline_stage() != ast::PipelineStage::kVertex) {
return nullptr; // Just clone func
}
+
+ // Build the AST expression & statement for assigning pointsize one.
+ auto* one = out.create<ast::ScalarConstructorExpression>(
+ Source{}, out.create<ast::FloatLiteral>(Source{}, f32, 1.0f));
+ auto* pointsize_ident = out.create<ast::IdentifierExpression>(
+ Source{}, out.Symbols().Register(kPointSizeVar));
+ auto* pointsize_assign = out.create<ast::AssignmentStatement>(
+ Source{}, pointsize_ident, one);
+
return CloneWithStatementsAtStart(ctx, func, {pointsize_assign});
})
.Clone();