Is it possible to use the same buffer as input for vertex shader and also as input for compute shader? (the computed results are computed into a different buffer.) If yes, is there any special synchronization needed?
There is notes on buffer usage flags that say “some combinations of flags are invalid”. Specifically it says that “a buffer cannot have both the VERTEX and INDEX flags” and “Unlike textures, READ | WRITE can be used for simultaneous read-write usage”.
Is it possible to know beforehand which combinations of usage flags are incompatible?Or is that something that depends on the platform and backend and one will only know at runtime? (By CreateGPUBuffer returning nullptr or something.)
(As for synchronization, there is an official tutorial ComputeSpriteBatch, where the render-pass is started right after the compute dispatch is called, using the computed data for rendering. As far as I understand these things use different pipelines so I find it strange that no synchronization is needed. Whatever, this should probably be a different question.)
I don’t understand why you have both SDL_GPU_BUFFERUSAGE_VERTEX
and SDL_GPU_BUFFERUSAGE_INDEX
buffer usage flags set, however I believe you would need SDL_GPU_BUFFERUSAGE_COMPUTE_STORAGE_READ
set in order to have the compute shader use the buffer and you can’t have both; you need to choose a single usage.
So I guess the answer is no, however you need to transfer the data to each of the GPU buffers using a transfer buffer, and I don’t see why you can’t keep that kicking around and use it to transfer data to both the vertex buffer and the compute storage read buffer on the GPU, which would be quick.
I don’t understand why you have both SDL_GPU_BUFFERUSAGE_VERTEX
and SDL_GPU_BUFFERUSAGE_INDEX
buffer usage flags set.
I don’t have such thing, I was quoting the documentation that it explicitly says that one can’t have those both.
you would need SDL_GPU_BUFFERUSAGE_COMPUTE_STORAGE_READ
set in order to have the compute shader use the buffer and you can’t have both; you need to choose a single usage.
Why are you sure this specific combination is not allowed? (COMPUTE_STORAGE_READ + VERTEX.) I could not find it in the docs.
So I guess the answer is no, however you need to transfer the data to each of the GPU buffers using a transfer buffer, and I don’t see why you can’t keep that kicking around and use it to transfer data to both the vertex buffer and the compute storage read buffer on the GPU, which would be quick.
Not sure I understand this. Though, if using one buffer is not an option, I can copy the data from one GPU-buffer into another, with “CopyGPUBufferToBuffer” so I don’t need the transfer-buffer to stay around.