Skip to content

GPU: keep the native indirect work budget in device-local memory - #20

Draft
gmankab wants to merge 6 commits into
spidercraft:linux-native-runtimefrom
gmankab:contrib/native-device-local-budget
Draft

gmankab wants to merge 6 commits into
spidercraft:linux-native-runtimefrom
gmankab:contrib/native-device-local-budget

Conversation

@gmankab

@gmankab gmankab commented Nov 25, 2026

Copy link
Copy Markdown

The native indirect-work counter is written by the GPU. Put it on the default heap using the same allocator as the private arguments. The list copies a four-byte zero into it once per execution and restores COMMON at close. If allocation on the default heap fails, the shared allocation remains available.

The new GPU readback test spends the budget in one clamp, checks that the next clamp empties its draw, then checks the same results on replay and after a list reset.

Alternating RX 6800 timestamp runs, in GPU ticks per clamp:

Valid records per clamp Clamps per list Shared counter Device-local counter
1 1 520–524 624–628
1 8 376–377 312–313
1 256 281–288 195
64 32 374–380 293–294
4,096 4 2,123–2,129 1,807–1,809
16,384 1 8,356–8,364 7,228–7,236

The initialization costs time on lists with just one small clamp. The repeated and large cases improved on this adapter. These measurements are from synthetic command lists, with initialization included.

Based-on: fxceless/victory-fork#220
Depends-on: #18
Tested-on: Fedora Linux 45, Intel Xeon E5-2670 v3, Lavapipe and AMD Radeon RX 6800 with RADV and native VKD3D-Proton. 48 tests passed on Lavapipe and six focused clamp tests passed on the RX 6800.
Assisted-by: gpt-6.2 sol xhigh

Review this layer's diff.

An in-place clamp overwrites records in the title shadow buffer and transitions the entire buffer even when later commands bind other regions as vertex or shader input. Read the title records through an SRV and execute from a reusable per-list buffer so only the clamp output changes state. Keep previous allocations alive when the list grows and preserve the signed base vertex and other draw offsets.

Based-on: Marvisak@315cea1
Tested-on: Fedora Linux 45, Lavapipe and native VKD3D-Proton (44 GPU tests passed)
Assisted-by: gpt-6.2 sol xhigh
The native clamp walks MaxCommandCount even when a count buffer limits execution to fewer records. Inactive records can contain unrelated data and consume the per-list budget before a valid dispatch. Read the count in the clamp, skip the unused records, and store the bounded count beside the private arguments for ExecuteIndirect. Earlier UAV writers are ordered before the clamp and their title buffers are restored before the title pipeline binds.

Based-on: Marvisak#242
Depends-on: spidercraft#11
Tested-on: Intel Xeon E5-2670 v3, Fedora Linux 45, Lavapipe and native VKD3D-Proton (45 GPU tests)
Assisted-by: gpt-6.2 sol xhigh
The argument clamp charges rejected records to a 32-bit accumulator.
After enough large records, the accumulator wraps and admits more
work even though the list has already spent its budget. A 128-record
test admits four maximum-cost draws when only two fit.

Saturate the reservation at the work limit. Groups reserve their
total once, so a large argument table avoids a compare-exchange loop
for each record. Resolve the one group that crosses the limit in lane
order. A single active group can update the counter directly because
the UAV barriers between clamps already order its access.

Read back large and small batches as well as the boundary inside a
group. Counted dispatches now use a separate atomic witness shader
to count commands even when the driver overlaps their dispatches.

Based-on: Marvisak#1510
Based-on: fxceless/victory-fork@f85101b
Depends-on: spidercraft#14
Tested-on: Fedora Linux 45, Intel Xeon E5-2670 v3, Lavapipe and AMD Radeon RX 6800 using native VKD3D-Proton. Microsoft FXC compiled both shaders as cs_5_1 under Wine.
Assisted-by: gpt-6.2 sol xhigh
Each native ExecuteIndirect transitioned its private scratch back to
COMMON immediately after reading it. The next clamp transitioned it
straight back to UNORDERED_ACCESS, adding a redundant barrier for
every command.

Keep the scratch in INDIRECT_ARGUMENT until the next clamp writes it.
Restore COMMON when replacing the allocation or closing the list so
a closed list can replay safely. Cache the allocation size to avoid a
descriptor query when it is reused.

Run counted ExecuteIndirect commands before and after growing the
scratch, replay the closed list, then reset and reuse the allocation.
Check each dispatch on the GPU through a separate witness slot.

Based-on: fxceless/victory-fork@f85101b
Depends-on: spidercraft#16
Tested-on: Fedora Linux 45, Intel Xeon E5-2670 v3, Lavapipe and AMD Radeon RX 6800 with RADV and native VKD3D-Proton
Assisted-by: gpt-6.2 sol xhigh
The native clamp wrote private arguments to a CPU-mapped allocation,
even though only the GPU consumes those bytes. Large batches took
longer to write on a discrete GPU.

Prefer a default-heap allocation for the private arguments. Keep the
CPU-mapped allocation available if the device-local allocation fails.
Use explicit GPU copies in the tests that read the scratch back, and
seed the inactive-record test with a prior clamp on the GPU.

The RX 6800's 4,096- and 16,384-record clamp cases improved by about
16% and 18% in alternating GPU timestamp runs, respectively.

Based-on: fxceless/victory-fork@f85101b
Depends-on: spidercraft#17
Tested-on: Fedora Linux 45, Intel Xeon E5-2670 v3, Lavapipe and AMD Radeon RX 6800 with RADV and native VKD3D-Proton. Windows-target clamp tests ran under Wine and Lavapipe.
Assisted-by: gpt-6.2 sol xhigh
The clamp repeatedly updates the list's work budget on the GPU, but
the budget lived in a CPU-mapped buffer. On discrete GPUs the shared
allocation made both the individual charges and group atomics cost
more.

Use the same device-local allocation path as indirect scratch. The
list copies an immutable zero into the counter before its first
clamp and restores COMMON when it closes. Each execution, including
a replay, runs the initialization. The allocation can fall back to
shared memory.

Exercise a list that spends the budget and then clamps another draw.
Read both results after replaying and after resetting that list.

Based-on: fxceless/victory-fork#220
Depends-on: spidercraft#18
Tested-on: Fedora Linux 45, Intel Xeon E5-2670 v3, Lavapipe and AMD Radeon RX 6800 with RADV and native VKD3D-Proton
Assisted-by: gpt-6.2 sol xhigh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant