writer/hlsl: Fix emission of EmitStorageBufferAccessor()

Fix number of parentheses emitted for all control flows.

Add a TINT_UNIMPLEMENTED() for types that are not currently handled.

Change-Id: I987776e4d3b6d7c4d237f44db8b0eebb1a9a7fbd
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/46266
Commit-Queue: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: James Price <jrprice@google.com>
This commit is contained in:
Ben Clayton 2021-03-30 20:20:28 +00:00 committed by Commit Bot service account
parent 0f02a6de00
commit 3ac4a0e013
1 changed files with 23 additions and 19 deletions

View File

@ -95,6 +95,13 @@ std::ostream& operator<<(std::ostream& s, const RegisterAndSpace& rs) {
return s; return s;
} }
// Helper for writting a '(' on construction and a ')' destruction.
struct ScopedParen {
std::ostream& s_;
explicit ScopedParen(std::ostream& s) : s_(s) { s << "("; }
~ScopedParen() { s_ << ")"; }
};
} // namespace } // namespace
GeneratorImpl::GeneratorImpl(const Program* program) GeneratorImpl::GeneratorImpl(const Program* program)
@ -2185,6 +2192,10 @@ bool GeneratorImpl::EmitStorageBufferAccessor(std::ostream& pre,
out << "asint("; out << "asint(";
} else if (result_type->is_unsigned_scalar_or_vector()) { } else if (result_type->is_unsigned_scalar_or_vector()) {
out << "asuint("; out << "asuint(";
} else {
TINT_UNIMPLEMENTED(diagnostics_)
<< result_type->FriendlyName(builder_.Symbols());
return false;
} }
} }
@ -2229,8 +2240,8 @@ bool GeneratorImpl::EmitStorageBufferAccessor(std::ostream& pre,
return true; return true;
} }
out << "uint" << mat->rows() << "x" << mat->columns() << "("; out << "uint" << mat->rows() << "x" << mat->columns();
ScopedParen p(out);
for (uint32_t i = 0; i < mat->columns(); i++) { for (uint32_t i = 0; i < mat->columns(); i++) {
if (i != 0) { if (i != 0) {
out << ", "; out << ", ";
@ -2239,29 +2250,22 @@ bool GeneratorImpl::EmitStorageBufferAccessor(std::ostream& pre,
out << buffer_name << "." << access_method << "(" << idx << " + " out << buffer_name << "." << access_method << "(" << idx << " + "
<< (i * stride) << ")"; << (i * stride) << ")";
} }
} else {
// Close the matrix type and outer cast out << buffer_name << "." << access_method;
out << "))"; ScopedParen p(out);
out << idx;
return true;
}
out << buffer_name << "." << access_method << "(" << idx;
if (is_store) { if (is_store) {
out << ", asuint("; out << ", asuint";
ScopedParen p2(out);
if (!EmitExpression(pre, out, rhs)) { if (!EmitExpression(pre, out, rhs)) {
return false; return false;
} }
out << ")"; }
} }
out << ")";
// Close the outer cast.
if (!is_store) { if (!is_store) {
out << ")"; out << ")";
} }
return true; return true;
} }