Skip to content

GTA VI: all local work to reach the lit world, on current main (draft) - #1965

Draft
antocorvo3000 wants to merge 37 commits into
Marvisak:mainfrom
antocorvo3000:gta6-all-work
Draft

antocorvo3000 wants to merge 37 commits into
Marvisak:mainfrom
antocorvo3000:gta6-all-work

Conversation

@antocorvo3000

@antocorvo3000 antocorvo3000 commented Nov 25, 2026 •

Copy link
Copy Markdown

Updated: the branch is now on top of current main (940d32f). This is the build that reaches the lit world of Grand Theft Auto VI 1.0.2.1 on an RX 6800 XT (Series X mode): exteriors and interiors lit, ~1.1-1.2 fps, about 5,000 draws/frame. Textures are still missing in places and some geometry is broken (hair as spikes); that is the next work. Opened as a draft so you can take what is useful; #1962 is the focused heap-usage change.

Findings on current main

  • Prologue cutscene crash with view marks. With cd94d35 and 940d32f the title crashes in the prologue cutscene (int_prolo_int_prolo_int, a title read of address -1, reproduced twice on plain 940d32f with only the run conveniences below). Without those two commits the same scene runs 19 minutes. Here view marks are behind VICTORY_VIEW_MARKS=1 (off) and 940d32f is reverted; the shader cache key includes the setting.
  • White game window (timing dependent). The presenter attached the swap chain to the first visible top-level window; if the title presented before showing its window, frames went to our own window and the title's stayed white. Now the swap chain goes to the title's stand-in window even before it is shown (VICTORY_PRESENT_STAND_IN, default on), with a window test that reproduces it.
  • Descriptor tables serialized the recording threads. Each table entry waited on the heap's made mutex, which waited on the VIEWS mutex: 167 us per table in the world (~2.3 s of thread time per frame). Lock-free fast path for unchanged slots, RwLock for VIEWS and buffer copy lookups (VICTORY_MIRROR_FAST, default on).

What is in it (beyond the earlier description)

  • Heap usage feedback, including descriptors loaded dynamically from tables (VICTORY_HEAP_TABLE_MARKS).
  • Translator: the 20 shaders that did not translate in the world now translate and validate (lane-mask joins, selects on untracked masks, SCC from lane-mask SOP ops, descriptor dimensions, f64 sums in whole-wave sections, unreachable phi predecessors, nested descriptor phis), each class behind a switch.
  • CopyTextureRegion to placed footprints, v_permlanex16_b32, v_cvt_f32_f64.
  • Diagnostics: per-pipeline GPU profile (VICTORY_GPU_PROFILE=1), per-stage CPU profile (VICTORY_CPU_PROFILE=1), capture on demand (capture-now in the capture folder).
  • Experimental, off by default and not ready: VRAM copies of title memory (VICTORY_VRAM_COPIES=1, with async it removed the device at the start screens) and overlapping CPU preparation with GPU completion (VICTORY_ASYNC_SUBMIT=1, reaches the world but the lighting disappears).
  • Local conveniences, probably not for main: VICTORY_TITLE_DIR, VICTORY_AUTO_A, in-memory patches of the 1.0.2.1 executable. The patches that switch off lighting passes (4, 5, 7-9) are off by default; patch 6 (world render resolution mode) is on: without it the title takes a render path where the light and tile lists are bound as 1x1 placeholders and the exposure sits at its minimum (black world).

Testing

cargo test --release --lib: victory-gpu 182, victory-shader 258 passed on this machine.

@antocorvo3000

Copy link
Copy Markdown
Author

More of the same work, for reference:

