-
Notifications
You must be signed in to change notification settings - Fork 984
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
metal uniform buffer size issue #185
Comments
Looks like the Rust disagrees with SPIRV/MSL about the size of some struct? Can you provide the struct itself on both sides? |
Sorry I’m on phone but on both macos, Linux and iOS sizeof always reports 204; I’ll send you the actual struct tonight. But basically it was some arrays of floats for a world, view and proj, plus a camera pos iirc? |
Here is the uniform; note I also just ran this on macOS using a Xcode project and it exhibits the behavior, but not run i run a pure rust cli version, which is.. weird. |
I think we should make sure that at some point during SPIRV sanitization we round up the constant buffer sizes to 16 bytes, and have the Rust code taking that into account when allocating buffer sizes. @Kangz we might need to bring this up with the working group (re: padding the uniform buffers to 16 byte alignment at SPIRV level). |
Yeah we're going to have that problem in various places like vertex buffers too that will need to be rounded to 4 bytes etc. We could open a gpuweb issue and tag @dneto0. |
@m4b How did you get the size of the struct? |
|
for iOS This worked for me #[derive(Clone, Debug)]
struct Vertex {
pos: [f32; 4],
tex: [f32; 2],
}
#[derive(Clone, Debug)]
struct QuadInstance {
coord: [f32; 16],
} For the matrices, I ended up doing |
Your uniforms already 16 byte aligned though, no? |
How is your |
It’s repr c, but I don’t think it’s relevant. Seems pretty clear metal expects 16 byte alignment for uniforms and 204 sizeof isn’t 16 byte aligned. |
I barely know this stuff but looking at the metal docs, I don't know if it expects 16 byte alignment for uniforms, I suspect it expects the biggest alignment that fits the total size. So if your size is
That will give you the correct size with appropriate alignment. Can't we pass alignment and size to the buffer descriptor so it can sort it out internally? @kvark would something like this work?
|
Also is there a way to get stride and alignment out of a struct? So an appropriate way to count the buffer size would be something like UnsafeMutableRawPointer.allocate(
bytes: count * MemoryLayout<Uniform>.stride,
alignedTo: MemoryLayout<Uniform>.alignment) This could be added on the |
185: Update readme r=kvark a=grovesNL Add logo and update readme text a bit (link to WASM progress, reword examples section slightly, etc.) [Rendered](https://github.com/grovesNL/wgpu-rs/blob/ea4bf79ff71f2089beace873a629072ebe233608/README.md) Co-authored-by: Joshua Groves <[email protected]>
Whatever solution we do, it seems like getting gpuweb/gpuweb#678 first would benefit it. It will force us to consider the shader-reflected size. |
185: Update readme r=kvark a=grovesNL Add logo and update readme text a bit (link to WASM progress, reword examples section slightly, etc.) [Rendered](https://github.com/grovesNL/wgpu-rs/blob/ea4bf79ff71f2089beace873a629072ebe233608/README.md) Co-authored-by: Joshua Groves <[email protected]>
As we haven't seen any reports due to this, going to close it due to the new backends. |
so i'm seeing this issue on metal iOS:
when i print my uniform
std::mem::size_of
above, it's 204, but metal refuses to run with this assertion error, so something is adding 4 bytes to the uniform buffer argument? if i add 4 to the size here it proceeds without error (presumably because it has enough space for the 208 byte argument now):this doesn't seem to happen on macOS only iOS; i'm guessing something is attempting to add padding so its
mod sizeof(ptr)
?The text was updated successfully, but these errors were encountered: