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

Lower integer/bool matrix types to arrays of vectors on targets without native support. #4386

Open
natevm opened this issue Jun 13, 2024 · 4 comments
Labels
goal:forward looking Feature needed at a later date, not connected to a specific use case. kind:enhancement a desirable new feature, option, or behavior

Comments

@natevm
Copy link
Contributor

natevm commented Jun 13, 2024

Odd bug I just hit.

I had some HLSL code that was recently ported over, which had something like this:

float3x4 mat = buffer[0];
if (any(isnan(mat)) return; // skip this one
// logic operating on mat below...

With the "emit spirv directly" backend, Slang seems to generate invalid SPIRV, creating a %mat3v4bool = OpTypeMatrix %v4bool 3 type.

This results vkCreateShaderModule throwing an error:

VUID-VkShaderModuleCreateInfo-pCode-08737(ERROR / SPEC): msgNum: -1520283006 - Validation Error: [ VUID-VkShaderModuleCreateInfo-pCode-08737 ] | MessageID = 0xa5625282 | vkCreateShaderModule(): pCreateInfo->pCode is not valid SPIR-V: Matrix types can only be parameterized with floating-point types.
%mat3v4bool = OpTypeMatrix %v4bool 3
. The Vulkan spec states: If pCode is a pointer to SPIR-V code, pCode must adhere to the validation rules described by the Validation Rules within a Module section of the SPIR-V Environment appendix (https://vulkan.lunarg.com/doc/view/1.3.268.0/windows/1.3-extensions/vkspec.html#VUID-VkShaderModuleCreateInfo-pCode-08737)

To be honest, I'm not really sure how DXC handles this...

@natevm
Copy link
Contributor Author

natevm commented Jun 13, 2024

As a workaround, I can do if (any(isnan(mat[0])) || any(isnan(mat[1])) || any(isnan(mat[2]))) return; and then this doesn't seem to generate boolean typed matrices.

@csyonghe
Copy link
Collaborator

DXC simply errors out on this code:

fatal error: generated SPIR-V is invalid: Expected bool scalar or vector type as Result Type: IsNan
  %30 = OpIsNan %v4float %29

@csyonghe
Copy link
Collaborator

In the long term, Slang should support integer and bool matrices on targets that doesn't have native support. We should just lower them into arrays of vectors.

@csyonghe csyonghe changed the title SPV backend generates invalid matrix of type bool Support lowering integer/bool matrix types to arrays of vectors on targets without native support. Jun 13, 2024
@csyonghe csyonghe changed the title Support lowering integer/bool matrix types to arrays of vectors on targets without native support. Lower integer/bool matrix types to arrays of vectors on targets without native support. Jun 13, 2024
@csyonghe csyonghe added kind:enhancement a desirable new feature, option, or behavior goal:forward looking Feature needed at a later date, not connected to a specific use case. labels Jun 13, 2024
@ArielG-NV
Copy link
Contributor

ArielG-NV commented Jul 4, 2024

Note:
Related to: #4291
Addition would enable the following tests to work with the Metal backend:

  • tests/hlsl-intrinsic/matrix-float.slang
  • tests/hlsl-intrinsic/matrix-int.slang
  • tests\bugs\op-assignment-unify-mat.slang

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
goal:forward looking Feature needed at a later date, not connected to a specific use case. kind:enhancement a desirable new feature, option, or behavior
Projects
None yet
Development

No branches or pull requests

3 participants