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
add info about alignment #107
Conversation
The best place to put something like this would be in showcase. Adding it to the main tutorial requires changing any tutorials after it. I think this is all useful information, but I don't think it requires a full tutorial. One thing to note: shared, and packed aren't supported by |
agreed, I will push changes to make it easier for you to see differences and if you decide its ready I can squash them. The shaderc thing sounds interesting and it would also be good to investigate if wgpu actually supports these things. |
Hello, I found your tutorials very helpful, but I wasn't really satisfied with the fact that uniform structs were manually aligned by adding additional fields. After trying a lot of different things out, I was able to come up with this solution for making portable structs that can be passed to shaders easily. I defined some types to represent shader data types, and as long as:
Then everything should be aligned correctly. Here's an example: Datatypes to represent shader types in Rust (some of these repr annotations are redundant, but I included them for clarity):
Then we can define the struct which will be passed to the shader (order of fields does not matter if it's the same as the shader):
Then on the Shader:
Or, for an array of uniforms:
Please let me know what you think of this solution. |
If you want to amend this pull request with something like what you described, that would be OK with me @I-graham . I just need a working code example before I can merge anything. EDIT: Integration with |
@sotrh I put everything in one commit and from my point of view would be ok with merging as is for the time being and then making further adjustments as needed using other PRs. |
I want all the showcase examples to have a working example crate. It doesn't need to be complex, it just needs to compile and run. |
Hm I‘m not yet sure what a good example would be. I could use the basic compute example from the wgpu-rs repo and make the struct that’s being used a bit more complicated and insert the padding manually as an example. |
added an example which can be extended once crates with full support for deriving layouts exist |
thanks for your tutorial it helped me a lot
I would be happy to contribute this info. I don't have a strong opinion on where the best place would be or what else would need to be added so feel free to request changes or if you want also modify it yourself.
I would like to add a few code examples but I'm not sure how to best display the alignment/ memory regions in markdown.