From 7d152e0936b16e8258d3a4aeee6627c5212e909f Mon Sep 17 00:00:00 2001 From: dan sinclair Date: Mon, 11 Jan 2021 16:24:32 +0000 Subject: [PATCH] Use TestNamer in the SPIR-V backend. This CL updates the SPIR-V generation tests to use the TestNamer. Change-Id: I6a1d9a4c41f080ba3518509864bb06f1629ab0a9 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/36941 Reviewed-by: Ryan Harrison Reviewed-by: Ben Clayton --- src/writer/spirv/builder.cc | 4 +- src/writer/spirv/builder.h | 5 +- src/writer/spirv/builder_call_test.cc | 16 ++--- .../spirv/builder_function_decoration_test.cc | 30 +++++----- src/writer/spirv/builder_function_test.cc | 36 +++++------ .../spirv/builder_function_variable_test.cc | 14 ++--- .../spirv/builder_global_variable_test.cc | 60 +++++++++---------- .../spirv/builder_ident_expression_test.cc | 4 +- src/writer/spirv/builder_intrinsic_test.cc | 60 ++++++++++--------- .../spirv/builder_intrinsic_texture_test.cc | 4 +- src/writer/spirv/builder_switch_test.cc | 30 +++++----- src/writer/spirv/builder_type_test.cc | 40 ++++++------- src/writer/spirv/generator.cc | 6 +- src/writer/spirv/generator.h | 2 + src/writer/spirv/test_helper.h | 5 +- 15 files changed, 164 insertions(+), 152 deletions(-) diff --git a/src/writer/spirv/builder.cc b/src/writer/spirv/builder.cc index 071ceab58b..8736c59422 100644 --- a/src/writer/spirv/builder.cc +++ b/src/writer/spirv/builder.cc @@ -278,8 +278,8 @@ Builder::AccessorInfo::AccessorInfo() : source_id(0), source_type(nullptr) {} Builder::AccessorInfo::~AccessorInfo() {} -Builder::Builder(ast::Module* mod) - : mod_(mod), namer_(std::make_unique(mod)), scope_stack_({}) {} +Builder::Builder(ast::Module* mod, Namer* namer) + : mod_(mod), namer_(namer), scope_stack_({}) {} Builder::~Builder() = default; diff --git a/src/writer/spirv/builder.h b/src/writer/spirv/builder.h index 900af2018d..2c2c38d6a7 100644 --- a/src/writer/spirv/builder.h +++ b/src/writer/spirv/builder.h @@ -85,7 +85,8 @@ class Builder { /// Constructor /// @param mod the module to generate from - explicit Builder(ast::Module* mod); + /// @param namer the namer to use + Builder(ast::Module* mod, Namer* namer); ~Builder(); /// Generates the SPIR-V instructions for the given module @@ -491,7 +492,7 @@ class Builder { Operand result_op(); ast::Module* mod_; - std::unique_ptr namer_; + Namer* namer_ = nullptr; std::string error_; uint32_t next_id_ = 1; uint32_t current_label_id_ = 0; diff --git a/src/writer/spirv/builder_call_test.cc b/src/writer/spirv/builder_call_test.cc index 51d9e9f814..9a4cd8e400 100644 --- a/src/writer/spirv/builder_call_test.cc +++ b/src/writer/spirv/builder_call_test.cc @@ -61,10 +61,10 @@ TEST_F(BuilderTest, Expression_Call) { ASSERT_TRUE(b.GenerateFunction(func)) << b.error(); EXPECT_EQ(b.GenerateCallExpression(expr), 14u) << b.error(); - EXPECT_EQ(DumpBuilder(b), R"(OpName %3 "a_func" -OpName %4 "a" -OpName %5 "b" -OpName %12 "main" + EXPECT_EQ(DumpBuilder(b), R"(OpName %3 "test_a_func" +OpName %4 "test_a" +OpName %5 "test_b" +OpName %12 "test_main" %2 = OpTypeFloat 32 %1 = OpTypeFunction %2 %2 %2 %11 = OpTypeVoid @@ -110,10 +110,10 @@ TEST_F(BuilderTest, Statement_Call) { ASSERT_TRUE(b.GenerateFunction(func)) << b.error(); EXPECT_TRUE(b.GenerateStatement(expr)) << b.error(); - EXPECT_EQ(DumpBuilder(b), R"(OpName %4 "a_func" -OpName %5 "a" -OpName %6 "b" -OpName %12 "main" + EXPECT_EQ(DumpBuilder(b), R"(OpName %4 "test_a_func" +OpName %5 "test_a" +OpName %6 "test_b" +OpName %12 "test_main" %2 = OpTypeVoid %3 = OpTypeFloat 32 %1 = OpTypeFunction %2 %3 %3 diff --git a/src/writer/spirv/builder_function_decoration_test.cc b/src/writer/spirv/builder_function_decoration_test.cc index 16189d6aac..639e6f706c 100644 --- a/src/writer/spirv/builder_function_decoration_test.cc +++ b/src/writer/spirv/builder_function_decoration_test.cc @@ -45,7 +45,7 @@ TEST_F(BuilderTest, FunctionDecoration_Stage) { ASSERT_TRUE(b.GenerateFunction(func)) << b.error(); EXPECT_EQ(DumpInstructions(b.entry_points()), - R"(OpEntryPoint Vertex %3 "main" + R"(OpEntryPoint Vertex %3 "test_main" )"); } @@ -105,10 +105,10 @@ TEST_F(BuilderTest, FunctionDecoration_Stage_WithUnusedInterfaceIds) { mod->AddGlobalVariable(v_wg); ASSERT_TRUE(b.GenerateFunction(func)) << b.error(); - EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "my_in" -OpName %4 "my_out" -OpName %7 "my_wg" -OpName %11 "main" + EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "test_my_in" +OpName %4 "test_my_out" +OpName %7 "test_my_wg" +OpName %11 "test_main" )"); EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeFloat 32 %2 = OpTypePointer Input %3 @@ -122,7 +122,7 @@ OpName %11 "main" %9 = OpTypeFunction %10 )"); EXPECT_EQ(DumpInstructions(b.entry_points()), - R"(OpEntryPoint Vertex %11 "main" + R"(OpEntryPoint Vertex %11 "test_main" )"); } @@ -158,10 +158,10 @@ TEST_F(BuilderTest, FunctionDecoration_Stage_WithUsedInterfaceIds) { mod->AddGlobalVariable(v_wg); ASSERT_TRUE(b.GenerateFunction(func)) << b.error(); - EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "my_in" -OpName %4 "my_out" -OpName %7 "my_wg" -OpName %11 "main" + EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "test_my_in" +OpName %4 "test_my_out" +OpName %7 "test_my_wg" +OpName %11 "test_main" )"); EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeFloat 32 %2 = OpTypePointer Input %3 @@ -175,7 +175,7 @@ OpName %11 "main" %9 = OpTypeFunction %10 )"); EXPECT_EQ(DumpInstructions(b.entry_points()), - R"(OpEntryPoint Vertex %11 "main" %4 %1 + R"(OpEntryPoint Vertex %11 "test_main" %4 %1 )"); } @@ -235,12 +235,12 @@ TEST_F(BuilderTest, FunctionDecoration_ExecutionMode_MultipleFragment) { ASSERT_TRUE(b.GenerateFunction(func1)) << b.error(); ASSERT_TRUE(b.GenerateFunction(func2)) << b.error(); EXPECT_EQ(DumpBuilder(b), - R"(OpEntryPoint Fragment %3 "main1" -OpEntryPoint Fragment %5 "main2" + R"(OpEntryPoint Fragment %3 "test_main1" +OpEntryPoint Fragment %5 "test_main2" OpExecutionMode %3 OriginUpperLeft OpExecutionMode %5 OriginUpperLeft -OpName %3 "main1" -OpName %5 "main2" +OpName %3 "test_main1" +OpName %5 "test_main2" %2 = OpTypeVoid %1 = OpTypeFunction %2 %3 = OpFunction %2 None %1 diff --git a/src/writer/spirv/builder_function_test.cc b/src/writer/spirv/builder_function_test.cc index a50017b674..69ebaee69c 100644 --- a/src/writer/spirv/builder_function_test.cc +++ b/src/writer/spirv/builder_function_test.cc @@ -50,7 +50,7 @@ TEST_F(BuilderTest, Function_Empty) { ast::FunctionDecorationList{}); ASSERT_TRUE(b.GenerateFunction(func)); - EXPECT_EQ(DumpBuilder(b), R"(OpName %3 "a_func" + EXPECT_EQ(DumpBuilder(b), R"(OpName %3 "test_a_func" %2 = OpTypeVoid %1 = OpTypeFunction %2 %3 = OpFunction %2 None %1 @@ -68,7 +68,7 @@ TEST_F(BuilderTest, Function_Terminator_Return) { ast::FunctionDecorationList{}); ASSERT_TRUE(b.GenerateFunction(func)); - EXPECT_EQ(DumpBuilder(b), R"(OpName %3 "a_func" + EXPECT_EQ(DumpBuilder(b), R"(OpName %3 "test_a_func" %2 = OpTypeVoid %1 = OpTypeFunction %2 %3 = OpFunction %2 None %1 @@ -89,8 +89,8 @@ TEST_F(BuilderTest, Function_Terminator_ReturnValue) { ASSERT_TRUE(td.DetermineFunction(func)) << td.error(); ASSERT_TRUE(b.GenerateGlobalVariable(var_a)) << b.error(); ASSERT_TRUE(b.GenerateFunction(func)) << b.error(); - EXPECT_EQ(DumpBuilder(b), R"(OpName %1 "a" -OpName %7 "a_func" + EXPECT_EQ(DumpBuilder(b), R"(OpName %1 "test_a" +OpName %7 "test_a_func" %3 = OpTypeFloat 32 %2 = OpTypePointer Private %3 %4 = OpConstantNull %3 @@ -113,7 +113,7 @@ TEST_F(BuilderTest, Function_Terminator_Discard) { ast::FunctionDecorationList{}); ASSERT_TRUE(b.GenerateFunction(func)); - EXPECT_EQ(DumpBuilder(b), R"(OpName %3 "a_func" + EXPECT_EQ(DumpBuilder(b), R"(OpName %3 "test_a_func" %2 = OpTypeVoid %1 = OpTypeFunction %2 %3 = OpFunction %2 None %1 @@ -136,9 +136,9 @@ TEST_F(BuilderTest, Function_WithParams) { EXPECT_TRUE(td.DetermineFunction(func)); ASSERT_TRUE(b.GenerateFunction(func)); - EXPECT_EQ(DumpBuilder(b), R"(OpName %4 "a_func" -OpName %5 "a" -OpName %6 "b" + EXPECT_EQ(DumpBuilder(b), R"(OpName %4 "test_a_func" +OpName %5 "test_a" +OpName %6 "test_b" %2 = OpTypeFloat 32 %3 = OpTypeInt 32 1 %1 = OpTypeFunction %2 %2 %3 @@ -160,7 +160,7 @@ TEST_F(BuilderTest, Function_WithBody) { ast::FunctionDecorationList{}); ASSERT_TRUE(b.GenerateFunction(func)); - EXPECT_EQ(DumpBuilder(b), R"(OpName %3 "a_func" + EXPECT_EQ(DumpBuilder(b), R"(OpName %3 "test_a_func" %2 = OpTypeVoid %1 = OpTypeFunction %2 %3 = OpFunction %2 None %1 @@ -269,17 +269,17 @@ TEST_F(BuilderTest, Emit_Multiple_EntryPoint_With_Same_ModuleVar) { ASSERT_TRUE(b.Build()); EXPECT_EQ(DumpBuilder(b), R"(OpCapability Shader OpMemoryModel Logical GLSL450 -OpEntryPoint GLCompute %7 "a" -OpEntryPoint GLCompute %17 "b" +OpEntryPoint GLCompute %7 "test_a" +OpEntryPoint GLCompute %17 "test_b" OpExecutionMode %7 LocalSize 1 1 1 OpExecutionMode %17 LocalSize 1 1 1 -OpName %3 "Data" -OpMemberName %3 0 "d" -OpName %1 "data" -OpName %7 "a" -OpName %14 "v" -OpName %17 "b" -OpName %21 "v" +OpName %3 "test_Data" +OpMemberName %3 0 "test_d" +OpName %1 "test_data" +OpName %7 "test_a" +OpName %14 "test_v" +OpName %17 "test_b" +OpName %21 "test_v" OpDecorate %3 Block OpMemberDecorate %3 0 Offset 0 OpDecorate %1 Binding 0 diff --git a/src/writer/spirv/builder_function_variable_test.cc b/src/writer/spirv/builder_function_variable_test.cc index fef4b90055..88ecc557c4 100644 --- a/src/writer/spirv/builder_function_variable_test.cc +++ b/src/writer/spirv/builder_function_variable_test.cc @@ -49,7 +49,7 @@ TEST_F(BuilderTest, FunctionVar_NoStorageClass) { b.push_function(Function{}); EXPECT_TRUE(b.GenerateFunctionVariable(v)) << b.error(); - EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "var" + EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "test_var" )"); EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeFloat 32 %2 = OpTypePointer Function %3 @@ -74,7 +74,7 @@ TEST_F(BuilderTest, FunctionVar_WithConstantConstructor) { EXPECT_TRUE(b.GenerateFunctionVariable(v)) << b.error(); ASSERT_FALSE(b.has_error()) << b.error(); - EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %6 "var" + EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %6 "test_var" )"); EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32 %1 = OpTypeVector %2 3 @@ -103,7 +103,7 @@ TEST_F(BuilderTest, FunctionVar_WithNonConstantConstructor) { EXPECT_TRUE(b.GenerateFunctionVariable(v)) << b.error(); ASSERT_FALSE(b.has_error()) << b.error(); - EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %7 "var" + EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %7 "test_var" )"); EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32 %1 = OpTypeVector %2 2 @@ -142,8 +142,8 @@ TEST_F(BuilderTest, FunctionVar_WithNonConstantConstructorLoadedFromVar) { EXPECT_TRUE(b.GenerateFunctionVariable(v2)) << b.error(); ASSERT_FALSE(b.has_error()) << b.error(); - EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %3 "v" -OpName %7 "v2" + EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %3 "test_v" +OpName %7 "test_v2" )"); EXPECT_EQ(DumpInstructions(b.types()), R"(%1 = OpTypeFloat 32 %2 = OpConstant %1 1 @@ -181,8 +181,8 @@ TEST_F(BuilderTest, FunctionVar_ConstWithVarInitializer) { EXPECT_TRUE(b.GenerateFunctionVariable(v2)) << b.error(); ASSERT_FALSE(b.has_error()) << b.error(); - EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %3 "v" -OpName %7 "v2" + EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %3 "test_v" +OpName %7 "test_v2" )"); EXPECT_EQ(DumpInstructions(b.types()), R"(%1 = OpTypeFloat 32 %2 = OpConstant %1 1 diff --git a/src/writer/spirv/builder_global_variable_test.cc b/src/writer/spirv/builder_global_variable_test.cc index 6d67e53e4b..dd2a76d7ed 100644 --- a/src/writer/spirv/builder_global_variable_test.cc +++ b/src/writer/spirv/builder_global_variable_test.cc @@ -52,7 +52,7 @@ using BuilderTest = TestHelper; TEST_F(BuilderTest, GlobalVar_NoStorageClass) { auto* v = Var("var", ast::StorageClass::kNone, ty.f32); EXPECT_TRUE(b.GenerateGlobalVariable(v)) << b.error(); - EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "var" + EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "test_var" )"); EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeFloat 32 %2 = OpTypePointer Private %3 @@ -64,7 +64,7 @@ TEST_F(BuilderTest, GlobalVar_NoStorageClass) { TEST_F(BuilderTest, GlobalVar_WithStorageClass) { auto* v = Var("var", ast::StorageClass::kOutput, ty.f32); EXPECT_TRUE(b.GenerateGlobalVariable(v)) << b.error(); - EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "var" + EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "test_var" )"); EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeFloat 32 %2 = OpTypePointer Output %3 @@ -76,7 +76,7 @@ TEST_F(BuilderTest, GlobalVar_WithStorageClass) { TEST_F(BuilderTest, GlobalVar_WithStorageClass_Input) { auto* v = Var("var", ast::StorageClass::kInput, ty.f32); EXPECT_TRUE(b.GenerateGlobalVariable(v)) << b.error(); - EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "var" + EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "test_var" )"); EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeFloat 32 %2 = OpTypePointer Input %3 @@ -95,7 +95,7 @@ TEST_F(BuilderTest, GlobalVar_WithConstructor) { EXPECT_TRUE(b.GenerateGlobalVariable(v)) << b.error(); ASSERT_FALSE(b.has_error()) << b.error(); - EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %6 "var" + EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %6 "test_var" )"); EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32 %1 = OpTypeVector %2 3 @@ -118,7 +118,7 @@ TEST_F(BuilderTest, GlobalVar_Const) { EXPECT_TRUE(b.GenerateGlobalVariable(v)) << b.error(); ASSERT_FALSE(b.has_error()) << b.error(); - EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %5 "var" + EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %5 "test_var" )"); EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32 %1 = OpTypeVector %2 3 @@ -183,7 +183,7 @@ TEST_F(BuilderTest, GlobalVar_WithLocation) { }); EXPECT_TRUE(b.GenerateGlobalVariable(v)) << b.error(); - EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "var" + EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "test_var" )"); EXPECT_EQ(DumpInstructions(b.annots()), R"(OpDecorate %1 Location 5 )"); @@ -202,7 +202,7 @@ TEST_F(BuilderTest, GlobalVar_WithBindingAndSet) { }); EXPECT_TRUE(b.GenerateGlobalVariable(v)) << b.error(); - EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "var" + EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "test_var" )"); EXPECT_EQ(DumpInstructions(b.annots()), R"(OpDecorate %1 Binding 2 OpDecorate %1 DescriptorSet 3 @@ -221,7 +221,7 @@ TEST_F(BuilderTest, GlobalVar_WithBuiltin) { }); EXPECT_TRUE(b.GenerateGlobalVariable(v)) << b.error(); - EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "var" + EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "test_var" )"); EXPECT_EQ(DumpInstructions(b.annots()), R"(OpDecorate %1 BuiltIn Position )"); @@ -239,7 +239,7 @@ TEST_F(BuilderTest, GlobalVar_ConstantId_Bool) { }); EXPECT_TRUE(b.GenerateGlobalVariable(v)) << b.error(); - EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %3 "var" + EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %3 "test_var" )"); EXPECT_EQ(DumpInstructions(b.annots()), R"(OpDecorate %2 SpecId 1200 )"); @@ -257,7 +257,7 @@ TEST_F(BuilderTest, GlobalVar_ConstantId_Bool_NoConstructor) { }); EXPECT_TRUE(b.GenerateGlobalVariable(v)) << b.error(); - EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "var" + EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "test_var" )"); EXPECT_EQ(DumpInstructions(b.annots()), R"(OpDecorate %4 SpecId 1200 )"); @@ -275,7 +275,7 @@ TEST_F(BuilderTest, GlobalVar_ConstantId_Scalar) { }); EXPECT_TRUE(b.GenerateGlobalVariable(v)) << b.error(); - EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %3 "var" + EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %3 "test_var" )"); EXPECT_EQ(DumpInstructions(b.annots()), R"(OpDecorate %2 SpecId 0 )"); @@ -293,7 +293,7 @@ TEST_F(BuilderTest, GlobalVar_ConstantId_Scalar_F32_NoConstructor) { }); EXPECT_TRUE(b.GenerateGlobalVariable(v)) << b.error(); - EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "var" + EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "test_var" )"); EXPECT_EQ(DumpInstructions(b.annots()), R"(OpDecorate %4 SpecId 0 )"); @@ -311,7 +311,7 @@ TEST_F(BuilderTest, GlobalVar_ConstantId_Scalar_I32_NoConstructor) { }); EXPECT_TRUE(b.GenerateGlobalVariable(v)) << b.error(); - EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "var" + EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "test_var" )"); EXPECT_EQ(DumpInstructions(b.annots()), R"(OpDecorate %4 SpecId 0 )"); @@ -329,7 +329,7 @@ TEST_F(BuilderTest, GlobalVar_ConstantId_Scalar_U32_NoConstructor) { }); EXPECT_TRUE(b.GenerateGlobalVariable(v)) << b.error(); - EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "var" + EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "test_var" )"); EXPECT_EQ(DumpInstructions(b.annots()), R"(OpDecorate %4 SpecId 0 )"); @@ -392,10 +392,10 @@ TEST_F(BuilderTest, GlobalVar_DeclReadOnly) { EXPECT_EQ(DumpInstructions(b.annots()), R"(OpMemberDecorate %3 0 NonWritable OpMemberDecorate %3 1 NonWritable )"); - EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %3 "A" -OpMemberName %3 0 "a" -OpMemberName %3 1 "b" -OpName %1 "b" + EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %3 "test_A" +OpMemberName %3 0 "test_a" +OpMemberName %3 1 "test_b" +OpName %1 "test_b" )"); EXPECT_EQ(DumpInstructions(b.types()), R"(%4 = OpTypeInt 32 1 %3 = OpTypeStruct %4 %4 @@ -421,9 +421,9 @@ TEST_F(BuilderTest, GlobalVar_TypeAliasDeclReadOnly) { EXPECT_EQ(DumpInstructions(b.annots()), R"(OpMemberDecorate %3 0 NonWritable )"); - EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %3 "A" -OpMemberName %3 0 "a" -OpName %1 "b" + EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %3 "test_A" +OpMemberName %3 0 "test_a" +OpName %1 "test_b" )"); EXPECT_EQ(DumpInstructions(b.types()), R"(%4 = OpTypeInt 32 1 %3 = OpTypeStruct %4 @@ -449,9 +449,9 @@ TEST_F(BuilderTest, GlobalVar_TypeAliasAssignReadOnly) { EXPECT_EQ(DumpInstructions(b.annots()), R"(OpMemberDecorate %3 0 NonWritable )"); - EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %3 "A" -OpMemberName %3 0 "a" -OpName %1 "b" + EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %3 "test_A" +OpMemberName %3 0 "test_a" +OpName %1 "test_b" )"); EXPECT_EQ(DumpInstructions(b.types()), R"(%4 = OpTypeInt 32 1 %3 = OpTypeStruct %4 @@ -480,12 +480,12 @@ TEST_F(BuilderTest, GlobalVar_TwoVarDeclReadOnly) { EXPECT_EQ(DumpInstructions(b.annots()), R"(OpMemberDecorate %3 0 NonWritable )"); - EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %3 "A" -OpMemberName %3 0 "a" -OpName %1 "b" -OpName %7 "A" -OpMemberName %7 0 "a" -OpName %5 "c" + EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %3 "test_A" +OpMemberName %3 0 "test_a" +OpName %1 "test_b" +OpName %7 "test_A" +OpMemberName %7 0 "test_a" +OpName %5 "test_c" )"); EXPECT_EQ(DumpInstructions(b.types()), R"(%4 = OpTypeInt 32 1 %3 = OpTypeStruct %4 diff --git a/src/writer/spirv/builder_ident_expression_test.cc b/src/writer/spirv/builder_ident_expression_test.cc index 453ef6bcae..1a92054aff 100644 --- a/src/writer/spirv/builder_ident_expression_test.cc +++ b/src/writer/spirv/builder_ident_expression_test.cc @@ -66,7 +66,7 @@ TEST_F(BuilderTest, IdentifierExpression_GlobalVar) { b.push_function(Function{}); EXPECT_TRUE(b.GenerateGlobalVariable(v)) << b.error(); - EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "var" + EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "test_var" )"); EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeFloat 32 %2 = OpTypePointer Output %3 @@ -108,7 +108,7 @@ TEST_F(BuilderTest, IdentifierExpression_FunctionVar) { b.push_function(Function{}); EXPECT_TRUE(b.GenerateFunctionVariable(v)) << b.error(); - EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "var" + EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "test_var" )"); EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeFloat 32 %2 = OpTypePointer Function %3 diff --git a/src/writer/spirv/builder_intrinsic_test.cc b/src/writer/spirv/builder_intrinsic_test.cc index c2dde98401..b47e1e5788 100644 --- a/src/writer/spirv/builder_intrinsic_test.cc +++ b/src/writer/spirv/builder_intrinsic_test.cc @@ -45,6 +45,7 @@ #include "src/type_determiner.h" #include "src/writer/spirv/builder.h" #include "src/writer/spirv/spv_dump.h" +#include "src/writer/test_namer.h" namespace tint { namespace writer { @@ -59,7 +60,8 @@ class IntrinsicBuilderTest : public ast::BuilderWithModule, } TypeDeterminer td{mod}; - spirv::Builder b{mod}; + TestNamer namer{mod}; + spirv::Builder b{mod, &namer}; }; template @@ -479,8 +481,8 @@ TEST_F(IntrinsicBuilderTest, Call_GLSLMethod_WithLoad) { EXPECT_EQ(b.GenerateCallExpression(expr), 9u) << b.error(); EXPECT_EQ(DumpBuilder(b), R"(%10 = OpExtInstImport "GLSL.std.450" -OpName %1 "ident" -OpName %7 "a_func" +OpName %1 "test_ident" +OpName %7 "test_a_func" %3 = OpTypeFloat 32 %2 = OpTypePointer Private %3 %4 = OpConstantNull %3 @@ -511,7 +513,7 @@ TEST_P(Intrinsic_Builtin_SingleParam_Float_Test, Call_Scalar) { EXPECT_EQ(b.GenerateCallExpression(expr), 5u) << b.error(); EXPECT_EQ(DumpBuilder(b), R"(%7 = OpExtInstImport "GLSL.std.450" -OpName %3 "a_func" +OpName %3 "test_a_func" %2 = OpTypeVoid %1 = OpTypeFunction %2 %6 = OpTypeFloat 32 @@ -538,7 +540,7 @@ TEST_P(Intrinsic_Builtin_SingleParam_Float_Test, Call_Vector) { EXPECT_EQ(b.GenerateCallExpression(expr), 5u) << b.error(); EXPECT_EQ(DumpBuilder(b), R"(%8 = OpExtInstImport "GLSL.std.450" -OpName %3 "a_func" +OpName %3 "test_a_func" %2 = OpTypeVoid %1 = OpTypeFunction %2 %7 = OpTypeFloat 32 @@ -591,7 +593,7 @@ TEST_F(IntrinsicBuilderTest, Call_Length_Scalar) { EXPECT_EQ(b.GenerateCallExpression(expr), 5u) << b.error(); EXPECT_EQ(DumpBuilder(b), R"(%7 = OpExtInstImport "GLSL.std.450" -OpName %3 "a_func" +OpName %3 "test_a_func" %2 = OpTypeVoid %1 = OpTypeFunction %2 %6 = OpTypeFloat 32 @@ -615,7 +617,7 @@ TEST_F(IntrinsicBuilderTest, Call_Length_Vector) { EXPECT_EQ(b.GenerateCallExpression(expr), 5u) << b.error(); EXPECT_EQ(DumpBuilder(b), R"(%7 = OpExtInstImport "GLSL.std.450" -OpName %3 "a_func" +OpName %3 "test_a_func" %2 = OpTypeVoid %1 = OpTypeFunction %2 %6 = OpTypeFloat 32 @@ -641,7 +643,7 @@ TEST_F(IntrinsicBuilderTest, Call_Normalize) { EXPECT_EQ(b.GenerateCallExpression(expr), 5u) << b.error(); EXPECT_EQ(DumpBuilder(b), R"(%8 = OpExtInstImport "GLSL.std.450" -OpName %3 "a_func" +OpName %3 "test_a_func" %2 = OpTypeVoid %1 = OpTypeFunction %2 %7 = OpTypeFloat 32 @@ -672,7 +674,7 @@ TEST_P(Intrinsic_Builtin_DualParam_Float_Test, Call_Scalar) { EXPECT_EQ(b.GenerateCallExpression(expr), 5u) << b.error(); EXPECT_EQ(DumpBuilder(b), R"(%7 = OpExtInstImport "GLSL.std.450" -OpName %3 "a_func" +OpName %3 "test_a_func" %2 = OpTypeVoid %1 = OpTypeFunction %2 %6 = OpTypeFloat 32 @@ -700,7 +702,7 @@ TEST_P(Intrinsic_Builtin_DualParam_Float_Test, Call_Vector) { EXPECT_EQ(b.GenerateCallExpression(expr), 5u) << b.error(); EXPECT_EQ(DumpBuilder(b), R"(%8 = OpExtInstImport "GLSL.std.450" -OpName %3 "a_func" +OpName %3 "test_a_func" %2 = OpTypeVoid %1 = OpTypeFunction %2 %7 = OpTypeFloat 32 @@ -736,7 +738,7 @@ TEST_F(IntrinsicBuilderTest, Call_Distance_Scalar) { EXPECT_EQ(b.GenerateCallExpression(expr), 5u) << b.error(); EXPECT_EQ(DumpBuilder(b), R"(%7 = OpExtInstImport "GLSL.std.450" -OpName %3 "a_func" +OpName %3 "test_a_func" %2 = OpTypeVoid %1 = OpTypeFunction %2 %6 = OpTypeFloat 32 @@ -761,7 +763,7 @@ TEST_F(IntrinsicBuilderTest, Call_Distance_Vector) { EXPECT_EQ(b.GenerateCallExpression(expr), 5u) << b.error(); EXPECT_EQ(DumpBuilder(b), R"(%7 = OpExtInstImport "GLSL.std.450" -OpName %3 "a_func" +OpName %3 "test_a_func" %2 = OpTypeVoid %1 = OpTypeFunction %2 %6 = OpTypeFloat 32 @@ -789,7 +791,7 @@ TEST_F(IntrinsicBuilderTest, Call_Cross) { EXPECT_EQ(b.GenerateCallExpression(expr), 5u) << b.error(); EXPECT_EQ(DumpBuilder(b), R"(%8 = OpExtInstImport "GLSL.std.450" -OpName %3 "a_func" +OpName %3 "test_a_func" %2 = OpTypeVoid %1 = OpTypeFunction %2 %7 = OpTypeFloat 32 @@ -819,7 +821,7 @@ TEST_P(Intrinsic_Builtin_ThreeParam_Float_Test, Call_Scalar) { EXPECT_EQ(b.GenerateCallExpression(expr), 5u) << b.error(); EXPECT_EQ(DumpBuilder(b), R"(%7 = OpExtInstImport "GLSL.std.450" -OpName %3 "a_func" +OpName %3 "test_a_func" %2 = OpTypeVoid %1 = OpTypeFunction %2 %6 = OpTypeFloat 32 @@ -848,7 +850,7 @@ TEST_P(Intrinsic_Builtin_ThreeParam_Float_Test, Call_Vector) { EXPECT_EQ(b.GenerateCallExpression(expr), 5u) << b.error(); EXPECT_EQ(DumpBuilder(b), R"(%8 = OpExtInstImport "GLSL.std.450" -OpName %3 "a_func" +OpName %3 "test_a_func" %2 = OpTypeVoid %1 = OpTypeFunction %2 %7 = OpTypeFloat 32 @@ -888,7 +890,7 @@ TEST_P(Intrinsic_Builtin_SingleParam_Sint_Test, Call_Scalar) { EXPECT_EQ(b.GenerateCallExpression(expr), 5u) << b.error(); EXPECT_EQ(DumpBuilder(b), R"(%7 = OpExtInstImport "GLSL.std.450" -OpName %3 "a_func" +OpName %3 "test_a_func" %2 = OpTypeVoid %1 = OpTypeFunction %2 %6 = OpTypeInt 32 1 @@ -915,7 +917,7 @@ TEST_P(Intrinsic_Builtin_SingleParam_Sint_Test, Call_Vector) { EXPECT_EQ(b.GenerateCallExpression(expr), 5u) << b.error(); EXPECT_EQ(DumpBuilder(b), R"(%8 = OpExtInstImport "GLSL.std.450" -OpName %3 "a_func" +OpName %3 "test_a_func" %2 = OpTypeVoid %1 = OpTypeFunction %2 %7 = OpTypeInt 32 1 @@ -949,7 +951,7 @@ TEST_P(Intrinsic_Builtin_SingleParam_Uint_Test, Call_Scalar) { EXPECT_EQ(b.GenerateCallExpression(expr), 5u) << b.error(); EXPECT_EQ(DumpBuilder(b), R"(%7 = OpExtInstImport "GLSL.std.450" -OpName %3 "a_func" +OpName %3 "test_a_func" %2 = OpTypeVoid %1 = OpTypeFunction %2 %6 = OpTypeInt 32 0 @@ -976,7 +978,7 @@ TEST_P(Intrinsic_Builtin_SingleParam_Uint_Test, Call_Vector) { EXPECT_EQ(b.GenerateCallExpression(expr), 5u) << b.error(); EXPECT_EQ(DumpBuilder(b), R"(%8 = OpExtInstImport "GLSL.std.450" -OpName %3 "a_func" +OpName %3 "test_a_func" %2 = OpTypeVoid %1 = OpTypeFunction %2 %7 = OpTypeInt 32 0 @@ -1010,7 +1012,7 @@ TEST_P(Intrinsic_Builtin_DualParam_SInt_Test, Call_Scalar) { EXPECT_EQ(b.GenerateCallExpression(expr), 5u) << b.error(); EXPECT_EQ(DumpBuilder(b), R"(%7 = OpExtInstImport "GLSL.std.450" -OpName %3 "a_func" +OpName %3 "test_a_func" %2 = OpTypeVoid %1 = OpTypeFunction %2 %6 = OpTypeInt 32 1 @@ -1037,7 +1039,7 @@ TEST_P(Intrinsic_Builtin_DualParam_SInt_Test, Call_Vector) { EXPECT_EQ(b.GenerateCallExpression(expr), 5u) << b.error(); EXPECT_EQ(DumpBuilder(b), R"(%8 = OpExtInstImport "GLSL.std.450" -OpName %3 "a_func" +OpName %3 "test_a_func" %2 = OpTypeVoid %1 = OpTypeFunction %2 %7 = OpTypeInt 32 1 @@ -1072,7 +1074,7 @@ TEST_P(Intrinsic_Builtin_DualParam_UInt_Test, Call_Scalar) { EXPECT_EQ(b.GenerateCallExpression(expr), 5u) << b.error(); EXPECT_EQ(DumpBuilder(b), R"(%7 = OpExtInstImport "GLSL.std.450" -OpName %3 "a_func" +OpName %3 "test_a_func" %2 = OpTypeVoid %1 = OpTypeFunction %2 %6 = OpTypeInt 32 0 @@ -1099,7 +1101,7 @@ TEST_P(Intrinsic_Builtin_DualParam_UInt_Test, Call_Vector) { EXPECT_EQ(b.GenerateCallExpression(expr), 5u) << b.error(); EXPECT_EQ(DumpBuilder(b), R"(%8 = OpExtInstImport "GLSL.std.450" -OpName %3 "a_func" +OpName %3 "test_a_func" %2 = OpTypeVoid %1 = OpTypeFunction %2 %7 = OpTypeInt 32 0 @@ -1134,7 +1136,7 @@ TEST_P(Intrinsic_Builtin_ThreeParam_Sint_Test, Call_Scalar) { EXPECT_EQ(b.GenerateCallExpression(expr), 5u) << b.error(); EXPECT_EQ(DumpBuilder(b), R"(%7 = OpExtInstImport "GLSL.std.450" -OpName %3 "a_func" +OpName %3 "test_a_func" %2 = OpTypeVoid %1 = OpTypeFunction %2 %6 = OpTypeInt 32 1 @@ -1163,7 +1165,7 @@ TEST_P(Intrinsic_Builtin_ThreeParam_Sint_Test, Call_Vector) { EXPECT_EQ(b.GenerateCallExpression(expr), 5u) << b.error(); EXPECT_EQ(DumpBuilder(b), R"(%8 = OpExtInstImport "GLSL.std.450" -OpName %3 "a_func" +OpName %3 "test_a_func" %2 = OpTypeVoid %1 = OpTypeFunction %2 %7 = OpTypeInt 32 1 @@ -1197,7 +1199,7 @@ TEST_P(Intrinsic_Builtin_ThreeParam_Uint_Test, Call_Scalar) { EXPECT_EQ(b.GenerateCallExpression(expr), 5u) << b.error(); EXPECT_EQ(DumpBuilder(b), R"(%7 = OpExtInstImport "GLSL.std.450" -OpName %3 "a_func" +OpName %3 "test_a_func" %2 = OpTypeVoid %1 = OpTypeFunction %2 %6 = OpTypeInt 32 0 @@ -1226,7 +1228,7 @@ TEST_P(Intrinsic_Builtin_ThreeParam_Uint_Test, Call_Vector) { EXPECT_EQ(b.GenerateCallExpression(expr), 5u) << b.error(); EXPECT_EQ(DumpBuilder(b), R"(%8 = OpExtInstImport "GLSL.std.450" -OpName %3 "a_func" +OpName %3 "test_a_func" %2 = OpTypeVoid %1 = OpTypeFunction %2 %7 = OpTypeInt 32 0 @@ -1260,8 +1262,8 @@ TEST_F(IntrinsicBuilderTest, Call_Determinant) { EXPECT_EQ(b.GenerateCallExpression(expr), 11u) << b.error(); EXPECT_EQ(DumpBuilder(b), R"(%12 = OpExtInstImport "GLSL.std.450" -OpName %3 "a_func" -OpName %5 "var" +OpName %3 "test_a_func" +OpName %5 "test_var" %2 = OpTypeVoid %1 = OpTypeFunction %2 %9 = OpTypeFloat 32 diff --git a/src/writer/spirv/builder_intrinsic_texture_test.cc b/src/writer/spirv/builder_intrinsic_texture_test.cc index a26bedd727..1651f120ea 100644 --- a/src/writer/spirv/builder_intrinsic_texture_test.cc +++ b/src/writer/spirv/builder_intrinsic_texture_test.cc @@ -24,6 +24,7 @@ #include "src/type_determiner.h" #include "src/writer/spirv/builder.h" #include "src/writer/spirv/spv_dump.h" +#include "src/writer/test_namer.h" namespace tint { namespace writer { @@ -2708,7 +2709,8 @@ class IntrinsicTextureTest } TypeDeterminer td{mod}; - spirv::Builder b{mod}; + TestNamer namer{mod}; + spirv::Builder b{mod, &namer}; }; INSTANTIATE_TEST_SUITE_P( diff --git a/src/writer/spirv/builder_switch_test.cc b/src/writer/spirv/builder_switch_test.cc index 71505292d3..8dcdd4039a 100644 --- a/src/writer/spirv/builder_switch_test.cc +++ b/src/writer/spirv/builder_switch_test.cc @@ -103,9 +103,9 @@ TEST_F(BuilderTest, Switch_WithCase) { EXPECT_TRUE(b.GenerateSwitchStatement(expr)) << b.error(); - EXPECT_EQ(DumpBuilder(b), R"(OpName %1 "v" -OpName %5 "a" -OpName %7 "a_func" + EXPECT_EQ(DumpBuilder(b), R"(OpName %1 "test_v" +OpName %5 "test_a" +OpName %7 "test_a_func" %3 = OpTypeInt 32 1 %2 = OpTypePointer Private %3 %4 = OpConstantNull %3 @@ -164,9 +164,9 @@ TEST_F(BuilderTest, Switch_WithDefault) { EXPECT_TRUE(b.GenerateSwitchStatement(expr)) << b.error(); - EXPECT_EQ(DumpBuilder(b), R"(OpName %1 "v" -OpName %5 "a" -OpName %7 "a_func" + EXPECT_EQ(DumpBuilder(b), R"(OpName %1 "test_v" +OpName %5 "test_a" +OpName %7 "test_a_func" %3 = OpTypeInt 32 1 %2 = OpTypePointer Private %3 %4 = OpConstantNull %3 @@ -238,9 +238,9 @@ TEST_F(BuilderTest, Switch_WithCaseAndDefault) { EXPECT_TRUE(b.GenerateSwitchStatement(expr)) << b.error(); - EXPECT_EQ(DumpBuilder(b), R"(OpName %1 "v" -OpName %5 "a" -OpName %7 "a_func" + EXPECT_EQ(DumpBuilder(b), R"(OpName %1 "test_v" +OpName %5 "test_a" +OpName %7 "test_a_func" %3 = OpTypeInt 32 1 %2 = OpTypePointer Private %3 %4 = OpConstantNull %3 @@ -321,9 +321,9 @@ TEST_F(BuilderTest, Switch_CaseWithFallthrough) { EXPECT_TRUE(b.GenerateSwitchStatement(expr)) << b.error(); - EXPECT_EQ(DumpBuilder(b), R"(OpName %1 "v" -OpName %5 "a" -OpName %7 "a_func" + EXPECT_EQ(DumpBuilder(b), R"(OpName %1 "test_v" +OpName %5 "test_a" +OpName %7 "test_a_func" %3 = OpTypeInt 32 1 %2 = OpTypePointer Private %3 %4 = OpConstantNull %3 @@ -431,9 +431,9 @@ TEST_F(BuilderTest, Switch_WithNestedBreak) { EXPECT_TRUE(b.GenerateSwitchStatement(expr)) << b.error(); - EXPECT_EQ(DumpBuilder(b), R"(OpName %1 "v" -OpName %5 "a" -OpName %7 "a_func" + EXPECT_EQ(DumpBuilder(b), R"(OpName %1 "test_v" +OpName %5 "test_a" +OpName %7 "test_a_func" %3 = OpTypeInt 32 1 %2 = OpTypePointer Private %3 %4 = OpConstantNull %3 diff --git a/src/writer/spirv/builder_type_test.cc b/src/writer/spirv/builder_type_test.cc index db2f45a487..6445c2c7af 100644 --- a/src/writer/spirv/builder_type_test.cc +++ b/src/writer/spirv/builder_type_test.cc @@ -251,7 +251,7 @@ TEST_F(BuilderTest_Type, GenerateStruct_Empty) { EXPECT_EQ(id, 1u); EXPECT_EQ(b.types().size(), 1u); - EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "S" + EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "test_S" )"); EXPECT_EQ(DumpInstructions(b.types()), R"(%1 = OpTypeStruct )"); @@ -269,8 +269,8 @@ TEST_F(BuilderTest_Type, GenerateStruct) { EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32 %1 = OpTypeStruct %2 )"); - EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "my_struct" -OpMemberName %1 0 "a" + EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "test_my_struct" +OpMemberName %1 0 "test_a" )"); } @@ -289,8 +289,8 @@ TEST_F(BuilderTest_Type, GenerateStruct_Decorated) { EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32 %1 = OpTypeStruct %2 )"); - EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "my_struct" -OpMemberName %1 0 "a" + EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "test_my_struct" +OpMemberName %1 0 "test_a" )"); EXPECT_EQ(DumpInstructions(b.annots()), R"(OpDecorate %1 Block )"); @@ -310,9 +310,9 @@ TEST_F(BuilderTest_Type, GenerateStruct_DecoratedMembers) { EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32 %1 = OpTypeStruct %2 %2 )"); - EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "S" -OpMemberName %1 0 "a" -OpMemberName %1 1 "b" + EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "test_S" +OpMemberName %1 0 "test_a" +OpMemberName %1 1 "test_b" )"); EXPECT_EQ(DumpInstructions(b.annots()), R"(OpMemberDecorate %1 0 Offset 0 OpMemberDecorate %1 1 Offset 8 @@ -340,10 +340,10 @@ TEST_F(BuilderTest_Type, GenerateStruct_NonLayout_Matrix) { %7 = OpTypeMatrix %8 4 %1 = OpTypeStruct %2 %5 %7 )"); - EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "S" -OpMemberName %1 0 "a" -OpMemberName %1 1 "b" -OpMemberName %1 2 "c" + EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "test_S" +OpMemberName %1 0 "test_a" +OpMemberName %1 1 "test_b" +OpMemberName %1 2 "test_c" )"); EXPECT_EQ(DumpInstructions(b.annots()), ""); } @@ -370,10 +370,10 @@ TEST_F(BuilderTest_Type, GenerateStruct_DecoratedMembers_LayoutMatrix) { %7 = OpTypeMatrix %8 4 %1 = OpTypeStruct %2 %5 %7 )"); - EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "S" -OpMemberName %1 0 "a" -OpMemberName %1 1 "b" -OpMemberName %1 2 "c" + EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "test_S" +OpMemberName %1 0 "test_a" +OpMemberName %1 1 "test_b" +OpMemberName %1 2 "test_c" )"); EXPECT_EQ(DumpInstructions(b.annots()), R"(OpMemberDecorate %1 0 Offset 0 OpMemberDecorate %1 0 ColMajor @@ -426,10 +426,10 @@ TEST_F(BuilderTest_Type, GenerateStruct_DecoratedMembers_LayoutArraysOfMatrix) { %11 = OpTypeRuntimeArray %12 %1 = OpTypeStruct %2 %8 %11 )"); - EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "S" -OpMemberName %1 0 "a" -OpMemberName %1 1 "b" -OpMemberName %1 2 "c" + EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "test_S" +OpMemberName %1 0 "test_a" +OpMemberName %1 1 "test_b" +OpMemberName %1 2 "test_c" )"); EXPECT_EQ(DumpInstructions(b.annots()), R"(OpMemberDecorate %1 0 Offset 0 OpMemberDecorate %1 0 ColMajor diff --git a/src/writer/spirv/generator.cc b/src/writer/spirv/generator.cc index c28cb130e5..9a435e4a64 100644 --- a/src/writer/spirv/generator.cc +++ b/src/writer/spirv/generator.cc @@ -22,13 +22,15 @@ namespace spirv { Generator::Generator(ast::Module module) : writer::Writer(std::move(module)), - builder_(std::make_unique(&module_)), + namer_(std::make_unique(&module_)), + builder_(std::make_unique(&module_, namer_.get())), writer_(std::make_unique()) {} Generator::~Generator() = default; void Generator::Reset() { - builder_ = std::make_unique(&module_); + namer_->Reset(); + builder_ = std::make_unique(&module_, namer_.get()); writer_ = std::make_unique(); } diff --git a/src/writer/spirv/generator.h b/src/writer/spirv/generator.h index f5968b2d2d..b1f37d7f3e 100644 --- a/src/writer/spirv/generator.h +++ b/src/writer/spirv/generator.h @@ -20,6 +20,7 @@ #include #include "src/ast/module.h" +#include "src/namer.h" #include "src/writer/spirv/binary_writer.h" #include "src/writer/spirv/builder.h" #include "src/writer/writer.h" @@ -54,6 +55,7 @@ class Generator : public writer::Writer { const std::vector& result() const { return writer_->result(); } private: + std::unique_ptr namer_; std::unique_ptr builder_; std::unique_ptr writer_; }; diff --git a/src/writer/spirv/test_helper.h b/src/writer/spirv/test_helper.h index cbc3d0e4a9..fcec3035da 100644 --- a/src/writer/spirv/test_helper.h +++ b/src/writer/spirv/test_helper.h @@ -23,6 +23,7 @@ #include "src/ast/module.h" #include "src/type_determiner.h" #include "src/writer/spirv/builder.h" +#include "src/writer/test_namer.h" namespace tint { namespace writer { @@ -32,11 +33,13 @@ namespace spirv { template class TestHelperBase : public ast::BuilderWithModule, public BASE { public: - TestHelperBase() : td(mod), b(mod) {} + TestHelperBase() : td(mod), namer(mod), b(mod, &namer) {} ~TestHelperBase() override = default; /// The type determiner TypeDeterminer td; + /// The test namer + TestNamer namer; /// The generator spirv::Builder b;