reader/spirv: Partially handle MatrixStride on matrix arrays

SPIR-V spec states:
> Each structure-type member that is a matrix or array-of-matrices must have be decorated with a MatrixStride Decoration

As already pointed out in https://dawn-review.googlesource.com/c/tint/+/59840, we were not handling arrays-of-matrices.
To do this correctly, we need the ast::StrideDecoration to be placed on the Matrix type, which is a much bigger change to support.
For now, chase the type, and error if we have a custom MatrixStride on an array of matrices, otherwise drop the decoration.

Bug: tint:1049
Fixed: tint:1088
Change-Id: Idcb75b3df88040836a03a14e0ca402ebee7be9a7
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/60923
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: David Neto <dneto@google.com>
Commit-Queue: David Neto <dneto@google.com>
Auto-Submit: Ben Clayton <bclayton@google.com>
This commit is contained in:
Ben Clayton
2021-08-06 19:48:32 +00:00
committed by Tint LUCI CQ
parent b612c50593
commit 1a1c42ef12
7 changed files with 571 additions and 4 deletions

View File

@@ -487,11 +487,22 @@ ast::DecorationList ParserImpl::ConvertMemberDecoration(
return {};
}
uint32_t stride = decoration[1];
uint32_t natural_stride = 0;
if (auto* mat = member_ty->As<Matrix>()) {
natural_stride = (mat->rows == 2) ? 8 : 16;
auto* ty = member_ty->UnwrapAlias();
while (auto* arr = ty->As<Array>()) {
ty = arr->type->UnwrapAlias();
}
auto* mat = ty->As<Matrix>();
if (!mat) {
Fail() << "MatrixStride cannot be applied to type " << ty->String();
return {};
}
uint32_t natural_stride = (mat->rows == 2) ? 8 : 16;
if (stride == natural_stride) {
return {}; // Decoration matches the natural stride for the matrix
}
if (!member_ty->Is<Matrix>()) {
Fail() << "custom matrix strides not currently supported on array of "
"matrices";
return {};
}
return {

View File

@@ -80,7 +80,10 @@ class Type : public Castable<Type> {
/// @returns true if this type is an unsigned scalar or vector
bool IsUnsignedScalarOrVector() const;
#ifndef NDEBUG
#ifdef NDEBUG
/// @returns "<no-type-info>", for debug purposes only
std::string String() const { return "<no-type-info>"; }
#else
/// @returns a string representation of the type, for debug purposes only
virtual std::string String() const = 0;
#endif // NDEBUG