Simplify usage of the TypeDeterminer in tests

Make private all TypeDeterminer::DetermineXXX() methods, forcing all tests to use the root-level TypeDeterminer::Determine() method.
Remove TypeDeterminer::RegisterVariableForTesting().

The main use for calling the TypeDeterminer::DetermineXXX() methods was to perform type determination on a partial AST.
This was messy and often resulting in multiple calls into TypeDeterminer. Most tests already perform a full TypeDeterminer::Determine() call when the program is built, so many of these were redundant.
The exposure of these internal methods for testing also makes refactoring the TypeDeterminer extremely difficult.

Add a number of ProgramBuilder helper methods for attaching the partial AST in these tests to the root of the AST, greatly simplifying the use of the TypeDeterminer:
* ProgramBuilder::Global() and ProgramBuilder::GlobalConst() are helpers that register the variable returned by ProgramBuilder::Var() and ProgramBuilder::Const(), respectively.
* ProgramBuilder::WrapInFunction() is a variadic function that accepts variables, expressions and statements, attaching these to the root of the AST via a dummy function.

Most test classes now no longer use their own TypeDeterminer, and instead properly depend on the automatic type determination performed at Program build time.

Bug: tint:390
Change-Id: Ie901890420c5de170cdf2a7aaef9b96fc3bebd60
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/40062
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: David Neto <dneto@google.com>
This commit is contained in:
Ben Clayton 2021-02-03 17:19:59 +00:00 committed by Commit Bot service account
parent 87c78ddabc
commit 401b96b9bb
59 changed files with 1946 additions and 2388 deletions

View File

@ -160,18 +160,18 @@ ast::Variable* TextureOverloadCase::buildTextureVariable(
};
switch (texture_kind) {
case ast::intrinsic::test::TextureKind::kRegular:
return b->Var(
return b->Global(
"texture", ast::StorageClass::kUniformConstant,
b->create<type::SampledTexture>(texture_dimension, datatype), nullptr,
decos);
case ast::intrinsic::test::TextureKind::kDepth:
return b->Var("texture", ast::StorageClass::kUniformConstant,
b->create<type::DepthTexture>(texture_dimension), nullptr,
decos);
return b->Global("texture", ast::StorageClass::kUniformConstant,
b->create<type::DepthTexture>(texture_dimension),
nullptr, decos);
case ast::intrinsic::test::TextureKind::kMultisampled:
return b->Var(
return b->Global(
"texture", ast::StorageClass::kUniformConstant,
b->create<type::MultisampledTexture>(texture_dimension, datatype),
nullptr, decos);
@ -182,8 +182,8 @@ ast::Variable* TextureOverloadCase::buildTextureVariable(
st->set_type(datatype);
auto* ac = b->create<type::AccessControl>(access_control, st);
return b->Var("texture", ast::StorageClass::kUniformConstant, ac, nullptr,
decos);
return b->Global("texture", ast::StorageClass::kUniformConstant, ac,
nullptr, decos);
}
}
@ -197,8 +197,8 @@ ast::Variable* TextureOverloadCase::buildSamplerVariable(
b->create<ast::GroupDecoration>(0),
b->create<ast::BindingDecoration>(1),
};
return b->Var("sampler", ast::StorageClass::kUniformConstant,
b->create<type::Sampler>(sampler_kind), nullptr, decos);
return b->Global("sampler", ast::StorageClass::kUniformConstant,
b->create<type::Sampler>(sampler_kind), nullptr, decos);
}
std::vector<TextureOverloadCase> TextureOverloadCase::ValidCases() {

View File

@ -242,10 +242,12 @@ struct TextureOverloadCase {
/// @returns the vector component type of the texture function return value
type::Type* resultVectorComponentType(ProgramBuilder* builder) const;
/// @param builder the AST builder used for the test
/// @returns a Variable holding the test texture
/// @returns a variable holding the test texture, automatically registered as
/// a global variable.
ast::Variable* buildTextureVariable(ProgramBuilder* builder) const;
/// @param builder the AST builder used for the test
/// @returns a Variable holding the test sampler
/// @returns a Variable holding the test sampler, automatically registered as
/// a global variable.
ast::Variable* buildSamplerVariable(ProgramBuilder* builder) const;
/// The enumerator for this overload

View File

@ -62,8 +62,7 @@ TEST_F(ModuleTest, IsValid_Empty) {
}
TEST_F(ModuleTest, IsValid_GlobalVariable) {
auto* var = Var("var", StorageClass::kInput, ty.f32());
AST().AddGlobalVariable(var);
Global("var", StorageClass::kInput, ty.f32());
Program program(std::move(*this));
EXPECT_TRUE(program.AST().IsValid());
}
@ -75,8 +74,7 @@ TEST_F(ModuleTest, IsValid_Null_GlobalVariable) {
}
TEST_F(ModuleTest, IsValid_Invalid_GlobalVariable) {
auto* var = Var("var", StorageClass::kInput, nullptr);
AST().AddGlobalVariable(var);
Global("var", StorageClass::kInput, nullptr);
Program program(std::move(*this));
EXPECT_FALSE(program.AST().IsValid());
}

View File

@ -107,14 +107,12 @@ class InspectorHelper : public ProgramBuilder {
std::string in, out;
std::tie(in, out) = inout;
AST().AddGlobalVariable(
Var(in, ast::StorageClass::kInput, ty.u32(), nullptr,
ast::VariableDecorationList{
create<ast::LocationDecoration>(location++)}));
AST().AddGlobalVariable(
Var(out, ast::StorageClass::kOutput, ty.u32(), nullptr,
ast::VariableDecorationList{
create<ast::LocationDecoration>(location++)}));
Global(in, ast::StorageClass::kInput, ty.u32(), nullptr,
ast::VariableDecorationList{
create<ast::LocationDecoration>(location++)});
Global(out, ast::StorageClass::kOutput, ty.u32(), nullptr,
ast::VariableDecorationList{
create<ast::LocationDecoration>(location++)});
}
}
@ -175,11 +173,10 @@ class InspectorHelper : public ProgramBuilder {
constructor =
create<ast::ScalarConstructorExpression>(MakeLiteral(type, val));
}
auto* var = Const(name, ast::StorageClass::kNone, type, constructor,
ast::VariableDecorationList{
create<ast::ConstantIdDecoration>(id),
});
AST().AddGlobalVariable(var);
GlobalConst(name, ast::StorageClass::kNone, type, constructor,
ast::VariableDecorationList{
create<ast::ConstantIdDecoration>(id),
});
}
/// @param type AST type of the literal, must resolve to BoolLiteral
@ -320,13 +317,11 @@ class InspectorHelper : public ProgramBuilder {
ast::StorageClass storage_class,
uint32_t group,
uint32_t binding) {
auto* var = Var(name, storage_class, type, nullptr,
ast::VariableDecorationList{
create<ast::BindingDecoration>(binding),
create<ast::GroupDecoration>(group),
});
AST().AddGlobalVariable(var);
GlobalConst(name, storage_class, type, nullptr,
ast::VariableDecorationList{
create<ast::BindingDecoration>(binding),
create<ast::GroupDecoration>(group),
});
}
/// Adds an uniform buffer variable to the program
@ -460,16 +455,14 @@ class InspectorHelper : public ProgramBuilder {
}
void AddGlobalVariable(const std::string& name, type::Type* type) {
AST().AddGlobalVariable(
Var(name, ast::StorageClass::kUniformConstant, type));
Global(name, ast::StorageClass::kUniformConstant, type);
}
/// Adds a depth texture variable to the program
/// @param name the name of the variable
/// @param type the type to use
void AddDepthTexture(const std::string& name, type::Type* type) {
AST().AddGlobalVariable(
Var(name, ast::StorageClass::kUniformConstant, type));
Global(name, ast::StorageClass::kUniformConstant, type);
}
/// Generates a function that references a specific sampler variable
@ -1104,13 +1097,11 @@ TEST_F(InspectorGetEntryPointTest, MultipleEntryPointsSharedInOutVariables) {
}
TEST_F(InspectorGetEntryPointTest, BuiltInsNotStageVariables) {
AST().AddGlobalVariable(
Var("in_var", ast::StorageClass::kInput, ty.u32(), nullptr,
ast::VariableDecorationList{
create<ast::BuiltinDecoration>(ast::Builtin::kPosition)}));
AST().AddGlobalVariable(
Var("out_var", ast::StorageClass::kOutput, ty.u32(), nullptr,
ast::VariableDecorationList{create<ast::LocationDecoration>(0)}));
Global("in_var", ast::StorageClass::kInput, ty.u32(), nullptr,
ast::VariableDecorationList{
create<ast::BuiltinDecoration>(ast::Builtin::kPosition)});
Global("out_var", ast::StorageClass::kOutput, ty.u32(), nullptr,
ast::VariableDecorationList{create<ast::LocationDecoration>(0)});
MakeInOutVariableBodyFunction("func", {{"in_var", "out_var"}}, {});

View File

@ -18,6 +18,8 @@
#include <sstream>
#include "src/ast/assignment_statement.h"
#include "src/ast/variable_decl_statement.h"
#include "src/clone_context.h"
#include "src/demangler.h"
#include "src/semantic/expression.h"
@ -101,10 +103,8 @@ ast::Variable* ProgramBuilder::Var(const std::string& name,
type::Type* type,
ast::Expression* constructor,
ast::VariableDecorationList decorations) {
auto* var = create<ast::Variable>(Symbols().Register(name), storage, type,
false, constructor, decorations);
OnVariableBuilt(var);
return var;
return create<ast::Variable>(Symbols().Register(name), storage, type, false,
constructor, decorations);
}
ast::Variable* ProgramBuilder::Var(const Source& source,
@ -113,10 +113,8 @@ ast::Variable* ProgramBuilder::Var(const Source& source,
type::Type* type,
ast::Expression* constructor,
ast::VariableDecorationList decorations) {
auto* var = create<ast::Variable>(source, Symbols().Register(name), storage,
type, false, constructor, decorations);
OnVariableBuilt(var);
return var;
return create<ast::Variable>(source, Symbols().Register(name), storage, type,
false, constructor, decorations);
}
ast::Variable* ProgramBuilder::Const(const std::string& name,
@ -130,10 +128,8 @@ ast::Variable* ProgramBuilder::Const(const std::string& name,
type::Type* type,
ast::Expression* constructor,
ast::VariableDecorationList decorations) {
auto* var = create<ast::Variable>(Symbols().Register(name), storage, type,
true, constructor, decorations);
OnVariableBuilt(var);
return var;
return create<ast::Variable>(Symbols().Register(name), storage, type, true,
constructor, decorations);
}
ast::Variable* ProgramBuilder::Const(const Source& source,
@ -142,10 +138,26 @@ ast::Variable* ProgramBuilder::Const(const Source& source,
type::Type* type,
ast::Expression* constructor,
ast::VariableDecorationList decorations) {
auto* var = create<ast::Variable>(source, Symbols().Register(name), storage,
type, true, constructor, decorations);
OnVariableBuilt(var);
return var;
return create<ast::Variable>(source, Symbols().Register(name), storage, type,
true, constructor, decorations);
}
ast::VariableDeclStatement* ProgramBuilder::WrapInStatement(ast::Variable* v) {
return create<ast::VariableDeclStatement>(v);
}
ast::Statement* ProgramBuilder::WrapInStatement(ast::Expression* expr) {
// TODO(ben-clayton): This is valid enough for the TypeDeterminer, but the LHS
// may not be assignable, and so may not validate.
return create<ast::AssignmentStatement>(expr, expr);
}
ast::Statement* ProgramBuilder::WrapInStatement(ast::Statement* stmt) {
return stmt;
}
void ProgramBuilder::WrapInFunction(ast::StatementList stmts) {
Func("test_function", {}, ty.void_(), stmts, {});
}
} // namespace tint

View File

@ -55,6 +55,11 @@
namespace tint {
// Forward declarations
namespace ast {
class VariableDeclStatement;
} // namespace ast
class CloneContext;
/// ProgramBuilder is a mutable builder for a Program.
@ -789,6 +794,28 @@ class ProgramBuilder {
ast::Expression* constructor,
ast::VariableDecorationList decorations);
/// @param args the arguments to pass to Var()
/// @returns a `ast::Variable` constructed by calling Var() with the arguments
/// of `args`, which is automatically registered as a global variable with the
/// ast::Module.
template <typename... ARGS>
ast::Variable* Global(ARGS&&... args) {
auto* var = Var(std::forward<ARGS>(args)...);
AST().AddGlobalVariable(var);
return var;
}
/// @param args the arguments to pass to Const()
/// @returns a const `ast::Variable` constructed by calling Var() with the
/// arguments of `args`, which is automatically registered as a global
/// variable with the ast::Module.
template <typename... ARGS>
ast::Variable* GlobalConst(ARGS&&... args) {
auto* var = Const(std::forward<ARGS>(args)...);
AST().AddGlobalVariable(var);
return var;
}
/// @param func the function name
/// @param args the function call arguments
/// @returns a `ast::CallExpression` to the function `func`, with the
@ -950,6 +977,35 @@ class ProgramBuilder {
/// expression has no resolved type.
type::Type* TypeOf(ast::Expression* expr) const;
/// Wraps the ast::Expression in a statement. This is used by tests that
/// construct a partial AST and require the TypeDeterminer to reach these
/// nodes.
/// @param expr the ast::Expression to be wrapped by an ast::Statement
/// @return the ast::Statement that wraps the ast::Expression
ast::Statement* WrapInStatement(ast::Expression* expr);
/// Wraps the ast::Variable in a ast::VariableDeclStatement. This is used by
/// tests that construct a partial AST and require the TypeDeterminer to reach
/// these nodes.
/// @param v the ast::Variable to be wrapped by an ast::VariableDeclStatement
/// @return the ast::VariableDeclStatement that wraps the ast::Variable
ast::VariableDeclStatement* WrapInStatement(ast::Variable* v);
/// Returns the statement argument. Used as a passthrough-overload by
/// WrapInFunction().
/// @param stmt the ast::Statement
/// @return `stmt`
ast::Statement* WrapInStatement(ast::Statement* stmt);
/// Wraps the list of arguments in a simple function so that each is reachable
/// by the TypeDeterminer.
/// @param args a mix of ast::Expression, ast::Statement, ast::Variables.
template <typename... ARGS>
void WrapInFunction(ARGS&&... args) {
ast::StatementList stmts{WrapInStatement(std::forward<ARGS>(args))...};
WrapInFunction(stmts);
}
/// @param stmts a list of ast::Statement that will be wrapped by a function,
/// so that each statement is reachable by the TypeDeterminer.
void WrapInFunction(ast::StatementList stmts);
/// The builder types
TypesBuilder ty;
@ -957,9 +1013,6 @@ class ProgramBuilder {
/// Asserts that the builder has not been moved.
void AssertNotMoved() const;
/// Called whenever a new variable is built with `Var()`.
virtual void OnVariableBuilt(ast::Variable*) {}
private:
type::Manager types_;
ASTNodeAllocator ast_nodes_;

View File

@ -49,8 +49,7 @@ TEST_F(ProgramTest, IsValid_Empty) {
}
TEST_F(ProgramTest, IsValid_GlobalVariable) {
auto* var = Var("var", ast::StorageClass::kInput, ty.f32());
AST().AddGlobalVariable(var);
Global("var", ast::StorageClass::kInput, ty.f32());
Program program(std::move(*this));
EXPECT_TRUE(program.IsValid());
@ -64,8 +63,7 @@ TEST_F(ProgramTest, IsValid_Null_GlobalVariable) {
}
TEST_F(ProgramTest, IsValid_Invalid_GlobalVariable) {
auto* var = Var("var", ast::StorageClass::kInput, nullptr);
AST().AddGlobalVariable(var);
Global("var", ast::StorageClass::kInput, nullptr);
Program program(std::move(*this));
EXPECT_FALSE(program.IsValid());

View File

@ -65,50 +65,11 @@ class TypeDeterminer {
/// @returns true if the type determiner was successful
bool Determine();
/// Determines type information for functions
/// @param funcs the functions to check
/// @returns true if the determination was successful
bool DetermineFunctions(const ast::FunctionList& funcs);
/// Determines type information for a function
/// @param func the function to check
/// @returns true if the determination was successful
bool DetermineFunction(ast::Function* func);
/// Determines type information for a set of statements
/// @param stmts the statements to check
/// @returns true if the determination was successful
bool DetermineStatements(const ast::BlockStatement* stmts);
/// Determines type information for a statement
/// @param stmt the statement to check
/// @returns true if the determination was successful
bool DetermineResultType(ast::Statement* stmt);
/// Determines type information for an expression list
/// @param list the expression list to check
/// @returns true if the determination was successful
bool DetermineResultType(const ast::ExpressionList& list);
/// Determines type information for an expression
/// @param expr the expression to check
/// @returns true if the determination was successful
bool DetermineResultType(ast::Expression* expr);
/// Determines the storage class for variables. This assumes that it is only
/// called for things in function scope, not module scope.
/// @param stmt the statement to check
/// @returns false on error
bool DetermineVariableStorageClass(ast::Statement* stmt);
/// Determines the result type based off a storage texture format
/// @param tex the storage texture
/// @returns false on error
bool DetermineStorageTextureSubtype(type::StorageTexture* tex);
/// Creates the semantic::Function nodes and adds them to the semantic::Info
/// of the ProgramBuilder.
void CreateSemanticFunctions() const;
/// Testing method to set a given variable into the type stack
/// @param var the variable to set
void RegisterVariableForTesting(ast::Variable* var) {
variable_stack_.set(var->symbol(), var);
}
/// Retrieves information for the requested import.
/// @param src the source of the import
/// @param path the import path
@ -159,6 +120,40 @@ class TypeDeterminer {
UniqueVector<Symbol> ancestor_entry_points;
};
/// Determines type information for functions
/// @param funcs the functions to check
/// @returns true if the determination was successful
bool DetermineFunctions(const ast::FunctionList& funcs);
/// Determines type information for a function
/// @param func the function to check
/// @returns true if the determination was successful
bool DetermineFunction(ast::Function* func);
/// Determines type information for a set of statements
/// @param stmts the statements to check
/// @returns true if the determination was successful
bool DetermineStatements(const ast::BlockStatement* stmts);
/// Determines type information for a statement
/// @param stmt the statement to check
/// @returns true if the determination was successful
bool DetermineResultType(ast::Statement* stmt);
/// Determines type information for an expression list
/// @param list the expression list to check
/// @returns true if the determination was successful
bool DetermineResultType(const ast::ExpressionList& list);
/// Determines type information for an expression
/// @param expr the expression to check
/// @returns true if the determination was successful
bool DetermineResultType(ast::Expression* expr);
/// Determines the storage class for variables. This assumes that it is only
/// called for things in function scope, not module scope.
/// @param stmt the statement to check
/// @returns false on error
bool DetermineVariableStorageClass(ast::Statement* stmt);
/// Determines the result type based off a storage texture format
/// @param tex the storage texture
/// @returns false on error
bool DetermineStorageTextureSubtype(type::StorageTexture* tex);
void set_error(const Source& src, const std::string& msg);
void set_referenced_from_function_if_needed(ast::Variable* var, bool local);
void set_entry_points(const Symbol& fn_sym, Symbol ep_sym);

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -56,7 +56,7 @@ TEST_F(ValidateControlBlockTest, SwitchSelectorExpressionNoneIntegerType_Fail) {
body),
});
EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error();
WrapInFunction(block);
ValidatorImpl& v = Build();
@ -87,7 +87,7 @@ TEST_F(ValidateControlBlockTest, SwitchWithoutDefault_Fail) {
body),
});
EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error();
WrapInFunction(block);
ValidatorImpl& v = Build();
@ -129,7 +129,7 @@ TEST_F(ValidateControlBlockTest, SwitchWithTwoDefault_Fail) {
switch_body),
});
EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error();
WrapInFunction(block);
ValidatorImpl& v = Build();
@ -164,7 +164,7 @@ TEST_F(ValidateControlBlockTest,
create<ast::VariableDeclStatement>(var),
create<ast::SwitchStatement>(Expr("a"), switch_body),
});
EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error();
WrapInFunction(block);
ValidatorImpl& v = Build();
@ -199,7 +199,7 @@ TEST_F(ValidateControlBlockTest,
create<ast::VariableDeclStatement>(var),
create<ast::SwitchStatement>(Expr("a"), switch_body),
});
EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error();
WrapInFunction(block);
ValidatorImpl& v = Build();
@ -240,7 +240,7 @@ TEST_F(ValidateControlBlockTest, NonUniqueCaseSelectorValueUint_Fail) {
create<ast::VariableDeclStatement>(var),
create<ast::SwitchStatement>(Expr("a"), switch_body),
});
EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error();
WrapInFunction(block);
ValidatorImpl& v = Build();
@ -283,7 +283,7 @@ TEST_F(ValidateControlBlockTest, NonUniqueCaseSelectorValueSint_Fail) {
create<ast::VariableDeclStatement>(var),
create<ast::SwitchStatement>(Expr("a"), switch_body),
});
EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error();
WrapInFunction(block);
ValidatorImpl& v = Build();
@ -314,7 +314,7 @@ TEST_F(ValidateControlBlockTest, LastClauseLastStatementIsFallthrough_Fail) {
create<ast::VariableDeclStatement>(var),
create<ast::SwitchStatement>(Expr("a"), body),
});
EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error();
WrapInFunction(block);
ValidatorImpl& v = Build();
@ -347,7 +347,7 @@ TEST_F(ValidateControlBlockTest, SwitchCase_Pass) {
create<ast::VariableDeclStatement>(var),
create<ast::SwitchStatement>(Expr("a"), body),
});
EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error();
WrapInFunction(block);
ValidatorImpl& v = Build();
@ -377,7 +377,7 @@ TEST_F(ValidateControlBlockTest, SwitchCaseAlias_Pass) {
});
AST().AddConstructedType(my_int);
EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error();
WrapInFunction(block);
ValidatorImpl& v = Build();

View File

@ -50,8 +50,6 @@ TEST_F(ValidateFunctionTest, VoidFunctionEndWithoutReturnStatement_Pass) {
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
});
EXPECT_TRUE(td()->Determine()) << td()->error();
ValidatorImpl& v = Build();
EXPECT_TRUE(v.Validate());
@ -68,8 +66,6 @@ TEST_F(ValidateFunctionTest,
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
});
EXPECT_TRUE(td()->Determine()) << td()->error();
ValidatorImpl& v = Build();
EXPECT_TRUE(v.Validate());
@ -87,8 +83,6 @@ TEST_F(ValidateFunctionTest, FunctionEndWithoutReturnStatement_Fail) {
},
ast::FunctionDecorationList{});
EXPECT_TRUE(td()->Determine()) << td()->error();
ValidatorImpl& v = Build();
EXPECT_FALSE(v.Validate());
@ -102,8 +96,6 @@ TEST_F(ValidateFunctionTest, FunctionEndWithoutReturnStatementEmptyBody_Fail) {
Func(Source{Source::Location{12, 34}}, "func", ast::VariableList{}, ty.i32(),
ast::StatementList{}, ast::FunctionDecorationList{});
EXPECT_TRUE(td()->Determine()) << td()->error();
ValidatorImpl& v = Build();
EXPECT_FALSE(v.Validate());
@ -123,8 +115,6 @@ TEST_F(ValidateFunctionTest, FunctionTypeMustMatchReturnStatementType_Pass) {
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
});
EXPECT_TRUE(td()->DetermineFunctions(AST().Functions())) << td()->error();
ValidatorImpl& v = Build();
const Program* program = v.program();
@ -140,8 +130,6 @@ TEST_F(ValidateFunctionTest, FunctionTypeMustMatchReturnStatementType_fail) {
},
ast::FunctionDecorationList{});
EXPECT_TRUE(td()->Determine()) << td()->error();
ValidatorImpl& v = Build();
EXPECT_FALSE(v.Validate());
@ -160,8 +148,6 @@ TEST_F(ValidateFunctionTest, FunctionTypeMustMatchReturnStatementTypeF32_fail) {
},
ast::FunctionDecorationList{});
EXPECT_TRUE(td()->Determine()) << td()->error();
ValidatorImpl& v = Build();
EXPECT_FALSE(v.Validate());
@ -186,8 +172,6 @@ TEST_F(ValidateFunctionTest, FunctionNamesMustBeUnique_fail) {
},
ast::FunctionDecorationList{});
EXPECT_TRUE(td()->Determine()) << td()->error();
ValidatorImpl& v = Build();
EXPECT_FALSE(v.Validate());
@ -207,8 +191,6 @@ TEST_F(ValidateFunctionTest, RecursionIsNotAllowed_Fail) {
},
ast::FunctionDecorationList{});
EXPECT_TRUE(td()->Determine()) << td()->error();
ValidatorImpl& v = Build();
EXPECT_FALSE(v.Validate()) << v.error();
@ -230,8 +212,6 @@ TEST_F(ValidateFunctionTest, RecursionIsNotAllowedExpr_Fail) {
},
ast::FunctionDecorationList{});
EXPECT_TRUE(td()->Determine()) << td()->error();
ValidatorImpl& v = Build();
EXPECT_FALSE(v.Validate()) << v.error();
@ -251,8 +231,6 @@ TEST_F(ValidateFunctionTest, Function_WithPipelineStage_NotVoid_Fail) {
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
});
EXPECT_TRUE(td()->Determine()) << td()->error();
ValidatorImpl& v = Build();
EXPECT_FALSE(v.Validate());
@ -275,8 +253,6 @@ TEST_F(ValidateFunctionTest, Function_WithPipelineStage_WithParams_Fail) {
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
});
EXPECT_TRUE(td()->Determine()) << td()->error();
ValidatorImpl& v = Build();
EXPECT_FALSE(v.Validate());
@ -299,8 +275,6 @@ TEST_F(ValidateFunctionTest, PipelineStage_MustBeUnique_Fail) {
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
});
EXPECT_TRUE(td()->Determine()) << td()->error();
ValidatorImpl& v = Build();
EXPECT_FALSE(v.Validate());
@ -321,8 +295,6 @@ TEST_F(ValidateFunctionTest, OnePipelineStageFunctionMustBePresent_Pass) {
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
});
EXPECT_TRUE(td()->Determine()) << td()->error();
ValidatorImpl& v = Build();
EXPECT_TRUE(v.Validate()) << v.error();
@ -336,8 +308,6 @@ TEST_F(ValidateFunctionTest, OnePipelineStageFunctionMustBePresent_Fail) {
},
ast::FunctionDecorationList{});
EXPECT_TRUE(td()->Determine()) << td()->error();
ValidatorImpl& v = Build();
EXPECT_FALSE(v.Validate());

View File

