Weigh a self-read's split by the texels its copy moves

The area rule (render/snapshot.rs) weighed the split as a copy of every texel of the color's
level. The split's copy for a draw that reads at its own pixels is cut: for a one-level,
one-slice color it moves only the texels inside the rectangle bounding the draw's scissors, a
pixel wider each way (render.rs's bound_own_pixel_reads, ShadowCopies::cuts). So the rule
overstated the split for readers through scissors smaller than the target, and since 61a367cb51
those took the snapshot where the split was the cheaper worst case: on the snapshot_crossover
lane's 1920x1080 private target, readers through 960x540 and 1280x720 scissors covering them
whole took up to 1.93x and 1.97x their split time on the Radeon 780M, and 1.32x and 1.41x on the
RX 7900 XTX (jobs 6872, 6871 against their own before runs).

The rule now weighs the split by what its copy moves, computed by the same two functions the copy
bound uses, now shared (scissors_bound, own_pixel_loads): a one-level, one-slice color's texels
around the scissors, else every texel of the level, as before. A reader through no scissor, the
consumer's self-reads, weighs as before and keeps the snapshot. By the rule a 4-byte color's
reader takes the snapshot through scissors whose rectangle holds about 786,432 pixels (1024x768)
or more and splits through smaller ones: on the crossover's target, 320x180 and 960x540 split,
1280x720 and the whole target snapshot.

Tests that relied on a small reader taking the snapshot now draw through scissors large enough:
- runtime_lane::snapshot_reads: a 1024x1024 target, the readers through the whole target's
  scissor (snapshot where the device takes the path); through QUARTER an RGBA8Unorm reader splits
  and an RGBA16Float one takes the snapshot; R8Unorm and RG8Unorm readers split; the
  feature-withheld and depth/stencil readers through the whole target, so their split is the
  feature's or the attachment's, not the rule's.
- tests::self_read_storage: a 1024x1024 target, the reader through no scissor.
- tests::snapshot_area: 8x8 scissors (copy of 10x10 texels): 4-byte split, 8-byte snapshot;
  960x540 split and 1280x720 snapshot over 1920x1080.
- attachment_read_costs: the composite workload's window readers split again; its docs say so.

docs/FAST-PATHS.md's attachment-read paragraph and the module docs carry the landed
snapshot_area_costs lane's numbers (rule against the split with fragmentShaderPixelInterlock
withheld): reader over 1.5% / the whole target, Radeon 780M 0.08-0.23x / 1.8-2.3x (job 6872),
RX 7900 XTX 0.25-0.43x / 1.3-2.1x (6871).

(cherry picked from commit ed15457d04c98f767511374ff4d368a0373a4361)
This commit is contained in:
Anees Iqbal committed 2026-11-07 23:05:20 -08:00
1 parent 20038c5c45
commit 37875af7f3
7 files changed
+179 -123

No files matched your search

+42 -24
View File
@@ -7185,25 +7185,8 @@ impl RenderLowering {
let rects = self
.state
.vk_scissors_in(&self.scissors, selects, &mut scissors);
let mut drawn: Option<[u32; 4]> = None;
for r in rects
.iter()
.filter(|r| r.extent.width > 0 && r.extent.height > 0)
{
let (x, y) = (r.offset.x.max(0) as u32, r.offset.y.max(0) as u32);
let rect = [x, y, x + r.extent.width, y + r.extent.height];
drawn = Some(match drawn {
Some([a, b, c, d]) => [
a.min(rect[0]),
b.min(rect[1]),
c.max(rect[2]),
d.max(rect[3]),
],
None => rect,
});
}
// A draw of no pixel reads nothing: its copy is left as it was.
let Some([x0, y0, x1, y1]) = drawn else {
let Some(drawn) = scissors_bound(rects) else {
return false;
};
let mut bounded = false;
@@ -7245,13 +7228,10 @@ impl RenderLowering {
let Some(texture) = texture.filter(|t| own && t.attached_in(&self.layout)) else {
continue;
};
let (w, h) = (texture.width() as u32, texture.height() as u32);
if w == 0 || h == 0 {
let Some(loads) = own_pixel_loads(drawn, texture) else {
continue;
}
let lo = |p: u32, side: u32| p.saturating_sub(1).min(side - 1);
let hi = |p: u32, side: u32| (p + 1).min(side);
used.loads = Some([lo(x0, w), lo(y0, h), hi(x1, w), hi(y1, h)]);
};
used.loads = Some(loads);
bounded = true;
}
bounded
@@ -13101,6 +13081,44 @@ fn late_store(
Ok(action)
}
/// The rectangle `[x0, y0, x1, y1)` bounding the pixels of `rects` (a draw's Vulkan scissors),
/// those of no pixel left out: `None` where none has one.
fn scissors_bound(rects: &[vk::Rect2D]) -> Option<[u32; 4]> {
let mut drawn: Option<[u32; 4]> = None;
for r in rects
.iter()
.filter(|r| r.extent.width > 0 && r.extent.height > 0)
{
let (x, y) = (r.offset.x.max(0) as u32, r.offset.y.max(0) as u32);
let rect = [x, y, x + r.extent.width, y + r.extent.height];
drawn = Some(match drawn {
Some([a, b, c, d]) => [
a.min(rect[0]),
b.min(rect[1]),
c.max(rect[2]),
d.max(rect[3]),
],
None => rect,
});
}
drawn
}
/// The texels of `texture` a draw whose scissors `drawn` bounds ([`scissors_bound`]) reads at its
/// fragments' own pixels, `[x0, y0, x1, y1)`: `drawn` widened by a pixel each way, for its helper
/// invocations, and clamped as the read's coordinate is, on each axis
/// `[min(max(x0 - 1, 0), w - 1), min(x1 + 1, w))`, `w` the texture's (`texture/attached_reads.rs`).
/// `None` for a texture of no texel.
fn own_pixel_loads([x0, y0, x1, y1]: [u32; 4], texture: &Texture) -> Option<[u32; 4]> {
let (w, h) = (texture.width() as u32, texture.height() as u32);
if w == 0 || h == 0 {
return None;
}
let lo = |p: u32, side: u32| p.saturating_sub(1).min(side - 1);
let hi = |p: u32, side: u32| (p + 1).min(side);
Some([lo(x0, w), lo(y0, h), hi(x1, w), hi(y1, h)])
}
#[cfg(test)]
mod tests {
use super::{
@@ -101,21 +101,23 @@
//! split copies the color whatever the draw covers. The rule weighs each form at the share least
//! favourable to it, in bytes of the split's copy: the snapshot at [`READER_COST`] and
//! [`SNAPSHOT_PIXEL_COST`] at each pixel its scissors bound, for each color (the draw covering
//! them whole), the split at [`READER_COST`] and its copy of each color's level, its texel bytes
//! each, whatever the snapshot's form (the draw covering nothing). It takes the form whose cost
//! there is the smaller multiple of the other form's: the snapshot where `READER_COST *
//! (READER_COST + pixels * SNAPSHOT_PIXEL_COST) <= (READER_COST + bytes)^2`. A reader whose
//! snapshot costs no more than the split's copy where it covers its scissors whole takes it, as
//! does a reader through scissors of a large color whatever it covers: a 4-byte color's reader,
//! `RGBA8Unorm`'s or `BGRA8Unorm`'s, takes the snapshot through scissors of up to two fifths of
//! its level at any size, and through the whole level from 786,432 pixels (1024x768), an
//! `RGBA16Float` one's through four fifths, and its whole level from 65,536 pixels (256x256),
//! and an `RGBA32Float` one's at any area. On the Iris Xe, the Radeon 780M and the RX 7900 XTX
//! them whole), the split at [`READER_COST`] and its copy (the draw covering nothing): each
//! color's texels its own-pixel reads take, inside the rectangle bounding its scissors a pixel
//! wider each way, where the color is a texture of one level and one slice, whose copy is cut
//! to them (`render.rs`'s `bound_own_pixel_reads`), else every texel of its level, its texel
//! bytes each, whatever the snapshot's form. It takes the form whose cost there is the smaller
//! multiple of the other form's: the snapshot where `READER_COST * (READER_COST + pixels *
//! SNAPSHOT_PIXEL_COST) <= (READER_COST + bytes)^2`. A reader whose snapshot costs no more than
//! the split's copy where it covers its scissors whole takes it, as does a reader through large
//! scissors whatever it covers: a reader of a one-level, one-slice 4-byte color,
//! `RGBA8Unorm`'s or `BGRA8Unorm`'s, takes the snapshot through scissors whose rectangle holds
//! about 786,432 pixels (1024x768) or more, an `RGBA16Float` one's from about 65,536 (256x256),
//! and an `RGBA32Float` one's at any size. On the Radeon 780M and the RX 7900 XTX
//! (`runtime_lane::attachment_read_costs::snapshot_area_costs`, 30 readers a frame over private
//! `BGRA8Unorm` targets of 1280x720 to 3662x2039, no scissor) a reader over 1.5% of the target
//! took 0.09 to 0.43 times the split's GPU time, and one over the whole target 1.04 to 1.28
//! times on the Iris Xe, 2.4 to 2.8 times on the Radeon 780M and 1.3 to 2.1 times on the RX 7900
//! XTX.
//! `BGRA8Unorm` targets of 1280x720 to 3662x2039, no scissor, the split on a device that
//! withholds `fragmentShaderPixelInterlock`) a reader over 1.5% of the target took 0.08 to 0.43
//! times the split's GPU time, and one over the whole target 1.8 to 2.3 times on the Radeon 780M
//! and 1.3 to 2.1 times on the RX 7900 XTX.
//! - **Pins.** A fetch of a color in the pixel interlock reads and writes its image as a storage
//! image, so a later fetch of a color whose image lacks `STORAGE` renders it through a stand-in
//! (`attachment_stand_in.rs`), which the pass's end puts in place for the whole pass, copied in
@@ -153,6 +155,7 @@ use crate::render_values::StoreAction;
use crate::texture::Texture;
use ash::vk;
use metal2vulkan::bind::{BindingPlan, ImageSource, PushHole, WriteSource};
use metal2vulkan::metal::TextureType;
use metal2vulkan::pipeline::{SlotClass, SlotRef, SnapshotForm, Stage};
use std::collections::BTreeSet;
@@ -197,7 +200,8 @@ const SNAPSHOT_PIXEL_COST: u64 = 20;
const READER_COST: u64 = 1 << 20;
/// Whether a draw takes the snapshot by the module docs' area rule: its scissors bound `pixels`
/// pixels over all the colors it reads so, of `bytes` bytes in all in the colors' levels.
/// pixels over all the colors it reads so, and the split's copy of those colors moves `bytes`
/// bytes.
pub(crate) fn snapshot_within(pixels: u64, bytes: u64) -> bool {
let (fixed, pixels, bytes) = (
u128::from(READER_COST),
@@ -461,8 +465,8 @@ impl RenderLowering {
/// [`snapshot_weights`](Self::snapshot_weights); counted by its size where
/// `METAL2VULKAN_LOG_PIPELINES` is set (`reader_sizes.rs`).
fn snapshot_cheaper(&self, pipeline: &DrawingState, colors: &[usize]) -> bool {
let (covered, pixels, bytes) = self.snapshot_weights(pipeline, colors);
let within = self.over_bytes(colors) || snapshot_within(covered, bytes);
let (covered, pixels, bytes, copied) = self.snapshot_weights(pipeline, colors);
let within = self.over_bytes(colors) || snapshot_within(covered, copied);
if crate::pipeline::creation_log_enabled() {
let device = self.core.device();
let line = crate::device::lock(&device.shared().reader_sizes)
@@ -497,33 +501,46 @@ impl RenderLowering {
/// the area rule (the module docs). The snapshot draw costs [`SNAPSHOT_PIXEL_COST`] for each
/// color at each pixel the draw covers, at most those its Vulkan scissors bound
/// (`EncoderState::vk_scissors`: each viewport's pixels within its scissor rectangle, inside
/// the render area); the split's copy is weighed as reading and writing each color's every
/// texel of the rendered level, its format's bytes each, an upper bound: a copy of a
/// one-level, one-slice texture's image moves only the texels around the draw's scissors, or
/// those the instances before changed (`ShadowCopies::cuts`), which errs toward the snapshot.
/// The draw's pixels for every color (the scissors' pixels times the colors), the colors'
/// pixels, and their bytes.
fn snapshot_weights(&self, pipeline: &DrawingState, colors: &[usize]) -> (u64, u64, u64) {
/// the render area); the split's copy is weighed as reading and writing each color's texels
/// its own-pixel reads take (`render.rs`'s `own_pixel_loads`) where the color is a texture of
/// one level and one slice ([`copy_cut`]), else every texel of the rendered level, its
/// format's bytes each: an upper bound, as a later copy moves only those of them the instances
/// before changed, which errs toward the snapshot. The draw's pixels for every color (the
/// scissors' pixels times the colors), the colors' pixels, their bytes, and the bytes the
/// split's copy moves.
fn snapshot_weights(&self, pipeline: &DrawingState, colors: &[usize]) -> (u64, u64, u64, u64) {
let selects = pipeline.base().graphics.writes_viewport_index
|| self.amplification.offsets_viewports();
let mut rects = [vk::Rect2D::default(); MAX_VIEWPORTS];
let bound: u64 = self
let rects = self
.state
.vk_scissors_in(&self.scissors, selects, &mut rects)
.vk_scissors_in(&self.scissors, selects, &mut rects);
let bound: u64 = rects
.iter()
.map(|r| u64::from(r.extent.width) * u64::from(r.extent.height))
.sum();
let (pixels, copied) = colors
let drawn = super::scissors_bound(rects);
let (pixels, bytes, copied) = colors
.iter()
.filter_map(|&index| self.layout.colors.get(index)?.as_ref())
.map(|color| {
let texture = &color.target.texture;
let [width, height] = color.target.extent;
let bytes = block_bytes(color.target.texture.pixel_format()).unwrap_or(0);
let texel = u64::from(block_bytes(texture.pixel_format()).unwrap_or(0));
let pixels = u64::from(width) * u64::from(height);
(pixels, pixels * u64::from(bytes))
let copied = match drawn.filter(|_| copy_cut(texture)) {
Some(drawn) => super::own_pixel_loads(drawn, texture).map_or(0, |r| {
u64::from(r[2] - r[0]) * u64::from(r[3] - r[1]) * texel
}),
None if drawn.is_none() => 0,
None => pixels * texel,
};
(pixels, pixels * texel, copied)
})
.fold((0, 0), |(p, c), (pixels, bytes)| (p + pixels, c + bytes));
(bound * colors.len() as u64, pixels, copied)
.fold((0, 0, 0), |(p, b, c), (pixels, bytes, copied)| {
(p + pixels, b + bytes, c + copied)
});
(bound * colors.len() as u64, pixels, bytes, copied)
}
/// Whether the plan `settled` for `wanted` reads through them (the module docs' checks that
@@ -641,6 +658,20 @@ impl RenderLowering {
}
}
/// Whether the split's copy of `texture` for a draw that reads it at its own pixels is cut to the
/// texels around the draw's scissors (`render.rs`'s `bound_own_pixel_reads`): its shadow is cut to
/// a rectangle (`ShadowCopies::cuts`) where it copies one region, one level and one slice of a 2D
/// image (`texture/view_shadow.rs`).
fn copy_cut(texture: &Texture) -> bool {
texture.mipmap_level_count() == 1
&& texture.array_length() == 1
&& texture.depth() == 1
&& !matches!(
texture.texture_type(),
TextureType::Cube | TextureType::CubeArray
)
}
/// Whether `slot` is a fragment texture slot among `slots`.
pub(super) fn is_snapshot_slot(slots: &BTreeSet<u32>, slot: &SlotRef) -> bool {
slot.stage == Stage::Fragment && slot.class == SlotClass::Texture && slots.contains(&slot.index)
@@ -8,9 +8,9 @@
//! every reader splits, and the target swaps only where a pass fetches it through the pixel
//! interlock into a scratch for want of `STORAGE` (MoltenVK's fetch). Each pass, a command buffer of its own over the
//! `BGRA8Unorm` target, fills the block [`BLOCK`] with a red of its own, then after a barrier draws
//! the block through its scissor with `tob_read`, each fragment writing the texel it read: the
//! pass's own red at every pixel of the block, as Metal orders the barrier, where a read of the
//! copy from before the pass would write the red before it.
//! the block through the whole target's scissor with `tob_read`, each fragment writing the texel
//! it read: the pass's own red at every pixel of the block, as Metal orders the barrier, where a
//! read of the copy from before the pass would write the red before it.
//!
//! A pass whose reader pinned the target and that then fetches the target (`fetch_ordered` over
//! [`FETCHED`], halving its red) renders it through a stand-in from the fetch on: the stand-in
@@ -43,15 +43,14 @@ use metal2vulkan::vk::ImageUsageFlags;
use std::sync::atomic::Ordering;
use std::time::{Duration, Instant};
/// The target's side, in pixels.
const SIDE: u64 = 32;
/// The target's side, in pixels: large enough that a reader through the whole target's scissor
/// takes the snapshot by the area rule (`render/snapshot.rs`).
const SIDE: u64 = 1024;
/// The target's format, a guest framebuffer's.
const FORMAT: PixelFormat = PixelFormat::BGRA8Unorm;
/// The block each pass fills and reads, `[x0, y0, x1, y1]`: its 64 pixels of the snapshot draw's
/// 20 bytes cost less than the split's copy of the target's 1024 texels of 4 bytes
/// (`RenderCommandEncoder::snapshot_cheaper`).
/// The block each pass fills and reads, `[x0, y0, x1, y1]`.
const BLOCK: [u64; 4] = [8, 8, 16, 16];
/// The block a fetching draw halves the red of, `[x0, y0, x1, y1]`: over a quarter of
@@ -161,7 +160,6 @@ fn pass_over(
(encoder.draw_primitives(PrimitiveType::Triangle, 0, 6, 1, 0)).unwrap();
let fragment = RenderStages::FRAGMENT;
encoder.memory_barrier_with_scope(BarrierScope::RENDER_TARGETS, fragment, fragment);
encoder.set_scissor_rect(scissor(BLOCK)).unwrap();
encoder.set_render_pipeline_state(read).unwrap();
encoder.set_fragment_texture(Some(target), 0).unwrap();
(encoder.draw_primitives(PrimitiveType::Triangle, 0, 6, 1, 0)).unwrap();
@@ -1,5 +1,7 @@
//! `render/snapshot.rs`'s area rule: a draw that reads its pass's texture through a snapshot or
//! takes the split by its form's cost at the share of its scissors least favourable to it.
//! takes the split by its form's cost at the share of its scissors least favourable to it, the
//! split's by the bytes its copy moves: a one-level, one-slice color's texels around the draw's
//! scissors, a pixel wider each way, or every texel of the color where it reads through none.
use crate::render::snapshot_within;
@@ -18,9 +20,9 @@ fn a_reader_through_no_scissor_over_a_large_color_takes_the_snapshot() {
assert!(snapshot_within(1280 * 720, 1280 * 720 * 4));
}
/// A 4-byte color's reader through its whole level takes the snapshot from 786,432 pixels
/// (1024x768) and an 8-byte one's from 65,536 (256x256), not one pixel fewer; a 16-byte one's at
/// any size.
/// A 4-byte color's reader through its whole level, the split copying every texel, takes the
/// snapshot from 786,432 pixels (1024x768) and an 8-byte one's from 65,536 (256x256), not one
/// pixel fewer; a 16-byte one's at any size.
#[test]
fn a_reader_through_its_whole_level_takes_the_snapshot_from_a_size_by_its_texel_bytes() {
assert!(snapshot_within(786_432, 786_432 * 4));
@@ -32,16 +34,16 @@ fn a_reader_through_its_whole_level_takes_the_snapshot_from_a_size_by_its_texel_
}
}
/// A 4-byte color's reader takes the snapshot through scissors of up to two fifths of its level
/// at any size: over a 32x32 `RGBA8Unorm` target, through a quarter of it (256 pixels) but not
/// through the whole (1024).
/// A reader through small scissors splits where its color's texels are narrow, the split
/// copying only the texels around them: through an 8x8 scissor (the copy's 10x10 texels) a 4-byte
/// color's reader splits and an 8-byte one's takes the snapshot; over a 1920x1080 4-byte color,
/// a reader through a 960x540 scissor splits and one through 1280x720 takes the snapshot.
#[test]
fn a_reader_through_two_fifths_of_a_small_level_takes_the_snapshot() {
assert!(snapshot_within(256, 1024 * 4));
assert!(!snapshot_within(1024, 1024 * 4));
for level in [1024, 65_536, 1 << 20] {
assert!(snapshot_within(level * 2 / 5, level * 4), "{level}");
}
fn a_reader_through_small_scissors_weighs_the_copy_around_them() {
assert!(!snapshot_within(64, 10 * 10 * 4));
assert!(snapshot_within(64, 10 * 10 * 8));
assert!(!snapshot_within(960 * 540, 962 * 542 * 4));
assert!(snapshot_within(1280 * 720, 1282 * 722 * 4));
}
/// Every reader whose snapshot over its whole scissors weighs no more than the split's copy takes
@@ -9,9 +9,9 @@
//! window's rectangle through its scissor, a memory barrier over the render targets and a draw
//! that reads the target at its own pixels over that rectangle (`tob_read`); then, in every other
//! pass, a barrier and a draw over a window that samples the target at other pixels
//! (`a4_fragment_select_sample`). Each own-pixel read takes a snapshot where the device takes the
//! path, as the area rule does through a window's scissor over this target (`render/snapshot.rs`),
//! else a split. The frame waits for its last command buffer.
//! (`a4_fragment_select_sample`). Each own-pixel read splits: through a window's scissor the area
//! rule (`render/snapshot.rs`) weighs the snapshot dearer than the split's copy of the texels
//! around it. The frame waits for its last command buffer.
//!
//! [`WARM`] frames run untimed, then [`TIMED`] frames are printed as one `ATTACHMENT-READ-COST`
//! line: the GPU time per frame (each command buffer's GPU end less its start, summed), the wall
@@ -15,10 +15,12 @@
//! format, that an earlier pass clears to red [`CLEARED`]. In the pass, which loads it, draw F
//! fills the block `[8, 16)²` with red [`FILL`]. The reader is `tob_read`
//! (`t.read(uint2(in.position.xy))`) over the block, blended `One + One`, so each fragment adds
//! what it read to the pixel, through a scissor of the block: the snapshot draw's 20 bytes at
//! each of its 64 pixels cost less than the split's copy of the target's 1024 texels of 4 bytes
//! (`RenderCommandEncoder::snapshot_cheaper`), and the snapshot of an `RGBA8Unorm` texture holds
//! its codes, 4 bytes a pixel. The tests
//! what it read to the pixel, through the whole target's scissor but where a test names another:
//! the area rule (`render/snapshot.rs`) takes the snapshot through scissors of a 4-byte color
//! this large whatever the reader covers, the split's copy of the target's 1,048,576 texels
//! weighing more than the snapshot draw's 20 bytes at each pixel would at most, each beside a
//! reader's fixed cost; and the snapshot of an `RGBA8Unorm` texture holds its codes, 4 bytes a
//! pixel. The tests
//! run under the default policy, the consumer's, and the first under the lane's exact policy too,
//! whose exact texel conversion the translator follows into its call
//! (`StageModule::snapshot_textures`).
@@ -27,12 +29,13 @@
//! reader in two instances (every pixel covered by two primitives of the one draw), a barrier,
//! 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`).
//! - [`readers_take_the_snapshot_by_the_area_rule`]: the same draws through wider scissors,
//! - [`readers_take_the_snapshot_by_the_area_rule`]: the same draws through each scissor,
//! whatever the snapshot's form (`render/snapshot.rs`'s area rule, each form beside a reader's
//! fixed cost of a mebibyte): over `RGBA8Unorm` through the whole target's scissor (1024 pixels
//! of 20 bytes against a copy of 1024 texels of 4), a split for each; through [`QUARTER`]'s (256
//! pixels, within two fifths of the target), and over `RGBA16Float` through [`QUARTER`]'s, a
//! snapshot for each where the device takes the path.
//! fixed cost of a mebibyte): over `RGBA8Unorm` through the whole target's, a snapshot for each
//! where the device takes the path; through [`QUARTER`]'s (256 pixels of 20 bytes against the
//! split's copy of the 18x18 texels around them, 4 bytes each), a split for each; over
//! `RGBA16Float` through [`QUARTER`]'s (the copy's texels of 8 bytes), a snapshot for each where
//! the device takes the path.
//! - [`a_surfaces_readers_take_the_snapshot_at_any_area`]: the same draws over a surface over
//! host pages, an `RGBA8Unorm` texture of an IOSurface plane over a no-copy buffer, through the
//! whole target's scissor: a snapshot for each where the device takes the path and the image
@@ -46,9 +49,10 @@
//! - [`each_form_reads_what_the_split_reads`]: the first test's draws over a target of each of
//! `RGBA8Unorm`, `BGRA8Unorm`, `R8Unorm`, `RG8Unorm` (8-bit codes), `RGBA16Float` (half-float
//! codes) and `RGB10A2Unorm` (bits): the bytes the split leaves, byte for byte, with a snapshot
//! for each reader where the device takes the path, the rule does (for each of them, `R8Unorm`'s
//! copy of 1024 bytes too) and the device keeps the color in place (an `RGBA8Unorm` one's on
//! every such device; the counts printed say which others did).
//! for each reader where the device takes the path, the rule does (not `R8Unorm`'s or
//! `RG8Unorm`'s, whose copies of 1 and 2 bytes a texel weigh less) and the device keeps the
//! color in place (an `RGBA8Unorm` one's on every such device; the counts printed say which
//! others did).
//! - [`without_a_barrier_the_readers_read_the_texels_from_before_the_pass`]: the same draws with
//! no barrier: every reader reads [`CLEARED`], the texel from before the pass at its own pixel,
//! through the copy taken before the pass: `FILL + 3 * CLEARED`, no snapshot. The M3 Max's
@@ -66,7 +70,7 @@
//! depth or stencil first and leave the drawing draw nothing (`FILL`). Under a `Less` depth
//! without writes both instances draw (`3 * FILL`).
use super::attachment_reads::{corners, floats, function, red, SIDE};
use super::attachment_reads::{floats, function, red};
use super::degrade_notices::on_device_with;
use super::host_memory::{no_copy, Mapping, GUEST_PAGE};
use super::in_place_rows;
@@ -92,12 +96,23 @@ const CLEARED: u8 = 64;
/// The red draw F writes over the block.
const FILL: u8 = 40;
/// The target's side, in pixels: large enough that a reader of a 4-byte color through the whole
/// target's scissor takes the snapshot by the area rule (`render/snapshot.rs`).
const SIDE: u64 = 1024;
/// The block F and the readers draw over.
const BLOCK: [u64; 4] = [8, 8, 16, 16];
/// A scissor of a quarter of the target, over the block.
const QUARTER: [u64; 4] = [8, 8, 24, 24];
/// 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;
floats([x(x0), y(y1), x(x1), y(y0)])
}
/// The features the snapshot path takes.
const FEATURES: [VkFeature; 4] = [
VkFeature::AttachmentFeedbackLoopLayout,
@@ -324,8 +339,8 @@ fn readers_over(
(bytes, moved, made)
}
/// [`readers`]' first test's pass over a private `RGBA8Unorm` target, through the block's
/// scissor, beside a `Depth32Float_Stencil8` attachment that an earlier pass clears to depth 1 and
/// [`readers`]' first test's pass over a private `RGBA8Unorm` target, through the whole
/// target's scissor, beside a `Depth32Float_Stencil8` attachment that an earlier pass clears to depth 1 and
/// stencil 0: F, under Metal's default depth/stencil state, then a barrier and the reader in two
/// instances under a state of `reader` (stencil reference 0). The target's bytes, tight rows, and
/// what the pass moved of the counts.
@@ -392,14 +407,6 @@ fn depth_stencil_readers(
encoder.set_fragment_texture(Some(&target), 0).unwrap();
encoder.set_depth_stencil_state(&reader).unwrap();
encoder.set_stencil_reference_value(0);
let [x0, y0, x1, y1] = BLOCK;
let rect = ScissorRect {
x: x0,
y: y0,
width: x1 - x0,
height: y1 - y0,
};
encoder.set_scissor_rect(rect).unwrap();
encoder.memory_barrier_with_scope(
BarrierScope::RENDER_TARGETS,
RenderStages::FRAGMENT,
@@ -481,8 +488,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, Some(BLOCK));
let (bytes, moved) = readers(device, &queue, PixelFormat::RGBA8Unorm, true, None);
let takes = snapshots(device);
eprintln!("snapshot reads, features {takes}, exact {exact}: {moved:?}");
holds("after barriers", &bytes, 6 * FILL);
@@ -514,21 +520,21 @@ fn readers_take_the_snapshot_by_the_area_rule() {
|device| {
let queue = device.new_command_queue().unwrap();
let narrow = PixelFormat::RGBA8Unorm;
let (snapshotted, splits) = if snapshots(device) { (2, 0) } else { (0, 2) };
let (bytes, moved) = readers(device, &queue, narrow, true, None);
eprintln!("snapshot reads, whole scissor, RGBA8Unorm: {moved:?}");
holds("whole scissor", &bytes, 6 * FILL);
assert_eq!(
(moved.snapshotted, moved.splits),
(0, 2),
(snapshotted, splits),
"RGBA8Unorm over the target: snapshots, splits"
);
let (snapshotted, splits) = if snapshots(device) { (2, 0) } else { (0, 2) };
let (bytes, moved) = readers(device, &queue, narrow, true, Some(QUARTER));
eprintln!("snapshot reads, quarter scissor, RGBA8Unorm: {moved:?}");
holds("quarter scissor", &bytes, 6 * FILL);
assert_eq!(
(moved.snapshotted, moved.splits),
(snapshotted, splits),
(0, 2),
"RGBA8Unorm over a quarter: snapshots, splits"
);
let wide = PixelFormat::RGBA16Float;
@@ -587,7 +593,7 @@ fn each_form_reads_what_the_split_reads() {
},
|device| {
let queue = device.new_command_queue().unwrap();
let (bytes, moved) = readers(device, &queue, format, true, Some(BLOCK));
let (bytes, moved) = readers(device, &queue, format, true, None);
assert_eq!(moved.splits, 2, "{format:?}: a split for each reader");
split = Some(bytes);
},
@@ -596,7 +602,7 @@ fn each_form_reads_what_the_split_reads() {
|_| {},
|device| {
let queue = device.new_command_queue().unwrap();
let (bytes, moved) = readers(device, &queue, format, true, Some(BLOCK));
let (bytes, moved) = readers(device, &queue, format, true, None);
eprintln!("snapshot reads, {format:?}: {moved:?}");
// Each reader through a snapshot where the device keeps the color in place (its
// image has storage usage), as `RGBA8Unorm`'s on every device that takes the path.
@@ -649,8 +655,7 @@ fn with_a_feature_withheld_the_readers_take_the_split() {
},
|device| {
let queue = device.new_command_queue().unwrap();
let (bytes, moved) =
readers(device, &queue, PixelFormat::RGBA8Unorm, true, Some(BLOCK));
let (bytes, moved) = readers(device, &queue, PixelFormat::RGBA8Unorm, true, None);
eprintln!("snapshot reads, {withheld:?} withheld: {moved:?}");
holds(&format!("{withheld:?} withheld"), &bytes, 6 * FILL);
assert_eq!(
+13 -11
View File
@@ -240,18 +240,20 @@ recorded here.
half of or more.
Elsewhere the area rule (`render/snapshot.rs`) weighs each form at the share of its scissors
least favourable to it, as a draw's recording cannot know what it covers: the snapshot draw at
20 bytes of the split's copy for each pixel its scissors bound, the split at a copy of every
texel of the color (an upper bound of the split's copy, which is cut to the scissors or to what
changed for a one-level, one-slice texture), each beside a reader's fixed cost of a mebibyte of
20 bytes of the split's copy for each pixel its scissors bound, the split at its copy (a
one-level, one-slice color's texels around the draw's scissors, a pixel wider each way, as the
copy is cut; else every texel of the level), each beside a reader's fixed cost of a mebibyte of
the copy; it takes the form whose cost there is the smaller multiple of the other's. A 4-byte
color's reader takes the snapshot through scissors of up to two fifths of the target at any
size, and at any area from 1024x768. Through no scissor over private `BGRA8Unorm` targets of
1280x720 to 3662x2039 (`runtime_lane::attachment_read_costs::snapshot_area_costs`), a reader
covering 1.5% of the target took 0.09 to 0.33 times the split's GPU time on the Iris Xe, 0.11 to
0.24 on the Radeon 780M and 0.25 to 0.43 on the RX 7900 XTX; one covering the whole target, the
rule's worst case, 1.04 to 1.28 times, 2.4 to 2.8 times and 1.3 to 2.1 times. Through a small
scissor covered whole the snapshot costs up to 2.1 times the split on the Iris Xe (a 320x180
scissor over a private 1920x1080 `BGRA8Unorm` texture). Other devices are not measured.
color's reader takes the snapshot through scissors whose rectangle holds about 1024x768 pixels
or more, and splits through smaller ones. Through no scissor over private `BGRA8Unorm` targets
of 1280x720 to 3662x2039 (`runtime_lane::attachment_read_costs::snapshot_area_costs`, the split
on a device that withholds `fragmentShaderPixelInterlock`), a reader covering 1.5% of the target
took 0.08 to 0.23 times the split's GPU time on the Radeon 780M and 0.25 to 0.43 on the RX 7900
XTX; one covering the whole target, the rule's worst case, 1.8 to 2.3 times and 1.3 to 2.1
times. Through scissors of 1280x720 over a private 1920x1080 target
(`runtime_lane::attachment_read_costs::snapshot_crossover`), a reader covering the whole
scissor took up to 2.0 times the split's time on the Radeon 780M and 1.4 times on the RX 7900
XTX. Other devices are not measured.
- **A texture over a no-copy buffer's host pages, or over a host-visible buffer longer than 32
MiB, that a shader writes of 1- or 2-byte texels (or whose class's check has not passed for an
access of its, or whose format, usage or pitch no image takes, or under