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