Skip to content

GTA VI: first approach with the title memory mirror (draft, for reference) - #1970

Draft
antocorvo3000 wants to merge 89 commits into
Marvisak:mainfrom
antocorvo3000:gta6-first-approach
Draft

antocorvo3000 wants to merge 89 commits into
Marvisak:mainfrom
antocorvo3000:gta6-first-approach

Conversation

@antocorvo3000

Copy link
Copy Markdown

Our first approach to Grand Theft Auto VI 1.0.2.1 (based on main of 24/11 morning, before many of your recent changes), published for reference: 87 commits of ours. Several of its fixes are now covered differently on main, but some are not, for example:

  • Title memory mirror: one reserved 128 GiB GPU buffer with title pages mapped at their own addresses; one reserved buffer per title memory view (raw views must end below 4 GiB of their resource).
  • Copy-back of only the dwords the GPU changed, and plain stores into read-write title memory.
  • Root UAVs declare only the bytes the shader can reach (range analysis of the translated DXIL).
  • Translator: image_sample_d_cl and cube gradients from face space, 64-bit image atomics (R32G32 views, SM 6.6), spilled compute roots, computed title reads and indexed root buffers, structured buffers of unknown stride, gather4 at an explicit level, s_getpc_b64, masked static buffer addresses in mesh shaders, backward lane permutes.
  • Compute dispatches past 65535 groups per dimension are split.
  • Texture to buffer copies (an earlier version of the one in GTA VI: all local work to reach the lit world, on current main (draft) #1965).
  • Diagnostics: device-removed reports naming mirror aliases, why a draw cannot bind, Agility SDK device factory (VICTORY_D3D12_AGILITY).
  • Local conveniences: two-plane compositor for Series S menus, VICTORY_AUTO_A, in-memory title patches.

The work that reaches the lit world on current main is #1965 (and #1962 for the black albedo). A budget-based alternative for placed-texture heap slots, superseded by #1962, is on branch gta6-placed-texture-budget of the fork.

edsuuu and others added 30 commits November 24, 2026 01:46
A draw whose table starts at a title slot the capped host heap does not
have, and that was not made afresh, got the title's offset as its user
data; the shader then indexed ResourceDescriptorHeap past the heap's end.
On NVIDIA that reads garbage descriptors and the device hangs (Marvisak#71). In
three DRED reports from an RTX 4060 Ti, 13 of 14, 22 of 29 and 20 of 29
of the tables the unfinished draws bound start past slot 1,000,000 (the
title's per-draw tables sit at its heap's top, around 1.2 million).

Such tables are made afresh, but when that fails (no free dynamic slot:
the 65,536 of a capped heap run out seconds into the world; or entries
reaching past the title heap's end) the draw fell back to the title's
offset. The draw or dispatch is dropped instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…heap

# Conflicts:
#	crates/victory-gpu/src/draw.rs
…ter copies, auto A, freed-texture grace, buffer padding)

Local build only, not for distribution.
… the device); copy-back compare threshold; sections opt-in
…loops electing with readfirstlane never ended for helper lanes and hung the GPU

Work by work (interrupted by its usage limit), committed by the other agent.
…ges mapped at their own addresses and shared by every copy (reads past a copy find neighbours or zeros, no page fault)
…(views, barriers, indirect); shader addresses stay the mirror's
# Conflicts:
#	crates/victory-gpu/src/shadow.rs
…tor, heavy passes, audio lock), applied only where the expected bytes are found
…hole in a submission is not checked again by other copies
The translated compute shader adds a per-component group-id offset (an extra
user-data dword, zero by default) to its workgroup id; the host runs the range
in chunks, rewriting the offset dwords between Dispatch calls. Indirect
dispatches stay clamped by the existing GPU-side clamp.
…iner, translated DXIL and GFX10 listing

Local diagnostics only: with VICTORY_LOCAL_SHADER_MANIFEST and VICTORY_LOCAL_DUMP=<dir>,
each validated shader leaves <id>.console.bin, <id>.translated.dxil and <id>.gfx10.txt.
…lane conditions, so impossible waterfall/join edges stayed possible)

Mesh shaders whose sampler descriptor is joined by an if/else with a loop
(adc5c689, fb5e4cf7, 903776ba, 89a62261, fe660f2d) now translate and validate.
Whole corpus: +42 validated programs, none lost.
…mirror ranges other copies' shaders write

copy_back read a 64 KiB piece of title memory, patched the GPU's bytes in and wrote the whole
piece back with WriteProcessMemory: title writes made in between to the rest of the piece were
lost. Root UAVs (declared to the end of their copy) reach into big heaps holding the title's
own records. Now each run of GPU-changed dwords is written by itself; a mirrored copy no longer
syncs other bytes into the shared mirror, and a handled piece is marked in the snapshot.

