-
Notifications
You must be signed in to change notification settings - Fork 61
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
Needs investigation: Matrix types as vertex attributes in shaders. #99
Comments
I realize the workaround is to replace |
(please ignore) mat3 is in fact not supported atm, only mat4, but looks like sokol-shdc currently doesn't throw an error (it should though). See here for the list of supported uniform types: https://github.com/floooh/sokol/blob/662272fca1d574aea1b2cd9e4f1171005d5834c0/sokol_gfx.h#L765-L801 I currently don't quite remember the reason why vec3 is allowed but mat3 is not, but it almost certainly had to do with alignment in arrays, and the GL backend's "uniform buffer flattening" (but I'll need to revisit that code, maybe it has been fixed with updating the Khronos dependencies). PS: or more likely it was because a typical mat3x3 on the CPU side is usually implemented as |
PS: please keep the ticket open, because I should at least add some sort of error message in sokol-shdc. |
I see, I didn't realize It probably should be an error because I was targeting Metal just fine and only had a problem with D3D11. |
Ooops, sorry lol. Looks like I need more morning coffee... Yeah, my bad. I actually never considered matrix types in vertices, let me think (and wake up) for a minute... |
Ok, so I never actually considered this case because the underlying 3D APIs don't support matrix types as vertex attributes (which explains why sokol-shdc doesn't know how to deal with it). Maybe shading languages usually do and expect that the vertex attributes are passed in as separate components though, I never thought about investingating this. I'll need to put aside some time for investigation. I would definitely recommend passing in matrices as separate vertex components though, and either do the matrix multiplication "manually" in the shader via dot products, or build a matrix from the attributes (performance-wise this shouldn't make a difference). |
No problem 👍 |
Using a
mat3
as a vertex attribute causes a panic when targeting D3D11.I repurposed the cube example in sokol-rust for a repro, check out this commit. (note: this will probably crash even if the current problem is fixed)
It looks like the validation is failing because
attrs[3]
andattrs[4]
have emptysem_name
s.I'm not sure if the problem is with sokol-shdc, sokol's validation, or a misunderstanding on my part. Fwiw, this works fine when targeting Metal.
The text was updated successfully, but these errors were encountered: