Repository navigation
GPU: read export YUV frames back asynchronously - #1632
Open
MatejKozlovsky wants to merge 2 commits into
Open
MatejKozlovsky wants to merge 2 commits into
MatejKozlovsky wants to merge 2 commits into
Conversation
Accelerator::comp_frame_yuv420 (default None) renders a top-level comp frame and converts it over the background to the H.264 export's 8-bit BT.709 limited-range 4:2:0, every byte within one level of the CPU conversion (the GPU kernel follows it operation for operation, including NaN and half-away-from-zero ties, but a driver may contract its arithmetic). A 4K frame then reads back 12 MB of planes instead of 133 MB of RGBA f32. The H.264 export asks the accelerator for planes when a frame needs nothing after the render (progressive, project depth, no crop/resize, rendered at the output size) and otherwise renders and converts on the CPU as before. Deferred readbacks (a browser worker) keep the pass-based path. Sizes the kernel can't take (width not a multiple of 8, odd height) are declined before any GPU work. rgba_to_yuv420 moves to effectcraft_raster::yuv so the export and the GPU tests share one reference. The GPU tests are #[ignore]d and fail without an adapter instead of passing untested.
Accelerator::comp_frame_yuv420_async submits the frame and hands the planes to a per-frame callback from a later poll_readbacks, so the caller can record the next frame while the copy runs. The callback runs exactly once (planes, or None when the readback fails or the device is lost) through the context's bounded readbacks. A frame that is declined, or whose readback can't start, returns the callback unused. The default implementation converts synchronously. - GpuContext::try_map_readback hands done back when the request can't start and reports when the buffer is unmapped; staging buffers return to the ring only then, so a cancelled readback never leaves a pending-mapped buffer for reuse. - At most 4 asynchronous frames are in flight: a slot is reserved atomically before rendering, and a further call polls until one frees up. - Gpu::poll_readbacks polls through the context's bridge with an opt-in that reads a timed-out wait as a busy queue (poll_readbacks_busy_ok). Every other caller, Gpu::wait included, still retires the context on a timeout.
This was referenced Oct 16, 2026
This branch has not been deployed
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.
Stacked on #1631, so the diff includes it until that lands.
On top of #1631, also from #898.
Adds
Accelerator::comp_frame_yuv420_async: render, submit, return. Planes come later in a per-frame callback frompoll_readbacks, so the next frame can record while the previous copy runs. Nothing calls it yet; export still uses the sync path. Switching needs a small reorder buffer, I'd do that separately once the API looks right.doneruns exactly once: planes, orNoneon failure/device loss (uses the context's existing bounded readbacks).Err(done), callback untouched, caller can go CPU. (GpuContext::try_map_readback;map_readbackwraps it.)doneruns on whichever thread polls, outside locks. Don't block in it or call back into the accelerator.poll_readbacksuses a new opt-inpoll_readbacks_busy_ok, where a wait timeout means "busy". Everything else,wait()included, still retires on timeout. (Adds a crate-privateGpu::wait_for(Duration)for that test.)Tests:
frames_in_flight_each_get_their_own_planesin_flight_cap_holds_across_threads(8 threads × 6 frames, never >4 pending)a_device_failure_fails_every_pending_readback_oncecancelled_readbacks_return_their_buffers_only_once_unmappedwait_past_its_deadline_retires_but_the_yuv_poll_does_notdeclined_async_frames_hand_the_callback_back_unusedasync_yuv_defaults_to_the_synchronous_conversion(render crate)Same test setup as #1631.