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

Vertex buffer binding #12474

Open
LucasSaragosa opened this issue Mar 6, 2025 · 2 comments
Open

Vertex buffer binding #12474

LucasSaragosa opened this issue Mar 6, 2025 · 2 comments
Assignees
Milestone

Comments

@LucasSaragosa
Copy link

When you bind a vertex buffer in METAL, sometimes with multiple buffers the render encoder fails because of uninitialised memory.
Error happens at SDL_gpu_metal.mm. Where it binds, the line

NSUInteger bufferOffsets[MAX_VERTEX_BUFFERS];

needs to be changed to

NSUInteger bufferOffsets[MAX_VERTEX_BUFFERS] = {0};

Which works, due to metal complaining about uninitialised memory. This is when binding vertex buffers at vertex buffer slots > 0. Happened on slot 1.

@slouken slouken added this to the 3.2.10 milestone Mar 6, 2025
@TheSpydog
Copy link
Collaborator

Can you try this scenario with the latest SDL3 code, and if it persists, provide a code sample that repros the uninitialized memory error? Looking at the logic I'm not seeing a reason we need to zero-initialize the full array, and I'm concerned that that solution might be working around a more fundamental problem with how we're binding resources.

@LucasSaragosa
Copy link
Author

ah sorry didn’t realise it want up to date.

the error is because when i bind to slot 1 (not 0) looking at the memory before passing in buffer offsets [0] is garbage and [1] the value. metal seems to still complain.
the other thing, in bind vertex buffers, the logic about that part is also that firstBinding plus i is only needed for bufferOffsets and not on metalBuffer[..], that only needs to be [i] . i’m not sure why maybe metal API has something wrong with it. setVertexBuffers in its render encoder errors. when changed, it works with no errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants