Skip to content
Open
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
69 changes: 50 additions & 19 deletions docs/d3d12_vulkan.md
Original file line number Diff line number Diff line change
Expand Up @@ -869,7 +869,7 @@ The compute path, end to end:
and an integer field outside 0..2^32−1 reads as 0.
- Root signatures use the model already on `main` (`runtime/src/root_signature.h`, `rt::rootsig`): `parse_rts0`
reads the serialized blob and `pack()` lays out the 32 user-data dwords by the section 3.5 default mapping,
refusing anything that would spill. `pack_stage()` lays them out in the console layout of one stage (section 3.5,
refusing graphics spills. `pack_stage()` lays them out in the console layout of one stage (section 3.5,
D3D-448); the compute bind point uses it.
- **GPU address arena** (section 3.3, when the device has `bufferDeviceAddress`): one host-visible,
device-addressable buffer, 256 MiB by default (`LEONIDA_ARENA_MB`, at most 4095 MiB, so every VA fits 32-bit
Expand Down Expand Up @@ -907,10 +907,11 @@ The compute path, end to end:
- **`CreateRootSignature`** parses the blob with `parse_rts0` and keeps each parameter's place in two layouts, both
the console's (one dword per table; section 3.5, D3D-448): `pack_stage(Stage::Pixel)` for the graphics bind point
(from s8; a signature past s31 there keeps `pack()`'s s0 layout, logged) and `pack_stage(Stage::Compute)` for the
compute one (from s4). It also checks
compute one (from s4, plus the full compute argument block; ROOT-SIG-SPILL-MODEL). It also checks
`pack_stage(Stage::Mesh)`: a signature past a mesh shader's 16-dword window is logged, and `DispatchMesh` with it
invalidates the list. A signature neither bind point can place (past s31: the spill layout is open; the
translated shaders have no below-base spill-pointer candidates) is refused with both reasons; one only a single layout places is created with a log line, and binding it at the other bind point
invalidates the list. Compute spills use the measured argument block; graphics spills remain unmeasured.
A signature neither bind point can
place is refused with both reasons; one only a single layout places is created with a log line, and binding it at the other bind point
invalidates the list. Before
that it answers as the host runtime does (`compare_invalid_arguments`, "root signature:", RTX 5070 / 621.14):
`S_FALSE` for a null output whatever the blob, then `E_INVALIDARG` for a node other than node 0 or a DXBC
Expand Down Expand Up @@ -2031,7 +2032,7 @@ Taken together this disagrees with the packing above (from s0, two dwords per ta
in root order from the stage base, each while it fits whole, a constant taking one dword per value, a root
CBV/SRV/UAV two (its 64-bit VA), a descriptor table **one** (the 32-bit VA of its first descriptor; the heaps live
below 4 GiB). A parameter that does not fit goes, with every later one, to the spill array behind `s[0:1]`
(section 7), which is not modelled, so such a signature is refused. How each part is known:
(section 7). Compute models that block below; other stages still refuse an unmeasured spill. How each part is known:
- **Compute, base s4: measured three ways.**
- The console compiler's output (section 7).
- The package's FidelityFX DLL, whose 29 compute containers carry their `RTS0` next to the console-compiled
Expand Down Expand Up @@ -2068,13 +2069,45 @@ native Windows, RTX 5080). What mesh shaders read below s16 was counted on the 1
s16; three read one 32-bit constant there (`s13` in one, `s15` in two), never a pointer, and they read it as 0 now.
Its meaning is not established. A root signature carries both layouts; one that only one of them can place is
created, and binding it at the other bind point invalidates the command list (`Close` returns `E_INVALIDARG`).
`s0..s3` of a compute dispatch are the driver's block; the layer leaves them zero (109 CS read `s1` as a constant,
42 `s3`; their meaning is open).
`s0..s3` of a compute dispatch are the driver's block; the layer supplies the argument block's console VA in
`s[0:1]` and leaves `s2..s3` zero. Other system-value meanings remain open.

**Compute argument block (ROOT-SIG-SPILL-MODEL).** Correlating the 52 `XboxBvhBuilder.dll` programs with their own
`RTS0` signatures and scalar-load offsets establishes a second convention alongside inline-from-s4: a packed
block behind the 40-bit pointer in `s[0:1]`. It holds **all** parameters, not just the overflowing tail, in signature
order: root CBV/SRV/UAV 8 bytes, constants 4 bytes per value, no alignment. A fitting signature reads the block
too. Four non-fitting signatures have eight root views and 14 constants (30 dwords); their loads agree with that
layout. Descriptor tables use the inline width of 4 bytes in the model; a spilling-table program has **not**
been measured. The synthetic tests exercise that width, not its retail provenance.

`StagePackResult` exposes block offsets for every compute parameter (at most 64 dwords by the D3D12 cost limit).
A parameter that cannot fit whole and every subsequent parameter have no inline placement. Setters maintain both
copies, including constant sub-offsets and address high words; dispatch and dispatch-kind `ExecuteIndirect` snapshot
the block by value. During preparation, each execution uploads a fresh immutable copy into the host-coherent GPU
address arena, with 64 zero padding bytes for wide scalar reads. Replay supplies its **arena offset**, not raw BDA,
in `s[0:1]`: the translator already adds `heap_base`. The queue keeps the allocation until its command-buffer
timeline ticket completes; failed preparation or submission releases unsubmitted ranges. Separate dispatches,
lists, repeat executions and queues never overwrite a shared signature-owned block. Vulkan's host-write to
queue-submit dependency publishes the coherent pre-submit writes; there is no transfer update requiring a
transfer-to-shader barrier. Missing upload support or allocation failure rejects preparation before GPU emission.

Checks: `root_signature_test` and `tests/test_root_sig_contract.py` cover packing and malformed tails;
`replay_root_arguments_test` covers snapshots, execution-time pointers, indirect dispatch and refusal paths;
`queue_root_arguments_test` checks timeline retention, two queues and preparation/submission failure rollback;
`vk_root_arguments_test` checks the same upload/replay contract with native GPU readback and validation;
`d3d12_root_arguments_test` reads back fitting and spilling blocks through the shader contract, partial setters,
two logical queues, direct/indirect/counted dispatches and repeat execution. These are synthetic tests, **not**
proof that the title's RT startup works. In particular, the meaning of `s4` as a system value in block-reading
builder programs is settled by their dispatch headers, not root packing: all 52 declare four user SGPRs,
TGID_X enabled and TG_SIZE disabled. `s4` is therefore `WorkgroupId.x`; the translator's existing compute
prologue overwrites the push-constant copy there. All 52 generated modules were checked for that initialization,
including the four with non-fitting signatures (local size 32). No translator change or runtime s4 override is
needed for this system input. Inline-from-s4 remains the separate convention used by the FidelityFX signatures.

**Measured: a real signature beside the count it produced.** `tools/fspx_unpack.py` decodes `COMPUTE_PGM_RSRC2` of
each of the 29 compute programs in `amd_fidelityfx_upscaler_xbox.dll`, and its `USER_SGPR` field is the count the
console launched the dispatch with. Every one of those 29 containers also carries an `RTS0`, which makes this the
only place in the package where a serialized root signature sits beside the dword count it produced
console launched the dispatch with. Every one of those 29 containers also carries an `RTS0`, so a serialized
root signature sits beside the dword count it produced
(`tools/rootsig_census.py`). The game's own 26,503 containers carry no `RTS0`, so their read sets cannot be joined
with a signature and cannot settle it either.

Expand Down Expand Up @@ -2108,9 +2141,8 @@ Still open: which CBV index lands in which pair. The four pairs do appear in dec
package proves that order, and every parameter in these 29 is `D3D12_SHADER_VISIBILITY_ALL`, so they say nothing
about the visibility question below.

Spill policy: a signature needing more than 32 user SGPRs, or more than the 64-dword D3D12 cost limit, is
refused loudly (`pack` returns the offending parameter) instead of being truncated. The console spills through
`__XB_GetRootSignatureSpillPointer`; until that layout is measured, refusing is the only correct behaviour.
Spill policy: compute uses the measured argument block above; graphics spills and signatures exceeding the
64-dword D3D12 cost limit are still refused, never truncated. `pack()` remains the legacy graphics mapping.

Measured (D3D-315): zero below-base spill-pointer candidates in the translated shaders.
`python -I tools/root_spill_census.py <spirv/index.json> --carve <dxbc/index.json> --expect-no-spill` exits 0 on
Expand All @@ -2137,7 +2169,8 @@ What this does not settle:
- **A spill behind a pointer at or above the base.** It reads the same as a table pointer, so the census can't
tell the two apart.

The spill layout stays unimplemented: no shader in the translated set reads a candidate a spill could sit behind.
That census covers the main shader set, not the embedded builder programs measured above; it does not contradict
their argument-block reads.

Reconciliation: `tools/root_sig_contract.py` checks a candidate root signature against every shader's
`user_sgpr_reads` from `spirv/index.json` (const32 vs constant dwords, 64-bit VAs vs view/table pairs) and fails
Expand Down Expand Up @@ -2232,12 +2265,10 @@ Things that can invalidate this simple model, all **Open**:
so the executable's pipeline table would settle it; `tests/test_user_sgpr_census.py` shows that the two models
give different counts. Mesh shaders (base s16) and the compute signatures are not covered here.
- **Root signature larger than 32 dwords.** D3D12 allows up to 64 dwords. The console has 32 user SGPRs, so a
driver must spill the rest to memory, probably behind a pointer in the user data. The current shader contract has
no representation for that. The likely answer is that this game keeps its root signatures small (bindless
descriptors, a few constants), but it must be measured. If a large root signature appears, the spill layout has
to be reverse-engineered from the shader's loads. Measured on the shader side (D3D-315, spill policy above):
zero below-base spill-pointer candidates in the translated shaders. The root signatures themselves, and how many
exceed the budget, are still to be dumped from the executable.
driver must spill non-fitting parameters to memory. The compute block behind s[0:1] is now measured and
modelled above, including embedded builder programs that use it even when the signature fits. Graphics spill
layout and a census of runtime-created title signatures remain open. The D3D-315 census above covers the main
shader set, not those embedded programs.
- **Direct heap indexing.** The bound heap base and stride are not root parameters. Measured (D3D-329, section
3.4): each heap's base reaches the shader as a 32-bit pointer in an entry SGPR, inside the user data for compute
(and below `s32` for the graphics stages, whose user count is not measured yet), and the stride is compiled into
Expand Down
Loading
Loading