Mirrored copies share pages: a refresh of another copy (merged mirror refresh, or a copy with its
own pending ranges) after a snapshot pulled title bytes into a range being written, and the
copy-back took them for the GPU's and wrote them over newer title writes. Mirror refreshes now
skip every mirrored range declared written in the submission being prepared.
…om face space; log shaders that read title memory (VICTORY_DENY_TITLE_MEMORY)
…lysis of the translated DXIL)

A root view has no size, so a root UAV was declared read and written from its
address to the end of its copy: refreshed, snapshotted and diffed for copy-back
over the game's own CPU records that share the title buffer.

The translator now bounds each root UAV (emit/extent.rs). Every access through
its handle (raw loads and stores, 32/64-bit atomics) gets the largest byte
offset it can use, as an affine bound in the dispatch's group counts and the
user-data dwords:
- thread/group ids (including a split dispatch's group offset), lanes,
  constants (folded);
- adds, products with a constant-bounded side, shifts, masks, remainders,
  divisions, min/max, selects, and phis outside loops.
A peak bound on every intermediate value makes the bound hold only if no
32-bit operation wrapped. HostShader::root_uav_extents exports it (also in
the shader cache). At bind time the runtime evaluates it with the direct
dispatch's (or mesh dispatch's) group counts and the bound user data. It falls
back to the end of the copy when unknown: draws, indirect dispatches, offsets
loaded from memory, loops, or a peak past 4 GiB.

The per-power-of-two-frame log counts bounded and unbounded root UAV binds
and their bytes. VICTORY_ROOT_UAV_EXTENT=0 restores the old ranges. The
offline batch tallies the slots: XboxBvhBuilder.dll (the only container with
root UAVs) has 45 of 80 bounded (8 constant, 37 by dispatch or user data);
the 35 left take offsets from memory. Validation counts are unchanged.
… unmade table entries instead of dropping draws; diagnostics count why host descriptors are missing
…ne WriteProcessMemory per run

8867c99 writes each run of GPU-changed dwords by itself; through the kernel that is one
WriteProcessMemory per run, ~10-80 us each, and the world's ~100,000 runs a frame took 1.7 to
5 s ("copying back" in vi55/vi56/vd37). The same runs are now stored directly where the piece is
committed read-write (one VirtualQuery answer kept for the pieces after it: a query walks the
whole region, ~80 us for 64 MB); elsewhere (read-only or otherwise protected) the kernel as
before. The bytes written are the same: runs are not merged, title bytes between them are never
written. The dword walk skips equal stretches 32 bytes at a time.

VICTORY_COPY_BACK_KERNEL=1 writes every run through the kernel again (bisection).

copy_back_cost (64 MB, release): 1,024 pieces x 128 dwords 9.86 s -> 14.6 ms; 256 x 1,024
17.0 s -> 12.0 ms; nothing changed 4.8 ms either way; identical title bytes in every case.
Tests: the fast walk matches the old one; both write modes give the same bytes (read-write and
read-only memory); a title thread's writes to the other dwords survive concurrent copy-backs.
…t views bind a null view, unset root constants read zero, mirror read+write no longer dropped

Direct draws and dispatches whose bind failed outside the descriptor tables were
counted nowhere, and indirect ones only as "prepare failed": every refusal is now
counted as "<pipeline> bind: <reason>" (and lenient substitutions as
"<pipeline> bind (lenient): ...").

Leniency, as for tables (VICTORY_STRICT_ROOTS=1 restores the drops):
- a root CBV/SRV/UAV the host cannot make (unset by the title, no host copy, ...)
  points at the title memory mirror's unmapped first page (tiled resources
  tier 2: reads zero, writes discarded);
- an unset root constant reads zero (unset tables still drop);
- reads and writes of the mirror in one bind are no longer dropped: the title
  memory table reads it through resources of its own, and buffers have no
  layout for a read and a write to disagree on.
…re read raw (55 compute shaders); trace dispatches of listed frames
…ade raw (runtime): GTA VI places 32-byte structures at 16-byte addresses, which D3D12 refuses as structured views (lighting read zeros); diagnostics for refused buffer views
…ructured views stay structured (raw would exceed 2^27 elements)

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

This pull request conflicts with main in 26 files, among them crates/victory-gpu/src/descriptor/host.rs, crates/victory-gpu/src/shadow.rs, crates/victory-shader/src/emit/lower.rs and apps/victory/src/run.rs. It will be reviewed once it is rebased onto current main.


Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants