A flagged fan-out draw is drawn in parts: only its flagged range region by region

Under DevicePolicy's RateMapRegionPolicy::FanOut the probe flags a draw that has a triangle
crossing w = 0 or reaching more regions than the geometry stage's copies. The whole draw was then
recorded region by region, once per region of the map (2074 for a 61 by 34 map), however few of
its triangles were flagged.

The probe now also records each flagged draw's first and last flagged triangle. A flagged list of
triangles of one instance, whose pipeline reads no [[primitive_id]] and writes no memory (the
conditions under which a draw is already cut into index ranges), is drawn in up to three parts in
its place: the triangles before the first flagged one fanned out, those from it to the last
region by region, and those after fanned out. Each part is a range of the draw's vertices or
indices, so each triangle keeps its vertices, vertex_id and order. Parts of a 16-bit index list
begin at even triangles, so their ranges start 4-byte aligned as the draw does. Any other flagged
draw is drawn region by region whole, as before.

The probe words grow from 1 + 2*32 to 1 + 4*32 per draw (bind::fan_out::PROBE_DRAW_WORDS). For a
flagged triangle the probe raises one of 32 words to u32::MAX - PrimitiveId and one to
PrimitiveId + 1, picked by PrimitiveId as the counts are, so no single word takes every atomic.
The wide marks that choose the variant of four copies now come only from triangles the probe does
not flag, so the fanned-out parts can take that variant.

Also: WorkCounts::rate_map_probe_wait_nanos sums the host's wall time from each probe's
submission until it saw it complete, so a walk can split host_step_nanos into the probe's round
trip and the host's own recording. rate_map_parted_draws and rate_map_parted_region_triangles
count the draws in parts and their triangles drawn region by region.

An earlier attempt drew a flagged draw through a geometry stage of 32 invocations, each taking a
block of up to 16 regions, in 5 passes over the map. On the pieces lane's frame with wide
triangles it made no GPU gain on an RTX 2080 (41.0 against 42.9 ms warm). On a Radeon 780M (RADV)
it went from 182 to 1900 ms, with one piece of 1.1 s. That attempt is not in this change.

Tests: render::fan_out's unit tests check that the parts take each triangle once, in order, with
no flagged triangle in a fanned-out part, and that the probe's words decode to the first and last
flagged triangle. The link test checks the probe's two atomic raises. The runtime's
rate_mapped_fan_out test adds two commands that draw the grid with one triangle over half the
target, one indexed and one without indices, and a triangle across w = 0 over the whole target.
Under FanOut all four flagged draws are drawn in parts and the frame is compared pixel for pixel
with the encoder's region-by-region frame. The pieces lane's wide frame checks that every flagged
draw is drawn in parts.
This commit is contained in:
Anees Iqbal committed 2026-11-13 02:43:42 -08:00
1 parent 0eb9f73862
commit dad0470c2e
15 files changed
+677 -191

No files matched your search

