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>
This commit is contained in:
Ben Clayton 2021-02-01 16:54:44 +00:00 committed by Commit Bot service account
parent 2e6a1bb396
commit 222e09735e
1 changed files with 9 additions and 8 deletions

View File

@ -64,14 +64,6 @@ Transform::Output EmitVertexPointSize::Run(const Program* in) {
});
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 @@ Transform::Output EmitVertexPointSize::Run(const Program* in) {
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();