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

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

@⁠QuentinDanblon on GitHub · 2026-11-21 21:38 UTC · original
QuentinDanblon:fix/rgb9e5-typed-uav → main · +1044 −25 · 6 files · 104 commits · closed without merging

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

**@⁠QuentinDanblon** on GitHub · 2026-11-21 21:38 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/55) `QuentinDanblon:fix/rgb9e5-typed-uav` → `main` · +1044 −25 · 6 files · 104 commits · closed without merging **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
GTA VI's amd_fidelityfx_upscaler_xbox.dll creates a 1920x1080 R9G9B9E5_SHAREDEXP
texture with ALLOW_UNORDERED_ACCESS (device slot 76). RDNA2 consoles accept it.
NVIDIA rejects it with E_INVALIDARG because the format lacks
FORMAT_SUPPORT1_TYPED_UNORDERED_ACCESS_VIEW, and ffxCreateContext throws.

Credit: the failure was observed and documented by americas-recomp
(realdody, GPL-2.0). Only the behavioural fact is used here; the code is
an independent implementation.

Measured on this machine with CheckFeatureSupport(FORMAT_SUPPORT):
- RTX 5090 and UHD 770: R9G9B9E5 Support1=0x8013f0, so CreateCommittedResource
  with ALLOW_UAV returns 0x80070057.
- WARP: Support1=0x2ecd3f1, and it accepts the texture.
- 85/86/115/191 (B5G6R5, B5G5R5A1, B4G4R4A4, A4B4G4R4) are the only other
  formats that WARP binds as typed UAVs and NVIDIA/Intel do not. They are left
  alone: there is no console evidence for them and no exact wider container.

R16G16B16A16_FLOAT is an exact container for RGB9E5. Every channel value
m*2^(e-24) (m<512, e<=31, max 65408) is an f16; a unit test checks all 16384.

uav_subst.rs:
- Decision gated on the host's real Support1. Unknown support never
  substitutes.
- Substitution applied in CreateCommittedResource (27, also reached by
  76/83), CreatePlacedResource (29) and CreatePlacedResourceX (44, which then
  gets its own committed resource because the wider texture must not alias the
  title's neighbouring VA placements).
- CPU-visible heaps are refused so that Map/Read/WriteToSubresource never see
  8-byte texels.
- Per-resource registry, validated against GetDesc.
- SRV/UAV/RTV descriptors whose format is R9G9B9E5 are rewritten through a
  hook on the real device's method table (18/19/20), installed with the first
  substitution. That one point covers wrapper slots, placed-view slots,
  title_heap and titles that hold the real device. SRV swizzles that read
  source alpha are forced to 1, as an RGB9E5 read returns.
- GetResourceAllocationInfo sizes substituted descs at 8 bytes per texel.
- Title-memory mirroring (upload.rs) widens console RGB9E5 texels to RGBA16F
  while de-tiling.
- On the Xbox command list, copies between a substituted texture and an
  R9G9B9E5 footprint or an unsubstituted texture are refused and logged; they
  are never forwarded as corrupt data. Substitute-to-substitute copies pass.

Not mapped:
- Shader UAV stores keep f16 values: more precise, within one RGB9E5 quantum,
  with no clamp of negatives/NaN/>65408.
- Typed UAV loads return the stored alpha.
- Reserved resources are not substituted.

Tests:
- Unit tests for the decision table, desc/view rewrite, swizzle, copy rules,
  conversions and the widening de-tile.
- hw_rgb9e5_typed_uav_texture_is_substituted goes through slot 76, writes
  with a UAV compute shader and reads back through an SRV.
  - On the RTX 5090: 512 texels are exact, 512 more are within one quantum,
    and the refusal of the console-footprint copy is checked.
  - The test skips on WARP, which supports the format natively.
  - With the debug layer it reports only the intended host rejection.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:08:38 +00:00
github-bot closed this pull request 2026-11-26 06:08:38 +00:00
Author
Owner

@⁠QuentinDanblon on GitHub · 2026-11-22 11:36 UTC · original

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.

**@⁠QuentinDanblon** on GitHub · 2026-11-22 11:36 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/55#issuecomment-7078556366) 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.
Author
Owner

@⁠omonkeyz on GitHub · 2026-11-22 13:12 UTC · original

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.

**@⁠omonkeyz** on GitHub · 2026-11-22 13:12 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/55#issuecomment-7079647873) 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

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