Merging one-record indirect mesh draws into one ExecuteIndirect: what blocks it, how many would merge (68–74%), and a plan #828
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/fxceless--victory-fork#828
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@VibeClauding on GitHub · 2026-11-25 09:22 UTC · original
The case for merging, and a plan
Goal: draw a run of consecutive one-record indirect mesh draws (same pipeline, same list) with one multi-record
ExecuteIndirect, keeping the picture correct.Why it's worth it:
What blocks it today, and why it can be lifted
dkdknight found that a descriptor table changes between consecutive draws, and command signatures can't set descriptor tables. Reading the code on
9376fd6, that table is ours, not the title's:State::bind(draw.rs ~1035) makes the title's tables fresh in dynamic slots and writes their offsets into the stage's user-data root constants. Shaders index the heap directly (CBV_SRV_UAV_HEAP_DIRECTLY_INDEXED,createHandleFromHeap). A command signature can set root constants per record (D3D12_INDIRECT_ARGUMENT_TYPE_CONSTANT).root_uav/root_srv_table(draw.rs ~1166–1350), made becausebounded_root_srvs()(pipeline/host.rs:277) turns root views into one-view tables so that a read can't leave its buffer.VICTORY_ROOT_SRV_DIRECT=1switches them back to root descriptors, which a command signature can set per record, but the bounds are needed. On an RTX 3070 (run 73:8dd30ab+ #220 #648 #670 #705 #346, Series S), that switch removed the device during loading:0x887A0006with no breadcrumbs, the submitting thread preparing, nothing of ours on the card. One run doesn't prove the cause, but unbounded root views are the obvious suspect. So root descriptors are not the way.The way that keeps the bounds: have the translator read a bounded root view through the heap. The shader takes
ResourceDescriptorHeap[i], whereiis the one-view table's slot, passed in a root-constant dword of the stage's user data. That is the same thingbindalready does for the title's own tables (RootType::Tableoffsets). After that, everythingbindsets per draw is root constants, and a command signature can set those per record. Our own root views (SLOT_MEMORY,SLOT_STRIDES,SLOT_FAULTS) are the same for every draw of a list, so they stay set once.How many draws could merge (this fork, RTX 3070, Series S, first room)
I ran a small script over
VICTORY_CAPTURE's ops log. A run is consecutive operations of one host list that are all one-record indirect draws of the same kind and pipeline, with nothing else of that list between them.That matches ThiagoAlexsander's 58% on the 5080 (#107). One-record indirect dispatches rarely run together (3–10%), so this is about mesh draws.
The script (Python, reads frame-N-ops.txt)
Plan (each step can be a PR of its own, behind
VICTORY_INDIRECT_MERGE=1, off by default)RootType::Otherkind) holding the heap index of the viewroot_uav/root_srv_tablemake. The shader builds the handle withcreateHandleFromHeap.pipeline/host.rsthen makes no table parameter for those slots, andbindwrites the index into the constants instead of callingSet*RootDescriptorTable. It changes translations, so the cache key moves. This keeps the bounds and is worth having on its own: one fewer root parameter per view.bind/prepare_forgo through one recorder:(param, Constants(Vec<u32>) | Srv(u64) | Uav(u64) | Cbv(u64)). Count every other command they record (barriers, render targets, tables, scissor). A draw whose preparation recorded nothing but root writes can join a run. This is a refactor with no behaviour change.CONSTANTargument per stage's user data (after step 0, that is all that varies), thenDISPATCH_MESH. It needs the root signature. Cached per root signature.State. A one-record mesh draw that passes step 1's test is appended to a pending run instead of executed: its root writes, and where its clamped arguments are ((scratch, at)from the window). The run is flushed with oneExecuteIndirect(signature, n, merged, 0, None, 0)when the next draw differs (pipeline, signature, a non-root command), on any other operation of the list, at close, and at a size limit.scratch + at_iinto the merged buffer at the record's offset.CopyBufferRegionper record, which is still far cheaper than anExecuteIndirect, and measure that first.VICTORY_GPU_TIMINGper command, fps A/B, andVICTORY_CAPTUREframes compared.Pitfalls I can see
mesh_scissor(list, true/false)is set around each meshExecuteIndirect. It's the same for a whole run, so it should bracket the merged call once.I'm starting on step 0, then 1–3, on VibeClauding/victory-fork and will link the branch here. Anyone who wants a step, say which one so we don't duplicate. Steps 2 and 4 can be written against step 1's interface without waiting for it, and step 1 doesn't depend on step 0.
AI-assisted (Claude Code); measured on my machine with my own copy; counts, timings and code references only.
@VibeClauding on GitHub · 2026-11-25 09:44 UTC · original
Step 0 is done and tested in game: VibeClauding/victory-fork@pr/root-view-index (
6176086on9376fd6, 4 files, +114/−34).VICTORY_ROOT_VIEW_INDEX=1: the translator reads the title's root SRVs/UAVs withcreateHandleFromHeapat an index from a user-data dword (newRootType::OthercodeUSER_VIEW_SLOT, dword 0 SRV / 1 UAV). The slot gets no table parameter.bindmakes the same bounded one-view table as before.root_uav/root_srv_tablenow return the slot and set a table only when given a parameter.bindwrites the slot into the constants.translate --warm allgives the same 254 programs that don't translate, with or without the switch. In game, run 74 (pipelines being made) and run 75: 8.2–9.0 fps, no errors, no device loss, nothing logged by the new path. That's the same speed as without the switch (8.1–9.0), as expected: it only makes the merge possible.emit/host.rsharness would need to pass the slot in user data. That's a good small task if someone wants one.With this, everything
bindsets per draw is root constants, apart from our ownSLOT_MEMORY/SLOT_STRIDES/SLOT_FAULTS, which are the same for every draw of a list. Steps 1–3 are open: take one. I'm working on the processor side for a while (see #10 / #612), so I won't start step 1 this week.AI-assisted (Claude Code).