GPU correctness fixes and optimizations

This commit is contained in:
Zachary Levy
2026-05-08 16:39:25 -07:00
parent c0fd79457c
commit 81ea3fd42c
3 changed files with 29 additions and 19 deletions
+7 -1
View File
@@ -684,7 +684,13 @@ upload_backdrop_primitives :: proc(device: ^sdl.GPUDevice, pass: ^sdl.GPUCopyPas
sdl.GPUBufferUsageFlags{.GRAPHICS_STORAGE_READ},
)
prim_array := sdl.MapGPUTransferBuffer(device, GLOB.backdrop.primitive_buffer.transfer, false)
// cycle=true: this is a persistent per-frame streaming transfer buffer. The previous
// frame's UploadToGPUBuffer is almost certainly still in flight when we map here
// (allowedFramesInFlight defaults to 2 on Metal). Without cycling, the CPU memcpy below
// races the GPU's blit read on the same MTLBuffer.contents. Cycling rebinds the
// container's active internal buffer to an unbound one (or allocates a new one) — O(1)
// in steady state, no fence wait. See SDL_gpu_metal.m's METAL_INTERNAL_PrepareBufferForWrite.
prim_array := sdl.MapGPUTransferBuffer(device, GLOB.backdrop.primitive_buffer.transfer, true)
if prim_array == nil {
log.panicf("Failed to map backdrop primitive transfer buffer: %s", sdl.GetError())
}