xg_xs: add XGSuggestSwizzleMode #292

Closed
github-bot wants to merge 1 commit from gh-pr/292/head into gh-pr/292/base
Owner

@⁠gringoestrangeiro on GitHub · 2026-11-23 16:05 UTC · original
gringoestrangeiro:xg-suggest-swizzle-mode → main · +96 −1 · 3 files · 1 commits · closed without merging

What

GTA VI 1.0.2.1 (Scarlett) imports XGSuggestSwizzleMode from xg_xs.dll by name. The compat DLL exports 23 functions today; this one is missing, so the title's loader cannot bind the import.

Contract from the title's call sites

Two call sites agree:

  • RCX = pointer to a D3D12_RESOURCE_DESC
  • RDX = 0
  • R8 = pointer to desc->Layout (desc + 0x2C)
  • the return value is fed to the title's HRESULT sanitizer

The title builds the descriptor, calls the API, then hands it to XGCreateTextureComputer. Its own fallback for a known mode writes 0x100 | mode into desc->Layout; D3D12Desc::to_tex2d already decodes 0x100..=0x11F as layout & 0x1F. The API therefore has to write 0x100 | XG_SWIZZLE_MODE into *out.

Implementation

XGSuggestSwizzleMode reads the descriptor, derives the bind/misc bits with the same mapping as D3D12Desc::to_tex2d, and reuses optimal_swizzle (the already-verified XGComputeOptimalSwizzleMode rules). It writes 0x100 | mode and returns S_OK. flags != 0 returns E_NOTIMPL because the title only passes 0 and no console behavior is known.

Tests cover 2D SRV/RT/depth/UAV, 3D, 1D, an invalid dimension and non-zero flags. cargo check --target x86_64-pc-windows-msvc -p xg_xs --lib passes; the crate's test target still needs the local oracle.rs fixture, same as before this change.

Verification limit

No console xg_xs.dll exporting this function was present in the analysed dumps (only the console OS image, not an extracted EmbeddedXvd), so the row is marked pending. If you can point me at a newer EmbeddedXvd with this export, I can turn it into a real oracle comparison.

**@⁠gringoestrangeiro** on GitHub · 2026-11-23 16:05 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/292) `gringoestrangeiro:xg-suggest-swizzle-mode` → `main` · +96 −1 · 3 files · 1 commits · closed without merging ## What GTA VI 1.0.2.1 (Scarlett) imports `XGSuggestSwizzleMode` from `xg_xs.dll` by name. The compat DLL exports 23 functions today; this one is missing, so the title's loader cannot bind the import. ## Contract from the title's call sites Two call sites agree: - `RCX` = pointer to a `D3D12_RESOURCE_DESC` - `RDX` = 0 - `R8` = pointer to `desc->Layout` (`desc + 0x2C`) - the return value is fed to the title's HRESULT sanitizer The title builds the descriptor, calls the API, then hands it to `XGCreateTextureComputer`. Its own fallback for a known mode writes `0x100 | mode` into `desc->Layout`; `D3D12Desc::to_tex2d` already decodes `0x100..=0x11F` as `layout & 0x1F`. The API therefore has to write `0x100 | XG_SWIZZLE_MODE` into `*out`. ## Implementation `XGSuggestSwizzleMode` reads the descriptor, derives the bind/misc bits with the same mapping as `D3D12Desc::to_tex2d`, and reuses `optimal_swizzle` (the already-verified `XGComputeOptimalSwizzleMode` rules). It writes `0x100 | mode` and returns `S_OK`. `flags != 0` returns `E_NOTIMPL` because the title only passes 0 and no console behavior is known. Tests cover 2D SRV/RT/depth/UAV, 3D, 1D, an invalid dimension and non-zero flags. `cargo check --target x86_64-pc-windows-msvc -p xg_xs --lib` passes; the crate's test target still needs the local `oracle.rs` fixture, same as before this change. ## Verification limit No console `xg_xs.dll` exporting this function was present in the analysed dumps (only the console OS image, not an extracted `EmbeddedXvd`), so the row is marked `pending`. If you can point me at a newer EmbeddedXvd with this export, I can turn it into a real oracle comparison.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:17:34 +00:00
github-bot closed this pull request 2026-11-26 06:17:34 +00:00
Author
Owner

@⁠gringoestrangeiro on GitHub · 2026-11-23 16:05 UTC · original

Import coverage of the GTA VI 1.0.2.1 Scarlett exe against the compat crates (console-only DLLs only):

console DLL imports present in compat
xmem 12 12
d3d12_xs 3 3
xg_xs 2 1
xapu 5 5
AcpHal 9 9
chad 5 5
XCRDAPI 1 1

The only missing name is XGSuggestSwizzleMode, which this PR adds. The remaining imports are title-shipped (Bink2Scarlett, XboxBvhBuilder, libHttpClient.GDK, XCurl), PC-provided (MFPlat/MFReadWrite, GameInput, WinHTTP, WS2_32), or API sets.

Also worth noting for the title entry: the dump has no extracted EmbeddedXvd (only the console OS image), so there is no per-title console-OS export table for GTA VI; the XGSuggestSwizzleMode row is therefore pending rather than oracle-verified.

