diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-04 23:44:17 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-05 01:40:08 -0300 |
| commit | 0fe85c8dc4afad25aa6b616d9d04d79257b27bf3 (patch) | |
| tree | a79f07fd2e336e91e690b25952951501a471ae1d /src/gui | |
| parent | 1bb7817f631957996ed52f1f9f9249a3e8e8e451 (diff) | |
| download | pardes-0fe85c8dc4afad25aa6b616d9d04d79257b27bf3.tar.gz pardes-0fe85c8dc4afad25aa6b616d9d04d79257b27bf3.zip | |
gui: the capture and the soft present copy the frame down through one downloadTarget, each still submitting and timing its own wait
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src/gui')
| -rw-r--r-- | src/gui/gui.zig | 39 |
1 files changed, 16 insertions, 23 deletions
diff --git a/src/gui/gui.zig b/src/gui/gui.zig index 427d3fd0..ca7b3dd6 100644 --- a/src/gui/gui.zig +++ b/src/gui/gui.zig @@ -8806,13 +8806,10 @@ fn ensureSoftTexture(g: *Gui, width: u32, height: u32) !*c.SDL_Texture { return next; } -fn softPresentFrame(g: *Gui, cmd: *c.SDL_GPUCommandBuffer, target: *c.SDL_GPUTexture, sw: u32, sh: u32) !void { - const bpp = c.SDL_GPUTextureFormatTexelBlockSize(g.swapchain_format); - const size = c.SDL_CalculateGPUTextureFormatSize(g.swapchain_format, sw, sh, 1); - if (size == 0 or bpp != 4) { - _ = c.SDL_SubmitGPUCommandBuffer(cmd); - return error.UnsupportedCaptureFormat; - } +/// The frame in `target`, `size` bytes, copied down into `capture_xfer` +/// (grown to it first) by `cmd`, which the caller submits and waits for. +/// With no buffer to be had the command buffer is submitted as it is. +fn downloadTarget(g: *Gui, cmd: *c.SDL_GPUCommandBuffer, target: *c.SDL_GPUTexture, sw: u32, sh: u32, size: u32) !*c.SDL_GPUTransferBuffer { if (g.capture_xfer == null or g.capture_xfer_size < size) { var info = c.SDL_GPUTransferBufferCreateInfo{ .usage = c.SDL_GPU_TRANSFERBUFFERUSAGE_DOWNLOAD, .size = size, .props = 0 }; const next = c.SDL_CreateGPUTransferBuffer(g.device, &info) orelse { @@ -8829,6 +8826,17 @@ fn softPresentFrame(g: *Gui, cmd: *c.SDL_GPUCommandBuffer, target: *c.SDL_GPUTex const dst = c.SDL_GPUTextureTransferInfo{ .transfer_buffer = xfer, .offset = 0, .pixels_per_row = sw, .rows_per_layer = sh }; c.SDL_DownloadFromGPUTexture(copy, &src, &dst); c.SDL_EndGPUCopyPass(copy); + return xfer; +} + +fn softPresentFrame(g: *Gui, cmd: *c.SDL_GPUCommandBuffer, target: *c.SDL_GPUTexture, sw: u32, sh: u32) !void { + const bpp = c.SDL_GPUTextureFormatTexelBlockSize(g.swapchain_format); + const size = c.SDL_CalculateGPUTextureFormatSize(g.swapchain_format, sw, sh, 1); + if (size == 0 or bpp != 4) { + _ = c.SDL_SubmitGPUCommandBuffer(cmd); + return error.UnsupportedCaptureFormat; + } + const xfer = try downloadTarget(g, cmd, target, sw, sh, size); const fence = c.SDL_SubmitGPUCommandBufferAndAcquireFence(cmd) orelse return error.GpuSubmit; defer c.SDL_ReleaseGPUFence(g.device, fence); @@ -8903,22 +8911,7 @@ fn captureFrame(g: *Gui, gpa: std.mem.Allocator, cmd: *c.SDL_GPUCommandBuffer, t _ = c.SDL_SubmitGPUCommandBuffer(cmd); return error.UnsupportedCaptureFormat; } - if (g.capture_xfer == null or g.capture_xfer_size < size) { - var info = c.SDL_GPUTransferBufferCreateInfo{ .usage = c.SDL_GPU_TRANSFERBUFFERUSAGE_DOWNLOAD, .size = size, .props = 0 }; - const next = c.SDL_CreateGPUTransferBuffer(g.device, &info) orelse { - _ = c.SDL_SubmitGPUCommandBuffer(cmd); - return error.GpuCreate; - }; - if (g.capture_xfer) |transfer| c.SDL_ReleaseGPUTransferBuffer(g.device, transfer); - g.capture_xfer = next; - g.capture_xfer_size = size; - } - const xfer = g.capture_xfer.?; - const copy = c.SDL_BeginGPUCopyPass(cmd); - const src = c.SDL_GPUTextureRegion{ .texture = target, .mip_level = 0, .layer = 0, .x = 0, .y = 0, .z = 0, .w = sw, .h = sh, .d = 1 }; - const dst = c.SDL_GPUTextureTransferInfo{ .transfer_buffer = xfer, .offset = 0, .pixels_per_row = sw, .rows_per_layer = sh }; - c.SDL_DownloadFromGPUTexture(copy, &src, &dst); - c.SDL_EndGPUCopyPass(copy); + const xfer = try downloadTarget(g, cmd, target, sw, sh, size); const submit_ns = monoNs(); const fence = c.SDL_SubmitGPUCommandBufferAndAcquireFence(cmd) orelse return error.GpuSubmit; |
