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

Open
github-bot wants to merge 89 commits from github-bot/gh-1970 into main AGit
Owner

@⁠antocorvo3000 on GitHub · 2026-11-25 01:56 UTC · original
antocorvo3000:gta6-first-approach → main · +10602 −840 · 38 files · 89 commits · draft

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 #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.

**@⁠antocorvo3000** on GitHub · 2026-11-25 01:56 UTC · [original](https://github.com/Marvisak/VIctory/pull/1970) `antocorvo3000:gta6-first-approach` → `main` · +10602 −840 · 38 files · 89 commits · draft 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 #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.
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 (#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 <[email protected]>
# Conflicts:
#	crates/victory-gpu/src/draw.rs
Local build only, not for distribution.
Work by work (interrupted by its usage limit), committed by the other agent.
# Conflicts:
#	crates/victory-gpu/src/shadow.rs
The descriptor data buffer now holds four dwords per heap slot, adding the
buffer view's element stride; a record-indexed buffer access without a
metadata stride becomes a raw access at index * stride + offset. A gather
at a level other than zero samples the four texel centers at the nearest
level.
# Conflicts:
#	crates/victory-gpu/src/descriptor/host.rs
This reverts commit 7dc968f89dc84b054bf49e524200c5eb3fd6f442.
The descriptor data buffer now has four dwords for every slot of the host view
heap (title and dynamic slots); a shader gets the slot count from its size and
sends an index past the heap to the heap's last slot, which is reserved and
stays null. Offline diagnostics for container parts and disassembly
(VICTORY_LOCAL_PARTS, VICTORY_LOCAL_DISASM).
- watch: guard sets (3 BTreeSets) -> chunked flag table; a range whose blocks are all clean/hole is answered without a walk; memory known as guarded view skips VirtualQuery/GetWriteWatch (VICTORY_FAST_GUARD=0 off)
- watch: allocation extents found by range without VirtualQuery (VICTORY_EXTENT_CACHE=0 off)
- shadow: MIRROR_CHECKED/COPIED hash maps -> one flat per-page table
- host: due textures hashed/detiled together on the pool at flush (VICTORY_TEX_PARALLEL=0 off)
- fix two watch tests (new submission between askings) and overflow in direct::remapped
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.
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.
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.
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.
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.
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.
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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:50:24 +00:00
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 03:15 UTC · original

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

**@⁠Marvisak** on GitHub · 2026-11-25 03:15 UTC · [original](https://github.com/Marvisak/VIctory/pull/1970#issuecomment-7151739966) <!-- victory-triage v1 head=ed73944bee83b0e23f3a56a9c1f36d60236ec53f verdict=needs-rebase at=2026-11-25T03:17:00Z --> 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](https://claude.ai/code)_
This pull request has changes conflicting with the target branch.
  • apps/victory/src/run.rs
  • apps/victory/src/shader.rs
  • apps/victory/src/translate.rs
  • crates/victory-gpu/src/copystat.rs
  • crates/victory-gpu/src/descriptor.rs
  • crates/victory-gpu/src/descriptor/host.rs
  • crates/victory-gpu/src/draw.rs
  • crates/victory-gpu/src/host.rs
  • crates/victory-gpu/src/lib.rs
  • crates/victory-gpu/src/list.rs
  • crates/victory-gpu/src/pipeline.rs
  • crates/victory-gpu/src/pipeline/host.rs
  • crates/victory-gpu/src/queue.rs
  • crates/victory-gpu/src/resource.rs
  • crates/victory-gpu/src/shader_cache.rs
  • crates/victory-gpu/src/shadow.rs
  • crates/victory-gpu/src/watch.rs
  • crates/victory-shader/src/emit/bitcode.rs
  • crates/victory-shader/src/emit/container.rs
  • crates/victory-shader/src/emit/host.rs
  • crates/victory-shader/src/emit/lower.rs
  • crates/victory-shader/src/emit/mod.rs
  • crates/victory-shader/src/emit/shader.rs
  • crates/victory-shader/src/emit/valu_tests.rs
  • crates/victory-shader/src/emit/waterfall_tests.rs
  • crates/victory-shader/src/emit/wave.rs
  • crates/victory-shader/src/resource.rs
  • crates/victory-shader/src/structure.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1970/head:github-bot/gh-1970'
git switch 'github-bot/gh-1970'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1970'
git switch 'github-bot/gh-1970'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1970'
git switch 'github-bot/gh-1970'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1970'
git switch 'main'
git merge --squash 'github-bot/gh-1970'
git switch 'main'
git merge --ff-only 'github-bot/gh-1970'
git switch 'main'
git merge 'github-bot/gh-1970'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!1970
No description provided.