Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MSL: row/column major issue. #2295

Open
urbeller opened this issue Mar 14, 2024 · 3 comments
Open

MSL: row/column major issue. #2295

urbeller opened this issue Mar 14, 2024 · 3 comments
Labels
question Further progress depends on answer from issue creator.

Comments

@urbeller
Copy link

the following matrix in HLSL:

float4x3 normalMatrix;

Gets translated to MSL as:

float3x4 normalMatrix;

Although the matrix dimensions are correct, the data does not seem to be copied correctly. For instance, an identity matrix ends up in MSL as:

1 0 0 0
0 0 0 1
0 1 0 0

It looks like we are properly generating a float3x4 matrix but with column-major data layout.

@HansKristian-Work
Copy link
Contributor

float4x3 in HLSL is row-major while MSL layouts are column-major. This is all expected. HLSL compilers to SPIR-V will implicitly transpose and reverse multiplication orders to make this work.

For instance, an identity matrix ends up in MSL as:

Are you sure? How did you generate that identity matrix?

@HansKristian-Work HansKristian-Work added the question Further progress depends on answer from issue creator. label Mar 18, 2024
@urbeller
Copy link
Author

Hello. Thank you for your reply ! I am aware of the row/column layout difference between the languages. But in this case, I was wondering if there wasn't a bug because the matrix is not squared. In my case, the identity data came from an array like this {1,0,0,0, 0,1,0,0, 0,0,1,0}. would that be possible (and because we are going from 4x3 to a 3x4) that the data gets offsetted ?

@HansKristian-Work
Copy link
Contributor

It depends. If it's an inline array in the shader it's the shader compiler's job to deal with it. You'll have to provide the input HLSL, output SPIR-V and output MSL.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further progress depends on answer from issue creator.
Projects
None yet
Development

No branches or pull requests

2 participants