Marvisak commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Needs work; needs the maintainer's decision. The branch now merges cleanly, but CI check fails at 2c16ed2. It is 37 commits and about 6,900 lines across 38 files, and it cannot be reviewed or merged as one change. The testers' reports above suggest some of this work matters, so here is what would make it reviewable:

  1. Patching the title's code. apply_patches in apps/victory/src/run.rs writes over the title's code in memory at fixed RVAs. It turns off its hang detector, lighting passes and an audio lock, and adds a VICTORY_PATCH env syntax for arbitrary patches. The "expected bytes" are, in effect, signatures. Whether VIctory patches title code at all is the maintainer's decision. It should be a separate PR of its own, with the offsets tied to the build identity (victory_game::identify), not a raw RVA table.
  2. The revert of main. Commit b4f959d reverts "GPU: a marked page's copy-back does not save the page for its own copy", which is main's head (940d32f). If that change is wrong, please say why in a separate PR.
  3. Commits marked "Local:". These are VICTORY_TITLE_DIR, VICTORY_AUTO_A, the scaled GPU clock and the per-build pipeline library. They are personal setup and don't belong here.
  4. The rest as separate PRs. For example: the VRAM shadow / dirty-page sync, the shader-translator lowerings (several may already have open PRs, such as v_permlanex16_b32 in Shaders: honor permlane EXEC and FI/BC flags (on #1014) #1737), the CPU and GPU profilers, and CopyTextureRegion texture-to-buffer. Each needs its own tests and description.
  5. CI. check needs to pass.

Generated by Claude Code

@fiestorra

Copy link
Copy Markdown
Contributor

Independent check on NVIDIA: as it stands, this branch still removes the device at frame 64 here — and that is the AMD/NVIDIA difference, not a criticism of the work

I ran your branch as it is (rev = c68d6fb, based on 42363ab, no rebase) on this machine: session 1 (interactive desktop), RTX 4090, driver 32.0.16.2124, release, empty cache, 150 s:

device removed                          2
no host texture … 2560x1440 format 115  1
host texture made only as a fallback    0
dropping unordered access               0
host view heap capped at 1000000        1
frame=64 draws=96

So on an NVIDIA card it does not reach the world: it stops at the same frame 64 that main at that revision stops at.

Why yours works and mine does not, as far as I can tell from the numbers: B4G4R4A4_UNORM (DXGI format 115) can be a render target on the RX 6800 XT and cannot on this driver. That is the ALLOW_RENDER_TARGET call the D3D12 debug layer refuses here:

id=599  A texture with D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET must be created with
        a format that is, or can be cast to, a render-target format.
        D3D12_RESOURCE_DESC::Format is B4G4R4A4_UNORM.

On your card the same call is legal and the boot goes on to the world; here it removes the device. That is why the same tree gives two completely different reports.

The two fixes that make it survive on NVIDIA are already open against main and do not touch what you are working on:

With those two on main today I measure no removal, 2,048 frames, 13,312 draws in 120 s, where main alone dies at frame 64. So the combination worth measuring is your branch rebased onto a main that has those two: if your work is what reaches the world on AMD, that is the first candidate to reach it on NVIDIA as well.

What stops that measurement right now: your branch conflicts with today's main in five files —

crates/victory-gpu/src/descriptor/host.rs
crates/victory-gpu/src/shader_cache.rs
crates/victory-gpu/src/shadow.rs
crates/victory-shader/src/emit/host.rs
crates/victory-shader/src/emit/shader.rs

which is also why GitHub reports it as not mergeable. I did not attempt the rebase: it is 3,262 lines across 28 files and the conflicts are in the page-marking and heap ground where guessing does more harm than good.

If it helps, I can measure the rebased tree the moment it exists — same scenario, numbers in a comment, on the card where the failure is reproducible.

No game data is involved: counts, warnings and a format name.

Written with an AI assistant.

…tor, heavy passes, audio lock), applied only where the expected bytes are found
… changed (whole 64 KiB pieces lost the title's stores: game crashes at world entry)
Port 90d2128 to upstream-try. Use PSV runtime info v3 for implicit compute samples on quad-compatible thread groups. The four-source offline corpus gains 735 DXIL validations and retains every existing emission and validation.
Port 03978e5 to upstream-try. Use SV_Barycentrics for direct reads and materialize entry inputs consumed by live phi edges. The four-source offline corpus gains three validating pixel shaders and retains all previous emissions and validations.
Check set bits directly for missing pages and leave empty words untouched during copy-back. VICTORY_SPARSE_PAGE_BITMAP=0 restores the original scans.
…destination)

- Add CopyLocationData union so CopyLocation matches D3D12_TEXTURE_COPY_LOCATION
  exactly (subresource index and placed footprint share the same 36 bytes).
- Route dst=FOOTPRINT, src=SUBRESOURCE to new copy_texture_to_buffer(), which:
  * validates format compatibility, row-pitch alignment (256 B) and source box;
  * uses host.shared_buffer() as a D3D12 staging buffer;
  * emits CopyTextureRegion on the host list (texture -> staging, offset 0);
  * barriers the staging buffer to COMMON and defers a TextureReadback so the
    next same-list buffer->texture upload that overlaps the same title range
    can compose the GPU-written bytes over the CPU-written bytes;
  * in defer_after(), opens the watched title pages and writes the texel rows
    back via write_mapped(), leaving row padding and out-of-box bytes alone.
- Extend the buffer->texture path: check for overlapping prior readbacks and,
  when found, compose them into the upload buffer via compose_texture_upload()
  before recording the copy, so round-trip title reads see GPU output.
- PlacedFootprint fields made pub(crate); bytes() now uses checked arithmetic
  and rejects footprints where the last row exceeds the pitch.
- Deferred struct gains a readbacks Vec; HostList exposes defer_texture_readback
  and texture_readbacks helpers.
- Unit tests: PlacedFootprint::bytes (1x1, two-row, full-row, BC1, invalid,
  unknown format) and CopyRows::new (full 2x2, sub-box, x-offset, volume
  two-slice, zero-size, out-of-bounds): 100 passed 0 failed.
Shaders that take descriptors from the resource heap itself (bindless
materials) read placed-texture slots that the heap mirror leaves null
until a draw reads them through a table (the shortcut that keeps ~20,000
host textures from being made at once). In Grand Theft Auto VI most
world materials sample that way, so their G-buffer albedo came out
black and the lit scene stayed dark.

Translated shaders now mark each heap slot they take a shader resource
view from in a bitmap (u1 in the memory space, an atomic OR per lane),
bound per list like the written-pages bitmap. After the list ran, each
marked slot still holding a placed texture left for later is made, so it
reads from the next list on. Only the textures in use are made.

VICTORY_HEAP_USAGE=0 turns the marks off (shaders as before). The frame
line reports slots marked, views made, and why marked slots were not
made. Unit tests leave the marks off (the hardware harness binds only
the parameters each test names).

Measured in the world: albedo coverage from ~20% to 99% of the screen;
about 10-20 views made per 5 s once streamed in; no view failed to make.
Resolve paired timestamp queries on the recorded lists and aggregate completed measurements by pipeline and command kind. Enable with VICTORY_GPU_PROFILE=1 in diagnostics builds.
With VICTORY_HEAP_USAGE_VRAM=1, clear private GPU-local bitmaps at submission, then copy marked bits to readback after each list. Preserve feedback across repeated list executions and fall back to the shared bitmap if allocation fails.
…HEAVY=1: some passes ran at 1280x720 in 2560x1440 targets and the GPU took twice as long
…er next; the title-filled texture debug line only in captured frames
…hed with them); the shader cache keys on view marks and heap usage
…n (VICTORY_CPU_PROFILE=1)

