Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions docs/d3d12_vulkan.md
Original file line number Diff line number Diff line change
Expand Up @@ -1302,7 +1302,8 @@ and any validation error fails them.
- `indirect_clamp_test`: the `ExecuteIndirect` argument clamp pass itself (section 4.7), with no game files: every
argument kind (draw, draw indexed, dispatch, mesh dispatch) and the counted variants, in-range records
bit-identical, garbage records bounded, records and counts past `max_command_count` empty, and the per-batch work
budget saturating; clean SKIP without a Vulkan device.
budget saturating; dispatch records bounded by the device's `maxComputeWorkGroupCount` (70 000 x 1 x 1 kept and run
where the device allows it, cut and counted where it does not); clean SKIP without a Vulkan device.
- `d3d12_gcl8_test`: the public `ID3D12GraphicsCommandList8` surface: `QueryInterface` for its IID,
`OMSetFrontAndBackStencilRef(1, 2)` with the recorded values, and the reference count around the query. It
creates only an allocator and a list, so it needs no GPU or Vulkan loader.
Expand Down Expand Up @@ -4339,14 +4340,22 @@ Not implemented yet:
`LEONIDA_SKIP_COMPUTE`) or mistranslates leaves whatever the memory held: a dispatch of billions of groups or a
draw of four billion vertices runs until the host resets the display driver. One small compute pass per
`ExecuteIndirect` call copies the active records into device-local scratch with their values bounded - 2^24
vertices or indices, 2^26 vertex instances (count times instances), 65 535 groups per dimension, 2^20 groups per
dispatch and a 2^27-unit work budget per call that saturates through an atomic compare-and-swap - and writes an
vertices or indices, 2^26 vertex instances (count times instances), the device's `maxComputeWorkGroupCount` groups
per dimension for a dispatch (65 535 for a mesh dispatch), 2^20 groups per dispatch and a 2^27-unit work budget per
call that saturates through an atomic compare-and-swap - and writes an
empty record past `min(count, max_command_count)` and past the budget, and the clamped count word a `*Count` draw
then reads (so the count is at most `maxDrawCount`, VUID-vkCmdDrawIndirectCount-countBuffer-02717). A draw record
of 2^23 vertices or indices an instance or more is a slot the title has not filled: it runs empty and charges
nothing (RT-INDIRECT-DRAW-UNFILLED-COUNT). Before, each was cut to 2^24 and charged that, so eight of them used up
the budget and every later draw in the list ran empty; a census in a VIctory fork found 90 such records in one
list. The indirect command reads that scratch. A draw emits the pass before its rendering scope opens: `vkCmdCopyBuffer` and a
list. A dispatch record's groups per dimension follow the device (#2230): the title's tile
passes ask for 67 440 groups in x at 2560x1440 (found in the VIctory-Belobug-AMD fork of VIctory,
`crates/victory-gpu/src/indirect.rs`), RADV runs 2^32 - 1 in x in one dispatch, and the cut at 65 535 dropped the
last 1 905 tiles of the pass. A device that allows less (llvmpipe: 65 535) still gets the record cut at its
limit: running the rest would take more dispatches with a group-ID base the translated shader does not read. The
counters' `indirect clamp dispatch:` line (every 10 s while dispatch records are clamped) gives the records, those
wider than 65 535 in x, the widest x that ran and those cut at the device's limits, so a run shows which case it
is. The indirect command reads that scratch. A draw emits the pass before its rendering scope opens: `vkCmdCopyBuffer` and a
memory barrier with a transfer access are not allowed inside a dynamic-rendering scope. The records are
bit-identical to the application's when they are within the limits, the argument and count buffers are left
untouched, and the scratch comes from a per-submission pool (`vulkan_scratch.h`) that a list with many indirect
Expand Down
11 changes: 11 additions & 0 deletions runtime/src/indirect_clamp.comp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ const uint unfilled_draw = 1u << 23u; // vertices or indices an instance
const uint max_vertex_instances = 1u << 26u; // vertex (or index) count times instance count
const uint max_mesh_dimension = 65535u; // groups in a mesh dispatch's x (dispatches: p.max_x, y, z)
const uint max_groups = 1u << 20u; // groups in one dispatch or mesh dispatch
const uint narrow_groups = 65535u; // the x a dispatch record was cut at before, for the counters
const uint budget = 1u << 27u; // work in the whole command list: vertices, indices, or groups * 64

// Charges `cost` units to the batch's budget. Saturating: a record that no longer fits runs empty, so the batch never
Expand Down Expand Up @@ -148,6 +149,8 @@ void main() {
uint y = min(asked_y, limit.y);
uint z = min(asked_z, limit.z);
if (p.kind == 3u) { y = 1u; z = 1u; }
// A dispatch past the device's limit in some dimension, cut there (stats word 14).
const bool past_device = p.kind != 3u && (x != asked_x || y != asked_y || z != asked_z);
const uint groups = p.flags >> 1u;
if (groups != 0u && x != 0u && y != 0u && z != 0u) {
x = min(x, groups);
Expand All @@ -159,6 +162,14 @@ void main() {
y = 0u;
z = 0u;
}
if (p.kind != 3u) {
// Dispatch records (stats words 12-15): those that run wider than 65 535 groups in x, the widest x that
// runs, those cut at the device's limits (and still run), and all of them.
atomicAdd(p.stats.data[15], 1u);
if (x > narrow_groups) atomicAdd(p.stats.data[12], 1u);
atomicMax(p.stats.data[13], x);
if (past_device && x != 0u) atomicAdd(p.stats.data[14], 1u);
}
clamped = x != asked_x || y != asked_y || z != asked_z ? 1u : 0u;
cost = x * y * z * (p.kind == 3u ? 128u : 64u);
words[0] = x;
Expand Down
Loading
Loading