How to properly write to a buffer every frame? #1438
-
Hello. I came from the
And it fails with the error:
It's confusing. Looks like I should use another flag. But since I'm creating a buffer for writing to it I'm expecting the usage to be
But it still fails:
What am I doing wrong? Also, I couldn't find any guidelines regarding per-frame buffer updates. In Basically I need to copy a big amount of data every frame and I'm searching for the fastest way. So it would be great if someone could provide best practices regarding this topic. |
Beta Was this translation helpful? Give feedback.
Replies: 0 comments 9 replies
-
Hi! I took the liberty of moving your issue into a discussion, because I feel that this isn't an actual issue reported.
WebGPU is quite close to Vulkan, but data transfers between CPU and GPU are indeed one of the main points of difference. The basic rules are:
So it may be difficult to wrap a Vulkan-trained head around these. One of the consequences of these rules is: staging buffers can't be used for anything other than staging. So if you have
You can do this just fine. There is
Similarly, have a look at the examples. They do per-frame updates. You don't need to rotate GPU buffers since WebGPU does the synchronization for you. Just call If you want to squeeze the last bit of upload perf, then the |
Beta Was this translation helpful? Give feedback.
-
Indeed, this is not an issue. The first i did thing before asking is tried to open Discussions, strange though I didn't see the tab. Thank you for moving the question.
I suppose that by "staging" you mean an intermediate buffer that's purpose is to deliver the data to the gpu and be forgotten. True, that in this case it should be
It would be great if you could give a technical explanation of how it's done. How a buffer gets updated? Is every buffer is created mapped on host? Then how do you handle the situation when the buffer is written while it's in use on the device? Or is there maybe a hidden staging buffer for every buffer?
Do you know any examples of how to use it? The documentation is pretty dry for this method. |
Beta Was this translation helpful? Give feedback.
-
Your assessment is correct.
Ok, sorry for confusing you! Initialization is special because we know the GPU isn't using the resource yet, so no-data-races property is guaranteed. Therefore, WebGPU makes it available for all buffers, regardless of their usage flags. |
Beta Was this translation helpful? Give feedback.
wgpu
allows you to have mapping with that native-only extension. WebGPU does not.Your assessment is correct.
Ok, sorry for confusing you!
mapped_at_creation
is not really a generic…