@ -66,14 +66,14 @@ TEST_F(ValidatorTest, AssignToScalar_Fail) {
auto* var = Var("my_var", ast::StorageClass::kNone, ty.i32(), Expr(2),
ast::VariableDecorationList{});
RegisterVariable(var);
auto* lhs = Expr(1);
auto* rhs = Expr("my_var");
SetSource(Source{Source::Location{12, 34}});
auto* assign = create<ast::AssignmentStatement>(lhs, rhs);
RegisterVariable(var);
EXPECT_TRUE(td()->DetermineResultType(assign));
WrapInFunction(assign);
ValidatorImpl& v = Build();
@ -93,8 +93,9 @@ TEST_F(ValidatorTest, UsingUndefinedVariable_Fail) {
auto* lhs = Expr("b");
auto* rhs = Expr(2);
auto* assign = create<ast::AssignmentStatement>(lhs, rhs);
WrapInFunction(assign);
EXPECT_FALSE(td()->DetermineResultType(assign));
EXPECT_FALSE(td()->Determine());
EXPECT_EQ(td()->error(),
"12:34: v-0006: identifier must be declared before use: b");
}
@ -111,8 +112,9 @@ TEST_F(ValidatorTest, UsingUndefinedVariableInBlockStatement_Fail) {
auto* body = create<ast::BlockStatement>(ast::StatementList{
create<ast::AssignmentStatement>(lhs, rhs),
});
WrapInFunction(body);
EXPECT_FALSE(td()->DetermineStatements(body));
EXPECT_FALSE(td()->Determine());
EXPECT_EQ(td()->error(),
"12:34: v-0006: identifier must be declared before use: b");
}
@ -122,19 +124,20 @@ TEST_F(ValidatorTest, AssignCompatibleTypes_Pass) {
// a = 2
auto* var = Var("a", ast::StorageClass::kNone, ty.i32(), Expr(2),
ast::VariableDecorationList{});
RegisterVariable(var);
auto* lhs = Expr("a");
auto* rhs = Expr(2);
auto* assign = create<ast::AssignmentStatement>(
Source{Source::Location{12, 34}}, lhs, rhs);
RegisterVariable(var);
EXPECT_TRUE(td()->DetermineResultType(assign)) << td()->error();
ASSERT_NE(TypeOf(lhs), nullptr);
ASSERT_NE(TypeOf(rhs), nullptr);
WrapInFunction(assign);
ValidatorImpl& v = Build();
ASSERT_NE(TypeOf(lhs), nullptr);
ASSERT_NE(TypeOf(rhs), nullptr);
EXPECT_TRUE(v.ValidateAssign(assign)) << v.error();
}
@ -145,19 +148,20 @@ TEST_F(ValidatorTest, AssignCompatibleTypesThroughAlias_Pass) {
auto* myint = ty.alias("myint", ty.i32());
auto* var = Var("a", ast::StorageClass::kNone, myint, Expr(2),
ast::VariableDecorationList{});
RegisterVariable(var);
auto* lhs = Expr("a");
auto* rhs = Expr(2);
auto* assign = create<ast::AssignmentStatement>(
Source{Source::Location{12, 34}}, lhs, rhs);
RegisterVariable(var);
EXPECT_TRUE(td()->DetermineResultType(assign)) << td()->error();
ASSERT_NE(TypeOf(lhs), nullptr);
ASSERT_NE(TypeOf(rhs), nullptr);
WrapInFunction(assign);
ValidatorImpl& v = Build();
ASSERT_NE(TypeOf(lhs), nullptr);
ASSERT_NE(TypeOf(rhs), nullptr);
EXPECT_TRUE(v.ValidateAssign(assign)) << v.error();
}
@ -169,20 +173,21 @@ TEST_F(ValidatorTest, AssignCompatibleTypesInferRHSLoad_Pass) {
ast::VariableDecorationList{});
auto* var_b = Var("b", ast::StorageClass::kNone, ty.i32(), Expr(3),
ast::VariableDecorationList{});
RegisterVariable(var_a);
RegisterVariable(var_b);
auto* lhs = Expr("a");
auto* rhs = Expr("b");
auto* assign = create<ast::AssignmentStatement>(
Source{Source::Location{12, 34}}, lhs, rhs);
RegisterVariable(var_a);
RegisterVariable(var_b);
EXPECT_TRUE(td()->DetermineResultType(assign)) << td()->error();
ASSERT_NE(TypeOf(lhs), nullptr);
ASSERT_NE(TypeOf(rhs), nullptr);
WrapInFunction(assign);
ValidatorImpl& v = Build();
ASSERT_NE(TypeOf(lhs), nullptr);
ASSERT_NE(TypeOf(rhs), nullptr);
EXPECT_TRUE(v.ValidateAssign(assign)) << v.error();
}
@ -194,20 +199,21 @@ TEST_F(ValidatorTest, AssignThroughPointer_Pass) {
auto* var_a = Var("a", func, ty.i32(), Expr(2), {});
auto* var_b = Const("b", ast::StorageClass::kNone, ty.pointer<int>(func),
Expr("a"), {});
RegisterVariable(var_a);
RegisterVariable(var_b);
auto* lhs = Expr("b");
auto* rhs = Expr(2);
auto* assign = create<ast::AssignmentStatement>(
Source{Source::Location{12, 34}}, lhs, rhs);
RegisterVariable(var_a);
RegisterVariable(var_b);
EXPECT_TRUE(td()->DetermineResultType(assign)) << td()->error();
ASSERT_NE(TypeOf(lhs), nullptr);
ASSERT_NE(TypeOf(rhs), nullptr);
WrapInFunction(assign);
ValidatorImpl& v = Build();
ASSERT_NE(TypeOf(lhs), nullptr);
ASSERT_NE(TypeOf(rhs), nullptr);
EXPECT_TRUE(v.ValidateAssign(assign)) << v.error();
}
@ -219,19 +225,20 @@ TEST_F(ValidatorTest, AssignIncompatibleTypes_Fail) {
auto* var = Var("a", ast::StorageClass::kNone, ty.i32(), Expr(2),
ast::VariableDecorationList{});
RegisterVariable(var);
auto* lhs = Expr("a");
auto* rhs = Expr(2.3f);
auto* assign = create<ast::AssignmentStatement>(
Source{Source::Location{12, 34}}, lhs, rhs);
RegisterVariable(var);
EXPECT_TRUE(td()->DetermineResultType(assign)) << td()->error();
ASSERT_NE(TypeOf(lhs), nullptr);
ASSERT_NE(TypeOf(rhs), nullptr);
WrapInFunction(assign);
ValidatorImpl& v = Build();
ASSERT_NE(TypeOf(lhs), nullptr);
ASSERT_NE(TypeOf(rhs), nullptr);
EXPECT_FALSE(v.ValidateAssign(assign));
ASSERT_TRUE(v.has_error());
// TODO(sarahM0): figure out what should be the error number.
@ -248,20 +255,21 @@ TEST_F(ValidatorTest, AssignThroughPointerWrongeStoreType_Fail) {
auto* var_a = Var("a", priv, ty.f32(), Expr(2), {});
auto* var_b = Const("b", ast::StorageClass::kNone, ty.pointer<float>(priv),
Expr("a"), {});
RegisterVariable(var_a);
RegisterVariable(var_b);
auto* lhs = Expr("a");
auto* rhs = Expr(2);
auto* assign = create<ast::AssignmentStatement>(
Source{Source::Location{12, 34}}, lhs, rhs);
RegisterVariable(var_a);
RegisterVariable(var_b);
EXPECT_TRUE(td()->DetermineResultType(assign)) << td()->error();
ASSERT_NE(TypeOf(lhs), nullptr);
ASSERT_NE(TypeOf(rhs), nullptr);
WrapInFunction(assign);
ValidatorImpl& v = Build();
ASSERT_NE(TypeOf(lhs), nullptr);
ASSERT_NE(TypeOf(rhs), nullptr);
EXPECT_FALSE(v.ValidateAssign(assign));
EXPECT_EQ(v.error(),
"12:34 v-000x: invalid assignment: can't assign value of type "
@ -284,13 +292,13 @@ TEST_F(ValidatorTest, AssignCompatibleTypesInBlockStatement_Pass) {
create<ast::AssignmentStatement>(Source{Source::Location{12, 34}}, lhs,
rhs),
});
EXPECT_TRUE(td()->DetermineStatements(body)) << td()->error();
ASSERT_NE(TypeOf(lhs), nullptr);
ASSERT_NE(TypeOf(rhs), nullptr);
WrapInFunction(body);
ValidatorImpl& v = Build();
ASSERT_NE(TypeOf(lhs), nullptr);
ASSERT_NE(TypeOf(rhs), nullptr);
EXPECT_TRUE(v.ValidateStatements(body)) << v.error();
}
@ -311,13 +319,13 @@ TEST_F(ValidatorTest, AssignIncompatibleTypesInBlockStatement_Fail) {
create<ast::AssignmentStatement>(Source{Source::Location{12, 34}}, lhs,
rhs),
});
EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error();
ASSERT_NE(TypeOf(lhs), nullptr);
ASSERT_NE(TypeOf(rhs), nullptr);
WrapInFunction(block);
ValidatorImpl& v = Build();
ASSERT_NE(TypeOf(lhs), nullptr);
ASSERT_NE(TypeOf(rhs), nullptr);
EXPECT_FALSE(v.ValidateStatements(block));
ASSERT_TRUE(v.has_error());
// TODO(sarahM0): figure out what should be the error number.
@ -350,12 +358,13 @@ TEST_F(ValidatorTest, AssignIncompatibleTypesInNestedBlockStatement_Fail) {
inner_block,
});
EXPECT_TRUE(td()->DetermineStatements(outer_block)) << td()->error();
ASSERT_NE(TypeOf(lhs), nullptr);
ASSERT_NE(TypeOf(rhs), nullptr);
WrapInFunction(outer_block);
ValidatorImpl& v = Build();
ASSERT_NE(TypeOf(lhs), nullptr);
ASSERT_NE(TypeOf(rhs), nullptr);
EXPECT_FALSE(v.ValidateStatements(outer_block));
ASSERT_TRUE(v.has_error());
// TODO(sarahM0): figure out what should be the error number.
@ -366,9 +375,9 @@ TEST_F(ValidatorTest, AssignIncompatibleTypesInNestedBlockStatement_Fail) {
TEST_F(ValidatorTest, GlobalVariableWithStorageClass_Pass) {
// var<in> gloabl_var: f32;
AST().AddGlobalVariable(Var(Source{Source::Location{12, 34}}, "global_var",
ast::StorageClass::kInput, ty.f32(), nullptr,
ast::VariableDecorationList{}));
Global(Source{Source::Location{12, 34}}, "global_var",
ast::StorageClass::kInput, ty.f32(), nullptr,
ast::VariableDecorationList{});
ValidatorImpl& v = Build();
const Program* program = v.program();
@ -379,10 +388,9 @@ TEST_F(ValidatorTest, GlobalVariableWithStorageClass_Pass) {
TEST_F(ValidatorTest, GlobalVariableNoStorageClass_Fail) {
// var gloabl_var: f32;
AST().AddGlobalVariable(Var(Source{Source::Location{12, 34}}, "global_var",
ast::StorageClass::kNone, ty.f32(), nullptr,
ast::VariableDecorationList{}));
EXPECT_TRUE(td()->Determine()) << td()->error();
Global(Source{Source::Location{12, 34}}, "global_var",
ast::StorageClass::kNone, ty.f32(), nullptr,
ast::VariableDecorationList{});
ValidatorImpl& v = Build();
@ -393,10 +401,9 @@ TEST_F(ValidatorTest, GlobalVariableNoStorageClass_Fail) {
TEST_F(ValidatorTest, GlobalConstantWithStorageClass_Fail) {
// const<in> gloabl_var: f32;
AST().AddGlobalVariable(Const(Source{Source::Location{12, 34}}, "global_var",
ast::StorageClass::kInput, ty.f32(), nullptr,
ast::VariableDecorationList{}));
EXPECT_TRUE(td()->Determine()) << td()->error();
GlobalConst(Source{Source::Location{12, 34}}, "global_var",
ast::StorageClass::kInput, ty.f32(), nullptr,
ast::VariableDecorationList{});
ValidatorImpl& v = Build();
@ -408,10 +415,9 @@ TEST_F(ValidatorTest, GlobalConstantWithStorageClass_Fail) {
TEST_F(ValidatorTest, GlobalConstNoStorageClass_Pass) {
// const gloabl_var: f32;
AST().AddGlobalVariable(Const(Source{Source::Location{12, 34}}, "global_var",
ast::StorageClass::kNone, ty.f32(), nullptr,
ast::VariableDecorationList{}));
EXPECT_TRUE(td()->Determine()) << td()->error();
GlobalConst(Source{Source::Location{12, 34}}, "global_var",
ast::StorageClass::kNone, ty.f32(), nullptr,
ast::VariableDecorationList{});
ValidatorImpl& v = Build();
@ -423,9 +429,8 @@ TEST_F(ValidatorTest, UsingUndefinedVariableGlobalVariable_Fail) {
// fn my_func() -> f32 {
// not_global_var = 3.14f;
// }
AST().AddGlobalVariable(Var("global_var", ast::StorageClass::kPrivate,
ty.f32(), Expr(2.1f),
ast::VariableDecorationList{}));
Global("global_var", ast::StorageClass::kPrivate, ty.f32(), Expr(2.1f),
ast::VariableDecorationList{});
SetSource(Source{Source::Location{12, 34}});
auto* lhs = Expr("not_global_var");
@ -451,9 +456,8 @@ TEST_F(ValidatorTest, UsingUndefinedVariableGlobalVariable_Pass) {
// return;
// }
AST().AddGlobalVariable(Var("global_var", ast::StorageClass::kPrivate,
ty.f32(), Expr(2.1f),
ast::VariableDecorationList{}));
Global("global_var", ast::StorageClass::kPrivate, ty.f32(), Expr(2.1f),
ast::VariableDecorationList{});
Func("my_func", ast::VariableList{}, ty.void_(),
ast::StatementList{
@ -465,8 +469,6 @@ TEST_F(ValidatorTest, UsingUndefinedVariableGlobalVariable_Pass) {
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
});
EXPECT_TRUE(td()->Determine()) << td()->error();
ValidatorImpl& v = Build();
EXPECT_TRUE(v.Validate()) << v.error();
@ -495,12 +497,13 @@ TEST_F(ValidatorTest, UsingUndefinedVariableInnerScope_Fail) {
rhs),
});
EXPECT_TRUE(td()->DetermineStatements(outer_body)) << td()->error();
ASSERT_NE(TypeOf(lhs), nullptr);
ASSERT_NE(TypeOf(rhs), nullptr);
WrapInFunction(outer_body);
ValidatorImpl& v = Build();
ASSERT_NE(TypeOf(lhs), nullptr);
ASSERT_NE(TypeOf(rhs), nullptr);
EXPECT_FALSE(v.ValidateStatements(outer_body));
EXPECT_EQ(v.error(), "12:34 v-0006: 'a' is not declared");
}
@ -528,12 +531,13 @@ TEST_F(ValidatorTest, UsingUndefinedVariableOuterScope_Pass) {
create<ast::IfStatement>(cond, body, ast::ElseStatementList{}),
});
EXPECT_TRUE(td()->DetermineStatements(outer_body)) << td()->error();
ASSERT_NE(TypeOf(lhs), nullptr);
ASSERT_NE(TypeOf(rhs), nullptr);
WrapInFunction(outer_body);
ValidatorImpl& v = Build();
ASSERT_NE(TypeOf(lhs), nullptr);
ASSERT_NE(TypeOf(rhs), nullptr);
EXPECT_TRUE(v.ValidateStatements(outer_body)) << v.error();
}
@ -561,12 +565,13 @@ TEST_F(ValidatorTest, UsingUndefinedVariableDifferentScope_Fail) {
second_body,
});
EXPECT_TRUE(td()->DetermineStatements(outer_body)) << td()->error();
ASSERT_NE(TypeOf(lhs), nullptr);
ASSERT_NE(TypeOf(rhs), nullptr);
WrapInFunction(outer_body);
ValidatorImpl& v = Build();
ASSERT_NE(TypeOf(lhs), nullptr);
ASSERT_NE(TypeOf(rhs), nullptr);
EXPECT_FALSE(v.ValidateStatements(outer_body));
EXPECT_EQ(v.error(), "12:34 v-0006: 'a' is not declared");
}
@ -574,14 +579,12 @@ TEST_F(ValidatorTest, UsingUndefinedVariableDifferentScope_Fail) {
TEST_F(ValidatorTest, GlobalVariableUnique_Pass) {
// var global_var0 : f32 = 0.1;
// var global_var1 : i32 = 0;
auto* var0 = Var("global_var0", ast::StorageClass::kPrivate, ty.f32(),
Expr(0.1f), ast::VariableDecorationList{});
AST().AddGlobalVariable(var0);
Global("global_var0", ast::StorageClass::kPrivate, ty.f32(), Expr(0.1f),
ast::VariableDecorationList{});
auto* var1 = Var(Source{Source::Location{12, 34}}, "global_var1",
ast::StorageClass::kPrivate, ty.f32(), Expr(0),
ast::VariableDecorationList{});
AST().AddGlobalVariable(var1);
Global(Source{Source::Location{12, 34}}, "global_var1",
ast::StorageClass::kPrivate, ty.f32(), Expr(0),
ast::VariableDecorationList{});
ValidatorImpl& v = Build();
const Program* program = v.program();
@ -593,14 +596,12 @@ TEST_F(ValidatorTest, GlobalVariableUnique_Pass) {
TEST_F(ValidatorTest, GlobalVariableNotUnique_Fail) {
// var global_var : f32 = 0.1;
// var global_var : i32 = 0;
auto* var0 = Var("global_var", ast::StorageClass::kPrivate, ty.f32(),
Expr(0.1f), ast::VariableDecorationList{});
AST().AddGlobalVariable(var0);
Global("global_var", ast::StorageClass::kPrivate, ty.f32(), Expr(0.1f),
ast::VariableDecorationList{});
auto* var1 = Var(Source{Source::Location{12, 34}}, "global_var",
ast::StorageClass::kPrivate, ty.i32(), Expr(0),
ast::VariableDecorationList{});
AST().AddGlobalVariable(var1);
Global(Source{Source::Location{12, 34}}, "global_var",
ast::StorageClass::kPrivate, ty.i32(), Expr(0),
ast::VariableDecorationList{});
ValidatorImpl& v = Build();
const Program* program = v.program();
@ -627,12 +628,13 @@ TEST_F(ValidatorTest, AssignToConstant_Fail) {
rhs),
});
EXPECT_TRUE(td()->DetermineStatements(body)) << td()->error();
ASSERT_NE(TypeOf(lhs), nullptr);
ASSERT_NE(TypeOf(rhs), nullptr);
WrapInFunction(body);
ValidatorImpl& v = Build();
ASSERT_NE(TypeOf(lhs), nullptr);
ASSERT_NE(TypeOf(rhs), nullptr);
EXPECT_FALSE(v.ValidateStatements(body));
EXPECT_EQ(v.error(), "12:34 v-0021: cannot re-assign a constant: 'a'");
}
@ -644,9 +646,8 @@ TEST_F(ValidatorTest, GlobalVariableFunctionVariableNotUnique_Fail) {
// return 0;
// }
auto* global_var = Var("a", ast::StorageClass::kPrivate, ty.f32(), Expr(2.1f),
ast::VariableDecorationList{});
AST().AddGlobalVariable(global_var);
Global("a", ast::StorageClass::kPrivate, ty.f32(), Expr(2.1f),
ast::VariableDecorationList{});
auto* var = Var("a", ast::StorageClass::kNone, ty.f32(), Expr(2.0f),
ast::VariableDecorationList{});
@ -658,8 +659,6 @@ TEST_F(ValidatorTest, GlobalVariableFunctionVariableNotUnique_Fail) {
},
ast::FunctionDecorationList{});
EXPECT_TRUE(td()->Determine()) << td()->error();
ValidatorImpl& v = Build();
EXPECT_FALSE(v.Validate()) << v.error();
@ -685,8 +684,6 @@ TEST_F(ValidatorTest, RedeclaredIndentifier_Fail) {
},
ast::FunctionDecorationList{});
EXPECT_TRUE(td()->Determine()) << td()->error();
ValidatorImpl& v = Build();
EXPECT_FALSE(v.Validate());
@ -715,7 +712,7 @@ TEST_F(ValidatorTest, RedeclaredIdentifierInnerScope_Pass) {
var_a_float),
});
EXPECT_TRUE(td()->DetermineStatements(outer_body)) << td()->error();
WrapInFunction(outer_body);
ValidatorImpl& v = Build();
@ -745,7 +742,7 @@ TEST_F(ValidatorTest, DISABLED_RedeclaredIdentifierInnerScope_False) {
create<ast::IfStatement>(cond, body, ast::ElseStatementList{}),
});
EXPECT_TRUE(td()->DetermineStatements(outer_body)) << td()->error();
WrapInFunction(outer_body);
ValidatorImpl& v = Build();
@ -770,7 +767,7 @@ TEST_F(ValidatorTest, RedeclaredIdentifierInnerScopeBlock_Pass) {
create<ast::VariableDeclStatement>(var_outer),
});
EXPECT_TRUE(td()->DetermineStatements(outer_body)) << td()->error();
WrapInFunction(outer_body);
ValidatorImpl& v = Build();
@ -794,7 +791,7 @@ TEST_F(ValidatorTest, RedeclaredIdentifierInnerScopeBlock_Fail) {
inner,
});
EXPECT_TRUE(td()->DetermineStatements(outer_body)) << td()->error();
WrapInFunction(outer_body);
ValidatorImpl& v = Build();
@ -829,8 +826,6 @@ TEST_F(ValidatorTest, RedeclaredIdentifierDifferentFunctions_Pass) {
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
});
EXPECT_TRUE(td()->Determine()) << td()->error();
ValidatorImpl& v = Build();
EXPECT_TRUE(v.Validate()) << v.error();
@ -843,8 +838,6 @@ TEST_F(ValidatorTest, VariableDeclNoConstructor_Pass) {
// }
auto* var = Var("a", ast::StorageClass::kNone, ty.i32(), nullptr,
ast::VariableDecorationList{});
td()->RegisterVariableForTesting(var);
auto* lhs = Expr("a");
auto* rhs = Expr(2);
@ -854,12 +847,13 @@ TEST_F(ValidatorTest, VariableDeclNoConstructor_Pass) {
rhs),
});
EXPECT_TRUE(td()->DetermineStatements(body)) << td()->error();
ASSERT_NE(TypeOf(lhs), nullptr);
ASSERT_NE(TypeOf(rhs), nullptr);
WrapInFunction(body);
ValidatorImpl& v = Build();
ASSERT_NE(TypeOf(lhs), nullptr);
ASSERT_NE(TypeOf(rhs), nullptr);
EXPECT_TRUE(v.ValidateStatements(body)) << v.error();
}

View File

@ -58,8 +58,18 @@ class ValidatorTestHelper : public ProgramBuilder {
/// Inserts a variable into the current scope.
/// @param var the variable to register.
void RegisterVariable(ast::Variable* var) {
AST().AddGlobalVariable(var);
vars_for_testing_.emplace_back(var);
td_->RegisterVariableForTesting(var);
}
/// Helper for returning the resolved semantic type of the expression `expr`
/// from the built program.
/// @param expr the AST expression
/// @return the resolved semantic type for the expression, or nullptr if the
/// expression has no resolved type.
type::Type* TypeOf(ast::Expression* expr) const {
auto* sem = program_->Sem().Get(expr);
return sem ? sem->Type() : nullptr;
}
private:

View File

@ -178,8 +178,6 @@ TEST_F(ValidatorTypeTest, RuntimeArrayInFunction_Fail) {
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
});
EXPECT_TRUE(td()->Determine()) << td()->error();
ValidatorImpl& v = Build();
EXPECT_FALSE(v.Validate());
@ -210,8 +208,6 @@ TEST_F(ValidatorTypeTest, RuntimeArrayAsParameter_Fail) {
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
});
EXPECT_TRUE(td()->Determine()) << td()->error();
ValidatorImpl& v = Build();
EXPECT_FALSE(v.Validate());

View File

