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 <rharrison@chromium.org> Reviewed-by: Ben Clayton <bclayton@google.com>
This commit is contained in:
parent
c8c31560de
commit
f74b90b3dd
2
BUILD.gn
2
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 += [
|
||||
|
|
|
@ -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})
|
||||
|
|
|
@ -58,6 +58,12 @@ class IdentifierExpression : public Castable<IdentifierExpression, Expression> {
|
|||
/// @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, Expression> {
|
|||
IdentifierExpression(const IdentifierExpression&) = delete;
|
||||
|
||||
Symbol const sym_;
|
||||
|
||||
Intrinsic intrinsic_ = Intrinsic::kNone; // Semantic info
|
||||
std::unique_ptr<intrinsic::Signature> intrinsic_sig_; // Semantic info
|
||||
bool is_swizzle_ = false; // Semantic info
|
||||
};
|
||||
|
||||
} // namespace ast
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1079,7 +1079,7 @@ bool TypeDeterminer::DetermineMemberAccessor(
|
|||
ret = mod_->create<ast::type::Pointer>(ret, ptr->storage_class());
|
||||
}
|
||||
} else if (auto* vec = data_type->As<ast::type::Vector>()) {
|
||||
// TODO(dsinclair): Swizzle, record into the identifier experesion
|
||||
expr->member()->SetIsSwizzle();
|
||||
|
||||
auto size = mod_->SymbolToName(expr->member()->symbol()).size();
|
||||
if (size == 1) {
|
||||
|
|
|
@ -22,13 +22,15 @@ namespace msl {
|
|||
|
||||
Generator::Generator(ast::Module module)
|
||||
: Text(std::move(module)),
|
||||
impl_(std::make_unique<GeneratorImpl>(&module_)) {}
|
||||
namer_(std::make_unique<UnsafeNamer>(&module_)),
|
||||
impl_(std::make_unique<GeneratorImpl>(&module_, namer_.get())) {}
|
||||
|
||||
Generator::~Generator() = default;
|
||||
|
||||
void Generator::Reset() {
|
||||
set_error("");
|
||||
impl_ = std::make_unique<GeneratorImpl>(&module_);
|
||||
namer_->Reset();
|
||||
impl_ = std::make_unique<GeneratorImpl>(&module_, namer_.get());
|
||||
}
|
||||
|
||||
bool Generator::Generate() {
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#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> namer_;
|
||||
std::unique_ptr<GeneratorImpl> impl_;
|
||||
};
|
||||
|
||||
|
|
|
@ -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<UnsafeNamer>(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_ << " ";
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
#ifndef SRC_WRITER_MSL_GENERATOR_IMPL_H_
|
||||
#define SRC_WRITER_MSL_GENERATOR_IMPL_H_
|
||||
|
||||
#include <memory>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
@ -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<ast::Variable*> 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* namer_;
|
||||
|
||||
std::unordered_map<uint32_t, EntryPointData> ep_sym_to_in_data_;
|
||||
std::unordered_map<uint32_t, EntryPointData> ep_sym_to_out_data_;
|
||||
|
@ -287,7 +287,7 @@ class GeneratorImpl : public TextGenerator {
|
|||
// This maps an input of "<entry_point_name>_<function_name>" 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<std::string, std::string> ep_func_name_remapped_;
|
||||
std::unordered_map<std::string, Symbol> ep_func_name_remapped_;
|
||||
};
|
||||
|
||||
} // namespace msl
|
||||
|
|
|
@ -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;
|
||||
)");
|
||||
}
|
||||
|
||||
|
|
|
@ -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<ast::ArrayAccessorExpression>()))
|
||||
<< gen.error();
|
||||
EXPECT_EQ(gen.result(), "ary[idx]");
|
||||
EXPECT_EQ(gen.result(), "test_ary[test_idx]");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -32,7 +32,7 @@ using MslGeneratorImplTest = TestHelper;
|
|||
TEST_F(MslGeneratorImplTest, EmitExpression_Bitcast) {
|
||||
auto* bitcast = create<ast::BitcastExpression>(ty.f32, Expr("id"));
|
||||
ASSERT_TRUE(gen.EmitExpression(bitcast)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "as_type<float>(id)");
|
||||
EXPECT_EQ(gen.result(), "as_type<float>(test_id)");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -34,14 +34,14 @@ TEST_F(MslGeneratorImplTest, EmitExpression_Cast_Scalar) {
|
|||
auto* cast = Construct<f32>("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<f32>("id");
|
||||
|
||||
ASSERT_TRUE(gen.EmitExpression(cast)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "float3(id)");
|
||||
EXPECT_EQ(gen.result(), "float3(test_id)");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
|
|
@ -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)]];
|
||||
};
|
||||
|
||||
)");
|
||||
|
|
|
@ -68,27 +68,7 @@ TEST_F(MslGeneratorImplTest, Emit_Function) {
|
|||
ASSERT_TRUE(gen.Generate()) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"(#include <metal_stdlib>
|
||||
|
||||
void my_func() {
|
||||
return;
|
||||
}
|
||||
|
||||
)");
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, Emit_Function_Name_Collision) {
|
||||
auto* func = Func("main", ast::VariableList{}, ty.void_,
|
||||
ast::StatementList{
|
||||
create<ast::ReturnStatement>(),
|
||||
},
|
||||
ast::FunctionDecorationList{});
|
||||
|
||||
mod->AddFunction(func);
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(gen.Generate()) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"(#include <metal_stdlib>
|
||||
|
||||
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 <metal_stdlib>
|
||||
|
||||
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 <metal_stdlib>
|
||||
|
||||
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 <metal_stdlib>
|
||||
|
||||
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 <metal_stdlib>
|
||||
|
||||
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 <metal_stdlib>
|
||||
|
||||
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::Struct>(
|
||||
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 <metal_stdlib>
|
||||
|
||||
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 <metal_stdlib>
|
||||
|
||||
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 <metal_stdlib>
|
||||
|
||||
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 <metal_stdlib>
|
||||
|
||||
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 <metal_stdlib>
|
||||
|
||||
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 <metal_stdlib>
|
||||
|
||||
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 <metal_stdlib>
|
||||
|
||||
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 <metal_stdlib>
|
||||
|
||||
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 <metal_stdlib>
|
||||
|
||||
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 <metal_stdlib>
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -69,7 +69,7 @@ TEST_F(MslGeneratorImplTest, DISABLED_Intrinsic_OuterProduct) {
|
|||
auto* a = Var("a", ast::StorageClass::kNone, ty.vec2<f32>());
|
||||
auto* b = Var("b", ast::StorageClass::kNone, ty.vec3<f32>());
|
||||
|
||||
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
|
||||
|
|
|
@ -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 "<unmatched texture overload>";
|
||||
} // 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) {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
)");
|
||||
|
|
|
@ -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<f32>());
|
||||
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<f32>());
|
||||
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
|
||||
|
|
|
@ -40,7 +40,7 @@ TEST_F(MslGeneratorImplTest, Emit_ModuleConstant) {
|
|||
array<f32, 3>(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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -57,7 +57,7 @@ TEST_F(MslGeneratorImplTest, Generate) {
|
|||
ASSERT_TRUE(gen.Generate()) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"(#include <metal_stdlib>
|
||||
|
||||
kernel void my_func() {
|
||||
kernel void test_my_func() {
|
||||
}
|
||||
|
||||
)");
|
||||
|
|
|
@ -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<bool, 4>(), 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<bool, 1>(), 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;
|
||||
})");
|
||||
}
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ TEST_P(MslUnaryOpTest, Emit) {
|
|||
auto params = GetParam();
|
||||
auto* op = create<ast::UnaryOpExpression>(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,
|
||||
|
|
|
@ -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<ast::VariableDeclStatement>(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<ast::VariableDeclStatement>(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);
|
||||
)");
|
||||
}
|
||||
|
||||
|
|
|
@ -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 <typename BASE>
|
||||
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;
|
||||
};
|
||||
|
|
|
@ -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
|
|
@ -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 <string>
|
||||
|
||||
#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_
|
Loading…
Reference in New Issue