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

Array Stride Mismatch in vec3-padded Struct #5262

Open
froody opened this issue Feb 18, 2024 · 10 comments
Open

Array Stride Mismatch in vec3-padded Struct #5262

froody opened this issue Feb 18, 2024 · 10 comments
Labels
api: metal Issues with Metal area: naga back-end Outputs of naga shader conversion lang: Metal Metal Shading Language naga Shader Translator

Comments

@froody
Copy link

froody commented Feb 18, 2024

Description
Running a compute shader with an input of an array of struct of 20 bytes will only see the first 20/32 entries.

Repro steps

  1. Clone https://github.com/froody/wgpu/tree/compute-bug
  2. cd examples
  3. cargo run hello_compute

Expected vs observed behavior
Observed:

result: 189
result with vertex 20: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0, 0, 0, 0, 0, 0, 0, 0]
result with vertex 32: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]

Expected:

result: 189
result with vertex 20: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
result with vertex 32: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]

Extra materials
Screenshots to help explain your problem.
Validation logs can be attached in case there are warnings and errors.
Zip-compressed API traces and GPU captures can also land here.

Platform
MacOS 14.3 (23D56), MacBookPro18,2

@cybersoulK

This comment was marked as outdated.

@froody

This comment was marked as outdated.

@cybersoulK

This comment was marked as outdated.

@cybersoulK

This comment was marked as outdated.

@cybersoulK

This comment was marked as outdated.

@froody

This comment was marked as outdated.

@froody
Copy link
Author

froody commented Feb 18, 2024

@cwfitzgerald cwfitzgerald changed the title Compute shader only sees first portion of buffer when element is a struct Array Stride Mismatch in vec3-padded Struct Feb 18, 2024
@cwfitzgerald cwfitzgerald added api: metal Issues with Metal area: naga back-end Outputs of naga shader conversion naga Shader Translator lang: Metal Metal Shading Language labels Feb 18, 2024
@cwfitzgerald
Copy link
Member

cwfitzgerald commented Feb 18, 2024

The issue here is as follows:

struct Inner { 
    vec: vec3<u32>,
    scalar1: u32,
    scalar2: u32
}

This struct is supposed to be size 32, alignment 16. However, when accessed through an array in metal, the stride shows itself to be 24. I suspect packed_uint3 doesn't have the alignment requirements?

struct Inner {
    metal::packed_uint3 vec;
    float scalar1;
    uint scalar2;
};

Unmark the test as failing on metal in #5264 to see the behavior.

@cwfitzgerald
Copy link
Member

Probably just need to insert an alignas(16) when we're using packed_uint3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: metal Issues with Metal area: naga back-end Outputs of naga shader conversion lang: Metal Metal Shading Language naga Shader Translator
Projects
None yet
Development

No branches or pull requests

3 participants