Commit Graph
57 Commits
Author SHA1 Message Date
Marvis 45863ced7b Merge pull request #57 from Yaekai/fix/null-buffer-views
GPU: emit null buffer SRV/UAV when descriptor names a buffer with null resource
2026-11-24 01:39:35 +01:00
Marvis 64c51313af Merge pull request #37 from alessiodeia/fix/valu-med3-fract-trig
shader: keep fract(NaN) as NaN on NVIDIA and add synthetic GPU VALU tests
2026-11-24 01:38:41 +01:00
Marvis bfd36dc4af Merge pull request #80 from tedin7/vic-far-jump-backward
shader: decode backward far jumps (signed offset literal)
2026-11-24 01:37:00 +01:00
Marvis 2ff52dae91 Merge pull request #81 from tedin7/vic-scalar-carry
Shaders: set SCC from the carry of s_addc_u32 and s_subb_u32
2026-11-24 01:36:05 +01:00
Marvis 32704bb307 Merge pull request #58 from Yaekai/feat/shader-xnor-swap
Shaders: lower v_xnor_b32 and v_swap_b32
2026-11-24 01:35:31 +01:00
Marvis 0d7b42a3a9 Merge pull request #56 from 9hvn9yt2vk-netizen/find-input-underflow
shader: look up an input channel without underflowing
2026-11-24 01:34:59 +01:00
Marvis acd540dc18 Merge pull request #43 from 9hvn9yt2vk-netizen/shader-mask-cycle
shader: a lane mask that needs its own value fails instead of overflo…
2026-11-24 01:34:43 +01:00
Marvis b70bb6871a Merge pull request #50 from Vanthys/fix/format-offset-overflow
Guard texture and XMA offsets against overflow
2026-11-24 01:34:04 +01:00
Marvis a1f014d94b Merge pull request #75 from tedin7/vic-pe-export-holes
PE: skip unused export slots instead of reporting them at RVA 0
2026-11-24 01:33:39 +01:00
Marvis f5626996c3 Merge pull request #30 from AndyLatimer/fix/pe-rva-offset-overflow
PE: checked offsets in rva_to_file_offset and layout, remove dbg_tls
2026-11-24 01:33:20 +01:00
Marvis 5f540cd231 Merge pull request #38 from raffclar/emulation-tests
Loader: test the AMD-only instruction emulation on any CPU (including AMD!)
2026-11-24 01:32:45 +01:00
Marvis 056cc6b3f2 Merge pull request #28 from ifBars/fix/windows10-import-directory
Loader: preserve an empty import table for Windows 10 static TLS
2026-11-24 01:31:11 +01:00
Marvis 2179ee8d1f Merge pull request #45 from HenriqueSBueno/clwb
loader: emulate clwb on Intel CPUs before Ice Lake, a write-back loop in one exception
2026-11-24 01:30:02 +01:00
ifBars 247cd6baa2 Merge branch 'main' into fix/windows10-import-directory 2026-11-23 16:23:29 -08:00
tedin7 d46789485c Shaders: set SCC from the carry of s_addc_u32 and s_subb_u32
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.
2026-11-24 01:17:24 +01:00
tedin7 ee6041788f fix: read a far jump's offset as signed so backward far jumps decode 2026-11-24 01:17:00 +01:00
tedin7 85d03354fb fix: skip unused export address slots instead of reporting them at RVA 0 2026-11-24 01:15:10 +01:00
Henrique Bueno 0369ebe42a loader: a clwb write-back loop runs in one exception 2026-11-23 21:14:15 -03:00
ifBars 178bbb7915 Keep an empty import descriptor so Windows assigns static TLS
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.
2026-11-23 16:07:09 -08:00
MarvisandClaude Fable 5.2 62b737a69b GPU: pipelines off the render thread and cached; indirect execution on
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 <[email protected]>
2026-11-24 01:02:11 +01:00
Yaekai e3e6dafd97 Shaders: lower v_xnor_b32 and v_swap_b32
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.
2026-11-24 00:59:52 +01:00
Yaekai 720c23161f GPU: emit null buffer SRV/UAV when descriptor names a buffer with null resource
When a title creates a null buffer view (resource == 0, ViewDimension == BUFFER), buffer_bytes(0) returns None, so null_for() fell through to null_like() / null_view() (or a 2D texture UAV) and emitted a 2D texture descriptor into a slot where a shader expects a buffer.

