d3d12_xs: R9G9B9E5 UAV textures stored as RGBA16F on hosts without typed UAV (FidelityFX on NVIDIA/Intel) #55

Closed
QuentinDanblon wants to merge 0 commits from upstream-pr/55 into main
QuentinDanblon commented 2026-11-21 21:38:23 +00:00 (Migrated from github.com)

Imported from omonkeyz/xbox-emulator. Originally posted by QuentinDanblon on 2026-11-21T21:38:23Z.


Library / area: d3d12_xs (resource creation, views, copies, title-memory mirror)

Exports changed (exports.txt rows): none

Source of the behaviour: D3D12 format support queries on the host. The observation that GTA VI's amd_fidelityfx_upscaler_xbox.dll creates a 1920x1080 R9G9B9E5_SHAREDEXP texture with ALLOW_UNORDERED_ACCESS comes from americas-recomp (GPL-2.0, observation only, no code taken).

Problem

Console RDNA2 supports typed UAVs on R9G9B9E5. NVIDIA and Intel don't (D3D12_FORMAT_SUPPORT1_TYPED_UNORDERED_ACCESS_VIEW is missing; RTX 5090 Support1 = 0x8013f0). Creating such a texture with the UAV flag returns E_INVALIDARG, so the FidelityFX upscaler fails ffxCreateContext. WARP supports the format, which is why tests on WARP don't see this.

Change (new uav_subst.rs)

  • Substitution: when the host lacks typed UAV for the format, the texture is created as R16G16B16A16_FLOAT. That format is an exact container for RGB9E5 (at most 9 significant bits, a multiple of the f16 subnormal step, max 65408 < 65504); a unit test checks all 16384 channel values. Only textures (not buffers) with ALLOW_UAV on non-CPU heaps are substituted, so Map, ReadFromSubresource and WriteToSubresource never see 8-byte texels.
  • Creation paths: slot 27 (also reached through 76/83), 29 and 44 (also reached through 77/70). Substituted placed textures get their own committed resource, because the PC texture is twice the size of the title's range.
  • Views: device methods 18/19/20 are hooked once. R9G9B9E5 views are rewritten to the substitute format, and SRV alpha is forced to 1, as an RGB9E5 read returns.
  • Sizes and mirror: GetResourceAllocationInfo sizes substituted descs at 8 bytes per texel. The title-memory mirror (upload.rs) widens the 4-byte console texels while de-tiling.
  • Copies between a substituted texture and an R9G9B9E5 footprint or texture are refused and logged, never silently corrupted. Substituted↔substituted and RGBA16F-footprint copies pass through.
  • The host format probe runs in D3D12XboxCreateDevice on the real device.

Not covered (documented in the module)

  • UAV stores keep the f16 value: no rounding to the shared exponent, and no clamping of negatives, NaN or values above 65408.
  • Typed UAV loads return the stored alpha.
  • ClearUAV values are not quantised.
  • Reserved resources (slot 30) are not substituted.
  • GetCopyableFootprints still describes the console layout.
  • B5G6R5, B5G5R5A1, B4G4R4A4 and A4B4G4R4 also lack typed UAV on NVIDIA and Intel. I left them out: no console evidence, and no wider format holds their values exactly.

Tests (on 0fc7295)

  • cargo test -p d3d12_xs: lib 420 pass, 1 fail, integration tests pass. The failure is centroid_bind … fxc, which also fails on main without this commit.

  • Hardware hw_ -- --ignored --test-threads=1: 37/37 pass on the RTX 5090 and 37/37 on WARP.

  • The new hw_rgb9e5_typed_uav_texture_is_substituted reproduces the host E_INVALIDARG, then:

    • creates the texture via slot 76;
    • writes 64x16 texels through a UAV compute pass and reads them back via SRV: 512 RGB9E5-representable values come back exact, 512 arbitrary values within one RGB9E5 quantum, and alpha reads 1.0;
    • checks that a copy to an R9G9B9E5 footprint is refused and a copy to an RGBA16F footprint works.

    The test skips on WARP because WARP supports the format natively.

  • Not run in a title.

  • cargo test -p d3d12_xs passes (except the fxc test that also fails on main)

  • No game or console files and no binaries included

  • No fake success; anything not possible is left missing with a note