@@ -200,16 +200,22 @@
//! region viewport's and four clip distances keeping it to its region's pixels. Before the
//! pass, the step records the commands' draws once more as a probe whose geometry stage emits
//! nothing: for each draw it flags a triangle that crosses `w = 0` or touches more regions than
//! the fan-out's copies (each region widened by an eighth of a pixel), and counts the copies of
//! the others. The probe is submitted on its own and waited for (`WorkCounts::rate_map_probes`,
//! its GPU time `WorkCounts::rate_map_probe_gpu_nanos`); then a flagged draw is drawn region by
//! region (`WorkCounts::rate_map_flagged_draws`) and the others fanned out
//! (`WorkCounts::rate_map_fanned_draws`), each in its command's place, so a pixel's fragments
//! keep their order: a pixel lies in one region. The probe also marks a draw a triangle of
//! which touches more regions than few copies (`bind::fan_out::FEW_COPIES`); a draw it marks
//! none of is drawn through the variant of that many copies (`RegionFanOut::DrawFew`,
//! `WorkCounts::rate_map_fanned_few_draws`), whose geometry stage declares the output of fewer
//! vertices. A fanned-out draw's work is its vertices, its
//! the fan-out's copies (each region widened by an eighth of a pixel), with the first and the
//! last triangle it flags, and counts the copies of the others. The probe is submitted on its
//! own and waited for (`WorkCounts::rate_map_probes`, its GPU time
//! `WorkCounts::rate_map_probe_gpu_nanos`, the host's wait `rate_map_probe_wait_nanos`); then a
//! flagged draw (`WorkCounts::rate_map_flagged_draws`) is drawn in parts where it is a list of
//! triangles of one instance whose pipeline reads no `[[primitive_id]]` and writes no memory
//! (`render/fan_out.rs`, **Parts**, `WorkCounts::rate_map_parted_draws`): its triangles from the
//! first flagged to the last region by region (`rate_map_parted_region_triangles`), those
//! before and after fanned out; another flagged draw is drawn region by region whole; and the
//! others are fanned out (`WorkCounts::rate_map_fanned_draws`), each in its command's place, so
//! a pixel's fragments keep their order: a pixel lies in one region. The probe also marks a draw
//! a triangle of which it does not flag touches more regions than few copies
//! (`bind::fan_out::FEW_COPIES`); a draw it marks none of is drawn, and so are a flagged
//! draw's parts fanned out, through the variant of that many copies (`RegionFanOut::DrawFew`;
//! `WorkCounts::rate_map_fanned_few_draws` counts the draws), whose geometry stage declares the
//! output of fewer vertices. A fanned-out draw's work is its vertices, its
//! triangles' geometry stage and three vertices per copy ([`fan_out_work`]), and it is never
//! cut into ranges. The probe stops at a command's barrier, and after a draw whose pipeline
//! writes memory, as it runs before every draw of the pass: the later commands are drawn region
@@ -273,7 +273,7 @@
//! own draw reads such a buffer at stride 0 (`render/vertex_strides.rs`).
use super::bound::Bound;
use super::fan_out::{self, FanOutDraw, FanOutRoutes, FanOutRun, Probe};
use super::fan_out::{self, FanOutDraw, FanOutRoutes, FanOutRun, Part, Probe, Probed};
use super::mesh::MeshGrid;
use super::pass_start_reads::{PassStartReads, PassStartTables};
use super::pass_steps::PassSteps;
@@ -344,8 +344,7 @@ use gpu::GpuForm;
pub(super) use gpu::ReplayedDraws;
use metal2vulkan::bind::indirect_commands::{Action, BufferStage, CommandRecord};
use metal2vulkan::bind::{
fan_out::{PROBE_COUNT_WORDS, PROBE_DRAW_WORDS},
DrawCall, RateMapRegions, ReplayFaults, ViewSetup,
fan_out::PROBE_DRAW_WORDS, DrawCall, RateMapRegions, ReplayFaults, ViewSetup,
};
use metal2vulkan::metal::{
IndexType, IndirectCommandType, PrimitiveTopologyClass, PrimitiveType, VertexStepFunction,
@@ -1114,15 +1113,69 @@ fn trail_draw(action: &Action) -> Option<(bool, u32, u32, u32)> {
/// The vertices of each primitive of `draw` of `pipeline`, where its indices may be drawn as
/// consecutive ranges, each a draw of its own, as Metal draws the whole (`rate_mapped_pass.rs`,
/// **Pieces**): a list of points, lines or triangles, which Metal never restarts, of one
/// instance, whose pipeline reads no `[[primitive_id]]` and writes no memory. `None` for any
/// other.
/// **Pieces**): [`list_vertices`]'s.
fn index_ranges_of(pipeline: &RenderPipelineState, draw: &IndexedDraw) -> Option<u32> {
list_vertices(pipeline, draw.primitive_type, draw.instance_count)
}
/// The triangles of `draw` of `pipeline`, and whether its parts begin at even ones, where a draw
/// the probe flagged is drawn in parts (`render/fan_out.rs`, **Parts**): a list of triangles whose
/// vertices or indices may be drawn as consecutive ranges ([`list_vertices`]), its parts of a
/// 16-bit index list beginning at even triangles. `None` for any other, drawn region by region
/// whole.
fn in_parts<B>(pipeline: &RenderPipelineState, draw: &Draw<B>) -> Option<(u32, bool)> {
let triangle = DrawPrimitiveType::Public(PrimitiveType::Triangle);
match draw {
Draw::Primitives(
Assembly::Primitives(PrimitiveType::Triangle),
DrawCall::Primitives {
vertex_count,
instance_count,
..
},
) => (list_vertices(pipeline, triangle, *instance_count) == Some(3))
.then_some((vertex_count / 3, false)),
Draw::Indexed(draw, _) => (draw.primitive_type == triangle
&& index_ranges_of(pipeline, draw) == Some(3))
.then_some((draw.index_count / 3, index_size(draw.index_type) == 2)),
_ => None,
}
}
/// The draw of `part` of a draw without indices `whole` (`render/fan_out.rs`, **Parts**): its
/// triangles' vertices, from the part's first.
fn part_call(whole: DrawCall, part: Part) -> DrawCall {
match whole {
DrawCall::Primitives {
vertex_start,
instance_count,
base_instance,
..
} => DrawCall::Primitives {
vertex_start: vertex_start + 3 * part.first,
vertex_count: 3 * part.count,
instance_count,
base_instance,
},
other => other,
}
}
/// The vertices of each primitive of a draw of `primitive_type` and `instance_count` instances of
/// `pipeline`, where its vertices or indices may be drawn as consecutive ranges, each a draw of
/// its own, as Metal draws the whole: a list of points, lines or triangles, which Metal never
/// restarts, of one instance, whose pipeline reads no `[[primitive_id]]` and writes no memory.
/// `None` for any other.
fn list_vertices(
pipeline: &RenderPipelineState,
primitive_type: DrawPrimitiveType,
instance_count: u32,
) -> Option<u32> {
let RenderStateKind::Graphics(state) = pipeline.kind() else {
return None;
};
let graphics = &state.base().graphics;
if draw.instance_count != 1
if instance_count != 1
|| graphics.reads_primitive_id
|| graphics.vertex_writes_memory
|| graphics.fragment_writes_memory
@@ -1130,7 +1183,7 @@ fn index_ranges_of(pipeline: &RenderPipelineState, draw: &IndexedDraw) -> Option
{
return None;
}
match draw.primitive_type {
match primitive_type {
DrawPrimitiveType::Public(PrimitiveType::Point) => Some(1),
DrawPrimitiveType::Public(PrimitiveType::Line) => Some(2),
DrawPrimitiveType::Public(PrimitiveType::Triangle) => Some(3),
@@ -2598,42 +2651,105 @@ impl RenderExecution {
if !probing {
found.piece_before(encoder);
}
match draw {
Draw::Primitives(assembly, draw) => {
encoder.draw(live, CALL, assembly, draw, DrawBuffers::default(), false)?
// A draw the probe flagged: drawn in parts where it can be, its triangles from the
// first it flagged to the last region by region and the others fanned out, each part
// a draw a piece may begin before; else region by region whole (`render/fan_out.rs`,
// **Parts**).
let fan = encoder.fan_out;
let parts = match fan.and_then(|fan| fan.flagged) {
Some(flagged) => {
let parts = (encoder.pipeline.as_ref())
.and_then(|pipeline| in_parts(pipeline, &draw))
.map(|(triangles, even)| fan_out::parts(flagged, triangles, even));
if parts.is_none() {
encoder.fan_out = None;
}
parts
}
Draw::Indexed(mut draw, (buffer, mut offset)) => {
// A draw that would hold more than a piece's work, drawn as consecutive ranges
// of its indices, each a draw a piece may begin before; the last below. A
// fanned-out draw, and a probe, is drawn whole.
let cut = encoder.rate_map.is_some() && !probing && encoder.fan_out.is_none();
let per_primitive = cut
.then(|| index_ranges_of(encoder.pipeline.as_ref()?, &draw))
.flatten();
if let Some(per_primitive) = per_primitive {
let size = index_size(draw.index_type);
let mut ranges = 0u64;
loop {
let most = rate_mapped_pass::index_range(regions, per_primitive);
if draw.index_count <= most {
break;
}
let range = IndexedDraw {
index_count: most,
..draw
};
encoder.draw_indexed(live, CALL, range, &buffer, offset)?;
None => None,
};
let part_fan = |part: &Part| {
(fan.filter(|_| part.fanned)).map(|fan| FanOutDraw {
flagged: None,
..fan
})
};
// Each part's triangles and whether its draw ran its fan-out variant.
let mut drawn = Vec::new();
match draw {
Draw::Primitives(assembly, whole) => {
let draws: Vec<(Option<FanOutDraw>, DrawCall, u32)> = match &parts {
None => vec![(encoder.fan_out, whole, 0)],
Some(parts) => (parts.iter())
.map(|part| (part_fan(part), part_call(whole, *part), part.count))
.collect(),
};
for (at, (fan_out, draw, triangles)) in draws.into_iter().enumerate() {
if at > 0 {
regions = note(found.piece_after(encoder));
found.piece_before(encoder);
draw.index_count -= most;
offset += u64::from(most) * size;
ranges += 1;
}
if ranges > 0 {
(encoder.core.device().shared().counts).rate_map_index_ranges(ranges);
}
encoder.fan_out = fan_out;
encoder.draw(live, CALL, assembly, draw, DrawBuffers::default(), false)?;
drawn.push((triangles, encoder.fanned.0));
}
}
Draw::Indexed(whole, (buffer, whole_offset)) => {
let size = index_size(whole.index_type);
let draws: Vec<(Option<FanOutDraw>, IndexedDraw, u64)> = match &parts {
None => vec![(encoder.fan_out, whole, whole_offset)],
Some(parts) => (parts.iter())
.map(|part| {
let draw = IndexedDraw {
index_count: 3 * part.count,
..whole
};
let offset = whole_offset + 3 * u64::from(part.first) * size;
(part_fan(part), draw, offset)
})
.collect(),
};
for (at, (fan_out, mut draw, mut offset)) in draws.into_iter().enumerate() {
if at > 0 {
regions = note(found.piece_after(encoder));
found.piece_before(encoder);
}
encoder.fan_out = fan_out;
let triangles = draw.index_count / 3;
// A draw that would hold more than a piece's work, drawn as consecutive
// ranges of its indices, each a draw a piece may begin before; the last
// below. A fanned-out draw, and a probe, is drawn whole.
let cut =
encoder.rate_map.is_some() && !probing && encoder.fan_out.is_none();
let per_primitive = cut
.then(|| index_ranges_of(encoder.pipeline.as_ref()?, &draw))
.flatten();
if let Some(per_primitive) = per_primitive {
let mut ranges = 0u64;
loop {
let most = rate_mapped_pass::index_range(regions, per_primitive);
if draw.index_count <= most {
break;
}
let range = IndexedDraw {
index_count: most,
..draw
};
encoder.draw_indexed(live, CALL, range, &buffer, offset)?;
regions = note(found.piece_after(encoder));
found.piece_before(encoder);
draw.index_count -= most;
offset += u64::from(most) * size;
ranges += 1;
}
if ranges > 0 {
let counts = &encoder.core.device().shared().counts;
counts.rate_map_index_ranges(ranges);
}
}
encoder.draw_indexed(live, CALL, draw, &buffer, offset)?;
drawn.push((triangles, encoder.fanned.0));
}
encoder.draw_indexed(live, CALL, draw, &buffer, offset)?;
}
Draw::Mesh(grid, object, mesh) => {
encoder.replay_plain = false;
@@ -2674,9 +2790,19 @@ impl RenderExecution {
if let Some(run) = &mut encoder.fan_run {
let (fanned, writes) = encoder.fanned;
run.end(place, fanned, writes);
if fanned && !probing {
let few = (encoder.fan_out).is_some_and(|f| f.mode == RegionFanOut::DrawFew);
(encoder.core.device().shared().counts).rate_map_fanned_draw(few);
let counts = &encoder.core.device().shared().counts;
match parts.is_some() {
true => counts.rate_map_drawn_in_parts(
(drawn.iter().filter(|(_, fanned)| !fanned))
.map(|&(triangles, _)| u64::from(triangles))
.sum(),
),
false if fanned && !probing => {
let few =
(encoder.fan_out).is_some_and(|fan| fan.mode == RegionFanOut::DrawFew);
counts.rate_map_fanned_draw(few);
}
false => {}
}
}
if !probing {
@@ -2684,14 +2810,20 @@ impl RenderExecution {
}
if let Some((notes, _)) = &mut trail {
use crate::encoder_trail::Route;
notes.routed(
match (probing, encoder.fanned.0, encoder.rate_map.is_some()) {
// Each part's route, or the whole draw's (a draw without parts drew once, or a
// mesh or patch draw none above).
let routes = match drawn.is_empty() {
true => vec![encoder.fanned.0],
false => drawn.iter().map(|&(_, fanned)| fanned).collect(),
};
for fanned in routes {
notes.routed(match (probing, fanned, encoder.rate_map.is_some()) {
(true, _, _) => Route::Probe,
(false, true, _) => Route::FannedOut,
(false, false, true) => Route::RegionByRegion,
(false, false, false) => Route::Plain,
},
);
});
}
}
}
if let Some((notes, _)) = trail {
@@ -3035,6 +3167,7 @@ impl RenderExecution {
mode,
index: 0,
copies: 0,
flagged: None,
});
for pipeline in named {
encoder.settle_draws(&mut live, pipeline, fanned);
@@ -4107,7 +4240,7 @@ impl DeferredPass {
.sum();
let draw_words = u64::from(PROBE_DRAW_WORDS);
let mut probes: Vec<ProbeRun> = Vec::with_capacity(reads.len());
let mut words: Arc<[u32]> = Arc::from([]);
let mut found_draws: Arc<[Probed]> = Arc::from([]);
let mut probed = None;
if commands > 0 {
let len = 4 * draw_words * commands as u64;
@@ -4140,20 +4273,13 @@ impl DeferredPass {
// the host by its last barrier; the words are writable and apart from the
// region.
unsafe { flags.copy_out(0, read_words.as_mut_ptr().cast(), 4 * read) };
// Each draw's flag, the copies its triangles emit (its counts' sum), and
// whether a triangle of it is too wide for few copies (a wide word marked).
let lanes = PROBE_COUNT_WORDS as usize;
let draws: Vec<u32> = (read_words.chunks(PROBE_DRAW_WORDS as usize))
.flat_map(|draw| {
let counts = draw.iter().skip(1).take(lanes);
let copies = counts.fold(0u32, |a, &w| a.saturating_add(w));
let wide = draw.iter().skip(1 + lanes).any(|&w| w != 0);
[draw[0], copies, u32::from(wide)]
})
// What the probe found of each draw (`fan_out::Probed`).
let draws: Vec<Probed> = (read_words.chunks(PROBE_DRAW_WORDS as usize))
.map(Probed::of)
.collect();
let flagged = draws.chunks(3).filter(|draw| draw[0] != 0).count();
let flagged = draws.iter().filter(|draw| draw.flagged.is_some()).count();
device.shared().counts.rate_map_probe(flagged as u64);
words = draws.into();
found_draws = draws.into();
}
probed = Some(recorded);
}
@@ -4167,7 +4293,7 @@ impl DeferredPass {
start,
faults,
slots,
words: Arc::clone(&words),
probed: Arc::clone(&found_draws),
}))
})
.collect();
@@ -4238,11 +4364,14 @@ impl DeferredPass {
});
core.retain(passes);
let mut recorded = core.end_segment()?;
// The host's wait for it, counted.
let started = Instant::now();
// SAFETY: the segment's command buffers, of the command buffer's pool, ended and
// recorded for this submission alone; what they use the segment holds, which the pass's
// joins.
let what = "the rasterization-rate map's fan-out probe";
let completed = unsafe { command_buffer.submit_waited(&recorded.raws, what) }?;
(device.shared().counts).rate_map_probe_waited(started.elapsed());
// Its time read and counted, its submission done.
drop(times);
recorded.raws.clear();
+102 -22
View File
@@ -1,12 +1,23 @@
//! A rate-mapped pass's triangles that a host step records, each drawn once and fanned out to the
//! map's regions (`rate_mapped_pass.rs`, **Fan-out**): whether the device fans them out, what the
//! next command's draw records, the probe's and the routes' runs of an execution's commands, and
//! the region table and viewport a fanned-out draw records through.
//! next command's draw records, the probe's and the routes' runs of an execution's commands, the
//! parts a flagged draw is drawn in, and the region table and viewport a fanned-out draw records
//! through.
//!
//! **Parts.** A draw the probe flagged, a list of triangles of one instance whose pipeline reads
//! no `[[primitive_id]]` and writes no memory (`render/executions.rs`, `in_parts`), is drawn in
//! up to three parts in its place ([`parts`]): its triangles before the first the probe flagged,
//! fanned out; those from it to the last it flagged, region by region; and those after, fanned
//! out. Each part is a draw of a range of the draw's vertices or indices, so each triangle keeps
//! its vertices, its `vertex_id`s and its place among the draw's: a pixel takes the draw's
//! fragments in the draw's order. A flagged draw of any other kind is drawn region by region
//! whole.
use super::executions::Command;
use crate::render_values::{ScissorRect, Viewport};
use crate::Device;
use ash::vk;
use metal2vulkan::bind::fan_out::PROBE_COUNT_WORDS;
use metal2vulkan::bind::ReplayFaults;
use metal2vulkan::device::{RateMapRegionPolicy, VkFeature};
use metal2vulkan::pipeline::RegionFanOut;
@@ -38,6 +49,74 @@ pub(super) struct FanOutDraw {
/// A draw's: the copies of its triangles the probe counted, which its work counts
/// (`rate_mapped_pass::fan_out_work`).
pub(super) copies: u32,
/// A draw the probe flagged: the first and the last of its triangles it flagged, between
/// which its parts are drawn region by region (the module docs, **Parts**).
pub(super) flagged: Option<(u32, u32)>,
}
/// What the probe found of a draw it probed, from its words (`bind::fan_out::PROBE_DRAW_WORDS`):
/// the copies its triangles emit (its counts summed), whether a triangle it does not flag is too
/// wide for few copies (`bind::fan_out::FEW_COPIES`, a wide word marked), and the first and the
/// last of its triangles it flagged, where it flagged one.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub(super) struct Probed {
pub(super) copies: u32,
pub(super) wide: bool,
pub(super) flagged: Option<(u32, u32)>,
}
impl Probed {
/// What the probe found of a draw of its `words`.
pub(super) fn of(words: &[u32]) -> Probed {
let lanes = PROBE_COUNT_WORDS as usize;
let set = |k: usize| words.iter().skip(1 + k * lanes).take(lanes).copied();
let first = set(2).max().unwrap_or(0);
let last = set(3).max().unwrap_or(0);
Probed {
copies: set(0).fold(0u32, u32::saturating_add),
wide: set(1).any(|w| w != 0),
flagged: (words.first().is_some_and(|&flag| flag != 0))
.then(|| (u32::MAX - first, last.saturating_sub(1))),
}
}
}
/// A part of a flagged draw (the module docs, **Parts**): `count` of its triangles from triangle
/// `first`, fanned out or region by region.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub(super) struct Part {
pub(super) first: u32,
pub(super) count: u32,
pub(super) fanned: bool,
}
/// The parts of a draw of `triangles` triangles whose triangles from `first` to `last` the probe
/// flagged (the module docs, **Parts**): those before `first` fanned out, those from it to `last`
/// region by region, and those after fanned out, an empty part left out. Where `even` (a list of
/// 16-bit indices, whose ranges start 4-byte aligned as the draw's do) each part begins at an even
/// triangle, the part drawn region by region widened to one. A flag past the triangles draws
/// every triangle region by region.
pub(super) fn parts((first, last): (u32, u32), triangles: u32, even: bool) -> Vec<Part> {
if first > last || last >= triangles {
return vec![Part {
first: 0,
count: triangles,
fanned: false,
}];
}
let (from, to) = match even {
true => (first & !1, (last + 1).next_multiple_of(2).min(triangles)),
false => (first, last + 1),
};
[(0, from, true), (from, to, false), (to, triangles, true)]
.into_iter()
.filter(|&(start, end, _)| end > start)
.map(|(start, end, fanned)| Part {
first: start,
count: end - start,
fanned,
})
.collect()
}
/// An encoder's run of an execution's commands where its host step fans the pass's triangles
@@ -80,31 +159,30 @@ impl Probe {
impl FanOutRun {
/// The fan-out of the draw of the command at `place` among the commands: the probe's, where
/// it probes on; the route's draw where the probe probed it and flagged none of its
/// triangles, of few copies where it marked none too wide for them; `None` for a draw
/// recorded region by region.
/// it probes on; the route's draw where the probe probed it, of few copies where it marked
/// none of the triangles it fans out too wide for them, and the triangles it flagged where it
/// flagged one, which the draw's parts take (the module docs, **Parts**); `None` for a draw
/// the probe did not probe, recorded region by region.
pub(super) fn begin(&self, place: usize) -> Option<FanOutDraw> {
match self {
FanOutRun::Probe(probe) => (!probe.stopped).then_some(FanOutDraw {
mode: RegionFanOut::Probe,
index: probe.next,
copies: 0,
flagged: None,
}),
FanOutRun::Route(routes) => {
let index = routes.slots.get(place).copied().flatten()?;
let word = |w: u32| routes.words.get(w as usize).copied();
let mode = match word(3 * index + 2)? {
0 => RegionFanOut::DrawFew,
_ => RegionFanOut::Draw,
};
match word(3 * index)? {
0 => Some(FanOutDraw {
mode,
index,
copies: word(3 * index + 1)?,
}),
_ => None,
}
let probed = routes.probed.get(index as usize)?;
Some(FanOutDraw {
mode: match probed.wide {
false => RegionFanOut::DrawFew,
true => RegionFanOut::Draw,
},
index,
copies: probed.copies,
flagged: probed.flagged,
})
}
}
}
@@ -148,15 +226,14 @@ impl FanOutRun {
/// The routes of an execution's commands at its host step (the module docs): the commands as the
/// step read them, once, for the probe and the routes alike, from command `start`; the faults the
/// read found; the index of each command's draw among the probe's, by its place among the
/// commands that run, where it was probed; and the probe's words, three a probed draw: its flag,
/// the copies its triangles emit (its counts summed), and 1 where a triangle of it is too wide for
/// few copies (`bind::fan_out::FEW_COPIES`).
/// commands that run, where it was probed; and what the probe found of each draw it probed, by
/// its index.
pub(super) struct FanOutRoutes {
pub(super) commands: Vec<Option<Command>>,
pub(super) start: u32,
pub(super) faults: ReplayFaults,
pub(super) slots: Vec<Option<u32>>,
pub(super) words: Arc<[u32]>,
pub(super) probed: Arc<[Probed]>,
}
/// An encoder's region table ([`table`]): its bytes, until its first draw that binds it uploads
@@ -241,3 +318,6 @@ pub(super) fn target(
},
)
}
#[cfg(test)]
mod tests;
@@ -0,0 +1,87 @@
use super::{parts, Part, Probed};
use metal2vulkan::bind::fan_out::{PROBE_COUNT_WORDS, PROBE_DRAW_WORDS};
/// A part of `count` triangles from `first`.
fn part(first: u32, count: u32, fanned: bool) -> Part {
Part {
first,
count,
fanned,
}
}
/// A flagged draw's parts take each of its triangles once, in order, those from the first flagged
/// one to the last region by region and the others fanned out; a 16-bit list's parts begin at
/// even triangles; a flag past the triangles draws them all region by region.
#[test]
fn a_flagged_draw_s_parts_take_each_triangle_once_in_order() {
assert_eq!(
parts((5, 7), 20, false),
[part(0, 5, true), part(5, 3, false), part(8, 12, true)]
);
assert_eq!(
parts((5, 7), 20, true),
[part(0, 4, true), part(4, 4, false), part(8, 12, true)]
);
assert_eq!(parts((0, 19), 20, false), [part(0, 20, false)]);
assert_eq!(parts((0, 0), 1, true), [part(0, 1, false)]);
assert_eq!(
parts((18, 18), 19, true),
[part(0, 18, true), part(18, 1, false)]
);
assert_eq!(parts((3, 2), 20, false), [part(0, 20, false)]);
assert_eq!(parts((3, 20), 20, false), [part(0, 20, false)]);
for triangles in 1..40 {
for first in 0..triangles {
for last in first..triangles {
for even in [false, true] {
let drawn = parts((first, last), triangles, even);
let mut next = 0;
for p in &drawn {
assert_eq!(p.first, next, "{drawn:?}");
assert!(p.count > 0, "{drawn:?}");
assert!(!even || p.first.is_multiple_of(2), "{drawn:?}");
let flagged =
(p.first..p.first + p.count).any(|t| (first..=last).contains(&t));
assert!(!p.fanned || !flagged, "{drawn:?}");
next += p.count;
}
assert_eq!(next, triangles, "{drawn:?}");
}
}
}
}
}
/// A probed draw's words: the counts summed, a wide mark, and the first and last flagged triangle
/// from the least and the greatest of their raised words.
#[test]
fn a_probed_draw_s_words_name_its_first_and_last_flagged_triangle() {
let lanes = PROBE_COUNT_WORDS as usize;
let mut words = vec![0u32; PROBE_DRAW_WORDS as usize];
words[1] = 3;
words[1 + lanes - 1] = 4;
assert_eq!(
Probed::of(&words),
Probed {
copies: 7,
wide: false,
flagged: None,
}
);
words[0] = 1;
words[1 + lanes + 2] = 1;
// Triangles 9 and 40 flagged, in their lanes.
words[1 + 2 * lanes + 9] = u32::MAX - 9;
words[1 + 2 * lanes + 8] = u32::MAX - 40;
words[1 + 3 * lanes + 9] = 10;
words[1 + 3 * lanes + 8] = 41;
assert_eq!(
Probed::of(&words),
Probed {
copies: 7,
wide: true,
flagged: Some((9, 40)),
}
);
}
@@ -1,22 +1,29 @@
//! A rate-mapped pass's executed commands at a host step, fanned out to the map's regions
//! (`rate_mapped_pass.rs`, **Fan-out**), under both settings of `RateMapRegionPolicy`. Every
//! command but two draws a grid of small triangles, twice, blended at half alpha in its own
//! command but five draws a grid of small triangles, twice, blended at half alpha in its own
//! colour; one between them draws a triangle over the whole target, which touches more regions
//! than the fan-out's copies, so the probe flags it, and another a triangle over four tiles a
//! side, which touches more regions than few copies (`bind::fan_out::FEW_COPIES`) and no more than
//! the copies. Under `FanOut` the probe runs once, the grid
//! commands are fanned out and the large one is drawn region by region, in its place; under `Exact`
//! no probe runs and every command is drawn region by region. Either way the target's bytes are
//! those of the same commands drawn on the encoder, region by region: a command lost, drawn twice
//! or out of order, or a copy drawn into another region, changes the pixels. The probe's and the
//! fanned-out draws' pipelines are begun at commit (`RenderExecution::settle`): the host step
//! takes them made or waits for them, and makes no more pipelines itself than it makes for the
//! same frame under `Exact`.
//! than the fan-out's copies, another a triangle over the whole target one of whose corners lies
//! behind the eye (`w` of -1), and two the grid with one of its triangles, [`WIDE_AT`], over half
//! the target, one with indices and one without, so the probe flags these four; and another a
//! triangle over four tiles a side, which touches more regions than few copies
//! (`bind::fan_out::FEW_COPIES`) and no more than the copies. Under `FanOut` the probe runs once,
//! the grid commands are fanned out, and the four it flagged are drawn in parts
//! (`render/fan_out.rs`, **Parts**), each in its place: each grid with the wide triangle in three,
//! the triangles before it and after it fanned out and it region by region, and each single
//! triangle region by region; under `Exact` no probe runs and every
//! command is drawn region by region. Either way the target's bytes are those of the same
//! commands drawn on the encoder, region by region: a command or a triangle lost, drawn twice or
//! out of order, or a copy drawn into another region or left out of its own, changes the pixels.
//! The
//! probe's and the fanned-out draws' pipelines are begun at commit (`RenderExecution::settle`):
//! the host step takes them made or waits for them, and makes no more pipelines itself than it
//! makes for the same frame under `Exact`.
//!
//! 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_triangle` and
//! `tob_solid` of the owned fixture `validation/fixtures/public/engine/tob_renders.ll`
//! (`llvm-as`).
//! `tob_solid` of the owned fixture `validation/fixtures/public/engine/tob_renders.ll`, and for
//! the triangle behind the eye `cfb_depth_vertex` of `engine/cfb_sample_depth.ll`, which draws
//! each vertex where its buffer holds it (`llvm-as`).
use super::blit_holds::{options, Scratch, WAIT};
use crate::write_routes::GpuWriter;
@@ -34,11 +41,17 @@ use metal2vulkan::metal::{
use metal2vulkan::pipeline::{ColorAttachmentDescriptor, RenderPipelineDescriptor, StageSource};
use std::path::Path;
/// The grid's quads on a side, the commands, and the one that draws the large triangle.
/// The grid's quads on a side, the commands, the one that draws the large triangle, the medium
/// one, the one across `w = 0`, and the grid with a wide triangle without indices and with
/// them, the triangle it replaces.
const GRID: u32 = 16;
const COMMANDS: u32 = 8;
const FLAT: u32 = 0;
const LARGE: u32 = 3;
const MEDIUM: u32 = 5;
const BEHIND: u32 = 6;
const MIXED: u32 = 7;
const WIDE_AT: u32 = 300;
/// A grid command's indices: the grid's triangles, twice.
const INDICES: u32 = 2 * GRID * GRID * 6;
/// The map's screen side, and its quality samples on both axes.
@@ -50,8 +63,14 @@ struct Workload {
device: Device,
queue: CommandQueue,
pipeline: RenderPipelineState,
/// The pipeline of the command across `w = 0`, its positions four floats a vertex.
behind_pipeline: RenderPipelineState,
behind: Buffer,
grid: Buffer,
grid_indices: Buffer,
mixed_indices: Buffer,
/// The vertices of the grid with a wide triangle, each triangle's three in order.
mixed_vertices: Buffer,
large: Buffer,
large_indices: Buffer,
medium_indices: Buffer,
@@ -60,12 +79,25 @@ struct Workload {
map: RasterizationRateMap,
}
/// What a command draws: its positions, its indices and their count.
fn draw_of(workload: &Workload, command: u32) -> (&Buffer, &Buffer, u32) {
/// What a command draws: its pipeline, its positions, its indices (`None`: none, its vertices in
/// order) and their count.
fn draw_of(
workload: &Workload,
command: u32,
) -> (&RenderPipelineState, &Buffer, Option<&Buffer>, u32) {
let (plain, behind) = (&workload.pipeline, &workload.behind_pipeline);
match command {
LARGE => (&workload.large, &workload.large_indices, 3),
MEDIUM => (&workload.large, &workload.medium_indices, 3),
_ => (&workload.grid, &workload.grid_indices, INDICES),
LARGE => (plain, &workload.large, Some(&workload.large_indices), 3),
MEDIUM => (plain, &workload.large, Some(&workload.medium_indices), 3),
BEHIND => (behind, &workload.behind, Some(&workload.large_indices), 3),
MIXED => (
plain,
&workload.grid,
Some(&workload.mixed_indices),
INDICES,
),
FLAT => (plain, &workload.mixed_vertices, None, INDICES),
_ => (plain, &workload.grid, Some(&workload.grid_indices), INDICES),
}
}
@@ -97,6 +129,17 @@ impl Workload {
let pipeline = device
.new_render_pipeline_state(&descriptor, &PipelineOptions::default())
.unwrap();
// The command across `w = 0`: the same colour stage, each vertex where its buffer holds it.
let ll = Path::new(env!("CARGO_MANIFEST_DIR"))
.join("../metal2vulkan-validation/fixtures/public/engine/cfb_sample_depth.ll");
let bitcode = metal2vulkan_devtools::llvm_assemble(&ll).unwrap();
let depth = metal2vulkan::library::Library::from_air(&bitcode).unwrap();
let depth = device.new_library_with_compile_library(depth);
let vertex = depth.new_function_with_name("cfb_depth_vertex").unwrap();
descriptor.vertex = StageSource::Function(vertex.function_descriptor());
let behind_pipeline = device
.new_render_pipeline_state(&descriptor, &PipelineOptions::default())
.unwrap();
// The grid's corners over the target, and its triangles twice.
let at = |i: u32| i as f32 * 2.0 / GRID as f32 - 1.0;
let grid: Vec<u8> = (0..=GRID)
@@ -119,6 +162,15 @@ impl Workload {
.collect();
let twice = [&triangles[..], &triangles[..]].concat();
let grid_indices: Vec<u8> = twice.iter().flat_map(|i| i.to_le_bytes()).collect();
// The grid with triangle `WIDE_AT` over the target's lower left half.
let mut mixed = twice.clone();
let wide = 3 * WIDE_AT as usize;
mixed[wide..wide + 3].copy_from_slice(&[corner(0, 0), corner(GRID, 0), corner(0, GRID)]);
let mixed_indices: Vec<u8> = mixed.iter().flat_map(|i| i.to_le_bytes()).collect();
let mixed_vertices: Vec<u8> = (mixed.iter())
.flat_map(|&i| [at(i % (GRID + 1)), at(i / (GRID + 1))])
.flat_map(f32::to_le_bytes)
.collect();
// One triangle over the whole target, and one from the centre of a tile of the map
// (32 screen pixels) to the centre of the fourth after it, on each axis.
let large: Vec<u8> = [
@@ -133,6 +185,19 @@ impl Workload {
.flatten()
.flat_map(f32::to_le_bytes)
.collect();
// A triangle whose third corner lies behind the eye, on the plane `w = 1 + y / 2`, whose
// part in view spans the target (`w` from 2/3 to 2 there, `|x|` at most 2, `y` from -2/3
// to 2): the device clips it off the target, and its edges lie off the target too, so no
// pixel centre is near one.
let behind: Vec<u8> = [
[-12.0f32, 4.0, 0.25, 3.0],
[12.0, 4.0, 0.25, 3.0],
[0.0, -4.0, 0.25, -1.0],
]
.into_iter()
.flatten()
.flat_map(f32::to_le_bytes)
.collect();
let indices =
|at: [u32; 3]| -> Vec<u8> { at.iter().flat_map(|i| i.to_le_bytes()).collect() };
let (large_indices, medium_indices) = (indices([0, 1, 2]), indices([3, 4, 5]));
@@ -151,7 +216,7 @@ impl Workload {
(device.new_buffer_with_bytes(bytes, ResourceOptions::shared())).unwrap()
};
let mut icb = IndirectCommandBufferDescriptor::new();
icb.command_types = IndirectCommandType::DRAW_INDEXED;
icb.command_types = IndirectCommandType::DRAW | IndirectCommandType::DRAW_INDEXED;
icb.inherit_buffers = false;
icb.max_vertex_buffer_bind_count = 1;
icb.max_fragment_buffer_bind_count = 1;
@@ -167,8 +232,12 @@ impl Workload {
let workload = Workload {
queue: device.new_command_queue().unwrap(),
pipeline,
behind_pipeline,
behind: buffer(&behind),
grid: buffer(&grid),
grid_indices: buffer(&grid_indices),
mixed_indices: buffer(&mixed_indices),
mixed_vertices: buffer(&mixed_vertices),
large: buffer(&large),
large_indices: buffer(&large_indices),
medium_indices: buffer(&medium_indices),
@@ -182,16 +251,14 @@ impl Workload {
.icb
.indirect_render_command_at(u64::from(k))
.unwrap();
command
.set_render_pipeline_state(&workload.pipeline)
.unwrap();
let (positions, indices, count) = draw_of(&workload, k);
let (pipeline, positions, indices, count) = draw_of(&workload, k);
command.set_render_pipeline_state(pipeline).unwrap();
command.set_vertex_buffer(Some(positions), 0, 0).unwrap();
command
.set_fragment_buffer(Some(&workload.colors), u64::from(k) * 256, 0)
.unwrap();
command
.draw_indexed_primitives(
match indices {
Some(indices) => command.draw_indexed_primitives(
PrimitiveType::Triangle,
u64::from(count),
IndexType::UInt32,
@@ -200,8 +267,10 @@ impl Workload {
1,
0,
0,
)
.unwrap();
),
None => command.draw_primitives(PrimitiveType::Triangle, 0, u64::from(count), 1, 0),
}
.unwrap();
}
// The GPU may write the records: the host step records the pass.
workload.icb.written_by_gpu(GpuWriter::Reset);
@@ -236,13 +305,14 @@ impl Workload {
.unwrap(),
false => {
for k in 0..COMMANDS {
let (positions, indices, count) = draw_of(self, k);
let (pipeline, positions, indices, count) = draw_of(self, k);
encoder.set_render_pipeline_state(pipeline).unwrap();
encoder.set_vertex_buffer(Some(positions), 0, 0).unwrap();
encoder
.set_fragment_buffer(Some(&self.colors), u64::from(k) * 256, 0)
.unwrap();
encoder
.draw_indexed_primitives(
match indices {
Some(indices) => encoder.draw_indexed_primitives(
PrimitiveType::Triangle,
count,
IndexType::UInt32,
@@ -251,8 +321,10 @@ impl Workload {
1,
0,
0,
)
.unwrap();
),
None => encoder.draw_primitives(PrimitiveType::Triangle, 0, count, 1, 0),
}
.unwrap();
}
}
}
@@ -292,32 +364,34 @@ fn fans_out(device: &Device) -> bool {
.all(|feature| features.contains(feature))
}
/// The probes, flagged draws and fanned-out draws between two counts.
fn fan_counts(before: &WorkCounts, after: &WorkCounts) -> [u64; 3] {
/// The probes, flagged draws, fanned-out draws and draws in parts between two counts.
fn fan_counts(before: &WorkCounts, after: &WorkCounts) -> [u64; 4] {
[
after.rate_map_probes - before.rate_map_probes,
after.rate_map_flagged_draws - before.rate_map_flagged_draws,
after.rate_map_fanned_draws - before.rate_map_fanned_draws,
after.rate_map_parted_draws - before.rate_map_parted_draws,
]
}
/// The texels of `a` and `b` that differ.
fn differing(a: &[u8], b: &[u8]) -> usize {
a.chunks(4).zip(b.chunks(4)).filter(|(a, b)| a != b).count()
/// The texels of `a` and `b` that differ: how many, and the first's index and its bytes in each.
fn differing<'a>(a: &'a [u8], b: &'a [u8]) -> (usize, Option<(usize, &'a [u8], &'a [u8])>) {
let mut differ = (a.chunks(4).zip(b.chunks(4)).enumerate()).filter(|(_, (a, b))| a != b);
let first = differ.next().map(|(at, (a, b))| (at, a, b));
(first.map_or(0, |_| 1 + differ.count()), first)
}
/// Under `FanOut` the host step probes once, fans the grid commands out and draws the large one
/// region by region between them, with the pipelines `commit` began: the fan-out's and the
/// regions variant's, so the step makes none. The grid commands are drawn through the variant of
/// few copies and the medium one through the most copies'. Its probe and its fanned-out draws
/// each upload the region table once, the commit's settle none. The pixels are the encoder's
/// region-by-region draws'.
/// Under `FanOut` the host step probes once, fans the grid commands out and draws the four it
/// flagged in parts between them, their one wide triangle each region by region, with the
/// pipelines `commit` began: the fan-out's and the regions variant's, so the step makes none. The grid commands are drawn through the variant of few copies and the medium one
/// through the most copies'. Its probe and its fanned-out draws each upload the region table
/// once, the commit's settle none. The pixels are the encoder's region-by-region draws'.
#[test]
fn a_host_step_fans_out_the_commands_the_probe_does_not_flag() {
let scratch = Scratch::new("rate-mapped-fan-out");
let workload = Workload::new(device_under(&scratch.0, RateMapRegionPolicy::FanOut));
let (drawn, before, after) = workload.frame(false);
assert_eq!(fan_counts(&before, &after), [0; 3], "the encoder's draws");
assert_eq!(fan_counts(&before, &after), [0; 4], "the encoder's draws");
let (fanned, before, after) = workload.frame(true);
let counts = fan_counts(&before, &after);
let probe_nanos = after.rate_map_probe_gpu_nanos - before.rate_map_probe_gpu_nanos;
@@ -326,31 +400,43 @@ fn a_host_step_fans_out_the_commands_the_probe_does_not_flag() {
let waited = after.rate_map_fan_out_pipelines_waited - before.rate_map_fan_out_pipelines_waited;
let tables = after.rate_map_fan_tables_uploaded - before.rate_map_fan_tables_uploaded;
let few = after.rate_map_fanned_few_draws - before.rate_map_fanned_few_draws;
let by_regions =
after.rate_map_parted_region_triangles - before.rate_map_parted_region_triangles;
let wait = after.rate_map_probe_wait_nanos - before.rate_map_probe_wait_nanos;
eprintln!(
"RATE-MAP-FAN-OUT counts {counts:?} probe_gpu_nanos {probe_nanos}; fan-out pipelines \
{ready} ready, {waited} waited for; {made} made at the step; {tables} region tables \
uploaded; {few} drawn of few copies"
"RATE-MAP-FAN-OUT counts {counts:?} probe_gpu_nanos {probe_nanos}, waited {wait} ns; \
fan-out pipelines {ready} ready, {waited} waited for; {made} made at the step; {tables} \
region tables uploaded; {few} drawn of few copies; {by_regions} triangles of draws in \
parts region by region"
);
assert_eq!(made, 0, "pipelines the host step made");
match fans_out(&workload.device) {
true => {
assert_eq!(counts, [1, 1, u64::from(COMMANDS - 1)]);
assert_eq!(counts, [1, 4, u64::from(COMMANDS - 4), 4]);
assert_eq!(tables, 2, "region tables uploaded");
assert!(
ready + waited >= 3,
"the commit began no probe or draw pipeline"
);
assert_eq!(few, u64::from(COMMANDS - 2), "draws of few copies");
assert_eq!(few, u64::from(COMMANDS - 5), "draws of few copies");
assert_eq!(
by_regions, 4,
"triangles of draws in parts region by region"
);
assert!(wait > 0, "the host's wait for the probe");
}
false => assert_eq!(counts, [0; 3]),
false => assert_eq!(counts, [0; 4]),
}
// Every pixel took the commands' blends: none is the clear's black.
assert!(
drawn.chunks(4).all(|texel| texel[..3] != [0, 0, 0]),
"a pixel the commands did not draw"
);
let differ = differing(&drawn, &fanned);
assert_eq!(differ, 0, "texels the fanned-out execution draws otherwise");
let (differ, first) = differing(&drawn, &fanned);
assert_eq!(
differ, 0,
"texels the fanned-out execution draws otherwise, the first {first:?}"
);
}
/// With the encoder trail on (`encoder_trail.rs`), the host step notes the states its commands
@@ -369,11 +455,14 @@ fn the_encoder_trail_fans_out_the_same_pixels() {
let counts = fan_counts(&before, &after);
eprintln!("RATE-MAP-FAN-OUT-TRAIL counts {counts:?}");
match fans_out(&workload.device) {
true => assert_eq!(counts, [1, 1, u64::from(COMMANDS - 1)]),
false => assert_eq!(counts, [0; 3]),
true => assert_eq!(counts, [1, 4, u64::from(COMMANDS - 4), 4]),
false => assert_eq!(counts, [0; 4]),
}
let differ = differing(&drawn, &fanned);
assert_eq!(differ, 0, "texels the fanned-out execution draws otherwise");
let (differ, first) = differing(&drawn, &fanned);
assert_eq!(
differ, 0,
"texels the fanned-out execution draws otherwise, the first {first:?}"
);
}
/// Under `Exact` no probe runs and every command is drawn region by region, with the regions
@@ -385,10 +474,13 @@ fn exact_regions_draw_every_command_region_by_region() {
let workload = Workload::new(device_under(&scratch.0, RateMapRegionPolicy::Exact));
let (drawn, _, _) = workload.frame(false);
let (exact, before, after) = workload.frame(true);
assert_eq!(fan_counts(&before, &after), [0; 3]);
assert_eq!(fan_counts(&before, &after), [0; 4]);
let made = after.host_step_pipelines_made - before.host_step_pipelines_made;
eprintln!("RATE-MAP-EXACT {made} made at the step");
assert_eq!(made, 0, "pipelines the host step made");
let differ = differing(&drawn, &exact);
assert_eq!(differ, 0, "texels the execution draws otherwise");
let (differ, first) = differing(&drawn, &exact);
assert_eq!(
differ, 0,
"texels the execution draws otherwise, the first {first:?}"
);
}
+37 -3
View File
@@ -231,9 +231,12 @@ pub(crate) struct Counters {
rate_map_piece_gpu_nanos_most: AtomicU64,
rate_map_probes: AtomicU64,
rate_map_probe_gpu_nanos: AtomicU64,
rate_map_probe_wait_nanos: AtomicU64,
rate_map_flagged_draws: AtomicU64,
rate_map_fanned_draws: AtomicU64,
rate_map_fanned_few_draws: AtomicU64,
rate_map_parted_draws: AtomicU64,
rate_map_parted_region_triangles: AtomicU64,
rate_map_fan_out_pipelines_ready: AtomicU64,
rate_map_fan_out_pipelines_waited: AtomicU64,
rate_map_fan_tables_uploaded: AtomicU64,
@@ -2778,7 +2781,7 @@ impl Counters {
}
/// A host step's probe of a rate-mapped pass's draws was submitted and waited for
/// (`rate_mapped_pass.rs`, **Fan-out**), of which `flagged` draws are drawn region by region.
/// (`rate_mapped_pass.rs`, **Fan-out**), of which it flagged `flagged` draws.
pub(crate) fn rate_map_probe(&self, flagged: u64) {
(self.rate_map_probes).fetch_add(1, Ordering::Relaxed);
(self.rate_map_flagged_draws).fetch_add(flagged, Ordering::Relaxed);
@@ -2807,6 +2810,20 @@ impl Counters {
(self.rate_map_probe_gpu_nanos).fetch_add(nanos, Ordering::Relaxed);
}
/// A host step waited `took` on the host's clock for its probe, from its submission until
/// the host saw it complete (`rate_mapped_pass.rs`, **Fan-out**).
pub(crate) fn rate_map_probe_waited(&self, took: std::time::Duration) {
let nanos = u64::try_from(took.as_nanos()).unwrap_or(u64::MAX);
(self.rate_map_probe_wait_nanos).fetch_add(nanos, Ordering::Relaxed);
}
/// A draw the probe flagged was drawn in parts (`render/fan_out.rs`, **Parts**), of which
/// `by_regions` triangles region by region.
pub(crate) fn rate_map_drawn_in_parts(&self, by_regions: u64) {
(self.rate_map_parted_draws).fetch_add(1, Ordering::Relaxed);
(self.rate_map_parted_region_triangles).fetch_add(by_regions, Ordering::Relaxed);
}
/// A command's draw in a rate-mapped pass was drawn once, fanned out to its regions, through
/// the variant of few copies where `few` (`rate_mapped_pass.rs`, **Fan-out**).
pub(crate) fn rate_map_fanned_draw(&self, few: bool) {
@@ -7025,8 +7042,16 @@ pub struct WorkCounts {
/// Their GPU time, in nanoseconds, read from timestamps written around each (none where the
/// device writes no timestamps or its driver's timestamps wait for every queue's).
pub rate_map_probe_gpu_nanos: u64,
/// The draws they probed that they flagged, each drawn region by region: a triangle crosses
/// `w = 0` or touches more regions than the fan-out's copies.
/// The host's wait for them, in nanoseconds on the host's clock, from each one's submission
/// until the host saw it complete: their GPU time
/// ([`rate_map_probe_gpu_nanos`](Self::rate_map_probe_gpu_nanos)), the submission's way to
/// the device and the completion's back, and the queue's work ahead of them. Part of
/// [`host_step_nanos`](Self::host_step_nanos).
pub rate_map_probe_wait_nanos: u64,
/// The draws they probed that they flagged: a triangle crosses `w = 0` or touches more
/// regions than the fan-out's copies. Each is drawn in parts
/// ([`rate_map_parted_draws`](Self::rate_map_parted_draws)), or region by region whole where
/// it cannot be (`render/fan_out.rs`, **Parts**).
pub rate_map_flagged_draws: u64,
/// Executed commands' draws in rate-mapped passes drawn once, fanned out to the regions their
/// triangles touch.
@@ -7034,6 +7059,11 @@ pub struct WorkCounts {
/// Of them, those the probe marked no triangle of too wide for few copies, drawn through the
/// variant of `bind::fan_out::FEW_COPIES` copies (`RegionFanOut::DrawFew`).
pub rate_map_fanned_few_draws: u64,
/// Flagged draws drawn in parts: the triangles from the first the probe flagged to the last
/// region by region, those before and after fanned out (`render/fan_out.rs`, **Parts**).
pub rate_map_parted_draws: u64,
/// Their triangles drawn region by region.
pub rate_map_parted_region_triangles: u64,
/// `VkPipeline`s of probes' and fanned-out draws' variants that `commit` began making on the
/// device's pool, settling what the host step that records the pass compiles, and that a
/// host step fanning the pass out found made already (`rate_mapped_pass.rs`, **Fan-out**).
@@ -10151,9 +10181,13 @@ impl Device {
.load(Ordering::Relaxed),
rate_map_probes: counters.rate_map_probes.load(Ordering::Relaxed),
rate_map_probe_gpu_nanos: counters.rate_map_probe_gpu_nanos.load(Ordering::Relaxed),
rate_map_probe_wait_nanos: (counters.rate_map_probe_wait_nanos).load(Ordering::Relaxed),
rate_map_flagged_draws: counters.rate_map_flagged_draws.load(Ordering::Relaxed),
rate_map_fanned_draws: counters.rate_map_fanned_draws.load(Ordering::Relaxed),
rate_map_fanned_few_draws: (counters.rate_map_fanned_few_draws).load(Ordering::Relaxed),
rate_map_parted_draws: (counters.rate_map_parted_draws).load(Ordering::Relaxed),
rate_map_parted_region_triangles: (counters.rate_map_parted_region_triangles)
.load(Ordering::Relaxed),
rate_map_fan_out_pipelines_ready: (counters.rate_map_fan_out_pipelines_ready)
.load(Ordering::Relaxed),
rate_map_fan_out_pipelines_waited: (counters.rate_map_fan_out_pipelines_waited)
@@ -32,9 +32,11 @@
//! triangles out to the regions (`RateMapRegionPolicy::FanOut`, `rate_mapped_pass.rs`,
//! **Fan-out**), after a probe; under `Exact` (`rate_mapped_pieces_host_step_exact`) every draw
//! is drawn region by region, as at `commit`. The line then states the probes, the draws they
//! flagged, the draws fanned out and the probes' GPU time; fanned out, a draw is never cut into
//! ranges, so only the region-by-region frames are checked for ranges and pieces, and a
//! fanned-out frame for its probe and its fanned-out draws.
//! flagged, the draws fanned out, the flagged ones drawn in parts and their triangles drawn
//! region by region (`rate_map_parted_draws`, `rate_map_parted_region_triangles`), and the
//! probes' GPU time and the host's wait for them (`rate_map_probe_wait_nanos`); fanned out, a
//! draw is never cut into ranges, so only the region-by-region frames are checked for ranges and
//! pieces, and a fanned-out frame for its probe, the host's wait for it and its fanned-out draws.
//!
//! With wide triangles among the grid's (`rate_mapped_pieces_host_step_wide` and its `_exact`
//! twin), one triangle of every [`WIDE_EVERY`] is replaced by one [`WIDE`] quads a side, which
@@ -109,8 +111,10 @@ const PIECE_LIMIT: Duration = Duration::from_secs(1);
/// The counts of `work`: the pieces past the first, the index ranges past the first, the pieces
/// timed, their GPU time and the longest's; the probes, the draws they flagged, the draws fanned
/// out and the probes' GPU time.
fn counts(work: &WorkCounts) -> [u64; 15] {
/// out and the probes' GPU time; the host step's time and making; the fan-out's pipelines; the
/// draws of few copies; the draws in parts and their triangles drawn region by region; the
/// host's wait for the probes.
fn counts(work: &WorkCounts) -> [u64; 18] {
[
work.rate_map_pieces,
work.rate_map_index_ranges,
@@ -127,6 +131,9 @@ fn counts(work: &WorkCounts) -> [u64; 15] {
work.rate_map_fan_out_pipelines_ready,
work.rate_map_fan_out_pipelines_waited,
work.rate_map_fanned_few_draws,
work.rate_map_parted_draws,
work.rate_map_parted_region_triangles,
work.rate_map_probe_wait_nanos,
]
}
@@ -382,6 +389,7 @@ fn pieces_frame(step: bool, policy: RateMapRegionPolicy, scale: u32, triangles:
let [probes, flagged, fanned, probe_nanos] = [5, 6, 7, 8].map(delta);
let [stepped, made, made_nanos, ready, waited] = [9, 10, 11, 12, 13].map(delta);
let few = delta(14);
let [parted, by_regions, probe_wait] = [15, 16, 17].map(delta);
let most = Duration::from_nanos(after[4]);
let indices: u64 = draws.iter().map(|&count| u64::from(count)).sum();
let mean = Duration::from_nanos(nanos / timed.max(1));
@@ -396,8 +404,9 @@ fn pieces_frame(step: bool, policy: RateMapRegionPolicy, scale: u32, triangles:
"RATE-MAP-PIECES {name} ({at}, {frame}): screen {}x{}, physical {}x{}, {regions} \
regions, {spread} commands of {indices} indices: the command buffer {:.1} ms of GPU \
time, {} pieces ({ranges} index ranges past the first); {timed} pieces timed, the \
longest {:.2} ms, the mean {:.2} ms; {probes} probes of {:.2} ms, {flagged} draws \
flagged, {fanned} fanned out ({few} of few copies); the host step {:.1} ms, \
longest {:.2} ms, the mean {:.2} ms; {probes} probes of {:.2} ms, waited for {:.2} ms, \
{flagged} draws flagged, {fanned} fanned out ({few} of few copies), {parted} drawn in \
parts ({by_regions} triangles region by region); the host step {:.1} ms, \
{made} pipelines made there, \
{:.1} ms creating render pipelines; the fan-out's pipelines {ready} ready at the \
step, {waited} waited for; the commit {:.1} ms",
@@ -410,6 +419,7 @@ fn pieces_frame(step: bool, policy: RateMapRegionPolicy, scale: u32, triangles:
most.as_secs_f64() * 1e3,
mean.as_secs_f64() * 1e3,
probe_nanos as f64 * 1e-6,
probe_wait as f64 * 1e-6,
stepped as f64 * 1e-6,
made_nanos as f64 * 1e-6,
commit.as_secs_f64() * 1e3,
@@ -423,6 +433,11 @@ fn pieces_frame(step: bool, policy: RateMapRegionPolicy, scale: u32, triangles:
triangles == Triangles::Wide,
"draws flagged: {flagged}"
);
assert_eq!(parted, flagged, "flagged draws drawn in parts");
assert!(
probe_wait > 0,
"the host's wait for the probe was not counted"
);
}
false => {
assert_eq!((probes, fanned), (0, 0), "a draw was fanned out");
+12 -8
View File
@@ -37,15 +37,19 @@
//! 0)`.
/// The words of a probe's flags each probed draw takes: its flag, then the
/// [`PROBE_COUNT_WORDS`] its triangles add their copies into, then as many its triangles that
/// reach more than [`FEW_COPIES`] pairs of segments mark (`pipeline::link::fan_out`, the probe),
/// from word `PROBE_DRAW_WORDS·i` for the draw of index `i`. The consumer sums a draw's counts,
/// and draws a draw none of whose wide words is marked through its variant of few copies
/// (`RegionFanOut::DrawFew`).
pub const PROBE_DRAW_WORDS: u32 = 1 + 2 * PROBE_COUNT_WORDS;
/// [`PROBE_COUNT_WORDS`] its triangles add their copies into, then as many its triangles that it
/// does not flag and that reach more than [`FEW_COPIES`] pairs of segments mark, then as many
/// that hold the greatest `u32::MAX − PrimitiveId` of its flagged triangles, then as many that
/// hold the greatest `PrimitiveId + 1` of them (`pipeline::link::fan_out`, the probe), from word
/// `PROBE_DRAW_WORDS·i` for the draw of index `i`, each zero before the probe. The consumer sums
/// a draw's counts, draws a draw none of whose wide words is marked through its variant of few
/// copies (`RegionFanOut::DrawFew`), and takes the first and the last flagged primitive of a
/// flagged draw from the least and the greatest of the last two sets.
pub const PROBE_DRAW_WORDS: u32 = 1 + 4 * PROBE_COUNT_WORDS;
/// The words a probed draw's triangles add their copies into, and the words they mark wide, a
/// triangle the one of each its `PrimitiveId` picks (`PrimitiveId mod PROBE_COUNT_WORDS`): one
/// The words a probed draw's triangles add their copies into, and in each of the other sets of
/// its words ([`PROBE_DRAW_WORDS`]) as many, a triangle the one of each set its `PrimitiveId`
/// picks (`PrimitiveId mod PROBE_COUNT_WORDS`): one
/// word every triangle of a draw added into made the probe 15.4 to 20.7 ms of an RTX 3090's GPU
/// time for 64 draws of 306,036 triangles; spread over these, 1.45 ms (NVIDIA 620.70.06, the
/// pieces lane).
+9 -5
View File
@@ -434,11 +434,15 @@ pub enum RegionFanOut {
/// `u32`s from `PROBE_DRAW_WORDS·i`, `i` its pushed index (`PushField::RegionProbe`, at
/// [`push_offset`](Self::push_offset) for stage `GEOMETRY`), it writes 1 into the first where a
/// triangle of the draw touches more regions than [`copies`](Self::copies), or crosses `w = 0`,
/// and the consumer draws such a draw region by region; adds the copies the draw emits of each
/// triangle it fans out into one of the `bind::fan_out::PROBE_COUNT_WORDS` after it, which the
/// draw's work counts; and writes 1 into one of the as many after those where a triangle touches
/// more regions than `bind::fan_out::FEW_COPIES`: a draw none of whose such words is 1 draws
/// through its [`RegionFanOut::DrawFew`] variant.
/// and raises the words after those below to that triangle's `PrimitiveId`; the consumer draws
/// such a draw's triangles from the first flagged one to the last region by region, the others
/// fanned out, or, where it cannot draw the draw in parts, the whole draw region by region. It
/// adds the copies the draw emits of each triangle it fans out into one of the
/// `bind::fan_out::PROBE_COUNT_WORDS` after the flag, which the draw's work counts; and writes 1
/// into one of the as many after those where a triangle it does not flag touches more regions
/// than `bind::fan_out::FEW_COPIES`: a draw none of whose such words is 1 draws, or its parts
/// fanned out draw, through its [`RegionFanOut::DrawFew`] variant. The words' layout is
/// `bind::fan_out::PROBE_DRAW_WORDS`'s.
#[non_exhaustive]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
@@ -27,9 +27,12 @@
//! widening, reach more pairs than the copies; and adds the copies the draw emits of each
//! triangle it fans out, the pairs its bounds reach unwidened, into the count its `PrimitiveId`
//! picks of the [`PROBE_COUNT_WORDS`] after it, so the consumer sums the draw's work and no
//! word takes every triangle's add; and for a triangle whose bounds, widened, reach more pairs
//! than [`FEW_COPIES`], writes 1 into the word its `PrimitiveId` picks of the as many after
//! those, which mark the draw one its variant of few copies cannot draw. Its writes need
//! word takes every triangle's add; for a triangle it does not flag whose bounds, widened,
//! reach more pairs than [`FEW_COPIES`], writes 1 into the word its `PrimitiveId` picks of the
//! as many after those, which mark the draw one its variant of few copies cannot draw; and for
//! a triangle it flags, raises the word its `PrimitiveId` picks of the as many after those to
//! `u32::MAX − PrimitiveId`, and of the as many after them to `PrimitiveId + 1`, so the
//! consumer finds the draw's first and last flagged triangle. Its writes need
//! `vertexPipelineStoresAndAtomics`.
use super::geometry::{array, kf, ku, scalar, GeometryStages};
@@ -402,10 +405,29 @@ pub(super) fn module(stages: &GeometryStages, fan: FanOutStage) -> BResult<Typed
let zero = ku(fb, 0)?;
fb.access_chain(base, &[zero, at])
};
// A flagged triangle: the draw's flag, and its `PrimitiveId` raised into the first's
// and the last's words it picks.
let lanes = ku(&mut fb, PROBE_COUNT_WORDS)?;
let wide_at = fb.binary(BinOp::IAdd, count_at, lanes)?;
let first_at = fb.binary(BinOp::IAdd, wide_at, lanes)?;
let last_at = fb.binary(BinOp::IAdd, first_at, lanes)?;
let most_id = ku(&mut fb, u32::MAX)?;
let first = fb.binary(BinOp::ISub, most_id, id)?;
let last = fb.binary(BinOp::IAdd, id, one)?;
let arm: ArmFn<'_, ()> = Box::new(move |fb, _| {
let ptr = word_ptr(fb, flag_at)?;
let one = ku(fb, 1)?;
fb.atomic_store(ptr, Scope::Device, Semantics::RELAXED, one)?;
for (at, value) in [(first_at, first), (last_at, last)] {
let ptr = word_ptr(fb, at)?;
fb.atomic(
AtomicOp::UMax,
ptr,
Scope::Device,
Semantics::RELAXED,
value,
)?;
}
Ok(ArmEnd::FallThrough(Vec::new()))
});
fb.if_(&mut ctx, flagged, arm, None)?;
@@ -422,11 +444,12 @@ pub(super) fn module(stages: &GeometryStages, fan: FanOutStage) -> BResult<Typed
Ok(ArmEnd::FallThrough(Vec::new()))
});
fb.if_(&mut ctx, counted, arm, None)?;
// More pairs than a draw of few copies emits: the wide word its `PrimitiveId` picks.
// A triangle it does not flag of more pairs than a draw of few copies emits: the wide
// word its `PrimitiveId` picks.
let few = ku(&mut fb, FEW_COPIES)?;
let wide = fb.binary(BinOp::UGreaterThan, count, few)?;
let lanes = ku(&mut fb, PROBE_COUNT_WORDS)?;
let wide_at = fb.binary(BinOp::IAdd, count_at, lanes)?;
let fanned = fb.unary(UnOp::LogicalNot, flagged)?;
let wide = fb.binary(BinOp::LogicalAnd, fanned, wide)?;
let arm: ArmFn<'_, ()> = Box::new(move |fb, _| {
let ptr = word_ptr(fb, wide_at)?;
let one = ku(fb, 1)?;
@@ -147,7 +147,8 @@ fn instructions(words: &[u32], op: crate::spv::Op) -> Vec<&[u32]> {
/// A probe's triangle stage adds each triangle's copies once, into the count of its draw's
/// [`PROBE_COUNT_WORDS`](crate::bind::fan_out::PROBE_COUNT_WORDS) that its `PrimitiveId` picks
/// (masked by their number less one), whether or not the fragment function reads the primitive's
/// index: no one word takes every triangle's add.
/// index: no one word takes every triangle's add. A flagged triangle raises its draw's first's and
/// last's words once each.
#[test]
fn a_probe_adds_a_triangle_s_copies_into_the_count_its_primitive_picks() {
use crate::spv::{BuiltIn, Decoration, Op};
@@ -167,6 +168,8 @@ fn a_probe_adds_a_triangle_s_copies_into_the_count_its_primitive_picks() {
assert_eq!(instructions(words, Op::AtomicIAdd).len(), 1, "one add");
// The flag's store, and the wide word's.
assert_eq!(instructions(words, Op::AtomicStore).len(), 2, "two stores");
// A flagged triangle's raise of the first's and the last's words.
assert_eq!(instructions(words, Op::AtomicUMax).len(), 2, "two raises");
let primitive = (instructions(words, Op::Decorate).into_iter())
.filter(|d| d[1..] == [Decoration::BuiltIn as u32, BuiltIn::PrimitiveId as u32])
.count();
+3 -2
View File
@@ -291,8 +291,9 @@ pub enum SyntheticBinding {
RateMapRegions,
/// A fan-out probe's flags (`GraphicsState::region_fan_out`), a storage buffer of `u32`s its
/// geometry stage writes into at the pushed index (`PushField::RegionProbe`,
/// `bind::fan_out::PROBE_DRAW_WORDS` a draw): a flag, the copies its draw emits, and the marks
/// of its triangles too wide for few copies. Declared with the vertex stage's symbols.
/// `bind::fan_out::PROBE_DRAW_WORDS` a draw): a flag, the copies its draw emits, the marks
/// of its triangles too wide for few copies, and its first and last flagged triangle. Declared
/// with the vertex stage's symbols.
RateMapFlags,
/// The render encoder's tessellation factor buffer (`setTessellationFactorBuffer:offset:
/// instanceStride:`), a read-only storage buffer of a tessellation pipeline's synthesized
+4 -1
View File
@@ -1107,7 +1107,7 @@ const-value metal2vulkan::bind::fan_out::FEW_COPIES 4
const-value metal2vulkan::bind::fan_out::HEADER_ENTRIES 2
const-value metal2vulkan::bind::fan_out::MAX_SEGMENTS 128
const-value metal2vulkan::bind::fan_out::PROBE_COUNT_WORDS 32
const-value metal2vulkan::bind::fan_out::PROBE_DRAW_WORDS 1 + 2 * PROBE_COUNT_WORDS
const-value metal2vulkan::bind::fan_out::PROBE_DRAW_WORDS 1 + 4 * PROBE_COUNT_WORDS
const-value metal2vulkan::bind::fan_out::TABLE_BYTES (HEADER_ENTRIES as u64 + 4 * MAX_SEGMENTS as u64) * 16
const-value metal2vulkan::bind::fan_out::WIDEN_PIXELS 0.125
const-value metal2vulkan::bind::indirect_commands::BINDING_COUNT 32
@@ -3243,11 +3243,14 @@ field metal2vulkan-runtime::WorkCounts.rate_map_fanned_draws pub rate_map_fanned
field metal2vulkan-runtime::WorkCounts.rate_map_fanned_few_draws pub rate_map_fanned_few_draws: u64
field metal2vulkan-runtime::WorkCounts.rate_map_flagged_draws pub rate_map_flagged_draws: u64
field metal2vulkan-runtime::WorkCounts.rate_map_index_ranges pub rate_map_index_ranges: u64
field metal2vulkan-runtime::WorkCounts.rate_map_parted_draws pub rate_map_parted_draws: u64
field metal2vulkan-runtime::WorkCounts.rate_map_parted_region_triangles pub rate_map_parted_region_triangles: u64
field metal2vulkan-runtime::WorkCounts.rate_map_piece_gpu_nanos pub rate_map_piece_gpu_nanos: u64
field metal2vulkan-runtime::WorkCounts.rate_map_piece_gpu_nanos_most pub rate_map_piece_gpu_nanos_most: u64
field metal2vulkan-runtime::WorkCounts.rate_map_pieces pub rate_map_pieces: u64
field metal2vulkan-runtime::WorkCounts.rate_map_pieces_timed pub rate_map_pieces_timed: u64
field metal2vulkan-runtime::WorkCounts.rate_map_probe_gpu_nanos pub rate_map_probe_gpu_nanos: u64
field metal2vulkan-runtime::WorkCounts.rate_map_probe_wait_nanos pub rate_map_probe_wait_nanos: u64
field metal2vulkan-runtime::WorkCounts.rate_map_probes pub rate_map_probes: u64
field metal2vulkan-runtime::WorkCounts.reading_draws_by_coverage pub reading_draws_by_coverage: u64
field metal2vulkan-runtime::WorkCounts.reading_draws_in_place pub reading_draws_in_place: u64
Can't render this file because it is too large.
+10 -5
View File
@@ -5774,11 +5774,16 @@ each item named states the rule in full.
triangles is drawn once instead where a probe finds that none of its triangles crosses `w = 0`
or touches more regions than the fan-out's copies: its variant's geometry stage emits a copy of
each triangle for each region it touches (`VariantKey::region_fan_out`), a pixel centre within a
rounding error of an edge possibly covered otherwise (`docs/FAST-PATHS.md`). The probe costs
the host step a submission it waits for before the pass, which runs each probed draw's vertex
function and geometry stage once and shades nothing (`WorkCounts::rate_map_probes`,
`rate_map_probe_gpu_nanos`); a fanned-out draw runs its vertex function once where region by
region it runs once per region (`rate_mapped_pass.rs`, **Fan-out**).
rounding error of an edge possibly covered otherwise (`docs/FAST-PATHS.md`). A draw the probe
flags, a list of triangles of one instance whose pipeline reads no `[[primitive_id]]` and
writes no memory, is drawn in parts in its place: its triangles from the first the probe
flagged to the last region by region, those before and after fanned out
(`WorkCounts::rate_map_parted_draws`); another flagged draw is drawn region by region. The
probe costs the host step a submission it waits for before the pass, which runs each probed
draw's vertex function and geometry stage once and shades nothing (`WorkCounts::rate_map_probes`,
`rate_map_probe_gpu_nanos`, the host's wait `rate_map_probe_wait_nanos`); a fanned-out draw
runs its vertex function once where region by region it runs once per region
(`rate_mapped_pass.rs`, **Fan-out**).
- **A pass over a map of a zero screen extent is refused**, `RegionError::RegionExtent` on that
axis: the layer has no physical pixel there, so no attachment of the map's physical size can be
made, and what Metal rasterizes in such a pass is not measured.
+1 -1
View File
@@ -47,7 +47,7 @@ three consumer pipelines: A2X (`a2x-s4`, `a2x-s96`), Xgc14 (`xgc14-bgra8`) and X
| An attachment (not memoryless) that a pass loads `DontCare` and does not store, in a pass whose draws reach a tile, is cleared over the render area (`clear_reach.rs`) on a driver measured to run that clear no slower than its `DONT_CARE` load (`DriverFact::UnstoredClearNoSlower`: MoltenVK on the M3 Max, RADV on the Radeon 780M), and left `DONT_CARE` on every other driver; an aspect of separate depth and stencil textures likewise, each aspect apart, in the scratch image of the combined format the pass renders them through (`depth_stencil_scratch.rs`). Metal's draws read zero (a colour) or the pass's clear value (depth, stencil) of such an attachment wherever they read it, never its earlier texels (an M3 Max under macOS 27.0.1: an `RG16Float` second colour a framebuffer fetch reads and a `Stencil8` a stencil test reads, in passes split and whole; a separate `Depth32Float` and `Stencil8` read by a depth and a stencil test, each aspect so loaded alone or both; `runtime_lane::dont_care_unstored`); Vulkan's `DONT_CARE` load leaves the contents undefined. | `unstored_dont_care_loads = UnstoredDontCarePolicy::Driver` | `unstored_dont_care_loads = UnstoredDontCarePolicy::Cleared`: cleared on every device, by the pass's first render pass instance's load operation, or before the pass where that instance leaves the attachment out (separate depth and stencil textures: by the scratch image's load operation of the aspect); Metal's answer wherever a draw reads it | On a driver without the fact, the draws read what its `DONT_CARE` load leaves (lavapipe: the attachment's earlier texels). An image the runtime makes to stand for an attachment (the scratch image of separate depth and stencil textures, a stand-in, a backing: `Device::new_planned_texture`) starts at zero on such a driver, never as its memory lies, which may hold a released texture's texels: a clear as it is made. `DontCareUnstoredLoad` (`dont-care-unstored-load`), once per device; `runtime_lane::dont_care_unstored` (both values: Metal's answer under `Cleared` and on a driver with the fact, lavapipe's earlier texels under `Driver`; separate depth and stencil textures alike, but what lavapipe's `DONT_CARE` leaves in the scratch image is printed, not checked) | Measured, `CLEAR` against `DONT_CARE`, the GPU's span per pass, medians of 15 frames in each of two rounds, eight 3648x2038 passes a frame (a `BGRA8Unorm` colour loaded and stored, an `RG16Float` colour and a `Depth32Float_Stencil8` loaded by the form and stored `DontCare`, one draw over the whole target writing all three; a probe whose runtime still left such a load `DONT_CARE`, without the validation layer): lavapipe (Mesa 26.2.6, llvmpipe on LLVM 23.1.4) 10480 and 10744 µs against 7280 and 7259, 3.2 to 3.5 ms more, its clear a write of every texel; ANV (Mesa 26.2.6) on the Iris Xe (RPL-P) 1936 and 1936 µs against 1907 and 1151, slower in both rounds; RADV (Mesa 26.2.6) on the Radeon 780M 861 and 865 µs against 1147 and 988, faster; MoltenVK 1.4.2 on the M3 Max 218 and 218 µs against 224 and 217, apart by less than one form's two rounds; NVIDIA's 615.71.09 on the RTX 5080 Laptop GPU 74.4 and 74.6 µs against 71.2 and 71.4, 3.2 µs more. Memory: none |
| A linear sample of a two-plane YCbCr texture whose planes a function reads in place (`YCBCR8_420_2P`, `YCBCR10_420_2P` through a uniform texel buffer over their codes, on an integrated GPU or a CPU device; `lower::sampler::in_place`), through a sampler that addresses no border on either plane axis, with no texel offset placed by a parent's size, is Vulkan's Y′CbCr model of the codes, as the device's own conversion with a linear chroma filter computes it: the four luma codes around the point and the four chroma pairs around the same point of the chroma plane (Metal's midpoint siting) blended bilinearly, then the surface's range and matrix (Metal's coefficients) in `float`, each channel clamped into `[0, 1]`: eight fetches. A runtime sampler's word decides as the function runs. A nearest sample, a border mode, a parent-placed offset and a gather are Metal's under either value. | `ycbcr_in_place_reads = YCbCrInPlacePolicy::Model` | `ycbcr_in_place_reads = YCbCrInPlacePolicy::Exact`: every tap Metal's texel (its chroma weighted 9/3/3/1 and rounded to a code, the fixed-point conversion), and the sample Metal's sum of the four taps' steps on the grid `2048`: twenty fetches and four conversions | The model reconstructs each channel at the point where Metal converts four taps and sums them: within the `float` arithmetic's rounding of the model (checked against an `f64` model on the CPU interpreter, `engine_ycbcr_in_place`), it differs from Metal's by the chroma the taps reconstruct, by Metal's roundings to a code and to `1/2048`, and where a tap's channel leaves `[0, 1]`, which Metal clamps before it sums. `HalfSampleFilter` / `FloatSampleFilter` under the bound converted 4:2:0 format, announced `ycbcr-filter-not-exact` | Radeon 780M (RADV): a 3840 x 2160 `YCBCR10_420_2P` frame sampled linearly into a 3840 x 2160 `BGRA8Unorm` target, GPU time per frame (median of 60): 6.4-6.9 ms under the exact form (`runtime_lane::video_frames`) |
| A vertex buffer layout a draw fetches in fixed function, on a driver whose fixed-function vertex input takes an element's displacement modulo `2^32` (`RuntimeDriverDefect::VertexFetchWrapsPast4GiB`: lavapipe), where the draw's indices (`uint` indices, a per-vertex layout) or its indirect arguments (any layout but a constant one) state how far it fetches: the layout keeps the fixed-function fetch, so an element `2^32` bytes or more past the buffer's bind offset reads the bytes at its displacement's low 32 bits, where Metal reads zero past a buffer that ends before them (`render/vertex_reach.rs`). A layout whose reach the draw's own values bound (its last vertex without indices, `65535` plus its base vertex with `ushort` indices, its base instance plus its last instance over the step rate) is pulled where that reach passes `2^32`, under either value, and reads zero. Other drivers read zero (RADV on the 780M, MoltenVK 1.4.2: `runtime_lane::far_vertex_fetches`). | `vertex_reach = VertexReachPolicy::Bounded` | `vertex_reach = VertexReachPolicy::Exact`: such a layout is pulled too, wherever its stride and furthest attribute could reach past `2^32` from the largest index or argument (on lavapipe, every `uint`-indexed draw's per-vertex layout of a stride above 0, and every indirect draw's layout but a constant one), the plan's pulled-vertex-buffer variant (`WorkCounts::far_vertex_fetch_pulled_draws`) | Under `Bounded`, on lavapipe, an element of such a draw at or past `2^32` reads the wrapped bytes: the conformance case `vertex-fetch-past-4gib-small-buffer` replayed under the default policy differs in 8 elements (its two far `uint`-indexed draws at stride 4), and passes under `Exact`. `VertexFetchMayWrap` (`vertex-fetch-may-wrap`), once per device, for a draw left so; `runtime_lane::far_vertex_fetches` (both values) | Measured on lavapipe (Mesa 26.2.4, LLVM 23.1.1) on a Core Ultra 9 275HX shared with other jobs (`runtime_lane::far_vertex_fetches::far_reach_costs`): a state drawn without indices and then with `uint` indices makes one pipeline under `Bounded` and two under `Exact`, the pulled variant made at the first `uint`-indexed draw; a pass of one draw of 65,536 `uint`-indexed points, from the encoder's making to the wait's return, takes 2.3 to 2.8 times as long pulled (medians of 20 passes: 0.94 against 2.41 ms beside two builds, 3.5 to 4.8 against 9.7 to 12.0 ms at a load average of 59 on 24 threads). On every other driver neither value changes a draw |
| A draw of triangles in a rasterization-rate-mapped pass that a host step records (an execution whose records the GPU writes or whose range a buffer holds), filled, of one amplification, without a compensation or a band, whose pipeline chooses no slice or viewport and writes no memory from its vertex function, over a map whose layers are alike and whose plan is a grid of at most 128 columns and rows, on a device that enables `geometryShader`, `shaderClipDistance` and `vertexPipelineStoresAndAtomics`, is drawn once and fanned out to the regions its triangles touch (`rate_mapped_pass.rs`, **Fan-out**): its variant's geometry stage emits a copy of each triangle for each region it touches, at most the copies the device's `maxGeometryTotalOutputComponents` allows up to 16, through one viewport over the render area, four clip distances keeping each copy to its region's pixels, where Metal shades each region through its own viewport. A probe recorded before the pass, submitted and waited for, flags a draw a triangle of which crosses `w = 0` or touches more regions than the copies, which is drawn region by region, and marks a draw a triangle of which touches more than four (`bind::fan_out::FEW_COPIES`): a draw it marks none of is drawn through the variant of four copies, whose geometry stage declares the output of fewer vertices, the three variants (the probe's, four copies and the most) begun at `commit`; it stops at a command's barrier and after a draw that writes memory. A copy's window coordinates are the region viewport's computed in the geometry stage, so a pixel centre within a rounding error of a triangle's edge may be covered by one route and not by the other | `rate_map_regions = RateMapRegionPolicy::FanOut` | `rate_map_regions = RateMapRegionPolicy::Exact`: every draw recorded once per region of the map's plan, each through its own viewport and scissor, its vertex function run once per region | No note of its own: the map's creation announces the pass as a near-equivalent (`rasterization-rate-map`). `WorkCounts::rate_map_probes`, `rate_map_flagged_draws` and `rate_map_fanned_draws` count the probes and the draws each route drew, `rate_map_fanned_few_draws` the fanned-out draws of four copies; `WorkCounts::rate_map_probe_gpu_nanos` the probes' GPU time | Measured at the host step, 64 executed commands of 918,108 indices over a 3648 by 1734 screen's 2074 regions (`runtime_lane::rate_mapped_pieces`), each frame cold (its pipelines begun at `commit`) then warm, the command buffer's GPU time under `FanOut` against `Exact`: an Iris Xe's (Mesa 26.2.6) 48 ms cold and 40 ms warm against 510 ms and 498 ms; a Radeon 780M's (Mesa 26.2.6) 40 ms and 30 ms against 299 ms and 233 ms (`Exact`'s from an earlier run); an RTX 3090's (NVIDIA 620.70.06) 29 ms and 6.1 ms against 64 ms and 58 ms, its cold frame's step waiting for the fan-out's pipelines. Every draw of the lane's is of four copies; on the Radeon 780M, in one run, two frames of them took 29.7 ms and 30.8 ms warm, where the same draws through the most copies took 36.8 ms and 34.5 ms (40.2 ms and 43.9 ms cold against 61.9 ms and 62.7 ms). The probe's GPU time 1.3 ms, 0.5 ms and 1.5 ms. Unmeasured on the RTX 5080. Under `Exact` a draw's vertex work is its vertices times the regions its viewport reaches (`rate_mapped_pass::draw_work`), under `FanOut` its vertices once, its triangles' geometry stage, three vertices per copy (`rate_mapped_pass::fan_out_work`) and the probe's run of the same draws, which emits nothing |
| A draw of triangles in a rasterization-rate-mapped pass that a host step records (an execution whose records the GPU writes or whose range a buffer holds), filled, of one amplification, without a compensation or a band, whose pipeline chooses no slice or viewport and writes no memory from its vertex function, over a map whose layers are alike and whose plan is a grid of at most 128 columns and rows, on a device that enables `geometryShader`, `shaderClipDistance` and `vertexPipelineStoresAndAtomics`, is drawn once and fanned out to the regions its triangles touch (`rate_mapped_pass.rs`, **Fan-out**): its variant's geometry stage emits a copy of each triangle for each region it touches, at most the copies the device's `maxGeometryTotalOutputComponents` allows up to 16, through one viewport over the render area, four clip distances keeping each copy to its region's pixels, where Metal shades each region through its own viewport. A probe recorded before the pass, submitted and waited for, flags a draw a triangle of which crosses `w = 0` or touches more regions than the copies, with the first and the last such triangle: a flagged list of triangles of one instance whose pipeline reads no `[[primitive_id]]` and writes no memory is drawn in parts in its place, its triangles from the first flagged to the last region by region and those before and after fanned out (`render/fan_out.rs`, **Parts**), and another flagged draw region by region; and marks a draw a triangle of which it does not flag touches more than four (`bind::fan_out::FEW_COPIES`): a draw it marks none of, and a flagged draw's parts fanned out, is drawn through the variant of four copies, whose geometry stage declares the output of fewer vertices, the three variants (the probe's, four copies and the most) begun at `commit`; it stops at a command's barrier and after a draw that writes memory. A copy's window coordinates are the region viewport's computed in the geometry stage, so a pixel centre within a rounding error of a triangle's edge may be covered by one route and not by the other | `rate_map_regions = RateMapRegionPolicy::FanOut` | `rate_map_regions = RateMapRegionPolicy::Exact`: every draw recorded once per region of the map's plan, each through its own viewport and scissor, its vertex function run once per region | No note of its own: the map's creation announces the pass as a near-equivalent (`rasterization-rate-map`). `WorkCounts::rate_map_probes`, `rate_map_flagged_draws` and `rate_map_fanned_draws` count the probes, the draws they flagged and the draws fanned out whole, `rate_map_fanned_few_draws` the fanned-out draws of four copies, `rate_map_parted_draws` the flagged draws drawn in parts and `rate_map_parted_region_triangles` their triangles drawn region by region; `WorkCounts::rate_map_probe_gpu_nanos` the probes' GPU time and `rate_map_probe_wait_nanos` the host's wait for them | Measured at the host step, 64 executed commands of 918,108 indices over a 3648 by 1734 screen's 2074 regions (`runtime_lane::rate_mapped_pieces`), each frame cold (its pipelines begun at `commit`) then warm, the command buffer's GPU time under `FanOut` against `Exact`: an Iris Xe's (Mesa 26.2.6) 48 ms cold and 40 ms warm against 510 ms and 498 ms; a Radeon 780M's (Mesa 26.2.6) 40 ms and 30 ms against 299 ms and 233 ms (`Exact`'s from an earlier run); an RTX 3090's (NVIDIA 620.70.06) 29 ms and 6.1 ms against 64 ms and 58 ms, its cold frame's step waiting for the fan-out's pipelines. Every draw of the lane's is of four copies; on the Radeon 780M, in one run, two frames of them took 29.7 ms and 30.8 ms warm, where the same draws through the most copies took 36.8 ms and 34.5 ms (40.2 ms and 43.9 ms cold against 61.9 ms and 62.7 ms). The probe's GPU time 1.3 ms, 0.5 ms and 1.5 ms. Unmeasured on the RTX 5080. Under `Exact` a draw's vertex work is its vertices times the regions its viewport reaches (`rate_mapped_pass::draw_work`), under `FanOut` its vertices once, its triangles' geometry stage, three vertices per copy (`rate_mapped_pass::fan_out_work`) and the probe's run of the same draws, which emits nothing |
| A `Managed` buffer's range that `did_modify_range` names, on a device without unified memory (two copies: the runtime's own host copy, or the caller's pages through their import, `managed.rs`, `managed_copy.rs`), is copied into the GPU's copy by the GPU as the submission of the next command buffer committed that uses the buffer runs, from the host copy as it holds the range then: no copy on the CPU and no staging (pages no import of their own maps are staged by the CPU at the commit under either value, but those a guest RAM's chunk imports hold all of, which the GPU copies from those imports: `WorkCounts::managed_bytes_copied_in_from_ram`, `managed_bytes_staged_in`). Macs differ on a CPU write of the range after the commit, before the GPU runs the command buffer: an AMD Radeon Pro 5300M (two copies, macOS 26.7.1) read the bytes at the commit, an Intel UHD Graphics 630 (one copy) read the later write (steps A,B,B,A,B against A,B,B,B,B; `runtime_lane::device_copies`), so the cheaper answer is the default. | `managed_copy_in = ManagedCopyInPolicy::AtSubmission` | `managed_copy_in = ManagedCopyInPolicy::AtCommit`: the commit takes the range as the host copy holds it then, by a CPU copy into staging buffers of host-cached system memory, freed once the submission that copies them in completed (at most 256 MiB staged ahead); a write after the commit reaches no command buffer committed before it, the 5300M's answer | A CPU write after the commit, before the GPU runs the command buffer, may be read. No notice: both answers are a Mac's. `tests::managed_copy_device`'s `ranges_named_*` (the default: each round reads its own bytes or those written after its commit, never an earlier round's; `AtCommit`: its own alone) and `runtime_lane::device_copies`'s `a_did_modify_range_reaches_the_bytes_the_next_commit_finds` (step 4 reads either answer) and `exact_answers_take_a_did_modify_range_at_the_commit` (step 4 reads the bytes at the commit) | A CPU copy of each range at the commit into system memory, which the commit waits for. `tests::managed_copy_device::managed_copy_in_bench` (`MANAGED-COPY-IN`, medians of 40 commits of 32 MiB each, two rounds, over the runtime's own buffer and the caller's pages): RTX 3090 (an eGPU, NVIDIA 620.70.06) `AtSubmission` commit 0.034 to 0.045 ms and 17.3 to 17.7 ms to the completion, `AtCommit` 1.8 to 2.9 ms and 19.2 to 20.2 ms; RX 7900 XTX (RADV, Mesa 26.2.6) `AtSubmission` 0.012 to 0.036 ms and 5.1 to 5.5 ms, `AtCommit` 1.9 to 2.2 ms and 7.1 to 7.5 ms. Memory: the staged ranges until their submission completed, in buffers the device parks and takes again |
All at once: `DevicePolicy::exact_answers()` sets every switch above; each row states its own cost.