diff --git a/BUILD.gn b/BUILD.gn index 5c9ff05fff..f940575bda 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -609,8 +609,6 @@ source_set("libtint_hlsl_writer_src") { "src/writer/hlsl/generator.h", "src/writer/hlsl/generator_impl.cc", "src/writer/hlsl/generator_impl.h", - "src/writer/hlsl/namer.cc", - "src/writer/hlsl/namer.h", ] configs += [ ":tint_common_config" ] @@ -1199,7 +1197,6 @@ source_set("tint_unittests_hlsl_writer_src") { "src/writer/hlsl/generator_impl_type_test.cc", "src/writer/hlsl/generator_impl_unary_op_test.cc", "src/writer/hlsl/generator_impl_variable_decl_statement_test.cc", - "src/writer/hlsl/namer_test.cc", "src/writer/hlsl/test_helper.h", ] diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index fa08d9d24a..7925a66c6a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -352,8 +352,6 @@ if(${TINT_BUILD_HLSL_WRITER}) writer/hlsl/generator.h writer/hlsl/generator_impl.cc writer/hlsl/generator_impl.h - writer/hlsl/namer.cc - writer/hlsl/namer.h ) endif() @@ -726,7 +724,6 @@ if(${TINT_BUILD_TESTS}) writer/hlsl/generator_impl_type_test.cc writer/hlsl/generator_impl_unary_op_test.cc writer/hlsl/generator_impl_variable_decl_statement_test.cc - writer/hlsl/namer_test.cc writer/hlsl/test_helper.h ) endif() diff --git a/src/writer/hlsl/generator_impl.cc b/src/writer/hlsl/generator_impl.cc index 193302aa11..9dae4b847b 100644 --- a/src/writer/hlsl/generator_impl.cc +++ b/src/writer/hlsl/generator_impl.cc @@ -141,7 +141,8 @@ const char* image_format_to_rwtexture_type( } // namespace -GeneratorImpl::GeneratorImpl(ast::Module* module) : module_(module) {} +GeneratorImpl::GeneratorImpl(ast::Module* module) + : module_(module), namer_(std::make_unique(module)) {} GeneratorImpl::~GeneratorImpl() = default; @@ -208,17 +209,6 @@ void GeneratorImpl::register_global(ast::Variable* global) { global_variables_.set(global->symbol(), global); } -std::string GeneratorImpl::generate_name(const std::string& prefix) { - std::string name = prefix; - uint32_t i = 0; - while (namer_.IsMapped(name) || namer_.IsRemapped(name)) { - name = prefix + "_" + std::to_string(i); - ++i; - } - namer_.RegisterRemappedName(name); - return name; -} - std::string GeneratorImpl::current_ep_var_name(VarType type) { std::string name = ""; switch (type) { @@ -254,10 +244,10 @@ bool GeneratorImpl::EmitConstructedType(std::ostream& out, return true; } out << "typedef "; - if (!EmitType(out, alias->type(), "")) { + if (!EmitType(out, alias->type(), Symbol())) { return false; } - out << " " << namer_.NameFor(alias->name()) << ";" << std::endl; + out << " " << namer_->NameFor(alias->symbol()) << ";" << std::endl; } else if (auto* str = ty->As()) { if (!EmitStructType(out, str, str->name())) { return false; @@ -300,7 +290,7 @@ bool GeneratorImpl::EmitBitcast(std::ostream& pre, } out << "as"; - if (!EmitType(out, expr->type(), "")) { + if (!EmitType(out, expr->type(), Symbol())) { return false; } out << "("; @@ -366,7 +356,7 @@ bool GeneratorImpl::EmitBinary(std::ostream& pre, return false; } - auto name = generate_name(kTempNamePrefix); + auto name = namer_->GenerateName(kTempNamePrefix); make_indent(pre); pre << "bool " << name << " = " << lhs_out.str() << ";" << std::endl; @@ -626,13 +616,13 @@ bool GeneratorImpl::EmitCall(std::ostream& pre, // // We create variables to hold the two parameters in case they're // // function calls with side effects. // auto* param0 = param[0].get(); - // auto* name0 = generate_name("outer_product_expr_0"); + // auto* name0 = namer_->GenerateName("outer_product_expr_0"); // auto* param1 = param[1].get(); - // auto* name1 = generate_name("outer_product_expr_1"); + // auto* name1 = namer_->GenerateName("outer_product_expr_1"); // make_indent(out); - // if (!EmitType(out, expr->result_type(), "")) { + // if (!EmitType(out, expr->result_type(), Symbol()) { // return false; // } // out << "("; @@ -984,7 +974,7 @@ bool GeneratorImpl::EmitTypeConstructor(std::ostream& pre, if (expr->type()->Is()) { out << "{"; } else { - if (!EmitType(out, expr->type(), "")) { + if (!EmitType(out, expr->type(), Symbol())) { return false; } out << "("; @@ -1090,7 +1080,7 @@ bool GeneratorImpl::EmitIdentifier(std::ostream&, out << name << "."; } } - out << namer_.NameFor(ident->name()); + out << namer_->NameFor(ident->symbol()); return true; } @@ -1241,7 +1231,7 @@ bool GeneratorImpl::EmitFunctionInternal(std::ostream& out, Symbol ep_sym) { auto name = func->symbol().to_str(); - if (!EmitType(out, func->return_type(), "")) { + if (!EmitType(out, func->return_type(), Symbol())) { return false; } @@ -1250,13 +1240,11 @@ bool GeneratorImpl::EmitFunctionInternal(std::ostream& out, if (emit_duplicate_functions) { auto func_name = name; auto ep_name = ep_sym.to_str(); - // TODO(dsinclair): The SymbolToName should go away and just use - // to_str() here when the conversion is complete. - name = generate_name(func->name() + "_" + module_->SymbolToName(ep_sym)); + name = namer_->GenerateName(namer_->NameFor(func->symbol()) + "_" + + namer_->NameFor(ep_sym)); ep_func_name_remapped_[ep_name + "_" + func_name] = name; } else { - // TODO(dsinclair): this should be updated to a remapped name - name = namer_.NameFor(func->name()); + name = namer_->NameFor(func->symbol()); } out << name << "("; @@ -1292,7 +1280,7 @@ bool GeneratorImpl::EmitFunctionInternal(std::ostream& out, } first = false; - if (!EmitType(out, v->type(), v->name())) { + if (!EmitType(out, v->type(), v->symbol())) { return false; } // Array name is output as part of the type @@ -1379,7 +1367,7 @@ bool GeneratorImpl::EmitEntryPointData( increment_indent(); make_indent(out); - if (!EmitType(out, type, "")) { + if (!EmitType(out, type, Symbol())) { return false; } out << " " << var->name() << ";" << std::endl; @@ -1423,9 +1411,9 @@ bool GeneratorImpl::EmitEntryPointData( } if (!in_variables.empty()) { - auto in_struct_name = - generate_name(func->name() + "_" + kInStructNameSuffix); - auto in_var_name = generate_name(kTintStructInVarPrefix); + auto in_struct_name = namer_->GenerateName(namer_->NameFor(func->symbol()) + + "_" + kInStructNameSuffix); + auto in_var_name = namer_->GenerateName(kTintStructInVarPrefix); ep_sym_to_in_data_[func->symbol().value()] = {in_struct_name, in_var_name}; make_indent(out); @@ -1438,7 +1426,7 @@ bool GeneratorImpl::EmitEntryPointData( auto* deco = data.second; make_indent(out); - if (!EmitType(out, var->type(), var->name())) { + if (!EmitType(out, var->type(), var->symbol())) { return false; } @@ -1469,9 +1457,9 @@ bool GeneratorImpl::EmitEntryPointData( } if (!outvariables.empty()) { - auto outstruct_name = - generate_name(func->name() + "_" + kOutStructNameSuffix); - auto outvar_name = generate_name(kTintStructOutVarPrefix); + auto outstruct_name = namer_->GenerateName(namer_->NameFor(func->symbol()) + + "_" + kOutStructNameSuffix); + auto outvar_name = namer_->GenerateName(kTintStructOutVarPrefix); ep_sym_to_out_data_[func->symbol().value()] = {outstruct_name, outvar_name}; make_indent(out); @@ -1483,7 +1471,7 @@ bool GeneratorImpl::EmitEntryPointData( auto* deco = data.second; make_indent(out); - if (!EmitType(out, var->type(), var->name())) { + if (!EmitType(out, var->type(), var->symbol())) { return false; } @@ -1569,8 +1557,7 @@ bool GeneratorImpl::EmitEntryPointFunction(std::ostream& out, } else { out << "void"; } - // TODO(dsinclair): This should output the remapped name - out << " " << namer_.NameFor(module_->SymbolToName(current_ep_sym_)) << "("; + out << " " << namer_->NameFor(current_ep_sym_) << "("; auto in_data = ep_sym_to_in_data_.find(current_ep_sym_.value()); if (in_data != ep_sym_to_in_data_.end()) { @@ -1649,8 +1636,8 @@ bool GeneratorImpl::EmitZeroValue(std::ostream& out, ast::type::Type* type) { bool GeneratorImpl::EmitLoop(std::ostream& out, ast::LoopStatement* stmt) { loop_emission_counter_++; - std::string guard = namer_.NameFor("tint_hlsl_is_first_" + - std::to_string(loop_emission_counter_)); + std::string guard = namer_->GenerateName( + "tint_hlsl_is_first_" + std::to_string(loop_emission_counter_)); if (stmt->has_continuing()) { make_indent(out); @@ -1877,11 +1864,11 @@ bool GeneratorImpl::EmitStorageBufferAccessor(std::ostream& pre, uint32_t stride = mat->rows() == 2 ? 8 : 16; if (is_store) { - if (!EmitType(out, mat, "")) { + if (!EmitType(out, mat, Symbol())) { return false; } - auto name = generate_name(kTempNamePrefix); + auto name = namer_->GenerateName(kTempNamePrefix); out << " " << name << " = "; if (!EmitExpression(pre, out, rhs)) { return false; @@ -2101,9 +2088,9 @@ bool GeneratorImpl::EmitSwitch(std::ostream& out, ast::SwitchStatement* stmt) { bool GeneratorImpl::EmitType(std::ostream& out, ast::type::Type* type, - const std::string& name) { + const Symbol& sym) { if (auto* alias = type->As()) { - out << namer_.NameFor(alias->name()); + out << namer_->NameFor(alias->symbol()); } else if (auto* ary = type->As()) { ast::type::Type* base_type = ary; std::vector sizes; @@ -2118,11 +2105,11 @@ bool GeneratorImpl::EmitType(std::ostream& out, } base_type = arr->type(); } - if (!EmitType(out, base_type, "")) { + if (!EmitType(out, base_type, Symbol())) { return false; } - if (!name.empty()) { - out << " " << namer_.NameFor(name); + if (sym.IsValid()) { + out << " " << namer_->NameFor(sym); } for (uint32_t size : sizes) { out << "[" << size << "]"; @@ -2134,7 +2121,7 @@ bool GeneratorImpl::EmitType(std::ostream& out, } else if (type->Is()) { out << "int"; } else if (auto* mat = type->As()) { - if (!EmitType(out, mat->type(), "")) { + if (!EmitType(out, mat->type(), Symbol())) { return false; } out << mat->rows() << "x" << mat->columns(); @@ -2205,7 +2192,7 @@ bool GeneratorImpl::EmitType(std::ostream& out, out << "uint" << size; } else { out << "vector<"; - if (!EmitType(out, vec->type(), "")) { + if (!EmitType(out, vec->type(), Symbol())) { return false; } out << ", " << size << ">"; @@ -2234,12 +2221,12 @@ bool GeneratorImpl::EmitStructType(std::ostream& out, // TODO(dsinclair): Handle [[offset]] annotation on structs // https://bugs.chromium.org/p/tint/issues/detail?id=184 - if (!EmitType(out, mem->type(), mem->name())) { + if (!EmitType(out, mem->type(), mem->symbol())) { return false; } // Array member name will be output with the type if (!mem->type()->Is()) { - out << " " << namer_.NameFor(mem->name()); + out << " " << namer_->NameFor(mem->symbol()); } out << ";" << std::endl; } @@ -2298,7 +2285,7 @@ bool GeneratorImpl::EmitVariable(std::ostream& out, if (var->is_const()) { out << "const "; } - if (!EmitType(out, var->type(), var->name())) { + if (!EmitType(out, var->type(), var->symbol())) { return false; } if (!var->type()->Is()) { @@ -2347,7 +2334,7 @@ bool GeneratorImpl::EmitProgramConstVariable(std::ostream& out, } out << "#endif" << std::endl; out << "static const "; - if (!EmitType(out, var->type(), var->name())) { + if (!EmitType(out, var->type(), var->symbol())) { return false; } out << " " << var->name() << " = WGSL_SPEC_CONSTANT_" << const_id << ";" @@ -2355,7 +2342,7 @@ bool GeneratorImpl::EmitProgramConstVariable(std::ostream& out, out << "#undef WGSL_SPEC_CONSTANT_" << const_id << std::endl; } else { out << "static const "; - if (!EmitType(out, var->type(), var->name())) { + if (!EmitType(out, var->type(), var->symbol())) { return false; } if (!var->type()->Is()) { diff --git a/src/writer/hlsl/generator_impl.h b/src/writer/hlsl/generator_impl.h index ebd98b993d..4a2a371971 100644 --- a/src/writer/hlsl/generator_impl.h +++ b/src/writer/hlsl/generator_impl.h @@ -15,6 +15,7 @@ #ifndef SRC_WRITER_HLSL_GENERATOR_IMPL_H_ #define SRC_WRITER_HLSL_GENERATOR_IMPL_H_ +#include #include #include #include @@ -41,8 +42,8 @@ #include "src/ast/type/struct_type.h" #include "src/ast/type_constructor_expression.h" #include "src/ast/unary_op_expression.h" +#include "src/namer.h" #include "src/scope_stack.h" -#include "src/writer/hlsl/namer.h" namespace tint { namespace writer { @@ -288,11 +289,9 @@ class GeneratorImpl { /// Handles generating type /// @param out the output stream /// @param type the type to generate - /// @param name the name of the variable, only used for array emission + /// @param sym the symbol of the variable, Only used for array emission /// @returns true if the type is emitted - bool EmitType(std::ostream& out, - ast::type::Type* type, - const std::string& name); + bool EmitType(std::ostream& out, ast::type::Type* type, const Symbol& sym); /// Handles generating a structure declaration /// @param out the output stream /// @param ty the struct to generate @@ -379,9 +378,6 @@ class GeneratorImpl { /// @returns true if an input or output struct is required. bool has_referenced_var_needing_struct(ast::Function* func); - /// @returns the namer for testing - Namer* namer_for_testing() { return &namer_; } - private: enum class VarType { kIn, kOut }; @@ -395,8 +391,8 @@ class GeneratorImpl { std::string error_; size_t indent_ = 0; - Namer namer_; ast::Module* module_ = nullptr; + std::unique_ptr namer_; Symbol current_ep_sym_; bool generating_entry_point_ = false; uint32_t loop_emission_counter_ = 0; diff --git a/src/writer/hlsl/generator_impl_alias_type_test.cc b/src/writer/hlsl/generator_impl_alias_type_test.cc index 544f4eaab2..f8c823b895 100644 --- a/src/writer/hlsl/generator_impl_alias_type_test.cc +++ b/src/writer/hlsl/generator_impl_alias_type_test.cc @@ -34,14 +34,6 @@ TEST_F(HlslGeneratorImplTest_Alias, EmitAlias_F32) { )"); } -TEST_F(HlslGeneratorImplTest_Alias, EmitAlias_NameCollision) { - auto* alias = ty.alias("float", ty.f32); - - ASSERT_TRUE(gen.EmitConstructedType(out, alias)) << gen.error(); - EXPECT_EQ(result(), R"(typedef float float_tint_0; -)"); -} - TEST_F(HlslGeneratorImplTest_Alias, EmitAlias_Struct) { auto* str = create( ast::StructMemberList{Member("a", ty.f32), diff --git a/src/writer/hlsl/generator_impl_function_test.cc b/src/writer/hlsl/generator_impl_function_test.cc index 49d453028a..42b5988c39 100644 --- a/src/writer/hlsl/generator_impl_function_test.cc +++ b/src/writer/hlsl/generator_impl_function_test.cc @@ -70,24 +70,6 @@ TEST_F(HlslGeneratorImplTest_Function, Emit_Function) { )"); } -TEST_F(HlslGeneratorImplTest_Function, Emit_Function_Name_Collision) { - auto* func = Func("GeometryShader", ast::VariableList{}, ty.void_, - ast::StatementList{ - create(), - }, - ast::FunctionDecorationList{}); - - mod->AddFunction(func); - gen.increment_indent(); - - ASSERT_TRUE(gen.Generate(out)) << gen.error(); - EXPECT_EQ(result(), R"( void GeometryShader_tint_0() { - return; - } - -)"); -} - TEST_F(HlslGeneratorImplTest_Function, Emit_Function_WithParams) { auto* func = Func("my_func", @@ -809,23 +791,6 @@ ep_1_out ep_1() { )"); } -TEST_F(HlslGeneratorImplTest_Function, - Emit_FunctionDecoration_EntryPoint_WithNameCollision) { - auto* func = Func( - "GeometryShader", ast::VariableList{}, ty.void_, ast::StatementList{}, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kFragment), - }); - - mod->AddFunction(func); - - ASSERT_TRUE(gen.Generate(out)) << gen.error(); - EXPECT_EQ(result(), R"(void GeometryShader_tint_0() { -} - -)"); -} - TEST_F(HlslGeneratorImplTest_Function, Emit_FunctionDecoration_EntryPoint_Compute) { auto* func = diff --git a/src/writer/hlsl/generator_impl_identifier_test.cc b/src/writer/hlsl/generator_impl_identifier_test.cc index eba1c18981..94bbab671c 100644 --- a/src/writer/hlsl/generator_impl_identifier_test.cc +++ b/src/writer/hlsl/generator_impl_identifier_test.cc @@ -29,13 +29,6 @@ TEST_F(HlslGeneratorImplTest_Identifier, EmitIdentifierExpression) { EXPECT_EQ(result(), "foo"); } -TEST_F(HlslGeneratorImplTest_Identifier, - EmitIdentifierExpression_Single_WithCollision) { - auto* i = Expr("virtual"); - ASSERT_TRUE(gen.EmitExpression(pre, out, i)) << gen.error(); - EXPECT_EQ(result(), "virtual_tint_0"); -} - } // namespace } // namespace hlsl } // namespace writer diff --git a/src/writer/hlsl/generator_impl_intrinsic_test.cc b/src/writer/hlsl/generator_impl_intrinsic_test.cc index 1841ef6346..0306eda35e 100644 --- a/src/writer/hlsl/generator_impl_intrinsic_test.cc +++ b/src/writer/hlsl/generator_impl_intrinsic_test.cc @@ -74,7 +74,7 @@ TEST_F(HlslGeneratorImplTest_Intrinsic, DISABLED_Intrinsic_OuterProduct) { auto* a = Var("a", ast::StorageClass::kNone, ty.vec2()); auto* b = Var("b", ast::StorageClass::kNone, ty.vec3()); - auto* call = Call("outer_product", "a", "b"); + auto* call = Call("outerProduct", "a", "b"); td.RegisterVariableForTesting(a); td.RegisterVariableForTesting(b); diff --git a/src/writer/hlsl/generator_impl_intrinsic_texture_test.cc b/src/writer/hlsl/generator_impl_intrinsic_texture_test.cc index eeaef416ba..08e828bf6a 100644 --- a/src/writer/hlsl/generator_impl_intrinsic_texture_test.cc +++ b/src/writer/hlsl/generator_impl_intrinsic_texture_test.cc @@ -33,181 +33,181 @@ std::string expected_texture_overload( using ValidTextureOverload = ast::intrinsic::test::ValidTextureOverload; switch (overload) { case ValidTextureOverload::kSample1dF32: - return R"(texture_tint_0.Sample(sampler_tint_0, 1.0f))"; + return R"(texture.Sample(sampler, 1.0f))"; case ValidTextureOverload::kSample1dArrayF32: - return R"(texture_tint_0.Sample(sampler_tint_0, float2(1.0f, float(2))))"; + return R"(texture.Sample(sampler, float2(1.0f, float(2))))"; case ValidTextureOverload::kSample2dF32: - return R"(texture_tint_0.Sample(sampler_tint_0, float2(1.0f, 2.0f)))"; + return R"(texture.Sample(sampler, float2(1.0f, 2.0f)))"; case ValidTextureOverload::kSample2dOffsetF32: - return R"(texture_tint_0.Sample(sampler_tint_0, float2(1.0f, 2.0f), int2(3, 4)))"; + return R"(texture.Sample(sampler, float2(1.0f, 2.0f), int2(3, 4)))"; case ValidTextureOverload::kSample2dArrayF32: - return R"(texture_tint_0.Sample(sampler_tint_0, float3(1.0f, 2.0f, float(3))))"; + return R"(texture.Sample(sampler, float3(1.0f, 2.0f, float(3))))"; case ValidTextureOverload::kSample2dArrayOffsetF32: - return R"(texture_tint_0.Sample(sampler_tint_0, float3(1.0f, 2.0f, float(3)), int2(4, 5)))"; + return R"(texture.Sample(sampler, float3(1.0f, 2.0f, float(3)), int2(4, 5)))"; case ValidTextureOverload::kSample3dF32: - return R"(texture_tint_0.Sample(sampler_tint_0, float3(1.0f, 2.0f, 3.0f)))"; + return R"(texture.Sample(sampler, float3(1.0f, 2.0f, 3.0f)))"; case ValidTextureOverload::kSample3dOffsetF32: - return R"(texture_tint_0.Sample(sampler_tint_0, float3(1.0f, 2.0f, 3.0f), int3(4, 5, 6)))"; + return R"(texture.Sample(sampler, float3(1.0f, 2.0f, 3.0f), int3(4, 5, 6)))"; case ValidTextureOverload::kSampleCubeF32: - return R"(texture_tint_0.Sample(sampler_tint_0, float3(1.0f, 2.0f, 3.0f)))"; + return R"(texture.Sample(sampler, float3(1.0f, 2.0f, 3.0f)))"; case ValidTextureOverload::kSampleCubeArrayF32: - return R"(texture_tint_0.Sample(sampler_tint_0, float4(1.0f, 2.0f, 3.0f, float(4))))"; + return R"(texture.Sample(sampler, float4(1.0f, 2.0f, 3.0f, float(4))))"; case ValidTextureOverload::kSampleDepth2dF32: - return R"(texture_tint_0.Sample(sampler_tint_0, float2(1.0f, 2.0f)))"; + return R"(texture.Sample(sampler, float2(1.0f, 2.0f)))"; case ValidTextureOverload::kSampleDepth2dOffsetF32: - return R"(texture_tint_0.Sample(sampler_tint_0, float2(1.0f, 2.0f), int2(3, 4)))"; + return R"(texture.Sample(sampler, float2(1.0f, 2.0f), int2(3, 4)))"; case ValidTextureOverload::kSampleDepth2dArrayF32: - return R"(texture_tint_0.Sample(sampler_tint_0, float3(1.0f, 2.0f, float(3))))"; + return R"(texture.Sample(sampler, float3(1.0f, 2.0f, float(3))))"; case ValidTextureOverload::kSampleDepth2dArrayOffsetF32: - return R"(texture_tint_0.Sample(sampler_tint_0, float3(1.0f, 2.0f, float(3)), int2(4, 5)))"; + return R"(texture.Sample(sampler, float3(1.0f, 2.0f, float(3)), int2(4, 5)))"; case ValidTextureOverload::kSampleDepthCubeF32: - return R"(texture_tint_0.Sample(sampler_tint_0, float3(1.0f, 2.0f, 3.0f)))"; + return R"(texture.Sample(sampler, float3(1.0f, 2.0f, 3.0f)))"; case ValidTextureOverload::kSampleDepthCubeArrayF32: - return R"(texture_tint_0.Sample(sampler_tint_0, float4(1.0f, 2.0f, 3.0f, float(4))))"; + return R"(texture.Sample(sampler, float4(1.0f, 2.0f, 3.0f, float(4))))"; case ValidTextureOverload::kSampleBias2dF32: - return R"(texture_tint_0.SampleBias(sampler_tint_0, float2(1.0f, 2.0f), 3.0f))"; + return R"(texture.SampleBias(sampler, float2(1.0f, 2.0f), 3.0f))"; case ValidTextureOverload::kSampleBias2dOffsetF32: - return R"(texture_tint_0.SampleBias(sampler_tint_0, float2(1.0f, 2.0f), 3.0f, int2(4, 5)))"; + return R"(texture.SampleBias(sampler, float2(1.0f, 2.0f), 3.0f, int2(4, 5)))"; case ValidTextureOverload::kSampleBias2dArrayF32: - return R"(texture_tint_0.SampleBias(sampler_tint_0, float3(1.0f, 2.0f, float(4)), 3.0f))"; + return R"(texture.SampleBias(sampler, float3(1.0f, 2.0f, float(4)), 3.0f))"; case ValidTextureOverload::kSampleBias2dArrayOffsetF32: - return R"(texture_tint_0.SampleBias(sampler_tint_0, float3(1.0f, 2.0f, float(3)), 4.0f, int2(5, 6)))"; + return R"(texture.SampleBias(sampler, float3(1.0f, 2.0f, float(3)), 4.0f, int2(5, 6)))"; case ValidTextureOverload::kSampleBias3dF32: - return R"(texture_tint_0.SampleBias(sampler_tint_0, float3(1.0f, 2.0f, 3.0f), 4.0f))"; + return R"(texture.SampleBias(sampler, float3(1.0f, 2.0f, 3.0f), 4.0f))"; case ValidTextureOverload::kSampleBias3dOffsetF32: - return R"(texture_tint_0.SampleBias(sampler_tint_0, float3(1.0f, 2.0f, 3.0f), 4.0f, int3(5, 6, 7)))"; + return R"(texture.SampleBias(sampler, float3(1.0f, 2.0f, 3.0f), 4.0f, int3(5, 6, 7)))"; case ValidTextureOverload::kSampleBiasCubeF32: - return R"(texture_tint_0.SampleBias(sampler_tint_0, float3(1.0f, 2.0f, 3.0f), 4.0f))"; + return R"(texture.SampleBias(sampler, float3(1.0f, 2.0f, 3.0f), 4.0f))"; case ValidTextureOverload::kSampleBiasCubeArrayF32: - return R"(texture_tint_0.SampleBias(sampler_tint_0, float4(1.0f, 2.0f, 3.0f, float(3)), 4.0f))"; + return R"(texture.SampleBias(sampler, float4(1.0f, 2.0f, 3.0f, float(3)), 4.0f))"; case ValidTextureOverload::kSampleLevel2dF32: - return R"(texture_tint_0.SampleLevel(sampler_tint_0, float2(1.0f, 2.0f), 3.0f))"; + return R"(texture.SampleLevel(sampler, float2(1.0f, 2.0f), 3.0f))"; case ValidTextureOverload::kSampleLevel2dOffsetF32: - return R"(texture_tint_0.SampleLevel(sampler_tint_0, float2(1.0f, 2.0f), 3.0f, int2(4, 5)))"; + return R"(texture.SampleLevel(sampler, float2(1.0f, 2.0f), 3.0f, int2(4, 5)))"; case ValidTextureOverload::kSampleLevel2dArrayF32: - return R"(texture_tint_0.SampleLevel(sampler_tint_0, float3(1.0f, 2.0f, float(3)), 4.0f))"; + return R"(texture.SampleLevel(sampler, float3(1.0f, 2.0f, float(3)), 4.0f))"; case ValidTextureOverload::kSampleLevel2dArrayOffsetF32: - return R"(texture_tint_0.SampleLevel(sampler_tint_0, float3(1.0f, 2.0f, float(3)), 4.0f, int2(5, 6)))"; + return R"(texture.SampleLevel(sampler, float3(1.0f, 2.0f, float(3)), 4.0f, int2(5, 6)))"; case ValidTextureOverload::kSampleLevel3dF32: - return R"(texture_tint_0.SampleLevel(sampler_tint_0, float3(1.0f, 2.0f, 3.0f), 4.0f))"; + return R"(texture.SampleLevel(sampler, float3(1.0f, 2.0f, 3.0f), 4.0f))"; case ValidTextureOverload::kSampleLevel3dOffsetF32: - return R"(texture_tint_0.SampleLevel(sampler_tint_0, float3(1.0f, 2.0f, 3.0f), 4.0f, int3(5, 6, 7)))"; + return R"(texture.SampleLevel(sampler, float3(1.0f, 2.0f, 3.0f), 4.0f, int3(5, 6, 7)))"; case ValidTextureOverload::kSampleLevelCubeF32: - return R"(texture_tint_0.SampleLevel(sampler_tint_0, float3(1.0f, 2.0f, 3.0f), 4.0f))"; + return R"(texture.SampleLevel(sampler, float3(1.0f, 2.0f, 3.0f), 4.0f))"; case ValidTextureOverload::kSampleLevelCubeArrayF32: - return R"(texture_tint_0.SampleLevel(sampler_tint_0, float4(1.0f, 2.0f, 3.0f, float(4)), 5.0f))"; + return R"(texture.SampleLevel(sampler, float4(1.0f, 2.0f, 3.0f, float(4)), 5.0f))"; case ValidTextureOverload::kSampleLevelDepth2dF32: - return R"(texture_tint_0.SampleLevel(sampler_tint_0, float2(1.0f, 2.0f), 3))"; + return R"(texture.SampleLevel(sampler, float2(1.0f, 2.0f), 3))"; case ValidTextureOverload::kSampleLevelDepth2dOffsetF32: - return R"(texture_tint_0.SampleLevel(sampler_tint_0, float2(1.0f, 2.0f), 3, int2(4, 5)))"; + return R"(texture.SampleLevel(sampler, float2(1.0f, 2.0f), 3, int2(4, 5)))"; case ValidTextureOverload::kSampleLevelDepth2dArrayF32: - return R"(texture_tint_0.SampleLevel(sampler_tint_0, float3(1.0f, 2.0f, float(3)), 4))"; + return R"(texture.SampleLevel(sampler, float3(1.0f, 2.0f, float(3)), 4))"; case ValidTextureOverload::kSampleLevelDepth2dArrayOffsetF32: - return R"(texture_tint_0.SampleLevel(sampler_tint_0, float3(1.0f, 2.0f, float(3)), 4, int2(5, 6)))"; + return R"(texture.SampleLevel(sampler, float3(1.0f, 2.0f, float(3)), 4, int2(5, 6)))"; case ValidTextureOverload::kSampleLevelDepthCubeF32: - return R"(texture_tint_0.SampleLevel(sampler_tint_0, float3(1.0f, 2.0f, 3.0f), 4))"; + return R"(texture.SampleLevel(sampler, float3(1.0f, 2.0f, 3.0f), 4))"; case ValidTextureOverload::kSampleLevelDepthCubeArrayF32: - return R"(texture_tint_0.SampleLevel(sampler_tint_0, float4(1.0f, 2.0f, 3.0f, float(4)), 5))"; + return R"(texture.SampleLevel(sampler, float4(1.0f, 2.0f, 3.0f, float(4)), 5))"; case ValidTextureOverload::kSampleGrad2dF32: - return R"(texture_tint_0.SampleGrad(sampler_tint_0, float2(1.0f, 2.0f), float2(3.0f, 4.0f), float2(5.0f, 6.0f)))"; + return R"(texture.SampleGrad(sampler, float2(1.0f, 2.0f), float2(3.0f, 4.0f), float2(5.0f, 6.0f)))"; case ValidTextureOverload::kSampleGrad2dOffsetF32: - return R"(texture_tint_0.SampleGrad(sampler_tint_0, float2(1.0f, 2.0f), float2(3.0f, 4.0f), float2(5.0f, 6.0f), int2(7, 8)))"; + return R"(texture.SampleGrad(sampler, float2(1.0f, 2.0f), float2(3.0f, 4.0f), float2(5.0f, 6.0f), int2(7, 8)))"; case ValidTextureOverload::kSampleGrad2dArrayF32: - return R"(texture_tint_0.SampleGrad(sampler_tint_0, float3(1.0f, 2.0f, float(3)), float2(4.0f, 5.0f), float2(6.0f, 7.0f)))"; + return R"(texture.SampleGrad(sampler, float3(1.0f, 2.0f, float(3)), float2(4.0f, 5.0f), float2(6.0f, 7.0f)))"; case ValidTextureOverload::kSampleGrad2dArrayOffsetF32: - return R"(texture_tint_0.SampleGrad(sampler_tint_0, float3(1.0f, 2.0f, float(3)), float2(4.0f, 5.0f), float2(6.0f, 7.0f), int2(8, 9)))"; + return R"(texture.SampleGrad(sampler, float3(1.0f, 2.0f, float(3)), float2(4.0f, 5.0f), float2(6.0f, 7.0f), int2(8, 9)))"; case ValidTextureOverload::kSampleGrad3dF32: - return R"(texture_tint_0.SampleGrad(sampler_tint_0, float3(1.0f, 2.0f, 3.0f), float3(4.0f, 5.0f, 6.0f), float3(7.0f, 8.0f, 9.0f)))"; + return R"(texture.SampleGrad(sampler, float3(1.0f, 2.0f, 3.0f), float3(4.0f, 5.0f, 6.0f), float3(7.0f, 8.0f, 9.0f)))"; case ValidTextureOverload::kSampleGrad3dOffsetF32: - return R"(texture_tint_0.SampleGrad(sampler_tint_0, float3(1.0f, 2.0f, 3.0f), float3(4.0f, 5.0f, 6.0f), float3(7.0f, 8.0f, 9.0f), int3(10, 11, 12)))"; + return R"(texture.SampleGrad(sampler, float3(1.0f, 2.0f, 3.0f), float3(4.0f, 5.0f, 6.0f), float3(7.0f, 8.0f, 9.0f), int3(10, 11, 12)))"; case ValidTextureOverload::kSampleGradCubeF32: - return R"(texture_tint_0.SampleGrad(sampler_tint_0, float3(1.0f, 2.0f, 3.0f), float3(4.0f, 5.0f, 6.0f), float3(7.0f, 8.0f, 9.0f)))"; + return R"(texture.SampleGrad(sampler, float3(1.0f, 2.0f, 3.0f), float3(4.0f, 5.0f, 6.0f), float3(7.0f, 8.0f, 9.0f)))"; case ValidTextureOverload::kSampleGradCubeArrayF32: - return R"(texture_tint_0.SampleGrad(sampler_tint_0, float4(1.0f, 2.0f, 3.0f, float(4)), float3(5.0f, 6.0f, 7.0f), float3(8.0f, 9.0f, 10.0f)))"; + return R"(texture.SampleGrad(sampler, float4(1.0f, 2.0f, 3.0f, float(4)), float3(5.0f, 6.0f, 7.0f), float3(8.0f, 9.0f, 10.0f)))"; case ValidTextureOverload::kSampleGradDepth2dF32: - return R"(texture_tint_0.SampleCmp(sampler_tint_0, float2(1.0f, 2.0f), 3.0f))"; + return R"(texture.SampleCmp(sampler, float2(1.0f, 2.0f), 3.0f))"; case ValidTextureOverload::kSampleGradDepth2dOffsetF32: - return R"(texture_tint_0.SampleCmp(sampler_tint_0, float2(1.0f, 2.0f), 3.0f, int2(4, 5)))"; + return R"(texture.SampleCmp(sampler, float2(1.0f, 2.0f), 3.0f, int2(4, 5)))"; case ValidTextureOverload::kSampleGradDepth2dArrayF32: - return R"(texture_tint_0.SampleCmp(sampler_tint_0, float3(1.0f, 2.0f, float(4)), 3.0f))"; + return R"(texture.SampleCmp(sampler, float3(1.0f, 2.0f, float(4)), 3.0f))"; case ValidTextureOverload::kSampleGradDepth2dArrayOffsetF32: - return R"(texture_tint_0.SampleCmp(sampler_tint_0, float3(1.0f, 2.0f, float(4)), 3.0f, int2(5, 6)))"; + return R"(texture.SampleCmp(sampler, float3(1.0f, 2.0f, float(4)), 3.0f, int2(5, 6)))"; case ValidTextureOverload::kSampleGradDepthCubeF32: - return R"(texture_tint_0.SampleCmp(sampler_tint_0, float3(1.0f, 2.0f, 3.0f), 4.0f))"; + return R"(texture.SampleCmp(sampler, float3(1.0f, 2.0f, 3.0f), 4.0f))"; case ValidTextureOverload::kSampleGradDepthCubeArrayF32: - return R"(texture_tint_0.SampleCmp(sampler_tint_0, float4(1.0f, 2.0f, 3.0f, float(4)), 5.0f))"; + return R"(texture.SampleCmp(sampler, float4(1.0f, 2.0f, 3.0f, float(4)), 5.0f))"; case ValidTextureOverload::kLoad1dF32: - return R"(texture_tint_0.Load(int2(1, 0)))"; + return R"(texture.Load(int2(1, 0)))"; case ValidTextureOverload::kLoad1dU32: - return R"(texture_tint_0.Load(int2(1, 0)))"; + return R"(texture.Load(int2(1, 0)))"; case ValidTextureOverload::kLoad1dI32: - return R"(texture_tint_0.Load(int2(1, 0)))"; + return R"(texture.Load(int2(1, 0)))"; case ValidTextureOverload::kLoad1dArrayF32: - return R"(texture_tint_0.Load(int3(1, 2, 0)))"; + return R"(texture.Load(int3(1, 2, 0)))"; case ValidTextureOverload::kLoad1dArrayU32: - return R"(texture_tint_0.Load(int3(1, 2, 0)))"; + return R"(texture.Load(int3(1, 2, 0)))"; case ValidTextureOverload::kLoad1dArrayI32: - return R"(texture_tint_0.Load(int3(1, 2, 0)))"; + return R"(texture.Load(int3(1, 2, 0)))"; case ValidTextureOverload::kLoad2dF32: - return R"(texture_tint_0.Load(int3(1, 2, 0)))"; + return R"(texture.Load(int3(1, 2, 0)))"; case ValidTextureOverload::kLoad2dU32: - return R"(texture_tint_0.Load(int3(1, 2, 0)))"; + return R"(texture.Load(int3(1, 2, 0)))"; case ValidTextureOverload::kLoad2dI32: - return R"(texture_tint_0.Load(int3(1, 2, 0)))"; + return R"(texture.Load(int3(1, 2, 0)))"; case ValidTextureOverload::kLoad2dLevelF32: - return R"(texture_tint_0.Load(int3(1, 2, 0), 3))"; + return R"(texture.Load(int3(1, 2, 0), 3))"; case ValidTextureOverload::kLoad2dLevelU32: - return R"(texture_tint_0.Load(int3(1, 2, 0), 3))"; + return R"(texture.Load(int3(1, 2, 0), 3))"; case ValidTextureOverload::kLoad2dLevelI32: - return R"(texture_tint_0.Load(int3(1, 2, 0), 3))"; + return R"(texture.Load(int3(1, 2, 0), 3))"; case ValidTextureOverload::kLoad2dArrayF32: - return R"(texture_tint_0.Load(int4(1, 2, 3, 0)))"; + return R"(texture.Load(int4(1, 2, 3, 0)))"; case ValidTextureOverload::kLoad2dArrayU32: - return R"(texture_tint_0.Load(int4(1, 2, 3, 0)))"; + return R"(texture.Load(int4(1, 2, 3, 0)))"; case ValidTextureOverload::kLoad2dArrayI32: - return R"(texture_tint_0.Load(int4(1, 2, 3, 0)))"; + return R"(texture.Load(int4(1, 2, 3, 0)))"; case ValidTextureOverload::kLoad2dArrayLevelF32: - return R"(texture_tint_0.Load(int4(1, 2, 3, 0), 4))"; + return R"(texture.Load(int4(1, 2, 3, 0), 4))"; case ValidTextureOverload::kLoad2dArrayLevelU32: - return R"(texture_tint_0.Load(int4(1, 2, 3, 0), 4))"; + return R"(texture.Load(int4(1, 2, 3, 0), 4))"; case ValidTextureOverload::kLoad2dArrayLevelI32: - return R"(texture_tint_0.Load(int4(1, 2, 3, 0), 4))"; + return R"(texture.Load(int4(1, 2, 3, 0), 4))"; case ValidTextureOverload::kLoad3dF32: - return R"(texture_tint_0.Load(int4(1, 2, 3, 0)))"; + return R"(texture.Load(int4(1, 2, 3, 0)))"; case ValidTextureOverload::kLoad3dU32: - return R"(texture_tint_0.Load(int4(1, 2, 3, 0)))"; + return R"(texture.Load(int4(1, 2, 3, 0)))"; case ValidTextureOverload::kLoad3dI32: - return R"(texture_tint_0.Load(int4(1, 2, 3, 0)))"; + return R"(texture.Load(int4(1, 2, 3, 0)))"; case ValidTextureOverload::kLoad3dLevelF32: - return R"(texture_tint_0.Load(int4(1, 2, 3, 0), 4))"; + return R"(texture.Load(int4(1, 2, 3, 0), 4))"; case ValidTextureOverload::kLoad3dLevelU32: - return R"(texture_tint_0.Load(int4(1, 2, 3, 0), 4))"; + return R"(texture.Load(int4(1, 2, 3, 0), 4))"; case ValidTextureOverload::kLoad3dLevelI32: - return R"(texture_tint_0.Load(int4(1, 2, 3, 0), 4))"; + return R"(texture.Load(int4(1, 2, 3, 0), 4))"; case ValidTextureOverload::kLoadMultisampled2dF32: - return R"(texture_tint_0.Load(int3(1, 2, 0), 3))"; + return R"(texture.Load(int3(1, 2, 0), 3))"; case ValidTextureOverload::kLoadMultisampled2dU32: - return R"(texture_tint_0.Load(int3(1, 2, 0), 3))"; + return R"(texture.Load(int3(1, 2, 0), 3))"; case ValidTextureOverload::kLoadMultisampled2dI32: - return R"(texture_tint_0.Load(int3(1, 2, 0), 3))"; + return R"(texture.Load(int3(1, 2, 0), 3))"; case ValidTextureOverload::kLoadMultisampled2dArrayF32: - return R"(texture_tint_0.Load(int4(1, 2, 3, 0), 4))"; + return R"(texture.Load(int4(1, 2, 3, 0), 4))"; case ValidTextureOverload::kLoadMultisampled2dArrayU32: - return R"(texture_tint_0.Load(int4(1, 2, 3, 0), 4))"; + return R"(texture.Load(int4(1, 2, 3, 0), 4))"; case ValidTextureOverload::kLoadMultisampled2dArrayI32: - return R"(texture_tint_0.Load(int4(1, 2, 3, 0), 4))"; + return R"(texture.Load(int4(1, 2, 3, 0), 4))"; case ValidTextureOverload::kLoadDepth2dF32: - return R"(texture_tint_0.Load(int3(1, 2, 0)))"; + return R"(texture.Load(int3(1, 2, 0)))"; case ValidTextureOverload::kLoadDepth2dLevelF32: - return R"(texture_tint_0.Load(int3(1, 2, 0), 3))"; + return R"(texture.Load(int3(1, 2, 0), 3))"; case ValidTextureOverload::kLoadDepth2dArrayF32: - return R"(texture_tint_0.Load(int4(1, 2, 3, 0)))"; + return R"(texture.Load(int4(1, 2, 3, 0)))"; case ValidTextureOverload::kLoadDepth2dArrayLevelF32: - return R"(texture_tint_0.Load(int4(1, 2, 3, 0), 4))"; + return R"(texture.Load(int4(1, 2, 3, 0), 4))"; case ValidTextureOverload::kLoadStorageRO1dRgba32float: - return R"(texture_tint_0.Load(1))"; + return R"(texture.Load(1))"; case ValidTextureOverload::kLoadStorageRO1dArrayRgba32float: - return R"(texture_tint_0.Load(int2(1, 2)))"; + return R"(texture.Load(int2(1, 2)))"; case ValidTextureOverload::kLoadStorageRO2dRgba8unorm: case ValidTextureOverload::kLoadStorageRO2dRgba8snorm: case ValidTextureOverload::kLoadStorageRO2dRgba8uint: @@ -224,21 +224,21 @@ std::string expected_texture_overload( case ValidTextureOverload::kLoadStorageRO2dRgba32uint: case ValidTextureOverload::kLoadStorageRO2dRgba32sint: case ValidTextureOverload::kLoadStorageRO2dRgba32float: - return R"(texture_tint_0.Load(int2(1, 2)))"; + return R"(texture.Load(int2(1, 2)))"; case ValidTextureOverload::kLoadStorageRO2dArrayRgba32float: - return R"(texture_tint_0.Load(int3(1, 2, 3)))"; + return R"(texture.Load(int3(1, 2, 3)))"; case ValidTextureOverload::kLoadStorageRO3dRgba32float: - return R"(texture_tint_0.Load(int3(1, 2, 3)))"; + return R"(texture.Load(int3(1, 2, 3)))"; case ValidTextureOverload::kStoreWO1dRgba32float: - return R"(texture_tint_0[1] = float4(2.0f, 3.0f, 4.0f, 5.0f))"; + return R"(texture[1] = float4(2.0f, 3.0f, 4.0f, 5.0f))"; case ValidTextureOverload::kStoreWO1dArrayRgba32float: - return R"(texture_tint_0[int2(1, 2)] = float4(3.0f, 4.0f, 5.0f, 6.0f))"; + return R"(texture[int2(1, 2)] = float4(3.0f, 4.0f, 5.0f, 6.0f))"; case ValidTextureOverload::kStoreWO2dRgba32float: - return R"(texture_tint_0[int2(1, 2)] = float4(3.0f, 4.0f, 5.0f, 6.0f))"; + return R"(texture[int2(1, 2)] = float4(3.0f, 4.0f, 5.0f, 6.0f))"; case ValidTextureOverload::kStoreWO2dArrayRgba32float: - return R"(texture_tint_0[int3(1, 2, 3)] = float4(4.0f, 5.0f, 6.0f, 7.0f))"; + return R"(texture[int3(1, 2, 3)] = float4(4.0f, 5.0f, 6.0f, 7.0f))"; case ValidTextureOverload::kStoreWO3dRgba32float: - return R"(texture_tint_0[int3(1, 2, 3)] = float4(4.0f, 5.0f, 6.0f, 7.0f))"; + return R"(texture[int3(1, 2, 3)] = float4(4.0f, 5.0f, 6.0f, 7.0f))"; } return ""; } // NOLINT - Ignore the length of this function diff --git a/src/writer/hlsl/generator_impl_test.cc b/src/writer/hlsl/generator_impl_test.cc index 2a4f8eda61..75980eb776 100644 --- a/src/writer/hlsl/generator_impl_test.cc +++ b/src/writer/hlsl/generator_impl_test.cc @@ -39,25 +39,6 @@ TEST_F(HlslGeneratorImplTest, Generate) { )"); } -TEST_F(HlslGeneratorImplTest, InputStructName) { - ASSERT_EQ(gen.generate_name("func_main_in"), "func_main_in"); -} - -TEST_F(HlslGeneratorImplTest, InputStructName_ConflictWithExisting) { - // Register the struct name as existing. - auto* namer = gen.namer_for_testing(); - namer->NameFor("func_main_out"); - - ASSERT_EQ(gen.generate_name("func_main_out"), "func_main_out_0"); -} - -TEST_F(HlslGeneratorImplTest, NameConflictWith_InputStructName) { - ASSERT_EQ(gen.generate_name("func_main_in"), "func_main_in"); - - ASSERT_TRUE(gen.EmitIdentifier(pre, out, Expr("func_main_in"))); - EXPECT_EQ(result(), "func_main_in_0"); -} - struct HlslBuiltinData { ast::Builtin builtin; const char* attribute_name; diff --git a/src/writer/hlsl/generator_impl_type_test.cc b/src/writer/hlsl/generator_impl_type_test.cc index 644e75f53f..ef697cd610 100644 --- a/src/writer/hlsl/generator_impl_type_test.cc +++ b/src/writer/hlsl/generator_impl_type_test.cc @@ -46,25 +46,20 @@ using HlslGeneratorImplTest_Type = TestHelper; TEST_F(HlslGeneratorImplTest_Type, EmitType_Alias) { auto* alias = ty.alias("alias", ty.f32); - ASSERT_TRUE(gen.EmitType(out, alias, "")) << gen.error(); + ASSERT_TRUE(gen.EmitType(out, alias, Symbol())) << gen.error(); EXPECT_EQ(result(), "alias"); } -TEST_F(HlslGeneratorImplTest_Type, EmitType_Alias_NameCollision) { - auto* alias = ty.alias("bool", ty.f32); - - ASSERT_TRUE(gen.EmitType(out, alias, "")) << gen.error(); - EXPECT_EQ(result(), "bool_tint_0"); -} - TEST_F(HlslGeneratorImplTest_Type, EmitType_Array) { - ASSERT_TRUE(gen.EmitType(out, ty.array(), "ary")) << gen.error(); + auto sym = mod->RegisterSymbol("ary"); + ASSERT_TRUE(gen.EmitType(out, ty.array(), sym)) << gen.error(); EXPECT_EQ(result(), "bool ary[4]"); } TEST_F(HlslGeneratorImplTest_Type, EmitType_ArrayOfArray) { auto* arr = ty.array(ty.array(), 5); - ASSERT_TRUE(gen.EmitType(out, arr, "ary")) << gen.error(); + auto sym = mod->RegisterSymbol("ary"); + ASSERT_TRUE(gen.EmitType(out, arr, sym)) << gen.error(); EXPECT_EQ(result(), "bool ary[5][4]"); } @@ -72,54 +67,46 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_ArrayOfArray) { TEST_F(HlslGeneratorImplTest_Type, DISABLED_EmitType_ArrayOfArrayOfRuntimeArray) { auto* arr = ty.array(ty.array(ty.array(), 5), 0); - ASSERT_TRUE(gen.EmitType(out, arr, "ary")) << gen.error(); + auto sym = mod->RegisterSymbol("ary"); + ASSERT_TRUE(gen.EmitType(out, arr, sym)) << gen.error(); EXPECT_EQ(result(), "bool ary[5][4][1]"); } TEST_F(HlslGeneratorImplTest_Type, EmitType_ArrayOfArrayOfArray) { auto* arr = ty.array(ty.array(ty.array(), 5), 6); - ASSERT_TRUE(gen.EmitType(out, arr, "ary")) << gen.error(); + auto sym = mod->RegisterSymbol("ary"); + ASSERT_TRUE(gen.EmitType(out, arr, sym)) << gen.error(); EXPECT_EQ(result(), "bool ary[6][5][4]"); } -TEST_F(HlslGeneratorImplTest_Type, EmitType_Array_NameCollision) { - ASSERT_TRUE(gen.EmitType(out, ty.array(), "bool")) << gen.error(); - EXPECT_EQ(result(), "bool bool_tint_0[4]"); -} - TEST_F(HlslGeneratorImplTest_Type, EmitType_Array_WithoutName) { - ASSERT_TRUE(gen.EmitType(out, ty.array(), "")) << gen.error(); + ASSERT_TRUE(gen.EmitType(out, ty.array(), Symbol())) << gen.error(); EXPECT_EQ(result(), "bool[4]"); } TEST_F(HlslGeneratorImplTest_Type, DISABLED_EmitType_RuntimeArray) { - ASSERT_TRUE(gen.EmitType(out, ty.array(), "ary")) << gen.error(); + auto sym = mod->RegisterSymbol("ary"); + ASSERT_TRUE(gen.EmitType(out, ty.array(), sym)) << gen.error(); EXPECT_EQ(result(), "bool ary[]"); } -TEST_F(HlslGeneratorImplTest_Type, - DISABLED_EmitType_RuntimeArray_NameCollision) { - ASSERT_TRUE(gen.EmitType(out, ty.array(), "double")) << gen.error(); - EXPECT_EQ(result(), "bool double_tint_0[]"); -} - TEST_F(HlslGeneratorImplTest_Type, EmitType_Bool) { - ASSERT_TRUE(gen.EmitType(out, ty.bool_, "")) << gen.error(); + ASSERT_TRUE(gen.EmitType(out, ty.bool_, Symbol())) << gen.error(); EXPECT_EQ(result(), "bool"); } TEST_F(HlslGeneratorImplTest_Type, EmitType_F32) { - ASSERT_TRUE(gen.EmitType(out, ty.f32, "")) << gen.error(); + ASSERT_TRUE(gen.EmitType(out, ty.f32, Symbol())) << gen.error(); EXPECT_EQ(result(), "float"); } TEST_F(HlslGeneratorImplTest_Type, EmitType_I32) { - ASSERT_TRUE(gen.EmitType(out, ty.i32, "")) << gen.error(); + ASSERT_TRUE(gen.EmitType(out, ty.i32, Symbol())) << gen.error(); EXPECT_EQ(result(), "int"); } TEST_F(HlslGeneratorImplTest_Type, EmitType_Matrix) { - ASSERT_TRUE(gen.EmitType(out, ty.mat2x3(), "")) << gen.error(); + ASSERT_TRUE(gen.EmitType(out, ty.mat2x3(), Symbol())) << gen.error(); EXPECT_EQ(result(), "float3x2"); } @@ -127,7 +114,7 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_Matrix) { TEST_F(HlslGeneratorImplTest_Type, DISABLED_EmitType_Pointer) { ast::type::Pointer p(ty.f32, ast::StorageClass::kWorkgroup); - ASSERT_TRUE(gen.EmitType(out, &p, "")) << gen.error(); + ASSERT_TRUE(gen.EmitType(out, &p, Symbol())) << gen.error(); EXPECT_EQ(result(), "float*"); } @@ -153,7 +140,7 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_Struct) { ast::StructDecorationList{}); auto* s = ty.struct_("S", str); - ASSERT_TRUE(gen.EmitType(out, s, "")) << gen.error(); + ASSERT_TRUE(gen.EmitType(out, s, Symbol())) << gen.error(); EXPECT_EQ(result(), "S"); } @@ -165,7 +152,7 @@ TEST_F(HlslGeneratorImplTest_Type, DISABLED_EmitType_Struct_InjectPadding) { ast::StructDecorationList{}); auto* s = ty.struct_("S", str); - ASSERT_TRUE(gen.EmitType(out, s, "")) << gen.error(); + ASSERT_TRUE(gen.EmitType(out, s, Symbol())) << gen.error(); EXPECT_EQ(result(), R"(struct { int8_t pad_0[4]; int a; @@ -184,8 +171,8 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_Struct_NameCollision) { auto* s = ty.struct_("S", str); ASSERT_TRUE(gen.EmitStructType(out, s, "S")) << gen.error(); EXPECT_EQ(result(), R"(struct S { - int double_tint_0; - float float_tint_0; + int double; + float float; }; )"); } @@ -209,31 +196,31 @@ TEST_F(HlslGeneratorImplTest_Type, DISABLED_EmitType_Struct_WithDecoration) { } TEST_F(HlslGeneratorImplTest_Type, EmitType_U32) { - ASSERT_TRUE(gen.EmitType(out, ty.u32, "")) << gen.error(); + ASSERT_TRUE(gen.EmitType(out, ty.u32, Symbol())) << gen.error(); EXPECT_EQ(result(), "uint"); } TEST_F(HlslGeneratorImplTest_Type, EmitType_Vector) { - ASSERT_TRUE(gen.EmitType(out, ty.vec3(), "")) << gen.error(); + ASSERT_TRUE(gen.EmitType(out, ty.vec3(), Symbol())) << gen.error(); EXPECT_EQ(result(), "float3"); } TEST_F(HlslGeneratorImplTest_Type, EmitType_Void) { - ASSERT_TRUE(gen.EmitType(out, ty.void_, "")) << gen.error(); + ASSERT_TRUE(gen.EmitType(out, ty.void_, Symbol())) << gen.error(); EXPECT_EQ(result(), "void"); } TEST_F(HlslGeneratorImplTest_Type, EmitSampler) { ast::type::Sampler sampler(ast::type::SamplerKind::kSampler); - ASSERT_TRUE(gen.EmitType(out, &sampler, "")) << gen.error(); + ASSERT_TRUE(gen.EmitType(out, &sampler, Symbol())) << gen.error(); EXPECT_EQ(result(), "SamplerState"); } TEST_F(HlslGeneratorImplTest_Type, EmitSamplerComparison) { ast::type::Sampler sampler(ast::type::SamplerKind::kComparisonSampler); - ASSERT_TRUE(gen.EmitType(out, &sampler, "")) << gen.error(); + ASSERT_TRUE(gen.EmitType(out, &sampler, Symbol())) << gen.error(); EXPECT_EQ(result(), "SamplerComparisonState"); } @@ -251,7 +238,7 @@ TEST_P(HlslDepthtexturesTest, Emit) { ast::type::DepthTexture s(params.dim); - ASSERT_TRUE(gen.EmitType(out, &s, "")) << gen.error(); + ASSERT_TRUE(gen.EmitType(out, &s, Symbol())) << gen.error(); EXPECT_EQ(result(), params.result); } INSTANTIATE_TEST_SUITE_P( @@ -279,7 +266,7 @@ TEST_P(HlslSampledtexturesTest, Emit) { ast::type::SampledTexture s(params.dim, ty.f32); - ASSERT_TRUE(gen.EmitType(out, &s, "")) << gen.error(); + ASSERT_TRUE(gen.EmitType(out, &s, Symbol())) << gen.error(); EXPECT_EQ(result(), params.result); } INSTANTIATE_TEST_SUITE_P( @@ -300,7 +287,7 @@ INSTANTIATE_TEST_SUITE_P( TEST_F(HlslGeneratorImplTest_Type, EmitMultisampledTexture) { ast::type::MultisampledTexture s(ast::type::TextureDimension::k2d, ty.f32); - ASSERT_TRUE(gen.EmitType(out, &s, "")) << gen.error(); + ASSERT_TRUE(gen.EmitType(out, &s, Symbol())) << gen.error(); EXPECT_EQ(result(), "Texture2D"); } @@ -324,7 +311,7 @@ TEST_P(HlslStoragetexturesTest, Emit) { : ast::AccessControl::kWriteOnly, params.imgfmt); - ASSERT_TRUE(gen.EmitType(out, &s, "")) << gen.error(); + ASSERT_TRUE(gen.EmitType(out, &s, Symbol())) << gen.error(); EXPECT_EQ(result(), params.result); } INSTANTIATE_TEST_SUITE_P( diff --git a/src/writer/hlsl/namer.cc b/src/writer/hlsl/namer.cc deleted file mode 100644 index a577d639e2..0000000000 --- a/src/writer/hlsl/namer.cc +++ /dev/null @@ -1,696 +0,0 @@ -// Copyright 2020 The Tint Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "src/writer/hlsl/namer.h" - -#include - -namespace tint { -namespace writer { -namespace hlsl { -namespace { - -// This list is used for a binary search and must be kept in sorted order. -const char* kNames[] = {"AddressU", - "AddressV", - "AddressW", - "AllMemoryBarrier", - "AllMemoryBarrierWithGroupSync", - "AppendStructuredBuffer", - "BINORMAL", - "BLENDINDICES", - "BLENDWEIGHT", - "BlendState", - "BorderColor", - "Buffer", - "ByteAddressBuffer", - "COLOR", - "CheckAccessFullyMapped", - "ComparisonFunc", - "CompileShader", - "ComputeShader", - "ConsumeStructuredBuffer", - "D3DCOLORtoUBYTE4", - "DEPTH", - "DepthStencilState", - "DepthStencilView", - "DeviceMemoryBarrier", - "DeviceMemroyBarrierWithGroupSync", - "DomainShader", - "EvaluateAttributeAtCentroid", - "EvaluateAttributeAtSample", - "EvaluateAttributeSnapped", - "FOG", - "Filter", - "GeometryShader", - "GetRenderTargetSampleCount", - "GetRenderTargetSamplePosition", - "GroupMemoryBarrier", - "GroupMemroyBarrierWithGroupSync", - "Hullshader", - "InputPatch", - "InterlockedAdd", - "InterlockedAnd", - "InterlockedCompareExchange", - "InterlockedCompareStore", - "InterlockedExchange", - "InterlockedMax", - "InterlockedMin", - "InterlockedOr", - "InterlockedXor", - "LineStream", - "MaxAnisotropy", - "MaxLOD", - "MinLOD", - "MipLODBias", - "NORMAL", - "NULL", - "Normal", - "OutputPatch", - "POSITION", - "POSITIONT", - "PSIZE", - "PixelShader", - "PointStream", - "Process2DQuadTessFactorsAvg", - "Process2DQuadTessFactorsMax", - "Process2DQuadTessFactorsMin", - "ProcessIsolineTessFactors", - "ProcessQuadTessFactorsAvg", - "ProcessQuadTessFactorsMax", - "ProcessQuadTessFactorsMin", - "ProcessTriTessFactorsAvg", - "ProcessTriTessFactorsMax", - "ProcessTriTessFactorsMin", - "RWBuffer", - "RWByteAddressBuffer", - "RWStructuredBuffer", - "RWTexture1D", - "RWTexture1DArray", - "RWTexture2D", - "RWTexture2DArray", - "RWTexture3D", - "RasterizerState", - "RenderTargetView", - "SV_ClipDistance", - "SV_Coverage", - "SV_CullDistance", - "SV_Depth", - "SV_DepthGreaterEqual", - "SV_DepthLessEqual", - "SV_DispatchThreadID", - "SV_DomainLocation", - "SV_GSInstanceID", - "SV_GroupID", - "SV_GroupIndex", - "SV_GroupThreadID", - "SV_InnerCoverage", - "SV_InsideTessFactor", - "SV_InstanceID", - "SV_IsFrontFace", - "SV_OutputControlPointID", - "SV_Position", - "SV_PrimitiveID", - "SV_RenderTargetArrayIndex", - "SV_SampleIndex", - "SV_StencilRef", - "SV_Target", - "SV_TessFactor", - "SV_VertexArrayIndex", - "SV_VertexID", - "Sampler", - "Sampler1D", - "Sampler2D", - "Sampler3D", - "SamplerCUBE", - "StructuredBuffer", - "TANGENT", - "TESSFACTOR", - "TEXCOORD", - "Texcoord", - "Texture", - "Texture1D", - "Texture1DArray", - "Texture2D", - "Texture2DArray", - "Texture2DMS", - "Texture2DMSArray", - "Texture3D", - "TextureCube", - "TextureCubeArray", - "TriangleStream", - "VFACE", - "VPOS", - "VertexShader", - "abort", - "abs", - "acos", - "all", - "allow_uav_condition", - "any", - "asdouble", - "asfloat", - "asin", - "asint", - "asm", - "asm_fragment", - "asuint", - "atan", - "atan2", - "auto", - "bool", - "bool1", - "bool1x1", - "bool1x2", - "bool1x3", - "bool1x4", - "bool2", - "bool2x1", - "bool2x2", - "bool2x3", - "bool2x4", - "bool3", - "bool3x1", - "bool3x2", - "bool3x3", - "bool3x4", - "bool4", - "bool4x1", - "bool4x2", - "bool4x3", - "bool4x4", - "branch", - "break", - "call", - "case", - "catch", - "cbuffer", - "ceil", - "centroid", - "char", - "clamp", - "class", - "clip", - "column_major", - "compile_fragment", - "const", - "const_cast", - "continue", - "cos", - "cosh", - "countbits", - "cross", - "ddx", - "ddx_coarse", - "ddx_fine", - "ddy", - "ddy_coarse", - "ddy_fine", - "degrees", - "delete", - "determinant", - "discard", - "distance", - "do", - "dot", - "double", - "double1", - "double1x1", - "double1x2", - "double1x3", - "double1x4", - "double2", - "double2x1", - "double2x2", - "double2x3", - "double2x4", - "double3", - "double3x1", - "double3x2", - "double3x3", - "double3x4", - "double4", - "double4x1", - "double4x2", - "double4x3", - "double4x4", - "dst", - "dword", - "dword1", - "dword1x1", - "dword1x2", - "dword1x3", - "dword1x4", - "dword2", - "dword2x1", - "dword2x2", - "dword2x3", - "dword2x4", - "dword3", - "dword3x1", - "dword3x2", - "dword3x3", - "dword3x4", - "dword4", - "dword4x1", - "dword4x2", - "dword4x3", - "dword4x4", - "dynamic_cast", - "else", - "enum", - "errorf", - "exp", - "exp2", - "explicit", - "export", - "extern", - "f16to32", - "f32tof16", - "faceforward", - "false", - "fastopt", - "firstbithigh", - "firstbitlow", - "flatten", - "float", - "float1", - "float1x1", - "float1x2", - "float1x3", - "float1x4", - "float2", - "float2x1", - "float2x2", - "float2x3", - "float2x4", - "float3", - "float3x1", - "float3x2", - "float3x3", - "float3x4", - "float4", - "float4x1", - "float4x2", - "float4x3", - "float4x4", - "floor", - "fma", - "fmod", - "for", - "forcecase", - "frac", - "frexp", - "friend", - "fwidth", - "fxgroup", - "goto", - "groupshared", - "half", - "half1", - "half1x1", - "half1x2", - "half1x3", - "half1x4", - "half2", - "half2x1", - "half2x2", - "half2x3", - "half2x4", - "half3", - "half3x1", - "half3x2", - "half3x3", - "half3x4", - "half4", - "half4x1", - "half4x2", - "half4x3", - "half4x4", - "if", - "in", - "inline", - "inout", - "int", - "int1", - "int1x1", - "int1x2", - "int1x3", - "int1x4", - "int2", - "int2x1", - "int2x2", - "int2x3", - "int2x4", - "int3", - "int3x1", - "int3x2", - "int3x3", - "int3x4", - "int4", - "int4x1", - "int4x2", - "int4x3", - "int4x4", - "interface", - "isfinite", - "isinf", - "isnan", - "ldexp", - "length", - "lerp", - "lineadj", - "linear", - "lit", - "log", - "log10", - "log2", - "long", - "loop", - "mad", - "matrix", - "max", - "min", - "min10float", - "min10float1", - "min10float1x1", - "min10float1x2", - "min10float1x3", - "min10float1x4", - "min10float2", - "min10float2x1", - "min10float2x2", - "min10float2x3", - "min10float2x4", - "min10float3", - "min10float3x1", - "min10float3x2", - "min10float3x3", - "min10float3x4", - "min10float4", - "min10float4x1", - "min10float4x2", - "min10float4x3", - "min10float4x4", - "min12int", - "min12int1", - "min12int1x1", - "min12int1x2", - "min12int1x3", - "min12int1x4", - "min12int2", - "min12int2x1", - "min12int2x2", - "min12int2x3", - "min12int2x4", - "min12int3", - "min12int3x1", - "min12int3x2", - "min12int3x3", - "min12int3x4", - "min12int4", - "min12int4x1", - "min12int4x2", - "min12int4x3", - "min12int4x4", - "min16float", - "min16float1", - "min16float1x1", - "min16float1x2", - "min16float1x3", - "min16float1x4", - "min16float2", - "min16float2x1", - "min16float2x2", - "min16float2x3", - "min16float2x4", - "min16float3", - "min16float3x1", - "min16float3x2", - "min16float3x3", - "min16float3x4", - "min16float4", - "min16float4x1", - "min16float4x2", - "min16float4x3", - "min16float4x4", - "min16int", - "min16int1", - "min16int1x1", - "min16int1x2", - "min16int1x3", - "min16int1x4", - "min16int2", - "min16int2x1", - "min16int2x2", - "min16int2x3", - "min16int2x4", - "min16int3", - "min16int3x1", - "min16int3x2", - "min16int3x3", - "min16int3x4", - "min16int4", - "min16int4x1", - "min16int4x2", - "min16int4x3", - "min16int4x4", - "min16uint", - "min16uint1", - "min16uint1x1", - "min16uint1x2", - "min16uint1x3", - "min16uint1x4", - "min16uint2", - "min16uint2x1", - "min16uint2x2", - "min16uint2x3", - "min16uint2x4", - "min16uint3", - "min16uint3x1", - "min16uint3x2", - "min16uint3x3", - "min16uint3x4", - "min16uint4", - "min16uint4x1", - "min16uint4x2", - "min16uint4x3", - "min16uint4x4", - "modf", - "msad4", - "mul", - "mutable", - "namespace", - "new", - "nointerpolation", - "noise", - "noperspective", - "normalize", - "numthreads", - "operator", - "out", - "packoffset", - "pass", - "pixelfragment", - "pixelshader", - "point", - "pow", - "precise", - "printf", - "private", - "protected", - "public", - "radians", - "rcp", - "reflect", - "refract", - "register", - "reinterpret_cast", - "return", - "reversebits", - "round", - "row_major", - "rsqrt", - "sample", - "sampler", - "sampler1D", - "sampler2D", - "sampler3D", - "samplerCUBE", - "sampler_state", - "saturate", - "shared", - "short", - "sign", - "signed", - "sin", - "sincos", - "sinh", - "sizeof", - "smoothstep", - "snorm", - "sqrt", - "stateblock", - "stateblock_state", - "static", - "static_cast", - "step", - "string", - "struct", - "switch", - "tan", - "tanh", - "tbuffer", - "technique", - "technique10", - "technique11", - "template", - "tex1D", - "tex1Dbias", - "tex1Dgrad", - "tex1Dlod", - "tex1Dproj", - "tex2D", - "tex2Dbias", - "tex2Dgrad", - "tex2Dlod", - "tex2Dproj", - "tex3D", - "tex3Dbias", - "tex3Dgrad", - "tex3Dlod", - "tex3Dproj", - "texCUBE", - "texCUBEbias", - "texCUBEgrad", - "texCUBElod", - "texCUBEproj", - "texture", - "texture1D", - "texture1DArray", - "texture2D", - "texture2DArray", - "texture2DMS", - "texture2DMSArray", - "texture3D", - "textureCube", - "textureCubeArray", - "this", - "throw", - "transpose", - "triangle", - "triangleadj", - "true", - "trunc", - "try", - "typedef", - "typename", - "uint", - "uint1", - "uint1x1", - "uint1x2", - "uint1x3", - "uint1x4", - "uint2", - "uint2x1", - "uint2x2", - "uint2x3", - "uint2x4", - "uint3", - "uint3x1", - "uint3x2", - "uint3x3", - "uint3x4", - "uint4", - "uint4x1", - "uint4x2", - "uint4x3", - "uint4x4", - "uniform", - "union", - "unorm", - "unroll", - "unsigned", - "using", - "vector", - "vertexfragment", - "vertexshader", - "virtual", - "void", - "volatile", - "while"}; - -} // namespace - -Namer::Namer() = default; - -Namer::~Namer() = default; - -std::string Namer::NameFor(const std::string& name) { - // If it's in the name map we can just return it. There are no shadow names - // in WGSL so this has to be unique in the WGSL names, and we've already - // checked the name collisions with HLSL. - auto it = name_map_.find(name); - if (it != name_map_.end()) { - return it->second; - } - - std::string ret_name = name; - if (std::binary_search(std::begin(kNames), std::end(kNames), ret_name)) { - uint32_t i = 0; - // Make sure there wasn't already a tint variable with the new name we've - // now created. - while (true) { - ret_name = name + "_tint_" + std::to_string(i); - it = name_map_.find(ret_name); - if (it == name_map_.end()) { - break; - } - i++; - } - RegisterRemappedName(ret_name); - } else { - uint32_t i = 0; - // Make sure the ident name wasn't assigned by a remapping. - while (true) { - if (!IsRemapped(ret_name)) { - break; - } - ret_name = name + "_" + std::to_string(i); - i++; - } - RegisterRemappedName(ret_name); - } - - name_map_[name] = ret_name; - return ret_name; -} - -bool Namer::IsMapped(const std::string& name) { - auto it = name_map_.find(name); - return it != name_map_.end(); -} - -bool Namer::IsRemapped(const std::string& name) { - auto it = remapped_names_.find(name); - return it != remapped_names_.end(); -} - -void Namer::RegisterRemappedName(const std::string& name) { - remapped_names_.insert(name); -} - -} // namespace hlsl -} // namespace writer -} // namespace tint diff --git a/src/writer/hlsl/namer.h b/src/writer/hlsl/namer.h deleted file mode 100644 index c067e2230a..0000000000 --- a/src/writer/hlsl/namer.h +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright 2020 The Tint Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#ifndef SRC_WRITER_HLSL_NAMER_H_ -#define SRC_WRITER_HLSL_NAMER_H_ - -#include -#include -#include - -namespace tint { -namespace writer { -namespace hlsl { - -/// Remaps maps names to avoid reserved words and collisions for HLSL. -class Namer { - public: - /// Constructor - Namer(); - ~Namer(); - - /// Returns a sanitized version of `name` - /// @param name the name to sanitize - /// @returns the sanitized version of `name` - std::string NameFor(const std::string& name); - - /// Registers a remapped name. - /// @param name the name to register - void RegisterRemappedName(const std::string& name); - - /// Returns if the given name has been mapped already - /// @param name the name to check - /// @returns true if the name has been mapped - bool IsMapped(const std::string& name); - - /// Returns if the given name has been remapped already - /// @param name the name to check - /// @returns true if the name has been remapped - bool IsRemapped(const std::string& name); - - private: - /// Map of original name to new name. The two names may be the same. - std::unordered_map name_map_; - // The list of names taken by the remapper - std::unordered_set remapped_names_; -}; - -} // namespace hlsl -} // namespace writer -} // namespace tint - -#endif // SRC_WRITER_HLSL_NAMER_H_ diff --git a/src/writer/hlsl/namer_test.cc b/src/writer/hlsl/namer_test.cc deleted file mode 100644 index adb2ee5a91..0000000000 --- a/src/writer/hlsl/namer_test.cc +++ /dev/null @@ -1,667 +0,0 @@ -// Copyright 2020 The Tint Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "src/writer/hlsl/namer.h" - -#include "gtest/gtest.h" - -namespace tint { -namespace writer { -namespace hlsl { -namespace { - -using HlslNamerTest = testing::Test; - -TEST_F(HlslNamerTest, ReturnsName) { - Namer n; - EXPECT_EQ("my_name", n.NameFor("my_name")); - EXPECT_EQ("my_name", n.NameFor("my_name")); -} - -TEST_F(HlslNamerTest, HandlesConflictWithRenamedReservedWordAfterIdentSeen) { - Namer n; - EXPECT_EQ("float_tint_0", n.NameFor("float_tint_0")); - EXPECT_EQ("float_tint_1", n.NameFor("float")); - EXPECT_EQ("float_tint_0", n.NameFor("float_tint_0")); -} - -TEST_F(HlslNamerTest, HandlesConflictWithRenamedReservedWordBeforeIdentSeen) { - Namer n; - EXPECT_EQ("float_tint_0", n.NameFor("float")); - EXPECT_EQ("float_tint_0_0", n.NameFor("float_tint_0")); - EXPECT_EQ("float_tint_0_0_0", n.NameFor("float_tint_0_0")); - EXPECT_EQ("float_tint_0_0", n.NameFor("float_tint_0")); -} - -using HlslReservedNameTest = testing::TestWithParam; -TEST_P(HlslReservedNameTest, Emit) { - auto name = GetParam(); - - Namer n; - EXPECT_EQ(name + "_tint_0", n.NameFor(name)); -} -INSTANTIATE_TEST_SUITE_P(HlslNamerTest, - HlslReservedNameTest, - testing::Values("AddressU", - "AddressV", - "AddressW", - "AllMemoryBarrier", - "AllMemoryBarrierWithGroupSync", - "AppendStructuredBuffer", - "BINORMAL", - "BLENDINDICES", - "BLENDWEIGHT", - "BlendState", - "BorderColor", - "Buffer", - "ByteAddressBuffer", - "COLOR", - "CheckAccessFullyMapped", - "ComparisonFunc", - "CompileShader", - "ComputeShader", - "ConsumeStructuredBuffer", - "D3DCOLORtoUBYTE4", - "DEPTH", - "DepthStencilState", - "DepthStencilView", - "DeviceMemoryBarrier", - "DeviceMemroyBarrierWithGroupSync", - "DomainShader", - "EvaluateAttributeAtCentroid", - "EvaluateAttributeAtSample", - "EvaluateAttributeSnapped", - "FOG", - "Filter", - "GeometryShader", - "GetRenderTargetSampleCount", - "GetRenderTargetSamplePosition", - "GroupMemoryBarrier", - "GroupMemroyBarrierWithGroupSync", - "Hullshader", - "InputPatch", - "InterlockedAdd", - "InterlockedAnd", - "InterlockedCompareExchange", - "InterlockedCompareStore", - "InterlockedExchange", - "InterlockedMax", - "InterlockedMin", - "InterlockedOr", - "InterlockedXor", - "LineStream", - "MaxAnisotropy", - "MaxLOD", - "MinLOD", - "MipLODBias", - "NORMAL", - "NULL", - "Normal", - "OutputPatch", - "POSITION", - "POSITIONT", - "PSIZE", - "PixelShader", - "PointStream", - "Process2DQuadTessFactorsAvg", - "Process2DQuadTessFactorsMax", - "Process2DQuadTessFactorsMin", - "ProcessIsolineTessFactors", - "ProcessQuadTessFactorsAvg", - "ProcessQuadTessFactorsMax", - "ProcessQuadTessFactorsMin", - "ProcessTriTessFactorsAvg", - "ProcessTriTessFactorsMax", - "ProcessTriTessFactorsMin", - "RWBuffer", - "RWByteAddressBuffer", - "RWStructuredBuffer", - "RWTexture1D", - "RWTexture1DArray", - "RWTexture2D", - "RWTexture2DArray", - "RWTexture3D", - "RasterizerState", - "RenderTargetView", - "SV_ClipDistance", - "SV_Coverage", - "SV_CullDistance", - "SV_Depth", - "SV_DepthGreaterEqual", - "SV_DepthLessEqual", - "SV_DispatchThreadID", - "SV_DomainLocation", - "SV_GSInstanceID", - "SV_GroupID", - "SV_GroupIndex", - "SV_GroupThreadID", - "SV_InnerCoverage", - "SV_InsideTessFactor", - "SV_InstanceID", - "SV_IsFrontFace", - "SV_OutputControlPointID", - "SV_Position", - "SV_PrimitiveID", - "SV_RenderTargetArrayIndex", - "SV_SampleIndex", - "SV_StencilRef", - "SV_Target", - "SV_TessFactor", - "SV_VertexArrayIndex", - "SV_VertexID", - "Sampler", - "Sampler1D", - "Sampler2D", - "Sampler3D", - "SamplerCUBE", - "StructuredBuffer", - "TANGENT", - "TESSFACTOR", - "TEXCOORD", - "Texcoord", - "Texture", - "Texture1D", - "Texture1DArray", - "Texture2D", - "Texture2DArray", - "Texture2DMS", - "Texture2DMSArray", - "Texture3D", - "TextureCube", - "TextureCubeArray", - "TriangleStream", - "VFACE", - "VPOS", - "VertexShader", - "abort", - "abs", - "acos", - "all", - "allow_uav_condition", - "any", - "asdouble", - "asfloat", - "asin", - "asint", - "asm", - "asm_fragment", - "asuint", - "atan", - "atan2", - "auto", - "bool", - "bool1", - "bool1x1", - "bool1x2", - "bool1x3", - "bool1x4", - "bool2", - "bool2x1", - "bool2x2", - "bool2x3", - "bool2x4", - "bool3", - "bool3x1", - "bool3x2", - "bool3x3", - "bool3x4", - "bool4", - "bool4x1", - "bool4x2", - "bool4x3", - "bool4x4", - "branch", - "break", - "call", - "case", - "catch", - "cbuffer", - "ceil", - "centroid", - "char", - "clamp", - "class", - "clip", - "column_major", - "compile_fragment", - "const", - "const_cast", - "continue", - "cos", - "cosh", - "countbits", - "cross", - "ddx", - "ddx_coarse", - "ddx_fine", - "ddy", - "ddy_coarse", - "ddy_fine", - "degrees", - "delete", - "determinant", - "discard", - "distance", - "do", - "dot", - "double", - "double1", - "double1x1", - "double1x2", - "double1x3", - "double1x4", - "double2", - "double2x1", - "double2x2", - "double2x3", - "double2x4", - "double3", - "double3x1", - "double3x2", - "double3x3", - "double3x4", - "double4", - "double4x1", - "double4x2", - "double4x3", - "double4x4", - "dst", - "dword", - "dword1", - "dword1x1", - "dword1x2", - "dword1x3", - "dword1x4", - "dword2", - "dword2x1", - "dword2x2", - "dword2x3", - "dword2x4", - "dword3", - "dword3x1", - "dword3x2", - "dword3x3", - "dword3x4", - "dword4", - "dword4x1", - "dword4x2", - "dword4x3", - "dword4x4", - "dynamic_cast", - "else", - "enum", - "errorf", - "exp", - "exp2", - "explicit", - "export", - "extern", - "f16to32", - "f32tof16", - "faceforward", - "false", - "fastopt", - "firstbithigh", - "firstbitlow", - "flatten", - "float", - "float1", - "float1x1", - "float1x2", - "float1x3", - "float1x4", - "float2", - "float2x1", - "float2x2", - "float2x3", - "float2x4", - "float3", - "float3x1", - "float3x2", - "float3x3", - "float3x4", - "float4", - "float4x1", - "float4x2", - "float4x3", - "float4x4", - "floor", - "fma", - "fmod", - "for", - "forcecase", - "frac", - "frexp", - "friend", - "fwidth", - "fxgroup", - "goto", - "groupshared", - "half", - "half1", - "half1x1", - "half1x2", - "half1x3", - "half1x4", - "half2", - "half2x1", - "half2x2", - "half2x3", - "half2x4", - "half3", - "half3x1", - "half3x2", - "half3x3", - "half3x4", - "half4", - "half4x1", - "half4x2", - "half4x3", - "half4x4", - "if", - "in", - "inline", - "inout", - "int", - "int1", - "int1x1", - "int1x2", - "int1x3", - "int1x4", - "int2", - "int2x1", - "int2x2", - "int2x3", - "int2x4", - "int3", - "int3x1", - "int3x2", - "int3x3", - "int3x4", - "int4", - "int4x1", - "int4x2", - "int4x3", - "int4x4", - "interface", - "isfinite", - "isinf", - "isnan", - "ldexp", - "length", - "lerp", - "lineadj", - "linear", - "lit", - "log", - "log10", - "log2", - "long", - "loop", - "mad", - "matrix", - "max", - "min", - "min10float", - "min10float1", - "min10float1x1", - "min10float1x2", - "min10float1x3", - "min10float1x4", - "min10float2", - "min10float2x1", - "min10float2x2", - "min10float2x3", - "min10float2x4", - "min10float3", - "min10float3x1", - "min10float3x2", - "min10float3x3", - "min10float3x4", - "min10float4", - "min10float4x1", - "min10float4x2", - "min10float4x3", - "min10float4x4", - "min12int", - "min12int1", - "min12int1x1", - "min12int1x2", - "min12int1x3", - "min12int1x4", - "min12int2", - "min12int2x1", - "min12int2x2", - "min12int2x3", - "min12int2x4", - "min12int3", - "min12int3x1", - "min12int3x2", - "min12int3x3", - "min12int3x4", - "min12int4", - "min12int4x1", - "min12int4x2", - "min12int4x3", - "min12int4x4", - "min16float", - "min16float1", - "min16float1x1", - "min16float1x2", - "min16float1x3", - "min16float1x4", - "min16float2", - "min16float2x1", - "min16float2x2", - "min16float2x3", - "min16float2x4", - "min16float3", - "min16float3x1", - "min16float3x2", - "min16float3x3", - "min16float3x4", - "min16float4", - "min16float4x1", - "min16float4x2", - "min16float4x3", - "min16float4x4", - "min16int", - "min16int1", - "min16int1x1", - "min16int1x2", - "min16int1x3", - "min16int1x4", - "min16int2", - "min16int2x1", - "min16int2x2", - "min16int2x3", - "min16int2x4", - "min16int3", - "min16int3x1", - "min16int3x2", - "min16int3x3", - "min16int3x4", - "min16int4", - "min16int4x1", - "min16int4x2", - "min16int4x3", - "min16int4x4", - "min16uint", - "min16uint1", - "min16uint1x1", - "min16uint1x2", - "min16uint1x3", - "min16uint1x4", - "min16uint2", - "min16uint2x1", - "min16uint2x2", - "min16uint2x3", - "min16uint2x4", - "min16uint3", - "min16uint3x1", - "min16uint3x2", - "min16uint3x3", - "min16uint3x4", - "min16uint4", - "min16uint4x1", - "min16uint4x2", - "min16uint4x3", - "min16uint4x4", - "modf", - "msad4", - "mul", - "mutable", - "namespace", - "new", - "nointerpolation", - "noise", - "noperspective", - "normalize", - "numthreads", - "operator", - "out", - "packoffset", - "pass", - "pixelfragment", - "pixelshader", - "point", - "pow", - "precise", - "printf", - "private", - "protected", - "public", - "radians", - "rcp", - "reflect", - "refract", - "register", - "reinterpret_cast", - "return", - "reversebits", - "round", - "row_major", - "rsqrt", - "sample", - "sampler1D", - "sampler2D", - "sampler3D", - "samplerCUBE", - "sampler_state", - "saturate", - "shared", - "short", - "sign", - "signed", - "sin", - "sincos", - "sinh", - "sizeof", - "smoothstep", - "snorm", - "sqrt", - "stateblock", - "stateblock_state", - "static", - "static_cast", - "step", - "string", - "struct", - "switch", - "tan", - "tanh", - "tbuffer", - "technique", - "technique10", - "technique11", - "template", - "tex1D", - "tex1Dbias", - "tex1Dgrad", - "tex1Dlod", - "tex1Dproj", - "tex2D", - "tex2Dbias", - "tex2Dgrad", - "tex2Dlod", - "tex2Dproj", - "tex3D", - "tex3Dbias", - "tex3Dgrad", - "tex3Dlod", - "tex3Dproj", - "texCUBE", - "texCUBEbias", - "texCUBEgrad", - "texCUBElod", - "texCUBEproj", - "texture", - "texture1D", - "texture1DArray", - "texture2D", - "texture2DArray", - "texture2DMS", - "texture2DMSArray", - "texture3D", - "textureCube", - "textureCubeArray", - "this", - "throw", - "transpose", - "triangle", - "triangleadj", - "true", - "trunc", - "try", - "typedef", - "typename", - "uint", - "uint1", - "uint1x1", - "uint1x2", - "uint1x3", - "uint1x4", - "uint2", - "uint2x1", - "uint2x2", - "uint2x3", - "uint2x4", - "uint3", - "uint3x1", - "uint3x2", - "uint3x3", - "uint3x4", - "uint4", - "uint4x1", - "uint4x2", - "uint4x3", - "uint4x4", - "uniform", - "union", - "unorm", - "unroll", - "unsigned", - "using", - "vector", - "vertexfragment", - "vertexshader", - "virtual", - "void", - "volatile", - "while")); - -} // namespace -} // namespace hlsl -} // namespace writer -} // namespace tint diff --git a/src/writer/msl/generator_impl.h b/src/writer/msl/generator_impl.h index b04e2a2372..68aa2bde7a 100644 --- a/src/writer/msl/generator_impl.h +++ b/src/writer/msl/generator_impl.h @@ -264,9 +264,6 @@ class GeneratorImpl : public TextGenerator { /// @returns the string name of the builtin or blank on error std::string builtin_to_attribute(ast::Builtin builtin) const; - /// @returns the namer for testing purposes - Namer* namer_for_testing() { return namer_.get(); } - private: enum class VarType { kIn, kOut };