<!-- greyfinch-sync:omonkeyz/xbox-emulator:issue:6534709423 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/pull/55). Originally posted by [QuentinDanblon](https://github.com/QuentinDanblon) on 2026-11-21T21:38:23Z. --- **Library / area:** d3d12_xs (resource creation, views, copies, title-memory mirror) **Exports changed (exports.txt rows):** none **Source of the behaviour:** D3D12 format support queries on the host. The observation that GTA VI's `amd_fidelityfx_upscaler_xbox.dll` creates a 1920x1080 R9G9B9E5_SHAREDEXP texture with ALLOW_UNORDERED_ACCESS comes from americas-recomp (GPL-2.0, observation only, no code taken). ### Problem Console RDNA2 supports typed UAVs on R9G9B9E5. NVIDIA and Intel don't (`D3D12_FORMAT_SUPPORT1_TYPED_UNORDERED_ACCESS_VIEW` is missing; RTX 5090 Support1 = 0x8013f0). Creating such a texture with the UAV flag returns E_INVALIDARG, so the FidelityFX upscaler fails `ffxCreateContext`. WARP supports the format, which is why tests on WARP don't see this. ### Change (new `uav_subst.rs`) - **Substitution**: when the host lacks typed UAV for the format, the texture is created as R16G16B16A16_FLOAT. That format is an exact container for RGB9E5 (at most 9 significant bits, a multiple of the f16 subnormal step, max 65408 < 65504); a unit test checks all 16384 channel values. Only textures (not buffers) with ALLOW_UAV on non-CPU heaps are substituted, so Map, ReadFromSubresource and WriteToSubresource never see 8-byte texels. - **Creation paths**: slot 27 (also reached through 76/83), 29 and 44 (also reached through 77/70). Substituted placed textures get their own committed resource, because the PC texture is twice the size of the title's range. - **Views**: device methods 18/19/20 are hooked once. R9G9B9E5 views are rewritten to the substitute format, and SRV alpha is forced to 1, as an RGB9E5 read returns. - **Sizes and mirror**: GetResourceAllocationInfo sizes substituted descs at 8 bytes per texel. The title-memory mirror (upload.rs) widens the 4-byte console texels while de-tiling. - **Copies** between a substituted texture and an R9G9B9E5 footprint or texture are refused and logged, never silently corrupted. Substituted↔substituted and RGBA16F-footprint copies pass through. - The host format probe runs in `D3D12XboxCreateDevice` on the real device. ### Not covered (documented in the module) - UAV stores keep the f16 value: no rounding to the shared exponent, and no clamping of negatives, NaN or values above 65408. - Typed UAV loads return the stored alpha. - ClearUAV values are not quantised. - Reserved resources (slot 30) are not substituted. - GetCopyableFootprints still describes the console layout. - B5G6R5, B5G5R5A1, B4G4R4A4 and A4B4G4R4 also lack typed UAV on NVIDIA and Intel. I left them out: no console evidence, and no wider format holds their values exactly. ### Tests (on 0fc7295) - `cargo test -p d3d12_xs`: lib 420 pass, 1 fail, integration tests pass. The failure is `centroid_bind … fxc`, which also fails on main without this commit. - Hardware `hw_ -- --ignored --test-threads=1`: 37/37 pass on the RTX 5090 and 37/37 on WARP. - The new `hw_rgb9e5_typed_uav_texture_is_substituted` reproduces the host E_INVALIDARG, then: - creates the texture via slot 76; - writes 64x16 texels through a UAV compute pass and reads them back via SRV: 512 RGB9E5-representable values come back exact, 512 arbitrary values within one RGB9E5 quantum, and alpha reads 1.0; - checks that a copy to an R9G9B9E5 footprint is refused and a copy to an RGBA16F footprint works. The test skips on WARP because WARP supports the format natively. - Not run in a title. - [x] `cargo test -p d3d12_xs` passes (except the fxc test that also fails on main) - [x] No game or console files and no binaries included - [x] No fake success; anything not possible is left `missing` with a note
QuentinDanblon commented 2026-11-22 11:36:48 +00:00 (Migrated from github.com)

Imported from omonkeyz/xbox-emulator. Originally posted by QuentinDanblon on 2026-11-22T11:36:48Z.


Rebased onto 51f5319. One conflict in upload.rs (check): main's stage_time measurement is kept, with the host element size of the substituted format. Main's new one_megabyte_detiles_on_one_thread_in_a_few_ms test passes None for the extra detile_span argument.

Tests on this base:

  • cargo test -p d3d12_xs --release --lib hw_ -- --ignored --test-threads=1: 39 of 39 on the RTX 5090, 39 of 39 with TOMBOX_HW_ADAPTER=warp.
  • --lib uav_subst: 10 pass.
  • --lib: 460 pass, 3 fail. Main alone: 450 pass, 2 fail (device_console_fix::tests::console_heap_properties_create_on_pc_through_every_wrapped_path and xs_exports::console_fixed_tests::fixed_result_dxgix_exports_match_every_console_d3d12_xs, both also failing here).

The third failure is slot_audit_tests::done_slots_have_real_handlers, and it does not come from a slot change (this PR does not touch the device vtable). The audit names each handler with SymFromAddr, and the release linker folds functions with identical code. device_wrap::dev_stub and console_slots_dev2::scarlett_notimpl both only return E_NOTIMPL, so they share one address and the name that comes back depends on link order. With this branch the fold resolves to dev_stub for Device 31-35, 69, 83, 85, 88 and 89, which the test counts as placeholders. Main's own audit output (TOMBOX_SLOT_AUDIT_OUT) already shows folded names: Device 7 is reported as title_heap::tests::f_release and Device 6 as cl_console_fix::set_name_x. Any change that moves the link order can trip it. A body for dev_stub that no real handler shares would make the audit independent of folding.

<!-- greyfinch-sync:omonkeyz/xbox-emulator:comment:7078556366 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/pull/55#issuecomment-7078556366). Originally posted by [QuentinDanblon](https://github.com/QuentinDanblon) on 2026-11-22T11:36:48Z. --- Rebased onto `51f5319`. One conflict in `upload.rs` (`check`): main's `stage_time` measurement is kept, with the host element size of the substituted format. Main's new `one_megabyte_detiles_on_one_thread_in_a_few_ms` test passes `None` for the extra `detile_span` argument. Tests on this base: - `cargo test -p d3d12_xs --release --lib hw_ -- --ignored --test-threads=1`: 39 of 39 on the RTX 5090, 39 of 39 with `TOMBOX_HW_ADAPTER=warp`. - `--lib uav_subst`: 10 pass. - `--lib`: 460 pass, 3 fail. Main alone: 450 pass, 2 fail (`device_console_fix::tests::console_heap_properties_create_on_pc_through_every_wrapped_path` and `xs_exports::console_fixed_tests::fixed_result_dxgix_exports_match_every_console_d3d12_xs`, both also failing here). The third failure is `slot_audit_tests::done_slots_have_real_handlers`, and it does not come from a slot change (this PR does not touch the device vtable). The audit names each handler with `SymFromAddr`, and the release linker folds functions with identical code. `device_wrap::dev_stub` and `console_slots_dev2::scarlett_notimpl` both only return `E_NOTIMPL`, so they share one address and the name that comes back depends on link order. With this branch the fold resolves to `dev_stub` for Device 31-35, 69, 83, 85, 88 and 89, which the test counts as placeholders. Main's own audit output (`TOMBOX_SLOT_AUDIT_OUT`) already shows folded names: Device 7 is reported as `title_heap::tests::f_release` and Device 6 as `cl_console_fix::set_name_x`. Any change that moves the link order can trip it. A body for `dev_stub` that no real handler shares would make the audit independent of folding.
omonkeyz commented 2026-11-22 13:12:50 +00:00 (Migrated from github.com)

Imported from omonkeyz/xbox-emulator. Originally posted by omonkeyz on 2026-11-22T13:12:50Z.


Main's history was rewritten, which auto-closed this PR (sorry for the noise). Please restate this without naming a title or the GPL-2.0 project as the source (keep those facts in the PR text), strip the comment lines, and rebase on the current device_wrap.rs. It needs maintainer hardware testing after that. To resubmit: git fetch this repo, branch from the current main, cherry-pick only your own commits (the old branch is based on the previous history and cannot be merged), and open a new PR.

<!-- greyfinch-sync:omonkeyz/xbox-emulator:comment:7079647873 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/pull/55#issuecomment-7079647873). Originally posted by [omonkeyz](https://github.com/omonkeyz) on 2026-11-22T13:12:50Z. --- Main's history was rewritten, which auto-closed this PR (sorry for the noise). Please restate this without naming a title or the GPL-2.0 project as the source (keep those facts in the PR text), strip the comment lines, and rebase on the current device_wrap.rs. It needs maintainer hardware testing after that. To resubmit: `git fetch` this repo, branch from the current `main`, cherry-pick only your own commits (the old branch is based on the previous history and cannot be merged), and open a new PR.

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!55
No description provided.