Skip to content

runtime: xg_xs.dll shim, XGCreateTextureComputer and XGSuggestSwizzleMode as traced E_NOTIMPL (RT-489) - #6891

Merged
shayderrr merged 2 commits into
ProjectLeonida:mainfrom
Jadiac5:runtime/xg-xs-shim
Nov 23, 2026
Merged

shayderrr merged 2 commits into
ProjectLeonida:mainfrom
Jadiac5:runtime/xg-xs-shim

Conversation

@Jadiac5

@Jadiac5 Jadiac5 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

xg_xs: serve XGCreateTextureComputer and XGSuggestSwizzleMode as traced E_NOTIMPL

Item: RT-489, the xg_xs.dll shim (2 of the 30 unimplemented imports listed in #6715). Claim:
#6750 (comment)

What the imports are for

xg_xs.dll is the console's texture layout library. The game executable imports two functions from it. Today
both resolve to the unimplemented thunk, which returns 0 (S_OK) and writes nothing. Callers then call through an
out pointer that was never written.

What the call sites show (static read of the executable, shapes and counts only)

  • XGSuggestSwizzleMode(desc*, 0, uint32_t* mode): 2 call sites, both in the game's helper that fills a texture
    description. mode points to a 32-bit field of that description. The helper sets the field to 0 first, and
    writes 0x100 | mode itself when it already knows the mode. The HRESULT is only passed back up. No caller
    branches on it.
  • XGCreateTextureComputer(desc*, computer** out): 4 call sites. Two test the HRESULT and take their failure path
    when it is negative. Two ignore it and call through *out at once.
  • On the returned object the callers use vtable slot 1 when they are done (3 sites), slot 2 with one out pointer
    to a large stack structure (2 sites), slot 8 with six arguments in a loop over subresources (1 site) and slot 10
    with seven arguments (1 site). No site reads the return value of slots 2, 8 or 10. No site calls slot 0.

What the shim does now

The runtime has no model of the console resource layout. runtime/src/gfx10_tiling.h covers two swizzle modes of
one 2D level, without mips or the structure slot 2 fills. So the shim computes no layout:

  • XGSuggestSwizzleMode returns E_NOTIMPL and writes nothing. The field keeps the 0 the caller put there.
  • XGCreateTextureComputer returns E_POINTER for a null out. Otherwise it returns E_NOTIMPL and still stores
    one static object in *out. The two checking callers fail cleanly. The two that don't check get an object they
    can call, instead of a null pointer. COM says *out is null on failure. This breaks that on purpose, for these
    callers.
  • Slots 0 and 1 return 1 and count nothing. Every other slot up to 31 logs its index and the caller (module+RVA)
    once and returns E_NOTIMPL. It writes nothing through its arguments.
  • Registered like the other shims: SHIM_TABLE, so owns_dll("xg_xs.dll") is true. Added to the gta6rt sources.
    docs/runtime_imports.md describes it and adds it to the owned-module list.

Hypothesis, not measured: that slots 0 and 1 are AddRef and Release; what slots 2, 8 and 10 mean; and that no
caller reaches a slot above 31. At one site the object is stored in another object and may be called later from
code this read did not follow.

Effect: a texture whose layout the game asks for is not laid out (slot 8 does not copy). This shim is meant to get
past boot without a crash, not to make textures right.

Tests

  • New xg_xs_test (synthetic, no game data): 16 checks, 16 pass. It resolves both exports through
    rt::shims::find and checks ownership, the return values, that the mode field is untouched, that the computer is
    stored, and that slots 2, 8, 10 and 31 return E_NOTIMPL without writing their buffers. It also checks that
    extra Releases are harmless.
  • ctest on xg_xs, xmem, unimplemented_policy, loader, pe_loader, loader_tls, process_cmdline, file_system:
    8 of 8 pass. gta6rt builds and links with the new file.
  • python -I tests/test_docs_repo_paths.py: OK. python -I scripts/check_no_game_data.py: exit 0.

Not tested: not run against the retail executable. The full ctest suite was not run.

Tested on Windows 11, MSVC 19.44 (AMD Radeon RX 9070 XT, driver 32.0.32029.2010; the tests use no GPU).

AI-assisted (Claude Code).

@soldsawn

Copy link
Copy Markdown

Independent Windows 11 check at head a9278c9c56 (AI-assisted).

  • Environment: Windows 11, MSVC 19.44.35230.0 (RelWithDebInfo, Ninja), NVIDIA GeForce RTX 4060 Laptop GPU (driver 32.0.16.1714).
  • Build (xg_xs_test, gta6rt): Clean.
  • xg_xs_test.exe: 16 checks, 0 failures.
  • Retail game_scarlett_master.exe (gta6rt.exe --dry-run, nothing executed): 5 module(s) mapped, 28 unimplemented import(s) (down from 30 on main), with both xg_xs imports resolved to the shim.

@devnull34 devnull34 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hardware & Environment

  • Host: Windows 11 Build 26300 x64
  • Toolchain: MSVC 19.44 (Visual Studio 2022), CMake 4.4

Verification Summary

Targets compiled with MSVC 19.44 and executed natively:

  1. **\xg_xs_test.exe**:

    • Passed with 16 checks, 0 failures.
    • Verified that \xg_xs.dll\ is owned by the shim registry.
    • Verified that \XGSuggestSwizzleMode\ returns \E_NOTIMPL\ while preserving caller input buffers.
    • Verified that \XGCreateTextureComputer\ rejects null output pointers with \E_POINTER, returns \E_NOTIMPL\ while handing out a safe dummy computer object for callers that don't check return codes.
    • Verified that texture computer vtable slots (slots 2, 8, 10, 31) trace one-shot diagnostics and return \E_NOTIMPL\ safely without corrupting caller memory.
  2. CTest:

    • \xg_xs: Passed (0.01s).
  3. Hygiene & Compliance:

    • Clean-room compliant: pure synthetic unit tests; zero game assets or proprietary code.
    • \git diff origin/main..HEAD --check: Clean (0 whitespace/formatting defects).

LGTM!

@shayderrr shayderrr left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

Adds runtime/shims/xg_xs.cpp: XGSuggestSwizzleMode and XGCreateTextureComputer return E_NOTIMPL with once-only caller logging. The latter deliberately still stores a static 32-slot vtable computer in *out because two measured executable call sites use it without checking the HRESULT; slots 0/1 are no-op AddRef/Release, all others log and return E_NOTIMPL without writing outputs. runtime/CMakeLists.txt registers the shim, an xg_xs_test target and a CTest. runtime/test/xg_xs_test.cpp covers registration, mode-field preservation, null-out and slots 1/2/8/10/31. Docs add the xg_xs note and add xg_xs.dll to owns_dll.

Why merge

Closes two of the 30 unimplemented imports from #6715 with behavior derived from static call-site reading, preventing null-pointer calls while staying honest about missing console texture layout. Synthetic Windows tests pass.

Verdict: Approve

@shayderrr

Copy link
Copy Markdown
Collaborator

Summary

Adds runtime/shims/xg_xs.cpp: XGSuggestSwizzleMode and XGCreateTextureComputer return E_NOTIMPL with once-only caller logging. The latter deliberately still stores a static 32-slot vtable computer in *out because two measured executable call sites use it without checking the HRESULT; slots 0/1 are no-op AddRef/Release, all others log and return E_NOTIMPL without writing outputs. runtime/CMakeLists.txt registers the shim, an xg_xs_test target and a CTest. runtime/test/xg_xs_test.cpp covers registration, mode-field preservation, null-out and slots 1/2/8/10/31. Docs add the xg_xs note and add xg_xs.dll to owns_dll.

Why merge

Closes two of the 30 unimplemented imports from #6715 with behavior derived from static call-site reading, preventing null-pointer calls while staying honest about missing console texture layout. Synthetic Windows tests pass.

Verdict: Approve

@itaskaev2

Copy link
Copy Markdown

Tested a9278c9c (contains main 1cc6e3c1) on Windows 11, NVIDIA GeForce RTX 4080 SUPER, driver 616.92, MSVC 14.51 (19.51), RelWithDebInfo: pass. AI-assisted (Claude Code), no game files.

This adds the full suite on a newer MSVC to @soldsawn's 19.44 run of xg_xs_test.

  • Full ctest: 259 of 262 pass, 11 skipped (no Bink, FSR or game inputs). xg_xs passes, 16 checks, 0 failures.
  • The 3 failures are d3d12_indirect_dispatch_count, d3d12_indirect_rt and xbox_present (0xc0000409). All three also fail on this machine on main 561b65a8, so they are not from this PR.
  • The whole runtime, gta6rt included, builds under 19.51 with no warning from xg_xs.cpp (/W4 /permissive-).

@Jadiac5

Jadiac5 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto main 5f47ed2b3 to clear the conflict in docs/runtime_imports.md (main added a section at the same place); no code change. Rebuilt and rerun on the new base: xg_xs_test 16 checks, 0 failures. Windows 11, MSVC 19.44. Not run against the retail executable.

AI-assisted (Claude Code).

@kapitche

Copy link
Copy Markdown
Collaborator

Tested a9278c9 merged with main e6190e7 on Windows 11 / RTX 4080 SUPER against own copy of the retail exe: pass. The new head cc26796 (the rebase) has the same runtime/ diff byte for byte and now merges cleanly with e6190e7, so the result carries over.

  • Build: MSVC 14.51 (VS 18), Ninja, RelWithDebInfo, gta6rt + xg_xs_test.
  • ctest -R xg_xs: 1/1 passed.
  • gta6rt --dry-run (LEONIDA_D3D12=vulkan, fresh --trace, --trace-d3d12, --overlay to a scratch folder): main has 30 unimplemented imports (shim 53) and the PR has 28 (shim 55). The only difference is xg_xs.dll going from 2 to 0; the other 28 are unchanged.
  • Negative control: the same dry run on main lists both xg_xs.dll imports as unimplemented.
  • gta6rt --run with LEONIDA_UNIMPLEMENTED=stop: main and the PR stop in the same place. Both exit 3 at the first unimplemented import (d3d12_xs.dll!D3D12ConfigureVirtualMemoryX, d3d12_xs: D3D12ConfigureVirtualMemoryX shim (first unimplemented call of the title) #6792), after 2 TLS callbacks and 4/4 DllMain OK. A stop-mode run on main doesn't reach the xg_xs calls yet, so this PR alone doesn't move --run.

@Pipodi

Pipodi commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested on the retail boot: pass. Own 1.0.2.1 copy, Windows 11, RTX 4090 / 617.42, LEONIDA_D3D12=vulkan, on Pipodi:boot-integration (the #6982 stack, this PR's commit cherry-picked; only docs/runtime_imports.md conflicted).

  • Without it, the title stopped with an access violation right after XGCreateTextureComputer. One of the unchecked callers calls through the computer at once (your slot 8).
  • With it, both exports log once. The title calls slot 8 on the static computer, gets E_NOTIMPL, and goes on to DirectStorage and device slot 67. The run reached 1,659 D3D12 calls, against 1,655 before.

So the design choice to store a computer in *out on failure is exactly what the boot needs. AI-assisted (Claude Code).

@Spacecer2

Copy link
Copy Markdown

Tested cc267964 on Linux (clang-cl 23.1.5 + xwin Win11 SDK 10.0.26100 + MSVC 14.44, wine-11.22), applied alone to main 07f1d7e: builds, xg_xs_test 16 checks 0 failures under wine, and the retail dry-run drops from 30 unimplemented imports to 28 with xg_xs.dll gone from the list. Shapes match what I measure on my own copy. One suggestion: slot 2 carries an out-parameter to a large caller stack structure and returning E_NOTIMPL with it unwritten leaves a caller that ignores the result reading an uninitialised stack slot — a __fastfail with the slot index after the warn_once would make that diagnosable instead of silent. This is the version I would merge for xg_xs.dll (reasoning and the comparison with #7009/#7079 is in the coordination issue).

@Jadiac5

Jadiac5 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the Wine run. I am leaving slot 2 as it is, for this reason:

  • Slot 2 already prints one line with the slot index and the caller's address the first time it is called, so the call is not silent.
  • A __fastfail there would end the process at a call the title today survives. The retail boot run above reports that the title calls slot 8, gets E_NOTIMPL and goes on, and the run got further than before. Stopping at slot 2 would take that away for anyone who reaches it.
  • LEONIDA_UNIMPLEMENTED=stop is the existing switch for people who want a hard stop. If the maintainers want the computer slots to follow that switch, I will add it.

AI-assisted (Claude Code).

@AirKyzzZ

Copy link
Copy Markdown
Contributor

Tested cc2679645 (the rebased head) on RTX 2060 (NVIDIA 566.14), Windows 10 22H2, clang-cl 23.1.6 + lld-link, SDK 10.0.26100: pass

Built gta6rt and xg_xs_test at the head as is, no clang-cl warnings from xg_xs.cpp or its test. ctest -R "^xg_xs$": 1/1 pass, 16 checks, 0 failures. The same test linked without shims/xg_xs.cpp (as on main): 3 failures (both exports unregistered, registry does not own xg_xs.dll), so it is not model-only. Not run against the retail executable. No game files. AI-assisted (Claude Code).

ErRusso added a commit to ErRusso/Leonida that referenced this pull request Nov 23, 2026
…shapes

- XGCreateTextureComputer: fix signature from 4 args (desc, device, riid,
  out) to the measured 2 args (desc, out**). The out pointer arrives in
  RDX, not R9 — the old 4-arg version wrote through a stale register
  as textureComputer, which the two callers that ignore the HRESULT
  would use as a null/wild vtable call. Now returns a static computer
  with a proper vtable (AddRef/Release for slot 0/1, E_NOTIMPL for
  all other slots with a one-time log).

- XGSuggestSwizzleMode: fix signature from 2 args (desc, mode*) to the
  measured 3 args (desc, flags, mode*). The mode* arrives in R8, not
  RDX, so *mode = 0 was previously writing to a wrong register. Now
  returns E_NOTIMPL and writes nothing (the caller already zeroed the
  field).

- AcpHalCreate: replace the non-dereferenceable id<<4 handle with a
  static object with a proper vtable (IAcpHal COM-like interface).
  Any method call through it logs once per slot and returns E_NOTIMPL
  instead of faulting.

Both fixes match the measured call shapes documented in the overlapping
PRs ItsNotRexed#6891 and ItsNotRexed#6981 and verified by reviewers.

AI-assisted: yes
zebraso added a commit to zebraso/Leonida that referenced this pull request Nov 23, 2026
@jtrudeau1530

Copy link
Copy Markdown

checked: merged #6891 squash 23060e0 on Wine/RADV, as a single addition to our frozen #7323 diagnostic stack. Full base and combination choices are linked there. Arch Linux, Wine 11.18, RX 7900 XT / RADV Mesa 26.2.3, clang-cl 23.1.6 + xwin; same shader library and 30-second offline sandbox, display enabled, no assertion skipping.

The shim and its test are byte-identical to the merged commit. CMake hunks applied with offsets; the documentation conflict kept both xg_xs and DirectStorage modules. No production adaptation. Build passes; xg_xs reports 16 checks, zero failures. Selected suite: 46/51, all eight proxy modes, tiny-frame, unimplemented policy, loader and shader-library checks pass. The same five earlier failures remain (native-abort expectation, missing-TMP TLS refusal, two Wine WARP device checks, old mesh Close). The previously reported #7115 host-caller regression is also a known limitation outside this subset.

One bounded retail comparison: the previous intentional XGSuggestSwizzleMode unimplemented-import stop is gone. XGSuggestSwizzleMode, XGCreateTextureComputer and computer slot 8 report E_NOTIMPL; the title continues past all three. This does not establish texture layout or copy correctness: those operations remain unimplemented by design.

The run reaches 2,261 D3D12 trace calls (1,636 ok, 40 void/called, 585 unsupported CreateLifetimeTracker calls). Separately, 42 slot-67 pipeline attempts report missing translated FSPX-form programs and E_INVALIDARG; their source and relation to the crash are unestablished. After device slot 108 is first logged, the run ends with an execute access violation on the main thread: init 0/run 5, no timeout. No usable host frame in the debugger backtrace. The first fault is not attributed to the XG shim, failed pipelines or slot 108 without another controlled comparison.

Source/patch and matching binary/PDB/DLL hashes verified. Inputs and raw traces remain local. #7323's S_OK stand-in is still present; this is a diagnostic integration result, not a gameplay or full-suite pass claim.

AI-assisted testing (Claude), review/reporting (Codex).
agent: yes

@memorypressure

Copy link
Copy Markdown

Post-merge heads-up from routine issue triage at main 867d922: your 23060e0 added xg_xs.cpp to add_executable(gta6rt ...) in runtime/CMakeLists.txt:111 but not to scripts/build_runtime.ps1's $files list — tests/test_build_runtime_fallback.py is RED on main comparing the two lists. One line in the .ps1 fixes it. AI-assisted: yes. Tested on Linux (RTX 5080 host), code-side check.

@seblessa

Copy link
Copy Markdown
Contributor

An offer for RT-489, which is yours, not a competing PR: a real layout computer behind these two exports, on top of this shim. It keeps your registration, the computer that is always stored, and the once-only log for unserved slots: main...seblessa:Leonida:xg-layout-upstream

  • XGSuggestSwizzleMode and XGCreateTextureComputer compute a GFX10 layout (sizes, alignment, per-mip/slice offsets, swizzle mode) instead of returning E_NOTIMPL. What's assumed rather than measured is marked ASSUMPTION: in the code.
  • This shim's test checks the computed results now instead of E_NOTIMPL. The other checks are kept, and there's a slot-31 check.
  • It also fixes a failure on main since this PR: tests/test_build_runtime_fallback.py fails because the cl.exe fallback list in scripts/build_runtime.ps1 lacks xg_xs.cpp.

One known gap: the D3D12 device's slot 25 can report less memory than the console layout needs, so a copy could run past it. That's on the device-proxy side, not here.

Tested on an RTX 4080 SUPER (driver 617.42, Windows 11 26H2): the xg tests pass 2 of 2, and test_build_runtime_fallback passes 8 of 8. We're stopping active work, so take it into your own work or drop it as you prefer.

AI-assisted (Claude Code).

@Zunraz

Zunraz commented Nov 23, 2026

Copy link
Copy Markdown

Native Windows retail follow-up for c4c51dc3a on the earlier combined RT-5 stack (local integration 1a3bdd189, based on main 8575d36ed): the unimplemented-import stop is cleared, but this remains a layout stand-in.

Control was 1,666 D3D12 calls and an unimplemented XGSuggestSwizzleMode stop. With this shim, two RTX 5090 runs both reach 2,269 calls, ending at two unsupported slot-133 texture placements in the older #7218 310773a01 integration, followed by the title breakpoint. That texture fallback is already implemented in newer #7218 revisions; this is not a report against its current head. No image/menu, no layout correctness claim.

xg_xs_test: 16 checks, 0 failures. Existing combined proxy mocks: all eight modes pass. ExecuteIndirect fixture: 49 parity cases and positive GPU dispatch pass, zero fixture failures. These are focused checks, not a full-suite run. The local startup shader library contains the 52 builder and 10 executable-embedded translated programs, not the full corpus.

A separate run on the integrated AMD Radeon Graphics ends earlier at 1,640 calls with an unhandled C++ exception. Cause not diagnosed; I am not treating it as a regression from this shim or as successful AMD coverage.

Windows 11 build 26300, RTX 5090 / 32.0.16.2124, clang-cl 21.1.8 + xwin SDK 10.0.26100, static CRT, Vulkan backend. Socket/DNS/transmission debugger guards active; no assert skipping. Vulkan validation layer unavailable. No game files, shaders, raw traces or title addresses attached. AI-assisted (Codex).

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.