Allow mat2/3/4 as attribute types
Popov72 opened this issue · 4 comments
That would be nice (and would help our WebGPU support in Babylon.js) to allow having attributes of types mat2/3/4 in the vertex shader.
According to @kainino0x, Vulkan does allow it, for Metal/D3D12 it has to be looked for.
Note that we can do it in WebGL by "binding" 4 vec4 in sequence with enableVertexAttribArray/vertexAttribPointer.
Marking as Needs Action to get this investigated first.
I investigated this briefly. I'm not 100% sure, but I think neither D3D12 nor Metal has this feature. I couldn't find documentation on them.
Vulkan: https://www.khronos.org/registry/vulkan/specs/1.2/html/chap21.html#fxvertex-attrib-location
Metal examples like this one promote the idea of indexing into a constant buffer with the vertexID. So for this case, I think the WebGPU equivalent would be to use a readonly storage buffer of array<mat4x4<f32>>
and do the same thing.
SPIRV-Cross translates SPIR-V mat4 attributes into four float4 attributes when targeting both MSL and HLSL (and reconstructs them into a mat4 in the generated code).
So it appears that the following are true:
- only supported on 1/3 backend APIs
- users can do it themselves
- there is no performance cost for users to do it
Seems straightforward that we could just defer this until after MVP?
In my previous discussions on the topic within wgpu
community, I always advocated against passing matrices in attributes. Almost never people really need mat4x4
in the attribute. At most it's mat3x4
, or better - a position/scale/rotation combination, which can often be encoded into 2 vectors (e.g. dual-quaternions).
Got a confirmation from magcius that HLSL doesn't support this.