From f74b90b3dd80d05729fd0da8640489c7d4b8601e Mon Sep 17 00:00:00 2001 From: dan sinclair Date: Mon, 11 Jan 2021 16:24:32 +0000 Subject: [PATCH] Use a test namer in the MSL generator. This CL updates the MSL generator to use a test namer, the various places where the incorrect name was emitted have been fixed. Change-Id: I20c990bdddc4f0580b09269920abe8376fa3ca07 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/36900 Reviewed-by: Ryan Harrison Reviewed-by: Ben Clayton --- BUILD.gn | 2 + src/CMakeLists.txt | 2 + src/ast/identifier_expression.h | 8 +- src/namer.cc | 4 + src/namer.h | 3 + src/type_determiner.cc | 2 +- src/writer/msl/generator.cc | 6 +- src/writer/msl/generator.h | 2 + src/writer/msl/generator_impl.cc | 109 +++++----- src/writer/msl/generator_impl.h | 16 +- .../msl/generator_impl_alias_type_test.cc | 10 +- .../msl/generator_impl_array_accessor_test.cc | 4 +- src/writer/msl/generator_impl_assign_test.cc | 2 +- src/writer/msl/generator_impl_binary_test.cc | 37 ++-- src/writer/msl/generator_impl_bitcast_test.cc | 2 +- src/writer/msl/generator_impl_call_test.cc | 6 +- src/writer/msl/generator_impl_cast_test.cc | 4 +- ...tor_impl_function_entry_point_data_test.cc | 28 +-- .../msl/generator_impl_function_test.cc | 204 ++++++++---------- .../msl/generator_impl_identifier_test.cc | 8 +- src/writer/msl/generator_impl_if_test.cc | 12 +- src/writer/msl/generator_impl_import_test.cc | 2 +- .../msl/generator_impl_intrinsic_test.cc | 8 +- .../generator_impl_intrinsic_texture_test.cc | 197 ++++++++--------- src/writer/msl/generator_impl_loop_test.cc | 12 +- .../generator_impl_member_accessor_test.cc | 24 ++- .../generator_impl_module_constant_test.cc | 5 +- src/writer/msl/generator_impl_return_test.cc | 2 +- src/writer/msl/generator_impl_switch_test.cc | 2 +- src/writer/msl/generator_impl_test.cc | 2 +- src/writer/msl/generator_impl_type_test.cc | 34 +-- .../msl/generator_impl_unary_op_test.cc | 2 +- ...rator_impl_variable_decl_statement_test.cc | 18 +- src/writer/msl/test_helper.h | 5 +- src/writer/test_namer.cc | 29 +++ src/writer/test_namer.h | 43 ++++ 36 files changed, 479 insertions(+), 377 deletions(-) create mode 100644 src/writer/test_namer.cc create mode 100644 src/writer/test_namer.h diff --git a/BUILD.gn b/BUILD.gn index f940575bda..c657175dc2 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -834,6 +834,8 @@ source_set("tint_unittests_core_src") { "src/validator/validator_function_test.cc", "src/validator/validator_test.cc", "src/writer/float_to_string_test.cc", + "src/writer/test_namer.cc", + "src/writer/test_namer.h", ] configs += [ diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7925a66c6a..44d2eaf6b7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -467,6 +467,8 @@ if(${TINT_BUILD_TESTS}) validator/validator_test.cc validator/validator_type_test.cc writer/float_to_string_test.cc + writer/test_namer.cc + writer/test_namer.h ) if(${TINT_BUILD_SPV_READER}) diff --git a/src/ast/identifier_expression.h b/src/ast/identifier_expression.h index b6b9b621f6..0f85346a67 100644 --- a/src/ast/identifier_expression.h +++ b/src/ast/identifier_expression.h @@ -58,6 +58,12 @@ class IdentifierExpression : public Castable { /// @returns true if this identifier is for an intrinsic bool IsIntrinsic() const { return intrinsic_ != Intrinsic::kNone; } + /// Sets the identifier as a swizzle + void SetIsSwizzle() { is_swizzle_ = true; } + + /// @returns true if this is a swizzle identifier + bool IsSwizzle() const { return is_swizzle_; } + /// Clones this node and all transitive child nodes using the `CloneContext` /// `ctx`. /// @note Semantic information such as resolved expression type and intrinsic @@ -78,9 +84,9 @@ class IdentifierExpression : public Castable { IdentifierExpression(const IdentifierExpression&) = delete; Symbol const sym_; - Intrinsic intrinsic_ = Intrinsic::kNone; // Semantic info std::unique_ptr intrinsic_sig_; // Semantic info + bool is_swizzle_ = false; // Semantic info }; } // namespace ast diff --git a/src/namer.cc b/src/namer.cc index f5f56004ca..d5f304d9b1 100644 --- a/src/namer.cc +++ b/src/namer.cc @@ -26,6 +26,10 @@ Namer::Namer(ast::Module* mod) : module_(mod) {} Namer::~Namer() = default; +void Namer::Reset() { + used_.clear(); +} + bool Namer::IsUsed(const std::string& name) { auto it = used_.find(name); return it != used_.end(); diff --git a/src/namer.h b/src/namer.h index 8d05eb2f34..7745cf07e4 100644 --- a/src/namer.h +++ b/src/namer.h @@ -42,6 +42,9 @@ class Namer { /// @returns the unique name string std::string GenerateName(const std::string& prefix); + /// Resets the namer, removing all known symbols. + void Reset(); + protected: /// Checks if `name` has been used /// @param name the name to check diff --git a/src/type_determiner.cc b/src/type_determiner.cc index 8459b8a978..0feed92468 100644 --- a/src/type_determiner.cc +++ b/src/type_determiner.cc @@ -1079,7 +1079,7 @@ bool TypeDeterminer::DetermineMemberAccessor( ret = mod_->create(ret, ptr->storage_class()); } } else if (auto* vec = data_type->As()) { - // TODO(dsinclair): Swizzle, record into the identifier experesion + expr->member()->SetIsSwizzle(); auto size = mod_->SymbolToName(expr->member()->symbol()).size(); if (size == 1) { diff --git a/src/writer/msl/generator.cc b/src/writer/msl/generator.cc index 46fa0733f0..fc7905b4aa 100644 --- a/src/writer/msl/generator.cc +++ b/src/writer/msl/generator.cc @@ -22,13 +22,15 @@ namespace msl { Generator::Generator(ast::Module module) : Text(std::move(module)), - impl_(std::make_unique(&module_)) {} + namer_(std::make_unique(&module_)), + impl_(std::make_unique(&module_, namer_.get())) {} Generator::~Generator() = default; void Generator::Reset() { set_error(""); - impl_ = std::make_unique(&module_); + namer_->Reset(); + impl_ = std::make_unique(&module_, namer_.get()); } bool Generator::Generate() { diff --git a/src/writer/msl/generator.h b/src/writer/msl/generator.h index d0a9de2aee..2e21cf677f 100644 --- a/src/writer/msl/generator.h +++ b/src/writer/msl/generator.h @@ -18,6 +18,7 @@ #include #include +#include "src/namer.h" #include "src/writer/msl/generator_impl.h" #include "src/writer/text.h" @@ -54,6 +55,7 @@ class Generator : public Text { std::string error() const; private: + std::unique_ptr namer_; std::unique_ptr impl_; }; diff --git a/src/writer/msl/generator_impl.cc b/src/writer/msl/generator_impl.cc index 7d920ac02f..6d91cfa5d1 100644 --- a/src/writer/msl/generator_impl.cc +++ b/src/writer/msl/generator_impl.cc @@ -96,10 +96,8 @@ uint32_t adjust_for_alignment(uint32_t count, uint32_t alignment) { } // namespace -GeneratorImpl::GeneratorImpl(ast::Module* module) - : TextGenerator(), - module_(module), - namer_(std::make_unique(module)) {} +GeneratorImpl::GeneratorImpl(ast::Module* module, Namer* namer) + : TextGenerator(), module_(module), namer_(namer) {} GeneratorImpl::~GeneratorImpl() = default; @@ -398,25 +396,25 @@ bool GeneratorImpl::EmitBreak(ast::BreakStatement*) { return true; } -std::string GeneratorImpl::current_ep_var_name(VarType type) { - std::string name = ""; +Symbol GeneratorImpl::current_ep_var_symbol(VarType type) { + Symbol sym; switch (type) { case VarType::kIn: { auto in_it = ep_sym_to_in_data_.find(current_ep_sym_.value()); if (in_it != ep_sym_to_in_data_.end()) { - name = in_it->second.var_name; + sym = in_it->second.var_symbol; } break; } case VarType::kOut: { auto out_it = ep_sym_to_out_data_.find(current_ep_sym_.value()); if (out_it != ep_sym_to_out_data_.end()) { - name = out_it->second.var_name; + sym = out_it->second.var_symbol; } break; } } - return name; + return sym; } std::string GeneratorImpl::generate_intrinsic_name(ast::Intrinsic intrinsic) { @@ -563,12 +561,11 @@ bool GeneratorImpl::EmitCall(ast::CallExpression* expr) { return true; } - auto name = namer_->NameFor(ident->symbol()); - auto caller_sym = ident->symbol(); - auto it = ep_func_name_remapped_.find(current_ep_sym_.to_str() + "_" + - caller_sym.to_str()); + auto name_sym = ident->symbol(); + auto it = ep_func_name_remapped_.find(module_->SymbolToName(current_ep_sym_) + + "_" + module_->SymbolToName(name_sym)); if (it != ep_func_name_remapped_.end()) { - name = it->second; + name_sym = it->second; } auto* func = module_->FindFunctionBySymbol(ident->symbol()); @@ -578,24 +575,24 @@ bool GeneratorImpl::EmitCall(ast::CallExpression* expr) { return false; } - out_ << name << "("; + out_ << namer_->NameFor(name_sym) << "("; bool first = true; if (has_referenced_in_var_needing_struct(func)) { - auto var_name = current_ep_var_name(VarType::kIn); - if (!var_name.empty()) { - out_ << var_name; + auto var_sym = current_ep_var_symbol(VarType::kIn); + if (var_sym.IsValid()) { + out_ << namer_->NameFor(var_sym); first = false; } } if (has_referenced_out_var_needing_struct(func)) { - auto var_name = current_ep_var_name(VarType::kOut); - if (!var_name.empty()) { + auto var_sym = current_ep_var_symbol(VarType::kOut); + if (var_sym.IsValid()) { if (!first) { out_ << ", "; } first = false; - out_ << var_name; + out_ << namer_->NameFor(var_sym); } } @@ -1018,13 +1015,14 @@ bool GeneratorImpl::EmitEntryPointData(ast::Function* func) { } if (!in_locations.empty()) { - auto in_struct_name = namer_->GenerateName(namer_->NameFor(func->symbol()) + - "_" + kInStructNameSuffix); + auto in_struct_sym = module_->RegisterSymbol(namer_->GenerateName( + module_->SymbolToName(func->symbol()) + "_" + kInStructNameSuffix)); auto in_var_name = namer_->GenerateName(kTintStructInVarPrefix); - ep_sym_to_in_data_[func->symbol().value()] = {in_struct_name, in_var_name}; + ep_sym_to_in_data_[func->symbol().value()] = { + in_struct_sym, module_->RegisterSymbol(in_var_name)}; make_indent(); - out_ << "struct " << in_struct_name << " {" << std::endl; + out_ << "struct " << namer_->NameFor(in_struct_sym) << " {" << std::endl; increment_indent(); @@ -1055,14 +1053,14 @@ bool GeneratorImpl::EmitEntryPointData(ast::Function* func) { } if (!out_variables.empty()) { - auto out_struct_name = namer_->GenerateName( - namer_->NameFor(func->symbol()) + "_" + kOutStructNameSuffix); + auto out_struct_sym = module_->RegisterSymbol(namer_->GenerateName( + module_->SymbolToName(func->symbol()) + "_" + kOutStructNameSuffix)); auto out_var_name = namer_->GenerateName(kTintStructOutVarPrefix); - ep_sym_to_out_data_[func->symbol().value()] = {out_struct_name, - out_var_name}; + ep_sym_to_out_data_[func->symbol().value()] = { + out_struct_sym, module_->RegisterSymbol(out_var_name)}; make_indent(); - out_ << "struct " << out_struct_name << " {" << std::endl; + out_ << "struct " << namer_->NameFor(out_struct_sym) << " {" << std::endl; increment_indent(); for (auto& data : out_variables) { @@ -1221,22 +1219,20 @@ bool GeneratorImpl::EmitFunction(ast::Function* func) { bool GeneratorImpl::EmitFunctionInternal(ast::Function* func, bool emit_duplicate_functions, Symbol ep_sym) { - auto name = func->symbol().to_str(); if (!EmitType(func->return_type(), Symbol())) { return false; } out_ << " "; + auto func_name_sym = func->symbol(); if (emit_duplicate_functions) { - auto func_name = name; - auto ep_name = ep_sym.to_str(); - name = namer_->GenerateName(namer_->NameFor(func->symbol()) + "_" + - namer_->NameFor(ep_sym)); - ep_func_name_remapped_[ep_name + "_" + func_name] = name; - } else { - name = namer_->NameFor(func->symbol()); + auto func_name = module_->SymbolToName(func_name_sym); + auto ep_name = module_->SymbolToName(ep_sym); + func_name_sym = module_->RegisterSymbol( + namer_->GenerateName(func_name + "_" + ep_name)); + ep_func_name_remapped_[ep_name + "_" + func_name] = func_name_sym; } - out_ << name << "("; + out_ << namer_->NameFor(func_name_sym) << "("; bool first = true; @@ -1247,8 +1243,8 @@ bool GeneratorImpl::EmitFunctionInternal(ast::Function* func, if (emit_duplicate_functions) { auto in_it = ep_sym_to_in_data_.find(ep_sym.value()); if (in_it != ep_sym_to_in_data_.end()) { - out_ << "thread " << in_it->second.struct_name << "& " - << in_it->second.var_name; + out_ << "thread " << namer_->NameFor(in_it->second.struct_symbol) << "& " + << namer_->NameFor(in_it->second.var_symbol); first = false; } @@ -1257,8 +1253,8 @@ bool GeneratorImpl::EmitFunctionInternal(ast::Function* func, if (!first) { out_ << ", "; } - out_ << "thread " << out_it->second.struct_name << "& " - << out_it->second.var_name; + out_ << "thread " << namer_->NameFor(out_it->second.struct_symbol) << "& " + << namer_->NameFor(out_it->second.var_symbol); first = false; } } @@ -1385,7 +1381,7 @@ bool GeneratorImpl::EmitEntryPointFunction(ast::Function* func) { auto out_data = ep_sym_to_out_data_.find(current_ep_sym_.value()); bool has_out_data = out_data != ep_sym_to_out_data_.end(); if (has_out_data) { - out_ << out_data->second.struct_name; + out_ << namer_->NameFor(out_data->second.struct_symbol); } else { out_ << "void"; } @@ -1394,8 +1390,8 @@ bool GeneratorImpl::EmitEntryPointFunction(ast::Function* func) { bool first = true; auto in_data = ep_sym_to_in_data_.find(current_ep_sym_.value()); if (in_data != ep_sym_to_in_data_.end()) { - out_ << in_data->second.struct_name << " " << in_data->second.var_name - << " [[stage_in]]"; + out_ << namer_->NameFor(in_data->second.struct_symbol) << " " + << namer_->NameFor(in_data->second.var_symbol) << " [[stage_in]]"; first = false; } @@ -1488,8 +1484,9 @@ bool GeneratorImpl::EmitEntryPointFunction(ast::Function* func) { if (has_out_data) { make_indent(); - out_ << out_data->second.struct_name << " " << out_data->second.var_name - << " = {};" << std::endl; + out_ << namer_->NameFor(out_data->second.struct_symbol) << " " + << namer_->NameFor(out_data->second.var_symbol) << " = {};" + << std::endl; } generating_entry_point_ = true; @@ -1527,15 +1524,21 @@ bool GeneratorImpl::EmitIdentifier(ast::IdentifierExpression* expr) { auto var_type = var->storage_class() == ast::StorageClass::kInput ? VarType::kIn : VarType::kOut; - auto name = current_ep_var_name(var_type); - if (name.empty()) { + auto sym = current_ep_var_symbol(var_type); + if (!sym.IsValid()) { error_ = "unable to find entry point data for variable"; return false; } - out_ << name << "."; + out_ << namer_->NameFor(sym) << "."; } } - out_ << namer_->NameFor(ident->symbol()); + + // Swizzles get written out directly + if (ident->IsSwizzle()) { + out_ << module_->SymbolToName(ident->symbol()); + } else { + out_ << namer_->NameFor(ident->symbol()); + } return true; } @@ -1690,7 +1693,7 @@ bool GeneratorImpl::EmitReturn(ast::ReturnStatement* stmt) { if (generating_entry_point_) { auto out_data = ep_sym_to_out_data_.find(current_ep_sym_.value()); if (out_data != ep_sym_to_out_data_.end()) { - out_ << " " << out_data->second.var_name; + out_ << " " << namer_->NameFor(out_data->second.var_symbol); } } else if (stmt->has_value()) { out_ << " "; diff --git a/src/writer/msl/generator_impl.h b/src/writer/msl/generator_impl.h index 68aa2bde7a..ece2afe62c 100644 --- a/src/writer/msl/generator_impl.h +++ b/src/writer/msl/generator_impl.h @@ -15,7 +15,6 @@ #ifndef SRC_WRITER_MSL_GENERATOR_IMPL_H_ #define SRC_WRITER_MSL_GENERATOR_IMPL_H_ -#include #include #include #include @@ -56,7 +55,8 @@ class GeneratorImpl : public TextGenerator { public: /// Constructor /// @param module the module to generate - explicit GeneratorImpl(ast::Module* module); + /// @param namer the namer to use for generation + GeneratorImpl(ast::Module* module, Namer* namer); ~GeneratorImpl(); /// @returns true on successful generation; false otherwise @@ -268,18 +268,18 @@ class GeneratorImpl : public TextGenerator { enum class VarType { kIn, kOut }; struct EntryPointData { - std::string struct_name; - std::string var_name; + Symbol struct_symbol; + Symbol var_symbol; }; - std::string current_ep_var_name(VarType type); + Symbol current_ep_var_symbol(VarType type); ScopeStack global_variables_; Symbol current_ep_sym_; bool generating_entry_point_ = false; - const ast::Module* module_ = nullptr; + ast::Module* module_ = nullptr; uint32_t loop_emission_counter_ = 0; - std::unique_ptr namer_; + Namer* namer_; std::unordered_map ep_sym_to_in_data_; std::unordered_map ep_sym_to_out_data_; @@ -287,7 +287,7 @@ class GeneratorImpl : public TextGenerator { // This maps an input of "_" to a remapped // function name. If there is no entry for a given key then function did // not need to be remapped for the entry point and can be emitted directly. - std::unordered_map ep_func_name_remapped_; + std::unordered_map ep_func_name_remapped_; }; } // namespace msl diff --git a/src/writer/msl/generator_impl_alias_type_test.cc b/src/writer/msl/generator_impl_alias_type_test.cc index 57fdf407ef..29cd5f82d2 100644 --- a/src/writer/msl/generator_impl_alias_type_test.cc +++ b/src/writer/msl/generator_impl_alias_type_test.cc @@ -31,7 +31,7 @@ TEST_F(MslGeneratorImplTest, EmitConstructedType_F32) { auto* alias = ty.alias("a", ty.f32); ASSERT_TRUE(gen.EmitConstructedType(alias)) << gen.error(); - EXPECT_EQ(gen.result(), R"(typedef float a; + EXPECT_EQ(gen.result(), R"(typedef float test_a; )"); } @@ -43,9 +43,9 @@ TEST_F(MslGeneratorImplTest, EmitConstructedType_Struct) { auto* s = ty.struct_("a", str); ASSERT_TRUE(gen.EmitConstructedType(s)) << gen.error(); - EXPECT_EQ(gen.result(), R"(struct a { - float a; - int b; + EXPECT_EQ(gen.result(), R"(struct test_a { + float test_a; + int test_b; }; )"); } @@ -60,7 +60,7 @@ TEST_F(MslGeneratorImplTest, EmitConstructedType_AliasStructIdent) { auto* alias = ty.alias("a", s); ASSERT_TRUE(gen.EmitConstructedType(alias)) << gen.error(); - EXPECT_EQ(gen.result(), R"(typedef b a; + EXPECT_EQ(gen.result(), R"(typedef test_b test_a; )"); } diff --git a/src/writer/msl/generator_impl_array_accessor_test.cc b/src/writer/msl/generator_impl_array_accessor_test.cc index 5b5c54d626..842e8c96f6 100644 --- a/src/writer/msl/generator_impl_array_accessor_test.cc +++ b/src/writer/msl/generator_impl_array_accessor_test.cc @@ -35,7 +35,7 @@ TEST_F(MslGeneratorImplTest, EmitExpression_ArrayAccessor) { auto* expr = IndexAccessor(Expr("ary"), 5); ASSERT_TRUE(gen.EmitExpression(expr)) << gen.error(); - EXPECT_EQ(gen.result(), "ary[5]"); + EXPECT_EQ(gen.result(), "test_ary[5]"); } TEST_F(MslGeneratorImplTest, EmitArrayAccessor) { @@ -43,7 +43,7 @@ TEST_F(MslGeneratorImplTest, EmitArrayAccessor) { ASSERT_TRUE(gen.EmitArrayAccessor(expr->As())) << gen.error(); - EXPECT_EQ(gen.result(), "ary[idx]"); + EXPECT_EQ(gen.result(), "test_ary[test_idx]"); } } // namespace diff --git a/src/writer/msl/generator_impl_assign_test.cc b/src/writer/msl/generator_impl_assign_test.cc index 6f7c70f46f..998eb5f7c8 100644 --- a/src/writer/msl/generator_impl_assign_test.cc +++ b/src/writer/msl/generator_impl_assign_test.cc @@ -34,7 +34,7 @@ TEST_F(MslGeneratorImplTest, Emit_Assign) { gen.increment_indent(); ASSERT_TRUE(gen.EmitStatement(assign)) << gen.error(); - EXPECT_EQ(gen.result(), " lhs = rhs;\n"); + EXPECT_EQ(gen.result(), " test_lhs = test_rhs;\n"); } } // namespace diff --git a/src/writer/msl/generator_impl_binary_test.cc b/src/writer/msl/generator_impl_binary_test.cc index b1b6ed07de..ec15d385fa 100644 --- a/src/writer/msl/generator_impl_binary_test.cc +++ b/src/writer/msl/generator_impl_binary_test.cc @@ -47,24 +47,25 @@ INSTANTIATE_TEST_SUITE_P( MslGeneratorImplTest, MslBinaryTest, testing::Values( - BinaryData{"(left & right)", ast::BinaryOp::kAnd}, - BinaryData{"(left | right)", ast::BinaryOp::kOr}, - BinaryData{"(left ^ right)", ast::BinaryOp::kXor}, - BinaryData{"(left && right)", ast::BinaryOp::kLogicalAnd}, - BinaryData{"(left || right)", ast::BinaryOp::kLogicalOr}, - BinaryData{"(left == right)", ast::BinaryOp::kEqual}, - BinaryData{"(left != right)", ast::BinaryOp::kNotEqual}, - BinaryData{"(left < right)", ast::BinaryOp::kLessThan}, - BinaryData{"(left > right)", ast::BinaryOp::kGreaterThan}, - BinaryData{"(left <= right)", ast::BinaryOp::kLessThanEqual}, - BinaryData{"(left >= right)", ast::BinaryOp::kGreaterThanEqual}, - BinaryData{"(left << right)", ast::BinaryOp::kShiftLeft}, - BinaryData{"(left >> right)", ast::BinaryOp::kShiftRight}, - BinaryData{"(left + right)", ast::BinaryOp::kAdd}, - BinaryData{"(left - right)", ast::BinaryOp::kSubtract}, - BinaryData{"(left * right)", ast::BinaryOp::kMultiply}, - BinaryData{"(left / right)", ast::BinaryOp::kDivide}, - BinaryData{"(left % right)", ast::BinaryOp::kModulo})); + BinaryData{"(test_left & test_right)", ast::BinaryOp::kAnd}, + BinaryData{"(test_left | test_right)", ast::BinaryOp::kOr}, + BinaryData{"(test_left ^ test_right)", ast::BinaryOp::kXor}, + BinaryData{"(test_left && test_right)", ast::BinaryOp::kLogicalAnd}, + BinaryData{"(test_left || test_right)", ast::BinaryOp::kLogicalOr}, + BinaryData{"(test_left == test_right)", ast::BinaryOp::kEqual}, + BinaryData{"(test_left != test_right)", ast::BinaryOp::kNotEqual}, + BinaryData{"(test_left < test_right)", ast::BinaryOp::kLessThan}, + BinaryData{"(test_left > test_right)", ast::BinaryOp::kGreaterThan}, + BinaryData{"(test_left <= test_right)", ast::BinaryOp::kLessThanEqual}, + BinaryData{"(test_left >= test_right)", + ast::BinaryOp::kGreaterThanEqual}, + BinaryData{"(test_left << test_right)", ast::BinaryOp::kShiftLeft}, + BinaryData{"(test_left >> test_right)", ast::BinaryOp::kShiftRight}, + BinaryData{"(test_left + test_right)", ast::BinaryOp::kAdd}, + BinaryData{"(test_left - test_right)", ast::BinaryOp::kSubtract}, + BinaryData{"(test_left * test_right)", ast::BinaryOp::kMultiply}, + BinaryData{"(test_left / test_right)", ast::BinaryOp::kDivide}, + BinaryData{"(test_left % test_right)", ast::BinaryOp::kModulo})); } // namespace } // namespace msl diff --git a/src/writer/msl/generator_impl_bitcast_test.cc b/src/writer/msl/generator_impl_bitcast_test.cc index de56fd8967..3fa6d399f8 100644 --- a/src/writer/msl/generator_impl_bitcast_test.cc +++ b/src/writer/msl/generator_impl_bitcast_test.cc @@ -32,7 +32,7 @@ using MslGeneratorImplTest = TestHelper; TEST_F(MslGeneratorImplTest, EmitExpression_Bitcast) { auto* bitcast = create(ty.f32, Expr("id")); ASSERT_TRUE(gen.EmitExpression(bitcast)) << gen.error(); - EXPECT_EQ(gen.result(), "as_type(id)"); + EXPECT_EQ(gen.result(), "as_type(test_id)"); } } // namespace diff --git a/src/writer/msl/generator_impl_call_test.cc b/src/writer/msl/generator_impl_call_test.cc index 3b7c9edb3d..a841690920 100644 --- a/src/writer/msl/generator_impl_call_test.cc +++ b/src/writer/msl/generator_impl_call_test.cc @@ -38,7 +38,7 @@ TEST_F(MslGeneratorImplTest, EmitExpression_Call_WithoutParams) { mod->AddFunction(func); ASSERT_TRUE(gen.EmitExpression(call)) << gen.error(); - EXPECT_EQ(gen.result(), "my_func()"); + EXPECT_EQ(gen.result(), "test_my_func()"); } TEST_F(MslGeneratorImplTest, EmitExpression_Call_WithParams) { @@ -48,7 +48,7 @@ TEST_F(MslGeneratorImplTest, EmitExpression_Call_WithParams) { mod->AddFunction(func); ASSERT_TRUE(gen.EmitExpression(call)) << gen.error(); - EXPECT_EQ(gen.result(), "my_func(param1, param2)"); + EXPECT_EQ(gen.result(), "test_my_func(test_param1, test_param2)"); } TEST_F(MslGeneratorImplTest, EmitStatement_Call) { @@ -61,7 +61,7 @@ TEST_F(MslGeneratorImplTest, EmitStatement_Call) { gen.increment_indent(); ASSERT_TRUE(gen.EmitStatement(expr)) << gen.error(); - EXPECT_EQ(gen.result(), " my_func(param1, param2);\n"); + EXPECT_EQ(gen.result(), " test_my_func(test_param1, test_param2);\n"); } } // namespace diff --git a/src/writer/msl/generator_impl_cast_test.cc b/src/writer/msl/generator_impl_cast_test.cc index 3713b86763..908bcfe514 100644 --- a/src/writer/msl/generator_impl_cast_test.cc +++ b/src/writer/msl/generator_impl_cast_test.cc @@ -34,14 +34,14 @@ TEST_F(MslGeneratorImplTest, EmitExpression_Cast_Scalar) { auto* cast = Construct("id"); ASSERT_TRUE(gen.EmitExpression(cast)) << gen.error(); - EXPECT_EQ(gen.result(), "float(id)"); + EXPECT_EQ(gen.result(), "float(test_id)"); } TEST_F(MslGeneratorImplTest, EmitExpression_Cast_Vector) { auto* cast = vec3("id"); ASSERT_TRUE(gen.EmitExpression(cast)) << gen.error(); - EXPECT_EQ(gen.result(), "float3(id)"); + EXPECT_EQ(gen.result(), "float3(test_id)"); } } // namespace diff --git a/src/writer/msl/generator_impl_function_entry_point_data_test.cc b/src/writer/msl/generator_impl_function_entry_point_data_test.cc index 461035b0bd..4ff8ce6235 100644 --- a/src/writer/msl/generator_impl_function_entry_point_data_test.cc +++ b/src/writer/msl/generator_impl_function_entry_point_data_test.cc @@ -76,9 +76,9 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Vertex_Input) { ASSERT_TRUE(td.Determine()) << td.error(); ASSERT_TRUE(gen.EmitEntryPointData(func)) << gen.error(); - EXPECT_EQ(gen.result(), R"(struct vtx_main_in { - float foo [[attribute(0)]]; - int bar [[attribute(1)]]; + EXPECT_EQ(gen.result(), R"(struct test_vtx_main_in { + float test_foo [[attribute(0)]]; + int test_bar [[attribute(1)]]; }; )"); @@ -122,9 +122,9 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Vertex_Output) { ASSERT_TRUE(td.Determine()) << td.error(); ASSERT_TRUE(gen.EmitEntryPointData(func)) << gen.error(); - EXPECT_EQ(gen.result(), R"(struct vtx_main_out { - float foo [[user(locn0)]]; - int bar [[user(locn1)]]; + EXPECT_EQ(gen.result(), R"(struct test_vtx_main_out { + float test_foo [[user(locn0)]]; + int test_bar [[user(locn1)]]; }; )"); @@ -168,9 +168,9 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Fragment_Input) { ASSERT_TRUE(td.Determine()) << td.error(); ASSERT_TRUE(gen.EmitEntryPointData(func)) << gen.error(); - EXPECT_EQ(gen.result(), R"(struct main_in { - float foo [[user(locn0)]]; - int bar [[user(locn1)]]; + EXPECT_EQ(gen.result(), R"(struct test_main_in { + float test_foo [[user(locn0)]]; + int test_bar [[user(locn1)]]; }; )"); @@ -214,9 +214,9 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Fragment_Output) { ASSERT_TRUE(td.Determine()) << td.error(); ASSERT_TRUE(gen.EmitEntryPointData(func)) << gen.error(); - EXPECT_EQ(gen.result(), R"(struct main_out { - float foo [[color(0)]]; - int bar [[color(1)]]; + EXPECT_EQ(gen.result(), R"(struct test_main_out { + float test_foo [[color(0)]]; + int test_bar [[color(1)]]; }; )"); @@ -338,8 +338,8 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Builtins) { ASSERT_TRUE(td.Determine()) << td.error(); ASSERT_TRUE(gen.EmitEntryPointData(func)) << gen.error(); - EXPECT_EQ(gen.result(), R"(struct main_out { - float depth [[depth(any)]]; + EXPECT_EQ(gen.result(), R"(struct test_main_out { + float test_depth [[depth(any)]]; }; )"); diff --git a/src/writer/msl/generator_impl_function_test.cc b/src/writer/msl/generator_impl_function_test.cc index aa6abd3a87..b325728337 100644 --- a/src/writer/msl/generator_impl_function_test.cc +++ b/src/writer/msl/generator_impl_function_test.cc @@ -68,27 +68,7 @@ TEST_F(MslGeneratorImplTest, Emit_Function) { ASSERT_TRUE(gen.Generate()) << gen.error(); EXPECT_EQ(gen.result(), R"(#include - void my_func() { - return; - } - -)"); -} - -TEST_F(MslGeneratorImplTest, Emit_Function_Name_Collision) { - auto* func = Func("main", ast::VariableList{}, ty.void_, - ast::StatementList{ - create(), - }, - ast::FunctionDecorationList{}); - - mod->AddFunction(func); - gen.increment_indent(); - - ASSERT_TRUE(gen.Generate()) << gen.error(); - EXPECT_EQ(gen.result(), R"(#include - - void main() { + void test_my_func() { return; } @@ -112,7 +92,7 @@ TEST_F(MslGeneratorImplTest, Emit_Function_WithParams) { ASSERT_TRUE(gen.Generate()) << gen.error(); EXPECT_EQ(gen.result(), R"(#include - void my_func(float a, int b) { + void test_my_func(float test_a, int test_b) { return; } @@ -149,18 +129,18 @@ TEST_F(MslGeneratorImplTest, Emit_FunctionDecoration_EntryPoint_WithInOutVars) { ASSERT_TRUE(gen.Generate()) << gen.error(); EXPECT_EQ(gen.result(), R"(#include -struct frag_main_in { - float foo [[user(locn0)]]; +struct test_frag_main_in { + float test_foo [[user(locn0)]]; }; -struct frag_main_out { - float bar [[color(1)]]; +struct test_frag_main_out { + float test_bar [[color(1)]]; }; -fragment frag_main_out frag_main(frag_main_in tint_in [[stage_in]]) { - frag_main_out tint_out = {}; - tint_out.bar = tint_in.foo; - return tint_out; +fragment test_frag_main_out test_frag_main(test_frag_main_in test_tint_in [[stage_in]]) { + test_frag_main_out test_tint_out = {}; + test_tint_out.test_bar = test_tint_in.test_foo; + return test_tint_out; } )"); @@ -202,14 +182,14 @@ TEST_F(MslGeneratorImplTest, ASSERT_TRUE(gen.Generate()) << gen.error(); EXPECT_EQ(gen.result(), R"(#include -struct frag_main_out { - float depth [[depth(any)]]; +struct test_frag_main_out { + float test_depth [[depth(any)]]; }; -fragment frag_main_out frag_main(float4 coord [[position]]) { - frag_main_out tint_out = {}; - tint_out.depth = coord.x; - return tint_out; +fragment test_frag_main_out test_frag_main(float4 test_coord [[position]]) { + test_frag_main_out test_tint_out = {}; + test_tint_out.test_depth = test_coord.x; + return test_tint_out; } )"); @@ -245,8 +225,8 @@ TEST_F(MslGeneratorImplTest, Emit_FunctionDecoration_EntryPoint_With_Uniform) { ASSERT_TRUE(gen.Generate()) << gen.error(); EXPECT_EQ(gen.result(), R"(#include -fragment void frag_main(constant float4& coord [[buffer(0)]]) { - float v = coord.x; +fragment void test_frag_main(constant float4& test_coord [[buffer(0)]]) { + float test_v = test_coord.x; return; } @@ -293,13 +273,13 @@ TEST_F(MslGeneratorImplTest, ASSERT_TRUE(gen.Generate()) << gen.error(); EXPECT_EQ(gen.result(), R"(#include -struct Data { - int a; - float b; +struct test_Data { + int test_a; + float test_b; }; -fragment void frag_main(device Data& coord [[buffer(0)]]) { - float v = coord.b; +fragment void test_frag_main(device test_Data& test_coord [[buffer(0)]]) { + float test_v = test_coord.test_b; return; } @@ -310,7 +290,7 @@ TEST_F(MslGeneratorImplTest, Emit_FunctionDecoration_EntryPoint_With_RO_StorageBuffer) { auto* str = create( ast::StructMemberList{Member("a", ty.i32, {MemberOffset(0)}), - Member("b", ty.f32, {MemberOffset(4)})}, + Member("x", ty.f32, {MemberOffset(4)})}, ast::StructDecorationList{}); auto* s = ty.struct_("Data", str); @@ -326,7 +306,7 @@ TEST_F(MslGeneratorImplTest, mod->AddGlobalVariable(coord_var); auto* var = Var("v", ast::StorageClass::kFunction, ty.f32, - MemberAccessor("coord", "b"), ast::VariableDecorationList{}); + MemberAccessor("coord", "x"), ast::VariableDecorationList{}); auto* func = Func("frag_main", ast::VariableList{}, ty.void_, @@ -345,13 +325,13 @@ TEST_F(MslGeneratorImplTest, ASSERT_TRUE(gen.Generate()) << gen.error(); EXPECT_EQ(gen.result(), R"(#include -struct Data { - int a; - float b; +struct test_Data { + int test_a; + float test_x; }; -fragment void frag_main(const device Data& coord [[buffer(0)]]) { - float v = coord.b; +fragment void test_frag_main(const device test_Data& test_coord [[buffer(0)]]) { + float test_v = test_coord.test_x; return; } @@ -410,25 +390,25 @@ TEST_F( ASSERT_TRUE(gen.Generate()) << gen.error(); EXPECT_EQ(gen.result(), R"(#include -struct ep_1_in { - float foo [[user(locn0)]]; +struct test_ep_1_in { + float test_foo [[user(locn0)]]; }; -struct ep_1_out { - float bar [[color(1)]]; - float val [[color(0)]]; +struct test_ep_1_out { + float test_bar [[color(1)]]; + float test_val [[color(0)]]; }; -float sub_func_ep_1(thread ep_1_in& tint_in, thread ep_1_out& tint_out, float param) { - tint_out.bar = tint_in.foo; - tint_out.val = param; - return tint_in.foo; +float test_sub_func_ep_1(thread test_ep_1_in& test_tint_in, thread test_ep_1_out& test_tint_out, float test_param) { + test_tint_out.test_bar = test_tint_in.test_foo; + test_tint_out.test_val = test_param; + return test_tint_in.test_foo; } -fragment ep_1_out ep_1(ep_1_in tint_in [[stage_in]]) { - ep_1_out tint_out = {}; - tint_out.bar = sub_func_ep_1(tint_in, tint_out, 1.0f); - return tint_out; +fragment test_ep_1_out test_ep_1(test_ep_1_in test_tint_in [[stage_in]]) { + test_ep_1_out test_tint_out = {}; + test_tint_out.test_bar = test_sub_func_ep_1(test_tint_in, test_tint_out, 1.0f); + return test_tint_out; } )"); @@ -473,18 +453,18 @@ TEST_F(MslGeneratorImplTest, ASSERT_TRUE(gen.Generate()) << gen.error(); EXPECT_EQ(gen.result(), R"(#include -struct ep_1_out { - float depth [[depth(any)]]; +struct test_ep_1_out { + float test_depth [[depth(any)]]; }; -float sub_func(float param) { - return param; +float test_sub_func(float test_param) { + return test_param; } -fragment ep_1_out ep_1() { - ep_1_out tint_out = {}; - tint_out.depth = sub_func(1.0f); - return tint_out; +fragment test_ep_1_out test_ep_1() { + test_ep_1_out test_tint_out = {}; + test_tint_out.test_depth = test_sub_func(1.0f); + return test_tint_out; } )"); @@ -538,19 +518,19 @@ TEST_F( ASSERT_TRUE(gen.Generate()) << gen.error(); EXPECT_EQ(gen.result(), R"(#include -struct ep_1_out { - float depth [[depth(any)]]; +struct test_ep_1_out { + float test_depth [[depth(any)]]; }; -float sub_func_ep_1(thread ep_1_out& tint_out, thread float4& coord, float param) { - tint_out.depth = coord.x; - return param; +float test_sub_func_ep_1(thread test_ep_1_out& test_tint_out, thread float4& test_coord, float test_param) { + test_tint_out.test_depth = test_coord.x; + return test_param; } -fragment ep_1_out ep_1(float4 coord [[position]]) { - ep_1_out tint_out = {}; - tint_out.depth = sub_func_ep_1(tint_out, coord, 1.0f); - return tint_out; +fragment test_ep_1_out test_ep_1(float4 test_coord [[position]]) { + test_ep_1_out test_tint_out = {}; + test_tint_out.test_depth = test_sub_func_ep_1(test_tint_out, test_coord, 1.0f); + return test_tint_out; } )"); @@ -599,12 +579,12 @@ TEST_F(MslGeneratorImplTest, ASSERT_TRUE(gen.Generate()) << gen.error(); EXPECT_EQ(gen.result(), R"(#include -float sub_func(constant float4& coord, float param) { - return coord.x; +float test_sub_func(constant float4& test_coord, float test_param) { + return test_coord.x; } -fragment void frag_main(constant float4& coord [[buffer(0)]]) { - float v = sub_func(coord, 1.0f); +fragment void test_frag_main(constant float4& test_coord [[buffer(0)]]) { + float test_v = test_sub_func(test_coord, 1.0f); return; } @@ -661,17 +641,17 @@ TEST_F(MslGeneratorImplTest, ASSERT_TRUE(gen.Generate()) << gen.error(); EXPECT_EQ(gen.result(), R"(#include -struct Data { - int a; - float b; +struct test_Data { + int test_a; + float test_b; }; -float sub_func(device Data& coord, float param) { - return coord.b; +float test_sub_func(device test_Data& test_coord, float test_param) { + return test_coord.test_b; } -fragment void frag_main(device Data& coord [[buffer(0)]]) { - float v = sub_func(coord, 1.0f); +fragment void test_frag_main(device test_Data& test_coord [[buffer(0)]]) { + float test_v = test_sub_func(test_coord, 1.0f); return; } @@ -731,17 +711,17 @@ TEST_F(MslGeneratorImplTest, ASSERT_TRUE(gen.Generate()) << gen.error(); EXPECT_EQ(gen.result(), R"(#include -struct Data { - int a; - float b; +struct test_Data { + int test_a; + float test_b; }; -float sub_func(const device Data& coord, float param) { - return coord.b; +float test_sub_func(const device test_Data& test_coord, float test_param) { + return test_coord.test_b; } -fragment void frag_main(const device Data& coord [[buffer(0)]]) { - float v = sub_func(coord, 1.0f); +fragment void test_frag_main(const device test_Data& test_coord [[buffer(0)]]) { + float test_v = test_sub_func(test_coord, 1.0f); return; } @@ -781,17 +761,17 @@ TEST_F(MslGeneratorImplTest, ASSERT_TRUE(gen.Generate()) << gen.error(); EXPECT_EQ(gen.result(), R"(#include -struct ep_1_out { - float bar [[color(1)]]; +struct test_ep_1_out { + float test_bar [[color(1)]]; }; -fragment ep_1_out ep_1() { - ep_1_out tint_out = {}; - tint_out.bar = 1.0f; +fragment test_ep_1_out test_ep_1() { + test_ep_1_out test_tint_out = {}; + test_tint_out.test_bar = 1.0f; if ((1 == 1)) { - return tint_out; + return test_tint_out; } - return tint_out; + return test_tint_out; } )"); @@ -813,7 +793,7 @@ TEST_F(MslGeneratorImplTest, Emit_Function_WithArrayParams) { ASSERT_TRUE(gen.Generate()) << gen.error(); EXPECT_EQ(gen.result(), R"(#include - void my_func(float a[5]) { + void test_my_func(float test_a[5]) { return; } @@ -892,17 +872,17 @@ TEST_F(MslGeneratorImplTest, ASSERT_TRUE(gen.Generate()) << gen.error(); EXPECT_EQ(gen.result(), R"(#include -struct Data { - float d; +struct test_Data { + float test_d; }; -kernel void a(device Data& data [[buffer(0)]]) { - float v = data.d; +kernel void test_a(device test_Data& test_data [[buffer(0)]]) { + float test_v = test_data.test_d; return; } -kernel void b(device Data& data [[buffer(0)]]) { - float v = data.d; +kernel void test_b(device test_Data& test_data [[buffer(0)]]) { + float test_v = test_data.test_d; return; } diff --git a/src/writer/msl/generator_impl_identifier_test.cc b/src/writer/msl/generator_impl_identifier_test.cc index 4a0bfa66c2..390b6ff1e3 100644 --- a/src/writer/msl/generator_impl_identifier_test.cc +++ b/src/writer/msl/generator_impl_identifier_test.cc @@ -28,13 +28,7 @@ using MslGeneratorImplTest = TestHelper; TEST_F(MslGeneratorImplTest, EmitIdentifierExpression) { auto* i = Expr("foo"); ASSERT_TRUE(gen.EmitExpression(i)) << gen.error(); - EXPECT_EQ(gen.result(), "foo"); -} - -TEST_F(MslGeneratorImplTest, EmitIdentifierExpression_Single_WithCollision) { - auto* i = Expr("virtual"); - ASSERT_TRUE(gen.EmitExpression(i)) << gen.error(); - EXPECT_EQ(gen.result(), "virtual"); + EXPECT_EQ(gen.result(), "test_foo"); } } // namespace diff --git a/src/writer/msl/generator_impl_if_test.cc b/src/writer/msl/generator_impl_if_test.cc index 7a42ac0877..d377c63a8e 100644 --- a/src/writer/msl/generator_impl_if_test.cc +++ b/src/writer/msl/generator_impl_if_test.cc @@ -38,7 +38,7 @@ TEST_F(MslGeneratorImplTest, Emit_If) { gen.increment_indent(); ASSERT_TRUE(gen.EmitStatement(i)) << gen.error(); - EXPECT_EQ(gen.result(), R"( if (cond) { + EXPECT_EQ(gen.result(), R"( if (test_cond) { return; } )"); @@ -63,9 +63,9 @@ TEST_F(MslGeneratorImplTest, Emit_IfWithElseIf) { gen.increment_indent(); ASSERT_TRUE(gen.EmitStatement(i)) << gen.error(); - EXPECT_EQ(gen.result(), R"( if (cond) { + EXPECT_EQ(gen.result(), R"( if (test_cond) { return; - } else if (else_cond) { + } else if (test_else_cond) { return; } )"); @@ -89,7 +89,7 @@ TEST_F(MslGeneratorImplTest, Emit_IfWithElse) { gen.increment_indent(); ASSERT_TRUE(gen.EmitStatement(i)) << gen.error(); - EXPECT_EQ(gen.result(), R"( if (cond) { + EXPECT_EQ(gen.result(), R"( if (test_cond) { return; } else { return; @@ -122,9 +122,9 @@ TEST_F(MslGeneratorImplTest, Emit_IfWithMultiple) { gen.increment_indent(); ASSERT_TRUE(gen.EmitStatement(i)) << gen.error(); - EXPECT_EQ(gen.result(), R"( if (cond) { + EXPECT_EQ(gen.result(), R"( if (test_cond) { return; - } else if (else_cond) { + } else if (test_else_cond) { return; } else { return; diff --git a/src/writer/msl/generator_impl_import_test.cc b/src/writer/msl/generator_impl_import_test.cc index b7d97d6d34..b9474bb6bf 100644 --- a/src/writer/msl/generator_impl_import_test.cc +++ b/src/writer/msl/generator_impl_import_test.cc @@ -187,7 +187,7 @@ TEST_F(MslGeneratorImplTest, MslImportData_Determinant) { ASSERT_TRUE(td.Determine()) << td.error(); ASSERT_TRUE(td.DetermineResultType(expr)) << td.error(); ASSERT_TRUE(gen.EmitCall(expr)) << gen.error(); - EXPECT_EQ(gen.result(), std::string("metal::determinant(var)")); + EXPECT_EQ(gen.result(), std::string("metal::determinant(test_var)")); } } // namespace diff --git a/src/writer/msl/generator_impl_intrinsic_test.cc b/src/writer/msl/generator_impl_intrinsic_test.cc index af661cbf69..25ff811362 100644 --- a/src/writer/msl/generator_impl_intrinsic_test.cc +++ b/src/writer/msl/generator_impl_intrinsic_test.cc @@ -69,7 +69,7 @@ TEST_F(MslGeneratorImplTest, 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); @@ -81,7 +81,9 @@ TEST_F(MslGeneratorImplTest, DISABLED_Intrinsic_OuterProduct) { gen.increment_indent(); ASSERT_TRUE(gen.EmitExpression(call)) << gen.error(); - EXPECT_EQ(gen.result(), " float3x2(a * b[0], a * b[1], a * b[2])"); + EXPECT_EQ( + gen.result(), + " float3x2(test_a * test_b[0], test_a * test_b[1], test_a * test_b[2])"); } TEST_F(MslGeneratorImplTest, Intrinsic_Bad_Name) { @@ -101,7 +103,7 @@ TEST_F(MslGeneratorImplTest, Intrinsic_Call) { gen.increment_indent(); ASSERT_TRUE(gen.EmitExpression(call)) << gen.error(); - EXPECT_EQ(gen.result(), " dot(param1, param2)"); + EXPECT_EQ(gen.result(), " dot(test_param1, test_param2)"); } } // namespace diff --git a/src/writer/msl/generator_impl_intrinsic_texture_test.cc b/src/writer/msl/generator_impl_intrinsic_texture_test.cc index 563e6971fc..9f04372e54 100644 --- a/src/writer/msl/generator_impl_intrinsic_texture_test.cc +++ b/src/writer/msl/generator_impl_intrinsic_texture_test.cc @@ -22,6 +22,7 @@ #include "src/ast/type/sampled_texture_type.h" #include "src/type_determiner.h" #include "src/writer/msl/generator_impl.h" +#include "src/writer/test_namer.h" namespace tint { namespace writer { @@ -33,181 +34,181 @@ std::string expected_texture_overload( using ValidTextureOverload = ast::intrinsic::test::ValidTextureOverload; switch (overload) { case ValidTextureOverload::kSample1dF32: - return R"(texture.sample(sampler, 1.0f))"; + return R"(test_texture.sample(test_sampler, 1.0f))"; case ValidTextureOverload::kSample1dArrayF32: - return R"(texture.sample(sampler, 1.0f, 2))"; + return R"(test_texture.sample(test_sampler, 1.0f, 2))"; case ValidTextureOverload::kSample2dF32: - return R"(texture.sample(sampler, float2(1.0f, 2.0f)))"; + return R"(test_texture.sample(test_sampler, float2(1.0f, 2.0f)))"; case ValidTextureOverload::kSample2dOffsetF32: - return R"(texture.sample(sampler, float2(1.0f, 2.0f), int2(3, 4)))"; + return R"(test_texture.sample(test_sampler, float2(1.0f, 2.0f), int2(3, 4)))"; case ValidTextureOverload::kSample2dArrayF32: - return R"(texture.sample(sampler, float2(1.0f, 2.0f), 3))"; + return R"(test_texture.sample(test_sampler, float2(1.0f, 2.0f), 3))"; case ValidTextureOverload::kSample2dArrayOffsetF32: - return R"(texture.sample(sampler, float2(1.0f, 2.0f), 3, int2(4, 5)))"; + return R"(test_texture.sample(test_sampler, float2(1.0f, 2.0f), 3, int2(4, 5)))"; case ValidTextureOverload::kSample3dF32: - return R"(texture.sample(sampler, float3(1.0f, 2.0f, 3.0f)))"; + return R"(test_texture.sample(test_sampler, float3(1.0f, 2.0f, 3.0f)))"; case ValidTextureOverload::kSample3dOffsetF32: - return R"(texture.sample(sampler, float3(1.0f, 2.0f, 3.0f), int3(4, 5, 6)))"; + return R"(test_texture.sample(test_sampler, float3(1.0f, 2.0f, 3.0f), int3(4, 5, 6)))"; case ValidTextureOverload::kSampleCubeF32: - return R"(texture.sample(sampler, float3(1.0f, 2.0f, 3.0f)))"; + return R"(test_texture.sample(test_sampler, float3(1.0f, 2.0f, 3.0f)))"; case ValidTextureOverload::kSampleCubeArrayF32: - return R"(texture.sample(sampler, float3(1.0f, 2.0f, 3.0f), 4))"; + return R"(test_texture.sample(test_sampler, float3(1.0f, 2.0f, 3.0f), 4))"; case ValidTextureOverload::kSampleDepth2dF32: - return R"(texture.sample(sampler, float2(1.0f, 2.0f)))"; + return R"(test_texture.sample(test_sampler, float2(1.0f, 2.0f)))"; case ValidTextureOverload::kSampleDepth2dOffsetF32: - return R"(texture.sample(sampler, float2(1.0f, 2.0f), int2(3, 4)))"; + return R"(test_texture.sample(test_sampler, float2(1.0f, 2.0f), int2(3, 4)))"; case ValidTextureOverload::kSampleDepth2dArrayF32: - return R"(texture.sample(sampler, float2(1.0f, 2.0f), 3))"; + return R"(test_texture.sample(test_sampler, float2(1.0f, 2.0f), 3))"; case ValidTextureOverload::kSampleDepth2dArrayOffsetF32: - return R"(texture.sample(sampler, float2(1.0f, 2.0f), 3, int2(4, 5)))"; + return R"(test_texture.sample(test_sampler, float2(1.0f, 2.0f), 3, int2(4, 5)))"; case ValidTextureOverload::kSampleDepthCubeF32: - return R"(texture.sample(sampler, float3(1.0f, 2.0f, 3.0f)))"; + return R"(test_texture.sample(test_sampler, float3(1.0f, 2.0f, 3.0f)))"; case ValidTextureOverload::kSampleDepthCubeArrayF32: - return R"(texture.sample(sampler, float3(1.0f, 2.0f, 3.0f), 4))"; + return R"(test_texture.sample(test_sampler, float3(1.0f, 2.0f, 3.0f), 4))"; case ValidTextureOverload::kSampleBias2dF32: - return R"(texture.sample(sampler, float2(1.0f, 2.0f), bias(3.0f)))"; + return R"(test_texture.sample(test_sampler, float2(1.0f, 2.0f), bias(3.0f)))"; case ValidTextureOverload::kSampleBias2dOffsetF32: - return R"(texture.sample(sampler, float2(1.0f, 2.0f), bias(3.0f), int2(4, 5)))"; + return R"(test_texture.sample(test_sampler, float2(1.0f, 2.0f), bias(3.0f), int2(4, 5)))"; case ValidTextureOverload::kSampleBias2dArrayF32: - return R"(texture.sample(sampler, float2(1.0f, 2.0f), 4, bias(3.0f)))"; + return R"(test_texture.sample(test_sampler, float2(1.0f, 2.0f), 4, bias(3.0f)))"; case ValidTextureOverload::kSampleBias2dArrayOffsetF32: - return R"(texture.sample(sampler, float2(1.0f, 2.0f), 3, bias(4.0f), int2(5, 6)))"; + return R"(test_texture.sample(test_sampler, float2(1.0f, 2.0f), 3, bias(4.0f), int2(5, 6)))"; case ValidTextureOverload::kSampleBias3dF32: - return R"(texture.sample(sampler, float3(1.0f, 2.0f, 3.0f), bias(4.0f)))"; + return R"(test_texture.sample(test_sampler, float3(1.0f, 2.0f, 3.0f), bias(4.0f)))"; case ValidTextureOverload::kSampleBias3dOffsetF32: - return R"(texture.sample(sampler, float3(1.0f, 2.0f, 3.0f), bias(4.0f), int3(5, 6, 7)))"; + return R"(test_texture.sample(test_sampler, float3(1.0f, 2.0f, 3.0f), bias(4.0f), int3(5, 6, 7)))"; case ValidTextureOverload::kSampleBiasCubeF32: - return R"(texture.sample(sampler, float3(1.0f, 2.0f, 3.0f), bias(4.0f)))"; + return R"(test_texture.sample(test_sampler, float3(1.0f, 2.0f, 3.0f), bias(4.0f)))"; case ValidTextureOverload::kSampleBiasCubeArrayF32: - return R"(texture.sample(sampler, float3(1.0f, 2.0f, 3.0f), 3, bias(4.0f)))"; + return R"(test_texture.sample(test_sampler, float3(1.0f, 2.0f, 3.0f), 3, bias(4.0f)))"; case ValidTextureOverload::kSampleLevel2dF32: - return R"(texture.sample(sampler, float2(1.0f, 2.0f), level(3.0f)))"; + return R"(test_texture.sample(test_sampler, float2(1.0f, 2.0f), level(3.0f)))"; case ValidTextureOverload::kSampleLevel2dOffsetF32: - return R"(texture.sample(sampler, float2(1.0f, 2.0f), level(3.0f), int2(4, 5)))"; + return R"(test_texture.sample(test_sampler, float2(1.0f, 2.0f), level(3.0f), int2(4, 5)))"; case ValidTextureOverload::kSampleLevel2dArrayF32: - return R"(texture.sample(sampler, float2(1.0f, 2.0f), 3, level(4.0f)))"; + return R"(test_texture.sample(test_sampler, float2(1.0f, 2.0f), 3, level(4.0f)))"; case ValidTextureOverload::kSampleLevel2dArrayOffsetF32: - return R"(texture.sample(sampler, float2(1.0f, 2.0f), 3, level(4.0f), int2(5, 6)))"; + return R"(test_texture.sample(test_sampler, float2(1.0f, 2.0f), 3, level(4.0f), int2(5, 6)))"; case ValidTextureOverload::kSampleLevel3dF32: - return R"(texture.sample(sampler, float3(1.0f, 2.0f, 3.0f), level(4.0f)))"; + return R"(test_texture.sample(test_sampler, float3(1.0f, 2.0f, 3.0f), level(4.0f)))"; case ValidTextureOverload::kSampleLevel3dOffsetF32: - return R"(texture.sample(sampler, float3(1.0f, 2.0f, 3.0f), level(4.0f), int3(5, 6, 7)))"; + return R"(test_texture.sample(test_sampler, float3(1.0f, 2.0f, 3.0f), level(4.0f), int3(5, 6, 7)))"; case ValidTextureOverload::kSampleLevelCubeF32: - return R"(texture.sample(sampler, float3(1.0f, 2.0f, 3.0f), level(4.0f)))"; + return R"(test_texture.sample(test_sampler, float3(1.0f, 2.0f, 3.0f), level(4.0f)))"; case ValidTextureOverload::kSampleLevelCubeArrayF32: - return R"(texture.sample(sampler, float3(1.0f, 2.0f, 3.0f), 4, level(5.0f)))"; + return R"(test_texture.sample(test_sampler, float3(1.0f, 2.0f, 3.0f), 4, level(5.0f)))"; case ValidTextureOverload::kSampleLevelDepth2dF32: - return R"(texture.sample(sampler, float2(1.0f, 2.0f), level(3)))"; + return R"(test_texture.sample(test_sampler, float2(1.0f, 2.0f), level(3)))"; case ValidTextureOverload::kSampleLevelDepth2dOffsetF32: - return R"(texture.sample(sampler, float2(1.0f, 2.0f), level(3), int2(4, 5)))"; + return R"(test_texture.sample(test_sampler, float2(1.0f, 2.0f), level(3), int2(4, 5)))"; case ValidTextureOverload::kSampleLevelDepth2dArrayF32: - return R"(texture.sample(sampler, float2(1.0f, 2.0f), 3, level(4)))"; + return R"(test_texture.sample(test_sampler, float2(1.0f, 2.0f), 3, level(4)))"; case ValidTextureOverload::kSampleLevelDepth2dArrayOffsetF32: - return R"(texture.sample(sampler, float2(1.0f, 2.0f), 3, level(4), int2(5, 6)))"; + return R"(test_texture.sample(test_sampler, float2(1.0f, 2.0f), 3, level(4), int2(5, 6)))"; case ValidTextureOverload::kSampleLevelDepthCubeF32: - return R"(texture.sample(sampler, float3(1.0f, 2.0f, 3.0f), level(4)))"; + return R"(test_texture.sample(test_sampler, float3(1.0f, 2.0f, 3.0f), level(4)))"; case ValidTextureOverload::kSampleLevelDepthCubeArrayF32: - return R"(texture.sample(sampler, float3(1.0f, 2.0f, 3.0f), 4, level(5)))"; + return R"(test_texture.sample(test_sampler, float3(1.0f, 2.0f, 3.0f), 4, level(5)))"; case ValidTextureOverload::kSampleGrad2dF32: - return R"(texture.sample(sampler, float2(1.0f, 2.0f), gradient2d(float2(3.0f, 4.0f), float2(5.0f, 6.0f))))"; + return R"(test_texture.sample(test_sampler, float2(1.0f, 2.0f), gradient2d(float2(3.0f, 4.0f), float2(5.0f, 6.0f))))"; case ValidTextureOverload::kSampleGrad2dOffsetF32: - return R"(texture.sample(sampler, float2(1.0f, 2.0f), gradient2d(float2(3.0f, 4.0f), float2(5.0f, 6.0f)), int2(7, 8)))"; + return R"(test_texture.sample(test_sampler, float2(1.0f, 2.0f), gradient2d(float2(3.0f, 4.0f), float2(5.0f, 6.0f)), int2(7, 8)))"; case ValidTextureOverload::kSampleGrad2dArrayF32: - return R"(texture.sample(sampler, float2(1.0f, 2.0f), 3, gradient2d(float2(4.0f, 5.0f), float2(6.0f, 7.0f))))"; + return R"(test_texture.sample(test_sampler, float2(1.0f, 2.0f), 3, gradient2d(float2(4.0f, 5.0f), float2(6.0f, 7.0f))))"; case ValidTextureOverload::kSampleGrad2dArrayOffsetF32: - return R"(texture.sample(sampler, float2(1.0f, 2.0f), 3, gradient2d(float2(4.0f, 5.0f), float2(6.0f, 7.0f)), int2(8, 9)))"; + return R"(test_texture.sample(test_sampler, float2(1.0f, 2.0f), 3, gradient2d(float2(4.0f, 5.0f), float2(6.0f, 7.0f)), int2(8, 9)))"; case ValidTextureOverload::kSampleGrad3dF32: - return R"(texture.sample(sampler, float3(1.0f, 2.0f, 3.0f), gradient3d(float3(4.0f, 5.0f, 6.0f), float3(7.0f, 8.0f, 9.0f))))"; + return R"(test_texture.sample(test_sampler, float3(1.0f, 2.0f, 3.0f), gradient3d(float3(4.0f, 5.0f, 6.0f), float3(7.0f, 8.0f, 9.0f))))"; case ValidTextureOverload::kSampleGrad3dOffsetF32: - return R"(texture.sample(sampler, float3(1.0f, 2.0f, 3.0f), gradient3d(float3(4.0f, 5.0f, 6.0f), float3(7.0f, 8.0f, 9.0f)), int3(10, 11, 12)))"; + return R"(test_texture.sample(test_sampler, float3(1.0f, 2.0f, 3.0f), gradient3d(float3(4.0f, 5.0f, 6.0f), float3(7.0f, 8.0f, 9.0f)), int3(10, 11, 12)))"; case ValidTextureOverload::kSampleGradCubeF32: - return R"(texture.sample(sampler, float3(1.0f, 2.0f, 3.0f), gradientcube(float3(4.0f, 5.0f, 6.0f), float3(7.0f, 8.0f, 9.0f))))"; + return R"(test_texture.sample(test_sampler, float3(1.0f, 2.0f, 3.0f), gradientcube(float3(4.0f, 5.0f, 6.0f), float3(7.0f, 8.0f, 9.0f))))"; case ValidTextureOverload::kSampleGradCubeArrayF32: - return R"(texture.sample(sampler, float3(1.0f, 2.0f, 3.0f), 4, gradientcube(float3(5.0f, 6.0f, 7.0f), float3(8.0f, 9.0f, 10.0f))))"; + return R"(test_texture.sample(test_sampler, float3(1.0f, 2.0f, 3.0f), 4, gradientcube(float3(5.0f, 6.0f, 7.0f), float3(8.0f, 9.0f, 10.0f))))"; case ValidTextureOverload::kSampleGradDepth2dF32: - return R"(texture.sample_compare(sampler, float2(1.0f, 2.0f), 3.0f))"; + return R"(test_texture.sample_compare(test_sampler, float2(1.0f, 2.0f), 3.0f))"; case ValidTextureOverload::kSampleGradDepth2dOffsetF32: - return R"(texture.sample_compare(sampler, float2(1.0f, 2.0f), 3.0f, int2(4, 5)))"; + return R"(test_texture.sample_compare(test_sampler, float2(1.0f, 2.0f), 3.0f, int2(4, 5)))"; case ValidTextureOverload::kSampleGradDepth2dArrayF32: - return R"(texture.sample_compare(sampler, float2(1.0f, 2.0f), 4, 3.0f))"; + return R"(test_texture.sample_compare(test_sampler, float2(1.0f, 2.0f), 4, 3.0f))"; case ValidTextureOverload::kSampleGradDepth2dArrayOffsetF32: - return R"(texture.sample_compare(sampler, float2(1.0f, 2.0f), 4, 3.0f, int2(5, 6)))"; + return R"(test_texture.sample_compare(test_sampler, float2(1.0f, 2.0f), 4, 3.0f, int2(5, 6)))"; case ValidTextureOverload::kSampleGradDepthCubeF32: - return R"(texture.sample_compare(sampler, float3(1.0f, 2.0f, 3.0f), 4.0f))"; + return R"(test_texture.sample_compare(test_sampler, float3(1.0f, 2.0f, 3.0f), 4.0f))"; case ValidTextureOverload::kSampleGradDepthCubeArrayF32: - return R"(texture.sample_compare(sampler, float3(1.0f, 2.0f, 3.0f), 4, 5.0f))"; + return R"(test_texture.sample_compare(test_sampler, float3(1.0f, 2.0f, 3.0f), 4, 5.0f))"; case ValidTextureOverload::kLoad1dF32: - return R"(texture.read(1))"; + return R"(test_texture.read(1))"; case ValidTextureOverload::kLoad1dU32: - return R"(texture.read(1))"; + return R"(test_texture.read(1))"; case ValidTextureOverload::kLoad1dI32: - return R"(texture.read(1))"; + return R"(test_texture.read(1))"; case ValidTextureOverload::kLoad1dArrayF32: - return R"(texture.read(1, 2))"; + return R"(test_texture.read(1, 2))"; case ValidTextureOverload::kLoad1dArrayU32: - return R"(texture.read(1, 2))"; + return R"(test_texture.read(1, 2))"; case ValidTextureOverload::kLoad1dArrayI32: - return R"(texture.read(1, 2))"; + return R"(test_texture.read(1, 2))"; case ValidTextureOverload::kLoad2dF32: - return R"(texture.read(int2(1, 2)))"; + return R"(test_texture.read(int2(1, 2)))"; case ValidTextureOverload::kLoad2dU32: - return R"(texture.read(int2(1, 2)))"; + return R"(test_texture.read(int2(1, 2)))"; case ValidTextureOverload::kLoad2dI32: - return R"(texture.read(int2(1, 2)))"; + return R"(test_texture.read(int2(1, 2)))"; case ValidTextureOverload::kLoad2dLevelF32: - return R"(texture.read(int2(1, 2), 3))"; + return R"(test_texture.read(int2(1, 2), 3))"; case ValidTextureOverload::kLoad2dLevelU32: - return R"(texture.read(int2(1, 2), 3))"; + return R"(test_texture.read(int2(1, 2), 3))"; case ValidTextureOverload::kLoad2dLevelI32: - return R"(texture.read(int2(1, 2), 3))"; + return R"(test_texture.read(int2(1, 2), 3))"; case ValidTextureOverload::kLoad2dArrayF32: - return R"(texture.read(int2(1, 2), 3))"; + return R"(test_texture.read(int2(1, 2), 3))"; case ValidTextureOverload::kLoad2dArrayU32: - return R"(texture.read(int2(1, 2), 3))"; + return R"(test_texture.read(int2(1, 2), 3))"; case ValidTextureOverload::kLoad2dArrayI32: - return R"(texture.read(int2(1, 2), 3))"; + return R"(test_texture.read(int2(1, 2), 3))"; case ValidTextureOverload::kLoad2dArrayLevelF32: - return R"(texture.read(int2(1, 2), 3, 4))"; + return R"(test_texture.read(int2(1, 2), 3, 4))"; case ValidTextureOverload::kLoad2dArrayLevelU32: - return R"(texture.read(int2(1, 2), 3, 4))"; + return R"(test_texture.read(int2(1, 2), 3, 4))"; case ValidTextureOverload::kLoad2dArrayLevelI32: - return R"(texture.read(int2(1, 2), 3, 4))"; + return R"(test_texture.read(int2(1, 2), 3, 4))"; case ValidTextureOverload::kLoad3dF32: - return R"(texture.read(int3(1, 2, 3)))"; + return R"(test_texture.read(int3(1, 2, 3)))"; case ValidTextureOverload::kLoad3dU32: - return R"(texture.read(int3(1, 2, 3)))"; + return R"(test_texture.read(int3(1, 2, 3)))"; case ValidTextureOverload::kLoad3dI32: - return R"(texture.read(int3(1, 2, 3)))"; + return R"(test_texture.read(int3(1, 2, 3)))"; case ValidTextureOverload::kLoad3dLevelF32: - return R"(texture.read(int3(1, 2, 3), 4))"; + return R"(test_texture.read(int3(1, 2, 3), 4))"; case ValidTextureOverload::kLoad3dLevelU32: - return R"(texture.read(int3(1, 2, 3), 4))"; + return R"(test_texture.read(int3(1, 2, 3), 4))"; case ValidTextureOverload::kLoad3dLevelI32: - return R"(texture.read(int3(1, 2, 3), 4))"; + return R"(test_texture.read(int3(1, 2, 3), 4))"; case ValidTextureOverload::kLoadMultisampled2dF32: - return R"(texture.read(int2(1, 2), 3))"; + return R"(test_texture.read(int2(1, 2), 3))"; case ValidTextureOverload::kLoadMultisampled2dU32: - return R"(texture.read(int2(1, 2), 3))"; + return R"(test_texture.read(int2(1, 2), 3))"; case ValidTextureOverload::kLoadMultisampled2dI32: - return R"(texture.read(int2(1, 2), 3))"; + return R"(test_texture.read(int2(1, 2), 3))"; case ValidTextureOverload::kLoadMultisampled2dArrayF32: - return R"(texture.read(int2(1, 2), 3, 4))"; + return R"(test_texture.read(int2(1, 2), 3, 4))"; case ValidTextureOverload::kLoadMultisampled2dArrayU32: - return R"(texture.read(int2(1, 2), 3, 4))"; + return R"(test_texture.read(int2(1, 2), 3, 4))"; case ValidTextureOverload::kLoadMultisampled2dArrayI32: - return R"(texture.read(int2(1, 2), 3, 4))"; + return R"(test_texture.read(int2(1, 2), 3, 4))"; case ValidTextureOverload::kLoadDepth2dF32: - return R"(texture.read(int2(1, 2)))"; + return R"(test_texture.read(int2(1, 2)))"; case ValidTextureOverload::kLoadDepth2dLevelF32: - return R"(texture.read(int2(1, 2), 3))"; + return R"(test_texture.read(int2(1, 2), 3))"; case ValidTextureOverload::kLoadDepth2dArrayF32: - return R"(texture.read(int2(1, 2), 3))"; + return R"(test_texture.read(int2(1, 2), 3))"; case ValidTextureOverload::kLoadDepth2dArrayLevelF32: - return R"(texture.read(int2(1, 2), 3, 4))"; + return R"(test_texture.read(int2(1, 2), 3, 4))"; case ValidTextureOverload::kLoadStorageRO1dRgba32float: - return R"(texture.read(1))"; + return R"(test_texture.read(1))"; case ValidTextureOverload::kLoadStorageRO1dArrayRgba32float: - return R"(texture.read(1, 2))"; + return R"(test_texture.read(1, 2))"; case ValidTextureOverload::kLoadStorageRO2dRgba8unorm: case ValidTextureOverload::kLoadStorageRO2dRgba8snorm: case ValidTextureOverload::kLoadStorageRO2dRgba8uint: @@ -224,21 +225,21 @@ std::string expected_texture_overload( case ValidTextureOverload::kLoadStorageRO2dRgba32uint: case ValidTextureOverload::kLoadStorageRO2dRgba32sint: case ValidTextureOverload::kLoadStorageRO2dRgba32float: - return R"(texture.read(int2(1, 2)))"; + return R"(test_texture.read(int2(1, 2)))"; case ValidTextureOverload::kLoadStorageRO2dArrayRgba32float: - return R"(texture.read(int2(1, 2), 3))"; + return R"(test_texture.read(int2(1, 2), 3))"; case ValidTextureOverload::kLoadStorageRO3dRgba32float: - return R"(texture.read(int3(1, 2, 3)))"; + return R"(test_texture.read(int3(1, 2, 3)))"; case ValidTextureOverload::kStoreWO1dRgba32float: - return R"(texture.write(float4(2.0f, 3.0f, 4.0f, 5.0f), 1))"; + return R"(test_texture.write(float4(2.0f, 3.0f, 4.0f, 5.0f), 1))"; case ValidTextureOverload::kStoreWO1dArrayRgba32float: - return R"(texture.write(float4(3.0f, 4.0f, 5.0f, 6.0f), 1, 2))"; + return R"(test_texture.write(float4(3.0f, 4.0f, 5.0f, 6.0f), 1, 2))"; case ValidTextureOverload::kStoreWO2dRgba32float: - return R"(texture.write(float4(3.0f, 4.0f, 5.0f, 6.0f), int2(1, 2)))"; + return R"(test_texture.write(float4(3.0f, 4.0f, 5.0f, 6.0f), int2(1, 2)))"; case ValidTextureOverload::kStoreWO2dArrayRgba32float: - return R"(texture.write(float4(4.0f, 5.0f, 6.0f, 7.0f), int2(1, 2), 3))"; + return R"(test_texture.write(float4(4.0f, 5.0f, 6.0f, 7.0f), int2(1, 2), 3))"; case ValidTextureOverload::kStoreWO3dRgba32float: - return R"(texture.write(float4(4.0f, 5.0f, 6.0f, 7.0f), int3(1, 2, 3)))"; + return R"(test_texture.write(float4(4.0f, 5.0f, 6.0f, 7.0f), int3(1, 2, 3)))"; } return ""; } // NOLINT - Ignore the length of this function @@ -253,8 +254,10 @@ class MslGeneratorIntrinsicTextureTest /// The type determiner TypeDeterminer td{mod}; + /// The namer + TestNamer namer{mod}; /// The generator - GeneratorImpl gen{mod}; + GeneratorImpl gen{mod, &namer}; }; TEST_P(MslGeneratorIntrinsicTextureTest, Call) { diff --git a/src/writer/msl/generator_impl_loop_test.cc b/src/writer/msl/generator_impl_loop_test.cc index 76e8a3e2f1..5e135b37c8 100644 --- a/src/writer/msl/generator_impl_loop_test.cc +++ b/src/writer/msl/generator_impl_loop_test.cc @@ -102,7 +102,7 @@ TEST_F(MslGeneratorImplTest, Emit_LoopNestedWithContinuing) { bool tint_msl_is_first_1 = true; for(;;) { if (!tint_msl_is_first_1) { - lhs = rhs; + test_lhs = test_rhs; } tint_msl_is_first_1 = false; @@ -162,16 +162,16 @@ TEST_F(MslGeneratorImplTest, Emit_LoopWithVarUsedInContinuing) { ASSERT_TRUE(gen.EmitStatement(outer)) << gen.error(); EXPECT_EQ(gen.result(), R"( { bool tint_msl_is_first_1 = true; - float lhs; - float other; + float test_lhs; + float test_other; for(;;) { if (!tint_msl_is_first_1) { - lhs = rhs; + test_lhs = test_rhs; } tint_msl_is_first_1 = false; - lhs = 2.400000095f; - other = 0.0f; + test_lhs = 2.400000095f; + test_other = 0.0f; } } )"); diff --git a/src/writer/msl/generator_impl_member_accessor_test.cc b/src/writer/msl/generator_impl_member_accessor_test.cc index f1b8644640..8eb0264f9d 100644 --- a/src/writer/msl/generator_impl_member_accessor_test.cc +++ b/src/writer/msl/generator_impl_member_accessor_test.cc @@ -32,7 +32,29 @@ TEST_F(MslGeneratorImplTest, EmitExpression_MemberAccessor) { auto* expr = MemberAccessor("str", "mem"); ASSERT_TRUE(gen.EmitExpression(expr)) << gen.error(); - EXPECT_EQ(gen.result(), "str.mem"); + EXPECT_EQ(gen.result(), "test_str.test_mem"); +} + +TEST_F(MslGeneratorImplTest, EmitExpression_MemberAccessor_Swizzle_xyz) { + auto* vec = Var("my_vec", ast::StorageClass::kPrivate, ty.vec4()); + td.RegisterVariableForTesting(vec); + mod->AddGlobalVariable(vec); + + auto* expr = MemberAccessor("my_vec", "xyz"); + ASSERT_TRUE(td.DetermineResultType(expr)) << td.error(); + ASSERT_TRUE(gen.EmitExpression(expr)) << gen.error(); + EXPECT_EQ(gen.result(), "test_my_vec.xyz"); +} + +TEST_F(MslGeneratorImplTest, EmitExpression_MemberAccessor_Swizzle_gbr) { + auto* vec = Var("my_vec", ast::StorageClass::kPrivate, ty.vec4()); + td.RegisterVariableForTesting(vec); + mod->AddGlobalVariable(vec); + + auto* expr = MemberAccessor("my_vec", "gbr"); + ASSERT_TRUE(td.DetermineResultType(expr)) << td.error(); + ASSERT_TRUE(gen.EmitExpression(expr)) << gen.error(); + EXPECT_EQ(gen.result(), "test_my_vec.gbr"); } } // namespace diff --git a/src/writer/msl/generator_impl_module_constant_test.cc b/src/writer/msl/generator_impl_module_constant_test.cc index 7e272d6aa8..71eb28931d 100644 --- a/src/writer/msl/generator_impl_module_constant_test.cc +++ b/src/writer/msl/generator_impl_module_constant_test.cc @@ -40,7 +40,7 @@ TEST_F(MslGeneratorImplTest, Emit_ModuleConstant) { array(1.f, 2.f, 3.f), ast::VariableDecorationList{}); ASSERT_TRUE(gen.EmitProgramConstVariable(var)) << gen.error(); - EXPECT_EQ(gen.result(), "constant float pos[3] = {1.0f, 2.0f, 3.0f};\n"); + EXPECT_EQ(gen.result(), "constant float test_pos[3] = {1.0f, 2.0f, 3.0f};\n"); } TEST_F(MslGeneratorImplTest, Emit_SpecConstant) { @@ -50,7 +50,8 @@ TEST_F(MslGeneratorImplTest, Emit_SpecConstant) { }); ASSERT_TRUE(gen.EmitProgramConstVariable(var)) << gen.error(); - EXPECT_EQ(gen.result(), "constant float pos [[function_constant(23)]];\n"); + EXPECT_EQ(gen.result(), + "constant float test_pos [[function_constant(23)]];\n"); } } // namespace diff --git a/src/writer/msl/generator_impl_return_test.cc b/src/writer/msl/generator_impl_return_test.cc index e017d6a86e..d3be1b0a13 100644 --- a/src/writer/msl/generator_impl_return_test.cc +++ b/src/writer/msl/generator_impl_return_test.cc @@ -42,7 +42,7 @@ TEST_F(MslGeneratorImplTest, Emit_ReturnWithValue) { gen.increment_indent(); ASSERT_TRUE(gen.EmitStatement(r)) << gen.error(); - EXPECT_EQ(gen.result(), " return expr;\n"); + EXPECT_EQ(gen.result(), " return test_expr;\n"); } } // namespace diff --git a/src/writer/msl/generator_impl_switch_test.cc b/src/writer/msl/generator_impl_switch_test.cc index c67822ae0b..00c29ba279 100644 --- a/src/writer/msl/generator_impl_switch_test.cc +++ b/src/writer/msl/generator_impl_switch_test.cc @@ -55,7 +55,7 @@ TEST_F(MslGeneratorImplTest, Emit_Switch) { gen.increment_indent(); ASSERT_TRUE(gen.EmitStatement(s)) << gen.error(); - EXPECT_EQ(gen.result(), R"( switch(cond) { + EXPECT_EQ(gen.result(), R"( switch(test_cond) { case 5: { break; } diff --git a/src/writer/msl/generator_impl_test.cc b/src/writer/msl/generator_impl_test.cc index 27ee2c05d9..cc761715bd 100644 --- a/src/writer/msl/generator_impl_test.cc +++ b/src/writer/msl/generator_impl_test.cc @@ -57,7 +57,7 @@ TEST_F(MslGeneratorImplTest, Generate) { ASSERT_TRUE(gen.Generate()) << gen.error(); EXPECT_EQ(gen.result(), R"(#include -kernel void my_func() { +kernel void test_my_func() { } )"); diff --git a/src/writer/msl/generator_impl_type_test.cc b/src/writer/msl/generator_impl_type_test.cc index a9fc6ed0b5..9731f809e7 100644 --- a/src/writer/msl/generator_impl_type_test.cc +++ b/src/writer/msl/generator_impl_type_test.cc @@ -49,13 +49,13 @@ using MslGeneratorImplTest = TestHelper; TEST_F(MslGeneratorImplTest, EmitType_Alias) { auto* alias = ty.alias("alias", ty.f32); ASSERT_TRUE(gen.EmitType(alias, Symbol())) << gen.error(); - EXPECT_EQ(gen.result(), "alias"); + EXPECT_EQ(gen.result(), "test_alias"); } TEST_F(MslGeneratorImplTest, EmitType_Array) { auto sym = mod->RegisterSymbol("ary"); ASSERT_TRUE(gen.EmitType(ty.array(), sym)) << gen.error(); - EXPECT_EQ(gen.result(), "bool ary[4]"); + EXPECT_EQ(gen.result(), "bool test_ary[4]"); } TEST_F(MslGeneratorImplTest, EmitType_ArrayOfArray) { @@ -63,7 +63,7 @@ TEST_F(MslGeneratorImplTest, EmitType_ArrayOfArray) { auto* b = ty.array(a, 5); auto sym = mod->RegisterSymbol("ary"); ASSERT_TRUE(gen.EmitType(b, sym)) << gen.error(); - EXPECT_EQ(gen.result(), "bool ary[5][4]"); + EXPECT_EQ(gen.result(), "bool test_ary[5][4]"); } // TODO(dsinclair): Is this possible? What order should it output in? @@ -73,7 +73,7 @@ TEST_F(MslGeneratorImplTest, DISABLED_EmitType_ArrayOfArrayOfRuntimeArray) { auto* c = ty.array(b, 0); auto sym = mod->RegisterSymbol("ary"); ASSERT_TRUE(gen.EmitType(c, sym)) << gen.error(); - EXPECT_EQ(gen.result(), "bool ary[5][4][1]"); + EXPECT_EQ(gen.result(), "bool test_ary[5][4][1]"); } TEST_F(MslGeneratorImplTest, EmitType_ArrayOfArrayOfArray) { @@ -82,7 +82,7 @@ TEST_F(MslGeneratorImplTest, EmitType_ArrayOfArrayOfArray) { auto* c = ty.array(b, 6); auto sym = mod->RegisterSymbol("ary"); ASSERT_TRUE(gen.EmitType(c, sym)) << gen.error(); - EXPECT_EQ(gen.result(), "bool ary[6][5][4]"); + EXPECT_EQ(gen.result(), "bool test_ary[6][5][4]"); } TEST_F(MslGeneratorImplTest, EmitType_Array_WithoutName) { @@ -93,7 +93,7 @@ TEST_F(MslGeneratorImplTest, EmitType_Array_WithoutName) { TEST_F(MslGeneratorImplTest, EmitType_RuntimeArray) { auto sym = mod->RegisterSymbol("ary"); ASSERT_TRUE(gen.EmitType(ty.array(), sym)) << gen.error(); - EXPECT_EQ(gen.result(), "bool ary[1]"); + EXPECT_EQ(gen.result(), "bool test_ary[1]"); } TEST_F(MslGeneratorImplTest, EmitType_Bool) { @@ -132,7 +132,7 @@ TEST_F(MslGeneratorImplTest, EmitType_Struct) { auto* s = ty.struct_("S", str); ASSERT_TRUE(gen.EmitType(s, Symbol())) << gen.error(); - EXPECT_EQ(gen.result(), "S"); + EXPECT_EQ(gen.result(), "test_S"); } TEST_F(MslGeneratorImplTest, EmitType_StructDecl) { @@ -144,9 +144,9 @@ TEST_F(MslGeneratorImplTest, EmitType_StructDecl) { auto* s = ty.struct_("S", str); ASSERT_TRUE(gen.EmitStructType(s)) << gen.error(); - EXPECT_EQ(gen.result(), R"(struct S { - int a; - float b; + EXPECT_EQ(gen.result(), R"(struct test_S { + int test_a; + float test_b; }; )"); } @@ -162,13 +162,13 @@ TEST_F(MslGeneratorImplTest, EmitType_Struct_InjectPadding) { auto* s = ty.struct_("S", str); ASSERT_TRUE(gen.EmitStructType(s)) << gen.error(); - EXPECT_EQ(gen.result(), R"(struct S { + EXPECT_EQ(gen.result(), R"(struct test_S { int8_t pad_0[4]; - int a; + int test_a; int8_t pad_1[24]; - float b; + float test_b; int8_t pad_2[92]; - float c; + float test_c; }; )"); } @@ -184,9 +184,9 @@ TEST_F(MslGeneratorImplTest, DISABLED_EmitType_Struct_WithDecoration) { auto* s = ty.struct_("S", str); ASSERT_TRUE(gen.EmitType(s, Symbol())) << gen.error(); - EXPECT_EQ(gen.result(), R"(struct { - int a; - float b; + EXPECT_EQ(gen.result(), R"(struct test_S { + int test_a; + float test_b; })"); } diff --git a/src/writer/msl/generator_impl_unary_op_test.cc b/src/writer/msl/generator_impl_unary_op_test.cc index c93bee2366..0673ea3fe1 100644 --- a/src/writer/msl/generator_impl_unary_op_test.cc +++ b/src/writer/msl/generator_impl_unary_op_test.cc @@ -40,7 +40,7 @@ TEST_P(MslUnaryOpTest, Emit) { auto params = GetParam(); auto* op = create(params.op, Expr("expr")); ASSERT_TRUE(gen.EmitExpression(op)) << gen.error(); - EXPECT_EQ(gen.result(), std::string(params.name) + "(expr)"); + EXPECT_EQ(gen.result(), std::string(params.name) + "(test_expr)"); } INSTANTIATE_TEST_SUITE_P(MslGeneratorImplTest, MslUnaryOpTest, diff --git a/src/writer/msl/generator_impl_variable_decl_statement_test.cc b/src/writer/msl/generator_impl_variable_decl_statement_test.cc index 777bb3254d..13158f0c72 100644 --- a/src/writer/msl/generator_impl_variable_decl_statement_test.cc +++ b/src/writer/msl/generator_impl_variable_decl_statement_test.cc @@ -47,7 +47,7 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement) { gen.increment_indent(); ASSERT_TRUE(gen.EmitStatement(stmt)) << gen.error(); - EXPECT_EQ(gen.result(), " float a = 0.0f;\n"); + EXPECT_EQ(gen.result(), " float test_a = 0.0f;\n"); } TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Const) { @@ -57,7 +57,7 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Const) { gen.increment_indent(); ASSERT_TRUE(gen.EmitStatement(stmt)) << gen.error(); - EXPECT_EQ(gen.result(), " const float a = 0.0f;\n"); + EXPECT_EQ(gen.result(), " const float test_a = 0.0f;\n"); } TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Array) { @@ -69,7 +69,7 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Array) { gen.increment_indent(); ASSERT_TRUE(gen.EmitStatement(stmt)) << gen.error(); - EXPECT_EQ(gen.result(), " float a[5] = {0.0f};\n"); + EXPECT_EQ(gen.result(), " float test_a[5] = {0.0f};\n"); } TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Struct) { @@ -85,7 +85,7 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Struct) { gen.increment_indent(); ASSERT_TRUE(gen.EmitStatement(stmt)) << gen.error(); - EXPECT_EQ(gen.result(), R"( S a = {}; + EXPECT_EQ(gen.result(), R"( test_S test_a = {}; )"); } @@ -96,7 +96,7 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Vector) { gen.increment_indent(); ASSERT_TRUE(gen.EmitStatement(stmt)) << gen.error(); - EXPECT_EQ(gen.result(), " float2 a = 0.0f;\n"); + EXPECT_EQ(gen.result(), " float2 test_a = 0.0f;\n"); } TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Matrix) { @@ -107,7 +107,7 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Matrix) { gen.increment_indent(); ASSERT_TRUE(gen.EmitStatement(stmt)) << gen.error(); - EXPECT_EQ(gen.result(), " float3x2 a = 0.0f;\n"); + EXPECT_EQ(gen.result(), " float3x2 test_a = 0.0f;\n"); } TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Private) { @@ -117,7 +117,7 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Private) { gen.increment_indent(); ASSERT_TRUE(gen.EmitStatement(stmt)) << gen.error(); - EXPECT_EQ(gen.result(), " float a = 0.0f;\n"); + EXPECT_EQ(gen.result(), " float test_a = 0.0f;\n"); } TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Initializer_Private) { @@ -126,7 +126,7 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Initializer_Private) { auto* stmt = create(var); ASSERT_TRUE(gen.EmitStatement(stmt)) << gen.error(); - EXPECT_EQ(gen.result(), R"(float a = initializer; + EXPECT_EQ(gen.result(), R"(float test_a = test_initializer; )"); } @@ -138,7 +138,7 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Initializer_ZeroVec) { auto* stmt = create(var); ASSERT_TRUE(gen.EmitStatement(stmt)) << gen.error(); - EXPECT_EQ(gen.result(), R"(float3 a = float3(0.0f); + EXPECT_EQ(gen.result(), R"(float3 test_a = float3(0.0f); )"); } diff --git a/src/writer/msl/test_helper.h b/src/writer/msl/test_helper.h index 554e628872..e4086b93ce 100644 --- a/src/writer/msl/test_helper.h +++ b/src/writer/msl/test_helper.h @@ -23,6 +23,7 @@ #include "src/ast/module.h" #include "src/type_determiner.h" #include "src/writer/msl/generator_impl.h" +#include "src/writer/test_namer.h" namespace tint { namespace writer { @@ -32,11 +33,13 @@ namespace msl { template class TestHelperBase : public BASE, public ast::BuilderWithModule { public: - TestHelperBase() : td(mod), gen(mod) {} + TestHelperBase() : td(mod), namer_(mod), gen(mod, &namer_) {} ~TestHelperBase() = default; /// The type determiner TypeDeterminer td; + /// The namer + TestNamer namer_; /// The generator GeneratorImpl gen; }; diff --git a/src/writer/test_namer.cc b/src/writer/test_namer.cc new file mode 100644 index 0000000000..0ab1a7db69 --- /dev/null +++ b/src/writer/test_namer.cc @@ -0,0 +1,29 @@ +// Copyright 2021 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/test_namer.h" + +namespace tint { +namespace writer { + +TestNamer::TestNamer(ast::Module* mod) : Namer(mod) {} + +TestNamer::~TestNamer() = default; + +std::string TestNamer::NameFor(const Symbol& sym) { + return "test_" + module_->SymbolToName(sym); +} + +} // namespace writer +} // namespace tint diff --git a/src/writer/test_namer.h b/src/writer/test_namer.h new file mode 100644 index 0000000000..44a7e684c7 --- /dev/null +++ b/src/writer/test_namer.h @@ -0,0 +1,43 @@ +// Copyright 2021 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_TEST_NAMER_H_ +#define SRC_WRITER_TEST_NAMER_H_ + +#include + +#include "src/namer.h" + +namespace tint { +namespace writer { + +/// A namer which returns the provided name prefixed with `test_`. +class TestNamer : public Namer { + public: + /// Constructor + /// @param mod the module to retrieve names from + explicit TestNamer(ast::Module* mod); + /// Destructor + ~TestNamer() override; + + /// Returns `name` + /// @param sym the symbol + /// @returns `name` or "" if not found + std::string NameFor(const Symbol& sym) override; +}; + +} // namespace writer +} // namespace tint + +#endif // SRC_WRITER_TEST_NAMER_H_