render: the M2 GPU zero-copy pipeline — wgpu 29, shared gpui device, GPU color LUTs

docs/zh/plans/render-pipeline-threads.md M2: the graph's textures stay
on the GPU from evaluation through presentation, and presentation runs
on the UI's own wgpu device.

- wgpu 25 -> 29 (naga 29) across the engine, unifying it with
  gpui_wgpu so engine textures are directly sampleable by the presenter
  (a single wgpu remains in the lockfile).
- GpuContext::adopt/install_shared: the app registers the window's
  device at startup and the render thread renders on it;
  texture_handle hands the raw Arc<wgpu::Texture> to
  SurfaceSource::Texture - zero-copy present on Linux/FreeBSD. The
  shared slot replaces an engine context that has not touched the GPU
  yet (startup-order guard) and refuses once it has.
- Texture::Gpu shares a GpuLease so clones release the registry token
  exactly once; the compositor, transitions and adjustment sweeps keep
  GPU textures end to end (no per-clip readbacks; GPU clears for
  black/generated frames).
- Color management stays on the GPU: the output node + display ICC
  chain is baked into a 65^3 3D LUT with the exact CPU reference and
  applied by the present WGSL pass (manual trilinear);
  ColorTransformJob bakes its OCIO processor the same way. Neither
  path skips color management.
- The explicit readback boundaries accept GPU textures: export
  encoder, CLI, worker shm, disk cache; CPU OpenFX already read back.
- M5 dependency: the YUV->RGB GPU pass (BT.601/709/2020 x
  limited/full) matches colormath::yuv444p16_to_rgb_f32.
- Acceptance: gpu_transfer_counters; single-clip and layered
  (multi-track + transition + adjustment) playback tests assert zero
  GPU->CPU readbacks, and the app test asserts adopted-device present
  is zero-copy. GPU tests hard-fail when OAK_REQUIRE_GPU is set (CI
  lavapipe) instead of skipping silently.
This commit is contained in:
2026-09-12 20:52:17 +08:00
parent a5b0b2a1b1
commit 48e99e56b7
29 changed files with 3014 additions and 782 deletions
+11 -8
View File
@@ -279,16 +279,19 @@ impl ExportTask {
}
}
/// Copy a rendered `oakrender` CPU texture into an `oakcodec` frame
/// with the matching video params (row-wise copy — line sizes may
/// differ between the render and codec frame layouts).
/// Copy a rendered `oakrender` texture into an `oakcodec` frame with
/// the matching video params (row-wise copy — line sizes may differ
/// between the render and codec frame layouts). A GPU texture is read
/// back here: the encoder input is one of the three explicit CPU
/// boundaries (M2).
fn to_codec_frame(texture: &Texture) -> Result<oak_codec::frame::Frame> {
let Texture::Cpu(frame) = texture else {
return Err(Error::Failed(
"Render produced a GPU texture; the CPU encoder path cannot consume it"
.to_string(),
));
let frame = match texture {
Texture::Cpu(frame) => frame.clone(),
Texture::Gpu { .. } => texture.to_frame().map_err(|e| {
Error::Failed(format!("Render frame readback for the encoder failed: {e:?}"))
})?,
};
let frame = &frame;
let params = CommonVideoParams::new_basic(
frame.width,
frame.height,