RUNTIME 2230: a reader through snapshots forgets only the kept draws that read its color
A direct draw that reads its own attachment through snapshots (not the in-place form) used to keep
nothing and forget every kept draw, those set aside for other pipeline states included. When it
records into its instance as it stood, on the encoder's own layout (no stand-in), and none of its
uses writes except its snapshots, it now forgets only the set-aside kept draws that read its
colors: one that reads a color's texture through its copy (Kept::through_copies), one that reads
it at narrowed levels (reads_attached), and one whose uses meet a color's memory
(render_target::shares_attachment, against that state's last-draw uses, which are the kept draw's
own). No kept draw can read a snapshot: only a reader binds one, and a reader never keeps. The
surviving draws keep their epoch and are "between", so their next draw is rebound; the reader's
snapshot writes are images, so pass_start_reads.fragments_wrote() stays false. Every other unkept
draw still forgets everything. LiveBind::forget_kept_where, RenderLowering::forget_readers, and a
snapshots_alone flag set where the draw's instance is decided; draw_again.rs documents it.
Why: on the XTX Launchpad walk 53% of draws (280 a present) take every step and none is carried,
because nearly every encoder holds a snapshot-reading draw that forgot every kept draw. A rebind
costs about a fifth of every step (~9 us saved a draw). Expected: fewer draws_none_kept and more
draws_rebound on the walk (about 21.6k of 24,947 snapshotted readers per 8 s qualify); not yet
measured on a walk.
Verified (imgleak, at e1a6c07dd8 on d5620581d5):
- tests::snapshot_reader_keeps (1024^2 BGRA8; reader, fill, sampler reading the reader's color
through its copy, reader, fill, sampler, fill; a second frame forgets before each draw), XTX
job 26011: release kept frame {snapshotted 2, none_kept 5, rebound 2}, apart frame {2, 7, 0};
pixels equal Metal's answer in both. Debug (every rebound checked against every step): both
checks pass.
- Controls (26014): without the change {none_kept 6, rebound 1}, test fails; sabotage ignoring
reads through copies {none_kept 4, rebound 3}, test fails.
- XTX release wider set 41/42, debug 27/28; the one failure, kept_shadowed_draws, fails
identically at the base product files on the XTX (pre-existing, being fixed separately).
- msi 25991: clippy plain and --cfg m2v_gpu clean; runtime 1525/1525.
Not yet: lavapipe (26022), the 780M, a walk.
No accuracy trade, no FAST-PATHS row. RUNTIME_VERSION 2229 -> 2230.
This commit is contained in:
1 parent
0be47bae24
commit
041038a914
7 files changed
+419
-6
No files matched your search
@@ -675,6 +675,24 @@ impl LiveBind {
|
||||
self.draw_kept.take()
|
||||
}
|
||||
|
||||
/// Let go of each kept draw set aside with the state of another pipeline state that `forgets`
|
||||
/// tells, given the draw and that state's last draw's uses (the kept draw's own), and keep
|
||||
/// the others (`RenderLowering::forget_readers`).
|
||||
pub(super) fn forget_kept_where<E>(
|
||||
&mut self,
|
||||
mut forgets: impl FnMut(&DrawKept, &CommandUses) -> Result<bool, E>,
|
||||
) -> Result<(), E> {
|
||||
for aside in &mut self.set_aside {
|
||||
let Some(kept) = aside.draw_kept.as_ref() else {
|
||||
continue;
|
||||
};
|
||||
if forgets(kept, &aside.uses)? {
|
||||
aside.draw_kept = None;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Of the kept draws set aside with the states of other pipeline states, keep for the next
|
||||
/// render encoder of its encoder's command buffer (`render/carried.rs`) those that `carries`
|
||||
/// tells carry (given each and whether its state holds its settle), of the `most` states set
|
||||
|
||||
@@ -1734,6 +1734,10 @@ pub(crate) struct RenderLowering {
|
||||
replay_plain: bool,
|
||||
/// The draw being drawn reached that keep's test and passed it ([`replay_plain`](Self::replay_plain)).
|
||||
plain_drawn: bool,
|
||||
/// The direct draw being drawn read through snapshots in its instance as it stood and wrote
|
||||
/// nothing but them: keeping nothing, it forgets only the kept draws that read its pass's
|
||||
/// colors (`render/draw_again.rs`).
|
||||
snapshots_alone: bool,
|
||||
/// The heap set versions the plain draws it replayed bound (`heap_sets::Bound`), each once,
|
||||
/// which a kept recording of them binds again (`kept_commands::KeptEffects`).
|
||||
replayed_heaps: Vec<Weak<SetVersion>>,
|
||||
@@ -2514,6 +2518,7 @@ impl RenderLowering {
|
||||
replaying: false,
|
||||
replay_plain: false,
|
||||
plain_drawn: false,
|
||||
snapshots_alone: false,
|
||||
replayed_heaps: Vec::new(),
|
||||
rerouting: false,
|
||||
forms: BufferForms::Bound,
|
||||
@@ -8313,6 +8318,7 @@ impl RenderLowering {
|
||||
}
|
||||
}
|
||||
self.drop_kept();
|
||||
self.snapshots_alone = false;
|
||||
let watch = EachWatch::start();
|
||||
// And whether it rasterizes, without which its primitives reach no tile (`no_raster_t11`).
|
||||
// And whether it chooses its viewport.
|
||||
@@ -8347,9 +8353,14 @@ impl RenderLowering {
|
||||
}
|
||||
// A draw that kept nothing may have changed what a draw set aside with another pipeline
|
||||
// state's bind state reads: every kept draw is forgotten, as at a call. One kept
|
||||
// recorded as a draw again of it would, into its instance as it stood.
|
||||
// recorded as a draw again of it would, into its instance as it stood. One that read
|
||||
// through snapshots and wrote nothing else wrote only its pass's colors and its
|
||||
// snapshots: it forgets the kept draws that read those alone (`render/draw_again.rs`).
|
||||
if self.again_kept().is_none() {
|
||||
self.forget_again();
|
||||
match self.snapshots_alone {
|
||||
true => self.forget_readers(live)?,
|
||||
false => self.forget_again(),
|
||||
}
|
||||
}
|
||||
// Every draw, one of nothing too; an execution's commands announce at the
|
||||
// execution (`executions.rs`).
|
||||
@@ -9809,6 +9820,14 @@ impl RenderLowering {
|
||||
if let Some(imageblock) = imageblock {
|
||||
uses.extend(imageblock.draw_uses()?);
|
||||
}
|
||||
// A direct draw that reads through snapshots, and whose every use but its snapshots'
|
||||
// writes nothing, writes its pass's colors and its snapshots alone: where it records into
|
||||
// its instance as it stood (below), it forgets only the kept draws that read them
|
||||
// (`render/draw_again.rs`).
|
||||
let snapshots_alone = matches!(&snapshot, Some(wanted) if !wanted.in_place)
|
||||
&& !self.replaying
|
||||
&& !self.rerouting
|
||||
&& uses.iter().all(|used| used.write.is_empty());
|
||||
uses.extend(snapshot_texels.iter().map(Texture::snapshot_use));
|
||||
// A draw that names a detached buffer records nothing: its submission fails.
|
||||
let named = uses
|
||||
@@ -10804,6 +10823,7 @@ impl RenderLowering {
|
||||
|| made_imageblock.is_some()
|
||||
|| pending.is_some();
|
||||
let stepless = !later_instance && !own_steps;
|
||||
self.snapshots_alone = snapshots_alone && !begun && !later_instance;
|
||||
// Recording starts here: nothing below can be refused.
|
||||
if let Some(written) = written {
|
||||
self.core.keep_set_zero(written, &writes);
|
||||
|
||||
@@ -39,7 +39,7 @@
|
||||
//! which every call does: at the call, on the device's lowering thread, and encoded again),
|
||||
//! refused or not, whatever it changes, with every kept draw set aside (below); so does a draw
|
||||
//! that keeps nothing (a draw again, a draw rebound and a draw kept are the only draws that
|
||||
//! leave them). A bind changes its
|
||||
//! leave them), but a reader through snapshots that writes nothing else (below). A bind changes its
|
||||
//! stage table's slots alone (and a bytes bind takes room in its command buffer's uploads), and
|
||||
//! a table's stamp tells each change apart (`argument_table::Stamp`): the kept draw keeps the
|
||||
//! four tables' stamps as it read them, and a draw whose tables kept them is the kept draw
|
||||
@@ -63,13 +63,28 @@
|
||||
//! wrote (`LiveBind::select`, `RenderLowering::select_kept`), and the draw starts from its own
|
||||
//! state's, with the draw kept beside it, where one is under the encoder's epoch (which every
|
||||
//! forgetting draws afresh: `DrawAgain`). Such a draw is between (`Kept::between`): draws of
|
||||
//! other states recorded since, each a draw kept or drawn again, into the same instance, whose
|
||||
//! steps only add to what the encoder holds (below). Its next draw is rebound whatever its
|
||||
//! other states recorded since, each a draw kept or drawn again, or a reader through snapshots
|
||||
//! that wrote none of what it reads (below), into the same instance, whose steps only add to
|
||||
//! what the encoder holds (below). Its next draw is rebound whatever its
|
||||
//! tables' stamps (`rebound.rs`), the changes of its tables since it read them brought in, its
|
||||
//! uses noted, added to the pass's reads and gathered whole, and every state command its
|
||||
//! record does not hold recorded; it takes no shortcut of a draw moved, which reads what the
|
||||
//! encoder's last draw left. Each state's bind state is its own, though states of one function
|
||||
//! pair share an interface, so the draw kept of one is never the other's.
|
||||
//! - **Past a reader through snapshots.** A draw that reads through snapshots
|
||||
//! (`render/snapshot.rs`) keeps nothing. Where it records into its instance as it stood, of the
|
||||
//! encoder's own colors, as a direct draw, and no use of it but its snapshots' writes, what it
|
||||
//! writes is its pass's colors and its snapshots: it forgets only the kept draws set aside that
|
||||
//! read them (`RenderLowering::forget_readers`), each that reads a color's texture through its
|
||||
//! copy (`Kept::through_copies`) or at levels apart from the attached ones
|
||||
//! (`render/attached_levels.rs`), or whose uses meet a color's memory
|
||||
//! (`render_target::shares_attachment`). No kept draw reads a snapshot: only a draw that reads
|
||||
//! through snapshots binds one. The others stay kept under the epoch, between, so the next draw
|
||||
//! of each is rebound (`rebound.rs`), recording every state command its instance's record does
|
||||
//! not hold, as after a draw kept of another state. The reader's other steps add to what the
|
||||
//! encoder holds as a kept draw's do; its barriers are inside the subpass, by region; and its
|
||||
//! snapshots are images, so the pass's fragments still wrote no buffer bytes a stage before
|
||||
//! them reads (`render/pass_start_reads.rs`). `tests::snapshot_reader_keeps` checks it.
|
||||
//! - **Of other arguments.** A draw that differs from the kept draw only in its arguments (its
|
||||
//! call of the same primitive type, with indices or without, its vertex or index counts and
|
||||
//! starts, its index buffer, index type or index buffer's offset, each read in place, its
|
||||
@@ -567,6 +582,21 @@ impl RenderLowering {
|
||||
self.again.epoch = Stamp::fresh();
|
||||
}
|
||||
|
||||
/// Forget the kept draws set aside with other pipeline states' bind states (`live`) that read
|
||||
/// what a draw that read through snapshots, keeping nothing, wrote: its pass's colors, read
|
||||
/// through their textures' copies, at levels apart from the attached ones, or by a use of
|
||||
/// their memory (`render_target::shares_attachment`). No kept draw reads a snapshot. The
|
||||
/// others stay kept under the encoder's epoch (the module docs).
|
||||
pub(super) fn forget_readers(&mut self, live: &mut LiveBind) -> Result<(), Error> {
|
||||
self.again.kept = None;
|
||||
let (memo, layout) = (&mut self.attached, &self.layout);
|
||||
let version = layout.version();
|
||||
live.forget_kept_where(|kept, uses| {
|
||||
let attached = kept.through_copies.0 || kept.reads_attached();
|
||||
Ok(attached || memo.shares((layout, version), uses)?)
|
||||
})
|
||||
}
|
||||
|
||||
/// The epoch a draw kept now is kept under ([`DrawAgain`]).
|
||||
pub(super) fn again_epoch(&self) -> Stamp {
|
||||
self.again.epoch
|
||||
|
||||
@@ -3045,6 +3045,7 @@ impl RenderExecution {
|
||||
replaying: true,
|
||||
replay_plain: true,
|
||||
plain_drawn: false,
|
||||
snapshots_alone: false,
|
||||
replayed_heaps: Vec::new(),
|
||||
rerouting: false,
|
||||
forms,
|
||||
|
||||
@@ -642,6 +642,8 @@ mod short_row_kinds;
|
||||
#[cfg(any(m2v_gpu, m2v_cpu_icd))]
|
||||
mod small_heap;
|
||||
mod snapshot_area;
|
||||
#[cfg(any(m2v_gpu, m2v_cpu_icd))]
|
||||
mod snapshot_reader_keeps;
|
||||
mod sorted_chunks;
|
||||
mod spares;
|
||||
#[cfg(any(m2v_gpu, m2v_cpu_icd))]
|
||||
|
||||
@@ -0,0 +1,342 @@
|
||||
//! A reader through snapshots (`render/snapshot.rs`) keeps nothing, and forgets only the kept
|
||||
//! draws that read what it wrote, its pass's colors and its snapshots (`render/draw_again.rs`,
|
||||
//! past a reader through snapshots): a kept draw of another pipeline state that reads none of it
|
||||
//! stays kept, and its next draw is rebound; one that reads the reader's color is forgotten.
|
||||
//!
|
||||
//! One pass over a [`SIDE`]-square private `BGRA8Unorm` target, loaded and stored, which a copy
|
||||
//! before it fills with [`CLEARED`] but [`PRE`] over [`SAMPLED`], with no scissor, draws in turn:
|
||||
//!
|
||||
//! 1. the reader (`tob_read`: each fragment writes the texel of its slot-0 texture, the target's,
|
||||
//! under it) over [`FIRST_READ`], which, through the whole target's scissor, takes the
|
||||
//! snapshot by the area rule on a device that takes the snapshot path;
|
||||
//! 2. the fill (`tob_solid`) of [`FILL`] with [`FILLED`], kept;
|
||||
//! 3. the sampler (`tob_sample`: each fragment samples the target's texture at its own position)
|
||||
//! over [`SAMPLED`], which reads the texture's copy from before its instance and is kept: a
|
||||
//! kept draw that reads the reader's color;
|
||||
//! 4. the reader over [`SECOND_READ`], in its instance as it stood: it forgets the sampler's kept
|
||||
//! draw and keeps the fill's;
|
||||
//! 5. the fill: its kept draw past the reader, rebound;
|
||||
//! 6. the sampler: forgotten, it takes every step and is kept again;
|
||||
//! 7. the fill: rebound after the sampler's draw.
|
||||
//!
|
||||
//! The same frame runs again with a call that keeps no draw before each draw but the first
|
||||
//! (`setTessellationFactorScale:`, which no draw of the pass reads), so each takes every step.
|
||||
//!
|
||||
//! Both frames answer alike: [`FILLED`] over [`FILL`], drawn last there; [`PRE`] over the rest of
|
||||
//! [`SAMPLED`], the texels from before the pass the sampler reads; [`CLEARED`] elsewhere, the
|
||||
//! readers writing back the texels they read, which no draw before them wrote. On a device that
|
||||
//! takes the snapshot path, both readers read through snapshots, and of the first frame's draws
|
||||
//! five find nothing kept (the first four and the sampler's second) where the second frame's seven
|
||||
//! do; the fill's two draws after the reader are rebound, each taking every step instead in
|
||||
//! builds with debug assertions and checking that the rebind worked out what every step works out
|
||||
//! (`rebound.rs`). A device without the path reads through copies, which keeps the readers.
|
||||
//!
|
||||
//! A device test: compiled only under the validation crate's GPU safety cfgs (`m2v_gpu`,
|
||||
//! `m2v_cpu_icd`), on the kind of device the cfg selects. The functions are `tob_rect`,
|
||||
//! `tob_solid`, `tob_read` and `tob_sample` of the owned fixture
|
||||
//! `validation/fixtures/public/engine/tob_renders.ll` (`llvm-as`).
|
||||
|
||||
use super::blit_holds::{device, Scratch, WAIT};
|
||||
use super::encoder_holds::{bytes_of, library};
|
||||
use crate::framebuffer_fetch::through_storage;
|
||||
use crate::{
|
||||
BlitOption, CommandQueue, Device, LoadAction, Origin, PipelineOptions, RenderCommandEncoder,
|
||||
RenderPassDescriptor, RenderPipelineState, ResourceOptions, SamplerState, Size, StoreAction,
|
||||
Texture, TextureDescriptor, WorkCounts,
|
||||
};
|
||||
use metal2vulkan::bind::SamplerDescriptor;
|
||||
use metal2vulkan::metal::{PixelFormat, PrimitiveType, TextureUsage};
|
||||
use metal2vulkan::pipeline::{ColorAttachmentDescriptor, RenderPipelineDescriptor, StageSource};
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
/// The target's side, in pixels: through the whole target's scissor, a reader of a 4-byte color
|
||||
/// takes the snapshot by the area rule.
|
||||
const SIDE: u64 = 1024;
|
||||
|
||||
/// The target's format.
|
||||
const FORMAT: PixelFormat = PixelFormat::BGRA8Unorm;
|
||||
|
||||
/// The rectangles the draws cover, `[x0, y0, x1, y1]`: the readers', apart from every other.
|
||||
const FIRST_READ: [u64; 4] = [600, 600, 664, 664];
|
||||
const SECOND_READ: [u64; 4] = [700, 700, 764, 764];
|
||||
const FILL: [u64; 4] = [100, 100, 300, 300];
|
||||
const SAMPLED: [u64; 4] = [200, 200, 400, 400];
|
||||
|
||||
/// The reds: the target's outside [`SAMPLED`] and inside it before the pass, and the fill's.
|
||||
const CLEARED: u8 = 20;
|
||||
const PRE: u8 = 160;
|
||||
const FILLED: u8 = 90;
|
||||
|
||||
/// The state of `tob_rect` and `tob_renders.ll`'s `fragment`, into a color of [`FORMAT`].
|
||||
fn state(device: &Device, fragment: &str) -> RenderPipelineState {
|
||||
let function = |name: &str| {
|
||||
let function = library(device, "engine/tob_renders.ll")
|
||||
.new_function_with_name(name)
|
||||
.unwrap();
|
||||
StageSource::Function(function.function_descriptor())
|
||||
};
|
||||
let mut descriptor = RenderPipelineDescriptor::new(function("tob_rect"));
|
||||
descriptor.fragment = Some(function(fragment));
|
||||
descriptor.color_attachments[0] = Some(ColorAttachmentDescriptor::new(FORMAT));
|
||||
device
|
||||
.new_render_pipeline_state(&descriptor, &PipelineOptions::default())
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
/// The pipeline states: the reader, the fill and the sampler.
|
||||
struct States {
|
||||
read: RenderPipelineState,
|
||||
fill: RenderPipelineState,
|
||||
sample: RenderPipelineState,
|
||||
}
|
||||
|
||||
/// A private [`FORMAT`] render target that shaders read.
|
||||
fn target(device: &Device) -> Texture {
|
||||
let mut descriptor = TextureDescriptor::texture_2d(FORMAT, SIDE, SIDE, false);
|
||||
descriptor.usage = TextureUsage::RENDER_TARGET | TextureUsage::SHADER_READ;
|
||||
descriptor.resource_options = ResourceOptions::private();
|
||||
device.new_texture(&descriptor).unwrap()
|
||||
}
|
||||
|
||||
/// The corners, in normalized device coordinates, of the target's pixels `[x0, x1) x [y0, y1)`.
|
||||
fn corners([x0, y0, x1, y1]: [u64; 4]) -> Vec<u8> {
|
||||
let x = |p: u64| p as f32 / SIDE as f32 * 2.0 - 1.0;
|
||||
let y = |p: u64| 1.0 - p as f32 / SIDE as f32 * 2.0;
|
||||
bytes_of(&[x(x0), y(y1), x(x1), y(y0)], f32::to_le_bytes)
|
||||
}
|
||||
|
||||
/// Whether `rect` holds pixel `(x, y)`.
|
||||
fn holds([x0, y0, x1, y1]: [u64; 4], (x, y): (u64, u64)) -> bool {
|
||||
(x0..x1).contains(&x) && (y0..y1).contains(&y)
|
||||
}
|
||||
|
||||
/// The target's red at each pixel before the pass: [`PRE`] over [`SAMPLED`], else [`CLEARED`].
|
||||
fn before_reds() -> Vec<u8> {
|
||||
(0..SIDE * SIDE)
|
||||
.map(|at| match holds(SAMPLED, (at % SIDE, at / SIDE)) {
|
||||
true => PRE,
|
||||
false => CLEARED,
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// The target's red at each pixel after the pass (the module docs).
|
||||
fn after_reds() -> Vec<u8> {
|
||||
let before = before_reds();
|
||||
(0..SIDE * SIDE)
|
||||
.map(|at| match holds(FILL, (at % SIDE, at / SIDE)) {
|
||||
true => FILLED,
|
||||
false => before[at as usize],
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Fill `target` with [`before_reds`], a command buffer of its own, completed.
|
||||
fn fill_before(queue: &CommandQueue, target: &Texture) {
|
||||
let row = SIDE * 4;
|
||||
// `BGRA8Unorm`'s red is its third byte.
|
||||
let texels: Vec<u8> = (before_reds().into_iter())
|
||||
.flat_map(|red| [0, 0, red, 255])
|
||||
.collect();
|
||||
let source = (queue.device())
|
||||
.new_buffer_with_bytes(&texels, ResourceOptions::shared())
|
||||
.unwrap();
|
||||
let command_buffer = queue.command_buffer().unwrap();
|
||||
let mut blit = command_buffer.blit_command_encoder().unwrap();
|
||||
(blit.copy_from_buffer_to_texture(
|
||||
&source,
|
||||
0,
|
||||
row,
|
||||
0,
|
||||
Size::new(SIDE, SIDE, 1),
|
||||
target,
|
||||
0,
|
||||
0,
|
||||
Origin::new(0, 0, 0),
|
||||
BlitOption::None,
|
||||
))
|
||||
.unwrap();
|
||||
blit.end_encoding().unwrap();
|
||||
command_buffer.commit().unwrap();
|
||||
command_buffer.wait_until_completed_for(WAIT).unwrap();
|
||||
assert_eq!(command_buffer.error(), None);
|
||||
}
|
||||
|
||||
/// The red of each of `texture`'s pixels, by row.
|
||||
fn reds(queue: &CommandQueue, texture: &Texture) -> Vec<u8> {
|
||||
let row = SIDE * 4;
|
||||
let back = (queue.device())
|
||||
.new_buffer(SIDE * row, ResourceOptions::shared())
|
||||
.unwrap();
|
||||
let command_buffer = queue.command_buffer().unwrap();
|
||||
let mut blit = command_buffer.blit_command_encoder().unwrap();
|
||||
(blit.copy_from_texture_to_buffer(
|
||||
texture,
|
||||
0,
|
||||
0,
|
||||
Origin::new(0, 0, 0),
|
||||
Size::new(SIDE, SIDE, 1),
|
||||
&back,
|
||||
0,
|
||||
row,
|
||||
SIDE * row,
|
||||
BlitOption::None,
|
||||
))
|
||||
.unwrap();
|
||||
blit.end_encoding().unwrap();
|
||||
command_buffer.commit().unwrap();
|
||||
command_buffer.wait_until_completed_for(WAIT).unwrap();
|
||||
let texels = super::merge_scratch::read(&back, SIDE * row);
|
||||
texels.chunks(4).map(|texel| texel[2]).collect()
|
||||
}
|
||||
|
||||
/// The frame over a new target (the module docs), each draw but the first after a call that keeps
|
||||
/// no draw where `apart`: the device's counts before and after the pass, and the target's reds
|
||||
/// after it. Into a queue of its own, which no earlier frame's kept draw is carried along
|
||||
/// (`render/carried.rs`).
|
||||
fn frame(
|
||||
device: &Device,
|
||||
states: &States,
|
||||
sampler: &SamplerState,
|
||||
apart: bool,
|
||||
) -> ((WorkCounts, WorkCounts), Vec<u8>) {
|
||||
let queue = &device.new_command_queue().unwrap();
|
||||
let target = target(device);
|
||||
fill_before(queue, &target);
|
||||
let before = device.work_counts();
|
||||
let command_buffer = queue.command_buffer().unwrap();
|
||||
let mut pass = RenderPassDescriptor::new();
|
||||
let color = &mut pass.color_attachments[0];
|
||||
color.texture = Some(target.clone());
|
||||
color.load_action = LoadAction::Load;
|
||||
color.store_action = StoreAction::Store;
|
||||
let mut encoder = command_buffer.render_command_encoder(&pass).unwrap();
|
||||
encoder.set_fragment_texture(Some(&target), 0).unwrap();
|
||||
(encoder.set_fragment_sampler_state(Some(sampler), 0)).unwrap();
|
||||
let filled = f32::from(FILLED) / 255.0;
|
||||
let rgba = bytes_of(&[filled, 0.0, 0.0, 1.0], f32::to_le_bytes);
|
||||
encoder.set_fragment_bytes(&rgba, 0).unwrap();
|
||||
let mut drawn = 0;
|
||||
let mut draw =
|
||||
|encoder: &mut RenderCommandEncoder, state: &RenderPipelineState, rect: [u64; 4]| {
|
||||
encoder.set_render_pipeline_state(state).unwrap();
|
||||
encoder.set_vertex_bytes(&corners(rect), 0).unwrap();
|
||||
if apart && drawn > 0 {
|
||||
encoder.set_tessellation_factor_scale(1.0);
|
||||
}
|
||||
(encoder.draw_primitives(PrimitiveType::Triangle, 0, 6, 1, 0)).unwrap();
|
||||
drawn += 1;
|
||||
};
|
||||
draw(&mut encoder, &states.read, FIRST_READ);
|
||||
draw(&mut encoder, &states.fill, FILL);
|
||||
draw(&mut encoder, &states.sample, SAMPLED);
|
||||
draw(&mut encoder, &states.read, SECOND_READ);
|
||||
draw(&mut encoder, &states.fill, FILL);
|
||||
draw(&mut encoder, &states.sample, SAMPLED);
|
||||
draw(&mut encoder, &states.fill, FILL);
|
||||
encoder.end_encoding().unwrap();
|
||||
command_buffer.commit().unwrap();
|
||||
command_buffer.wait_until_completed_for(WAIT).unwrap();
|
||||
assert_eq!(command_buffer.error(), None);
|
||||
let after = device.work_counts();
|
||||
((before, after), reds(queue, &target))
|
||||
}
|
||||
|
||||
/// What a frame's pass moved of the counts between `before` and `after`.
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
struct Keeps {
|
||||
/// `WorkCounts::reading_draws_snapshotted`, `draws_none_kept`, `draws_rebound`,
|
||||
/// `draws_rebind_stopped`, `draws_unlike_kept` and `draws_unkept`.
|
||||
snapshotted: u64,
|
||||
none_kept: u64,
|
||||
rebound: u64,
|
||||
stopped: u64,
|
||||
unlike: u64,
|
||||
unkept: u64,
|
||||
}
|
||||
|
||||
fn moved((before, after): &(WorkCounts, WorkCounts)) -> Keeps {
|
||||
let delta = |count: fn(&WorkCounts) -> u64| count(after) - count(before);
|
||||
Keeps {
|
||||
snapshotted: delta(|c| c.reading_draws_snapshotted),
|
||||
none_kept: delta(|c| c.draws_none_kept),
|
||||
rebound: delta(|c| c.draws_rebound),
|
||||
stopped: delta(|c| c.draws_rebind_stopped),
|
||||
unlike: delta(|c| c.draws_unlike_kept),
|
||||
unkept: delta(|c| c.draws_unkept),
|
||||
}
|
||||
}
|
||||
|
||||
/// Wait until the device's pipeline pool makes nothing.
|
||||
fn settled(device: &Device) {
|
||||
let until = Instant::now() + WAIT;
|
||||
while device.work_counts().pipeline_pool_busy != 0 {
|
||||
assert!(Instant::now() < until, "the pipeline pool still busy");
|
||||
std::thread::sleep(Duration::from_millis(1));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_reader_through_snapshots_forgets_only_the_kept_draws_that_read_its_color() {
|
||||
let scratch = Scratch::new("snapshot-reader-keeps");
|
||||
let device = device(&scratch.0);
|
||||
let states = States {
|
||||
read: state(&device, "tob_read"),
|
||||
fill: state(&device, "tob_solid"),
|
||||
sample: state(&device, "tob_sample"),
|
||||
};
|
||||
let sampler = (device.new_sampler_state(&SamplerDescriptor::new())).unwrap();
|
||||
// A frame first, so every pipeline its draws take is made before the frames counted.
|
||||
frame(&device, &states, &sampler, false);
|
||||
settled(&device);
|
||||
let (kept_counts, kept_reds) = frame(&device, &states, &sampler, false);
|
||||
let (apart_counts, apart_reds) = frame(&device, &states, &sampler, true);
|
||||
let want = after_reds();
|
||||
for (frame, reds) in [("kept", &kept_reds), ("apart", &apart_reds)] {
|
||||
if let Some(at) = (0..reds.len()).find(|&at| reds[at] != want[at]) {
|
||||
let (x, y) = (at as u64 % SIDE, at as u64 / SIDE);
|
||||
panic!(
|
||||
"{frame} frame: pixel ({x}, {y}) holds red {}, not {}",
|
||||
reds[at], want[at]
|
||||
);
|
||||
}
|
||||
}
|
||||
let (kept, apart) = (moved(&kept_counts), moved(&apart_counts));
|
||||
let snapshots = device.shared().color_write_masks.is_some()
|
||||
&& through_storage(device.compile_device().profile());
|
||||
eprintln!(
|
||||
"SNAPSHOT-READER-KEEPS {}: snapshot path {snapshots}; kept {kept:?}; apart {apart:?}",
|
||||
device.name()
|
||||
);
|
||||
if !snapshots {
|
||||
assert_eq!(kept.snapshotted, 0, "the readers through snapshots");
|
||||
return;
|
||||
}
|
||||
// Five draws find nothing kept: the first four, and the sampler's second, which the second
|
||||
// reader forgot. The fill's two draws after the reader are rebound, or in builds with debug
|
||||
// assertions take every step to check the rebind (each the first after a draw kept).
|
||||
let debug = cfg!(debug_assertions);
|
||||
let want = Keeps {
|
||||
snapshotted: 2,
|
||||
none_kept: 5,
|
||||
rebound: u64::from(!debug) * 2,
|
||||
stopped: 0,
|
||||
unlike: 0,
|
||||
unkept: 2,
|
||||
};
|
||||
assert_eq!(kept, want, "the kept frame's keeps on {}", device.name());
|
||||
let apart_want = Keeps {
|
||||
snapshotted: 2,
|
||||
none_kept: 7,
|
||||
rebound: 0,
|
||||
stopped: 0,
|
||||
unlike: 0,
|
||||
unkept: 2,
|
||||
};
|
||||
assert_eq!(
|
||||
apart,
|
||||
apart_want,
|
||||
"the apart frame's keeps on {}",
|
||||
device.name()
|
||||
);
|
||||
}
|
||||
Vendored
+1
-1
@@ -94,7 +94,7 @@ pub const ARTIFACT_FORMAT_VERSION: u32 = 518;
|
||||
/// changes no behaviour, and then updates that hash alone with the commit saying why, or changes
|
||||
/// behaviour and also bumps this version. The commit that bumps it says what changed; this comment
|
||||
/// keeps no history.
|
||||
pub const RUNTIME_VERSION: u32 = 2229;
|
||||
pub const RUNTIME_VERSION: u32 = 2230;
|
||||
|
||||
/// The digest of the sources this build of the crate was compiled from: SHA-256, as lowercase hex,
|
||||
/// of the manifest, the build script, and exactly the files the crate roots' module tree compiles
|
||||
|
||||
Reference in new issue
Block a user