Skip to content

Port Marvisak/VIctory#294 (Root UAVs) onto #185 + main (stacked on #4) - #5

Closed
desplmfao wants to merge 139 commits into
aycow:fix/direct-indexed-buffer-coherencyfrom
desplmfao:port/294-on-185
Closed

desplmfao wants to merge 139 commits into
aycow:fix/direct-indexed-buffer-coherencyfrom
desplmfao:port/294-on-185

Conversation

@desplmfao

@desplmfao desplmfao commented Nov 24, 2026 •

Copy link
Copy Markdown

This PR is mainly for testing: it checks whether Marvisak#294 can work on top of Marvisak#185 and current main, and what it takes to make the two fit. Feel free to merge it if you want it, but it adds about 1,400 lines and overlaps Marvisak#493's root SRV handling, so it could make the upstream history and Marvisak#185 itself a bit messier. Keeping it as a follow-up after Marvisak#185 lands, or leaving Marvisak#294 to be updated by its author, is just as fine.

Port of Marvisak#294 by @wbkepler ("GPU & shader: full Root SRV extent refresh, safe fallback VAs, and Root UAVs") onto Marvisak#185 as merged with current main in #4. Stacked on #4: until #4 lands, this diff includes #4's merge commits.

Marvisak#294's two commits (bffaefd, 0050ce5) are merged unchanged with their original author. The only changes of mine are the two merge commits that resolve conflicts with Marvisak#185 and main. Review should go to Marvisak#294 for the feature itself; this PR is about whether it fits on Marvisak#185.

Why

On NVIDIA under Proton, the world's lighting and composition compute passes are dropped. With Marvisak#489 (which includes Marvisak#302) on the Marvisak#185 stack, most of them get past the root-argument problem, and the next failure for several is a root UAV or typed root view is not supported, which Marvisak#294 adds. For example, compute 3b90165a77d95cdf drops about 1,000 draws per frame in the world.

Conflicts

The first merge, of Marvisak#294 into #4's branch, had 17 hunks in 7 files:

file resolution
emit/{host,mod,lower}.rs, shader_cache.rs (struct fields) both sides' new fields kept: Marvisak#185's heap_buffer_srvs, Marvisak#294's root_uavs
shader_cache.rs decode reads root_uavs before heap_buffer_srvs, in the order encode writes them; the cache is keyed by the build fingerprint, so there is no format version to bump
emit/shader.rs features Marvisak#185's STENCIL_REF and Marvisak#294's UAVS_AT_EVERY_STAGE / UAVS_64 flags, all kept
shadow.rs both new methods kept (superseded, read_u32); loose() keeps Marvisak#294's texture::committed check and allocates through Marvisak#185's allocate_buffer (its counters)
emit/valu_tests.rs both sides' new tests kept
hidden: test initializers Marvisak#294's HostShader in a test gains heap_buffer_srvs; Marvisak#185's shader_usage test gains root_uavs

The second merge brings #4's update to main ffe310e: lower.rs keeps Marvisak#294's field next to main's test-only fields. Marvisak#294's two tests that call resource::track gain main's new Some(&structured) argument, and main's new waterfall test gets root_uavs.

Tests

Windows target, cross-built on Linux, run under proton-cachyos 11.0 with vkd3d-proton on an RTX 5080:

AI-assisted (Claude Code).

🤖 Generated with Claude Code

jeremygold02 and others added 30 commits November 23, 2026 19:21
ADVANCE_XMA_READ added the title's block count to the 5-bit read block
in u32 before taking it modulo the ring size, so a count near u32::MAX
overflowed (a panic in debug builds). The count is reduced modulo the
ring first; the result is the same for every count that did not
overflow.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
kernel_will_write (fread's size times count, saturated) and
title_memory_remapped added the length to the address unchecked, so a
huge fread count overflowed (a panic in debug builds). The end now
saturates at the top of the address space.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Each rANS symbol scanned all of its model's bucket starts to find the slot's
bucket, then rebuilt the symbol's frequency and start from the symbol. A
per-model table of the bucket at each 256-slot window's first slot now starts
the search, which steps over the few buckets that begin inside the window; the
symbol, frequency and remainder come straight from that bucket. The lane loop
also keeps the record offset instead of dividing by the symbols per block on
every symbol.

Synthetic streams, release, one core (median of 3 runs, 16384 blocks):
BC1 177 -> 128 ns/block, BC4 184 -> 128, BC7 591 -> 452.

Tests: the window lookup against the scan for every slot of every model
(shipped tables, uniform tables, one-slot buckets); a payload step against the
first version's arithmetic on the shipped tables; every format's lane layout
round trips at 1 to 1000 blocks; an ignored throughput benchmark.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
CreateFileA, GetFileAttributesA, fopen, fopen_s and the narrow
std::_Fiopen turn the title's virtual-drive path into a host path and
then passed it to our own wide wrapper, which looked it up a second time.
When the host path starts with a letter that is itself mounted, it was
rewritten again: with the game on a host G: drive (say G:\GTA6), the
title's G:\x64\a.rpf became G:\GTA6\x64\a.rpf and then
G:\GTA6\GTA6\x64\a.rpf, so every narrow open of a title file failed.
The same happens for T: when the data folder is on a host T: drive.

They now call the host's wide function directly, as DeleteFileA,
SetCurrentDirectoryA, _open, _stat64i32 and remove already do.
…passes

Module::write dropped unread phis by sweeping every instruction until a
sweep changed nothing, allocating an operand Vec per instruction per
sweep. A chain of merges needs one sweep per merge, so the cost grew with
instructions x merges. A worklist now visits each instruction once and
reads operands through a callback; the block DFS, latch folding and the
call/phi/gep records stop allocating too. The written bytes are the same
(pinned by a test against the previous writer's output).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The scalar bit tests decode and are tracked in ir.rs (they write SCC) but the lowering had no case for them, so any shader using one failed to translate with Unsupported.
Reserve a new staging path and clean it up if writing or publishing fails. Cover a failed publication with a synthetic destination directory.
XMemMapPhysicalPages with a count of 0, and the GPU's page-mapping copy
of a zero-length range, went into unmap with an empty range. Its search
for views starting inside asked the view map for a range that runs
backwards, which BTreeMap panics on once any view exists; in an
extern "system" function that aborts the process. Without that panic
the view holding the address would have been unmapped and mapped again
as two.

unmap now returns at once for a length of 0.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
An illegal or privileged instruction is reported by its address only,
which does not say which instruction it was. On an Intel host that is
the question every such report raises (clwb, clzero, rdpru, an SSE4a
form...), and reporters have had to guess or dump the bytes by hand.

The report's first line now ends with up to 15 bytes at the faulting
address, as hex, read no further than the end of that page, so the
report names the instruction by itself.
An access violation is reported with the address it touched and
nothing else, so a read of free memory, a write to memory that was
reserved but whose commit failed, a stack guard page and a write to
code or constants all look the same in a report.

The report now adds what VirtualQuery says is at that address: nothing,
reserved but never committed, a guard page, or the page's protection,
with the module for an image's pages.
When the host cannot make an unordered-access view (no host texture, a
format the host does not allow, a placed texture not mirrored), null_for()
wrote a 2D null UAV whatever the title asked for. A shader that writes a
3D texture through it then has a dimension mismatch: GPU-based validation
reports it ("UAV Dimension Expected: TEXTURE3D, UAV Dimension In
Descriptor: TEXTURE2D") for the world's wind field
(WindNew:CS_CopyWindFieldBeforeUpdateWithSmooth, compute 5bb23d336331db1d,
image_load/image_store dim:SQ_RSRC_IMG_3D). Shader views already get a
null view of the title's dimension (null_like); unordered views did not.

Null texture UAVs now keep the title's dimension: 1D, 1D and 2D arrays,
3D (WSize -1). Multisampled and unnamed dimensions stay 2D. With this,
the validation error is gone on an RTX 5070.

Tests: the dimension mapping, and a null 3D UAV made on the real device
leaves it alive.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…guration's folder

A provider's folder is the user's folder plus the configuration id as a
file name. An empty id gave the user's folder itself, where the other
configurations' folders are. Opening the provider converts containers
of the old layout, which are folders without a `~` or a dot in their
name, as a configuration's folder is: each was taken for one, an empty
container was committed in its place and the folder was removed with
every save in it.

An empty id is now treated as no id (the default configuration).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
WinHttpGetProxySettingsEx is absent from Windows 10's winhttp.dll, so the
host-presence assertion panicked there. The HLE supplies it itself; skip it
only when the host lacks it, keeping the check for every other export.

Fixes Marvisak#118
XUserGetGamertag returned the name for every component, the modern
suffix included. The GDK documents the suffix as empty when there is
none, and a title that shows "name#suffix" whenever the suffix is not
empty showed "Player#Player".

The modern suffix (component 2) is now empty; the classic, modern and
unique modern components are still the name.
An unimplemented import with the default Trap policy printed its name
and aborted. abort() is a fast fail: it skips the exception handlers
and the panic hook, which are what append to crashes.log, so the most
common bring-up crash left nothing there, not even which import it was.

The trap now reports through log_crash, which prints the same line,
appends it to the crash log and adds the title's last debug output.
XTaskQueueDispatch with an infinite timeout waited until a callback was
queued. Terminating the queue refuses new callbacks and drained the
queued ones without waking anyone, so a dispatcher thread's loop
(`while (XTaskQueueDispatch(queue, port, INFINITE));`, which ends by
terminating the queue) stayed in its wait for good, and so did whoever
joined that thread. A dispatch begun after the termination did the same.

A dispatch now also ends, returning false, when its queue is
terminated: the termination wakes the port's waiters after draining it.
The flag is the queue's, so a dispatch on another queue that shares the
port waits on.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The SOPP table had s_ttracedata_imm at 0x26, as Mesa's opcode list
does; RDNA2 encodes it at 0x28 (AMD's RDNA2 ISA, LLVM's GFX10 tables
and disassembler tests). A shader with the thread-trace marker decoded
it as an unknown opcode and failed to translate, though the IR drops
the marker as harmless.
…value

f32_to_half rounds to nearest by adding half an ulp to the mantissa,
then or-ed the shifted mantissa into the exponent field. When the
rounding carried out of the mantissa, that carry is the exponent's low
bit: or-ed into an odd exponent it was lost, so values just below a
power of two came out at the power below (2 - 2^-12 gave 1.0, not 2.0).
Rectangle lists use it for the fourth corner of half-float elements.

The carry is now added into the exponent.
The device answers QueryInterface for ID3D12Device and for its newer
levels (Grand Theft Auto VI creates it as ID3D12Device11). A device
child's GetDevice and the DXGI device's QueryInterface knew only the
first: asked for the device by the interface the title holds, they
answered E_NOINTERFACE with a null pointer.

Both now ask the device's own test (is_device).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Reading and loading a title DLL report its path when they fail;
preparing it, in between, did not. A DLL the PE parser refuses ended
the run with just "malformed image: ..." (or the like), without saying
which of the title's DLLs it was.

The prepare step now adds "preparing <path>" like its neighbours.
Typed buffer loads in the 10_11_11, 11_11_10 and 10_10_10_2 families
(GFX10 unified formats 30-49) were refused, failing the shader. Fill in
their channel layouts and decode the unsigned 11- and 10-bit floats by
shifting them into half position for legacyF16ToF32, which is exact for
denormals, infinities and NaNs. Format numbers from LLVM's UfmtGFX10,
channel order from Mesa's ac_formats.c.

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

- Refresh the full remaining Shadow buffer extent for Root SRVs and Root UAVs instead of truncating at 1 MiB (keeping Root CBVs at the 64 KiB D3D12 limit).

- Guard shadow::find/loose against low (<0x10000) and uncommitted addresses, and bind permanently-alive 4 MiB zeroed/sink fallback GPU VAs instead of skipping Set*Root*View when a root view is unset, null, or unmapped.

- Support Root UAVs (u<slot>, space1 RWByteAddressBuffer) end-to-end across victory-shader (descriptor handle, global_store_dword*, s_load_dword* on root descriptors, PSV0/dx.resources metadata, SFI0/ShaderFlags UAVsAtEveryStage=1<<16), shader_cache (VSH2), pipeline::host (deduplicating shared (kind, slot) root views across stages), and draw (binding, gpu_writes write-back, and post-draw/dispatch UAV barriers).

- Add unit, dxil.dll validation, WARP, and host GPU tests covering >1 MiB Root SRV dirty-page refresh, null/unmapped fallback VAs, cross-stage root view deduplication, and Root UAV execution/write-back.
A descriptor picked without a branch, as the compiler does when it
hoists both loads (invariant memory) and turns the if/else into a
select, reaches the resource instruction through s_cselect_b64 per half
(or s_cselect_b32 / s_cmov per dword). None of its dwords is then a
load, so tracking stopped with "a descriptor neither loaded nor built"
and the whole program, and every draw using it, was dropped.

Such words are now split by the SCC value they all read: what each is
when SCC is set (S0) and when it is clear (S1, or the old destination
for s_cmov), with words not selected the same on both sides, and each
side traced on its own into a new Source::Select. Selections with
different conditions stop, and a choice that mixes two descriptors
still stops as "a descriptor changed after loading". The lowering picks
the heap index of the two loaded descriptors by SCC and creates one
heap handle, as a phi of loaded descriptors already does per edge.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AZ9pSB4ZoXYUifuXg8gm66
A descriptor held in VGPRs is used through a waterfall loop: each pass
reads the first active lane's dwords with v_readfirstlane_b32, compares
them with every lane's own (v_cmp_eq), runs the access with the lanes
that match and repeats for the rest. Tracing stopped at the readfirstlane
results ("a descriptor neither loaded nor built").

The tracer now follows the read lanes' dwords to where each lane gets its
own: global_load_dword* from a table or heap at a per-lane address (an
image descriptor's two x4 loads lined up), or a v_cndmask_b32 choice per
lane between such sources (e.g. two s_load descriptors). Other sources
fail naming them (LDS read, buffer load, phi, input, computed VGPRs).
The loop's compares of those reads with their own dwords are recorded.

Lowering gives the access each lane's heap index (its load address over
the descriptor size, or a per-lane select of indices) with
createHandleFromHeap's nonUniformIndex set, lowers the recorded
readfirstlanes as the lane's own dword and their compares as true, so
the loop runs once with all lanes. Wave32 and wave64 are tested.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AZ9pSB4ZoXYUifuXg8gm66
RtlVirtualUnwind and RtlCaptureContext want a 16-byte aligned CONTEXT,
and windows-sys 0.61 declares the x64 CONTEXT without align(16). In a
debug build the by-value copy in unwind_into, and the test's stack
context, landed 8 bytes off (an address ending in ...838), so
unwinds_like_the_system_walk crashed the whole victory-loader test binary
with a stack-overflow message and STATUS_ACCESS_VIOLATION. Aligning only
the test's context was not enough: the copy in unwind_into, which the
crash handler and stacks.rs also unwind with, faulted as well.

unwind_into now copies its context into an Aligned16 wrapper and unwinds
that; the test captures into one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
When HostHeap::dynamic ran out, State::tables skipped the fresh table and
the stage's user data fell back to the title's table offset. Constant
buffer tables are always made fresh and never mirrored, so the shader read
whatever host descriptor sat at those slots as a constant buffer; on AMD a
texture or null descriptor read as a buffer gives a wild base address and
the device is removed (Marvisak#59: faults at 0x7000037xxxxx, 0x8000037xxxxx,
0x33c4000, a different pipeline every run, about 60 s in).

bind now reports that a table could not be made, and the draw, mesh
dispatch, dispatch or indirect execution is dropped. The dynamic range grows
from 2^16 to 2^18 slots, which the world did not exhaust on an RX 9070 XT.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Marvisak and others added 28 commits November 24, 2026 09:17
HLE: return XAsync payloads for nonnegative results
…pth-position

Shaders: centroid position with conservative depth
…ta-dir

core: show data_dir in config and check its asset policy
Shaders: a phi that only another read phi consumes is live too (Marvisak#604)
Shaders: image_sample_o with constant offsets
…-inline-constants

Shaders: decode GFX10 packed inline constants by operand type
GPU diagnostics: describe a buffer UAV by its range, not as uav None
…-target-dir

Loader tests: build the probe fixture under CARGO_TARGET_TMPDIR
…u-texture-source

GPU: upload CPU-written textures before full and region copies
…rivate-links

Docs: rustdoc builds the loader, GPU and shader crates without warnings
…pload-128

GPU: use the host upload path for texture staging copies
…ull-unbind

GPU: unbind vertex buffer slots for null view arrays
…fg-windows

Shaders: gate the constant_color test helper to Windows
…o-link

Docs: drop the private intra-doc link to MICRO in texture.rs
Shaders: v_cmp_lg is ordered on AMD hosts too (olt | ogt, not fcmp one)
Three conflicts:
- descriptor.rs: main (Marvisak#365) publishes the host heap only after replaying
  pending writes; Marvisak#185 stores it as an Arc. Main's order, wrapped in Arc.
- draw.rs: main (Marvisak#336) makes bind() return false when a table cannot be
  made; Marvisak#185 makes it pub(crate) for its tests. Both.
- host.rs: main (Marvisak#87) and Marvisak#185 both fixed the copy statistics' frame
  denominator (copy_stats_frames vs diagnostic_frames). Main's kept,
  Marvisak#185's duplicate counter removed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
main's s_bitcmp test (3c86053) calls lowers() with one argument; Marvisak#185
gave it a second (rsrc2). Zero, as in the other tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Audio, watch: no overflow on huge title sizes (XMA read advance, fread)
BCPack: find a slot's bucket from a window table
watch.rs: main (Marvisak#88, ec0d155) saturates the end of announced writes and
remaps; Marvisak#185 had restructured title_memory_remapped around a checked
end that returned on overflow. Marvisak#185's structure with main's saturating
end, so a remap past the top of the address space still covers up to
it. Both sides' new tests kept.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A Windows job on the pinned toolchain: clippy with -D warnings on the
default and the --all-features (diagnostics) build, then cargo test
--workspace, which includes the asset-policy test.

main did not build its tests: scalar_bit_tests_lower called lowers()
without the rsrc2 argument a parallel change added (0, no input
registers). Also drops a double parenthesis clippy flagged in an xasync
test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
main now has CI (clippy with -D warnings, then the workspace's tests) and
three new tests that call `resource::track`, which this branch gives a
fourth argument. No textual conflict, but the test target did not build:
those three calls (emit/lower.rs, twice in emit/mod.rs) now structure the
program first and pass it, as this branch's other callers do. Both of
CI's clippy commands are clean on the result.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…e VALU tests

The four tests of emit/waterfall_tests.rs each dispatch on the hardware
adapter and on WARP. Run in parallel, the test process sometimes died of
an access violation (7 of 24 runs of these four tests on an integration
branch; an image test beside a VALU test does the same on WARP). They now
take the VALU tests' lock, which moves out of `run_cases` to be shared.
With it: 340 workspace tests pass with VICTORY_WARP=1, as on a CI runner,
and the shader tests pass on the RTX 5070.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Shaders: per-lane descriptors chosen by control flow (stacked on Marvisak#307)
The console compiler loops over a per-lane descriptor by reading the
first active lane's table offset (v_readfirstlane_b32), narrowing EXEC
to the lanes with the same one (v_cmpx_eq_u32), loading that entry
(s_load_dwordx8) and dropping those lanes (s_andn2_wrexec). Such a load
now goes through the waterfall proof; when it holds, each lane loads its
own entry through a non-uniform handle. Unproven, the offset stays the
first lane's, as before.

Translation census over the title's 26,096 programs: none lost, 108 get
past these loops to a later refusal. The 249 programs behind Marvisak#736 also
need per-lane size queries in loops without an access.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts:
#	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/lower.rs
#	crates/victory-shader/src/emit/mod.rs
#	crates/victory-shader/src/emit/shader.rs
#	crates/victory-shader/src/emit/valu_tests.rs
Two conflicts:
- lower.rs: main adds test-only fields (nonuniform_handles, wave_ops)
  next to Marvisak#185's heap_buffer_srvs. Both kept.
- shader.rs heap_handle(): main passes a nonuniform flag through;
  Marvisak#185 records heap buffer SRV indices there. Both: Marvisak#185's recording,
  then main's nonuniform handling.

Main's new nonuniform parameter is passed as false in Marvisak#185's
heap_buffer_srv tests, as those handles were uniform before, and
main's new waterfall test gets Marvisak#185's heap_buffer_srvs field.

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

lower.rs: Marvisak#294's root_uavs next to main's test-only fields, both kept.
Two Marvisak#294 tests and the new waterfall test updated for main's
resource::track(..., Some(&structured)) and Marvisak#294's root_uavs field.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@desplmfao
desplmfao marked this pull request as draft November 24, 2026 12:21
@desplmfao desplmfao closed this Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.