Files
6gbvram---16gb-ram/docs/architecture.md
T
r4.andClaude Opus 5.5 6638098cee Shaders: per-lane descriptors chosen by control flow
A waterfall loop whose descriptor dwords are VGPR phis stopped with "a
descriptor read from the first lane of a phi" (294 programs of the
title on #307, all at if/else joins of two s_load_dwordx4 descriptors
copied into VGPRs). An EXEC if/else leaves two phis per dword: the
flow block's joins an arm's dwords with what lanes that skipped the arm
held before (inputs, unrelated loads and arithmetic in the title), the
join after the other arm picks per path. Only lanes that never read the
descriptor bring those other values, so tracing every edge fails.

Tracing (resource::track now takes the program's per-lane form):
- per-lane phis of one block are traced on each edge into it that the
  lanes accessing the descriptor can take, from structure's lane
  conditions (new Structured::reach, the exits' conditions, and
  Bools::meet, a read-only satisfiability check); the trace starts from
  what holds in the access's block. Edges no such lane takes are None
  in the new Source::LanePhi { block, args };
- every per-lane write it follows (v_mov_b32 copies, v_cndmask_b32,
  global_load_dword*) must run in all those lanes: a guarded one fails
  with "a per-lane descriptor written where some lanes may keep the old
  one". On #307 an else arm without its s_cbranch_execz traced as the
  second descriptor for every lane;
- a loop header's phi fails with "a descriptor read from the first lane
  of a phi at a loop header", words defined after the join with "a
  descriptor partly joined by control flow"; without the per-lane form
  (structurisation failed) the join is refused.

Lowering computes each traced edge's heap index at its predecessor's end
(through lane_heap_index, so loads, per-lane loads, choices and nested
joins work), joins them with a phi (0 on untaken edges) and makes the
handle non-uniform. The waterfall compares need no change.

Tests: the if/else of two loaded image descriptors, a join of a per-lane
load and a v_cndmask choice, nested arms choosing a buffer descriptor
with lanes that skip both and do not load (pruned only by the access's
condition), a loop header phi, and an unskipped else arm. On #307's head
the three join programs fail with "...of a phi" and the unskipped arm is
traced as one descriptor for all lanes. On an RTX 5070 and WARP, each
lane reads its own arm's texture or buffer; the shaders pass dxil.dll
1.8.2502.11. Reversing the phi's inputs fails validation, flipping the
heap index fails the GPU check.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-24 06:59:46 +02:00

5.3 KiB

Architecture

 user's files (outside repo)             VIctory
 ───────────────────────────             ─────────────────────────────────────────
 game assets ──────────────────────────► victory-pipeline + victory-game
                                         (victory-formats, victory-shader)
                                                    │
                                                    ▼
                                         cache_dir: converted data
                                                    │
 game executable ─► victory-loader ────► title code (native x86-64)
                    prepare, map, bind      │ imports
                                            ▼
                                         victory-hle ── host Windows (shared APIs)
                                            │ D3D12.X
                                            ▼
                                         victory-gpu ─► host D3D12
                                            │ shaders at pipeline creation
                                            ▼
                                         victory-shader ◄─► cache_dir

Shaders are translated when the title creates a pipeline, from the bytes it passes, wherever it loaded them from (executable, archive, memory). Converting them ahead of time from files is only a warm-up.

Crates

Crate Role
victory-core config, asset-policy guard, logging
victory-pe read-only PE32+ and import-library analysis
victory-loader prepare, map, bind and start the title image
victory-hle console API implementations, host pass-through policy
victory-gpu D3D12.X objects, command lists and GPU memory → host D3D12
victory-shader Xbox shader containers → host shaders
victory-formats the GPU's texture layouts (sizes, tiling, detiling), audio codecs; planned: BCPack
victory-pipeline converter trait, content-addressed cache
victory-game Grand Theft Auto VI-specific formats, build identities, hooks
apps/victory command-line front end
xtask asset-policy check, git hooks
tests/fixtures/hle-probe a stand-in "title" (our own code) for loader tests

Everything except victory-game is platform-level and can be tested with any Xbox Series title.

Import resolution

For every dll!function the title imports, in order:

  1. our implementation in victory-hle::modules (always wins);
  2. the host's own function, if HostPolicy allows that DLL;
  3. an export of a DLL the title ships beside its executable, mapped like the executable (only DLLs neither of the above serves);
  4. a generated stub that names the import when called (--unimplemented trap breaks into the debugger and aborts; zero logs once and returns 0).

LoadLibrary* of a console-only DLL we implement (e.g. xgameruntime.dll) returns a pseudo handle; GetProcAddress on it finds our functions. LoadLibrary* of a title DLL returns its mapped image, mapping it first if nothing imports it. By name, as by import, a title gets only host DLLs HostPolicy passes through, and GetProcAddress on one returns our override where import binding would. QueryApiImpl hands out our runtime objects by provider and interface id (victory-hle::modules::xgameruntime lists the areas); online areas answer as an offline console. Game saves are files under VICTORY_DATA_DIR.

Title storage is a drive on the console, and titles build paths on that. victory-hle::modules::files binds every path-taking title import (kernel32 and the C/C++ runtime) and rewrites paths on a virtual drive to the host folder behind it; persistent local storage is one such drive over a folder under VICTORY_DATA_DIR. Other paths reach the host unchanged.

An exe's code reaches its static TLS as slot 0; mapped as a DLL it gets another slot, so the loader redirects those loads (victory-loader::tls). victory run --execute installs a crash reporter that names faults as module+rva and unwinds the faulting thread's stack (victory-loader::crash).

victory census shows this classification without running anything (it does not map title DLLs; victory run without --execute does).

Shaders

victory_shader::ir::build turns a native program into SSA, one instruction per machine instruction. victory_shader::structure then removes EXEC: lane masks become per-lane booleans, wave-wide mask tests become per-lane branches, and vector instructions keep a guard only where a lane can reach them with its EXEC bit clear. victory_shader::resource traces each descriptor and scalar memory address to the root parameter it comes from (table, heap, root descriptor or constant). A descriptor a waterfall loop reads from the first lane (v_readfirstlane_b32) is traced to the per-lane load or choice that gives each lane its own (a mask's v_cndmask_b32, or an if/else whose arms each set it: traced on the paths the lanes take, from structurisation), and accessed with a non-uniform heap index in one pass. victory translate runs every shader it finds (containers, SGD5 files) through these and lists what they cannot handle yet.