writer/hlsl: Rework string printing

Remove `pre` and `out` parameters from most generator methods.
Use the `out_` string stream in TextGenerator, add helpers to TextGenerator to simplify line printing.

Remove the `pre` and `out` fields from TestHelper.

Cleans up the `pre` aspects of the HLSL writer, so the same concept can be used by the MSL writer.
Fixes indentation bugs in formatting.

Change-Id: Ia35daf632c7c7b84a6fbf3b9ae42baaeb3c97649
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/55960
Auto-Submit: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Reviewed-by: David Neto <dneto@google.com>
Reviewed-by: James Price <jrprice@google.com>
This commit is contained in:
Ben Clayton 2021-06-26 11:11:55 +00:00 committed by Tint LUCI CQ
parent e25a8fc7f0
commit c03a09c106
48 changed files with 1480 additions and 1563 deletions

View File

@ -26,7 +26,7 @@ Generator::Generator(const Program* program)
Generator::~Generator() = default;
bool Generator::Generate() {
auto ret = impl_->Generate(out_);
auto ret = impl_->Generate();
if (!ret) {
error_ = impl_->error();
}
@ -34,7 +34,7 @@ bool Generator::Generate() {
}
std::string Generator::result() const {
return out_.str();
return impl_->result();
}
std::string Generator::error() const {

View File

@ -48,7 +48,6 @@ class Generator : public Text {
std::string error() const;
private:
std::ostringstream out_;
std::unique_ptr<GeneratorImpl> impl_;
};

File diff suppressed because it is too large Load Diff

View File

@ -54,320 +54,246 @@ class GeneratorImpl : public TextGenerator {
explicit GeneratorImpl(const Program* program);
~GeneratorImpl();
/// @param out the output stream
/// @returns true on successful generation; false otherwise
bool Generate(std::ostream& out);
bool Generate();
/// Handles an array accessor expression
/// @param pre the preamble for the expression stream
/// @param out the output of the expression stream
/// @param expr the expression to emit
/// @returns true if the array accessor was emitted
bool EmitArrayAccessor(std::ostream& pre,
std::ostream& out,
ast::ArrayAccessorExpression* expr);
bool EmitArrayAccessor(std::ostream& out, ast::ArrayAccessorExpression* expr);
/// Handles an assignment statement
/// @param out the output stream
/// @param stmt the statement to emit
/// @returns true if the statement was emitted successfully
bool EmitAssign(std::ostream& out, ast::AssignmentStatement* stmt);
bool EmitAssign(ast::AssignmentStatement* stmt);
/// Handles generating a binary expression
/// @param pre the preamble for the expression stream
/// @param out the output of the expression stream
/// @param expr the binary expression
/// @returns true if the expression was emitted, false otherwise
bool EmitBinary(std::ostream& pre,
std::ostream& out,
ast::BinaryExpression* expr);
bool EmitBinary(std::ostream& out, ast::BinaryExpression* expr);
/// Handles generating a bitcast expression
/// @param pre the preamble for the expression stream
/// @param out the output of the expression stream
/// @param expr the as expression
/// @returns true if the bitcast was emitted
bool EmitBitcast(std::ostream& pre,
std::ostream& out,
ast::BitcastExpression* expr);
bool EmitBitcast(std::ostream& out, ast::BitcastExpression* expr);
/// 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 a block statement
/// @param out the output stream
/// @param stmt the statement to emit
/// @returns true if the statement was emitted successfully
bool EmitBlock(std::ostream& out, const ast::BlockStatement* stmt);
/// Handles a block statement with a newline at the end
/// @param out the output stream
/// @param stmt the statement to emit
/// @returns true if the statement was emitted successfully
bool EmitIndentedBlockAndNewline(std::ostream& out,
ast::BlockStatement* stmt);
/// Handles a block statement with a newline at the end
/// @param out the output stream
/// @param stmt the statement to emit
/// @returns true if the statement was emitted successfully
bool EmitBlockAndNewline(std::ostream& out, const ast::BlockStatement* stmt);
bool EmitBlock(const ast::BlockStatement* stmt);
/// Handles a break statement
/// @param out the output stream
/// @param stmt the statement to emit
/// @returns true if the statement was emitted successfully
bool EmitBreak(std::ostream& out, ast::BreakStatement* stmt);
bool EmitBreak(ast::BreakStatement* stmt);
/// Handles generating a call expression
/// @param pre the preamble for the expression stream
/// @param out the output of the expression stream
/// @param expr the call expression
/// @returns true if the call expression is emitted
bool EmitCall(std::ostream& pre,
std::ostream& out,
ast::CallExpression* expr);
bool EmitCall(std::ostream& out, ast::CallExpression* expr);
/// Handles generating a call expression to a
/// transform::DecomposeMemoryAccess::Intrinsic for a uniform buffer
/// @param pre the preamble for the expression stream
/// @param out the output of the expression stream
/// @param expr the call expression
/// @param intrinsic the transform::DecomposeMemoryAccess::Intrinsic
/// @returns true if the call expression is emitted
bool EmitUniformBufferAccess(
std::ostream& pre,
std::ostream& out,
ast::CallExpression* expr,
const transform::DecomposeMemoryAccess::Intrinsic* intrinsic);
/// Handles generating a call expression to a
/// transform::DecomposeMemoryAccess::Intrinsic for a storage buffer
/// @param pre the preamble for the expression stream
/// @param out the output of the expression stream
/// @param expr the call expression
/// @param intrinsic the transform::DecomposeMemoryAccess::Intrinsic
/// @returns true if the call expression is emitted
bool EmitStorageBufferAccess(
std::ostream& pre,
std::ostream& out,
ast::CallExpression* expr,
const transform::DecomposeMemoryAccess::Intrinsic* intrinsic);
/// Handles generating a barrier intrinsic call
/// @param pre the preamble for the expression stream
/// @param out the output of the expression stream
/// @param intrinsic the semantic information for the barrier intrinsic
/// @returns true if the call expression is emitted
bool EmitBarrierCall(std::ostream& pre,
std::ostream& out,
const sem::Intrinsic* intrinsic);
bool EmitBarrierCall(std::ostream& out, const sem::Intrinsic* intrinsic);
/// Handles generating an atomic intrinsic call for a storage buffer variable
/// @param pre the preamble for the expression stream
/// @param out the output of the expression stream
/// @param expr the call expression
/// @param op the atomic op
/// @returns true if the call expression is emitted
bool EmitStorageAtomicCall(
std::ostream& pre,
std::ostream& out,
ast::CallExpression* expr,
transform::DecomposeMemoryAccess::Intrinsic::Op op);
/// Handles generating an atomic intrinsic call for a workgroup variable
/// @param pre the preamble for the expression stream
/// @param out the output of the expression stream
/// @param expr the call expression
/// @param intrinsic the semantic information for the atomic intrinsic
/// @returns true if the call expression is emitted
bool EmitWorkgroupAtomicCall(std::ostream& pre,
std::ostream& out,
bool EmitWorkgroupAtomicCall(std::ostream& out,
ast::CallExpression* expr,
const sem::Intrinsic* intrinsic);
/// Handles generating a call to a texture function (`textureSample`,
/// `textureSampleGrad`, etc)
/// @param pre the preamble for the expression stream
/// @param out the output of the expression stream
/// @param expr the call expression
/// @param intrinsic the semantic information for the texture intrinsic
/// @returns true if the call expression is emitted
bool EmitTextureCall(std::ostream& pre,
std::ostream& out,
bool EmitTextureCall(std::ostream& out,
ast::CallExpression* expr,
const sem::Intrinsic* intrinsic);
/// Handles generating a call to the `select()` intrinsic
/// @param pre the preamble of the expression stream
/// @param out the output of the expression stream
/// @param expr the call expression
/// @returns true if the call expression is emitted
bool EmitSelectCall(std::ostream& pre,
std::ostream& out,
ast::CallExpression* expr);
bool EmitSelectCall(std::ostream& out, ast::CallExpression* expr);
/// Handles generating a call to the `frexp()` intrinsic
/// @param pre the preamble of the expression stream
/// @param out the output of the expression stream
/// @param expr the call expression
/// @param intrinsic the semantic information for the intrinsic
/// @returns true if the call expression is emitted
bool EmitFrexpCall(std::ostream& pre,
std::ostream& out,
bool EmitFrexpCall(std::ostream& out,
ast::CallExpression* expr,
const sem::Intrinsic* intrinsic);
/// Handles generating a call to the `isNormal()` intrinsic
/// @param pre the preamble of the expression stream
/// @param out the output of the expression stream
/// @param expr the call expression
/// @param intrinsic the semantic information for the intrinsic
/// @returns true if the call expression is emitted
bool EmitIsNormalCall(std::ostream& pre,
std::ostream& out,
bool EmitIsNormalCall(std::ostream& out,
ast::CallExpression* expr,
const sem::Intrinsic* intrinsic);
/// Handles generating a call to data packing intrinsic
/// @param pre the preamble of the expression stream
/// @param out the output of the expression stream
/// @param expr the call expression
/// @param intrinsic the semantic information for the texture intrinsic
/// @returns true if the call expression is emitted
bool EmitDataPackingCall(std::ostream& pre,
std::ostream& out,
bool EmitDataPackingCall(std::ostream& out,
ast::CallExpression* expr,
const sem::Intrinsic* intrinsic);
/// Handles generating a call to data unpacking intrinsic
/// @param pre the preamble of the expression stream
/// @param out the output of the expression stream
/// @param expr the call expression
/// @param intrinsic the semantic information for the texture intrinsic
/// @returns true if the call expression is emitted
bool EmitDataUnpackingCall(std::ostream& pre,
std::ostream& out,
bool EmitDataUnpackingCall(std::ostream& out,
ast::CallExpression* expr,
const sem::Intrinsic* intrinsic);
/// Handles a case statement
/// @param out the output stream
/// @param stmt the statement
/// @returns true if the statment was emitted successfully
bool EmitCase(std::ostream& out, ast::CaseStatement* stmt);
/// @returns true if the statement was emitted successfully
bool EmitCase(ast::CaseStatement* stmt);
/// Handles generating constructor expressions
/// @param pre the preamble for the expression stream
/// @param out the output of the expression stream
/// @param expr the constructor expression
/// @returns true if the expression was emitted
bool EmitConstructor(std::ostream& pre,
std::ostream& out,
ast::ConstructorExpression* expr);
bool EmitConstructor(std::ostream& out, ast::ConstructorExpression* expr);
/// Handles generating a discard statement
/// @param out the output stream
/// @param stmt the discard statement
/// @returns true if the statement was successfully emitted
bool EmitDiscard(std::ostream& out, ast::DiscardStatement* stmt);
bool EmitDiscard(ast::DiscardStatement* stmt);
/// Handles generating a scalar constructor
/// @param pre the preamble for the expression stream
/// @param out the output of the expression stream
/// @param expr the scalar constructor expression
/// @returns true if the scalar constructor is emitted
bool EmitScalarConstructor(std::ostream& pre,
std::ostream& out,
bool EmitScalarConstructor(std::ostream& out,
ast::ScalarConstructorExpression* expr);
/// Handles emitting a type constructor
/// @param pre the preamble for the expression stream
/// @param out the output of the expression stream
/// @param expr the type constructor expression
/// @returns true if the constructor is emitted
bool EmitTypeConstructor(std::ostream& pre,
std::ostream& out,
bool EmitTypeConstructor(std::ostream& out,
ast::TypeConstructorExpression* expr);
/// Handles a continue statement
/// @param out the output stream
/// @param stmt the statement to emit
/// @returns true if the statement was emitted successfully
bool EmitContinue(std::ostream& out, ast::ContinueStatement* stmt);
bool EmitContinue(ast::ContinueStatement* stmt);
/// Handles generate an Expression
/// @param pre the preamble for the expression stream
/// @param out the output of the expression stream
/// @param expr the expression
/// @returns true if the expression was emitted
bool EmitExpression(std::ostream& pre,
std::ostream& out,
ast::Expression* expr);
bool EmitExpression(std::ostream& out, ast::Expression* expr);
/// Handles generating a function
/// @param out the output stream
/// @param func the function to generate
/// @returns true if the function was emitted
bool EmitFunction(std::ostream& out, ast::Function* func);
bool EmitFunction(ast::Function* func);
/// Handles emitting a global variable
/// @param out the output stream
/// @param global the global variable
/// @returns true on success
bool EmitGlobalVariable(std::ostream& out, ast::Variable* global);
bool EmitGlobalVariable(ast::Variable* global);
/// Handles emitting a global variable with the uniform storage class
/// @param out the output stream
/// @param var the global variable
/// @returns true on success
bool EmitUniformVariable(std::ostream& out, const sem::Variable* var);
bool EmitUniformVariable(const sem::Variable* var);
/// Handles emitting a global variable with the storage storage class
/// @param out the output stream
/// @param var the global variable
/// @returns true on success
bool EmitStorageVariable(std::ostream& out, const sem::Variable* var);
bool EmitStorageVariable(const sem::Variable* var);
/// Handles emitting a global variable with the handle storage class
/// @param out the output stream
/// @param var the global variable
/// @returns true on success
bool EmitHandleVariable(std::ostream& out, const sem::Variable* var);
bool EmitHandleVariable(const sem::Variable* var);
/// Handles emitting a global variable with the private storage class
/// @param out the output stream
/// @param var the global variable
/// @returns true on success
bool EmitPrivateVariable(std::ostream& out, const sem::Variable* var);
bool EmitPrivateVariable(const sem::Variable* var);
/// Handles emitting a global variable with the workgroup storage class
/// @param out the output stream
/// @param var the global variable
/// @returns true on success
bool EmitWorkgroupVariable(std::ostream& out, const sem::Variable* var);
bool EmitWorkgroupVariable(const sem::Variable* var);
/// Handles emitting the entry point function
/// @param out the output stream
/// @param func the entry point
/// @returns true if the entry point function was emitted
bool EmitEntryPointFunction(std::ostream& out, ast::Function* func);
bool EmitEntryPointFunction(ast::Function* func);
/// Handles an if statement
/// @param out the output stream
/// @param stmt the statement to emit
/// @returns true if the statement was successfully emitted
bool EmitIf(std::ostream& out, ast::IfStatement* stmt);
bool EmitIf(ast::IfStatement* stmt);
/// Handles a literal
/// @param out the output stream
/// @param lit the literal to emit
/// @returns true if the literal was successfully emitted
bool EmitLiteral(std::ostream& out, ast::Literal* lit);
/// Handles a loop statement
/// @param out the output stream
/// @param stmt the statement to emit
/// @returns true if the statement was emitted
bool EmitLoop(std::ostream& out, ast::LoopStatement* stmt);
bool EmitLoop(ast::LoopStatement* stmt);
/// Handles generating an identifier expression
/// @param pre the preamble for the expression stream
/// @param out the output of the expression stream
/// @param expr the identifier expression
/// @returns true if the identifeir was emitted
bool EmitIdentifier(std::ostream& pre,
std::ostream& out,
ast::IdentifierExpression* expr);
bool EmitIdentifier(std::ostream& out, ast::IdentifierExpression* expr);
/// Handles a member accessor expression
/// @param pre the preamble for the expression stream
/// @param out the output of the expression stream
/// @param expr the member accessor expression
/// @returns true if the member accessor was emitted
bool EmitMemberAccessor(std::ostream& pre,
std::ostream& out,
bool EmitMemberAccessor(std::ostream& out,
ast::MemberAccessorExpression* expr);
/// Handles return statements
/// @param out the output stream
/// @param stmt the statement to emit
/// @returns true if the statement was successfully emitted
bool EmitReturn(std::ostream& out, ast::ReturnStatement* stmt);
bool EmitReturn(ast::ReturnStatement* stmt);
/// Handles statement
/// @param out the output stream
/// @param stmt the statement to emit
/// @returns true if the statement was emitted
bool EmitStatement(std::ostream& out, ast::Statement* stmt);
bool EmitStatement(ast::Statement* stmt);
/// Handles generating a switch statement
/// @param out the output stream
/// @param stmt the statement to emit
/// @returns true if the statement was emitted
bool EmitSwitch(std::ostream& out, ast::SwitchStatement* stmt);
bool EmitSwitch(ast::SwitchStatement* stmt);
/// Handles generating type
/// @param out the output stream
/// @param type the type to generate
@ -396,33 +322,27 @@ class GeneratorImpl : public TextGenerator {
ast::Access access,
const std::string& name);
/// Handles generating a structure declaration
/// @param out the output stream
/// @param ty the struct to generate
/// @returns true if the struct is emitted
bool EmitStructType(std::ostream& out, const sem::Struct* ty);
bool EmitStructType(const sem::Struct* ty);
/// Handles a unary op expression
/// @param pre the preamble for the expression stream
/// @param out the output of the expression stream
/// @param expr the expression to emit
/// @returns true if the expression was emitted
bool EmitUnaryOp(std::ostream& pre,
std::ostream& out,
ast::UnaryOpExpression* expr);
bool EmitUnaryOp(std::ostream& out, ast::UnaryOpExpression* expr);
/// Emits the zero value for the given type
/// @param out the output stream
/// @param type the type to emit the value for
/// @returns true if the zero value was successfully emitted.
bool EmitZeroValue(std::ostream& out, const sem::Type* type);
/// Handles generating a variable
/// @param out the output stream
/// @param var the variable to generate
/// @returns true if the variable was emitted
bool EmitVariable(std::ostream& out, ast::Variable* var);
bool EmitVariable(ast::Variable* var);
/// Handles generating a program scope constant variable
/// @param out the output stream
/// @param var the variable to emit
/// @returns true if the variable was emitted
bool EmitProgramConstVariable(std::ostream& out, const ast::Variable* var);
bool EmitProgramConstVariable(const ast::Variable* var);
/// Handles generating a builtin method name
/// @param intrinsic the semantic info for the intrinsic
@ -466,29 +386,8 @@ class GeneratorImpl : public TextGenerator {
return builder_.TypeOf(type_decl);
}
/// Emits `prefix`, followed by an opening brace `{`, then calls `cb` to emit
/// the block body, then finally emits the closing brace `}`.
/// @param out the output stream
/// @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(std::ostream& out, const std::string& prefix, F&& cb);
/// Emits an opening brace `{`, then calls `cb` to emit the block body, then
/// finally emits the closing brace `}`.
/// @param out the output stream
/// @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(std::ostream& out, F&& cb) {
return EmitBlockBraces(out, "", std::forward<F>(cb));
}
ProgramBuilder builder_;
std::function<bool(std::ostream& out)> emit_continuing_;
std::function<bool()> emit_continuing_;
std::unordered_map<const sem::Struct*, std::string> structure_builders_;
};

View File

@ -28,8 +28,9 @@ TEST_F(HlslGeneratorImplTest_Expression, ArrayAccessor) {
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.EmitExpression(pre, out, expr)) << gen.error();
EXPECT_EQ(result(), "ary[5]");
std::stringstream out;
ASSERT_TRUE(gen.EmitExpression(out, expr)) << gen.error();
EXPECT_EQ(out.str(), "ary[5]");
}
} // namespace

View File

@ -31,8 +31,8 @@ TEST_F(HlslGeneratorImplTest_Assign, Emit_Assign) {
gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(out, assign)) << gen.error();
EXPECT_EQ(result(), " lhs = rhs;\n");
ASSERT_TRUE(gen.EmitStatement(assign)) << gen.error();
EXPECT_EQ(gen.result(), " lhs = rhs;\n");
}
} // namespace

View File

@ -56,8 +56,9 @@ TEST_P(HlslBinaryTest, Emit_f32) {
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.EmitExpression(pre, out, expr)) << gen.error();
EXPECT_EQ(result(), params.result);
std::stringstream out;
ASSERT_TRUE(gen.EmitExpression(out, expr)) << gen.error();
EXPECT_EQ(out.str(), params.result);
}
TEST_P(HlslBinaryTest, Emit_u32) {
auto params = GetParam();
@ -74,8 +75,9 @@ TEST_P(HlslBinaryTest, Emit_u32) {
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.EmitExpression(pre, out, expr)) << gen.error();
EXPECT_EQ(result(), params.result);
std::stringstream out;
ASSERT_TRUE(gen.EmitExpression(out, expr)) << gen.error();
EXPECT_EQ(out.str(), params.result);
}
TEST_P(HlslBinaryTest, Emit_i32) {
auto params = GetParam();
@ -98,8 +100,9 @@ TEST_P(HlslBinaryTest, Emit_i32) {
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.EmitExpression(pre, out, expr)) << gen.error();
EXPECT_EQ(result(), params.result);
std::stringstream out;
ASSERT_TRUE(gen.EmitExpression(out, expr)) << gen.error();
EXPECT_EQ(out.str(), params.result);
}
INSTANTIATE_TEST_SUITE_P(
HlslGeneratorImplTest,
@ -133,8 +136,9 @@ TEST_F(HlslGeneratorImplTest_Binary, Multiply_VectorScalar) {
GeneratorImpl& gen = Build();
EXPECT_TRUE(gen.EmitExpression(pre, out, expr)) << gen.error();
EXPECT_EQ(result(),
std::stringstream out;
EXPECT_TRUE(gen.EmitExpression(out, expr)) << gen.error();
EXPECT_EQ(out.str(),
"(float3(1.0f, 1.0f, 1.0f) * "
"1.0f)");
}
@ -150,8 +154,9 @@ TEST_F(HlslGeneratorImplTest_Binary, Multiply_ScalarVector) {
GeneratorImpl& gen = Build();
EXPECT_TRUE(gen.EmitExpression(pre, out, expr)) << gen.error();
EXPECT_EQ(result(),
std::stringstream out;
EXPECT_TRUE(gen.EmitExpression(out, expr)) << gen.error();
EXPECT_EQ(out.str(),
"(1.0f * float3(1.0f, 1.0f, "
"1.0f))");
}
@ -167,8 +172,9 @@ TEST_F(HlslGeneratorImplTest_Binary, Multiply_MatrixScalar) {
GeneratorImpl& gen = Build();
EXPECT_TRUE(gen.EmitExpression(pre, out, expr)) << gen.error();
EXPECT_EQ(result(), "(mat * 1.0f)");
std::stringstream out;
EXPECT_TRUE(gen.EmitExpression(out, expr)) << gen.error();
EXPECT_EQ(out.str(), "(mat * 1.0f)");
}
TEST_F(HlslGeneratorImplTest_Binary, Multiply_ScalarMatrix) {
@ -182,8 +188,9 @@ TEST_F(HlslGeneratorImplTest_Binary, Multiply_ScalarMatrix) {
GeneratorImpl& gen = Build();
EXPECT_TRUE(gen.EmitExpression(pre, out, expr)) << gen.error();
EXPECT_EQ(result(), "(1.0f * mat)");
std::stringstream out;
EXPECT_TRUE(gen.EmitExpression(out, expr)) << gen.error();
EXPECT_EQ(out.str(), "(1.0f * mat)");
}
TEST_F(HlslGeneratorImplTest_Binary, Multiply_MatrixVector) {
@ -197,8 +204,9 @@ TEST_F(HlslGeneratorImplTest_Binary, Multiply_MatrixVector) {
GeneratorImpl& gen = Build();
EXPECT_TRUE(gen.EmitExpression(pre, out, expr)) << gen.error();
EXPECT_EQ(result(), "mul(float3(1.0f, 1.0f, 1.0f), mat)");
std::stringstream out;
EXPECT_TRUE(gen.EmitExpression(out, expr)) << gen.error();
EXPECT_EQ(out.str(), "mul(float3(1.0f, 1.0f, 1.0f), mat)");
}
TEST_F(HlslGeneratorImplTest_Binary, Multiply_VectorMatrix) {
@ -212,8 +220,9 @@ TEST_F(HlslGeneratorImplTest_Binary, Multiply_VectorMatrix) {
GeneratorImpl& gen = Build();
EXPECT_TRUE(gen.EmitExpression(pre, out, expr)) << gen.error();
EXPECT_EQ(result(), "mul(mat, float3(1.0f, 1.0f, 1.0f))");
std::stringstream out;
EXPECT_TRUE(gen.EmitExpression(out, expr)) << gen.error();
EXPECT_EQ(out.str(), "mul(mat, float3(1.0f, 1.0f, 1.0f))");
}
TEST_F(HlslGeneratorImplTest_Binary, Multiply_MatrixMatrix) {
@ -226,8 +235,9 @@ TEST_F(HlslGeneratorImplTest_Binary, Multiply_MatrixMatrix) {
GeneratorImpl& gen = Build();
EXPECT_TRUE(gen.EmitExpression(pre, out, expr)) << gen.error();
EXPECT_EQ(result(), "mul(rhs, lhs)");
std::stringstream out;
EXPECT_TRUE(gen.EmitExpression(out, expr)) << gen.error();
EXPECT_EQ(out.str(), "mul(rhs, lhs)");
}
TEST_F(HlslGeneratorImplTest_Binary, Logical_And) {
@ -240,9 +250,10 @@ TEST_F(HlslGeneratorImplTest_Binary, Logical_And) {
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.EmitExpression(pre, out, expr)) << gen.error();
EXPECT_EQ(result(), "(tint_tmp)");
EXPECT_EQ(pre_result(), R"(bool tint_tmp = a;
std::stringstream out;
ASSERT_TRUE(gen.EmitExpression(out, expr)) << gen.error();
EXPECT_EQ(out.str(), "(tint_tmp)");
EXPECT_EQ(gen.result(), R"(bool tint_tmp = a;
if (tint_tmp) {
tint_tmp = b;
}
@ -266,19 +277,20 @@ TEST_F(HlslGeneratorImplTest_Binary, Logical_Multi) {
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.EmitExpression(pre, out, expr)) << gen.error();
EXPECT_EQ(result(), "(tint_tmp_1)");
EXPECT_EQ(pre_result(), R"(bool tint_tmp = a;
if (tint_tmp) {
tint_tmp = b;
std::stringstream out;
ASSERT_TRUE(gen.EmitExpression(out, expr)) << gen.error();
EXPECT_EQ(out.str(), "(tint_tmp)");
EXPECT_EQ(gen.result(), R"(bool tint_tmp_1 = a;
if (tint_tmp_1) {
tint_tmp_1 = b;
}
bool tint_tmp_1 = (tint_tmp);
if (!tint_tmp_1) {
bool tint_tmp = (tint_tmp_1);
if (!tint_tmp) {
bool tint_tmp_2 = c;
if (!tint_tmp_2) {
tint_tmp_2 = d;
}
tint_tmp_1 = (tint_tmp_2);
tint_tmp = (tint_tmp_2);
}
)");
}
@ -293,9 +305,10 @@ TEST_F(HlslGeneratorImplTest_Binary, Logical_Or) {
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.EmitExpression(pre, out, expr)) << gen.error();
EXPECT_EQ(result(), "(tint_tmp)");
EXPECT_EQ(pre_result(), R"(bool tint_tmp = a;
std::stringstream out;
ASSERT_TRUE(gen.EmitExpression(out, expr)) << gen.error();
EXPECT_EQ(out.str(), "(tint_tmp)");
EXPECT_EQ(gen.result(), R"(bool tint_tmp = a;
if (!tint_tmp) {
tint_tmp = b;
}
@ -338,8 +351,8 @@ TEST_F(HlslGeneratorImplTest_Binary, If_WithLogical) {
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.EmitStatement(out, expr)) << gen.error();
EXPECT_EQ(result(), R"(bool tint_tmp = a;
ASSERT_TRUE(gen.EmitStatement(expr)) << gen.error();
EXPECT_EQ(gen.result(), R"(bool tint_tmp = a;
if (tint_tmp) {
tint_tmp = b;
}
@ -375,16 +388,16 @@ TEST_F(HlslGeneratorImplTest_Binary, Return_WithLogical) {
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.EmitStatement(out, expr)) << gen.error();
EXPECT_EQ(result(), R"(bool tint_tmp = a;
if (tint_tmp) {
tint_tmp = b;
ASSERT_TRUE(gen.EmitStatement(expr)) << gen.error();
EXPECT_EQ(gen.result(), R"(bool tint_tmp_1 = a;
if (tint_tmp_1) {
tint_tmp_1 = b;
}
bool tint_tmp_1 = (tint_tmp);
if (!tint_tmp_1) {
tint_tmp_1 = c;
bool tint_tmp = (tint_tmp_1);
if (!tint_tmp) {
tint_tmp = c;
}
return (tint_tmp_1);
return (tint_tmp);
)");
}
@ -406,16 +419,16 @@ TEST_F(HlslGeneratorImplTest_Binary, Assign_WithLogical) {
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.EmitStatement(out, expr)) << gen.error();
EXPECT_EQ(result(), R"(bool tint_tmp = b;
if (!tint_tmp) {
tint_tmp = c;
ASSERT_TRUE(gen.EmitStatement(expr)) << gen.error();
EXPECT_EQ(gen.result(), R"(bool tint_tmp_1 = b;
if (!tint_tmp_1) {
tint_tmp_1 = c;
}
bool tint_tmp_1 = (tint_tmp);
if (tint_tmp_1) {
tint_tmp_1 = d;
bool tint_tmp = (tint_tmp_1);
if (tint_tmp) {
tint_tmp = d;
}
a = (tint_tmp_1);
a = (tint_tmp);
)");
}
@ -438,16 +451,16 @@ TEST_F(HlslGeneratorImplTest_Binary, Decl_WithLogical) {
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.EmitStatement(out, decl)) << gen.error();
EXPECT_EQ(result(), R"(bool tint_tmp = b;
if (tint_tmp) {
tint_tmp = c;
ASSERT_TRUE(gen.EmitStatement(decl)) << gen.error();
EXPECT_EQ(gen.result(), R"(bool tint_tmp_1 = b;
if (tint_tmp_1) {
tint_tmp_1 = c;
}
bool tint_tmp_1 = (tint_tmp);
if (!tint_tmp_1) {
tint_tmp_1 = d;
bool tint_tmp = (tint_tmp_1);
if (!tint_tmp) {
tint_tmp = d;
}
bool a = (tint_tmp_1);
bool a = (tint_tmp);
)");
}
@ -467,8 +480,9 @@ TEST_F(HlslGeneratorImplTest_Binary, Bitcast_WithLogical) {
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.EmitExpression(pre, out, expr)) << gen.error();
EXPECT_EQ(pre_result(), R"(bool tint_tmp = a;
std::stringstream out;
ASSERT_TRUE(gen.EmitExpression(out, expr)) << gen.error();
EXPECT_EQ(gen.result(), R"(bool tint_tmp = a;
if (tint_tmp) {
bool tint_tmp_1 = b;
if (!tint_tmp_1) {
@ -477,7 +491,7 @@ if (tint_tmp) {
tint_tmp = (tint_tmp_1);
}
)");
EXPECT_EQ(result(), R"(asint((tint_tmp)))");
EXPECT_EQ(out.str(), R"(asint((tint_tmp)))");
}
TEST_F(HlslGeneratorImplTest_Binary, Call_WithLogical) {
@ -512,8 +526,8 @@ TEST_F(HlslGeneratorImplTest_Binary, Call_WithLogical) {
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.EmitStatement(out, expr)) << gen.error();
EXPECT_EQ(result(), R"(bool tint_tmp = a;
ASSERT_TRUE(gen.EmitStatement(expr)) << gen.error();
EXPECT_EQ(gen.result(), R"(bool tint_tmp = a;
if (tint_tmp) {
tint_tmp = b;
}
@ -521,19 +535,19 @@ bool tint_tmp_1 = c;
if (!tint_tmp_1) {
tint_tmp_1 = d;
}
bool tint_tmp_2 = a;
if (!tint_tmp_2) {
tint_tmp_2 = c;
bool tint_tmp_3 = a;
if (!tint_tmp_3) {
tint_tmp_3 = c;
}
bool tint_tmp_3 = (tint_tmp_2);
if (tint_tmp_3) {
bool tint_tmp_2 = (tint_tmp_3);
if (tint_tmp_2) {
bool tint_tmp_4 = b;
if (!tint_tmp_4) {
tint_tmp_4 = d;
}
tint_tmp_3 = (tint_tmp_4);
tint_tmp_2 = (tint_tmp_4);
}
foo((tint_tmp), (tint_tmp_1), (tint_tmp_3));
foo((tint_tmp), (tint_tmp_1), (tint_tmp_2));
)");
}

View File

@ -27,8 +27,9 @@ TEST_F(HlslGeneratorImplTest_Bitcast, EmitExpression_Bitcast_Float) {
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.EmitExpression(pre, out, bitcast)) << gen.error();
EXPECT_EQ(result(), "asfloat(1)");
std::stringstream out;
ASSERT_TRUE(gen.EmitExpression(out, bitcast)) << gen.error();
EXPECT_EQ(out.str(), "asfloat(1)");
}
TEST_F(HlslGeneratorImplTest_Bitcast, EmitExpression_Bitcast_Int) {
@ -37,8 +38,9 @@ TEST_F(HlslGeneratorImplTest_Bitcast, EmitExpression_Bitcast_Int) {
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.EmitExpression(pre, out, bitcast)) << gen.error();
EXPECT_EQ(result(), "asint(1u)");
std::stringstream out;
ASSERT_TRUE(gen.EmitExpression(out, bitcast)) << gen.error();
EXPECT_EQ(out.str(), "asint(1u)");
}
TEST_F(HlslGeneratorImplTest_Bitcast, EmitExpression_Bitcast_Uint) {
@ -47,8 +49,9 @@ TEST_F(HlslGeneratorImplTest_Bitcast, EmitExpression_Bitcast_Uint) {
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.EmitExpression(pre, out, bitcast)) << gen.error();
EXPECT_EQ(result(), "asuint(1)");
std::stringstream out;
ASSERT_TRUE(gen.EmitExpression(out, bitcast)) << gen.error();
EXPECT_EQ(out.str(), "asuint(1)");
}
} // namespace

View File

@ -29,27 +29,13 @@ TEST_F(HlslGeneratorImplTest_Block, Emit_Block) {
gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(out, b)) << gen.error();
EXPECT_EQ(result(), R"( {
ASSERT_TRUE(gen.EmitStatement(b)) << gen.error();
EXPECT_EQ(gen.result(), R"( {
discard;
}
)");
}
TEST_F(HlslGeneratorImplTest_Block, Emit_Block_WithoutNewline) {
auto* b = Block(create<ast::DiscardStatement>());
WrapInFunction(b);
GeneratorImpl& gen = Build();
gen.increment_indent();
ASSERT_TRUE(gen.EmitBlock(out, b)) << gen.error();
EXPECT_EQ(result(), R"({
discard;
})");
}
} // namespace
} // namespace hlsl
} // namespace writer

View File

@ -29,8 +29,8 @@ TEST_F(HlslGeneratorImplTest_Break, Emit_Break) {
gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(out, b)) << gen.error();
EXPECT_EQ(result(), " break;\n");
ASSERT_TRUE(gen.EmitStatement(b)) << gen.error();
EXPECT_EQ(gen.result(), " break;\n");
}
} // namespace

View File

@ -31,8 +31,9 @@ TEST_F(HlslGeneratorImplTest_Call, EmitExpression_Call_WithoutParams) {
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.EmitExpression(pre, out, call)) << gen.error();
EXPECT_EQ(result(), "my_func()");
std::stringstream out;
ASSERT_TRUE(gen.EmitExpression(out, call)) << gen.error();
EXPECT_EQ(out.str(), "my_func()");
}
TEST_F(HlslGeneratorImplTest_Call, EmitExpression_Call_WithParams) {
@ -50,8 +51,9 @@ TEST_F(HlslGeneratorImplTest_Call, EmitExpression_Call_WithParams) {
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.EmitExpression(pre, out, call)) << gen.error();
EXPECT_EQ(result(), "my_func(param1, param2)");
std::stringstream out;
ASSERT_TRUE(gen.EmitExpression(out, call)) << gen.error();
EXPECT_EQ(out.str(), "my_func(param1, param2)");
}
TEST_F(HlslGeneratorImplTest_Call, EmitStatement_Call) {
@ -70,8 +72,8 @@ TEST_F(HlslGeneratorImplTest_Call, EmitStatement_Call) {
GeneratorImpl& gen = Build();
gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(out, call)) << gen.error();
EXPECT_EQ(result(), " my_func(param1, param2);\n");
ASSERT_TRUE(gen.EmitStatement(call)) << gen.error();
EXPECT_EQ(gen.result(), " my_func(param1, param2);\n");
}
} // namespace

View File

@ -33,8 +33,8 @@ TEST_F(HlslGeneratorImplTest_Case, Emit_Case) {
gen.increment_indent();
ASSERT_TRUE(gen.EmitCase(out, c)) << gen.error();
EXPECT_EQ(result(), R"( case 5: {
ASSERT_TRUE(gen.EmitCase(c)) << gen.error();
EXPECT_EQ(gen.result(), R"( case 5: {
break;
}
)");
@ -50,8 +50,8 @@ TEST_F(HlslGeneratorImplTest_Case, Emit_Case_BreaksByDefault) {
gen.increment_indent();
ASSERT_TRUE(gen.EmitCase(out, c)) << gen.error();
EXPECT_EQ(result(), R"( case 5: {
ASSERT_TRUE(gen.EmitCase(c)) << gen.error();
EXPECT_EQ(gen.result(), R"( case 5: {
break;
}
)");
@ -68,8 +68,8 @@ TEST_F(HlslGeneratorImplTest_Case, Emit_Case_WithFallthrough) {
gen.increment_indent();
ASSERT_TRUE(gen.EmitCase(out, c)) << gen.error();
EXPECT_EQ(result(), R"( case 5: {
ASSERT_TRUE(gen.EmitCase(c)) << gen.error();
EXPECT_EQ(gen.result(), R"( case 5: {
/* fallthrough */
}
)");
@ -87,8 +87,8 @@ TEST_F(HlslGeneratorImplTest_Case, Emit_Case_MultipleSelectors) {
gen.increment_indent();
ASSERT_TRUE(gen.EmitCase(out, c)) << gen.error();
EXPECT_EQ(result(), R"( case 5:
ASSERT_TRUE(gen.EmitCase(c)) << gen.error();
EXPECT_EQ(gen.result(), R"( case 5:
case 6: {
break;
}
@ -104,8 +104,8 @@ TEST_F(HlslGeneratorImplTest_Case, Emit_Case_Default) {
gen.increment_indent();
ASSERT_TRUE(gen.EmitCase(out, c)) << gen.error();
EXPECT_EQ(result(), R"( default: {
ASSERT_TRUE(gen.EmitCase(c)) << gen.error();
EXPECT_EQ(gen.result(), R"( default: {
break;
}
)");

View File

@ -27,8 +27,9 @@ TEST_F(HlslGeneratorImplTest_Cast, EmitExpression_Cast_Scalar) {
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.EmitExpression(pre, out, cast)) << gen.error();
EXPECT_EQ(result(), "float(1)");
std::stringstream out;
ASSERT_TRUE(gen.EmitExpression(out, cast)) << gen.error();
EXPECT_EQ(out.str(), "float(1)");
}
TEST_F(HlslGeneratorImplTest_Cast, EmitExpression_Cast_Vector) {
@ -37,8 +38,9 @@ TEST_F(HlslGeneratorImplTest_Cast, EmitExpression_Cast_Vector) {
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.EmitExpression(pre, out, cast)) << gen.error();
EXPECT_EQ(result(), "float3(int3(1, 2, 3))");
std::stringstream out;
ASSERT_TRUE(gen.EmitExpression(out, cast)) << gen.error();
EXPECT_EQ(out.str(), "float3(int3(1, 2, 3))");
}
} // namespace

View File

@ -29,8 +29,8 @@ TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Bool) {
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_THAT(result(), HasSubstr("false"));
ASSERT_TRUE(gen.Generate()) << gen.error();
EXPECT_THAT(gen.result(), HasSubstr("false"));
}
TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Int) {
@ -38,8 +38,8 @@ TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Int) {
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_THAT(result(), HasSubstr("-12345"));
ASSERT_TRUE(gen.Generate()) << gen.error();
EXPECT_THAT(gen.result(), HasSubstr("-12345"));
}
TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_UInt) {
@ -47,8 +47,8 @@ TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_UInt) {
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_THAT(result(), HasSubstr("56779u"));
ASSERT_TRUE(gen.Generate()) << gen.error();
EXPECT_THAT(gen.result(), HasSubstr("56779u"));
}
TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Float) {
@ -57,8 +57,8 @@ TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Float) {
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_THAT(result(), HasSubstr("1073741824.0f"));
ASSERT_TRUE(gen.Generate()) << gen.error();
EXPECT_THAT(gen.result(), HasSubstr("1073741824.0f"));
}
TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Float) {
@ -66,8 +66,8 @@ TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Float) {
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_THAT(result(), HasSubstr("float(-0.000012f)"));
ASSERT_TRUE(gen.Generate()) << gen.error();
EXPECT_THAT(gen.result(), HasSubstr("float(-0.000012f)"));
}
TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Bool) {
@ -75,8 +75,8 @@ TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Bool) {
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_THAT(result(), HasSubstr("bool(true)"));
ASSERT_TRUE(gen.Generate()) << gen.error();
EXPECT_THAT(gen.result(), HasSubstr("bool(true)"));
}
TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Int) {
@ -84,8 +84,8 @@ TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Int) {
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_THAT(result(), HasSubstr("int(-12345)"));
ASSERT_TRUE(gen.Generate()) << gen.error();
EXPECT_THAT(gen.result(), HasSubstr("int(-12345)"));
}
TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Uint) {
@ -93,8 +93,8 @@ TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Uint) {
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_THAT(result(), HasSubstr("uint(12345u)"));
ASSERT_TRUE(gen.Generate()) << gen.error();
EXPECT_THAT(gen.result(), HasSubstr("uint(12345u)"));
}
TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Vec) {
@ -102,8 +102,8 @@ TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Vec) {
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_THAT(result(), HasSubstr("float3(1.0f, 2.0f, 3.0f)"));
ASSERT_TRUE(gen.Generate()) << gen.error();
EXPECT_THAT(gen.result(), HasSubstr("float3(1.0f, 2.0f, 3.0f)"));
}
TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Vec_Empty) {
@ -111,8 +111,8 @@ TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Vec_Empty) {
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_THAT(result(), HasSubstr("float3(0.0f, 0.0f, 0.0f)"));
ASSERT_TRUE(gen.Generate()) << gen.error();
EXPECT_THAT(gen.result(), HasSubstr("float3(0.0f, 0.0f, 0.0f)"));
}
TEST_F(HlslGeneratorImplTest_Constructor,
@ -121,8 +121,8 @@ TEST_F(HlslGeneratorImplTest_Constructor,
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_THAT(result(), HasSubstr("float3((2.0f).xxx)"));
ASSERT_TRUE(gen.Generate()) << gen.error();
EXPECT_THAT(gen.result(), HasSubstr("float3((2.0f).xxx)"));
}
TEST_F(HlslGeneratorImplTest_Constructor,
@ -131,8 +131,8 @@ TEST_F(HlslGeneratorImplTest_Constructor,
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_THAT(result(), HasSubstr("bool3((true).xxx)"));
ASSERT_TRUE(gen.Generate()) << gen.error();
EXPECT_THAT(gen.result(), HasSubstr("bool3((true).xxx)"));
}
TEST_F(HlslGeneratorImplTest_Constructor,
@ -141,8 +141,8 @@ TEST_F(HlslGeneratorImplTest_Constructor,
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_THAT(result(), HasSubstr("int3((2).xxx)"));
ASSERT_TRUE(gen.Generate()) << gen.error();
EXPECT_THAT(gen.result(), HasSubstr("int3((2).xxx)"));
}
TEST_F(HlslGeneratorImplTest_Constructor,
@ -151,8 +151,8 @@ TEST_F(HlslGeneratorImplTest_Constructor,
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_THAT(result(), HasSubstr("uint3((2u).xxx)"));
ASSERT_TRUE(gen.Generate()) << gen.error();
EXPECT_THAT(gen.result(), HasSubstr("uint3((2u).xxx)"));
}
TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Mat) {
@ -161,10 +161,10 @@ TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Mat) {
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
ASSERT_TRUE(gen.Generate()) << gen.error();
EXPECT_THAT(
result(),
gen.result(),
HasSubstr(
"float2x3(float3(1.0f, 2.0f, 3.0f), float3(3.0f, 4.0f, 5.0f))"));
}
@ -174,9 +174,9 @@ TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Mat_Empty) {
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
ASSERT_TRUE(gen.Generate()) << gen.error();
EXPECT_THAT(result(),
EXPECT_THAT(gen.result(),
HasSubstr("float2x3(0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)"));
}
@ -187,8 +187,8 @@ TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Array) {
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_THAT(result(),
ASSERT_TRUE(gen.Generate()) << gen.error();
EXPECT_THAT(gen.result(),
HasSubstr("{float3(1.0f, 2.0f, 3.0f), float3(4.0f, 5.0f, 6.0f),"
" float3(7.0f, 8.0f, 9.0f)}"));
}
@ -200,8 +200,8 @@ TEST_F(HlslGeneratorImplTest_Constructor,
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_THAT(result(),
ASSERT_TRUE(gen.Generate()) << gen.error();
EXPECT_THAT(gen.result(),
HasSubstr("{float3(0.0f, 0.0f, 0.0f), float3(0.0f, 0.0f, 0.0f),"
" float3(0.0f, 0.0f, 0.0f)}"));
}
@ -217,8 +217,8 @@ TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Struct) {
GeneratorImpl& gen = SanitizeAndBuild();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_THAT(result(), HasSubstr("{1, 2.0f, int3(3, 4, 5)}"));
ASSERT_TRUE(gen.Generate()) << gen.error();
EXPECT_THAT(gen.result(), HasSubstr("{1, 2.0f, int3(3, 4, 5)}"));
}
TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Struct_Empty) {
@ -232,8 +232,8 @@ TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Struct_Empty) {
GeneratorImpl& gen = SanitizeAndBuild();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_THAT(result(), HasSubstr("{0, 0.0f, int3(0, 0, 0)}"));
ASSERT_TRUE(gen.Generate()) << gen.error();
EXPECT_THAT(gen.result(), HasSubstr("{0, 0.0f, int3(0, 0, 0)}"));
}
} // namespace

View File

@ -29,8 +29,8 @@ TEST_F(HlslGeneratorImplTest_Continue, Emit_Continue) {
gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(out, loop)) << gen.error();
EXPECT_EQ(result(), R"( while (true) {
ASSERT_TRUE(gen.EmitStatement(loop)) << gen.error();
EXPECT_EQ(gen.result(), R"( while (true) {
continue;
}
)");

View File

@ -29,8 +29,8 @@ TEST_F(HlslGeneratorImplTest_Discard, Emit_Discard) {
gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(out, stmt)) << gen.error();
EXPECT_EQ(result(), " discard;\n");
ASSERT_TRUE(gen.EmitStatement(stmt)) << gen.error();
EXPECT_EQ(gen.result(), " discard;\n");
}
} // namespace

View File

@ -38,8 +38,8 @@ TEST_F(HlslGeneratorImplTest_Function, Emit_Function) {
gen.increment_indent();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_EQ(result(), R"( void my_func() {
ASSERT_TRUE(gen.Generate()) << gen.error();
EXPECT_EQ(gen.result(), R"( void my_func() {
return;
}
)");
@ -55,8 +55,8 @@ TEST_F(HlslGeneratorImplTest_Function, Emit_Function_Name_Collision) {
gen.increment_indent();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_THAT(result(), HasSubstr(R"( void tint_symbol() {
ASSERT_TRUE(gen.Generate()) << gen.error();
EXPECT_THAT(gen.result(), HasSubstr(R"( void tint_symbol() {
return;
})"));
}
@ -72,8 +72,8 @@ TEST_F(HlslGeneratorImplTest_Function, Emit_Function_WithParams) {
gen.increment_indent();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_EQ(result(), R"( void my_func(float a, int b) {
ASSERT_TRUE(gen.Generate()) << gen.error();
EXPECT_EQ(gen.result(), R"( void my_func(float a, int b) {
return;
}
)");
@ -88,8 +88,8 @@ TEST_F(HlslGeneratorImplTest_Function,
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_EQ(result(), R"(void main() {
ASSERT_TRUE(gen.Generate()) << gen.error();
EXPECT_EQ(gen.result(), R"(void main() {
return;
}
)");
@ -104,8 +104,8 @@ TEST_F(HlslGeneratorImplTest_Function, PtrParameter) {
GeneratorImpl& gen = SanitizeAndBuild();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_THAT(result(), HasSubstr(R"(float f(inout float foo) {
ASSERT_TRUE(gen.Generate()) << gen.error();
EXPECT_THAT(gen.result(), HasSubstr(R"(float f(inout float foo) {
return foo;
}
)"));
@ -122,8 +122,8 @@ TEST_F(HlslGeneratorImplTest_Function,
GeneratorImpl& gen = SanitizeAndBuild();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_EQ(result(), R"(struct tint_symbol_1 {
ASSERT_TRUE(gen.Generate()) << gen.error();
EXPECT_EQ(gen.result(), R"(struct tint_symbol_1 {
float foo : TEXCOORD0;
};
struct tint_symbol_2 {
@ -152,8 +152,8 @@ TEST_F(HlslGeneratorImplTest_Function,
GeneratorImpl& gen = SanitizeAndBuild();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_EQ(result(), R"(struct tint_symbol_1 {
ASSERT_TRUE(gen.Generate()) << gen.error();
EXPECT_EQ(gen.result(), R"(struct tint_symbol_1 {
float4 coord : SV_Position;
};
struct tint_symbol_2 {
@ -206,8 +206,8 @@ TEST_F(HlslGeneratorImplTest_Function,
GeneratorImpl& gen = SanitizeAndBuild();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_EQ(result(), R"(struct Interface {
ASSERT_TRUE(gen.Generate()) << gen.error();
EXPECT_EQ(gen.result(), R"(struct Interface {
float4 pos;
float col1;
float col2;
@ -275,8 +275,8 @@ TEST_F(HlslGeneratorImplTest_Function,
GeneratorImpl& gen = SanitizeAndBuild();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_EQ(result(), R"(struct VertexOutput {
ASSERT_TRUE(gen.Generate()) << gen.error();
EXPECT_EQ(gen.result(), R"(struct VertexOutput {
float4 pos;
};
@ -340,8 +340,8 @@ TEST_F(HlslGeneratorImplTest_Function,
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_EQ(result(), R"(cbuffer cbuffer_ubo : register(b0, space1) {
ASSERT_TRUE(gen.Generate()) << gen.error();
EXPECT_EQ(gen.result(), R"(cbuffer cbuffer_ubo : register(b0, space1) {
uint4 ubo[1];
};
@ -381,8 +381,8 @@ TEST_F(HlslGeneratorImplTest_Function,
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_EQ(result(), R"(cbuffer cbuffer_uniforms : register(b0, space1) {
ASSERT_TRUE(gen.Generate()) << gen.error();
EXPECT_EQ(gen.result(), R"(cbuffer cbuffer_uniforms : register(b0, space1) {
uint4 uniforms[1];
};
@ -423,8 +423,8 @@ TEST_F(HlslGeneratorImplTest_Function,
GeneratorImpl& gen = SanitizeAndBuild();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_EQ(result(),
ASSERT_TRUE(gen.Generate()) << gen.error();
EXPECT_EQ(gen.result(),
R"(RWByteAddressBuffer coord : register(u0, space1);
void frag_main() {
@ -463,8 +463,8 @@ TEST_F(HlslGeneratorImplTest_Function,
GeneratorImpl& gen = SanitizeAndBuild();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_EQ(result(),
ASSERT_TRUE(gen.Generate()) << gen.error();
EXPECT_EQ(gen.result(),
R"(ByteAddressBuffer coord : register(t0, space1);
void frag_main() {
@ -500,8 +500,8 @@ TEST_F(HlslGeneratorImplTest_Function,
GeneratorImpl& gen = SanitizeAndBuild();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_EQ(result(),
ASSERT_TRUE(gen.Generate()) << gen.error();
EXPECT_EQ(gen.result(),
R"(RWByteAddressBuffer coord : register(u0, space1);
void frag_main() {
@ -538,8 +538,8 @@ TEST_F(HlslGeneratorImplTest_Function,
GeneratorImpl& gen = SanitizeAndBuild();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_EQ(result(),
ASSERT_TRUE(gen.Generate()) << gen.error();
EXPECT_EQ(gen.result(),
R"(RWByteAddressBuffer coord : register(u0, space1);
void frag_main() {
@ -578,8 +578,8 @@ TEST_F(HlslGeneratorImplTest_Function,
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_EQ(result(), R"(cbuffer cbuffer_coord : register(b0, space1) {
ASSERT_TRUE(gen.Generate()) << gen.error();
EXPECT_EQ(gen.result(), R"(cbuffer cbuffer_coord : register(b0, space1) {
uint4 coord[1];
};
@ -624,8 +624,8 @@ TEST_F(HlslGeneratorImplTest_Function,
GeneratorImpl& gen = SanitizeAndBuild();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_EQ(result(),
ASSERT_TRUE(gen.Generate()) << gen.error();
EXPECT_EQ(gen.result(),
R"(RWByteAddressBuffer coord : register(u0, space1);
float sub_func(float param) {
@ -648,8 +648,8 @@ TEST_F(HlslGeneratorImplTest_Function,
GeneratorImpl& gen = SanitizeAndBuild();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_EQ(result(), R"(void tint_symbol() {
ASSERT_TRUE(gen.Generate()) << gen.error();
EXPECT_EQ(gen.result(), R"(void tint_symbol() {
return;
}
)");
@ -666,8 +666,8 @@ TEST_F(HlslGeneratorImplTest_Function, Emit_Decoration_EntryPoint_Compute) {
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_EQ(result(), R"([numthreads(1, 1, 1)]
ASSERT_TRUE(gen.Generate()) << gen.error();
EXPECT_EQ(gen.result(), R"([numthreads(1, 1, 1)]
void main() {
return;
}
@ -684,8 +684,8 @@ TEST_F(HlslGeneratorImplTest_Function,
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_EQ(result(), R"([numthreads(2, 4, 6)]
ASSERT_TRUE(gen.Generate()) << gen.error();
EXPECT_EQ(gen.result(), R"([numthreads(2, 4, 6)]
void main() {
return;
}
@ -705,8 +705,8 @@ TEST_F(HlslGeneratorImplTest_Function,
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_EQ(result(), R"(static const int width = int(2);
ASSERT_TRUE(gen.Generate()) << gen.error();
EXPECT_EQ(gen.result(), R"(static const int width = int(2);
static const int height = int(3);
static const int depth = int(4);
@ -730,8 +730,8 @@ TEST_F(HlslGeneratorImplTest_Function,
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_EQ(result(), R"(#ifndef WGSL_SPEC_CONSTANT_7
ASSERT_TRUE(gen.Generate()) << gen.error();
EXPECT_EQ(gen.result(), R"(#ifndef WGSL_SPEC_CONSTANT_7
#define WGSL_SPEC_CONSTANT_7 int(2)
#endif
static const int width = WGSL_SPEC_CONSTANT_7;
@ -759,8 +759,8 @@ TEST_F(HlslGeneratorImplTest_Function, Emit_Function_WithArrayParams) {
GeneratorImpl& gen = SanitizeAndBuild();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_THAT(result(), HasSubstr(R"(
ASSERT_TRUE(gen.Generate()) << gen.error();
EXPECT_THAT(gen.result(), HasSubstr(R"(
struct tint_array_wrapper {
float arr[5];
};
@ -779,8 +779,8 @@ TEST_F(HlslGeneratorImplTest_Function, Emit_Function_WithArrayReturn) {
GeneratorImpl& gen = SanitizeAndBuild();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_THAT(result(), HasSubstr(R"(
ASSERT_TRUE(gen.Generate()) << gen.error();
EXPECT_THAT(gen.result(), HasSubstr(R"(
struct tint_array_wrapper {
float arr[5];
};
@ -851,8 +851,8 @@ TEST_F(HlslGeneratorImplTest_Function,
GeneratorImpl& gen = SanitizeAndBuild();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_EQ(result(), R"(RWByteAddressBuffer data : register(u0, space0);
ASSERT_TRUE(gen.Generate()) << gen.error();
EXPECT_EQ(gen.result(), R"(RWByteAddressBuffer data : register(u0, space0);
[numthreads(1, 1, 1)]
void a() {

View File

@ -29,8 +29,9 @@ TEST_F(HlslGeneratorImplTest_Identifier, EmitIdentifierExpression) {
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.EmitExpression(pre, out, i)) << gen.error();
EXPECT_EQ(result(), "foo");
std::stringstream out;
ASSERT_TRUE(gen.EmitExpression(out, i)) << gen.error();
EXPECT_EQ(out.str(), "foo");
}
} // namespace

View File

@ -32,8 +32,8 @@ TEST_F(HlslGeneratorImplTest_If, Emit_If) {
GeneratorImpl& gen = Build();
gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(out, i)) << gen.error();
EXPECT_EQ(result(), R"( if (cond) {
ASSERT_TRUE(gen.EmitStatement(i)) << gen.error();
EXPECT_EQ(gen.result(), R"( if (cond) {
return;
}
)");
@ -57,8 +57,8 @@ TEST_F(HlslGeneratorImplTest_If, Emit_IfWithElseIf) {
gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(out, i)) << gen.error();
EXPECT_EQ(result(), R"( if (cond) {
ASSERT_TRUE(gen.EmitStatement(i)) << gen.error();
EXPECT_EQ(gen.result(), R"( if (cond) {
return;
} else {
if (else_cond) {
@ -84,8 +84,8 @@ TEST_F(HlslGeneratorImplTest_If, Emit_IfWithElse) {
gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(out, i)) << gen.error();
EXPECT_EQ(result(), R"( if (cond) {
ASSERT_TRUE(gen.EmitStatement(i)) << gen.error();
EXPECT_EQ(gen.result(), R"( if (cond) {
return;
} else {
return;
@ -116,8 +116,8 @@ TEST_F(HlslGeneratorImplTest_If, Emit_IfWithMultiple) {
gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(out, i)) << gen.error();
EXPECT_EQ(result(), R"( if (cond) {
ASSERT_TRUE(gen.EmitStatement(i)) << gen.error();
EXPECT_EQ(gen.result(), R"( if (cond) {
return;
} else {
if (else_cond) {

View File

@ -40,8 +40,9 @@ TEST_P(HlslImportData_SingleParamTest, FloatScalar) {
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.EmitCall(pre, out, expr)) << gen.error();
EXPECT_EQ(result(), std::string(param.hlsl_name) + "(1.0f)");
std::stringstream out;
ASSERT_TRUE(gen.EmitCall(out, expr)) << gen.error();
EXPECT_EQ(out.str(), std::string(param.hlsl_name) + "(1.0f)");
}
INSTANTIATE_TEST_SUITE_P(HlslGeneratorImplTest_Import,
HlslImportData_SingleParamTest,
@ -78,8 +79,9 @@ TEST_P(HlslImportData_SingleIntParamTest, IntScalar) {
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.EmitCall(pre, out, expr)) << gen.error();
EXPECT_EQ(result(), std::string(param.hlsl_name) + "(1)");
std::stringstream out;
ASSERT_TRUE(gen.EmitCall(out, expr)) << gen.error();
EXPECT_EQ(out.str(), std::string(param.hlsl_name) + "(1)");
}
INSTANTIATE_TEST_SUITE_P(HlslGeneratorImplTest_Import,
HlslImportData_SingleIntParamTest,
@ -95,8 +97,9 @@ TEST_P(HlslImportData_SingleVectorParamTest, FloatVector) {
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.EmitCall(pre, out, expr)) << gen.error();
EXPECT_EQ(result(),
std::stringstream out;
ASSERT_TRUE(gen.EmitCall(out, expr)) << gen.error();
EXPECT_EQ(out.str(),
std::string(param.hlsl_name) + "(float3(1.0f, 2.0f, 3.0f))");
}
INSTANTIATE_TEST_SUITE_P(HlslGeneratorImplTest_Import,
@ -136,8 +139,9 @@ TEST_P(HlslImportData_DualParamTest, FloatScalar) {
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.EmitCall(pre, out, expr)) << gen.error();
EXPECT_EQ(result(), std::string(param.hlsl_name) + "(1.0f, 2.0f)");
std::stringstream out;
ASSERT_TRUE(gen.EmitCall(out, expr)) << gen.error();
EXPECT_EQ(out.str(), std::string(param.hlsl_name) + "(1.0f, 2.0f)");
}
INSTANTIATE_TEST_SUITE_P(HlslGeneratorImplTest_Import,
HlslImportData_DualParamTest,
@ -159,8 +163,9 @@ TEST_P(HlslImportData_DualParam_VectorTest, FloatVector) {
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.EmitCall(pre, out, expr)) << gen.error();
EXPECT_EQ(result(),
std::stringstream out;
ASSERT_TRUE(gen.EmitCall(out, expr)) << gen.error();
EXPECT_EQ(out.str(),
std::string(param.hlsl_name) +
"(float3(1.0f, 2.0f, 3.0f), float3(4.0f, 5.0f, 6.0f))");
}
@ -177,8 +182,9 @@ TEST_P(HlslImportData_DualParam_Int_Test, IntScalar) {
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.EmitCall(pre, out, expr)) << gen.error();
EXPECT_EQ(result(), std::string(param.hlsl_name) + "(1, 2)");
std::stringstream out;
ASSERT_TRUE(gen.EmitCall(out, expr)) << gen.error();
EXPECT_EQ(out.str(), std::string(param.hlsl_name) + "(1, 2)");
}
INSTANTIATE_TEST_SUITE_P(HlslGeneratorImplTest_Import,
HlslImportData_DualParam_Int_Test,
@ -194,8 +200,9 @@ TEST_P(HlslImportData_TripleParamTest, FloatScalar) {
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.EmitCall(pre, out, expr)) << gen.error();
EXPECT_EQ(result(), std::string(param.hlsl_name) + "(1.0f, 2.0f, 3.0f)");
std::stringstream out;
ASSERT_TRUE(gen.EmitCall(out, expr)) << gen.error();
EXPECT_EQ(out.str(), std::string(param.hlsl_name) + "(1.0f, 2.0f, 3.0f)");
}
INSTANTIATE_TEST_SUITE_P(
HlslGeneratorImplTest_Import,
@ -218,8 +225,9 @@ TEST_P(HlslImportData_TripleParam_Int_Test, IntScalar) {
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.EmitCall(pre, out, expr)) << gen.error();
EXPECT_EQ(result(), std::string(param.hlsl_name) + "(1, 2, 3)");
std::stringstream out;
ASSERT_TRUE(gen.EmitCall(out, expr)) << gen.error();
EXPECT_EQ(out.str(), std::string(param.hlsl_name) + "(1, 2, 3)");
}
INSTANTIATE_TEST_SUITE_P(HlslGeneratorImplTest_Import,
HlslImportData_TripleParam_Int_Test,
@ -233,8 +241,9 @@ TEST_F(HlslGeneratorImplTest_Import, HlslImportData_Determinant) {
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.EmitCall(pre, out, expr)) << gen.error();
EXPECT_EQ(result(), std::string("determinant(var)"));
std::stringstream out;
ASSERT_TRUE(gen.EmitCall(out, expr)) << gen.error();
EXPECT_EQ(out.str(), std::string("determinant(var)"));
}
} // namespace

View File

@ -268,8 +268,9 @@ TEST_F(HlslGeneratorImplTest_Intrinsic, Intrinsic_Call) {
GeneratorImpl& gen = Build();
gen.increment_indent();
ASSERT_TRUE(gen.EmitExpression(pre, out, call)) << gen.error();
EXPECT_EQ(result(), "dot(param1, param2)");
std::stringstream out;
ASSERT_TRUE(gen.EmitExpression(out, call)) << gen.error();
EXPECT_EQ(out.str(), "dot(param1, param2)");
}
TEST_F(HlslGeneratorImplTest_Intrinsic, Select_Scalar) {
@ -278,8 +279,9 @@ TEST_F(HlslGeneratorImplTest_Intrinsic, Select_Scalar) {
GeneratorImpl& gen = Build();
gen.increment_indent();
ASSERT_TRUE(gen.EmitExpression(pre, out, call)) << gen.error();
EXPECT_EQ(result(), "(true ? 1.0f : 2.0f)");
std::stringstream out;
ASSERT_TRUE(gen.EmitExpression(out, call)) << gen.error();
EXPECT_EQ(out.str(), "(true ? 1.0f : 2.0f)");
}
TEST_F(HlslGeneratorImplTest_Intrinsic, Select_Vector) {
@ -289,8 +291,9 @@ TEST_F(HlslGeneratorImplTest_Intrinsic, Select_Vector) {
GeneratorImpl& gen = Build();
gen.increment_indent();
ASSERT_TRUE(gen.EmitExpression(pre, out, call)) << gen.error();
EXPECT_EQ(result(), "(bool2(true, false) ? int2(1, 2) : int2(3, 4))");
std::stringstream out;
ASSERT_TRUE(gen.EmitExpression(out, call)) << gen.error();
EXPECT_EQ(out.str(), "(bool2(true, false) ? int2(1, 2) : int2(3, 4))");
}
TEST_F(HlslGeneratorImplTest_Intrinsic, Modf_Scalar) {
@ -300,8 +303,8 @@ TEST_F(HlslGeneratorImplTest_Intrinsic, Modf_Scalar) {
GeneratorImpl& gen = SanitizeAndBuild();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_THAT(result(), HasSubstr("modf(1.0f, res)"));
ASSERT_TRUE(gen.Generate()) << gen.error();
EXPECT_THAT(gen.result(), HasSubstr("modf(1.0f, res)"));
}
TEST_F(HlslGeneratorImplTest_Intrinsic, Modf_Vector) {
@ -311,8 +314,8 @@ TEST_F(HlslGeneratorImplTest_Intrinsic, Modf_Vector) {
GeneratorImpl& gen = SanitizeAndBuild();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_THAT(result(), HasSubstr("modf(float3(0.0f, 0.0f, 0.0f), res)"));
ASSERT_TRUE(gen.Generate()) << gen.error();
EXPECT_THAT(gen.result(), HasSubstr("modf(float3(0.0f, 0.0f, 0.0f), res)"));
}
TEST_F(HlslGeneratorImplTest_Intrinsic, Frexp_Scalar_i32) {
@ -322,8 +325,8 @@ TEST_F(HlslGeneratorImplTest_Intrinsic, Frexp_Scalar_i32) {
GeneratorImpl& gen = SanitizeAndBuild();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_THAT(result(), HasSubstr(R"(
ASSERT_TRUE(gen.Generate()) << gen.error();
EXPECT_THAT(gen.result(), HasSubstr(R"(
float tint_tmp;
float tint_tmp_1 = frexp(1.0f, tint_tmp);
exp = int(tint_tmp);
@ -338,8 +341,8 @@ TEST_F(HlslGeneratorImplTest_Intrinsic, Frexp_Vector_i32) {
GeneratorImpl& gen = SanitizeAndBuild();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_THAT(result(), HasSubstr(R"(
ASSERT_TRUE(gen.Generate()) << gen.error();
EXPECT_THAT(gen.result(), HasSubstr(R"(
float3 tint_tmp;
float3 tint_tmp_1 = frexp(float3(0.0f, 0.0f, 0.0f), tint_tmp);
res = int3(tint_tmp);
@ -354,8 +357,8 @@ TEST_F(HlslGeneratorImplTest_Intrinsic, IsNormal_Scalar) {
GeneratorImpl& gen = SanitizeAndBuild();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_THAT(result(), HasSubstr(R"(
ASSERT_TRUE(gen.Generate()) << gen.error();
EXPECT_THAT(gen.result(), HasSubstr(R"(
uint tint_isnormal_exponent = asuint(val) & 0x7f80000;
uint tint_isnormal_clamped = clamp(tint_isnormal_exponent, 0x0080000, 0x7f00000);
(tint_isnormal_clamped == tint_isnormal_exponent);
@ -369,8 +372,8 @@ TEST_F(HlslGeneratorImplTest_Intrinsic, IsNormal_Vector) {
GeneratorImpl& gen = SanitizeAndBuild();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_THAT(result(), HasSubstr(R"(
ASSERT_TRUE(gen.Generate()) << gen.error();
EXPECT_THAT(gen.result(), HasSubstr(R"(
uint3 tint_isnormal_exponent = asuint(val) & 0x7f80000;
uint3 tint_isnormal_clamped = clamp(tint_isnormal_exponent, 0x0080000, 0x7f00000);
(tint_isnormal_clamped == tint_isnormal_exponent);
@ -384,10 +387,11 @@ TEST_F(HlslGeneratorImplTest_Intrinsic, Pack4x8Snorm) {
GeneratorImpl& gen = Build();
gen.increment_indent();
ASSERT_TRUE(gen.EmitExpression(pre, out, call)) << gen.error();
EXPECT_THAT(pre_result(), HasSubstr("int4 tint_tmp = int4(round(clamp(p1, "
std::stringstream out;
ASSERT_TRUE(gen.EmitExpression(out, call)) << gen.error();
EXPECT_THAT(gen.result(), HasSubstr("int4 tint_tmp = int4(round(clamp(p1, "
"-1.0, 1.0) * 127.0)) & 0xff;"));
EXPECT_THAT(result(), HasSubstr("asuint(tint_tmp.x | tint_tmp.y << 8 | "
EXPECT_THAT(out.str(), HasSubstr("asuint(tint_tmp.x | tint_tmp.y << 8 | "
"tint_tmp.z << 16 | tint_tmp.w << 24)"));
}
@ -398,10 +402,11 @@ TEST_F(HlslGeneratorImplTest_Intrinsic, Pack4x8Unorm) {
GeneratorImpl& gen = Build();
gen.increment_indent();
ASSERT_TRUE(gen.EmitExpression(pre, out, call)) << gen.error();
EXPECT_THAT(pre_result(), HasSubstr("uint4 tint_tmp = uint4(round(clamp(p1, "
std::stringstream out;
ASSERT_TRUE(gen.EmitExpression(out, call)) << gen.error();
EXPECT_THAT(gen.result(), HasSubstr("uint4 tint_tmp = uint4(round(clamp(p1, "
"0.0, 1.0) * 255.0));"));
EXPECT_THAT(result(), HasSubstr("(tint_tmp.x | tint_tmp.y << 8 | "
EXPECT_THAT(out.str(), HasSubstr("(tint_tmp.x | tint_tmp.y << 8 | "
"tint_tmp.z << 16 | tint_tmp.w << 24)"));
}
@ -412,10 +417,11 @@ TEST_F(HlslGeneratorImplTest_Intrinsic, Pack2x16Snorm) {
GeneratorImpl& gen = Build();
gen.increment_indent();
ASSERT_TRUE(gen.EmitExpression(pre, out, call)) << gen.error();
EXPECT_THAT(pre_result(), HasSubstr("int2 tint_tmp = int2(round(clamp(p1, "
std::stringstream out;
ASSERT_TRUE(gen.EmitExpression(out, call)) << gen.error();
EXPECT_THAT(gen.result(), HasSubstr("int2 tint_tmp = int2(round(clamp(p1, "
"-1.0, 1.0) * 32767.0)) & 0xffff;"));
EXPECT_THAT(result(), HasSubstr("asuint(tint_tmp.x | tint_tmp.y << 16)"));
EXPECT_THAT(out.str(), HasSubstr("asuint(tint_tmp.x | tint_tmp.y << 16)"));
}
TEST_F(HlslGeneratorImplTest_Intrinsic, Pack2x16Unorm) {
@ -425,10 +431,11 @@ TEST_F(HlslGeneratorImplTest_Intrinsic, Pack2x16Unorm) {
GeneratorImpl& gen = Build();
gen.increment_indent();
ASSERT_TRUE(gen.EmitExpression(pre, out, call)) << gen.error();
EXPECT_THAT(pre_result(), HasSubstr("uint2 tint_tmp = uint2(round(clamp(p1, "
std::stringstream out;
ASSERT_TRUE(gen.EmitExpression(out, call)) << gen.error();
EXPECT_THAT(gen.result(), HasSubstr("uint2 tint_tmp = uint2(round(clamp(p1, "
"0.0, 1.0) * 65535.0));"));
EXPECT_THAT(result(), HasSubstr("(tint_tmp.x | tint_tmp.y << 16)"));
EXPECT_THAT(out.str(), HasSubstr("(tint_tmp.x | tint_tmp.y << 16)"));
}
TEST_F(HlslGeneratorImplTest_Intrinsic, Pack2x16Float) {
@ -438,9 +445,10 @@ TEST_F(HlslGeneratorImplTest_Intrinsic, Pack2x16Float) {
GeneratorImpl& gen = Build();
gen.increment_indent();
ASSERT_TRUE(gen.EmitExpression(pre, out, call)) << gen.error();
EXPECT_THAT(pre_result(), HasSubstr("uint2 tint_tmp = f32tof16(p1);"));
EXPECT_THAT(result(), HasSubstr("(tint_tmp.x | tint_tmp.y << 16)"));
std::stringstream out;
ASSERT_TRUE(gen.EmitExpression(out, call)) << gen.error();
EXPECT_THAT(gen.result(), HasSubstr("uint2 tint_tmp = f32tof16(p1);"));
EXPECT_THAT(out.str(), HasSubstr("(tint_tmp.x | tint_tmp.y << 16)"));
}
TEST_F(HlslGeneratorImplTest_Intrinsic, Unpack4x8Snorm) {
@ -450,12 +458,13 @@ TEST_F(HlslGeneratorImplTest_Intrinsic, Unpack4x8Snorm) {
GeneratorImpl& gen = Build();
gen.increment_indent();
ASSERT_TRUE(gen.EmitExpression(pre, out, call)) << gen.error();
EXPECT_THAT(pre_result(), HasSubstr("int tint_tmp_1 = int(p1);"));
EXPECT_THAT(pre_result(),
std::stringstream out;
ASSERT_TRUE(gen.EmitExpression(out, call)) << gen.error();
EXPECT_THAT(gen.result(), HasSubstr("int tint_tmp_1 = int(p1);"));
EXPECT_THAT(gen.result(),
HasSubstr("int4 tint_tmp = int4(tint_tmp_1 << 24, tint_tmp_1 "
"<< 16, tint_tmp_1 << 8, tint_tmp_1) >> 24;"));
EXPECT_THAT(result(),
EXPECT_THAT(out.str(),
HasSubstr("clamp(float4(tint_tmp) / 127.0, -1.0, 1.0)"));
}
@ -466,13 +475,14 @@ TEST_F(HlslGeneratorImplTest_Intrinsic, Unpack4x8Unorm) {
GeneratorImpl& gen = Build();
gen.increment_indent();
ASSERT_TRUE(gen.EmitExpression(pre, out, call)) << gen.error();
EXPECT_THAT(pre_result(), HasSubstr("uint tint_tmp_1 = p1;"));
std::stringstream out;
ASSERT_TRUE(gen.EmitExpression(out, call)) << gen.error();
EXPECT_THAT(gen.result(), HasSubstr("uint tint_tmp_1 = p1;"));
EXPECT_THAT(
pre_result(),
gen.result(),
HasSubstr("uint4 tint_tmp = uint4(tint_tmp_1 & 0xff, (tint_tmp_1 >> "
"8) & 0xff, (tint_tmp_1 >> 16) & 0xff, tint_tmp_1 >> 24);"));
EXPECT_THAT(result(), HasSubstr("float4(tint_tmp) / 255.0"));
EXPECT_THAT(out.str(), HasSubstr("float4(tint_tmp) / 255.0"));
}
TEST_F(HlslGeneratorImplTest_Intrinsic, Unpack2x16Snorm) {
@ -482,12 +492,13 @@ TEST_F(HlslGeneratorImplTest_Intrinsic, Unpack2x16Snorm) {
GeneratorImpl& gen = Build();
gen.increment_indent();
ASSERT_TRUE(gen.EmitExpression(pre, out, call)) << gen.error();
EXPECT_THAT(pre_result(), HasSubstr("int tint_tmp_1 = int(p1);"));
std::stringstream out;
ASSERT_TRUE(gen.EmitExpression(out, call)) << gen.error();
EXPECT_THAT(gen.result(), HasSubstr("int tint_tmp_1 = int(p1);"));
EXPECT_THAT(
pre_result(),
gen.result(),
HasSubstr("int2 tint_tmp = int2(tint_tmp_1 << 16, tint_tmp_1) >> 16;"));
EXPECT_THAT(result(),
EXPECT_THAT(out.str(),
HasSubstr("clamp(float2(tint_tmp) / 32767.0, -1.0, 1.0)"));
}
@ -498,12 +509,13 @@ TEST_F(HlslGeneratorImplTest_Intrinsic, Unpack2x16Unorm) {
GeneratorImpl& gen = Build();
gen.increment_indent();
ASSERT_TRUE(gen.EmitExpression(pre, out, call)) << gen.error();
EXPECT_THAT(pre_result(), HasSubstr("uint tint_tmp_1 = p1;"));
EXPECT_THAT(pre_result(),
std::stringstream out;
ASSERT_TRUE(gen.EmitExpression(out, call)) << gen.error();
EXPECT_THAT(gen.result(), HasSubstr("uint tint_tmp_1 = p1;"));
EXPECT_THAT(gen.result(),
HasSubstr("uint2 tint_tmp = uint2(tint_tmp_1 & 0xffff, "
"tint_tmp_1 >> 16);"));
EXPECT_THAT(result(), HasSubstr("float2(tint_tmp) / 65535.0"));
EXPECT_THAT(out.str(), HasSubstr("float2(tint_tmp) / 65535.0"));
}
TEST_F(HlslGeneratorImplTest_Intrinsic, Unpack2x16Float) {
@ -513,9 +525,10 @@ TEST_F(HlslGeneratorImplTest_Intrinsic, Unpack2x16Float) {
GeneratorImpl& gen = Build();
gen.increment_indent();
ASSERT_TRUE(gen.EmitExpression(pre, out, call)) << gen.error();
EXPECT_THAT(pre_result(), HasSubstr("uint tint_tmp = p1;"));
EXPECT_THAT(result(),
std::stringstream out;
ASSERT_TRUE(gen.EmitExpression(out, call)) << gen.error();
EXPECT_THAT(gen.result(), HasSubstr("uint tint_tmp = p1;"));
EXPECT_THAT(out.str(),
HasSubstr("f16tof32(uint2(tint_tmp & 0xffff, tint_tmp >> 16))"));
}
@ -526,8 +539,8 @@ TEST_F(HlslGeneratorImplTest_Intrinsic, StorageBarrier) {
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_EQ(result(), R"([numthreads(1, 1, 1)]
ASSERT_TRUE(gen.Generate()) << gen.error();
EXPECT_EQ(gen.result(), R"([numthreads(1, 1, 1)]
void main() {
DeviceMemoryBarrierWithGroupSync();
return;
@ -542,8 +555,8 @@ TEST_F(HlslGeneratorImplTest_Intrinsic, WorkgroupBarrier) {
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_EQ(result(), R"([numthreads(1, 1, 1)]
ASSERT_TRUE(gen.Generate()) << gen.error();
EXPECT_EQ(gen.result(), R"([numthreads(1, 1, 1)]
void main() {
GroupMemoryBarrierWithGroupSync();
return;
@ -561,8 +574,8 @@ TEST_F(HlslGeneratorImplTest_Intrinsic, Ignore) {
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_EQ(result(), R"(int f(int a, int b, int c) {
ASSERT_TRUE(gen.Generate()) << gen.error();
EXPECT_EQ(gen.result(), R"(int f(int a, int b, int c) {
return ((a + b) * c);
}

View File

@ -381,12 +381,12 @@ TEST_P(HlslGeneratorIntrinsicTextureTest, Call) {
GeneratorImpl& gen = SanitizeAndBuild();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
ASSERT_TRUE(gen.Generate()) << gen.error();
auto expected = expected_texture_overload(param.overload);
EXPECT_THAT(result(), HasSubstr(expected.pre));
EXPECT_THAT(result(), HasSubstr(expected.out));
EXPECT_THAT(gen.result(), HasSubstr(expected.pre));
EXPECT_THAT(gen.result(), HasSubstr(expected.out));
}
INSTANTIATE_TEST_SUITE_P(

View File

@ -33,8 +33,8 @@ TEST_F(HlslGeneratorImplTest_Loop, Emit_Loop) {
gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(out, l)) << gen.error();
EXPECT_EQ(result(), R"( while (true) {
ASSERT_TRUE(gen.EmitStatement(l)) << gen.error();
EXPECT_EQ(gen.result(), R"( while (true) {
discard;
}
)");
@ -51,8 +51,8 @@ TEST_F(HlslGeneratorImplTest_Loop, Emit_LoopWithContinuing) {
gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(out, l)) << gen.error();
EXPECT_EQ(result(), R"( while (true) {
ASSERT_TRUE(gen.EmitStatement(l)) << gen.error();
EXPECT_EQ(gen.result(), R"( while (true) {
discard;
{
return;
@ -83,8 +83,8 @@ TEST_F(HlslGeneratorImplTest_Loop, Emit_LoopNestedWithContinuing) {
gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(out, outer)) << gen.error();
EXPECT_EQ(result(), R"( while (true) {
ASSERT_TRUE(gen.EmitStatement(outer)) << gen.error();
EXPECT_EQ(gen.result(), R"( while (true) {
while (true) {
discard;
{
@ -137,8 +137,8 @@ TEST_F(HlslGeneratorImplTest_Loop, Emit_LoopWithVarUsedInContinuing) {
gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(out, outer)) << gen.error();
EXPECT_EQ(result(), R"( while (true) {
ASSERT_TRUE(gen.EmitStatement(outer)) << gen.error();
EXPECT_EQ(gen.result(), R"( while (true) {
float lhs = 2.400000095f;
float other = 0.0f;
{

View File

@ -131,8 +131,8 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor, EmitExpression_MemberAccessor) {
GeneratorImpl& gen = SanitizeAndBuild();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_EQ(result(), R"(struct Data {
ASSERT_TRUE(gen.Generate()) << gen.error();
EXPECT_EQ(gen.result(), R"(struct Data {
float mem;
};
@ -181,8 +181,8 @@ TEST_P(HlslGeneratorImplTest_MemberAccessor_StorageBufferLoad, Test) {
GeneratorImpl& gen = SanitizeAndBuild();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_THAT(result(), HasSubstr(p.expected));
ASSERT_TRUE(gen.Generate()) << gen.error();
EXPECT_THAT(gen.result(), HasSubstr(p.expected));
}
INSTANTIATE_TEST_SUITE_P(
@ -254,8 +254,8 @@ TEST_P(HlslGeneratorImplTest_MemberAccessor_StorageBufferStore, Test) {
GeneratorImpl& gen = SanitizeAndBuild();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_THAT(result(), HasSubstr(p.expected));
ASSERT_TRUE(gen.Generate()) << gen.error();
EXPECT_THAT(gen.result(), HasSubstr(p.expected));
}
INSTANTIATE_TEST_SUITE_P(
@ -339,7 +339,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor, StorageBuffer_Store_Matrix_Empty) {
GeneratorImpl& gen = SanitizeAndBuild();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
ASSERT_TRUE(gen.Generate()) << gen.error();
auto* expected =
R"(void tint_symbol_1(RWByteAddressBuffer buffer, uint offset, float2x3 value) {
buffer.Store3((offset + 0u), asuint(value[0u]));
@ -353,7 +353,7 @@ void main() {
return;
}
)";
EXPECT_EQ(result(), expected);
EXPECT_EQ(gen.result(), expected);
}
TEST_F(HlslGeneratorImplTest_MemberAccessor,
@ -378,7 +378,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
GeneratorImpl& gen = SanitizeAndBuild();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
ASSERT_TRUE(gen.Generate()) << gen.error();
auto* expected =
R"(RWByteAddressBuffer data : register(u0, space1);
@ -387,7 +387,7 @@ void main() {
return;
}
)";
EXPECT_EQ(result(), expected);
EXPECT_EQ(gen.result(), expected);
}
TEST_F(HlslGeneratorImplTest_MemberAccessor,
@ -410,7 +410,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
GeneratorImpl& gen = SanitizeAndBuild();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
ASSERT_TRUE(gen.Generate()) << gen.error();
auto* expected =
R"(RWByteAddressBuffer data : register(u0, space1);
@ -419,7 +419,7 @@ void main() {
return;
}
)";
EXPECT_EQ(result(), expected);
EXPECT_EQ(gen.result(), expected);
}
TEST_F(HlslGeneratorImplTest_MemberAccessor,
@ -443,7 +443,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
GeneratorImpl& gen = SanitizeAndBuild();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
ASSERT_TRUE(gen.Generate()) << gen.error();
auto* expected =
R"(RWByteAddressBuffer data : register(u0, space1);
@ -452,7 +452,7 @@ void main() {
return;
}
)";
EXPECT_EQ(result(), expected);
EXPECT_EQ(gen.result(), expected);
}
TEST_F(HlslGeneratorImplTest_MemberAccessor, StorageBuffer_Store_ToArray) {
@ -473,7 +473,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor, StorageBuffer_Store_ToArray) {
GeneratorImpl& gen = SanitizeAndBuild();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
ASSERT_TRUE(gen.Generate()) << gen.error();
auto* expected =
R"(RWByteAddressBuffer data : register(u0, space1);
@ -482,7 +482,7 @@ void main() {
return;
}
)";
EXPECT_EQ(result(), expected);
EXPECT_EQ(gen.result(), expected);
}
TEST_F(HlslGeneratorImplTest_MemberAccessor, StorageBuffer_Load_MultiLevel) {
@ -514,7 +514,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor, StorageBuffer_Load_MultiLevel) {
GeneratorImpl& gen = SanitizeAndBuild();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
ASSERT_TRUE(gen.Generate()) << gen.error();
auto* expected =
R"(RWByteAddressBuffer data : register(u0, space1);
@ -523,7 +523,7 @@ void main() {
return;
}
)";
EXPECT_EQ(result(), expected);
EXPECT_EQ(gen.result(), expected);
}
TEST_F(HlslGeneratorImplTest_MemberAccessor,
@ -558,7 +558,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
GeneratorImpl& gen = SanitizeAndBuild();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
ASSERT_TRUE(gen.Generate()) << gen.error();
auto* expected =
R"(RWByteAddressBuffer data : register(u0, space1);
@ -567,7 +567,7 @@ void main() {
return;
}
)";
EXPECT_EQ(result(), expected);
EXPECT_EQ(gen.result(), expected);
}
TEST_F(HlslGeneratorImplTest_MemberAccessor,
@ -602,7 +602,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
GeneratorImpl& gen = SanitizeAndBuild();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
ASSERT_TRUE(gen.Generate()) << gen.error();
auto* expected =
R"(RWByteAddressBuffer data : register(u0, space1);
@ -611,7 +611,7 @@ void main() {
return;
}
)";
EXPECT_EQ(result(), expected);
EXPECT_EQ(gen.result(), expected);
}
TEST_F(HlslGeneratorImplTest_MemberAccessor,
@ -646,7 +646,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
GeneratorImpl& gen = SanitizeAndBuild();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
ASSERT_TRUE(gen.Generate()) << gen.error();
auto* expected =
R"(RWByteAddressBuffer data : register(u0, space1);
@ -655,7 +655,7 @@ void main() {
return;
}
)";
EXPECT_EQ(result(), expected);
EXPECT_EQ(gen.result(), expected);
}
TEST_F(HlslGeneratorImplTest_MemberAccessor, StorageBuffer_Store_MultiLevel) {
@ -686,7 +686,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor, StorageBuffer_Store_MultiLevel) {
GeneratorImpl& gen = SanitizeAndBuild();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
ASSERT_TRUE(gen.Generate()) << gen.error();
auto* expected =
R"(RWByteAddressBuffer data : register(u0, space1);
@ -695,7 +695,7 @@ void main() {
return;
}
)";
EXPECT_EQ(result(), expected);
EXPECT_EQ(gen.result(), expected);
}
TEST_F(HlslGeneratorImplTest_MemberAccessor,
@ -730,7 +730,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
GeneratorImpl& gen = SanitizeAndBuild();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
ASSERT_TRUE(gen.Generate()) << gen.error();
auto* expected =
R"(RWByteAddressBuffer data : register(u0, space1);
@ -739,7 +739,7 @@ void main() {
return;
}
)";
EXPECT_EQ(result(), expected);
EXPECT_EQ(gen.result(), expected);
}
TEST_F(HlslGeneratorImplTest_MemberAccessor, Swizzle_xyz) {
@ -749,8 +749,8 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor, Swizzle_xyz) {
WrapInFunction(var, expr);
GeneratorImpl& gen = SanitizeAndBuild();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_THAT(result(), HasSubstr("my_vec.xyz"));
ASSERT_TRUE(gen.Generate()) << gen.error();
EXPECT_THAT(gen.result(), HasSubstr("my_vec.xyz"));
}
TEST_F(HlslGeneratorImplTest_MemberAccessor, Swizzle_gbr) {
@ -760,8 +760,8 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor, Swizzle_gbr) {
WrapInFunction(var, expr);
GeneratorImpl& gen = SanitizeAndBuild();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_THAT(result(), HasSubstr("my_vec.gbr"));
ASSERT_TRUE(gen.Generate()) << gen.error();
EXPECT_THAT(gen.result(), HasSubstr("my_vec.gbr"));
}
} // namespace

View File

@ -28,8 +28,8 @@ TEST_F(HlslGeneratorImplTest_ModuleConstant, Emit_ModuleConstant) {
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.EmitProgramConstVariable(out, var)) << gen.error();
EXPECT_EQ(result(), "static const float pos[3] = {1.0f, 2.0f, 3.0f};\n");
ASSERT_TRUE(gen.EmitProgramConstVariable(var)) << gen.error();
EXPECT_EQ(gen.result(), "static const float pos[3] = {1.0f, 2.0f, 3.0f};\n");
}
TEST_F(HlslGeneratorImplTest_ModuleConstant, Emit_SpecConstant) {
@ -40,8 +40,8 @@ TEST_F(HlslGeneratorImplTest_ModuleConstant, Emit_SpecConstant) {
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.EmitProgramConstVariable(out, var)) << gen.error();
EXPECT_EQ(result(), R"(#ifndef WGSL_SPEC_CONSTANT_23
ASSERT_TRUE(gen.EmitProgramConstVariable(var)) << gen.error();
EXPECT_EQ(gen.result(), R"(#ifndef WGSL_SPEC_CONSTANT_23
#define WGSL_SPEC_CONSTANT_23 3.0f
#endif
static const float pos = WGSL_SPEC_CONSTANT_23;
@ -56,8 +56,8 @@ TEST_F(HlslGeneratorImplTest_ModuleConstant, Emit_SpecConstant_NoConstructor) {
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.EmitProgramConstVariable(out, var)) << gen.error();
EXPECT_EQ(result(), R"(#ifndef WGSL_SPEC_CONSTANT_23
ASSERT_TRUE(gen.EmitProgramConstVariable(var)) << gen.error();
EXPECT_EQ(gen.result(), R"(#ifndef WGSL_SPEC_CONSTANT_23
#error spec constant required for constant id 23
#endif
static const float pos = WGSL_SPEC_CONSTANT_23;
@ -76,9 +76,9 @@ TEST_F(HlslGeneratorImplTest_ModuleConstant, Emit_SpecConstant_NoId) {
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.EmitProgramConstVariable(out, a)) << gen.error();
ASSERT_TRUE(gen.EmitProgramConstVariable(out, b)) << gen.error();
EXPECT_EQ(result(), R"(#ifndef WGSL_SPEC_CONSTANT_0
ASSERT_TRUE(gen.EmitProgramConstVariable(a)) << gen.error();
ASSERT_TRUE(gen.EmitProgramConstVariable(b)) << gen.error();
EXPECT_EQ(gen.result(), R"(#ifndef WGSL_SPEC_CONSTANT_0
#define WGSL_SPEC_CONSTANT_0 3.0f
#endif
static const float a = WGSL_SPEC_CONSTANT_0;

View File

@ -29,8 +29,8 @@ TEST_F(HlslGeneratorImplTest_Return, Emit_Return) {
gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(out, r)) << gen.error();
EXPECT_EQ(result(), " return;\n");
ASSERT_TRUE(gen.EmitStatement(r)) << gen.error();
EXPECT_EQ(gen.result(), " return;\n");
}
TEST_F(HlslGeneratorImplTest_Return, Emit_ReturnWithValue) {
@ -41,8 +41,8 @@ TEST_F(HlslGeneratorImplTest_Return, Emit_ReturnWithValue) {
gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(out, r)) << gen.error();
EXPECT_EQ(result(), " return 123;\n");
ASSERT_TRUE(gen.EmitStatement(r)) << gen.error();
EXPECT_EQ(gen.result(), " return 123;\n");
}
} // namespace

View File

@ -45,9 +45,9 @@ TEST_F(HlslSanitizerTest, Call_ArrayLength) {
GeneratorImpl& gen = SanitizeAndBuild();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
ASSERT_TRUE(gen.Generate()) << gen.error();
auto got = result();
auto got = gen.result();
auto* expect = R"(ByteAddressBuffer b : register(t1, space2);
void a_func() {
@ -85,9 +85,9 @@ TEST_F(HlslSanitizerTest, Call_ArrayLength_OtherMembersInStruct) {
GeneratorImpl& gen = SanitizeAndBuild();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
ASSERT_TRUE(gen.Generate()) << gen.error();
auto got = result();
auto got = gen.result();
auto* expect = R"(ByteAddressBuffer b : register(t1, space2);
void a_func() {
@ -127,9 +127,9 @@ TEST_F(HlslSanitizerTest, Call_ArrayLength_ViaLets) {
GeneratorImpl& gen = SanitizeAndBuild();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
ASSERT_TRUE(gen.Generate()) << gen.error();
auto got = result();
auto got = gen.result();
auto* expect = R"(ByteAddressBuffer b : register(t1, space2);
void a_func() {
@ -159,9 +159,9 @@ TEST_F(HlslSanitizerTest, PromoteArrayInitializerToConstVar) {
GeneratorImpl& gen = SanitizeAndBuild();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
ASSERT_TRUE(gen.Generate()) << gen.error();
auto got = result();
auto got = gen.result();
auto* expect = R"(struct tint_array_wrapper {
int arr[4];
};
@ -196,9 +196,9 @@ TEST_F(HlslSanitizerTest, PromoteStructInitializerToConstVar) {
GeneratorImpl& gen = SanitizeAndBuild();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
ASSERT_TRUE(gen.Generate()) << gen.error();
auto got = result();
auto got = gen.result();
auto* expect = R"(struct S {
int a;
float3 b;
@ -235,9 +235,9 @@ TEST_F(HlslSanitizerTest, InlinePtrLetsBasic) {
GeneratorImpl& gen = SanitizeAndBuild();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
ASSERT_TRUE(gen.Generate()) << gen.error();
auto got = result();
auto got = gen.result();
auto* expect = R"(void main() {
int v = 0;
int x = v;
@ -278,9 +278,9 @@ TEST_F(HlslSanitizerTest, InlinePtrLetsComplexChain) {
GeneratorImpl& gen = SanitizeAndBuild();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
ASSERT_TRUE(gen.Generate()) << gen.error();
auto got = result();
auto got = gen.result();
auto* expect = R"(void main() {
float4x4 m = float4x4(0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f);
float f = m[2][1];
@ -322,9 +322,9 @@ TEST_F(HlslSanitizerTest, InlineParam) {
GeneratorImpl& gen = SanitizeAndBuild();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
ASSERT_TRUE(gen.Generate()) << gen.error();
auto got = result();
auto got = gen.result();
auto* expect = R"(int x(inout int p) {
return p;
}

View File

@ -46,8 +46,8 @@ TEST_F(HlslGeneratorImplTest_Switch, Emit_Switch) {
gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(out, s)) << gen.error();
EXPECT_EQ(result(), R"( switch(cond) {
ASSERT_TRUE(gen.EmitStatement(s)) << gen.error();
EXPECT_EQ(gen.result(), R"( switch(cond) {
case 5: {
break;
}

View File

@ -24,7 +24,7 @@ using HlslGeneratorImplTest = TestHelper;
TEST_F(HlslGeneratorImplTest, ErrorIfSanitizerNotRun) {
auto program = std::make_unique<Program>(std::move(*this));
GeneratorImpl gen(program.get());
EXPECT_FALSE(gen.Generate(out));
EXPECT_FALSE(gen.Generate());
EXPECT_EQ(
gen.error(),
"error: HLSL writer requires the transform::Hlsl sanitizer to have been "
@ -37,8 +37,8 @@ TEST_F(HlslGeneratorImplTest, Generate) {
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_EQ(result(), R"(void my_func() {
ASSERT_TRUE(gen.Generate()) << gen.error();
EXPECT_EQ(gen.result(), R"(void my_func() {
}
)");
}

View File

@ -37,10 +37,11 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_Array) {
GeneratorImpl& gen = Build();
std::stringstream out;
ASSERT_TRUE(gen.EmitType(out, program->TypeOf(arr), ast::StorageClass::kNone,
ast::Access::kReadWrite, "ary"))
<< gen.error();
EXPECT_EQ(result(), "bool ary[4]");
EXPECT_EQ(out.str(), "bool ary[4]");
}
TEST_F(HlslGeneratorImplTest_Type, EmitType_ArrayOfArray) {
@ -49,10 +50,11 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_ArrayOfArray) {
GeneratorImpl& gen = Build();
std::stringstream out;
ASSERT_TRUE(gen.EmitType(out, program->TypeOf(arr), ast::StorageClass::kNone,
ast::Access::kReadWrite, "ary"))
<< gen.error();
EXPECT_EQ(result(), "bool ary[5][4]");
EXPECT_EQ(out.str(), "bool ary[5][4]");
}
// TODO(dsinclair): Is this possible? What order should it output in?
@ -63,10 +65,11 @@ TEST_F(HlslGeneratorImplTest_Type,
GeneratorImpl& gen = Build();
std::stringstream out;
ASSERT_TRUE(gen.EmitType(out, program->TypeOf(arr), ast::StorageClass::kNone,
ast::Access::kReadWrite, "ary"))
<< gen.error();
EXPECT_EQ(result(), "bool ary[5][4][1]");
EXPECT_EQ(out.str(), "bool ary[5][4][1]");
}
TEST_F(HlslGeneratorImplTest_Type, EmitType_ArrayOfArrayOfArray) {
@ -75,10 +78,11 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_ArrayOfArrayOfArray) {
GeneratorImpl& gen = Build();
std::stringstream out;
ASSERT_TRUE(gen.EmitType(out, program->TypeOf(arr), ast::StorageClass::kNone,
ast::Access::kReadWrite, "ary"))
<< gen.error();
EXPECT_EQ(result(), "bool ary[6][5][4]");
EXPECT_EQ(out.str(), "bool ary[6][5][4]");
}
TEST_F(HlslGeneratorImplTest_Type, EmitType_Array_WithoutName) {
@ -87,10 +91,11 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_Array_WithoutName) {
GeneratorImpl& gen = Build();
std::stringstream out;
ASSERT_TRUE(gen.EmitType(out, program->TypeOf(arr), ast::StorageClass::kNone,
ast::Access::kReadWrite, ""))
<< gen.error();
EXPECT_EQ(result(), "bool[4]");
EXPECT_EQ(out.str(), "bool[4]");
}
TEST_F(HlslGeneratorImplTest_Type, EmitType_Bool) {
@ -98,10 +103,11 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_Bool) {
GeneratorImpl& gen = Build();
std::stringstream out;
ASSERT_TRUE(gen.EmitType(out, bool_, ast::StorageClass::kNone,
ast::Access::kReadWrite, ""))
<< gen.error();
EXPECT_EQ(result(), "bool");
EXPECT_EQ(out.str(), "bool");
}
TEST_F(HlslGeneratorImplTest_Type, EmitType_F32) {
@ -109,10 +115,11 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_F32) {
GeneratorImpl& gen = Build();
std::stringstream out;
ASSERT_TRUE(gen.EmitType(out, f32, ast::StorageClass::kNone,
ast::Access::kReadWrite, ""))
<< gen.error();
EXPECT_EQ(result(), "float");
EXPECT_EQ(out.str(), "float");
}
TEST_F(HlslGeneratorImplTest_Type, EmitType_I32) {
@ -120,10 +127,11 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_I32) {
GeneratorImpl& gen = Build();
std::stringstream out;
ASSERT_TRUE(gen.EmitType(out, i32, ast::StorageClass::kNone,
ast::Access::kReadWrite, ""))
<< gen.error();
EXPECT_EQ(result(), "int");
EXPECT_EQ(out.str(), "int");
}
TEST_F(HlslGeneratorImplTest_Type, EmitType_Matrix) {
@ -133,10 +141,11 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_Matrix) {
GeneratorImpl& gen = Build();
std::stringstream out;
ASSERT_TRUE(gen.EmitType(out, mat2x3, ast::StorageClass::kNone,
ast::Access::kReadWrite, ""))
<< gen.error();
EXPECT_EQ(result(), "float2x3");
EXPECT_EQ(out.str(), "float2x3");
}
// TODO(dsinclair): How to annotate as workgroup?
@ -147,10 +156,11 @@ TEST_F(HlslGeneratorImplTest_Type, DISABLED_EmitType_Pointer) {
GeneratorImpl& gen = Build();
std::stringstream out;
ASSERT_TRUE(gen.EmitType(out, p, ast::StorageClass::kNone,
ast::Access::kReadWrite, ""))
<< gen.error();
EXPECT_EQ(result(), "float*");
EXPECT_EQ(out.str(), "float*");
}
TEST_F(HlslGeneratorImplTest_Type, EmitType_StructDecl) {
@ -163,8 +173,8 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_StructDecl) {
GeneratorImpl& gen = Build();
auto* sem_s = program->TypeOf(s)->As<sem::Struct>();
ASSERT_TRUE(gen.EmitStructType(out, sem_s)) << gen.error();
EXPECT_EQ(result(), R"(struct S {
ASSERT_TRUE(gen.EmitStructType(sem_s)) << gen.error();
EXPECT_EQ(gen.result(), R"(struct S {
int a;
float b;
};
@ -187,8 +197,8 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_StructDecl_OmittedIfStorageBuffer) {
GeneratorImpl& gen = Build();
auto* sem_s = program->TypeOf(s)->As<sem::Struct>();
ASSERT_TRUE(gen.EmitStructType(out, sem_s)) << gen.error();
EXPECT_EQ(result(), "");
ASSERT_TRUE(gen.EmitStructType(sem_s)) << gen.error();
EXPECT_EQ(gen.result(), "");
}
TEST_F(HlslGeneratorImplTest_Type, EmitType_Struct) {
@ -201,10 +211,11 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_Struct) {
GeneratorImpl& gen = Build();
auto* sem_s = program->TypeOf(s)->As<sem::Struct>();
std::stringstream out;
ASSERT_TRUE(gen.EmitType(out, sem_s, ast::StorageClass::kNone,
ast::Access::kReadWrite, ""))
<< gen.error();
EXPECT_EQ(result(), "S");
EXPECT_EQ(out.str(), "S");
}
TEST_F(HlslGeneratorImplTest_Type, EmitType_Struct_NameCollision) {
@ -216,8 +227,8 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_Struct_NameCollision) {
GeneratorImpl& gen = SanitizeAndBuild();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_THAT(result(), HasSubstr(R"(struct S {
ASSERT_TRUE(gen.Generate()) << gen.error();
EXPECT_THAT(gen.result(), HasSubstr(R"(struct S {
int tint_symbol;
float tint_symbol_1;
};
@ -229,10 +240,11 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_U32) {
GeneratorImpl& gen = Build();
std::stringstream out;
ASSERT_TRUE(gen.EmitType(out, u32, ast::StorageClass::kNone,
ast::Access::kReadWrite, ""))
<< gen.error();
EXPECT_EQ(result(), "uint");
EXPECT_EQ(out.str(), "uint");
}
TEST_F(HlslGeneratorImplTest_Type, EmitType_Vector) {
@ -241,10 +253,11 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_Vector) {
GeneratorImpl& gen = Build();
std::stringstream out;
ASSERT_TRUE(gen.EmitType(out, vec3, ast::StorageClass::kNone,
ast::Access::kReadWrite, ""))
<< gen.error();
EXPECT_EQ(result(), "float3");
EXPECT_EQ(out.str(), "float3");
}
TEST_F(HlslGeneratorImplTest_Type, EmitType_Void) {
@ -252,10 +265,11 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_Void) {
GeneratorImpl& gen = Build();
std::stringstream out;
ASSERT_TRUE(gen.EmitType(out, void_, ast::StorageClass::kNone,
ast::Access::kReadWrite, ""))
<< gen.error();
EXPECT_EQ(result(), "void");
EXPECT_EQ(out.str(), "void");
}
TEST_F(HlslGeneratorImplTest_Type, EmitSampler) {
@ -263,10 +277,11 @@ TEST_F(HlslGeneratorImplTest_Type, EmitSampler) {
GeneratorImpl& gen = Build();
std::stringstream out;
ASSERT_TRUE(gen.EmitType(out, sampler, ast::StorageClass::kNone,
ast::Access::kReadWrite, ""))
<< gen.error();
EXPECT_EQ(result(), "SamplerState");
EXPECT_EQ(out.str(), "SamplerState");
}
TEST_F(HlslGeneratorImplTest_Type, EmitSamplerComparison) {
@ -274,10 +289,11 @@ TEST_F(HlslGeneratorImplTest_Type, EmitSamplerComparison) {
GeneratorImpl& gen = Build();
std::stringstream out;
ASSERT_TRUE(gen.EmitType(out, sampler, ast::StorageClass::kNone,
ast::Access::kReadWrite, ""))
<< gen.error();
EXPECT_EQ(result(), "SamplerComparisonState");
EXPECT_EQ(out.str(), "SamplerComparisonState");
}
struct HlslDepthTextureData {
@ -305,8 +321,8 @@ TEST_P(HlslDepthTexturesTest, Emit) {
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_THAT(result(), HasSubstr(params.result));
ASSERT_TRUE(gen.Generate()) << gen.error();
EXPECT_THAT(gen.result(), HasSubstr(params.result));
}
INSTANTIATE_TEST_SUITE_P(
HlslGeneratorImplTest_Type,
@ -361,8 +377,8 @@ TEST_P(HlslSampledTexturesTest, Emit) {
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_THAT(result(), HasSubstr(params.result));
ASSERT_TRUE(gen.Generate()) << gen.error();
EXPECT_THAT(gen.result(), HasSubstr(params.result));
}
INSTANTIATE_TEST_SUITE_P(
HlslGeneratorImplTest_Type,
@ -465,10 +481,11 @@ TEST_F(HlslGeneratorImplTest_Type, EmitMultisampledTexture) {
GeneratorImpl& gen = Build();
std::stringstream out;
ASSERT_TRUE(gen.EmitType(out, s, ast::StorageClass::kNone,
ast::Access::kReadWrite, ""))
<< gen.error();
EXPECT_EQ(result(), "Texture2DMS<float4>");
EXPECT_EQ(out.str(), "Texture2DMS<float4>");
}
struct HlslStorageTextureData {
@ -501,8 +518,8 @@ TEST_P(HlslStorageTexturesTest, Emit) {
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_THAT(result(), HasSubstr(params.result));
ASSERT_TRUE(gen.Generate()) << gen.error();
EXPECT_THAT(gen.result(), HasSubstr(params.result));
}
INSTANTIATE_TEST_SUITE_P(
HlslGeneratorImplTest_Type,

View File

@ -29,8 +29,9 @@ TEST_F(HlslUnaryOpTest, AddressOf) {
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.EmitExpression(pre, out, op)) << gen.error();
EXPECT_EQ(result(), "expr");
std::stringstream out;
ASSERT_TRUE(gen.EmitExpression(out, op)) << gen.error();
EXPECT_EQ(out.str(), "expr");
}
TEST_F(HlslUnaryOpTest, Complement) {
@ -41,8 +42,9 @@ TEST_F(HlslUnaryOpTest, Complement) {
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.EmitExpression(pre, out, op)) << gen.error();
EXPECT_EQ(result(), "~(expr)");
std::stringstream out;
ASSERT_TRUE(gen.EmitExpression(out, op)) << gen.error();
EXPECT_EQ(out.str(), "~(expr)");
}
TEST_F(HlslUnaryOpTest, Indirection) {
@ -56,8 +58,9 @@ TEST_F(HlslUnaryOpTest, Indirection) {
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.EmitExpression(pre, out, op)) << gen.error();
EXPECT_EQ(result(), "expr");
std::stringstream out;
ASSERT_TRUE(gen.EmitExpression(out, op)) << gen.error();
EXPECT_EQ(out.str(), "expr");
}
TEST_F(HlslUnaryOpTest, Not) {
@ -67,8 +70,9 @@ TEST_F(HlslUnaryOpTest, Not) {
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.EmitExpression(pre, out, op)) << gen.error();
EXPECT_EQ(result(), "!(expr)");
std::stringstream out;
ASSERT_TRUE(gen.EmitExpression(out, op)) << gen.error();
EXPECT_EQ(out.str(), "!(expr)");
}
TEST_F(HlslUnaryOpTest, Negation) {
@ -79,8 +83,9 @@ TEST_F(HlslUnaryOpTest, Negation) {
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.EmitExpression(pre, out, op)) << gen.error();
EXPECT_EQ(result(), "-(expr)");
std::stringstream out;
ASSERT_TRUE(gen.EmitExpression(out, op)) << gen.error();
EXPECT_EQ(out.str(), "-(expr)");
}
} // namespace
} // namespace hlsl

View File

@ -34,8 +34,8 @@ TEST_F(HlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement) {
gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(out, stmt)) << gen.error();
EXPECT_EQ(result(), " float a = 0.0f;\n");
ASSERT_TRUE(gen.EmitStatement(stmt)) << gen.error();
EXPECT_EQ(gen.result(), " float a = 0.0f;\n");
}
TEST_F(HlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement_Const) {
@ -47,8 +47,8 @@ TEST_F(HlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement_Const) {
gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(out, stmt)) << gen.error();
EXPECT_EQ(result(), " const float a = 0.0f;\n");
ASSERT_TRUE(gen.EmitStatement(stmt)) << gen.error();
EXPECT_EQ(gen.result(), " const float a = 0.0f;\n");
}
TEST_F(HlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement_Array) {
@ -60,8 +60,8 @@ TEST_F(HlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement_Array) {
gen.increment_indent();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_THAT(result(),
ASSERT_TRUE(gen.Generate()) << gen.error();
EXPECT_THAT(gen.result(),
HasSubstr(" float a[5] = {0.0f, 0.0f, 0.0f, 0.0f, 0.0f};\n"));
}
@ -74,8 +74,8 @@ TEST_F(HlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement_Private) {
gen.increment_indent();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_THAT(result(), HasSubstr(" static float a = 0.0f;\n"));
ASSERT_TRUE(gen.Generate()) << gen.error();
EXPECT_THAT(gen.result(), HasSubstr(" static float a = 0.0f;\n"));
}
TEST_F(HlslGeneratorImplTest_VariableDecl,
@ -87,8 +87,8 @@ TEST_F(HlslGeneratorImplTest_VariableDecl,
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_THAT(result(), HasSubstr(R"(float a = initializer;
ASSERT_TRUE(gen.Generate()) << gen.error();
EXPECT_THAT(gen.result(), HasSubstr(R"(float a = initializer;
)"));
}
@ -101,8 +101,8 @@ TEST_F(HlslGeneratorImplTest_VariableDecl,
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.EmitStatement(out, stmt)) << gen.error();
EXPECT_EQ(result(), R"(float3 a = float3(0.0f, 0.0f, 0.0f);
ASSERT_TRUE(gen.EmitStatement(stmt)) << gen.error();
EXPECT_EQ(gen.result(), R"(float3 a = float3(0.0f, 0.0f, 0.0f);
)");
}
@ -116,8 +116,8 @@ TEST_F(HlslGeneratorImplTest_VariableDecl,
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.EmitStatement(out, stmt)) << gen.error();
EXPECT_EQ(result(),
ASSERT_TRUE(gen.EmitStatement(stmt)) << gen.error();
EXPECT_EQ(gen.result(),
R"(float2x3 a = float2x3(0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f);
)");
}

View File

@ -32,8 +32,8 @@ TEST_F(HlslGeneratorImplTest_WorkgroupVar, Basic) {
{Stage(ast::PipelineStage::kCompute)});
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_THAT(result(), HasSubstr("groupshared float wg;\n"));
ASSERT_TRUE(gen.Generate()) << gen.error();
EXPECT_THAT(gen.result(), HasSubstr("groupshared float wg;\n"));
}
TEST_F(HlslGeneratorImplTest_WorkgroupVar, Aliased) {
@ -45,8 +45,8 @@ TEST_F(HlslGeneratorImplTest_WorkgroupVar, Aliased) {
{Stage(ast::PipelineStage::kCompute)});
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_THAT(result(), HasSubstr("groupshared float wg;\n"));
ASSERT_TRUE(gen.Generate()) << gen.error();
EXPECT_THAT(gen.result(), HasSubstr("groupshared float wg;\n"));
}
} // namespace

View File

@ -96,16 +96,6 @@ class TestHelperBase : public BODY, public ProgramBuilder {
return *gen_;
}
/// @returns the result string
std::string result() const { return out.str(); }
/// @returns the pre result string
std::string pre_result() const { return pre.str(); }
/// The output stream
std::ostringstream out;
/// The pre-output stream
std::ostringstream pre;
/// The program built with a call to Build()
std::unique_ptr<Program> program;

View File

@ -31,5 +31,38 @@ void TextGenerator::make_indent(std::ostream& out) const {
}
}
TextGenerator::LineWriter::LineWriter(TextGenerator* generator)
: gen(generator) {}
TextGenerator::LineWriter::LineWriter(LineWriter&& other) {
gen = other.gen;
other.gen = nullptr;
}
TextGenerator::LineWriter::~LineWriter() {
if (gen) {
auto str = os.str();
if (!str.empty()) {
gen->make_indent();
gen->out_ << str << std::endl;
}
}
}
TextGenerator::ScopedParen::ScopedParen(std::ostream& stream) : s(stream) {
s << "(";
}
TextGenerator::ScopedParen::~ScopedParen() {
s << ")";
}
TextGenerator::ScopedIndent::ScopedIndent(TextGenerator* generator)
: gen(generator) {
gen->increment_indent();
}
TextGenerator::ScopedIndent::~ScopedIndent() {
gen->decrement_indent();
}
} // namespace writer
} // namespace tint

View File

@ -17,6 +17,7 @@
#include <sstream>
#include <string>
#include <utility>
#include "src/diagnostic/diagnostic.h"
@ -58,6 +59,72 @@ class TextGenerator {
std::string error() const { return diagnostics_.str(); }
protected:
/// LineWriter is a helper that acts as a string buffer, who's content is
/// emitted to the TextGenerator as a single line on destruction.
struct LineWriter {
public:
/// Constructor
/// @param generator the TextGenerator that the LineWriter will append its
/// content to on destruction
explicit LineWriter(TextGenerator* generator);
/// Move constructor
/// @param rhs the LineWriter to move
LineWriter(LineWriter&& rhs);
/// Destructor
~LineWriter();
/// @returns the ostringstream
operator std::ostream &() { return os; }
/// @param rhs the value to write to the line
/// @returns the ostream so calls can be chained
template <typename T>
std::ostream& operator<<(T&& rhs) {
return os << std::forward<T>(rhs);
}
private:
LineWriter(const LineWriter&) = delete;
LineWriter& operator=(const LineWriter&) = delete;
std::ostringstream os;
TextGenerator* gen;
};
/// Helper for writing a '(' on construction and a ')' destruction.
struct ScopedParen {
/// Constructor
/// @param stream the std::ostream that will be written to
explicit ScopedParen(std::ostream& stream);
/// Destructor
~ScopedParen();
private:
ScopedParen(ScopedParen&& rhs) = delete;
ScopedParen(const ScopedParen&) = delete;
ScopedParen& operator=(const ScopedParen&) = delete;
std::ostream& s;
};
/// Helper for incrementing indentation on construction and decrementing
/// indentation on destruction.
struct ScopedIndent {
/// Constructor
/// @param generator the TextGenerator that the ScopedIndent will indent
explicit ScopedIndent(TextGenerator* generator);
/// Destructor
~ScopedIndent();
private:
ScopedIndent(ScopedIndent&& rhs) = delete;
ScopedIndent(const ScopedIndent&) = delete;
ScopedIndent& operator=(const ScopedIndent&) = delete;
TextGenerator* gen;
};
/// @returns a new LineWriter, used for buffering and writing a line to out_
LineWriter line() { return LineWriter(this); }
/// The text output stream
std::ostringstream out_;
/// Diagnostics generated by the generator

View File

@ -26,29 +26,29 @@ void main(tint_symbol_2 tint_symbol_1) {
const float4 nonCoveredColor = float4(0.0f, 1.0f, 0.0f, 1.0f);
bool success = true;
const int scalar_offset = (16u) / 4;
bool tint_tmp_2 = (dstTexCoord.x < uniforms[scalar_offset / 4][scalar_offset % 4]);
if (!tint_tmp_2) {
const int scalar_offset_1 = (20u) / 4;
tint_tmp_2 = (dstTexCoord.y < uniforms[scalar_offset_1 / 4][scalar_offset_1 % 4]);
bool tint_tmp_4 = (dstTexCoord.x < uniforms[scalar_offset / 4][scalar_offset % 4]);
if (!tint_tmp_4) {
const int scalar_offset_1 = (20u) / 4;
tint_tmp_4 = (dstTexCoord.y < uniforms[scalar_offset_1 / 4][scalar_offset_1 % 4]);
}
bool tint_tmp_3 = (tint_tmp_2);
bool tint_tmp_3 = (tint_tmp_4);
if (!tint_tmp_3) {
const int scalar_offset_2 = (16u) / 4;
const int scalar_offset_2 = (16u) / 4;
const int scalar_offset_3 = (24u) / 4;
tint_tmp_3 = (dstTexCoord.x >= (uniforms[scalar_offset_2 / 4][scalar_offset_2 % 4] + uniforms[scalar_offset_3 / 4][scalar_offset_3 % 4]));
}
bool tint_tmp_4 = (tint_tmp_3);
if (!tint_tmp_4) {
const int scalar_offset_4 = (20u) / 4;
bool tint_tmp_2 = (tint_tmp_3);
if (!tint_tmp_2) {
const int scalar_offset_4 = (20u) / 4;
const int scalar_offset_5 = (28u) / 4;
tint_tmp_4 = (dstTexCoord.y >= (uniforms[scalar_offset_4 / 4][scalar_offset_4 % 4] + uniforms[scalar_offset_5 / 4][scalar_offset_5 % 4]));
tint_tmp_2 = (dstTexCoord.y >= (uniforms[scalar_offset_4 / 4][scalar_offset_4 % 4] + uniforms[scalar_offset_5 / 4][scalar_offset_5 % 4]));
}
if ((tint_tmp_4)) {
if ((tint_tmp_2)) {
bool tint_tmp_5 = success;
if (tint_tmp_5) {
tint_tmp_5 = all((tint_symbol.Load(int3(dstTexCoord, 0), 0) == nonCoveredColor));
}
success = (tint_tmp_5);
success = (tint_tmp_5);
} else {
const int scalar_offset_6 = (16u) / 4;
uint4 ubo_load = uniforms[scalar_offset_6 / 4];
@ -63,33 +63,33 @@ success = (tint_tmp_5);
const float4 dstColor = tint_symbol.Load(int3(dstTexCoord, 0), 0);
const int scalar_offset_9 = (4u) / 4;
if ((uniforms[scalar_offset_9 / 4][scalar_offset_9 % 4] == 2u)) {
bool tint_tmp_6 = success;
if (tint_tmp_6) {
tint_tmp_6 = aboutEqual(dstColor.r, srcColor.r);
}
bool tint_tmp_7 = (tint_tmp_6);
bool tint_tmp_7 = success;
if (tint_tmp_7) {
tint_tmp_7 = aboutEqual(dstColor.g, srcColor.g);
tint_tmp_7 = aboutEqual(dstColor.r, srcColor.r);
}
success = (tint_tmp_7);
bool tint_tmp_6 = (tint_tmp_7);
if (tint_tmp_6) {
tint_tmp_6 = aboutEqual(dstColor.g, srcColor.g);
}
success = (tint_tmp_6);
} else {
bool tint_tmp_8 = success;
if (tint_tmp_8) {
tint_tmp_8 = aboutEqual(dstColor.r, srcColor.r);
}
bool tint_tmp_9 = (tint_tmp_8);
if (tint_tmp_9) {
tint_tmp_9 = aboutEqual(dstColor.g, srcColor.g);
}
bool tint_tmp_10 = (tint_tmp_9);
if (tint_tmp_10) {
tint_tmp_10 = aboutEqual(dstColor.b, srcColor.b);
}
bool tint_tmp_11 = (tint_tmp_10);
bool tint_tmp_11 = success;
if (tint_tmp_11) {
tint_tmp_11 = aboutEqual(dstColor.a, srcColor.a);
tint_tmp_11 = aboutEqual(dstColor.r, srcColor.r);
}
success = (tint_tmp_11);
bool tint_tmp_10 = (tint_tmp_11);
if (tint_tmp_10) {
tint_tmp_10 = aboutEqual(dstColor.g, srcColor.g);
}
bool tint_tmp_9 = (tint_tmp_10);
if (tint_tmp_9) {
tint_tmp_9 = aboutEqual(dstColor.b, srcColor.b);
}
bool tint_tmp_8 = (tint_tmp_9);
if (tint_tmp_8) {
tint_tmp_8 = aboutEqual(dstColor.a, srcColor.a);
}
success = (tint_tmp_8);
}
}
const uint outputIndex = ((GlobalInvocationID.y * uint(dstSize.x)) + GlobalInvocationID.x);

View File

@ -9,10 +9,10 @@ float mm_readA(uint row, uint col) {
const int scalar_offset = (0u) / 4;
bool tint_tmp = (row < uniforms[scalar_offset / 4][scalar_offset % 4]);
if (tint_tmp) {
const int scalar_offset_1 = (4u) / 4;
const int scalar_offset_1 = (4u) / 4;
tint_tmp = (col < uniforms[scalar_offset_1 / 4][scalar_offset_1 % 4]);
}
if ((tint_tmp)) {
if ((tint_tmp)) {
const int scalar_offset_2 = (4u) / 4;
const float result = asfloat(firstMatrix.Load((4u * ((row * uniforms[scalar_offset_2 / 4][scalar_offset_2 % 4]) + col))));
return result;
@ -24,10 +24,10 @@ float mm_readB(uint row, uint col) {
const int scalar_offset_3 = (4u) / 4;
bool tint_tmp_1 = (row < uniforms[scalar_offset_3 / 4][scalar_offset_3 % 4]);
if (tint_tmp_1) {
const int scalar_offset_4 = (8u) / 4;
const int scalar_offset_4 = (8u) / 4;
tint_tmp_1 = (col < uniforms[scalar_offset_4 / 4][scalar_offset_4 % 4]);
}
if ((tint_tmp_1)) {
if ((tint_tmp_1)) {
const int scalar_offset_5 = (8u) / 4;
const float result = asfloat(secondMatrix.Load((4u * ((row * uniforms[scalar_offset_5 / 4][scalar_offset_5 % 4]) + col))));
return result;
@ -39,10 +39,10 @@ void mm_write(uint row, uint col, float value) {
const int scalar_offset_6 = (0u) / 4;
bool tint_tmp_2 = (row < uniforms[scalar_offset_6 / 4][scalar_offset_6 % 4]);
if (tint_tmp_2) {
const int scalar_offset_7 = (8u) / 4;
const int scalar_offset_7 = (8u) / 4;
tint_tmp_2 = (col < uniforms[scalar_offset_7 / 4][scalar_offset_7 % 4]);
}
if ((tint_tmp_2)) {
if ((tint_tmp_2)) {
const int scalar_offset_8 = (8u) / 4;
const uint index = (col + (row * uniforms[scalar_offset_8 / 4][scalar_offset_8 % 4]));
resultMatrix.Store((4u * index), asuint(value));

View File

@ -1,6 +1,6 @@
void pack2x16float_0e97b3() {
uint2 tint_tmp = f32tof16(float2(0.0f, 0.0f));
uint res = (tint_tmp.x | tint_tmp.y << 16);
uint res = (tint_tmp.x | tint_tmp.y << 16);
}
struct tint_symbol {

View File

@ -1,6 +1,6 @@
void pack2x16snorm_6c169b() {
int2 tint_tmp = int2(round(clamp(float2(0.0f, 0.0f), -1.0, 1.0) * 32767.0)) & 0xffff;
uint res = asuint(tint_tmp.x | tint_tmp.y << 16);
uint res = asuint(tint_tmp.x | tint_tmp.y << 16);
}
struct tint_symbol {

View File

@ -1,6 +1,6 @@
void pack2x16unorm_0f08e4() {
uint2 tint_tmp = uint2(round(clamp(float2(0.0f, 0.0f), 0.0, 1.0) * 65535.0));
uint res = (tint_tmp.x | tint_tmp.y << 16);
uint res = (tint_tmp.x | tint_tmp.y << 16);
}
struct tint_symbol {

View File

@ -1,6 +1,6 @@
void pack4x8snorm_4d22e7() {
int4 tint_tmp = int4(round(clamp(float4(0.0f, 0.0f, 0.0f, 0.0f), -1.0, 1.0) * 127.0)) & 0xff;
uint res = asuint(tint_tmp.x | tint_tmp.y << 8 | tint_tmp.z << 16 | tint_tmp.w << 24);
uint res = asuint(tint_tmp.x | tint_tmp.y << 8 | tint_tmp.z << 16 | tint_tmp.w << 24);
}
struct tint_symbol {

View File

@ -1,6 +1,6 @@
void pack4x8unorm_95c456() {
uint4 tint_tmp = uint4(round(clamp(float4(0.0f, 0.0f, 0.0f, 0.0f), 0.0, 1.0) * 255.0));
uint res = (tint_tmp.x | tint_tmp.y << 8 | tint_tmp.z << 16 | tint_tmp.w << 24);
uint res = (tint_tmp.x | tint_tmp.y << 8 | tint_tmp.z << 16 | tint_tmp.w << 24);
}
struct tint_symbol {

View File

@ -1,6 +1,6 @@
void unpack2x16float_32a5cf() {
uint tint_tmp = 1u;
float2 res = f16tof32(uint2(tint_tmp & 0xffff, tint_tmp >> 16));
float2 res = f16tof32(uint2(tint_tmp & 0xffff, tint_tmp >> 16));
}
struct tint_symbol {

View File

@ -1,7 +1,7 @@
void unpack2x16snorm_b4aea6() {
int tint_tmp_1 = int(1u);
int2 tint_tmp = int2(tint_tmp_1 << 16, tint_tmp_1) >> 16;
float2 res = clamp(float2(tint_tmp) / 32767.0, -1.0, 1.0);
int2 tint_tmp = int2(tint_tmp_1 << 16, tint_tmp_1) >> 16;
float2 res = clamp(float2(tint_tmp) / 32767.0, -1.0, 1.0);
}
struct tint_symbol {

View File

@ -1,7 +1,7 @@
void unpack2x16unorm_7699c0() {
uint tint_tmp_1 = 1u;
uint2 tint_tmp = uint2(tint_tmp_1 & 0xffff, tint_tmp_1 >> 16);
float2 res = float2(tint_tmp) / 65535.0;
uint2 tint_tmp = uint2(tint_tmp_1 & 0xffff, tint_tmp_1 >> 16);
float2 res = float2(tint_tmp) / 65535.0;
}
struct tint_symbol {

View File

@ -1,7 +1,7 @@
void unpack4x8snorm_523fb3() {
int tint_tmp_1 = int(1u);
int4 tint_tmp = int4(tint_tmp_1 << 24, tint_tmp_1 << 16, tint_tmp_1 << 8, tint_tmp_1) >> 24;
float4 res = clamp(float4(tint_tmp) / 127.0, -1.0, 1.0);
int4 tint_tmp = int4(tint_tmp_1 << 24, tint_tmp_1 << 16, tint_tmp_1 << 8, tint_tmp_1) >> 24;
float4 res = clamp(float4(tint_tmp) / 127.0, -1.0, 1.0);
}
struct tint_symbol {

View File

@ -1,7 +1,7 @@
void unpack4x8unorm_750c74() {
uint tint_tmp_1 = 1u;
uint4 tint_tmp = uint4(tint_tmp_1 & 0xff, (tint_tmp_1 >> 8) & 0xff, (tint_tmp_1 >> 16) & 0xff, tint_tmp_1 >> 24);
float4 res = float4(tint_tmp) / 255.0;
uint4 tint_tmp = uint4(tint_tmp_1 & 0xff, (tint_tmp_1 >> 8) & 0xff, (tint_tmp_1 >> 16) & 0xff, tint_tmp_1 >> 24);
float4 res = float4(tint_tmp) / 255.0;
}
struct tint_symbol {