Check desc[1] == 1 (D3D12_SRV_DIMENSION_BUFFER / D3D12_UAV_DIMENSION_BUFFER) in null_for() for both View::Shader and View::Unordered so null buffer views get a matching null buffer descriptor.
2026-11-24 00:59:49 +01:00
9hvn9yt2vk-netizen 0f198bf66b shader: look up an input channel without underflowing
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.
2026-11-24 00:57:59 +01:00
ifBars 47f321ed15 Clear the IAT directory alongside the import directory
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.
2026-11-23 15:55:36 -08:00
alessiodeiaandBlueKaiman a95f6aec42 shader: keep fract(NaN) as NaN on NVIDIA and add synthetic GPU VALU tests
Fixes a real-hardware NVIDIA bug in fract() from 36eb0b4 and adds synthetic GFX10 -> DXIL -> GPU/WARP regression tests for the RDNA2 VALU lowerings from #2:

- fract(): select(OGT(r, k), k, r) is folded by NVIDIA's DXIL compiler into FMNMX (minNum), which swallows NaN and turns v_fract_f32(NaN) into 0x3f7fffff (and v_fract_f16(NaN) into 0x3bff). Comparing with pred::OGE against a distinct threshold (1.0 for f32, 1 - 2^-12 for f16) prevents the minNum fold and preserves NaN and +/-inf -> NaN on both NVIDIA hardware and WARP.
- valu_tests.rs: builds minimal synthetic GFX10 compute shaders, lowers them through the full pipeline (ir::build -> resource::track -> io::raise -> structure -> lower), validates with dxil.dll when present, and executes them via Host::dispatch on both hardware GPU and WARP without requiring console dxc. Covers v_fract_f32/f16, v_med3_f32/f16, v_sin/v_cos_f32/f16, and v_bfe_i32/u32 + s_bfe_i32.

Co-authored-by: BlueKaiman <[email protected]>
2026-11-24 00:51:42 +01:00
Manuel Pérez 058fab325d PE: remove leftover dbg_tls test and check layout offsets
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.
2026-11-24 00:48:47 +01:00
Vanthys 536c5d4371 Reject empty XMA test fixture directories 2026-11-24 00:46:54 +01:00
Vanthys 7078f1e744 Guard texture and XMA offsets against overflow 2026-11-24 00:46:54 +01:00
Henrique Bueno 8b8ca7e746 loader: emulate clwb on Intel CPUs before Ice Lake 2026-11-23 20:43:13 -03:00
9hvn9yt2vk-netizen a0f45928d6 shader: a lane mask that needs its own value fails instead of overflowing 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.
2026-11-24 00:42:03 +01:00
raffclar d1aa2093b8 Loader: test 64-bit extrq at index 0, not in AMD's undefined range 2026-11-23 23:34:49 +00:00
Marvis b9aff99b98 Merge pull request #21 from Nostyxx/fix/nvidia-view-heap-cap
GPU: make tables past a capped host view heap afresh (NVIDIA menu hang)
2026-11-24 00:34:23 +01:00
Marvis 6d7df474b3 Merge pull request #19 from raffclar/exit-watchdog
Process exit: start the watchdog before other threads end
2026-11-24 00:31:26 +01:00
raffclar 27b5152288 Loader: test the AMD-only instruction emulation on any CPU
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.
2026-11-23 23:30:15 +00:00
Marvis c07f19d559 Merge pull request #15 from 9hvn9yt2vk-netizen/fix-texture-extents
texture: refuse extents past 16384 texels instead of overflowing
2026-11-24 00:28:40 +01:00
ifBars 96a964e16c Keep an empty import descriptor for the Windows 10 loader 2026-11-23 15:20:22 -08:00
Manuel PérezandClaude Opus 5.5 8661578c1b PE: checked file offset in rva_to_file_offset
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 <[email protected]>
2026-11-24 00:19:38 +01:00
Marvis b8000d18dc Merge pull request #14 from 9hvn9yt2vk-netizen/fix-xma-zero-length
xma: stop at a zero-length frame instead of looping forever
2026-11-24 00:18:09 +01:00
NostyxxandClaude Opus 5.5 f3ae2edbd4 GPU: make tables past a capped host view heap afresh
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 <[email protected]>
2026-11-24 06:16:01 +07:00
MarvisandClaude Fable 5.2 d50f2368cb GPU: the world stays up; indirect execution behind a switch
The host device was removed seconds into the world because a shader read
a descriptor of the wrong kind: empty slots held a null 2D texture view
where the shader expected a buffer, which gave a garbage heap index and
a read far past the view heap. Null descriptors now have the kind the
shader expects (raw buffer, constant buffer, or a texture of the title's
own dimension). The world then ran to a 240 s time limit with no removal.

Also:
- Host lists hold the textures, pipelines, root signatures and heaps they
  name, and heap slots hold the resource they view (the title releases
  objects before submitting lists that use them).
- The device-removed report places the fault against the host descriptor
  heaps and names our own uploads; VICTORY_D3D12_GBV turns on GPU-based
  validation, VICTORY_DUMP_TARGETS works.
- Indirect execution (draw, indexed draw, dispatch, mesh dispatch): the
  world draws most of its geometry this way. Arguments are clamped and
  charged to a per-list budget by a small compute pass first, so garbage
  cannot hang the GPU. Off by default (VICTORY_INDIRECT=1): with it on
  the title's own GPU watchdog ends the run about 30 s into the world.
- Shader-written ranges are copied back once per submission and only
  where they differ; refreshes beside them copy only stale pages. The
  frame-rate line counts copy-backs and dropped draws.

Not working yet: the world's picture is black (indirect draws off, and
hundreds of draws per frame have no translated shader).

Co-Authored-By: Claude Fable 5.2 <[email protected]>
2026-11-24 00:13:19 +01:00
MarvisandClaude Fable 5.2 1922261412 Shaders: sine and cosine in turns, exact zeros at half and quarter turns
v_sin and v_cos (f32 and f16) take an angle in turns. The whole turns
now come off first (x - round_even(x), exact), so a large angle keeps
its fraction of a turn instead of losing it when scaled to radians.
The sine of a half turn and the cosine of a quarter turn are exactly +0,
as the hardware gives; the host's functions of the rounded angle give
about 1e-7. A zero operand passes unreduced, so sin(-0) stays -0.

float_semantics_are_the_consoles asserts the exact zeros (it failed
before this change). The compiler the tests use takes whole turns off
itself, so the large-angle path cannot be reached from HLSL and rests
on the measurements cited in issue #2.

Left from the issue: denormal operands of the legacy multiply, which
needs the float mode register as state first.

Refs #2

Co-Authored-By: Claude Fable 5.2 <[email protected]>
2026-11-24 00:13:19 +01:00
MarvisandClaude Fable 5.2 5d52765de7 Shaders: med3 with NaN, fract below 1.0, signed bit fields past bit 31
Three lowerings gave results the console's GPU does not (issue #2, from
hardware measurements published by another project):

- v_med3_f32/f16: with a NaN operand the hardware gives the minimum of
  the three; we gave the median of the other two.
