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

BufferVec: always allocate a GPU buffer #10457

Closed
wants to merge 1 commit into from

Conversation

SludgePhD
Copy link
Contributor

@SludgePhD SludgePhD commented Nov 8, 2023

Objective

When BufferVec::write_buffer is called without any data in the buffer, it does not allocate a GPU buffer, which then causes draw calls using that buffer to get skipped (usually). If the draw call does important work even with zero elements in the BufferVec, such as clearing the render target, this work is skipped as well, resulting in incorrect output.

Solution

It is unintuitive that BufferVec behaves like this, so this PR changes it to always allocate a GPU-side buffer when write_buffer or reserve is called, even when that buffer ends up with a size of 0.


Changelog

Fixed

Fixed BufferVec::write_buffer and BufferVec::reserve not allocating a GPU-side buffer when empty.

@alice-i-cecile alice-i-cecile added C-Bug An unexpected or incorrect behavior A-Rendering Drawing game state to the screen labels Nov 9, 2023
@JMS55
Copy link
Contributor

JMS55 commented Nov 23, 2023

What is your use case for an empty BufferVec? It looks like we currently only use it for skinning and morph target data, but that's going to go away soon anyways.

@SludgePhD
Copy link
Contributor Author

I use it for an instance-rate vertex buffer to store instance data in. Should I be using something else for that? I briefly looked at DynamicStorageBuffer but it seems to have the same bug.

@jgayfer
Copy link
Contributor

jgayfer commented Jul 17, 2024

Hard to test with merge conflicts, but I've run into this same issue. It was a big gotcha for me that using a GpuArrayBuffer (which is backed by a BufferVec) would end up with no binding in the event of an empty array.

@SludgePhD I will gladly test + review once conflicts are fixed!

@jgayfer jgayfer added the S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged label Jul 17, 2024
@SludgePhD SludgePhD force-pushed the buffervec-allocation branch from 3ac29db to c2f426a Compare July 17, 2024 13:00
@SludgePhD
Copy link
Contributor Author

Rebased it

@jgayfer jgayfer added S-Needs-Review Needs reviewer attention (from anyone!) to move forward and removed S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged labels Jul 17, 2024
@jgayfer jgayfer self-requested a review July 17, 2024 13:36
@jgayfer
Copy link
Contributor

jgayfer commented Jul 17, 2024

I'm noticed that since this PR was opened, we now have RawBufferVec and BufferVec. In my case I was having issues with BufferVec as its used by GpuArrayBuffer.

Would it make sense to apply this change set to both variants?

@SludgePhD
Copy link
Contributor Author

DynamicStorageBuffer has the same issue. If this is going to be fixed (I think it should), then it should probably be fixed for all of them. That said, I'm kinda out of spoons at the moment, so I'll close this PR. Feel free to take over!

@SludgePhD SludgePhD closed this Jul 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior S-Needs-Review Needs reviewer attention (from anyone!) to move forward
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants