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

Don't rebind vertex buffers in Metal if only the offset index has changed #980

Merged
merged 2 commits into from
Jan 27, 2024

Conversation

staminajim
Copy link
Contributor

In Metal, if you're reusing a vertex buffer with a different offset, you can use setVertexBufferOffset instead of setVertexBuffer: https://developer.apple.com/library/archive/documentation/3DDrawing/Conceptual/MTLBestPracticesGuide/BufferBindings.html

If you don't you get loads of redundant buffer binding warnings when running in Xcode (and presumably this is also less efficient for sending data to the GPU)

Fixes #979

I'm using this change in my game engine and seems to be working perfectly fine

@floooh
Copy link
Owner

floooh commented Jan 26, 2024

The fix looks suspiciously simple ;)

TBH I'm not sure why I haven't done this in the first place when all the caching machinery is already there (I'm aware of the ability to only update the offset btw, I'm using that in the uniform data updates), I will have to dig a bit into the code and git history to make sure this doesn't revert any previous fixes.

But yes, I agree that it is at least a good thing to get rid of those Metal debugger warnings. I'll try to look into the PR during the weekend.

@floooh floooh self-assigned this Jan 26, 2024
@floooh
Copy link
Owner

floooh commented Jan 26, 2024

...it's crazy how brittle GH Actions is... (iOS build failed because it couldn't clone sokol)

@floooh
Copy link
Owner

floooh commented Jan 27, 2024

I'll give this PR a whirl now.

@floooh
Copy link
Owner

floooh commented Jan 27, 2024

Ah right, there is already a code path which skips the setVertexBuffer alltogether if both the buffer and offset match, just not the path for only updating the offset if the buffer matches but not the offset...

...your change has a duplicate SOKOL_ASSERT, but I'll fix that during the merge.

@floooh floooh merged commit 821724a into floooh:master Jan 27, 2024
23 checks passed
@floooh
Copy link
Owner

floooh commented Jan 27, 2024

Ok merged. Many thanks!

I also removed a couple of unused pointers from the Metal state cache while at it (see: 41e7b04), and updated the changelog.

@staminajim
Copy link
Contributor Author

Wonderful thanks, great job :)

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

Successfully merging this pull request may close these issues.

Redundant buffer bindings on metal when only changing vertex buffer offset
2 participants