rt: an execution pushes each slot word of a command through a token of its own

On NVIDIA's driver (620.70.06, an RTX 2080) a 24-byte PUSH_CONSTANT token in an execution of 96
sequences or more carried sequence 31's bytes in every later sequence, while the SEQUENCE_INDEX
token stayed right. A standalone program found it with rt's own push layout: a 256-byte
VK_SHADER_STAGE_ALL range, the 24-byte token at push 0, an 8-byte token at 112 and the sequence
index at 104. Halving the program's other properties placed it in that layout (m3-max-62928, 62938
and 62947). Its first bisect run, the 24-byte token described as three 8-byte tokens of the same
bytes, drew right in every cell on the 2080 (m3-max-62960) and the XTX (m3-max-62961), and on
lavapipe under the validation layer (m3-max-62959).

tokens() no longer merges a run of slot words at consecutive offsets into one token: each slot
word the content pushes is its own 8-byte token, on every device, and Tokens::pushes holds
(command offset, push offset) pairs. Parts of 64 stay.

The cost: a command takes one token per buffer slot plus three, so maxIndirectCommandsTokenCount
caps its slots at 13 on lavapipe, 29 on NVIDIA's driver and 125 on RADV
(IndirectCommandsKind::Tokens). On the 2080 the standalone program's part of 64 commands of three
vertex words and one fragment word takes 69,888 preprocess bytes against 57,600. The README's
known gaps say both, and its execution sentence and the Tokens refusal's doc say one token per
slot.

Test: an_executions_tokens_are_a_token_per_slot_word (was ..._are_its_runs_of_slot_words) expects
five tokens for the five slot words that used to share two.
This commit is contained in:
Anees Iqbal committed 2026-11-21 03:37:30 -08:00
1 parent 64fa6a7a9a
commit 511f1819b3
4 files changed
+39 -35

No files matched your search

+14 -5
View File
@@ -3568,9 +3568,9 @@ vertex and fragment buffers (`inheritBuffers` false), at most 31 of each stage.
`optimize_indirect_command_buffer` records nothing.
- `RenderCommandEncoder::execute_commands_in_buffer` runs the range in parts of 64 commands, in
order, the last part the rest: one `vkCmdExecuteGeneratedCommandsEXT` a part, a sequence a
command, with the encoder's pipeline state and render state: a push constant token for each run
of slot words the state's functions read at consecutive push offsets, the index buffer token, a
sequence index token and the indexed draw token. Before each part the execution pushes the part's
command, with the encoder's pipeline state and render state: a push constant token for each
slot word the state's functions read, the index buffer token, a sequence index token and the
indexed draw token. Before each part the execution pushes the part's
first command, which the vertex function adds to the sequence index. The device keeps 64 command
layouts, one per shape of tokens, and 256 execution shapes of a part's 64 commands, one per
state, raster state (the depth clip and triangle fill modes, which choose the state's pipeline)
@@ -3621,12 +3621,21 @@ vertex and fragment buffers (`inheritBuffers` false), at most 31 of each stage.
an execution of N commands whose generated commands pass about 4 MiB (296 bytes a command,
14,170 commands) drew only its first N - 14,170 commands, or none, a driver bug; on NVIDIA's
driver (620.70.06, an RTX 2080) one of 96 commands or more (65 drew right) ended with its own
29th to 32nd commands on top of every later one, a cause not yet found. The parts cost, at
29th to 32nd commands on top of every later one, under the token bug below. The parts cost, at
14,000 commands against one execution: 62% more GPU time on the XTX and 61 times as much on the
2080, and 25 to 34 times the recording time. Their memory, for a frame of Apple's rendering
sample at its worst (45,024 commands of 17 tokens in 11 executions, 710 parts): about 108 MB of
preprocess regions on the 2080 and 28 MB on the XTX, where single executions would take about 27
MB on each (592 and 608 bytes a command).
- Each slot word a command holds is a push constant token of its own, on every device, where a run
of words at consecutive offsets could share one: on NVIDIA's driver (620.70.06, an RTX 2080) a
24-byte push constant token in an execution of 96 commands or more carried command 31's bytes in
every later command, and three 8-byte tokens of the same bytes carried each command's own (a
standalone program, which draws right either way on RADV and lavapipe). The cost: a command takes
at most `maxIndirectCommandsTokenCount` less 3 buffer slots (13 on lavapipe, 29 on NVIDIA's
driver, 125 on RADV), and on the 2080 that program's part of 64 commands of three vertex words
and one fragment word takes 69,888 preprocess bytes, against 57,600 with the vertex words in one
token.
- On NVIDIA's driver (620.70.06, an RTX 2080) an execution whose leading commands draw nothing
loses the draws after them in the same part: after a reset of commands 0 to 31, an execution of
commands 0 to 63 draws nothing. A cause not yet found.
@@ -3649,7 +3658,7 @@ vertex and fragment buffers (`inheritBuffers` false), at most 31 of each stage.
(`InheritedBuffers`), more than 31 buffers of a stage (`BindCount`), a count of 0 or one past
`maxIndirectSequenceCount` (`Capacity`), a compute state for indirect command buffers
(`ComputeCommands`), an execution with a state made without `supportIndirectCommandBuffers`
(`UnflaggedState`), one whose slot runs take more tokens than `maxIndirectCommandsTokenCount`
(`UnflaggedState`), one whose slots take more tokens than `maxIndirectCommandsTokenCount`
(`Tokens`: 16 on lavapipe, 32 on NVIDIA's driver, 128 on RADV), and one whose functions read what
a command cannot carry: a slot the command holds outside the push bytes, a fixed-function vertex
binding, or a vertex layout that must draw from base instance 0 (`DrawInput`).
+2 -2
View File
@@ -1376,8 +1376,8 @@ pub enum IndirectCommandsKind {
/// vertex function does not skip the commands outside the range.
UnflaggedState,
/// An execution whose pipeline state's buffer slots need more tokens than the device takes in
/// one command (`maxIndirectCommandsTokenCount`): one per run of slots its functions push
/// consecutively, the sequence index, the index buffer and the draw.
/// one command (`maxIndirectCommandsTokenCount`): one per buffer slot of the command its
/// functions read, the sequence index, the index buffer and the draw.
Tokens,
/// An execution whose pipeline state reads what a command cannot carry: a buffer slot the
/// command binds placed outside the push constants (in a parameter block), a fixed-function
+17 -22
View File
@@ -214,15 +214,20 @@ pub(crate) struct Indirect {
evicted_at: AtomicU64,
}
/// The tokens of an execution of a content's commands of one record layout: each run of slot
/// words the content pushes one after another (its offset in a command, its push offset and its
/// bytes), then the index buffer, the sequence index at its push offset, and the indexed draw at
/// the layout's offsets; and the push offset of the part's first command, which an execution
/// pushes before each part.
/// The tokens of an execution of a content's commands of one record layout: each slot word the
/// content pushes, a token of its own (its offset in a command and its push offset), then the
/// index buffer, the sequence index at its push offset, and the indexed draw at the layout's
/// offsets; and the push offset of the part's first command, which an execution pushes before
/// each part.
///
/// A token of one 8-byte word each, never one token for a run of words: on NVIDIA's driver
/// (620.70.06, an RTX 2080) a 24-byte push constant token of an execution of more than 64
/// sequences carried an earlier sequence's bytes, where three 8-byte tokens of the same bytes
/// carried each sequence's own.
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub(crate) struct Tokens {
pub(crate) layout: IndirectDrawLayout,
pub(crate) pushes: Vec<(u32, u32, u32)>,
pub(crate) pushes: Vec<(u32, u32)>,
pub(crate) sequence: u32,
pub(crate) base: u32,
}
@@ -417,7 +422,7 @@ impl Indirect {
},
};
let pushes: Vec<dgc::PushConstantToken> = (tokens.pushes.iter())
.map(|&(_, push, bytes)| range(push, bytes))
.map(|&(_, push)| range(push, IndirectDrawLayout::SLOT_BYTES))
.collect();
let sequence = range(tokens.sequence, 4);
let index = dgc::IndexBufferToken {
@@ -647,11 +652,10 @@ impl Indirect {
}
}
/// The tokens of an execution of `draws`' content's commands of `layout`: a push constant token
/// for each run of the slot words the content pushes at consecutive offsets for consecutive slots
/// of a command, the slots the command holds alone, then the index buffer, the sequence index at
/// the content's `IndirectSequence` field and the indexed draw; the part's first command goes at
/// its `IndirectBase` field.
/// The tokens of an execution of `draws`' content's commands of `layout` ([`Tokens`]): a push
/// constant token for each slot word the content pushes of a slot the command holds, then the
/// index buffer, the sequence index at the content's `IndirectSequence` field and the indexed
/// draw; the part's first command goes at its `IndirectBase` field.
///
/// Err: [`IndirectCommandsKind::UnflaggedState`] for a content whose vertex function reads no
/// execution range; [`IndirectCommandsKind::DrawInput`] for one that reads a slot the command
@@ -697,18 +701,9 @@ pub(crate) fn tokens(
return Err(IndirectCommandsKind::DrawInput);
}
words.sort_unstable();
let mut pushes: Vec<(u32, u32, u32)> = Vec::new();
for (at, push) in words {
match pushes.last_mut() {
Some((first, pushed, bytes)) if *first + *bytes == at && *pushed + *bytes == push => {
*bytes += 8
}
_ => pushes.push((at, push, 8)),
}
}
Ok(Tokens {
layout,
pushes,
pushes: words,
sequence,
base,
})
@@ -87,11 +87,11 @@ fn a_commands_slots_are_pushed_with_the_widest_bounds() {
}
#[test]
fn an_executions_tokens_are_its_runs_of_slot_words() {
fn an_executions_tokens_are_a_token_per_slot_word() {
let layout = IndirectDrawLayout::new(3, 2).expect("a layout");
// Vertex slots 0 to 2 and fragment slot 0 lie at consecutive offsets of both the push bytes
// and the command: one run. Fragment slot 1 follows in the command but not in the push bytes,
// and vertex slot 3 is past the command's count.
// and the command, and still take a token each. Fragment slot 1 follows in the command but
// not in the push bytes, and vertex slot 3 is past the command's count.
let fields = ranged(vec![
(DrawPlace::Push(0), VERTEX, slot(0)),
(DrawPlace::Push(8), VERTEX, slot(1)),
@@ -101,10 +101,10 @@ fn an_executions_tokens_are_its_runs_of_slot_words() {
(DrawPlace::Push(48), VERTEX, slot(3)),
]);
let found = tokens(&draws(fields), layout).expect("tokens");
assert_eq!(found.pushes, [(0, 0, 32), (32, 40, 8)]);
assert_eq!((found.sequence, found.base, found.count()), (104, 108, 5));
assert_eq!(found.pushes, [(0, 0), (8, 8), (16, 16), (24, 24), (32, 40)]);
assert_eq!((found.sequence, found.base, found.count()), (104, 108, 8));
// Fourteen slots, two apart in the command and consecutive in the push bytes: a run each.
// Fourteen slots, two apart in the command and consecutive in the push bytes: a token each.
let wide = IndirectDrawLayout::new(27, 0).expect("a layout");
let fields = ranged(
(0..14)