From f10321aad5dc8d291507367f57c8b8dc69c71e97 Mon Sep 17 00:00:00 2001 From: Anees Iqbal Date: Thu, 12 Nov 2026 12:17:28 -0800 Subject: [PATCH] A pass left for its draws' pipelines takes its encoding again once they are made A render pass whose draw's VkPipeline was still being made as it was encoded records as a segment of its encoder once the pipeline is made (render/pending.rs). A rate map's reset after that making finished, before the command buffer's commit or after it while the command buffer waited, encoded the pass again from its log, and the splice refused it: the segment in its place was neither one whose pipelines are still being made nor work recorded on the GPU alone. The pass then drew by the map it took and the reset announced rate-map-reset-unencoded, where Metal's GPU draws by the map as reset. The rate-mapped multi-draw route made this common: its vertex variant is made at a pass's first draw, so the reset lanes failed by timing (a_reset_shows_in_a_pass_not_yet_submitted and a_reset_shows_in_every_pass_not_yet_submitted on lavapipe, jobs m3-max-22179 and m3-max-22244). The splice now also takes the place of a render pass left for its draws' or tile dispatches' pipelines alone and executing no render commands (Deferred::left_for_pipelines, DeferredPass::left_for_pipelines), made since or not: the encoding again recorded those draws where it found their pipelines made, or left a segment of its own where they were still being made, and what the first recording took stays retained, as for a segment still being made. Verified, before the fix: a diagnostic on lavapipe (job m3-max-22327) waited a second after the draw and refused the splice in both cases ("keeps false gpu_alone false ... making false"), shading the identity's 64 by 64 pixels with the notice; without the wait the pipeline was still being made and the splice took it. The new lane a_reset_shows_in_a_pass_whose_pipeline_was_made_after_its_draw waits for the making (WorkCounts::variant_pipelines_made) and checks the half map's 33 by 33 pixels and no notice. --- .../src/command_buffer/reencode.rs | 6 +- crates/metal2vulkan-runtime/src/deferred.rs | 11 ++++ .../src/render/executions.rs | 8 +++ .../src/runtime_lane/rate_mapped_passes.rs | 66 +++++++++++++++++++ 4 files changed, 90 insertions(+), 1 deletion(-) diff --git a/crates/metal2vulkan-runtime/src/command_buffer/reencode.rs b/crates/metal2vulkan-runtime/src/command_buffer/reencode.rs index 5f307ca61..8775e7e4e 100644 --- a/crates/metal2vulkan-runtime/src/command_buffer/reencode.rs +++ b/crates/metal2vulkan-runtime/src/command_buffer/reencode.rs @@ -349,7 +349,10 @@ impl State { /// `VkCommandBuffer`s go with the pool unsubmitted. Refused, changing nothing and giving /// `replayed` back, where its place holds other parts than the encoding again's, or a segment /// but one whose pipelines are being made (which goes, the encoding again having left one of - /// its own in its place), work its commit recorded on the GPU alone, a run's merge (which + /// its own in its place), a render pass left for its draws' pipelines alone and recorded or + /// not since they were made (which goes, the encoding again having recorded those draws, or + /// left a segment of its own where it found them still being made), work its commit recorded + /// on the GPU alone, a run's merge (which /// goes, the encoding again merging after itself, `pass_runs.rs`), or a staged gather (which /// goes, the encoding again copying through the imports, `host_ram/copy.rs`), or its group /// was submitted, or the command buffer completed. @@ -368,6 +371,7 @@ impl State { recorded.sparse.is_empty() && (recorded.segments.iter()).all(|segment| { segment.keeps_pipelines() + || segment.work.left_for_pipelines() || segment.gpu_alone || segment.work.joins_a_run() || segment.work.recorded_by_an_encoding_again() diff --git a/crates/metal2vulkan-runtime/src/deferred.rs b/crates/metal2vulkan-runtime/src/deferred.rs index 707c14f99..6a9e63179 100644 --- a/crates/metal2vulkan-runtime/src/deferred.rs +++ b/crates/metal2vulkan-runtime/src/deferred.rs @@ -700,6 +700,17 @@ impl Deferred { } } + /// Whether it is a render pass left for its draws' or tile dispatches' pipelines alone, made + /// since or not (`DeferredPass::left_for_pipelines`): an encoding again records those draws + /// where it finds their pipelines made, and leaves a segment of its own where they are still + /// being made, so it takes such a pass's place (`State::splice_replay`). + pub(super) fn left_for_pipelines(&self) -> bool { + match self { + Deferred::RenderPass(pass) => pass.left_for_pipelines(), + _ => false, + } + } + /// Whether a pipeline the work records is still being made (`render/pending.rs`). pub(super) fn making(&self) -> bool { match self { diff --git a/crates/metal2vulkan-runtime/src/render/executions.rs b/crates/metal2vulkan-runtime/src/render/executions.rs index a9da66fb6..7624383ef 100644 --- a/crates/metal2vulkan-runtime/src/render/executions.rs +++ b/crates/metal2vulkan-runtime/src/render/executions.rs @@ -2957,6 +2957,14 @@ impl DeferredPass { || self.steps.tile_pipelines().any(TilePipelines::failed) } + /// Whether it was left for the pipelines of its draws or tile dispatches alone, made since or + /// not: it has such draws or dispatches (`render/pending.rs`, `render/pending_tile.rs`) and + /// executes no render commands. + pub(crate) fn left_for_pipelines(&self) -> bool { + !self.executes() + && (!self.pending.is_empty() || self.steps.tile_pipelines().next().is_some()) + } + /// Whether it executes render commands, whose records its recording reads: everything else it /// records its calls resolved (`Deferred::resolved_at_its_calls`). pub(crate) fn executes(&self) -> bool { diff --git a/crates/metal2vulkan-validation/src/runtime_lane/rate_mapped_passes.rs b/crates/metal2vulkan-validation/src/runtime_lane/rate_mapped_passes.rs index 044baaf02..40405d79a 100644 --- a/crates/metal2vulkan-validation/src/runtime_lane/rate_mapped_passes.rs +++ b/crates/metal2vulkan-validation/src/runtime_lane/rate_mapped_passes.rs @@ -701,6 +701,72 @@ fn a_reset_shows_in_every_pass_not_yet_submitted() { }); } +/// A reset from the identity to half quality shows in a pass whose draw's `VkPipeline` was still +/// being made as it was encoded (`render/pending.rs`) and was made before the reset: after the +/// draw, and after `commit` while the command buffer waits for an event the CPU signals after +/// the reset. The runtime encodes the pass again in its place (`command_buffer/reencode.rs`): +/// the half-quality map's 33 by 33 physical pixels, as Metal's GPU reads the map as it runs the +/// pass, and without a notice. Where the device made the draw's pipeline before the draw (a +/// device without the multi-draw route, whose variant a rate-mapped draw takes), the reset shows +/// as in [`a_reset_shows_in_a_pass_not_yet_submitted`]. +#[test] +fn a_reset_shows_in_a_pass_whose_pipeline_was_made_after_its_draw() { + let half = (33 * 33, [0, 0, 32, 32], [[0.5, 0.5], [32.5, 32.5]]); + for held in [false, true] { + fresh(|fixture, messages| { + let device = &fixture.device; + let map = reset_map(fixture, 1.0, true); + let target = fixture.target(64); + let to = descriptor(SCREEN, SCREEN, &[(0.5, 0.5)]); + let queue = device.new_command_queue().unwrap(); + let command_buffer = queue.command_buffer().unwrap(); + let event = device.new_shared_event().unwrap(); + if held { + (command_buffer.encode_wait_for_event(EventRef::from(&event), 1)).unwrap(); + } + let before = device.work_counts(); + let mut encoder = command_buffer + .render_command_encoder(&pass(&map, &target)) + .unwrap(); + encoder.set_render_pipeline_state(&fixture.state).unwrap(); + (encoder.set_fragment_buffer(Some(&fixture.screen), 0, 0)).unwrap(); + (encoder.draw_primitives(PrimitiveType::Triangle, 0, 3, 1, 0)).unwrap(); + // Its pipeline made: the making counted, and a moment for its outcome to land. + let pended = device.work_counts().draws_unkept_making > before.draws_unkept_making; + if pended { + let deadline = std::time::Instant::now() + WAIT; + while device.work_counts().variant_pipelines_made == before.variant_pipelines_made { + assert!( + std::time::Instant::now() < deadline, + "held {held}: never made" + ); + std::thread::sleep(std::time::Duration::from_millis(1)); + } + std::thread::sleep(std::time::Duration::from_millis(100)); + } + if !held { + map.reset_using_descriptor(&to).unwrap(); + } + encoder.end_encoding().unwrap(); + command_buffer.commit().unwrap(); + if held { + map.reset_using_descriptor(&to).unwrap(); + event.set_signaled_value(1); + } + command_buffer.wait_until_completed_for(WAIT).unwrap(); + assert_eq!(command_buffer.status(), CommandBufferStatus::Completed); + let case = format!("held {held}, pended {pended}"); + eprintln!("RESET-AFTER-MAKING {case}"); + assert_eq!(shaded(&target), half, "{case}"); + let kinds = counts(&messages.take_notices()); + assert!( + !kinds.contains_key(&Degradation::RateMapResetUnencoded), + "{case}: {kinds:?}" + ); + }); + } +} + /// Our probe `rs`'s resets to another screen (the M3 Max under macOS 27.0.1, each case in a /// process of its own, repeated alike): a pass over the identity of a mutable map of `taken` /// pixels a side, reset to the identity of `now` pixels after its encoder opened, after