[hlsl-writer] Emit zero matrix values.
This CL extends the zero emission to support matrices. Bug: tint:7 Change-Id: I7e39a68c83edb096fc4b365c66539e8a8b7cb1db Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/27443 Commit-Queue: dan sinclair <dsinclair@chromium.org> Reviewed-by: Sarah Mashayekhi <sarahmashay@google.com> Reviewed-by: David Neto <dneto@google.com>
This commit is contained in:
parent
04746d930d
commit
42b0e2d5af
|
@ -1430,6 +1430,16 @@ bool GeneratorImpl::EmitZeroValue(std::ostream& out, ast::type::Type* type) {
|
||||||
out << "0u";
|
out << "0u";
|
||||||
} else if (type->IsVector()) {
|
} else if (type->IsVector()) {
|
||||||
return EmitZeroValue(out, type->AsVector()->type());
|
return EmitZeroValue(out, type->AsVector()->type());
|
||||||
|
} else if (type->IsMatrix()) {
|
||||||
|
auto* mat = type->AsMatrix();
|
||||||
|
for (uint32_t i = 0; i < (mat->rows() * mat->columns()); i++) {
|
||||||
|
if (i != 0) {
|
||||||
|
out << ", ";
|
||||||
|
}
|
||||||
|
if (!EmitZeroValue(out, mat->type())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
error_ = "Invalid type for zero emission: " + type->type_name();
|
error_ = "Invalid type for zero emission: " + type->type_name();
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
#include "src/ast/module.h"
|
#include "src/ast/module.h"
|
||||||
#include "src/ast/type/array_type.h"
|
#include "src/ast/type/array_type.h"
|
||||||
#include "src/ast/type/f32_type.h"
|
#include "src/ast/type/f32_type.h"
|
||||||
|
#include "src/ast/type/matrix_type.h"
|
||||||
#include "src/ast/type/vector_type.h"
|
#include "src/ast/type/vector_type.h"
|
||||||
#include "src/ast/variable.h"
|
#include "src/ast/variable.h"
|
||||||
#include "src/ast/variable_decl_statement.h"
|
#include "src/ast/variable_decl_statement.h"
|
||||||
|
@ -130,6 +131,27 @@ TEST_F(HlslGeneratorImplTest_VariableDecl,
|
||||||
)");
|
)");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(HlslGeneratorImplTest_VariableDecl,
|
||||||
|
Emit_VariableDeclStatement_Initializer_ZeroMat) {
|
||||||
|
ast::type::F32Type f32;
|
||||||
|
ast::type::MatrixType mat(&f32, 3, 2);
|
||||||
|
|
||||||
|
ast::ExpressionList values;
|
||||||
|
auto zero_mat =
|
||||||
|
std::make_unique<ast::TypeConstructorExpression>(&mat, std::move(values));
|
||||||
|
|
||||||
|
auto var =
|
||||||
|
std::make_unique<ast::Variable>("a", ast::StorageClass::kNone, &mat);
|
||||||
|
var->set_constructor(std::move(zero_mat));
|
||||||
|
|
||||||
|
ast::VariableDeclStatement stmt(std::move(var));
|
||||||
|
ASSERT_TRUE(gen().EmitStatement(out(), &stmt)) << gen().error();
|
||||||
|
EXPECT_EQ(
|
||||||
|
result(),
|
||||||
|
R"(matrix<float, 3, 2> a = matrix<float, 3, 2>(0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f);
|
||||||
|
)");
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
} // namespace hlsl
|
} // namespace hlsl
|
||||||
} // namespace writer
|
} // namespace writer
|
||||||
|
|
Loading…
Reference in New Issue