xg_xs: add XGSuggestSwizzleMode #292

Closed
gringoestrangeiro wants to merge 1 commit from upstream-pr/292 into main
gringoestrangeiro commented 2026-11-23 16:05:04 +00:00 (Migrated from github.com)

Imported from omonkeyz/xbox-emulator. Originally posted by gringoestrangeiro on 2026-11-23T16:05:04Z.


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.

<!-- greyfinch-sync:omonkeyz/xbox-emulator:issue:6563410111 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/pull/292). Originally posted by [gringoestrangeiro](https://github.com/gringoestrangeiro) on 2026-11-23T16:05:04Z. --- ## 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 commented 2026-11-23 16:05:58 +00:00 (Migrated from github.com)

Imported from omonkeyz/xbox-emulator. Originally posted by gringoestrangeiro on 2026-11-23T16:05:58Z.


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.

<!-- greyfinch-sync:omonkeyz/xbox-emulator:comment:7106604184 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/pull/292#issuecomment-7106604184). Originally posted by [gringoestrangeiro](https://github.com/gringoestrangeiro) on 2026-11-23T16:05:58Z. --- 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.
GDAgent commented 2026-11-23 17:08:28 +00:00 (Migrated from github.com)

Imported from omonkeyz/xbox-emulator. Originally posted by GDAgent on 2026-11-23T17:08:28Z.


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.
<!-- greyfinch-sync:omonkeyz/xbox-emulator:comment:7108209775 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/pull/292#issuecomment-7108209775). Originally posted by [GDAgent](https://github.com/GDAgent) on 2026-11-23T17:08:28Z. --- 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.
BuHHuTlyx commented 2026-11-23 21:27:39 +00:00 (Migrated from github.com)

Imported from omonkeyz/xbox-emulator. Originally posted by BuHHuTlyx on 2026-11-23T21:27:39Z.


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

<!-- greyfinch-sync:omonkeyz/xbox-emulator:comment:7114490203 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/pull/292#issuecomment-7114490203). Originally posted by [BuHHuTlyx](https://github.com/BuHHuTlyx) on 2026-11-23T21:27:39Z. --- 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)
omonkeyz commented 2026-11-25 13:51:09 +00:00 (Migrated from github.com)

Imported from omonkeyz/xbox-emulator. Originally posted by omonkeyz on 2026-11-25T13:51:09Z.


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.

<!-- greyfinch-sync:omonkeyz/xbox-emulator:comment:7164383683 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/pull/292#issuecomment-7164383683). Originally posted by [omonkeyz](https://github.com/omonkeyz) on 2026-11-25T13:51:09Z. --- 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

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
omonkeyz/xbox-emulator!292
No description provided.