Timers summed per stage (draw prepare, bind, heaps, pipeline, tables,
table entries, readable, user data, root views, vertex/index buffers,
target states; submission: sync heaps, bindless uploads, run deferred by
step kind, batch flush, preludes, vram sync) and counters of lookups and
locks on the path, logged every 5 s per frame. Off by default; off, each
timer is one relaxed atomic load. Adds an ignored micro-benchmark,
draw::tests::draw_sequence_bench, that replays 5000 world-like draws
(tables of constant buffers, raw buffer views and placed textures,
vertex and index buffers, a root constant buffer) and one submission.
The vertex/index part of prepare_for moves into State::vertex_index,
unchanged, so the benchmark can call it.
…ets, per-lane fetches, slots no UsedResource names) mark their slots too, so placed textures read that way are made (VICTORY_HEAP_TABLE_MARKS=0 turns it off; part of the shader cache key)
…RROR_FAST, default on)

The in-game profile showed ~167 us per table (12 entries). A benchmark
with six threads recording at once over one shared heap, 5,000 registered
buffers and a thread writing view records meanwhile (draw_threads_bench)
reproduces it: 168.6 us per table, 9.8 us per entry spent waiting for the
heap's made-slots mutex, held by each mirror while it waited for the
global view-records mutex that the title's view creation keeps taking.

- Host heap slots keep their record keys in atomics; a slot already made
  from the record a draw finds returns its view without the heap's lock
  (VICTORY_MIRROR_FAST=0 takes the lock every time as before). A slot
  being remade shows key 0 until its view is written.
- View records sit behind an RwLock: lookups share it, and recording a
  view already known takes only the shared lock.
- Buffer copy lookups share an RwLock; only making a copy takes it
  exclusively.
- Finer profile stages inside table entries (mirror, its lock waits,
  descriptors made, placed textures, copy lookup and its lock, deferred
  refresh, texture state) and counts of slots remade.

Benchmark per table: 168.6 us before, 31.7 us with the switch off (the
RwLocks alone), 19-23 us with it on; recording wall time 341 ms -> 45 ms.
…ult off); note_use without a key per draw

VICTORY_BATCH_PRECISE_COPIES=1: a title copy at submission flushes only
the pending refreshes whose ranges reach the pages it writes and drops
only the current ranges there, instead of flushing every copy and making
every copy due again (the world has 60-90 title copies per frame, each of
which made every later list check its big buffers again).
VICTORY_BATCH_FLUSH_ONE=1: a range shaders write (not marked) flushes only
its own copy's pending refresh before its snapshot.
Both default off: with fewer flushes a copy's ranges merge into wider
hulls, and a range a list asked for before a title copy rewrote it in the
same submission may then hold the copy's bytes (the old path does the
same where its hulls reach it). Every other asked range holds the same
bytes: precise_flushes_give_shaders_the_same_bytes runs one step script
both ways on identical memory and compares them (228 copy updates against
172 with both on). Adds title_copies_per_submission, an ignored
benchmark, and a copy-update count to the CPU profile.

memory::note_use finds a pipeline counted before by name instead of
making an owned String key on every draw reading title memory
(VICTORY_NOTE_USE_LOOKUP, default on; same counts, unit-tested).
The CPU profile counts views made readable instead of timing each one
(the timer alone cost about 1 us per draw).
…M copies are on

The VRAM copy port changed indirect::done to leave the argument buffer in
the common state for every run. With VICTORY_VRAM_COPIES unset it goes
back to unordered access again, as before the port, so the switch off
records the same barriers as the build without VRAM copies.
…ws it

The presenter took the first visible window of the process. When the
title presented its first frame before it showed its window, there was
none: the presenter made a window of its own and kept presenting there,
while the title's window (the stand-in victory-hle shows for it) stayed
white for the whole run. Boot timing decides that race, so unrelated
changes moved builds from one side of it to the other.

The swap chain now goes to the stand-in (class VIctory.title) whether it
is shown yet or not, a shown one first (VICTORY_PRESENT_STAND_IN, default
on; =0 takes only a visible window, as before).

The "presenting to a window" line names the window (hwnd, stand_in,
visible, own), and a failing swap chain Present is logged (first 8).

frames_presented_before_the_title_shows_its_window_reach_it (ignored: it
opens a window) presents before showing a hidden stand-in, then reads the
stand-in back as composed (PrintWindow with full content): red with the
switch on; white with VICTORY_PRESENT_STAND_IN=0.
…out it the world came out black (light lists bound as placeholders, exposure at its minimum)
@antocorvo3000 antocorvo3000 changed the title GTA VI: all local work to reach the lit world (draft, for reference) GTA VI: all local work to reach the lit world, on current main (draft) Nov 25, 2026
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