From 7e239bfb0b6f2ca1416a06b21fe789540709c7eb Mon Sep 17 00:00:00 2001 From: Vyacheslav Venglovsky Date: Wed, 25 Nov 2026 00:54:13 +0100 Subject: [PATCH] GPU: the indirect clamp's groups past a count touch the budget not at all An execution may ask for thousands of records with a count buffer that counts a few: the clamp runs a group per 64 asked. Before the charge per group, the threads past the count returned at once; with it, the first thread of every group read the budget word, and for mesh records added the group's notes to it, records or none. In memory the CPU maps that is up to three atomics across the bus per empty group (on an RTX 5070 an in-game A/B of 32c6229 ran slower, #220). Now a group without records makes no atomic; the group's barriers stay in uniform control flow. Co-Authored-By: Claude Opus 5.5 --- crates/victory-gpu/src/indirect.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/crates/victory-gpu/src/indirect.rs b/crates/victory-gpu/src/indirect.rs index e89cb70..fbc9805 100644 --- a/crates/victory-gpu/src/indirect.rs +++ b/crates/victory-gpu/src/indirect.rs @@ -132,12 +132,15 @@ void main(uint3 id : SV_DispatchThreadID, uint gi : SV_GroupIndex) { InterlockedMax(largest_asked, asked, was); InterlockedAdd(all_asked, min(asked, 1u << 24), was); } - if (gi == 0) { + // The group's own records: none for a group past a count buffer's + // count (an execution may ask for thousands and count a few), which + // touches the budget not at all, as its threads did not before. + uint first = id.x - gi; + uint n = eff_count > first ? min(64u, eff_count - first) : 0u; + if (gi == 0 && n > 0) { // What the records charge, from `before` on, in lane order: a // record that does not fit whole runs empty and takes the rest. // Only the group's own records are walked (one, clamped alone). - uint first = id.x; - uint n = eff_count > first ? min(64u, eff_count - first) : 0u; uint before; budget.InterlockedOr(0, 0, before); [allow_uav_condition] @@ -167,7 +170,7 @@ void main(uint3 id : SV_DispatchThreadID, uint gi : SV_GroupIndex) { } } GroupMemoryBarrierWithGroupSync(); - if (gi == 0 && kind > 2) { + if (gi == 0 && kind > 2 && n > 0) { uint was; budget.InterlockedMax(4, largest_asked, was); budget.InterlockedAdd(8, all_asked, was);