RUNTIME 2337: A pass's first draw that samples a color the pass clears reads its copy cleared to the clear, with no barrier too
A draw that samples a texture its own pass renders reads the texture's shadow, a copy taken before the pass's load actions (texture/attached_reads.rs). In a pass that clears the color, a first draw that sampled it with no barrier read the texels from before the pass at every pixel it read: the M3 Max's answer, while both x86 Macs read the clear there (probe ownread: no draw before it, so the load and the draws before it wrote only the clear). The copy was cleared to the clear (Texture::cleared_copy, vkCmdClearColorImage) only after a memory barrier before the pass's first draw. The Macs disagree, so Metal's answer is either; the macOS guests are x86 ones, and a clear of the copy costs less than a copy of the texture. RenderLowering's draw now takes the cleared copy for every draw that samples a color the pass clears before any draw of the pass recorded, wherever Texture::cleared_copy holds (a whole single-sampled 2D texture of one level and slice that one color renders in place), with a barrier before it or none; the draw keeps nothing to draw again, as after the barrier. A pass that loads the color, and every read outside cleared_copy, read as before. Tests: attachment_reads' no-barrier lane becomes a_first_draw_with_no_barrier_reads_its_pass_s_load, Load and Clear over both target kinds, the texture of its own image taking the cleared copy (attachment_read_clears) and reading the clear where the pass clears; check() counts a cleared copy as taking no split's place with no barrier. framebuffer_fetch gains a_first_fetch_after_a_clear_reads_the_clear (a fetch after a Clear reads the clear, not the texels from before the pass). The conformance rows pass-start-barrier-*-sample with no barrier accept the clear too, as the -read rows did. docs/API.md's accepted differences and attached_reads.rs's docs say which Macs answer what. Verification: the jobs that compile and run it are reported with this sha. With: 645f1c3323 snapshot_reads' first test makes its readers' pipelines before the counted pass; af0a44cc6d The render lanes and inline-split tests read their fixtures where the test runner names the crate; 8b5cd6dfb4 attachment_reads' first-draw lane lets a target over a buffer's bytes take the cleared copy too (test-only). The user's GitHub issue 17. Compiled in m3-max-31319 at 8b5cd6dfb4 (clippy x3; lavapipe lanes, the first-draw lane, the fetch-after-clear lane, the 14 pass-start-barrier conformance rows exact and default; the negative fails).
This commit is contained in:
1 parent
86d50ef800
commit
5fcd8be7de
14 files changed
+237
-109
No files matched your search
@@ -28,12 +28,14 @@
|
||||
//! gives and the runtime orders (`fence.rs`), which the case states from what each draw writes:
|
||||
//! the clear where the barrier is the pass's first command, and the solid draw's color where that
|
||||
//! draw came before it. Its justification is `docs/API.md`'s accepted difference
|
||||
//! [`MAC2_BARRIER`]. The rows that read at their own pixels with no barrier accept the clear too,
|
||||
//! what the draws before the read wrote, an x86 Mac's answer, which the runtime reads where it
|
||||
//! takes the read through a snapshot (a target over a buffer, on a device with the snapshot
|
||||
//! route: `render/snapshot.rs`): `docs/API.md`'s accepted difference [`DRAWN_WITHOUT_BARRIER`].
|
||||
//! [`MAC2_BARRIER`]. The rows that read or sample with no barrier accept the clear too: what the
|
||||
//! load and the draws before the read wrote, both x86 Macs' answer at a pass's first draw, which
|
||||
//! the runtime reads through a copy cleared to the clear before any draw of the pass, where the
|
||||
//! copy can be so (a private target: `WorkCounts::attachment_read_clears`), or through a snapshot
|
||||
//! (a target over a buffer read at its own pixels, on a device with the snapshot route:
|
||||
//! `render/snapshot.rs`): `docs/API.md`'s accepted difference [`DRAWN_WITHOUT_BARRIER`].
|
||||
//! Elsewhere it reads the copy taken before the pass, the texels from before it, as the M3 Max
|
||||
//! does (`texture/attached_reads.rs`). The rows that sample with no barrier accept nothing else.
|
||||
//! does (`texture/attached_reads.rs`).
|
||||
//!
|
||||
//! A texture's texels are recorded as their runs of equal rows, each row's texels as their runs
|
||||
//! of equal texels (`fresh_contents::texel_runs`): a lossless encoding whose size follows how often
|
||||
@@ -754,13 +756,14 @@ impl Row {
|
||||
})
|
||||
}
|
||||
|
||||
/// What the runtime answers for a row that reads at its own pixels with no barrier, where it
|
||||
/// takes the read through a snapshot (the module docs): the clear, as the barrier's rows
|
||||
/// answer. `None` for every other row.
|
||||
/// What the runtime answers for a row that reads or samples with no barrier, where it takes
|
||||
/// the read through a copy cleared to the clear or through a snapshot (the module docs): the
|
||||
/// clear, as the barrier's rows answer. `None` for every other row.
|
||||
fn drawn(&self) -> Option<Vec<u8>> {
|
||||
match self.shape {
|
||||
Shape::Small {
|
||||
read: Small::Read, ..
|
||||
read: Small::Read | Small::Sample,
|
||||
..
|
||||
} => Some(image([SMALL; 2], |x, y| match inside(AREA, x, y) {
|
||||
true => reordered(texel(CLEAR)),
|
||||
false => texel(CLEAR),
|
||||
@@ -848,8 +851,8 @@ impl Case for PassStartRead {
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
// A read with no barrier may answer the clear where the runtime reads it through a
|
||||
// snapshot (the module docs).
|
||||
// A read with no barrier may answer the clear where the runtime reads it through a copy
|
||||
// cleared to it or a snapshot (the module docs).
|
||||
if let Some(bytes) = self.row.drawn() {
|
||||
allowances.push(Allowance::new(
|
||||
format!("case/{}", texels_site(0)),
|
||||
|
||||
@@ -7943,9 +7943,10 @@ impl RenderLowering {
|
||||
})
|
||||
}
|
||||
|
||||
/// The clears a draw `call` of a plan of `facts` that samples a color the pass clears after a
|
||||
/// memory barrier before its first draw reads through copies cleared to them, in its
|
||||
/// instance, instead of the pass splitting (`texture/attached_reads.rs`): each texture it
|
||||
/// The clears a draw `call` of a plan of `facts` that samples a color the pass clears reads
|
||||
/// through copies cleared to them, in its instance, instead of the copies of the texels from
|
||||
/// before the pass, or, after a memory barrier before the pass's first draw, instead of the
|
||||
/// pass splitting (`texture/attached_reads.rs`): each texture it
|
||||
/// samples that such a color renders, by its shadow ([`Texture::cleared_copy`]), but those the
|
||||
/// pass's first instance clears in already. `None` where one may not be cleared so, where the
|
||||
/// pass split or ran a tile dispatch, or where one is new and a draw recorded into the pass
|
||||
@@ -9515,26 +9516,21 @@ impl RenderLowering {
|
||||
// has begun its render pass instance with no color in the feedback loop layout, so the
|
||||
// draw records into a new one (`render/snapshot.rs`). So does a draw that binds a texture
|
||||
// the current instance holds in that layout as a storage image.
|
||||
// After a memory barrier before the pass's first draw, one that samples a color the pass
|
||||
// clears reads a copy that holds the clear (`texture/attached_reads.rs`): the pass's load
|
||||
// actions are behind the barrier. The copy is cleared to it before the pass where that can
|
||||
// be, before any draw of the pass; else the draw records into an instance after the
|
||||
// pass's first, which runs the clear, and the copy is taken between.
|
||||
// One that samples a color the pass clears, before any draw of the pass, reads a copy
|
||||
// cleared to the clear before the pass where that can be (`texture/attached_reads.rs`),
|
||||
// with a memory barrier before the pass's first draw or none. Else, after such a barrier,
|
||||
// which puts the pass's load actions before the draw, it records into an instance after
|
||||
// the pass's first, which runs the clear, and the copy is taken between; with no barrier
|
||||
// it reads the copy taken before the pass.
|
||||
let attached = !self.replaying
|
||||
&& snapshot.is_none()
|
||||
&& self.samples_attachment(&facts, Texture::attached_among);
|
||||
let behind_loads = attached
|
||||
&& self.loads_ordered
|
||||
&& self.samples_attachment(&facts, Texture::cleared_among);
|
||||
let clears = attached && self.samples_attachment(&facts, Texture::cleared_among);
|
||||
let copy_clears = clears.then(|| self.cleared_copies(&facts, call)).flatten();
|
||||
let behind_loads = clears && self.loads_ordered && copy_clears.is_none();
|
||||
// Such a draw keeps nothing to draw again: its copy's clear, or its split, is its own
|
||||
// (`render/draw_again.rs`).
|
||||
let reads_clear = behind_loads;
|
||||
// Where each such color's copy can be cleared to the clear instead, before any draw of the
|
||||
// pass, the draw stays in its instance and reads it there (`texture/attached_reads.rs`).
|
||||
let copy_clears = behind_loads
|
||||
.then(|| self.cleared_copies(&facts, call))
|
||||
.flatten();
|
||||
let behind_loads = behind_loads && copy_clears.is_none();
|
||||
let reads_clear = behind_loads || copy_clears.is_some();
|
||||
// A draw after a barrier inside the instance that reads nothing the instance drew reads
|
||||
// the copy taken before the instance, which holds what a split's would.
|
||||
let inside = attached && self.current.barriers && !self.barrier && !behind_loads;
|
||||
|
||||
@@ -83,8 +83,7 @@ fn device(cache: &Path) -> Device {
|
||||
|
||||
/// The fixture's state of `tob_rect` and `fragment`, one `RGBA8Unorm` target.
|
||||
fn state(device: &Device, fragment: &str) -> RenderPipelineState {
|
||||
let ll = Path::new(env!("CARGO_MANIFEST_DIR"))
|
||||
.join("../metal2vulkan-validation/fixtures/public/engine/tob_renders.ll");
|
||||
let ll = metal2vulkan_devtools::engine_dir().join("tob_renders.ll");
|
||||
let bitcode = metal2vulkan_devtools::llvm_assemble(&ll).unwrap();
|
||||
let library = metal2vulkan::library::Library::from_air(&bitcode).unwrap();
|
||||
let library = device.new_library_with_compile_library(library);
|
||||
|
||||
@@ -71,8 +71,7 @@ fn device(cache: &Path) -> Device {
|
||||
|
||||
/// The fixture's state of `tob_rect` and `fragment`, one `RGBA8Unorm` target.
|
||||
fn state(device: &Device, fragment: &str) -> RenderPipelineState {
|
||||
let ll = Path::new(env!("CARGO_MANIFEST_DIR"))
|
||||
.join("../metal2vulkan-validation/fixtures/public/engine/tob_renders.ll");
|
||||
let ll = metal2vulkan_devtools::engine_dir().join("tob_renders.ll");
|
||||
let bitcode = metal2vulkan_devtools::llvm_assemble(&ll).unwrap();
|
||||
let library = metal2vulkan::library::Library::from_air(&bitcode).unwrap();
|
||||
let library = device.new_library_with_compile_library(library);
|
||||
|
||||
@@ -71,10 +71,15 @@
|
||||
//! scissors where it reads the texture at its fragments' own pixels alone, below; else every
|
||||
//! one). The copy taken before the instance then holds each of them as the split's would, and
|
||||
//! the draw stays in the instance and reads it.
|
||||
//! - **After a memory barrier before the pass's first draw.** Such a barrier orders the pass's
|
||||
//! load actions before the draws after it (`fence.rs`): a draw after it that samples the
|
||||
//! texture of a color the pass clears ([`Texture::cleared_in`]) reads the clear on a Mac2 GPU,
|
||||
//! where the copy taken ahead of the pass's load actions holds the texels from before the pass.
|
||||
//! - **A color the pass clears.** Before any draw of the pass has recorded, a draw that samples
|
||||
//! the texture of a color the pass clears ([`Texture::cleared_in`]) reads the clear on both
|
||||
//! x86 Macs (probe `ownread` above: no draw before it, so what the load and the draws before it
|
||||
//! wrote is the clear), and on a Mac2 GPU after a memory barrier before the pass's first draw,
|
||||
//! which orders the pass's load actions before the draws after it (`fence.rs`); an M3 Max with
|
||||
//! no barrier read the texels from before the pass. The Macs disagree, the macOS guests the
|
||||
//! runtime serves are x86 ones, and a clear of the copy costs less than a copy of the texture,
|
||||
//! so the runtime takes the clear where it can, with a barrier before the draw or none, where
|
||||
//! the copy taken ahead of the pass's load actions would hold the texels from before the pass.
|
||||
//! Before any draw of the pass has recorded, the copy holds nothing but the clear there, so
|
||||
//! where it can be cleared to it ([`Texture::cleared_copy`]: the copy is an image of its own,
|
||||
//! the texture a single-sampled 2D one of one level and slice that one color renders whole, in
|
||||
@@ -87,12 +92,13 @@
|
||||
//! instance (`WorkCounts::attachment_read_clears`): no instance of the clear alone, no store and
|
||||
//! load of the attachment between two, and no copy. Later draws of that instance read the same
|
||||
//! copy, as they would read the copy after the clear's instance. Otherwise, and once a draw has
|
||||
//! recorded (it may have written the attachment, which the copy must then hold), it records
|
||||
//! into an instance after the pass's first, which runs the pass's load actions and draws
|
||||
//! nothing where no draw came before (`render.rs`, `WorkCounts::attachment_read_splits`),
|
||||
//! before which the copy is taken, or reads through snapshots inside its instance (below). A
|
||||
//! draw that samples a color the pass loads, or none, records as with no barrier: the copy
|
||||
//! ahead of the load holds what it loads.
|
||||
//! recorded (it may have written the attachment, which the copy must then hold), a draw after
|
||||
//! such a barrier records into an instance after the pass's first, which runs the pass's load
|
||||
//! actions and draws nothing where no draw came before (`render.rs`,
|
||||
//! `WorkCounts::attachment_read_splits`), before which the copy is taken, or reads through
|
||||
//! snapshots inside its instance (below); one with no barrier before it reads the copy taken
|
||||
//! ahead of the load, the M3 Max's answer. A draw that samples a color the pass loads, or none,
|
||||
//! records as with no barrier: the copy ahead of the load holds what it loads.
|
||||
//! - **The copy** is the texture's shadow, an image of its own, whose truth is the texture's
|
||||
//! image or its buffer's bytes. The pass's shadow plan (`render/shadows.rs`) copies the truth
|
||||
//! in before each instance whose draws read the shadow, after the instances before it wrote
|
||||
@@ -331,8 +337,8 @@ impl Texture {
|
||||
|
||||
/// Whether the texture presents a level and layer that a color attachment of `layout`'s
|
||||
/// instance whose load action clears it renders, as [`attached_in`](Self::attached_in) tells:
|
||||
/// what a draw after a memory barrier before the pass's first draw reads of it is the clear
|
||||
/// (the module docs).
|
||||
/// what a draw before any draw of the pass, or after a memory barrier before the pass's first
|
||||
/// draw, reads of it is the clear (the module docs).
|
||||
pub(crate) fn cleared_in(&self, layout: &PassLayout) -> bool {
|
||||
self.cleared_among(&AttachedColors::of(layout))
|
||||
}
|
||||
@@ -360,8 +366,9 @@ impl Texture {
|
||||
}
|
||||
|
||||
/// The copy a sampled slot binding of the texture by the draw `call` reads, and the clear it
|
||||
/// reads there, after a memory barrier before its pass's first draw and before any draw of the
|
||||
/// pass, where that copy may be cleared to it instead of the pass splitting (the module docs):
|
||||
/// reads there, before any draw of the pass, where that copy may be cleared to it instead of
|
||||
/// holding the texels from before the pass, or, after a memory barrier before the pass's first
|
||||
/// draw, instead of the pass splitting (the module docs):
|
||||
/// the texture's shadow, made here where the draw's binding has not made it yet
|
||||
/// ([`attached_shadow_copies`](Self::attached_shadow_copies)), is an image of its own that a
|
||||
/// clear in clears (`ShadowCopies::cleared_image`), and the texture a
|
||||
|
||||
@@ -55,9 +55,12 @@
|
||||
//! - [`a_draw_after_one_that_wrote_behind_a_pass_start_barrier_reads_what_it_wrote`]: the same
|
||||
//! with draw A between the barrier and the read reads A's red inside A's block, the clear
|
||||
//! around it, and takes no cleared copy.
|
||||
//! - [`a_draw_after_a_clear_with_no_barrier_reads_the_texels_from_before_the_pass`]: the same with
|
||||
//! no barrier reads the red from before the pass, with no split; or the clear, where the
|
||||
//! runtime reads `psb_read` over a buffer's bytes through a snapshot.
|
||||
//! - [`a_first_draw_with_no_barrier_reads_its_pass_s_load`]: the same with no barrier, in a pass
|
||||
//! that loads the target and in one that clears it: it reads the red from before the pass where
|
||||
//! the pass loads it, and the clear where it clears it, through its copy cleared to it in the
|
||||
//! pass's first instance (`attachment_read_clears`, which the texture of its own image always
|
||||
//! takes) or through a snapshot, with no split; or, where neither (a copy not cleared so, on a
|
||||
//! device without the snapshot route), the red from before the pass, the M3 Max's answer.
|
||||
//! - [`a_barrier_at_the_pass_start_costs_nothing_without_a_read_of_a_cleared_color`]: a pass that
|
||||
//! loads the target and reads it after the barrier, or clears it and reads another texture,
|
||||
//! splits nothing and begins as many instances and takes as many copies and snapshots as the
|
||||
@@ -302,8 +305,12 @@ fn check(name: &str, moved: &Moved, barriers: u64) {
|
||||
);
|
||||
return;
|
||||
}
|
||||
// With no barrier, a snapshot takes no split's place.
|
||||
let unordered = if barriers == 0 { moved.snapshotted } else { 0 };
|
||||
// With no barrier, a snapshot or a cleared copy takes no split's place.
|
||||
let unordered = if barriers == 0 {
|
||||
moved.snapshotted + moved.cleared
|
||||
} else {
|
||||
0
|
||||
};
|
||||
assert_eq!(
|
||||
moved.splits + moved.cleared + moved.snapshotted,
|
||||
barriers + unordered,
|
||||
@@ -1090,51 +1097,74 @@ fn a_draw_after_a_barrier_at_the_pass_start_reads_the_clear() {
|
||||
});
|
||||
}
|
||||
|
||||
/// With no barrier, the draw of a pass that clears its target reads the texels from before the
|
||||
/// pass at its own pixel through the copy, the M3 Max's answer (probe `selfsample`; it reads them
|
||||
/// after a barrier too), with no split; or, where the runtime reads `psb_read` through a snapshot
|
||||
/// (over a buffer's bytes, on a device with the snapshot route), the clear, an x86 Mac's answer
|
||||
/// (`docs/API.md`'s accepted differences).
|
||||
/// With no barrier, the pass's first draw reads, at its own pixel (`psb_read`) or sampling at its
|
||||
/// pixel's center (`psb_sample`), what the pass's load wrote: the red from before the pass where
|
||||
/// it loads the target, through the copy taken before the pass or a snapshot; and the clear where
|
||||
/// it clears it, through its copy cleared to the clear in the pass's first instance
|
||||
/// (`attachment_read_clears`), as both x86 Macs read a first draw's pixels there, or through a
|
||||
/// snapshot (over a buffer's bytes, on a device with the snapshot route), with no split. The
|
||||
/// texture of its own image, which takes no snapshot through [`READ_AREA`]'s small scissor (the
|
||||
/// area rule, `render/snapshot.rs`), always takes the cleared copy, and one over a buffer's bytes
|
||||
/// where its copy can be cleared so; where neither holds, it reads the red from before the pass,
|
||||
/// the M3 Max's answer (`docs/API.md`'s accepted differences).
|
||||
#[test]
|
||||
fn a_draw_after_a_clear_with_no_barrier_reads_the_texels_from_before_the_pass() {
|
||||
fn a_first_draw_with_no_barrier_reads_its_pass_s_load() {
|
||||
on_device(|device, _messages| {
|
||||
let queue = device.new_command_queue().unwrap();
|
||||
for fragment in ["psb_read", "psb_sample"] {
|
||||
let state = psb_state(device, fragment);
|
||||
for (name, target, _buffer) in targets(device) {
|
||||
let name = format!("{name}, {fragment}");
|
||||
let counted = device.work_counts();
|
||||
let bytes = started_pass(
|
||||
&queue,
|
||||
&target,
|
||||
(LoadAction::Clear, Start::Nothing, None),
|
||||
(&state, &target),
|
||||
);
|
||||
let after = device.work_counts();
|
||||
let moved = moved(&counted, &after);
|
||||
assert!(
|
||||
moved.snapshotted == 0
|
||||
|| (name.starts_with("over a buffer") && fragment == "psb_read"),
|
||||
"{name}: a snapshot"
|
||||
);
|
||||
let seen = match moved.snapshotted {
|
||||
0 => [BEFORE, 0, 0, 255],
|
||||
_ => CLEAR,
|
||||
};
|
||||
hold_area(&name, &bytes, reordered(seen), CLEAR);
|
||||
check(&name, &moved, 0);
|
||||
assert_eq!(instances(&counted, &after)[0], 0, "{name}: a split");
|
||||
for load in [LoadAction::Load, LoadAction::Clear] {
|
||||
for fragment in ["psb_read", "psb_sample"] {
|
||||
let state = psb_state(device, fragment);
|
||||
for (name, target, _buffer) in targets(device) {
|
||||
let name = format!("{name}, {fragment}, {load:?}");
|
||||
let counted = device.work_counts();
|
||||
let bytes = started_pass(
|
||||
&queue,
|
||||
&target,
|
||||
(load, Start::Nothing, None),
|
||||
(&state, &target),
|
||||
);
|
||||
let after = device.work_counts();
|
||||
let moved = moved(&counted, &after);
|
||||
assert!(
|
||||
moved.snapshotted == 0
|
||||
|| (name.starts_with("over a buffer") && fragment == "psb_read"),
|
||||
"{name}: a snapshot"
|
||||
);
|
||||
// The texture of its own image takes the cleared copy wherever the pass
|
||||
// clears it; one over a buffer's bytes where its copy can be cleared so (a
|
||||
// snapshot in its place where the device takes one).
|
||||
let own = name.starts_with("its own image");
|
||||
let clears = load == LoadAction::Clear;
|
||||
if clears && own {
|
||||
assert_eq!(moved.cleared, 1, "{name}: the copy cleared to the clear");
|
||||
}
|
||||
if !clears {
|
||||
assert_eq!(
|
||||
moved.cleared, 0,
|
||||
"{name}: a copy cleared in a pass that loads"
|
||||
);
|
||||
}
|
||||
let before = [BEFORE, 0, 0, 255];
|
||||
let (seen, outside) = match load {
|
||||
LoadAction::Clear if moved.cleared + moved.snapshotted > 0 => {
|
||||
(CLEAR, CLEAR)
|
||||
}
|
||||
LoadAction::Clear => (before, CLEAR),
|
||||
_ => (before, before),
|
||||
};
|
||||
eprintln!(
|
||||
"first draw reads, {name}: cleared copies {}, snapshotted {}",
|
||||
moved.cleared, moved.snapshotted
|
||||
);
|
||||
hold_area(&name, &bytes, reordered(seen), outside);
|
||||
check(&name, &moved, 0);
|
||||
assert_eq!(instances(&counted, &after)[0], 0, "{name}: a split");
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// After a memory barrier at the start of a pass that clears its target, draw A fills its block,
|
||||
/// then the draw reads the target through [`READ_AREA`]: it reads A's red inside A's block and the
|
||||
/// clear around it, as the copy after the instance A drew in holds (a Mac2 GPU orders A's write
|
||||
/// before the read nowhere; the copy holds what the draws between the barrier and the read
|
||||
/// wrote, `texture/attached_reads.rs`). A drew before it, so its copy is no copy cleared to the
|
||||
/// clear (`attachment_read_clears`), but a split's or a snapshot.
|
||||
#[test]
|
||||
fn a_draw_after_one_that_wrote_behind_a_pass_start_barrier_reads_what_it_wrote() {
|
||||
on_device(|device, _messages| {
|
||||
|
||||
@@ -187,7 +187,6 @@ use metal2vulkan_runtime::{
|
||||
VkImageLayouts,
|
||||
};
|
||||
use std::collections::BTreeSet;
|
||||
use std::path::Path;
|
||||
|
||||
/// The fullscreen triangle's depth.
|
||||
const Z: f32 = 0.5;
|
||||
@@ -202,9 +201,7 @@ fn library(lane: &Lane, stem: &str) -> Library {
|
||||
|
||||
/// The engine fixture `stem`'s library on `device`.
|
||||
fn fixture(device: &Device, stem: &str) -> Library {
|
||||
let ll = Path::new(env!("CARGO_MANIFEST_DIR"))
|
||||
.join("fixtures/public/engine")
|
||||
.join(format!("{stem}.ll"));
|
||||
let ll = metal2vulkan_devtools::engine_dir().join(format!("{stem}.ll"));
|
||||
let bitcode = llvm_assemble(&ll).unwrap();
|
||||
device.new_library_with_air(&bitcode).unwrap()
|
||||
}
|
||||
@@ -564,6 +561,38 @@ fn fetches_read_every_earlier_fragment_of_the_pixel() {
|
||||
quiet(lane, &messages);
|
||||
}
|
||||
|
||||
/// A pass's first draw that fetches its color reads what the pass's load wrote: the clear, in a
|
||||
/// pass that clears a target holding other texels from before it. `fetch_scalar` halves what it
|
||||
/// fetched, so the pass before, cleared to 0.5, leaves 0.25, and the pass that clears it to 0.75
|
||||
/// leaves 0.375, where a fetch of the texels from before the pass would leave 0.125.
|
||||
#[test]
|
||||
fn a_first_fetch_after_a_clear_reads_the_clear() {
|
||||
let (messages, cache, lane) = lane();
|
||||
if !fetches(&lane.device) {
|
||||
return;
|
||||
}
|
||||
let vertices = library(&lane, "rt6_resolves");
|
||||
let fetch = library(&lane, "fragment_fetch");
|
||||
let pf = PixelFormat::R32Float;
|
||||
let ran = (|| {
|
||||
let halve = pipeline(&lane, &vertices, (&fetch, "fetch_scalar"), &[pf], 1)?;
|
||||
let target = lane.texture(pf, ONE, TextureUsage::RENDER_TARGET);
|
||||
for clear in [0.5, 0.75] {
|
||||
let targets = [(
|
||||
&target,
|
||||
ClearColor::new(clear, 0.0, 0.0, 0.0),
|
||||
StoreAction::Store,
|
||||
)];
|
||||
steps(&lane, &pass(&targets, None), &[&halve])?;
|
||||
}
|
||||
Ok(lane.read(&target, (0, 0), 4, BlitOption::None))
|
||||
})();
|
||||
let halved = 0.375f32.to_le_bytes().repeat(TEXELS);
|
||||
expect(&lane, "a first fetch after a clear", ran, &halved);
|
||||
drop(cache);
|
||||
quiet(lane, &messages);
|
||||
}
|
||||
|
||||
/// Three integer read-modify-writes of the pixel, one a draw, in order (the module docs).
|
||||
#[test]
|
||||
fn integer_read_modify_writes_follow_draw_order() {
|
||||
|
||||
@@ -117,7 +117,6 @@ use metal2vulkan_runtime::{
|
||||
RenderPassDescriptor, RenderPipelineState, ResourceOptions, ScissorRect, Size, StoreAction,
|
||||
Texture, TextureDescriptor, WorkCounts,
|
||||
};
|
||||
use std::path::Path;
|
||||
use std::sync::atomic::Ordering;
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
@@ -695,7 +694,7 @@ fn a_blend_beside_a_stencil_attachment_renders_the_linear_texture_apart() {
|
||||
|
||||
/// The owned fixture `zwd_shapes`' library on `device`.
|
||||
fn zwd_library(device: &Device) -> metal2vulkan_runtime::Library {
|
||||
let ll = Path::new(env!("CARGO_MANIFEST_DIR")).join("fixtures/public/engine/zwd_shapes.ll");
|
||||
let ll = metal2vulkan_devtools::engine_dir().join("zwd_shapes.ll");
|
||||
device
|
||||
.new_library_with_air(&llvm_assemble(&ll).unwrap())
|
||||
.unwrap()
|
||||
|
||||
@@ -68,7 +68,6 @@ use metal2vulkan_runtime::{
|
||||
Origin, PipelineOptions, RenderPassDescriptor, RenderPipelineState, ResourceOptions, Size,
|
||||
StoreAction, Texture, TextureDescriptor,
|
||||
};
|
||||
use std::path::Path;
|
||||
use std::time::Instant;
|
||||
|
||||
/// The consumer's display surface's size.
|
||||
@@ -728,7 +727,7 @@ pub(super) fn blending_beside_scratch(
|
||||
|
||||
/// [`rects`]'s pipeline descriptor.
|
||||
fn rects_descriptor(device: &Device, pf: PixelFormat, blends: bool) -> RenderPipelineDescriptor {
|
||||
let ll = Path::new(env!("CARGO_MANIFEST_DIR")).join("fixtures/public/engine/tob_renders.ll");
|
||||
let ll = metal2vulkan_devtools::engine_dir().join("tob_renders.ll");
|
||||
let library = device
|
||||
.new_library_with_air(&llvm_assemble(&ll).unwrap())
|
||||
.unwrap();
|
||||
|
||||
@@ -44,7 +44,6 @@ use metal2vulkan_runtime::{
|
||||
ResourceOptions, RuntimeGap, Size, StoreAction, Texture, TextureDescriptor,
|
||||
};
|
||||
use std::cell::RefCell;
|
||||
use std::path::Path;
|
||||
|
||||
/// The lane's device, queue and the fixture's library (`memoryless.rs` draws with them too).
|
||||
pub(super) struct Lane {
|
||||
@@ -63,7 +62,7 @@ pub(super) fn lane_with(adjust: impl FnOnce(&mut DeviceOptions)) -> (Messages, S
|
||||
let messages = Messages::default();
|
||||
let cache = ScratchCache::new().unwrap();
|
||||
let device = validated_device_with(TEST_DEVICE, &messages, cache.path(), adjust).unwrap();
|
||||
let ll = Path::new(env!("CARGO_MANIFEST_DIR")).join("fixtures/public/engine/rt6_resolves.ll");
|
||||
let ll = metal2vulkan_devtools::engine_dir().join("rt6_resolves.ll");
|
||||
let bitcode = llvm_assemble(&ll).unwrap();
|
||||
let lane = Lane {
|
||||
queue: device.new_command_queue().unwrap(),
|
||||
|
||||
@@ -30,7 +30,11 @@
|
||||
//! the reader once more: `3 * FILL`, then `6 * FILL`. A read of the attachment itself would
|
||||
//! race with the draw's own color writes, the second primitive reading the first's (`4 * FILL`).
|
||||
//! Where the pass's first instance recorded inline, the instance the first reader splits off it
|
||||
//! records inline too, and the second reader into it (`WorkCounts::inline_split_instances`).
|
||||
//! records inline too, and the second reader into it (`WorkCounts::inline_split_instances`): an
|
||||
//! instance after a split records inline only for a draw whose pipeline is made as it draws
|
||||
//! (`render/inline_splits.rs`), so the pass follows a first one of the same states over a
|
||||
//! target of its own, whose command buffer completes once their pipelines are made, and no
|
||||
//! draw of the pass hands its pipeline to the device's pool (`WorkCounts::pipelines_pooled`).
|
||||
//! - [`a_reader_that_discards_by_its_texel_takes_the_snapshot`]: the first test's draws with a
|
||||
//! reader that discards its fragment where the texel it read is redder than 0.4
|
||||
//! (`sd_read_discarding` of `snapshot_discard.metal`): the first reader adds `FILL` twice
|
||||
@@ -199,7 +203,8 @@ fn state_in(
|
||||
|
||||
/// What the pass moved of the counts: reads through snapshots, of them those recorded into a
|
||||
/// new instance as their own recorded inline, the instances after a split recorded inline too
|
||||
/// (`render/inline_splits.rs`), splits for attachment reads, and reads through copies.
|
||||
/// (`render/inline_splits.rs`), splits for attachment reads, reads through copies, and draws that
|
||||
/// handed the making of their pipeline to the device's pool.
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
struct Moved {
|
||||
snapshotted: u64,
|
||||
@@ -207,6 +212,7 @@ struct Moved {
|
||||
inline_instances: u64,
|
||||
splits: u64,
|
||||
copies: u64,
|
||||
pooled: u64,
|
||||
}
|
||||
|
||||
fn moved(before: &WorkCounts, after: &WorkCounts) -> Moved {
|
||||
@@ -216,6 +222,7 @@ fn moved(before: &WorkCounts, after: &WorkCounts) -> Moved {
|
||||
inline_instances: after.inline_split_instances - before.inline_split_instances,
|
||||
splits: after.attachment_read_splits - before.attachment_read_splits,
|
||||
copies: after.attachment_reads_through_copies - before.attachment_reads_through_copies,
|
||||
pooled: after.pipelines_pooled - before.pipelines_pooled,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -244,6 +251,35 @@ fn readers(
|
||||
(bytes, moved)
|
||||
}
|
||||
|
||||
/// [`readers`]' pass with barriers, through the whole target's scissor, after a first one of the
|
||||
/// same states over a target of its own: its command buffer completes once the pipelines its
|
||||
/// draws took are made, which the second pass's draws find made.
|
||||
fn readers_warm(device: &Device, queue: &CommandQueue, format: PixelFormat) -> (Vec<u8>, Moved) {
|
||||
let states = (
|
||||
state(device, SOLID, false, format),
|
||||
state(device, READ, true, format),
|
||||
);
|
||||
readers_with(
|
||||
device,
|
||||
queue,
|
||||
(&states.0, &states.1),
|
||||
format,
|
||||
true,
|
||||
None,
|
||||
false,
|
||||
);
|
||||
let (bytes, moved, _) = readers_with(
|
||||
device,
|
||||
queue,
|
||||
(&states.0, &states.1),
|
||||
format,
|
||||
true,
|
||||
None,
|
||||
false,
|
||||
);
|
||||
(bytes, moved)
|
||||
}
|
||||
|
||||
/// How [`readers_over`]' target was made: whether the image its passes render took feedback loop
|
||||
/// usage (`WorkCounts::feedback_loop_alias_images` for an image aliasing its bytes, or
|
||||
/// `feedback_loop_shadow_images` for a shadow), and whether a snapshot's fetch reads it there: a
|
||||
@@ -271,6 +307,27 @@ fn readers_over(
|
||||
) -> (Vec<u8>, Moved, Made) {
|
||||
let fill = state(device, SOLID, false, format);
|
||||
let read = state(device, reader, true, format);
|
||||
readers_with(
|
||||
device,
|
||||
queue,
|
||||
(&fill, &read),
|
||||
format,
|
||||
barriers,
|
||||
scissor,
|
||||
surface,
|
||||
)
|
||||
}
|
||||
|
||||
/// [`readers_over`]' pass of the states `(fill, read)`, over a new target.
|
||||
fn readers_with(
|
||||
device: &Device,
|
||||
queue: &CommandQueue,
|
||||
(fill, read): (&RenderPipelineState, &RenderPipelineState),
|
||||
format: PixelFormat,
|
||||
barriers: bool,
|
||||
scissor: Option<[u64; 4]>,
|
||||
surface: bool,
|
||||
) -> (Vec<u8>, Moved, Made) {
|
||||
let mut d = TextureDescriptor::texture_2d(format, SIDE, SIDE, false);
|
||||
d.usage = TextureUsage::RENDER_TARGET | TextureUsage::SHADER_READ;
|
||||
d.resource_options = ResourceOptions::private();
|
||||
@@ -328,7 +385,7 @@ fn readers_over(
|
||||
pass.color_attachments[0].load_action = LoadAction::Load;
|
||||
let counted = device.work_counts();
|
||||
let mut encoder = command_buffer.render_command_encoder(&pass).unwrap();
|
||||
encoder.set_render_pipeline_state(&fill).unwrap();
|
||||
encoder.set_render_pipeline_state(fill).unwrap();
|
||||
encoder.set_vertex_bytes(&corners(BLOCK), 0).unwrap();
|
||||
let red = f32::from(FILL) / 255.0;
|
||||
encoder
|
||||
@@ -337,7 +394,7 @@ fn readers_over(
|
||||
encoder
|
||||
.draw_primitives(PrimitiveType::Triangle, 0, 6, 1, 0)
|
||||
.unwrap();
|
||||
encoder.set_render_pipeline_state(&read).unwrap();
|
||||
encoder.set_render_pipeline_state(read).unwrap();
|
||||
encoder.set_fragment_texture(Some(&target), 0).unwrap();
|
||||
if let Some([x0, y0, x1, y1]) = scissor {
|
||||
let rect = ScissorRect {
|
||||
@@ -536,7 +593,7 @@ fn overlapping_primitives_read_what_the_draws_before_the_barrier_wrote() {
|
||||
},
|
||||
|device, _messages| {
|
||||
let queue = device.new_command_queue().unwrap();
|
||||
let (bytes, moved) = readers(device, &queue, PixelFormat::RGBA8Unorm, true, None);
|
||||
let (bytes, moved) = readers_warm(device, &queue, PixelFormat::RGBA8Unorm);
|
||||
let takes = snapshots(device);
|
||||
eprintln!("snapshot reads, features {takes}, exact {exact}: {moved:?}");
|
||||
holds("after barriers", &bytes, 6 * FILL);
|
||||
@@ -549,7 +606,12 @@ fn overlapping_primitives_read_what_the_draws_before_the_barrier_wrote() {
|
||||
assert_eq!(moved.splits, 0, "exact {exact}: splits");
|
||||
assert!(moved.inline_splits <= 1, "exact {exact}: inline splits");
|
||||
// The instance the first reader split off an inline one records inline too,
|
||||
// and the second reader records into it (`render/inline_splits.rs`).
|
||||
// and the second reader records into it (`render/inline_splits.rs`): their
|
||||
// pipelines made by the pass before.
|
||||
assert_eq!(
|
||||
moved.pooled, 0,
|
||||
"exact {exact}: draws making their pipelines"
|
||||
);
|
||||
assert_eq!(
|
||||
moved.inline_instances, moved.inline_splits,
|
||||
"exact {exact}: instances after an inline one recorded inline"
|
||||
|
||||
@@ -57,7 +57,6 @@ use metal2vulkan_runtime::{
|
||||
StoreAction, Texture, TextureDescriptor,
|
||||
};
|
||||
use sha2::{Digest, Sha256};
|
||||
use std::path::Path;
|
||||
|
||||
/// The surface's size, its rows' bytes, and its bytes.
|
||||
const W: usize = 1920;
|
||||
@@ -370,7 +369,7 @@ fn pipeline(
|
||||
fragment: &str,
|
||||
blends: bool,
|
||||
) -> Result<RenderPipelineState, metal2vulkan_runtime::Error> {
|
||||
let ll = Path::new(env!("CARGO_MANIFEST_DIR")).join("fixtures/public/engine/zws_compositor.ll");
|
||||
let ll = metal2vulkan_devtools::engine_dir().join("zws_compositor.ll");
|
||||
let library = device
|
||||
.new_library_with_air(&llvm_assemble(&ll).unwrap())
|
||||
.unwrap();
|
||||
|
||||
Vendored
+1
-1
@@ -94,7 +94,7 @@ pub const ARTIFACT_FORMAT_VERSION: u32 = 523;
|
||||
/// 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 = 2336;
|
||||
pub const RUNTIME_VERSION: u32 = 2337;
|
||||
|
||||
/// 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
|
||||
|
||||
+8
-1
@@ -5513,7 +5513,8 @@ each item named states the rule in full.
|
||||
pass's first instance, where the copy can be so (`WorkCounts::attachment_read_clears`), else
|
||||
an instance after one of the clear alone. With no
|
||||
barrier a draw reads at its own pixel what the draws before it wrote where the runtime takes no
|
||||
copy for it, else the texels from before the pass, the M3 Max's answer (below). The
|
||||
copy for it; else, before any draw of a pass that clears the color, the clear where its copy can
|
||||
be cleared to it, and otherwise the texels from before the pass, the M3 Max's answer (below). The
|
||||
conformance cases `pass-start-barrier-*` keep the M3 Max's texels and take the Mac2 answer as
|
||||
the one other, and their rows that read at their own pixels with no barrier the clear (below).
|
||||
- **A draw that reads its own pass's color attachment at its own pixels reads what the draws
|
||||
@@ -5537,6 +5538,12 @@ each item named states the rule in full.
|
||||
large scissors alone (`WorkCounts::reading_draws_snapshotted`). On a Radeon 780M a
|
||||
compositor's frame of six such readers over surfaces took 3.41 ms of GPU time against 4.07
|
||||
with the copies;
|
||||
- a draw before any draw of a pass that clears the color reads a copy cleared to the clear,
|
||||
where the copy can be so (`Texture::cleared_copy`: a whole single-sampled 2D texture of one
|
||||
level and slice that one color renders in place; `WorkCounts::attachment_read_clears`): what
|
||||
both x86 Macs read at such a draw's pixels, as the load and no draw before it wrote only the
|
||||
clear there, the answer x86 macOS guests are written against, and a clear of the copy costs
|
||||
less than a copy of the texture;
|
||||
- every other such draw reads a copy taken before the pass, the M3 Max's answer: a private
|
||||
texture's reader through small scissors, and every reader on lavapipe (which has
|
||||
rasterization-order access) or on a device without the interlock, such as the Radeon RX 550
|
||||
|
||||
Reference in new issue
Block a user