From af780816caee64fe2694352d233c0305ac812abc Mon Sep 17 00:00:00 2001 From: dan sinclair Date: Tue, 29 Sep 2020 23:57:03 +0000 Subject: [PATCH] [wgsl-writer] Emit constant_id decorations. This CL adds constant_id decorations to the WGSL writer. Bug: tint:152 Change-Id: I637d158c0ef4d0ace2ce70a6fb3cbe6f0b8b3b4e Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/29102 Commit-Queue: dan sinclair Reviewed-by: Ryan Harrison Reviewed-by: David Neto --- src/writer/wgsl/generator_impl.cc | 3 +++ src/writer/wgsl/generator_impl_variable_test.cc | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/writer/wgsl/generator_impl.cc b/src/writer/wgsl/generator_impl.cc index e13fe6b179..f78b99c457 100644 --- a/src/writer/wgsl/generator_impl.cc +++ b/src/writer/wgsl/generator_impl.cc @@ -29,6 +29,7 @@ #include "src/ast/call_expression.h" #include "src/ast/call_statement.h" #include "src/ast/case_statement.h" +#include "src/ast/constant_id_decoration.h" #include "src/ast/constructor_expression.h" #include "src/ast/continue_statement.h" #include "src/ast/decorated_variable.h" @@ -724,6 +725,8 @@ bool GeneratorImpl::EmitVariableDecorations(ast::DecoratedVariable* var) { out_ << "location(" << deco->AsLocation()->value() << ")"; } else if (deco->IsBuiltin()) { out_ << "builtin(" << deco->AsBuiltin()->value() << ")"; + } else if (deco->IsConstantId()) { + out_ << "constant_id(" << deco->AsConstantId()->value() << ")"; } else { error_ = "unknown variable decoration"; return false; diff --git a/src/writer/wgsl/generator_impl_variable_test.cc b/src/writer/wgsl/generator_impl_variable_test.cc index 6665a91489..1b72849d3e 100644 --- a/src/writer/wgsl/generator_impl_variable_test.cc +++ b/src/writer/wgsl/generator_impl_variable_test.cc @@ -17,6 +17,7 @@ #include "gtest/gtest.h" #include "src/ast/binding_decoration.h" #include "src/ast/builtin_decoration.h" +#include "src/ast/constant_id_decoration.h" #include "src/ast/decorated_variable.h" #include "src/ast/location_decoration.h" #include "src/ast/set_decoration.h" @@ -77,6 +78,7 @@ TEST_F(WgslGeneratorImplTest, EmitVariable_Decorated_Multiple) { decos.push_back(std::make_unique(0)); decos.push_back(std::make_unique(1)); decos.push_back(std::make_unique(2)); + decos.push_back(std::make_unique(42)); ast::DecoratedVariable dv; dv.set_name("a"); @@ -87,7 +89,7 @@ TEST_F(WgslGeneratorImplTest, EmitVariable_Decorated_Multiple) { ASSERT_TRUE(g.EmitVariable(&dv)) << g.error(); EXPECT_EQ( g.result(), - R"([[builtin(position), binding(0), set(1), location(2)]] var a : f32; + R"([[builtin(position), binding(0), set(1), location(2), constant_id(42)]] var a : f32; )"); }