- v_fract_f32/f16: the hardware never reaches 1.0 (a tiny negative
  input gives the largest value below it); the host's own fract differs
  by vendor and can give 1.0.
- v_bfe_i32/s_bfe_i32: a signed field running past bit 31 extends from
  bit 31; the shift is arithmetic now. Fields that fit are unchanged.

The fract case is asserted in float_semantics_are_the_consoles (the
console compiler emits v_fract_f32 for frac). The other two cannot be
produced from HLSL with the compiler the tests use and rest on the
measured values in the issue.

Still open from the issue: range reduction before sine and cosine, and
denormal operands of the legacy multiply.

Refs #2

Co-Authored-By: Claude Fable 5.2 <[email protected]>
2026-11-24 00:13:19 +01:00
9hvn9yt2vk-netizen 2ad0a1ef74 texture: refuse extents past 16384 texels instead of overflowing
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).
2026-11-24 00:08:59 +01:00
Marvis abb8d9fe14 Merge pull request #10 from ismailchaka1/emulate-amd-only-instructions
loader: emulate AMD-only instructions on Intel CPUs
2026-11-24 00:08:20 +01:00
raffclar 1d1f82651a Process exit: start the watchdog before other threads end
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.
2026-11-23 23:08:01 +00:00
9hvn9yt2vk-netizen 72fbbc3f87 xma: stop at a zero-length frame instead of looping forever
next_frame walks the frames before `start` to learn whether the frame at
`start` is the packet's last. A damaged packet whose earlier frame has a
length of 0 never advanced `at`, so the walk spun forever (in a debug build
it overflowed `number` after about 4 billion rounds and panicked).

Apply the rule read_frame already uses: a length that does not cover its
own 15-bit field is not a frame, and the search ends.

Found with a random-input harness. The new test hangs without the fix and
passes at once with it.
2026-11-24 00:08:01 +01:00
ismailchaka1andClaude Opus 5.5 934e67fbad loader: emulate AMD-only instructions on Intel CPUs
The title is built for Zen 2 and uses clzero, monitorx/mwaitx and SSE4a's
extrq/insertq, which Intel CPUs lack: it died at startup with an illegal
instruction on an i7-14700KF. The vectored handler now does their job and
resumes: clzero zeroes the 64-byte line at rax, monitorx is skipped, mwaitx
yields, extrq/insertq run on the saved XMM registers.

Tested: victory-loader crash tests (new one runs each instruction), and the
title now gets past startup on an i7-14700KF with an RTX 4070 SUPER.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-23 22:49:54 +00:00
Marvis 4776fb84d0 Merge pull request #4 from Exorion1er/fix/tls-callbacks-reloc
Loader: keep the cleared TLS callback pointer out of base relocations
2026-11-23 23:45:26 +01:00
ExorionandClaude Opus 5.5 c21208c18a Loader: keep the cleared TLS callback pointer out of base relocations
prepare() zeroes the title's TLS AddressOfCallBacks but left the
IMAGE_REL_BASED_DIR64 entry that patches it. When the loader maps the
prepared copy away from its preferred base, that entry turns the 0 into
the rebase delta and the loader reads TLS callbacks from there. On
Windows the copy lands at 0x140000000 so the delta is 0; under Wine,
which maps DYNAMIC_BASE images high, LoadLibraryExW faults in ntdll
before any title code runs.

The entry is now rewritten as IMAGE_REL_BASED_ABSOLUTE (a no-op), and
the prepare test checks that no relocation targets the cleared field.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-23 23:37:05 +01:00
MarvisandClaude Fable 5.2 015d45bfff README: status, subsystem table, how to run, debugging switches
Says how far the title gets (menus at 30 fps, the world reached but not
rendering), what each subsystem does and still needs, and warns that the
world can reset the display driver on a real GPU. Adds how to run the
title, the translate command, and tables for the keyboard pad and the
debugging switches.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
2026-11-23 23:15:07 +01:00