Skip to content

[LAB-06] Validate only active ExecuteIndirect records - #11

Draft
arthurprudenteres wants to merge 41 commits into
mainfrom
lab-06-effective-indirect-count
Draft

arthurprudenteres wants to merge 41 commits into
mainfrom
lab-06-effective-indirect-count

Conversation

@arthurprudenteres

Copy link
Copy Markdown
Collaborator

Refs #6.

Problem and change

The argument clamp used MaxCommandCount for validation even when ExecuteIndirect consumed fewer records. In the WARP repro, a count of 1 with a maximum of 2 changed the inactive second record from [1025, 1024, 1] to [0, 1024, 1] under both barrier paths (exit 101).

Candidate ad25178 makes the GPU clamp use the effective count for argument access and work-budget accounting. If the counter overlaps a field the clamp can write, both the clamp and native execution use the same snapshot, and the original counter is restored after consumption. The change is in crates/victory-gpu/src/indirect.rs and crates/victory-gpu/src/draw.rs.

Validation

Windows x64 build 26300.9974, Rust/Cargo 1.98.1, WARP (Microsoft Basic Render Driver), and RTX 5060 Ti driver 621.24. The runs exercised zero, one, an above-maximum count, no counter, separate and shared buffers, and overlapping counter reuse across submissions.

  • Enhanced barriers passed 17/17 focused tests on each adapter. The forced legacy path exercised 16 tests on each adapter, with the enhanced-only copy fixture skipped. WARP with VICTORY_GPU_TIMING=1 also passed 17/17. Each run exited 0.
  • The local integration checkout reported 283 successful workspace test results, zero failures, and four ignored tests. Five conditional shader checks returned early because compiler tooling was unavailable. cargo check and the asset policy check exited 0.
cargo test --locked --offline -p victory-gpu --features diagnostics indirect -- --nocapture --test-threads=1
cargo test --locked --offline --workspace --features victory/diagnostics -- --nocapture --test-threads=1
cargo check --locked --offline --workspace
cargo xtask policy

Set VICTORY_D3D12_WARP=1 and VICTORY_WARP=1 for WARP. Set VICTORY_TEST_LEGACY_INDIRECT=1 in a separate test process to force legacy barriers. The D3D12 debug layer was unavailable. Windows 10, Linux/Proton, gameplay, rendering, and the title watchdog remain unverified.

Upstream dependency

This draft is blocked on Marvisak/VIctory#40, tested at a2ab63d. The comparison against the fork's main currently includes upstream integration history. The reviewable LAB-06 change is candidate ad25178 alone. After Marvisak#40 is integrated, reapply that commit to the updated base and rerun validation before marking the draft ready.

raffclar and others added 30 commits November 23, 2026 23:08
The exit code ended the other threads first and then started the
watchdog. A thread that ends can hold the heap lock or the loader lock.
A new thread needs both, so the watchdog did not start and the exit did
not stop.

Now the exit code starts the watchdog and waits until it runs its own
code: only then are its loader notices and Rust's thread set-up done.
The watchdog publishes its thread id, and end_other_threads does not
end it. The wait has the same deadline as the detach, because this
thread, or a thread that waits for it, can hold the loader lock; then
the watchdog cannot start.

After the deadline the watchdog only ends the process. It does not
log, because logging needs the heap and the lock of the log writer.

The exit test now also checks that a thread in `keep` is not ended.
Layout::new checked that width, height and depth are non-zero but not that
they are bounded, so values a title passes unchecked (up to u32::MAX)
overflowed the size arithmetic: `offset * depth` in the linear layout,
`slice_size * slices` and the per-mip sizes in the tiled one, and a u32
next_multiple_of in Layout::tiled. Debug builds panicked; release builds
wrapped silently and returned a wrong size.

Refuse anything past 16384 texels per side, the most a GFX10 image
descriptor holds, so no texture the GPU can use is affected.

Found with a random-input harness (four distinct overflow sites, none left
after this change).
The title's shader-visible view heap has 1,245,184 slots. NVIDIA caps
shader-visible view heaps at 1,000,000, so HostHeap::new falls back to a
heap of 1,000,000 whose title part ends at 934,464, with the dynamic
slots after it. The title binds a per-frame table ring in its top slots
(934,464 to 1,245,184, moving 4,096 slots a frame), so those tables'
host offsets either aliased the dynamic slots or ran past the heap's
end. On NVIDIA the GPU then hangs within the first-boot screens
(DXGI_ERROR_DEVICE_HUNG), after black and glitched frames.

A table that reaches past the host heap's title slots is now made
afresh in dynamic slots, as tables holding constant buffers already
are, and the shader is given the new offset. Hosts that take the whole
heap (AMD) are unchanged. mirror() logs the highest title slot it
meets past the host heap, once per new maximum.

Tested on an RTX 3080 (driver 32.0.16.2114): the first-boot screens and
menus run without glitches, and the title loads into the intro with no
device loss (before: device removed about 45-60 s in, 3 of 3 runs). The
slot warning went from 78 lines to none. cargo test --workspace passes.

Refs #16, #11

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A section whose PointerToRawData lies near 4 GiB made
file_offset + delta overflow: a panic in debug builds, a wrong offset in
release ones. The section now yields no offset.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
texture: refuse extents past 16384 texels instead of overflowing
The test for the emulation runs the real instructions. AMD CPUs, and
most CI runners, execute them natively, so the emulation was tested
only on Intel CPUs.

The new tests give the emulation instruction bytes and saved registers
directly, so they work on any CPU. They cover clzero, monitorx/mwaitx,
the immediate and register forms of extrq/insertq, xmm8 to xmm15,
length 0, and the instructions and exceptions it must not emulate.

The old test stays: on an Intel CPU it is the only test of the full
path through the vectored handler.
Process exit: start the watchdog before other threads end
GPU: make tables past a capped host view heap afresh (NVIDIA menu hang)
…wing the stack

In a wave64 compute program, writing only EXEC's high dword (for
example s_mov_b32 exec_hi, 0) and then running any vector instruction
crashed the whole process with a stack overflow. The new mask is opaque
and keyed by the unchanged low dword, so lowering the instruction's guard
asked for that dword's value, the value is a lane mask read as data, its
ballot needs the mask's lane bit, and that bit needs the value again:
mask_dword -> boolean -> atom -> get -> mask_dword, without end.

mask_dword now notes the masks whose ballot it is building, and a mask
reached again on the way fails with a reason. The instruction then fails
like any other that cannot be expressed: its result is missing, and only
a side effect that uses it stops the translation. A shader the translator
cannot handle must not take the title down at pipeline creation.

Found with a random-input harness over the whole translation (ir,
resource, io, structure, emit) of random decodable compute programs. The
new test overflows the stack without the fix. One million further
programs (about 160,000 fully translated) gave no panic, hang or
overflow.
Removes the print-only dbg_tls test in image.rs (TLS presence is already asserted in parses_own_test_binary) and switches layout.rs offset helpers (read_u32, read_u64, optional_header_offset, file_header_offset, data_directory_offset) to checked arithmetic so extreme offsets return None instead of overflowing.
Windows 10 maps the prepared image with both entries empty. The binder already retains the original slot RVAs, so preparation need not locate a linker-provided terminator.
find_input matched each input element with
`(row and channel in the element).then_some((id, channel - e.col))`.
then_some evaluates its argument first, so the subtraction ran for every
element, also those whose first channel is past the one asked for. In a
build with overflow checks (tests, debug runs) a pixel shader reading a
channel below any element that starts at z or w panicked, whichever row
that element was in, and packed inputs such as a float2 in .zw are
common. Release builds wrapped and threw the value away.

then() computes it only when the element holds the channel.

Found with a random-input harness over pixel, vertex and mesh programs
with matching signatures. The new test panics without the fix.
Add lowering for v_xnor_b32 and v_swap_b32 (seen in GTA VI world compute shaders), and record v.dst as a read in ir.rs for v_swap_b32 / v_swaprel_b32 since both operands are read before being swapped.
With indirect execution the world's first frame asked for over 1,200
pipelines at once and took more than 30 s, so the title's own GPU
watchdog ended the run. Host pipelines are now made by worker threads: a
first use waits at most 0.5 s per title frame, and that pipeline's draws
are dropped until it is ready. The world presents frames again, and
indirect execution is the default (the switch is gone).

Pipelines are cached across runs:
- every host pipeline goes into a pipeline library saved under the cache
  folder (named by a hash of the translated code, our root signature and
  the state; a blob the device rejects starts an empty library);
- the pipelines drawn with are remembered and started during loading on
  the next run.
One cold and one warm run: the last pipeline was ready 38 s after the
world's first frame cold, 1.4 s warm; the first world frame took 3.2 s
cold, 0.37 s warm.

Also:
- Copy-backs of shader-written ranges return only the bytes the GPU
  changed; they used to overwrite what the title's CPU wrote meanwhile,
  which crashed the title.
- Indirect dispatch records are bounded (group counts were not), and the
  console's single-dispatch argument type runs as a dispatch.
- Per-shader counts of dropped draws in the diagnostics log; a switch
  that submits and times each list alone.

Not working yet: the world shows no geometry, and runs end on a GPU page
fault after at most about 55 s.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Use the descriptor count already validated by the PE parser, so the directory size need not include the null terminator. Check the OS-assigned static TLS index on a mapped test DLL.
Both returned no carry, so SCC was missing and a branch or select on a 64-bit scalar add or subtract failed to translate. They now share the carry logic of v_add_co_ci_u32 and v_sub_co_ci_u32.
loader: emulate clwb on Intel CPUs before Ice Lake, a write-back loop in one exception
…tory

Loader: preserve an empty import table for Windows 10 static TLS
aycow and others added 11 commits November 23, 2026 19:32
Loader: test the AMD-only instruction emulation on any CPU (including AMD!)
…rflow

PE: checked offsets in rva_to_file_offset and layout, remove dbg_tls
PE: skip unused export slots instead of reporting them at RVA 0
Guard texture and XMA offsets against overflow
shader: a lane mask that needs its own value fails instead of overflo…
…erflow

shader: look up an input channel without underflowing
Shaders: lower v_xnor_b32 and v_swap_b32
Shaders: set SCC from the carry of s_addc_u32 and s_subb_u32
Read the same GPU-produced counter as the native indirect call. Keep aliased counters intact across clamping and resubmission, using the existing list budget buffer and both barrier paths.
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.