@ -60,18 +60,15 @@ using HlslBinaryTest = TestParamHelper<BinaryData>;
TEST_P(HlslBinaryTest, Emit_f32) {
auto params = GetParam();
auto* left_var = Var("left", ast::StorageClass::kFunction, ty.f32());
auto* right_var = Var("right", ast::StorageClass::kFunction, ty.f32());
Global("left", ast::StorageClass::kFunction, ty.f32());
Global("right", ast::StorageClass::kFunction, ty.f32());
auto* left = Expr("left");
auto* right = Expr("right");
td.RegisterVariableForTesting(left_var);
td.RegisterVariableForTesting(right_var);
auto* expr = create<ast::BinaryExpression>(params.op, left, right);
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
GeneratorImpl& gen = Build();
@ -81,18 +78,15 @@ TEST_P(HlslBinaryTest, Emit_f32) {
TEST_P(HlslBinaryTest, Emit_u32) {
auto params = GetParam();
auto* left_var = Var("left", ast::StorageClass::kFunction, ty.u32());
auto* right_var = Var("right", ast::StorageClass::kFunction, ty.u32());
Global("left", ast::StorageClass::kFunction, ty.u32());
Global("right", ast::StorageClass::kFunction, ty.u32());
auto* left = Expr("left");
auto* right = Expr("right");
td.RegisterVariableForTesting(left_var);
td.RegisterVariableForTesting(right_var);
auto* expr = create<ast::BinaryExpression>(params.op, left, right);
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
GeneratorImpl& gen = Build();
@ -102,18 +96,15 @@ TEST_P(HlslBinaryTest, Emit_u32) {
TEST_P(HlslBinaryTest, Emit_i32) {
auto params = GetParam();
auto* left_var = Var("left", ast::StorageClass::kFunction, ty.i32());
auto* right_var = Var("right", ast::StorageClass::kFunction, ty.i32());
Global("left", ast::StorageClass::kFunction, ty.i32());
Global("right", ast::StorageClass::kFunction, ty.i32());
auto* left = Expr("left");
auto* right = Expr("right");
td.RegisterVariableForTesting(left_var);
td.RegisterVariableForTesting(right_var);
auto* expr = create<ast::BinaryExpression>(params.op, left, right);
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
GeneratorImpl& gen = Build();
@ -148,7 +139,7 @@ TEST_F(HlslGeneratorImplTest_Binary, Multiply_VectorScalar) {
auto* expr =
create<ast::BinaryExpression>(ast::BinaryOp::kMultiply, lhs, rhs);
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
GeneratorImpl& gen = Build();
@ -165,7 +156,7 @@ TEST_F(HlslGeneratorImplTest_Binary, Multiply_ScalarVector) {
auto* expr =
create<ast::BinaryExpression>(ast::BinaryOp::kMultiply, lhs, rhs);
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
GeneratorImpl& gen = Build();
@ -176,16 +167,13 @@ TEST_F(HlslGeneratorImplTest_Binary, Multiply_ScalarVector) {
}
TEST_F(HlslGeneratorImplTest_Binary, Multiply_MatrixScalar) {
auto* var = Var("mat", ast::StorageClass::kFunction, ty.mat3x3<f32>());
Global("mat", ast::StorageClass::kFunction, ty.mat3x3<f32>());
auto* lhs = Expr("mat");
auto* rhs = Expr(1.f);
td.RegisterVariableForTesting(var);
auto* expr =
create<ast::BinaryExpression>(ast::BinaryOp::kMultiply, lhs, rhs);
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
GeneratorImpl& gen = Build();
@ -194,16 +182,13 @@ TEST_F(HlslGeneratorImplTest_Binary, Multiply_MatrixScalar) {
}
TEST_F(HlslGeneratorImplTest_Binary, Multiply_ScalarMatrix) {
auto* var = Var("mat", ast::StorageClass::kFunction, ty.mat3x3<f32>());
Global("mat", ast::StorageClass::kFunction, ty.mat3x3<f32>());
auto* lhs = Expr(1.f);
auto* rhs = Expr("mat");
td.RegisterVariableForTesting(var);
auto* expr =
create<ast::BinaryExpression>(ast::BinaryOp::kMultiply, lhs, rhs);
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
GeneratorImpl& gen = Build();
@ -212,16 +197,13 @@ TEST_F(HlslGeneratorImplTest_Binary, Multiply_ScalarMatrix) {
}
TEST_F(HlslGeneratorImplTest_Binary, Multiply_MatrixVector) {
auto* var = Var("mat", ast::StorageClass::kFunction, ty.mat3x3<f32>());
Global("mat", ast::StorageClass::kFunction, ty.mat3x3<f32>());
auto* lhs = Expr("mat");
auto* rhs = vec3<f32>(1.f, 1.f, 1.f);
td.RegisterVariableForTesting(var);
auto* expr =
create<ast::BinaryExpression>(ast::BinaryOp::kMultiply, lhs, rhs);
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
GeneratorImpl& gen = Build();
@ -230,16 +212,13 @@ TEST_F(HlslGeneratorImplTest_Binary, Multiply_MatrixVector) {
}
TEST_F(HlslGeneratorImplTest_Binary, Multiply_VectorMatrix) {
auto* var = Var("mat", ast::StorageClass::kFunction, ty.mat3x3<f32>());
Global("mat", ast::StorageClass::kFunction, ty.mat3x3<f32>());
auto* lhs = vec3<f32>(1.f, 1.f, 1.f);
auto* rhs = Expr("mat");
td.RegisterVariableForTesting(var);
auto* expr =
create<ast::BinaryExpression>(ast::BinaryOp::kMultiply, lhs, rhs);
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
GeneratorImpl& gen = Build();
@ -248,16 +227,13 @@ TEST_F(HlslGeneratorImplTest_Binary, Multiply_VectorMatrix) {
}
TEST_F(HlslGeneratorImplTest_Binary, Multiply_MatrixMatrix) {
auto* var = Var("mat", ast::StorageClass::kFunction, ty.mat3x3<f32>());
Global("mat", ast::StorageClass::kFunction, ty.mat3x3<f32>());
auto* lhs = Expr("mat");
auto* rhs = Expr("mat");
td.RegisterVariableForTesting(var);
auto* expr =
create<ast::BinaryExpression>(ast::BinaryOp::kMultiply, lhs, rhs);
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
GeneratorImpl& gen = Build();

View File

@ -44,21 +44,15 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
// int bar : TEXCOORD1;
// };
auto* foo_var = Var("foo", ast::StorageClass::kInput, ty.f32(), nullptr,
ast::VariableDecorationList{
create<ast::LocationDecoration>(0),
});
Global("foo", ast::StorageClass::kInput, ty.f32(), nullptr,
ast::VariableDecorationList{
create<ast::LocationDecoration>(0),
});
auto* bar_var = Var("bar", ast::StorageClass::kInput, ty.i32(), nullptr,
ast::VariableDecorationList{
create<ast::LocationDecoration>(1),
});
td.RegisterVariableForTesting(foo_var);
td.RegisterVariableForTesting(bar_var);
AST().AddGlobalVariable(foo_var);
AST().AddGlobalVariable(bar_var);
Global("bar", ast::StorageClass::kInput, ty.i32(), nullptr,
ast::VariableDecorationList{
create<ast::LocationDecoration>(1),
});
Func("vtx_main", ast::VariableList{}, ty.f32(),
ast::StatementList{
@ -93,21 +87,15 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
// int bar : TEXCOORD1;
// };
auto* foo_var = Var("foo", ast::StorageClass::kOutput, ty.f32(), nullptr,
ast::VariableDecorationList{
create<ast::LocationDecoration>(0),
});
Global("foo", ast::StorageClass::kOutput, ty.f32(), nullptr,
ast::VariableDecorationList{
create<ast::LocationDecoration>(0),
});
auto* bar_var = Var("bar", ast::StorageClass::kOutput, ty.i32(), nullptr,
ast::VariableDecorationList{
create<ast::LocationDecoration>(1),
});
td.RegisterVariableForTesting(foo_var);
td.RegisterVariableForTesting(bar_var);
AST().AddGlobalVariable(foo_var);
AST().AddGlobalVariable(bar_var);
Global("bar", ast::StorageClass::kOutput, ty.i32(), nullptr,
ast::VariableDecorationList{
create<ast::LocationDecoration>(1),
});
Func("vtx_main", ast::VariableList{}, ty.f32(),
ast::StatementList{
@ -142,21 +130,15 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
// int bar : TEXCOORD1;
// };
auto* foo_var = Var("foo", ast::StorageClass::kInput, ty.f32(), nullptr,
ast::VariableDecorationList{
create<ast::LocationDecoration>(0),
});
Global("foo", ast::StorageClass::kInput, ty.f32(), nullptr,
ast::VariableDecorationList{
create<ast::LocationDecoration>(0),
});
auto* bar_var = Var("bar", ast::StorageClass::kInput, ty.i32(), nullptr,
ast::VariableDecorationList{
create<ast::LocationDecoration>(1),
});
td.RegisterVariableForTesting(foo_var);
td.RegisterVariableForTesting(bar_var);
AST().AddGlobalVariable(foo_var);
AST().AddGlobalVariable(bar_var);
Global("bar", ast::StorageClass::kInput, ty.i32(), nullptr,
ast::VariableDecorationList{
create<ast::LocationDecoration>(1),
});
Func("main", ast::VariableList{}, ty.f32(),
ast::StatementList{
@ -191,21 +173,15 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
// int bar : SV_Target1;
// };
auto* foo_var = Var("foo", ast::StorageClass::kOutput, ty.f32(), nullptr,
ast::VariableDecorationList{
create<ast::LocationDecoration>(0),
});
Global("foo", ast::StorageClass::kOutput, ty.f32(), nullptr,
ast::VariableDecorationList{
create<ast::LocationDecoration>(0),
});
auto* bar_var = Var("bar", ast::StorageClass::kOutput, ty.i32(), nullptr,
ast::VariableDecorationList{
create<ast::LocationDecoration>(1),
});
td.RegisterVariableForTesting(foo_var);
td.RegisterVariableForTesting(bar_var);
AST().AddGlobalVariable(foo_var);
AST().AddGlobalVariable(bar_var);
Global("bar", ast::StorageClass::kOutput, ty.i32(), nullptr,
ast::VariableDecorationList{
create<ast::LocationDecoration>(1),
});
Func("main", ast::VariableList{}, ty.f32(),
ast::StatementList{
@ -237,21 +213,15 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
//
// -> Error, not allowed
auto* foo_var = Var("foo", ast::StorageClass::kInput, ty.f32(), nullptr,
ast::VariableDecorationList{
create<ast::LocationDecoration>(0),
});
Global("foo", ast::StorageClass::kInput, ty.f32(), nullptr,
ast::VariableDecorationList{
create<ast::LocationDecoration>(0),
});
auto* bar_var = Var("bar", ast::StorageClass::kInput, ty.i32(), nullptr,
ast::VariableDecorationList{
create<ast::LocationDecoration>(1),
});
td.RegisterVariableForTesting(foo_var);
td.RegisterVariableForTesting(bar_var);
AST().AddGlobalVariable(foo_var);
AST().AddGlobalVariable(bar_var);
Global("bar", ast::StorageClass::kInput, ty.i32(), nullptr,
ast::VariableDecorationList{
create<ast::LocationDecoration>(1),
});
Func("main", ast::VariableList{}, ty.f32(),
ast::StatementList{
@ -278,21 +248,15 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
//
// -> Error not allowed
auto* foo_var = Var("foo", ast::StorageClass::kOutput, ty.f32(), nullptr,
ast::VariableDecorationList{
create<ast::LocationDecoration>(0),
});
Global("foo", ast::StorageClass::kOutput, ty.f32(), nullptr,
ast::VariableDecorationList{
create<ast::LocationDecoration>(0),
});
auto* bar_var = Var("bar", ast::StorageClass::kOutput, ty.i32(), nullptr,
ast::VariableDecorationList{
create<ast::LocationDecoration>(1),
});
td.RegisterVariableForTesting(foo_var);
td.RegisterVariableForTesting(bar_var);
AST().AddGlobalVariable(foo_var);
AST().AddGlobalVariable(bar_var);
Global("bar", ast::StorageClass::kOutput, ty.i32(), nullptr,
ast::VariableDecorationList{
create<ast::LocationDecoration>(1),
});
Func("main", ast::VariableList{}, ty.f32(),
ast::StatementList{
@ -325,23 +289,15 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
// float depth : SV_Depth;
// };
auto* coord_var =
Var("coord", ast::StorageClass::kInput, ty.vec4<f32>(), nullptr,
ast::VariableDecorationList{
create<ast::BuiltinDecoration>(ast::Builtin::kFragCoord),
});
Global("coord", ast::StorageClass::kInput, ty.vec4<f32>(), nullptr,
ast::VariableDecorationList{
create<ast::BuiltinDecoration>(ast::Builtin::kFragCoord),
});
auto* depth_var =
Var("depth", ast::StorageClass::kOutput, ty.f32(), nullptr,
ast::VariableDecorationList{
create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth),
});
td.RegisterVariableForTesting(coord_var);
td.RegisterVariableForTesting(depth_var);
AST().AddGlobalVariable(coord_var);
AST().AddGlobalVariable(depth_var);
Global("depth", ast::StorageClass::kOutput, ty.f32(), nullptr,
ast::VariableDecorationList{
create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth),
});
Func("main", ast::VariableList{}, ty.void_(),
ast::StatementList{

View File

@ -132,21 +132,15 @@ TEST_F(HlslGeneratorImplTest_Function,
TEST_F(HlslGeneratorImplTest_Function,
Emit_FunctionDecoration_EntryPoint_NoReturn_InOut) {
auto* foo_var = Var("foo", ast::StorageClass::kInput, ty.f32(), nullptr,
ast::VariableDecorationList{
create<ast::LocationDecoration>(0),
});
Global("foo", ast::StorageClass::kInput, ty.f32(), nullptr,
ast::VariableDecorationList{
create<ast::LocationDecoration>(0),
});
auto* bar_var = Var("bar", ast::StorageClass::kOutput, ty.f32(), nullptr,
ast::VariableDecorationList{
create<ast::LocationDecoration>(1),
});
td.RegisterVariableForTesting(foo_var);
td.RegisterVariableForTesting(bar_var);
AST().AddGlobalVariable(foo_var);
AST().AddGlobalVariable(bar_var);
Global("bar", ast::StorageClass::kOutput, ty.f32(), nullptr,
ast::VariableDecorationList{
create<ast::LocationDecoration>(1),
});
Func("main", ast::VariableList{}, ty.void_(),
ast::StatementList{
@ -178,21 +172,15 @@ main_out main(main_in tint_in) {
TEST_F(HlslGeneratorImplTest_Function,
Emit_FunctionDecoration_EntryPoint_WithInOutVars) {
auto* foo_var = Var("foo", ast::StorageClass::kInput, ty.f32(), nullptr,
ast::VariableDecorationList{
create<ast::LocationDecoration>(0),
});
Global("foo", ast::StorageClass::kInput, ty.f32(), nullptr,
ast::VariableDecorationList{
create<ast::LocationDecoration>(0),
});
auto* bar_var = Var("bar", ast::StorageClass::kOutput, ty.f32(), nullptr,
ast::VariableDecorationList{
create<ast::LocationDecoration>(1),
});
td.RegisterVariableForTesting(foo_var);
td.RegisterVariableForTesting(bar_var);
AST().AddGlobalVariable(foo_var);
AST().AddGlobalVariable(bar_var);
Global("bar", ast::StorageClass::kOutput, ty.f32(), nullptr,
ast::VariableDecorationList{
create<ast::LocationDecoration>(1),
});
Func("frag_main", ast::VariableList{}, ty.void_(),
ast::StatementList{
@ -225,23 +213,15 @@ frag_main_out frag_main(frag_main_in tint_in) {
TEST_F(HlslGeneratorImplTest_Function,
Emit_FunctionDecoration_EntryPoint_WithInOut_Builtins) {
auto* coord_var =
Var("coord", ast::StorageClass::kInput, ty.vec4<f32>(), nullptr,
ast::VariableDecorationList{
create<ast::BuiltinDecoration>(ast::Builtin::kFragCoord),
});
Global("coord", ast::StorageClass::kInput, ty.vec4<f32>(), nullptr,
ast::VariableDecorationList{
create<ast::BuiltinDecoration>(ast::Builtin::kFragCoord),
});
auto* depth_var =
Var("depth", ast::StorageClass::kOutput, ty.f32(), nullptr,
ast::VariableDecorationList{
create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth),
});
td.RegisterVariableForTesting(coord_var);
td.RegisterVariableForTesting(depth_var);
AST().AddGlobalVariable(coord_var);
AST().AddGlobalVariable(depth_var);
Global("depth", ast::StorageClass::kOutput, ty.f32(), nullptr,
ast::VariableDecorationList{
create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth),
});
Func("frag_main", ast::VariableList{}, ty.void_(),
ast::StatementList{
@ -275,15 +255,11 @@ frag_main_out frag_main(frag_main_in tint_in) {
TEST_F(HlslGeneratorImplTest_Function,
Emit_FunctionDecoration_EntryPoint_With_Uniform) {
auto* coord_var =
Var("coord", ast::StorageClass::kUniform, ty.vec4<f32>(), nullptr,
ast::VariableDecorationList{
create<ast::BindingDecoration>(0),
create<ast::GroupDecoration>(1),
});
td.RegisterVariableForTesting(coord_var);
AST().AddGlobalVariable(coord_var);
Global("coord", ast::StorageClass::kUniform, ty.vec4<f32>(), nullptr,
ast::VariableDecorationList{
create<ast::BindingDecoration>(0),
create<ast::GroupDecoration>(1),
});
auto* var = Var("v", ast::StorageClass::kFunction, ty.f32(),
MemberAccessor("coord", "x"), ast::VariableDecorationList{});
@ -320,17 +296,14 @@ TEST_F(HlslGeneratorImplTest_Function,
auto* s = ty.struct_("Uniforms", str);
auto* coord_var = Var("uniforms", ast::StorageClass::kUniform, s, nullptr,
ast::VariableDecorationList{
create<ast::BindingDecoration>(0),
create<ast::GroupDecoration>(1),
});
Global("uniforms", ast::StorageClass::kUniform, s, nullptr,
ast::VariableDecorationList{
create<ast::BindingDecoration>(0),
create<ast::GroupDecoration>(1),
});
AST().AddConstructedType(s);
td.RegisterVariableForTesting(coord_var);
AST().AddGlobalVariable(coord_var);
auto* var = Var("v", ast::StorageClass::kFunction, ty.f32(),
create<ast::MemberAccessorExpression>(
MemberAccessor("uniforms", "coord"), Expr("x")),
@ -372,14 +345,11 @@ TEST_F(HlslGeneratorImplTest_Function,
auto* s = ty.struct_("Data", str);
type::AccessControl ac(ast::AccessControl::kReadWrite, s);
auto* coord_var = Var("coord", ast::StorageClass::kStorage, &ac, nullptr,
ast::VariableDecorationList{
create<ast::BindingDecoration>(0),
create<ast::GroupDecoration>(1),
});
td.RegisterVariableForTesting(coord_var);
AST().AddGlobalVariable(coord_var);
Global("coord", ast::StorageClass::kStorage, &ac, nullptr,
ast::VariableDecorationList{
create<ast::BindingDecoration>(0),
create<ast::GroupDecoration>(1),
});
auto* var = Var("v", ast::StorageClass::kFunction, ty.f32(),
MemberAccessor("coord", "b"), ast::VariableDecorationList{});
@ -416,15 +386,11 @@ TEST_F(HlslGeneratorImplTest_Function,
auto* s = ty.struct_("Data", str);
type::AccessControl ac(ast::AccessControl::kReadOnly, s);
auto* coord_var = Var("coord", ast::StorageClass::kStorage, &ac, nullptr,
ast::VariableDecorationList{
// decorations
create<ast::BindingDecoration>(0),
create<ast::GroupDecoration>(1),
});
td.RegisterVariableForTesting(coord_var);
AST().AddGlobalVariable(coord_var);
Global("coord", ast::StorageClass::kStorage, &ac, nullptr,
ast::VariableDecorationList{
create<ast::BindingDecoration>(0),
create<ast::GroupDecoration>(1),
});
auto* var = Var("v", ast::StorageClass::kFunction, ty.f32(),
MemberAccessor("coord", "b"), ast::VariableDecorationList{});
@ -461,14 +427,11 @@ TEST_F(HlslGeneratorImplTest_Function,
auto* s = ty.struct_("Data", str);
type::AccessControl ac(ast::AccessControl::kReadWrite, s);
auto* coord_var = Var("coord", ast::StorageClass::kStorage, &ac, nullptr,
ast::VariableDecorationList{
create<ast::BindingDecoration>(0),
create<ast::GroupDecoration>(1),
});
td.RegisterVariableForTesting(coord_var);
AST().AddGlobalVariable(coord_var);
Global("coord", ast::StorageClass::kStorage, &ac, nullptr,
ast::VariableDecorationList{
create<ast::BindingDecoration>(0),
create<ast::GroupDecoration>(1),
});
Func("frag_main", ast::VariableList{}, ty.void_(),
ast::StatementList{
@ -496,28 +459,20 @@ void frag_main() {
TEST_F(
HlslGeneratorImplTest_Function,
Emit_FunctionDecoration_Called_By_EntryPoints_WithLocationGlobals_And_Params) { // NOLINT
auto* foo_var = Var("foo", ast::StorageClass::kInput, ty.f32(), nullptr,
ast::VariableDecorationList{
create<ast::LocationDecoration>(0),
});
Global("foo", ast::StorageClass::kInput, ty.f32(), nullptr,
ast::VariableDecorationList{
create<ast::LocationDecoration>(0),
});
auto* bar_var = Var("bar", ast::StorageClass::kOutput, ty.f32(), nullptr,
ast::VariableDecorationList{
create<ast::LocationDecoration>(1),
});
Global("bar", ast::StorageClass::kOutput, ty.f32(), nullptr,
ast::VariableDecorationList{
create<ast::LocationDecoration>(1),
});
auto* val_var = Var("val", ast::StorageClass::kOutput, ty.f32(), nullptr,
ast::VariableDecorationList{
create<ast::LocationDecoration>(0),
});
td.RegisterVariableForTesting(foo_var);
td.RegisterVariableForTesting(bar_var);
td.RegisterVariableForTesting(val_var);
AST().AddGlobalVariable(foo_var);
AST().AddGlobalVariable(bar_var);
AST().AddGlobalVariable(val_var);
Global("val", ast::StorageClass::kOutput, ty.f32(), nullptr,
ast::VariableDecorationList{
create<ast::LocationDecoration>(0),
});
Func("sub_func",
ast::VariableList{Var("param", ast::StorageClass::kFunction, ty.f32())},
@ -568,15 +523,10 @@ ep_1_out ep_1(ep_1_in tint_in) {
TEST_F(HlslGeneratorImplTest_Function,
Emit_FunctionDecoration_Called_By_EntryPoints_NoUsedGlobals) {
auto* depth_var =
Var("depth", ast::StorageClass::kOutput, ty.f32(), nullptr,
ast::VariableDecorationList{
create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth),
});
td.RegisterVariableForTesting(depth_var);
AST().AddGlobalVariable(depth_var);
Global("depth", ast::StorageClass::kOutput, ty.f32(), nullptr,
ast::VariableDecorationList{
create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth),
});
Func("sub_func",
ast::VariableList{Var("param", ast::StorageClass::kFunction, ty.f32())},
@ -619,23 +569,15 @@ ep_1_out ep_1() {
TEST_F(
HlslGeneratorImplTest_Function,
Emit_FunctionDecoration_Called_By_EntryPoints_WithBuiltinGlobals_And_Params) { // NOLINT
auto* coord_var =
Var("coord", ast::StorageClass::kInput, ty.vec4<f32>(), nullptr,
ast::VariableDecorationList{
create<ast::BuiltinDecoration>(ast::Builtin::kFragCoord),
});
Global("coord", ast::StorageClass::kInput, ty.vec4<f32>(), nullptr,
ast::VariableDecorationList{
create<ast::BuiltinDecoration>(ast::Builtin::kFragCoord),
});
auto* depth_var =
Var("depth", ast::StorageClass::kOutput, ty.f32(), nullptr,
ast::VariableDecorationList{
create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth),
});
td.RegisterVariableForTesting(coord_var);
td.RegisterVariableForTesting(depth_var);
AST().AddGlobalVariable(coord_var);
AST().AddGlobalVariable(depth_var);
Global("depth", ast::StorageClass::kOutput, ty.f32(), nullptr,
ast::VariableDecorationList{
create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth),
});
Func("sub_func",
ast::VariableList{Var("param", ast::StorageClass::kFunction, ty.f32())},
@ -684,16 +626,11 @@ ep_1_out ep_1(ep_1_in tint_in) {
TEST_F(HlslGeneratorImplTest_Function,
Emit_FunctionDecoration_Called_By_EntryPoint_With_Uniform) {
auto* coord_var =
Var("coord", ast::StorageClass::kUniform, ty.vec4<f32>(), nullptr,
ast::VariableDecorationList{
create<ast::BindingDecoration>(0),
create<ast::GroupDecoration>(1),
});
td.RegisterVariableForTesting(coord_var);
AST().AddGlobalVariable(coord_var);
Global("coord", ast::StorageClass::kUniform, ty.vec4<f32>(), nullptr,
ast::VariableDecorationList{
create<ast::BindingDecoration>(0),
create<ast::GroupDecoration>(1),
});
Func("sub_func",
ast::VariableList{Var("param", ast::StorageClass::kFunction, ty.f32())},
@ -737,15 +674,11 @@ void frag_main() {
TEST_F(HlslGeneratorImplTest_Function,
Emit_FunctionDecoration_Called_By_EntryPoint_With_StorageBuffer) {
type::AccessControl ac(ast::AccessControl::kReadWrite, ty.vec4<f32>());
auto* coord_var = Var("coord", ast::StorageClass::kStorage, &ac, nullptr,
ast::VariableDecorationList{
create<ast::BindingDecoration>(0),
create<ast::GroupDecoration>(1),
});
td.RegisterVariableForTesting(coord_var);
AST().AddGlobalVariable(coord_var);
Global("coord", ast::StorageClass::kStorage, &ac, nullptr,
ast::VariableDecorationList{
create<ast::BindingDecoration>(0),
create<ast::GroupDecoration>(1),
});
Func("sub_func",
ast::VariableList{Var("param", ast::StorageClass::kFunction, ty.f32())},
@ -786,13 +719,10 @@ void frag_main() {
TEST_F(HlslGeneratorImplTest_Function,
Emit_FunctionDecoration_EntryPoints_WithGlobal_Nested_Return) {
auto* bar_var = Var("bar", ast::StorageClass::kOutput, ty.f32(), nullptr,
ast::VariableDecorationList{
create<ast::LocationDecoration>(1),
});
td.RegisterVariableForTesting(bar_var);
AST().AddGlobalVariable(bar_var);
Global("bar", ast::StorageClass::kOutput, ty.f32(), nullptr,
ast::VariableDecorationList{
create<ast::LocationDecoration>(1),
});
auto* list = create<ast::BlockStatement>(ast::StatementList{
create<ast::ReturnStatement>(),
@ -935,17 +865,15 @@ TEST_F(HlslGeneratorImplTest_Function,
ast::StructDecorationList{create<ast::StructBlockDecoration>()});
auto* s = ty.struct_("Data", str);
AST().AddConstructedType(s);
type::AccessControl ac(ast::AccessControl::kReadWrite, s);
auto* data_var = Var("data", ast::StorageClass::kStorage, &ac, nullptr,
ast::VariableDecorationList{
create<ast::BindingDecoration>(0),
create<ast::GroupDecoration>(0),
});
AST().AddConstructedType(s);
td.RegisterVariableForTesting(data_var);
AST().AddGlobalVariable(data_var);
Global("data", ast::StorageClass::kStorage, &ac, nullptr,
ast::VariableDecorationList{
create<ast::BindingDecoration>(0),
create<ast::GroupDecoration>(0),
});
{
auto* var = Var("v", ast::StorageClass::kFunction, ty.f32(),

View File

@ -52,8 +52,7 @@ TEST_P(HlslImportData_SingleParamTest, FloatScalar) {
auto* ident = Expr(param.name);
auto* expr = Call(ident, 1.f);
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
GeneratorImpl& gen = Build();
@ -93,8 +92,7 @@ TEST_P(HlslImportData_SingleIntParamTest, IntScalar) {
auto param = GetParam();
auto* expr = Call(param.name, Expr(1));
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
GeneratorImpl& gen = Build();
@ -110,8 +108,7 @@ TEST_P(HlslImportData_DualParamTest, FloatScalar) {
auto param = GetParam();
auto* expr = Call(param.name, 1.f, 2.f);
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
GeneratorImpl& gen = Build();
@ -134,8 +131,7 @@ TEST_P(HlslImportData_DualParam_VectorTest, FloatVector) {
auto* expr =
Call(param.name, vec3<f32>(1.f, 2.f, 3.f), vec3<f32>(4.f, 5.f, 6.f));
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
GeneratorImpl& gen = Build();
@ -153,8 +149,7 @@ TEST_P(HlslImportData_DualParam_Int_Test, IntScalar) {
auto param = GetParam();
auto* expr = Call(param.name, 1, 2);
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
GeneratorImpl& gen = Build();
@ -171,8 +166,7 @@ TEST_P(HlslImportData_TripleParamTest, FloatScalar) {
auto param = GetParam();
auto* expr = Call(param.name, 1.f, 2.f, 3.f);
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
GeneratorImpl& gen = Build();
@ -196,8 +190,7 @@ TEST_P(HlslImportData_TripleParam_Int_Test, IntScalar) {
auto param = GetParam();
auto* expr = Call(param.name, 1, 2, 3);
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
GeneratorImpl& gen = Build();
@ -209,15 +202,10 @@ INSTANTIATE_TEST_SUITE_P(HlslGeneratorImplTest_Import,
testing::Values(HlslImportData{"clamp", "clamp"}));
TEST_F(HlslGeneratorImplTest_Import, HlslImportData_Determinant) {
auto* var = Var("var", ast::StorageClass::kFunction, ty.mat3x3<f32>());
Global("var", ast::StorageClass::kFunction, ty.mat3x3<f32>());
auto* expr = Call("determinant", "var");
AST().AddGlobalVariable(var);
// Register the global
ASSERT_TRUE(td.Determine()) << td.error();
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
GeneratorImpl& gen = Build();

View File

@ -155,24 +155,17 @@ TEST_P(HlslIntrinsicTest, Emit) {
auto* call = GenerateCall(param.intrinsic, param.type, this);
ASSERT_NE(nullptr, call) << "Unhandled intrinsic";
WrapInFunction(call);
Global("f1", ast::StorageClass::kFunction, ty.vec2<float>());
Global("f2", ast::StorageClass::kFunction, ty.vec2<float>());
Global("f3", ast::StorageClass::kFunction, ty.vec2<float>());
Global("u1", ast::StorageClass::kFunction, ty.vec2<unsigned int>());
Global("u2", ast::StorageClass::kFunction, ty.vec2<unsigned int>());
Global("u3", ast::StorageClass::kFunction, ty.vec2<unsigned int>());
Global("b1", ast::StorageClass::kFunction, ty.vec2<bool>());
Global("m1", ast::StorageClass::kFunction, ty.mat2x2<float>());
auto* f1 = Var("f1", ast::StorageClass::kFunction, ty.vec2<float>());
auto* f2 = Var("f2", ast::StorageClass::kFunction, ty.vec2<float>());
auto* f3 = Var("f3", ast::StorageClass::kFunction, ty.vec2<float>());
auto* u1 = Var("u1", ast::StorageClass::kFunction, ty.vec2<unsigned int>());
auto* u2 = Var("u2", ast::StorageClass::kFunction, ty.vec2<unsigned int>());
auto* u3 = Var("u3", ast::StorageClass::kFunction, ty.vec2<unsigned int>());
auto* b1 = Var("b1", ast::StorageClass::kFunction, ty.vec2<bool>());
auto* m1 = Var("m1", ast::StorageClass::kFunction, ty.mat2x2<float>());
td.RegisterVariableForTesting(f1);
td.RegisterVariableForTesting(f2);
td.RegisterVariableForTesting(f3);
td.RegisterVariableForTesting(u1);
td.RegisterVariableForTesting(u2);
td.RegisterVariableForTesting(u3);
td.RegisterVariableForTesting(b1);
td.RegisterVariableForTesting(m1);
ASSERT_TRUE(td.DetermineResultType(call)) << td.error();
GeneratorImpl& gen = Build();
EXPECT_EQ(
@ -261,13 +254,10 @@ TEST_F(HlslGeneratorImplTest_Intrinsic, DISABLED_Intrinsic_Select) {
TEST_F(HlslGeneratorImplTest_Intrinsic, Intrinsic_Call) {
auto* call = Call("dot", "param1", "param2");
auto* v1 = Var("param1", ast::StorageClass::kFunction, ty.vec3<f32>());
auto* v2 = Var("param2", ast::StorageClass::kFunction, ty.vec3<f32>());
Global("param1", ast::StorageClass::kFunction, ty.vec3<f32>());
Global("param2", ast::StorageClass::kFunction, ty.vec3<f32>());
td.RegisterVariableForTesting(v1);
td.RegisterVariableForTesting(v2);
ASSERT_TRUE(td.DetermineResultType(call)) << td.error();
WrapInFunction(call);
GeneratorImpl& gen = Build();

View File

@ -404,12 +404,7 @@ ExpectedResult expected_texture_overload(
} // NOLINT - Ignore the length of this function
class HlslGeneratorIntrinsicTextureTest
: public TestParamHelper<ast::intrinsic::test::TextureOverloadCase> {
protected:
void OnVariableBuilt(ast::Variable* var) override {
td.RegisterVariableForTesting(var);
}
};
: public TestParamHelper<ast::intrinsic::test::TextureOverloadCase> {};
TEST_P(HlslGeneratorIntrinsicTextureTest, Call) {
auto param = GetParam();
@ -418,9 +413,7 @@ TEST_P(HlslGeneratorIntrinsicTextureTest, Call) {
param.buildSamplerVariable(this);
auto* call = Call(param.function, param.args(this));
ASSERT_TRUE(td.Determine()) << td.error();
ASSERT_TRUE(td.DetermineResultType(call)) << td.error();
WrapInFunction(call);
GeneratorImpl& gen = Build();

View File

@ -45,13 +45,10 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor, EmitExpression_MemberAccessor) {
ast::StructDecorationList{});
auto* s = ty.struct_("Str", strct);
auto* str_var = Var("str", ast::StorageClass::kPrivate, s);
AST().AddGlobalVariable(str_var);
auto* str_var = Global("str", ast::StorageClass::kPrivate, s);
auto* expr = MemberAccessor("str", "mem");
td.RegisterVariableForTesting(str_var);
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
GeneratorImpl& gen = Build();
@ -78,14 +75,10 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
ast::StructDecorationList{});
auto* s = ty.struct_("Data", str);
auto* coord_var = Var("data", ast::StorageClass::kStorage, s);
AST().AddGlobalVariable(coord_var);
td.RegisterVariableForTesting(coord_var);
auto* coord_var = Global("data", ast::StorageClass::kStorage, s);
auto* expr = MemberAccessor("data", "b");
ASSERT_TRUE(td.Determine()) << td.error();
ASSERT_TRUE(td.DetermineResultType(expr));
WrapInFunction(expr);
GeneratorImpl& gen = Build();
@ -111,14 +104,10 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
Member("b", ty.f32(), {MemberOffset(4)})},
ast::StructDecorationList{});
auto* s = ty.struct_("Data", str);
auto* coord_var = Var("data", ast::StorageClass::kStorage, s);
AST().AddGlobalVariable(coord_var);
td.RegisterVariableForTesting(coord_var);
auto* coord_var = Global("data", ast::StorageClass::kStorage, s);
auto* expr = MemberAccessor("data", "a");
ASSERT_TRUE(td.Determine()) << td.error();
ASSERT_TRUE(td.DetermineResultType(expr));
WrapInFunction(expr);
GeneratorImpl& gen = Build();
@ -148,21 +137,14 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
ast::StructDecorationList{});
auto* s = ty.struct_("Data", str);
auto* b_var = Var("b", ast::StorageClass::kPrivate, ty.mat2x3<f32>());
AST().AddGlobalVariable(b_var);
auto* coord_var = Var("data", ast::StorageClass::kStorage, s);
AST().AddGlobalVariable(coord_var);
auto* b_var = Global("b", ast::StorageClass::kPrivate, ty.mat2x3<f32>());
auto* coord_var = Global("data", ast::StorageClass::kStorage, s);
auto* lhs = MemberAccessor("data", "a");
auto* rhs = Expr("b");
auto* assign = create<ast::AssignmentStatement>(lhs, rhs);
td.RegisterVariableForTesting(coord_var);
td.RegisterVariableForTesting(b_var);
ASSERT_TRUE(td.Determine()) << td.error();
ASSERT_TRUE(td.DetermineResultType(assign));
WrapInFunction(assign);
GeneratorImpl& gen = Build();
@ -196,17 +178,13 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
ast::StructDecorationList{});
auto* s = ty.struct_("Data", str);
auto* coord_var = Var("data", ast::StorageClass::kStorage, s);
AST().AddGlobalVariable(coord_var);
td.RegisterVariableForTesting(coord_var);
auto* coord_var = Global("data", ast::StorageClass::kStorage, s);
auto* lhs = MemberAccessor("data", "a");
auto* rhs = Construct(ty.mat2x3<f32>(), ast::ExpressionList{});
auto* assign = create<ast::AssignmentStatement>(lhs, rhs);
ASSERT_TRUE(td.Determine()) << td.error();
ASSERT_TRUE(td.DetermineResultType(assign));
WrapInFunction(assign);
GeneratorImpl& gen = Build();
@ -239,14 +217,10 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
ast::StructDecorationList{});
auto* s = ty.struct_("Data", str);
auto* coord_var = Var("data", ast::StorageClass::kStorage, s);
AST().AddGlobalVariable(coord_var);
td.RegisterVariableForTesting(coord_var);
auto* coord_var = Global("data", ast::StorageClass::kStorage, s);
auto* expr = MemberAccessor("data", "a");
ASSERT_TRUE(td.Determine()) << td.error();
ASSERT_TRUE(td.DetermineResultType(expr));
WrapInFunction(expr);
GeneratorImpl& gen = Build();
@ -281,14 +255,10 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
ast::StructDecorationList{});
auto* s = ty.struct_("Data", str);
auto* coord_var = Var("data", ast::StorageClass::kStorage, s);
AST().AddGlobalVariable(coord_var);
td.RegisterVariableForTesting(coord_var);
auto* coord_var = Global("data", ast::StorageClass::kStorage, s);
auto* expr = MemberAccessor("data", "a");
ASSERT_TRUE(td.Determine()) << td.error();
ASSERT_TRUE(td.DetermineResultType(expr));
WrapInFunction(expr);
GeneratorImpl& gen = Build();
@ -316,14 +286,10 @@ TEST_F(
ast::StructDecorationList{});
auto* s = ty.struct_("Data", str);
auto* coord_var = Var("data", ast::StorageClass::kStorage, s);
AST().AddGlobalVariable(coord_var);
td.RegisterVariableForTesting(coord_var);
auto* coord_var = Global("data", ast::StorageClass::kStorage, s);
auto* expr = MemberAccessor("data", "a");
ASSERT_TRUE(td.Determine()) << td.error();
ASSERT_TRUE(td.DetermineResultType(expr));
WrapInFunction(expr);
GeneratorImpl& gen = Build();
@ -352,15 +318,11 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
ast::StructDecorationList{});
auto* s = ty.struct_("Data", str);
auto* coord_var = Var("data", ast::StorageClass::kStorage, s);
AST().AddGlobalVariable(coord_var);
td.RegisterVariableForTesting(coord_var);
auto* coord_var = Global("data", ast::StorageClass::kStorage, s);
auto* expr = IndexAccessor(
IndexAccessor(MemberAccessor("data", "a"), Expr(2)), Expr(1));
ASSERT_TRUE(td.Determine()) << td.error();
ASSERT_TRUE(td.DetermineResultType(expr));
WrapInFunction(expr);
GeneratorImpl& gen = Build();
@ -388,14 +350,10 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
ast::StructMemberList{Member("a", &ary, {MemberOffset(0)})},
ast::StructDecorationList{});
auto* s = ty.struct_("Data", str);
auto* coord_var = Var("data", ast::StorageClass::kStorage, s);
AST().AddGlobalVariable(coord_var);
td.RegisterVariableForTesting(coord_var);
auto* coord_var = Global("data", ast::StorageClass::kStorage, s);
auto* expr = IndexAccessor(MemberAccessor("data", "a"), Expr(2));
ASSERT_TRUE(td.Determine()) << td.error();
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
GeneratorImpl& gen = Build();
@ -423,15 +381,11 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
ast::StructMemberList{Member("a", &ary, {MemberOffset(0)})},
ast::StructDecorationList{});
auto* s = ty.struct_("Data", str);
auto* coord_var = Var("data", ast::StorageClass::kStorage, s);
AST().AddGlobalVariable(coord_var);
td.RegisterVariableForTesting(coord_var);
auto* coord_var = Global("data", ast::StorageClass::kStorage, s);
auto* expr = IndexAccessor(MemberAccessor("data", "a"),
Sub(Add(Expr(2), Expr(4)), Expr(3)));
ASSERT_TRUE(td.Determine()) << td.error();
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
GeneratorImpl& gen = Build();
@ -458,16 +412,12 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
ast::StructDecorationList{});
auto* s = ty.struct_("Data", str);
auto* coord_var = Var("data", ast::StorageClass::kStorage, s);
AST().AddGlobalVariable(coord_var);
td.RegisterVariableForTesting(coord_var);
auto* coord_var = Global("data", ast::StorageClass::kStorage, s);
auto* lhs = MemberAccessor("data", "b");
auto* rhs = Expr(2.0f);
auto* assign = create<ast::AssignmentStatement>(lhs, rhs);
ASSERT_TRUE(td.Determine()) << td.error();
ASSERT_TRUE(td.DetermineResultType(assign));
WrapInFunction(assign);
GeneratorImpl& gen = Build();
@ -498,16 +448,12 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
ast::StructDecorationList{});
auto* s = ty.struct_("Data", str);
auto* coord_var = Var("data", ast::StorageClass::kStorage, s);
AST().AddGlobalVariable(coord_var);
td.RegisterVariableForTesting(coord_var);
auto* coord_var = Global("data", ast::StorageClass::kStorage, s);
auto* lhs = IndexAccessor(MemberAccessor("data", "a"), Expr(2));
auto* rhs = Expr(2);
auto* assign = create<ast::AssignmentStatement>(lhs, rhs);
ASSERT_TRUE(td.Determine()) << td.error();
ASSERT_TRUE(td.DetermineResultType(assign)) << td.error();
WrapInFunction(assign);
GeneratorImpl& gen = Build();
@ -535,16 +481,12 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
ast::StructDecorationList{});
auto* s = ty.struct_("Data", str);
auto* coord_var = Var("data", ast::StorageClass::kStorage, s);
AST().AddGlobalVariable(coord_var);
td.RegisterVariableForTesting(coord_var);
auto* coord_var = Global("data", ast::StorageClass::kStorage, s);
auto* lhs = MemberAccessor("data", "a");
auto* rhs = Expr(2);
auto* assign = create<ast::AssignmentStatement>(lhs, rhs);
ASSERT_TRUE(td.Determine()) << td.error();
ASSERT_TRUE(td.DetermineResultType(assign));
WrapInFunction(assign);
GeneratorImpl& gen = Build();
@ -572,14 +514,10 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
ast::StructDecorationList{});
auto* s = ty.struct_("Data", str);
auto* coord_var = Var("data", ast::StorageClass::kStorage, s);
AST().AddGlobalVariable(coord_var);
td.RegisterVariableForTesting(coord_var);
auto* coord_var = Global("data", ast::StorageClass::kStorage, s);
auto* expr = MemberAccessor("data", "b");
ASSERT_TRUE(td.Determine()) << td.error();
ASSERT_TRUE(td.DetermineResultType(expr));
WrapInFunction(expr);
GeneratorImpl& gen = Build();
@ -606,17 +544,14 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
ast::StructDecorationList{});
auto* s = ty.struct_("Data", str);
auto* coord_var = Var("data", ast::StorageClass::kStorage, s);
AST().AddGlobalVariable(coord_var);
td.RegisterVariableForTesting(coord_var);
auto* coord_var = Global("data", ast::StorageClass::kStorage, s);
auto* lhs = MemberAccessor("data", "b");
auto* rhs = vec3<f32>(1.f, 2.f, 3.f);
auto* assign = create<ast::AssignmentStatement>(lhs, rhs);
ASSERT_TRUE(td.Determine()) << td.error();
ASSERT_TRUE(td.DetermineResultType(assign));
WrapInFunction(assign);
GeneratorImpl& gen = Build();
@ -661,15 +596,11 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
ast::StructDecorationList{});
auto* pre_struct = ty.struct_("Pre", pre_str);
auto* coord_var = Var("data", ast::StorageClass::kStorage, pre_struct);
AST().AddGlobalVariable(coord_var);
td.RegisterVariableForTesting(coord_var);
auto* coord_var = Global("data", ast::StorageClass::kStorage, pre_struct);
auto* expr =
MemberAccessor(IndexAccessor(MemberAccessor("data", "c"), Expr(2)), "b");
ASSERT_TRUE(td.Determine()) << td.error();
ASSERT_TRUE(td.DetermineResultType(expr));
WrapInFunction(expr);
GeneratorImpl& gen = Build();
@ -710,17 +641,12 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
ast::StructDecorationList{});
auto* pre_struct = ty.struct_("Pre", pre_str);
auto* coord_var = Var("data", ast::StorageClass::kStorage, pre_struct);
AST().AddGlobalVariable(coord_var);
td.RegisterVariableForTesting(coord_var);
auto* coord_var = Global("data", ast::StorageClass::kStorage, pre_struct);
auto* expr = MemberAccessor(
MemberAccessor(IndexAccessor(MemberAccessor("data", "c"), Expr(2)), "b"),
"xy");
ASSERT_TRUE(td.Determine()) << td.error();
ASSERT_TRUE(td.DetermineResultType(expr));
WrapInFunction(expr);
GeneratorImpl& gen = Build();
@ -764,16 +690,12 @@ TEST_F(
ast::StructDecorationList{});
auto* pre_struct = ty.struct_("Pre", pre_str);
auto* coord_var = Var("data", ast::StorageClass::kStorage, pre_struct);
AST().AddGlobalVariable(coord_var);
td.RegisterVariableForTesting(coord_var);
auto* coord_var = Global("data", ast::StorageClass::kStorage, pre_struct);
auto* expr = MemberAccessor(
MemberAccessor(IndexAccessor(MemberAccessor("data", "c"), Expr(2)), "b"),
"g");
ASSERT_TRUE(td.Determine()) << td.error();
ASSERT_TRUE(td.DetermineResultType(expr));
WrapInFunction(expr);
GeneratorImpl& gen = Build();
@ -816,16 +738,12 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
ast::StructDecorationList{});
auto* pre_struct = ty.struct_("Pre", pre_str);
auto* coord_var = Var("data", ast::StorageClass::kStorage, pre_struct);
AST().AddGlobalVariable(coord_var);
td.RegisterVariableForTesting(coord_var);
auto* coord_var = Global("data", ast::StorageClass::kStorage, pre_struct);
auto* expr = IndexAccessor(
MemberAccessor(IndexAccessor(MemberAccessor("data", "c"), Expr(2)), "b"),
Expr(1));
ASSERT_TRUE(td.Determine()) << td.error();
ASSERT_TRUE(td.DetermineResultType(expr));
WrapInFunction(expr);
GeneratorImpl& gen = Build();
@ -868,9 +786,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
ast::StructDecorationList{});
auto* pre_struct = ty.struct_("Pre", pre_str);
auto* coord_var = Var("data", ast::StorageClass::kStorage, pre_struct);
AST().AddGlobalVariable(coord_var);
td.RegisterVariableForTesting(coord_var);
auto* coord_var = Global("data", ast::StorageClass::kStorage, pre_struct);
auto* lhs =
MemberAccessor(IndexAccessor(MemberAccessor("data", "c"), Expr(2)), "b");
@ -878,8 +794,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
auto* assign =
create<ast::AssignmentStatement>(lhs, vec3<f32>(1.f, 2.f, 3.f));
ASSERT_TRUE(td.Determine()) << td.error();
ASSERT_TRUE(td.DetermineResultType(assign));
WrapInFunction(assign);
GeneratorImpl& gen = Build();
@ -924,9 +839,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
ast::StructDecorationList{});
auto* pre_struct = ty.struct_("Pre", pre_str);
auto* coord_var = Var("data", ast::StorageClass::kStorage, pre_struct);
AST().AddGlobalVariable(coord_var);
td.RegisterVariableForTesting(coord_var);
auto* coord_var = Global("data", ast::StorageClass::kStorage, pre_struct);
auto* lhs = MemberAccessor(
MemberAccessor(IndexAccessor(MemberAccessor("data", "c"), Expr(2)), "b"),
@ -935,8 +848,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
auto* assign = create<ast::AssignmentStatement>(lhs, rhs);
ASSERT_TRUE(td.Determine()) << td.error();
ASSERT_TRUE(td.DetermineResultType(assign));
WrapInFunction(assign);
GeneratorImpl& gen = Build();
@ -950,12 +862,10 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
TEST_F(HlslGeneratorImplTest_MemberAccessor,
EmitExpression_MemberAccessor_Swizzle_xyz) {
auto* vec = Var("my_vec", ast::StorageClass::kPrivate, ty.vec4<f32>());
td.RegisterVariableForTesting(vec);
Global("my_vec", ast::StorageClass::kPrivate, ty.vec4<f32>());
auto* expr = MemberAccessor("my_vec", "xyz");
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.EmitExpression(pre, out, expr)) << gen.error();
@ -964,12 +874,10 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
TEST_F(HlslGeneratorImplTest_MemberAccessor,
EmitExpression_MemberAccessor_Swizzle_gbr) {
auto* vec = Var("my_vec", ast::StorageClass::kPrivate, ty.vec4<f32>());
td.RegisterVariableForTesting(vec);
Global("my_vec", ast::StorageClass::kPrivate, ty.vec4<f32>());
auto* expr = MemberAccessor("my_vec", "gbr");
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.EmitExpression(pre, out, expr)) << gen.error();

View File

@ -407,14 +407,15 @@ using HlslStoragetexturesTest = TestParamHelper<HlslStorageTextureData>;
TEST_P(HlslStoragetexturesTest, Emit) {
auto params = GetParam();
type::StorageTexture s(params.dim, params.imgfmt);
type::AccessControl ac(params.ro ? ast::AccessControl::kReadOnly
: ast::AccessControl::kWriteOnly,
&s);
auto* s = create<type::StorageTexture>(params.dim, params.imgfmt);
auto* ac =
create<type::AccessControl>(params.ro ? ast::AccessControl::kReadOnly
: ast::AccessControl::kWriteOnly,
s);
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.EmitType(out, &ac, "")) << gen.error();
ASSERT_TRUE(gen.EmitType(out, ac, "")) << gen.error();
EXPECT_EQ(result(), params.result);
}
INSTANTIATE_TEST_SUITE_P(

View File

@ -33,7 +33,7 @@ namespace hlsl {
template <typename BODY>
class TestHelperBase : public BODY, public ProgramBuilder {
public:
TestHelperBase() : td(this) {}
TestHelperBase() = default;
~TestHelperBase() = default;
/// Builds and returns a GeneratorImpl from the program.
@ -55,9 +55,6 @@ class TestHelperBase : public BODY, public ProgramBuilder {
/// @returns the pre result string
std::string pre_result() const { return pre.str(); }
/// The type determiner
TypeDeterminer td;
/// The output stream
std::ostringstream out;
/// The pre-output stream

View File

@ -47,19 +47,11 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Vertex_Input) {
// int bar [[attribute(1)]];
// };
auto* foo_var =
Var("foo", ast::StorageClass::kInput, ty.f32(), nullptr,
ast::VariableDecorationList{create<ast::LocationDecoration>(0)});
Global("foo", ast::StorageClass::kInput, ty.f32(), nullptr,
ast::VariableDecorationList{create<ast::LocationDecoration>(0)});
auto* bar_var =
Var("bar", ast::StorageClass::kInput, ty.i32(), nullptr,
ast::VariableDecorationList{create<ast::LocationDecoration>(1)});
td.RegisterVariableForTesting(foo_var);
td.RegisterVariableForTesting(bar_var);
AST().AddGlobalVariable(foo_var);
AST().AddGlobalVariable(bar_var);
Global("bar", ast::StorageClass::kInput, ty.i32(), nullptr,
ast::VariableDecorationList{create<ast::LocationDecoration>(1)});
auto body = ast::StatementList{
create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")),
@ -92,19 +84,11 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Vertex_Output) {
// int bar [[user(locn1)]];
// };
auto* foo_var =
Var("foo", ast::StorageClass::kOutput, ty.f32(), nullptr,
ast::VariableDecorationList{create<ast::LocationDecoration>(0)});
Global("foo", ast::StorageClass::kOutput, ty.f32(), nullptr,
ast::VariableDecorationList{create<ast::LocationDecoration>(0)});
auto* bar_var =
Var("bar", ast::StorageClass::kOutput, ty.i32(), nullptr,
ast::VariableDecorationList{create<ast::LocationDecoration>(1)});
td.RegisterVariableForTesting(foo_var);
td.RegisterVariableForTesting(bar_var);
AST().AddGlobalVariable(foo_var);
AST().AddGlobalVariable(bar_var);
Global("bar", ast::StorageClass::kOutput, ty.i32(), nullptr,
ast::VariableDecorationList{create<ast::LocationDecoration>(1)});
auto body = ast::StatementList{
create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")),
@ -137,19 +121,11 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Fragment_Input) {
// int bar [[user(locn1)]];
// };
auto* foo_var =
Var("foo", ast::StorageClass::kInput, ty.f32(), nullptr,
ast::VariableDecorationList{create<ast::LocationDecoration>(0)});
Global("foo", ast::StorageClass::kInput, ty.f32(), nullptr,
ast::VariableDecorationList{create<ast::LocationDecoration>(0)});
auto* bar_var =
Var("bar", ast::StorageClass::kInput, ty.i32(), nullptr,
ast::VariableDecorationList{create<ast::LocationDecoration>(1)});
td.RegisterVariableForTesting(foo_var);
td.RegisterVariableForTesting(bar_var);
AST().AddGlobalVariable(foo_var);
AST().AddGlobalVariable(bar_var);
Global("bar", ast::StorageClass::kInput, ty.i32(), nullptr,
ast::VariableDecorationList{create<ast::LocationDecoration>(1)});
auto body = ast::StatementList{
create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")),
@ -182,19 +158,11 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Fragment_Output) {
// int bar [[color(1)]];
// };
auto* foo_var =
Var("foo", ast::StorageClass::kOutput, ty.f32(), nullptr,
ast::VariableDecorationList{create<ast::LocationDecoration>(0)});
Global("foo", ast::StorageClass::kOutput, ty.f32(), nullptr,
ast::VariableDecorationList{create<ast::LocationDecoration>(0)});
auto* bar_var =
Var("bar", ast::StorageClass::kOutput, ty.i32(), nullptr,
ast::VariableDecorationList{create<ast::LocationDecoration>(1)});
td.RegisterVariableForTesting(foo_var);
td.RegisterVariableForTesting(bar_var);
AST().AddGlobalVariable(foo_var);
AST().AddGlobalVariable(bar_var);
Global("bar", ast::StorageClass::kOutput, ty.i32(), nullptr,
ast::VariableDecorationList{create<ast::LocationDecoration>(1)});
auto body = ast::StatementList{
create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")),
@ -224,19 +192,11 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Compute_Input) {
//
// -> Error, not allowed
auto* foo_var =
Var("foo", ast::StorageClass::kInput, ty.f32(), nullptr,
ast::VariableDecorationList{create<ast::LocationDecoration>(0)});
Global("foo", ast::StorageClass::kInput, ty.f32(), nullptr,
ast::VariableDecorationList{create<ast::LocationDecoration>(0)});
auto* bar_var =
Var("bar", ast::StorageClass::kInput, ty.i32(), nullptr,
ast::VariableDecorationList{create<ast::LocationDecoration>(1)});
td.RegisterVariableForTesting(foo_var);
td.RegisterVariableForTesting(bar_var);
AST().AddGlobalVariable(foo_var);
AST().AddGlobalVariable(bar_var);
Global("bar", ast::StorageClass::kInput, ty.i32(), nullptr,
ast::VariableDecorationList{create<ast::LocationDecoration>(1)});
auto body = ast::StatementList{
create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")),
@ -261,19 +221,11 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Compute_Output) {
//
// -> Error not allowed
auto* foo_var =
Var("foo", ast::StorageClass::kOutput, ty.f32(), nullptr,
ast::VariableDecorationList{create<ast::LocationDecoration>(0)});
Global("foo", ast::StorageClass::kOutput, ty.f32(), nullptr,
ast::VariableDecorationList{create<ast::LocationDecoration>(0)});
auto* bar_var =
Var("bar", ast::StorageClass::kOutput, ty.i32(), nullptr,
ast::VariableDecorationList{create<ast::LocationDecoration>(1)});
td.RegisterVariableForTesting(foo_var);
td.RegisterVariableForTesting(bar_var);
AST().AddGlobalVariable(foo_var);
AST().AddGlobalVariable(bar_var);
Global("bar", ast::StorageClass::kOutput, ty.i32(), nullptr,
ast::VariableDecorationList{create<ast::LocationDecoration>(1)});
auto body = ast::StatementList{
create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")),
@ -303,21 +255,13 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Builtins) {
// float depth [[depth(any)]];
// };
auto* coord_var =
Var("coord", ast::StorageClass::kInput, ty.vec4<f32>(), nullptr,
ast::VariableDecorationList{
create<ast::BuiltinDecoration>(ast::Builtin::kFragCoord)});
Global("coord", ast::StorageClass::kInput, ty.vec4<f32>(), nullptr,
ast::VariableDecorationList{
create<ast::BuiltinDecoration>(ast::Builtin::kFragCoord)});
auto* depth_var =
Var("depth", ast::StorageClass::kOutput, ty.f32(), nullptr,
ast::VariableDecorationList{
create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth)});
td.RegisterVariableForTesting(coord_var);
td.RegisterVariableForTesting(depth_var);
AST().AddGlobalVariable(coord_var);
AST().AddGlobalVariable(depth_var);
Global("depth", ast::StorageClass::kOutput, ty.f32(), nullptr,
ast::VariableDecorationList{
create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth)});
auto body = ast::StatementList{create<ast::AssignmentStatement>(
Expr("depth"), MemberAccessor("coord", "x"))};

View File

@ -142,19 +142,11 @@ fragment void main_tint_0() {
TEST_F(MslGeneratorImplTest,
Emit_FunctionDecoration_EntryPoint_NoReturn_InOut) {
auto* foo_var =
Var("foo", ast::StorageClass::kInput, ty.f32(), nullptr,
ast::VariableDecorationList{create<ast::LocationDecoration>(0)});
Global("foo", ast::StorageClass::kInput, ty.f32(), nullptr,
ast::VariableDecorationList{create<ast::LocationDecoration>(0)});
auto* bar_var =
Var("bar", ast::StorageClass::kOutput, ty.f32(), nullptr,
ast::VariableDecorationList{create<ast::LocationDecoration>(1)});
td.RegisterVariableForTesting(foo_var);
td.RegisterVariableForTesting(bar_var);
AST().AddGlobalVariable(foo_var);
AST().AddGlobalVariable(bar_var);
Global("bar", ast::StorageClass::kOutput, ty.f32(), nullptr,
ast::VariableDecorationList{create<ast::LocationDecoration>(1)});
Func("main", ast::VariableList{}, ty.void_(),
ast::StatementList{
@ -186,19 +178,11 @@ fragment main_out main_tint_0(main_in tint_in [[stage_in]]) {
}
TEST_F(MslGeneratorImplTest, Emit_FunctionDecoration_EntryPoint_WithInOutVars) {
auto* foo_var =
Var("foo", ast::StorageClass::kInput, ty.f32(), nullptr,
ast::VariableDecorationList{create<ast::LocationDecoration>(0)});
Global("foo", ast::StorageClass::kInput, ty.f32(), nullptr,
ast::VariableDecorationList{create<ast::LocationDecoration>(0)});
auto* bar_var =
Var("bar", ast::StorageClass::kOutput, ty.f32(), nullptr,
ast::VariableDecorationList{create<ast::LocationDecoration>(1)});
td.RegisterVariableForTesting(foo_var);
td.RegisterVariableForTesting(bar_var);
AST().AddGlobalVariable(foo_var);
AST().AddGlobalVariable(bar_var);
Global("bar", ast::StorageClass::kOutput, ty.f32(), nullptr,
ast::VariableDecorationList{create<ast::LocationDecoration>(1)});
auto body = ast::StatementList{
create<ast::AssignmentStatement>(Expr("bar"), Expr("foo")),
@ -232,21 +216,13 @@ fragment frag_main_out frag_main(frag_main_in tint_in [[stage_in]]) {
TEST_F(MslGeneratorImplTest,
Emit_FunctionDecoration_EntryPoint_WithInOut_Builtins) {
auto* coord_var =
Var("coord", ast::StorageClass::kInput, ty.vec4<f32>(), nullptr,
ast::VariableDecorationList{
create<ast::BuiltinDecoration>(ast::Builtin::kFragCoord)});
Global("coord", ast::StorageClass::kInput, ty.vec4<f32>(), nullptr,
ast::VariableDecorationList{
create<ast::BuiltinDecoration>(ast::Builtin::kFragCoord)});
auto* depth_var =
Var("depth", ast::StorageClass::kOutput, ty.f32(), nullptr,
ast::VariableDecorationList{
create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth)});
td.RegisterVariableForTesting(coord_var);
td.RegisterVariableForTesting(depth_var);
AST().AddGlobalVariable(coord_var);
AST().AddGlobalVariable(depth_var);
Global("depth", ast::StorageClass::kOutput, ty.f32(), nullptr,
ast::VariableDecorationList{
create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth)});
auto body = ast::StatementList{
create<ast::AssignmentStatement>(Expr("depth"),
@ -278,14 +254,9 @@ fragment frag_main_out frag_main(float4 coord [[position]]) {
}
TEST_F(MslGeneratorImplTest, Emit_FunctionDecoration_EntryPoint_With_Uniform) {
auto* coord_var =
Var("coord", ast::StorageClass::kUniform, ty.vec4<f32>(), nullptr,
ast::VariableDecorationList{create<ast::BindingDecoration>(0),
create<ast::GroupDecoration>(1)});
td.RegisterVariableForTesting(coord_var);
AST().AddGlobalVariable(coord_var);
Global("coord", ast::StorageClass::kUniform, ty.vec4<f32>(), nullptr,
ast::VariableDecorationList{create<ast::BindingDecoration>(0),
create<ast::GroupDecoration>(1)});
auto* var = Var("v", ast::StorageClass::kFunction, ty.f32(),
MemberAccessor("coord", "x"), ast::VariableDecorationList{});
@ -324,14 +295,9 @@ TEST_F(MslGeneratorImplTest,
AST().AddConstructedType(s);
auto* coord_var =
Var("coord", ast::StorageClass::kStorage, &ac, nullptr,
ast::VariableDecorationList{create<ast::BindingDecoration>(0),
create<ast::GroupDecoration>(1)});
td.RegisterVariableForTesting(coord_var);
AST().AddGlobalVariable(coord_var);
Global("coord", ast::StorageClass::kStorage, &ac, nullptr,
ast::VariableDecorationList{create<ast::BindingDecoration>(0),
create<ast::GroupDecoration>(1)});
auto* var = Var("v", ast::StorageClass::kFunction, ty.f32(),
MemberAccessor("coord", "b"), ast::VariableDecorationList{});
@ -374,13 +340,9 @@ TEST_F(MslGeneratorImplTest,
type::AccessControl ac(ast::AccessControl::kReadOnly, s);
AST().AddConstructedType(s);
auto* coord_var =
Var("coord", ast::StorageClass::kStorage, &ac, nullptr,
ast::VariableDecorationList{create<ast::BindingDecoration>(0),
create<ast::GroupDecoration>(1)});
td.RegisterVariableForTesting(coord_var);
AST().AddGlobalVariable(coord_var);
Global("coord", ast::StorageClass::kStorage, &ac, nullptr,
ast::VariableDecorationList{create<ast::BindingDecoration>(0),
create<ast::GroupDecoration>(1)});
auto* var = Var("v", ast::StorageClass::kFunction, ty.f32(),
MemberAccessor("coord", "b"), ast::VariableDecorationList{});
@ -415,25 +377,14 @@ fragment void frag_main(const device Data& coord [[buffer(0)]]) {
TEST_F(
MslGeneratorImplTest,
Emit_FunctionDecoration_Called_By_EntryPoints_WithLocationGlobals_And_Params) { // NOLINT
auto* foo_var =
Var("foo", ast::StorageClass::kInput, ty.f32(), nullptr,
ast::VariableDecorationList{create<ast::LocationDecoration>(0)});
Global("foo", ast::StorageClass::kInput, ty.f32(), nullptr,
ast::VariableDecorationList{create<ast::LocationDecoration>(0)});
auto* bar_var =
Var("bar", ast::StorageClass::kOutput, ty.f32(), nullptr,
ast::VariableDecorationList{create<ast::LocationDecoration>(1)});
Global("bar", ast::StorageClass::kOutput, ty.f32(), nullptr,
ast::VariableDecorationList{create<ast::LocationDecoration>(1)});
auto* val_var =
Var("val", ast::StorageClass::kOutput, ty.f32(), nullptr,
ast::VariableDecorationList{create<ast::LocationDecoration>(0)});
td.RegisterVariableForTesting(foo_var);
td.RegisterVariableForTesting(bar_var);
td.RegisterVariableForTesting(val_var);
AST().AddGlobalVariable(foo_var);
AST().AddGlobalVariable(bar_var);
AST().AddGlobalVariable(val_var);
Global("val", ast::StorageClass::kOutput, ty.f32(), nullptr,
ast::VariableDecorationList{create<ast::LocationDecoration>(0)});
ast::VariableList params;
params.push_back(Var("param", ast::StorageClass::kFunction, ty.f32()));
@ -486,13 +437,9 @@ fragment ep_1_out ep_1(ep_1_in tint_in [[stage_in]]) {
TEST_F(MslGeneratorImplTest,
Emit_FunctionDecoration_Called_By_EntryPoints_NoUsedGlobals) {
auto* depth_var =
Var("depth", ast::StorageClass::kOutput, ty.f32(), nullptr,
ast::VariableDecorationList{
create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth)});
td.RegisterVariableForTesting(depth_var);
AST().AddGlobalVariable(depth_var);
Global("depth", ast::StorageClass::kOutput, ty.f32(), nullptr,
ast::VariableDecorationList{
create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth)});
ast::VariableList params;
params.push_back(Var("param", ast::StorageClass::kFunction, ty.f32()));
@ -538,21 +485,13 @@ fragment ep_1_out ep_1() {
TEST_F(
MslGeneratorImplTest,
Emit_FunctionDecoration_Called_By_EntryPoints_WithBuiltinGlobals_And_Params) { // NOLINT
auto* coord_var =
Var("coord", ast::StorageClass::kInput, ty.vec4<f32>(), nullptr,
ast::VariableDecorationList{
create<ast::BuiltinDecoration>(ast::Builtin::kFragCoord)});
Global("coord", ast::StorageClass::kInput, ty.vec4<f32>(), nullptr,
ast::VariableDecorationList{
create<ast::BuiltinDecoration>(ast::Builtin::kFragCoord)});
auto* depth_var =
Var("depth", ast::StorageClass::kOutput, ty.f32(), nullptr,
ast::VariableDecorationList{
create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth)});
td.RegisterVariableForTesting(coord_var);
td.RegisterVariableForTesting(depth_var);
AST().AddGlobalVariable(coord_var);
AST().AddGlobalVariable(depth_var);
Global("depth", ast::StorageClass::kOutput, ty.f32(), nullptr,
ast::VariableDecorationList{
create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth)});
ast::VariableList params;
params.push_back(Var("param", ast::StorageClass::kFunction, ty.f32()));
@ -600,13 +539,9 @@ fragment ep_1_out ep_1(float4 coord [[position]]) {
TEST_F(MslGeneratorImplTest,
Emit_FunctionDecoration_Called_By_EntryPoint_With_Uniform) {
auto* coord_var =
Var("coord", ast::StorageClass::kUniform, ty.vec4<f32>(), nullptr,
ast::VariableDecorationList{create<ast::BindingDecoration>(0),
create<ast::GroupDecoration>(1)});
td.RegisterVariableForTesting(coord_var);
AST().AddGlobalVariable(coord_var);
Global("coord", ast::StorageClass::kUniform, ty.vec4<f32>(), nullptr,
ast::VariableDecorationList{create<ast::BindingDecoration>(0),
create<ast::GroupDecoration>(1)});
ast::VariableList params;
params.push_back(Var("param", ast::StorageClass::kFunction, ty.f32()));
@ -660,17 +595,12 @@ TEST_F(MslGeneratorImplTest,
type::AccessControl ac(ast::AccessControl::kReadWrite, s);
AST().AddConstructedType(s);
auto* coord_var =
Var("coord", ast::StorageClass::kStorage, &ac, nullptr,
ast::VariableDecorationList{create<ast::BindingDecoration>(0),
create<ast::GroupDecoration>(1)});
td.RegisterVariableForTesting(coord_var);
AST().AddGlobalVariable(coord_var);
Global("coord", ast::StorageClass::kStorage, &ac, nullptr,
ast::VariableDecorationList{create<ast::BindingDecoration>(0),
create<ast::GroupDecoration>(1)});
ast::VariableList params;
params.push_back(
Var("param", ast::StorageClass::kFunction, ty.f32())); // decorations
params.push_back(Var("param", ast::StorageClass::kFunction, ty.f32()));
auto body = ast::StatementList{
create<ast::ReturnStatement>(MemberAccessor("coord", "b"))};
@ -722,17 +652,12 @@ TEST_F(MslGeneratorImplTest,
type::AccessControl ac(ast::AccessControl::kReadOnly, s);
AST().AddConstructedType(s);
auto* coord_var =
Var("coord", ast::StorageClass::kStorage, &ac, nullptr,
ast::VariableDecorationList{create<ast::BindingDecoration>(0),
create<ast::GroupDecoration>(1)});
td.RegisterVariableForTesting(coord_var);
AST().AddGlobalVariable(coord_var);
Global("coord", ast::StorageClass::kStorage, &ac, nullptr,
ast::VariableDecorationList{create<ast::BindingDecoration>(0),
create<ast::GroupDecoration>(1)});
ast::VariableList params;
params.push_back(
Var("param", ast::StorageClass::kFunction, ty.f32())); // decorations
params.push_back(Var("param", ast::StorageClass::kFunction, ty.f32()));
auto body = ast::StatementList{
create<ast::ReturnStatement>(MemberAccessor("coord", "b"))};
@ -778,12 +703,8 @@ fragment void frag_main(const device Data& coord [[buffer(0)]]) {
TEST_F(MslGeneratorImplTest,
Emit_FunctionDecoration_EntryPoints_WithGlobal_Nested_Return) {
auto* bar_var =
Var("bar", ast::StorageClass::kOutput, ty.f32(), nullptr,
ast::VariableDecorationList{create<ast::LocationDecoration>(1)});
td.RegisterVariableForTesting(bar_var);
AST().AddGlobalVariable(bar_var);
Global("bar", ast::StorageClass::kOutput, ty.f32(), nullptr,
ast::VariableDecorationList{create<ast::LocationDecoration>(1)});
auto* list = create<ast::BlockStatement>(ast::StatementList{
create<ast::ReturnStatement>(),
@ -893,14 +814,11 @@ TEST_F(MslGeneratorImplTest,
auto* s = ty.struct_("Data", str);
type::AccessControl ac(ast::AccessControl::kReadWrite, s);
auto* data_var =
Var("data", ast::StorageClass::kStorage, &ac, nullptr,
ast::VariableDecorationList{create<ast::BindingDecoration>(0),
create<ast::GroupDecoration>(0)});
Global("data", ast::StorageClass::kStorage, &ac, nullptr,
ast::VariableDecorationList{create<ast::BindingDecoration>(0),
create<ast::GroupDecoration>(0)});
AST().AddConstructedType(s);
td.RegisterVariableForTesting(data_var);
AST().AddGlobalVariable(data_var);
{
auto* var = Var("v", ast::StorageClass::kFunction, ty.f32(),

View File

@ -53,7 +53,7 @@ TEST_P(MslImportData_SingleParamTest, FloatScalar) {
auto* call = Call(param.name, 1.f);
// The call type determination will set the intrinsic data for the ident
ASSERT_TRUE(td.DetermineResultType(call)) << td.error();
WrapInFunction(call);
GeneratorImpl& gen = Build();
@ -89,7 +89,7 @@ INSTANTIATE_TEST_SUITE_P(MslGeneratorImplTest,
TEST_F(MslGeneratorImplTest, MslImportData_SingleParamTest_IntScalar) {
auto* expr = Call("abs", 1);
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
GeneratorImpl& gen = Build();
@ -102,7 +102,7 @@ TEST_P(MslImportData_DualParamTest, FloatScalar) {
auto param = GetParam();
auto* expr = Call(param.name, 1.0f, 2.0f);
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
GeneratorImpl& gen = Build();
@ -126,7 +126,7 @@ TEST_P(MslImportData_DualParam_VectorTest, FloatVector) {
auto* expr =
Call(param.name, vec3<f32>(1.f, 2.f, 3.f), vec3<f32>(4.f, 5.f, 6.f));
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
GeneratorImpl& gen = Build();
@ -144,7 +144,7 @@ TEST_P(MslImportData_DualParam_Int_Test, IntScalar) {
auto param = GetParam();
auto* expr = Call(param.name, 1, 2);
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
GeneratorImpl& gen = Build();
@ -161,7 +161,7 @@ TEST_P(MslImportData_TripleParamTest, FloatScalar) {
auto param = GetParam();
auto* expr = Call(param.name, 1.f, 2.f, 3.f);
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
GeneratorImpl& gen = Build();
@ -183,7 +183,7 @@ TEST_P(MslImportData_TripleParam_Int_Test, IntScalar) {
auto param = GetParam();
auto* expr = Call(param.name, 1, 2, 3);
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
GeneratorImpl& gen = Build();
@ -197,14 +197,11 @@ INSTANTIATE_TEST_SUITE_P(MslGeneratorImplTest,
MslImportData{"clamp", "clamp"}));
TEST_F(MslGeneratorImplTest, MslImportData_Determinant) {
auto* var = Var("var", ast::StorageClass::kFunction, ty.mat3x3<f32>());
AST().AddGlobalVariable(var);
Global("var", ast::StorageClass::kFunction, ty.mat3x3<f32>());
auto* expr = Call("determinant", "var");
// Register the global
ASSERT_TRUE(td.Determine()) << td.error();
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
GeneratorImpl& gen = Build();

View File

@ -158,24 +158,17 @@ TEST_P(MslIntrinsicTest, Emit) {
auto* call = GenerateCall(param.intrinsic, param.type, this);
ASSERT_NE(nullptr, call) << "Unhandled intrinsic";
WrapInFunction(call);
Global("f1", ast::StorageClass::kFunction, ty.vec2<float>());
Global("f2", ast::StorageClass::kFunction, ty.vec2<float>());
Global("f3", ast::StorageClass::kFunction, ty.vec2<float>());
Global("u1", ast::StorageClass::kFunction, ty.vec2<unsigned int>());
Global("u2", ast::StorageClass::kFunction, ty.vec2<unsigned int>());
Global("u3", ast::StorageClass::kFunction, ty.vec2<unsigned int>());
Global("b1", ast::StorageClass::kFunction, ty.vec2<bool>());
Global("m1", ast::StorageClass::kFunction, ty.mat2x2<float>());
auto* f1 = Var("f1", ast::StorageClass::kFunction, ty.vec2<float>());
auto* f2 = Var("f2", ast::StorageClass::kFunction, ty.vec2<float>());
auto* f3 = Var("f3", ast::StorageClass::kFunction, ty.vec2<float>());
auto* u1 = Var("u1", ast::StorageClass::kFunction, ty.vec2<unsigned int>());
auto* u2 = Var("u2", ast::StorageClass::kFunction, ty.vec2<unsigned int>());
auto* u3 = Var("u3", ast::StorageClass::kFunction, ty.vec2<unsigned int>());
auto* b1 = Var("b1", ast::StorageClass::kFunction, ty.vec2<bool>());
auto* m1 = Var("m1", ast::StorageClass::kFunction, ty.mat2x2<float>());
td.RegisterVariableForTesting(f1);
td.RegisterVariableForTesting(f2);
td.RegisterVariableForTesting(f3);
td.RegisterVariableForTesting(u1);
td.RegisterVariableForTesting(u2);
td.RegisterVariableForTesting(u3);
td.RegisterVariableForTesting(b1);
td.RegisterVariableForTesting(m1);
ASSERT_TRUE(td.DetermineResultType(call)) << td.error();
GeneratorImpl& gen = Build();
EXPECT_EQ(
@ -270,15 +263,11 @@ INSTANTIATE_TEST_SUITE_P(
"metal::trunc"}));
TEST_F(MslGeneratorImplTest, Intrinsic_Call) {
Global("param1", ast::StorageClass::kFunction, ty.vec2<f32>());
Global("param2", ast::StorageClass::kFunction, ty.vec2<f32>());
auto* call = Call("dot", "param1", "param2");
auto* v1 = Var("param1", ast::StorageClass::kFunction, ty.vec2<f32>());
auto* v2 = Var("param2", ast::StorageClass::kFunction, ty.vec2<f32>());
td.RegisterVariableForTesting(v1);
td.RegisterVariableForTesting(v2);
ASSERT_TRUE(td.DetermineResultType(call)) << td.error();
WrapInFunction(call);
GeneratorImpl& gen = Build();

View File

@ -305,12 +305,7 @@ std::string expected_texture_overload(
} // NOLINT - Ignore the length of this function
class MslGeneratorIntrinsicTextureTest
: public TestParamHelper<ast::intrinsic::test::TextureOverloadCase> {
protected:
void OnVariableBuilt(ast::Variable* var) override {
td.RegisterVariableForTesting(var);
}
};
: public TestParamHelper<ast::intrinsic::test::TextureOverloadCase> {};
TEST_P(MslGeneratorIntrinsicTextureTest, Call) {
auto param = GetParam();
@ -320,9 +315,7 @@ TEST_P(MslGeneratorIntrinsicTextureTest, Call) {
auto* call =
create<ast::CallExpression>(Expr(param.function), param.args(this));
ASSERT_TRUE(td.Determine()) << td.error();
ASSERT_TRUE(td.DetermineResultType(call)) << td.error();
WrapInFunction(call);
GeneratorImpl& gen = Build();

View File

@ -40,6 +40,7 @@ TEST_F(MslGeneratorImplTest, Emit_Loop) {
create<ast::DiscardStatement>(),
});
auto* l = create<ast::LoopStatement>(body, nullptr);
WrapInFunction(l);
GeneratorImpl& gen = Build();
@ -60,6 +61,7 @@ TEST_F(MslGeneratorImplTest, Emit_LoopWithContinuing) {
create<ast::ReturnStatement>(),
});
auto* l = create<ast::LoopStatement>(body, continuing);
WrapInFunction(l);
GeneratorImpl& gen = Build();
@ -98,6 +100,7 @@ TEST_F(MslGeneratorImplTest, Emit_LoopNestedWithContinuing) {
});
auto* outer = create<ast::LoopStatement>(body, continuing);
WrapInFunction(outer);
GeneratorImpl& gen = Build();
@ -163,6 +166,7 @@ TEST_F(MslGeneratorImplTest, Emit_LoopWithVarUsedInContinuing) {
});
auto* outer = create<ast::LoopStatement>(body, continuing);
WrapInFunction(outer);
GeneratorImpl& gen = Build();

View File

@ -30,6 +30,7 @@ using MslGeneratorImplTest = TestHelper;
TEST_F(MslGeneratorImplTest, EmitExpression_MemberAccessor) {
auto* expr = MemberAccessor("str", "mem");
WrapInFunction(expr);
GeneratorImpl& gen = Build();
@ -38,12 +39,10 @@ TEST_F(MslGeneratorImplTest, EmitExpression_MemberAccessor) {
}
TEST_F(MslGeneratorImplTest, EmitExpression_MemberAccessor_Swizzle_xyz) {
auto* vec = Var("my_vec", ast::StorageClass::kPrivate, ty.vec4<f32>());
td.RegisterVariableForTesting(vec);
Global("my_vec", ast::StorageClass::kPrivate, ty.vec4<f32>());
auto* expr = MemberAccessor("my_vec", "xyz");
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.EmitExpression(expr)) << gen.error();
@ -51,11 +50,10 @@ TEST_F(MslGeneratorImplTest, EmitExpression_MemberAccessor_Swizzle_xyz) {
}
TEST_F(MslGeneratorImplTest, EmitExpression_MemberAccessor_Swizzle_gbr) {
auto* vec = Var("my_vec", ast::StorageClass::kPrivate, ty.vec4<f32>());
td.RegisterVariableForTesting(vec);
Global("my_vec", ast::StorageClass::kPrivate, ty.vec4<f32>());
auto* expr = MemberAccessor("my_vec", "gbr");
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.EmitExpression(expr)) << gen.error();

View File

@ -421,16 +421,17 @@ using MslStorageTexturesTest = TestParamHelper<MslStorageTextureData>;
TEST_P(MslStorageTexturesTest, Emit) {
auto params = GetParam();
type::StorageTexture s(params.dim, type::ImageFormat::kR16Float);
type::AccessControl ac(params.ro ? ast::AccessControl::kReadOnly
: ast::AccessControl::kWriteOnly,
&s);
ASSERT_TRUE(td.DetermineStorageTextureSubtype(&s)) << td.error();
auto* s =
create<type::StorageTexture>(params.dim, type::ImageFormat::kR16Float);
auto* ac =
create<type::AccessControl>(params.ro ? ast::AccessControl::kReadOnly
: ast::AccessControl::kWriteOnly,
s);
Global("test_var", ast::StorageClass::kNone, ac);
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.EmitType(&ac, "")) << gen.error();
ASSERT_TRUE(gen.EmitType(ac, "")) << gen.error();
EXPECT_EQ(gen.result(), params.result);
}
INSTANTIATE_TEST_SUITE_P(

View File

@ -43,6 +43,7 @@ using MslGeneratorImplTest = TestHelper;
TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement) {
auto* var = Var("a", ast::StorageClass::kNone, ty.f32());
auto* stmt = create<ast::VariableDeclStatement>(var);
WrapInFunction(stmt);
GeneratorImpl& gen = Build();
@ -55,6 +56,7 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement) {
TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Const) {
auto* var = Const("a", ast::StorageClass::kNone, ty.f32());
auto* stmt = create<ast::VariableDeclStatement>(var);
WrapInFunction(stmt);
GeneratorImpl& gen = Build();
@ -69,6 +71,7 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Array) {
auto* var = Var("a", ast::StorageClass::kNone, &ary);
auto* stmt = create<ast::VariableDeclStatement>(var);
WrapInFunction(stmt);
GeneratorImpl& gen = Build();
@ -87,6 +90,7 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Struct) {
auto* s = ty.struct_("S", str);
auto* var = Var("a", ast::StorageClass::kNone, s);
auto* stmt = create<ast::VariableDeclStatement>(var);
WrapInFunction(stmt);
GeneratorImpl& gen = Build();
@ -100,6 +104,7 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Struct) {
TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Vector) {
auto* var = Var("a", ast::StorageClass::kFunction, ty.vec2<f32>());
auto* stmt = create<ast::VariableDeclStatement>(var);
WrapInFunction(stmt);
GeneratorImpl& gen = Build();
@ -113,6 +118,7 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Matrix) {
auto* var = Var("a", ast::StorageClass::kFunction, ty.mat3x2<f32>());
auto* stmt = create<ast::VariableDeclStatement>(var);
WrapInFunction(stmt);
GeneratorImpl& gen = Build();
@ -125,6 +131,7 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Matrix) {
TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Private) {
auto* var = Var("a", ast::StorageClass::kPrivate, ty.f32());
auto* stmt = create<ast::VariableDeclStatement>(var);
WrapInFunction(stmt);
GeneratorImpl& gen = Build();
@ -138,6 +145,7 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Initializer_Private) {
auto* var = Var("a", ast::StorageClass::kNone, ty.f32(), Expr("initializer"),
ast::VariableDecorationList{});
auto* stmt = create<ast::VariableDeclStatement>(var);
WrapInFunction(stmt);
GeneratorImpl& gen = Build();
@ -152,6 +160,7 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Initializer_ZeroVec) {
auto* var = Var("a", ast::StorageClass::kNone, ty.vec3<f32>(), zero_vec,
ast::VariableDecorationList{});
auto* stmt = create<ast::VariableDeclStatement>(var);
WrapInFunction(stmt);
GeneratorImpl& gen = Build();

View File

@ -32,7 +32,7 @@ namespace msl {
template <typename BASE>
class TestHelperBase : public BASE, public ProgramBuilder {
public:
TestHelperBase() : td(this) {}
TestHelperBase() = default;
~TestHelperBase() = default;
/// Builds and returns a GeneratorImpl from the program.
@ -48,8 +48,6 @@ class TestHelperBase : public BASE, public ProgramBuilder {
return *gen_;
}
/// The type determiner
TypeDeterminer td;
/// The program built with a call to Build()
std::unique_ptr<Program> program;

View File

@ -49,14 +49,13 @@ TEST_F(BuilderTest, ArrayAccessor) {
// vec3<f32> ary;
// ary[1] -> ptr<f32>
auto* var = Var("ary", ast::StorageClass::kFunction, ty.vec3<f32>());
auto* var = Global("ary", ast::StorageClass::kFunction, ty.vec3<f32>());
auto* ary = Expr("ary");
auto* idx_expr = Expr(1);
auto* expr = IndexAccessor(ary, idx_expr);
td.RegisterVariableForTesting(var);
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
spirv::Builder& b = Build();
@ -86,17 +85,14 @@ TEST_F(BuilderTest, Accessor_Array_LoadIndex) {
// idx : i32;
// ary[idx] -> ptr<f32>
auto* var = Var("ary", ast::StorageClass::kFunction, ty.vec3<f32>());
auto* idx = Var("idx", ast::StorageClass::kFunction, ty.i32());
auto* var = Global("ary", ast::StorageClass::kFunction, ty.vec3<f32>());
auto* idx = Global("idx", ast::StorageClass::kFunction, ty.i32());
auto* ary = Expr("ary");
auto* idx_expr = Expr("idx");
auto* expr = IndexAccessor(ary, idx_expr);
td.RegisterVariableForTesting(var);
td.RegisterVariableForTesting(idx);
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
spirv::Builder& b = Build();
@ -129,14 +125,12 @@ TEST_F(BuilderTest, ArrayAccessor_Dynamic) {
// vec3<f32> ary;
// ary[1 + 2] -> ptr<f32>
auto* var = Var("ary", ast::StorageClass::kFunction, ty.vec3<f32>());
auto* var = Global("ary", ast::StorageClass::kFunction, ty.vec3<f32>());
auto* ary = Expr("ary");
auto* expr = IndexAccessor(ary, Add(1, 2));
td.RegisterVariableForTesting(var);
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
spirv::Builder& b = Build();
@ -169,12 +163,10 @@ TEST_F(BuilderTest, ArrayAccessor_MultiLevel) {
// ary = array<vec3<f32>, 4>
// ary[3][2];
auto* var = Var("ary", ast::StorageClass::kFunction, &ary4);
auto* var = Global("ary", ast::StorageClass::kFunction, &ary4);
auto* expr = IndexAccessor(IndexAccessor("ary", 3), 2);
td.RegisterVariableForTesting(var);
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
spirv::Builder& b = Build();
@ -209,12 +201,10 @@ TEST_F(BuilderTest, Accessor_ArrayWithSwizzle) {
// var a : array<vec3<f32>, 4>;
// a[2].xy;
auto* var = Var("ary", ast::StorageClass::kFunction, &ary4);
auto* var = Global("ary", ast::StorageClass::kFunction, &ary4);
auto* expr = MemberAccessor(IndexAccessor("ary", 2), "xy");
td.RegisterVariableForTesting(var);
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
spirv::Builder& b = Build();
@ -257,12 +247,10 @@ TEST_F(BuilderTest, MemberAccessor) {
ast::StructDecorationList{});
auto* s_type = ty.struct_("my_struct", s);
auto* var = Var("ident", ast::StorageClass::kFunction, s_type);
auto* var = Global("ident", ast::StorageClass::kFunction, s_type);
auto* expr = MemberAccessor("ident", "b");
td.RegisterVariableForTesting(var);
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
spirv::Builder& b = Build();
@ -307,11 +295,9 @@ TEST_F(BuilderTest, MemberAccessor_Nested) {
create<ast::Struct>(ast::StructMemberList{Member("inner", inner_struct)},
ast::StructDecorationList{}));
auto* var = Var("ident", ast::StorageClass::kFunction, s_type);
auto* var = Global("ident", ast::StorageClass::kFunction, s_type);
auto* expr = MemberAccessor(MemberAccessor("ident", "inner"), "a");
td.RegisterVariableForTesting(var);
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
spirv::Builder& b = Build();
@ -359,11 +345,9 @@ TEST_F(BuilderTest, MemberAccessor_Nested_WithAlias) {
create<ast::Struct>(ast::StructMemberList{Member("inner", alias)},
ast::StructDecorationList{}));
auto* var = Var("ident", ast::StorageClass::kFunction, s_type);
auto* var = Global("ident", ast::StorageClass::kFunction, s_type);
auto* expr = MemberAccessor(MemberAccessor("ident", "inner"), "a");
td.RegisterVariableForTesting(var);
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
spirv::Builder& b = Build();
@ -409,12 +393,10 @@ TEST_F(BuilderTest, MemberAccessor_Nested_Assignment_LHS) {
create<ast::Struct>(ast::StructMemberList{Member("inner", inner_struct)},
ast::StructDecorationList{}));
auto* var = Var("ident", ast::StorageClass::kFunction, s_type);
auto* var = Global("ident", ast::StorageClass::kFunction, s_type);
auto* expr = create<ast::AssignmentStatement>(
MemberAccessor(MemberAccessor("ident", "inner"), "a"), Expr(2.0f));
td.RegisterVariableForTesting(var);
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
spirv::Builder& b = Build();
@ -463,15 +445,12 @@ TEST_F(BuilderTest, MemberAccessor_Nested_Assignment_RHS) {
create<ast::Struct>(ast::StructMemberList{Member("inner", inner_struct)},
ast::StructDecorationList{}));
auto* var = Var("ident", ast::StorageClass::kFunction, s_type);
auto* store = Var("store", ast::StorageClass::kFunction, ty.f32());
auto* var = Global("ident", ast::StorageClass::kFunction, s_type);
auto* store = Global("store", ast::StorageClass::kFunction, ty.f32());
auto* rhs = MemberAccessor(MemberAccessor("ident", "inner"), "a");
auto* expr = create<ast::AssignmentStatement>(Expr("store"), rhs);
td.RegisterVariableForTesting(var);
td.RegisterVariableForTesting(store);
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
spirv::Builder& b = Build();
@ -505,12 +484,10 @@ OpStore %7 %13
TEST_F(BuilderTest, MemberAccessor_Swizzle_Single) {
// ident.y
auto* var = Var("ident", ast::StorageClass::kFunction, ty.vec3<f32>());
auto* var = Global("ident", ast::StorageClass::kFunction, ty.vec3<f32>());
auto* expr = MemberAccessor("ident", "y");
td.RegisterVariableForTesting(var);
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
spirv::Builder& b = Build();
@ -538,12 +515,10 @@ TEST_F(BuilderTest, MemberAccessor_Swizzle_Single) {
TEST_F(BuilderTest, MemberAccessor_Swizzle_MultipleNames) {
// ident.yx
auto* var = Var("ident", ast::StorageClass::kFunction, ty.vec3<f32>());
auto* var = Global("ident", ast::StorageClass::kFunction, ty.vec3<f32>());
auto* expr = MemberAccessor("ident", "yx");
td.RegisterVariableForTesting(var);
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
spirv::Builder& b = Build();
@ -570,12 +545,10 @@ TEST_F(BuilderTest, MemberAccessor_Swizzle_MultipleNames) {
TEST_F(BuilderTest, MemberAccessor_Swizzle_of_Swizzle) {
// ident.yxz.xz
auto* var = Var("ident", ast::StorageClass::kFunction, ty.vec3<f32>());
auto* var = Global("ident", ast::StorageClass::kFunction, ty.vec3<f32>());
auto* expr = MemberAccessor(MemberAccessor("ident", "yxz"), "xz");
td.RegisterVariableForTesting(var);
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
spirv::Builder& b = Build();
@ -603,12 +576,10 @@ TEST_F(BuilderTest, MemberAccessor_Swizzle_of_Swizzle) {
TEST_F(BuilderTest, MemberAccessor_Member_of_Swizzle) {
// ident.yxz.x
auto* var = Var("ident", ast::StorageClass::kFunction, ty.vec3<f32>());
auto* var = Global("ident", ast::StorageClass::kFunction, ty.vec3<f32>());
auto* expr = MemberAccessor(MemberAccessor("ident", "yxz"), "x");
td.RegisterVariableForTesting(var);
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
spirv::Builder& b = Build();
@ -635,12 +606,10 @@ TEST_F(BuilderTest, MemberAccessor_Member_of_Swizzle) {
TEST_F(BuilderTest, MemberAccessor_Array_of_Swizzle) {
// index.yxz[1]
auto* var = Var("ident", ast::StorageClass::kFunction, ty.vec3<f32>());
auto* var = Global("ident", ast::StorageClass::kFunction, ty.vec3<f32>());
auto* expr = IndexAccessor(MemberAccessor("ident", "yxz"), 1);
td.RegisterVariableForTesting(var);
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
spirv::Builder& b = Build();
@ -693,7 +662,7 @@ TEST_F(BuilderTest, Accessor_Mixed_ArrayAndMember) {
auto* a_type = ty.struct_("A", s);
type::Array a_ary_type(a_type, 2, ast::ArrayDecorationList{});
auto* var = Var("index", ast::StorageClass::kFunction, &a_ary_type);
auto* var = Global("index", ast::StorageClass::kFunction, &a_ary_type);
auto* expr = MemberAccessor(
MemberAccessor(
MemberAccessor(
@ -702,9 +671,7 @@ TEST_F(BuilderTest, Accessor_Mixed_ArrayAndMember) {
"bar"),
"baz"),
"yx");
td.RegisterVariableForTesting(var);
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
spirv::Builder& b = Build();
@ -751,16 +718,14 @@ TEST_F(BuilderTest, Accessor_Array_Of_Vec) {
type::Array arr(ty.vec2<f32>(), 3, ast::ArrayDecorationList{});
auto* var = Const("pos", ast::StorageClass::kPrivate, &arr,
Construct(&arr, vec2<f32>(0.0f, 0.5f),
vec2<f32>(-0.5f, -0.5f), vec2<f32>(0.5f, -0.5f)),
{});
auto* var =
GlobalConst("pos", ast::StorageClass::kPrivate, &arr,
Construct(&arr, vec2<f32>(0.0f, 0.5f),
vec2<f32>(-0.5f, -0.5f), vec2<f32>(0.5f, -0.5f)),
ast::VariableDecorationList{});
auto* expr = IndexAccessor("pos", 1u);
td.RegisterVariableForTesting(var);
ASSERT_TRUE(td.DetermineResultType(var->constructor())) << td.error();
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
spirv::Builder& b = Build();
@ -798,14 +763,11 @@ TEST_F(BuilderTest, Accessor_Const_Vec) {
// const pos : vec2<f32> = vec2<f32>(0.0, 0.5);
// pos[1]
auto* var = Const("pos", ast::StorageClass::kPrivate, ty.vec2<f32>(),
vec2<f32>(0.0f, 0.5f), {});
auto* var = GlobalConst("pos", ast::StorageClass::kPrivate, ty.vec2<f32>(),
vec2<f32>(0.0f, 0.5f), ast::VariableDecorationList{});
auto* expr = IndexAccessor("pos", 1u);
td.RegisterVariableForTesting(var);
ASSERT_TRUE(td.DetermineResultType(var->constructor())) << td.error();
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
spirv::Builder& b = Build();

View File

@ -42,12 +42,11 @@ namespace {
using BuilderTest = TestHelper;
TEST_F(BuilderTest, Assign_Var) {
auto* v = Var("var", ast::StorageClass::kOutput, ty.f32());
auto* v = Global("var", ast::StorageClass::kOutput, ty.f32());
auto* assign = create<ast::AssignmentStatement>(Expr("var"), Expr(1.f));
td.RegisterVariableForTesting(v);
ASSERT_TRUE(td.DetermineResultType(assign)) << td.error();
WrapInFunction(assign);
spirv::Builder& b = Build();
@ -71,12 +70,11 @@ TEST_F(BuilderTest, Assign_Var) {
}
TEST_F(BuilderTest, Assign_Var_OutsideFunction_IsError) {
auto* v = Var("var", ast::StorageClass::kOutput, ty.f32());
auto* v = Global("var", ast::StorageClass::kOutput, ty.f32());
auto* assign = create<ast::AssignmentStatement>(Expr("var"), Expr(1.f));
td.RegisterVariableForTesting(v);
ASSERT_TRUE(td.DetermineResultType(assign)) << td.error();
WrapInFunction(assign);
spirv::Builder& b = Build();
@ -91,14 +89,12 @@ TEST_F(BuilderTest, Assign_Var_OutsideFunction_IsError) {
}
TEST_F(BuilderTest, Assign_Var_ZeroConstructor) {
auto* v = Var("var", ast::StorageClass::kOutput, ty.vec3<f32>());
auto* v = Global("var", ast::StorageClass::kOutput, ty.vec3<f32>());
auto* val = vec3<f32>();
auto* assign = create<ast::AssignmentStatement>(Expr("var"), val);
td.RegisterVariableForTesting(v);
ASSERT_TRUE(td.DetermineResultType(assign)) << td.error();
WrapInFunction(assign);
spirv::Builder& b = Build();
@ -124,11 +120,11 @@ TEST_F(BuilderTest, Assign_Var_ZeroConstructor) {
TEST_F(BuilderTest, Assign_Var_Complex_ConstructorWithExtract) {
auto* init = vec3<f32>(vec2<f32>(1.f, 2.f), 3.f);
auto* v = Var("var", ast::StorageClass::kOutput, ty.vec3<f32>());
auto* v = Global("var", ast::StorageClass::kOutput, ty.vec3<f32>());
auto* assign = create<ast::AssignmentStatement>(Expr("var"), init);
td.RegisterVariableForTesting(v);
ASSERT_TRUE(td.DetermineResultType(assign)) << td.error();
WrapInFunction(assign);
spirv::Builder& b = Build();
@ -161,11 +157,11 @@ OpStore %1 %13
TEST_F(BuilderTest, Assign_Var_Complex_Constructor) {
auto* init = vec3<f32>(1.f, 2.f, 3.f);
auto* v = Var("var", ast::StorageClass::kOutput, ty.vec3<f32>());
auto* v = Global("var", ast::StorageClass::kOutput, ty.vec3<f32>());
auto* assign = create<ast::AssignmentStatement>(Expr("var"), init);
td.RegisterVariableForTesting(v);
ASSERT_TRUE(td.DetermineResultType(assign)) << td.error();
WrapInFunction(assign);
spirv::Builder& b = Build();
@ -204,13 +200,12 @@ TEST_F(BuilderTest, Assign_StructMember) {
ast::StructDecorationList{});
auto* s_type = ty.struct_("my_struct", s);
auto* v = Var("ident", ast::StorageClass::kFunction, s_type);
auto* v = Global("ident", ast::StorageClass::kFunction, s_type);
auto* assign =
create<ast::AssignmentStatement>(MemberAccessor("ident", "b"), Expr(4.f));
td.RegisterVariableForTesting(v);
ASSERT_TRUE(td.DetermineResultType(assign)) << td.error();
WrapInFunction(assign);
spirv::Builder& b = Build();
@ -238,14 +233,12 @@ OpStore %8 %9
}
TEST_F(BuilderTest, Assign_Vector) {
auto* v = Var("var", ast::StorageClass::kOutput, ty.vec3<f32>());
auto* v = Global("var", ast::StorageClass::kOutput, ty.vec3<f32>());
auto* val = vec3<f32>(1.f, 1.f, 3.f);
auto* assign = create<ast::AssignmentStatement>(Expr("var"), val);
td.RegisterVariableForTesting(v);
ASSERT_TRUE(td.DetermineResultType(assign)) << td.error();
WrapInFunction(assign);
spirv::Builder& b = Build();
@ -274,13 +267,12 @@ TEST_F(BuilderTest, Assign_Vector) {
TEST_F(BuilderTest, Assign_Vector_MemberByName) {
// var.y = 1
auto* v = Var("var", ast::StorageClass::kOutput, ty.vec3<f32>());
auto* v = Global("var", ast::StorageClass::kOutput, ty.vec3<f32>());
auto* assign =
create<ast::AssignmentStatement>(MemberAccessor("var", "y"), Expr(1.f));
td.RegisterVariableForTesting(v);
ASSERT_TRUE(td.DetermineResultType(assign)) << td.error();
WrapInFunction(assign);
spirv::Builder& b = Build();
@ -311,13 +303,12 @@ OpStore %9 %10
TEST_F(BuilderTest, Assign_Vector_MemberByIndex) {
// var[1] = 1
auto* v = Var("var", ast::StorageClass::kOutput, ty.vec3<f32>());
auto* v = Global("var", ast::StorageClass::kOutput, ty.vec3<f32>());
auto* assign =
create<ast::AssignmentStatement>(IndexAccessor("var", 1), Expr(1.f));
td.RegisterVariableForTesting(v);
ASSERT_TRUE(td.DetermineResultType(assign)) << td.error();
WrapInFunction(assign);
spirv::Builder& b = Build();

View File

@ -59,7 +59,7 @@ TEST_P(BinaryArithSignedIntegerTest, Scalar) {
auto* expr = create<ast::BinaryExpression>(param.op, lhs, rhs);
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
spirv::Builder& b = Build();
@ -82,7 +82,7 @@ TEST_P(BinaryArithSignedIntegerTest, Vector) {
auto* expr = create<ast::BinaryExpression>(param.op, lhs, rhs);
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
spirv::Builder& b = Build();
@ -100,12 +100,11 @@ TEST_P(BinaryArithSignedIntegerTest, Vector) {
TEST_P(BinaryArithSignedIntegerTest, Scalar_Loads) {
auto param = GetParam();
auto* var = Var("param", ast::StorageClass::kFunction, ty.i32());
auto* var = Global("param", ast::StorageClass::kFunction, ty.i32());
auto* expr =
create<ast::BinaryExpression>(param.op, Expr("param"), Expr("param"));
td.RegisterVariableForTesting(var);
EXPECT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
spirv::Builder& b = Build();
@ -152,7 +151,7 @@ TEST_P(BinaryArithUnsignedIntegerTest, Scalar) {
auto* expr = create<ast::BinaryExpression>(param.op, lhs, rhs);
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
spirv::Builder& b = Build();
@ -174,7 +173,7 @@ TEST_P(BinaryArithUnsignedIntegerTest, Vector) {
auto* expr = create<ast::BinaryExpression>(param.op, lhs, rhs);
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
spirv::Builder& b = Build();
@ -213,7 +212,8 @@ TEST_P(BinaryArithFloatTest, Scalar) {
auto* expr = create<ast::BinaryExpression>(param.op, lhs, rhs);
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
spirv::Builder& b = Build();
b.push_function(Function{});
@ -235,7 +235,7 @@ TEST_P(BinaryArithFloatTest, Vector) {
auto* expr = create<ast::BinaryExpression>(param.op, lhs, rhs);
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
spirv::Builder& b = Build();
@ -268,7 +268,7 @@ TEST_P(BinaryCompareUnsignedIntegerTest, Scalar) {
auto* expr = create<ast::BinaryExpression>(param.op, lhs, rhs);
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
spirv::Builder& b = Build();
@ -292,7 +292,7 @@ TEST_P(BinaryCompareUnsignedIntegerTest, Vector) {
auto* expr = create<ast::BinaryExpression>(param.op, lhs, rhs);
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
spirv::Builder& b = Build();
@ -329,7 +329,7 @@ TEST_P(BinaryCompareSignedIntegerTest, Scalar) {
auto* expr = create<ast::BinaryExpression>(param.op, lhs, rhs);
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
spirv::Builder& b = Build();
@ -353,7 +353,7 @@ TEST_P(BinaryCompareSignedIntegerTest, Vector) {
auto* expr = create<ast::BinaryExpression>(param.op, lhs, rhs);
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
spirv::Builder& b = Build();
@ -390,7 +390,7 @@ TEST_P(BinaryCompareFloatTest, Scalar) {
auto* expr = create<ast::BinaryExpression>(param.op, lhs, rhs);
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
spirv::Builder& b = Build();
@ -414,7 +414,7 @@ TEST_P(BinaryCompareFloatTest, Vector) {
auto* expr = create<ast::BinaryExpression>(param.op, lhs, rhs);
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
spirv::Builder& b = Build();
@ -449,7 +449,7 @@ TEST_F(BuilderTest, Binary_Multiply_VectorScalar) {
auto* expr =
create<ast::BinaryExpression>(ast::BinaryOp::kMultiply, lhs, rhs);
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
spirv::Builder& b = Build();
@ -473,7 +473,7 @@ TEST_F(BuilderTest, Binary_Multiply_ScalarVector) {
auto* expr =
create<ast::BinaryExpression>(ast::BinaryOp::kMultiply, lhs, rhs);
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
spirv::Builder& b = Build();
@ -491,12 +491,12 @@ TEST_F(BuilderTest, Binary_Multiply_ScalarVector) {
}
TEST_F(BuilderTest, Binary_Multiply_MatrixScalar) {
auto* var = Var("mat", ast::StorageClass::kFunction, ty.mat3x3<f32>());
td.RegisterVariableForTesting(var);
auto* var = Global("mat", ast::StorageClass::kFunction, ty.mat3x3<f32>());
auto* expr = create<ast::BinaryExpression>(ast::BinaryOp::kMultiply,
Expr("mat"), Expr(1.f));
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
spirv::Builder& b = Build();
@ -519,13 +519,12 @@ TEST_F(BuilderTest, Binary_Multiply_MatrixScalar) {
}
TEST_F(BuilderTest, Binary_Multiply_ScalarMatrix) {
auto* var = Var("mat", ast::StorageClass::kFunction, ty.mat3x3<f32>());
td.RegisterVariableForTesting(var);
auto* var = Global("mat", ast::StorageClass::kFunction, ty.mat3x3<f32>());
auto* expr = create<ast::BinaryExpression>(ast::BinaryOp::kMultiply,
Expr(1.f), Expr("mat"));
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
spirv::Builder& b = Build();
@ -548,15 +547,13 @@ TEST_F(BuilderTest, Binary_Multiply_ScalarMatrix) {
}
TEST_F(BuilderTest, Binary_Multiply_MatrixVector) {
auto* var = Var("mat", ast::StorageClass::kFunction, ty.mat3x3<f32>());
auto* var = Global("mat", ast::StorageClass::kFunction, ty.mat3x3<f32>());
auto* rhs = vec3<f32>(1.f, 1.f, 1.f);
td.RegisterVariableForTesting(var);
auto* expr =
create<ast::BinaryExpression>(ast::BinaryOp::kMultiply, Expr("mat"), rhs);
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
spirv::Builder& b = Build();
@ -580,15 +577,13 @@ TEST_F(BuilderTest, Binary_Multiply_MatrixVector) {
}
TEST_F(BuilderTest, Binary_Multiply_VectorMatrix) {
auto* var = Var("mat", ast::StorageClass::kFunction, ty.mat3x3<f32>());
auto* var = Global("mat", ast::StorageClass::kFunction, ty.mat3x3<f32>());
auto* lhs = vec3<f32>(1.f, 1.f, 1.f);
td.RegisterVariableForTesting(var);
auto* expr =
create<ast::BinaryExpression>(ast::BinaryOp::kMultiply, lhs, Expr("mat"));
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
spirv::Builder& b = Build();
@ -612,13 +607,12 @@ TEST_F(BuilderTest, Binary_Multiply_VectorMatrix) {
}
TEST_F(BuilderTest, Binary_Multiply_MatrixMatrix) {
auto* var = Var("mat", ast::StorageClass::kFunction, ty.mat3x3<f32>());
td.RegisterVariableForTesting(var);
auto* var = Global("mat", ast::StorageClass::kFunction, ty.mat3x3<f32>());
auto* expr = create<ast::BinaryExpression>(ast::BinaryOp::kMultiply,
Expr("mat"), Expr("mat"));
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
spirv::Builder& b = Build();
@ -650,7 +644,7 @@ TEST_F(BuilderTest, Binary_LogicalAnd) {
auto* expr =
create<ast::BinaryExpression>(ast::BinaryOp::kLogicalAnd, lhs, rhs);
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
spirv::Builder& b = Build();
@ -680,18 +674,15 @@ OpBranch %7
}
TEST_F(BuilderTest, Binary_LogicalAnd_WithLoads) {
auto* a_var = Var("a", ast::StorageClass::kFunction, ty.bool_(), Expr(true),
ast::VariableDecorationList{});
auto* b_var = Var("b", ast::StorageClass::kFunction, ty.bool_(), Expr(false),
ast::VariableDecorationList{});
td.RegisterVariableForTesting(a_var);
td.RegisterVariableForTesting(b_var);
auto* a_var = Global("a", ast::StorageClass::kFunction, ty.bool_(),
Expr(true), ast::VariableDecorationList{});
auto* b_var = Global("b", ast::StorageClass::kFunction, ty.bool_(),
Expr(false), ast::VariableDecorationList{});
auto* expr = create<ast::BinaryExpression>(ast::BinaryOp::kLogicalAnd,
Expr("a"), Expr("b"));
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
spirv::Builder& b = Build();
@ -733,7 +724,7 @@ TEST_F(BuilderTest, Binary_logicalOr_Nested_LogicalAnd) {
auto* expr = create<ast::BinaryExpression>(ast::BinaryOp::kLogicalOr,
Expr(true), logical_and_expr);
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
spirv::Builder& b = Build();
@ -773,7 +764,7 @@ TEST_F(BuilderTest, Binary_logicalAnd_Nested_LogicalOr) {
auto* expr = create<ast::BinaryExpression>(ast::BinaryOp::kLogicalAnd,
Expr(true), logical_or_expr);
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
spirv::Builder& b = Build();
@ -812,7 +803,7 @@ TEST_F(BuilderTest, Binary_LogicalOr) {
auto* expr =
create<ast::BinaryExpression>(ast::BinaryOp::kLogicalOr, lhs, rhs);
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
spirv::Builder& b = Build();
@ -842,18 +833,15 @@ OpBranch %7
}
TEST_F(BuilderTest, Binary_LogicalOr_WithLoads) {
auto* a_var = Var("a", ast::StorageClass::kFunction, ty.bool_(), Expr(true),
ast::VariableDecorationList{});
auto* b_var = Var("b", ast::StorageClass::kFunction, ty.bool_(), Expr(false),
ast::VariableDecorationList{});
td.RegisterVariableForTesting(a_var);
td.RegisterVariableForTesting(b_var);
auto* a_var = Global("a", ast::StorageClass::kFunction, ty.bool_(),
Expr(true), ast::VariableDecorationList{});
auto* b_var = Global("b", ast::StorageClass::kFunction, ty.bool_(),
Expr(false), ast::VariableDecorationList{});
auto* expr = create<ast::BinaryExpression>(ast::BinaryOp::kLogicalOr,
Expr("a"), Expr("b"));
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
spirv::Builder& b = Build();

View File

@ -34,7 +34,7 @@ using BuilderTest = TestHelper;
TEST_F(BuilderTest, Bitcast) {
auto* bitcast = create<ast::BitcastExpression>(ty.u32(), Expr(2.4f));
ASSERT_TRUE(td.DetermineResultType(bitcast)) << td.error();
WrapInFunction(bitcast);
spirv::Builder& b = Build();
@ -53,7 +53,7 @@ TEST_F(BuilderTest, Bitcast) {
TEST_F(BuilderTest, Bitcast_DuplicateType) {
auto* bitcast = create<ast::BitcastExpression>(ty.f32(), Expr(2.4f));
ASSERT_TRUE(td.DetermineResultType(bitcast)) << td.error();
WrapInFunction(bitcast);
spirv::Builder& b = Build();

View File

@ -47,7 +47,7 @@ TEST_F(BuilderTest, Block) {
create<ast::AssignmentStatement>(Expr("var"), Expr(1.f)), inner,
create<ast::AssignmentStatement>(Expr("var"), Expr(3.f))});
ASSERT_TRUE(td.DetermineResultType(outer)) << td.error();
WrapInFunction(outer);
spirv::Builder& b = Build();

View File

@ -53,9 +53,8 @@ TEST_F(BuilderTest, Expression_Call) {
ast::FunctionDecorationList{});
auto* expr = Call("a_func", 1.f, 1.f);
ASSERT_TRUE(td.DetermineFunction(func)) << td.error();
ASSERT_TRUE(td.DetermineFunction(a_func)) << td.error();
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
spirv::Builder& b = Build();
@ -104,9 +103,7 @@ TEST_F(BuilderTest, Statement_Call) {
auto* expr = create<ast::CallStatement>(Call("a_func", 1.f, 1.f));
ASSERT_TRUE(td.DetermineFunction(func)) << td.error();
ASSERT_TRUE(td.DetermineFunction(a_func)) << td.error();
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
spirv::Builder& b = Build();

View File

@ -64,8 +64,7 @@ TEST_F(SpvBuilderConstructorTest, Const) {
TEST_F(SpvBuilderConstructorTest, Type_WithCasts_OutsideFunction_IsError) {
auto* t = Construct<f32>(Construct<u32>(1));
EXPECT_TRUE(td.DetermineResultType(t)) << td.error();
WrapInFunction(t);
spirv::Builder& b = Build();
@ -78,8 +77,7 @@ TEST_F(SpvBuilderConstructorTest, Type_WithCasts_OutsideFunction_IsError) {
TEST_F(SpvBuilderConstructorTest, Type) {
auto* t = vec3<f32>(1.0f, 1.0f, 3.0f);
EXPECT_TRUE(td.DetermineResultType(t)) << td.error();
WrapInFunction(t);
spirv::Builder& b = Build();
@ -96,8 +94,7 @@ TEST_F(SpvBuilderConstructorTest, Type) {
TEST_F(SpvBuilderConstructorTest, Type_WithCasts) {
auto* t = vec2<f32>(Construct<f32>(1), Construct<f32>(1));
EXPECT_TRUE(td.DetermineResultType(t)) << td.error();
WrapInFunction(t);
spirv::Builder& b = Build();
@ -124,8 +121,7 @@ TEST_F(SpvBuilderConstructorTest, Type_WithAlias) {
auto* alias = ty.alias("Int", ty.i32());
auto* cast = Construct(alias, 2.3f);
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
WrapInFunction(cast);
spirv::Builder& b = Build();
@ -142,11 +138,10 @@ TEST_F(SpvBuilderConstructorTest, Type_WithAlias) {
}
TEST_F(SpvBuilderConstructorTest, Type_IdentifierExpression_Param) {
auto* var = Var("ident", ast::StorageClass::kFunction, ty.f32());
auto* var = Global("ident", ast::StorageClass::kFunction, ty.f32());
auto* t = vec2<f32>(1.0f, "ident");
EXPECT_TRUE(td.DetermineResultType(t)) << td.error();
WrapInFunction(t);
spirv::Builder& b = Build();
@ -174,8 +169,7 @@ TEST_F(SpvBuilderConstructorTest, Type_IdentifierExpression_Param) {
TEST_F(SpvBuilderConstructorTest, Vector_Bitcast_Params) {
auto* t = vec2<u32>(1, 1);
EXPECT_TRUE(td.DetermineResultType(t)) << td.error();
WrapInFunction(t);
spirv::Builder& b = Build();
@ -202,8 +196,7 @@ TEST_F(SpvBuilderConstructorTest, Type_NonConst_Value_Fails) {
Expr(3.0f));
auto* t = vec2<f32>(1.0f, rel);
EXPECT_TRUE(td.DetermineResultType(t)) << td.error();
WrapInFunction(t);
spirv::Builder& b = Build();
@ -214,8 +207,7 @@ TEST_F(SpvBuilderConstructorTest, Type_NonConst_Value_Fails) {
TEST_F(SpvBuilderConstructorTest, Type_Bool_With_Bool) {
auto* cast = Construct<bool>(true);
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
WrapInFunction(cast);
spirv::Builder& b = Build();
@ -232,8 +224,7 @@ TEST_F(SpvBuilderConstructorTest, Type_Bool_With_Bool) {
TEST_F(SpvBuilderConstructorTest, Type_I32_With_I32) {
auto* cast = Construct<i32>(2);
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
WrapInFunction(cast);
spirv::Builder& b = Build();
@ -248,8 +239,7 @@ TEST_F(SpvBuilderConstructorTest, Type_I32_With_I32) {
TEST_F(SpvBuilderConstructorTest, Type_U32_With_U32) {
auto* cast = Construct<u32>(2u);
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
WrapInFunction(cast);
spirv::Builder& b = Build();
@ -264,8 +254,7 @@ TEST_F(SpvBuilderConstructorTest, Type_U32_With_U32) {
TEST_F(SpvBuilderConstructorTest, Type_F32_With_F32) {
auto* cast = Construct<f32>(2.0f);
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
WrapInFunction(cast);
spirv::Builder& b = Build();
@ -280,8 +269,7 @@ TEST_F(SpvBuilderConstructorTest, Type_F32_With_F32) {
TEST_F(SpvBuilderConstructorTest, Type_Vec2_With_F32_F32) {
auto* cast = vec2<f32>(2.0f, 2.0f);
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
WrapInFunction(cast);
spirv::Builder& b = Build();
@ -298,8 +286,7 @@ TEST_F(SpvBuilderConstructorTest, Type_Vec2_With_F32_F32) {
TEST_F(SpvBuilderConstructorTest, Type_Vec2_With_Vec2) {
auto* value = vec2<f32>(2.0f, 2.0f);
auto* cast = vec2<f32>(value);
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
WrapInFunction(cast);
spirv::Builder& b = Build();
@ -316,8 +303,7 @@ TEST_F(SpvBuilderConstructorTest, Type_Vec2_With_Vec2) {
TEST_F(SpvBuilderConstructorTest, Type_Vec3_With_F32_F32_F32) {
auto* cast = vec3<f32>(2.0f, 2.0f, 2.0f);
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
WrapInFunction(cast);
spirv::Builder& b = Build();
@ -333,8 +319,7 @@ TEST_F(SpvBuilderConstructorTest, Type_Vec3_With_F32_F32_F32) {
TEST_F(SpvBuilderConstructorTest, Type_Vec3_With_F32_Vec2) {
auto* cast = vec3<f32>(2.0f, vec2<f32>(2.0f, 2.0f));
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
WrapInFunction(cast);
spirv::Builder& b = Build();
@ -356,8 +341,7 @@ TEST_F(SpvBuilderConstructorTest, Type_Vec3_With_F32_Vec2) {
TEST_F(SpvBuilderConstructorTest, Type_Vec3_With_Vec2_F32) {
auto* cast = vec3<f32>(vec2<f32>(2.0f, 2.0f), 2.0f);
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
WrapInFunction(cast);
spirv::Builder& b = Build();
@ -380,8 +364,7 @@ TEST_F(SpvBuilderConstructorTest, Type_Vec3_With_Vec2_F32) {
TEST_F(SpvBuilderConstructorTest, Type_Vec3_With_Vec3) {
auto* value = vec3<f32>(2.0f, 2.0f, 2.0f);
auto* cast = vec3<f32>(value);
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
WrapInFunction(cast);
spirv::Builder& b = Build();
@ -398,8 +381,7 @@ TEST_F(SpvBuilderConstructorTest, Type_Vec3_With_Vec3) {
TEST_F(SpvBuilderConstructorTest, Type_Vec4_With_F32_F32_F32_F32) {
auto* cast = vec4<f32>(2.0f, 2.0f, 2.0f, 2.0f);
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
WrapInFunction(cast);
spirv::Builder& b = Build();
@ -415,8 +397,7 @@ TEST_F(SpvBuilderConstructorTest, Type_Vec4_With_F32_F32_F32_F32) {
TEST_F(SpvBuilderConstructorTest, Type_Vec4_With_F32_F32_Vec2) {
auto* cast = vec4<f32>(2.0f, 2.0f, vec2<f32>(2.0f, 2.0f));
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
WrapInFunction(cast);
spirv::Builder& b = Build();
@ -438,8 +419,7 @@ TEST_F(SpvBuilderConstructorTest, Type_Vec4_With_F32_F32_Vec2) {
TEST_F(SpvBuilderConstructorTest, Type_Vec4_With_F32_Vec2_F32) {
auto* cast = vec4<f32>(2.0f, vec2<f32>(2.0f, 2.0f), 2.0f);
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
WrapInFunction(cast);
spirv::Builder& b = Build();
@ -461,8 +441,7 @@ TEST_F(SpvBuilderConstructorTest, Type_Vec4_With_F32_Vec2_F32) {
TEST_F(SpvBuilderConstructorTest, Type_Vec4_With_Vec2_F32_F32) {
auto* cast = vec4<f32>(vec2<f32>(2.0f, 2.0f), 2.0f, 2.0f);
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
WrapInFunction(cast);
spirv::Builder& b = Build();
@ -484,8 +463,7 @@ TEST_F(SpvBuilderConstructorTest, Type_Vec4_With_Vec2_F32_F32) {
TEST_F(SpvBuilderConstructorTest, Type_Vec4_With_Vec2_Vec2) {
auto* cast = vec4<f32>(vec2<f32>(2.0f, 2.0f), vec2<f32>(2.0f, 2.0f));
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
WrapInFunction(cast);
spirv::Builder& b = Build();
@ -509,8 +487,7 @@ TEST_F(SpvBuilderConstructorTest, Type_Vec4_With_Vec2_Vec2) {
TEST_F(SpvBuilderConstructorTest, Type_Vec4_With_F32_Vec3) {
auto* cast = vec4<f32>(2.0f, vec3<f32>(2.0f, 2.0f, 2.0f));
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
WrapInFunction(cast);
spirv::Builder& b = Build();
@ -533,8 +510,7 @@ TEST_F(SpvBuilderConstructorTest, Type_Vec4_With_F32_Vec3) {
TEST_F(SpvBuilderConstructorTest, Type_Vec4_With_Vec3_F32) {
auto* cast = vec4<f32>(vec3<f32>(2.0f, 2.0f, 2.0f), 2.0f);
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
WrapInFunction(cast);
spirv::Builder& b = Build();
@ -558,8 +534,7 @@ TEST_F(SpvBuilderConstructorTest, Type_Vec4_With_Vec3_F32) {
TEST_F(SpvBuilderConstructorTest, Type_Vec4_With_Vec4) {
auto* value = vec4<f32>(2.0f, 2.0f, 2.0f, 2.0f);
auto* cast = vec4<f32>(value);
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
WrapInFunction(cast);
spirv::Builder& b = Build();
@ -576,8 +551,7 @@ TEST_F(SpvBuilderConstructorTest, Type_Vec4_With_Vec4) {
TEST_F(SpvBuilderConstructorTest, Type_ModuleScope_Vec2_With_Vec2) {
auto* cast = vec2<f32>(vec2<f32>(2.0f, 2.0f));
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
WrapInFunction(cast);
spirv::Builder& b = Build();
@ -593,8 +567,7 @@ TEST_F(SpvBuilderConstructorTest, Type_ModuleScope_Vec2_With_Vec2) {
TEST_F(SpvBuilderConstructorTest, Type_ModuleScope_Vec3_With_Vec3) {
auto* cast = vec3<f32>(vec3<f32>(2.0f, 2.0f, 2.0f));
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
WrapInFunction(cast);
spirv::Builder& b = Build();
@ -610,8 +583,7 @@ TEST_F(SpvBuilderConstructorTest, Type_ModuleScope_Vec3_With_Vec3) {
TEST_F(SpvBuilderConstructorTest, Type_ModuleScope_Vec4_With_Vec4) {
auto* cast = vec4<f32>(vec4<f32>(2.0f, 2.0f, 2.0f, 2.0f));
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
WrapInFunction(cast);
spirv::Builder& b = Build();
@ -627,8 +599,7 @@ TEST_F(SpvBuilderConstructorTest, Type_ModuleScope_Vec4_With_Vec4) {
TEST_F(SpvBuilderConstructorTest, Type_ModuleScope_Vec3_With_F32_Vec2) {
auto* cast = vec3<f32>(2.0f, vec2<f32>(2.0f, 2.0f));
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
WrapInFunction(cast);
spirv::Builder& b = Build();
@ -651,8 +622,7 @@ TEST_F(SpvBuilderConstructorTest, Type_ModuleScope_Vec3_With_F32_Vec2) {
TEST_F(SpvBuilderConstructorTest, Type_ModuleScope_Vec3_With_Vec2_F32) {
auto* cast = vec3<f32>(vec2<f32>(2.0f, 2.0f), 2.0f);
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
WrapInFunction(cast);
spirv::Builder& b = Build();
@ -675,8 +645,7 @@ TEST_F(SpvBuilderConstructorTest, Type_ModuleScope_Vec3_With_Vec2_F32) {
TEST_F(SpvBuilderConstructorTest, Type_ModuleScope_Vec4_With_F32_F32_Vec2) {
auto* cast = vec4<f32>(2.0f, 2.0f, vec2<f32>(2.0f, 2.0f));
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
WrapInFunction(cast);
spirv::Builder& b = Build();
@ -699,8 +668,7 @@ TEST_F(SpvBuilderConstructorTest, Type_ModuleScope_Vec4_With_F32_F32_Vec2) {
TEST_F(SpvBuilderConstructorTest, Type_ModuleScope_Vec4_With_F32_Vec2_F32) {
auto* cast = vec4<f32>(2.0f, vec2<f32>(2.0f, 2.0f), 2.0f);
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
WrapInFunction(cast);
spirv::Builder& b = Build();
@ -723,8 +691,7 @@ TEST_F(SpvBuilderConstructorTest, Type_ModuleScope_Vec4_With_F32_Vec2_F32) {
TEST_F(SpvBuilderConstructorTest, Type_ModuleScope_Vec4_With_Vec2_F32_F32) {
auto* cast = vec4<f32>(vec2<f32>(2.0f, 2.0f), 2.0f, 2.0f);
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
WrapInFunction(cast);
spirv::Builder& b = Build();
@ -747,8 +714,7 @@ TEST_F(SpvBuilderConstructorTest, Type_ModuleScope_Vec4_With_Vec2_F32_F32) {
TEST_F(SpvBuilderConstructorTest, Type_ModuleScope_Vec4_With_Vec2_Vec2) {
auto* cast = vec4<f32>(vec2<f32>(2.0f, 2.0f), vec2<f32>(2.0f, 2.0f));
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
WrapInFunction(cast);
spirv::Builder& b = Build();
@ -773,8 +739,7 @@ TEST_F(SpvBuilderConstructorTest, Type_ModuleScope_Vec4_With_Vec2_Vec2) {
TEST_F(SpvBuilderConstructorTest, Type_ModuleScope_Vec4_With_F32_Vec3) {
auto* cast = vec4<f32>(2.0f, vec3<f32>(2.0f, 2.0f, 2.0f));
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
WrapInFunction(cast);
spirv::Builder& b = Build();
@ -799,8 +764,7 @@ TEST_F(SpvBuilderConstructorTest, Type_ModuleScope_Vec4_With_F32_Vec3) {
TEST_F(SpvBuilderConstructorTest, Type_ModuleScope_Vec4_With_Vec3_F32) {
auto* cast = vec4<f32>(vec3<f32>(2.0f, 2.0f, 2.0f), 2.0f);
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
WrapInFunction(cast);
spirv::Builder& b = Build();
@ -825,8 +789,7 @@ TEST_F(SpvBuilderConstructorTest, Type_ModuleScope_Vec4_With_Vec3_F32) {
TEST_F(SpvBuilderConstructorTest, Type_Mat2x2_With_Vec2_Vec2) {
auto* cast = mat2x2<f32>(vec2<f32>(2.0f, 2.0f), vec2<f32>(2.0f, 2.0f));
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
WrapInFunction(cast);
spirv::Builder& b = Build();
@ -845,8 +808,7 @@ TEST_F(SpvBuilderConstructorTest, Type_Mat2x2_With_Vec2_Vec2) {
TEST_F(SpvBuilderConstructorTest, Type_Mat3x2_With_Vec2_Vec2_Vec2) {
auto* cast = mat3x2<f32>(vec2<f32>(2.0f, 2.0f), vec2<f32>(2.0f, 2.0f),
vec2<f32>(2.0f, 2.0f));
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
WrapInFunction(cast);
spirv::Builder& b = Build();
@ -865,8 +827,7 @@ TEST_F(SpvBuilderConstructorTest, Type_Mat3x2_With_Vec2_Vec2_Vec2) {
TEST_F(SpvBuilderConstructorTest, Type_Mat4x2_With_Vec2_Vec2_Vec2_Vec2) {
auto* cast = mat4x2<f32>(vec2<f32>(2.0f, 2.0f), vec2<f32>(2.0f, 2.0f),
vec2<f32>(2.0f, 2.0f), vec2<f32>(2.0f, 2.0f));
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
WrapInFunction(cast);
spirv::Builder& b = Build();
@ -885,8 +846,7 @@ TEST_F(SpvBuilderConstructorTest, Type_Mat4x2_With_Vec2_Vec2_Vec2_Vec2) {
TEST_F(SpvBuilderConstructorTest, Type_Mat2x3_With_Vec3_Vec3) {
auto* cast =
mat2x3<f32>(vec3<f32>(2.0f, 2.0f, 2.0f), vec3<f32>(2.0f, 2.0f, 2.0f));
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
WrapInFunction(cast);
spirv::Builder& b = Build();
@ -906,8 +866,7 @@ TEST_F(SpvBuilderConstructorTest, Type_Mat3x3_With_Vec3_Vec3_Vec3) {
auto* cast =
mat3x3<f32>(vec3<f32>(2.0f, 2.0f, 2.0f), vec3<f32>(2.0f, 2.0f, 2.0f),
vec3<f32>(2.0f, 2.0f, 2.0f));
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
WrapInFunction(cast);
spirv::Builder& b = Build();
@ -927,8 +886,7 @@ TEST_F(SpvBuilderConstructorTest, Type_Mat4x3_With_Vec3_Vec3_Vec3_Vec3) {
auto* cast =
mat4x3<f32>(vec3<f32>(2.0f, 2.0f, 2.0f), vec3<f32>(2.0f, 2.0f, 2.0f),
vec3<f32>(2.0f, 2.0f, 2.0f), vec3<f32>(2.0f, 2.0f, 2.0f));
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
WrapInFunction(cast);
spirv::Builder& b = Build();
@ -947,8 +905,7 @@ TEST_F(SpvBuilderConstructorTest, Type_Mat4x3_With_Vec3_Vec3_Vec3_Vec3) {
TEST_F(SpvBuilderConstructorTest, Type_Mat2x4_With_Vec4_Vec4) {
auto* cast = mat2x4<f32>(vec4<f32>(2.0f, 2.0f, 2.0f, 2.0f),
vec4<f32>(2.0f, 2.0f, 2.0f, 2.0f));
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
WrapInFunction(cast);
spirv::Builder& b = Build();
@ -968,8 +925,7 @@ TEST_F(SpvBuilderConstructorTest, Type_Mat3x4_With_Vec4_Vec4_Vec4) {
auto* cast = mat3x4<f32>(vec4<f32>(2.0f, 2.0f, 2.0f, 2.0f),
vec4<f32>(2.0f, 2.0f, 2.0f, 2.0f),
vec4<f32>(2.0f, 2.0f, 2.0f, 2.0f));
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
WrapInFunction(cast);
spirv::Builder& b = Build();
@ -989,8 +945,7 @@ TEST_F(SpvBuilderConstructorTest, Type_Mat4x4_With_Vec4_Vec4_Vec4_Vec4) {
auto* cast = mat4x4<f32>(
vec4<f32>(2.0f, 2.0f, 2.0f, 2.0f), vec4<f32>(2.0f, 2.0f, 2.0f, 2.0f),
vec4<f32>(2.0f, 2.0f, 2.0f, 2.0f), vec4<f32>(2.0f, 2.0f, 2.0f, 2.0f));
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
WrapInFunction(cast);
spirv::Builder& b = Build();
@ -1008,8 +963,7 @@ TEST_F(SpvBuilderConstructorTest, Type_Mat4x4_With_Vec4_Vec4_Vec4_Vec4) {
TEST_F(SpvBuilderConstructorTest, Type_Array_5_F32) {
auto* cast = array<f32, 5>(2.0f, 2.0f, 2.0f, 2.0f, 2.0f);
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
WrapInFunction(cast);
spirv::Builder& b = Build();
@ -1028,8 +982,7 @@ TEST_F(SpvBuilderConstructorTest, Type_Array_5_F32) {
TEST_F(SpvBuilderConstructorTest, Type_Array_2_Vec3) {
auto* cast =
array<f32, 2>(vec3<f32>(2.0f, 2.0f, 2.0f), vec3<f32>(2.0f, 2.0f, 2.0f));
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
WrapInFunction(cast);
spirv::Builder& b = Build();
@ -1057,7 +1010,7 @@ TEST_F(SpvBuilderConstructorTest, Type_Struct) {
auto* s_type = ty.struct_("my_struct", s);
auto* t = Construct(s_type, 2.0f, vec3<f32>(2.0f, 2.0f, 2.0f));
EXPECT_TRUE(td.DetermineResultType(t)) << td.error();
WrapInFunction(t);
spirv::Builder& b = Build();
@ -1078,7 +1031,7 @@ TEST_F(SpvBuilderConstructorTest, Type_Struct) {
TEST_F(SpvBuilderConstructorTest, Type_ZeroInit_F32) {
auto* t = Construct(ty.f32());
EXPECT_TRUE(td.DetermineResultType(t)) << td.error();
WrapInFunction(t);
spirv::Builder& b = Build();
@ -1095,7 +1048,7 @@ TEST_F(SpvBuilderConstructorTest, Type_ZeroInit_F32) {
TEST_F(SpvBuilderConstructorTest, Type_ZeroInit_I32) {
auto* t = Construct<i32>();
EXPECT_TRUE(td.DetermineResultType(t)) << td.error();
WrapInFunction(t);
spirv::Builder& b = Build();
@ -1112,7 +1065,7 @@ TEST_F(SpvBuilderConstructorTest, Type_ZeroInit_I32) {
TEST_F(SpvBuilderConstructorTest, Type_ZeroInit_U32) {
auto* t = Construct<u32>();
EXPECT_TRUE(td.DetermineResultType(t)) << td.error();
WrapInFunction(t);
spirv::Builder& b = Build();
@ -1129,7 +1082,7 @@ TEST_F(SpvBuilderConstructorTest, Type_ZeroInit_U32) {
TEST_F(SpvBuilderConstructorTest, Type_ZeroInit_Bool) {
auto* t = Construct(ty.bool_());
EXPECT_TRUE(td.DetermineResultType(t)) << td.error();
WrapInFunction(t);
spirv::Builder& b = Build();
@ -1146,7 +1099,7 @@ TEST_F(SpvBuilderConstructorTest, Type_ZeroInit_Bool) {
TEST_F(SpvBuilderConstructorTest, Type_ZeroInit_Vector) {
auto* t = vec2<i32>();
EXPECT_TRUE(td.DetermineResultType(t)) << td.error();
WrapInFunction(t);
spirv::Builder& b = Build();
@ -1164,7 +1117,7 @@ TEST_F(SpvBuilderConstructorTest, Type_ZeroInit_Vector) {
TEST_F(SpvBuilderConstructorTest, Type_ZeroInit_Matrix) {
auto* t = mat4x2<f32>();
EXPECT_TRUE(td.DetermineResultType(t)) << td.error();
WrapInFunction(t);
spirv::Builder& b = Build();
@ -1183,7 +1136,7 @@ TEST_F(SpvBuilderConstructorTest, Type_ZeroInit_Matrix) {
TEST_F(SpvBuilderConstructorTest, Type_ZeroInit_Array) {
auto* t = array<i32, 2>();
EXPECT_TRUE(td.DetermineResultType(t)) << td.error();
WrapInFunction(t);
spirv::Builder& b = Build();
@ -1208,7 +1161,7 @@ TEST_F(SpvBuilderConstructorTest, Type_ZeroInit_Struct) {
ast::StructDecorationList{});
auto* s_type = ty.struct_("my_struct", s);
auto* t = Construct(s_type);
EXPECT_TRUE(td.DetermineResultType(t)) << td.error();
WrapInFunction(t);
spirv::Builder& b = Build();
@ -1225,8 +1178,7 @@ TEST_F(SpvBuilderConstructorTest, Type_ZeroInit_Struct) {
TEST_F(SpvBuilderConstructorTest, Type_Convert_U32_To_I32) {
auto* cast = Construct<i32>(2u);
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
WrapInFunction(cast);
spirv::Builder& b = Build();
@ -1244,8 +1196,7 @@ TEST_F(SpvBuilderConstructorTest, Type_Convert_U32_To_I32) {
TEST_F(SpvBuilderConstructorTest, Type_Convert_I32_To_U32) {
auto* cast = Construct<u32>(2);
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
WrapInFunction(cast);
spirv::Builder& b = Build();
@ -1263,8 +1214,7 @@ TEST_F(SpvBuilderConstructorTest, Type_Convert_I32_To_U32) {
TEST_F(SpvBuilderConstructorTest, Type_Convert_F32_To_I32) {
auto* cast = Construct<i32>(2.4f);
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
WrapInFunction(cast);
spirv::Builder& b = Build();
@ -1282,8 +1232,7 @@ TEST_F(SpvBuilderConstructorTest, Type_Convert_F32_To_I32) {
TEST_F(SpvBuilderConstructorTest, Type_Convert_F32_To_U32) {
auto* cast = Construct<u32>(2.4f);
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
WrapInFunction(cast);
spirv::Builder& b = Build();
@ -1301,8 +1250,7 @@ TEST_F(SpvBuilderConstructorTest, Type_Convert_F32_To_U32) {
TEST_F(SpvBuilderConstructorTest, Type_Convert_I32_To_F32) {
auto* cast = Construct<f32>(2);
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
WrapInFunction(cast);
spirv::Builder& b = Build();
@ -1320,8 +1268,7 @@ TEST_F(SpvBuilderConstructorTest, Type_Convert_I32_To_F32) {
TEST_F(SpvBuilderConstructorTest, Type_Convert_U32_To_F32) {
auto* cast = Construct<f32>(2u);
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
WrapInFunction(cast);
spirv::Builder& b = Build();
@ -1338,11 +1285,10 @@ TEST_F(SpvBuilderConstructorTest, Type_Convert_U32_To_F32) {
}
TEST_F(SpvBuilderConstructorTest, Type_Convert_Vectors_U32_to_I32) {
auto* var = Var("i", ast::StorageClass::kPrivate, ty.vec3<u32>());
auto* var = Global("i", ast::StorageClass::kPrivate, ty.vec3<u32>());
auto* cast = vec3<i32>("i");
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
WrapInFunction(cast);
spirv::Builder& b = Build();
@ -1365,11 +1311,10 @@ TEST_F(SpvBuilderConstructorTest, Type_Convert_Vectors_U32_to_I32) {
}
TEST_F(SpvBuilderConstructorTest, Type_Convert_Vectors_F32_to_I32) {
auto* var = Var("i", ast::StorageClass::kPrivate, ty.vec3<f32>());
auto* var = Global("i", ast::StorageClass::kPrivate, ty.vec3<f32>());
auto* cast = vec3<i32>("i");
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
WrapInFunction(cast);
spirv::Builder& b = Build();
@ -1392,11 +1337,10 @@ TEST_F(SpvBuilderConstructorTest, Type_Convert_Vectors_F32_to_I32) {
}
TEST_F(SpvBuilderConstructorTest, Type_Convert_Vectors_I32_to_U32) {
auto* var = Var("i", ast::StorageClass::kPrivate, ty.vec3<i32>());
auto* var = Global("i", ast::StorageClass::kPrivate, ty.vec3<i32>());
auto* cast = vec3<u32>("i");
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
WrapInFunction(cast);
spirv::Builder& b = Build();
@ -1419,11 +1363,10 @@ TEST_F(SpvBuilderConstructorTest, Type_Convert_Vectors_I32_to_U32) {
}
TEST_F(SpvBuilderConstructorTest, Type_Convert_Vectors_F32_to_U32) {
auto* var = Var("i", ast::StorageClass::kPrivate, ty.vec3<f32>());
auto* var = Global("i", ast::StorageClass::kPrivate, ty.vec3<f32>());
auto* cast = vec3<u32>("i");
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
WrapInFunction(cast);
spirv::Builder& b = Build();
@ -1446,11 +1389,10 @@ TEST_F(SpvBuilderConstructorTest, Type_Convert_Vectors_F32_to_U32) {
}
TEST_F(SpvBuilderConstructorTest, Type_Convert_Vectors_I32_to_F32) {
auto* var = Var("i", ast::StorageClass::kPrivate, ty.vec3<i32>());
auto* var = Global("i", ast::StorageClass::kPrivate, ty.vec3<i32>());
auto* cast = vec3<f32>("i");
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
WrapInFunction(cast);
spirv::Builder& b = Build();
@ -1473,11 +1415,10 @@ TEST_F(SpvBuilderConstructorTest, Type_Convert_Vectors_I32_to_F32) {
}
TEST_F(SpvBuilderConstructorTest, Type_Convert_Vectors_U32_to_F32) {
auto* var = Var("i", ast::StorageClass::kPrivate, ty.vec3<u32>());
auto* var = Global("i", ast::StorageClass::kPrivate, ty.vec3<u32>());
auto* cast = vec3<f32>("i");
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
WrapInFunction(cast);
spirv::Builder& b = Build();
@ -1503,8 +1444,7 @@ TEST_F(SpvBuilderConstructorTest,
IsConstructorConst_GlobalVectorWithAllConstConstructors) {
// vec3<f32>(1.0, 2.0, 3.0) -> true
auto* t = vec3<f32>(1.f, 2.f, 3.f);
ASSERT_TRUE(td.DetermineResultType(t)) << td.error();
WrapInFunction(t);
spirv::Builder& b = Build();
@ -1514,13 +1454,13 @@ TEST_F(SpvBuilderConstructorTest,
TEST_F(SpvBuilderConstructorTest, IsConstructorConst_GlobalVector_WithIdent) {
// vec3<f32>(a, b, c) -> false -- ERROR
Global("a", ast::StorageClass::kPrivate, ty.f32());
Global("b", ast::StorageClass::kPrivate, ty.f32());
Global("c", ast::StorageClass::kPrivate, ty.f32());
auto* t = vec3<f32>("a", "b", "c");
Var("a", ast::StorageClass::kPrivate, ty.f32());
Var("b", ast::StorageClass::kPrivate, ty.f32());
Var("c", ast::StorageClass::kPrivate, ty.f32());
ASSERT_TRUE(td.DetermineResultType(t)) << td.error();
WrapInFunction(t);
spirv::Builder& b = Build();
@ -1535,8 +1475,7 @@ TEST_F(SpvBuilderConstructorTest,
// -> true
auto* t = Construct(ty.array(ty.vec2<f32>(), 2), vec3<f32>(1.f, 2.f, 3.f),
vec3<f32>(1.f, 2.f, 3.f));
ASSERT_TRUE(td.DetermineResultType(t)) << td.error();
WrapInFunction(t);
spirv::Builder& b = Build();
@ -1549,8 +1488,7 @@ TEST_F(SpvBuilderConstructorTest,
// vec3<f32>(f32(1.0), f32(2.0)) -> false
auto* t = vec2<f32>(Construct<f32>(1.f), Construct<f32>(2.f));
ASSERT_TRUE(td.DetermineResultType(t)) << td.error();
WrapInFunction(t);
spirv::Builder& b = Build();
@ -1563,8 +1501,7 @@ TEST_F(SpvBuilderConstructorTest,
// vec3<f32>(f32(1), f32(2)) -> false
auto* t = vec2<f32>(Construct<f32>(1), Construct<f32>(2));
ASSERT_TRUE(td.DetermineResultType(t)) << td.error();
WrapInFunction(t);
spirv::Builder& b = Build();
@ -1577,8 +1514,7 @@ TEST_F(SpvBuilderConstructorTest,
// vec3<f32>(1.0, 2.0, 3.0) -> true
auto* t = vec3<f32>(1.f, 2.f, 3.f);
ASSERT_TRUE(td.DetermineResultType(t)) << td.error();
WrapInFunction(t);
spirv::Builder& b = Build();
@ -1590,12 +1526,11 @@ TEST_F(SpvBuilderConstructorTest, IsConstructorConst_Vector_WithIdent) {
// vec3<f32>(a, b, c) -> false
auto* t = vec3<f32>("a", "b", "c");
WrapInFunction(t);
Var("a", ast::StorageClass::kPrivate, ty.f32());
Var("b", ast::StorageClass::kPrivate, ty.f32());
Var("c", ast::StorageClass::kPrivate, ty.f32());
ASSERT_TRUE(td.DetermineResultType(t)) << td.error();
Global("a", ast::StorageClass::kPrivate, ty.f32());
Global("b", ast::StorageClass::kPrivate, ty.f32());
Global("c", ast::StorageClass::kPrivate, ty.f32());
spirv::Builder& b = Build();
@ -1612,8 +1547,7 @@ TEST_F(SpvBuilderConstructorTest,
auto* second = vec3<f32>(1.f, 2.f, 3.f);
auto* t = Construct(ty.array(ty.vec3<f32>(), 2), first, second);
ASSERT_TRUE(td.DetermineResultType(t)) << td.error();
WrapInFunction(t);
spirv::Builder& b = Build();
@ -1626,8 +1560,7 @@ TEST_F(SpvBuilderConstructorTest,
// vec2<f32>(f32(1), f32(2)) -> false
auto* t = vec2<f32>(1, 2);
ASSERT_TRUE(td.DetermineResultType(t)) << td.error();
WrapInFunction(t);
spirv::Builder& b = Build();
@ -1639,8 +1572,7 @@ TEST_F(SpvBuilderConstructorTest, IsConstructorConst_WithTypeCastConstructor) {
// vec3<f32>(f32(1), f32(2)) -> false
auto* t = vec3<f32>(1, 2);
ASSERT_TRUE(td.DetermineResultType(t)) << td.error();
WrapInFunction(t);
spirv::Builder& b = Build();
@ -1650,8 +1582,7 @@ TEST_F(SpvBuilderConstructorTest, IsConstructorConst_WithTypeCastConstructor) {
TEST_F(SpvBuilderConstructorTest, IsConstructorConst_BitCastScalars) {
auto* t = vec2<u32>(1, 1);
ASSERT_TRUE(td.DetermineResultType(t)) << td.error();
WrapInFunction(t);
spirv::Builder& b = Build();
@ -1668,7 +1599,7 @@ TEST_F(SpvBuilderConstructorTest, IsConstructorConst_Struct) {
ast::StructDecorationList{});
auto* s_type = ty.struct_("my_struct", s);
auto* t = Construct(s_type, 2.f, vec3<f32>(2.f, 2.f, 2.f));
ASSERT_TRUE(td.DetermineResultType(t)) << td.error();
WrapInFunction(t);
spirv::Builder& b = Build();
@ -1687,11 +1618,10 @@ TEST_F(SpvBuilderConstructorTest,
auto* s_type = ty.struct_("my_struct", s);
auto* t = Construct(s_type, 2.f, "a", 2.f);
WrapInFunction(t);
Var("a", ast::StorageClass::kPrivate, ty.f32());
Var("b", ast::StorageClass::kPrivate, ty.f32());
ASSERT_TRUE(td.DetermineResultType(t)) << td.error();
Global("a", ast::StorageClass::kPrivate, ty.f32());
Global("b", ast::StorageClass::kPrivate, ty.f32());
spirv::Builder& b = Build();

View File

@ -97,13 +97,9 @@ TEST_F(BuilderTest, FunctionDecoration_Stage_WithUnusedInterfaceIds) {
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
});
auto* v_in = Var("my_in", ast::StorageClass::kInput, ty.f32());
auto* v_out = Var("my_out", ast::StorageClass::kOutput, ty.f32());
auto* v_wg = Var("my_wg", ast::StorageClass::kWorkgroup, ty.f32());
AST().AddGlobalVariable(v_in);
AST().AddGlobalVariable(v_out);
AST().AddGlobalVariable(v_wg);
auto* v_in = Global("my_in", ast::StorageClass::kInput, ty.f32());
auto* v_out = Global("my_out", ast::StorageClass::kOutput, ty.f32());
auto* v_wg = Global("my_wg", ast::StorageClass::kWorkgroup, ty.f32());
spirv::Builder& b = Build();
@ -146,13 +142,9 @@ TEST_F(BuilderTest, FunctionDecoration_Stage_WithUsedInterfaceIds) {
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
});
auto* v_in = Var("my_in", ast::StorageClass::kInput, ty.f32());
auto* v_out = Var("my_out", ast::StorageClass::kOutput, ty.f32());
auto* v_wg = Var("my_wg", ast::StorageClass::kWorkgroup, ty.f32());
AST().AddGlobalVariable(v_in);
AST().AddGlobalVariable(v_out);
AST().AddGlobalVariable(v_wg);
auto* v_in = Global("my_in", ast::StorageClass::kInput, ty.f32());
auto* v_out = Global("my_out", ast::StorageClass::kOutput, ty.f32());
auto* v_wg = Global("my_wg", ast::StorageClass::kWorkgroup, ty.f32());
spirv::Builder& b = Build();
@ -266,12 +258,10 @@ OpFunctionEnd
}
TEST_F(BuilderTest, FunctionDecoration_ExecutionMode_FragDepth) {
auto* fragdepth =
Var("fragdepth", ast::StorageClass::kOutput, ty.f32(), nullptr,
ast::VariableDecorationList{
create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth),
});
AST().AddGlobalVariable(fragdepth);
Global("fragdepth", ast::StorageClass::kOutput, ty.f32(), nullptr,
ast::VariableDecorationList{
create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth),
});
auto* func =
Func("main", ast::VariableList{}, ty.void_(),

View File

@ -85,7 +85,7 @@ OpFunctionEnd
}
TEST_F(BuilderTest, Function_Terminator_ReturnValue) {
AST().AddGlobalVariable(Var("a", ast::StorageClass::kPrivate, ty.f32()));
Global("a", ast::StorageClass::kPrivate, ty.f32());
Func("a_func", {}, ty.void_(),
ast::StatementList{create<ast::ReturnStatement>(Expr("a"))},
@ -238,16 +238,14 @@ TEST_F(BuilderTest, Emit_Multiple_EntryPoint_With_Same_ModuleVar) {
auto* s = ty.struct_("Data", str);
type::AccessControl ac(ast::AccessControl::kReadWrite, s);
auto* data_var = Var("data", ast::StorageClass::kStorage, &ac, nullptr,
ast::VariableDecorationList{
create<ast::BindingDecoration>(0),
create<ast::GroupDecoration>(0),
});
Global("data", ast::StorageClass::kStorage, &ac, nullptr,
ast::VariableDecorationList{
create<ast::BindingDecoration>(0),
create<ast::GroupDecoration>(0),
});
AST().AddConstructedType(s);
AST().AddGlobalVariable(data_var);
{
auto* var = Var("v", ast::StorageClass::kFunction, ty.f32(),
MemberAccessor("data", "d"), ast::VariableDecorationList{});

View File

@ -45,7 +45,7 @@ namespace {
using BuilderTest = TestHelper;
TEST_F(BuilderTest, FunctionVar_NoStorageClass) {
auto* v = Var("var", ast::StorageClass::kNone, ty.f32());
auto* v = Global("var", ast::StorageClass::kNone, ty.f32());
spirv::Builder& b = Build();
@ -66,11 +66,9 @@ TEST_F(BuilderTest, FunctionVar_NoStorageClass) {
TEST_F(BuilderTest, FunctionVar_WithConstantConstructor) {
auto* init = vec3<f32>(1.f, 1.f, 3.f);
EXPECT_TRUE(td.DetermineResultType(init)) << td.error();
auto* v = Var("var", ast::StorageClass::kOutput, ty.f32(), init,
ast::VariableDecorationList{});
td.RegisterVariableForTesting(v);
auto* v = Global("var", ast::StorageClass::kOutput, ty.f32(), init,
ast::VariableDecorationList{});
spirv::Builder& b = Build();
@ -98,12 +96,10 @@ TEST_F(BuilderTest, FunctionVar_WithConstantConstructor) {
TEST_F(BuilderTest, FunctionVar_WithNonConstantConstructor) {
auto* init = vec2<f32>(1.f, Add(3.f, 3.f));
EXPECT_TRUE(td.DetermineResultType(init)) << td.error();
auto* v = Var("var", ast::StorageClass::kFunction, ty.vec2<f32>(), init,
ast::VariableDecorationList{});
auto* v = Global("var", ast::StorageClass::kFunction, ty.vec2<f32>(), init,
ast::VariableDecorationList{});
td.RegisterVariableForTesting(v);
spirv::Builder& b = Build();
b.push_function(Function{});
@ -133,16 +129,11 @@ TEST_F(BuilderTest, FunctionVar_WithNonConstantConstructorLoadedFromVar) {
// var v : f32 = 1.0;
// var v2 : f32 = v; // Should generate the load and store automatically.
auto* v = Var("v", ast::StorageClass::kFunction, ty.f32(), Expr(1.f),
ast::VariableDecorationList{});
td.RegisterVariableForTesting(v);
auto* v = Global("v", ast::StorageClass::kFunction, ty.f32(), Expr(1.f),
ast::VariableDecorationList{});
auto* v2 = Var("v2", ast::StorageClass::kFunction, ty.f32(), Expr("v"),
ast::VariableDecorationList{});
td.RegisterVariableForTesting(v2);
ASSERT_TRUE(td.DetermineResultType(v->constructor())) << td.error();
ASSERT_TRUE(td.DetermineResultType(v2->constructor())) << td.error();
auto* v2 = Global("v2", ast::StorageClass::kFunction, ty.f32(), Expr("v"),
ast::VariableDecorationList{});
spirv::Builder& b = Build();
@ -174,16 +165,11 @@ TEST_F(BuilderTest, FunctionVar_ConstWithVarInitializer) {
// var v : f32 = 1.0;
// const v2 : f32 = v; // Should generate the load
auto* v = Var("v", ast::StorageClass::kFunction, ty.f32(), Expr(1.f),
ast::VariableDecorationList{});
td.RegisterVariableForTesting(v);
auto* v = Global("v", ast::StorageClass::kFunction, ty.f32(), Expr(1.f),
ast::VariableDecorationList{});
auto* v2 = Var("v2", ast::StorageClass::kFunction, ty.f32(), Expr("v"),
ast::VariableDecorationList{});
td.RegisterVariableForTesting(v2);
ASSERT_TRUE(td.DetermineResultType(v->constructor())) << td.error();
ASSERT_TRUE(td.DetermineResultType(v2->constructor())) << td.error();
auto* v2 = Global("v2", ast::StorageClass::kFunction, ty.f32(), Expr("v"),
ast::VariableDecorationList{});
spirv::Builder& b = Build();
@ -213,12 +199,11 @@ OpStore %7 %6
TEST_F(BuilderTest, FunctionVar_Const) {
auto* init = vec3<f32>(1.f, 1.f, 3.f);
EXPECT_TRUE(td.DetermineResultType(init)) << td.error();
auto* v = Const("var", ast::StorageClass::kOutput, ty.f32(), init,
ast::VariableDecorationList{});
td.RegisterVariableForTesting(v);
WrapInFunction(v);
spirv::Builder& b = Build();

View File

@ -50,7 +50,7 @@ namespace {
using BuilderTest = TestHelper;
TEST_F(BuilderTest, GlobalVar_NoStorageClass) {
auto* v = Var("var", ast::StorageClass::kNone, ty.f32());
auto* v = Global("var", ast::StorageClass::kNone, ty.f32());
spirv::Builder& b = Build();
@ -65,7 +65,7 @@ TEST_F(BuilderTest, GlobalVar_NoStorageClass) {
}
TEST_F(BuilderTest, GlobalVar_WithStorageClass) {
auto* v = Var("var", ast::StorageClass::kOutput, ty.f32());
auto* v = Global("var", ast::StorageClass::kOutput, ty.f32());
spirv::Builder& b = Build();
@ -80,7 +80,7 @@ TEST_F(BuilderTest, GlobalVar_WithStorageClass) {
}
TEST_F(BuilderTest, GlobalVar_WithStorageClass_Input) {
auto* v = Var("var", ast::StorageClass::kInput, ty.f32());
auto* v = Global("var", ast::StorageClass::kInput, ty.f32());
spirv::Builder& b = Build();
@ -95,11 +95,9 @@ TEST_F(BuilderTest, GlobalVar_WithStorageClass_Input) {
TEST_F(BuilderTest, GlobalVar_WithConstructor) {
auto* init = vec3<f32>(1.f, 1.f, 3.f);
EXPECT_TRUE(td.DetermineResultType(init)) << td.error();
auto* v = Var("var", ast::StorageClass::kOutput, ty.f32(), init,
ast::VariableDecorationList{});
td.RegisterVariableForTesting(v);
auto* v = Global("var", ast::StorageClass::kOutput, ty.f32(), init,
ast::VariableDecorationList{});
spirv::Builder& b = Build();
@ -120,11 +118,9 @@ TEST_F(BuilderTest, GlobalVar_WithConstructor) {
TEST_F(BuilderTest, GlobalVar_Const) {
auto* init = vec3<f32>(1.f, 1.f, 3.f);
EXPECT_TRUE(td.DetermineResultType(init)) << td.error();
auto* v = Const("var", ast::StorageClass::kOutput, ty.f32(), init,
ast::VariableDecorationList{});
td.RegisterVariableForTesting(v);
auto* v = GlobalConst("var", ast::StorageClass::kOutput, ty.f32(), init,
ast::VariableDecorationList{});
spirv::Builder& b = Build();
@ -143,11 +139,9 @@ TEST_F(BuilderTest, GlobalVar_Const) {
TEST_F(BuilderTest, GlobalVar_Complex_Constructor) {
auto* init = vec3<f32>(ast::ExpressionList{Expr(1.f), Expr(2.f), Expr(3.f)});
EXPECT_TRUE(td.DetermineResultType(init)) << td.error();
auto* v = Const("var", ast::StorageClass::kOutput, ty.f32(), init,
ast::VariableDecorationList{});
td.RegisterVariableForTesting(v);
auto* v = GlobalConst("var", ast::StorageClass::kOutput, ty.f32(), init,
ast::VariableDecorationList{});
spirv::Builder& b = Build();
@ -166,11 +160,8 @@ TEST_F(BuilderTest, GlobalVar_Complex_Constructor) {
TEST_F(BuilderTest, GlobalVar_Complex_ConstructorWithExtract) {
auto* init = vec3<f32>(vec2<f32>(1.f, 2.f), 3.f);
EXPECT_TRUE(td.DetermineResultType(init)) << td.error();
auto* v = Const("var", ast::StorageClass::kOutput, ty.f32(), init,
ast::VariableDecorationList{});
td.RegisterVariableForTesting(v);
auto* v = GlobalConst("var", ast::StorageClass::kOutput, ty.f32(), init,
ast::VariableDecorationList{});
spirv::Builder& b = Build();
@ -194,10 +185,10 @@ TEST_F(BuilderTest, GlobalVar_Complex_ConstructorWithExtract) {
}
TEST_F(BuilderTest, GlobalVar_WithLocation) {
auto* v = Var("var", ast::StorageClass::kOutput, ty.f32(), nullptr,
ast::VariableDecorationList{
create<ast::LocationDecoration>(5),
});
auto* v = Global("var", ast::StorageClass::kOutput, ty.f32(), nullptr,
ast::VariableDecorationList{
create<ast::LocationDecoration>(5),
});
spirv::Builder& b = Build();
@ -214,11 +205,11 @@ TEST_F(BuilderTest, GlobalVar_WithLocation) {
}
TEST_F(BuilderTest, GlobalVar_WithBindingAndGroup) {
auto* v = Var("var", ast::StorageClass::kOutput, ty.f32(), nullptr,
ast::VariableDecorationList{
create<ast::BindingDecoration>(2),
create<ast::GroupDecoration>(3),
});
auto* v = Global("var", ast::StorageClass::kOutput, ty.f32(), nullptr,
ast::VariableDecorationList{
create<ast::BindingDecoration>(2),
create<ast::GroupDecoration>(3),
});
spirv::Builder& b = Build();
@ -236,10 +227,10 @@ OpDecorate %1 DescriptorSet 3
}
TEST_F(BuilderTest, GlobalVar_WithBuiltin) {
auto* v = Var("var", ast::StorageClass::kOutput, ty.f32(), nullptr,
ast::VariableDecorationList{
create<ast::BuiltinDecoration>(ast::Builtin::kPosition),
});
auto* v = Global("var", ast::StorageClass::kOutput, ty.f32(), nullptr,
ast::VariableDecorationList{
create<ast::BuiltinDecoration>(ast::Builtin::kPosition),
});
spirv::Builder& b = Build();
@ -256,10 +247,10 @@ TEST_F(BuilderTest, GlobalVar_WithBuiltin) {
}
TEST_F(BuilderTest, GlobalVar_ConstantId_Bool) {
auto* v = Var("var", ast::StorageClass::kNone, ty.bool_(), Expr(true),
ast::VariableDecorationList{
create<ast::ConstantIdDecoration>(1200),
});
auto* v = Global("var", ast::StorageClass::kNone, ty.bool_(), Expr(true),
ast::VariableDecorationList{
create<ast::ConstantIdDecoration>(1200),
});
spirv::Builder& b = Build();
@ -276,10 +267,10 @@ TEST_F(BuilderTest, GlobalVar_ConstantId_Bool) {
}
TEST_F(BuilderTest, GlobalVar_ConstantId_Bool_NoConstructor) {
auto* v = Var("var", ast::StorageClass::kNone, ty.bool_(), nullptr,
ast::VariableDecorationList{
create<ast::ConstantIdDecoration>(1200),
});
auto* v = Global("var", ast::StorageClass::kNone, ty.bool_(), nullptr,
ast::VariableDecorationList{
create<ast::ConstantIdDecoration>(1200),
});
spirv::Builder& b = Build();
@ -296,10 +287,10 @@ TEST_F(BuilderTest, GlobalVar_ConstantId_Bool_NoConstructor) {
}
TEST_F(BuilderTest, GlobalVar_ConstantId_Scalar) {
auto* v = Var("var", ast::StorageClass::kNone, ty.f32(), Expr(2.f),
ast::VariableDecorationList{
create<ast::ConstantIdDecoration>(0),
});
auto* v = Global("var", ast::StorageClass::kNone, ty.f32(), Expr(2.f),
ast::VariableDecorationList{
create<ast::ConstantIdDecoration>(0),
});
spirv::Builder& b = Build();
@ -316,10 +307,10 @@ TEST_F(BuilderTest, GlobalVar_ConstantId_Scalar) {
}
TEST_F(BuilderTest, GlobalVar_ConstantId_Scalar_F32_NoConstructor) {
auto* v = Var("var", ast::StorageClass::kNone, ty.f32(), nullptr,
ast::VariableDecorationList{
create<ast::ConstantIdDecoration>(0),
});
auto* v = Global("var", ast::StorageClass::kNone, ty.f32(), nullptr,
ast::VariableDecorationList{
create<ast::ConstantIdDecoration>(0),
});
spirv::Builder& b = Build();
@ -336,10 +327,10 @@ TEST_F(BuilderTest, GlobalVar_ConstantId_Scalar_F32_NoConstructor) {
}
TEST_F(BuilderTest, GlobalVar_ConstantId_Scalar_I32_NoConstructor) {
auto* v = Var("var", ast::StorageClass::kNone, ty.i32(), nullptr,
ast::VariableDecorationList{
create<ast::ConstantIdDecoration>(0),
});
auto* v = Global("var", ast::StorageClass::kNone, ty.i32(), nullptr,
ast::VariableDecorationList{
create<ast::ConstantIdDecoration>(0),
});
spirv::Builder& b = Build();
@ -356,10 +347,10 @@ TEST_F(BuilderTest, GlobalVar_ConstantId_Scalar_I32_NoConstructor) {
}
TEST_F(BuilderTest, GlobalVar_ConstantId_Scalar_U32_NoConstructor) {
auto* v = Var("var", ast::StorageClass::kNone, ty.u32(), nullptr,
ast::VariableDecorationList{
create<ast::ConstantIdDecoration>(0),
});
auto* v = Global("var", ast::StorageClass::kNone, ty.u32(), nullptr,
ast::VariableDecorationList{
create<ast::ConstantIdDecoration>(0),
});
spirv::Builder& b = Build();
@ -386,6 +377,7 @@ inline std::ostream& operator<<(std::ostream& out, BuiltinData data) {
using BuiltinDataTest = TestParamHelper<BuiltinData>;
TEST_P(BuiltinDataTest, Convert) {
auto params = GetParam();
spirv::Builder& b = Build();
EXPECT_EQ(b.ConvertBuiltin(params.builtin), params.result);
@ -421,9 +413,9 @@ TEST_F(BuilderTest, GlobalVar_DeclReadOnly) {
"A", create<ast::Struct>(ast::StructMemberList{Member("a", ty.i32()),
Member("b", ty.i32())},
ast::StructDecorationList{}));
type::AccessControl ac{ast::AccessControl::kReadOnly, A};
auto* ac = create<type::AccessControl>(ast::AccessControl::kReadOnly, A);
auto* var = Var("b", ast::StorageClass::kStorage, &ac);
auto* var = Global("b", ast::StorageClass::kStorage, ac);
spirv::Builder& b = Build();
@ -455,8 +447,8 @@ TEST_F(BuilderTest, GlobalVar_TypeAliasDeclReadOnly) {
"A", create<ast::Struct>(ast::StructMemberList{Member("a", ty.i32())},
ast::StructDecorationList{}));
auto* B = ty.alias("B", A);
type::AccessControl ac{ast::AccessControl::kReadOnly, B};
auto* var = Var("b", ast::StorageClass::kStorage, &ac);
auto* ac = create<type::AccessControl>(ast::AccessControl::kReadOnly, B);
auto* var = Global("b", ast::StorageClass::kStorage, ac);
spirv::Builder& b = Build();
@ -485,9 +477,9 @@ TEST_F(BuilderTest, GlobalVar_TypeAliasAssignReadOnly) {
auto* A = ty.struct_(
"A", create<ast::Struct>(ast::StructMemberList{Member("a", ty.i32())},
ast::StructDecorationList{}));
type::AccessControl ac{ast::AccessControl::kReadOnly, A};
auto* B = ty.alias("B", &ac);
auto* var = Var("b", ast::StorageClass::kStorage, B);
auto* ac = create<type::AccessControl>(ast::AccessControl::kReadOnly, A);
auto* B = ty.alias("B", ac);
auto* var = Global("b", ast::StorageClass::kStorage, B);
spirv::Builder& b = Build();
@ -519,8 +511,8 @@ TEST_F(BuilderTest, GlobalVar_TwoVarDeclReadOnly) {
type::AccessControl read{ast::AccessControl::kReadOnly, A};
type::AccessControl rw{ast::AccessControl::kReadWrite, A};
auto* var_b = Var("b", ast::StorageClass::kStorage, &read);
auto* var_c = Var("c", ast::StorageClass::kStorage, &rw);
auto* var_b = Global("b", ast::StorageClass::kStorage, &read);
auto* var_c = Global("c", ast::StorageClass::kStorage, &rw);
spirv::Builder& b = Build();
@ -550,13 +542,12 @@ OpName %5 "c"
TEST_F(BuilderTest, GlobalVar_TextureStorageReadOnly) {
// var<uniform_constant> a : [[access(read)]] texture_storage_2d<r32uint>;
type::StorageTexture type(type::TextureDimension::k2d,
type::ImageFormat::kR32Uint);
ASSERT_TRUE(td.DetermineStorageTextureSubtype(&type)) << td.error();
auto* type = create<type::StorageTexture>(type::TextureDimension::k2d,
type::ImageFormat::kR32Uint);
type::AccessControl ac(ast::AccessControl::kReadOnly, &type);
auto* ac = create<type::AccessControl>(ast::AccessControl::kReadOnly, type);
auto* var_a = Var("a", ast::StorageClass::kUniformConstant, &ac);
auto* var_a = Global("a", ast::StorageClass::kUniformConstant, ac);
spirv::Builder& b = Build();
@ -574,13 +565,13 @@ TEST_F(BuilderTest, GlobalVar_TextureStorageReadOnly) {
TEST_F(BuilderTest, GlobalVar_TextureStorageWriteOnly) {
// var<uniform_constant> a : [[access(write)]] texture_storage_2d<r32uint>;
type::StorageTexture type(type::TextureDimension::k2d,
type::ImageFormat::kR32Uint);
ASSERT_TRUE(td.DetermineStorageTextureSubtype(&type)) << td.error();
auto* type = create<type::StorageTexture>(type::TextureDimension::k2d,
type::ImageFormat::kR32Uint);
Global("test_var", ast::StorageClass::kNone, type);
type::AccessControl ac(ast::AccessControl::kWriteOnly, &type);
auto* ac = create<type::AccessControl>(ast::AccessControl::kWriteOnly, type);
auto* var_a = Var("a", ast::StorageClass::kUniformConstant, &ac);
auto* var_a = Global("a", ast::StorageClass::kUniformConstant, ac);
spirv::Builder& b = Build();
@ -601,15 +592,17 @@ TEST_F(BuilderTest, GlobalVar_TextureStorageWithDifferentAccess) {
// var<uniform_constant> a : [[access(read)]] texture_storage_2d<r32uint>;
// var<uniform_constant> b : [[access(write)]] texture_storage_2d<r32uint>;
type::StorageTexture st(type::TextureDimension::k2d,
type::ImageFormat::kR32Uint);
ASSERT_TRUE(td.DetermineStorageTextureSubtype(&st)) << td.error();
auto* st = create<type::StorageTexture>(type::TextureDimension::k2d,
type::ImageFormat::kR32Uint);
type::AccessControl type_a(ast::AccessControl::kReadOnly, &st);
auto* var_a = Var("a", ast::StorageClass::kUniformConstant, &type_a);
Global("test_var", ast::StorageClass::kNone, st);
type::AccessControl type_b(ast::AccessControl::kWriteOnly, &st);
auto* var_b = Var("b", ast::StorageClass::kUniformConstant, &type_b);
auto* type_a = create<type::AccessControl>(ast::AccessControl::kReadOnly, st);
auto* var_a = Global("a", ast::StorageClass::kUniformConstant, type_a);
auto* type_b =
create<type::AccessControl>(ast::AccessControl::kWriteOnly, st);
auto* var_b = Global("b", ast::StorageClass::kUniformConstant, type_b);
spirv::Builder& b = Build();

View File

@ -39,14 +39,12 @@ using BuilderTest = TestHelper;
TEST_F(BuilderTest, IdentifierExpression_GlobalConst) {
auto* init = vec3<f32>(1.f, 1.f, 3.f);
EXPECT_TRUE(td.DetermineResultType(init)) << td.error();
auto* v = Const("var", ast::StorageClass::kOutput, ty.f32(), init,
ast::VariableDecorationList{});
td.RegisterVariableForTesting(v);
auto* v = GlobalConst("var", ast::StorageClass::kOutput, ty.f32(), init,
ast::VariableDecorationList{});
auto* expr = Expr("var");
ASSERT_TRUE(td.DetermineResultType(expr));
WrapInFunction(expr);
spirv::Builder& b = Build();
@ -64,11 +62,10 @@ TEST_F(BuilderTest, IdentifierExpression_GlobalConst) {
}
TEST_F(BuilderTest, IdentifierExpression_GlobalVar) {
auto* v = Var("var", ast::StorageClass::kOutput, ty.f32());
td.RegisterVariableForTesting(v);
auto* v = Global("var", ast::StorageClass::kOutput, ty.f32());
auto* expr = Expr("var");
ASSERT_TRUE(td.DetermineResultType(expr));
WrapInFunction(expr);
spirv::Builder& b = Build();
@ -87,14 +84,12 @@ TEST_F(BuilderTest, IdentifierExpression_GlobalVar) {
TEST_F(BuilderTest, IdentifierExpression_FunctionConst) {
auto* init = vec3<f32>(1.f, 1.f, 3.f);
EXPECT_TRUE(td.DetermineResultType(init)) << td.error();
auto* v = Const("var", ast::StorageClass::kOutput, ty.f32(), init,
ast::VariableDecorationList{});
td.RegisterVariableForTesting(v);
auto* expr = Expr("var");
ASSERT_TRUE(td.DetermineResultType(expr));
WrapInFunction(v, expr);
spirv::Builder& b = Build();
@ -113,10 +108,8 @@ TEST_F(BuilderTest, IdentifierExpression_FunctionConst) {
TEST_F(BuilderTest, IdentifierExpression_FunctionVar) {
auto* v = Var("var", ast::StorageClass::kNone, ty.f32());
td.RegisterVariableForTesting(v);
auto* expr = Expr("var");
ASSERT_TRUE(td.DetermineResultType(expr));
WrapInFunction(v, expr);
spirv::Builder& b = Build();
@ -138,11 +131,10 @@ TEST_F(BuilderTest, IdentifierExpression_FunctionVar) {
}
TEST_F(BuilderTest, IdentifierExpression_Load) {
auto* var = Var("var", ast::StorageClass::kPrivate, ty.i32());
td.RegisterVariableForTesting(var);
auto* var = Global("var", ast::StorageClass::kPrivate, ty.i32());
auto* expr = Add("var", "var");
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
spirv::Builder& b = Build();
@ -164,12 +156,11 @@ TEST_F(BuilderTest, IdentifierExpression_Load) {
}
TEST_F(BuilderTest, IdentifierExpression_NoLoadConst) {
auto* var = Const("var", ast::StorageClass::kNone, ty.i32(), Expr(2),
ast::VariableDecorationList{});
td.RegisterVariableForTesting(var);
auto* var = GlobalConst("var", ast::StorageClass::kNone, ty.i32(), Expr(2),
ast::VariableDecorationList{});
auto* expr = Add("var", "var");
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
spirv::Builder& b = Build();

View File

@ -48,8 +48,7 @@ TEST_F(BuilderTest, If_Empty) {
auto* expr = create<ast::IfStatement>(
cond, create<ast::BlockStatement>(ast::StatementList{}),
ast::ElseStatementList{});
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
spirv::Builder& b = Build();
@ -77,8 +76,7 @@ TEST_F(BuilderTest, If_Empty_OutsideFunction_IsError) {
ast::ElseStatementList elses;
auto* block = create<ast::BlockStatement>(ast::StatementList{});
auto* expr = create<ast::IfStatement>(cond, block, elses);
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
spirv::Builder& b = Build();
@ -94,14 +92,12 @@ TEST_F(BuilderTest, If_WithStatements) {
// v = 2;
// }
auto* var = Var("v", ast::StorageClass::kPrivate, ty.i32());
auto* var = Global("v", ast::StorageClass::kPrivate, ty.i32());
auto* body = create<ast::BlockStatement>(
ast::StatementList{create<ast::AssignmentStatement>(Expr("v"), Expr(2))});
auto* expr =
create<ast::IfStatement>(Expr(true), body, ast::ElseStatementList{});
td.RegisterVariableForTesting(var);
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
spirv::Builder& b = Build();
@ -134,7 +130,7 @@ TEST_F(BuilderTest, If_WithElse) {
// v = 3;
// }
auto* var = Var("v", ast::StorageClass::kPrivate, ty.i32());
auto* var = Global("v", ast::StorageClass::kPrivate, ty.i32());
auto* body = create<ast::BlockStatement>(
ast::StatementList{create<ast::AssignmentStatement>(Expr("v"), Expr(2))});
auto* else_body = create<ast::BlockStatement>(
@ -143,10 +139,7 @@ TEST_F(BuilderTest, If_WithElse) {
auto* expr = create<ast::IfStatement>(
Expr(true), body,
ast::ElseStatementList{create<ast::ElseStatement>(nullptr, else_body)});
td.RegisterVariableForTesting(var);
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
spirv::Builder& b = Build();
@ -183,7 +176,7 @@ TEST_F(BuilderTest, If_WithElseIf) {
// v = 3;
// }
auto* var = Var("v", ast::StorageClass::kPrivate, ty.i32());
auto* var = Global("v", ast::StorageClass::kPrivate, ty.i32());
auto* body = create<ast::BlockStatement>(
ast::StatementList{create<ast::AssignmentStatement>(Expr("v"), Expr(2))});
auto* else_body = create<ast::BlockStatement>(
@ -194,10 +187,7 @@ TEST_F(BuilderTest, If_WithElseIf) {
ast::ElseStatementList{
create<ast::ElseStatement>(Expr(true), else_body),
});
td.RegisterVariableForTesting(var);
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
spirv::Builder& b = Build();
@ -243,7 +233,7 @@ TEST_F(BuilderTest, If_WithMultiple) {
// v = 5;
// }
auto* var = Var("v", ast::StorageClass::kPrivate, ty.i32());
auto* var = Global("v", ast::StorageClass::kPrivate, ty.i32());
auto* body = create<ast::BlockStatement>(
ast::StatementList{create<ast::AssignmentStatement>(Expr("v"), Expr(2))});
auto* elseif_1_body = create<ast::BlockStatement>(
@ -260,10 +250,7 @@ TEST_F(BuilderTest, If_WithMultiple) {
create<ast::ElseStatement>(Expr(false), elseif_2_body),
create<ast::ElseStatement>(nullptr, else_body),
});
td.RegisterVariableForTesting(var);
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
spirv::Builder& b = Build();
@ -332,8 +319,7 @@ TEST_F(BuilderTest, If_WithBreak) {
auto* expr = create<ast::LoopStatement>(
loop_body, create<ast::BlockStatement>(ast::StatementList{}));
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
spirv::Builder& b = Build();
@ -382,8 +368,7 @@ TEST_F(BuilderTest, If_WithElseBreak) {
auto* expr = create<ast::LoopStatement>(
loop_body, create<ast::BlockStatement>(ast::StatementList{}));
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
spirv::Builder& b = Build();
@ -432,8 +417,7 @@ TEST_F(BuilderTest, If_WithContinue) {
auto* expr = create<ast::LoopStatement>(
loop_body, create<ast::BlockStatement>(ast::StatementList{}));
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
spirv::Builder& b = Build();
@ -482,8 +466,7 @@ TEST_F(BuilderTest, If_WithElseContinue) {
auto* expr = create<ast::LoopStatement>(
loop_body, create<ast::BlockStatement>(ast::StatementList{}));
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
spirv::Builder& b = Build();
@ -523,7 +506,7 @@ TEST_F(BuilderTest, If_WithReturn) {
auto* expr =
create<ast::IfStatement>(Expr(true), if_body, ast::ElseStatementList{});
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
spirv::Builder& b = Build();
@ -552,7 +535,7 @@ TEST_F(BuilderTest, If_WithReturnValue) {
auto* expr =
create<ast::IfStatement>(Expr(true), if_body, ast::ElseStatementList{});
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
spirv::Builder& b = Build();
@ -577,14 +560,12 @@ TEST_F(BuilderTest, If_WithLoad_Bug327) {
// if (a) {
// }
auto* var = Var("a", ast::StorageClass::kFunction, ty.bool_());
td.RegisterVariableForTesting(var);
auto* var = Global("a", ast::StorageClass::kFunction, ty.bool_());
auto* expr = create<ast::IfStatement>(
Expr("a"), create<ast::BlockStatement>(ast::StatementList{}),
ast::ElseStatementList{});
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
spirv::Builder& b = Build();

View File

@ -69,10 +69,10 @@ using IntrinsicBoolTest = IntrinsicBuilderTestWithParam<IntrinsicData>;
TEST_P(IntrinsicBoolTest, Call_Bool) {
auto param = GetParam();
auto* var = Var("v", ast::StorageClass::kPrivate, ty.vec3<bool>());
auto* expr = Call(param.name, "v");
auto* var = Global("v", ast::StorageClass::kPrivate, ty.vec3<bool>());
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
auto* expr = Call(param.name, "v");
WrapInFunction(expr);
spirv::Builder& b = Build();
@ -100,10 +100,10 @@ using IntrinsicFloatTest = IntrinsicBuilderTestWithParam<IntrinsicData>;
TEST_P(IntrinsicFloatTest, Call_Float_Scalar) {
auto param = GetParam();
auto* var = Var("v", ast::StorageClass::kPrivate, ty.f32());
auto* expr = Call(param.name, "v");
auto* var = Global("v", ast::StorageClass::kPrivate, ty.f32());
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
auto* expr = Call(param.name, "v");
WrapInFunction(expr);
spirv::Builder& b = Build();
@ -126,10 +126,10 @@ TEST_P(IntrinsicFloatTest, Call_Float_Scalar) {
TEST_P(IntrinsicFloatTest, Call_Float_Vector) {
auto param = GetParam();
auto* var = Var("v", ast::StorageClass::kPrivate, ty.vec3<f32>());
auto* expr = Call(param.name, "v");
auto* var = Global("v", ast::StorageClass::kPrivate, ty.vec3<f32>());
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
auto* expr = Call(param.name, "v");
WrapInFunction(expr);
spirv::Builder& b = Build();
@ -159,10 +159,10 @@ using IntrinsicIntTest = IntrinsicBuilderTestWithParam<IntrinsicData>;
TEST_P(IntrinsicIntTest, Call_SInt_Scalar) {
auto param = GetParam();
auto* var = Var("v", ast::StorageClass::kPrivate, ty.i32());
auto* expr = Call(param.name, "v");
auto* var = Global("v", ast::StorageClass::kPrivate, ty.i32());
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
auto* expr = Call(param.name, "v");
WrapInFunction(expr);
spirv::Builder& b = Build();
@ -184,10 +184,10 @@ TEST_P(IntrinsicIntTest, Call_SInt_Scalar) {
TEST_P(IntrinsicIntTest, Call_SInt_Vector) {
auto param = GetParam();
auto* var = Var("v", ast::StorageClass::kPrivate, ty.vec3<i32>());
auto* expr = Call(param.name, "v");
auto* var = Global("v", ast::StorageClass::kPrivate, ty.vec3<i32>());
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
auto* expr = Call(param.name, "v");
WrapInFunction(expr);
spirv::Builder& b = Build();
@ -210,10 +210,10 @@ TEST_P(IntrinsicIntTest, Call_SInt_Vector) {
TEST_P(IntrinsicIntTest, Call_UInt_Scalar) {
auto param = GetParam();
auto* var = Var("v", ast::StorageClass::kPrivate, ty.u32());
auto* expr = Call(param.name, "v");
auto* var = Global("v", ast::StorageClass::kPrivate, ty.u32());
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
auto* expr = Call(param.name, "v");
WrapInFunction(expr);
spirv::Builder& b = Build();
@ -235,10 +235,10 @@ TEST_P(IntrinsicIntTest, Call_UInt_Scalar) {
TEST_P(IntrinsicIntTest, Call_UInt_Vector) {
auto param = GetParam();
auto* var = Var("v", ast::StorageClass::kPrivate, ty.vec3<u32>());
auto* expr = Call(param.name, "v");
auto* var = Global("v", ast::StorageClass::kPrivate, ty.vec3<u32>());
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
auto* expr = Call(param.name, "v");
WrapInFunction(expr);
spirv::Builder& b = Build();
@ -264,10 +264,10 @@ INSTANTIATE_TEST_SUITE_P(
IntrinsicData{"reverseBits", "OpBitReverse"}));
TEST_F(IntrinsicBuilderTest, Call_Dot) {
auto* var = Var("v", ast::StorageClass::kPrivate, ty.vec3<f32>());
auto* expr = Call("dot", "v", "v");
auto* var = Global("v", ast::StorageClass::kPrivate, ty.vec3<f32>());
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
auto* expr = Call("dot", "v", "v");
WrapInFunction(expr);
spirv::Builder& b = Build();
@ -292,10 +292,10 @@ using IntrinsicDeriveTest = IntrinsicBuilderTestWithParam<IntrinsicData>;
TEST_P(IntrinsicDeriveTest, Call_Derivative_Scalar) {
auto param = GetParam();
auto* var = Var("v", ast::StorageClass::kPrivate, ty.f32());
auto* expr = Call(param.name, "v");
auto* var = Global("v", ast::StorageClass::kPrivate, ty.f32());
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
auto* expr = Call(param.name, "v");
WrapInFunction(expr);
spirv::Builder& b = Build();
@ -317,10 +317,10 @@ TEST_P(IntrinsicDeriveTest, Call_Derivative_Scalar) {
TEST_P(IntrinsicDeriveTest, Call_Derivative_Vector) {
auto param = GetParam();
auto* var = Var("v", ast::StorageClass::kPrivate, ty.vec3<f32>());
auto* expr = Call(param.name, "v");
auto* var = Global("v", ast::StorageClass::kPrivate, ty.vec3<f32>());
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
auto* expr = Call(param.name, "v");
WrapInFunction(expr);
spirv::Builder& b = Build();
@ -360,11 +360,13 @@ INSTANTIATE_TEST_SUITE_P(
IntrinsicData{"fwidthCoarse", "OpFwidthCoarse"}));
TEST_F(IntrinsicBuilderTest, Call_Select) {
auto* v3 = Var("v3", ast::StorageClass::kPrivate, ty.vec3<f32>());
auto* bool_v3 = Var("bool_v3", ast::StorageClass::kPrivate, ty.vec3<bool>());
auto* expr = Call("select", "v3", "v3", "bool_v3");
auto* v3 = Global("v3", ast::StorageClass::kPrivate, ty.vec3<f32>());
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
auto* bool_v3 =
Global("bool_v3", ast::StorageClass::kPrivate, ty.vec3<bool>());
auto* expr = Call("select", "v3", "v3", "bool_v3");
WrapInFunction(expr);
spirv::Builder& b = Build();
@ -398,15 +400,17 @@ TEST_F(IntrinsicBuilderTest, Call_TextureSampleCompare_Twice) {
type::Sampler s(type::SamplerKind::kComparisonSampler);
type::DepthTexture t(type::TextureDimension::k2d);
auto* tex = Var("texture", ast::StorageClass::kNone, &t);
auto* sampler = Var("sampler", ast::StorageClass::kNone, &s);
auto* tex = Global("texture", ast::StorageClass::kNone, &t);
auto* sampler = Global("sampler", ast::StorageClass::kNone, &s);
auto* expr1 = Call("textureSampleCompare", "texture", "sampler",
vec2<f32>(1.0f, 2.0f), 2.0f);
auto* expr2 = Call("textureSampleCompare", "texture", "sampler",
vec2<f32>(1.0f, 2.0f), 2.0f);
EXPECT_TRUE(td.DetermineResultType(expr1)) << td.error();
EXPECT_TRUE(td.DetermineResultType(expr2)) << td.error();
WrapInFunction(expr1);
WrapInFunction(expr2);
spirv::Builder& b = Build();
@ -446,10 +450,10 @@ TEST_F(IntrinsicBuilderTest, Call_TextureSampleCompare_Twice) {
}
TEST_F(IntrinsicBuilderTest, Call_GLSLMethod_WithLoad) {
auto* var = Var("ident", ast::StorageClass::kPrivate, ty.f32());
auto* expr = Call("round", "ident");
auto* var = Global("ident", ast::StorageClass::kPrivate, ty.f32());
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
auto* expr = Call("round", "ident");
WrapInFunction(expr);
auto* func = Func("a_func", ast::VariableList{}, ty.void_(),
ast::StatementList{}, ast::FunctionDecorationList{});
@ -484,7 +488,7 @@ TEST_P(Intrinsic_Builtin_SingleParam_Float_Test, Call_Scalar) {
auto param = GetParam();
auto* expr = Call(param.name, 1.0f);
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
auto* func = Func("a_func", ast::VariableList{}, ty.void_(),
ast::StatementList{}, ast::FunctionDecorationList{});
@ -513,7 +517,7 @@ TEST_P(Intrinsic_Builtin_SingleParam_Float_Test, Call_Vector) {
auto param = GetParam();
auto* expr = Call(param.name, vec2<f32>(1.0f, 1.0f));
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
auto* func = Func("a_func", ast::VariableList{}, ty.void_(),
ast::StatementList{}, ast::FunctionDecorationList{});
@ -568,7 +572,7 @@ INSTANTIATE_TEST_SUITE_P(IntrinsicBuilderTest,
TEST_F(IntrinsicBuilderTest, Call_Length_Scalar) {
auto* expr = Call("length", 1.0f);
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
auto* func = Func("a_func", ast::VariableList{}, ty.void_(),
ast::StatementList{}, ast::FunctionDecorationList{});
@ -594,7 +598,7 @@ OpFunctionEnd
TEST_F(IntrinsicBuilderTest, Call_Length_Vector) {
auto* expr = Call("length", vec2<f32>(1.0f, 1.0f));
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
auto* func = Func("a_func", ast::VariableList{}, ty.void_(),
ast::StatementList{}, ast::FunctionDecorationList{});
@ -622,7 +626,7 @@ OpFunctionEnd
TEST_F(IntrinsicBuilderTest, Call_Normalize) {
auto* expr = Call("normalize", vec2<f32>(1.0f, 1.0f));
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
auto* func = Func("a_func", ast::VariableList{}, ty.void_(),
ast::StatementList{}, ast::FunctionDecorationList{});
@ -655,7 +659,7 @@ TEST_P(Intrinsic_Builtin_DualParam_Float_Test, Call_Scalar) {
auto* expr = Call(param.name, 1.0f, 1.0f);
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
auto* func = Func("a_func", ast::VariableList{}, ty.void_(),
ast::StatementList{}, ast::FunctionDecorationList{});
@ -685,7 +689,7 @@ TEST_P(Intrinsic_Builtin_DualParam_Float_Test, Call_Vector) {
auto* expr = Call(param.name, vec2<f32>(1.0f, 1.0f), vec2<f32>(1.0f, 1.0f));
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
auto* func = Func("a_func", ast::VariableList{}, ty.void_(),
ast::StatementList{}, ast::FunctionDecorationList{});
@ -723,7 +727,7 @@ INSTANTIATE_TEST_SUITE_P(IntrinsicBuilderTest,
TEST_F(IntrinsicBuilderTest, Call_Distance_Scalar) {
auto* expr = Call("distance", 1.0f, 1.0f);
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
auto* func = Func("a_func", ast::VariableList{}, ty.void_(),
ast::StatementList{}, ast::FunctionDecorationList{});
@ -750,7 +754,7 @@ OpFunctionEnd
TEST_F(IntrinsicBuilderTest, Call_Distance_Vector) {
auto* expr = Call("distance", vec2<f32>(1.0f, 1.0f), vec2<f32>(1.0f, 1.0f));
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
auto* func = Func("a_func", ast::VariableList{}, ty.void_(),
ast::StatementList{}, ast::FunctionDecorationList{});
@ -780,7 +784,7 @@ TEST_F(IntrinsicBuilderTest, Call_Cross) {
auto* expr =
Call("cross", vec3<f32>(1.0f, 1.0f, 1.0f), vec3<f32>(1.0f, 1.0f, 1.0f));
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
auto* func = Func("a_func", ast::VariableList{}, ty.void_(),
ast::StatementList{}, ast::FunctionDecorationList{});
@ -812,7 +816,7 @@ TEST_P(Intrinsic_Builtin_ThreeParam_Float_Test, Call_Scalar) {
auto param = GetParam();
auto* expr = Call(param.name, 1.0f, 1.0f, 1.0f);
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
auto* func = Func("a_func", ast::VariableList{}, ty.void_(),
ast::StatementList{}, ast::FunctionDecorationList{});
@ -843,7 +847,7 @@ TEST_P(Intrinsic_Builtin_ThreeParam_Float_Test, Call_Vector) {
auto* expr = Call(param.name, vec2<f32>(1.0f, 1.0f), vec2<f32>(1.0f, 1.0f),
vec2<f32>(1.0f, 1.0f));
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
auto* func = Func("a_func", ast::VariableList{}, ty.void_(),
ast::StatementList{}, ast::FunctionDecorationList{});
@ -885,7 +889,7 @@ TEST_P(Intrinsic_Builtin_SingleParam_Sint_Test, Call_Scalar) {
auto param = GetParam();
auto* expr = Call(param.name, 1);
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
auto* func = Func("a_func", ast::VariableList{}, ty.void_(),
ast::StatementList{}, ast::FunctionDecorationList{});
@ -914,7 +918,7 @@ TEST_P(Intrinsic_Builtin_SingleParam_Sint_Test, Call_Vector) {
auto param = GetParam();
auto* expr = Call(param.name, vec2<i32>(1, 1));
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
auto* func = Func("a_func", ast::VariableList{}, ty.void_(),
ast::StatementList{}, ast::FunctionDecorationList{});
@ -950,7 +954,7 @@ TEST_P(Intrinsic_Builtin_SingleParam_Uint_Test, Call_Scalar) {
auto param = GetParam();
auto* expr = Call(param.name, 1u);
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
auto* func = Func("a_func", ast::VariableList{}, ty.void_(),
ast::StatementList{}, ast::FunctionDecorationList{});
@ -979,7 +983,7 @@ TEST_P(Intrinsic_Builtin_SingleParam_Uint_Test, Call_Vector) {
auto param = GetParam();
auto* expr = Call(param.name, vec2<u32>(1u, 1u));
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
auto* func = Func("a_func", ast::VariableList{}, ty.void_(),
ast::StatementList{}, ast::FunctionDecorationList{});
@ -1015,7 +1019,7 @@ TEST_P(Intrinsic_Builtin_DualParam_SInt_Test, Call_Scalar) {
auto param = GetParam();
auto* expr = Call(param.name, 1, 1);
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
auto* func = Func("a_func", ast::VariableList{}, ty.void_(),
ast::StatementList{}, ast::FunctionDecorationList{});
@ -1044,7 +1048,7 @@ TEST_P(Intrinsic_Builtin_DualParam_SInt_Test, Call_Vector) {
auto param = GetParam();
auto* expr = Call(param.name, vec2<i32>(1, 1), vec2<i32>(1, 1));
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
auto* func = Func("a_func", ast::VariableList{}, ty.void_(),
ast::StatementList{}, ast::FunctionDecorationList{});
@ -1081,7 +1085,7 @@ TEST_P(Intrinsic_Builtin_DualParam_UInt_Test, Call_Scalar) {
auto param = GetParam();
auto* expr = Call(param.name, 1u, 1u);
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
auto* func = Func("a_func", ast::VariableList{}, ty.void_(),
ast::StatementList{}, ast::FunctionDecorationList{});
@ -1110,7 +1114,7 @@ TEST_P(Intrinsic_Builtin_DualParam_UInt_Test, Call_Vector) {
auto param = GetParam();
auto* expr = Call(param.name, vec2<u32>(1u, 1u), vec2<u32>(1u, 1u));
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
auto* func = Func("a_func", ast::VariableList{}, ty.void_(),
ast::StatementList{}, ast::FunctionDecorationList{});
@ -1147,7 +1151,7 @@ TEST_P(Intrinsic_Builtin_ThreeParam_Sint_Test, Call_Scalar) {
auto param = GetParam();
auto* expr = Call(param.name, 1, 1, 1);
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
auto* func = Func("a_func", ast::VariableList{}, ty.void_(),
ast::StatementList{}, ast::FunctionDecorationList{});
@ -1178,7 +1182,7 @@ TEST_P(Intrinsic_Builtin_ThreeParam_Sint_Test, Call_Vector) {
auto* expr =
Call(param.name, vec2<i32>(1, 1), vec2<i32>(1, 1), vec2<i32>(1, 1));
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
auto* func = Func("a_func", ast::VariableList{}, ty.void_(),
ast::StatementList{}, ast::FunctionDecorationList{});
@ -1214,7 +1218,7 @@ TEST_P(Intrinsic_Builtin_ThreeParam_Uint_Test, Call_Scalar) {
auto param = GetParam();
auto* expr = Call(param.name, 1u, 1u, 1u);
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
auto* func = Func("a_func", ast::VariableList{}, ty.void_(),
ast::StatementList{}, ast::FunctionDecorationList{});
@ -1245,7 +1249,7 @@ TEST_P(Intrinsic_Builtin_ThreeParam_Uint_Test, Call_Vector) {
auto* expr =
Call(param.name, vec2<u32>(1u, 1u), vec2<u32>(1u, 1u), vec2<u32>(1u, 1u));
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
auto* func = Func("a_func", ast::VariableList{}, ty.void_(),
ast::StatementList{}, ast::FunctionDecorationList{});
@ -1276,10 +1280,10 @@ INSTANTIATE_TEST_SUITE_P(IntrinsicBuilderTest,
testing::Values(IntrinsicData{"clamp", "UClamp"}));
TEST_F(IntrinsicBuilderTest, Call_Determinant) {
auto* var = Var("var", ast::StorageClass::kPrivate, ty.mat3x3<f32>());
auto* expr = Call("determinant", "var");
auto* var = Global("var", ast::StorageClass::kPrivate, ty.mat3x3<f32>());
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
auto* expr = Call("determinant", "var");
WrapInFunction(expr);
auto* func = Func("a_func", ast::VariableList{}, ty.void_(),
ast::StatementList{}, ast::FunctionDecorationList{});
@ -1316,10 +1320,10 @@ TEST_F(IntrinsicBuilderTest, Call_ArrayLength) {
create<ast::Struct>(ast::StructMemberList{Member("a", ty.array<f32>())},
ast::StructDecorationList{});
auto* s_type = ty.struct_("my_struct", s);
auto* var = Var("b", ast::StorageClass::kPrivate, s_type);
auto* expr = Call("arrayLength", MemberAccessor("b", "a"));
auto* var = Global("b", ast::StorageClass::kPrivate, s_type);
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
auto* expr = Call("arrayLength", MemberAccessor("b", "a"));
WrapInFunction(expr);
auto* func = Func("a_func", ast::VariableList{}, ty.void_(),
ast::StatementList{}, ast::FunctionDecorationList{});
@ -1354,10 +1358,10 @@ TEST_F(IntrinsicBuilderTest, Call_ArrayLength_OtherMembersInStruct) {
ast::StructDecorationList{});
auto* s_type = ty.struct_("my_struct", s);
auto* var = Var("b", ast::StorageClass::kPrivate, s_type);
auto* expr = Call("arrayLength", MemberAccessor("b", "a"));
auto* var = Global("b", ast::StorageClass::kPrivate, s_type);
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
auto* expr = Call("arrayLength", MemberAccessor("b", "a"));
WrapInFunction(expr);
auto* func = Func("a_func", ast::VariableList{}, ty.void_(),
ast::StatementList{}, ast::FunctionDecorationList{});

View File

@ -4126,9 +4126,7 @@ TEST_P(IntrinsicTextureTest, Call) {
auto* call =
create<ast::CallExpression>(Expr(param.function), param.args(this));
EXPECT_TRUE(td.Determine()) << td.error();
EXPECT_TRUE(td.DetermineResultType(call)) << td.error();
WrapInFunction(call);
spirv::Builder& b = Build();
@ -4149,8 +4147,8 @@ TEST_P(IntrinsicTextureTest, Call) {
TEST_P(IntrinsicTextureTest, ValidateSPIRV) {
auto param = GetParam();
AST().AddGlobalVariable(param.buildTextureVariable(this));
AST().AddGlobalVariable(param.buildSamplerVariable(this));
param.buildTextureVariable(this);
param.buildSamplerVariable(this);
auto* call =
create<ast::CallExpression>(Expr(param.function), param.args(this));
@ -4163,11 +4161,9 @@ TEST_P(IntrinsicTextureTest, ValidateSPIRV) {
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
});
ASSERT_TRUE(td.Determine()) << td.error();
spirv::Builder& b = Build();
ASSERT_TRUE(b.Build()) << td.error();
ASSERT_TRUE(b.Build()) << b.error();
BinaryWriter writer;
writer.WriteHeader(b.id_bound());
@ -4211,11 +4207,12 @@ TEST_P(IntrinsicTextureTest, OutsideFunction_IsError) {
auto* texture = param.buildTextureVariable(this);
auto* sampler = param.buildSamplerVariable(this);
AST().AddGlobalVariable(texture);
AST().AddGlobalVariable(sampler);
auto* call =
create<ast::CallExpression>(Expr(param.function), param.args(this));
EXPECT_TRUE(td.DetermineResultType(call)) << td.error();
WrapInFunction(call);
spirv::Builder& b = Build();

View File

@ -42,8 +42,7 @@ TEST_F(BuilderTest, Loop_Empty) {
auto* loop = create<ast::LoopStatement>(
create<ast::BlockStatement>(ast::StatementList{}),
create<ast::BlockStatement>(ast::StatementList{}));
ASSERT_TRUE(td.DetermineResultType(loop)) << td.error();
WrapInFunction(loop);
spirv::Builder& b = Build();
@ -68,15 +67,13 @@ TEST_F(BuilderTest, Loop_WithoutContinuing) {
// v = 2;
// }
auto* var = Var("v", ast::StorageClass::kPrivate, ty.i32());
auto* var = Global("v", ast::StorageClass::kPrivate, ty.i32());
auto* body = create<ast::BlockStatement>(
ast::StatementList{create<ast::AssignmentStatement>(Expr("v"), Expr(2))});
auto* loop = create<ast::LoopStatement>(
body, create<ast::BlockStatement>(ast::StatementList{}));
td.RegisterVariableForTesting(var);
ASSERT_TRUE(td.DetermineResultType(loop)) << td.error();
WrapInFunction(loop);
spirv::Builder& b = Build();
@ -112,16 +109,14 @@ TEST_F(BuilderTest, Loop_WithContinuing) {
// }
// }
auto* var = Var("v", ast::StorageClass::kPrivate, ty.i32());
auto* var = Global("v", ast::StorageClass::kPrivate, ty.i32());
auto* body = create<ast::BlockStatement>(
ast::StatementList{create<ast::AssignmentStatement>(Expr("v"), Expr(2))});
auto* continuing = create<ast::BlockStatement>(
ast::StatementList{create<ast::AssignmentStatement>(Expr("v"), Expr(3))});
auto* loop = create<ast::LoopStatement>(body, continuing);
td.RegisterVariableForTesting(var);
ASSERT_TRUE(td.DetermineResultType(loop)) << td.error();
WrapInFunction(loop);
spirv::Builder& b = Build();
@ -160,8 +155,7 @@ TEST_F(BuilderTest, Loop_WithContinue) {
});
auto* loop = create<ast::LoopStatement>(
body, create<ast::BlockStatement>(ast::StatementList{}));
ASSERT_TRUE(td.DetermineResultType(loop)) << td.error();
WrapInFunction(loop);
spirv::Builder& b = Build();
@ -190,8 +184,7 @@ TEST_F(BuilderTest, Loop_WithBreak) {
});
auto* loop = create<ast::LoopStatement>(
body, create<ast::BlockStatement>(ast::StatementList{}));
ASSERT_TRUE(td.DetermineResultType(loop)) << td.error();
WrapInFunction(loop);
spirv::Builder& b = Build();

View File

@ -51,8 +51,7 @@ TEST_F(BuilderTest, Return_WithValue) {
auto* val = vec3<f32>(1.f, 1.f, 3.f);
auto* ret = create<ast::ReturnStatement>(val);
EXPECT_TRUE(td.DetermineResultType(ret)) << td.error();
WrapInFunction(ret);
spirv::Builder& b = Build();
@ -72,12 +71,10 @@ TEST_F(BuilderTest, Return_WithValue) {
}
TEST_F(BuilderTest, Return_WithValue_GeneratesLoad) {
auto* var = Var("param", ast::StorageClass::kFunction, ty.f32());
auto* var = Global("param", ast::StorageClass::kFunction, ty.f32());
auto* ret = create<ast::ReturnStatement>(Expr("param"));
td.RegisterVariableForTesting(var);
EXPECT_TRUE(td.DetermineResultType(ret)) << td.error();
WrapInFunction(ret);
spirv::Builder& b = Build();

View File

@ -44,7 +44,8 @@ TEST_F(BuilderTest, Switch_Empty) {
// }
auto* expr = create<ast::SwitchStatement>(Expr(1), ast::CaseStatementList{});
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
spirv::Builder& b = Build();
@ -71,8 +72,8 @@ TEST_F(BuilderTest, Switch_WithCase) {
// v = 2;
// }
auto* v = Var("v", ast::StorageClass::kPrivate, ty.i32());
auto* a = Var("a", ast::StorageClass::kPrivate, ty.i32());
auto* v = Global("v", ast::StorageClass::kPrivate, ty.i32());
auto* a = Global("a", ast::StorageClass::kPrivate, ty.i32());
auto* case_1_body = create<ast::BlockStatement>(
ast::StatementList{create<ast::AssignmentStatement>(Expr("v"), Expr(1))});
@ -92,9 +93,7 @@ TEST_F(BuilderTest, Switch_WithCase) {
auto* expr = create<ast::SwitchStatement>(Expr("a"), cases);
td.RegisterVariableForTesting(v);
td.RegisterVariableForTesting(a);
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
auto* func = Func("a_func", {}, ty.i32(), ast::StatementList{},
ast::FunctionDecorationList{});
@ -143,8 +142,8 @@ TEST_F(BuilderTest, Switch_WithDefault) {
// v = 1;
// }
auto* v = Var("v", ast::StorageClass::kPrivate, ty.i32());
auto* a = Var("a", ast::StorageClass::kPrivate, ty.i32());
auto* v = Global("v", ast::StorageClass::kPrivate, ty.i32());
auto* a = Global("a", ast::StorageClass::kPrivate, ty.i32());
auto* default_body = create<ast::BlockStatement>(
ast::StatementList{create<ast::AssignmentStatement>(Expr("v"), Expr(1))});
@ -155,9 +154,7 @@ TEST_F(BuilderTest, Switch_WithDefault) {
auto* expr = create<ast::SwitchStatement>(Expr("a"), cases);
td.RegisterVariableForTesting(v);
td.RegisterVariableForTesting(a);
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
auto* func = Func("a_func", {}, ty.i32(), ast::StatementList{},
ast::FunctionDecorationList{});
@ -204,8 +201,8 @@ TEST_F(BuilderTest, Switch_WithCaseAndDefault) {
// v = 3;
// }
auto* v = Var("v", ast::StorageClass::kPrivate, ty.i32());
auto* a = Var("a", ast::StorageClass::kPrivate, ty.i32());
auto* v = Global("v", ast::StorageClass::kPrivate, ty.i32());
auto* a = Global("a", ast::StorageClass::kPrivate, ty.i32());
auto* case_1_body = create<ast::BlockStatement>(
ast::StatementList{create<ast::AssignmentStatement>(Expr("v"), Expr(1))});
@ -231,9 +228,7 @@ TEST_F(BuilderTest, Switch_WithCaseAndDefault) {
auto* expr = create<ast::SwitchStatement>(Expr("a"), cases);
td.RegisterVariableForTesting(v);
td.RegisterVariableForTesting(a);
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
auto* func = Func("a_func", {}, ty.i32(), ast::StatementList{},
ast::FunctionDecorationList{});
@ -289,8 +284,8 @@ TEST_F(BuilderTest, Switch_CaseWithFallthrough) {
// v = 3;
// }
auto* v = Var("v", ast::StorageClass::kPrivate, ty.i32());
auto* a = Var("a", ast::StorageClass::kPrivate, ty.i32());
auto* v = Global("v", ast::StorageClass::kPrivate, ty.i32());
auto* a = Global("a", ast::StorageClass::kPrivate, ty.i32());
auto* case_1_body = create<ast::BlockStatement>(
ast::StatementList{create<ast::AssignmentStatement>(Expr("v"), Expr(1)),
@ -316,9 +311,7 @@ TEST_F(BuilderTest, Switch_CaseWithFallthrough) {
auto* expr = create<ast::SwitchStatement>(Expr("a"), cases);
td.RegisterVariableForTesting(v);
td.RegisterVariableForTesting(a);
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
auto* func = Func("a_func", {}, ty.i32(), ast::StatementList{},
ast::FunctionDecorationList{});
@ -370,8 +363,8 @@ TEST_F(BuilderTest, Switch_CaseFallthroughLastStatement) {
// fallthrough;
// }
auto* v = Var("v", ast::StorageClass::kPrivate, ty.i32());
auto* a = Var("a", ast::StorageClass::kPrivate, ty.i32());
auto* v = Global("v", ast::StorageClass::kPrivate, ty.i32());
auto* a = Global("a", ast::StorageClass::kPrivate, ty.i32());
auto* case_1_body = create<ast::BlockStatement>(
ast::StatementList{create<ast::AssignmentStatement>(Expr("v"), Expr(1)),
@ -385,9 +378,7 @@ TEST_F(BuilderTest, Switch_CaseFallthroughLastStatement) {
auto* expr = create<ast::SwitchStatement>(Expr("a"), cases);
td.RegisterVariableForTesting(v);
td.RegisterVariableForTesting(a);
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
auto* func = Func("a_func", {}, ty.i32(), ast::StatementList{},
ast::FunctionDecorationList{});
@ -411,8 +402,8 @@ TEST_F(BuilderTest, Switch_WithNestedBreak) {
// v = 1;
// }
auto* v = Var("v", ast::StorageClass::kPrivate, ty.i32());
auto* a = Var("a", ast::StorageClass::kPrivate, ty.i32());
auto* v = Global("v", ast::StorageClass::kPrivate, ty.i32());
auto* a = Global("a", ast::StorageClass::kPrivate, ty.i32());
auto* if_body = create<ast::BlockStatement>(ast::StatementList{
create<ast::BreakStatement>(),
@ -430,9 +421,7 @@ TEST_F(BuilderTest, Switch_WithNestedBreak) {
auto* expr = create<ast::SwitchStatement>(Expr("a"), cases);
td.RegisterVariableForTesting(v);
td.RegisterVariableForTesting(a);
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
auto* func = Func("a_func", {}, ty.i32(), ast::StatementList{},
ast::FunctionDecorationList{});

View File

@ -733,11 +733,11 @@ TEST_F(BuilderTest_Type, MultisampledTexture_Generate_2d_f32) {
}
TEST_F(BuilderTest_Type, SampledTexture_Generate_1d_i32) {
type::SampledTexture s(type::TextureDimension::k1d, ty.i32());
auto* s = create<type::SampledTexture>(type::TextureDimension::k1d, ty.i32());
spirv::Builder& b = Build();
EXPECT_EQ(b.GenerateTypeIfNeeded(&s), 1u);
EXPECT_EQ(b.GenerateTypeIfNeeded(s), 1u);
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()),
R"(%2 = OpTypeInt 32 1
@ -750,11 +750,11 @@ TEST_F(BuilderTest_Type, SampledTexture_Generate_1d_i32) {
}
TEST_F(BuilderTest_Type, SampledTexture_Generate_1d_u32) {
type::SampledTexture s(type::TextureDimension::k1d, ty.u32());
auto* s = create<type::SampledTexture>(type::TextureDimension::k1d, ty.u32());
spirv::Builder& b = Build();
EXPECT_EQ(b.GenerateTypeIfNeeded(&s), 1u);
EXPECT_EQ(b.GenerateTypeIfNeeded(s), 1u);
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()),
R"(%2 = OpTypeInt 32 0
@ -767,11 +767,11 @@ TEST_F(BuilderTest_Type, SampledTexture_Generate_1d_u32) {
}
TEST_F(BuilderTest_Type, SampledTexture_Generate_1d_f32) {
type::SampledTexture s(type::TextureDimension::k1d, ty.f32());
auto* s = create<type::SampledTexture>(type::TextureDimension::k1d, ty.f32());
spirv::Builder& b = Build();
EXPECT_EQ(b.GenerateTypeIfNeeded(&s), 1u);
EXPECT_EQ(b.GenerateTypeIfNeeded(s), 1u);
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()),
R"(%2 = OpTypeFloat 32
@ -784,11 +784,12 @@ TEST_F(BuilderTest_Type, SampledTexture_Generate_1d_f32) {
}
TEST_F(BuilderTest_Type, SampledTexture_Generate_1dArray) {
type::SampledTexture s(type::TextureDimension::k1dArray, ty.f32());
auto* s =
create<type::SampledTexture>(type::TextureDimension::k1dArray, ty.f32());
spirv::Builder& b = Build();
EXPECT_EQ(b.GenerateTypeIfNeeded(&s), 1u);
EXPECT_EQ(b.GenerateTypeIfNeeded(s), 1u);
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()),
R"(%2 = OpTypeFloat 32
@ -801,11 +802,11 @@ TEST_F(BuilderTest_Type, SampledTexture_Generate_1dArray) {
}
TEST_F(BuilderTest_Type, SampledTexture_Generate_2d) {
type::SampledTexture s(type::TextureDimension::k2d, ty.f32());
auto* s = create<type::SampledTexture>(type::TextureDimension::k2d, ty.f32());
spirv::Builder& b = Build();
EXPECT_EQ(b.GenerateTypeIfNeeded(&s), 1u);
EXPECT_EQ(b.GenerateTypeIfNeeded(s), 1u);
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()),
R"(%2 = OpTypeFloat 32
@ -814,11 +815,12 @@ TEST_F(BuilderTest_Type, SampledTexture_Generate_2d) {
}
TEST_F(BuilderTest_Type, SampledTexture_Generate_2d_array) {
type::SampledTexture s(type::TextureDimension::k2dArray, ty.f32());
auto* s =
create<type::SampledTexture>(type::TextureDimension::k2dArray, ty.f32());
spirv::Builder& b = Build();
EXPECT_EQ(b.GenerateTypeIfNeeded(&s), 1u);
EXPECT_EQ(b.GenerateTypeIfNeeded(s), 1u);
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()),
R"(%2 = OpTypeFloat 32
@ -827,11 +829,11 @@ TEST_F(BuilderTest_Type, SampledTexture_Generate_2d_array) {
}
TEST_F(BuilderTest_Type, SampledTexture_Generate_3d) {
type::SampledTexture s(type::TextureDimension::k3d, ty.f32());
auto* s = create<type::SampledTexture>(type::TextureDimension::k3d, ty.f32());
spirv::Builder& b = Build();
EXPECT_EQ(b.GenerateTypeIfNeeded(&s), 1u);
EXPECT_EQ(b.GenerateTypeIfNeeded(s), 1u);
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()),
R"(%2 = OpTypeFloat 32
@ -840,11 +842,12 @@ TEST_F(BuilderTest_Type, SampledTexture_Generate_3d) {
}
TEST_F(BuilderTest_Type, SampledTexture_Generate_Cube) {
type::SampledTexture s(type::TextureDimension::kCube, ty.f32());
auto* s =
create<type::SampledTexture>(type::TextureDimension::kCube, ty.f32());
spirv::Builder& b = Build();
EXPECT_EQ(b.GenerateTypeIfNeeded(&s), 1u);
EXPECT_EQ(b.GenerateTypeIfNeeded(s), 1u);
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()),
R"(%2 = OpTypeFloat 32
@ -854,11 +857,12 @@ TEST_F(BuilderTest_Type, SampledTexture_Generate_Cube) {
}
TEST_F(BuilderTest_Type, SampledTexture_Generate_CubeArray) {
type::SampledTexture s(type::TextureDimension::kCubeArray, ty.f32());
auto* s = create<type::SampledTexture>(type::TextureDimension::kCubeArray,
ty.f32());
spirv::Builder& b = Build();
EXPECT_EQ(b.GenerateTypeIfNeeded(&s), 1u);
EXPECT_EQ(b.GenerateTypeIfNeeded(s), 1u);
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()),
R"(%2 = OpTypeFloat 32
@ -870,14 +874,14 @@ TEST_F(BuilderTest_Type, SampledTexture_Generate_CubeArray) {
}
TEST_F(BuilderTest_Type, StorageTexture_Generate_1d_R16Float) {
type::StorageTexture s(type::TextureDimension::k1d,
type::ImageFormat::kR16Float);
auto* s = create<type::StorageTexture>(type::TextureDimension::k1d,
type::ImageFormat::kR16Float);
ASSERT_TRUE(td.DetermineStorageTextureSubtype(&s)) << td.error();
Global("test_var", ast::StorageClass::kNone, s);
spirv::Builder& b = Build();
EXPECT_EQ(b.GenerateTypeIfNeeded(&s), 1u);
EXPECT_EQ(b.GenerateTypeIfNeeded(s), 1u);
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
%1 = OpTypeImage %2 1D 0 0 0 2 R16f
@ -890,14 +894,14 @@ OpCapability StorageImageExtendedFormats
}
TEST_F(BuilderTest_Type, StorageTexture_Generate_1d_R8SNorm) {
type::StorageTexture s(type::TextureDimension::k1d,
type::ImageFormat::kR8Snorm);
auto* s = create<type::StorageTexture>(type::TextureDimension::k1d,
type::ImageFormat::kR8Snorm);
ASSERT_TRUE(td.DetermineStorageTextureSubtype(&s)) << td.error();
Global("test_var", ast::StorageClass::kNone, s);
spirv::Builder& b = Build();
EXPECT_EQ(b.GenerateTypeIfNeeded(&s), 1u);
EXPECT_EQ(b.GenerateTypeIfNeeded(s), 1u);
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
%1 = OpTypeImage %2 1D 0 0 0 2 R8Snorm
@ -910,14 +914,14 @@ OpCapability StorageImageExtendedFormats
}
TEST_F(BuilderTest_Type, StorageTexture_Generate_1d_R8UNorm) {
type::StorageTexture s(type::TextureDimension::k1d,
type::ImageFormat::kR8Unorm);
auto* s = create<type::StorageTexture>(type::TextureDimension::k1d,
type::ImageFormat::kR8Unorm);
ASSERT_TRUE(td.DetermineStorageTextureSubtype(&s)) << td.error();
Global("test_var", ast::StorageClass::kNone, s);
spirv::Builder& b = Build();
EXPECT_EQ(b.GenerateTypeIfNeeded(&s), 1u);
EXPECT_EQ(b.GenerateTypeIfNeeded(s), 1u);
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
%1 = OpTypeImage %2 1D 0 0 0 2 R8
@ -930,14 +934,14 @@ OpCapability StorageImageExtendedFormats
}
TEST_F(BuilderTest_Type, StorageTexture_Generate_1d_R8Uint) {
type::StorageTexture s(type::TextureDimension::k1d,
type::ImageFormat::kR8Uint);
auto* s = create<type::StorageTexture>(type::TextureDimension::k1d,
type::ImageFormat::kR8Uint);
ASSERT_TRUE(td.DetermineStorageTextureSubtype(&s)) << td.error();
Global("test_var", ast::StorageClass::kNone, s);
spirv::Builder& b = Build();
EXPECT_EQ(b.GenerateTypeIfNeeded(&s), 1u);
EXPECT_EQ(b.GenerateTypeIfNeeded(s), 1u);
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeInt 32 0
%1 = OpTypeImage %2 1D 0 0 0 2 R8ui
@ -945,14 +949,14 @@ TEST_F(BuilderTest_Type, StorageTexture_Generate_1d_R8Uint) {
}
TEST_F(BuilderTest_Type, StorageTexture_Generate_1d_R8Sint) {
type::StorageTexture s(type::TextureDimension::k1d,
type::ImageFormat::kR8Sint);
auto* s = create<type::StorageTexture>(type::TextureDimension::k1d,
type::ImageFormat::kR8Sint);
ASSERT_TRUE(td.DetermineStorageTextureSubtype(&s)) << td.error();
Global("test_var", ast::StorageClass::kNone, s);
spirv::Builder& b = Build();
EXPECT_EQ(b.GenerateTypeIfNeeded(&s), 1u);
EXPECT_EQ(b.GenerateTypeIfNeeded(s), 1u);
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeInt 32 1
%1 = OpTypeImage %2 1D 0 0 0 2 R8i
@ -960,14 +964,14 @@ TEST_F(BuilderTest_Type, StorageTexture_Generate_1d_R8Sint) {
}
TEST_F(BuilderTest_Type, StorageTexture_Generate_1d_array) {
type::StorageTexture s(type::TextureDimension::k1dArray,
type::ImageFormat::kR16Float);
auto* s = create<type::StorageTexture>(type::TextureDimension::k1dArray,
type::ImageFormat::kR16Float);
ASSERT_TRUE(td.DetermineStorageTextureSubtype(&s)) << td.error();
Global("test_var", ast::StorageClass::kNone, s);
spirv::Builder& b = Build();
EXPECT_EQ(b.GenerateTypeIfNeeded(&s), 1u);
EXPECT_EQ(b.GenerateTypeIfNeeded(s), 1u);
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
%1 = OpTypeImage %2 1D 0 1 0 2 R16f
@ -980,14 +984,14 @@ OpCapability StorageImageExtendedFormats
}
TEST_F(BuilderTest_Type, StorageTexture_Generate_2d) {
type::StorageTexture s(type::TextureDimension::k2d,
type::ImageFormat::kR16Float);
auto* s = create<type::StorageTexture>(type::TextureDimension::k2d,
type::ImageFormat::kR16Float);
ASSERT_TRUE(td.DetermineStorageTextureSubtype(&s)) << td.error();
Global("test_var", ast::StorageClass::kNone, s);
spirv::Builder& b = Build();
EXPECT_EQ(b.GenerateTypeIfNeeded(&s), 1u);
EXPECT_EQ(b.GenerateTypeIfNeeded(s), 1u);
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
%1 = OpTypeImage %2 2D 0 0 0 2 R16f
@ -995,14 +999,14 @@ TEST_F(BuilderTest_Type, StorageTexture_Generate_2d) {
}
TEST_F(BuilderTest_Type, StorageTexture_Generate_2dArray) {
type::StorageTexture s(type::TextureDimension::k2dArray,
type::ImageFormat::kR16Float);
auto* s = create<type::StorageTexture>(type::TextureDimension::k2dArray,
type::ImageFormat::kR16Float);
ASSERT_TRUE(td.DetermineStorageTextureSubtype(&s)) << td.error();
Global("test_var", ast::StorageClass::kNone, s);
spirv::Builder& b = Build();
EXPECT_EQ(b.GenerateTypeIfNeeded(&s), 1u);
EXPECT_EQ(b.GenerateTypeIfNeeded(s), 1u);
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
%1 = OpTypeImage %2 2D 0 1 0 2 R16f
@ -1010,14 +1014,14 @@ TEST_F(BuilderTest_Type, StorageTexture_Generate_2dArray) {
}
TEST_F(BuilderTest_Type, StorageTexture_Generate_3d) {
type::StorageTexture s(type::TextureDimension::k3d,
type::ImageFormat::kR16Float);
auto* s = create<type::StorageTexture>(type::TextureDimension::k3d,
type::ImageFormat::kR16Float);
ASSERT_TRUE(td.DetermineStorageTextureSubtype(&s)) << td.error();
Global("test_var", ast::StorageClass::kNone, s);
spirv::Builder& b = Build();
EXPECT_EQ(b.GenerateTypeIfNeeded(&s), 1u);
EXPECT_EQ(b.GenerateTypeIfNeeded(s), 1u);
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
%1 = OpTypeImage %2 3D 0 0 0 2 R16f
@ -1026,14 +1030,14 @@ TEST_F(BuilderTest_Type, StorageTexture_Generate_3d) {
TEST_F(BuilderTest_Type,
StorageTexture_Generate_SampledTypeFloat_Format_r32float) {
type::StorageTexture s(type::TextureDimension::k2d,
type::ImageFormat::kR32Float);
auto* s = create<type::StorageTexture>(type::TextureDimension::k2d,
type::ImageFormat::kR32Float);
ASSERT_TRUE(td.DetermineStorageTextureSubtype(&s)) << td.error();
Global("test_var", ast::StorageClass::kNone, s);
spirv::Builder& b = Build();
EXPECT_EQ(b.GenerateTypeIfNeeded(&s), 1u);
EXPECT_EQ(b.GenerateTypeIfNeeded(s), 1u);
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
%1 = OpTypeImage %2 2D 0 0 0 2 R32f
@ -1042,14 +1046,14 @@ TEST_F(BuilderTest_Type,
TEST_F(BuilderTest_Type,
StorageTexture_Generate_SampledTypeSint_Format_r32sint) {
type::StorageTexture s(type::TextureDimension::k2d,
type::ImageFormat::kR32Sint);
auto* s = create<type::StorageTexture>(type::TextureDimension::k2d,
type::ImageFormat::kR32Sint);
ASSERT_TRUE(td.DetermineStorageTextureSubtype(&s)) << td.error();
Global("test_var", ast::StorageClass::kNone, s);
spirv::Builder& b = Build();
EXPECT_EQ(b.GenerateTypeIfNeeded(&s), 1u);
EXPECT_EQ(b.GenerateTypeIfNeeded(s), 1u);
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeInt 32 1
%1 = OpTypeImage %2 2D 0 0 0 2 R32i
@ -1058,14 +1062,14 @@ TEST_F(BuilderTest_Type,
TEST_F(BuilderTest_Type,
StorageTexture_Generate_SampledTypeUint_Format_r32uint) {
type::StorageTexture s(type::TextureDimension::k2d,
type::ImageFormat::kR32Uint);
auto* s = create<type::StorageTexture>(type::TextureDimension::k2d,
type::ImageFormat::kR32Uint);
ASSERT_TRUE(td.DetermineStorageTextureSubtype(&s)) << td.error();
Global("test_var", ast::StorageClass::kNone, s);
spirv::Builder& b = Build();
EXPECT_EQ(b.GenerateTypeIfNeeded(&s), 1u);
EXPECT_EQ(b.GenerateTypeIfNeeded(s), 1u);
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeInt 32 0
%1 = OpTypeImage %2 2D 0 0 0 2 R32ui

View File

@ -39,7 +39,7 @@ using BuilderTest = TestHelper;
TEST_F(BuilderTest, UnaryOp_Negation_Integer) {
auto* expr = create<ast::UnaryOpExpression>(ast::UnaryOp::kNegation, Expr(1));
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
spirv::Builder& b = Build();
@ -56,7 +56,7 @@ TEST_F(BuilderTest, UnaryOp_Negation_Integer) {
TEST_F(BuilderTest, UnaryOp_Negation_Float) {
auto* expr =
create<ast::UnaryOpExpression>(ast::UnaryOp::kNegation, Expr(1.f));
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
spirv::Builder& b = Build();
@ -72,7 +72,7 @@ TEST_F(BuilderTest, UnaryOp_Negation_Float) {
TEST_F(BuilderTest, UnaryOp_Not) {
auto* expr = create<ast::UnaryOpExpression>(ast::UnaryOp::kNot, Expr(false));
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
spirv::Builder& b = Build();
@ -87,13 +87,11 @@ TEST_F(BuilderTest, UnaryOp_Not) {
}
TEST_F(BuilderTest, UnaryOp_LoadRequired) {
auto* var = Var("param", ast::StorageClass::kFunction, ty.vec3<f32>());
auto* var = Global("param", ast::StorageClass::kFunction, ty.vec3<f32>());
auto* expr =
create<ast::UnaryOpExpression>(ast::UnaryOp::kNegation, Expr("param"));
td.RegisterVariableForTesting(var);
EXPECT_TRUE(td.DetermineResultType(expr)) << td.error();
WrapInFunction(expr);
spirv::Builder& b = Build();

View File

@ -20,6 +20,7 @@
#include "gtest/gtest.h"
#include "src/ast/module.h"
#include "src/diagnostic/formatter.h"
#include "src/program_builder.h"
#include "src/type_determiner.h"
#include "src/writer/spirv/builder.h"
@ -32,7 +33,7 @@ namespace spirv {
template <typename BASE>
class TestHelperBase : public ProgramBuilder, public BASE {
public:
TestHelperBase() : td(this) {}
TestHelperBase() = default;
~TestHelperBase() override = default;
/// Builds and returns a spirv::Builder from the program.
@ -43,23 +44,22 @@ class TestHelperBase : public ProgramBuilder, public BASE {
if (spirv_builder) {
return *spirv_builder;
}
[&]() {
ASSERT_TRUE(IsValid()) << "Builder program is not valid\n"
<< diag::Formatter().format(Diagnostics());
}();
program = std::make_unique<Program>(std::move(*this));
[&]() {
ASSERT_TRUE(program->IsValid())
<< diag::Formatter().format(program->Diagnostics());
}();
spirv_builder = std::make_unique<spirv::Builder>(program.get());
return *spirv_builder;
}
/// The type determiner
TypeDeterminer td;
/// The program built with a call to Build()
std::unique_ptr<Program> program;
protected:
/// Called whenever a new variable is built with `Var()`.
/// @param var the variable that was built
void OnVariableBuilt(ast::Variable* var) override {
td.RegisterVariableForTesting(var);
}
private:
std::unique_ptr<spirv::Builder> spirv_builder;
};

View File

@ -184,18 +184,14 @@ TEST_F(WgslGeneratorImplTest,
auto* s = ty.struct_("Data", str);
type::AccessControl ac(ast::AccessControl::kReadWrite, s);
auto* data_var = Var("data", ast::StorageClass::kStorage, &ac, nullptr,
ast::VariableDecorationList{
// decorations
create<ast::BindingDecoration>(0),
create<ast::GroupDecoration>(0),
});
Global("data", ast::StorageClass::kStorage, &ac, nullptr,
ast::VariableDecorationList{
create<ast::BindingDecoration>(0),
create<ast::GroupDecoration>(0),
});
AST().AddConstructedType(s);
td.RegisterVariableForTesting(data_var);
AST().AddGlobalVariable(data_var);
{
auto* var =
Var("v", ast::StorageClass::kFunction, ty.f32(),

View File

@ -386,12 +386,12 @@ using WgslGenerator_StorageTextureTest = TestParamHelper<StorageTextureData>;
TEST_P(WgslGenerator_StorageTextureTest, EmitType_StorageTexture) {
auto param = GetParam();
type::StorageTexture t(param.dim, param.fmt);
type::AccessControl ac(param.access, &t);
auto* t = create<type::StorageTexture>(param.dim, param.fmt);
auto* ac = create<type::AccessControl>(param.access, t);
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.EmitType(&ac)) << gen.error();
ASSERT_TRUE(gen.EmitType(ac)) << gen.error();
EXPECT_EQ(gen.result(), param.name);
}
INSTANTIATE_TEST_SUITE_P(

View File

@ -31,9 +31,10 @@ namespace {
using WgslGeneratorImplTest = TestHelper;
TEST_F(WgslGeneratorImplTest, Emit_VariableDeclStatement) {
auto* var = Var("a", ast::StorageClass::kNone, ty.f32());
auto* var = Global("a", ast::StorageClass::kNone, ty.f32());
auto* stmt = create<ast::VariableDeclStatement>(var);
WrapInFunction(stmt);
GeneratorImpl& gen = Build();
@ -48,9 +49,10 @@ TEST_F(WgslGeneratorImplTest, Emit_VariableDeclStatement_Function) {
// storage class. Rely on defaulting.
// https://github.com/gpuweb/gpuweb/issues/654
auto* var = Var("a", ast::StorageClass::kFunction, ty.f32());
auto* var = Global("a", ast::StorageClass::kFunction, ty.f32());
auto* stmt = create<ast::VariableDeclStatement>(var);
WrapInFunction(stmt);
GeneratorImpl& gen = Build();
@ -61,9 +63,10 @@ TEST_F(WgslGeneratorImplTest, Emit_VariableDeclStatement_Function) {
}
TEST_F(WgslGeneratorImplTest, Emit_VariableDeclStatement_Private) {
auto* var = Var("a", ast::StorageClass::kPrivate, ty.f32());
auto* var = Global("a", ast::StorageClass::kPrivate, ty.f32());
auto* stmt = create<ast::VariableDeclStatement>(var);
WrapInFunction(stmt);
GeneratorImpl& gen = Build();

View File

@ -34,7 +34,7 @@ namespace {
using WgslGeneratorImplTest = TestHelper;
TEST_F(WgslGeneratorImplTest, EmitVariable) {
auto* v = Var("a", ast::StorageClass::kNone, ty.f32());
auto* v = Global("a", ast::StorageClass::kNone, ty.f32());
GeneratorImpl& gen = Build();
@ -44,7 +44,7 @@ TEST_F(WgslGeneratorImplTest, EmitVariable) {
}
TEST_F(WgslGeneratorImplTest, EmitVariable_StorageClass) {
auto* v = Var("a", ast::StorageClass::kInput, ty.f32());
auto* v = Global("a", ast::StorageClass::kInput, ty.f32());
GeneratorImpl& gen = Build();
@ -54,10 +54,10 @@ TEST_F(WgslGeneratorImplTest, EmitVariable_StorageClass) {
}
TEST_F(WgslGeneratorImplTest, EmitVariable_Decorated) {
auto* v = Var("a", ast::StorageClass::kNone, ty.f32(), nullptr,
ast::VariableDecorationList{
create<ast::LocationDecoration>(2),
});
auto* v = Global("a", ast::StorageClass::kNone, ty.f32(), nullptr,
ast::VariableDecorationList{
create<ast::LocationDecoration>(2),
});
GeneratorImpl& gen = Build();
@ -67,14 +67,14 @@ TEST_F(WgslGeneratorImplTest, EmitVariable_Decorated) {
}
TEST_F(WgslGeneratorImplTest, EmitVariable_Decorated_Multiple) {
auto* v = Var("a", ast::StorageClass::kNone, ty.f32(), nullptr,
ast::VariableDecorationList{
create<ast::BuiltinDecoration>(ast::Builtin::kPosition),
create<ast::BindingDecoration>(0),
create<ast::GroupDecoration>(1),
create<ast::LocationDecoration>(2),
create<ast::ConstantIdDecoration>(42),
});
auto* v = Global("a", ast::StorageClass::kNone, ty.f32(), nullptr,
ast::VariableDecorationList{
create<ast::BuiltinDecoration>(ast::Builtin::kPosition),
create<ast::BindingDecoration>(0),
create<ast::GroupDecoration>(1),
create<ast::LocationDecoration>(2),
create<ast::ConstantIdDecoration>(42),
});
GeneratorImpl& gen = Build();
@ -86,8 +86,8 @@ TEST_F(WgslGeneratorImplTest, EmitVariable_Decorated_Multiple) {
}
TEST_F(WgslGeneratorImplTest, EmitVariable_Constructor) {
auto* v = Var("a", ast::StorageClass::kNone, ty.f32(), Expr("initializer"),
ast::VariableDecorationList{});
auto* v = Global("a", ast::StorageClass::kNone, ty.f32(), Expr("initializer"),
ast::VariableDecorationList{});
GeneratorImpl& gen = Build();