microsoft / microsoft/DirectXShaderCompiler

[RW]StructuredBuffer<matrix> ignores orientation

Open
#1,803 2 comments 0 reactions 1 assignee View on GitHub

@tristanlabelle is already working on this.

Since Dec 21, 2018.

bug matrix-bug
Dominant language
C++
Stars
3.7k
Forks
900
Avg merge
2d 11h
Merged PRs (30d)
44

Description

Repro:

typedef row_major int2x2 rmi22;
RWStructuredBuffer<rmi22> buf;
void main() { buf[0] = int2x2(11, 12, 21, 22); }

DXC generated code (packing orientation ignored):

call void @dx.op.bufferStore.i32(i32 69, %dx.types.Handle %buf_UAV_structbuf, i32 0, i32 0, i32 11, i32 21, i32 12, i32 22, i8 15)

FXC generated code (packing orientation taken into account):

store_structured u0.xyzw, l(0), l(0), l(11,12,21,22)

The problem is that RWStructuredBuffer<rmi22> causes a template specialization to be created, which calls Sema::CheckTemplateTypeArgument for rmi22 and uses getCanonicalType to get the final type. Hence the instantiated type is RWStructuredBuffer<matrix<int, 2, 2>>, whose operator[](int index) returns an unattributed matrix<int, 2, 2>&.

Note FXC has a bug here: it will not accept the syntax RWStructuredBuffer<row_major int2x2> and will not honor /Zpr nor #pragma pack_matrix(row_major) on RWStructuredBuffer<int2x2>, always defaulting to column_major. The only way to get it to store in row-major format is using the typedef method above.

This is similar to, but not the same as #1788 , where the matrix is a field of a struct used as a structured buffer.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.