Repository navigation
Create storage buffers that compute shaders can read or write - #669
Merged
Merged
Conversation
…s can read or write
…t empty data as under 4 bytes
stanoddly
force-pushed
the
storage-buffer-usage
branch
from
October 26, 2026 21:14
7ed7280 to
4158681
Compare
|
📦 Development package |
|
✅ Development package validation passed on all platforms. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #652.
A compute shader could not read or write a storage buffer created through Pixely.
CreateStorageBuffer<T>(ReadOnlySpan<T>)was the only way to create one, and it hardcodedSDL_GPU_BUFFERUSAGE_GRAPHICS_STORAGE_READ.API
StorageBufferUsageflags enum:GraphicsStorageRead,ComputeStorageReadandComputeStorageWrite, with SDL's flag values.GpuStorageBuffer.Usage.GpuMemorySystem.CreateStorageBuffer<T>(int length, StorageBufferUsage usage), also onICopyPass. It creates the buffer without an upload, so its contents are undefined until a compute shader writes it orUpdateStorageBufferfills it. It throws for an empty usage or one with unknown bits.CreateStorageBuffer<T>(ReadOnlySpan<T>)keeps the usageGraphicsStorageRead.Behavior
Both create methods throw
ArgumentOutOfRangeExceptionfor a buffer under 4 bytes, empty data included, or overint.MaxValuebytes.SizeInBytes, computed as anint, from overflowing.The GPU allocation is rounded up to a multiple of 4 bytes. D3D12 views a storage buffer as
size / 4raw 32-bit elements, so it would not reach the last 1 to 3 bytes of another size.SizeInByteskeeps the size asked for.Binding a storage buffer whose usage lacks what the binding needs throws
InvalidOperationException. The message names the binding, the slot, the buffer's usage and the needed usage.RenderPass.BindVertexStorageBuffersandBindFragmentStorageBuffersneedGraphicsStorageRead.ComputePass.BindReadOnlyStorageBuffersneedsComputeStorageRead.StorageBufferReadWriteBindingpassed toCommandBuffer.CreateComputePassneedsComputeStorageWrite.SDL does not check buffer usage on bind, not even in debug mode (
SDL_BeginGPUComputePasshas// TODO: validate buffer usage?).Breaking change
CreateStorageBuffer<T>(ReadOnlySpan<T>)now throwsArgumentOutOfRangeExceptionfor data under 4 bytes or overint.MaxValuebytes. Empty data threw a plainArgumentExceptionbefore; the new exception derives from it.No game in stanoddly/Games binds storage buffers to a compute pass.
Not included
ComputePass.DispatchIndirecttakes aGpuStorageBuffer, but SDL needsSDL_GPU_BUFFERUSAGE_INDIRECTfor it, which no Pixely buffer can have.Testing
Pixely.Tests: 617 passed, including newStorageBufferUsageTestsfor the size, length and usage checks, the rounding of the allocation, and the bind usage check.Pixely.Models.Tests: 225 passed.src/Pixelybuilds fornet11.0-browser.