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:
parent
87c78ddabc
commit
401b96b9bb
|
@ -160,18 +160,18 @@ ast::Variable* TextureOverloadCase::buildTextureVariable(
|
||||||
};
|
};
|
||||||
switch (texture_kind) {
|
switch (texture_kind) {
|
||||||
case ast::intrinsic::test::TextureKind::kRegular:
|
case ast::intrinsic::test::TextureKind::kRegular:
|
||||||
return b->Var(
|
return b->Global(
|
||||||
"texture", ast::StorageClass::kUniformConstant,
|
"texture", ast::StorageClass::kUniformConstant,
|
||||||
b->create<type::SampledTexture>(texture_dimension, datatype), nullptr,
|
b->create<type::SampledTexture>(texture_dimension, datatype), nullptr,
|
||||||
decos);
|
decos);
|
||||||
|
|
||||||
case ast::intrinsic::test::TextureKind::kDepth:
|
case ast::intrinsic::test::TextureKind::kDepth:
|
||||||
return b->Var("texture", ast::StorageClass::kUniformConstant,
|
return b->Global("texture", ast::StorageClass::kUniformConstant,
|
||||||
b->create<type::DepthTexture>(texture_dimension), nullptr,
|
b->create<type::DepthTexture>(texture_dimension),
|
||||||
decos);
|
nullptr, decos);
|
||||||
|
|
||||||
case ast::intrinsic::test::TextureKind::kMultisampled:
|
case ast::intrinsic::test::TextureKind::kMultisampled:
|
||||||
return b->Var(
|
return b->Global(
|
||||||
"texture", ast::StorageClass::kUniformConstant,
|
"texture", ast::StorageClass::kUniformConstant,
|
||||||
b->create<type::MultisampledTexture>(texture_dimension, datatype),
|
b->create<type::MultisampledTexture>(texture_dimension, datatype),
|
||||||
nullptr, decos);
|
nullptr, decos);
|
||||||
|
@ -182,8 +182,8 @@ ast::Variable* TextureOverloadCase::buildTextureVariable(
|
||||||
st->set_type(datatype);
|
st->set_type(datatype);
|
||||||
|
|
||||||
auto* ac = b->create<type::AccessControl>(access_control, st);
|
auto* ac = b->create<type::AccessControl>(access_control, st);
|
||||||
return b->Var("texture", ast::StorageClass::kUniformConstant, ac, nullptr,
|
return b->Global("texture", ast::StorageClass::kUniformConstant, ac,
|
||||||
decos);
|
nullptr, decos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -197,7 +197,7 @@ ast::Variable* TextureOverloadCase::buildSamplerVariable(
|
||||||
b->create<ast::GroupDecoration>(0),
|
b->create<ast::GroupDecoration>(0),
|
||||||
b->create<ast::BindingDecoration>(1),
|
b->create<ast::BindingDecoration>(1),
|
||||||
};
|
};
|
||||||
return b->Var("sampler", ast::StorageClass::kUniformConstant,
|
return b->Global("sampler", ast::StorageClass::kUniformConstant,
|
||||||
b->create<type::Sampler>(sampler_kind), nullptr, decos);
|
b->create<type::Sampler>(sampler_kind), nullptr, decos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -242,10 +242,12 @@ struct TextureOverloadCase {
|
||||||
/// @returns the vector component type of the texture function return value
|
/// @returns the vector component type of the texture function return value
|
||||||
type::Type* resultVectorComponentType(ProgramBuilder* builder) const;
|
type::Type* resultVectorComponentType(ProgramBuilder* builder) const;
|
||||||
/// @param builder the AST builder used for the test
|
/// @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;
|
ast::Variable* buildTextureVariable(ProgramBuilder* builder) const;
|
||||||
/// @param builder the AST builder used for the test
|
/// @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;
|
ast::Variable* buildSamplerVariable(ProgramBuilder* builder) const;
|
||||||
|
|
||||||
/// The enumerator for this overload
|
/// The enumerator for this overload
|
||||||
|
|
|
@ -62,8 +62,7 @@ TEST_F(ModuleTest, IsValid_Empty) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ModuleTest, IsValid_GlobalVariable) {
|
TEST_F(ModuleTest, IsValid_GlobalVariable) {
|
||||||
auto* var = Var("var", StorageClass::kInput, ty.f32());
|
Global("var", StorageClass::kInput, ty.f32());
|
||||||
AST().AddGlobalVariable(var);
|
|
||||||
Program program(std::move(*this));
|
Program program(std::move(*this));
|
||||||
EXPECT_TRUE(program.AST().IsValid());
|
EXPECT_TRUE(program.AST().IsValid());
|
||||||
}
|
}
|
||||||
|
@ -75,8 +74,7 @@ TEST_F(ModuleTest, IsValid_Null_GlobalVariable) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ModuleTest, IsValid_Invalid_GlobalVariable) {
|
TEST_F(ModuleTest, IsValid_Invalid_GlobalVariable) {
|
||||||
auto* var = Var("var", StorageClass::kInput, nullptr);
|
Global("var", StorageClass::kInput, nullptr);
|
||||||
AST().AddGlobalVariable(var);
|
|
||||||
Program program(std::move(*this));
|
Program program(std::move(*this));
|
||||||
EXPECT_FALSE(program.AST().IsValid());
|
EXPECT_FALSE(program.AST().IsValid());
|
||||||
}
|
}
|
||||||
|
|
|
@ -107,14 +107,12 @@ class InspectorHelper : public ProgramBuilder {
|
||||||
std::string in, out;
|
std::string in, out;
|
||||||
std::tie(in, out) = inout;
|
std::tie(in, out) = inout;
|
||||||
|
|
||||||
AST().AddGlobalVariable(
|
Global(in, ast::StorageClass::kInput, ty.u32(), nullptr,
|
||||||
Var(in, ast::StorageClass::kInput, ty.u32(), nullptr,
|
|
||||||
ast::VariableDecorationList{
|
ast::VariableDecorationList{
|
||||||
create<ast::LocationDecoration>(location++)}));
|
create<ast::LocationDecoration>(location++)});
|
||||||
AST().AddGlobalVariable(
|
Global(out, ast::StorageClass::kOutput, ty.u32(), nullptr,
|
||||||
Var(out, ast::StorageClass::kOutput, ty.u32(), nullptr,
|
|
||||||
ast::VariableDecorationList{
|
ast::VariableDecorationList{
|
||||||
create<ast::LocationDecoration>(location++)}));
|
create<ast::LocationDecoration>(location++)});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -175,11 +173,10 @@ class InspectorHelper : public ProgramBuilder {
|
||||||
constructor =
|
constructor =
|
||||||
create<ast::ScalarConstructorExpression>(MakeLiteral(type, val));
|
create<ast::ScalarConstructorExpression>(MakeLiteral(type, val));
|
||||||
}
|
}
|
||||||
auto* var = Const(name, ast::StorageClass::kNone, type, constructor,
|
GlobalConst(name, ast::StorageClass::kNone, type, constructor,
|
||||||
ast::VariableDecorationList{
|
ast::VariableDecorationList{
|
||||||
create<ast::ConstantIdDecoration>(id),
|
create<ast::ConstantIdDecoration>(id),
|
||||||
});
|
});
|
||||||
AST().AddGlobalVariable(var);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @param type AST type of the literal, must resolve to BoolLiteral
|
/// @param type AST type of the literal, must resolve to BoolLiteral
|
||||||
|
@ -320,13 +317,11 @@ class InspectorHelper : public ProgramBuilder {
|
||||||
ast::StorageClass storage_class,
|
ast::StorageClass storage_class,
|
||||||
uint32_t group,
|
uint32_t group,
|
||||||
uint32_t binding) {
|
uint32_t binding) {
|
||||||
auto* var = Var(name, storage_class, type, nullptr,
|
GlobalConst(name, storage_class, type, nullptr,
|
||||||
ast::VariableDecorationList{
|
ast::VariableDecorationList{
|
||||||
create<ast::BindingDecoration>(binding),
|
create<ast::BindingDecoration>(binding),
|
||||||
create<ast::GroupDecoration>(group),
|
create<ast::GroupDecoration>(group),
|
||||||
});
|
});
|
||||||
|
|
||||||
AST().AddGlobalVariable(var);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Adds an uniform buffer variable to the program
|
/// 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) {
|
void AddGlobalVariable(const std::string& name, type::Type* type) {
|
||||||
AST().AddGlobalVariable(
|
Global(name, ast::StorageClass::kUniformConstant, type);
|
||||||
Var(name, ast::StorageClass::kUniformConstant, type));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Adds a depth texture variable to the program
|
/// Adds a depth texture variable to the program
|
||||||
/// @param name the name of the variable
|
/// @param name the name of the variable
|
||||||
/// @param type the type to use
|
/// @param type the type to use
|
||||||
void AddDepthTexture(const std::string& name, type::Type* type) {
|
void AddDepthTexture(const std::string& name, type::Type* type) {
|
||||||
AST().AddGlobalVariable(
|
Global(name, ast::StorageClass::kUniformConstant, type);
|
||||||
Var(name, ast::StorageClass::kUniformConstant, type));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Generates a function that references a specific sampler variable
|
/// Generates a function that references a specific sampler variable
|
||||||
|
@ -1104,13 +1097,11 @@ TEST_F(InspectorGetEntryPointTest, MultipleEntryPointsSharedInOutVariables) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(InspectorGetEntryPointTest, BuiltInsNotStageVariables) {
|
TEST_F(InspectorGetEntryPointTest, BuiltInsNotStageVariables) {
|
||||||
AST().AddGlobalVariable(
|
Global("in_var", ast::StorageClass::kInput, ty.u32(), nullptr,
|
||||||
Var("in_var", ast::StorageClass::kInput, ty.u32(), nullptr,
|
|
||||||
ast::VariableDecorationList{
|
ast::VariableDecorationList{
|
||||||
create<ast::BuiltinDecoration>(ast::Builtin::kPosition)}));
|
create<ast::BuiltinDecoration>(ast::Builtin::kPosition)});
|
||||||
AST().AddGlobalVariable(
|
Global("out_var", ast::StorageClass::kOutput, ty.u32(), nullptr,
|
||||||
Var("out_var", ast::StorageClass::kOutput, ty.u32(), nullptr,
|
ast::VariableDecorationList{create<ast::LocationDecoration>(0)});
|
||||||
ast::VariableDecorationList{create<ast::LocationDecoration>(0)}));
|
|
||||||
|
|
||||||
MakeInOutVariableBodyFunction("func", {{"in_var", "out_var"}}, {});
|
MakeInOutVariableBodyFunction("func", {{"in_var", "out_var"}}, {});
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,8 @@
|
||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
|
#include "src/ast/assignment_statement.h"
|
||||||
|
#include "src/ast/variable_decl_statement.h"
|
||||||
#include "src/clone_context.h"
|
#include "src/clone_context.h"
|
||||||
#include "src/demangler.h"
|
#include "src/demangler.h"
|
||||||
#include "src/semantic/expression.h"
|
#include "src/semantic/expression.h"
|
||||||
|
@ -101,10 +103,8 @@ ast::Variable* ProgramBuilder::Var(const std::string& name,
|
||||||
type::Type* type,
|
type::Type* type,
|
||||||
ast::Expression* constructor,
|
ast::Expression* constructor,
|
||||||
ast::VariableDecorationList decorations) {
|
ast::VariableDecorationList decorations) {
|
||||||
auto* var = create<ast::Variable>(Symbols().Register(name), storage, type,
|
return create<ast::Variable>(Symbols().Register(name), storage, type, false,
|
||||||
false, constructor, decorations);
|
constructor, decorations);
|
||||||
OnVariableBuilt(var);
|
|
||||||
return var;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ast::Variable* ProgramBuilder::Var(const Source& source,
|
ast::Variable* ProgramBuilder::Var(const Source& source,
|
||||||
|
@ -113,10 +113,8 @@ ast::Variable* ProgramBuilder::Var(const Source& source,
|
||||||
type::Type* type,
|
type::Type* type,
|
||||||
ast::Expression* constructor,
|
ast::Expression* constructor,
|
||||||
ast::VariableDecorationList decorations) {
|
ast::VariableDecorationList decorations) {
|
||||||
auto* var = create<ast::Variable>(source, Symbols().Register(name), storage,
|
return create<ast::Variable>(source, Symbols().Register(name), storage, type,
|
||||||
type, false, constructor, decorations);
|
false, constructor, decorations);
|
||||||
OnVariableBuilt(var);
|
|
||||||
return var;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ast::Variable* ProgramBuilder::Const(const std::string& name,
|
ast::Variable* ProgramBuilder::Const(const std::string& name,
|
||||||
|
@ -130,10 +128,8 @@ ast::Variable* ProgramBuilder::Const(const std::string& name,
|
||||||
type::Type* type,
|
type::Type* type,
|
||||||
ast::Expression* constructor,
|
ast::Expression* constructor,
|
||||||
ast::VariableDecorationList decorations) {
|
ast::VariableDecorationList decorations) {
|
||||||
auto* var = create<ast::Variable>(Symbols().Register(name), storage, type,
|
return create<ast::Variable>(Symbols().Register(name), storage, type, true,
|
||||||
true, constructor, decorations);
|
constructor, decorations);
|
||||||
OnVariableBuilt(var);
|
|
||||||
return var;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ast::Variable* ProgramBuilder::Const(const Source& source,
|
ast::Variable* ProgramBuilder::Const(const Source& source,
|
||||||
|
@ -142,10 +138,26 @@ ast::Variable* ProgramBuilder::Const(const Source& source,
|
||||||
type::Type* type,
|
type::Type* type,
|
||||||
ast::Expression* constructor,
|
ast::Expression* constructor,
|
||||||
ast::VariableDecorationList decorations) {
|
ast::VariableDecorationList decorations) {
|
||||||
auto* var = create<ast::Variable>(source, Symbols().Register(name), storage,
|
return create<ast::Variable>(source, Symbols().Register(name), storage, type,
|
||||||
type, true, constructor, decorations);
|
true, constructor, decorations);
|
||||||
OnVariableBuilt(var);
|
}
|
||||||
return var;
|
|
||||||
|
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
|
} // namespace tint
|
||||||
|
|
|
@ -55,6 +55,11 @@
|
||||||
|
|
||||||
namespace tint {
|
namespace tint {
|
||||||
|
|
||||||
|
// Forward declarations
|
||||||
|
namespace ast {
|
||||||
|
class VariableDeclStatement;
|
||||||
|
} // namespace ast
|
||||||
|
|
||||||
class CloneContext;
|
class CloneContext;
|
||||||
|
|
||||||
/// ProgramBuilder is a mutable builder for a Program.
|
/// ProgramBuilder is a mutable builder for a Program.
|
||||||
|
@ -789,6 +794,28 @@ class ProgramBuilder {
|
||||||
ast::Expression* constructor,
|
ast::Expression* constructor,
|
||||||
ast::VariableDecorationList decorations);
|
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 func the function name
|
||||||
/// @param args the function call arguments
|
/// @param args the function call arguments
|
||||||
/// @returns a `ast::CallExpression` to the function `func`, with the
|
/// @returns a `ast::CallExpression` to the function `func`, with the
|
||||||
|
@ -950,6 +977,35 @@ class ProgramBuilder {
|
||||||
/// expression has no resolved type.
|
/// expression has no resolved type.
|
||||||
type::Type* TypeOf(ast::Expression* expr) const;
|
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
|
/// The builder types
|
||||||
TypesBuilder ty;
|
TypesBuilder ty;
|
||||||
|
|
||||||
|
@ -957,9 +1013,6 @@ class ProgramBuilder {
|
||||||
/// Asserts that the builder has not been moved.
|
/// Asserts that the builder has not been moved.
|
||||||
void AssertNotMoved() const;
|
void AssertNotMoved() const;
|
||||||
|
|
||||||
/// Called whenever a new variable is built with `Var()`.
|
|
||||||
virtual void OnVariableBuilt(ast::Variable*) {}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
type::Manager types_;
|
type::Manager types_;
|
||||||
ASTNodeAllocator ast_nodes_;
|
ASTNodeAllocator ast_nodes_;
|
||||||
|
|
|
@ -49,8 +49,7 @@ TEST_F(ProgramTest, IsValid_Empty) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ProgramTest, IsValid_GlobalVariable) {
|
TEST_F(ProgramTest, IsValid_GlobalVariable) {
|
||||||
auto* var = Var("var", ast::StorageClass::kInput, ty.f32());
|
Global("var", ast::StorageClass::kInput, ty.f32());
|
||||||
AST().AddGlobalVariable(var);
|
|
||||||
|
|
||||||
Program program(std::move(*this));
|
Program program(std::move(*this));
|
||||||
EXPECT_TRUE(program.IsValid());
|
EXPECT_TRUE(program.IsValid());
|
||||||
|
@ -64,8 +63,7 @@ TEST_F(ProgramTest, IsValid_Null_GlobalVariable) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ProgramTest, IsValid_Invalid_GlobalVariable) {
|
TEST_F(ProgramTest, IsValid_Invalid_GlobalVariable) {
|
||||||
auto* var = Var("var", ast::StorageClass::kInput, nullptr);
|
Global("var", ast::StorageClass::kInput, nullptr);
|
||||||
AST().AddGlobalVariable(var);
|
|
||||||
|
|
||||||
Program program(std::move(*this));
|
Program program(std::move(*this));
|
||||||
EXPECT_FALSE(program.IsValid());
|
EXPECT_FALSE(program.IsValid());
|
||||||
|
|
|
@ -65,50 +65,11 @@ class TypeDeterminer {
|
||||||
|
|
||||||
/// @returns true if the type determiner was successful
|
/// @returns true if the type determiner was successful
|
||||||
bool Determine();
|
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
|
/// Creates the semantic::Function nodes and adds them to the semantic::Info
|
||||||
/// of the ProgramBuilder.
|
/// of the ProgramBuilder.
|
||||||
void CreateSemanticFunctions() const;
|
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.
|
/// Retrieves information for the requested import.
|
||||||
/// @param src the source of the import
|
/// @param src the source of the import
|
||||||
/// @param path the import path
|
/// @param path the import path
|
||||||
|
@ -159,6 +120,40 @@ class TypeDeterminer {
|
||||||
UniqueVector<Symbol> ancestor_entry_points;
|
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_error(const Source& src, const std::string& msg);
|
||||||
void set_referenced_from_function_if_needed(ast::Variable* var, bool local);
|
void set_referenced_from_function_if_needed(ast::Variable* var, bool local);
|
||||||
void set_entry_points(const Symbol& fn_sym, Symbol ep_sym);
|
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
|
@ -56,7 +56,7 @@ TEST_F(ValidateControlBlockTest, SwitchSelectorExpressionNoneIntegerType_Fail) {
|
||||||
body),
|
body),
|
||||||
});
|
});
|
||||||
|
|
||||||
EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error();
|
WrapInFunction(block);
|
||||||
|
|
||||||
ValidatorImpl& v = Build();
|
ValidatorImpl& v = Build();
|
||||||
|
|
||||||
|
@ -87,7 +87,7 @@ TEST_F(ValidateControlBlockTest, SwitchWithoutDefault_Fail) {
|
||||||
body),
|
body),
|
||||||
});
|
});
|
||||||
|
|
||||||
EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error();
|
WrapInFunction(block);
|
||||||
|
|
||||||
ValidatorImpl& v = Build();
|
ValidatorImpl& v = Build();
|
||||||
|
|
||||||
|
@ -129,7 +129,7 @@ TEST_F(ValidateControlBlockTest, SwitchWithTwoDefault_Fail) {
|
||||||
switch_body),
|
switch_body),
|
||||||
});
|
});
|
||||||
|
|
||||||
EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error();
|
WrapInFunction(block);
|
||||||
|
|
||||||
ValidatorImpl& v = Build();
|
ValidatorImpl& v = Build();
|
||||||
|
|
||||||
|
@ -164,7 +164,7 @@ TEST_F(ValidateControlBlockTest,
|
||||||
create<ast::VariableDeclStatement>(var),
|
create<ast::VariableDeclStatement>(var),
|
||||||
create<ast::SwitchStatement>(Expr("a"), switch_body),
|
create<ast::SwitchStatement>(Expr("a"), switch_body),
|
||||||
});
|
});
|
||||||
EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error();
|
WrapInFunction(block);
|
||||||
|
|
||||||
ValidatorImpl& v = Build();
|
ValidatorImpl& v = Build();
|
||||||
|
|
||||||
|
@ -199,7 +199,7 @@ TEST_F(ValidateControlBlockTest,
|
||||||
create<ast::VariableDeclStatement>(var),
|
create<ast::VariableDeclStatement>(var),
|
||||||
create<ast::SwitchStatement>(Expr("a"), switch_body),
|
create<ast::SwitchStatement>(Expr("a"), switch_body),
|
||||||
});
|
});
|
||||||
EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error();
|
WrapInFunction(block);
|
||||||
|
|
||||||
ValidatorImpl& v = Build();
|
ValidatorImpl& v = Build();
|
||||||
|
|
||||||
|
@ -240,7 +240,7 @@ TEST_F(ValidateControlBlockTest, NonUniqueCaseSelectorValueUint_Fail) {
|
||||||
create<ast::VariableDeclStatement>(var),
|
create<ast::VariableDeclStatement>(var),
|
||||||
create<ast::SwitchStatement>(Expr("a"), switch_body),
|
create<ast::SwitchStatement>(Expr("a"), switch_body),
|
||||||
});
|
});
|
||||||
EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error();
|
WrapInFunction(block);
|
||||||
|
|
||||||
ValidatorImpl& v = Build();
|
ValidatorImpl& v = Build();
|
||||||
|
|
||||||
|
@ -283,7 +283,7 @@ TEST_F(ValidateControlBlockTest, NonUniqueCaseSelectorValueSint_Fail) {
|
||||||
create<ast::VariableDeclStatement>(var),
|
create<ast::VariableDeclStatement>(var),
|
||||||
create<ast::SwitchStatement>(Expr("a"), switch_body),
|
create<ast::SwitchStatement>(Expr("a"), switch_body),
|
||||||
});
|
});
|
||||||
EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error();
|
WrapInFunction(block);
|
||||||
|
|
||||||
ValidatorImpl& v = Build();
|
ValidatorImpl& v = Build();
|
||||||
|
|
||||||
|
@ -314,7 +314,7 @@ TEST_F(ValidateControlBlockTest, LastClauseLastStatementIsFallthrough_Fail) {
|
||||||
create<ast::VariableDeclStatement>(var),
|
create<ast::VariableDeclStatement>(var),
|
||||||
create<ast::SwitchStatement>(Expr("a"), body),
|
create<ast::SwitchStatement>(Expr("a"), body),
|
||||||
});
|
});
|
||||||
EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error();
|
WrapInFunction(block);
|
||||||
|
|
||||||
ValidatorImpl& v = Build();
|
ValidatorImpl& v = Build();
|
||||||
|
|
||||||
|
@ -347,7 +347,7 @@ TEST_F(ValidateControlBlockTest, SwitchCase_Pass) {
|
||||||
create<ast::VariableDeclStatement>(var),
|
create<ast::VariableDeclStatement>(var),
|
||||||
create<ast::SwitchStatement>(Expr("a"), body),
|
create<ast::SwitchStatement>(Expr("a"), body),
|
||||||
});
|
});
|
||||||
EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error();
|
WrapInFunction(block);
|
||||||
|
|
||||||
ValidatorImpl& v = Build();
|
ValidatorImpl& v = Build();
|
||||||
|
|
||||||
|
@ -377,7 +377,7 @@ TEST_F(ValidateControlBlockTest, SwitchCaseAlias_Pass) {
|
||||||
});
|
});
|
||||||
AST().AddConstructedType(my_int);
|
AST().AddConstructedType(my_int);
|
||||||
|
|
||||||
EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error();
|
WrapInFunction(block);
|
||||||
|
|
||||||
ValidatorImpl& v = Build();
|
ValidatorImpl& v = Build();
|
||||||
|
|
||||||
|
|
|
@ -50,8 +50,6 @@ TEST_F(ValidateFunctionTest, VoidFunctionEndWithoutReturnStatement_Pass) {
|
||||||
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
|
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
|
||||||
});
|
});
|
||||||
|
|
||||||
EXPECT_TRUE(td()->Determine()) << td()->error();
|
|
||||||
|
|
||||||
ValidatorImpl& v = Build();
|
ValidatorImpl& v = Build();
|
||||||
|
|
||||||
EXPECT_TRUE(v.Validate());
|
EXPECT_TRUE(v.Validate());
|
||||||
|
@ -68,8 +66,6 @@ TEST_F(ValidateFunctionTest,
|
||||||
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
|
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
|
||||||
});
|
});
|
||||||
|
|
||||||
EXPECT_TRUE(td()->Determine()) << td()->error();
|
|
||||||
|
|
||||||
ValidatorImpl& v = Build();
|
ValidatorImpl& v = Build();
|
||||||
|
|
||||||
EXPECT_TRUE(v.Validate());
|
EXPECT_TRUE(v.Validate());
|
||||||
|
@ -87,8 +83,6 @@ TEST_F(ValidateFunctionTest, FunctionEndWithoutReturnStatement_Fail) {
|
||||||
},
|
},
|
||||||
ast::FunctionDecorationList{});
|
ast::FunctionDecorationList{});
|
||||||
|
|
||||||
EXPECT_TRUE(td()->Determine()) << td()->error();
|
|
||||||
|
|
||||||
ValidatorImpl& v = Build();
|
ValidatorImpl& v = Build();
|
||||||
|
|
||||||
EXPECT_FALSE(v.Validate());
|
EXPECT_FALSE(v.Validate());
|
||||||
|
@ -102,8 +96,6 @@ TEST_F(ValidateFunctionTest, FunctionEndWithoutReturnStatementEmptyBody_Fail) {
|
||||||
Func(Source{Source::Location{12, 34}}, "func", ast::VariableList{}, ty.i32(),
|
Func(Source{Source::Location{12, 34}}, "func", ast::VariableList{}, ty.i32(),
|
||||||
ast::StatementList{}, ast::FunctionDecorationList{});
|
ast::StatementList{}, ast::FunctionDecorationList{});
|
||||||
|
|
||||||
EXPECT_TRUE(td()->Determine()) << td()->error();
|
|
||||||
|
|
||||||
ValidatorImpl& v = Build();
|
ValidatorImpl& v = Build();
|
||||||
|
|
||||||
EXPECT_FALSE(v.Validate());
|
EXPECT_FALSE(v.Validate());
|
||||||
|
@ -123,8 +115,6 @@ TEST_F(ValidateFunctionTest, FunctionTypeMustMatchReturnStatementType_Pass) {
|
||||||
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
|
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
|
||||||
});
|
});
|
||||||
|
|
||||||
EXPECT_TRUE(td()->DetermineFunctions(AST().Functions())) << td()->error();
|
|
||||||
|
|
||||||
ValidatorImpl& v = Build();
|
ValidatorImpl& v = Build();
|
||||||
const Program* program = v.program();
|
const Program* program = v.program();
|
||||||
|
|
||||||
|
@ -140,8 +130,6 @@ TEST_F(ValidateFunctionTest, FunctionTypeMustMatchReturnStatementType_fail) {
|
||||||
},
|
},
|
||||||
ast::FunctionDecorationList{});
|
ast::FunctionDecorationList{});
|
||||||
|
|
||||||
EXPECT_TRUE(td()->Determine()) << td()->error();
|
|
||||||
|
|
||||||
ValidatorImpl& v = Build();
|
ValidatorImpl& v = Build();
|
||||||
|
|
||||||
EXPECT_FALSE(v.Validate());
|
EXPECT_FALSE(v.Validate());
|
||||||
|
@ -160,8 +148,6 @@ TEST_F(ValidateFunctionTest, FunctionTypeMustMatchReturnStatementTypeF32_fail) {
|
||||||
},
|
},
|
||||||
ast::FunctionDecorationList{});
|
ast::FunctionDecorationList{});
|
||||||
|
|
||||||
EXPECT_TRUE(td()->Determine()) << td()->error();
|
|
||||||
|
|
||||||
ValidatorImpl& v = Build();
|
ValidatorImpl& v = Build();
|
||||||
|
|
||||||
EXPECT_FALSE(v.Validate());
|
EXPECT_FALSE(v.Validate());
|
||||||
|
@ -186,8 +172,6 @@ TEST_F(ValidateFunctionTest, FunctionNamesMustBeUnique_fail) {
|
||||||
},
|
},
|
||||||
ast::FunctionDecorationList{});
|
ast::FunctionDecorationList{});
|
||||||
|
|
||||||
EXPECT_TRUE(td()->Determine()) << td()->error();
|
|
||||||
|
|
||||||
ValidatorImpl& v = Build();
|
ValidatorImpl& v = Build();
|
||||||
|
|
||||||
EXPECT_FALSE(v.Validate());
|
EXPECT_FALSE(v.Validate());
|
||||||
|
@ -207,8 +191,6 @@ TEST_F(ValidateFunctionTest, RecursionIsNotAllowed_Fail) {
|
||||||
},
|
},
|
||||||
ast::FunctionDecorationList{});
|
ast::FunctionDecorationList{});
|
||||||
|
|
||||||
EXPECT_TRUE(td()->Determine()) << td()->error();
|
|
||||||
|
|
||||||
ValidatorImpl& v = Build();
|
ValidatorImpl& v = Build();
|
||||||
|
|
||||||
EXPECT_FALSE(v.Validate()) << v.error();
|
EXPECT_FALSE(v.Validate()) << v.error();
|
||||||
|
@ -230,8 +212,6 @@ TEST_F(ValidateFunctionTest, RecursionIsNotAllowedExpr_Fail) {
|
||||||
},
|
},
|
||||||
ast::FunctionDecorationList{});
|
ast::FunctionDecorationList{});
|
||||||
|
|
||||||
EXPECT_TRUE(td()->Determine()) << td()->error();
|
|
||||||
|
|
||||||
ValidatorImpl& v = Build();
|
ValidatorImpl& v = Build();
|
||||||
|
|
||||||
EXPECT_FALSE(v.Validate()) << v.error();
|
EXPECT_FALSE(v.Validate()) << v.error();
|
||||||
|
@ -251,8 +231,6 @@ TEST_F(ValidateFunctionTest, Function_WithPipelineStage_NotVoid_Fail) {
|
||||||
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
|
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
|
||||||
});
|
});
|
||||||
|
|
||||||
EXPECT_TRUE(td()->Determine()) << td()->error();
|
|
||||||
|
|
||||||
ValidatorImpl& v = Build();
|
ValidatorImpl& v = Build();
|
||||||
|
|
||||||
EXPECT_FALSE(v.Validate());
|
EXPECT_FALSE(v.Validate());
|
||||||
|
@ -275,8 +253,6 @@ TEST_F(ValidateFunctionTest, Function_WithPipelineStage_WithParams_Fail) {
|
||||||
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
|
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
|
||||||
});
|
});
|
||||||
|
|
||||||
EXPECT_TRUE(td()->Determine()) << td()->error();
|
|
||||||
|
|
||||||
ValidatorImpl& v = Build();
|
ValidatorImpl& v = Build();
|
||||||
|
|
||||||
EXPECT_FALSE(v.Validate());
|
EXPECT_FALSE(v.Validate());
|
||||||
|
@ -299,8 +275,6 @@ TEST_F(ValidateFunctionTest, PipelineStage_MustBeUnique_Fail) {
|
||||||
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
|
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
|
||||||
});
|
});
|
||||||
|
|
||||||
EXPECT_TRUE(td()->Determine()) << td()->error();
|
|
||||||
|
|
||||||
ValidatorImpl& v = Build();
|
ValidatorImpl& v = Build();
|
||||||
|
|
||||||
EXPECT_FALSE(v.Validate());
|
EXPECT_FALSE(v.Validate());
|
||||||
|
@ -321,8 +295,6 @@ TEST_F(ValidateFunctionTest, OnePipelineStageFunctionMustBePresent_Pass) {
|
||||||
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
|
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
|
||||||
});
|
});
|
||||||
|
|
||||||
EXPECT_TRUE(td()->Determine()) << td()->error();
|
|
||||||
|
|
||||||
ValidatorImpl& v = Build();
|
ValidatorImpl& v = Build();
|
||||||
|
|
||||||
EXPECT_TRUE(v.Validate()) << v.error();
|
EXPECT_TRUE(v.Validate()) << v.error();
|
||||||
|
@ -336,8 +308,6 @@ TEST_F(ValidateFunctionTest, OnePipelineStageFunctionMustBePresent_Fail) {
|
||||||
},
|
},
|
||||||
ast::FunctionDecorationList{});
|
ast::FunctionDecorationList{});
|
||||||
|
|
||||||
EXPECT_TRUE(td()->Determine()) << td()->error();
|
|
||||||
|
|
||||||
ValidatorImpl& v = Build();
|
ValidatorImpl& v = Build();
|
||||||
|
|
||||||
EXPECT_FALSE(v.Validate());
|
EXPECT_FALSE(v.Validate());
|
||||||
|
|
|
@ -66,14 +66,14 @@ TEST_F(ValidatorTest, AssignToScalar_Fail) {
|
||||||
|
|
||||||
auto* var = Var("my_var", ast::StorageClass::kNone, ty.i32(), Expr(2),
|
auto* var = Var("my_var", ast::StorageClass::kNone, ty.i32(), Expr(2),
|
||||||
ast::VariableDecorationList{});
|
ast::VariableDecorationList{});
|
||||||
|
RegisterVariable(var);
|
||||||
|
|
||||||
auto* lhs = Expr(1);
|
auto* lhs = Expr(1);
|
||||||
auto* rhs = Expr("my_var");
|
auto* rhs = Expr("my_var");
|
||||||
|
|
||||||
SetSource(Source{Source::Location{12, 34}});
|
SetSource(Source{Source::Location{12, 34}});
|
||||||
auto* assign = create<ast::AssignmentStatement>(lhs, rhs);
|
auto* assign = create<ast::AssignmentStatement>(lhs, rhs);
|
||||||
RegisterVariable(var);
|
WrapInFunction(assign);
|
||||||
|
|
||||||
EXPECT_TRUE(td()->DetermineResultType(assign));
|
|
||||||
|
|
||||||
ValidatorImpl& v = Build();
|
ValidatorImpl& v = Build();
|
||||||
|
|
||||||
|
@ -93,8 +93,9 @@ TEST_F(ValidatorTest, UsingUndefinedVariable_Fail) {
|
||||||
auto* lhs = Expr("b");
|
auto* lhs = Expr("b");
|
||||||
auto* rhs = Expr(2);
|
auto* rhs = Expr(2);
|
||||||
auto* assign = create<ast::AssignmentStatement>(lhs, rhs);
|
auto* assign = create<ast::AssignmentStatement>(lhs, rhs);
|
||||||
|
WrapInFunction(assign);
|
||||||
|
|
||||||
EXPECT_FALSE(td()->DetermineResultType(assign));
|
EXPECT_FALSE(td()->Determine());
|
||||||
EXPECT_EQ(td()->error(),
|
EXPECT_EQ(td()->error(),
|
||||||
"12:34: v-0006: identifier must be declared before use: b");
|
"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{
|
auto* body = create<ast::BlockStatement>(ast::StatementList{
|
||||||
create<ast::AssignmentStatement>(lhs, rhs),
|
create<ast::AssignmentStatement>(lhs, rhs),
|
||||||
});
|
});
|
||||||
|
WrapInFunction(body);
|
||||||
|
|
||||||
EXPECT_FALSE(td()->DetermineStatements(body));
|
EXPECT_FALSE(td()->Determine());
|
||||||
EXPECT_EQ(td()->error(),
|
EXPECT_EQ(td()->error(),
|
||||||
"12:34: v-0006: identifier must be declared before use: b");
|
"12:34: v-0006: identifier must be declared before use: b");
|
||||||
}
|
}
|
||||||
|
@ -122,19 +124,20 @@ TEST_F(ValidatorTest, AssignCompatibleTypes_Pass) {
|
||||||
// a = 2
|
// a = 2
|
||||||
auto* var = Var("a", ast::StorageClass::kNone, ty.i32(), Expr(2),
|
auto* var = Var("a", ast::StorageClass::kNone, ty.i32(), Expr(2),
|
||||||
ast::VariableDecorationList{});
|
ast::VariableDecorationList{});
|
||||||
|
RegisterVariable(var);
|
||||||
|
|
||||||
auto* lhs = Expr("a");
|
auto* lhs = Expr("a");
|
||||||
auto* rhs = Expr(2);
|
auto* rhs = Expr(2);
|
||||||
|
|
||||||
auto* assign = create<ast::AssignmentStatement>(
|
auto* assign = create<ast::AssignmentStatement>(
|
||||||
Source{Source::Location{12, 34}}, lhs, rhs);
|
Source{Source::Location{12, 34}}, lhs, rhs);
|
||||||
RegisterVariable(var);
|
WrapInFunction(assign);
|
||||||
EXPECT_TRUE(td()->DetermineResultType(assign)) << td()->error();
|
|
||||||
ASSERT_NE(TypeOf(lhs), nullptr);
|
|
||||||
ASSERT_NE(TypeOf(rhs), nullptr);
|
|
||||||
|
|
||||||
ValidatorImpl& v = Build();
|
ValidatorImpl& v = Build();
|
||||||
|
|
||||||
|
ASSERT_NE(TypeOf(lhs), nullptr);
|
||||||
|
ASSERT_NE(TypeOf(rhs), nullptr);
|
||||||
|
|
||||||
EXPECT_TRUE(v.ValidateAssign(assign)) << v.error();
|
EXPECT_TRUE(v.ValidateAssign(assign)) << v.error();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,19 +148,20 @@ TEST_F(ValidatorTest, AssignCompatibleTypesThroughAlias_Pass) {
|
||||||
auto* myint = ty.alias("myint", ty.i32());
|
auto* myint = ty.alias("myint", ty.i32());
|
||||||
auto* var = Var("a", ast::StorageClass::kNone, myint, Expr(2),
|
auto* var = Var("a", ast::StorageClass::kNone, myint, Expr(2),
|
||||||
ast::VariableDecorationList{});
|
ast::VariableDecorationList{});
|
||||||
|
RegisterVariable(var);
|
||||||
|
|
||||||
auto* lhs = Expr("a");
|
auto* lhs = Expr("a");
|
||||||
auto* rhs = Expr(2);
|
auto* rhs = Expr(2);
|
||||||
|
|
||||||
auto* assign = create<ast::AssignmentStatement>(
|
auto* assign = create<ast::AssignmentStatement>(
|
||||||
Source{Source::Location{12, 34}}, lhs, rhs);
|
Source{Source::Location{12, 34}}, lhs, rhs);
|
||||||
RegisterVariable(var);
|
WrapInFunction(assign);
|
||||||
EXPECT_TRUE(td()->DetermineResultType(assign)) << td()->error();
|
|
||||||
ASSERT_NE(TypeOf(lhs), nullptr);
|
|
||||||
ASSERT_NE(TypeOf(rhs), nullptr);
|
|
||||||
|
|
||||||
ValidatorImpl& v = Build();
|
ValidatorImpl& v = Build();
|
||||||
|
|
||||||
|
ASSERT_NE(TypeOf(lhs), nullptr);
|
||||||
|
ASSERT_NE(TypeOf(rhs), nullptr);
|
||||||
|
|
||||||
EXPECT_TRUE(v.ValidateAssign(assign)) << v.error();
|
EXPECT_TRUE(v.ValidateAssign(assign)) << v.error();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -169,20 +173,21 @@ TEST_F(ValidatorTest, AssignCompatibleTypesInferRHSLoad_Pass) {
|
||||||
ast::VariableDecorationList{});
|
ast::VariableDecorationList{});
|
||||||
auto* var_b = Var("b", ast::StorageClass::kNone, ty.i32(), Expr(3),
|
auto* var_b = Var("b", ast::StorageClass::kNone, ty.i32(), Expr(3),
|
||||||
ast::VariableDecorationList{});
|
ast::VariableDecorationList{});
|
||||||
|
RegisterVariable(var_a);
|
||||||
|
RegisterVariable(var_b);
|
||||||
|
|
||||||
auto* lhs = Expr("a");
|
auto* lhs = Expr("a");
|
||||||
auto* rhs = Expr("b");
|
auto* rhs = Expr("b");
|
||||||
|
|
||||||
auto* assign = create<ast::AssignmentStatement>(
|
auto* assign = create<ast::AssignmentStatement>(
|
||||||
Source{Source::Location{12, 34}}, lhs, rhs);
|
Source{Source::Location{12, 34}}, lhs, rhs);
|
||||||
RegisterVariable(var_a);
|
WrapInFunction(assign);
|
||||||
RegisterVariable(var_b);
|
|
||||||
EXPECT_TRUE(td()->DetermineResultType(assign)) << td()->error();
|
|
||||||
ASSERT_NE(TypeOf(lhs), nullptr);
|
|
||||||
ASSERT_NE(TypeOf(rhs), nullptr);
|
|
||||||
|
|
||||||
ValidatorImpl& v = Build();
|
ValidatorImpl& v = Build();
|
||||||
|
|
||||||
|
ASSERT_NE(TypeOf(lhs), nullptr);
|
||||||
|
ASSERT_NE(TypeOf(rhs), nullptr);
|
||||||
|
|
||||||
EXPECT_TRUE(v.ValidateAssign(assign)) << v.error();
|
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_a = Var("a", func, ty.i32(), Expr(2), {});
|
||||||
auto* var_b = Const("b", ast::StorageClass::kNone, ty.pointer<int>(func),
|
auto* var_b = Const("b", ast::StorageClass::kNone, ty.pointer<int>(func),
|
||||||
Expr("a"), {});
|
Expr("a"), {});
|
||||||
|
RegisterVariable(var_a);
|
||||||
|
RegisterVariable(var_b);
|
||||||
|
|
||||||
auto* lhs = Expr("b");
|
auto* lhs = Expr("b");
|
||||||
auto* rhs = Expr(2);
|
auto* rhs = Expr(2);
|
||||||
|
|
||||||
auto* assign = create<ast::AssignmentStatement>(
|
auto* assign = create<ast::AssignmentStatement>(
|
||||||
Source{Source::Location{12, 34}}, lhs, rhs);
|
Source{Source::Location{12, 34}}, lhs, rhs);
|
||||||
RegisterVariable(var_a);
|
WrapInFunction(assign);
|
||||||
RegisterVariable(var_b);
|
|
||||||
EXPECT_TRUE(td()->DetermineResultType(assign)) << td()->error();
|
|
||||||
ASSERT_NE(TypeOf(lhs), nullptr);
|
|
||||||
ASSERT_NE(TypeOf(rhs), nullptr);
|
|
||||||
|
|
||||||
ValidatorImpl& v = Build();
|
ValidatorImpl& v = Build();
|
||||||
|
|
||||||
|
ASSERT_NE(TypeOf(lhs), nullptr);
|
||||||
|
ASSERT_NE(TypeOf(rhs), nullptr);
|
||||||
|
|
||||||
EXPECT_TRUE(v.ValidateAssign(assign)) << v.error();
|
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),
|
auto* var = Var("a", ast::StorageClass::kNone, ty.i32(), Expr(2),
|
||||||
ast::VariableDecorationList{});
|
ast::VariableDecorationList{});
|
||||||
|
RegisterVariable(var);
|
||||||
|
|
||||||
auto* lhs = Expr("a");
|
auto* lhs = Expr("a");
|
||||||
auto* rhs = Expr(2.3f);
|
auto* rhs = Expr(2.3f);
|
||||||
|
|
||||||
auto* assign = create<ast::AssignmentStatement>(
|
auto* assign = create<ast::AssignmentStatement>(
|
||||||
Source{Source::Location{12, 34}}, lhs, rhs);
|
Source{Source::Location{12, 34}}, lhs, rhs);
|
||||||
RegisterVariable(var);
|
WrapInFunction(assign);
|
||||||
EXPECT_TRUE(td()->DetermineResultType(assign)) << td()->error();
|
|
||||||
ASSERT_NE(TypeOf(lhs), nullptr);
|
|
||||||
ASSERT_NE(TypeOf(rhs), nullptr);
|
|
||||||
|
|
||||||
ValidatorImpl& v = Build();
|
ValidatorImpl& v = Build();
|
||||||
|
|
||||||
|
ASSERT_NE(TypeOf(lhs), nullptr);
|
||||||
|
ASSERT_NE(TypeOf(rhs), nullptr);
|
||||||
|
|
||||||
EXPECT_FALSE(v.ValidateAssign(assign));
|
EXPECT_FALSE(v.ValidateAssign(assign));
|
||||||
ASSERT_TRUE(v.has_error());
|
ASSERT_TRUE(v.has_error());
|
||||||
// TODO(sarahM0): figure out what should be the error number.
|
// 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_a = Var("a", priv, ty.f32(), Expr(2), {});
|
||||||
auto* var_b = Const("b", ast::StorageClass::kNone, ty.pointer<float>(priv),
|
auto* var_b = Const("b", ast::StorageClass::kNone, ty.pointer<float>(priv),
|
||||||
Expr("a"), {});
|
Expr("a"), {});
|
||||||
|
RegisterVariable(var_a);
|
||||||
|
RegisterVariable(var_b);
|
||||||
|
|
||||||
auto* lhs = Expr("a");
|
auto* lhs = Expr("a");
|
||||||
auto* rhs = Expr(2);
|
auto* rhs = Expr(2);
|
||||||
|
|
||||||
auto* assign = create<ast::AssignmentStatement>(
|
auto* assign = create<ast::AssignmentStatement>(
|
||||||
Source{Source::Location{12, 34}}, lhs, rhs);
|
Source{Source::Location{12, 34}}, lhs, rhs);
|
||||||
RegisterVariable(var_a);
|
WrapInFunction(assign);
|
||||||
RegisterVariable(var_b);
|
|
||||||
EXPECT_TRUE(td()->DetermineResultType(assign)) << td()->error();
|
|
||||||
ASSERT_NE(TypeOf(lhs), nullptr);
|
|
||||||
ASSERT_NE(TypeOf(rhs), nullptr);
|
|
||||||
|
|
||||||
ValidatorImpl& v = Build();
|
ValidatorImpl& v = Build();
|
||||||
|
|
||||||
|
ASSERT_NE(TypeOf(lhs), nullptr);
|
||||||
|
ASSERT_NE(TypeOf(rhs), nullptr);
|
||||||
|
|
||||||
EXPECT_FALSE(v.ValidateAssign(assign));
|
EXPECT_FALSE(v.ValidateAssign(assign));
|
||||||
EXPECT_EQ(v.error(),
|
EXPECT_EQ(v.error(),
|
||||||
"12:34 v-000x: invalid assignment: can't assign value of type "
|
"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,
|
create<ast::AssignmentStatement>(Source{Source::Location{12, 34}}, lhs,
|
||||||
rhs),
|
rhs),
|
||||||
});
|
});
|
||||||
|
WrapInFunction(body);
|
||||||
EXPECT_TRUE(td()->DetermineStatements(body)) << td()->error();
|
|
||||||
ASSERT_NE(TypeOf(lhs), nullptr);
|
|
||||||
ASSERT_NE(TypeOf(rhs), nullptr);
|
|
||||||
|
|
||||||
ValidatorImpl& v = Build();
|
ValidatorImpl& v = Build();
|
||||||
|
|
||||||
|
ASSERT_NE(TypeOf(lhs), nullptr);
|
||||||
|
ASSERT_NE(TypeOf(rhs), nullptr);
|
||||||
|
|
||||||
EXPECT_TRUE(v.ValidateStatements(body)) << v.error();
|
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,
|
create<ast::AssignmentStatement>(Source{Source::Location{12, 34}}, lhs,
|
||||||
rhs),
|
rhs),
|
||||||
});
|
});
|
||||||
|
WrapInFunction(block);
|
||||||
EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error();
|
|
||||||
ASSERT_NE(TypeOf(lhs), nullptr);
|
|
||||||
ASSERT_NE(TypeOf(rhs), nullptr);
|
|
||||||
|
|
||||||
ValidatorImpl& v = Build();
|
ValidatorImpl& v = Build();
|
||||||
|
|
||||||
|
ASSERT_NE(TypeOf(lhs), nullptr);
|
||||||
|
ASSERT_NE(TypeOf(rhs), nullptr);
|
||||||
|
|
||||||
EXPECT_FALSE(v.ValidateStatements(block));
|
EXPECT_FALSE(v.ValidateStatements(block));
|
||||||
ASSERT_TRUE(v.has_error());
|
ASSERT_TRUE(v.has_error());
|
||||||
// TODO(sarahM0): figure out what should be the error number.
|
// TODO(sarahM0): figure out what should be the error number.
|
||||||
|
@ -350,12 +358,13 @@ TEST_F(ValidatorTest, AssignIncompatibleTypesInNestedBlockStatement_Fail) {
|
||||||
inner_block,
|
inner_block,
|
||||||
});
|
});
|
||||||
|
|
||||||
EXPECT_TRUE(td()->DetermineStatements(outer_block)) << td()->error();
|
WrapInFunction(outer_block);
|
||||||
ASSERT_NE(TypeOf(lhs), nullptr);
|
|
||||||
ASSERT_NE(TypeOf(rhs), nullptr);
|
|
||||||
|
|
||||||
ValidatorImpl& v = Build();
|
ValidatorImpl& v = Build();
|
||||||
|
|
||||||
|
ASSERT_NE(TypeOf(lhs), nullptr);
|
||||||
|
ASSERT_NE(TypeOf(rhs), nullptr);
|
||||||
|
|
||||||
EXPECT_FALSE(v.ValidateStatements(outer_block));
|
EXPECT_FALSE(v.ValidateStatements(outer_block));
|
||||||
ASSERT_TRUE(v.has_error());
|
ASSERT_TRUE(v.has_error());
|
||||||
// TODO(sarahM0): figure out what should be the error number.
|
// TODO(sarahM0): figure out what should be the error number.
|
||||||
|
@ -366,9 +375,9 @@ TEST_F(ValidatorTest, AssignIncompatibleTypesInNestedBlockStatement_Fail) {
|
||||||
|
|
||||||
TEST_F(ValidatorTest, GlobalVariableWithStorageClass_Pass) {
|
TEST_F(ValidatorTest, GlobalVariableWithStorageClass_Pass) {
|
||||||
// var<in> gloabl_var: f32;
|
// var<in> gloabl_var: f32;
|
||||||
AST().AddGlobalVariable(Var(Source{Source::Location{12, 34}}, "global_var",
|
Global(Source{Source::Location{12, 34}}, "global_var",
|
||||||
ast::StorageClass::kInput, ty.f32(), nullptr,
|
ast::StorageClass::kInput, ty.f32(), nullptr,
|
||||||
ast::VariableDecorationList{}));
|
ast::VariableDecorationList{});
|
||||||
|
|
||||||
ValidatorImpl& v = Build();
|
ValidatorImpl& v = Build();
|
||||||
const Program* program = v.program();
|
const Program* program = v.program();
|
||||||
|
@ -379,10 +388,9 @@ TEST_F(ValidatorTest, GlobalVariableWithStorageClass_Pass) {
|
||||||
|
|
||||||
TEST_F(ValidatorTest, GlobalVariableNoStorageClass_Fail) {
|
TEST_F(ValidatorTest, GlobalVariableNoStorageClass_Fail) {
|
||||||
// var gloabl_var: f32;
|
// var gloabl_var: f32;
|
||||||
AST().AddGlobalVariable(Var(Source{Source::Location{12, 34}}, "global_var",
|
Global(Source{Source::Location{12, 34}}, "global_var",
|
||||||
ast::StorageClass::kNone, ty.f32(), nullptr,
|
ast::StorageClass::kNone, ty.f32(), nullptr,
|
||||||
ast::VariableDecorationList{}));
|
ast::VariableDecorationList{});
|
||||||
EXPECT_TRUE(td()->Determine()) << td()->error();
|
|
||||||
|
|
||||||
ValidatorImpl& v = Build();
|
ValidatorImpl& v = Build();
|
||||||
|
|
||||||
|
@ -393,10 +401,9 @@ TEST_F(ValidatorTest, GlobalVariableNoStorageClass_Fail) {
|
||||||
|
|
||||||
TEST_F(ValidatorTest, GlobalConstantWithStorageClass_Fail) {
|
TEST_F(ValidatorTest, GlobalConstantWithStorageClass_Fail) {
|
||||||
// const<in> gloabl_var: f32;
|
// const<in> gloabl_var: f32;
|
||||||
AST().AddGlobalVariable(Const(Source{Source::Location{12, 34}}, "global_var",
|
GlobalConst(Source{Source::Location{12, 34}}, "global_var",
|
||||||
ast::StorageClass::kInput, ty.f32(), nullptr,
|
ast::StorageClass::kInput, ty.f32(), nullptr,
|
||||||
ast::VariableDecorationList{}));
|
ast::VariableDecorationList{});
|
||||||
EXPECT_TRUE(td()->Determine()) << td()->error();
|
|
||||||
|
|
||||||
ValidatorImpl& v = Build();
|
ValidatorImpl& v = Build();
|
||||||
|
|
||||||
|
@ -408,10 +415,9 @@ TEST_F(ValidatorTest, GlobalConstantWithStorageClass_Fail) {
|
||||||
|
|
||||||
TEST_F(ValidatorTest, GlobalConstNoStorageClass_Pass) {
|
TEST_F(ValidatorTest, GlobalConstNoStorageClass_Pass) {
|
||||||
// const gloabl_var: f32;
|
// const gloabl_var: f32;
|
||||||
AST().AddGlobalVariable(Const(Source{Source::Location{12, 34}}, "global_var",
|
GlobalConst(Source{Source::Location{12, 34}}, "global_var",
|
||||||
ast::StorageClass::kNone, ty.f32(), nullptr,
|
ast::StorageClass::kNone, ty.f32(), nullptr,
|
||||||
ast::VariableDecorationList{}));
|
ast::VariableDecorationList{});
|
||||||
EXPECT_TRUE(td()->Determine()) << td()->error();
|
|
||||||
|
|
||||||
ValidatorImpl& v = Build();
|
ValidatorImpl& v = Build();
|
||||||
|
|
||||||
|
@ -423,9 +429,8 @@ TEST_F(ValidatorTest, UsingUndefinedVariableGlobalVariable_Fail) {
|
||||||
// fn my_func() -> f32 {
|
// fn my_func() -> f32 {
|
||||||
// not_global_var = 3.14f;
|
// not_global_var = 3.14f;
|
||||||
// }
|
// }
|
||||||
AST().AddGlobalVariable(Var("global_var", ast::StorageClass::kPrivate,
|
Global("global_var", ast::StorageClass::kPrivate, ty.f32(), Expr(2.1f),
|
||||||
ty.f32(), Expr(2.1f),
|
ast::VariableDecorationList{});
|
||||||
ast::VariableDecorationList{}));
|
|
||||||
|
|
||||||
SetSource(Source{Source::Location{12, 34}});
|
SetSource(Source{Source::Location{12, 34}});
|
||||||
auto* lhs = Expr("not_global_var");
|
auto* lhs = Expr("not_global_var");
|
||||||
|
@ -451,9 +456,8 @@ TEST_F(ValidatorTest, UsingUndefinedVariableGlobalVariable_Pass) {
|
||||||
// return;
|
// return;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
AST().AddGlobalVariable(Var("global_var", ast::StorageClass::kPrivate,
|
Global("global_var", ast::StorageClass::kPrivate, ty.f32(), Expr(2.1f),
|
||||||
ty.f32(), Expr(2.1f),
|
ast::VariableDecorationList{});
|
||||||
ast::VariableDecorationList{}));
|
|
||||||
|
|
||||||
Func("my_func", ast::VariableList{}, ty.void_(),
|
Func("my_func", ast::VariableList{}, ty.void_(),
|
||||||
ast::StatementList{
|
ast::StatementList{
|
||||||
|
@ -465,8 +469,6 @@ TEST_F(ValidatorTest, UsingUndefinedVariableGlobalVariable_Pass) {
|
||||||
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
|
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
|
||||||
});
|
});
|
||||||
|
|
||||||
EXPECT_TRUE(td()->Determine()) << td()->error();
|
|
||||||
|
|
||||||
ValidatorImpl& v = Build();
|
ValidatorImpl& v = Build();
|
||||||
|
|
||||||
EXPECT_TRUE(v.Validate()) << v.error();
|
EXPECT_TRUE(v.Validate()) << v.error();
|
||||||
|
@ -495,12 +497,13 @@ TEST_F(ValidatorTest, UsingUndefinedVariableInnerScope_Fail) {
|
||||||
rhs),
|
rhs),
|
||||||
});
|
});
|
||||||
|
|
||||||
EXPECT_TRUE(td()->DetermineStatements(outer_body)) << td()->error();
|
WrapInFunction(outer_body);
|
||||||
ASSERT_NE(TypeOf(lhs), nullptr);
|
|
||||||
ASSERT_NE(TypeOf(rhs), nullptr);
|
|
||||||
|
|
||||||
ValidatorImpl& v = Build();
|
ValidatorImpl& v = Build();
|
||||||
|
|
||||||
|
ASSERT_NE(TypeOf(lhs), nullptr);
|
||||||
|
ASSERT_NE(TypeOf(rhs), nullptr);
|
||||||
|
|
||||||
EXPECT_FALSE(v.ValidateStatements(outer_body));
|
EXPECT_FALSE(v.ValidateStatements(outer_body));
|
||||||
EXPECT_EQ(v.error(), "12:34 v-0006: 'a' is not declared");
|
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{}),
|
create<ast::IfStatement>(cond, body, ast::ElseStatementList{}),
|
||||||
});
|
});
|
||||||
|
|
||||||
EXPECT_TRUE(td()->DetermineStatements(outer_body)) << td()->error();
|
WrapInFunction(outer_body);
|
||||||
ASSERT_NE(TypeOf(lhs), nullptr);
|
|
||||||
ASSERT_NE(TypeOf(rhs), nullptr);
|
|
||||||
|
|
||||||
ValidatorImpl& v = Build();
|
ValidatorImpl& v = Build();
|
||||||
|
|
||||||
|
ASSERT_NE(TypeOf(lhs), nullptr);
|
||||||
|
ASSERT_NE(TypeOf(rhs), nullptr);
|
||||||
|
|
||||||
EXPECT_TRUE(v.ValidateStatements(outer_body)) << v.error();
|
EXPECT_TRUE(v.ValidateStatements(outer_body)) << v.error();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -561,12 +565,13 @@ TEST_F(ValidatorTest, UsingUndefinedVariableDifferentScope_Fail) {
|
||||||
second_body,
|
second_body,
|
||||||
});
|
});
|
||||||
|
|
||||||
EXPECT_TRUE(td()->DetermineStatements(outer_body)) << td()->error();
|
WrapInFunction(outer_body);
|
||||||
ASSERT_NE(TypeOf(lhs), nullptr);
|
|
||||||
ASSERT_NE(TypeOf(rhs), nullptr);
|
|
||||||
|
|
||||||
ValidatorImpl& v = Build();
|
ValidatorImpl& v = Build();
|
||||||
|
|
||||||
|
ASSERT_NE(TypeOf(lhs), nullptr);
|
||||||
|
ASSERT_NE(TypeOf(rhs), nullptr);
|
||||||
|
|
||||||
EXPECT_FALSE(v.ValidateStatements(outer_body));
|
EXPECT_FALSE(v.ValidateStatements(outer_body));
|
||||||
EXPECT_EQ(v.error(), "12:34 v-0006: 'a' is not declared");
|
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) {
|
TEST_F(ValidatorTest, GlobalVariableUnique_Pass) {
|
||||||
// var global_var0 : f32 = 0.1;
|
// var global_var0 : f32 = 0.1;
|
||||||
// var global_var1 : i32 = 0;
|
// var global_var1 : i32 = 0;
|
||||||
auto* var0 = Var("global_var0", ast::StorageClass::kPrivate, ty.f32(),
|
Global("global_var0", ast::StorageClass::kPrivate, ty.f32(), Expr(0.1f),
|
||||||
Expr(0.1f), ast::VariableDecorationList{});
|
ast::VariableDecorationList{});
|
||||||
AST().AddGlobalVariable(var0);
|
|
||||||
|
|
||||||
auto* var1 = Var(Source{Source::Location{12, 34}}, "global_var1",
|
Global(Source{Source::Location{12, 34}}, "global_var1",
|
||||||
ast::StorageClass::kPrivate, ty.f32(), Expr(0),
|
ast::StorageClass::kPrivate, ty.f32(), Expr(0),
|
||||||
ast::VariableDecorationList{});
|
ast::VariableDecorationList{});
|
||||||
AST().AddGlobalVariable(var1);
|
|
||||||
|
|
||||||
ValidatorImpl& v = Build();
|
ValidatorImpl& v = Build();
|
||||||
const Program* program = v.program();
|
const Program* program = v.program();
|
||||||
|
@ -593,14 +596,12 @@ TEST_F(ValidatorTest, GlobalVariableUnique_Pass) {
|
||||||
TEST_F(ValidatorTest, GlobalVariableNotUnique_Fail) {
|
TEST_F(ValidatorTest, GlobalVariableNotUnique_Fail) {
|
||||||
// var global_var : f32 = 0.1;
|
// var global_var : f32 = 0.1;
|
||||||
// var global_var : i32 = 0;
|
// var global_var : i32 = 0;
|
||||||
auto* var0 = Var("global_var", ast::StorageClass::kPrivate, ty.f32(),
|
Global("global_var", ast::StorageClass::kPrivate, ty.f32(), Expr(0.1f),
|
||||||
Expr(0.1f), ast::VariableDecorationList{});
|
ast::VariableDecorationList{});
|
||||||
AST().AddGlobalVariable(var0);
|
|
||||||
|
|
||||||
auto* var1 = Var(Source{Source::Location{12, 34}}, "global_var",
|
Global(Source{Source::Location{12, 34}}, "global_var",
|
||||||
ast::StorageClass::kPrivate, ty.i32(), Expr(0),
|
ast::StorageClass::kPrivate, ty.i32(), Expr(0),
|
||||||
ast::VariableDecorationList{});
|
ast::VariableDecorationList{});
|
||||||
AST().AddGlobalVariable(var1);
|
|
||||||
|
|
||||||
ValidatorImpl& v = Build();
|
ValidatorImpl& v = Build();
|
||||||
const Program* program = v.program();
|
const Program* program = v.program();
|
||||||
|
@ -627,12 +628,13 @@ TEST_F(ValidatorTest, AssignToConstant_Fail) {
|
||||||
rhs),
|
rhs),
|
||||||
});
|
});
|
||||||
|
|
||||||
EXPECT_TRUE(td()->DetermineStatements(body)) << td()->error();
|
WrapInFunction(body);
|
||||||
ASSERT_NE(TypeOf(lhs), nullptr);
|
|
||||||
ASSERT_NE(TypeOf(rhs), nullptr);
|
|
||||||
|
|
||||||
ValidatorImpl& v = Build();
|
ValidatorImpl& v = Build();
|
||||||
|
|
||||||
|
ASSERT_NE(TypeOf(lhs), nullptr);
|
||||||
|
ASSERT_NE(TypeOf(rhs), nullptr);
|
||||||
|
|
||||||
EXPECT_FALSE(v.ValidateStatements(body));
|
EXPECT_FALSE(v.ValidateStatements(body));
|
||||||
EXPECT_EQ(v.error(), "12:34 v-0021: cannot re-assign a constant: 'a'");
|
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;
|
// return 0;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
auto* global_var = Var("a", ast::StorageClass::kPrivate, ty.f32(), Expr(2.1f),
|
Global("a", ast::StorageClass::kPrivate, ty.f32(), Expr(2.1f),
|
||||||
ast::VariableDecorationList{});
|
ast::VariableDecorationList{});
|
||||||
AST().AddGlobalVariable(global_var);
|
|
||||||
|
|
||||||
auto* var = Var("a", ast::StorageClass::kNone, ty.f32(), Expr(2.0f),
|
auto* var = Var("a", ast::StorageClass::kNone, ty.f32(), Expr(2.0f),
|
||||||
ast::VariableDecorationList{});
|
ast::VariableDecorationList{});
|
||||||
|
@ -658,8 +659,6 @@ TEST_F(ValidatorTest, GlobalVariableFunctionVariableNotUnique_Fail) {
|
||||||
},
|
},
|
||||||
ast::FunctionDecorationList{});
|
ast::FunctionDecorationList{});
|
||||||
|
|
||||||
EXPECT_TRUE(td()->Determine()) << td()->error();
|
|
||||||
|
|
||||||
ValidatorImpl& v = Build();
|
ValidatorImpl& v = Build();
|
||||||
|
|
||||||
EXPECT_FALSE(v.Validate()) << v.error();
|
EXPECT_FALSE(v.Validate()) << v.error();
|
||||||
|
@ -685,8 +684,6 @@ TEST_F(ValidatorTest, RedeclaredIndentifier_Fail) {
|
||||||
},
|
},
|
||||||
ast::FunctionDecorationList{});
|
ast::FunctionDecorationList{});
|
||||||
|
|
||||||
EXPECT_TRUE(td()->Determine()) << td()->error();
|
|
||||||
|
|
||||||
ValidatorImpl& v = Build();
|
ValidatorImpl& v = Build();
|
||||||
|
|
||||||
EXPECT_FALSE(v.Validate());
|
EXPECT_FALSE(v.Validate());
|
||||||
|
@ -715,7 +712,7 @@ TEST_F(ValidatorTest, RedeclaredIdentifierInnerScope_Pass) {
|
||||||
var_a_float),
|
var_a_float),
|
||||||
});
|
});
|
||||||
|
|
||||||
EXPECT_TRUE(td()->DetermineStatements(outer_body)) << td()->error();
|
WrapInFunction(outer_body);
|
||||||
|
|
||||||
ValidatorImpl& v = Build();
|
ValidatorImpl& v = Build();
|
||||||
|
|
||||||
|
@ -745,7 +742,7 @@ TEST_F(ValidatorTest, DISABLED_RedeclaredIdentifierInnerScope_False) {
|
||||||
create<ast::IfStatement>(cond, body, ast::ElseStatementList{}),
|
create<ast::IfStatement>(cond, body, ast::ElseStatementList{}),
|
||||||
});
|
});
|
||||||
|
|
||||||
EXPECT_TRUE(td()->DetermineStatements(outer_body)) << td()->error();
|
WrapInFunction(outer_body);
|
||||||
|
|
||||||
ValidatorImpl& v = Build();
|
ValidatorImpl& v = Build();
|
||||||
|
|
||||||
|
@ -770,7 +767,7 @@ TEST_F(ValidatorTest, RedeclaredIdentifierInnerScopeBlock_Pass) {
|
||||||
create<ast::VariableDeclStatement>(var_outer),
|
create<ast::VariableDeclStatement>(var_outer),
|
||||||
});
|
});
|
||||||
|
|
||||||
EXPECT_TRUE(td()->DetermineStatements(outer_body)) << td()->error();
|
WrapInFunction(outer_body);
|
||||||
|
|
||||||
ValidatorImpl& v = Build();
|
ValidatorImpl& v = Build();
|
||||||
|
|
||||||
|
@ -794,7 +791,7 @@ TEST_F(ValidatorTest, RedeclaredIdentifierInnerScopeBlock_Fail) {
|
||||||
inner,
|
inner,
|
||||||
});
|
});
|
||||||
|
|
||||||
EXPECT_TRUE(td()->DetermineStatements(outer_body)) << td()->error();
|
WrapInFunction(outer_body);
|
||||||
|
|
||||||
ValidatorImpl& v = Build();
|
ValidatorImpl& v = Build();
|
||||||
|
|
||||||
|
@ -829,8 +826,6 @@ TEST_F(ValidatorTest, RedeclaredIdentifierDifferentFunctions_Pass) {
|
||||||
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
|
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
|
||||||
});
|
});
|
||||||
|
|
||||||
EXPECT_TRUE(td()->Determine()) << td()->error();
|
|
||||||
|
|
||||||
ValidatorImpl& v = Build();
|
ValidatorImpl& v = Build();
|
||||||
|
|
||||||
EXPECT_TRUE(v.Validate()) << v.error();
|
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,
|
auto* var = Var("a", ast::StorageClass::kNone, ty.i32(), nullptr,
|
||||||
ast::VariableDecorationList{});
|
ast::VariableDecorationList{});
|
||||||
|
|
||||||
td()->RegisterVariableForTesting(var);
|
|
||||||
auto* lhs = Expr("a");
|
auto* lhs = Expr("a");
|
||||||
auto* rhs = Expr(2);
|
auto* rhs = Expr(2);
|
||||||
|
|
||||||
|
@ -854,12 +847,13 @@ TEST_F(ValidatorTest, VariableDeclNoConstructor_Pass) {
|
||||||
rhs),
|
rhs),
|
||||||
});
|
});
|
||||||
|
|
||||||
EXPECT_TRUE(td()->DetermineStatements(body)) << td()->error();
|
WrapInFunction(body);
|
||||||
ASSERT_NE(TypeOf(lhs), nullptr);
|
|
||||||
ASSERT_NE(TypeOf(rhs), nullptr);
|
|
||||||
|
|
||||||
ValidatorImpl& v = Build();
|
ValidatorImpl& v = Build();
|
||||||
|
|
||||||
|
ASSERT_NE(TypeOf(lhs), nullptr);
|
||||||
|
ASSERT_NE(TypeOf(rhs), nullptr);
|
||||||
|
|
||||||
EXPECT_TRUE(v.ValidateStatements(body)) << v.error();
|
EXPECT_TRUE(v.ValidateStatements(body)) << v.error();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -58,8 +58,18 @@ class ValidatorTestHelper : public ProgramBuilder {
|
||||||
/// Inserts a variable into the current scope.
|
/// Inserts a variable into the current scope.
|
||||||
/// @param var the variable to register.
|
/// @param var the variable to register.
|
||||||
void RegisterVariable(ast::Variable* var) {
|
void RegisterVariable(ast::Variable* var) {
|
||||||
|
AST().AddGlobalVariable(var);
|
||||||
vars_for_testing_.emplace_back(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:
|
private:
|
||||||
|
|
|
@ -178,8 +178,6 @@ TEST_F(ValidatorTypeTest, RuntimeArrayInFunction_Fail) {
|
||||||
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
|
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
|
||||||
});
|
});
|
||||||
|
|
||||||
EXPECT_TRUE(td()->Determine()) << td()->error();
|
|
||||||
|
|
||||||
ValidatorImpl& v = Build();
|
ValidatorImpl& v = Build();
|
||||||
|
|
||||||
EXPECT_FALSE(v.Validate());
|
EXPECT_FALSE(v.Validate());
|
||||||
|
@ -210,8 +208,6 @@ TEST_F(ValidatorTypeTest, RuntimeArrayAsParameter_Fail) {
|
||||||
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
|
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
|
||||||
});
|
});
|
||||||
|
|
||||||
EXPECT_TRUE(td()->Determine()) << td()->error();
|
|
||||||
|
|
||||||
ValidatorImpl& v = Build();
|
ValidatorImpl& v = Build();
|
||||||
|
|
||||||
EXPECT_FALSE(v.Validate());
|
EXPECT_FALSE(v.Validate());
|
||||||
|
|
|
@ -60,18 +60,15 @@ using HlslBinaryTest = TestParamHelper<BinaryData>;
|
||||||
TEST_P(HlslBinaryTest, Emit_f32) {
|
TEST_P(HlslBinaryTest, Emit_f32) {
|
||||||
auto params = GetParam();
|
auto params = GetParam();
|
||||||
|
|
||||||
auto* left_var = Var("left", ast::StorageClass::kFunction, ty.f32());
|
Global("left", ast::StorageClass::kFunction, ty.f32());
|
||||||
auto* right_var = Var("right", ast::StorageClass::kFunction, ty.f32());
|
Global("right", ast::StorageClass::kFunction, ty.f32());
|
||||||
|
|
||||||
auto* left = Expr("left");
|
auto* left = Expr("left");
|
||||||
auto* right = Expr("right");
|
auto* right = Expr("right");
|
||||||
|
|
||||||
td.RegisterVariableForTesting(left_var);
|
|
||||||
td.RegisterVariableForTesting(right_var);
|
|
||||||
|
|
||||||
auto* expr = create<ast::BinaryExpression>(params.op, left, right);
|
auto* expr = create<ast::BinaryExpression>(params.op, left, right);
|
||||||
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
WrapInFunction(expr);
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
|
@ -81,18 +78,15 @@ TEST_P(HlslBinaryTest, Emit_f32) {
|
||||||
TEST_P(HlslBinaryTest, Emit_u32) {
|
TEST_P(HlslBinaryTest, Emit_u32) {
|
||||||
auto params = GetParam();
|
auto params = GetParam();
|
||||||
|
|
||||||
auto* left_var = Var("left", ast::StorageClass::kFunction, ty.u32());
|
Global("left", ast::StorageClass::kFunction, ty.u32());
|
||||||
auto* right_var = Var("right", ast::StorageClass::kFunction, ty.u32());
|
Global("right", ast::StorageClass::kFunction, ty.u32());
|
||||||
|
|
||||||
auto* left = Expr("left");
|
auto* left = Expr("left");
|
||||||
auto* right = Expr("right");
|
auto* right = Expr("right");
|
||||||
|
|
||||||
td.RegisterVariableForTesting(left_var);
|
|
||||||
td.RegisterVariableForTesting(right_var);
|
|
||||||
|
|
||||||
auto* expr = create<ast::BinaryExpression>(params.op, left, right);
|
auto* expr = create<ast::BinaryExpression>(params.op, left, right);
|
||||||
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
WrapInFunction(expr);
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
|
@ -102,18 +96,15 @@ TEST_P(HlslBinaryTest, Emit_u32) {
|
||||||
TEST_P(HlslBinaryTest, Emit_i32) {
|
TEST_P(HlslBinaryTest, Emit_i32) {
|
||||||
auto params = GetParam();
|
auto params = GetParam();
|
||||||
|
|
||||||
auto* left_var = Var("left", ast::StorageClass::kFunction, ty.i32());
|
Global("left", ast::StorageClass::kFunction, ty.i32());
|
||||||
auto* right_var = Var("right", ast::StorageClass::kFunction, ty.i32());
|
Global("right", ast::StorageClass::kFunction, ty.i32());
|
||||||
|
|
||||||
auto* left = Expr("left");
|
auto* left = Expr("left");
|
||||||
auto* right = Expr("right");
|
auto* right = Expr("right");
|
||||||
|
|
||||||
td.RegisterVariableForTesting(left_var);
|
|
||||||
td.RegisterVariableForTesting(right_var);
|
|
||||||
|
|
||||||
auto* expr = create<ast::BinaryExpression>(params.op, left, right);
|
auto* expr = create<ast::BinaryExpression>(params.op, left, right);
|
||||||
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
WrapInFunction(expr);
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
|
@ -148,7 +139,7 @@ TEST_F(HlslGeneratorImplTest_Binary, Multiply_VectorScalar) {
|
||||||
auto* expr =
|
auto* expr =
|
||||||
create<ast::BinaryExpression>(ast::BinaryOp::kMultiply, lhs, rhs);
|
create<ast::BinaryExpression>(ast::BinaryOp::kMultiply, lhs, rhs);
|
||||||
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
WrapInFunction(expr);
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
|
@ -165,7 +156,7 @@ TEST_F(HlslGeneratorImplTest_Binary, Multiply_ScalarVector) {
|
||||||
auto* expr =
|
auto* expr =
|
||||||
create<ast::BinaryExpression>(ast::BinaryOp::kMultiply, lhs, rhs);
|
create<ast::BinaryExpression>(ast::BinaryOp::kMultiply, lhs, rhs);
|
||||||
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
WrapInFunction(expr);
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
|
@ -176,16 +167,13 @@ TEST_F(HlslGeneratorImplTest_Binary, Multiply_ScalarVector) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(HlslGeneratorImplTest_Binary, Multiply_MatrixScalar) {
|
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* lhs = Expr("mat");
|
||||||
auto* rhs = Expr(1.f);
|
auto* rhs = Expr(1.f);
|
||||||
|
|
||||||
td.RegisterVariableForTesting(var);
|
|
||||||
|
|
||||||
auto* expr =
|
auto* expr =
|
||||||
create<ast::BinaryExpression>(ast::BinaryOp::kMultiply, lhs, rhs);
|
create<ast::BinaryExpression>(ast::BinaryOp::kMultiply, lhs, rhs);
|
||||||
|
WrapInFunction(expr);
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
|
@ -194,16 +182,13 @@ TEST_F(HlslGeneratorImplTest_Binary, Multiply_MatrixScalar) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(HlslGeneratorImplTest_Binary, Multiply_ScalarMatrix) {
|
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* lhs = Expr(1.f);
|
||||||
auto* rhs = Expr("mat");
|
auto* rhs = Expr("mat");
|
||||||
|
|
||||||
td.RegisterVariableForTesting(var);
|
|
||||||
|
|
||||||
auto* expr =
|
auto* expr =
|
||||||
create<ast::BinaryExpression>(ast::BinaryOp::kMultiply, lhs, rhs);
|
create<ast::BinaryExpression>(ast::BinaryOp::kMultiply, lhs, rhs);
|
||||||
|
WrapInFunction(expr);
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
|
@ -212,16 +197,13 @@ TEST_F(HlslGeneratorImplTest_Binary, Multiply_ScalarMatrix) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(HlslGeneratorImplTest_Binary, Multiply_MatrixVector) {
|
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* lhs = Expr("mat");
|
||||||
auto* rhs = vec3<f32>(1.f, 1.f, 1.f);
|
auto* rhs = vec3<f32>(1.f, 1.f, 1.f);
|
||||||
|
|
||||||
td.RegisterVariableForTesting(var);
|
|
||||||
|
|
||||||
auto* expr =
|
auto* expr =
|
||||||
create<ast::BinaryExpression>(ast::BinaryOp::kMultiply, lhs, rhs);
|
create<ast::BinaryExpression>(ast::BinaryOp::kMultiply, lhs, rhs);
|
||||||
|
WrapInFunction(expr);
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
|
@ -230,16 +212,13 @@ TEST_F(HlslGeneratorImplTest_Binary, Multiply_MatrixVector) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(HlslGeneratorImplTest_Binary, Multiply_VectorMatrix) {
|
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* lhs = vec3<f32>(1.f, 1.f, 1.f);
|
||||||
auto* rhs = Expr("mat");
|
auto* rhs = Expr("mat");
|
||||||
|
|
||||||
td.RegisterVariableForTesting(var);
|
|
||||||
|
|
||||||
auto* expr =
|
auto* expr =
|
||||||
create<ast::BinaryExpression>(ast::BinaryOp::kMultiply, lhs, rhs);
|
create<ast::BinaryExpression>(ast::BinaryOp::kMultiply, lhs, rhs);
|
||||||
|
WrapInFunction(expr);
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
|
@ -248,16 +227,13 @@ TEST_F(HlslGeneratorImplTest_Binary, Multiply_VectorMatrix) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(HlslGeneratorImplTest_Binary, Multiply_MatrixMatrix) {
|
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* lhs = Expr("mat");
|
||||||
auto* rhs = Expr("mat");
|
auto* rhs = Expr("mat");
|
||||||
|
|
||||||
td.RegisterVariableForTesting(var);
|
|
||||||
|
|
||||||
auto* expr =
|
auto* expr =
|
||||||
create<ast::BinaryExpression>(ast::BinaryOp::kMultiply, lhs, rhs);
|
create<ast::BinaryExpression>(ast::BinaryOp::kMultiply, lhs, rhs);
|
||||||
|
WrapInFunction(expr);
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
|
|
|
@ -44,22 +44,16 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
|
||||||
// int bar : TEXCOORD1;
|
// int bar : TEXCOORD1;
|
||||||
// };
|
// };
|
||||||
|
|
||||||
auto* foo_var = Var("foo", ast::StorageClass::kInput, ty.f32(), nullptr,
|
Global("foo", ast::StorageClass::kInput, ty.f32(), nullptr,
|
||||||
ast::VariableDecorationList{
|
ast::VariableDecorationList{
|
||||||
create<ast::LocationDecoration>(0),
|
create<ast::LocationDecoration>(0),
|
||||||
});
|
});
|
||||||
|
|
||||||
auto* bar_var = Var("bar", ast::StorageClass::kInput, ty.i32(), nullptr,
|
Global("bar", ast::StorageClass::kInput, ty.i32(), nullptr,
|
||||||
ast::VariableDecorationList{
|
ast::VariableDecorationList{
|
||||||
create<ast::LocationDecoration>(1),
|
create<ast::LocationDecoration>(1),
|
||||||
});
|
});
|
||||||
|
|
||||||
td.RegisterVariableForTesting(foo_var);
|
|
||||||
td.RegisterVariableForTesting(bar_var);
|
|
||||||
|
|
||||||
AST().AddGlobalVariable(foo_var);
|
|
||||||
AST().AddGlobalVariable(bar_var);
|
|
||||||
|
|
||||||
Func("vtx_main", ast::VariableList{}, ty.f32(),
|
Func("vtx_main", ast::VariableList{}, ty.f32(),
|
||||||
ast::StatementList{
|
ast::StatementList{
|
||||||
create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")),
|
create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")),
|
||||||
|
@ -93,22 +87,16 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
|
||||||
// int bar : TEXCOORD1;
|
// int bar : TEXCOORD1;
|
||||||
// };
|
// };
|
||||||
|
|
||||||
auto* foo_var = Var("foo", ast::StorageClass::kOutput, ty.f32(), nullptr,
|
Global("foo", ast::StorageClass::kOutput, ty.f32(), nullptr,
|
||||||
ast::VariableDecorationList{
|
ast::VariableDecorationList{
|
||||||
create<ast::LocationDecoration>(0),
|
create<ast::LocationDecoration>(0),
|
||||||
});
|
});
|
||||||
|
|
||||||
auto* bar_var = Var("bar", ast::StorageClass::kOutput, ty.i32(), nullptr,
|
Global("bar", ast::StorageClass::kOutput, ty.i32(), nullptr,
|
||||||
ast::VariableDecorationList{
|
ast::VariableDecorationList{
|
||||||
create<ast::LocationDecoration>(1),
|
create<ast::LocationDecoration>(1),
|
||||||
});
|
});
|
||||||
|
|
||||||
td.RegisterVariableForTesting(foo_var);
|
|
||||||
td.RegisterVariableForTesting(bar_var);
|
|
||||||
|
|
||||||
AST().AddGlobalVariable(foo_var);
|
|
||||||
AST().AddGlobalVariable(bar_var);
|
|
||||||
|
|
||||||
Func("vtx_main", ast::VariableList{}, ty.f32(),
|
Func("vtx_main", ast::VariableList{}, ty.f32(),
|
||||||
ast::StatementList{
|
ast::StatementList{
|
||||||
create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")),
|
create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")),
|
||||||
|
@ -142,22 +130,16 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
|
||||||
// int bar : TEXCOORD1;
|
// int bar : TEXCOORD1;
|
||||||
// };
|
// };
|
||||||
|
|
||||||
auto* foo_var = Var("foo", ast::StorageClass::kInput, ty.f32(), nullptr,
|
Global("foo", ast::StorageClass::kInput, ty.f32(), nullptr,
|
||||||
ast::VariableDecorationList{
|
ast::VariableDecorationList{
|
||||||
create<ast::LocationDecoration>(0),
|
create<ast::LocationDecoration>(0),
|
||||||
});
|
});
|
||||||
|
|
||||||
auto* bar_var = Var("bar", ast::StorageClass::kInput, ty.i32(), nullptr,
|
Global("bar", ast::StorageClass::kInput, ty.i32(), nullptr,
|
||||||
ast::VariableDecorationList{
|
ast::VariableDecorationList{
|
||||||
create<ast::LocationDecoration>(1),
|
create<ast::LocationDecoration>(1),
|
||||||
});
|
});
|
||||||
|
|
||||||
td.RegisterVariableForTesting(foo_var);
|
|
||||||
td.RegisterVariableForTesting(bar_var);
|
|
||||||
|
|
||||||
AST().AddGlobalVariable(foo_var);
|
|
||||||
AST().AddGlobalVariable(bar_var);
|
|
||||||
|
|
||||||
Func("main", ast::VariableList{}, ty.f32(),
|
Func("main", ast::VariableList{}, ty.f32(),
|
||||||
ast::StatementList{
|
ast::StatementList{
|
||||||
create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")),
|
create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")),
|
||||||
|
@ -191,22 +173,16 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
|
||||||
// int bar : SV_Target1;
|
// int bar : SV_Target1;
|
||||||
// };
|
// };
|
||||||
|
|
||||||
auto* foo_var = Var("foo", ast::StorageClass::kOutput, ty.f32(), nullptr,
|
Global("foo", ast::StorageClass::kOutput, ty.f32(), nullptr,
|
||||||
ast::VariableDecorationList{
|
ast::VariableDecorationList{
|
||||||
create<ast::LocationDecoration>(0),
|
create<ast::LocationDecoration>(0),
|
||||||
});
|
});
|
||||||
|
|
||||||
auto* bar_var = Var("bar", ast::StorageClass::kOutput, ty.i32(), nullptr,
|
Global("bar", ast::StorageClass::kOutput, ty.i32(), nullptr,
|
||||||
ast::VariableDecorationList{
|
ast::VariableDecorationList{
|
||||||
create<ast::LocationDecoration>(1),
|
create<ast::LocationDecoration>(1),
|
||||||
});
|
});
|
||||||
|
|
||||||
td.RegisterVariableForTesting(foo_var);
|
|
||||||
td.RegisterVariableForTesting(bar_var);
|
|
||||||
|
|
||||||
AST().AddGlobalVariable(foo_var);
|
|
||||||
AST().AddGlobalVariable(bar_var);
|
|
||||||
|
|
||||||
Func("main", ast::VariableList{}, ty.f32(),
|
Func("main", ast::VariableList{}, ty.f32(),
|
||||||
ast::StatementList{
|
ast::StatementList{
|
||||||
create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")),
|
create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")),
|
||||||
|
@ -237,22 +213,16 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
|
||||||
//
|
//
|
||||||
// -> Error, not allowed
|
// -> Error, not allowed
|
||||||
|
|
||||||
auto* foo_var = Var("foo", ast::StorageClass::kInput, ty.f32(), nullptr,
|
Global("foo", ast::StorageClass::kInput, ty.f32(), nullptr,
|
||||||
ast::VariableDecorationList{
|
ast::VariableDecorationList{
|
||||||
create<ast::LocationDecoration>(0),
|
create<ast::LocationDecoration>(0),
|
||||||
});
|
});
|
||||||
|
|
||||||
auto* bar_var = Var("bar", ast::StorageClass::kInput, ty.i32(), nullptr,
|
Global("bar", ast::StorageClass::kInput, ty.i32(), nullptr,
|
||||||
ast::VariableDecorationList{
|
ast::VariableDecorationList{
|
||||||
create<ast::LocationDecoration>(1),
|
create<ast::LocationDecoration>(1),
|
||||||
});
|
});
|
||||||
|
|
||||||
td.RegisterVariableForTesting(foo_var);
|
|
||||||
td.RegisterVariableForTesting(bar_var);
|
|
||||||
|
|
||||||
AST().AddGlobalVariable(foo_var);
|
|
||||||
AST().AddGlobalVariable(bar_var);
|
|
||||||
|
|
||||||
Func("main", ast::VariableList{}, ty.f32(),
|
Func("main", ast::VariableList{}, ty.f32(),
|
||||||
ast::StatementList{
|
ast::StatementList{
|
||||||
create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")),
|
create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")),
|
||||||
|
@ -278,22 +248,16 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
|
||||||
//
|
//
|
||||||
// -> Error not allowed
|
// -> Error not allowed
|
||||||
|
|
||||||
auto* foo_var = Var("foo", ast::StorageClass::kOutput, ty.f32(), nullptr,
|
Global("foo", ast::StorageClass::kOutput, ty.f32(), nullptr,
|
||||||
ast::VariableDecorationList{
|
ast::VariableDecorationList{
|
||||||
create<ast::LocationDecoration>(0),
|
create<ast::LocationDecoration>(0),
|
||||||
});
|
});
|
||||||
|
|
||||||
auto* bar_var = Var("bar", ast::StorageClass::kOutput, ty.i32(), nullptr,
|
Global("bar", ast::StorageClass::kOutput, ty.i32(), nullptr,
|
||||||
ast::VariableDecorationList{
|
ast::VariableDecorationList{
|
||||||
create<ast::LocationDecoration>(1),
|
create<ast::LocationDecoration>(1),
|
||||||
});
|
});
|
||||||
|
|
||||||
td.RegisterVariableForTesting(foo_var);
|
|
||||||
td.RegisterVariableForTesting(bar_var);
|
|
||||||
|
|
||||||
AST().AddGlobalVariable(foo_var);
|
|
||||||
AST().AddGlobalVariable(bar_var);
|
|
||||||
|
|
||||||
Func("main", ast::VariableList{}, ty.f32(),
|
Func("main", ast::VariableList{}, ty.f32(),
|
||||||
ast::StatementList{
|
ast::StatementList{
|
||||||
create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")),
|
create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")),
|
||||||
|
@ -325,24 +289,16 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
|
||||||
// float depth : SV_Depth;
|
// float depth : SV_Depth;
|
||||||
// };
|
// };
|
||||||
|
|
||||||
auto* coord_var =
|
Global("coord", ast::StorageClass::kInput, ty.vec4<f32>(), nullptr,
|
||||||
Var("coord", ast::StorageClass::kInput, ty.vec4<f32>(), nullptr,
|
|
||||||
ast::VariableDecorationList{
|
ast::VariableDecorationList{
|
||||||
create<ast::BuiltinDecoration>(ast::Builtin::kFragCoord),
|
create<ast::BuiltinDecoration>(ast::Builtin::kFragCoord),
|
||||||
});
|
});
|
||||||
|
|
||||||
auto* depth_var =
|
Global("depth", ast::StorageClass::kOutput, ty.f32(), nullptr,
|
||||||
Var("depth", ast::StorageClass::kOutput, ty.f32(), nullptr,
|
|
||||||
ast::VariableDecorationList{
|
ast::VariableDecorationList{
|
||||||
create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth),
|
create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth),
|
||||||
});
|
});
|
||||||
|
|
||||||
td.RegisterVariableForTesting(coord_var);
|
|
||||||
td.RegisterVariableForTesting(depth_var);
|
|
||||||
|
|
||||||
AST().AddGlobalVariable(coord_var);
|
|
||||||
AST().AddGlobalVariable(depth_var);
|
|
||||||
|
|
||||||
Func("main", ast::VariableList{}, ty.void_(),
|
Func("main", ast::VariableList{}, ty.void_(),
|
||||||
ast::StatementList{
|
ast::StatementList{
|
||||||
create<ast::AssignmentStatement>(Expr("depth"),
|
create<ast::AssignmentStatement>(Expr("depth"),
|
||||||
|
|
|
@ -132,22 +132,16 @@ TEST_F(HlslGeneratorImplTest_Function,
|
||||||
|
|
||||||
TEST_F(HlslGeneratorImplTest_Function,
|
TEST_F(HlslGeneratorImplTest_Function,
|
||||||
Emit_FunctionDecoration_EntryPoint_NoReturn_InOut) {
|
Emit_FunctionDecoration_EntryPoint_NoReturn_InOut) {
|
||||||
auto* foo_var = Var("foo", ast::StorageClass::kInput, ty.f32(), nullptr,
|
Global("foo", ast::StorageClass::kInput, ty.f32(), nullptr,
|
||||||
ast::VariableDecorationList{
|
ast::VariableDecorationList{
|
||||||
create<ast::LocationDecoration>(0),
|
create<ast::LocationDecoration>(0),
|
||||||
});
|
});
|
||||||
|
|
||||||
auto* bar_var = Var("bar", ast::StorageClass::kOutput, ty.f32(), nullptr,
|
Global("bar", ast::StorageClass::kOutput, ty.f32(), nullptr,
|
||||||
ast::VariableDecorationList{
|
ast::VariableDecorationList{
|
||||||
create<ast::LocationDecoration>(1),
|
create<ast::LocationDecoration>(1),
|
||||||
});
|
});
|
||||||
|
|
||||||
td.RegisterVariableForTesting(foo_var);
|
|
||||||
td.RegisterVariableForTesting(bar_var);
|
|
||||||
|
|
||||||
AST().AddGlobalVariable(foo_var);
|
|
||||||
AST().AddGlobalVariable(bar_var);
|
|
||||||
|
|
||||||
Func("main", ast::VariableList{}, ty.void_(),
|
Func("main", ast::VariableList{}, ty.void_(),
|
||||||
ast::StatementList{
|
ast::StatementList{
|
||||||
create<ast::AssignmentStatement>(Expr("bar"), Expr("foo")),
|
create<ast::AssignmentStatement>(Expr("bar"), Expr("foo")),
|
||||||
|
@ -178,22 +172,16 @@ main_out main(main_in tint_in) {
|
||||||
|
|
||||||
TEST_F(HlslGeneratorImplTest_Function,
|
TEST_F(HlslGeneratorImplTest_Function,
|
||||||
Emit_FunctionDecoration_EntryPoint_WithInOutVars) {
|
Emit_FunctionDecoration_EntryPoint_WithInOutVars) {
|
||||||
auto* foo_var = Var("foo", ast::StorageClass::kInput, ty.f32(), nullptr,
|
Global("foo", ast::StorageClass::kInput, ty.f32(), nullptr,
|
||||||
ast::VariableDecorationList{
|
ast::VariableDecorationList{
|
||||||
create<ast::LocationDecoration>(0),
|
create<ast::LocationDecoration>(0),
|
||||||
});
|
});
|
||||||
|
|
||||||
auto* bar_var = Var("bar", ast::StorageClass::kOutput, ty.f32(), nullptr,
|
Global("bar", ast::StorageClass::kOutput, ty.f32(), nullptr,
|
||||||
ast::VariableDecorationList{
|
ast::VariableDecorationList{
|
||||||
create<ast::LocationDecoration>(1),
|
create<ast::LocationDecoration>(1),
|
||||||
});
|
});
|
||||||
|
|
||||||
td.RegisterVariableForTesting(foo_var);
|
|
||||||
td.RegisterVariableForTesting(bar_var);
|
|
||||||
|
|
||||||
AST().AddGlobalVariable(foo_var);
|
|
||||||
AST().AddGlobalVariable(bar_var);
|
|
||||||
|
|
||||||
Func("frag_main", ast::VariableList{}, ty.void_(),
|
Func("frag_main", ast::VariableList{}, ty.void_(),
|
||||||
ast::StatementList{
|
ast::StatementList{
|
||||||
create<ast::AssignmentStatement>(Expr("bar"), Expr("foo")),
|
create<ast::AssignmentStatement>(Expr("bar"), Expr("foo")),
|
||||||
|
@ -225,24 +213,16 @@ frag_main_out frag_main(frag_main_in tint_in) {
|
||||||
|
|
||||||
TEST_F(HlslGeneratorImplTest_Function,
|
TEST_F(HlslGeneratorImplTest_Function,
|
||||||
Emit_FunctionDecoration_EntryPoint_WithInOut_Builtins) {
|
Emit_FunctionDecoration_EntryPoint_WithInOut_Builtins) {
|
||||||
auto* coord_var =
|
Global("coord", ast::StorageClass::kInput, ty.vec4<f32>(), nullptr,
|
||||||
Var("coord", ast::StorageClass::kInput, ty.vec4<f32>(), nullptr,
|
|
||||||
ast::VariableDecorationList{
|
ast::VariableDecorationList{
|
||||||
create<ast::BuiltinDecoration>(ast::Builtin::kFragCoord),
|
create<ast::BuiltinDecoration>(ast::Builtin::kFragCoord),
|
||||||
});
|
});
|
||||||
|
|
||||||
auto* depth_var =
|
Global("depth", ast::StorageClass::kOutput, ty.f32(), nullptr,
|
||||||
Var("depth", ast::StorageClass::kOutput, ty.f32(), nullptr,
|
|
||||||
ast::VariableDecorationList{
|
ast::VariableDecorationList{
|
||||||
create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth),
|
create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth),
|
||||||
});
|
});
|
||||||
|
|
||||||
td.RegisterVariableForTesting(coord_var);
|
|
||||||
td.RegisterVariableForTesting(depth_var);
|
|
||||||
|
|
||||||
AST().AddGlobalVariable(coord_var);
|
|
||||||
AST().AddGlobalVariable(depth_var);
|
|
||||||
|
|
||||||
Func("frag_main", ast::VariableList{}, ty.void_(),
|
Func("frag_main", ast::VariableList{}, ty.void_(),
|
||||||
ast::StatementList{
|
ast::StatementList{
|
||||||
create<ast::AssignmentStatement>(Expr("depth"),
|
create<ast::AssignmentStatement>(Expr("depth"),
|
||||||
|
@ -275,16 +255,12 @@ frag_main_out frag_main(frag_main_in tint_in) {
|
||||||
|
|
||||||
TEST_F(HlslGeneratorImplTest_Function,
|
TEST_F(HlslGeneratorImplTest_Function,
|
||||||
Emit_FunctionDecoration_EntryPoint_With_Uniform) {
|
Emit_FunctionDecoration_EntryPoint_With_Uniform) {
|
||||||
auto* coord_var =
|
Global("coord", ast::StorageClass::kUniform, ty.vec4<f32>(), nullptr,
|
||||||
Var("coord", ast::StorageClass::kUniform, ty.vec4<f32>(), nullptr,
|
|
||||||
ast::VariableDecorationList{
|
ast::VariableDecorationList{
|
||||||
create<ast::BindingDecoration>(0),
|
create<ast::BindingDecoration>(0),
|
||||||
create<ast::GroupDecoration>(1),
|
create<ast::GroupDecoration>(1),
|
||||||
});
|
});
|
||||||
|
|
||||||
td.RegisterVariableForTesting(coord_var);
|
|
||||||
AST().AddGlobalVariable(coord_var);
|
|
||||||
|
|
||||||
auto* var = Var("v", ast::StorageClass::kFunction, ty.f32(),
|
auto* var = Var("v", ast::StorageClass::kFunction, ty.f32(),
|
||||||
MemberAccessor("coord", "x"), ast::VariableDecorationList{});
|
MemberAccessor("coord", "x"), ast::VariableDecorationList{});
|
||||||
|
|
||||||
|
@ -320,7 +296,7 @@ TEST_F(HlslGeneratorImplTest_Function,
|
||||||
|
|
||||||
auto* s = ty.struct_("Uniforms", str);
|
auto* s = ty.struct_("Uniforms", str);
|
||||||
|
|
||||||
auto* coord_var = Var("uniforms", ast::StorageClass::kUniform, s, nullptr,
|
Global("uniforms", ast::StorageClass::kUniform, s, nullptr,
|
||||||
ast::VariableDecorationList{
|
ast::VariableDecorationList{
|
||||||
create<ast::BindingDecoration>(0),
|
create<ast::BindingDecoration>(0),
|
||||||
create<ast::GroupDecoration>(1),
|
create<ast::GroupDecoration>(1),
|
||||||
|
@ -328,9 +304,6 @@ TEST_F(HlslGeneratorImplTest_Function,
|
||||||
|
|
||||||
AST().AddConstructedType(s);
|
AST().AddConstructedType(s);
|
||||||
|
|
||||||
td.RegisterVariableForTesting(coord_var);
|
|
||||||
AST().AddGlobalVariable(coord_var);
|
|
||||||
|
|
||||||
auto* var = Var("v", ast::StorageClass::kFunction, ty.f32(),
|
auto* var = Var("v", ast::StorageClass::kFunction, ty.f32(),
|
||||||
create<ast::MemberAccessorExpression>(
|
create<ast::MemberAccessorExpression>(
|
||||||
MemberAccessor("uniforms", "coord"), Expr("x")),
|
MemberAccessor("uniforms", "coord"), Expr("x")),
|
||||||
|
@ -372,15 +345,12 @@ TEST_F(HlslGeneratorImplTest_Function,
|
||||||
auto* s = ty.struct_("Data", str);
|
auto* s = ty.struct_("Data", str);
|
||||||
type::AccessControl ac(ast::AccessControl::kReadWrite, s);
|
type::AccessControl ac(ast::AccessControl::kReadWrite, s);
|
||||||
|
|
||||||
auto* coord_var = Var("coord", ast::StorageClass::kStorage, &ac, nullptr,
|
Global("coord", ast::StorageClass::kStorage, &ac, nullptr,
|
||||||
ast::VariableDecorationList{
|
ast::VariableDecorationList{
|
||||||
create<ast::BindingDecoration>(0),
|
create<ast::BindingDecoration>(0),
|
||||||
create<ast::GroupDecoration>(1),
|
create<ast::GroupDecoration>(1),
|
||||||
});
|
});
|
||||||
|
|
||||||
td.RegisterVariableForTesting(coord_var);
|
|
||||||
AST().AddGlobalVariable(coord_var);
|
|
||||||
|
|
||||||
auto* var = Var("v", ast::StorageClass::kFunction, ty.f32(),
|
auto* var = Var("v", ast::StorageClass::kFunction, ty.f32(),
|
||||||
MemberAccessor("coord", "b"), ast::VariableDecorationList{});
|
MemberAccessor("coord", "b"), ast::VariableDecorationList{});
|
||||||
|
|
||||||
|
@ -416,16 +386,12 @@ TEST_F(HlslGeneratorImplTest_Function,
|
||||||
auto* s = ty.struct_("Data", str);
|
auto* s = ty.struct_("Data", str);
|
||||||
type::AccessControl ac(ast::AccessControl::kReadOnly, s);
|
type::AccessControl ac(ast::AccessControl::kReadOnly, s);
|
||||||
|
|
||||||
auto* coord_var = Var("coord", ast::StorageClass::kStorage, &ac, nullptr,
|
Global("coord", ast::StorageClass::kStorage, &ac, nullptr,
|
||||||
ast::VariableDecorationList{
|
ast::VariableDecorationList{
|
||||||
// decorations
|
|
||||||
create<ast::BindingDecoration>(0),
|
create<ast::BindingDecoration>(0),
|
||||||
create<ast::GroupDecoration>(1),
|
create<ast::GroupDecoration>(1),
|
||||||
});
|
});
|
||||||
|
|
||||||
td.RegisterVariableForTesting(coord_var);
|
|
||||||
AST().AddGlobalVariable(coord_var);
|
|
||||||
|
|
||||||
auto* var = Var("v", ast::StorageClass::kFunction, ty.f32(),
|
auto* var = Var("v", ast::StorageClass::kFunction, ty.f32(),
|
||||||
MemberAccessor("coord", "b"), ast::VariableDecorationList{});
|
MemberAccessor("coord", "b"), ast::VariableDecorationList{});
|
||||||
|
|
||||||
|
@ -461,15 +427,12 @@ TEST_F(HlslGeneratorImplTest_Function,
|
||||||
auto* s = ty.struct_("Data", str);
|
auto* s = ty.struct_("Data", str);
|
||||||
type::AccessControl ac(ast::AccessControl::kReadWrite, s);
|
type::AccessControl ac(ast::AccessControl::kReadWrite, s);
|
||||||
|
|
||||||
auto* coord_var = Var("coord", ast::StorageClass::kStorage, &ac, nullptr,
|
Global("coord", ast::StorageClass::kStorage, &ac, nullptr,
|
||||||
ast::VariableDecorationList{
|
ast::VariableDecorationList{
|
||||||
create<ast::BindingDecoration>(0),
|
create<ast::BindingDecoration>(0),
|
||||||
create<ast::GroupDecoration>(1),
|
create<ast::GroupDecoration>(1),
|
||||||
});
|
});
|
||||||
|
|
||||||
td.RegisterVariableForTesting(coord_var);
|
|
||||||
AST().AddGlobalVariable(coord_var);
|
|
||||||
|
|
||||||
Func("frag_main", ast::VariableList{}, ty.void_(),
|
Func("frag_main", ast::VariableList{}, ty.void_(),
|
||||||
ast::StatementList{
|
ast::StatementList{
|
||||||
create<ast::AssignmentStatement>(MemberAccessor("coord", "b"),
|
create<ast::AssignmentStatement>(MemberAccessor("coord", "b"),
|
||||||
|
@ -496,29 +459,21 @@ void frag_main() {
|
||||||
TEST_F(
|
TEST_F(
|
||||||
HlslGeneratorImplTest_Function,
|
HlslGeneratorImplTest_Function,
|
||||||
Emit_FunctionDecoration_Called_By_EntryPoints_WithLocationGlobals_And_Params) { // NOLINT
|
Emit_FunctionDecoration_Called_By_EntryPoints_WithLocationGlobals_And_Params) { // NOLINT
|
||||||
auto* foo_var = Var("foo", ast::StorageClass::kInput, ty.f32(), nullptr,
|
Global("foo", ast::StorageClass::kInput, ty.f32(), nullptr,
|
||||||
ast::VariableDecorationList{
|
ast::VariableDecorationList{
|
||||||
create<ast::LocationDecoration>(0),
|
create<ast::LocationDecoration>(0),
|
||||||
});
|
});
|
||||||
|
|
||||||
auto* bar_var = Var("bar", ast::StorageClass::kOutput, ty.f32(), nullptr,
|
Global("bar", ast::StorageClass::kOutput, ty.f32(), nullptr,
|
||||||
ast::VariableDecorationList{
|
ast::VariableDecorationList{
|
||||||
create<ast::LocationDecoration>(1),
|
create<ast::LocationDecoration>(1),
|
||||||
});
|
});
|
||||||
|
|
||||||
auto* val_var = Var("val", ast::StorageClass::kOutput, ty.f32(), nullptr,
|
Global("val", ast::StorageClass::kOutput, ty.f32(), nullptr,
|
||||||
ast::VariableDecorationList{
|
ast::VariableDecorationList{
|
||||||
create<ast::LocationDecoration>(0),
|
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);
|
|
||||||
|
|
||||||
Func("sub_func",
|
Func("sub_func",
|
||||||
ast::VariableList{Var("param", ast::StorageClass::kFunction, ty.f32())},
|
ast::VariableList{Var("param", ast::StorageClass::kFunction, ty.f32())},
|
||||||
ty.f32(),
|
ty.f32(),
|
||||||
|
@ -568,16 +523,11 @@ ep_1_out ep_1(ep_1_in tint_in) {
|
||||||
|
|
||||||
TEST_F(HlslGeneratorImplTest_Function,
|
TEST_F(HlslGeneratorImplTest_Function,
|
||||||
Emit_FunctionDecoration_Called_By_EntryPoints_NoUsedGlobals) {
|
Emit_FunctionDecoration_Called_By_EntryPoints_NoUsedGlobals) {
|
||||||
auto* depth_var =
|
Global("depth", ast::StorageClass::kOutput, ty.f32(), nullptr,
|
||||||
Var("depth", ast::StorageClass::kOutput, ty.f32(), nullptr,
|
|
||||||
ast::VariableDecorationList{
|
ast::VariableDecorationList{
|
||||||
create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth),
|
create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth),
|
||||||
});
|
});
|
||||||
|
|
||||||
td.RegisterVariableForTesting(depth_var);
|
|
||||||
|
|
||||||
AST().AddGlobalVariable(depth_var);
|
|
||||||
|
|
||||||
Func("sub_func",
|
Func("sub_func",
|
||||||
ast::VariableList{Var("param", ast::StorageClass::kFunction, ty.f32())},
|
ast::VariableList{Var("param", ast::StorageClass::kFunction, ty.f32())},
|
||||||
ty.f32(),
|
ty.f32(),
|
||||||
|
@ -619,24 +569,16 @@ ep_1_out ep_1() {
|
||||||
TEST_F(
|
TEST_F(
|
||||||
HlslGeneratorImplTest_Function,
|
HlslGeneratorImplTest_Function,
|
||||||
Emit_FunctionDecoration_Called_By_EntryPoints_WithBuiltinGlobals_And_Params) { // NOLINT
|
Emit_FunctionDecoration_Called_By_EntryPoints_WithBuiltinGlobals_And_Params) { // NOLINT
|
||||||
auto* coord_var =
|
Global("coord", ast::StorageClass::kInput, ty.vec4<f32>(), nullptr,
|
||||||
Var("coord", ast::StorageClass::kInput, ty.vec4<f32>(), nullptr,
|
|
||||||
ast::VariableDecorationList{
|
ast::VariableDecorationList{
|
||||||
create<ast::BuiltinDecoration>(ast::Builtin::kFragCoord),
|
create<ast::BuiltinDecoration>(ast::Builtin::kFragCoord),
|
||||||
});
|
});
|
||||||
|
|
||||||
auto* depth_var =
|
Global("depth", ast::StorageClass::kOutput, ty.f32(), nullptr,
|
||||||
Var("depth", ast::StorageClass::kOutput, ty.f32(), nullptr,
|
|
||||||
ast::VariableDecorationList{
|
ast::VariableDecorationList{
|
||||||
create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth),
|
create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth),
|
||||||
});
|
});
|
||||||
|
|
||||||
td.RegisterVariableForTesting(coord_var);
|
|
||||||
td.RegisterVariableForTesting(depth_var);
|
|
||||||
|
|
||||||
AST().AddGlobalVariable(coord_var);
|
|
||||||
AST().AddGlobalVariable(depth_var);
|
|
||||||
|
|
||||||
Func("sub_func",
|
Func("sub_func",
|
||||||
ast::VariableList{Var("param", ast::StorageClass::kFunction, ty.f32())},
|
ast::VariableList{Var("param", ast::StorageClass::kFunction, ty.f32())},
|
||||||
ty.f32(),
|
ty.f32(),
|
||||||
|
@ -684,17 +626,12 @@ ep_1_out ep_1(ep_1_in tint_in) {
|
||||||
|
|
||||||
TEST_F(HlslGeneratorImplTest_Function,
|
TEST_F(HlslGeneratorImplTest_Function,
|
||||||
Emit_FunctionDecoration_Called_By_EntryPoint_With_Uniform) {
|
Emit_FunctionDecoration_Called_By_EntryPoint_With_Uniform) {
|
||||||
auto* coord_var =
|
Global("coord", ast::StorageClass::kUniform, ty.vec4<f32>(), nullptr,
|
||||||
Var("coord", ast::StorageClass::kUniform, ty.vec4<f32>(), nullptr,
|
|
||||||
ast::VariableDecorationList{
|
ast::VariableDecorationList{
|
||||||
create<ast::BindingDecoration>(0),
|
create<ast::BindingDecoration>(0),
|
||||||
create<ast::GroupDecoration>(1),
|
create<ast::GroupDecoration>(1),
|
||||||
});
|
});
|
||||||
|
|
||||||
td.RegisterVariableForTesting(coord_var);
|
|
||||||
|
|
||||||
AST().AddGlobalVariable(coord_var);
|
|
||||||
|
|
||||||
Func("sub_func",
|
Func("sub_func",
|
||||||
ast::VariableList{Var("param", ast::StorageClass::kFunction, ty.f32())},
|
ast::VariableList{Var("param", ast::StorageClass::kFunction, ty.f32())},
|
||||||
ty.f32(),
|
ty.f32(),
|
||||||
|
@ -737,16 +674,12 @@ void frag_main() {
|
||||||
TEST_F(HlslGeneratorImplTest_Function,
|
TEST_F(HlslGeneratorImplTest_Function,
|
||||||
Emit_FunctionDecoration_Called_By_EntryPoint_With_StorageBuffer) {
|
Emit_FunctionDecoration_Called_By_EntryPoint_With_StorageBuffer) {
|
||||||
type::AccessControl ac(ast::AccessControl::kReadWrite, ty.vec4<f32>());
|
type::AccessControl ac(ast::AccessControl::kReadWrite, ty.vec4<f32>());
|
||||||
auto* coord_var = Var("coord", ast::StorageClass::kStorage, &ac, nullptr,
|
Global("coord", ast::StorageClass::kStorage, &ac, nullptr,
|
||||||
ast::VariableDecorationList{
|
ast::VariableDecorationList{
|
||||||
create<ast::BindingDecoration>(0),
|
create<ast::BindingDecoration>(0),
|
||||||
create<ast::GroupDecoration>(1),
|
create<ast::GroupDecoration>(1),
|
||||||
});
|
});
|
||||||
|
|
||||||
td.RegisterVariableForTesting(coord_var);
|
|
||||||
|
|
||||||
AST().AddGlobalVariable(coord_var);
|
|
||||||
|
|
||||||
Func("sub_func",
|
Func("sub_func",
|
||||||
ast::VariableList{Var("param", ast::StorageClass::kFunction, ty.f32())},
|
ast::VariableList{Var("param", ast::StorageClass::kFunction, ty.f32())},
|
||||||
ty.f32(),
|
ty.f32(),
|
||||||
|
@ -786,14 +719,11 @@ void frag_main() {
|
||||||
|
|
||||||
TEST_F(HlslGeneratorImplTest_Function,
|
TEST_F(HlslGeneratorImplTest_Function,
|
||||||
Emit_FunctionDecoration_EntryPoints_WithGlobal_Nested_Return) {
|
Emit_FunctionDecoration_EntryPoints_WithGlobal_Nested_Return) {
|
||||||
auto* bar_var = Var("bar", ast::StorageClass::kOutput, ty.f32(), nullptr,
|
Global("bar", ast::StorageClass::kOutput, ty.f32(), nullptr,
|
||||||
ast::VariableDecorationList{
|
ast::VariableDecorationList{
|
||||||
create<ast::LocationDecoration>(1),
|
create<ast::LocationDecoration>(1),
|
||||||
});
|
});
|
||||||
|
|
||||||
td.RegisterVariableForTesting(bar_var);
|
|
||||||
AST().AddGlobalVariable(bar_var);
|
|
||||||
|
|
||||||
auto* list = create<ast::BlockStatement>(ast::StatementList{
|
auto* list = create<ast::BlockStatement>(ast::StatementList{
|
||||||
create<ast::ReturnStatement>(),
|
create<ast::ReturnStatement>(),
|
||||||
});
|
});
|
||||||
|
@ -935,18 +865,16 @@ TEST_F(HlslGeneratorImplTest_Function,
|
||||||
ast::StructDecorationList{create<ast::StructBlockDecoration>()});
|
ast::StructDecorationList{create<ast::StructBlockDecoration>()});
|
||||||
|
|
||||||
auto* s = ty.struct_("Data", str);
|
auto* s = ty.struct_("Data", str);
|
||||||
|
AST().AddConstructedType(s);
|
||||||
|
|
||||||
type::AccessControl ac(ast::AccessControl::kReadWrite, s);
|
type::AccessControl ac(ast::AccessControl::kReadWrite, s);
|
||||||
|
|
||||||
auto* data_var = Var("data", ast::StorageClass::kStorage, &ac, nullptr,
|
Global("data", ast::StorageClass::kStorage, &ac, nullptr,
|
||||||
ast::VariableDecorationList{
|
ast::VariableDecorationList{
|
||||||
create<ast::BindingDecoration>(0),
|
create<ast::BindingDecoration>(0),
|
||||||
create<ast::GroupDecoration>(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(),
|
auto* var = Var("v", ast::StorageClass::kFunction, ty.f32(),
|
||||||
MemberAccessor("data", "d"), ast::VariableDecorationList{});
|
MemberAccessor("data", "d"), ast::VariableDecorationList{});
|
||||||
|
|
|
@ -52,8 +52,7 @@ TEST_P(HlslImportData_SingleParamTest, FloatScalar) {
|
||||||
|
|
||||||
auto* ident = Expr(param.name);
|
auto* ident = Expr(param.name);
|
||||||
auto* expr = Call(ident, 1.f);
|
auto* expr = Call(ident, 1.f);
|
||||||
|
WrapInFunction(expr);
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
|
@ -93,8 +92,7 @@ TEST_P(HlslImportData_SingleIntParamTest, IntScalar) {
|
||||||
auto param = GetParam();
|
auto param = GetParam();
|
||||||
|
|
||||||
auto* expr = Call(param.name, Expr(1));
|
auto* expr = Call(param.name, Expr(1));
|
||||||
|
WrapInFunction(expr);
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
|
@ -110,8 +108,7 @@ TEST_P(HlslImportData_DualParamTest, FloatScalar) {
|
||||||
auto param = GetParam();
|
auto param = GetParam();
|
||||||
|
|
||||||
auto* expr = Call(param.name, 1.f, 2.f);
|
auto* expr = Call(param.name, 1.f, 2.f);
|
||||||
|
WrapInFunction(expr);
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
|
@ -134,8 +131,7 @@ TEST_P(HlslImportData_DualParam_VectorTest, FloatVector) {
|
||||||
|
|
||||||
auto* expr =
|
auto* expr =
|
||||||
Call(param.name, vec3<f32>(1.f, 2.f, 3.f), vec3<f32>(4.f, 5.f, 6.f));
|
Call(param.name, vec3<f32>(1.f, 2.f, 3.f), vec3<f32>(4.f, 5.f, 6.f));
|
||||||
|
WrapInFunction(expr);
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
|
@ -153,8 +149,7 @@ TEST_P(HlslImportData_DualParam_Int_Test, IntScalar) {
|
||||||
auto param = GetParam();
|
auto param = GetParam();
|
||||||
|
|
||||||
auto* expr = Call(param.name, 1, 2);
|
auto* expr = Call(param.name, 1, 2);
|
||||||
|
WrapInFunction(expr);
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
|
@ -171,8 +166,7 @@ TEST_P(HlslImportData_TripleParamTest, FloatScalar) {
|
||||||
auto param = GetParam();
|
auto param = GetParam();
|
||||||
|
|
||||||
auto* expr = Call(param.name, 1.f, 2.f, 3.f);
|
auto* expr = Call(param.name, 1.f, 2.f, 3.f);
|
||||||
|
WrapInFunction(expr);
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
|
@ -196,8 +190,7 @@ TEST_P(HlslImportData_TripleParam_Int_Test, IntScalar) {
|
||||||
auto param = GetParam();
|
auto param = GetParam();
|
||||||
|
|
||||||
auto* expr = Call(param.name, 1, 2, 3);
|
auto* expr = Call(param.name, 1, 2, 3);
|
||||||
|
WrapInFunction(expr);
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
|
@ -209,15 +202,10 @@ INSTANTIATE_TEST_SUITE_P(HlslGeneratorImplTest_Import,
|
||||||
testing::Values(HlslImportData{"clamp", "clamp"}));
|
testing::Values(HlslImportData{"clamp", "clamp"}));
|
||||||
|
|
||||||
TEST_F(HlslGeneratorImplTest_Import, HlslImportData_Determinant) {
|
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");
|
auto* expr = Call("determinant", "var");
|
||||||
|
WrapInFunction(expr);
|
||||||
AST().AddGlobalVariable(var);
|
|
||||||
|
|
||||||
// Register the global
|
|
||||||
ASSERT_TRUE(td.Determine()) << td.error();
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
|
|
|
@ -155,24 +155,17 @@ TEST_P(HlslIntrinsicTest, Emit) {
|
||||||
|
|
||||||
auto* call = GenerateCall(param.intrinsic, param.type, this);
|
auto* call = GenerateCall(param.intrinsic, param.type, this);
|
||||||
ASSERT_NE(nullptr, call) << "Unhandled intrinsic";
|
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();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
EXPECT_EQ(
|
EXPECT_EQ(
|
||||||
|
@ -261,13 +254,10 @@ TEST_F(HlslGeneratorImplTest_Intrinsic, DISABLED_Intrinsic_Select) {
|
||||||
TEST_F(HlslGeneratorImplTest_Intrinsic, Intrinsic_Call) {
|
TEST_F(HlslGeneratorImplTest_Intrinsic, Intrinsic_Call) {
|
||||||
auto* call = Call("dot", "param1", "param2");
|
auto* call = Call("dot", "param1", "param2");
|
||||||
|
|
||||||
auto* v1 = Var("param1", ast::StorageClass::kFunction, ty.vec3<f32>());
|
Global("param1", ast::StorageClass::kFunction, ty.vec3<f32>());
|
||||||
auto* v2 = Var("param2", ast::StorageClass::kFunction, ty.vec3<f32>());
|
Global("param2", ast::StorageClass::kFunction, ty.vec3<f32>());
|
||||||
|
|
||||||
td.RegisterVariableForTesting(v1);
|
WrapInFunction(call);
|
||||||
td.RegisterVariableForTesting(v2);
|
|
||||||
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(call)) << td.error();
|
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
|
|
|
@ -404,12 +404,7 @@ ExpectedResult expected_texture_overload(
|
||||||
} // NOLINT - Ignore the length of this function
|
} // NOLINT - Ignore the length of this function
|
||||||
|
|
||||||
class HlslGeneratorIntrinsicTextureTest
|
class HlslGeneratorIntrinsicTextureTest
|
||||||
: public TestParamHelper<ast::intrinsic::test::TextureOverloadCase> {
|
: public TestParamHelper<ast::intrinsic::test::TextureOverloadCase> {};
|
||||||
protected:
|
|
||||||
void OnVariableBuilt(ast::Variable* var) override {
|
|
||||||
td.RegisterVariableForTesting(var);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
TEST_P(HlslGeneratorIntrinsicTextureTest, Call) {
|
TEST_P(HlslGeneratorIntrinsicTextureTest, Call) {
|
||||||
auto param = GetParam();
|
auto param = GetParam();
|
||||||
|
@ -418,9 +413,7 @@ TEST_P(HlslGeneratorIntrinsicTextureTest, Call) {
|
||||||
param.buildSamplerVariable(this);
|
param.buildSamplerVariable(this);
|
||||||
|
|
||||||
auto* call = Call(param.function, param.args(this));
|
auto* call = Call(param.function, param.args(this));
|
||||||
|
WrapInFunction(call);
|
||||||
ASSERT_TRUE(td.Determine()) << td.error();
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(call)) << td.error();
|
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
|
|
|
@ -45,13 +45,10 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor, EmitExpression_MemberAccessor) {
|
||||||
ast::StructDecorationList{});
|
ast::StructDecorationList{});
|
||||||
|
|
||||||
auto* s = ty.struct_("Str", strct);
|
auto* s = ty.struct_("Str", strct);
|
||||||
auto* str_var = Var("str", ast::StorageClass::kPrivate, s);
|
auto* str_var = Global("str", ast::StorageClass::kPrivate, s);
|
||||||
AST().AddGlobalVariable(str_var);
|
|
||||||
|
|
||||||
auto* expr = MemberAccessor("str", "mem");
|
auto* expr = MemberAccessor("str", "mem");
|
||||||
|
WrapInFunction(expr);
|
||||||
td.RegisterVariableForTesting(str_var);
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
|
@ -78,14 +75,10 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
||||||
ast::StructDecorationList{});
|
ast::StructDecorationList{});
|
||||||
|
|
||||||
auto* s = ty.struct_("Data", str);
|
auto* s = ty.struct_("Data", str);
|
||||||
auto* coord_var = Var("data", ast::StorageClass::kStorage, s);
|
auto* coord_var = Global("data", ast::StorageClass::kStorage, s);
|
||||||
AST().AddGlobalVariable(coord_var);
|
|
||||||
td.RegisterVariableForTesting(coord_var);
|
|
||||||
|
|
||||||
auto* expr = MemberAccessor("data", "b");
|
auto* expr = MemberAccessor("data", "b");
|
||||||
|
WrapInFunction(expr);
|
||||||
ASSERT_TRUE(td.Determine()) << td.error();
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr));
|
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
|
@ -111,14 +104,10 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
||||||
Member("b", ty.f32(), {MemberOffset(4)})},
|
Member("b", ty.f32(), {MemberOffset(4)})},
|
||||||
ast::StructDecorationList{});
|
ast::StructDecorationList{});
|
||||||
auto* s = ty.struct_("Data", str);
|
auto* s = ty.struct_("Data", str);
|
||||||
auto* coord_var = Var("data", ast::StorageClass::kStorage, s);
|
auto* coord_var = Global("data", ast::StorageClass::kStorage, s);
|
||||||
AST().AddGlobalVariable(coord_var);
|
|
||||||
td.RegisterVariableForTesting(coord_var);
|
|
||||||
|
|
||||||
auto* expr = MemberAccessor("data", "a");
|
auto* expr = MemberAccessor("data", "a");
|
||||||
|
WrapInFunction(expr);
|
||||||
ASSERT_TRUE(td.Determine()) << td.error();
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr));
|
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
|
@ -148,21 +137,14 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
||||||
ast::StructDecorationList{});
|
ast::StructDecorationList{});
|
||||||
|
|
||||||
auto* s = ty.struct_("Data", str);
|
auto* s = ty.struct_("Data", str);
|
||||||
auto* b_var = Var("b", ast::StorageClass::kPrivate, ty.mat2x3<f32>());
|
auto* b_var = Global("b", ast::StorageClass::kPrivate, ty.mat2x3<f32>());
|
||||||
AST().AddGlobalVariable(b_var);
|
auto* coord_var = Global("data", ast::StorageClass::kStorage, s);
|
||||||
auto* coord_var = Var("data", ast::StorageClass::kStorage, s);
|
|
||||||
AST().AddGlobalVariable(coord_var);
|
|
||||||
|
|
||||||
auto* lhs = MemberAccessor("data", "a");
|
auto* lhs = MemberAccessor("data", "a");
|
||||||
auto* rhs = Expr("b");
|
auto* rhs = Expr("b");
|
||||||
|
|
||||||
auto* assign = create<ast::AssignmentStatement>(lhs, rhs);
|
auto* assign = create<ast::AssignmentStatement>(lhs, rhs);
|
||||||
|
WrapInFunction(assign);
|
||||||
td.RegisterVariableForTesting(coord_var);
|
|
||||||
td.RegisterVariableForTesting(b_var);
|
|
||||||
|
|
||||||
ASSERT_TRUE(td.Determine()) << td.error();
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(assign));
|
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
|
@ -196,17 +178,13 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
||||||
ast::StructDecorationList{});
|
ast::StructDecorationList{});
|
||||||
|
|
||||||
auto* s = ty.struct_("Data", str);
|
auto* s = ty.struct_("Data", str);
|
||||||
auto* coord_var = Var("data", ast::StorageClass::kStorage, s);
|
auto* coord_var = Global("data", ast::StorageClass::kStorage, s);
|
||||||
AST().AddGlobalVariable(coord_var);
|
|
||||||
td.RegisterVariableForTesting(coord_var);
|
|
||||||
|
|
||||||
auto* lhs = MemberAccessor("data", "a");
|
auto* lhs = MemberAccessor("data", "a");
|
||||||
auto* rhs = Construct(ty.mat2x3<f32>(), ast::ExpressionList{});
|
auto* rhs = Construct(ty.mat2x3<f32>(), ast::ExpressionList{});
|
||||||
|
|
||||||
auto* assign = create<ast::AssignmentStatement>(lhs, rhs);
|
auto* assign = create<ast::AssignmentStatement>(lhs, rhs);
|
||||||
|
WrapInFunction(assign);
|
||||||
ASSERT_TRUE(td.Determine()) << td.error();
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(assign));
|
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
|
@ -239,14 +217,10 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
||||||
ast::StructDecorationList{});
|
ast::StructDecorationList{});
|
||||||
|
|
||||||
auto* s = ty.struct_("Data", str);
|
auto* s = ty.struct_("Data", str);
|
||||||
auto* coord_var = Var("data", ast::StorageClass::kStorage, s);
|
auto* coord_var = Global("data", ast::StorageClass::kStorage, s);
|
||||||
AST().AddGlobalVariable(coord_var);
|
|
||||||
td.RegisterVariableForTesting(coord_var);
|
|
||||||
|
|
||||||
auto* expr = MemberAccessor("data", "a");
|
auto* expr = MemberAccessor("data", "a");
|
||||||
|
WrapInFunction(expr);
|
||||||
ASSERT_TRUE(td.Determine()) << td.error();
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr));
|
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
|
@ -281,14 +255,10 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
||||||
ast::StructDecorationList{});
|
ast::StructDecorationList{});
|
||||||
|
|
||||||
auto* s = ty.struct_("Data", str);
|
auto* s = ty.struct_("Data", str);
|
||||||
auto* coord_var = Var("data", ast::StorageClass::kStorage, s);
|
auto* coord_var = Global("data", ast::StorageClass::kStorage, s);
|
||||||
AST().AddGlobalVariable(coord_var);
|
|
||||||
td.RegisterVariableForTesting(coord_var);
|
|
||||||
|
|
||||||
auto* expr = MemberAccessor("data", "a");
|
auto* expr = MemberAccessor("data", "a");
|
||||||
|
WrapInFunction(expr);
|
||||||
ASSERT_TRUE(td.Determine()) << td.error();
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr));
|
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
|
@ -316,14 +286,10 @@ TEST_F(
|
||||||
ast::StructDecorationList{});
|
ast::StructDecorationList{});
|
||||||
|
|
||||||
auto* s = ty.struct_("Data", str);
|
auto* s = ty.struct_("Data", str);
|
||||||
auto* coord_var = Var("data", ast::StorageClass::kStorage, s);
|
auto* coord_var = Global("data", ast::StorageClass::kStorage, s);
|
||||||
AST().AddGlobalVariable(coord_var);
|
|
||||||
td.RegisterVariableForTesting(coord_var);
|
|
||||||
|
|
||||||
auto* expr = MemberAccessor("data", "a");
|
auto* expr = MemberAccessor("data", "a");
|
||||||
|
WrapInFunction(expr);
|
||||||
ASSERT_TRUE(td.Determine()) << td.error();
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr));
|
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
|
@ -352,15 +318,11 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
||||||
ast::StructDecorationList{});
|
ast::StructDecorationList{});
|
||||||
|
|
||||||
auto* s = ty.struct_("Data", str);
|
auto* s = ty.struct_("Data", str);
|
||||||
auto* coord_var = Var("data", ast::StorageClass::kStorage, s);
|
auto* coord_var = Global("data", ast::StorageClass::kStorage, s);
|
||||||
AST().AddGlobalVariable(coord_var);
|
|
||||||
td.RegisterVariableForTesting(coord_var);
|
|
||||||
|
|
||||||
auto* expr = IndexAccessor(
|
auto* expr = IndexAccessor(
|
||||||
IndexAccessor(MemberAccessor("data", "a"), Expr(2)), Expr(1));
|
IndexAccessor(MemberAccessor("data", "a"), Expr(2)), Expr(1));
|
||||||
|
WrapInFunction(expr);
|
||||||
ASSERT_TRUE(td.Determine()) << td.error();
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr));
|
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
|
@ -388,14 +350,10 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
||||||
ast::StructMemberList{Member("a", &ary, {MemberOffset(0)})},
|
ast::StructMemberList{Member("a", &ary, {MemberOffset(0)})},
|
||||||
ast::StructDecorationList{});
|
ast::StructDecorationList{});
|
||||||
auto* s = ty.struct_("Data", str);
|
auto* s = ty.struct_("Data", str);
|
||||||
auto* coord_var = Var("data", ast::StorageClass::kStorage, s);
|
auto* coord_var = Global("data", ast::StorageClass::kStorage, s);
|
||||||
AST().AddGlobalVariable(coord_var);
|
|
||||||
td.RegisterVariableForTesting(coord_var);
|
|
||||||
|
|
||||||
auto* expr = IndexAccessor(MemberAccessor("data", "a"), Expr(2));
|
auto* expr = IndexAccessor(MemberAccessor("data", "a"), Expr(2));
|
||||||
|
WrapInFunction(expr);
|
||||||
ASSERT_TRUE(td.Determine()) << td.error();
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
|
@ -423,15 +381,11 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
||||||
ast::StructMemberList{Member("a", &ary, {MemberOffset(0)})},
|
ast::StructMemberList{Member("a", &ary, {MemberOffset(0)})},
|
||||||
ast::StructDecorationList{});
|
ast::StructDecorationList{});
|
||||||
auto* s = ty.struct_("Data", str);
|
auto* s = ty.struct_("Data", str);
|
||||||
auto* coord_var = Var("data", ast::StorageClass::kStorage, s);
|
auto* coord_var = Global("data", ast::StorageClass::kStorage, s);
|
||||||
AST().AddGlobalVariable(coord_var);
|
|
||||||
td.RegisterVariableForTesting(coord_var);
|
|
||||||
|
|
||||||
auto* expr = IndexAccessor(MemberAccessor("data", "a"),
|
auto* expr = IndexAccessor(MemberAccessor("data", "a"),
|
||||||
Sub(Add(Expr(2), Expr(4)), Expr(3)));
|
Sub(Add(Expr(2), Expr(4)), Expr(3)));
|
||||||
|
WrapInFunction(expr);
|
||||||
ASSERT_TRUE(td.Determine()) << td.error();
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
|
@ -458,16 +412,12 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
||||||
ast::StructDecorationList{});
|
ast::StructDecorationList{});
|
||||||
|
|
||||||
auto* s = ty.struct_("Data", str);
|
auto* s = ty.struct_("Data", str);
|
||||||
auto* coord_var = Var("data", ast::StorageClass::kStorage, s);
|
auto* coord_var = Global("data", ast::StorageClass::kStorage, s);
|
||||||
AST().AddGlobalVariable(coord_var);
|
|
||||||
td.RegisterVariableForTesting(coord_var);
|
|
||||||
|
|
||||||
auto* lhs = MemberAccessor("data", "b");
|
auto* lhs = MemberAccessor("data", "b");
|
||||||
auto* rhs = Expr(2.0f);
|
auto* rhs = Expr(2.0f);
|
||||||
auto* assign = create<ast::AssignmentStatement>(lhs, rhs);
|
auto* assign = create<ast::AssignmentStatement>(lhs, rhs);
|
||||||
|
WrapInFunction(assign);
|
||||||
ASSERT_TRUE(td.Determine()) << td.error();
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(assign));
|
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
|
@ -498,16 +448,12 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
||||||
ast::StructDecorationList{});
|
ast::StructDecorationList{});
|
||||||
|
|
||||||
auto* s = ty.struct_("Data", str);
|
auto* s = ty.struct_("Data", str);
|
||||||
auto* coord_var = Var("data", ast::StorageClass::kStorage, s);
|
auto* coord_var = Global("data", ast::StorageClass::kStorage, s);
|
||||||
AST().AddGlobalVariable(coord_var);
|
|
||||||
td.RegisterVariableForTesting(coord_var);
|
|
||||||
|
|
||||||
auto* lhs = IndexAccessor(MemberAccessor("data", "a"), Expr(2));
|
auto* lhs = IndexAccessor(MemberAccessor("data", "a"), Expr(2));
|
||||||
auto* rhs = Expr(2);
|
auto* rhs = Expr(2);
|
||||||
auto* assign = create<ast::AssignmentStatement>(lhs, rhs);
|
auto* assign = create<ast::AssignmentStatement>(lhs, rhs);
|
||||||
|
WrapInFunction(assign);
|
||||||
ASSERT_TRUE(td.Determine()) << td.error();
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(assign)) << td.error();
|
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
|
@ -535,16 +481,12 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
||||||
ast::StructDecorationList{});
|
ast::StructDecorationList{});
|
||||||
|
|
||||||
auto* s = ty.struct_("Data", str);
|
auto* s = ty.struct_("Data", str);
|
||||||
auto* coord_var = Var("data", ast::StorageClass::kStorage, s);
|
auto* coord_var = Global("data", ast::StorageClass::kStorage, s);
|
||||||
AST().AddGlobalVariable(coord_var);
|
|
||||||
td.RegisterVariableForTesting(coord_var);
|
|
||||||
|
|
||||||
auto* lhs = MemberAccessor("data", "a");
|
auto* lhs = MemberAccessor("data", "a");
|
||||||
auto* rhs = Expr(2);
|
auto* rhs = Expr(2);
|
||||||
auto* assign = create<ast::AssignmentStatement>(lhs, rhs);
|
auto* assign = create<ast::AssignmentStatement>(lhs, rhs);
|
||||||
|
WrapInFunction(assign);
|
||||||
ASSERT_TRUE(td.Determine()) << td.error();
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(assign));
|
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
|
@ -572,14 +514,10 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
||||||
ast::StructDecorationList{});
|
ast::StructDecorationList{});
|
||||||
|
|
||||||
auto* s = ty.struct_("Data", str);
|
auto* s = ty.struct_("Data", str);
|
||||||
auto* coord_var = Var("data", ast::StorageClass::kStorage, s);
|
auto* coord_var = Global("data", ast::StorageClass::kStorage, s);
|
||||||
AST().AddGlobalVariable(coord_var);
|
|
||||||
td.RegisterVariableForTesting(coord_var);
|
|
||||||
|
|
||||||
auto* expr = MemberAccessor("data", "b");
|
auto* expr = MemberAccessor("data", "b");
|
||||||
|
WrapInFunction(expr);
|
||||||
ASSERT_TRUE(td.Determine()) << td.error();
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr));
|
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
|
@ -606,17 +544,14 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
||||||
ast::StructDecorationList{});
|
ast::StructDecorationList{});
|
||||||
|
|
||||||
auto* s = ty.struct_("Data", str);
|
auto* s = ty.struct_("Data", str);
|
||||||
auto* coord_var = Var("data", ast::StorageClass::kStorage, s);
|
auto* coord_var = Global("data", ast::StorageClass::kStorage, s);
|
||||||
AST().AddGlobalVariable(coord_var);
|
|
||||||
td.RegisterVariableForTesting(coord_var);
|
|
||||||
|
|
||||||
auto* lhs = MemberAccessor("data", "b");
|
auto* lhs = MemberAccessor("data", "b");
|
||||||
auto* rhs = vec3<f32>(1.f, 2.f, 3.f);
|
auto* rhs = vec3<f32>(1.f, 2.f, 3.f);
|
||||||
|
|
||||||
auto* assign = create<ast::AssignmentStatement>(lhs, rhs);
|
auto* assign = create<ast::AssignmentStatement>(lhs, rhs);
|
||||||
|
|
||||||
ASSERT_TRUE(td.Determine()) << td.error();
|
WrapInFunction(assign);
|
||||||
ASSERT_TRUE(td.DetermineResultType(assign));
|
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
|
@ -661,15 +596,11 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
||||||
ast::StructDecorationList{});
|
ast::StructDecorationList{});
|
||||||
|
|
||||||
auto* pre_struct = ty.struct_("Pre", pre_str);
|
auto* pre_struct = ty.struct_("Pre", pre_str);
|
||||||
auto* coord_var = Var("data", ast::StorageClass::kStorage, pre_struct);
|
auto* coord_var = Global("data", ast::StorageClass::kStorage, pre_struct);
|
||||||
AST().AddGlobalVariable(coord_var);
|
|
||||||
td.RegisterVariableForTesting(coord_var);
|
|
||||||
|
|
||||||
auto* expr =
|
auto* expr =
|
||||||
MemberAccessor(IndexAccessor(MemberAccessor("data", "c"), Expr(2)), "b");
|
MemberAccessor(IndexAccessor(MemberAccessor("data", "c"), Expr(2)), "b");
|
||||||
|
WrapInFunction(expr);
|
||||||
ASSERT_TRUE(td.Determine()) << td.error();
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr));
|
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
|
@ -710,17 +641,12 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
||||||
ast::StructDecorationList{});
|
ast::StructDecorationList{});
|
||||||
|
|
||||||
auto* pre_struct = ty.struct_("Pre", pre_str);
|
auto* pre_struct = ty.struct_("Pre", pre_str);
|
||||||
auto* coord_var = Var("data", ast::StorageClass::kStorage, pre_struct);
|
auto* coord_var = Global("data", ast::StorageClass::kStorage, pre_struct);
|
||||||
AST().AddGlobalVariable(coord_var);
|
|
||||||
|
|
||||||
td.RegisterVariableForTesting(coord_var);
|
|
||||||
|
|
||||||
auto* expr = MemberAccessor(
|
auto* expr = MemberAccessor(
|
||||||
MemberAccessor(IndexAccessor(MemberAccessor("data", "c"), Expr(2)), "b"),
|
MemberAccessor(IndexAccessor(MemberAccessor("data", "c"), Expr(2)), "b"),
|
||||||
"xy");
|
"xy");
|
||||||
|
WrapInFunction(expr);
|
||||||
ASSERT_TRUE(td.Determine()) << td.error();
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr));
|
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
|
@ -764,16 +690,12 @@ TEST_F(
|
||||||
ast::StructDecorationList{});
|
ast::StructDecorationList{});
|
||||||
|
|
||||||
auto* pre_struct = ty.struct_("Pre", pre_str);
|
auto* pre_struct = ty.struct_("Pre", pre_str);
|
||||||
auto* coord_var = Var("data", ast::StorageClass::kStorage, pre_struct);
|
auto* coord_var = Global("data", ast::StorageClass::kStorage, pre_struct);
|
||||||
AST().AddGlobalVariable(coord_var);
|
|
||||||
td.RegisterVariableForTesting(coord_var);
|
|
||||||
|
|
||||||
auto* expr = MemberAccessor(
|
auto* expr = MemberAccessor(
|
||||||
MemberAccessor(IndexAccessor(MemberAccessor("data", "c"), Expr(2)), "b"),
|
MemberAccessor(IndexAccessor(MemberAccessor("data", "c"), Expr(2)), "b"),
|
||||||
"g");
|
"g");
|
||||||
|
WrapInFunction(expr);
|
||||||
ASSERT_TRUE(td.Determine()) << td.error();
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr));
|
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
|
@ -816,16 +738,12 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
||||||
ast::StructDecorationList{});
|
ast::StructDecorationList{});
|
||||||
|
|
||||||
auto* pre_struct = ty.struct_("Pre", pre_str);
|
auto* pre_struct = ty.struct_("Pre", pre_str);
|
||||||
auto* coord_var = Var("data", ast::StorageClass::kStorage, pre_struct);
|
auto* coord_var = Global("data", ast::StorageClass::kStorage, pre_struct);
|
||||||
AST().AddGlobalVariable(coord_var);
|
|
||||||
td.RegisterVariableForTesting(coord_var);
|
|
||||||
|
|
||||||
auto* expr = IndexAccessor(
|
auto* expr = IndexAccessor(
|
||||||
MemberAccessor(IndexAccessor(MemberAccessor("data", "c"), Expr(2)), "b"),
|
MemberAccessor(IndexAccessor(MemberAccessor("data", "c"), Expr(2)), "b"),
|
||||||
Expr(1));
|
Expr(1));
|
||||||
|
WrapInFunction(expr);
|
||||||
ASSERT_TRUE(td.Determine()) << td.error();
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr));
|
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
|
@ -868,9 +786,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
||||||
ast::StructDecorationList{});
|
ast::StructDecorationList{});
|
||||||
|
|
||||||
auto* pre_struct = ty.struct_("Pre", pre_str);
|
auto* pre_struct = ty.struct_("Pre", pre_str);
|
||||||
auto* coord_var = Var("data", ast::StorageClass::kStorage, pre_struct);
|
auto* coord_var = Global("data", ast::StorageClass::kStorage, pre_struct);
|
||||||
AST().AddGlobalVariable(coord_var);
|
|
||||||
td.RegisterVariableForTesting(coord_var);
|
|
||||||
|
|
||||||
auto* lhs =
|
auto* lhs =
|
||||||
MemberAccessor(IndexAccessor(MemberAccessor("data", "c"), Expr(2)), "b");
|
MemberAccessor(IndexAccessor(MemberAccessor("data", "c"), Expr(2)), "b");
|
||||||
|
@ -878,8 +794,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
||||||
auto* assign =
|
auto* assign =
|
||||||
create<ast::AssignmentStatement>(lhs, vec3<f32>(1.f, 2.f, 3.f));
|
create<ast::AssignmentStatement>(lhs, vec3<f32>(1.f, 2.f, 3.f));
|
||||||
|
|
||||||
ASSERT_TRUE(td.Determine()) << td.error();
|
WrapInFunction(assign);
|
||||||
ASSERT_TRUE(td.DetermineResultType(assign));
|
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
|
@ -924,9 +839,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
||||||
ast::StructDecorationList{});
|
ast::StructDecorationList{});
|
||||||
|
|
||||||
auto* pre_struct = ty.struct_("Pre", pre_str);
|
auto* pre_struct = ty.struct_("Pre", pre_str);
|
||||||
auto* coord_var = Var("data", ast::StorageClass::kStorage, pre_struct);
|
auto* coord_var = Global("data", ast::StorageClass::kStorage, pre_struct);
|
||||||
AST().AddGlobalVariable(coord_var);
|
|
||||||
td.RegisterVariableForTesting(coord_var);
|
|
||||||
|
|
||||||
auto* lhs = MemberAccessor(
|
auto* lhs = MemberAccessor(
|
||||||
MemberAccessor(IndexAccessor(MemberAccessor("data", "c"), Expr(2)), "b"),
|
MemberAccessor(IndexAccessor(MemberAccessor("data", "c"), Expr(2)), "b"),
|
||||||
|
@ -935,8 +848,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
||||||
|
|
||||||
auto* assign = create<ast::AssignmentStatement>(lhs, rhs);
|
auto* assign = create<ast::AssignmentStatement>(lhs, rhs);
|
||||||
|
|
||||||
ASSERT_TRUE(td.Determine()) << td.error();
|
WrapInFunction(assign);
|
||||||
ASSERT_TRUE(td.DetermineResultType(assign));
|
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
|
@ -950,12 +862,10 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
||||||
|
|
||||||
TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
||||||
EmitExpression_MemberAccessor_Swizzle_xyz) {
|
EmitExpression_MemberAccessor_Swizzle_xyz) {
|
||||||
auto* vec = Var("my_vec", ast::StorageClass::kPrivate, ty.vec4<f32>());
|
Global("my_vec", ast::StorageClass::kPrivate, ty.vec4<f32>());
|
||||||
td.RegisterVariableForTesting(vec);
|
|
||||||
|
|
||||||
auto* expr = MemberAccessor("my_vec", "xyz");
|
auto* expr = MemberAccessor("my_vec", "xyz");
|
||||||
|
WrapInFunction(expr);
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
ASSERT_TRUE(gen.EmitExpression(pre, out, expr)) << gen.error();
|
ASSERT_TRUE(gen.EmitExpression(pre, out, expr)) << gen.error();
|
||||||
|
@ -964,12 +874,10 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
||||||
|
|
||||||
TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
||||||
EmitExpression_MemberAccessor_Swizzle_gbr) {
|
EmitExpression_MemberAccessor_Swizzle_gbr) {
|
||||||
auto* vec = Var("my_vec", ast::StorageClass::kPrivate, ty.vec4<f32>());
|
Global("my_vec", ast::StorageClass::kPrivate, ty.vec4<f32>());
|
||||||
td.RegisterVariableForTesting(vec);
|
|
||||||
|
|
||||||
auto* expr = MemberAccessor("my_vec", "gbr");
|
auto* expr = MemberAccessor("my_vec", "gbr");
|
||||||
|
WrapInFunction(expr);
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
ASSERT_TRUE(gen.EmitExpression(pre, out, expr)) << gen.error();
|
ASSERT_TRUE(gen.EmitExpression(pre, out, expr)) << gen.error();
|
||||||
|
|
|
@ -407,14 +407,15 @@ using HlslStoragetexturesTest = TestParamHelper<HlslStorageTextureData>;
|
||||||
TEST_P(HlslStoragetexturesTest, Emit) {
|
TEST_P(HlslStoragetexturesTest, Emit) {
|
||||||
auto params = GetParam();
|
auto params = GetParam();
|
||||||
|
|
||||||
type::StorageTexture s(params.dim, params.imgfmt);
|
auto* s = create<type::StorageTexture>(params.dim, params.imgfmt);
|
||||||
type::AccessControl ac(params.ro ? ast::AccessControl::kReadOnly
|
auto* ac =
|
||||||
|
create<type::AccessControl>(params.ro ? ast::AccessControl::kReadOnly
|
||||||
: ast::AccessControl::kWriteOnly,
|
: ast::AccessControl::kWriteOnly,
|
||||||
&s);
|
s);
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
ASSERT_TRUE(gen.EmitType(out, &ac, "")) << gen.error();
|
ASSERT_TRUE(gen.EmitType(out, ac, "")) << gen.error();
|
||||||
EXPECT_EQ(result(), params.result);
|
EXPECT_EQ(result(), params.result);
|
||||||
}
|
}
|
||||||
INSTANTIATE_TEST_SUITE_P(
|
INSTANTIATE_TEST_SUITE_P(
|
||||||
|
|
|
@ -33,7 +33,7 @@ namespace hlsl {
|
||||||
template <typename BODY>
|
template <typename BODY>
|
||||||
class TestHelperBase : public BODY, public ProgramBuilder {
|
class TestHelperBase : public BODY, public ProgramBuilder {
|
||||||
public:
|
public:
|
||||||
TestHelperBase() : td(this) {}
|
TestHelperBase() = default;
|
||||||
~TestHelperBase() = default;
|
~TestHelperBase() = default;
|
||||||
|
|
||||||
/// Builds and returns a GeneratorImpl from the program.
|
/// Builds and returns a GeneratorImpl from the program.
|
||||||
|
@ -55,9 +55,6 @@ class TestHelperBase : public BODY, public ProgramBuilder {
|
||||||
/// @returns the pre result string
|
/// @returns the pre result string
|
||||||
std::string pre_result() const { return pre.str(); }
|
std::string pre_result() const { return pre.str(); }
|
||||||
|
|
||||||
/// The type determiner
|
|
||||||
TypeDeterminer td;
|
|
||||||
|
|
||||||
/// The output stream
|
/// The output stream
|
||||||
std::ostringstream out;
|
std::ostringstream out;
|
||||||
/// The pre-output stream
|
/// The pre-output stream
|
||||||
|
|
|
@ -47,20 +47,12 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Vertex_Input) {
|
||||||
// int bar [[attribute(1)]];
|
// int bar [[attribute(1)]];
|
||||||
// };
|
// };
|
||||||
|
|
||||||
auto* foo_var =
|
Global("foo", ast::StorageClass::kInput, ty.f32(), nullptr,
|
||||||
Var("foo", ast::StorageClass::kInput, ty.f32(), nullptr,
|
|
||||||
ast::VariableDecorationList{create<ast::LocationDecoration>(0)});
|
ast::VariableDecorationList{create<ast::LocationDecoration>(0)});
|
||||||
|
|
||||||
auto* bar_var =
|
Global("bar", ast::StorageClass::kInput, ty.i32(), nullptr,
|
||||||
Var("bar", ast::StorageClass::kInput, ty.i32(), nullptr,
|
|
||||||
ast::VariableDecorationList{create<ast::LocationDecoration>(1)});
|
ast::VariableDecorationList{create<ast::LocationDecoration>(1)});
|
||||||
|
|
||||||
td.RegisterVariableForTesting(foo_var);
|
|
||||||
td.RegisterVariableForTesting(bar_var);
|
|
||||||
|
|
||||||
AST().AddGlobalVariable(foo_var);
|
|
||||||
AST().AddGlobalVariable(bar_var);
|
|
||||||
|
|
||||||
auto body = ast::StatementList{
|
auto body = ast::StatementList{
|
||||||
create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")),
|
create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")),
|
||||||
create<ast::AssignmentStatement>(Expr("bar"), Expr("bar")),
|
create<ast::AssignmentStatement>(Expr("bar"), Expr("bar")),
|
||||||
|
@ -92,20 +84,12 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Vertex_Output) {
|
||||||
// int bar [[user(locn1)]];
|
// int bar [[user(locn1)]];
|
||||||
// };
|
// };
|
||||||
|
|
||||||
auto* foo_var =
|
Global("foo", ast::StorageClass::kOutput, ty.f32(), nullptr,
|
||||||
Var("foo", ast::StorageClass::kOutput, ty.f32(), nullptr,
|
|
||||||
ast::VariableDecorationList{create<ast::LocationDecoration>(0)});
|
ast::VariableDecorationList{create<ast::LocationDecoration>(0)});
|
||||||
|
|
||||||
auto* bar_var =
|
Global("bar", ast::StorageClass::kOutput, ty.i32(), nullptr,
|
||||||
Var("bar", ast::StorageClass::kOutput, ty.i32(), nullptr,
|
|
||||||
ast::VariableDecorationList{create<ast::LocationDecoration>(1)});
|
ast::VariableDecorationList{create<ast::LocationDecoration>(1)});
|
||||||
|
|
||||||
td.RegisterVariableForTesting(foo_var);
|
|
||||||
td.RegisterVariableForTesting(bar_var);
|
|
||||||
|
|
||||||
AST().AddGlobalVariable(foo_var);
|
|
||||||
AST().AddGlobalVariable(bar_var);
|
|
||||||
|
|
||||||
auto body = ast::StatementList{
|
auto body = ast::StatementList{
|
||||||
create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")),
|
create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")),
|
||||||
create<ast::AssignmentStatement>(Expr("bar"), Expr("bar")),
|
create<ast::AssignmentStatement>(Expr("bar"), Expr("bar")),
|
||||||
|
@ -137,20 +121,12 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Fragment_Input) {
|
||||||
// int bar [[user(locn1)]];
|
// int bar [[user(locn1)]];
|
||||||
// };
|
// };
|
||||||
|
|
||||||
auto* foo_var =
|
Global("foo", ast::StorageClass::kInput, ty.f32(), nullptr,
|
||||||
Var("foo", ast::StorageClass::kInput, ty.f32(), nullptr,
|
|
||||||
ast::VariableDecorationList{create<ast::LocationDecoration>(0)});
|
ast::VariableDecorationList{create<ast::LocationDecoration>(0)});
|
||||||
|
|
||||||
auto* bar_var =
|
Global("bar", ast::StorageClass::kInput, ty.i32(), nullptr,
|
||||||
Var("bar", ast::StorageClass::kInput, ty.i32(), nullptr,
|
|
||||||
ast::VariableDecorationList{create<ast::LocationDecoration>(1)});
|
ast::VariableDecorationList{create<ast::LocationDecoration>(1)});
|
||||||
|
|
||||||
td.RegisterVariableForTesting(foo_var);
|
|
||||||
td.RegisterVariableForTesting(bar_var);
|
|
||||||
|
|
||||||
AST().AddGlobalVariable(foo_var);
|
|
||||||
AST().AddGlobalVariable(bar_var);
|
|
||||||
|
|
||||||
auto body = ast::StatementList{
|
auto body = ast::StatementList{
|
||||||
create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")),
|
create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")),
|
||||||
create<ast::AssignmentStatement>(Expr("bar"), Expr("bar")),
|
create<ast::AssignmentStatement>(Expr("bar"), Expr("bar")),
|
||||||
|
@ -182,20 +158,12 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Fragment_Output) {
|
||||||
// int bar [[color(1)]];
|
// int bar [[color(1)]];
|
||||||
// };
|
// };
|
||||||
|
|
||||||
auto* foo_var =
|
Global("foo", ast::StorageClass::kOutput, ty.f32(), nullptr,
|
||||||
Var("foo", ast::StorageClass::kOutput, ty.f32(), nullptr,
|
|
||||||
ast::VariableDecorationList{create<ast::LocationDecoration>(0)});
|
ast::VariableDecorationList{create<ast::LocationDecoration>(0)});
|
||||||
|
|
||||||
auto* bar_var =
|
Global("bar", ast::StorageClass::kOutput, ty.i32(), nullptr,
|
||||||
Var("bar", ast::StorageClass::kOutput, ty.i32(), nullptr,
|
|
||||||
ast::VariableDecorationList{create<ast::LocationDecoration>(1)});
|
ast::VariableDecorationList{create<ast::LocationDecoration>(1)});
|
||||||
|
|
||||||
td.RegisterVariableForTesting(foo_var);
|
|
||||||
td.RegisterVariableForTesting(bar_var);
|
|
||||||
|
|
||||||
AST().AddGlobalVariable(foo_var);
|
|
||||||
AST().AddGlobalVariable(bar_var);
|
|
||||||
|
|
||||||
auto body = ast::StatementList{
|
auto body = ast::StatementList{
|
||||||
create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")),
|
create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")),
|
||||||
create<ast::AssignmentStatement>(Expr("bar"), Expr("bar")),
|
create<ast::AssignmentStatement>(Expr("bar"), Expr("bar")),
|
||||||
|
@ -224,20 +192,12 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Compute_Input) {
|
||||||
//
|
//
|
||||||
// -> Error, not allowed
|
// -> Error, not allowed
|
||||||
|
|
||||||
auto* foo_var =
|
Global("foo", ast::StorageClass::kInput, ty.f32(), nullptr,
|
||||||
Var("foo", ast::StorageClass::kInput, ty.f32(), nullptr,
|
|
||||||
ast::VariableDecorationList{create<ast::LocationDecoration>(0)});
|
ast::VariableDecorationList{create<ast::LocationDecoration>(0)});
|
||||||
|
|
||||||
auto* bar_var =
|
Global("bar", ast::StorageClass::kInput, ty.i32(), nullptr,
|
||||||
Var("bar", ast::StorageClass::kInput, ty.i32(), nullptr,
|
|
||||||
ast::VariableDecorationList{create<ast::LocationDecoration>(1)});
|
ast::VariableDecorationList{create<ast::LocationDecoration>(1)});
|
||||||
|
|
||||||
td.RegisterVariableForTesting(foo_var);
|
|
||||||
td.RegisterVariableForTesting(bar_var);
|
|
||||||
|
|
||||||
AST().AddGlobalVariable(foo_var);
|
|
||||||
AST().AddGlobalVariable(bar_var);
|
|
||||||
|
|
||||||
auto body = ast::StatementList{
|
auto body = ast::StatementList{
|
||||||
create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")),
|
create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")),
|
||||||
create<ast::AssignmentStatement>(Expr("bar"), Expr("bar")),
|
create<ast::AssignmentStatement>(Expr("bar"), Expr("bar")),
|
||||||
|
@ -261,20 +221,12 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Compute_Output) {
|
||||||
//
|
//
|
||||||
// -> Error not allowed
|
// -> Error not allowed
|
||||||
|
|
||||||
auto* foo_var =
|
Global("foo", ast::StorageClass::kOutput, ty.f32(), nullptr,
|
||||||
Var("foo", ast::StorageClass::kOutput, ty.f32(), nullptr,
|
|
||||||
ast::VariableDecorationList{create<ast::LocationDecoration>(0)});
|
ast::VariableDecorationList{create<ast::LocationDecoration>(0)});
|
||||||
|
|
||||||
auto* bar_var =
|
Global("bar", ast::StorageClass::kOutput, ty.i32(), nullptr,
|
||||||
Var("bar", ast::StorageClass::kOutput, ty.i32(), nullptr,
|
|
||||||
ast::VariableDecorationList{create<ast::LocationDecoration>(1)});
|
ast::VariableDecorationList{create<ast::LocationDecoration>(1)});
|
||||||
|
|
||||||
td.RegisterVariableForTesting(foo_var);
|
|
||||||
td.RegisterVariableForTesting(bar_var);
|
|
||||||
|
|
||||||
AST().AddGlobalVariable(foo_var);
|
|
||||||
AST().AddGlobalVariable(bar_var);
|
|
||||||
|
|
||||||
auto body = ast::StatementList{
|
auto body = ast::StatementList{
|
||||||
create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")),
|
create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")),
|
||||||
create<ast::AssignmentStatement>(Expr("bar"), Expr("bar")),
|
create<ast::AssignmentStatement>(Expr("bar"), Expr("bar")),
|
||||||
|
@ -303,22 +255,14 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Builtins) {
|
||||||
// float depth [[depth(any)]];
|
// float depth [[depth(any)]];
|
||||||
// };
|
// };
|
||||||
|
|
||||||
auto* coord_var =
|
Global("coord", ast::StorageClass::kInput, ty.vec4<f32>(), nullptr,
|
||||||
Var("coord", ast::StorageClass::kInput, ty.vec4<f32>(), nullptr,
|
|
||||||
ast::VariableDecorationList{
|
ast::VariableDecorationList{
|
||||||
create<ast::BuiltinDecoration>(ast::Builtin::kFragCoord)});
|
create<ast::BuiltinDecoration>(ast::Builtin::kFragCoord)});
|
||||||
|
|
||||||
auto* depth_var =
|
Global("depth", ast::StorageClass::kOutput, ty.f32(), nullptr,
|
||||||
Var("depth", ast::StorageClass::kOutput, ty.f32(), nullptr,
|
|
||||||
ast::VariableDecorationList{
|
ast::VariableDecorationList{
|
||||||
create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth)});
|
create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth)});
|
||||||
|
|
||||||
td.RegisterVariableForTesting(coord_var);
|
|
||||||
td.RegisterVariableForTesting(depth_var);
|
|
||||||
|
|
||||||
AST().AddGlobalVariable(coord_var);
|
|
||||||
AST().AddGlobalVariable(depth_var);
|
|
||||||
|
|
||||||
auto body = ast::StatementList{create<ast::AssignmentStatement>(
|
auto body = ast::StatementList{create<ast::AssignmentStatement>(
|
||||||
Expr("depth"), MemberAccessor("coord", "x"))};
|
Expr("depth"), MemberAccessor("coord", "x"))};
|
||||||
|
|
||||||
|
|
|
@ -142,20 +142,12 @@ fragment void main_tint_0() {
|
||||||
|
|
||||||
TEST_F(MslGeneratorImplTest,
|
TEST_F(MslGeneratorImplTest,
|
||||||
Emit_FunctionDecoration_EntryPoint_NoReturn_InOut) {
|
Emit_FunctionDecoration_EntryPoint_NoReturn_InOut) {
|
||||||
auto* foo_var =
|
Global("foo", ast::StorageClass::kInput, ty.f32(), nullptr,
|
||||||
Var("foo", ast::StorageClass::kInput, ty.f32(), nullptr,
|
|
||||||
ast::VariableDecorationList{create<ast::LocationDecoration>(0)});
|
ast::VariableDecorationList{create<ast::LocationDecoration>(0)});
|
||||||
|
|
||||||
auto* bar_var =
|
Global("bar", ast::StorageClass::kOutput, ty.f32(), nullptr,
|
||||||
Var("bar", ast::StorageClass::kOutput, ty.f32(), nullptr,
|
|
||||||
ast::VariableDecorationList{create<ast::LocationDecoration>(1)});
|
ast::VariableDecorationList{create<ast::LocationDecoration>(1)});
|
||||||
|
|
||||||
td.RegisterVariableForTesting(foo_var);
|
|
||||||
td.RegisterVariableForTesting(bar_var);
|
|
||||||
|
|
||||||
AST().AddGlobalVariable(foo_var);
|
|
||||||
AST().AddGlobalVariable(bar_var);
|
|
||||||
|
|
||||||
Func("main", ast::VariableList{}, ty.void_(),
|
Func("main", ast::VariableList{}, ty.void_(),
|
||||||
ast::StatementList{
|
ast::StatementList{
|
||||||
create<ast::AssignmentStatement>(Expr("bar"), Expr("foo")),
|
create<ast::AssignmentStatement>(Expr("bar"), Expr("foo")),
|
||||||
|
@ -186,20 +178,12 @@ fragment main_out main_tint_0(main_in tint_in [[stage_in]]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(MslGeneratorImplTest, Emit_FunctionDecoration_EntryPoint_WithInOutVars) {
|
TEST_F(MslGeneratorImplTest, Emit_FunctionDecoration_EntryPoint_WithInOutVars) {
|
||||||
auto* foo_var =
|
Global("foo", ast::StorageClass::kInput, ty.f32(), nullptr,
|
||||||
Var("foo", ast::StorageClass::kInput, ty.f32(), nullptr,
|
|
||||||
ast::VariableDecorationList{create<ast::LocationDecoration>(0)});
|
ast::VariableDecorationList{create<ast::LocationDecoration>(0)});
|
||||||
|
|
||||||
auto* bar_var =
|
Global("bar", ast::StorageClass::kOutput, ty.f32(), nullptr,
|
||||||
Var("bar", ast::StorageClass::kOutput, ty.f32(), nullptr,
|
|
||||||
ast::VariableDecorationList{create<ast::LocationDecoration>(1)});
|
ast::VariableDecorationList{create<ast::LocationDecoration>(1)});
|
||||||
|
|
||||||
td.RegisterVariableForTesting(foo_var);
|
|
||||||
td.RegisterVariableForTesting(bar_var);
|
|
||||||
|
|
||||||
AST().AddGlobalVariable(foo_var);
|
|
||||||
AST().AddGlobalVariable(bar_var);
|
|
||||||
|
|
||||||
auto body = ast::StatementList{
|
auto body = ast::StatementList{
|
||||||
create<ast::AssignmentStatement>(Expr("bar"), Expr("foo")),
|
create<ast::AssignmentStatement>(Expr("bar"), Expr("foo")),
|
||||||
create<ast::ReturnStatement>(),
|
create<ast::ReturnStatement>(),
|
||||||
|
@ -232,22 +216,14 @@ fragment frag_main_out frag_main(frag_main_in tint_in [[stage_in]]) {
|
||||||
|
|
||||||
TEST_F(MslGeneratorImplTest,
|
TEST_F(MslGeneratorImplTest,
|
||||||
Emit_FunctionDecoration_EntryPoint_WithInOut_Builtins) {
|
Emit_FunctionDecoration_EntryPoint_WithInOut_Builtins) {
|
||||||
auto* coord_var =
|
Global("coord", ast::StorageClass::kInput, ty.vec4<f32>(), nullptr,
|
||||||
Var("coord", ast::StorageClass::kInput, ty.vec4<f32>(), nullptr,
|
|
||||||
ast::VariableDecorationList{
|
ast::VariableDecorationList{
|
||||||
create<ast::BuiltinDecoration>(ast::Builtin::kFragCoord)});
|
create<ast::BuiltinDecoration>(ast::Builtin::kFragCoord)});
|
||||||
|
|
||||||
auto* depth_var =
|
Global("depth", ast::StorageClass::kOutput, ty.f32(), nullptr,
|
||||||
Var("depth", ast::StorageClass::kOutput, ty.f32(), nullptr,
|
|
||||||
ast::VariableDecorationList{
|
ast::VariableDecorationList{
|
||||||
create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth)});
|
create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth)});
|
||||||
|
|
||||||
td.RegisterVariableForTesting(coord_var);
|
|
||||||
td.RegisterVariableForTesting(depth_var);
|
|
||||||
|
|
||||||
AST().AddGlobalVariable(coord_var);
|
|
||||||
AST().AddGlobalVariable(depth_var);
|
|
||||||
|
|
||||||
auto body = ast::StatementList{
|
auto body = ast::StatementList{
|
||||||
create<ast::AssignmentStatement>(Expr("depth"),
|
create<ast::AssignmentStatement>(Expr("depth"),
|
||||||
MemberAccessor("coord", "x")),
|
MemberAccessor("coord", "x")),
|
||||||
|
@ -278,15 +254,10 @@ fragment frag_main_out frag_main(float4 coord [[position]]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(MslGeneratorImplTest, Emit_FunctionDecoration_EntryPoint_With_Uniform) {
|
TEST_F(MslGeneratorImplTest, Emit_FunctionDecoration_EntryPoint_With_Uniform) {
|
||||||
auto* coord_var =
|
Global("coord", ast::StorageClass::kUniform, ty.vec4<f32>(), nullptr,
|
||||||
Var("coord", ast::StorageClass::kUniform, ty.vec4<f32>(), nullptr,
|
|
||||||
ast::VariableDecorationList{create<ast::BindingDecoration>(0),
|
ast::VariableDecorationList{create<ast::BindingDecoration>(0),
|
||||||
create<ast::GroupDecoration>(1)});
|
create<ast::GroupDecoration>(1)});
|
||||||
|
|
||||||
td.RegisterVariableForTesting(coord_var);
|
|
||||||
|
|
||||||
AST().AddGlobalVariable(coord_var);
|
|
||||||
|
|
||||||
auto* var = Var("v", ast::StorageClass::kFunction, ty.f32(),
|
auto* var = Var("v", ast::StorageClass::kFunction, ty.f32(),
|
||||||
MemberAccessor("coord", "x"), ast::VariableDecorationList{});
|
MemberAccessor("coord", "x"), ast::VariableDecorationList{});
|
||||||
|
|
||||||
|
@ -324,15 +295,10 @@ TEST_F(MslGeneratorImplTest,
|
||||||
|
|
||||||
AST().AddConstructedType(s);
|
AST().AddConstructedType(s);
|
||||||
|
|
||||||
auto* coord_var =
|
Global("coord", ast::StorageClass::kStorage, &ac, nullptr,
|
||||||
Var("coord", ast::StorageClass::kStorage, &ac, nullptr,
|
|
||||||
ast::VariableDecorationList{create<ast::BindingDecoration>(0),
|
ast::VariableDecorationList{create<ast::BindingDecoration>(0),
|
||||||
create<ast::GroupDecoration>(1)});
|
create<ast::GroupDecoration>(1)});
|
||||||
|
|
||||||
td.RegisterVariableForTesting(coord_var);
|
|
||||||
|
|
||||||
AST().AddGlobalVariable(coord_var);
|
|
||||||
|
|
||||||
auto* var = Var("v", ast::StorageClass::kFunction, ty.f32(),
|
auto* var = Var("v", ast::StorageClass::kFunction, ty.f32(),
|
||||||
MemberAccessor("coord", "b"), ast::VariableDecorationList{});
|
MemberAccessor("coord", "b"), ast::VariableDecorationList{});
|
||||||
|
|
||||||
|
@ -374,14 +340,10 @@ TEST_F(MslGeneratorImplTest,
|
||||||
type::AccessControl ac(ast::AccessControl::kReadOnly, s);
|
type::AccessControl ac(ast::AccessControl::kReadOnly, s);
|
||||||
AST().AddConstructedType(s);
|
AST().AddConstructedType(s);
|
||||||
|
|
||||||
auto* coord_var =
|
Global("coord", ast::StorageClass::kStorage, &ac, nullptr,
|
||||||
Var("coord", ast::StorageClass::kStorage, &ac, nullptr,
|
|
||||||
ast::VariableDecorationList{create<ast::BindingDecoration>(0),
|
ast::VariableDecorationList{create<ast::BindingDecoration>(0),
|
||||||
create<ast::GroupDecoration>(1)});
|
create<ast::GroupDecoration>(1)});
|
||||||
|
|
||||||
td.RegisterVariableForTesting(coord_var);
|
|
||||||
AST().AddGlobalVariable(coord_var);
|
|
||||||
|
|
||||||
auto* var = Var("v", ast::StorageClass::kFunction, ty.f32(),
|
auto* var = Var("v", ast::StorageClass::kFunction, ty.f32(),
|
||||||
MemberAccessor("coord", "b"), ast::VariableDecorationList{});
|
MemberAccessor("coord", "b"), ast::VariableDecorationList{});
|
||||||
|
|
||||||
|
@ -415,26 +377,15 @@ fragment void frag_main(const device Data& coord [[buffer(0)]]) {
|
||||||
TEST_F(
|
TEST_F(
|
||||||
MslGeneratorImplTest,
|
MslGeneratorImplTest,
|
||||||
Emit_FunctionDecoration_Called_By_EntryPoints_WithLocationGlobals_And_Params) { // NOLINT
|
Emit_FunctionDecoration_Called_By_EntryPoints_WithLocationGlobals_And_Params) { // NOLINT
|
||||||
auto* foo_var =
|
Global("foo", ast::StorageClass::kInput, ty.f32(), nullptr,
|
||||||
Var("foo", ast::StorageClass::kInput, ty.f32(), nullptr,
|
|
||||||
ast::VariableDecorationList{create<ast::LocationDecoration>(0)});
|
ast::VariableDecorationList{create<ast::LocationDecoration>(0)});
|
||||||
|
|
||||||
auto* bar_var =
|
Global("bar", ast::StorageClass::kOutput, ty.f32(), nullptr,
|
||||||
Var("bar", ast::StorageClass::kOutput, ty.f32(), nullptr,
|
|
||||||
ast::VariableDecorationList{create<ast::LocationDecoration>(1)});
|
ast::VariableDecorationList{create<ast::LocationDecoration>(1)});
|
||||||
|
|
||||||
auto* val_var =
|
Global("val", ast::StorageClass::kOutput, ty.f32(), nullptr,
|
||||||
Var("val", ast::StorageClass::kOutput, ty.f32(), nullptr,
|
|
||||||
ast::VariableDecorationList{create<ast::LocationDecoration>(0)});
|
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);
|
|
||||||
|
|
||||||
ast::VariableList params;
|
ast::VariableList params;
|
||||||
params.push_back(Var("param", ast::StorageClass::kFunction, ty.f32()));
|
params.push_back(Var("param", ast::StorageClass::kFunction, ty.f32()));
|
||||||
|
|
||||||
|
@ -486,14 +437,10 @@ fragment ep_1_out ep_1(ep_1_in tint_in [[stage_in]]) {
|
||||||
|
|
||||||
TEST_F(MslGeneratorImplTest,
|
TEST_F(MslGeneratorImplTest,
|
||||||
Emit_FunctionDecoration_Called_By_EntryPoints_NoUsedGlobals) {
|
Emit_FunctionDecoration_Called_By_EntryPoints_NoUsedGlobals) {
|
||||||
auto* depth_var =
|
Global("depth", ast::StorageClass::kOutput, ty.f32(), nullptr,
|
||||||
Var("depth", ast::StorageClass::kOutput, ty.f32(), nullptr,
|
|
||||||
ast::VariableDecorationList{
|
ast::VariableDecorationList{
|
||||||
create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth)});
|
create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth)});
|
||||||
|
|
||||||
td.RegisterVariableForTesting(depth_var);
|
|
||||||
AST().AddGlobalVariable(depth_var);
|
|
||||||
|
|
||||||
ast::VariableList params;
|
ast::VariableList params;
|
||||||
params.push_back(Var("param", ast::StorageClass::kFunction, ty.f32()));
|
params.push_back(Var("param", ast::StorageClass::kFunction, ty.f32()));
|
||||||
|
|
||||||
|
@ -538,22 +485,14 @@ fragment ep_1_out ep_1() {
|
||||||
TEST_F(
|
TEST_F(
|
||||||
MslGeneratorImplTest,
|
MslGeneratorImplTest,
|
||||||
Emit_FunctionDecoration_Called_By_EntryPoints_WithBuiltinGlobals_And_Params) { // NOLINT
|
Emit_FunctionDecoration_Called_By_EntryPoints_WithBuiltinGlobals_And_Params) { // NOLINT
|
||||||
auto* coord_var =
|
Global("coord", ast::StorageClass::kInput, ty.vec4<f32>(), nullptr,
|
||||||
Var("coord", ast::StorageClass::kInput, ty.vec4<f32>(), nullptr,
|
|
||||||
ast::VariableDecorationList{
|
ast::VariableDecorationList{
|
||||||
create<ast::BuiltinDecoration>(ast::Builtin::kFragCoord)});
|
create<ast::BuiltinDecoration>(ast::Builtin::kFragCoord)});
|
||||||
|
|
||||||
auto* depth_var =
|
Global("depth", ast::StorageClass::kOutput, ty.f32(), nullptr,
|
||||||
Var("depth", ast::StorageClass::kOutput, ty.f32(), nullptr,
|
|
||||||
ast::VariableDecorationList{
|
ast::VariableDecorationList{
|
||||||
create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth)});
|
create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth)});
|
||||||
|
|
||||||
td.RegisterVariableForTesting(coord_var);
|
|
||||||
td.RegisterVariableForTesting(depth_var);
|
|
||||||
|
|
||||||
AST().AddGlobalVariable(coord_var);
|
|
||||||
AST().AddGlobalVariable(depth_var);
|
|
||||||
|
|
||||||
ast::VariableList params;
|
ast::VariableList params;
|
||||||
params.push_back(Var("param", ast::StorageClass::kFunction, ty.f32()));
|
params.push_back(Var("param", ast::StorageClass::kFunction, ty.f32()));
|
||||||
|
|
||||||
|
@ -600,14 +539,10 @@ fragment ep_1_out ep_1(float4 coord [[position]]) {
|
||||||
|
|
||||||
TEST_F(MslGeneratorImplTest,
|
TEST_F(MslGeneratorImplTest,
|
||||||
Emit_FunctionDecoration_Called_By_EntryPoint_With_Uniform) {
|
Emit_FunctionDecoration_Called_By_EntryPoint_With_Uniform) {
|
||||||
auto* coord_var =
|
Global("coord", ast::StorageClass::kUniform, ty.vec4<f32>(), nullptr,
|
||||||
Var("coord", ast::StorageClass::kUniform, ty.vec4<f32>(), nullptr,
|
|
||||||
ast::VariableDecorationList{create<ast::BindingDecoration>(0),
|
ast::VariableDecorationList{create<ast::BindingDecoration>(0),
|
||||||
create<ast::GroupDecoration>(1)});
|
create<ast::GroupDecoration>(1)});
|
||||||
|
|
||||||
td.RegisterVariableForTesting(coord_var);
|
|
||||||
AST().AddGlobalVariable(coord_var);
|
|
||||||
|
|
||||||
ast::VariableList params;
|
ast::VariableList params;
|
||||||
params.push_back(Var("param", ast::StorageClass::kFunction, ty.f32()));
|
params.push_back(Var("param", ast::StorageClass::kFunction, ty.f32()));
|
||||||
|
|
||||||
|
@ -660,17 +595,12 @@ TEST_F(MslGeneratorImplTest,
|
||||||
type::AccessControl ac(ast::AccessControl::kReadWrite, s);
|
type::AccessControl ac(ast::AccessControl::kReadWrite, s);
|
||||||
AST().AddConstructedType(s);
|
AST().AddConstructedType(s);
|
||||||
|
|
||||||
auto* coord_var =
|
Global("coord", ast::StorageClass::kStorage, &ac, nullptr,
|
||||||
Var("coord", ast::StorageClass::kStorage, &ac, nullptr,
|
|
||||||
ast::VariableDecorationList{create<ast::BindingDecoration>(0),
|
ast::VariableDecorationList{create<ast::BindingDecoration>(0),
|
||||||
create<ast::GroupDecoration>(1)});
|
create<ast::GroupDecoration>(1)});
|
||||||
|
|
||||||
td.RegisterVariableForTesting(coord_var);
|
|
||||||
AST().AddGlobalVariable(coord_var);
|
|
||||||
|
|
||||||
ast::VariableList params;
|
ast::VariableList params;
|
||||||
params.push_back(
|
params.push_back(Var("param", ast::StorageClass::kFunction, ty.f32()));
|
||||||
Var("param", ast::StorageClass::kFunction, ty.f32())); // decorations
|
|
||||||
|
|
||||||
auto body = ast::StatementList{
|
auto body = ast::StatementList{
|
||||||
create<ast::ReturnStatement>(MemberAccessor("coord", "b"))};
|
create<ast::ReturnStatement>(MemberAccessor("coord", "b"))};
|
||||||
|
@ -722,17 +652,12 @@ TEST_F(MslGeneratorImplTest,
|
||||||
type::AccessControl ac(ast::AccessControl::kReadOnly, s);
|
type::AccessControl ac(ast::AccessControl::kReadOnly, s);
|
||||||
AST().AddConstructedType(s);
|
AST().AddConstructedType(s);
|
||||||
|
|
||||||
auto* coord_var =
|
Global("coord", ast::StorageClass::kStorage, &ac, nullptr,
|
||||||
Var("coord", ast::StorageClass::kStorage, &ac, nullptr,
|
|
||||||
ast::VariableDecorationList{create<ast::BindingDecoration>(0),
|
ast::VariableDecorationList{create<ast::BindingDecoration>(0),
|
||||||
create<ast::GroupDecoration>(1)});
|
create<ast::GroupDecoration>(1)});
|
||||||
|
|
||||||
td.RegisterVariableForTesting(coord_var);
|
|
||||||
AST().AddGlobalVariable(coord_var);
|
|
||||||
|
|
||||||
ast::VariableList params;
|
ast::VariableList params;
|
||||||
params.push_back(
|
params.push_back(Var("param", ast::StorageClass::kFunction, ty.f32()));
|
||||||
Var("param", ast::StorageClass::kFunction, ty.f32())); // decorations
|
|
||||||
|
|
||||||
auto body = ast::StatementList{
|
auto body = ast::StatementList{
|
||||||
create<ast::ReturnStatement>(MemberAccessor("coord", "b"))};
|
create<ast::ReturnStatement>(MemberAccessor("coord", "b"))};
|
||||||
|
@ -778,13 +703,9 @@ fragment void frag_main(const device Data& coord [[buffer(0)]]) {
|
||||||
|
|
||||||
TEST_F(MslGeneratorImplTest,
|
TEST_F(MslGeneratorImplTest,
|
||||||
Emit_FunctionDecoration_EntryPoints_WithGlobal_Nested_Return) {
|
Emit_FunctionDecoration_EntryPoints_WithGlobal_Nested_Return) {
|
||||||
auto* bar_var =
|
Global("bar", ast::StorageClass::kOutput, ty.f32(), nullptr,
|
||||||
Var("bar", ast::StorageClass::kOutput, ty.f32(), nullptr,
|
|
||||||
ast::VariableDecorationList{create<ast::LocationDecoration>(1)});
|
ast::VariableDecorationList{create<ast::LocationDecoration>(1)});
|
||||||
|
|
||||||
td.RegisterVariableForTesting(bar_var);
|
|
||||||
AST().AddGlobalVariable(bar_var);
|
|
||||||
|
|
||||||
auto* list = create<ast::BlockStatement>(ast::StatementList{
|
auto* list = create<ast::BlockStatement>(ast::StatementList{
|
||||||
create<ast::ReturnStatement>(),
|
create<ast::ReturnStatement>(),
|
||||||
});
|
});
|
||||||
|
@ -893,14 +814,11 @@ TEST_F(MslGeneratorImplTest,
|
||||||
auto* s = ty.struct_("Data", str);
|
auto* s = ty.struct_("Data", str);
|
||||||
type::AccessControl ac(ast::AccessControl::kReadWrite, s);
|
type::AccessControl ac(ast::AccessControl::kReadWrite, s);
|
||||||
|
|
||||||
auto* data_var =
|
Global("data", ast::StorageClass::kStorage, &ac, nullptr,
|
||||||
Var("data", ast::StorageClass::kStorage, &ac, nullptr,
|
|
||||||
ast::VariableDecorationList{create<ast::BindingDecoration>(0),
|
ast::VariableDecorationList{create<ast::BindingDecoration>(0),
|
||||||
create<ast::GroupDecoration>(0)});
|
create<ast::GroupDecoration>(0)});
|
||||||
|
|
||||||
AST().AddConstructedType(s);
|
AST().AddConstructedType(s);
|
||||||
td.RegisterVariableForTesting(data_var);
|
|
||||||
AST().AddGlobalVariable(data_var);
|
|
||||||
|
|
||||||
{
|
{
|
||||||
auto* var = Var("v", ast::StorageClass::kFunction, ty.f32(),
|
auto* var = Var("v", ast::StorageClass::kFunction, ty.f32(),
|
||||||
|
|
|
@ -53,7 +53,7 @@ TEST_P(MslImportData_SingleParamTest, FloatScalar) {
|
||||||
auto* call = Call(param.name, 1.f);
|
auto* call = Call(param.name, 1.f);
|
||||||
|
|
||||||
// The call type determination will set the intrinsic data for the ident
|
// The call type determination will set the intrinsic data for the ident
|
||||||
ASSERT_TRUE(td.DetermineResultType(call)) << td.error();
|
WrapInFunction(call);
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
|
@ -89,7 +89,7 @@ INSTANTIATE_TEST_SUITE_P(MslGeneratorImplTest,
|
||||||
|
|
||||||
TEST_F(MslGeneratorImplTest, MslImportData_SingleParamTest_IntScalar) {
|
TEST_F(MslGeneratorImplTest, MslImportData_SingleParamTest_IntScalar) {
|
||||||
auto* expr = Call("abs", 1);
|
auto* expr = Call("abs", 1);
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
WrapInFunction(expr);
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
|
@ -102,7 +102,7 @@ TEST_P(MslImportData_DualParamTest, FloatScalar) {
|
||||||
auto param = GetParam();
|
auto param = GetParam();
|
||||||
auto* expr = Call(param.name, 1.0f, 2.0f);
|
auto* expr = Call(param.name, 1.0f, 2.0f);
|
||||||
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
WrapInFunction(expr);
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
|
@ -126,7 +126,7 @@ TEST_P(MslImportData_DualParam_VectorTest, FloatVector) {
|
||||||
|
|
||||||
auto* expr =
|
auto* expr =
|
||||||
Call(param.name, vec3<f32>(1.f, 2.f, 3.f), vec3<f32>(4.f, 5.f, 6.f));
|
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();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
|
@ -144,7 +144,7 @@ TEST_P(MslImportData_DualParam_Int_Test, IntScalar) {
|
||||||
auto param = GetParam();
|
auto param = GetParam();
|
||||||
|
|
||||||
auto* expr = Call(param.name, 1, 2);
|
auto* expr = Call(param.name, 1, 2);
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
WrapInFunction(expr);
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
|
@ -161,7 +161,7 @@ TEST_P(MslImportData_TripleParamTest, FloatScalar) {
|
||||||
auto param = GetParam();
|
auto param = GetParam();
|
||||||
|
|
||||||
auto* expr = Call(param.name, 1.f, 2.f, 3.f);
|
auto* expr = Call(param.name, 1.f, 2.f, 3.f);
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
WrapInFunction(expr);
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
|
@ -183,7 +183,7 @@ TEST_P(MslImportData_TripleParam_Int_Test, IntScalar) {
|
||||||
auto param = GetParam();
|
auto param = GetParam();
|
||||||
|
|
||||||
auto* expr = Call(param.name, 1, 2, 3);
|
auto* expr = Call(param.name, 1, 2, 3);
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
WrapInFunction(expr);
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
|
@ -197,14 +197,11 @@ INSTANTIATE_TEST_SUITE_P(MslGeneratorImplTest,
|
||||||
MslImportData{"clamp", "clamp"}));
|
MslImportData{"clamp", "clamp"}));
|
||||||
|
|
||||||
TEST_F(MslGeneratorImplTest, MslImportData_Determinant) {
|
TEST_F(MslGeneratorImplTest, MslImportData_Determinant) {
|
||||||
auto* var = Var("var", ast::StorageClass::kFunction, ty.mat3x3<f32>());
|
Global("var", ast::StorageClass::kFunction, ty.mat3x3<f32>());
|
||||||
AST().AddGlobalVariable(var);
|
|
||||||
|
|
||||||
auto* expr = Call("determinant", "var");
|
auto* expr = Call("determinant", "var");
|
||||||
|
|
||||||
// Register the global
|
WrapInFunction(expr);
|
||||||
ASSERT_TRUE(td.Determine()) << td.error();
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
|
|
|
@ -158,24 +158,17 @@ TEST_P(MslIntrinsicTest, Emit) {
|
||||||
|
|
||||||
auto* call = GenerateCall(param.intrinsic, param.type, this);
|
auto* call = GenerateCall(param.intrinsic, param.type, this);
|
||||||
ASSERT_NE(nullptr, call) << "Unhandled intrinsic";
|
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();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
EXPECT_EQ(
|
EXPECT_EQ(
|
||||||
|
@ -270,15 +263,11 @@ INSTANTIATE_TEST_SUITE_P(
|
||||||
"metal::trunc"}));
|
"metal::trunc"}));
|
||||||
|
|
||||||
TEST_F(MslGeneratorImplTest, Intrinsic_Call) {
|
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* call = Call("dot", "param1", "param2");
|
||||||
|
WrapInFunction(call);
|
||||||
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();
|
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
|
|
|
@ -305,12 +305,7 @@ std::string expected_texture_overload(
|
||||||
} // NOLINT - Ignore the length of this function
|
} // NOLINT - Ignore the length of this function
|
||||||
|
|
||||||
class MslGeneratorIntrinsicTextureTest
|
class MslGeneratorIntrinsicTextureTest
|
||||||
: public TestParamHelper<ast::intrinsic::test::TextureOverloadCase> {
|
: public TestParamHelper<ast::intrinsic::test::TextureOverloadCase> {};
|
||||||
protected:
|
|
||||||
void OnVariableBuilt(ast::Variable* var) override {
|
|
||||||
td.RegisterVariableForTesting(var);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
TEST_P(MslGeneratorIntrinsicTextureTest, Call) {
|
TEST_P(MslGeneratorIntrinsicTextureTest, Call) {
|
||||||
auto param = GetParam();
|
auto param = GetParam();
|
||||||
|
@ -320,9 +315,7 @@ TEST_P(MslGeneratorIntrinsicTextureTest, Call) {
|
||||||
|
|
||||||
auto* call =
|
auto* call =
|
||||||
create<ast::CallExpression>(Expr(param.function), param.args(this));
|
create<ast::CallExpression>(Expr(param.function), param.args(this));
|
||||||
|
WrapInFunction(call);
|
||||||
ASSERT_TRUE(td.Determine()) << td.error();
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(call)) << td.error();
|
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,7 @@ TEST_F(MslGeneratorImplTest, Emit_Loop) {
|
||||||
create<ast::DiscardStatement>(),
|
create<ast::DiscardStatement>(),
|
||||||
});
|
});
|
||||||
auto* l = create<ast::LoopStatement>(body, nullptr);
|
auto* l = create<ast::LoopStatement>(body, nullptr);
|
||||||
|
WrapInFunction(l);
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
|
@ -60,6 +61,7 @@ TEST_F(MslGeneratorImplTest, Emit_LoopWithContinuing) {
|
||||||
create<ast::ReturnStatement>(),
|
create<ast::ReturnStatement>(),
|
||||||
});
|
});
|
||||||
auto* l = create<ast::LoopStatement>(body, continuing);
|
auto* l = create<ast::LoopStatement>(body, continuing);
|
||||||
|
WrapInFunction(l);
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
|
@ -98,6 +100,7 @@ TEST_F(MslGeneratorImplTest, Emit_LoopNestedWithContinuing) {
|
||||||
});
|
});
|
||||||
|
|
||||||
auto* outer = create<ast::LoopStatement>(body, continuing);
|
auto* outer = create<ast::LoopStatement>(body, continuing);
|
||||||
|
WrapInFunction(outer);
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
|
@ -163,6 +166,7 @@ TEST_F(MslGeneratorImplTest, Emit_LoopWithVarUsedInContinuing) {
|
||||||
});
|
});
|
||||||
|
|
||||||
auto* outer = create<ast::LoopStatement>(body, continuing);
|
auto* outer = create<ast::LoopStatement>(body, continuing);
|
||||||
|
WrapInFunction(outer);
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,7 @@ using MslGeneratorImplTest = TestHelper;
|
||||||
|
|
||||||
TEST_F(MslGeneratorImplTest, EmitExpression_MemberAccessor) {
|
TEST_F(MslGeneratorImplTest, EmitExpression_MemberAccessor) {
|
||||||
auto* expr = MemberAccessor("str", "mem");
|
auto* expr = MemberAccessor("str", "mem");
|
||||||
|
WrapInFunction(expr);
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
|
@ -38,12 +39,10 @@ TEST_F(MslGeneratorImplTest, EmitExpression_MemberAccessor) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(MslGeneratorImplTest, EmitExpression_MemberAccessor_Swizzle_xyz) {
|
TEST_F(MslGeneratorImplTest, EmitExpression_MemberAccessor_Swizzle_xyz) {
|
||||||
auto* vec = Var("my_vec", ast::StorageClass::kPrivate, ty.vec4<f32>());
|
Global("my_vec", ast::StorageClass::kPrivate, ty.vec4<f32>());
|
||||||
|
|
||||||
td.RegisterVariableForTesting(vec);
|
|
||||||
|
|
||||||
auto* expr = MemberAccessor("my_vec", "xyz");
|
auto* expr = MemberAccessor("my_vec", "xyz");
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
WrapInFunction(expr);
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
ASSERT_TRUE(gen.EmitExpression(expr)) << gen.error();
|
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) {
|
TEST_F(MslGeneratorImplTest, EmitExpression_MemberAccessor_Swizzle_gbr) {
|
||||||
auto* vec = Var("my_vec", ast::StorageClass::kPrivate, ty.vec4<f32>());
|
Global("my_vec", ast::StorageClass::kPrivate, ty.vec4<f32>());
|
||||||
td.RegisterVariableForTesting(vec);
|
|
||||||
|
|
||||||
auto* expr = MemberAccessor("my_vec", "gbr");
|
auto* expr = MemberAccessor("my_vec", "gbr");
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
WrapInFunction(expr);
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
ASSERT_TRUE(gen.EmitExpression(expr)) << gen.error();
|
ASSERT_TRUE(gen.EmitExpression(expr)) << gen.error();
|
||||||
|
|
|
@ -421,16 +421,17 @@ using MslStorageTexturesTest = TestParamHelper<MslStorageTextureData>;
|
||||||
TEST_P(MslStorageTexturesTest, Emit) {
|
TEST_P(MslStorageTexturesTest, Emit) {
|
||||||
auto params = GetParam();
|
auto params = GetParam();
|
||||||
|
|
||||||
type::StorageTexture s(params.dim, type::ImageFormat::kR16Float);
|
auto* s =
|
||||||
type::AccessControl ac(params.ro ? ast::AccessControl::kReadOnly
|
create<type::StorageTexture>(params.dim, type::ImageFormat::kR16Float);
|
||||||
|
auto* ac =
|
||||||
|
create<type::AccessControl>(params.ro ? ast::AccessControl::kReadOnly
|
||||||
: ast::AccessControl::kWriteOnly,
|
: ast::AccessControl::kWriteOnly,
|
||||||
&s);
|
s);
|
||||||
|
Global("test_var", ast::StorageClass::kNone, ac);
|
||||||
ASSERT_TRUE(td.DetermineStorageTextureSubtype(&s)) << td.error();
|
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
ASSERT_TRUE(gen.EmitType(&ac, "")) << gen.error();
|
ASSERT_TRUE(gen.EmitType(ac, "")) << gen.error();
|
||||||
EXPECT_EQ(gen.result(), params.result);
|
EXPECT_EQ(gen.result(), params.result);
|
||||||
}
|
}
|
||||||
INSTANTIATE_TEST_SUITE_P(
|
INSTANTIATE_TEST_SUITE_P(
|
||||||
|
|
|
@ -43,6 +43,7 @@ using MslGeneratorImplTest = TestHelper;
|
||||||
TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement) {
|
TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement) {
|
||||||
auto* var = Var("a", ast::StorageClass::kNone, ty.f32());
|
auto* var = Var("a", ast::StorageClass::kNone, ty.f32());
|
||||||
auto* stmt = create<ast::VariableDeclStatement>(var);
|
auto* stmt = create<ast::VariableDeclStatement>(var);
|
||||||
|
WrapInFunction(stmt);
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
|
@ -55,6 +56,7 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement) {
|
||||||
TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Const) {
|
TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Const) {
|
||||||
auto* var = Const("a", ast::StorageClass::kNone, ty.f32());
|
auto* var = Const("a", ast::StorageClass::kNone, ty.f32());
|
||||||
auto* stmt = create<ast::VariableDeclStatement>(var);
|
auto* stmt = create<ast::VariableDeclStatement>(var);
|
||||||
|
WrapInFunction(stmt);
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
|
@ -69,6 +71,7 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Array) {
|
||||||
|
|
||||||
auto* var = Var("a", ast::StorageClass::kNone, &ary);
|
auto* var = Var("a", ast::StorageClass::kNone, &ary);
|
||||||
auto* stmt = create<ast::VariableDeclStatement>(var);
|
auto* stmt = create<ast::VariableDeclStatement>(var);
|
||||||
|
WrapInFunction(stmt);
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
|
@ -87,6 +90,7 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Struct) {
|
||||||
auto* s = ty.struct_("S", str);
|
auto* s = ty.struct_("S", str);
|
||||||
auto* var = Var("a", ast::StorageClass::kNone, s);
|
auto* var = Var("a", ast::StorageClass::kNone, s);
|
||||||
auto* stmt = create<ast::VariableDeclStatement>(var);
|
auto* stmt = create<ast::VariableDeclStatement>(var);
|
||||||
|
WrapInFunction(stmt);
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
|
@ -100,6 +104,7 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Struct) {
|
||||||
TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Vector) {
|
TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Vector) {
|
||||||
auto* var = Var("a", ast::StorageClass::kFunction, ty.vec2<f32>());
|
auto* var = Var("a", ast::StorageClass::kFunction, ty.vec2<f32>());
|
||||||
auto* stmt = create<ast::VariableDeclStatement>(var);
|
auto* stmt = create<ast::VariableDeclStatement>(var);
|
||||||
|
WrapInFunction(stmt);
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
|
@ -113,6 +118,7 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Matrix) {
|
||||||
auto* var = Var("a", ast::StorageClass::kFunction, ty.mat3x2<f32>());
|
auto* var = Var("a", ast::StorageClass::kFunction, ty.mat3x2<f32>());
|
||||||
|
|
||||||
auto* stmt = create<ast::VariableDeclStatement>(var);
|
auto* stmt = create<ast::VariableDeclStatement>(var);
|
||||||
|
WrapInFunction(stmt);
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
|
@ -125,6 +131,7 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Matrix) {
|
||||||
TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Private) {
|
TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Private) {
|
||||||
auto* var = Var("a", ast::StorageClass::kPrivate, ty.f32());
|
auto* var = Var("a", ast::StorageClass::kPrivate, ty.f32());
|
||||||
auto* stmt = create<ast::VariableDeclStatement>(var);
|
auto* stmt = create<ast::VariableDeclStatement>(var);
|
||||||
|
WrapInFunction(stmt);
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
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"),
|
auto* var = Var("a", ast::StorageClass::kNone, ty.f32(), Expr("initializer"),
|
||||||
ast::VariableDecorationList{});
|
ast::VariableDecorationList{});
|
||||||
auto* stmt = create<ast::VariableDeclStatement>(var);
|
auto* stmt = create<ast::VariableDeclStatement>(var);
|
||||||
|
WrapInFunction(stmt);
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
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,
|
auto* var = Var("a", ast::StorageClass::kNone, ty.vec3<f32>(), zero_vec,
|
||||||
ast::VariableDecorationList{});
|
ast::VariableDecorationList{});
|
||||||
auto* stmt = create<ast::VariableDeclStatement>(var);
|
auto* stmt = create<ast::VariableDeclStatement>(var);
|
||||||
|
WrapInFunction(stmt);
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,7 @@ namespace msl {
|
||||||
template <typename BASE>
|
template <typename BASE>
|
||||||
class TestHelperBase : public BASE, public ProgramBuilder {
|
class TestHelperBase : public BASE, public ProgramBuilder {
|
||||||
public:
|
public:
|
||||||
TestHelperBase() : td(this) {}
|
TestHelperBase() = default;
|
||||||
~TestHelperBase() = default;
|
~TestHelperBase() = default;
|
||||||
|
|
||||||
/// Builds and returns a GeneratorImpl from the program.
|
/// Builds and returns a GeneratorImpl from the program.
|
||||||
|
@ -48,8 +48,6 @@ class TestHelperBase : public BASE, public ProgramBuilder {
|
||||||
return *gen_;
|
return *gen_;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The type determiner
|
|
||||||
TypeDeterminer td;
|
|
||||||
/// The program built with a call to Build()
|
/// The program built with a call to Build()
|
||||||
std::unique_ptr<Program> program;
|
std::unique_ptr<Program> program;
|
||||||
|
|
||||||
|
|
|
@ -49,14 +49,13 @@ TEST_F(BuilderTest, ArrayAccessor) {
|
||||||
// vec3<f32> ary;
|
// vec3<f32> ary;
|
||||||
// ary[1] -> ptr<f32>
|
// 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* ary = Expr("ary");
|
||||||
auto* idx_expr = Expr(1);
|
auto* idx_expr = Expr(1);
|
||||||
|
|
||||||
auto* expr = IndexAccessor(ary, idx_expr);
|
auto* expr = IndexAccessor(ary, idx_expr);
|
||||||
td.RegisterVariableForTesting(var);
|
WrapInFunction(expr);
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -86,17 +85,14 @@ TEST_F(BuilderTest, Accessor_Array_LoadIndex) {
|
||||||
// idx : i32;
|
// idx : i32;
|
||||||
// ary[idx] -> ptr<f32>
|
// ary[idx] -> ptr<f32>
|
||||||
|
|
||||||
auto* var = Var("ary", ast::StorageClass::kFunction, ty.vec3<f32>());
|
auto* var = Global("ary", ast::StorageClass::kFunction, ty.vec3<f32>());
|
||||||
auto* idx = Var("idx", ast::StorageClass::kFunction, ty.i32());
|
auto* idx = Global("idx", ast::StorageClass::kFunction, ty.i32());
|
||||||
|
|
||||||
auto* ary = Expr("ary");
|
auto* ary = Expr("ary");
|
||||||
auto* idx_expr = Expr("idx");
|
auto* idx_expr = Expr("idx");
|
||||||
|
|
||||||
auto* expr = IndexAccessor(ary, idx_expr);
|
auto* expr = IndexAccessor(ary, idx_expr);
|
||||||
|
WrapInFunction(expr);
|
||||||
td.RegisterVariableForTesting(var);
|
|
||||||
td.RegisterVariableForTesting(idx);
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -129,14 +125,12 @@ TEST_F(BuilderTest, ArrayAccessor_Dynamic) {
|
||||||
// vec3<f32> ary;
|
// vec3<f32> ary;
|
||||||
// ary[1 + 2] -> ptr<f32>
|
// 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* ary = Expr("ary");
|
||||||
|
|
||||||
auto* expr = IndexAccessor(ary, Add(1, 2));
|
auto* expr = IndexAccessor(ary, Add(1, 2));
|
||||||
|
WrapInFunction(expr);
|
||||||
td.RegisterVariableForTesting(var);
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -169,12 +163,10 @@ TEST_F(BuilderTest, ArrayAccessor_MultiLevel) {
|
||||||
// ary = array<vec3<f32>, 4>
|
// ary = array<vec3<f32>, 4>
|
||||||
// ary[3][2];
|
// 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);
|
auto* expr = IndexAccessor(IndexAccessor("ary", 3), 2);
|
||||||
|
WrapInFunction(expr);
|
||||||
td.RegisterVariableForTesting(var);
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -209,12 +201,10 @@ TEST_F(BuilderTest, Accessor_ArrayWithSwizzle) {
|
||||||
// var a : array<vec3<f32>, 4>;
|
// var a : array<vec3<f32>, 4>;
|
||||||
// a[2].xy;
|
// 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");
|
auto* expr = MemberAccessor(IndexAccessor("ary", 2), "xy");
|
||||||
|
WrapInFunction(expr);
|
||||||
td.RegisterVariableForTesting(var);
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -257,12 +247,10 @@ TEST_F(BuilderTest, MemberAccessor) {
|
||||||
ast::StructDecorationList{});
|
ast::StructDecorationList{});
|
||||||
|
|
||||||
auto* s_type = ty.struct_("my_struct", s);
|
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");
|
auto* expr = MemberAccessor("ident", "b");
|
||||||
|
WrapInFunction(expr);
|
||||||
td.RegisterVariableForTesting(var);
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -307,11 +295,9 @@ TEST_F(BuilderTest, MemberAccessor_Nested) {
|
||||||
create<ast::Struct>(ast::StructMemberList{Member("inner", inner_struct)},
|
create<ast::Struct>(ast::StructMemberList{Member("inner", inner_struct)},
|
||||||
ast::StructDecorationList{}));
|
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");
|
auto* expr = MemberAccessor(MemberAccessor("ident", "inner"), "a");
|
||||||
|
WrapInFunction(expr);
|
||||||
td.RegisterVariableForTesting(var);
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -359,11 +345,9 @@ TEST_F(BuilderTest, MemberAccessor_Nested_WithAlias) {
|
||||||
create<ast::Struct>(ast::StructMemberList{Member("inner", alias)},
|
create<ast::Struct>(ast::StructMemberList{Member("inner", alias)},
|
||||||
ast::StructDecorationList{}));
|
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");
|
auto* expr = MemberAccessor(MemberAccessor("ident", "inner"), "a");
|
||||||
|
WrapInFunction(expr);
|
||||||
td.RegisterVariableForTesting(var);
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -409,12 +393,10 @@ TEST_F(BuilderTest, MemberAccessor_Nested_Assignment_LHS) {
|
||||||
create<ast::Struct>(ast::StructMemberList{Member("inner", inner_struct)},
|
create<ast::Struct>(ast::StructMemberList{Member("inner", inner_struct)},
|
||||||
ast::StructDecorationList{}));
|
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>(
|
auto* expr = create<ast::AssignmentStatement>(
|
||||||
MemberAccessor(MemberAccessor("ident", "inner"), "a"), Expr(2.0f));
|
MemberAccessor(MemberAccessor("ident", "inner"), "a"), Expr(2.0f));
|
||||||
|
WrapInFunction(expr);
|
||||||
td.RegisterVariableForTesting(var);
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -463,15 +445,12 @@ TEST_F(BuilderTest, MemberAccessor_Nested_Assignment_RHS) {
|
||||||
create<ast::Struct>(ast::StructMemberList{Member("inner", inner_struct)},
|
create<ast::Struct>(ast::StructMemberList{Member("inner", inner_struct)},
|
||||||
ast::StructDecorationList{}));
|
ast::StructDecorationList{}));
|
||||||
|
|
||||||
auto* var = Var("ident", ast::StorageClass::kFunction, s_type);
|
auto* var = Global("ident", ast::StorageClass::kFunction, s_type);
|
||||||
auto* store = Var("store", ast::StorageClass::kFunction, ty.f32());
|
auto* store = Global("store", ast::StorageClass::kFunction, ty.f32());
|
||||||
|
|
||||||
auto* rhs = MemberAccessor(MemberAccessor("ident", "inner"), "a");
|
auto* rhs = MemberAccessor(MemberAccessor("ident", "inner"), "a");
|
||||||
auto* expr = create<ast::AssignmentStatement>(Expr("store"), rhs);
|
auto* expr = create<ast::AssignmentStatement>(Expr("store"), rhs);
|
||||||
|
WrapInFunction(expr);
|
||||||
td.RegisterVariableForTesting(var);
|
|
||||||
td.RegisterVariableForTesting(store);
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -505,12 +484,10 @@ OpStore %7 %13
|
||||||
TEST_F(BuilderTest, MemberAccessor_Swizzle_Single) {
|
TEST_F(BuilderTest, MemberAccessor_Swizzle_Single) {
|
||||||
// ident.y
|
// 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");
|
auto* expr = MemberAccessor("ident", "y");
|
||||||
|
WrapInFunction(expr);
|
||||||
td.RegisterVariableForTesting(var);
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -538,12 +515,10 @@ TEST_F(BuilderTest, MemberAccessor_Swizzle_Single) {
|
||||||
TEST_F(BuilderTest, MemberAccessor_Swizzle_MultipleNames) {
|
TEST_F(BuilderTest, MemberAccessor_Swizzle_MultipleNames) {
|
||||||
// ident.yx
|
// 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");
|
auto* expr = MemberAccessor("ident", "yx");
|
||||||
|
WrapInFunction(expr);
|
||||||
td.RegisterVariableForTesting(var);
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -570,12 +545,10 @@ TEST_F(BuilderTest, MemberAccessor_Swizzle_MultipleNames) {
|
||||||
TEST_F(BuilderTest, MemberAccessor_Swizzle_of_Swizzle) {
|
TEST_F(BuilderTest, MemberAccessor_Swizzle_of_Swizzle) {
|
||||||
// ident.yxz.xz
|
// 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");
|
auto* expr = MemberAccessor(MemberAccessor("ident", "yxz"), "xz");
|
||||||
|
WrapInFunction(expr);
|
||||||
td.RegisterVariableForTesting(var);
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -603,12 +576,10 @@ TEST_F(BuilderTest, MemberAccessor_Swizzle_of_Swizzle) {
|
||||||
TEST_F(BuilderTest, MemberAccessor_Member_of_Swizzle) {
|
TEST_F(BuilderTest, MemberAccessor_Member_of_Swizzle) {
|
||||||
// ident.yxz.x
|
// 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");
|
auto* expr = MemberAccessor(MemberAccessor("ident", "yxz"), "x");
|
||||||
|
WrapInFunction(expr);
|
||||||
td.RegisterVariableForTesting(var);
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -635,12 +606,10 @@ TEST_F(BuilderTest, MemberAccessor_Member_of_Swizzle) {
|
||||||
TEST_F(BuilderTest, MemberAccessor_Array_of_Swizzle) {
|
TEST_F(BuilderTest, MemberAccessor_Array_of_Swizzle) {
|
||||||
// index.yxz[1]
|
// 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);
|
auto* expr = IndexAccessor(MemberAccessor("ident", "yxz"), 1);
|
||||||
|
WrapInFunction(expr);
|
||||||
td.RegisterVariableForTesting(var);
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -693,7 +662,7 @@ TEST_F(BuilderTest, Accessor_Mixed_ArrayAndMember) {
|
||||||
auto* a_type = ty.struct_("A", s);
|
auto* a_type = ty.struct_("A", s);
|
||||||
|
|
||||||
type::Array a_ary_type(a_type, 2, ast::ArrayDecorationList{});
|
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(
|
auto* expr = MemberAccessor(
|
||||||
MemberAccessor(
|
MemberAccessor(
|
||||||
MemberAccessor(
|
MemberAccessor(
|
||||||
|
@ -702,9 +671,7 @@ TEST_F(BuilderTest, Accessor_Mixed_ArrayAndMember) {
|
||||||
"bar"),
|
"bar"),
|
||||||
"baz"),
|
"baz"),
|
||||||
"yx");
|
"yx");
|
||||||
|
WrapInFunction(expr);
|
||||||
td.RegisterVariableForTesting(var);
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -751,16 +718,14 @@ TEST_F(BuilderTest, Accessor_Array_Of_Vec) {
|
||||||
|
|
||||||
type::Array arr(ty.vec2<f32>(), 3, ast::ArrayDecorationList{});
|
type::Array arr(ty.vec2<f32>(), 3, ast::ArrayDecorationList{});
|
||||||
|
|
||||||
auto* var = Const("pos", ast::StorageClass::kPrivate, &arr,
|
auto* var =
|
||||||
|
GlobalConst("pos", ast::StorageClass::kPrivate, &arr,
|
||||||
Construct(&arr, vec2<f32>(0.0f, 0.5f),
|
Construct(&arr, vec2<f32>(0.0f, 0.5f),
|
||||||
vec2<f32>(-0.5f, -0.5f), vec2<f32>(0.5f, -0.5f)),
|
vec2<f32>(-0.5f, -0.5f), vec2<f32>(0.5f, -0.5f)),
|
||||||
{});
|
ast::VariableDecorationList{});
|
||||||
|
|
||||||
auto* expr = IndexAccessor("pos", 1u);
|
auto* expr = IndexAccessor("pos", 1u);
|
||||||
|
WrapInFunction(expr);
|
||||||
td.RegisterVariableForTesting(var);
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(var->constructor())) << td.error();
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -798,14 +763,11 @@ TEST_F(BuilderTest, Accessor_Const_Vec) {
|
||||||
// const pos : vec2<f32> = vec2<f32>(0.0, 0.5);
|
// const pos : vec2<f32> = vec2<f32>(0.0, 0.5);
|
||||||
// pos[1]
|
// pos[1]
|
||||||
|
|
||||||
auto* var = Const("pos", ast::StorageClass::kPrivate, ty.vec2<f32>(),
|
auto* var = GlobalConst("pos", ast::StorageClass::kPrivate, ty.vec2<f32>(),
|
||||||
vec2<f32>(0.0f, 0.5f), {});
|
vec2<f32>(0.0f, 0.5f), ast::VariableDecorationList{});
|
||||||
|
|
||||||
auto* expr = IndexAccessor("pos", 1u);
|
auto* expr = IndexAccessor("pos", 1u);
|
||||||
|
WrapInFunction(expr);
|
||||||
td.RegisterVariableForTesting(var);
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(var->constructor())) << td.error();
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
|
|
@ -42,12 +42,11 @@ namespace {
|
||||||
using BuilderTest = TestHelper;
|
using BuilderTest = TestHelper;
|
||||||
|
|
||||||
TEST_F(BuilderTest, Assign_Var) {
|
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));
|
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();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -71,12 +70,11 @@ TEST_F(BuilderTest, Assign_Var) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(BuilderTest, Assign_Var_OutsideFunction_IsError) {
|
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));
|
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();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -91,14 +89,12 @@ TEST_F(BuilderTest, Assign_Var_OutsideFunction_IsError) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(BuilderTest, Assign_Var_ZeroConstructor) {
|
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* val = vec3<f32>();
|
||||||
auto* assign = create<ast::AssignmentStatement>(Expr("var"), val);
|
auto* assign = create<ast::AssignmentStatement>(Expr("var"), val);
|
||||||
|
|
||||||
td.RegisterVariableForTesting(v);
|
WrapInFunction(assign);
|
||||||
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(assign)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -124,11 +120,11 @@ TEST_F(BuilderTest, Assign_Var_ZeroConstructor) {
|
||||||
TEST_F(BuilderTest, Assign_Var_Complex_ConstructorWithExtract) {
|
TEST_F(BuilderTest, Assign_Var_Complex_ConstructorWithExtract) {
|
||||||
auto* init = vec3<f32>(vec2<f32>(1.f, 2.f), 3.f);
|
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);
|
auto* assign = create<ast::AssignmentStatement>(Expr("var"), init);
|
||||||
|
|
||||||
td.RegisterVariableForTesting(v);
|
WrapInFunction(assign);
|
||||||
ASSERT_TRUE(td.DetermineResultType(assign)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -161,11 +157,11 @@ OpStore %1 %13
|
||||||
TEST_F(BuilderTest, Assign_Var_Complex_Constructor) {
|
TEST_F(BuilderTest, Assign_Var_Complex_Constructor) {
|
||||||
auto* init = vec3<f32>(1.f, 2.f, 3.f);
|
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);
|
auto* assign = create<ast::AssignmentStatement>(Expr("var"), init);
|
||||||
|
|
||||||
td.RegisterVariableForTesting(v);
|
WrapInFunction(assign);
|
||||||
ASSERT_TRUE(td.DetermineResultType(assign)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -204,13 +200,12 @@ TEST_F(BuilderTest, Assign_StructMember) {
|
||||||
ast::StructDecorationList{});
|
ast::StructDecorationList{});
|
||||||
|
|
||||||
auto* s_type = ty.struct_("my_struct", s);
|
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 =
|
auto* assign =
|
||||||
create<ast::AssignmentStatement>(MemberAccessor("ident", "b"), Expr(4.f));
|
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();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -238,14 +233,12 @@ OpStore %8 %9
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(BuilderTest, Assign_Vector) {
|
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* val = vec3<f32>(1.f, 1.f, 3.f);
|
||||||
|
|
||||||
auto* assign = create<ast::AssignmentStatement>(Expr("var"), val);
|
auto* assign = create<ast::AssignmentStatement>(Expr("var"), val);
|
||||||
td.RegisterVariableForTesting(v);
|
|
||||||
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(assign)) << td.error();
|
WrapInFunction(assign);
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -274,13 +267,12 @@ TEST_F(BuilderTest, Assign_Vector) {
|
||||||
TEST_F(BuilderTest, Assign_Vector_MemberByName) {
|
TEST_F(BuilderTest, Assign_Vector_MemberByName) {
|
||||||
// var.y = 1
|
// 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 =
|
auto* assign =
|
||||||
create<ast::AssignmentStatement>(MemberAccessor("var", "y"), Expr(1.f));
|
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();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -311,13 +303,12 @@ OpStore %9 %10
|
||||||
TEST_F(BuilderTest, Assign_Vector_MemberByIndex) {
|
TEST_F(BuilderTest, Assign_Vector_MemberByIndex) {
|
||||||
// var[1] = 1
|
// 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 =
|
auto* assign =
|
||||||
create<ast::AssignmentStatement>(IndexAccessor("var", 1), Expr(1.f));
|
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();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
|
|
@ -59,7 +59,7 @@ TEST_P(BinaryArithSignedIntegerTest, Scalar) {
|
||||||
|
|
||||||
auto* expr = create<ast::BinaryExpression>(param.op, lhs, rhs);
|
auto* expr = create<ast::BinaryExpression>(param.op, lhs, rhs);
|
||||||
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
WrapInFunction(expr);
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -82,7 +82,7 @@ TEST_P(BinaryArithSignedIntegerTest, Vector) {
|
||||||
|
|
||||||
auto* expr = create<ast::BinaryExpression>(param.op, lhs, rhs);
|
auto* expr = create<ast::BinaryExpression>(param.op, lhs, rhs);
|
||||||
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
WrapInFunction(expr);
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -100,12 +100,11 @@ TEST_P(BinaryArithSignedIntegerTest, Vector) {
|
||||||
TEST_P(BinaryArithSignedIntegerTest, Scalar_Loads) {
|
TEST_P(BinaryArithSignedIntegerTest, Scalar_Loads) {
|
||||||
auto param = GetParam();
|
auto param = GetParam();
|
||||||
|
|
||||||
auto* var = Var("param", ast::StorageClass::kFunction, ty.i32());
|
auto* var = Global("param", ast::StorageClass::kFunction, ty.i32());
|
||||||
auto* expr =
|
auto* expr =
|
||||||
create<ast::BinaryExpression>(param.op, Expr("param"), Expr("param"));
|
create<ast::BinaryExpression>(param.op, Expr("param"), Expr("param"));
|
||||||
|
|
||||||
td.RegisterVariableForTesting(var);
|
WrapInFunction(expr);
|
||||||
EXPECT_TRUE(td.DetermineResultType(expr)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -152,7 +151,7 @@ TEST_P(BinaryArithUnsignedIntegerTest, Scalar) {
|
||||||
|
|
||||||
auto* expr = create<ast::BinaryExpression>(param.op, lhs, rhs);
|
auto* expr = create<ast::BinaryExpression>(param.op, lhs, rhs);
|
||||||
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
WrapInFunction(expr);
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -174,7 +173,7 @@ TEST_P(BinaryArithUnsignedIntegerTest, Vector) {
|
||||||
|
|
||||||
auto* expr = create<ast::BinaryExpression>(param.op, lhs, rhs);
|
auto* expr = create<ast::BinaryExpression>(param.op, lhs, rhs);
|
||||||
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
WrapInFunction(expr);
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -213,7 +212,8 @@ TEST_P(BinaryArithFloatTest, Scalar) {
|
||||||
|
|
||||||
auto* expr = create<ast::BinaryExpression>(param.op, lhs, rhs);
|
auto* expr = create<ast::BinaryExpression>(param.op, lhs, rhs);
|
||||||
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
WrapInFunction(expr);
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
b.push_function(Function{});
|
b.push_function(Function{});
|
||||||
|
@ -235,7 +235,7 @@ TEST_P(BinaryArithFloatTest, Vector) {
|
||||||
|
|
||||||
auto* expr = create<ast::BinaryExpression>(param.op, lhs, rhs);
|
auto* expr = create<ast::BinaryExpression>(param.op, lhs, rhs);
|
||||||
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
WrapInFunction(expr);
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -268,7 +268,7 @@ TEST_P(BinaryCompareUnsignedIntegerTest, Scalar) {
|
||||||
|
|
||||||
auto* expr = create<ast::BinaryExpression>(param.op, lhs, rhs);
|
auto* expr = create<ast::BinaryExpression>(param.op, lhs, rhs);
|
||||||
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
WrapInFunction(expr);
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -292,7 +292,7 @@ TEST_P(BinaryCompareUnsignedIntegerTest, Vector) {
|
||||||
|
|
||||||
auto* expr = create<ast::BinaryExpression>(param.op, lhs, rhs);
|
auto* expr = create<ast::BinaryExpression>(param.op, lhs, rhs);
|
||||||
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
WrapInFunction(expr);
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -329,7 +329,7 @@ TEST_P(BinaryCompareSignedIntegerTest, Scalar) {
|
||||||
|
|
||||||
auto* expr = create<ast::BinaryExpression>(param.op, lhs, rhs);
|
auto* expr = create<ast::BinaryExpression>(param.op, lhs, rhs);
|
||||||
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
WrapInFunction(expr);
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -353,7 +353,7 @@ TEST_P(BinaryCompareSignedIntegerTest, Vector) {
|
||||||
|
|
||||||
auto* expr = create<ast::BinaryExpression>(param.op, lhs, rhs);
|
auto* expr = create<ast::BinaryExpression>(param.op, lhs, rhs);
|
||||||
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
WrapInFunction(expr);
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -390,7 +390,7 @@ TEST_P(BinaryCompareFloatTest, Scalar) {
|
||||||
|
|
||||||
auto* expr = create<ast::BinaryExpression>(param.op, lhs, rhs);
|
auto* expr = create<ast::BinaryExpression>(param.op, lhs, rhs);
|
||||||
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
WrapInFunction(expr);
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -414,7 +414,7 @@ TEST_P(BinaryCompareFloatTest, Vector) {
|
||||||
|
|
||||||
auto* expr = create<ast::BinaryExpression>(param.op, lhs, rhs);
|
auto* expr = create<ast::BinaryExpression>(param.op, lhs, rhs);
|
||||||
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
WrapInFunction(expr);
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -449,7 +449,7 @@ TEST_F(BuilderTest, Binary_Multiply_VectorScalar) {
|
||||||
auto* expr =
|
auto* expr =
|
||||||
create<ast::BinaryExpression>(ast::BinaryOp::kMultiply, lhs, rhs);
|
create<ast::BinaryExpression>(ast::BinaryOp::kMultiply, lhs, rhs);
|
||||||
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
WrapInFunction(expr);
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -473,7 +473,7 @@ TEST_F(BuilderTest, Binary_Multiply_ScalarVector) {
|
||||||
auto* expr =
|
auto* expr =
|
||||||
create<ast::BinaryExpression>(ast::BinaryOp::kMultiply, lhs, rhs);
|
create<ast::BinaryExpression>(ast::BinaryOp::kMultiply, lhs, rhs);
|
||||||
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
WrapInFunction(expr);
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -491,12 +491,12 @@ TEST_F(BuilderTest, Binary_Multiply_ScalarVector) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(BuilderTest, Binary_Multiply_MatrixScalar) {
|
TEST_F(BuilderTest, Binary_Multiply_MatrixScalar) {
|
||||||
auto* var = Var("mat", ast::StorageClass::kFunction, ty.mat3x3<f32>());
|
auto* var = Global("mat", ast::StorageClass::kFunction, ty.mat3x3<f32>());
|
||||||
td.RegisterVariableForTesting(var);
|
|
||||||
|
|
||||||
auto* expr = create<ast::BinaryExpression>(ast::BinaryOp::kMultiply,
|
auto* expr = create<ast::BinaryExpression>(ast::BinaryOp::kMultiply,
|
||||||
Expr("mat"), Expr(1.f));
|
Expr("mat"), Expr(1.f));
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
|
||||||
|
WrapInFunction(expr);
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -519,13 +519,12 @@ TEST_F(BuilderTest, Binary_Multiply_MatrixScalar) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(BuilderTest, Binary_Multiply_ScalarMatrix) {
|
TEST_F(BuilderTest, Binary_Multiply_ScalarMatrix) {
|
||||||
auto* var = Var("mat", ast::StorageClass::kFunction, ty.mat3x3<f32>());
|
auto* var = Global("mat", ast::StorageClass::kFunction, ty.mat3x3<f32>());
|
||||||
td.RegisterVariableForTesting(var);
|
|
||||||
|
|
||||||
auto* expr = create<ast::BinaryExpression>(ast::BinaryOp::kMultiply,
|
auto* expr = create<ast::BinaryExpression>(ast::BinaryOp::kMultiply,
|
||||||
Expr(1.f), Expr("mat"));
|
Expr(1.f), Expr("mat"));
|
||||||
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
WrapInFunction(expr);
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -548,15 +547,13 @@ TEST_F(BuilderTest, Binary_Multiply_ScalarMatrix) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(BuilderTest, Binary_Multiply_MatrixVector) {
|
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);
|
auto* rhs = vec3<f32>(1.f, 1.f, 1.f);
|
||||||
|
|
||||||
td.RegisterVariableForTesting(var);
|
|
||||||
|
|
||||||
auto* expr =
|
auto* expr =
|
||||||
create<ast::BinaryExpression>(ast::BinaryOp::kMultiply, Expr("mat"), rhs);
|
create<ast::BinaryExpression>(ast::BinaryOp::kMultiply, Expr("mat"), rhs);
|
||||||
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
WrapInFunction(expr);
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -580,15 +577,13 @@ TEST_F(BuilderTest, Binary_Multiply_MatrixVector) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(BuilderTest, Binary_Multiply_VectorMatrix) {
|
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);
|
auto* lhs = vec3<f32>(1.f, 1.f, 1.f);
|
||||||
|
|
||||||
td.RegisterVariableForTesting(var);
|
|
||||||
|
|
||||||
auto* expr =
|
auto* expr =
|
||||||
create<ast::BinaryExpression>(ast::BinaryOp::kMultiply, lhs, Expr("mat"));
|
create<ast::BinaryExpression>(ast::BinaryOp::kMultiply, lhs, Expr("mat"));
|
||||||
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
WrapInFunction(expr);
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -612,13 +607,12 @@ TEST_F(BuilderTest, Binary_Multiply_VectorMatrix) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(BuilderTest, Binary_Multiply_MatrixMatrix) {
|
TEST_F(BuilderTest, Binary_Multiply_MatrixMatrix) {
|
||||||
auto* var = Var("mat", ast::StorageClass::kFunction, ty.mat3x3<f32>());
|
auto* var = Global("mat", ast::StorageClass::kFunction, ty.mat3x3<f32>());
|
||||||
td.RegisterVariableForTesting(var);
|
|
||||||
|
|
||||||
auto* expr = create<ast::BinaryExpression>(ast::BinaryOp::kMultiply,
|
auto* expr = create<ast::BinaryExpression>(ast::BinaryOp::kMultiply,
|
||||||
Expr("mat"), Expr("mat"));
|
Expr("mat"), Expr("mat"));
|
||||||
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
WrapInFunction(expr);
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -650,7 +644,7 @@ TEST_F(BuilderTest, Binary_LogicalAnd) {
|
||||||
auto* expr =
|
auto* expr =
|
||||||
create<ast::BinaryExpression>(ast::BinaryOp::kLogicalAnd, lhs, rhs);
|
create<ast::BinaryExpression>(ast::BinaryOp::kLogicalAnd, lhs, rhs);
|
||||||
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
WrapInFunction(expr);
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -680,18 +674,15 @@ OpBranch %7
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(BuilderTest, Binary_LogicalAnd_WithLoads) {
|
TEST_F(BuilderTest, Binary_LogicalAnd_WithLoads) {
|
||||||
auto* a_var = Var("a", ast::StorageClass::kFunction, ty.bool_(), Expr(true),
|
auto* a_var = Global("a", ast::StorageClass::kFunction, ty.bool_(),
|
||||||
ast::VariableDecorationList{});
|
Expr(true), ast::VariableDecorationList{});
|
||||||
auto* b_var = Var("b", ast::StorageClass::kFunction, ty.bool_(), Expr(false),
|
auto* b_var = Global("b", ast::StorageClass::kFunction, ty.bool_(),
|
||||||
ast::VariableDecorationList{});
|
Expr(false), ast::VariableDecorationList{});
|
||||||
|
|
||||||
td.RegisterVariableForTesting(a_var);
|
|
||||||
td.RegisterVariableForTesting(b_var);
|
|
||||||
|
|
||||||
auto* expr = create<ast::BinaryExpression>(ast::BinaryOp::kLogicalAnd,
|
auto* expr = create<ast::BinaryExpression>(ast::BinaryOp::kLogicalAnd,
|
||||||
Expr("a"), Expr("b"));
|
Expr("a"), Expr("b"));
|
||||||
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
WrapInFunction(expr);
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -733,7 +724,7 @@ TEST_F(BuilderTest, Binary_logicalOr_Nested_LogicalAnd) {
|
||||||
auto* expr = create<ast::BinaryExpression>(ast::BinaryOp::kLogicalOr,
|
auto* expr = create<ast::BinaryExpression>(ast::BinaryOp::kLogicalOr,
|
||||||
Expr(true), logical_and_expr);
|
Expr(true), logical_and_expr);
|
||||||
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
WrapInFunction(expr);
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -773,7 +764,7 @@ TEST_F(BuilderTest, Binary_logicalAnd_Nested_LogicalOr) {
|
||||||
auto* expr = create<ast::BinaryExpression>(ast::BinaryOp::kLogicalAnd,
|
auto* expr = create<ast::BinaryExpression>(ast::BinaryOp::kLogicalAnd,
|
||||||
Expr(true), logical_or_expr);
|
Expr(true), logical_or_expr);
|
||||||
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
WrapInFunction(expr);
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -812,7 +803,7 @@ TEST_F(BuilderTest, Binary_LogicalOr) {
|
||||||
auto* expr =
|
auto* expr =
|
||||||
create<ast::BinaryExpression>(ast::BinaryOp::kLogicalOr, lhs, rhs);
|
create<ast::BinaryExpression>(ast::BinaryOp::kLogicalOr, lhs, rhs);
|
||||||
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
WrapInFunction(expr);
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -842,18 +833,15 @@ OpBranch %7
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(BuilderTest, Binary_LogicalOr_WithLoads) {
|
TEST_F(BuilderTest, Binary_LogicalOr_WithLoads) {
|
||||||
auto* a_var = Var("a", ast::StorageClass::kFunction, ty.bool_(), Expr(true),
|
auto* a_var = Global("a", ast::StorageClass::kFunction, ty.bool_(),
|
||||||
ast::VariableDecorationList{});
|
Expr(true), ast::VariableDecorationList{});
|
||||||
auto* b_var = Var("b", ast::StorageClass::kFunction, ty.bool_(), Expr(false),
|
auto* b_var = Global("b", ast::StorageClass::kFunction, ty.bool_(),
|
||||||
ast::VariableDecorationList{});
|
Expr(false), ast::VariableDecorationList{});
|
||||||
|
|
||||||
td.RegisterVariableForTesting(a_var);
|
|
||||||
td.RegisterVariableForTesting(b_var);
|
|
||||||
|
|
||||||
auto* expr = create<ast::BinaryExpression>(ast::BinaryOp::kLogicalOr,
|
auto* expr = create<ast::BinaryExpression>(ast::BinaryOp::kLogicalOr,
|
||||||
Expr("a"), Expr("b"));
|
Expr("a"), Expr("b"));
|
||||||
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
WrapInFunction(expr);
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,7 @@ using BuilderTest = TestHelper;
|
||||||
TEST_F(BuilderTest, Bitcast) {
|
TEST_F(BuilderTest, Bitcast) {
|
||||||
auto* bitcast = create<ast::BitcastExpression>(ty.u32(), Expr(2.4f));
|
auto* bitcast = create<ast::BitcastExpression>(ty.u32(), Expr(2.4f));
|
||||||
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(bitcast)) << td.error();
|
WrapInFunction(bitcast);
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ TEST_F(BuilderTest, Bitcast) {
|
||||||
TEST_F(BuilderTest, Bitcast_DuplicateType) {
|
TEST_F(BuilderTest, Bitcast_DuplicateType) {
|
||||||
auto* bitcast = create<ast::BitcastExpression>(ty.f32(), Expr(2.4f));
|
auto* bitcast = create<ast::BitcastExpression>(ty.f32(), Expr(2.4f));
|
||||||
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(bitcast)) << td.error();
|
WrapInFunction(bitcast);
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
|
|
@ -47,7 +47,7 @@ TEST_F(BuilderTest, Block) {
|
||||||
create<ast::AssignmentStatement>(Expr("var"), Expr(1.f)), inner,
|
create<ast::AssignmentStatement>(Expr("var"), Expr(1.f)), inner,
|
||||||
create<ast::AssignmentStatement>(Expr("var"), Expr(3.f))});
|
create<ast::AssignmentStatement>(Expr("var"), Expr(3.f))});
|
||||||
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(outer)) << td.error();
|
WrapInFunction(outer);
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
|
|
@ -53,9 +53,8 @@ TEST_F(BuilderTest, Expression_Call) {
|
||||||
ast::FunctionDecorationList{});
|
ast::FunctionDecorationList{});
|
||||||
|
|
||||||
auto* expr = Call("a_func", 1.f, 1.f);
|
auto* expr = Call("a_func", 1.f, 1.f);
|
||||||
ASSERT_TRUE(td.DetermineFunction(func)) << td.error();
|
|
||||||
ASSERT_TRUE(td.DetermineFunction(a_func)) << td.error();
|
WrapInFunction(expr);
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
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));
|
auto* expr = create<ast::CallStatement>(Call("a_func", 1.f, 1.f));
|
||||||
|
|
||||||
ASSERT_TRUE(td.DetermineFunction(func)) << td.error();
|
WrapInFunction(expr);
|
||||||
ASSERT_TRUE(td.DetermineFunction(a_func)) << td.error();
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
|
|
@ -64,8 +64,7 @@ TEST_F(SpvBuilderConstructorTest, Const) {
|
||||||
|
|
||||||
TEST_F(SpvBuilderConstructorTest, Type_WithCasts_OutsideFunction_IsError) {
|
TEST_F(SpvBuilderConstructorTest, Type_WithCasts_OutsideFunction_IsError) {
|
||||||
auto* t = Construct<f32>(Construct<u32>(1));
|
auto* t = Construct<f32>(Construct<u32>(1));
|
||||||
|
WrapInFunction(t);
|
||||||
EXPECT_TRUE(td.DetermineResultType(t)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -78,8 +77,7 @@ TEST_F(SpvBuilderConstructorTest, Type_WithCasts_OutsideFunction_IsError) {
|
||||||
|
|
||||||
TEST_F(SpvBuilderConstructorTest, Type) {
|
TEST_F(SpvBuilderConstructorTest, Type) {
|
||||||
auto* t = vec3<f32>(1.0f, 1.0f, 3.0f);
|
auto* t = vec3<f32>(1.0f, 1.0f, 3.0f);
|
||||||
|
WrapInFunction(t);
|
||||||
EXPECT_TRUE(td.DetermineResultType(t)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -96,8 +94,7 @@ TEST_F(SpvBuilderConstructorTest, Type) {
|
||||||
|
|
||||||
TEST_F(SpvBuilderConstructorTest, Type_WithCasts) {
|
TEST_F(SpvBuilderConstructorTest, Type_WithCasts) {
|
||||||
auto* t = vec2<f32>(Construct<f32>(1), Construct<f32>(1));
|
auto* t = vec2<f32>(Construct<f32>(1), Construct<f32>(1));
|
||||||
|
WrapInFunction(t);
|
||||||
EXPECT_TRUE(td.DetermineResultType(t)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -124,8 +121,7 @@ TEST_F(SpvBuilderConstructorTest, Type_WithAlias) {
|
||||||
|
|
||||||
auto* alias = ty.alias("Int", ty.i32());
|
auto* alias = ty.alias("Int", ty.i32());
|
||||||
auto* cast = Construct(alias, 2.3f);
|
auto* cast = Construct(alias, 2.3f);
|
||||||
|
WrapInFunction(cast);
|
||||||
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -142,11 +138,10 @@ TEST_F(SpvBuilderConstructorTest, Type_WithAlias) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(SpvBuilderConstructorTest, Type_IdentifierExpression_Param) {
|
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");
|
auto* t = vec2<f32>(1.0f, "ident");
|
||||||
|
WrapInFunction(t);
|
||||||
EXPECT_TRUE(td.DetermineResultType(t)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -174,8 +169,7 @@ TEST_F(SpvBuilderConstructorTest, Type_IdentifierExpression_Param) {
|
||||||
|
|
||||||
TEST_F(SpvBuilderConstructorTest, Vector_Bitcast_Params) {
|
TEST_F(SpvBuilderConstructorTest, Vector_Bitcast_Params) {
|
||||||
auto* t = vec2<u32>(1, 1);
|
auto* t = vec2<u32>(1, 1);
|
||||||
|
WrapInFunction(t);
|
||||||
EXPECT_TRUE(td.DetermineResultType(t)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -202,8 +196,7 @@ TEST_F(SpvBuilderConstructorTest, Type_NonConst_Value_Fails) {
|
||||||
Expr(3.0f));
|
Expr(3.0f));
|
||||||
|
|
||||||
auto* t = vec2<f32>(1.0f, rel);
|
auto* t = vec2<f32>(1.0f, rel);
|
||||||
|
WrapInFunction(t);
|
||||||
EXPECT_TRUE(td.DetermineResultType(t)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -214,8 +207,7 @@ TEST_F(SpvBuilderConstructorTest, Type_NonConst_Value_Fails) {
|
||||||
|
|
||||||
TEST_F(SpvBuilderConstructorTest, Type_Bool_With_Bool) {
|
TEST_F(SpvBuilderConstructorTest, Type_Bool_With_Bool) {
|
||||||
auto* cast = Construct<bool>(true);
|
auto* cast = Construct<bool>(true);
|
||||||
|
WrapInFunction(cast);
|
||||||
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -232,8 +224,7 @@ TEST_F(SpvBuilderConstructorTest, Type_Bool_With_Bool) {
|
||||||
|
|
||||||
TEST_F(SpvBuilderConstructorTest, Type_I32_With_I32) {
|
TEST_F(SpvBuilderConstructorTest, Type_I32_With_I32) {
|
||||||
auto* cast = Construct<i32>(2);
|
auto* cast = Construct<i32>(2);
|
||||||
|
WrapInFunction(cast);
|
||||||
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -248,8 +239,7 @@ TEST_F(SpvBuilderConstructorTest, Type_I32_With_I32) {
|
||||||
|
|
||||||
TEST_F(SpvBuilderConstructorTest, Type_U32_With_U32) {
|
TEST_F(SpvBuilderConstructorTest, Type_U32_With_U32) {
|
||||||
auto* cast = Construct<u32>(2u);
|
auto* cast = Construct<u32>(2u);
|
||||||
|
WrapInFunction(cast);
|
||||||
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -264,8 +254,7 @@ TEST_F(SpvBuilderConstructorTest, Type_U32_With_U32) {
|
||||||
|
|
||||||
TEST_F(SpvBuilderConstructorTest, Type_F32_With_F32) {
|
TEST_F(SpvBuilderConstructorTest, Type_F32_With_F32) {
|
||||||
auto* cast = Construct<f32>(2.0f);
|
auto* cast = Construct<f32>(2.0f);
|
||||||
|
WrapInFunction(cast);
|
||||||
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -280,8 +269,7 @@ TEST_F(SpvBuilderConstructorTest, Type_F32_With_F32) {
|
||||||
|
|
||||||
TEST_F(SpvBuilderConstructorTest, Type_Vec2_With_F32_F32) {
|
TEST_F(SpvBuilderConstructorTest, Type_Vec2_With_F32_F32) {
|
||||||
auto* cast = vec2<f32>(2.0f, 2.0f);
|
auto* cast = vec2<f32>(2.0f, 2.0f);
|
||||||
|
WrapInFunction(cast);
|
||||||
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -298,8 +286,7 @@ TEST_F(SpvBuilderConstructorTest, Type_Vec2_With_F32_F32) {
|
||||||
TEST_F(SpvBuilderConstructorTest, Type_Vec2_With_Vec2) {
|
TEST_F(SpvBuilderConstructorTest, Type_Vec2_With_Vec2) {
|
||||||
auto* value = vec2<f32>(2.0f, 2.0f);
|
auto* value = vec2<f32>(2.0f, 2.0f);
|
||||||
auto* cast = vec2<f32>(value);
|
auto* cast = vec2<f32>(value);
|
||||||
|
WrapInFunction(cast);
|
||||||
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -316,8 +303,7 @@ TEST_F(SpvBuilderConstructorTest, Type_Vec2_With_Vec2) {
|
||||||
|
|
||||||
TEST_F(SpvBuilderConstructorTest, Type_Vec3_With_F32_F32_F32) {
|
TEST_F(SpvBuilderConstructorTest, Type_Vec3_With_F32_F32_F32) {
|
||||||
auto* cast = vec3<f32>(2.0f, 2.0f, 2.0f);
|
auto* cast = vec3<f32>(2.0f, 2.0f, 2.0f);
|
||||||
|
WrapInFunction(cast);
|
||||||
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
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) {
|
TEST_F(SpvBuilderConstructorTest, Type_Vec3_With_F32_Vec2) {
|
||||||
auto* cast = vec3<f32>(2.0f, vec2<f32>(2.0f, 2.0f));
|
auto* cast = vec3<f32>(2.0f, vec2<f32>(2.0f, 2.0f));
|
||||||
|
WrapInFunction(cast);
|
||||||
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -356,8 +341,7 @@ TEST_F(SpvBuilderConstructorTest, Type_Vec3_With_F32_Vec2) {
|
||||||
|
|
||||||
TEST_F(SpvBuilderConstructorTest, Type_Vec3_With_Vec2_F32) {
|
TEST_F(SpvBuilderConstructorTest, Type_Vec3_With_Vec2_F32) {
|
||||||
auto* cast = vec3<f32>(vec2<f32>(2.0f, 2.0f), 2.0f);
|
auto* cast = vec3<f32>(vec2<f32>(2.0f, 2.0f), 2.0f);
|
||||||
|
WrapInFunction(cast);
|
||||||
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -380,8 +364,7 @@ TEST_F(SpvBuilderConstructorTest, Type_Vec3_With_Vec2_F32) {
|
||||||
TEST_F(SpvBuilderConstructorTest, Type_Vec3_With_Vec3) {
|
TEST_F(SpvBuilderConstructorTest, Type_Vec3_With_Vec3) {
|
||||||
auto* value = vec3<f32>(2.0f, 2.0f, 2.0f);
|
auto* value = vec3<f32>(2.0f, 2.0f, 2.0f);
|
||||||
auto* cast = vec3<f32>(value);
|
auto* cast = vec3<f32>(value);
|
||||||
|
WrapInFunction(cast);
|
||||||
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
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) {
|
TEST_F(SpvBuilderConstructorTest, Type_Vec4_With_F32_F32_F32_F32) {
|
||||||
auto* cast = vec4<f32>(2.0f, 2.0f, 2.0f, 2.0f);
|
auto* cast = vec4<f32>(2.0f, 2.0f, 2.0f, 2.0f);
|
||||||
|
WrapInFunction(cast);
|
||||||
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
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) {
|
TEST_F(SpvBuilderConstructorTest, Type_Vec4_With_F32_F32_Vec2) {
|
||||||
auto* cast = vec4<f32>(2.0f, 2.0f, vec2<f32>(2.0f, 2.0f));
|
auto* cast = vec4<f32>(2.0f, 2.0f, vec2<f32>(2.0f, 2.0f));
|
||||||
|
WrapInFunction(cast);
|
||||||
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
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) {
|
TEST_F(SpvBuilderConstructorTest, Type_Vec4_With_F32_Vec2_F32) {
|
||||||
auto* cast = vec4<f32>(2.0f, vec2<f32>(2.0f, 2.0f), 2.0f);
|
auto* cast = vec4<f32>(2.0f, vec2<f32>(2.0f, 2.0f), 2.0f);
|
||||||
|
WrapInFunction(cast);
|
||||||
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
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) {
|
TEST_F(SpvBuilderConstructorTest, Type_Vec4_With_Vec2_F32_F32) {
|
||||||
auto* cast = vec4<f32>(vec2<f32>(2.0f, 2.0f), 2.0f, 2.0f);
|
auto* cast = vec4<f32>(vec2<f32>(2.0f, 2.0f), 2.0f, 2.0f);
|
||||||
|
WrapInFunction(cast);
|
||||||
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
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) {
|
TEST_F(SpvBuilderConstructorTest, Type_Vec4_With_Vec2_Vec2) {
|
||||||
auto* cast = vec4<f32>(vec2<f32>(2.0f, 2.0f), vec2<f32>(2.0f, 2.0f));
|
auto* cast = vec4<f32>(vec2<f32>(2.0f, 2.0f), vec2<f32>(2.0f, 2.0f));
|
||||||
|
WrapInFunction(cast);
|
||||||
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -509,8 +487,7 @@ TEST_F(SpvBuilderConstructorTest, Type_Vec4_With_Vec2_Vec2) {
|
||||||
|
|
||||||
TEST_F(SpvBuilderConstructorTest, Type_Vec4_With_F32_Vec3) {
|
TEST_F(SpvBuilderConstructorTest, Type_Vec4_With_F32_Vec3) {
|
||||||
auto* cast = vec4<f32>(2.0f, vec3<f32>(2.0f, 2.0f, 2.0f));
|
auto* cast = vec4<f32>(2.0f, vec3<f32>(2.0f, 2.0f, 2.0f));
|
||||||
|
WrapInFunction(cast);
|
||||||
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -533,8 +510,7 @@ TEST_F(SpvBuilderConstructorTest, Type_Vec4_With_F32_Vec3) {
|
||||||
|
|
||||||
TEST_F(SpvBuilderConstructorTest, Type_Vec4_With_Vec3_F32) {
|
TEST_F(SpvBuilderConstructorTest, Type_Vec4_With_Vec3_F32) {
|
||||||
auto* cast = vec4<f32>(vec3<f32>(2.0f, 2.0f, 2.0f), 2.0f);
|
auto* cast = vec4<f32>(vec3<f32>(2.0f, 2.0f, 2.0f), 2.0f);
|
||||||
|
WrapInFunction(cast);
|
||||||
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -558,8 +534,7 @@ TEST_F(SpvBuilderConstructorTest, Type_Vec4_With_Vec3_F32) {
|
||||||
TEST_F(SpvBuilderConstructorTest, Type_Vec4_With_Vec4) {
|
TEST_F(SpvBuilderConstructorTest, Type_Vec4_With_Vec4) {
|
||||||
auto* value = vec4<f32>(2.0f, 2.0f, 2.0f, 2.0f);
|
auto* value = vec4<f32>(2.0f, 2.0f, 2.0f, 2.0f);
|
||||||
auto* cast = vec4<f32>(value);
|
auto* cast = vec4<f32>(value);
|
||||||
|
WrapInFunction(cast);
|
||||||
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -576,8 +551,7 @@ TEST_F(SpvBuilderConstructorTest, Type_Vec4_With_Vec4) {
|
||||||
|
|
||||||
TEST_F(SpvBuilderConstructorTest, Type_ModuleScope_Vec2_With_Vec2) {
|
TEST_F(SpvBuilderConstructorTest, Type_ModuleScope_Vec2_With_Vec2) {
|
||||||
auto* cast = vec2<f32>(vec2<f32>(2.0f, 2.0f));
|
auto* cast = vec2<f32>(vec2<f32>(2.0f, 2.0f));
|
||||||
|
WrapInFunction(cast);
|
||||||
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -593,8 +567,7 @@ TEST_F(SpvBuilderConstructorTest, Type_ModuleScope_Vec2_With_Vec2) {
|
||||||
|
|
||||||
TEST_F(SpvBuilderConstructorTest, Type_ModuleScope_Vec3_With_Vec3) {
|
TEST_F(SpvBuilderConstructorTest, Type_ModuleScope_Vec3_With_Vec3) {
|
||||||
auto* cast = vec3<f32>(vec3<f32>(2.0f, 2.0f, 2.0f));
|
auto* cast = vec3<f32>(vec3<f32>(2.0f, 2.0f, 2.0f));
|
||||||
|
WrapInFunction(cast);
|
||||||
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -610,8 +583,7 @@ TEST_F(SpvBuilderConstructorTest, Type_ModuleScope_Vec3_With_Vec3) {
|
||||||
|
|
||||||
TEST_F(SpvBuilderConstructorTest, Type_ModuleScope_Vec4_With_Vec4) {
|
TEST_F(SpvBuilderConstructorTest, Type_ModuleScope_Vec4_With_Vec4) {
|
||||||
auto* cast = vec4<f32>(vec4<f32>(2.0f, 2.0f, 2.0f, 2.0f));
|
auto* cast = vec4<f32>(vec4<f32>(2.0f, 2.0f, 2.0f, 2.0f));
|
||||||
|
WrapInFunction(cast);
|
||||||
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
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) {
|
TEST_F(SpvBuilderConstructorTest, Type_ModuleScope_Vec3_With_F32_Vec2) {
|
||||||
auto* cast = vec3<f32>(2.0f, vec2<f32>(2.0f, 2.0f));
|
auto* cast = vec3<f32>(2.0f, vec2<f32>(2.0f, 2.0f));
|
||||||
|
WrapInFunction(cast);
|
||||||
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
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) {
|
TEST_F(SpvBuilderConstructorTest, Type_ModuleScope_Vec3_With_Vec2_F32) {
|
||||||
auto* cast = vec3<f32>(vec2<f32>(2.0f, 2.0f), 2.0f);
|
auto* cast = vec3<f32>(vec2<f32>(2.0f, 2.0f), 2.0f);
|
||||||
|
WrapInFunction(cast);
|
||||||
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
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) {
|
TEST_F(SpvBuilderConstructorTest, Type_ModuleScope_Vec4_With_F32_F32_Vec2) {
|
||||||
auto* cast = vec4<f32>(2.0f, 2.0f, vec2<f32>(2.0f, 2.0f));
|
auto* cast = vec4<f32>(2.0f, 2.0f, vec2<f32>(2.0f, 2.0f));
|
||||||
|
WrapInFunction(cast);
|
||||||
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
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) {
|
TEST_F(SpvBuilderConstructorTest, Type_ModuleScope_Vec4_With_F32_Vec2_F32) {
|
||||||
auto* cast = vec4<f32>(2.0f, vec2<f32>(2.0f, 2.0f), 2.0f);
|
auto* cast = vec4<f32>(2.0f, vec2<f32>(2.0f, 2.0f), 2.0f);
|
||||||
|
WrapInFunction(cast);
|
||||||
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
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) {
|
TEST_F(SpvBuilderConstructorTest, Type_ModuleScope_Vec4_With_Vec2_F32_F32) {
|
||||||
auto* cast = vec4<f32>(vec2<f32>(2.0f, 2.0f), 2.0f, 2.0f);
|
auto* cast = vec4<f32>(vec2<f32>(2.0f, 2.0f), 2.0f, 2.0f);
|
||||||
|
WrapInFunction(cast);
|
||||||
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
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) {
|
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));
|
auto* cast = vec4<f32>(vec2<f32>(2.0f, 2.0f), vec2<f32>(2.0f, 2.0f));
|
||||||
|
WrapInFunction(cast);
|
||||||
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
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) {
|
TEST_F(SpvBuilderConstructorTest, Type_ModuleScope_Vec4_With_F32_Vec3) {
|
||||||
auto* cast = vec4<f32>(2.0f, vec3<f32>(2.0f, 2.0f, 2.0f));
|
auto* cast = vec4<f32>(2.0f, vec3<f32>(2.0f, 2.0f, 2.0f));
|
||||||
|
WrapInFunction(cast);
|
||||||
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
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) {
|
TEST_F(SpvBuilderConstructorTest, Type_ModuleScope_Vec4_With_Vec3_F32) {
|
||||||
auto* cast = vec4<f32>(vec3<f32>(2.0f, 2.0f, 2.0f), 2.0f);
|
auto* cast = vec4<f32>(vec3<f32>(2.0f, 2.0f, 2.0f), 2.0f);
|
||||||
|
WrapInFunction(cast);
|
||||||
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
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) {
|
TEST_F(SpvBuilderConstructorTest, Type_Mat2x2_With_Vec2_Vec2) {
|
||||||
auto* cast = mat2x2<f32>(vec2<f32>(2.0f, 2.0f), vec2<f32>(2.0f, 2.0f));
|
auto* cast = mat2x2<f32>(vec2<f32>(2.0f, 2.0f), vec2<f32>(2.0f, 2.0f));
|
||||||
|
WrapInFunction(cast);
|
||||||
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
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) {
|
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),
|
auto* cast = mat3x2<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));
|
||||||
|
WrapInFunction(cast);
|
||||||
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
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) {
|
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),
|
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));
|
vec2<f32>(2.0f, 2.0f), vec2<f32>(2.0f, 2.0f));
|
||||||
|
WrapInFunction(cast);
|
||||||
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
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) {
|
TEST_F(SpvBuilderConstructorTest, Type_Mat2x3_With_Vec3_Vec3) {
|
||||||
auto* cast =
|
auto* cast =
|
||||||
mat2x3<f32>(vec3<f32>(2.0f, 2.0f, 2.0f), vec3<f32>(2.0f, 2.0f, 2.0f));
|
mat2x3<f32>(vec3<f32>(2.0f, 2.0f, 2.0f), vec3<f32>(2.0f, 2.0f, 2.0f));
|
||||||
|
WrapInFunction(cast);
|
||||||
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -906,8 +866,7 @@ TEST_F(SpvBuilderConstructorTest, Type_Mat3x3_With_Vec3_Vec3_Vec3) {
|
||||||
auto* cast =
|
auto* cast =
|
||||||
mat3x3<f32>(vec3<f32>(2.0f, 2.0f, 2.0f), vec3<f32>(2.0f, 2.0f, 2.0f),
|
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));
|
vec3<f32>(2.0f, 2.0f, 2.0f));
|
||||||
|
WrapInFunction(cast);
|
||||||
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -927,8 +886,7 @@ TEST_F(SpvBuilderConstructorTest, Type_Mat4x3_With_Vec3_Vec3_Vec3_Vec3) {
|
||||||
auto* cast =
|
auto* cast =
|
||||||
mat4x3<f32>(vec3<f32>(2.0f, 2.0f, 2.0f), vec3<f32>(2.0f, 2.0f, 2.0f),
|
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));
|
vec3<f32>(2.0f, 2.0f, 2.0f), vec3<f32>(2.0f, 2.0f, 2.0f));
|
||||||
|
WrapInFunction(cast);
|
||||||
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
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) {
|
TEST_F(SpvBuilderConstructorTest, Type_Mat2x4_With_Vec4_Vec4) {
|
||||||
auto* cast = mat2x4<f32>(vec4<f32>(2.0f, 2.0f, 2.0f, 2.0f),
|
auto* cast = mat2x4<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));
|
||||||
|
WrapInFunction(cast);
|
||||||
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
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),
|
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),
|
||||||
vec4<f32>(2.0f, 2.0f, 2.0f, 2.0f));
|
vec4<f32>(2.0f, 2.0f, 2.0f, 2.0f));
|
||||||
|
WrapInFunction(cast);
|
||||||
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -989,8 +945,7 @@ TEST_F(SpvBuilderConstructorTest, Type_Mat4x4_With_Vec4_Vec4_Vec4_Vec4) {
|
||||||
auto* cast = mat4x4<f32>(
|
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),
|
||||||
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));
|
||||||
|
WrapInFunction(cast);
|
||||||
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
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) {
|
TEST_F(SpvBuilderConstructorTest, Type_Array_5_F32) {
|
||||||
auto* cast = array<f32, 5>(2.0f, 2.0f, 2.0f, 2.0f, 2.0f);
|
auto* cast = array<f32, 5>(2.0f, 2.0f, 2.0f, 2.0f, 2.0f);
|
||||||
|
WrapInFunction(cast);
|
||||||
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -1028,8 +982,7 @@ TEST_F(SpvBuilderConstructorTest, Type_Array_5_F32) {
|
||||||
TEST_F(SpvBuilderConstructorTest, Type_Array_2_Vec3) {
|
TEST_F(SpvBuilderConstructorTest, Type_Array_2_Vec3) {
|
||||||
auto* cast =
|
auto* cast =
|
||||||
array<f32, 2>(vec3<f32>(2.0f, 2.0f, 2.0f), vec3<f32>(2.0f, 2.0f, 2.0f));
|
array<f32, 2>(vec3<f32>(2.0f, 2.0f, 2.0f), vec3<f32>(2.0f, 2.0f, 2.0f));
|
||||||
|
WrapInFunction(cast);
|
||||||
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -1057,7 +1010,7 @@ TEST_F(SpvBuilderConstructorTest, Type_Struct) {
|
||||||
auto* s_type = ty.struct_("my_struct", s);
|
auto* s_type = ty.struct_("my_struct", s);
|
||||||
|
|
||||||
auto* t = Construct(s_type, 2.0f, vec3<f32>(2.0f, 2.0f, 2.0f));
|
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();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -1078,7 +1031,7 @@ TEST_F(SpvBuilderConstructorTest, Type_Struct) {
|
||||||
TEST_F(SpvBuilderConstructorTest, Type_ZeroInit_F32) {
|
TEST_F(SpvBuilderConstructorTest, Type_ZeroInit_F32) {
|
||||||
auto* t = Construct(ty.f32());
|
auto* t = Construct(ty.f32());
|
||||||
|
|
||||||
EXPECT_TRUE(td.DetermineResultType(t)) << td.error();
|
WrapInFunction(t);
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -1095,7 +1048,7 @@ TEST_F(SpvBuilderConstructorTest, Type_ZeroInit_F32) {
|
||||||
TEST_F(SpvBuilderConstructorTest, Type_ZeroInit_I32) {
|
TEST_F(SpvBuilderConstructorTest, Type_ZeroInit_I32) {
|
||||||
auto* t = Construct<i32>();
|
auto* t = Construct<i32>();
|
||||||
|
|
||||||
EXPECT_TRUE(td.DetermineResultType(t)) << td.error();
|
WrapInFunction(t);
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -1112,7 +1065,7 @@ TEST_F(SpvBuilderConstructorTest, Type_ZeroInit_I32) {
|
||||||
TEST_F(SpvBuilderConstructorTest, Type_ZeroInit_U32) {
|
TEST_F(SpvBuilderConstructorTest, Type_ZeroInit_U32) {
|
||||||
auto* t = Construct<u32>();
|
auto* t = Construct<u32>();
|
||||||
|
|
||||||
EXPECT_TRUE(td.DetermineResultType(t)) << td.error();
|
WrapInFunction(t);
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -1129,7 +1082,7 @@ TEST_F(SpvBuilderConstructorTest, Type_ZeroInit_U32) {
|
||||||
TEST_F(SpvBuilderConstructorTest, Type_ZeroInit_Bool) {
|
TEST_F(SpvBuilderConstructorTest, Type_ZeroInit_Bool) {
|
||||||
auto* t = Construct(ty.bool_());
|
auto* t = Construct(ty.bool_());
|
||||||
|
|
||||||
EXPECT_TRUE(td.DetermineResultType(t)) << td.error();
|
WrapInFunction(t);
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -1146,7 +1099,7 @@ TEST_F(SpvBuilderConstructorTest, Type_ZeroInit_Bool) {
|
||||||
TEST_F(SpvBuilderConstructorTest, Type_ZeroInit_Vector) {
|
TEST_F(SpvBuilderConstructorTest, Type_ZeroInit_Vector) {
|
||||||
auto* t = vec2<i32>();
|
auto* t = vec2<i32>();
|
||||||
|
|
||||||
EXPECT_TRUE(td.DetermineResultType(t)) << td.error();
|
WrapInFunction(t);
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -1164,7 +1117,7 @@ TEST_F(SpvBuilderConstructorTest, Type_ZeroInit_Vector) {
|
||||||
TEST_F(SpvBuilderConstructorTest, Type_ZeroInit_Matrix) {
|
TEST_F(SpvBuilderConstructorTest, Type_ZeroInit_Matrix) {
|
||||||
auto* t = mat4x2<f32>();
|
auto* t = mat4x2<f32>();
|
||||||
|
|
||||||
EXPECT_TRUE(td.DetermineResultType(t)) << td.error();
|
WrapInFunction(t);
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -1183,7 +1136,7 @@ TEST_F(SpvBuilderConstructorTest, Type_ZeroInit_Matrix) {
|
||||||
TEST_F(SpvBuilderConstructorTest, Type_ZeroInit_Array) {
|
TEST_F(SpvBuilderConstructorTest, Type_ZeroInit_Array) {
|
||||||
auto* t = array<i32, 2>();
|
auto* t = array<i32, 2>();
|
||||||
|
|
||||||
EXPECT_TRUE(td.DetermineResultType(t)) << td.error();
|
WrapInFunction(t);
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -1208,7 +1161,7 @@ TEST_F(SpvBuilderConstructorTest, Type_ZeroInit_Struct) {
|
||||||
ast::StructDecorationList{});
|
ast::StructDecorationList{});
|
||||||
auto* s_type = ty.struct_("my_struct", s);
|
auto* s_type = ty.struct_("my_struct", s);
|
||||||
auto* t = Construct(s_type);
|
auto* t = Construct(s_type);
|
||||||
EXPECT_TRUE(td.DetermineResultType(t)) << td.error();
|
WrapInFunction(t);
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -1225,8 +1178,7 @@ TEST_F(SpvBuilderConstructorTest, Type_ZeroInit_Struct) {
|
||||||
|
|
||||||
TEST_F(SpvBuilderConstructorTest, Type_Convert_U32_To_I32) {
|
TEST_F(SpvBuilderConstructorTest, Type_Convert_U32_To_I32) {
|
||||||
auto* cast = Construct<i32>(2u);
|
auto* cast = Construct<i32>(2u);
|
||||||
|
WrapInFunction(cast);
|
||||||
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -1244,8 +1196,7 @@ TEST_F(SpvBuilderConstructorTest, Type_Convert_U32_To_I32) {
|
||||||
|
|
||||||
TEST_F(SpvBuilderConstructorTest, Type_Convert_I32_To_U32) {
|
TEST_F(SpvBuilderConstructorTest, Type_Convert_I32_To_U32) {
|
||||||
auto* cast = Construct<u32>(2);
|
auto* cast = Construct<u32>(2);
|
||||||
|
WrapInFunction(cast);
|
||||||
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -1263,8 +1214,7 @@ TEST_F(SpvBuilderConstructorTest, Type_Convert_I32_To_U32) {
|
||||||
|
|
||||||
TEST_F(SpvBuilderConstructorTest, Type_Convert_F32_To_I32) {
|
TEST_F(SpvBuilderConstructorTest, Type_Convert_F32_To_I32) {
|
||||||
auto* cast = Construct<i32>(2.4f);
|
auto* cast = Construct<i32>(2.4f);
|
||||||
|
WrapInFunction(cast);
|
||||||
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -1282,8 +1232,7 @@ TEST_F(SpvBuilderConstructorTest, Type_Convert_F32_To_I32) {
|
||||||
|
|
||||||
TEST_F(SpvBuilderConstructorTest, Type_Convert_F32_To_U32) {
|
TEST_F(SpvBuilderConstructorTest, Type_Convert_F32_To_U32) {
|
||||||
auto* cast = Construct<u32>(2.4f);
|
auto* cast = Construct<u32>(2.4f);
|
||||||
|
WrapInFunction(cast);
|
||||||
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -1301,8 +1250,7 @@ TEST_F(SpvBuilderConstructorTest, Type_Convert_F32_To_U32) {
|
||||||
|
|
||||||
TEST_F(SpvBuilderConstructorTest, Type_Convert_I32_To_F32) {
|
TEST_F(SpvBuilderConstructorTest, Type_Convert_I32_To_F32) {
|
||||||
auto* cast = Construct<f32>(2);
|
auto* cast = Construct<f32>(2);
|
||||||
|
WrapInFunction(cast);
|
||||||
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -1320,8 +1268,7 @@ TEST_F(SpvBuilderConstructorTest, Type_Convert_I32_To_F32) {
|
||||||
|
|
||||||
TEST_F(SpvBuilderConstructorTest, Type_Convert_U32_To_F32) {
|
TEST_F(SpvBuilderConstructorTest, Type_Convert_U32_To_F32) {
|
||||||
auto* cast = Construct<f32>(2u);
|
auto* cast = Construct<f32>(2u);
|
||||||
|
WrapInFunction(cast);
|
||||||
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
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) {
|
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");
|
auto* cast = vec3<i32>("i");
|
||||||
|
WrapInFunction(cast);
|
||||||
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
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) {
|
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");
|
auto* cast = vec3<i32>("i");
|
||||||
|
WrapInFunction(cast);
|
||||||
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
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) {
|
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");
|
auto* cast = vec3<u32>("i");
|
||||||
|
WrapInFunction(cast);
|
||||||
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
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) {
|
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");
|
auto* cast = vec3<u32>("i");
|
||||||
|
WrapInFunction(cast);
|
||||||
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
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) {
|
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");
|
auto* cast = vec3<f32>("i");
|
||||||
|
WrapInFunction(cast);
|
||||||
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
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) {
|
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");
|
auto* cast = vec3<f32>("i");
|
||||||
|
WrapInFunction(cast);
|
||||||
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -1503,8 +1444,7 @@ TEST_F(SpvBuilderConstructorTest,
|
||||||
IsConstructorConst_GlobalVectorWithAllConstConstructors) {
|
IsConstructorConst_GlobalVectorWithAllConstConstructors) {
|
||||||
// vec3<f32>(1.0, 2.0, 3.0) -> true
|
// vec3<f32>(1.0, 2.0, 3.0) -> true
|
||||||
auto* t = vec3<f32>(1.f, 2.f, 3.f);
|
auto* t = vec3<f32>(1.f, 2.f, 3.f);
|
||||||
|
WrapInFunction(t);
|
||||||
ASSERT_TRUE(td.DetermineResultType(t)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -1514,13 +1454,13 @@ TEST_F(SpvBuilderConstructorTest,
|
||||||
|
|
||||||
TEST_F(SpvBuilderConstructorTest, IsConstructorConst_GlobalVector_WithIdent) {
|
TEST_F(SpvBuilderConstructorTest, IsConstructorConst_GlobalVector_WithIdent) {
|
||||||
// vec3<f32>(a, b, c) -> false -- ERROR
|
// 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");
|
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();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -1535,8 +1475,7 @@ TEST_F(SpvBuilderConstructorTest,
|
||||||
// -> true
|
// -> true
|
||||||
auto* t = Construct(ty.array(ty.vec2<f32>(), 2), vec3<f32>(1.f, 2.f, 3.f),
|
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));
|
vec3<f32>(1.f, 2.f, 3.f));
|
||||||
|
WrapInFunction(t);
|
||||||
ASSERT_TRUE(td.DetermineResultType(t)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -1549,8 +1488,7 @@ TEST_F(SpvBuilderConstructorTest,
|
||||||
// vec3<f32>(f32(1.0), f32(2.0)) -> false
|
// vec3<f32>(f32(1.0), f32(2.0)) -> false
|
||||||
|
|
||||||
auto* t = vec2<f32>(Construct<f32>(1.f), Construct<f32>(2.f));
|
auto* t = vec2<f32>(Construct<f32>(1.f), Construct<f32>(2.f));
|
||||||
|
WrapInFunction(t);
|
||||||
ASSERT_TRUE(td.DetermineResultType(t)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -1563,8 +1501,7 @@ TEST_F(SpvBuilderConstructorTest,
|
||||||
// vec3<f32>(f32(1), f32(2)) -> false
|
// vec3<f32>(f32(1), f32(2)) -> false
|
||||||
|
|
||||||
auto* t = vec2<f32>(Construct<f32>(1), Construct<f32>(2));
|
auto* t = vec2<f32>(Construct<f32>(1), Construct<f32>(2));
|
||||||
|
WrapInFunction(t);
|
||||||
ASSERT_TRUE(td.DetermineResultType(t)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -1577,8 +1514,7 @@ TEST_F(SpvBuilderConstructorTest,
|
||||||
// vec3<f32>(1.0, 2.0, 3.0) -> true
|
// vec3<f32>(1.0, 2.0, 3.0) -> true
|
||||||
|
|
||||||
auto* t = vec3<f32>(1.f, 2.f, 3.f);
|
auto* t = vec3<f32>(1.f, 2.f, 3.f);
|
||||||
|
WrapInFunction(t);
|
||||||
ASSERT_TRUE(td.DetermineResultType(t)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -1590,12 +1526,11 @@ TEST_F(SpvBuilderConstructorTest, IsConstructorConst_Vector_WithIdent) {
|
||||||
// vec3<f32>(a, b, c) -> false
|
// vec3<f32>(a, b, c) -> false
|
||||||
|
|
||||||
auto* t = vec3<f32>("a", "b", "c");
|
auto* t = vec3<f32>("a", "b", "c");
|
||||||
|
WrapInFunction(t);
|
||||||
|
|
||||||
Var("a", ast::StorageClass::kPrivate, ty.f32());
|
Global("a", ast::StorageClass::kPrivate, ty.f32());
|
||||||
Var("b", ast::StorageClass::kPrivate, ty.f32());
|
Global("b", ast::StorageClass::kPrivate, ty.f32());
|
||||||
Var("c", ast::StorageClass::kPrivate, ty.f32());
|
Global("c", ast::StorageClass::kPrivate, ty.f32());
|
||||||
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(t)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -1612,8 +1547,7 @@ TEST_F(SpvBuilderConstructorTest,
|
||||||
auto* second = vec3<f32>(1.f, 2.f, 3.f);
|
auto* second = vec3<f32>(1.f, 2.f, 3.f);
|
||||||
|
|
||||||
auto* t = Construct(ty.array(ty.vec3<f32>(), 2), first, second);
|
auto* t = Construct(ty.array(ty.vec3<f32>(), 2), first, second);
|
||||||
|
WrapInFunction(t);
|
||||||
ASSERT_TRUE(td.DetermineResultType(t)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -1626,8 +1560,7 @@ TEST_F(SpvBuilderConstructorTest,
|
||||||
// vec2<f32>(f32(1), f32(2)) -> false
|
// vec2<f32>(f32(1), f32(2)) -> false
|
||||||
|
|
||||||
auto* t = vec2<f32>(1, 2);
|
auto* t = vec2<f32>(1, 2);
|
||||||
|
WrapInFunction(t);
|
||||||
ASSERT_TRUE(td.DetermineResultType(t)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -1639,8 +1572,7 @@ TEST_F(SpvBuilderConstructorTest, IsConstructorConst_WithTypeCastConstructor) {
|
||||||
// vec3<f32>(f32(1), f32(2)) -> false
|
// vec3<f32>(f32(1), f32(2)) -> false
|
||||||
|
|
||||||
auto* t = vec3<f32>(1, 2);
|
auto* t = vec3<f32>(1, 2);
|
||||||
|
WrapInFunction(t);
|
||||||
ASSERT_TRUE(td.DetermineResultType(t)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -1650,8 +1582,7 @@ TEST_F(SpvBuilderConstructorTest, IsConstructorConst_WithTypeCastConstructor) {
|
||||||
|
|
||||||
TEST_F(SpvBuilderConstructorTest, IsConstructorConst_BitCastScalars) {
|
TEST_F(SpvBuilderConstructorTest, IsConstructorConst_BitCastScalars) {
|
||||||
auto* t = vec2<u32>(1, 1);
|
auto* t = vec2<u32>(1, 1);
|
||||||
|
WrapInFunction(t);
|
||||||
ASSERT_TRUE(td.DetermineResultType(t)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -1668,7 +1599,7 @@ TEST_F(SpvBuilderConstructorTest, IsConstructorConst_Struct) {
|
||||||
ast::StructDecorationList{});
|
ast::StructDecorationList{});
|
||||||
auto* s_type = ty.struct_("my_struct", s);
|
auto* s_type = ty.struct_("my_struct", s);
|
||||||
auto* t = Construct(s_type, 2.f, vec3<f32>(2.f, 2.f, 2.f));
|
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();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -1687,11 +1618,10 @@ TEST_F(SpvBuilderConstructorTest,
|
||||||
|
|
||||||
auto* s_type = ty.struct_("my_struct", s);
|
auto* s_type = ty.struct_("my_struct", s);
|
||||||
auto* t = Construct(s_type, 2.f, "a", 2.f);
|
auto* t = Construct(s_type, 2.f, "a", 2.f);
|
||||||
|
WrapInFunction(t);
|
||||||
|
|
||||||
Var("a", ast::StorageClass::kPrivate, ty.f32());
|
Global("a", ast::StorageClass::kPrivate, ty.f32());
|
||||||
Var("b", ast::StorageClass::kPrivate, ty.f32());
|
Global("b", ast::StorageClass::kPrivate, ty.f32());
|
||||||
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(t)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
|
|
@ -97,13 +97,9 @@ TEST_F(BuilderTest, FunctionDecoration_Stage_WithUnusedInterfaceIds) {
|
||||||
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
|
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
|
||||||
});
|
});
|
||||||
|
|
||||||
auto* v_in = Var("my_in", ast::StorageClass::kInput, ty.f32());
|
auto* v_in = Global("my_in", ast::StorageClass::kInput, ty.f32());
|
||||||
auto* v_out = Var("my_out", ast::StorageClass::kOutput, ty.f32());
|
auto* v_out = Global("my_out", ast::StorageClass::kOutput, ty.f32());
|
||||||
auto* v_wg = Var("my_wg", ast::StorageClass::kWorkgroup, ty.f32());
|
auto* v_wg = Global("my_wg", ast::StorageClass::kWorkgroup, ty.f32());
|
||||||
|
|
||||||
AST().AddGlobalVariable(v_in);
|
|
||||||
AST().AddGlobalVariable(v_out);
|
|
||||||
AST().AddGlobalVariable(v_wg);
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -146,13 +142,9 @@ TEST_F(BuilderTest, FunctionDecoration_Stage_WithUsedInterfaceIds) {
|
||||||
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
|
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
|
||||||
});
|
});
|
||||||
|
|
||||||
auto* v_in = Var("my_in", ast::StorageClass::kInput, ty.f32());
|
auto* v_in = Global("my_in", ast::StorageClass::kInput, ty.f32());
|
||||||
auto* v_out = Var("my_out", ast::StorageClass::kOutput, ty.f32());
|
auto* v_out = Global("my_out", ast::StorageClass::kOutput, ty.f32());
|
||||||
auto* v_wg = Var("my_wg", ast::StorageClass::kWorkgroup, ty.f32());
|
auto* v_wg = Global("my_wg", ast::StorageClass::kWorkgroup, ty.f32());
|
||||||
|
|
||||||
AST().AddGlobalVariable(v_in);
|
|
||||||
AST().AddGlobalVariable(v_out);
|
|
||||||
AST().AddGlobalVariable(v_wg);
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -266,12 +258,10 @@ OpFunctionEnd
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(BuilderTest, FunctionDecoration_ExecutionMode_FragDepth) {
|
TEST_F(BuilderTest, FunctionDecoration_ExecutionMode_FragDepth) {
|
||||||
auto* fragdepth =
|
Global("fragdepth", ast::StorageClass::kOutput, ty.f32(), nullptr,
|
||||||
Var("fragdepth", ast::StorageClass::kOutput, ty.f32(), nullptr,
|
|
||||||
ast::VariableDecorationList{
|
ast::VariableDecorationList{
|
||||||
create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth),
|
create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth),
|
||||||
});
|
});
|
||||||
AST().AddGlobalVariable(fragdepth);
|
|
||||||
|
|
||||||
auto* func =
|
auto* func =
|
||||||
Func("main", ast::VariableList{}, ty.void_(),
|
Func("main", ast::VariableList{}, ty.void_(),
|
||||||
|
|
|
@ -85,7 +85,7 @@ OpFunctionEnd
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(BuilderTest, Function_Terminator_ReturnValue) {
|
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_(),
|
Func("a_func", {}, ty.void_(),
|
||||||
ast::StatementList{create<ast::ReturnStatement>(Expr("a"))},
|
ast::StatementList{create<ast::ReturnStatement>(Expr("a"))},
|
||||||
|
@ -238,7 +238,7 @@ TEST_F(BuilderTest, Emit_Multiple_EntryPoint_With_Same_ModuleVar) {
|
||||||
auto* s = ty.struct_("Data", str);
|
auto* s = ty.struct_("Data", str);
|
||||||
type::AccessControl ac(ast::AccessControl::kReadWrite, s);
|
type::AccessControl ac(ast::AccessControl::kReadWrite, s);
|
||||||
|
|
||||||
auto* data_var = Var("data", ast::StorageClass::kStorage, &ac, nullptr,
|
Global("data", ast::StorageClass::kStorage, &ac, nullptr,
|
||||||
ast::VariableDecorationList{
|
ast::VariableDecorationList{
|
||||||
create<ast::BindingDecoration>(0),
|
create<ast::BindingDecoration>(0),
|
||||||
create<ast::GroupDecoration>(0),
|
create<ast::GroupDecoration>(0),
|
||||||
|
@ -246,8 +246,6 @@ TEST_F(BuilderTest, Emit_Multiple_EntryPoint_With_Same_ModuleVar) {
|
||||||
|
|
||||||
AST().AddConstructedType(s);
|
AST().AddConstructedType(s);
|
||||||
|
|
||||||
AST().AddGlobalVariable(data_var);
|
|
||||||
|
|
||||||
{
|
{
|
||||||
auto* var = Var("v", ast::StorageClass::kFunction, ty.f32(),
|
auto* var = Var("v", ast::StorageClass::kFunction, ty.f32(),
|
||||||
MemberAccessor("data", "d"), ast::VariableDecorationList{});
|
MemberAccessor("data", "d"), ast::VariableDecorationList{});
|
||||||
|
|
|
@ -45,7 +45,7 @@ namespace {
|
||||||
using BuilderTest = TestHelper;
|
using BuilderTest = TestHelper;
|
||||||
|
|
||||||
TEST_F(BuilderTest, FunctionVar_NoStorageClass) {
|
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();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -66,11 +66,9 @@ TEST_F(BuilderTest, FunctionVar_NoStorageClass) {
|
||||||
|
|
||||||
TEST_F(BuilderTest, FunctionVar_WithConstantConstructor) {
|
TEST_F(BuilderTest, FunctionVar_WithConstantConstructor) {
|
||||||
auto* init = vec3<f32>(1.f, 1.f, 3.f);
|
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,
|
auto* v = Global("var", ast::StorageClass::kOutput, ty.f32(), init,
|
||||||
ast::VariableDecorationList{});
|
ast::VariableDecorationList{});
|
||||||
td.RegisterVariableForTesting(v);
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -98,12 +96,10 @@ TEST_F(BuilderTest, FunctionVar_WithConstantConstructor) {
|
||||||
|
|
||||||
TEST_F(BuilderTest, FunctionVar_WithNonConstantConstructor) {
|
TEST_F(BuilderTest, FunctionVar_WithNonConstantConstructor) {
|
||||||
auto* init = vec2<f32>(1.f, Add(3.f, 3.f));
|
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,
|
auto* v = Global("var", ast::StorageClass::kFunction, ty.vec2<f32>(), init,
|
||||||
ast::VariableDecorationList{});
|
ast::VariableDecorationList{});
|
||||||
|
|
||||||
td.RegisterVariableForTesting(v);
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
b.push_function(Function{});
|
b.push_function(Function{});
|
||||||
|
@ -133,16 +129,11 @@ TEST_F(BuilderTest, FunctionVar_WithNonConstantConstructorLoadedFromVar) {
|
||||||
// var v : f32 = 1.0;
|
// var v : f32 = 1.0;
|
||||||
// var v2 : f32 = v; // Should generate the load and store automatically.
|
// var v2 : f32 = v; // Should generate the load and store automatically.
|
||||||
|
|
||||||
auto* v = Var("v", ast::StorageClass::kFunction, ty.f32(), Expr(1.f),
|
auto* v = Global("v", ast::StorageClass::kFunction, ty.f32(), Expr(1.f),
|
||||||
ast::VariableDecorationList{});
|
ast::VariableDecorationList{});
|
||||||
td.RegisterVariableForTesting(v);
|
|
||||||
|
|
||||||
auto* v2 = Var("v2", ast::StorageClass::kFunction, ty.f32(), Expr("v"),
|
auto* v2 = Global("v2", ast::StorageClass::kFunction, ty.f32(), Expr("v"),
|
||||||
ast::VariableDecorationList{});
|
ast::VariableDecorationList{});
|
||||||
td.RegisterVariableForTesting(v2);
|
|
||||||
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(v->constructor())) << td.error();
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(v2->constructor())) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -174,16 +165,11 @@ TEST_F(BuilderTest, FunctionVar_ConstWithVarInitializer) {
|
||||||
// var v : f32 = 1.0;
|
// var v : f32 = 1.0;
|
||||||
// const v2 : f32 = v; // Should generate the load
|
// const v2 : f32 = v; // Should generate the load
|
||||||
|
|
||||||
auto* v = Var("v", ast::StorageClass::kFunction, ty.f32(), Expr(1.f),
|
auto* v = Global("v", ast::StorageClass::kFunction, ty.f32(), Expr(1.f),
|
||||||
ast::VariableDecorationList{});
|
ast::VariableDecorationList{});
|
||||||
td.RegisterVariableForTesting(v);
|
|
||||||
|
|
||||||
auto* v2 = Var("v2", ast::StorageClass::kFunction, ty.f32(), Expr("v"),
|
auto* v2 = Global("v2", ast::StorageClass::kFunction, ty.f32(), Expr("v"),
|
||||||
ast::VariableDecorationList{});
|
ast::VariableDecorationList{});
|
||||||
td.RegisterVariableForTesting(v2);
|
|
||||||
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(v->constructor())) << td.error();
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(v2->constructor())) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -213,12 +199,11 @@ OpStore %7 %6
|
||||||
|
|
||||||
TEST_F(BuilderTest, FunctionVar_Const) {
|
TEST_F(BuilderTest, FunctionVar_Const) {
|
||||||
auto* init = vec3<f32>(1.f, 1.f, 3.f);
|
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,
|
auto* v = Const("var", ast::StorageClass::kOutput, ty.f32(), init,
|
||||||
ast::VariableDecorationList{});
|
ast::VariableDecorationList{});
|
||||||
|
|
||||||
td.RegisterVariableForTesting(v);
|
WrapInFunction(v);
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
|
|
@ -50,7 +50,7 @@ namespace {
|
||||||
using BuilderTest = TestHelper;
|
using BuilderTest = TestHelper;
|
||||||
|
|
||||||
TEST_F(BuilderTest, GlobalVar_NoStorageClass) {
|
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();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -65,7 +65,7 @@ TEST_F(BuilderTest, GlobalVar_NoStorageClass) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(BuilderTest, GlobalVar_WithStorageClass) {
|
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();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -80,7 +80,7 @@ TEST_F(BuilderTest, GlobalVar_WithStorageClass) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(BuilderTest, GlobalVar_WithStorageClass_Input) {
|
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();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -95,11 +95,9 @@ TEST_F(BuilderTest, GlobalVar_WithStorageClass_Input) {
|
||||||
|
|
||||||
TEST_F(BuilderTest, GlobalVar_WithConstructor) {
|
TEST_F(BuilderTest, GlobalVar_WithConstructor) {
|
||||||
auto* init = vec3<f32>(1.f, 1.f, 3.f);
|
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,
|
auto* v = Global("var", ast::StorageClass::kOutput, ty.f32(), init,
|
||||||
ast::VariableDecorationList{});
|
ast::VariableDecorationList{});
|
||||||
td.RegisterVariableForTesting(v);
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -120,11 +118,9 @@ TEST_F(BuilderTest, GlobalVar_WithConstructor) {
|
||||||
|
|
||||||
TEST_F(BuilderTest, GlobalVar_Const) {
|
TEST_F(BuilderTest, GlobalVar_Const) {
|
||||||
auto* init = vec3<f32>(1.f, 1.f, 3.f);
|
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,
|
auto* v = GlobalConst("var", ast::StorageClass::kOutput, ty.f32(), init,
|
||||||
ast::VariableDecorationList{});
|
ast::VariableDecorationList{});
|
||||||
td.RegisterVariableForTesting(v);
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -143,11 +139,9 @@ TEST_F(BuilderTest, GlobalVar_Const) {
|
||||||
|
|
||||||
TEST_F(BuilderTest, GlobalVar_Complex_Constructor) {
|
TEST_F(BuilderTest, GlobalVar_Complex_Constructor) {
|
||||||
auto* init = vec3<f32>(ast::ExpressionList{Expr(1.f), Expr(2.f), Expr(3.f)});
|
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,
|
auto* v = GlobalConst("var", ast::StorageClass::kOutput, ty.f32(), init,
|
||||||
ast::VariableDecorationList{});
|
ast::VariableDecorationList{});
|
||||||
td.RegisterVariableForTesting(v);
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -166,11 +160,8 @@ TEST_F(BuilderTest, GlobalVar_Complex_Constructor) {
|
||||||
TEST_F(BuilderTest, GlobalVar_Complex_ConstructorWithExtract) {
|
TEST_F(BuilderTest, GlobalVar_Complex_ConstructorWithExtract) {
|
||||||
auto* init = vec3<f32>(vec2<f32>(1.f, 2.f), 3.f);
|
auto* init = vec3<f32>(vec2<f32>(1.f, 2.f), 3.f);
|
||||||
|
|
||||||
EXPECT_TRUE(td.DetermineResultType(init)) << td.error();
|
auto* v = GlobalConst("var", ast::StorageClass::kOutput, ty.f32(), init,
|
||||||
|
|
||||||
auto* v = Const("var", ast::StorageClass::kOutput, ty.f32(), init,
|
|
||||||
ast::VariableDecorationList{});
|
ast::VariableDecorationList{});
|
||||||
td.RegisterVariableForTesting(v);
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -194,7 +185,7 @@ TEST_F(BuilderTest, GlobalVar_Complex_ConstructorWithExtract) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(BuilderTest, GlobalVar_WithLocation) {
|
TEST_F(BuilderTest, GlobalVar_WithLocation) {
|
||||||
auto* v = Var("var", ast::StorageClass::kOutput, ty.f32(), nullptr,
|
auto* v = Global("var", ast::StorageClass::kOutput, ty.f32(), nullptr,
|
||||||
ast::VariableDecorationList{
|
ast::VariableDecorationList{
|
||||||
create<ast::LocationDecoration>(5),
|
create<ast::LocationDecoration>(5),
|
||||||
});
|
});
|
||||||
|
@ -214,7 +205,7 @@ TEST_F(BuilderTest, GlobalVar_WithLocation) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(BuilderTest, GlobalVar_WithBindingAndGroup) {
|
TEST_F(BuilderTest, GlobalVar_WithBindingAndGroup) {
|
||||||
auto* v = Var("var", ast::StorageClass::kOutput, ty.f32(), nullptr,
|
auto* v = Global("var", ast::StorageClass::kOutput, ty.f32(), nullptr,
|
||||||
ast::VariableDecorationList{
|
ast::VariableDecorationList{
|
||||||
create<ast::BindingDecoration>(2),
|
create<ast::BindingDecoration>(2),
|
||||||
create<ast::GroupDecoration>(3),
|
create<ast::GroupDecoration>(3),
|
||||||
|
@ -236,7 +227,7 @@ OpDecorate %1 DescriptorSet 3
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(BuilderTest, GlobalVar_WithBuiltin) {
|
TEST_F(BuilderTest, GlobalVar_WithBuiltin) {
|
||||||
auto* v = Var("var", ast::StorageClass::kOutput, ty.f32(), nullptr,
|
auto* v = Global("var", ast::StorageClass::kOutput, ty.f32(), nullptr,
|
||||||
ast::VariableDecorationList{
|
ast::VariableDecorationList{
|
||||||
create<ast::BuiltinDecoration>(ast::Builtin::kPosition),
|
create<ast::BuiltinDecoration>(ast::Builtin::kPosition),
|
||||||
});
|
});
|
||||||
|
@ -256,7 +247,7 @@ TEST_F(BuilderTest, GlobalVar_WithBuiltin) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(BuilderTest, GlobalVar_ConstantId_Bool) {
|
TEST_F(BuilderTest, GlobalVar_ConstantId_Bool) {
|
||||||
auto* v = Var("var", ast::StorageClass::kNone, ty.bool_(), Expr(true),
|
auto* v = Global("var", ast::StorageClass::kNone, ty.bool_(), Expr(true),
|
||||||
ast::VariableDecorationList{
|
ast::VariableDecorationList{
|
||||||
create<ast::ConstantIdDecoration>(1200),
|
create<ast::ConstantIdDecoration>(1200),
|
||||||
});
|
});
|
||||||
|
@ -276,7 +267,7 @@ TEST_F(BuilderTest, GlobalVar_ConstantId_Bool) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(BuilderTest, GlobalVar_ConstantId_Bool_NoConstructor) {
|
TEST_F(BuilderTest, GlobalVar_ConstantId_Bool_NoConstructor) {
|
||||||
auto* v = Var("var", ast::StorageClass::kNone, ty.bool_(), nullptr,
|
auto* v = Global("var", ast::StorageClass::kNone, ty.bool_(), nullptr,
|
||||||
ast::VariableDecorationList{
|
ast::VariableDecorationList{
|
||||||
create<ast::ConstantIdDecoration>(1200),
|
create<ast::ConstantIdDecoration>(1200),
|
||||||
});
|
});
|
||||||
|
@ -296,7 +287,7 @@ TEST_F(BuilderTest, GlobalVar_ConstantId_Bool_NoConstructor) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(BuilderTest, GlobalVar_ConstantId_Scalar) {
|
TEST_F(BuilderTest, GlobalVar_ConstantId_Scalar) {
|
||||||
auto* v = Var("var", ast::StorageClass::kNone, ty.f32(), Expr(2.f),
|
auto* v = Global("var", ast::StorageClass::kNone, ty.f32(), Expr(2.f),
|
||||||
ast::VariableDecorationList{
|
ast::VariableDecorationList{
|
||||||
create<ast::ConstantIdDecoration>(0),
|
create<ast::ConstantIdDecoration>(0),
|
||||||
});
|
});
|
||||||
|
@ -316,7 +307,7 @@ TEST_F(BuilderTest, GlobalVar_ConstantId_Scalar) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(BuilderTest, GlobalVar_ConstantId_Scalar_F32_NoConstructor) {
|
TEST_F(BuilderTest, GlobalVar_ConstantId_Scalar_F32_NoConstructor) {
|
||||||
auto* v = Var("var", ast::StorageClass::kNone, ty.f32(), nullptr,
|
auto* v = Global("var", ast::StorageClass::kNone, ty.f32(), nullptr,
|
||||||
ast::VariableDecorationList{
|
ast::VariableDecorationList{
|
||||||
create<ast::ConstantIdDecoration>(0),
|
create<ast::ConstantIdDecoration>(0),
|
||||||
});
|
});
|
||||||
|
@ -336,7 +327,7 @@ TEST_F(BuilderTest, GlobalVar_ConstantId_Scalar_F32_NoConstructor) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(BuilderTest, GlobalVar_ConstantId_Scalar_I32_NoConstructor) {
|
TEST_F(BuilderTest, GlobalVar_ConstantId_Scalar_I32_NoConstructor) {
|
||||||
auto* v = Var("var", ast::StorageClass::kNone, ty.i32(), nullptr,
|
auto* v = Global("var", ast::StorageClass::kNone, ty.i32(), nullptr,
|
||||||
ast::VariableDecorationList{
|
ast::VariableDecorationList{
|
||||||
create<ast::ConstantIdDecoration>(0),
|
create<ast::ConstantIdDecoration>(0),
|
||||||
});
|
});
|
||||||
|
@ -356,7 +347,7 @@ TEST_F(BuilderTest, GlobalVar_ConstantId_Scalar_I32_NoConstructor) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(BuilderTest, GlobalVar_ConstantId_Scalar_U32_NoConstructor) {
|
TEST_F(BuilderTest, GlobalVar_ConstantId_Scalar_U32_NoConstructor) {
|
||||||
auto* v = Var("var", ast::StorageClass::kNone, ty.u32(), nullptr,
|
auto* v = Global("var", ast::StorageClass::kNone, ty.u32(), nullptr,
|
||||||
ast::VariableDecorationList{
|
ast::VariableDecorationList{
|
||||||
create<ast::ConstantIdDecoration>(0),
|
create<ast::ConstantIdDecoration>(0),
|
||||||
});
|
});
|
||||||
|
@ -386,6 +377,7 @@ inline std::ostream& operator<<(std::ostream& out, BuiltinData data) {
|
||||||
using BuiltinDataTest = TestParamHelper<BuiltinData>;
|
using BuiltinDataTest = TestParamHelper<BuiltinData>;
|
||||||
TEST_P(BuiltinDataTest, Convert) {
|
TEST_P(BuiltinDataTest, Convert) {
|
||||||
auto params = GetParam();
|
auto params = GetParam();
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
EXPECT_EQ(b.ConvertBuiltin(params.builtin), params.result);
|
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()),
|
"A", create<ast::Struct>(ast::StructMemberList{Member("a", ty.i32()),
|
||||||
Member("b", ty.i32())},
|
Member("b", ty.i32())},
|
||||||
ast::StructDecorationList{}));
|
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();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -455,8 +447,8 @@ TEST_F(BuilderTest, GlobalVar_TypeAliasDeclReadOnly) {
|
||||||
"A", create<ast::Struct>(ast::StructMemberList{Member("a", ty.i32())},
|
"A", create<ast::Struct>(ast::StructMemberList{Member("a", ty.i32())},
|
||||||
ast::StructDecorationList{}));
|
ast::StructDecorationList{}));
|
||||||
auto* B = ty.alias("B", A);
|
auto* B = ty.alias("B", A);
|
||||||
type::AccessControl ac{ast::AccessControl::kReadOnly, B};
|
auto* ac = create<type::AccessControl>(ast::AccessControl::kReadOnly, B);
|
||||||
auto* var = Var("b", ast::StorageClass::kStorage, &ac);
|
auto* var = Global("b", ast::StorageClass::kStorage, ac);
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -485,9 +477,9 @@ TEST_F(BuilderTest, GlobalVar_TypeAliasAssignReadOnly) {
|
||||||
auto* A = ty.struct_(
|
auto* A = ty.struct_(
|
||||||
"A", create<ast::Struct>(ast::StructMemberList{Member("a", ty.i32())},
|
"A", create<ast::Struct>(ast::StructMemberList{Member("a", ty.i32())},
|
||||||
ast::StructDecorationList{}));
|
ast::StructDecorationList{}));
|
||||||
type::AccessControl ac{ast::AccessControl::kReadOnly, A};
|
auto* ac = create<type::AccessControl>(ast::AccessControl::kReadOnly, A);
|
||||||
auto* B = ty.alias("B", &ac);
|
auto* B = ty.alias("B", ac);
|
||||||
auto* var = Var("b", ast::StorageClass::kStorage, B);
|
auto* var = Global("b", ast::StorageClass::kStorage, B);
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -519,8 +511,8 @@ TEST_F(BuilderTest, GlobalVar_TwoVarDeclReadOnly) {
|
||||||
type::AccessControl read{ast::AccessControl::kReadOnly, A};
|
type::AccessControl read{ast::AccessControl::kReadOnly, A};
|
||||||
type::AccessControl rw{ast::AccessControl::kReadWrite, A};
|
type::AccessControl rw{ast::AccessControl::kReadWrite, A};
|
||||||
|
|
||||||
auto* var_b = Var("b", ast::StorageClass::kStorage, &read);
|
auto* var_b = Global("b", ast::StorageClass::kStorage, &read);
|
||||||
auto* var_c = Var("c", ast::StorageClass::kStorage, &rw);
|
auto* var_c = Global("c", ast::StorageClass::kStorage, &rw);
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -550,13 +542,12 @@ OpName %5 "c"
|
||||||
TEST_F(BuilderTest, GlobalVar_TextureStorageReadOnly) {
|
TEST_F(BuilderTest, GlobalVar_TextureStorageReadOnly) {
|
||||||
// var<uniform_constant> a : [[access(read)]] texture_storage_2d<r32uint>;
|
// var<uniform_constant> a : [[access(read)]] texture_storage_2d<r32uint>;
|
||||||
|
|
||||||
type::StorageTexture type(type::TextureDimension::k2d,
|
auto* type = create<type::StorageTexture>(type::TextureDimension::k2d,
|
||||||
type::ImageFormat::kR32Uint);
|
type::ImageFormat::kR32Uint);
|
||||||
ASSERT_TRUE(td.DetermineStorageTextureSubtype(&type)) << td.error();
|
|
||||||
|
|
||||||
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();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -574,13 +565,13 @@ TEST_F(BuilderTest, GlobalVar_TextureStorageReadOnly) {
|
||||||
TEST_F(BuilderTest, GlobalVar_TextureStorageWriteOnly) {
|
TEST_F(BuilderTest, GlobalVar_TextureStorageWriteOnly) {
|
||||||
// var<uniform_constant> a : [[access(write)]] texture_storage_2d<r32uint>;
|
// var<uniform_constant> a : [[access(write)]] texture_storage_2d<r32uint>;
|
||||||
|
|
||||||
type::StorageTexture type(type::TextureDimension::k2d,
|
auto* type = create<type::StorageTexture>(type::TextureDimension::k2d,
|
||||||
type::ImageFormat::kR32Uint);
|
type::ImageFormat::kR32Uint);
|
||||||
ASSERT_TRUE(td.DetermineStorageTextureSubtype(&type)) << td.error();
|
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();
|
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> a : [[access(read)]] texture_storage_2d<r32uint>;
|
||||||
// var<uniform_constant> b : [[access(write)]] texture_storage_2d<r32uint>;
|
// var<uniform_constant> b : [[access(write)]] texture_storage_2d<r32uint>;
|
||||||
|
|
||||||
type::StorageTexture st(type::TextureDimension::k2d,
|
auto* st = create<type::StorageTexture>(type::TextureDimension::k2d,
|
||||||
type::ImageFormat::kR32Uint);
|
type::ImageFormat::kR32Uint);
|
||||||
ASSERT_TRUE(td.DetermineStorageTextureSubtype(&st)) << td.error();
|
|
||||||
|
|
||||||
type::AccessControl type_a(ast::AccessControl::kReadOnly, &st);
|
Global("test_var", ast::StorageClass::kNone, st);
|
||||||
auto* var_a = Var("a", ast::StorageClass::kUniformConstant, &type_a);
|
|
||||||
|
|
||||||
type::AccessControl type_b(ast::AccessControl::kWriteOnly, &st);
|
auto* type_a = create<type::AccessControl>(ast::AccessControl::kReadOnly, st);
|
||||||
auto* var_b = Var("b", ast::StorageClass::kUniformConstant, &type_b);
|
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();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
|
|
@ -39,14 +39,12 @@ using BuilderTest = TestHelper;
|
||||||
|
|
||||||
TEST_F(BuilderTest, IdentifierExpression_GlobalConst) {
|
TEST_F(BuilderTest, IdentifierExpression_GlobalConst) {
|
||||||
auto* init = vec3<f32>(1.f, 1.f, 3.f);
|
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,
|
auto* v = GlobalConst("var", ast::StorageClass::kOutput, ty.f32(), init,
|
||||||
ast::VariableDecorationList{});
|
ast::VariableDecorationList{});
|
||||||
td.RegisterVariableForTesting(v);
|
|
||||||
|
|
||||||
auto* expr = Expr("var");
|
auto* expr = Expr("var");
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr));
|
WrapInFunction(expr);
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -64,11 +62,10 @@ TEST_F(BuilderTest, IdentifierExpression_GlobalConst) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(BuilderTest, IdentifierExpression_GlobalVar) {
|
TEST_F(BuilderTest, IdentifierExpression_GlobalVar) {
|
||||||
auto* v = Var("var", ast::StorageClass::kOutput, ty.f32());
|
auto* v = Global("var", ast::StorageClass::kOutput, ty.f32());
|
||||||
td.RegisterVariableForTesting(v);
|
|
||||||
|
|
||||||
auto* expr = Expr("var");
|
auto* expr = Expr("var");
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr));
|
WrapInFunction(expr);
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -87,14 +84,12 @@ TEST_F(BuilderTest, IdentifierExpression_GlobalVar) {
|
||||||
|
|
||||||
TEST_F(BuilderTest, IdentifierExpression_FunctionConst) {
|
TEST_F(BuilderTest, IdentifierExpression_FunctionConst) {
|
||||||
auto* init = vec3<f32>(1.f, 1.f, 3.f);
|
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,
|
auto* v = Const("var", ast::StorageClass::kOutput, ty.f32(), init,
|
||||||
ast::VariableDecorationList{});
|
ast::VariableDecorationList{});
|
||||||
td.RegisterVariableForTesting(v);
|
|
||||||
|
|
||||||
auto* expr = Expr("var");
|
auto* expr = Expr("var");
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr));
|
WrapInFunction(v, expr);
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -113,10 +108,8 @@ TEST_F(BuilderTest, IdentifierExpression_FunctionConst) {
|
||||||
|
|
||||||
TEST_F(BuilderTest, IdentifierExpression_FunctionVar) {
|
TEST_F(BuilderTest, IdentifierExpression_FunctionVar) {
|
||||||
auto* v = Var("var", ast::StorageClass::kNone, ty.f32());
|
auto* v = Var("var", ast::StorageClass::kNone, ty.f32());
|
||||||
td.RegisterVariableForTesting(v);
|
|
||||||
|
|
||||||
auto* expr = Expr("var");
|
auto* expr = Expr("var");
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr));
|
WrapInFunction(v, expr);
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -138,11 +131,10 @@ TEST_F(BuilderTest, IdentifierExpression_FunctionVar) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(BuilderTest, IdentifierExpression_Load) {
|
TEST_F(BuilderTest, IdentifierExpression_Load) {
|
||||||
auto* var = Var("var", ast::StorageClass::kPrivate, ty.i32());
|
auto* var = Global("var", ast::StorageClass::kPrivate, ty.i32());
|
||||||
td.RegisterVariableForTesting(var);
|
|
||||||
|
|
||||||
auto* expr = Add("var", "var");
|
auto* expr = Add("var", "var");
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
WrapInFunction(expr);
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -164,12 +156,11 @@ TEST_F(BuilderTest, IdentifierExpression_Load) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(BuilderTest, IdentifierExpression_NoLoadConst) {
|
TEST_F(BuilderTest, IdentifierExpression_NoLoadConst) {
|
||||||
auto* var = Const("var", ast::StorageClass::kNone, ty.i32(), Expr(2),
|
auto* var = GlobalConst("var", ast::StorageClass::kNone, ty.i32(), Expr(2),
|
||||||
ast::VariableDecorationList{});
|
ast::VariableDecorationList{});
|
||||||
td.RegisterVariableForTesting(var);
|
|
||||||
|
|
||||||
auto* expr = Add("var", "var");
|
auto* expr = Add("var", "var");
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
WrapInFunction(expr);
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
|
|
@ -48,8 +48,7 @@ TEST_F(BuilderTest, If_Empty) {
|
||||||
auto* expr = create<ast::IfStatement>(
|
auto* expr = create<ast::IfStatement>(
|
||||||
cond, create<ast::BlockStatement>(ast::StatementList{}),
|
cond, create<ast::BlockStatement>(ast::StatementList{}),
|
||||||
ast::ElseStatementList{});
|
ast::ElseStatementList{});
|
||||||
|
WrapInFunction(expr);
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -77,8 +76,7 @@ TEST_F(BuilderTest, If_Empty_OutsideFunction_IsError) {
|
||||||
ast::ElseStatementList elses;
|
ast::ElseStatementList elses;
|
||||||
auto* block = create<ast::BlockStatement>(ast::StatementList{});
|
auto* block = create<ast::BlockStatement>(ast::StatementList{});
|
||||||
auto* expr = create<ast::IfStatement>(cond, block, elses);
|
auto* expr = create<ast::IfStatement>(cond, block, elses);
|
||||||
|
WrapInFunction(expr);
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -94,14 +92,12 @@ TEST_F(BuilderTest, If_WithStatements) {
|
||||||
// v = 2;
|
// 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>(
|
auto* body = create<ast::BlockStatement>(
|
||||||
ast::StatementList{create<ast::AssignmentStatement>(Expr("v"), Expr(2))});
|
ast::StatementList{create<ast::AssignmentStatement>(Expr("v"), Expr(2))});
|
||||||
auto* expr =
|
auto* expr =
|
||||||
create<ast::IfStatement>(Expr(true), body, ast::ElseStatementList{});
|
create<ast::IfStatement>(Expr(true), body, ast::ElseStatementList{});
|
||||||
|
WrapInFunction(expr);
|
||||||
td.RegisterVariableForTesting(var);
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -134,7 +130,7 @@ TEST_F(BuilderTest, If_WithElse) {
|
||||||
// v = 3;
|
// 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>(
|
auto* body = create<ast::BlockStatement>(
|
||||||
ast::StatementList{create<ast::AssignmentStatement>(Expr("v"), Expr(2))});
|
ast::StatementList{create<ast::AssignmentStatement>(Expr("v"), Expr(2))});
|
||||||
auto* else_body = create<ast::BlockStatement>(
|
auto* else_body = create<ast::BlockStatement>(
|
||||||
|
@ -143,10 +139,7 @@ TEST_F(BuilderTest, If_WithElse) {
|
||||||
auto* expr = create<ast::IfStatement>(
|
auto* expr = create<ast::IfStatement>(
|
||||||
Expr(true), body,
|
Expr(true), body,
|
||||||
ast::ElseStatementList{create<ast::ElseStatement>(nullptr, else_body)});
|
ast::ElseStatementList{create<ast::ElseStatement>(nullptr, else_body)});
|
||||||
|
WrapInFunction(expr);
|
||||||
td.RegisterVariableForTesting(var);
|
|
||||||
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -183,7 +176,7 @@ TEST_F(BuilderTest, If_WithElseIf) {
|
||||||
// v = 3;
|
// 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>(
|
auto* body = create<ast::BlockStatement>(
|
||||||
ast::StatementList{create<ast::AssignmentStatement>(Expr("v"), Expr(2))});
|
ast::StatementList{create<ast::AssignmentStatement>(Expr("v"), Expr(2))});
|
||||||
auto* else_body = create<ast::BlockStatement>(
|
auto* else_body = create<ast::BlockStatement>(
|
||||||
|
@ -194,10 +187,7 @@ TEST_F(BuilderTest, If_WithElseIf) {
|
||||||
ast::ElseStatementList{
|
ast::ElseStatementList{
|
||||||
create<ast::ElseStatement>(Expr(true), else_body),
|
create<ast::ElseStatement>(Expr(true), else_body),
|
||||||
});
|
});
|
||||||
|
WrapInFunction(expr);
|
||||||
td.RegisterVariableForTesting(var);
|
|
||||||
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -243,7 +233,7 @@ TEST_F(BuilderTest, If_WithMultiple) {
|
||||||
// v = 5;
|
// 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>(
|
auto* body = create<ast::BlockStatement>(
|
||||||
ast::StatementList{create<ast::AssignmentStatement>(Expr("v"), Expr(2))});
|
ast::StatementList{create<ast::AssignmentStatement>(Expr("v"), Expr(2))});
|
||||||
auto* elseif_1_body = create<ast::BlockStatement>(
|
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>(Expr(false), elseif_2_body),
|
||||||
create<ast::ElseStatement>(nullptr, else_body),
|
create<ast::ElseStatement>(nullptr, else_body),
|
||||||
});
|
});
|
||||||
|
WrapInFunction(expr);
|
||||||
td.RegisterVariableForTesting(var);
|
|
||||||
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -332,8 +319,7 @@ TEST_F(BuilderTest, If_WithBreak) {
|
||||||
|
|
||||||
auto* expr = create<ast::LoopStatement>(
|
auto* expr = create<ast::LoopStatement>(
|
||||||
loop_body, create<ast::BlockStatement>(ast::StatementList{}));
|
loop_body, create<ast::BlockStatement>(ast::StatementList{}));
|
||||||
|
WrapInFunction(expr);
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -382,8 +368,7 @@ TEST_F(BuilderTest, If_WithElseBreak) {
|
||||||
|
|
||||||
auto* expr = create<ast::LoopStatement>(
|
auto* expr = create<ast::LoopStatement>(
|
||||||
loop_body, create<ast::BlockStatement>(ast::StatementList{}));
|
loop_body, create<ast::BlockStatement>(ast::StatementList{}));
|
||||||
|
WrapInFunction(expr);
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -432,8 +417,7 @@ TEST_F(BuilderTest, If_WithContinue) {
|
||||||
|
|
||||||
auto* expr = create<ast::LoopStatement>(
|
auto* expr = create<ast::LoopStatement>(
|
||||||
loop_body, create<ast::BlockStatement>(ast::StatementList{}));
|
loop_body, create<ast::BlockStatement>(ast::StatementList{}));
|
||||||
|
WrapInFunction(expr);
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -482,8 +466,7 @@ TEST_F(BuilderTest, If_WithElseContinue) {
|
||||||
|
|
||||||
auto* expr = create<ast::LoopStatement>(
|
auto* expr = create<ast::LoopStatement>(
|
||||||
loop_body, create<ast::BlockStatement>(ast::StatementList{}));
|
loop_body, create<ast::BlockStatement>(ast::StatementList{}));
|
||||||
|
WrapInFunction(expr);
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -523,7 +506,7 @@ TEST_F(BuilderTest, If_WithReturn) {
|
||||||
|
|
||||||
auto* expr =
|
auto* expr =
|
||||||
create<ast::IfStatement>(Expr(true), if_body, ast::ElseStatementList{});
|
create<ast::IfStatement>(Expr(true), if_body, ast::ElseStatementList{});
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
WrapInFunction(expr);
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -552,7 +535,7 @@ TEST_F(BuilderTest, If_WithReturnValue) {
|
||||||
|
|
||||||
auto* expr =
|
auto* expr =
|
||||||
create<ast::IfStatement>(Expr(true), if_body, ast::ElseStatementList{});
|
create<ast::IfStatement>(Expr(true), if_body, ast::ElseStatementList{});
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
WrapInFunction(expr);
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -577,14 +560,12 @@ TEST_F(BuilderTest, If_WithLoad_Bug327) {
|
||||||
// if (a) {
|
// if (a) {
|
||||||
// }
|
// }
|
||||||
|
|
||||||
auto* var = Var("a", ast::StorageClass::kFunction, ty.bool_());
|
auto* var = Global("a", ast::StorageClass::kFunction, ty.bool_());
|
||||||
td.RegisterVariableForTesting(var);
|
|
||||||
|
|
||||||
auto* expr = create<ast::IfStatement>(
|
auto* expr = create<ast::IfStatement>(
|
||||||
Expr("a"), create<ast::BlockStatement>(ast::StatementList{}),
|
Expr("a"), create<ast::BlockStatement>(ast::StatementList{}),
|
||||||
ast::ElseStatementList{});
|
ast::ElseStatementList{});
|
||||||
|
WrapInFunction(expr);
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
|
|
@ -69,10 +69,10 @@ using IntrinsicBoolTest = IntrinsicBuilderTestWithParam<IntrinsicData>;
|
||||||
TEST_P(IntrinsicBoolTest, Call_Bool) {
|
TEST_P(IntrinsicBoolTest, Call_Bool) {
|
||||||
auto param = GetParam();
|
auto param = GetParam();
|
||||||
|
|
||||||
auto* var = Var("v", ast::StorageClass::kPrivate, ty.vec3<bool>());
|
auto* var = Global("v", ast::StorageClass::kPrivate, ty.vec3<bool>());
|
||||||
auto* expr = Call(param.name, "v");
|
|
||||||
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
auto* expr = Call(param.name, "v");
|
||||||
|
WrapInFunction(expr);
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -100,10 +100,10 @@ using IntrinsicFloatTest = IntrinsicBuilderTestWithParam<IntrinsicData>;
|
||||||
TEST_P(IntrinsicFloatTest, Call_Float_Scalar) {
|
TEST_P(IntrinsicFloatTest, Call_Float_Scalar) {
|
||||||
auto param = GetParam();
|
auto param = GetParam();
|
||||||
|
|
||||||
auto* var = Var("v", ast::StorageClass::kPrivate, ty.f32());
|
auto* var = Global("v", ast::StorageClass::kPrivate, ty.f32());
|
||||||
auto* expr = Call(param.name, "v");
|
|
||||||
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
auto* expr = Call(param.name, "v");
|
||||||
|
WrapInFunction(expr);
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -126,10 +126,10 @@ TEST_P(IntrinsicFloatTest, Call_Float_Scalar) {
|
||||||
TEST_P(IntrinsicFloatTest, Call_Float_Vector) {
|
TEST_P(IntrinsicFloatTest, Call_Float_Vector) {
|
||||||
auto param = GetParam();
|
auto param = GetParam();
|
||||||
|
|
||||||
auto* var = Var("v", ast::StorageClass::kPrivate, ty.vec3<f32>());
|
auto* var = Global("v", ast::StorageClass::kPrivate, ty.vec3<f32>());
|
||||||
auto* expr = Call(param.name, "v");
|
|
||||||
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
auto* expr = Call(param.name, "v");
|
||||||
|
WrapInFunction(expr);
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -159,10 +159,10 @@ using IntrinsicIntTest = IntrinsicBuilderTestWithParam<IntrinsicData>;
|
||||||
TEST_P(IntrinsicIntTest, Call_SInt_Scalar) {
|
TEST_P(IntrinsicIntTest, Call_SInt_Scalar) {
|
||||||
auto param = GetParam();
|
auto param = GetParam();
|
||||||
|
|
||||||
auto* var = Var("v", ast::StorageClass::kPrivate, ty.i32());
|
auto* var = Global("v", ast::StorageClass::kPrivate, ty.i32());
|
||||||
auto* expr = Call(param.name, "v");
|
|
||||||
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
auto* expr = Call(param.name, "v");
|
||||||
|
WrapInFunction(expr);
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -184,10 +184,10 @@ TEST_P(IntrinsicIntTest, Call_SInt_Scalar) {
|
||||||
TEST_P(IntrinsicIntTest, Call_SInt_Vector) {
|
TEST_P(IntrinsicIntTest, Call_SInt_Vector) {
|
||||||
auto param = GetParam();
|
auto param = GetParam();
|
||||||
|
|
||||||
auto* var = Var("v", ast::StorageClass::kPrivate, ty.vec3<i32>());
|
auto* var = Global("v", ast::StorageClass::kPrivate, ty.vec3<i32>());
|
||||||
auto* expr = Call(param.name, "v");
|
|
||||||
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
auto* expr = Call(param.name, "v");
|
||||||
|
WrapInFunction(expr);
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -210,10 +210,10 @@ TEST_P(IntrinsicIntTest, Call_SInt_Vector) {
|
||||||
TEST_P(IntrinsicIntTest, Call_UInt_Scalar) {
|
TEST_P(IntrinsicIntTest, Call_UInt_Scalar) {
|
||||||
auto param = GetParam();
|
auto param = GetParam();
|
||||||
|
|
||||||
auto* var = Var("v", ast::StorageClass::kPrivate, ty.u32());
|
auto* var = Global("v", ast::StorageClass::kPrivate, ty.u32());
|
||||||
auto* expr = Call(param.name, "v");
|
|
||||||
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
auto* expr = Call(param.name, "v");
|
||||||
|
WrapInFunction(expr);
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -235,10 +235,10 @@ TEST_P(IntrinsicIntTest, Call_UInt_Scalar) {
|
||||||
TEST_P(IntrinsicIntTest, Call_UInt_Vector) {
|
TEST_P(IntrinsicIntTest, Call_UInt_Vector) {
|
||||||
auto param = GetParam();
|
auto param = GetParam();
|
||||||
|
|
||||||
auto* var = Var("v", ast::StorageClass::kPrivate, ty.vec3<u32>());
|
auto* var = Global("v", ast::StorageClass::kPrivate, ty.vec3<u32>());
|
||||||
auto* expr = Call(param.name, "v");
|
|
||||||
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
auto* expr = Call(param.name, "v");
|
||||||
|
WrapInFunction(expr);
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -264,10 +264,10 @@ INSTANTIATE_TEST_SUITE_P(
|
||||||
IntrinsicData{"reverseBits", "OpBitReverse"}));
|
IntrinsicData{"reverseBits", "OpBitReverse"}));
|
||||||
|
|
||||||
TEST_F(IntrinsicBuilderTest, Call_Dot) {
|
TEST_F(IntrinsicBuilderTest, Call_Dot) {
|
||||||
auto* var = Var("v", ast::StorageClass::kPrivate, ty.vec3<f32>());
|
auto* var = Global("v", ast::StorageClass::kPrivate, ty.vec3<f32>());
|
||||||
auto* expr = Call("dot", "v", "v");
|
|
||||||
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
auto* expr = Call("dot", "v", "v");
|
||||||
|
WrapInFunction(expr);
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -292,10 +292,10 @@ using IntrinsicDeriveTest = IntrinsicBuilderTestWithParam<IntrinsicData>;
|
||||||
TEST_P(IntrinsicDeriveTest, Call_Derivative_Scalar) {
|
TEST_P(IntrinsicDeriveTest, Call_Derivative_Scalar) {
|
||||||
auto param = GetParam();
|
auto param = GetParam();
|
||||||
|
|
||||||
auto* var = Var("v", ast::StorageClass::kPrivate, ty.f32());
|
auto* var = Global("v", ast::StorageClass::kPrivate, ty.f32());
|
||||||
auto* expr = Call(param.name, "v");
|
|
||||||
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
auto* expr = Call(param.name, "v");
|
||||||
|
WrapInFunction(expr);
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -317,10 +317,10 @@ TEST_P(IntrinsicDeriveTest, Call_Derivative_Scalar) {
|
||||||
TEST_P(IntrinsicDeriveTest, Call_Derivative_Vector) {
|
TEST_P(IntrinsicDeriveTest, Call_Derivative_Vector) {
|
||||||
auto param = GetParam();
|
auto param = GetParam();
|
||||||
|
|
||||||
auto* var = Var("v", ast::StorageClass::kPrivate, ty.vec3<f32>());
|
auto* var = Global("v", ast::StorageClass::kPrivate, ty.vec3<f32>());
|
||||||
auto* expr = Call(param.name, "v");
|
|
||||||
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
auto* expr = Call(param.name, "v");
|
||||||
|
WrapInFunction(expr);
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -360,11 +360,13 @@ INSTANTIATE_TEST_SUITE_P(
|
||||||
IntrinsicData{"fwidthCoarse", "OpFwidthCoarse"}));
|
IntrinsicData{"fwidthCoarse", "OpFwidthCoarse"}));
|
||||||
|
|
||||||
TEST_F(IntrinsicBuilderTest, Call_Select) {
|
TEST_F(IntrinsicBuilderTest, Call_Select) {
|
||||||
auto* v3 = Var("v3", ast::StorageClass::kPrivate, ty.vec3<f32>());
|
auto* v3 = Global("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");
|
|
||||||
|
|
||||||
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();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -398,15 +400,17 @@ TEST_F(IntrinsicBuilderTest, Call_TextureSampleCompare_Twice) {
|
||||||
type::Sampler s(type::SamplerKind::kComparisonSampler);
|
type::Sampler s(type::SamplerKind::kComparisonSampler);
|
||||||
type::DepthTexture t(type::TextureDimension::k2d);
|
type::DepthTexture t(type::TextureDimension::k2d);
|
||||||
|
|
||||||
auto* tex = Var("texture", ast::StorageClass::kNone, &t);
|
auto* tex = Global("texture", ast::StorageClass::kNone, &t);
|
||||||
auto* sampler = Var("sampler", ast::StorageClass::kNone, &s);
|
|
||||||
|
auto* sampler = Global("sampler", ast::StorageClass::kNone, &s);
|
||||||
|
|
||||||
auto* expr1 = Call("textureSampleCompare", "texture", "sampler",
|
auto* expr1 = Call("textureSampleCompare", "texture", "sampler",
|
||||||
vec2<f32>(1.0f, 2.0f), 2.0f);
|
vec2<f32>(1.0f, 2.0f), 2.0f);
|
||||||
auto* expr2 = Call("textureSampleCompare", "texture", "sampler",
|
auto* expr2 = Call("textureSampleCompare", "texture", "sampler",
|
||||||
vec2<f32>(1.0f, 2.0f), 2.0f);
|
vec2<f32>(1.0f, 2.0f), 2.0f);
|
||||||
|
|
||||||
EXPECT_TRUE(td.DetermineResultType(expr1)) << td.error();
|
WrapInFunction(expr1);
|
||||||
EXPECT_TRUE(td.DetermineResultType(expr2)) << td.error();
|
WrapInFunction(expr2);
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -446,10 +450,10 @@ TEST_F(IntrinsicBuilderTest, Call_TextureSampleCompare_Twice) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(IntrinsicBuilderTest, Call_GLSLMethod_WithLoad) {
|
TEST_F(IntrinsicBuilderTest, Call_GLSLMethod_WithLoad) {
|
||||||
auto* var = Var("ident", ast::StorageClass::kPrivate, ty.f32());
|
auto* var = Global("ident", ast::StorageClass::kPrivate, ty.f32());
|
||||||
auto* expr = Call("round", "ident");
|
|
||||||
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
auto* expr = Call("round", "ident");
|
||||||
|
WrapInFunction(expr);
|
||||||
|
|
||||||
auto* func = Func("a_func", ast::VariableList{}, ty.void_(),
|
auto* func = Func("a_func", ast::VariableList{}, ty.void_(),
|
||||||
ast::StatementList{}, ast::FunctionDecorationList{});
|
ast::StatementList{}, ast::FunctionDecorationList{});
|
||||||
|
@ -484,7 +488,7 @@ TEST_P(Intrinsic_Builtin_SingleParam_Float_Test, Call_Scalar) {
|
||||||
auto param = GetParam();
|
auto param = GetParam();
|
||||||
|
|
||||||
auto* expr = Call(param.name, 1.0f);
|
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_(),
|
auto* func = Func("a_func", ast::VariableList{}, ty.void_(),
|
||||||
ast::StatementList{}, ast::FunctionDecorationList{});
|
ast::StatementList{}, ast::FunctionDecorationList{});
|
||||||
|
@ -513,7 +517,7 @@ TEST_P(Intrinsic_Builtin_SingleParam_Float_Test, Call_Vector) {
|
||||||
auto param = GetParam();
|
auto param = GetParam();
|
||||||
|
|
||||||
auto* expr = Call(param.name, vec2<f32>(1.0f, 1.0f));
|
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_(),
|
auto* func = Func("a_func", ast::VariableList{}, ty.void_(),
|
||||||
ast::StatementList{}, ast::FunctionDecorationList{});
|
ast::StatementList{}, ast::FunctionDecorationList{});
|
||||||
|
@ -568,7 +572,7 @@ INSTANTIATE_TEST_SUITE_P(IntrinsicBuilderTest,
|
||||||
TEST_F(IntrinsicBuilderTest, Call_Length_Scalar) {
|
TEST_F(IntrinsicBuilderTest, Call_Length_Scalar) {
|
||||||
auto* expr = Call("length", 1.0f);
|
auto* expr = Call("length", 1.0f);
|
||||||
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
WrapInFunction(expr);
|
||||||
|
|
||||||
auto* func = Func("a_func", ast::VariableList{}, ty.void_(),
|
auto* func = Func("a_func", ast::VariableList{}, ty.void_(),
|
||||||
ast::StatementList{}, ast::FunctionDecorationList{});
|
ast::StatementList{}, ast::FunctionDecorationList{});
|
||||||
|
@ -594,7 +598,7 @@ OpFunctionEnd
|
||||||
|
|
||||||
TEST_F(IntrinsicBuilderTest, Call_Length_Vector) {
|
TEST_F(IntrinsicBuilderTest, Call_Length_Vector) {
|
||||||
auto* expr = Call("length", vec2<f32>(1.0f, 1.0f));
|
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_(),
|
auto* func = Func("a_func", ast::VariableList{}, ty.void_(),
|
||||||
ast::StatementList{}, ast::FunctionDecorationList{});
|
ast::StatementList{}, ast::FunctionDecorationList{});
|
||||||
|
@ -622,7 +626,7 @@ OpFunctionEnd
|
||||||
|
|
||||||
TEST_F(IntrinsicBuilderTest, Call_Normalize) {
|
TEST_F(IntrinsicBuilderTest, Call_Normalize) {
|
||||||
auto* expr = Call("normalize", vec2<f32>(1.0f, 1.0f));
|
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_(),
|
auto* func = Func("a_func", ast::VariableList{}, ty.void_(),
|
||||||
ast::StatementList{}, ast::FunctionDecorationList{});
|
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);
|
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_(),
|
auto* func = Func("a_func", ast::VariableList{}, ty.void_(),
|
||||||
ast::StatementList{}, ast::FunctionDecorationList{});
|
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));
|
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_(),
|
auto* func = Func("a_func", ast::VariableList{}, ty.void_(),
|
||||||
ast::StatementList{}, ast::FunctionDecorationList{});
|
ast::StatementList{}, ast::FunctionDecorationList{});
|
||||||
|
@ -723,7 +727,7 @@ INSTANTIATE_TEST_SUITE_P(IntrinsicBuilderTest,
|
||||||
TEST_F(IntrinsicBuilderTest, Call_Distance_Scalar) {
|
TEST_F(IntrinsicBuilderTest, Call_Distance_Scalar) {
|
||||||
auto* expr = Call("distance", 1.0f, 1.0f);
|
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_(),
|
auto* func = Func("a_func", ast::VariableList{}, ty.void_(),
|
||||||
ast::StatementList{}, ast::FunctionDecorationList{});
|
ast::StatementList{}, ast::FunctionDecorationList{});
|
||||||
|
@ -750,7 +754,7 @@ OpFunctionEnd
|
||||||
TEST_F(IntrinsicBuilderTest, Call_Distance_Vector) {
|
TEST_F(IntrinsicBuilderTest, Call_Distance_Vector) {
|
||||||
auto* expr = Call("distance", vec2<f32>(1.0f, 1.0f), vec2<f32>(1.0f, 1.0f));
|
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_(),
|
auto* func = Func("a_func", ast::VariableList{}, ty.void_(),
|
||||||
ast::StatementList{}, ast::FunctionDecorationList{});
|
ast::StatementList{}, ast::FunctionDecorationList{});
|
||||||
|
@ -780,7 +784,7 @@ TEST_F(IntrinsicBuilderTest, Call_Cross) {
|
||||||
auto* expr =
|
auto* expr =
|
||||||
Call("cross", vec3<f32>(1.0f, 1.0f, 1.0f), vec3<f32>(1.0f, 1.0f, 1.0f));
|
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_(),
|
auto* func = Func("a_func", ast::VariableList{}, ty.void_(),
|
||||||
ast::StatementList{}, ast::FunctionDecorationList{});
|
ast::StatementList{}, ast::FunctionDecorationList{});
|
||||||
|
@ -812,7 +816,7 @@ TEST_P(Intrinsic_Builtin_ThreeParam_Float_Test, Call_Scalar) {
|
||||||
auto param = GetParam();
|
auto param = GetParam();
|
||||||
|
|
||||||
auto* expr = Call(param.name, 1.0f, 1.0f, 1.0f);
|
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_(),
|
auto* func = Func("a_func", ast::VariableList{}, ty.void_(),
|
||||||
ast::StatementList{}, ast::FunctionDecorationList{});
|
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),
|
auto* expr = Call(param.name, vec2<f32>(1.0f, 1.0f), 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_(),
|
auto* func = Func("a_func", ast::VariableList{}, ty.void_(),
|
||||||
ast::StatementList{}, ast::FunctionDecorationList{});
|
ast::StatementList{}, ast::FunctionDecorationList{});
|
||||||
|
@ -885,7 +889,7 @@ TEST_P(Intrinsic_Builtin_SingleParam_Sint_Test, Call_Scalar) {
|
||||||
auto param = GetParam();
|
auto param = GetParam();
|
||||||
|
|
||||||
auto* expr = Call(param.name, 1);
|
auto* expr = Call(param.name, 1);
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
WrapInFunction(expr);
|
||||||
|
|
||||||
auto* func = Func("a_func", ast::VariableList{}, ty.void_(),
|
auto* func = Func("a_func", ast::VariableList{}, ty.void_(),
|
||||||
ast::StatementList{}, ast::FunctionDecorationList{});
|
ast::StatementList{}, ast::FunctionDecorationList{});
|
||||||
|
@ -914,7 +918,7 @@ TEST_P(Intrinsic_Builtin_SingleParam_Sint_Test, Call_Vector) {
|
||||||
auto param = GetParam();
|
auto param = GetParam();
|
||||||
|
|
||||||
auto* expr = Call(param.name, vec2<i32>(1, 1));
|
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_(),
|
auto* func = Func("a_func", ast::VariableList{}, ty.void_(),
|
||||||
ast::StatementList{}, ast::FunctionDecorationList{});
|
ast::StatementList{}, ast::FunctionDecorationList{});
|
||||||
|
@ -950,7 +954,7 @@ TEST_P(Intrinsic_Builtin_SingleParam_Uint_Test, Call_Scalar) {
|
||||||
auto param = GetParam();
|
auto param = GetParam();
|
||||||
|
|
||||||
auto* expr = Call(param.name, 1u);
|
auto* expr = Call(param.name, 1u);
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
WrapInFunction(expr);
|
||||||
|
|
||||||
auto* func = Func("a_func", ast::VariableList{}, ty.void_(),
|
auto* func = Func("a_func", ast::VariableList{}, ty.void_(),
|
||||||
ast::StatementList{}, ast::FunctionDecorationList{});
|
ast::StatementList{}, ast::FunctionDecorationList{});
|
||||||
|
@ -979,7 +983,7 @@ TEST_P(Intrinsic_Builtin_SingleParam_Uint_Test, Call_Vector) {
|
||||||
auto param = GetParam();
|
auto param = GetParam();
|
||||||
|
|
||||||
auto* expr = Call(param.name, vec2<u32>(1u, 1u));
|
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_(),
|
auto* func = Func("a_func", ast::VariableList{}, ty.void_(),
|
||||||
ast::StatementList{}, ast::FunctionDecorationList{});
|
ast::StatementList{}, ast::FunctionDecorationList{});
|
||||||
|
@ -1015,7 +1019,7 @@ TEST_P(Intrinsic_Builtin_DualParam_SInt_Test, Call_Scalar) {
|
||||||
auto param = GetParam();
|
auto param = GetParam();
|
||||||
|
|
||||||
auto* expr = Call(param.name, 1, 1);
|
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_(),
|
auto* func = Func("a_func", ast::VariableList{}, ty.void_(),
|
||||||
ast::StatementList{}, ast::FunctionDecorationList{});
|
ast::StatementList{}, ast::FunctionDecorationList{});
|
||||||
|
@ -1044,7 +1048,7 @@ TEST_P(Intrinsic_Builtin_DualParam_SInt_Test, Call_Vector) {
|
||||||
auto param = GetParam();
|
auto param = GetParam();
|
||||||
|
|
||||||
auto* expr = Call(param.name, vec2<i32>(1, 1), vec2<i32>(1, 1));
|
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_(),
|
auto* func = Func("a_func", ast::VariableList{}, ty.void_(),
|
||||||
ast::StatementList{}, ast::FunctionDecorationList{});
|
ast::StatementList{}, ast::FunctionDecorationList{});
|
||||||
|
@ -1081,7 +1085,7 @@ TEST_P(Intrinsic_Builtin_DualParam_UInt_Test, Call_Scalar) {
|
||||||
auto param = GetParam();
|
auto param = GetParam();
|
||||||
|
|
||||||
auto* expr = Call(param.name, 1u, 1u);
|
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_(),
|
auto* func = Func("a_func", ast::VariableList{}, ty.void_(),
|
||||||
ast::StatementList{}, ast::FunctionDecorationList{});
|
ast::StatementList{}, ast::FunctionDecorationList{});
|
||||||
|
@ -1110,7 +1114,7 @@ TEST_P(Intrinsic_Builtin_DualParam_UInt_Test, Call_Vector) {
|
||||||
auto param = GetParam();
|
auto param = GetParam();
|
||||||
|
|
||||||
auto* expr = Call(param.name, vec2<u32>(1u, 1u), vec2<u32>(1u, 1u));
|
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_(),
|
auto* func = Func("a_func", ast::VariableList{}, ty.void_(),
|
||||||
ast::StatementList{}, ast::FunctionDecorationList{});
|
ast::StatementList{}, ast::FunctionDecorationList{});
|
||||||
|
@ -1147,7 +1151,7 @@ TEST_P(Intrinsic_Builtin_ThreeParam_Sint_Test, Call_Scalar) {
|
||||||
auto param = GetParam();
|
auto param = GetParam();
|
||||||
|
|
||||||
auto* expr = Call(param.name, 1, 1, 1);
|
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_(),
|
auto* func = Func("a_func", ast::VariableList{}, ty.void_(),
|
||||||
ast::StatementList{}, ast::FunctionDecorationList{});
|
ast::StatementList{}, ast::FunctionDecorationList{});
|
||||||
|
@ -1178,7 +1182,7 @@ TEST_P(Intrinsic_Builtin_ThreeParam_Sint_Test, Call_Vector) {
|
||||||
auto* expr =
|
auto* expr =
|
||||||
Call(param.name, vec2<i32>(1, 1), vec2<i32>(1, 1), vec2<i32>(1, 1));
|
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_(),
|
auto* func = Func("a_func", ast::VariableList{}, ty.void_(),
|
||||||
ast::StatementList{}, ast::FunctionDecorationList{});
|
ast::StatementList{}, ast::FunctionDecorationList{});
|
||||||
|
@ -1214,7 +1218,7 @@ TEST_P(Intrinsic_Builtin_ThreeParam_Uint_Test, Call_Scalar) {
|
||||||
auto param = GetParam();
|
auto param = GetParam();
|
||||||
|
|
||||||
auto* expr = Call(param.name, 1u, 1u, 1u);
|
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_(),
|
auto* func = Func("a_func", ast::VariableList{}, ty.void_(),
|
||||||
ast::StatementList{}, ast::FunctionDecorationList{});
|
ast::StatementList{}, ast::FunctionDecorationList{});
|
||||||
|
@ -1245,7 +1249,7 @@ TEST_P(Intrinsic_Builtin_ThreeParam_Uint_Test, Call_Vector) {
|
||||||
auto* expr =
|
auto* expr =
|
||||||
Call(param.name, vec2<u32>(1u, 1u), vec2<u32>(1u, 1u), vec2<u32>(1u, 1u));
|
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_(),
|
auto* func = Func("a_func", ast::VariableList{}, ty.void_(),
|
||||||
ast::StatementList{}, ast::FunctionDecorationList{});
|
ast::StatementList{}, ast::FunctionDecorationList{});
|
||||||
|
@ -1276,10 +1280,10 @@ INSTANTIATE_TEST_SUITE_P(IntrinsicBuilderTest,
|
||||||
testing::Values(IntrinsicData{"clamp", "UClamp"}));
|
testing::Values(IntrinsicData{"clamp", "UClamp"}));
|
||||||
|
|
||||||
TEST_F(IntrinsicBuilderTest, Call_Determinant) {
|
TEST_F(IntrinsicBuilderTest, Call_Determinant) {
|
||||||
auto* var = Var("var", ast::StorageClass::kPrivate, ty.mat3x3<f32>());
|
auto* var = Global("var", ast::StorageClass::kPrivate, ty.mat3x3<f32>());
|
||||||
auto* expr = Call("determinant", "var");
|
|
||||||
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
auto* expr = Call("determinant", "var");
|
||||||
|
WrapInFunction(expr);
|
||||||
|
|
||||||
auto* func = Func("a_func", ast::VariableList{}, ty.void_(),
|
auto* func = Func("a_func", ast::VariableList{}, ty.void_(),
|
||||||
ast::StatementList{}, ast::FunctionDecorationList{});
|
ast::StatementList{}, ast::FunctionDecorationList{});
|
||||||
|
@ -1316,10 +1320,10 @@ TEST_F(IntrinsicBuilderTest, Call_ArrayLength) {
|
||||||
create<ast::Struct>(ast::StructMemberList{Member("a", ty.array<f32>())},
|
create<ast::Struct>(ast::StructMemberList{Member("a", ty.array<f32>())},
|
||||||
ast::StructDecorationList{});
|
ast::StructDecorationList{});
|
||||||
auto* s_type = ty.struct_("my_struct", s);
|
auto* s_type = ty.struct_("my_struct", s);
|
||||||
auto* var = Var("b", ast::StorageClass::kPrivate, s_type);
|
auto* var = Global("b", ast::StorageClass::kPrivate, s_type);
|
||||||
auto* expr = Call("arrayLength", MemberAccessor("b", "a"));
|
|
||||||
|
|
||||||
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_(),
|
auto* func = Func("a_func", ast::VariableList{}, ty.void_(),
|
||||||
ast::StatementList{}, ast::FunctionDecorationList{});
|
ast::StatementList{}, ast::FunctionDecorationList{});
|
||||||
|
@ -1354,10 +1358,10 @@ TEST_F(IntrinsicBuilderTest, Call_ArrayLength_OtherMembersInStruct) {
|
||||||
ast::StructDecorationList{});
|
ast::StructDecorationList{});
|
||||||
|
|
||||||
auto* s_type = ty.struct_("my_struct", s);
|
auto* s_type = ty.struct_("my_struct", s);
|
||||||
auto* var = Var("b", ast::StorageClass::kPrivate, s_type);
|
auto* var = Global("b", ast::StorageClass::kPrivate, s_type);
|
||||||
auto* expr = Call("arrayLength", MemberAccessor("b", "a"));
|
|
||||||
|
|
||||||
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_(),
|
auto* func = Func("a_func", ast::VariableList{}, ty.void_(),
|
||||||
ast::StatementList{}, ast::FunctionDecorationList{});
|
ast::StatementList{}, ast::FunctionDecorationList{});
|
||||||
|
|
|
@ -4126,9 +4126,7 @@ TEST_P(IntrinsicTextureTest, Call) {
|
||||||
|
|
||||||
auto* call =
|
auto* call =
|
||||||
create<ast::CallExpression>(Expr(param.function), param.args(this));
|
create<ast::CallExpression>(Expr(param.function), param.args(this));
|
||||||
|
WrapInFunction(call);
|
||||||
EXPECT_TRUE(td.Determine()) << td.error();
|
|
||||||
EXPECT_TRUE(td.DetermineResultType(call)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -4149,8 +4147,8 @@ TEST_P(IntrinsicTextureTest, Call) {
|
||||||
TEST_P(IntrinsicTextureTest, ValidateSPIRV) {
|
TEST_P(IntrinsicTextureTest, ValidateSPIRV) {
|
||||||
auto param = GetParam();
|
auto param = GetParam();
|
||||||
|
|
||||||
AST().AddGlobalVariable(param.buildTextureVariable(this));
|
param.buildTextureVariable(this);
|
||||||
AST().AddGlobalVariable(param.buildSamplerVariable(this));
|
param.buildSamplerVariable(this);
|
||||||
|
|
||||||
auto* call =
|
auto* call =
|
||||||
create<ast::CallExpression>(Expr(param.function), param.args(this));
|
create<ast::CallExpression>(Expr(param.function), param.args(this));
|
||||||
|
@ -4163,11 +4161,9 @@ TEST_P(IntrinsicTextureTest, ValidateSPIRV) {
|
||||||
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
|
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
|
||||||
});
|
});
|
||||||
|
|
||||||
ASSERT_TRUE(td.Determine()) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
ASSERT_TRUE(b.Build()) << td.error();
|
ASSERT_TRUE(b.Build()) << b.error();
|
||||||
|
|
||||||
BinaryWriter writer;
|
BinaryWriter writer;
|
||||||
writer.WriteHeader(b.id_bound());
|
writer.WriteHeader(b.id_bound());
|
||||||
|
@ -4211,11 +4207,12 @@ TEST_P(IntrinsicTextureTest, OutsideFunction_IsError) {
|
||||||
|
|
||||||
auto* texture = param.buildTextureVariable(this);
|
auto* texture = param.buildTextureVariable(this);
|
||||||
auto* sampler = param.buildSamplerVariable(this);
|
auto* sampler = param.buildSamplerVariable(this);
|
||||||
|
AST().AddGlobalVariable(texture);
|
||||||
|
AST().AddGlobalVariable(sampler);
|
||||||
|
|
||||||
auto* call =
|
auto* call =
|
||||||
create<ast::CallExpression>(Expr(param.function), param.args(this));
|
create<ast::CallExpression>(Expr(param.function), param.args(this));
|
||||||
|
WrapInFunction(call);
|
||||||
EXPECT_TRUE(td.DetermineResultType(call)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
|
|
@ -42,8 +42,7 @@ TEST_F(BuilderTest, Loop_Empty) {
|
||||||
auto* loop = create<ast::LoopStatement>(
|
auto* loop = create<ast::LoopStatement>(
|
||||||
create<ast::BlockStatement>(ast::StatementList{}),
|
create<ast::BlockStatement>(ast::StatementList{}),
|
||||||
create<ast::BlockStatement>(ast::StatementList{}));
|
create<ast::BlockStatement>(ast::StatementList{}));
|
||||||
|
WrapInFunction(loop);
|
||||||
ASSERT_TRUE(td.DetermineResultType(loop)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -68,15 +67,13 @@ TEST_F(BuilderTest, Loop_WithoutContinuing) {
|
||||||
// v = 2;
|
// 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>(
|
auto* body = create<ast::BlockStatement>(
|
||||||
ast::StatementList{create<ast::AssignmentStatement>(Expr("v"), Expr(2))});
|
ast::StatementList{create<ast::AssignmentStatement>(Expr("v"), Expr(2))});
|
||||||
|
|
||||||
auto* loop = create<ast::LoopStatement>(
|
auto* loop = create<ast::LoopStatement>(
|
||||||
body, create<ast::BlockStatement>(ast::StatementList{}));
|
body, create<ast::BlockStatement>(ast::StatementList{}));
|
||||||
|
WrapInFunction(loop);
|
||||||
td.RegisterVariableForTesting(var);
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(loop)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
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>(
|
auto* body = create<ast::BlockStatement>(
|
||||||
ast::StatementList{create<ast::AssignmentStatement>(Expr("v"), Expr(2))});
|
ast::StatementList{create<ast::AssignmentStatement>(Expr("v"), Expr(2))});
|
||||||
auto* continuing = create<ast::BlockStatement>(
|
auto* continuing = create<ast::BlockStatement>(
|
||||||
ast::StatementList{create<ast::AssignmentStatement>(Expr("v"), Expr(3))});
|
ast::StatementList{create<ast::AssignmentStatement>(Expr("v"), Expr(3))});
|
||||||
|
|
||||||
auto* loop = create<ast::LoopStatement>(body, continuing);
|
auto* loop = create<ast::LoopStatement>(body, continuing);
|
||||||
|
WrapInFunction(loop);
|
||||||
td.RegisterVariableForTesting(var);
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(loop)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -160,8 +155,7 @@ TEST_F(BuilderTest, Loop_WithContinue) {
|
||||||
});
|
});
|
||||||
auto* loop = create<ast::LoopStatement>(
|
auto* loop = create<ast::LoopStatement>(
|
||||||
body, create<ast::BlockStatement>(ast::StatementList{}));
|
body, create<ast::BlockStatement>(ast::StatementList{}));
|
||||||
|
WrapInFunction(loop);
|
||||||
ASSERT_TRUE(td.DetermineResultType(loop)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -190,8 +184,7 @@ TEST_F(BuilderTest, Loop_WithBreak) {
|
||||||
});
|
});
|
||||||
auto* loop = create<ast::LoopStatement>(
|
auto* loop = create<ast::LoopStatement>(
|
||||||
body, create<ast::BlockStatement>(ast::StatementList{}));
|
body, create<ast::BlockStatement>(ast::StatementList{}));
|
||||||
|
WrapInFunction(loop);
|
||||||
ASSERT_TRUE(td.DetermineResultType(loop)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
|
|
@ -51,8 +51,7 @@ TEST_F(BuilderTest, Return_WithValue) {
|
||||||
auto* val = vec3<f32>(1.f, 1.f, 3.f);
|
auto* val = vec3<f32>(1.f, 1.f, 3.f);
|
||||||
|
|
||||||
auto* ret = create<ast::ReturnStatement>(val);
|
auto* ret = create<ast::ReturnStatement>(val);
|
||||||
|
WrapInFunction(ret);
|
||||||
EXPECT_TRUE(td.DetermineResultType(ret)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -72,12 +71,10 @@ TEST_F(BuilderTest, Return_WithValue) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(BuilderTest, Return_WithValue_GeneratesLoad) {
|
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"));
|
auto* ret = create<ast::ReturnStatement>(Expr("param"));
|
||||||
|
WrapInFunction(ret);
|
||||||
td.RegisterVariableForTesting(var);
|
|
||||||
EXPECT_TRUE(td.DetermineResultType(ret)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,8 @@ TEST_F(BuilderTest, Switch_Empty) {
|
||||||
// }
|
// }
|
||||||
|
|
||||||
auto* expr = create<ast::SwitchStatement>(Expr(1), ast::CaseStatementList{});
|
auto* expr = create<ast::SwitchStatement>(Expr(1), ast::CaseStatementList{});
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
|
||||||
|
WrapInFunction(expr);
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -71,8 +72,8 @@ TEST_F(BuilderTest, Switch_WithCase) {
|
||||||
// v = 2;
|
// v = 2;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
auto* v = Var("v", ast::StorageClass::kPrivate, ty.i32());
|
auto* v = Global("v", ast::StorageClass::kPrivate, ty.i32());
|
||||||
auto* a = Var("a", ast::StorageClass::kPrivate, ty.i32());
|
auto* a = Global("a", ast::StorageClass::kPrivate, ty.i32());
|
||||||
|
|
||||||
auto* case_1_body = create<ast::BlockStatement>(
|
auto* case_1_body = create<ast::BlockStatement>(
|
||||||
ast::StatementList{create<ast::AssignmentStatement>(Expr("v"), Expr(1))});
|
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);
|
auto* expr = create<ast::SwitchStatement>(Expr("a"), cases);
|
||||||
|
|
||||||
td.RegisterVariableForTesting(v);
|
WrapInFunction(expr);
|
||||||
td.RegisterVariableForTesting(a);
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
|
||||||
|
|
||||||
auto* func = Func("a_func", {}, ty.i32(), ast::StatementList{},
|
auto* func = Func("a_func", {}, ty.i32(), ast::StatementList{},
|
||||||
ast::FunctionDecorationList{});
|
ast::FunctionDecorationList{});
|
||||||
|
@ -143,8 +142,8 @@ TEST_F(BuilderTest, Switch_WithDefault) {
|
||||||
// v = 1;
|
// v = 1;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
auto* v = Var("v", ast::StorageClass::kPrivate, ty.i32());
|
auto* v = Global("v", ast::StorageClass::kPrivate, ty.i32());
|
||||||
auto* a = Var("a", ast::StorageClass::kPrivate, ty.i32());
|
auto* a = Global("a", ast::StorageClass::kPrivate, ty.i32());
|
||||||
|
|
||||||
auto* default_body = create<ast::BlockStatement>(
|
auto* default_body = create<ast::BlockStatement>(
|
||||||
ast::StatementList{create<ast::AssignmentStatement>(Expr("v"), Expr(1))});
|
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);
|
auto* expr = create<ast::SwitchStatement>(Expr("a"), cases);
|
||||||
|
|
||||||
td.RegisterVariableForTesting(v);
|
WrapInFunction(expr);
|
||||||
td.RegisterVariableForTesting(a);
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
|
||||||
|
|
||||||
auto* func = Func("a_func", {}, ty.i32(), ast::StatementList{},
|
auto* func = Func("a_func", {}, ty.i32(), ast::StatementList{},
|
||||||
ast::FunctionDecorationList{});
|
ast::FunctionDecorationList{});
|
||||||
|
@ -204,8 +201,8 @@ TEST_F(BuilderTest, Switch_WithCaseAndDefault) {
|
||||||
// v = 3;
|
// v = 3;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
auto* v = Var("v", ast::StorageClass::kPrivate, ty.i32());
|
auto* v = Global("v", ast::StorageClass::kPrivate, ty.i32());
|
||||||
auto* a = Var("a", ast::StorageClass::kPrivate, ty.i32());
|
auto* a = Global("a", ast::StorageClass::kPrivate, ty.i32());
|
||||||
|
|
||||||
auto* case_1_body = create<ast::BlockStatement>(
|
auto* case_1_body = create<ast::BlockStatement>(
|
||||||
ast::StatementList{create<ast::AssignmentStatement>(Expr("v"), Expr(1))});
|
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);
|
auto* expr = create<ast::SwitchStatement>(Expr("a"), cases);
|
||||||
|
|
||||||
td.RegisterVariableForTesting(v);
|
WrapInFunction(expr);
|
||||||
td.RegisterVariableForTesting(a);
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
|
||||||
|
|
||||||
auto* func = Func("a_func", {}, ty.i32(), ast::StatementList{},
|
auto* func = Func("a_func", {}, ty.i32(), ast::StatementList{},
|
||||||
ast::FunctionDecorationList{});
|
ast::FunctionDecorationList{});
|
||||||
|
@ -289,8 +284,8 @@ TEST_F(BuilderTest, Switch_CaseWithFallthrough) {
|
||||||
// v = 3;
|
// v = 3;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
auto* v = Var("v", ast::StorageClass::kPrivate, ty.i32());
|
auto* v = Global("v", ast::StorageClass::kPrivate, ty.i32());
|
||||||
auto* a = Var("a", ast::StorageClass::kPrivate, ty.i32());
|
auto* a = Global("a", ast::StorageClass::kPrivate, ty.i32());
|
||||||
|
|
||||||
auto* case_1_body = create<ast::BlockStatement>(
|
auto* case_1_body = create<ast::BlockStatement>(
|
||||||
ast::StatementList{create<ast::AssignmentStatement>(Expr("v"), Expr(1)),
|
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);
|
auto* expr = create<ast::SwitchStatement>(Expr("a"), cases);
|
||||||
|
|
||||||
td.RegisterVariableForTesting(v);
|
WrapInFunction(expr);
|
||||||
td.RegisterVariableForTesting(a);
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
|
||||||
|
|
||||||
auto* func = Func("a_func", {}, ty.i32(), ast::StatementList{},
|
auto* func = Func("a_func", {}, ty.i32(), ast::StatementList{},
|
||||||
ast::FunctionDecorationList{});
|
ast::FunctionDecorationList{});
|
||||||
|
@ -370,8 +363,8 @@ TEST_F(BuilderTest, Switch_CaseFallthroughLastStatement) {
|
||||||
// fallthrough;
|
// fallthrough;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
auto* v = Var("v", ast::StorageClass::kPrivate, ty.i32());
|
auto* v = Global("v", ast::StorageClass::kPrivate, ty.i32());
|
||||||
auto* a = Var("a", ast::StorageClass::kPrivate, ty.i32());
|
auto* a = Global("a", ast::StorageClass::kPrivate, ty.i32());
|
||||||
|
|
||||||
auto* case_1_body = create<ast::BlockStatement>(
|
auto* case_1_body = create<ast::BlockStatement>(
|
||||||
ast::StatementList{create<ast::AssignmentStatement>(Expr("v"), Expr(1)),
|
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);
|
auto* expr = create<ast::SwitchStatement>(Expr("a"), cases);
|
||||||
|
|
||||||
td.RegisterVariableForTesting(v);
|
WrapInFunction(expr);
|
||||||
td.RegisterVariableForTesting(a);
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
|
||||||
|
|
||||||
auto* func = Func("a_func", {}, ty.i32(), ast::StatementList{},
|
auto* func = Func("a_func", {}, ty.i32(), ast::StatementList{},
|
||||||
ast::FunctionDecorationList{});
|
ast::FunctionDecorationList{});
|
||||||
|
@ -411,8 +402,8 @@ TEST_F(BuilderTest, Switch_WithNestedBreak) {
|
||||||
// v = 1;
|
// v = 1;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
auto* v = Var("v", ast::StorageClass::kPrivate, ty.i32());
|
auto* v = Global("v", ast::StorageClass::kPrivate, ty.i32());
|
||||||
auto* a = Var("a", ast::StorageClass::kPrivate, ty.i32());
|
auto* a = Global("a", ast::StorageClass::kPrivate, ty.i32());
|
||||||
|
|
||||||
auto* if_body = create<ast::BlockStatement>(ast::StatementList{
|
auto* if_body = create<ast::BlockStatement>(ast::StatementList{
|
||||||
create<ast::BreakStatement>(),
|
create<ast::BreakStatement>(),
|
||||||
|
@ -430,9 +421,7 @@ TEST_F(BuilderTest, Switch_WithNestedBreak) {
|
||||||
|
|
||||||
auto* expr = create<ast::SwitchStatement>(Expr("a"), cases);
|
auto* expr = create<ast::SwitchStatement>(Expr("a"), cases);
|
||||||
|
|
||||||
td.RegisterVariableForTesting(v);
|
WrapInFunction(expr);
|
||||||
td.RegisterVariableForTesting(a);
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
|
||||||
|
|
||||||
auto* func = Func("a_func", {}, ty.i32(), ast::StatementList{},
|
auto* func = Func("a_func", {}, ty.i32(), ast::StatementList{},
|
||||||
ast::FunctionDecorationList{});
|
ast::FunctionDecorationList{});
|
||||||
|
|
|
@ -733,11 +733,11 @@ TEST_F(BuilderTest_Type, MultisampledTexture_Generate_2d_f32) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(BuilderTest_Type, SampledTexture_Generate_1d_i32) {
|
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();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
EXPECT_EQ(b.GenerateTypeIfNeeded(&s), 1u);
|
EXPECT_EQ(b.GenerateTypeIfNeeded(s), 1u);
|
||||||
ASSERT_FALSE(b.has_error()) << b.error();
|
ASSERT_FALSE(b.has_error()) << b.error();
|
||||||
EXPECT_EQ(DumpInstructions(b.types()),
|
EXPECT_EQ(DumpInstructions(b.types()),
|
||||||
R"(%2 = OpTypeInt 32 1
|
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) {
|
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();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
EXPECT_EQ(b.GenerateTypeIfNeeded(&s), 1u);
|
EXPECT_EQ(b.GenerateTypeIfNeeded(s), 1u);
|
||||||
ASSERT_FALSE(b.has_error()) << b.error();
|
ASSERT_FALSE(b.has_error()) << b.error();
|
||||||
EXPECT_EQ(DumpInstructions(b.types()),
|
EXPECT_EQ(DumpInstructions(b.types()),
|
||||||
R"(%2 = OpTypeInt 32 0
|
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) {
|
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();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
EXPECT_EQ(b.GenerateTypeIfNeeded(&s), 1u);
|
EXPECT_EQ(b.GenerateTypeIfNeeded(s), 1u);
|
||||||
ASSERT_FALSE(b.has_error()) << b.error();
|
ASSERT_FALSE(b.has_error()) << b.error();
|
||||||
EXPECT_EQ(DumpInstructions(b.types()),
|
EXPECT_EQ(DumpInstructions(b.types()),
|
||||||
R"(%2 = OpTypeFloat 32
|
R"(%2 = OpTypeFloat 32
|
||||||
|
@ -784,11 +784,12 @@ TEST_F(BuilderTest_Type, SampledTexture_Generate_1d_f32) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(BuilderTest_Type, SampledTexture_Generate_1dArray) {
|
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();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
EXPECT_EQ(b.GenerateTypeIfNeeded(&s), 1u);
|
EXPECT_EQ(b.GenerateTypeIfNeeded(s), 1u);
|
||||||
ASSERT_FALSE(b.has_error()) << b.error();
|
ASSERT_FALSE(b.has_error()) << b.error();
|
||||||
EXPECT_EQ(DumpInstructions(b.types()),
|
EXPECT_EQ(DumpInstructions(b.types()),
|
||||||
R"(%2 = OpTypeFloat 32
|
R"(%2 = OpTypeFloat 32
|
||||||
|
@ -801,11 +802,11 @@ TEST_F(BuilderTest_Type, SampledTexture_Generate_1dArray) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(BuilderTest_Type, SampledTexture_Generate_2d) {
|
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();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
EXPECT_EQ(b.GenerateTypeIfNeeded(&s), 1u);
|
EXPECT_EQ(b.GenerateTypeIfNeeded(s), 1u);
|
||||||
ASSERT_FALSE(b.has_error()) << b.error();
|
ASSERT_FALSE(b.has_error()) << b.error();
|
||||||
EXPECT_EQ(DumpInstructions(b.types()),
|
EXPECT_EQ(DumpInstructions(b.types()),
|
||||||
R"(%2 = OpTypeFloat 32
|
R"(%2 = OpTypeFloat 32
|
||||||
|
@ -814,11 +815,12 @@ TEST_F(BuilderTest_Type, SampledTexture_Generate_2d) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(BuilderTest_Type, SampledTexture_Generate_2d_array) {
|
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();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
EXPECT_EQ(b.GenerateTypeIfNeeded(&s), 1u);
|
EXPECT_EQ(b.GenerateTypeIfNeeded(s), 1u);
|
||||||
ASSERT_FALSE(b.has_error()) << b.error();
|
ASSERT_FALSE(b.has_error()) << b.error();
|
||||||
EXPECT_EQ(DumpInstructions(b.types()),
|
EXPECT_EQ(DumpInstructions(b.types()),
|
||||||
R"(%2 = OpTypeFloat 32
|
R"(%2 = OpTypeFloat 32
|
||||||
|
@ -827,11 +829,11 @@ TEST_F(BuilderTest_Type, SampledTexture_Generate_2d_array) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(BuilderTest_Type, SampledTexture_Generate_3d) {
|
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();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
EXPECT_EQ(b.GenerateTypeIfNeeded(&s), 1u);
|
EXPECT_EQ(b.GenerateTypeIfNeeded(s), 1u);
|
||||||
ASSERT_FALSE(b.has_error()) << b.error();
|
ASSERT_FALSE(b.has_error()) << b.error();
|
||||||
EXPECT_EQ(DumpInstructions(b.types()),
|
EXPECT_EQ(DumpInstructions(b.types()),
|
||||||
R"(%2 = OpTypeFloat 32
|
R"(%2 = OpTypeFloat 32
|
||||||
|
@ -840,11 +842,12 @@ TEST_F(BuilderTest_Type, SampledTexture_Generate_3d) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(BuilderTest_Type, SampledTexture_Generate_Cube) {
|
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();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
EXPECT_EQ(b.GenerateTypeIfNeeded(&s), 1u);
|
EXPECT_EQ(b.GenerateTypeIfNeeded(s), 1u);
|
||||||
ASSERT_FALSE(b.has_error()) << b.error();
|
ASSERT_FALSE(b.has_error()) << b.error();
|
||||||
EXPECT_EQ(DumpInstructions(b.types()),
|
EXPECT_EQ(DumpInstructions(b.types()),
|
||||||
R"(%2 = OpTypeFloat 32
|
R"(%2 = OpTypeFloat 32
|
||||||
|
@ -854,11 +857,12 @@ TEST_F(BuilderTest_Type, SampledTexture_Generate_Cube) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(BuilderTest_Type, SampledTexture_Generate_CubeArray) {
|
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();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
EXPECT_EQ(b.GenerateTypeIfNeeded(&s), 1u);
|
EXPECT_EQ(b.GenerateTypeIfNeeded(s), 1u);
|
||||||
ASSERT_FALSE(b.has_error()) << b.error();
|
ASSERT_FALSE(b.has_error()) << b.error();
|
||||||
EXPECT_EQ(DumpInstructions(b.types()),
|
EXPECT_EQ(DumpInstructions(b.types()),
|
||||||
R"(%2 = OpTypeFloat 32
|
R"(%2 = OpTypeFloat 32
|
||||||
|
@ -870,14 +874,14 @@ TEST_F(BuilderTest_Type, SampledTexture_Generate_CubeArray) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(BuilderTest_Type, StorageTexture_Generate_1d_R16Float) {
|
TEST_F(BuilderTest_Type, StorageTexture_Generate_1d_R16Float) {
|
||||||
type::StorageTexture s(type::TextureDimension::k1d,
|
auto* s = create<type::StorageTexture>(type::TextureDimension::k1d,
|
||||||
type::ImageFormat::kR16Float);
|
type::ImageFormat::kR16Float);
|
||||||
|
|
||||||
ASSERT_TRUE(td.DetermineStorageTextureSubtype(&s)) << td.error();
|
Global("test_var", ast::StorageClass::kNone, s);
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
EXPECT_EQ(b.GenerateTypeIfNeeded(&s), 1u);
|
EXPECT_EQ(b.GenerateTypeIfNeeded(s), 1u);
|
||||||
ASSERT_FALSE(b.has_error()) << b.error();
|
ASSERT_FALSE(b.has_error()) << b.error();
|
||||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
|
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
|
||||||
%1 = OpTypeImage %2 1D 0 0 0 2 R16f
|
%1 = OpTypeImage %2 1D 0 0 0 2 R16f
|
||||||
|
@ -890,14 +894,14 @@ OpCapability StorageImageExtendedFormats
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(BuilderTest_Type, StorageTexture_Generate_1d_R8SNorm) {
|
TEST_F(BuilderTest_Type, StorageTexture_Generate_1d_R8SNorm) {
|
||||||
type::StorageTexture s(type::TextureDimension::k1d,
|
auto* s = create<type::StorageTexture>(type::TextureDimension::k1d,
|
||||||
type::ImageFormat::kR8Snorm);
|
type::ImageFormat::kR8Snorm);
|
||||||
|
|
||||||
ASSERT_TRUE(td.DetermineStorageTextureSubtype(&s)) << td.error();
|
Global("test_var", ast::StorageClass::kNone, s);
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
EXPECT_EQ(b.GenerateTypeIfNeeded(&s), 1u);
|
EXPECT_EQ(b.GenerateTypeIfNeeded(s), 1u);
|
||||||
ASSERT_FALSE(b.has_error()) << b.error();
|
ASSERT_FALSE(b.has_error()) << b.error();
|
||||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
|
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
|
||||||
%1 = OpTypeImage %2 1D 0 0 0 2 R8Snorm
|
%1 = OpTypeImage %2 1D 0 0 0 2 R8Snorm
|
||||||
|
@ -910,14 +914,14 @@ OpCapability StorageImageExtendedFormats
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(BuilderTest_Type, StorageTexture_Generate_1d_R8UNorm) {
|
TEST_F(BuilderTest_Type, StorageTexture_Generate_1d_R8UNorm) {
|
||||||
type::StorageTexture s(type::TextureDimension::k1d,
|
auto* s = create<type::StorageTexture>(type::TextureDimension::k1d,
|
||||||
type::ImageFormat::kR8Unorm);
|
type::ImageFormat::kR8Unorm);
|
||||||
|
|
||||||
ASSERT_TRUE(td.DetermineStorageTextureSubtype(&s)) << td.error();
|
Global("test_var", ast::StorageClass::kNone, s);
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
EXPECT_EQ(b.GenerateTypeIfNeeded(&s), 1u);
|
EXPECT_EQ(b.GenerateTypeIfNeeded(s), 1u);
|
||||||
ASSERT_FALSE(b.has_error()) << b.error();
|
ASSERT_FALSE(b.has_error()) << b.error();
|
||||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
|
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
|
||||||
%1 = OpTypeImage %2 1D 0 0 0 2 R8
|
%1 = OpTypeImage %2 1D 0 0 0 2 R8
|
||||||
|
@ -930,14 +934,14 @@ OpCapability StorageImageExtendedFormats
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(BuilderTest_Type, StorageTexture_Generate_1d_R8Uint) {
|
TEST_F(BuilderTest_Type, StorageTexture_Generate_1d_R8Uint) {
|
||||||
type::StorageTexture s(type::TextureDimension::k1d,
|
auto* s = create<type::StorageTexture>(type::TextureDimension::k1d,
|
||||||
type::ImageFormat::kR8Uint);
|
type::ImageFormat::kR8Uint);
|
||||||
|
|
||||||
ASSERT_TRUE(td.DetermineStorageTextureSubtype(&s)) << td.error();
|
Global("test_var", ast::StorageClass::kNone, s);
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
EXPECT_EQ(b.GenerateTypeIfNeeded(&s), 1u);
|
EXPECT_EQ(b.GenerateTypeIfNeeded(s), 1u);
|
||||||
ASSERT_FALSE(b.has_error()) << b.error();
|
ASSERT_FALSE(b.has_error()) << b.error();
|
||||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeInt 32 0
|
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeInt 32 0
|
||||||
%1 = OpTypeImage %2 1D 0 0 0 2 R8ui
|
%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) {
|
TEST_F(BuilderTest_Type, StorageTexture_Generate_1d_R8Sint) {
|
||||||
type::StorageTexture s(type::TextureDimension::k1d,
|
auto* s = create<type::StorageTexture>(type::TextureDimension::k1d,
|
||||||
type::ImageFormat::kR8Sint);
|
type::ImageFormat::kR8Sint);
|
||||||
|
|
||||||
ASSERT_TRUE(td.DetermineStorageTextureSubtype(&s)) << td.error();
|
Global("test_var", ast::StorageClass::kNone, s);
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
EXPECT_EQ(b.GenerateTypeIfNeeded(&s), 1u);
|
EXPECT_EQ(b.GenerateTypeIfNeeded(s), 1u);
|
||||||
ASSERT_FALSE(b.has_error()) << b.error();
|
ASSERT_FALSE(b.has_error()) << b.error();
|
||||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeInt 32 1
|
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeInt 32 1
|
||||||
%1 = OpTypeImage %2 1D 0 0 0 2 R8i
|
%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) {
|
TEST_F(BuilderTest_Type, StorageTexture_Generate_1d_array) {
|
||||||
type::StorageTexture s(type::TextureDimension::k1dArray,
|
auto* s = create<type::StorageTexture>(type::TextureDimension::k1dArray,
|
||||||
type::ImageFormat::kR16Float);
|
type::ImageFormat::kR16Float);
|
||||||
|
|
||||||
ASSERT_TRUE(td.DetermineStorageTextureSubtype(&s)) << td.error();
|
Global("test_var", ast::StorageClass::kNone, s);
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
EXPECT_EQ(b.GenerateTypeIfNeeded(&s), 1u);
|
EXPECT_EQ(b.GenerateTypeIfNeeded(s), 1u);
|
||||||
ASSERT_FALSE(b.has_error()) << b.error();
|
ASSERT_FALSE(b.has_error()) << b.error();
|
||||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
|
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
|
||||||
%1 = OpTypeImage %2 1D 0 1 0 2 R16f
|
%1 = OpTypeImage %2 1D 0 1 0 2 R16f
|
||||||
|
@ -980,14 +984,14 @@ OpCapability StorageImageExtendedFormats
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(BuilderTest_Type, StorageTexture_Generate_2d) {
|
TEST_F(BuilderTest_Type, StorageTexture_Generate_2d) {
|
||||||
type::StorageTexture s(type::TextureDimension::k2d,
|
auto* s = create<type::StorageTexture>(type::TextureDimension::k2d,
|
||||||
type::ImageFormat::kR16Float);
|
type::ImageFormat::kR16Float);
|
||||||
|
|
||||||
ASSERT_TRUE(td.DetermineStorageTextureSubtype(&s)) << td.error();
|
Global("test_var", ast::StorageClass::kNone, s);
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
EXPECT_EQ(b.GenerateTypeIfNeeded(&s), 1u);
|
EXPECT_EQ(b.GenerateTypeIfNeeded(s), 1u);
|
||||||
ASSERT_FALSE(b.has_error()) << b.error();
|
ASSERT_FALSE(b.has_error()) << b.error();
|
||||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
|
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
|
||||||
%1 = OpTypeImage %2 2D 0 0 0 2 R16f
|
%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) {
|
TEST_F(BuilderTest_Type, StorageTexture_Generate_2dArray) {
|
||||||
type::StorageTexture s(type::TextureDimension::k2dArray,
|
auto* s = create<type::StorageTexture>(type::TextureDimension::k2dArray,
|
||||||
type::ImageFormat::kR16Float);
|
type::ImageFormat::kR16Float);
|
||||||
|
|
||||||
ASSERT_TRUE(td.DetermineStorageTextureSubtype(&s)) << td.error();
|
Global("test_var", ast::StorageClass::kNone, s);
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
EXPECT_EQ(b.GenerateTypeIfNeeded(&s), 1u);
|
EXPECT_EQ(b.GenerateTypeIfNeeded(s), 1u);
|
||||||
ASSERT_FALSE(b.has_error()) << b.error();
|
ASSERT_FALSE(b.has_error()) << b.error();
|
||||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
|
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
|
||||||
%1 = OpTypeImage %2 2D 0 1 0 2 R16f
|
%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) {
|
TEST_F(BuilderTest_Type, StorageTexture_Generate_3d) {
|
||||||
type::StorageTexture s(type::TextureDimension::k3d,
|
auto* s = create<type::StorageTexture>(type::TextureDimension::k3d,
|
||||||
type::ImageFormat::kR16Float);
|
type::ImageFormat::kR16Float);
|
||||||
|
|
||||||
ASSERT_TRUE(td.DetermineStorageTextureSubtype(&s)) << td.error();
|
Global("test_var", ast::StorageClass::kNone, s);
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
EXPECT_EQ(b.GenerateTypeIfNeeded(&s), 1u);
|
EXPECT_EQ(b.GenerateTypeIfNeeded(s), 1u);
|
||||||
ASSERT_FALSE(b.has_error()) << b.error();
|
ASSERT_FALSE(b.has_error()) << b.error();
|
||||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
|
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
|
||||||
%1 = OpTypeImage %2 3D 0 0 0 2 R16f
|
%1 = OpTypeImage %2 3D 0 0 0 2 R16f
|
||||||
|
@ -1026,14 +1030,14 @@ TEST_F(BuilderTest_Type, StorageTexture_Generate_3d) {
|
||||||
|
|
||||||
TEST_F(BuilderTest_Type,
|
TEST_F(BuilderTest_Type,
|
||||||
StorageTexture_Generate_SampledTypeFloat_Format_r32float) {
|
StorageTexture_Generate_SampledTypeFloat_Format_r32float) {
|
||||||
type::StorageTexture s(type::TextureDimension::k2d,
|
auto* s = create<type::StorageTexture>(type::TextureDimension::k2d,
|
||||||
type::ImageFormat::kR32Float);
|
type::ImageFormat::kR32Float);
|
||||||
|
|
||||||
ASSERT_TRUE(td.DetermineStorageTextureSubtype(&s)) << td.error();
|
Global("test_var", ast::StorageClass::kNone, s);
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
EXPECT_EQ(b.GenerateTypeIfNeeded(&s), 1u);
|
EXPECT_EQ(b.GenerateTypeIfNeeded(s), 1u);
|
||||||
ASSERT_FALSE(b.has_error()) << b.error();
|
ASSERT_FALSE(b.has_error()) << b.error();
|
||||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
|
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
|
||||||
%1 = OpTypeImage %2 2D 0 0 0 2 R32f
|
%1 = OpTypeImage %2 2D 0 0 0 2 R32f
|
||||||
|
@ -1042,14 +1046,14 @@ TEST_F(BuilderTest_Type,
|
||||||
|
|
||||||
TEST_F(BuilderTest_Type,
|
TEST_F(BuilderTest_Type,
|
||||||
StorageTexture_Generate_SampledTypeSint_Format_r32sint) {
|
StorageTexture_Generate_SampledTypeSint_Format_r32sint) {
|
||||||
type::StorageTexture s(type::TextureDimension::k2d,
|
auto* s = create<type::StorageTexture>(type::TextureDimension::k2d,
|
||||||
type::ImageFormat::kR32Sint);
|
type::ImageFormat::kR32Sint);
|
||||||
|
|
||||||
ASSERT_TRUE(td.DetermineStorageTextureSubtype(&s)) << td.error();
|
Global("test_var", ast::StorageClass::kNone, s);
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
EXPECT_EQ(b.GenerateTypeIfNeeded(&s), 1u);
|
EXPECT_EQ(b.GenerateTypeIfNeeded(s), 1u);
|
||||||
ASSERT_FALSE(b.has_error()) << b.error();
|
ASSERT_FALSE(b.has_error()) << b.error();
|
||||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeInt 32 1
|
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeInt 32 1
|
||||||
%1 = OpTypeImage %2 2D 0 0 0 2 R32i
|
%1 = OpTypeImage %2 2D 0 0 0 2 R32i
|
||||||
|
@ -1058,14 +1062,14 @@ TEST_F(BuilderTest_Type,
|
||||||
|
|
||||||
TEST_F(BuilderTest_Type,
|
TEST_F(BuilderTest_Type,
|
||||||
StorageTexture_Generate_SampledTypeUint_Format_r32uint) {
|
StorageTexture_Generate_SampledTypeUint_Format_r32uint) {
|
||||||
type::StorageTexture s(type::TextureDimension::k2d,
|
auto* s = create<type::StorageTexture>(type::TextureDimension::k2d,
|
||||||
type::ImageFormat::kR32Uint);
|
type::ImageFormat::kR32Uint);
|
||||||
|
|
||||||
ASSERT_TRUE(td.DetermineStorageTextureSubtype(&s)) << td.error();
|
Global("test_var", ast::StorageClass::kNone, s);
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
EXPECT_EQ(b.GenerateTypeIfNeeded(&s), 1u);
|
EXPECT_EQ(b.GenerateTypeIfNeeded(s), 1u);
|
||||||
ASSERT_FALSE(b.has_error()) << b.error();
|
ASSERT_FALSE(b.has_error()) << b.error();
|
||||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeInt 32 0
|
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeInt 32 0
|
||||||
%1 = OpTypeImage %2 2D 0 0 0 2 R32ui
|
%1 = OpTypeImage %2 2D 0 0 0 2 R32ui
|
||||||
|
|
|
@ -39,7 +39,7 @@ using BuilderTest = TestHelper;
|
||||||
|
|
||||||
TEST_F(BuilderTest, UnaryOp_Negation_Integer) {
|
TEST_F(BuilderTest, UnaryOp_Negation_Integer) {
|
||||||
auto* expr = create<ast::UnaryOpExpression>(ast::UnaryOp::kNegation, Expr(1));
|
auto* expr = create<ast::UnaryOpExpression>(ast::UnaryOp::kNegation, Expr(1));
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
WrapInFunction(expr);
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ TEST_F(BuilderTest, UnaryOp_Negation_Integer) {
|
||||||
TEST_F(BuilderTest, UnaryOp_Negation_Float) {
|
TEST_F(BuilderTest, UnaryOp_Negation_Float) {
|
||||||
auto* expr =
|
auto* expr =
|
||||||
create<ast::UnaryOpExpression>(ast::UnaryOp::kNegation, Expr(1.f));
|
create<ast::UnaryOpExpression>(ast::UnaryOp::kNegation, Expr(1.f));
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
WrapInFunction(expr);
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -72,7 +72,7 @@ TEST_F(BuilderTest, UnaryOp_Negation_Float) {
|
||||||
|
|
||||||
TEST_F(BuilderTest, UnaryOp_Not) {
|
TEST_F(BuilderTest, UnaryOp_Not) {
|
||||||
auto* expr = create<ast::UnaryOpExpression>(ast::UnaryOp::kNot, Expr(false));
|
auto* expr = create<ast::UnaryOpExpression>(ast::UnaryOp::kNot, Expr(false));
|
||||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
WrapInFunction(expr);
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -87,13 +87,11 @@ TEST_F(BuilderTest, UnaryOp_Not) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(BuilderTest, UnaryOp_LoadRequired) {
|
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 =
|
auto* expr =
|
||||||
create<ast::UnaryOpExpression>(ast::UnaryOp::kNegation, Expr("param"));
|
create<ast::UnaryOpExpression>(ast::UnaryOp::kNegation, Expr("param"));
|
||||||
|
WrapInFunction(expr);
|
||||||
td.RegisterVariableForTesting(var);
|
|
||||||
EXPECT_TRUE(td.DetermineResultType(expr)) << td.error();
|
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
|
|
||||||
#include "gtest/gtest.h"
|
#include "gtest/gtest.h"
|
||||||
#include "src/ast/module.h"
|
#include "src/ast/module.h"
|
||||||
|
#include "src/diagnostic/formatter.h"
|
||||||
#include "src/program_builder.h"
|
#include "src/program_builder.h"
|
||||||
#include "src/type_determiner.h"
|
#include "src/type_determiner.h"
|
||||||
#include "src/writer/spirv/builder.h"
|
#include "src/writer/spirv/builder.h"
|
||||||
|
@ -32,7 +33,7 @@ namespace spirv {
|
||||||
template <typename BASE>
|
template <typename BASE>
|
||||||
class TestHelperBase : public ProgramBuilder, public BASE {
|
class TestHelperBase : public ProgramBuilder, public BASE {
|
||||||
public:
|
public:
|
||||||
TestHelperBase() : td(this) {}
|
TestHelperBase() = default;
|
||||||
~TestHelperBase() override = default;
|
~TestHelperBase() override = default;
|
||||||
|
|
||||||
/// Builds and returns a spirv::Builder from the program.
|
/// Builds and returns a spirv::Builder from the program.
|
||||||
|
@ -43,23 +44,22 @@ class TestHelperBase : public ProgramBuilder, public BASE {
|
||||||
if (spirv_builder) {
|
if (spirv_builder) {
|
||||||
return *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));
|
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());
|
spirv_builder = std::make_unique<spirv::Builder>(program.get());
|
||||||
return *spirv_builder;
|
return *spirv_builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The type determiner
|
|
||||||
TypeDeterminer td;
|
|
||||||
/// The program built with a call to Build()
|
/// The program built with a call to Build()
|
||||||
std::unique_ptr<Program> program;
|
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:
|
private:
|
||||||
std::unique_ptr<spirv::Builder> spirv_builder;
|
std::unique_ptr<spirv::Builder> spirv_builder;
|
||||||
};
|
};
|
||||||
|
|
|
@ -184,18 +184,14 @@ TEST_F(WgslGeneratorImplTest,
|
||||||
auto* s = ty.struct_("Data", str);
|
auto* s = ty.struct_("Data", str);
|
||||||
type::AccessControl ac(ast::AccessControl::kReadWrite, s);
|
type::AccessControl ac(ast::AccessControl::kReadWrite, s);
|
||||||
|
|
||||||
auto* data_var = Var("data", ast::StorageClass::kStorage, &ac, nullptr,
|
Global("data", ast::StorageClass::kStorage, &ac, nullptr,
|
||||||
ast::VariableDecorationList{
|
ast::VariableDecorationList{
|
||||||
// decorations
|
|
||||||
create<ast::BindingDecoration>(0),
|
create<ast::BindingDecoration>(0),
|
||||||
create<ast::GroupDecoration>(0),
|
create<ast::GroupDecoration>(0),
|
||||||
});
|
});
|
||||||
|
|
||||||
AST().AddConstructedType(s);
|
AST().AddConstructedType(s);
|
||||||
|
|
||||||
td.RegisterVariableForTesting(data_var);
|
|
||||||
AST().AddGlobalVariable(data_var);
|
|
||||||
|
|
||||||
{
|
{
|
||||||
auto* var =
|
auto* var =
|
||||||
Var("v", ast::StorageClass::kFunction, ty.f32(),
|
Var("v", ast::StorageClass::kFunction, ty.f32(),
|
||||||
|
|
|
@ -386,12 +386,12 @@ using WgslGenerator_StorageTextureTest = TestParamHelper<StorageTextureData>;
|
||||||
TEST_P(WgslGenerator_StorageTextureTest, EmitType_StorageTexture) {
|
TEST_P(WgslGenerator_StorageTextureTest, EmitType_StorageTexture) {
|
||||||
auto param = GetParam();
|
auto param = GetParam();
|
||||||
|
|
||||||
type::StorageTexture t(param.dim, param.fmt);
|
auto* t = create<type::StorageTexture>(param.dim, param.fmt);
|
||||||
type::AccessControl ac(param.access, &t);
|
auto* ac = create<type::AccessControl>(param.access, t);
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
ASSERT_TRUE(gen.EmitType(&ac)) << gen.error();
|
ASSERT_TRUE(gen.EmitType(ac)) << gen.error();
|
||||||
EXPECT_EQ(gen.result(), param.name);
|
EXPECT_EQ(gen.result(), param.name);
|
||||||
}
|
}
|
||||||
INSTANTIATE_TEST_SUITE_P(
|
INSTANTIATE_TEST_SUITE_P(
|
||||||
|
|
|
@ -31,9 +31,10 @@ namespace {
|
||||||
using WgslGeneratorImplTest = TestHelper;
|
using WgslGeneratorImplTest = TestHelper;
|
||||||
|
|
||||||
TEST_F(WgslGeneratorImplTest, Emit_VariableDeclStatement) {
|
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);
|
auto* stmt = create<ast::VariableDeclStatement>(var);
|
||||||
|
WrapInFunction(stmt);
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
|
@ -48,9 +49,10 @@ TEST_F(WgslGeneratorImplTest, Emit_VariableDeclStatement_Function) {
|
||||||
// storage class. Rely on defaulting.
|
// storage class. Rely on defaulting.
|
||||||
// https://github.com/gpuweb/gpuweb/issues/654
|
// 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);
|
auto* stmt = create<ast::VariableDeclStatement>(var);
|
||||||
|
WrapInFunction(stmt);
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
|
@ -61,9 +63,10 @@ TEST_F(WgslGeneratorImplTest, Emit_VariableDeclStatement_Function) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(WgslGeneratorImplTest, Emit_VariableDeclStatement_Private) {
|
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);
|
auto* stmt = create<ast::VariableDeclStatement>(var);
|
||||||
|
WrapInFunction(stmt);
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,7 @@ namespace {
|
||||||
using WgslGeneratorImplTest = TestHelper;
|
using WgslGeneratorImplTest = TestHelper;
|
||||||
|
|
||||||
TEST_F(WgslGeneratorImplTest, EmitVariable) {
|
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();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ TEST_F(WgslGeneratorImplTest, EmitVariable) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(WgslGeneratorImplTest, EmitVariable_StorageClass) {
|
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();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
|
@ -54,7 +54,7 @@ TEST_F(WgslGeneratorImplTest, EmitVariable_StorageClass) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(WgslGeneratorImplTest, EmitVariable_Decorated) {
|
TEST_F(WgslGeneratorImplTest, EmitVariable_Decorated) {
|
||||||
auto* v = Var("a", ast::StorageClass::kNone, ty.f32(), nullptr,
|
auto* v = Global("a", ast::StorageClass::kNone, ty.f32(), nullptr,
|
||||||
ast::VariableDecorationList{
|
ast::VariableDecorationList{
|
||||||
create<ast::LocationDecoration>(2),
|
create<ast::LocationDecoration>(2),
|
||||||
});
|
});
|
||||||
|
@ -67,7 +67,7 @@ TEST_F(WgslGeneratorImplTest, EmitVariable_Decorated) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(WgslGeneratorImplTest, EmitVariable_Decorated_Multiple) {
|
TEST_F(WgslGeneratorImplTest, EmitVariable_Decorated_Multiple) {
|
||||||
auto* v = Var("a", ast::StorageClass::kNone, ty.f32(), nullptr,
|
auto* v = Global("a", ast::StorageClass::kNone, ty.f32(), nullptr,
|
||||||
ast::VariableDecorationList{
|
ast::VariableDecorationList{
|
||||||
create<ast::BuiltinDecoration>(ast::Builtin::kPosition),
|
create<ast::BuiltinDecoration>(ast::Builtin::kPosition),
|
||||||
create<ast::BindingDecoration>(0),
|
create<ast::BindingDecoration>(0),
|
||||||
|
@ -86,7 +86,7 @@ TEST_F(WgslGeneratorImplTest, EmitVariable_Decorated_Multiple) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(WgslGeneratorImplTest, EmitVariable_Constructor) {
|
TEST_F(WgslGeneratorImplTest, EmitVariable_Constructor) {
|
||||||
auto* v = Var("a", ast::StorageClass::kNone, ty.f32(), Expr("initializer"),
|
auto* v = Global("a", ast::StorageClass::kNone, ty.f32(), Expr("initializer"),
|
||||||
ast::VariableDecorationList{});
|
ast::VariableDecorationList{});
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
Loading…
Reference in New Issue