Skip to content

Shaders, GPU: read through addresses passed in two root constants and lower scalar loads (#710, #748) - #4

Open
LAKSHYA-cmd-tech wants to merge 34 commits into
mainfrom
feature/root-constant-addresses
Open

LAKSHYA-cmd-tech wants to merge 34 commits into
mainfrom
feature/root-constant-addresses

Conversation

@LAKSHYA-cmd-tech

Copy link
Copy Markdown
Owner

Integrates Marvisak#302 (spill-table arguments), Marvisak#489 (entry-state arguments), Marvisak#710 (root-constant address pairs as root SRVs), and scalar smem load lowering for s_load_dword* through root constants (Marvisak#748). Resolves 992+ retail shader translation failures.

LAKSHYA-cmd-tech and others added 30 commits November 24, 2026 13:58
…grate/gta6-world-and-shader-fixes

# Conflicts:
#	crates/victory-gpu/src/descriptor/host.rs
GetProcAddress on one of our pseudo modules returned NULL for a name it
does not export, or for any ordinal, without setting the last error. The
host sets ERROR_PROC_NOT_FOUND (127), and a caller that builds its
failure from GetLastError() got 0, HRESULT_FROM_WIN32(0) being S_OK.

Test: a missing name on kernel32 (the host's, for comparison), and a
missing name and an ordinal on xgameruntime.dll, each after clearing
the last error.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
RegOpenKeyW and RegOpenKeyExW returned ERROR_FILE_NOT_FOUND for any
path below our stand-in for HKLM\...\CurrentVersion\OEM, including a
null or empty one. The documented behaviour, and the host's: RegOpenKeyW
gives back the key it was passed, RegOpenKeyExW a handle to the same
key. Other paths below it still are not found (it has no subkeys).

Test: both functions with a null and an empty subkey, on our key and on
a host key for comparison.

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

v_med3_f32 and v_med3_f16 return the least operand when one is NaN, which
`med3` chose with `fcmp uno`. NVIDIA's driver assumes no NaNs in that
compare and folds it to false, so the NaN case gave the plain median:
v_med3_f32_matches_rdna2_with_nan failed on an RTX 3050 Ti
(`v_med3_f32(1.0, 2.0, NaN) = 2`, want 1). An integer test of the bits
(|x| > +inf) cannot be folded that way.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
map_dll lowercased the DLL's name and joined that to the title folder.
On a case-sensitive folder (WSL creates them so, and new subfolders
inherit the flag) GameLib.dll is not gamelib.dll: is_file() was false
and the DLL was skipped without an error, so its imports went to stubs
and a title's own LoadLibrary saw "not a title image".

The lowercased name stays the key (seen, wanted, the returned list).
The file is the name as written or, failing that, the folder's entry
that matches it ignoring ASCII case, as the Windows loader ignores case.

Test: a case-sensitive temp folder (fsutil setCaseSensitiveInfo, no
admin) holding Late.dll, loaded as Late.dll, LATE.DLL and late.dll.
Skipped where Windows cannot make such a folder.

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

Stacked on Marvisak#336.

A list keeps the dynamic slots its draws took until the title resets it.
Every submission is waited for, so once a list has run the GPU no longer
reads them, but a capped view heap (NVIDIA: 1,000,000 slots, 65,536 of them
dynamic) is full within seconds of the world and every later table is
refused: the draw or dispatch is dropped (Marvisak#336 drops it instead of reading
the title's slots).

When `HostHeap::dynamic` has no room, `State::take_dynamic` now takes back
the slots of the oldest list that already ran (`descriptor::lease`), one
list at a time, and retries. That list is marked lost; submitting it again
without a reset is refused (its draws are dropped, as a table that could not
be made already drops one) and it works again once the title resets it. A
list is not taken back while it runs: `start` and `reclaim` share one lock.
Nothing changes while the heap has room.

Co-authored-by: OpenBot <335604065+openbotgit[bot]@users.noreply.github.com>
…p devices in XUserFindForDevice

- `xmem`: track title-owned allocations (`XMemAllocDefault`, committed pages
  inside `XMemVirtualAlloc` reservations, and `XMemAllocatePhysicalPages`)
  split across total and GPU-optimal budgets in `XMemGetWorkingSetStatistics`
  instead of reporting host `PagefileUsage` (which includes host GPU mirrors
  and shader compiler memory).
- `xasync`: serve delayed `XTaskQueue` callbacks from one lazily started shared
  timer thread backed by a min-heap + condvar instead of spawning a new OS
  thread per delayed submission, and cap `POOL` worker growth to a bounded
  limit (`(available_parallelism * 2).clamp(8, 64)`).
- `xuser`: return the single signed-in offline local user from
  `XUserFindForDevice` (`find_for_device`) for valid non-zero
  `APP_LOCAL_DEVICE_ID` values, `USER_NOT_FOUND` for all-zero IDs, and
  `E_INVALIDARG` for null pointers.

Adds 4 unit tests covering working-set tracking (and host memory exclusion),
shared-timer deadline ordering, bounded thread-pool burst execution, and
device-to-user lookup.
Typed-format stores whose format is in the instruction (MTBUF) were
refused by name. They now lower as raw stores of the element's dwords
when no conversion is involved: formats of 32-bit channels (uint, sint,
float; 32 to 32_32_32_32) store the data's bits, and the _d16_ forms of
the 16-bit float formats (16_16, 16_16_16_16) store their halves as they
are. The instruction must supply every channel of the format, as the
typed loads' layout gives it.

Everything else stays refused with a reason: norm, scaled and narrow
integer formats (conversions), elements under a dword (a
read-modify-write lanes would race on), and f32 data for half formats,
because DXIL's f32-to-f16 op rounds toward zero (measured below) where
the console rounds to nearest even; Marvisak#422 addresses that.

GPU tests store each lowered layout on the host GPU and WARP and read
the dwords back; another test checks the refusals.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
LAKSHYA-cmd-tech and others added 4 commits November 24, 2026 15:51
A compute program whose root signature does not fit the 16 user SGPRs
finds its arguments through a spill table: s[0:1] holds a pointer (high
dword masked to 40 bits, usually copied to s2/s3 first) to a table of
the user data, and the program s_loads descriptors and constants from
it. Table dword k is user SGPR 16 + k. The translator only knew
addresses that come from the declared root layout, so every such
program failed with "an address in an SGPR that is no root parameter".

For compute programs whose root layout lies entirely at user SGPR 16 and
above, loads from that pointer with a constant offset become s_mov_b32
copies of the user SGPRs the dwords stand for, before the SSA is built,
so resource tracking and lowering see what they see for ordinary root
arguments. Only straight-line code from the pointer's set-up is
rewritten (tags are dropped at branch targets and on any overwrite of
the pointer registers); other loads stay loads.

On the title's world shaders this took the "SGPR that is no root
parameter" failures from 34 programs to 4 in one run. Other failures
that were hidden behind it now show (address not from a root parameter,
root UAV or typed root view, an address from a phi...). Whether the
translated programs render correctly has not been checked beyond that.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The spill-table rewrite turned each load into `s_mov_b32 sK, s(16+k)`,
which reads what the register holds at that point. A program that has
already written SGPRs 16 and up (the destination of an earlier table
load, say) then reads the wrong root argument, with no refusal.

The program now first copies the user SGPRs its table loads stand for
into a block of SGPRs it never reads or writes, and the loads read that
block. Without such a block below VCC, or when a branch can return to
the program's entry, nothing is rewritten.

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

coderabbitai Bot commented Nov 24, 2026

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 18a4e847-ccc2-4c43-b1de-675812b95427
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

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.

9 participants