writer/msl: Rework string printing
Add `out` parameters to expression and type generators. Use the new helper classes in TextGenerator. Cleans up bad formatting. Prepares the writer generating 'pre' statements, required for atomics. If-else statements are generated slightly differently. This is done so that 'pre' statements for the else conditions are scoped correctly. This is identical to the HLSL writer. Bug tint:892 Change-Id: I4c6e96c90673ba30898b3682bf3198497d63a2d4 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/56067 Kokoro: Kokoro <noreply+kokoro@google.com> Reviewed-by: James Price <jrprice@google.com> Commit-Queue: Ben Clayton <bclayton@google.com>
This commit is contained in:
parent
a5715e3320
commit
f24b37e122
File diff suppressed because it is too large
Load Diff
|
@ -64,62 +64,63 @@ class GeneratorImpl : public TextGenerator {
|
||||||
/// @returns true if the declared type was emitted
|
/// @returns true if the declared type was emitted
|
||||||
bool EmitTypeDecl(const sem::Type* ty);
|
bool EmitTypeDecl(const sem::Type* ty);
|
||||||
/// Handles an array accessor expression
|
/// Handles an array accessor expression
|
||||||
|
/// @param out the output of the expression stream
|
||||||
/// @param expr the expression to emit
|
/// @param expr the expression to emit
|
||||||
/// @returns true if the array accessor was emitted
|
/// @returns true if the array accessor was emitted
|
||||||
bool EmitArrayAccessor(ast::ArrayAccessorExpression* expr);
|
bool EmitArrayAccessor(std::ostream& out, ast::ArrayAccessorExpression* expr);
|
||||||
/// Handles an assignment statement
|
/// Handles an assignment statement
|
||||||
/// @param stmt the statement to emit
|
/// @param stmt the statement to emit
|
||||||
/// @returns true if the statement was emitted successfully
|
/// @returns true if the statement was emitted successfully
|
||||||
bool EmitAssign(ast::AssignmentStatement* stmt);
|
bool EmitAssign(ast::AssignmentStatement* stmt);
|
||||||
/// Handles generating a binary expression
|
/// Handles generating a binary expression
|
||||||
|
/// @param out the output of the expression stream
|
||||||
/// @param expr the binary expression
|
/// @param expr the binary expression
|
||||||
/// @returns true if the expression was emitted, false otherwise
|
/// @returns true if the expression was emitted, false otherwise
|
||||||
bool EmitBinary(ast::BinaryExpression* expr);
|
bool EmitBinary(std::ostream& out, ast::BinaryExpression* expr);
|
||||||
/// Handles generating a bitcast expression
|
/// Handles generating a bitcast expression
|
||||||
|
/// @param out the output of the expression stream
|
||||||
/// @param expr the bitcast expression
|
/// @param expr the bitcast expression
|
||||||
/// @returns true if the bitcast was emitted
|
/// @returns true if the bitcast was emitted
|
||||||
bool EmitBitcast(ast::BitcastExpression* expr);
|
bool EmitBitcast(std::ostream& out, ast::BitcastExpression* expr);
|
||||||
/// Handles a block statement
|
/// Handles a block statement
|
||||||
/// @param stmt the statement to emit
|
/// @param stmt the statement to emit
|
||||||
/// @returns true if the statement was emitted successfully
|
/// @returns true if the statement was emitted successfully
|
||||||
bool EmitBlock(const ast::BlockStatement* stmt);
|
bool EmitBlock(const ast::BlockStatement* stmt);
|
||||||
/// Handles a block statement with a newline at the end
|
|
||||||
/// @param stmt the statement to emit
|
|
||||||
/// @returns true if the statement was emitted successfully
|
|
||||||
bool EmitIndentedBlockAndNewline(ast::BlockStatement* stmt);
|
|
||||||
/// Handles a block statement with a newline at the end
|
|
||||||
/// @param stmt the statement to emit
|
|
||||||
/// @returns true if the statement was emitted successfully
|
|
||||||
bool EmitBlockAndNewline(const ast::BlockStatement* stmt);
|
|
||||||
/// Handles a break statement
|
/// Handles a break statement
|
||||||
/// @param stmt the statement to emit
|
/// @param stmt the statement to emit
|
||||||
/// @returns true if the statement was emitted successfully
|
/// @returns true if the statement was emitted successfully
|
||||||
bool EmitBreak(ast::BreakStatement* stmt);
|
bool EmitBreak(ast::BreakStatement* stmt);
|
||||||
/// Handles generating a call expression
|
/// Handles generating a call expression
|
||||||
|
/// @param out the output of the expression stream
|
||||||
/// @param expr the call expression
|
/// @param expr the call expression
|
||||||
/// @returns true if the call expression is emitted
|
/// @returns true if the call expression is emitted
|
||||||
bool EmitCall(ast::CallExpression* expr);
|
bool EmitCall(std::ostream& out, ast::CallExpression* expr);
|
||||||
/// Handles generating an intrinsic call expression
|
/// Handles generating an intrinsic call expression
|
||||||
|
/// @param out the output of the expression stream
|
||||||
/// @param expr the call expression
|
/// @param expr the call expression
|
||||||
/// @param intrinsic the intrinsic being called
|
/// @param intrinsic the intrinsic being called
|
||||||
/// @returns true if the call expression is emitted
|
/// @returns true if the call expression is emitted
|
||||||
bool EmitIntrinsicCall(ast::CallExpression* expr,
|
bool EmitIntrinsicCall(std::ostream& out,
|
||||||
|
ast::CallExpression* expr,
|
||||||
const sem::Intrinsic* intrinsic);
|
const sem::Intrinsic* intrinsic);
|
||||||
/// Handles generating a call to a texture function (`textureSample`,
|
/// Handles generating a call to a texture function (`textureSample`,
|
||||||
/// `textureSampleGrad`, etc)
|
/// `textureSampleGrad`, etc)
|
||||||
|
/// @param out the output of the expression stream
|
||||||
/// @param expr the call expression
|
/// @param expr the call expression
|
||||||
/// @param intrinsic the semantic information for the texture intrinsic
|
/// @param intrinsic the semantic information for the texture intrinsic
|
||||||
/// @returns true if the call expression is emitted
|
/// @returns true if the call expression is emitted
|
||||||
bool EmitTextureCall(ast::CallExpression* expr,
|
bool EmitTextureCall(std::ostream& out,
|
||||||
|
ast::CallExpression* expr,
|
||||||
const sem::Intrinsic* intrinsic);
|
const sem::Intrinsic* intrinsic);
|
||||||
/// Handles a case statement
|
/// Handles a case statement
|
||||||
/// @param stmt the statement
|
/// @param stmt the statement
|
||||||
/// @returns true if the statement was emitted successfully
|
/// @returns true if the statement was emitted successfully
|
||||||
bool EmitCase(ast::CaseStatement* stmt);
|
bool EmitCase(ast::CaseStatement* stmt);
|
||||||
/// Handles generating constructor expressions
|
/// Handles generating constructor expressions
|
||||||
|
/// @param out the output of the expression stream
|
||||||
/// @param expr the constructor expression
|
/// @param expr the constructor expression
|
||||||
/// @returns true if the expression was emitted
|
/// @returns true if the expression was emitted
|
||||||
bool EmitConstructor(ast::ConstructorExpression* expr);
|
bool EmitConstructor(std::ostream& out, ast::ConstructorExpression* expr);
|
||||||
/// Handles a continue statement
|
/// Handles a continue statement
|
||||||
/// @param stmt the statement to emit
|
/// @param stmt the statement to emit
|
||||||
/// @returns true if the statement was emitted successfully
|
/// @returns true if the statement was emitted successfully
|
||||||
|
@ -128,85 +129,106 @@ class GeneratorImpl : public TextGenerator {
|
||||||
/// @param stmt the discard statement
|
/// @param stmt the discard statement
|
||||||
/// @returns true if the statement was successfully emitted
|
/// @returns true if the statement was successfully emitted
|
||||||
bool EmitDiscard(ast::DiscardStatement* stmt);
|
bool EmitDiscard(ast::DiscardStatement* stmt);
|
||||||
/// Handles generating an else statement
|
|
||||||
/// @param stmt the statement to emit
|
|
||||||
/// @returns true if the statement was emitted
|
|
||||||
bool EmitElse(ast::ElseStatement* stmt);
|
|
||||||
/// Handles emitting the entry point function
|
/// Handles emitting the entry point function
|
||||||
/// @param func the entry point function
|
/// @param func the entry point function
|
||||||
/// @returns true if the entry point function was emitted
|
/// @returns true if the entry point function was emitted
|
||||||
bool EmitEntryPointFunction(ast::Function* func);
|
bool EmitEntryPointFunction(ast::Function* func);
|
||||||
/// Handles generate an Expression
|
/// Handles generate an Expression
|
||||||
|
/// @param out the output of the expression stream
|
||||||
/// @param expr the expression
|
/// @param expr the expression
|
||||||
/// @returns true if the expression was emitted
|
/// @returns true if the expression was emitted
|
||||||
bool EmitExpression(ast::Expression* expr);
|
bool EmitExpression(std::ostream& out, ast::Expression* expr);
|
||||||
/// Handles generating a function
|
/// Handles generating a function
|
||||||
/// @param func the function to generate
|
/// @param func the function to generate
|
||||||
/// @returns true if the function was emitted
|
/// @returns true if the function was emitted
|
||||||
bool EmitFunction(ast::Function* func);
|
bool EmitFunction(ast::Function* func);
|
||||||
/// Handles generating an identifier expression
|
/// Handles generating an identifier expression
|
||||||
|
/// @param out the output of the expression stream
|
||||||
/// @param expr the identifier expression
|
/// @param expr the identifier expression
|
||||||
/// @returns true if the identifier was emitted
|
/// @returns true if the identifier was emitted
|
||||||
bool EmitIdentifier(ast::IdentifierExpression* expr);
|
bool EmitIdentifier(std::ostream& out, ast::IdentifierExpression* expr);
|
||||||
/// Handles an if statement
|
/// Handles an if statement
|
||||||
/// @param stmt the statement to emit
|
/// @param stmt the statement to emit
|
||||||
/// @returns true if the statement was successfully emitted
|
/// @returns true if the statement was successfully emitted
|
||||||
bool EmitIf(ast::IfStatement* stmt);
|
bool EmitIf(ast::IfStatement* stmt);
|
||||||
/// Handles a literal
|
/// Handles a literal
|
||||||
|
/// @param out the output of the expression stream
|
||||||
/// @param lit the literal to emit
|
/// @param lit the literal to emit
|
||||||
/// @returns true if the literal was successfully emitted
|
/// @returns true if the literal was successfully emitted
|
||||||
bool EmitLiteral(ast::Literal* lit);
|
bool EmitLiteral(std::ostream& out, ast::Literal* lit);
|
||||||
/// Handles a loop statement
|
/// Handles a loop statement
|
||||||
/// @param stmt the statement to emit
|
/// @param stmt the statement to emit
|
||||||
/// @returns true if the statement was emitted
|
/// @returns true if the statement was emitted
|
||||||
bool EmitLoop(ast::LoopStatement* stmt);
|
bool EmitLoop(ast::LoopStatement* stmt);
|
||||||
/// Handles a member accessor expression
|
/// Handles a member accessor expression
|
||||||
|
/// @param out the output of the expression stream
|
||||||
/// @param expr the member accessor expression
|
/// @param expr the member accessor expression
|
||||||
/// @returns true if the member accessor was emitted
|
/// @returns true if the member accessor was emitted
|
||||||
bool EmitMemberAccessor(ast::MemberAccessorExpression* expr);
|
bool EmitMemberAccessor(std::ostream& out,
|
||||||
|
ast::MemberAccessorExpression* expr);
|
||||||
/// Handles return statements
|
/// Handles return statements
|
||||||
/// @param stmt the statement to emit
|
/// @param stmt the statement to emit
|
||||||
/// @returns true if the statement was successfully emitted
|
/// @returns true if the statement was successfully emitted
|
||||||
bool EmitReturn(ast::ReturnStatement* stmt);
|
bool EmitReturn(ast::ReturnStatement* stmt);
|
||||||
/// Handles generating a scalar constructor
|
/// Handles generating a scalar constructor
|
||||||
|
/// @param out the output of the expression stream
|
||||||
/// @param expr the scalar constructor expression
|
/// @param expr the scalar constructor expression
|
||||||
/// @returns true if the scalar constructor is emitted
|
/// @returns true if the scalar constructor is emitted
|
||||||
bool EmitScalarConstructor(ast::ScalarConstructorExpression* expr);
|
bool EmitScalarConstructor(std::ostream& out,
|
||||||
|
ast::ScalarConstructorExpression* expr);
|
||||||
/// Handles emitting a pipeline stage name
|
/// Handles emitting a pipeline stage name
|
||||||
|
/// @param out the output of the expression stream
|
||||||
/// @param stage the stage to emit
|
/// @param stage the stage to emit
|
||||||
void EmitStage(ast::PipelineStage stage);
|
void EmitStage(std::ostream& out, ast::PipelineStage stage);
|
||||||
/// Handles statement
|
/// Handles statement
|
||||||
/// @param stmt the statement to emit
|
/// @param stmt the statement to emit
|
||||||
/// @returns true if the statement was emitted
|
/// @returns true if the statement was emitted
|
||||||
bool EmitStatement(ast::Statement* stmt);
|
bool EmitStatement(ast::Statement* stmt);
|
||||||
|
/// Emits a list of statements
|
||||||
|
/// @param stmts the statement list
|
||||||
|
/// @returns true if the statements were emitted successfully
|
||||||
|
bool EmitStatements(const ast::StatementList& stmts);
|
||||||
|
/// Emits a list of statements with an indentation
|
||||||
|
/// @param stmts the statement list
|
||||||
|
/// @returns true if the statements were emitted successfully
|
||||||
|
bool EmitStatementsWithIndent(const ast::StatementList& stmts);
|
||||||
/// Handles generating a switch statement
|
/// Handles generating a switch statement
|
||||||
/// @param stmt the statement to emit
|
/// @param stmt the statement to emit
|
||||||
/// @returns true if the statement was emitted
|
/// @returns true if the statement was emitted
|
||||||
bool EmitSwitch(ast::SwitchStatement* stmt);
|
bool EmitSwitch(ast::SwitchStatement* stmt);
|
||||||
/// Handles generating a type
|
/// Handles generating a type
|
||||||
|
/// @param out the output of the type stream
|
||||||
/// @param type the type to generate
|
/// @param type the type to generate
|
||||||
/// @param name the name of the variable, only used for array emission
|
/// @param name the name of the variable, only used for array emission
|
||||||
/// @returns true if the type is emitted
|
/// @returns true if the type is emitted
|
||||||
bool EmitType(const sem::Type* type, const std::string& name);
|
bool EmitType(std::ostream& out,
|
||||||
|
const sem::Type* type,
|
||||||
|
const std::string& name);
|
||||||
/// Handles generating an MSL-packed storage type.
|
/// Handles generating an MSL-packed storage type.
|
||||||
/// If the type does not have a packed form, the standard non-packed form is
|
/// If the type does not have a packed form, the standard non-packed form is
|
||||||
/// emitted.
|
/// emitted.
|
||||||
|
/// @param out the output of the type stream
|
||||||
/// @param type the type to generate
|
/// @param type the type to generate
|
||||||
/// @param name the name of the variable, only used for array emission
|
/// @param name the name of the variable, only used for array emission
|
||||||
/// @returns true if the type is emitted
|
/// @returns true if the type is emitted
|
||||||
bool EmitPackedType(const sem::Type* type, const std::string& name);
|
bool EmitPackedType(std::ostream& out,
|
||||||
|
const sem::Type* type,
|
||||||
|
const std::string& name);
|
||||||
/// Handles generating a struct declaration
|
/// Handles generating a struct declaration
|
||||||
/// @param str the struct to generate
|
/// @param str the struct to generate
|
||||||
/// @returns true if the struct is emitted
|
/// @returns true if the struct is emitted
|
||||||
bool EmitStructType(const sem::Struct* str);
|
bool EmitStructType(const sem::Struct* str);
|
||||||
/// Handles emitting a type constructor
|
/// Handles emitting a type constructor
|
||||||
|
/// @param out the output of the expression stream
|
||||||
/// @param expr the type constructor expression
|
/// @param expr the type constructor expression
|
||||||
/// @returns true if the constructor is emitted
|
/// @returns true if the constructor is emitted
|
||||||
bool EmitTypeConstructor(ast::TypeConstructorExpression* expr);
|
bool EmitTypeConstructor(std::ostream& out,
|
||||||
|
ast::TypeConstructorExpression* expr);
|
||||||
/// Handles a unary op expression
|
/// Handles a unary op expression
|
||||||
|
/// @param out the output of the expression stream
|
||||||
/// @param expr the expression to emit
|
/// @param expr the expression to emit
|
||||||
/// @returns true if the expression was emitted
|
/// @returns true if the expression was emitted
|
||||||
bool EmitUnaryOp(ast::UnaryOpExpression* expr);
|
bool EmitUnaryOp(std::ostream& out, ast::UnaryOpExpression* expr);
|
||||||
/// Handles generating a variable
|
/// Handles generating a variable
|
||||||
/// @param var the variable to generate
|
/// @param var the variable to generate
|
||||||
/// @returns true if the variable was emitted
|
/// @returns true if the variable was emitted
|
||||||
|
@ -216,9 +238,10 @@ class GeneratorImpl : public TextGenerator {
|
||||||
/// @returns true if the variable was emitted
|
/// @returns true if the variable was emitted
|
||||||
bool EmitProgramConstVariable(const ast::Variable* var);
|
bool EmitProgramConstVariable(const ast::Variable* var);
|
||||||
/// Emits the zero value for the given type
|
/// Emits the zero value for the given type
|
||||||
|
/// @param out the output of the expression stream
|
||||||
/// @param type the type to emit the value for
|
/// @param type the type to emit the value for
|
||||||
/// @returns true if the zero value was successfully emitted.
|
/// @returns true if the zero value was successfully emitted.
|
||||||
bool EmitZeroValue(const sem::Type* type);
|
bool EmitZeroValue(std::ostream& out, const sem::Type* type);
|
||||||
|
|
||||||
/// Handles generating a builtin name
|
/// Handles generating a builtin name
|
||||||
/// @param intrinsic the semantic info for the intrinsic
|
/// @param intrinsic the semantic info for the intrinsic
|
||||||
|
@ -259,15 +282,6 @@ class GeneratorImpl : public TextGenerator {
|
||||||
/// type.
|
/// type.
|
||||||
SizeAndAlign MslPackedTypeSizeAndAlign(const sem::Type* ty);
|
SizeAndAlign MslPackedTypeSizeAndAlign(const sem::Type* ty);
|
||||||
|
|
||||||
/// Emits `prefix`, followed by an opening brace `{`, then calls `cb` to emit
|
|
||||||
/// the block body, then finally emits the closing brace `}`.
|
|
||||||
/// @param prefix the string to emit before the opening brace
|
|
||||||
/// @param cb a function or function-like object with the signature `bool()`
|
|
||||||
/// that emits the block body.
|
|
||||||
/// @returns the return value of `cb`.
|
|
||||||
template <typename F>
|
|
||||||
bool EmitBlockBraces(const std::string& prefix, F&& cb);
|
|
||||||
|
|
||||||
const Program* program_ = nullptr;
|
const Program* program_ = nullptr;
|
||||||
std::function<bool()> emit_continuing_;
|
std::function<bool()> emit_continuing_;
|
||||||
};
|
};
|
||||||
|
|
|
@ -28,8 +28,9 @@ TEST_F(MslGeneratorImplTest, ArrayAccessor) {
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
ASSERT_TRUE(gen.EmitExpression(expr)) << gen.error();
|
std::stringstream out;
|
||||||
EXPECT_EQ(gen.result(), "ary[5]");
|
ASSERT_TRUE(gen.EmitExpression(out, expr)) << gen.error();
|
||||||
|
EXPECT_EQ(out.str(), "ary[5]");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(MslGeneratorImplTest, ArrayAccessor_OfDref) {
|
TEST_F(MslGeneratorImplTest, ArrayAccessor_OfDref) {
|
||||||
|
@ -41,8 +42,9 @@ TEST_F(MslGeneratorImplTest, ArrayAccessor_OfDref) {
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
ASSERT_TRUE(gen.EmitExpression(expr)) << gen.error();
|
std::stringstream out;
|
||||||
EXPECT_EQ(gen.result(), "(*(p))[5]");
|
ASSERT_TRUE(gen.EmitExpression(out, expr)) << gen.error();
|
||||||
|
EXPECT_EQ(out.str(), "(*(p))[5]");
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
|
@ -47,8 +47,9 @@ TEST_P(MslBinaryTest, Emit) {
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
ASSERT_TRUE(gen.EmitExpression(expr)) << gen.error();
|
std::stringstream out;
|
||||||
EXPECT_EQ(gen.result(), params.result);
|
ASSERT_TRUE(gen.EmitExpression(out, expr)) << gen.error();
|
||||||
|
EXPECT_EQ(out.str(), params.result);
|
||||||
}
|
}
|
||||||
INSTANTIATE_TEST_SUITE_P(
|
INSTANTIATE_TEST_SUITE_P(
|
||||||
MslGeneratorImplTest,
|
MslGeneratorImplTest,
|
||||||
|
|
|
@ -27,8 +27,9 @@ TEST_F(MslGeneratorImplTest, EmitExpression_Bitcast) {
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
ASSERT_TRUE(gen.EmitExpression(bitcast)) << gen.error();
|
std::stringstream out;
|
||||||
EXPECT_EQ(gen.result(), "as_type<float>(1)");
|
ASSERT_TRUE(gen.EmitExpression(out, bitcast)) << gen.error();
|
||||||
|
EXPECT_EQ(out.str(), "as_type<float>(1)");
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
|
@ -47,7 +47,8 @@ TEST_F(MslGeneratorImplTest, Emit_Block_WithoutNewline) {
|
||||||
ASSERT_TRUE(gen.EmitBlock(b)) << gen.error();
|
ASSERT_TRUE(gen.EmitBlock(b)) << gen.error();
|
||||||
EXPECT_EQ(gen.result(), R"( {
|
EXPECT_EQ(gen.result(), R"( {
|
||||||
discard_fragment();
|
discard_fragment();
|
||||||
})");
|
}
|
||||||
|
)");
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
|
@ -31,8 +31,9 @@ TEST_F(MslGeneratorImplTest, EmitExpression_Call_WithoutParams) {
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
ASSERT_TRUE(gen.EmitExpression(call)) << gen.error();
|
std::stringstream out;
|
||||||
EXPECT_EQ(gen.result(), "my_func()");
|
ASSERT_TRUE(gen.EmitExpression(out, call)) << gen.error();
|
||||||
|
EXPECT_EQ(out.str(), "my_func()");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(MslGeneratorImplTest, EmitExpression_Call_WithParams) {
|
TEST_F(MslGeneratorImplTest, EmitExpression_Call_WithParams) {
|
||||||
|
@ -50,8 +51,9 @@ TEST_F(MslGeneratorImplTest, EmitExpression_Call_WithParams) {
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
ASSERT_TRUE(gen.EmitExpression(call)) << gen.error();
|
std::stringstream out;
|
||||||
EXPECT_EQ(gen.result(), "my_func(param1, param2)");
|
ASSERT_TRUE(gen.EmitExpression(out, call)) << gen.error();
|
||||||
|
EXPECT_EQ(out.str(), "my_func(param1, param2)");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(MslGeneratorImplTest, EmitStatement_Call) {
|
TEST_F(MslGeneratorImplTest, EmitStatement_Call) {
|
||||||
|
|
|
@ -27,8 +27,9 @@ TEST_F(MslGeneratorImplTest, EmitExpression_Cast_Scalar) {
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
ASSERT_TRUE(gen.EmitExpression(cast)) << gen.error();
|
std::stringstream out;
|
||||||
EXPECT_EQ(gen.result(), "float(1)");
|
ASSERT_TRUE(gen.EmitExpression(out, cast)) << gen.error();
|
||||||
|
EXPECT_EQ(out.str(), "float(1)");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(MslGeneratorImplTest, EmitExpression_Cast_Vector) {
|
TEST_F(MslGeneratorImplTest, EmitExpression_Cast_Vector) {
|
||||||
|
@ -37,8 +38,9 @@ TEST_F(MslGeneratorImplTest, EmitExpression_Cast_Vector) {
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
ASSERT_TRUE(gen.EmitExpression(cast)) << gen.error();
|
std::stringstream out;
|
||||||
EXPECT_EQ(gen.result(), "float3(int3(1, 2, 3))");
|
ASSERT_TRUE(gen.EmitExpression(out, cast)) << gen.error();
|
||||||
|
EXPECT_EQ(out.str(), "float3(int3(1, 2, 3))");
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
|
@ -29,8 +29,9 @@ TEST_F(MslGeneratorImplTest, EmitIdentifierExpression) {
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
ASSERT_TRUE(gen.EmitExpression(i)) << gen.error();
|
std::stringstream out;
|
||||||
EXPECT_EQ(gen.result(), "foo");
|
ASSERT_TRUE(gen.EmitExpression(out, i)) << gen.error();
|
||||||
|
EXPECT_EQ(out.str(), "foo");
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
|
@ -50,9 +50,11 @@ TEST_F(MslGeneratorImplTest, Emit_IfWithElseIf) {
|
||||||
ASSERT_TRUE(gen.EmitStatement(i)) << gen.error();
|
ASSERT_TRUE(gen.EmitStatement(i)) << gen.error();
|
||||||
EXPECT_EQ(gen.result(), R"( if (cond) {
|
EXPECT_EQ(gen.result(), R"( if (cond) {
|
||||||
return;
|
return;
|
||||||
} else if (else_cond) {
|
} else {
|
||||||
|
if (else_cond) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
)");
|
)");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,11 +90,13 @@ TEST_F(MslGeneratorImplTest, Emit_IfWithMultiple) {
|
||||||
ASSERT_TRUE(gen.EmitStatement(i)) << gen.error();
|
ASSERT_TRUE(gen.EmitStatement(i)) << gen.error();
|
||||||
EXPECT_EQ(gen.result(), R"( if (cond) {
|
EXPECT_EQ(gen.result(), R"( if (cond) {
|
||||||
return;
|
return;
|
||||||
} else if (else_cond) {
|
} else {
|
||||||
|
if (else_cond) {
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
)");
|
)");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -81,8 +81,9 @@ TEST_F(MslGeneratorImplTest, MslImportData_SingleParamTest_IntScalar) {
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
ASSERT_TRUE(gen.EmitCall(expr)) << gen.error();
|
std::stringstream out;
|
||||||
EXPECT_EQ(gen.result(), R"(abs(1))");
|
ASSERT_TRUE(gen.EmitCall(out, expr)) << gen.error();
|
||||||
|
EXPECT_EQ(out.str(), R"(abs(1))");
|
||||||
}
|
}
|
||||||
|
|
||||||
using MslImportData_DualParamTest = TestParamHelper<MslImportData>;
|
using MslImportData_DualParamTest = TestParamHelper<MslImportData>;
|
||||||
|
@ -94,8 +95,9 @@ TEST_P(MslImportData_DualParamTest, FloatScalar) {
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
ASSERT_TRUE(gen.EmitCall(expr)) << gen.error();
|
std::stringstream out;
|
||||||
EXPECT_EQ(gen.result(), std::string(param.msl_name) + "(1.0f, 2.0f)");
|
ASSERT_TRUE(gen.EmitCall(out, expr)) << gen.error();
|
||||||
|
EXPECT_EQ(out.str(), std::string(param.msl_name) + "(1.0f, 2.0f)");
|
||||||
}
|
}
|
||||||
INSTANTIATE_TEST_SUITE_P(MslGeneratorImplTest,
|
INSTANTIATE_TEST_SUITE_P(MslGeneratorImplTest,
|
||||||
MslImportData_DualParamTest,
|
MslImportData_DualParamTest,
|
||||||
|
@ -117,8 +119,9 @@ TEST_P(MslImportData_DualParam_VectorTest, FloatVector) {
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
ASSERT_TRUE(gen.EmitCall(expr)) << gen.error();
|
std::stringstream out;
|
||||||
EXPECT_EQ(gen.result(), std::string(param.msl_name) +
|
ASSERT_TRUE(gen.EmitCall(out, expr)) << gen.error();
|
||||||
|
EXPECT_EQ(out.str(), std::string(param.msl_name) +
|
||||||
"(float3(1.0f, 2.0f, 3.0f), "
|
"(float3(1.0f, 2.0f, 3.0f), "
|
||||||
"float3(4.0f, 5.0f, 6.0f))");
|
"float3(4.0f, 5.0f, 6.0f))");
|
||||||
}
|
}
|
||||||
|
@ -135,8 +138,9 @@ TEST_P(MslImportData_DualParam_Int_Test, IntScalar) {
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
ASSERT_TRUE(gen.EmitCall(expr)) << gen.error();
|
std::stringstream out;
|
||||||
EXPECT_EQ(gen.result(), std::string(param.msl_name) + "(1, 2)");
|
ASSERT_TRUE(gen.EmitCall(out, expr)) << gen.error();
|
||||||
|
EXPECT_EQ(out.str(), std::string(param.msl_name) + "(1, 2)");
|
||||||
}
|
}
|
||||||
INSTANTIATE_TEST_SUITE_P(MslGeneratorImplTest,
|
INSTANTIATE_TEST_SUITE_P(MslGeneratorImplTest,
|
||||||
MslImportData_DualParam_Int_Test,
|
MslImportData_DualParam_Int_Test,
|
||||||
|
@ -152,8 +156,9 @@ TEST_P(MslImportData_TripleParamTest, FloatScalar) {
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
ASSERT_TRUE(gen.EmitCall(expr)) << gen.error();
|
std::stringstream out;
|
||||||
EXPECT_EQ(gen.result(), std::string(param.msl_name) + "(1.0f, 2.0f, 3.0f)");
|
ASSERT_TRUE(gen.EmitCall(out, expr)) << gen.error();
|
||||||
|
EXPECT_EQ(out.str(), std::string(param.msl_name) + "(1.0f, 2.0f, 3.0f)");
|
||||||
}
|
}
|
||||||
INSTANTIATE_TEST_SUITE_P(
|
INSTANTIATE_TEST_SUITE_P(
|
||||||
MslGeneratorImplTest,
|
MslGeneratorImplTest,
|
||||||
|
@ -173,8 +178,9 @@ TEST_P(MslImportData_TripleParam_Int_Test, IntScalar) {
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
ASSERT_TRUE(gen.EmitCall(expr)) << gen.error();
|
std::stringstream out;
|
||||||
EXPECT_EQ(gen.result(), std::string(param.msl_name) + "(1, 2, 3)");
|
ASSERT_TRUE(gen.EmitCall(out, expr)) << gen.error();
|
||||||
|
EXPECT_EQ(out.str(), std::string(param.msl_name) + "(1, 2, 3)");
|
||||||
}
|
}
|
||||||
INSTANTIATE_TEST_SUITE_P(MslGeneratorImplTest,
|
INSTANTIATE_TEST_SUITE_P(MslGeneratorImplTest,
|
||||||
MslImportData_TripleParam_Int_Test,
|
MslImportData_TripleParam_Int_Test,
|
||||||
|
@ -190,8 +196,9 @@ TEST_F(MslGeneratorImplTest, MslImportData_Determinant) {
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
ASSERT_TRUE(gen.EmitCall(expr)) << gen.error();
|
std::stringstream out;
|
||||||
EXPECT_EQ(gen.result(), std::string("determinant(var)"));
|
ASSERT_TRUE(gen.EmitCall(out, expr)) << gen.error();
|
||||||
|
EXPECT_EQ(out.str(), std::string("determinant(var)"));
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
|
@ -291,9 +291,9 @@ TEST_F(MslGeneratorImplTest, Intrinsic_Call) {
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
gen.increment_indent();
|
std::stringstream out;
|
||||||
ASSERT_TRUE(gen.EmitExpression(call)) << gen.error();
|
ASSERT_TRUE(gen.EmitExpression(out, call)) << gen.error();
|
||||||
EXPECT_EQ(gen.result(), " dot(param1, param2)");
|
EXPECT_EQ(out.str(), "dot(param1, param2)");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(MslGeneratorImplTest, StorageBarrier) {
|
TEST_F(MslGeneratorImplTest, StorageBarrier) {
|
||||||
|
@ -302,9 +302,9 @@ TEST_F(MslGeneratorImplTest, StorageBarrier) {
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
gen.increment_indent();
|
std::stringstream out;
|
||||||
ASSERT_TRUE(gen.EmitExpression(call)) << gen.error();
|
ASSERT_TRUE(gen.EmitExpression(out, call)) << gen.error();
|
||||||
EXPECT_EQ(gen.result(), " threadgroup_barrier(mem_flags::mem_device)");
|
EXPECT_EQ(out.str(), "threadgroup_barrier(mem_flags::mem_device)");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(MslGeneratorImplTest, WorkgroupBarrier) {
|
TEST_F(MslGeneratorImplTest, WorkgroupBarrier) {
|
||||||
|
@ -313,9 +313,9 @@ TEST_F(MslGeneratorImplTest, WorkgroupBarrier) {
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
gen.increment_indent();
|
std::stringstream out;
|
||||||
ASSERT_TRUE(gen.EmitExpression(call)) << gen.error();
|
ASSERT_TRUE(gen.EmitExpression(out, call)) << gen.error();
|
||||||
EXPECT_EQ(gen.result(), " threadgroup_barrier(mem_flags::mem_threadgroup)");
|
EXPECT_EQ(out.str(), "threadgroup_barrier(mem_flags::mem_threadgroup)");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(MslGeneratorImplTest, Pack2x16Float) {
|
TEST_F(MslGeneratorImplTest, Pack2x16Float) {
|
||||||
|
@ -325,9 +325,9 @@ TEST_F(MslGeneratorImplTest, Pack2x16Float) {
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
gen.increment_indent();
|
std::stringstream out;
|
||||||
ASSERT_TRUE(gen.EmitExpression(call)) << gen.error();
|
ASSERT_TRUE(gen.EmitExpression(out, call)) << gen.error();
|
||||||
EXPECT_EQ(gen.result(), " as_type<uint>(half2(p1))");
|
EXPECT_EQ(out.str(), "as_type<uint>(half2(p1))");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(MslGeneratorImplTest, Unpack2x16Float) {
|
TEST_F(MslGeneratorImplTest, Unpack2x16Float) {
|
||||||
|
@ -337,9 +337,9 @@ TEST_F(MslGeneratorImplTest, Unpack2x16Float) {
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
gen.increment_indent();
|
std::stringstream out;
|
||||||
ASSERT_TRUE(gen.EmitExpression(call)) << gen.error();
|
ASSERT_TRUE(gen.EmitExpression(out, call)) << gen.error();
|
||||||
EXPECT_EQ(gen.result(), " float2(as_type<half2>(p1))");
|
EXPECT_EQ(out.str(), "float2(as_type<half2>(p1))");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(MslGeneratorImplTest, Ignore) {
|
TEST_F(MslGeneratorImplTest, Ignore) {
|
||||||
|
|
|
@ -281,10 +281,11 @@ TEST_P(MslGeneratorIntrinsicTextureTest, Call) {
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
ASSERT_TRUE(gen.EmitExpression(call)) << gen.error();
|
std::stringstream out;
|
||||||
|
ASSERT_TRUE(gen.EmitExpression(out, call)) << gen.error();
|
||||||
|
|
||||||
auto expected = expected_texture_overload(param.overload);
|
auto expected = expected_texture_overload(param.overload);
|
||||||
EXPECT_EQ(expected, gen.result());
|
EXPECT_EQ(expected, out.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
INSTANTIATE_TEST_SUITE_P(
|
INSTANTIATE_TEST_SUITE_P(
|
||||||
|
|
|
@ -29,8 +29,9 @@ TEST_F(MslGeneratorImplTest, EmitExpression_MemberAccessor) {
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
ASSERT_TRUE(gen.EmitExpression(expr)) << gen.error();
|
std::stringstream out;
|
||||||
EXPECT_EQ(gen.result(), "str.mem");
|
ASSERT_TRUE(gen.EmitExpression(out, expr)) << gen.error();
|
||||||
|
EXPECT_EQ(out.str(), "str.mem");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(MslGeneratorImplTest, EmitExpression_MemberAccessor_Swizzle_xyz) {
|
TEST_F(MslGeneratorImplTest, EmitExpression_MemberAccessor_Swizzle_xyz) {
|
||||||
|
@ -40,8 +41,9 @@ TEST_F(MslGeneratorImplTest, EmitExpression_MemberAccessor_Swizzle_xyz) {
|
||||||
WrapInFunction(expr);
|
WrapInFunction(expr);
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
ASSERT_TRUE(gen.EmitExpression(expr)) << gen.error();
|
std::stringstream out;
|
||||||
EXPECT_EQ(gen.result(), "my_vec.xyz");
|
ASSERT_TRUE(gen.EmitExpression(out, expr)) << gen.error();
|
||||||
|
EXPECT_EQ(out.str(), "my_vec.xyz");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(MslGeneratorImplTest, EmitExpression_MemberAccessor_Swizzle_gbr) {
|
TEST_F(MslGeneratorImplTest, EmitExpression_MemberAccessor_Swizzle_gbr) {
|
||||||
|
@ -51,8 +53,9 @@ TEST_F(MslGeneratorImplTest, EmitExpression_MemberAccessor_Swizzle_gbr) {
|
||||||
WrapInFunction(expr);
|
WrapInFunction(expr);
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
ASSERT_TRUE(gen.EmitExpression(expr)) << gen.error();
|
std::stringstream out;
|
||||||
EXPECT_EQ(gen.result(), "my_vec.gbr");
|
ASSERT_TRUE(gen.EmitExpression(out, expr)) << gen.error();
|
||||||
|
EXPECT_EQ(out.str(), "my_vec.gbr");
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
|
@ -66,8 +66,9 @@ TEST_F(MslGeneratorImplTest, EmitType_Array) {
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
ASSERT_TRUE(gen.EmitType(program->TypeOf(arr), "ary")) << gen.error();
|
std::stringstream out;
|
||||||
EXPECT_EQ(gen.result(), "bool ary[4]");
|
ASSERT_TRUE(gen.EmitType(out, program->TypeOf(arr), "ary")) << gen.error();
|
||||||
|
EXPECT_EQ(out.str(), "bool ary[4]");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(MslGeneratorImplTest, EmitType_ArrayOfArray) {
|
TEST_F(MslGeneratorImplTest, EmitType_ArrayOfArray) {
|
||||||
|
@ -77,8 +78,9 @@ TEST_F(MslGeneratorImplTest, EmitType_ArrayOfArray) {
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
ASSERT_TRUE(gen.EmitType(program->TypeOf(b), "ary")) << gen.error();
|
std::stringstream out;
|
||||||
EXPECT_EQ(gen.result(), "bool ary[5][4]");
|
ASSERT_TRUE(gen.EmitType(out, program->TypeOf(b), "ary")) << gen.error();
|
||||||
|
EXPECT_EQ(out.str(), "bool ary[5][4]");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(MslGeneratorImplTest, EmitType_ArrayOfArrayOfArray) {
|
TEST_F(MslGeneratorImplTest, EmitType_ArrayOfArrayOfArray) {
|
||||||
|
@ -89,8 +91,9 @@ TEST_F(MslGeneratorImplTest, EmitType_ArrayOfArrayOfArray) {
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
ASSERT_TRUE(gen.EmitType(program->TypeOf(c), "ary")) << gen.error();
|
std::stringstream out;
|
||||||
EXPECT_EQ(gen.result(), "bool ary[6][5][4]");
|
ASSERT_TRUE(gen.EmitType(out, program->TypeOf(c), "ary")) << gen.error();
|
||||||
|
EXPECT_EQ(out.str(), "bool ary[6][5][4]");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(MslGeneratorImplTest, EmitType_Array_WithoutName) {
|
TEST_F(MslGeneratorImplTest, EmitType_Array_WithoutName) {
|
||||||
|
@ -99,8 +102,9 @@ TEST_F(MslGeneratorImplTest, EmitType_Array_WithoutName) {
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
ASSERT_TRUE(gen.EmitType(program->TypeOf(arr), "")) << gen.error();
|
std::stringstream out;
|
||||||
EXPECT_EQ(gen.result(), "bool[4]");
|
ASSERT_TRUE(gen.EmitType(out, program->TypeOf(arr), "")) << gen.error();
|
||||||
|
EXPECT_EQ(out.str(), "bool[4]");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(MslGeneratorImplTest, EmitType_RuntimeArray) {
|
TEST_F(MslGeneratorImplTest, EmitType_RuntimeArray) {
|
||||||
|
@ -109,8 +113,9 @@ TEST_F(MslGeneratorImplTest, EmitType_RuntimeArray) {
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
ASSERT_TRUE(gen.EmitType(program->TypeOf(arr), "ary")) << gen.error();
|
std::stringstream out;
|
||||||
EXPECT_EQ(gen.result(), "bool ary[1]");
|
ASSERT_TRUE(gen.EmitType(out, program->TypeOf(arr), "ary")) << gen.error();
|
||||||
|
EXPECT_EQ(out.str(), "bool ary[1]");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(MslGeneratorImplTest, EmitType_ArrayWithStride) {
|
TEST_F(MslGeneratorImplTest, EmitType_ArrayWithStride) {
|
||||||
|
@ -143,8 +148,9 @@ TEST_F(MslGeneratorImplTest, EmitType_Bool) {
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
ASSERT_TRUE(gen.EmitType(bool_, "")) << gen.error();
|
std::stringstream out;
|
||||||
EXPECT_EQ(gen.result(), "bool");
|
ASSERT_TRUE(gen.EmitType(out, bool_, "")) << gen.error();
|
||||||
|
EXPECT_EQ(out.str(), "bool");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(MslGeneratorImplTest, EmitType_F32) {
|
TEST_F(MslGeneratorImplTest, EmitType_F32) {
|
||||||
|
@ -152,8 +158,9 @@ TEST_F(MslGeneratorImplTest, EmitType_F32) {
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
ASSERT_TRUE(gen.EmitType(f32, "")) << gen.error();
|
std::stringstream out;
|
||||||
EXPECT_EQ(gen.result(), "float");
|
ASSERT_TRUE(gen.EmitType(out, f32, "")) << gen.error();
|
||||||
|
EXPECT_EQ(out.str(), "float");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(MslGeneratorImplTest, EmitType_I32) {
|
TEST_F(MslGeneratorImplTest, EmitType_I32) {
|
||||||
|
@ -161,8 +168,9 @@ TEST_F(MslGeneratorImplTest, EmitType_I32) {
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
ASSERT_TRUE(gen.EmitType(i32, "")) << gen.error();
|
std::stringstream out;
|
||||||
EXPECT_EQ(gen.result(), "int");
|
ASSERT_TRUE(gen.EmitType(out, i32, "")) << gen.error();
|
||||||
|
EXPECT_EQ(out.str(), "int");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(MslGeneratorImplTest, EmitType_Matrix) {
|
TEST_F(MslGeneratorImplTest, EmitType_Matrix) {
|
||||||
|
@ -172,8 +180,9 @@ TEST_F(MslGeneratorImplTest, EmitType_Matrix) {
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
ASSERT_TRUE(gen.EmitType(mat2x3, "")) << gen.error();
|
std::stringstream out;
|
||||||
EXPECT_EQ(gen.result(), "float2x3");
|
ASSERT_TRUE(gen.EmitType(out, mat2x3, "")) << gen.error();
|
||||||
|
EXPECT_EQ(out.str(), "float2x3");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(MslGeneratorImplTest, EmitType_Pointer) {
|
TEST_F(MslGeneratorImplTest, EmitType_Pointer) {
|
||||||
|
@ -183,8 +192,9 @@ TEST_F(MslGeneratorImplTest, EmitType_Pointer) {
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
ASSERT_TRUE(gen.EmitType(p, "")) << gen.error();
|
std::stringstream out;
|
||||||
EXPECT_EQ(gen.result(), "threadgroup float* ");
|
ASSERT_TRUE(gen.EmitType(out, p, "")) << gen.error();
|
||||||
|
EXPECT_EQ(out.str(), "threadgroup float* ");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(MslGeneratorImplTest, EmitType_Struct) {
|
TEST_F(MslGeneratorImplTest, EmitType_Struct) {
|
||||||
|
@ -195,8 +205,9 @@ TEST_F(MslGeneratorImplTest, EmitType_Struct) {
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
ASSERT_TRUE(gen.EmitType(program->TypeOf(s), "")) << gen.error();
|
std::stringstream out;
|
||||||
EXPECT_EQ(gen.result(), "S");
|
ASSERT_TRUE(gen.EmitType(out, program->TypeOf(s), "")) << gen.error();
|
||||||
|
EXPECT_EQ(out.str(), "S");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(MslGeneratorImplTest, EmitType_StructDecl) {
|
TEST_F(MslGeneratorImplTest, EmitType_StructDecl) {
|
||||||
|
@ -670,8 +681,9 @@ TEST_F(MslGeneratorImplTest, DISABLED_EmitType_Struct_WithDecoration) {
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
ASSERT_TRUE(gen.EmitType(program->TypeOf(s), "")) << gen.error();
|
std::stringstream out;
|
||||||
EXPECT_EQ(gen.result(), R"(struct {
|
ASSERT_TRUE(gen.EmitType(out, program->TypeOf(s), "")) << gen.error();
|
||||||
|
EXPECT_EQ(out.str(), R"(struct {
|
||||||
/* 0x0000 */ int a;
|
/* 0x0000 */ int a;
|
||||||
/* 0x0004 */ float b;
|
/* 0x0004 */ float b;
|
||||||
})");
|
})");
|
||||||
|
@ -682,8 +694,9 @@ TEST_F(MslGeneratorImplTest, EmitType_U32) {
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
ASSERT_TRUE(gen.EmitType(u32, "")) << gen.error();
|
std::stringstream out;
|
||||||
EXPECT_EQ(gen.result(), "uint");
|
ASSERT_TRUE(gen.EmitType(out, u32, "")) << gen.error();
|
||||||
|
EXPECT_EQ(out.str(), "uint");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(MslGeneratorImplTest, EmitType_Vector) {
|
TEST_F(MslGeneratorImplTest, EmitType_Vector) {
|
||||||
|
@ -692,8 +705,9 @@ TEST_F(MslGeneratorImplTest, EmitType_Vector) {
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
ASSERT_TRUE(gen.EmitType(vec3, "")) << gen.error();
|
std::stringstream out;
|
||||||
EXPECT_EQ(gen.result(), "float3");
|
ASSERT_TRUE(gen.EmitType(out, vec3, "")) << gen.error();
|
||||||
|
EXPECT_EQ(out.str(), "float3");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(MslGeneratorImplTest, EmitType_Void) {
|
TEST_F(MslGeneratorImplTest, EmitType_Void) {
|
||||||
|
@ -701,8 +715,9 @@ TEST_F(MslGeneratorImplTest, EmitType_Void) {
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
ASSERT_TRUE(gen.EmitType(void_, "")) << gen.error();
|
std::stringstream out;
|
||||||
EXPECT_EQ(gen.result(), "void");
|
ASSERT_TRUE(gen.EmitType(out, void_, "")) << gen.error();
|
||||||
|
EXPECT_EQ(out.str(), "void");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(MslGeneratorImplTest, EmitType_Sampler) {
|
TEST_F(MslGeneratorImplTest, EmitType_Sampler) {
|
||||||
|
@ -710,8 +725,9 @@ TEST_F(MslGeneratorImplTest, EmitType_Sampler) {
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
ASSERT_TRUE(gen.EmitType(sampler, "")) << gen.error();
|
std::stringstream out;
|
||||||
EXPECT_EQ(gen.result(), "sampler");
|
ASSERT_TRUE(gen.EmitType(out, sampler, "")) << gen.error();
|
||||||
|
EXPECT_EQ(out.str(), "sampler");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(MslGeneratorImplTest, EmitType_SamplerComparison) {
|
TEST_F(MslGeneratorImplTest, EmitType_SamplerComparison) {
|
||||||
|
@ -719,8 +735,9 @@ TEST_F(MslGeneratorImplTest, EmitType_SamplerComparison) {
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
ASSERT_TRUE(gen.EmitType(sampler, "")) << gen.error();
|
std::stringstream out;
|
||||||
EXPECT_EQ(gen.result(), "sampler");
|
ASSERT_TRUE(gen.EmitType(out, sampler, "")) << gen.error();
|
||||||
|
EXPECT_EQ(out.str(), "sampler");
|
||||||
}
|
}
|
||||||
|
|
||||||
struct MslDepthTextureData {
|
struct MslDepthTextureData {
|
||||||
|
@ -739,8 +756,9 @@ TEST_P(MslDepthTexturesTest, Emit) {
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
ASSERT_TRUE(gen.EmitType(&s, "")) << gen.error();
|
std::stringstream out;
|
||||||
EXPECT_EQ(gen.result(), params.result);
|
ASSERT_TRUE(gen.EmitType(out, &s, "")) << gen.error();
|
||||||
|
EXPECT_EQ(out.str(), params.result);
|
||||||
}
|
}
|
||||||
INSTANTIATE_TEST_SUITE_P(
|
INSTANTIATE_TEST_SUITE_P(
|
||||||
MslGeneratorImplTest,
|
MslGeneratorImplTest,
|
||||||
|
@ -772,8 +790,9 @@ TEST_P(MslSampledtexturesTest, Emit) {
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
ASSERT_TRUE(gen.EmitType(s, "")) << gen.error();
|
std::stringstream out;
|
||||||
EXPECT_EQ(gen.result(), params.result);
|
ASSERT_TRUE(gen.EmitType(out, s, "")) << gen.error();
|
||||||
|
EXPECT_EQ(out.str(), params.result);
|
||||||
}
|
}
|
||||||
INSTANTIATE_TEST_SUITE_P(
|
INSTANTIATE_TEST_SUITE_P(
|
||||||
MslGeneratorImplTest,
|
MslGeneratorImplTest,
|
||||||
|
@ -798,8 +817,9 @@ TEST_F(MslGeneratorImplTest, Emit_TypeMultisampledTexture) {
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
ASSERT_TRUE(gen.EmitType(ms, "")) << gen.error();
|
std::stringstream out;
|
||||||
EXPECT_EQ(gen.result(), "texture2d_ms<uint, access::read>");
|
ASSERT_TRUE(gen.EmitType(out, ms, "")) << gen.error();
|
||||||
|
EXPECT_EQ(out.str(), "texture2d_ms<uint, access::read>");
|
||||||
}
|
}
|
||||||
|
|
||||||
struct MslStorageTextureData {
|
struct MslStorageTextureData {
|
||||||
|
@ -826,8 +846,9 @@ TEST_P(MslStorageTexturesTest, Emit) {
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
ASSERT_TRUE(gen.EmitType(program->TypeOf(s), "")) << gen.error();
|
std::stringstream out;
|
||||||
EXPECT_EQ(gen.result(), params.result);
|
ASSERT_TRUE(gen.EmitType(out, program->TypeOf(s), "")) << gen.error();
|
||||||
|
EXPECT_EQ(out.str(), params.result);
|
||||||
}
|
}
|
||||||
INSTANTIATE_TEST_SUITE_P(
|
INSTANTIATE_TEST_SUITE_P(
|
||||||
MslGeneratorImplTest,
|
MslGeneratorImplTest,
|
||||||
|
|
|
@ -29,8 +29,9 @@ TEST_F(MslUnaryOpTest, AddressOf) {
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
ASSERT_TRUE(gen.EmitExpression(op)) << gen.error();
|
std::stringstream out;
|
||||||
EXPECT_EQ(gen.result(), "&(expr)");
|
ASSERT_TRUE(gen.EmitExpression(out, op)) << gen.error();
|
||||||
|
EXPECT_EQ(out.str(), "&(expr)");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(MslUnaryOpTest, Complement) {
|
TEST_F(MslUnaryOpTest, Complement) {
|
||||||
|
@ -41,8 +42,9 @@ TEST_F(MslUnaryOpTest, Complement) {
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
ASSERT_TRUE(gen.EmitExpression(op)) << gen.error();
|
std::stringstream out;
|
||||||
EXPECT_EQ(gen.result(), "~(expr)");
|
ASSERT_TRUE(gen.EmitExpression(out, op)) << gen.error();
|
||||||
|
EXPECT_EQ(out.str(), "~(expr)");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(MslUnaryOpTest, Indirection) {
|
TEST_F(MslUnaryOpTest, Indirection) {
|
||||||
|
@ -56,8 +58,9 @@ TEST_F(MslUnaryOpTest, Indirection) {
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
ASSERT_TRUE(gen.EmitExpression(op)) << gen.error();
|
std::stringstream out;
|
||||||
EXPECT_EQ(gen.result(), "*(expr)");
|
ASSERT_TRUE(gen.EmitExpression(out, op)) << gen.error();
|
||||||
|
EXPECT_EQ(out.str(), "*(expr)");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(MslUnaryOpTest, Not) {
|
TEST_F(MslUnaryOpTest, Not) {
|
||||||
|
@ -67,8 +70,9 @@ TEST_F(MslUnaryOpTest, Not) {
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
ASSERT_TRUE(gen.EmitExpression(op)) << gen.error();
|
std::stringstream out;
|
||||||
EXPECT_EQ(gen.result(), "!(expr)");
|
ASSERT_TRUE(gen.EmitExpression(out, op)) << gen.error();
|
||||||
|
EXPECT_EQ(out.str(), "!(expr)");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(MslUnaryOpTest, Negation) {
|
TEST_F(MslUnaryOpTest, Negation) {
|
||||||
|
@ -79,8 +83,9 @@ TEST_F(MslUnaryOpTest, Negation) {
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
ASSERT_TRUE(gen.EmitExpression(op)) << gen.error();
|
std::stringstream out;
|
||||||
EXPECT_EQ(gen.result(), "-(expr)");
|
ASSERT_TRUE(gen.EmitExpression(out, op)) << gen.error();
|
||||||
|
EXPECT_EQ(out.str(), "-(expr)");
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
|
@ -44,8 +44,9 @@ TextGenerator::LineWriter::~LineWriter() {
|
||||||
auto str = os.str();
|
auto str = os.str();
|
||||||
if (!str.empty()) {
|
if (!str.empty()) {
|
||||||
gen->make_indent();
|
gen->make_indent();
|
||||||
gen->out_ << str << std::endl;
|
gen->out_ << str;
|
||||||
}
|
}
|
||||||
|
gen->out_ << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue