Skip to content

Port Marvisak/VIctory#704 + #193 (unknown-stride buffers) onto #185 + main (stacked on #4) - #6

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

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

Conversation

@desplmfao

Copy link
Copy Markdown

This PR is mainly for testing: it checks whether Marvisak#704 (stacked on Marvisak#193) can work on top of Marvisak#185 and current main, and what it takes to make them fit. Feel free to merge it if you want it, but it adds about 1,900 lines and touches the same shader and descriptor code as Marvisak#185, 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#704 and Marvisak#193 to be updated by their authors, is just as fine.

Port of Marvisak#704 by @r4tedx ("unknown-stride buffers are read through a raw view of the same bytes") and Marvisak#193 by @n-romanovich ("add runtime stride table for structured buffers") onto Marvisak#185 as merged with current main in #4. Stacked on #4. Their seven commits are merged unchanged, with their original authors. The only commit of mine is the merge that resolves the conflicts.

Why

On NVIDIA under Proton, VICTORY_PRODUCERS=1 (from Marvisak#638) shows which dropped dispatches produce data that running draws read. On this stack, 7 of the 10 most-read dropped producers fail with a structured buffer of unknown stride is not supported, each feeding 500+ running draws or dispatches. Examples are compute 17af15c4015cb4b6, fdd56d97a806bcca, 9209777e8face9dd, 1c4b3c0547e3e6fa and 55679a0547649d0b. That is a likely source of the black world and of reads of garbage.

Conflicts

The merge had 19 hunks in 7 files:

where resolution
struct fields (emit/{host,mod,shader,lower}.rs, valu_tests.rs) Marvisak#185's heap_buffer_srvs and Marvisak#704's stride_table, both kept
shader_cache.rs both encoded and decoded, heap buffer SRVs first, then the stride-table flag; the cache is keyed by the build fingerprint
lower.rs descriptor indices main's lane_heap_index / fetched_index (per-lane descriptors, waterfall loops) and Marvisak#704's heap_slot / stride_entry are both kept, since main handles Source::LanePhi etc. and Marvisak#704's heap_slot handles Source::Phi. The raw handle passes main's new nonuniform flag as false, because its slot comes from a uniform descriptor
descriptor/host.rs imports united; Marvisak#185's Slots struct keeps made
hidden Marvisak#704's tests use main's resource::track(..., Some(&structured)) and the other side's new fields; SrvRange gets a clone of the shadow, since Marvisak#704's code uses it afterwards

Tests

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

  • cargo check --workspace --all-targets, with and without victory-gpu/diagnostics: clean.
  • victory-gpu with diagnostics, --test-threads 1: 94 passed, 2 failed (argument_clamp_builds, a_rejected_blob_gives_an_empty_library). Both fail on Merge current main into #185 (3 conflicts resolved) #4 alone too: the indirect clamp and pipeline library don't build under Wine here.
  • victory-shader (--skip valu_tests --skip wave_tests): 114 passed, 1 failed (stub_pipeline_is_created, because vkd3d-proton accepts a zeroed DXIL digest; it fails on Merge current main into #185 (3 conflicts resolved) #4 alone too).
  • Stride, raw view, heap buffer and waterfall tests: 30 passed in victory-shader and 3 in victory-gpu.
  • No game run with this branch yet.

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>
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 27 commits November 24, 2026 09:18
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>
…clamps, and non-multiple-of-4 stride refusal
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>
main now has CI (clippy with -D warnings, then the workspace's tests). No
conflict; both of CI's clippy commands are clean on the result.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…ew-kinds

Marvisak#193 moved: buffer views are clamped to what is left of the host copy, a
shader that reads the stride table without a host view heap is not run,
and a known stride that is no multiple of four is refused. Conflicts were
with main, not with this branch's change: `bind` already returns whether
the draw may run (Marvisak#336), with its doc comment and the dropped counter, and
main already renamed the second test module in host.rs. main's side kept
in all three; Marvisak#193's `return false` in the stride-table branch is in.

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>
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>
Conflicts:
- struct fields and cache format: Marvisak#185's heap_buffer_srvs and the
  stride_table flag, both kept (encoded and decoded heap first, then the
  flag).
- lower.rs: main's lane_heap_index/fetched_index (per-lane descriptors)
  and Marvisak#704's heap_slot/stride_entry, both kept; the raw handle passes
  main's new nonuniform flag as false (its slot is uniform).
- descriptor/host.rs: imports united; Marvisak#185's Slots struct keeps .

Hidden: Marvisak#704's tests and SrvRange use main's resource::track(...,
Some(&structured)) and the other side's new fields; the shadow is
cloned into the SrvRange since Marvisak#704's code uses it afterwards.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.