**@⁠gringoestrangeiro** on GitHub · 2026-11-23 16:05 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/292#issuecomment-7106604184) Import coverage of the GTA VI 1.0.2.1 Scarlett exe against the compat crates (console-only DLLs only): | console DLL | imports | present in compat | |---|---:|---| | xmem | 12 | 12 | | d3d12_xs | 3 | 3 | | xg_xs | 2 | 1 | | xapu | 5 | 5 | | AcpHal | 9 | 9 | | chad | 5 | 5 | | XCRDAPI | 1 | 1 | The only missing name is `XGSuggestSwizzleMode`, which this PR adds. The remaining imports are title-shipped (Bink2Scarlett, XboxBvhBuilder, libHttpClient.GDK, XCurl), PC-provided (MFPlat/MFReadWrite, GameInput, WinHTTP, WS2_32), or API sets. Also worth noting for the title entry: the dump has no extracted `EmbeddedXvd` (only the console OS image), so there is no per-title console-OS export table for GTA VI; the `XGSuggestSwizzleMode` row is therefore `pending` rather than oracle-verified.
Author
Owner

@⁠GDAgent on GitHub · 2026-11-23 17:08 UTC · original

Independent confirmation: we had reached the same contract from the call sites of the same title (desc in RCX, flags 0, &desc->Layout in R8, 0x100 | mode written, HRESULT returned) and an implementation with the same mode rules, so we are dropping ours in favour of this PR.

Two small suggestions from our version, take them or leave them:

  • The bind/misc mapping is now a second copy of the one in D3D12Desc::to_tex2d. We split it into a bind_and_misc() helper and an implicit_mode() helper on D3D12Desc and used them from both places, so the layout-UNKNOWN path of to_tex2d and XGSuggestSwizzleMode cannot drift apart. A test that checks XGSuggestSwizzleMode against to_tex2d with Layout = 0 for the same desc pins that.
  • On the missing src/oracle.rs: we hit the same thing (the crate's test target does not build on a clean checkout). We could only run the xg_xs tests by cutting the oracle modules out locally; it may be worth a separate issue so the fixture-dependent tests are gated instead.
**@⁠GDAgent** on GitHub · 2026-11-23 17:08 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/292#issuecomment-7108209775) Independent confirmation: we had reached the same contract from the call sites of the same title (desc in RCX, flags 0, `&desc->Layout` in R8, `0x100 | mode` written, HRESULT returned) and an implementation with the same mode rules, so we are dropping ours in favour of this PR. Two small suggestions from our version, take them or leave them: - The bind/misc mapping is now a second copy of the one in `D3D12Desc::to_tex2d`. We split it into a `bind_and_misc()` helper and an `implicit_mode()` helper on `D3D12Desc` and used them from both places, so the layout-UNKNOWN path of `to_tex2d` and `XGSuggestSwizzleMode` cannot drift apart. A test that checks `XGSuggestSwizzleMode` against `to_tex2d` with `Layout = 0` for the same desc pins that. - On the missing `src/oracle.rs`: we hit the same thing (the crate's test target does not build on a clean checkout). We could only run the xg_xs tests by cutting the oracle modules out locally; it may be worth a separate issue so the fixture-dependent tests are gated instead.
Author
Owner

@⁠BuHHuTlyx on GitHub · 2026-11-23 21:27 UTC · original

I tried the shared-helper approach suggested above. The attached patch applies to b90b64fc70cfdc70762ea658e105f8d53aac7b5f. It shares the descriptor flag and implicit layout logic and adds a regression test that passes &desc->Layout as the output pointer and checks the resulting mode against to_tex2d with Layout = 0.

With #310 applied, cargo test --locked -p xg_xs passed all 21 tests on native Windows MSVC. dumpbin /exports also confirmed the PR DLL exports XGSuggestSwizzleMode by name.

One loader detail to verify: the pending row is absent from the generated compat_routes.rs. If the title import uses the host route table, it needs a route entry. The exported name is available when loading the built DLL directly.

xg-swizzle-shared-layout.patch.txt

**@⁠BuHHuTlyx** on GitHub · 2026-11-23 21:27 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/292#issuecomment-7114490203) I tried the shared-helper approach suggested above. The attached patch applies to `b90b64fc70cfdc70762ea658e105f8d53aac7b5f`. It shares the descriptor flag and implicit layout logic and adds a regression test that passes `&desc->Layout` as the output pointer and checks the resulting mode against `to_tex2d` with `Layout = 0`. With #310 applied, `cargo test --locked -p xg_xs` passed all 21 tests on native Windows MSVC. `dumpbin /exports` also confirmed the PR DLL exports `XGSuggestSwizzleMode` by name. One loader detail to verify: the `pending` row is absent from the generated `compat_routes.rs`. If the title import uses the host route table, it needs a route entry. The exported name is available when loading the built DLL directly. [xg-swizzle-shared-layout.patch.txt](https://github.com/user-attachments/files/35300209/xg-swizzle-shared-layout.patch.txt)
Author
Owner

@⁠omonkeyz on GitHub · 2026-11-25 13:51 UTC · original

Thanks. The exports.txt line describes a specific title's call site, and the project cannot take title-specific facts. Please resubmit with the note removed and the (desc, flags, out) signature backed by a public source (GDK header or docs) or a console xg_xs.dll oracle test.

**@⁠omonkeyz** on GitHub · 2026-11-25 13:51 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/292#issuecomment-7164383683) Thanks. The exports.txt line describes a specific title's call site, and the project cannot take title-specific facts. Please resubmit with the note removed and the (desc, flags, out) signature backed by a public source (GDK header or docs) or a console xg_xs.dll oracle test.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.