d3d12_xs: R9G9B9E5 UAV textures stored as RGBA16F on hosts without typed UAV for that format (core: creation and views) #277

Closed
github-bot wants to merge 2 commits from github-bot/gh-277 into main AGit
Owner

@⁠QuentinDanblon on GitHub · 2026-11-23 10:53 UTC · original
pr/uav-rgb9e5-core → main · +2158 −28 · 8 files · 2 commits · closed without merging

Library / area: d3d12_xs: resource creation (device_wrap.rs slots 27, 29, 44), view creation, copies on the Xbox command list (slots 16, 17, 83, 84), upload.rs mirroring. New uav_subst.rs, uav_subst_copy.rs, uav_subst_hw.rs.

Exports changed (exports.txt rows): none

Source of the behaviour:

  • Public AMD FidelityFX SDK v2.4.0 (MIT, 7539ae8b), read only: Kits/FidelityFX/backend/dx12/ffx_dx12.cpp maps FFX_API_SURFACE_FORMAT_R9G9B9E5_SHAREDEXP one to one to DXGI_FORMAT_R9G9B9E5_SHAREDEXP and UAV usage to ALLOW_UNORDERED_ACCESS (line 715). No code taken.
  • An Xbox build of the FidelityFX upscaler DLL that ships with a GDK title carries strings of that backend file and imports d3d12_xs.dll. No string in it names R9G9B9E5, so which resource asks for the format is not established. No file of the title is in this PR.
  • Host support, measured on this PC with CheckFeatureSupport(FORMAT_SUPPORT): RTX 5090 Support1 = 0x8013f0 for format 67, no typed UAV, CreateCommittedResource returns E_INVALIDARG. WARP: 0x2ecd3f1, accepted.
  • RGB9E5 encode: Khronos EXT_texture_shared_exponent specification (N=9, B=15, Emax=31, max 65408, negatives and NaN to 0, round to nearest, half up). No code taken from any project.

Two commits: the core (creation and views), then the conversion that replaces the copy and upload refusals of the first version.

Commit 1: creation and views

A 1D/2D/3D texture in format 67 with ALLOW_UNORDERED_ACCESS, one sample, no RT or DS flag, is stored as R16G16B16A16_FLOAT when the device that creates it reports no typed UAV for format 67. Unknown support never substitutes. On a host with native support (WARP) nothing changes.

R16G16B16A16_FLOAT holds every RGB9E5 texel exactly: rgb9e5_channels_are_exact_f16 checks all 16384 channel values.

  • CreateCommittedResource (slot 27, also reached from 76 and 83): decided after depth_uav, then through res_pool::try_create with the substituted desc.
  • CreatePlacedResource (slot 29): the substituted texture is twice the console layout reserved at that heap offset, so it is created committed with the heap's properties, the fallback alias::committed_when_too_big already uses.
  • CreatePlacedResourceX (slot 44): the substituted desc goes through alias::create_placed_x; gpu_va and placed keep the console desc, because the title's memory holds console texels.
  • The registry is a private-data mark on the resource. If the mark or the view hook cannot be set, the resource is released and creation returns E_FAIL.
  • SRV, UAV and RTV creation are hooked on the real device's method table (slots 18, 19, 20) at the first substitution. A view in format 67 on a substituted texture gets R16G16B16A16_FLOAT. An SRV with format UNKNOWN or a null desc gets an explicit view. SRV swizzles that read source alpha are forced to 1. Views in any other format are forwarded unchanged.
  • A texture in a CPU-visible heap is not substituted; the host rejects it as before.

Commit 2: copies and uploads convert

  • Copies on the Xbox command list (slots 16, 17, 83, 84) with a substituted texture on one side and R9G9B9E5 on the other are staged through a DEFAULT-heap scratch buffer. A cs_6_0 shader (DXC, embedded root signature) converts the scratch in place: decode RGB9E5 words to RGBA16F texels, encode the reverse. Title resources are only touched by CopyTextureRegion / CopyBufferRegion, in the states the title set.
  • Copy-out to a footprint writes merged per-row CopyBufferRegion runs, so bytes between rows and outside the box are never written.
  • After the pass, the title's root signature, PSO, root arguments and descriptor heaps are restored with cl2_state::reapply, as depth_uav does. Predication is not touched.
  • Substituted to substituted, same host format: forwarded unchanged.
  • CopyResource (17) and CopyResourceX (84) between a substituted and an R9G9B9E5 texture with the same dimensions and mips: converted subresource by subresource. Slot 84 flags go through the existing copy_resource_x_plan validation first.
  • upload.rs mirrors title memory into a substituted texture: the detiler widens each RGB9E5 texel to RGBA16F while writing the host layout (widen_span), and host-side sizes use 8 bytes per texel.
  • Every converted copy is logged and counted; note_gpu_write is called on the destination.

Still refused (logged and counted, nothing copied)

These calls return void, so the title is not told. I list them so you can say which ones you want handled another way.

  • Conversion on a copy-queue list: the pass needs a compute dispatch. The console would do this copy; we do not.
  • Copies whose other side is not R9G9B9E5 (for example an RGBA16F footprint), between different substitutes, CopyResource with a buffer on one side or with mismatched dimensions, mips or array size, CopyResourceX whose flags fail the console validation. As far as I know none of these is a valid copy for an R9G9B9E5 texture on the console either.
  • DXC, PSO, root signature or scratch creation failure, a region past 32-bit scratch size, depth over 65535.
  • upload.rs: a substitute other than RGBA16F, or an XG element size other than 4 bytes.

Not covered, not claimed

  • No title was run.
  • The scratch is one buffer per list origin, grown by powers of two from 64 KiB. A replaced scratch is never freed, because a recorded list may still reference it. A list executed on two queues at once would share it.
  • Slot 83 flags are ignored, as the chain bottom already does.
  • Non-canonical RGB9E5 words come back canonical after a decode and encode round trip: same value, maybe other bits.
  • Console rounding for its own RGB9E5 UAV stores is not known; this encode is the specification's.
  • Shader UAV stores keep f16 values: never less precise, within one RGB9E5 quantum for inputs in [0, 65408], no clamp of negatives, NaN or larger values. Typed UAV loads return the stored alpha.
  • Reserved resources are not substituted. GetDesc on a substituted texture returns the host format. GetResourceAllocationInfo answers with the console layout. The view hook covers at most four device method tables.
  • device_wrap.rs is not re-checked against #239 yet: #239 is still open. I will rebase and re-check when it lands.

Tests

Base f89e410, RTX 5090 PC, Windows 11, and WARP (TOMBOX_HW_ADAPTER=warp).

  • Unit, cargo test -p d3d12_xs --release --lib: 21 tests matching uav_subst / rgb9e5 pass, among them decode_matches_the_exact_value_of_every_channel (all 16384 channel values and 100000 random words), the copy and resource-copy rule tables, scratch layout and run merging, rgb9e5_texels_are_widened_to_rgba16f_while_detiling. upload: 15 pass.

  • Hardware. WARP binds R9G9B9E5 as a typed UAV, so a test-only flag (FORCE_NO_TYPED_UAV) clears that bit and the conversion path runs there too.

    • hw_rgb9e5_copies_out_of_a_substituted_texture_are_encoded_bit_exact: 256x256 texels covering every f16 value per channel; whole footprint, boxed slot 83 copy with untouched padding, texture copy, CopyResource, CopyResourceX, compared bit-exact with a reference written in the test from the specification.
    • hw_rgb9e5_copies_into_a_substituted_texture_are_decoded_exact: every mantissa and exponent; footprint, boxed footprint with a marker kept outside the box, texture via slot 83, CopyResource.
    • hw_rgb9e5_conversions_on_a_copy_queue_list_are_refused.
    • The three tests of commit 1, adjusted: the slot 16 copy to an R9G9B9E5 footprint is checked bit-exact, the RGBA16F footprint copy is refused.
    • hw_rgb9e5_title_memory_is_mirrored_into_a_substituted_texture needs an xg_xs.dll on the search path. With the workspace's own one (cargo build --release -p xg_xs, target/release on PATH): 8192 title texels widened from RGB9E5 to RGBA16F on upload, twice (first upload, then after a CPU rewrite, no write lost). The layout there comes from the workspace's xg_xs, not a console DLL.
    • 7 of 7 pass on WARP and 7 of 7 on the RTX 5090.
  • Mutations: dropping the half-up rounding term in the HLSL encode makes the encode test fail on WARP (33027 of 65536 texels differ); moving the subnormal bound in rgb9e5_half makes the exact decode unit test fail. Both restored.

  • hw_uav_subst_view_hook_cost_per_call (commit 1): best of 9 rounds of 100000 calls, tens of nanoseconds per view at most, run-to-run noise larger than the hook's cost.

  • pr_gate.py --base origin/main: 0 problems.

  • cargo test -p d3d12_xs passes for what is listed above

  • No game or console files and no binaries included

  • No fake success: the copies and uploads that were refused now convert; what is still refused is listed above, with a log line and a counter

🤖 Generated with Claude Code

**@⁠QuentinDanblon** on GitHub · 2026-11-23 10:53 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/277) `pr/uav-rgb9e5-core` → `main` · +2158 −28 · 8 files · 2 commits · closed without merging **Library / area:** `d3d12_xs`: resource creation (`device_wrap.rs` slots 27, 29, 44), view creation, copies on the Xbox command list (slots 16, 17, 83, 84), `upload.rs` mirroring. New `uav_subst.rs`, `uav_subst_copy.rs`, `uav_subst_hw.rs`. **Exports changed (exports.txt rows):** none **Source of the behaviour:** - Public AMD FidelityFX SDK v2.4.0 (MIT, `7539ae8b`), read only: `Kits/FidelityFX/backend/dx12/ffx_dx12.cpp` maps `FFX_API_SURFACE_FORMAT_R9G9B9E5_SHAREDEXP` one to one to `DXGI_FORMAT_R9G9B9E5_SHAREDEXP` and UAV usage to `ALLOW_UNORDERED_ACCESS` (line 715). No code taken. - An Xbox build of the FidelityFX upscaler DLL that ships with a GDK title carries strings of that backend file and imports `d3d12_xs.dll`. No string in it names R9G9B9E5, so which resource asks for the format is not established. No file of the title is in this PR. - Host support, measured on this PC with `CheckFeatureSupport(FORMAT_SUPPORT)`: RTX 5090 `Support1 = 0x8013f0` for format 67, no typed UAV, `CreateCommittedResource` returns `E_INVALIDARG`. WARP: `0x2ecd3f1`, accepted. - RGB9E5 encode: Khronos `EXT_texture_shared_exponent` specification (N=9, B=15, Emax=31, max 65408, negatives and NaN to 0, round to nearest, half up). No code taken from any project. Two commits: the core (creation and views), then the conversion that replaces the copy and upload refusals of the first version. ### Commit 1: creation and views A 1D/2D/3D texture in format 67 with `ALLOW_UNORDERED_ACCESS`, one sample, no RT or DS flag, is stored as `R16G16B16A16_FLOAT` when the device that creates it reports no typed UAV for format 67. Unknown support never substitutes. On a host with native support (WARP) nothing changes. `R16G16B16A16_FLOAT` holds every RGB9E5 texel exactly: `rgb9e5_channels_are_exact_f16` checks all 16384 channel values. - `CreateCommittedResource` (slot 27, also reached from 76 and 83): decided after `depth_uav`, then through `res_pool::try_create` with the substituted desc. - `CreatePlacedResource` (slot 29): the substituted texture is twice the console layout reserved at that heap offset, so it is created committed with the heap's properties, the fallback `alias::committed_when_too_big` already uses. - `CreatePlacedResourceX` (slot 44): the substituted desc goes through `alias::create_placed_x`; `gpu_va` and `placed` keep the console desc, because the title's memory holds console texels. - The registry is a private-data mark on the resource. If the mark or the view hook cannot be set, the resource is released and creation returns `E_FAIL`. - SRV, UAV and RTV creation are hooked on the real device's method table (slots 18, 19, 20) at the first substitution. A view in format 67 on a substituted texture gets `R16G16B16A16_FLOAT`. An SRV with format `UNKNOWN` or a null desc gets an explicit view. SRV swizzles that read source alpha are forced to 1. Views in any other format are forwarded unchanged. - A texture in a CPU-visible heap is not substituted; the host rejects it as before. ### Commit 2: copies and uploads convert - Copies on the Xbox command list (slots 16, 17, 83, 84) with a substituted texture on one side and R9G9B9E5 on the other are staged through a DEFAULT-heap scratch buffer. A cs_6_0 shader (DXC, embedded root signature) converts the scratch in place: decode RGB9E5 words to RGBA16F texels, encode the reverse. Title resources are only touched by `CopyTextureRegion` / `CopyBufferRegion`, in the states the title set. - Copy-out to a footprint writes merged per-row `CopyBufferRegion` runs, so bytes between rows and outside the box are never written. - After the pass, the title's root signature, PSO, root arguments and descriptor heaps are restored with `cl2_state::reapply`, as `depth_uav` does. Predication is not touched. - Substituted to substituted, same host format: forwarded unchanged. - `CopyResource` (17) and `CopyResourceX` (84) between a substituted and an R9G9B9E5 texture with the same dimensions and mips: converted subresource by subresource. Slot 84 flags go through the existing `copy_resource_x_plan` validation first. - `upload.rs` mirrors title memory into a substituted texture: the detiler widens each RGB9E5 texel to RGBA16F while writing the host layout (`widen_span`), and host-side sizes use 8 bytes per texel. - Every converted copy is logged and counted; `note_gpu_write` is called on the destination. ### Still refused (logged and counted, nothing copied) These calls return void, so the title is not told. I list them so you can say which ones you want handled another way. - Conversion on a copy-queue list: the pass needs a compute dispatch. The console would do this copy; we do not. - Copies whose other side is not R9G9B9E5 (for example an RGBA16F footprint), between different substitutes, `CopyResource` with a buffer on one side or with mismatched dimensions, mips or array size, `CopyResourceX` whose flags fail the console validation. As far as I know none of these is a valid copy for an R9G9B9E5 texture on the console either. - DXC, PSO, root signature or scratch creation failure, a region past 32-bit scratch size, depth over 65535. - `upload.rs`: a substitute other than RGBA16F, or an XG element size other than 4 bytes. ### Not covered, not claimed - No title was run. - The scratch is one buffer per list origin, grown by powers of two from 64 KiB. A replaced scratch is never freed, because a recorded list may still reference it. A list executed on two queues at once would share it. - Slot 83 flags are ignored, as the chain bottom already does. - Non-canonical RGB9E5 words come back canonical after a decode and encode round trip: same value, maybe other bits. - Console rounding for its own RGB9E5 UAV stores is not known; this encode is the specification's. - Shader UAV stores keep f16 values: never less precise, within one RGB9E5 quantum for inputs in [0, 65408], no clamp of negatives, NaN or larger values. Typed UAV loads return the stored alpha. - Reserved resources are not substituted. `GetDesc` on a substituted texture returns the host format. `GetResourceAllocationInfo` answers with the console layout. The view hook covers at most four device method tables. - `device_wrap.rs` is not re-checked against #239 yet: #239 is still open. I will rebase and re-check when it lands. ### Tests Base `f89e410`, RTX 5090 PC, Windows 11, and WARP (`TOMBOX_HW_ADAPTER=warp`). - Unit, `cargo test -p d3d12_xs --release --lib`: 21 tests matching `uav_subst` / `rgb9e5` pass, among them `decode_matches_the_exact_value_of_every_channel` (all 16384 channel values and 100000 random words), the copy and resource-copy rule tables, scratch layout and run merging, `rgb9e5_texels_are_widened_to_rgba16f_while_detiling`. `upload`: 15 pass. - Hardware. WARP binds R9G9B9E5 as a typed UAV, so a test-only flag (`FORCE_NO_TYPED_UAV`) clears that bit and the conversion path runs there too. - `hw_rgb9e5_copies_out_of_a_substituted_texture_are_encoded_bit_exact`: 256x256 texels covering every f16 value per channel; whole footprint, boxed slot 83 copy with untouched padding, texture copy, `CopyResource`, `CopyResourceX`, compared bit-exact with a reference written in the test from the specification. - `hw_rgb9e5_copies_into_a_substituted_texture_are_decoded_exact`: every mantissa and exponent; footprint, boxed footprint with a marker kept outside the box, texture via slot 83, `CopyResource`. - `hw_rgb9e5_conversions_on_a_copy_queue_list_are_refused`. - The three tests of commit 1, adjusted: the slot 16 copy to an R9G9B9E5 footprint is checked bit-exact, the RGBA16F footprint copy is refused. - `hw_rgb9e5_title_memory_is_mirrored_into_a_substituted_texture` needs an `xg_xs.dll` on the search path. With the workspace's own one (`cargo build --release -p xg_xs`, `target/release` on `PATH`): 8192 title texels widened from RGB9E5 to RGBA16F on upload, twice (first upload, then after a CPU rewrite, no write lost). The layout there comes from the workspace's `xg_xs`, not a console DLL. - 7 of 7 pass on WARP and 7 of 7 on the RTX 5090. - Mutations: dropping the half-up rounding term in the HLSL encode makes the encode test fail on WARP (33027 of 65536 texels differ); moving the subnormal bound in `rgb9e5_half` makes the exact decode unit test fail. Both restored. - `hw_uav_subst_view_hook_cost_per_call` (commit 1): best of 9 rounds of 100000 calls, tens of nanoseconds per view at most, run-to-run noise larger than the hook's cost. - `pr_gate.py --base origin/main`: 0 problems. - [x] `cargo test -p d3d12_xs` passes for what is listed above - [x] No game or console files and no binaries included - [x] No fake success: the copies and uploads that were refused now convert; what is still refused is listed above, with a log line and a counter 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Sources for why a title would ask for this format:
- The public AMD FidelityFX SDK (MIT) DX12 backend maps an FFX R9G9B9E5
  surface one-to-one to DXGI_FORMAT_R9G9B9E5_SHAREDEXP and UAV usage to
  D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS, with no format conversion
  (backend/dx12/ffx_dx12.cpp, ffxGetDX12FormatFromSurfaceFormat).
- An Xbox build of the FidelityFX upscaler DLL shipped with a GDK title
  carries strings of that backend file and imports d3d12_xs.dll. No string
  in that DLL names R9G9B9E5, so which resource asks for the format is not
  established. No title was run for this commit.
Hosts without FORMAT_SUPPORT1_TYPED_UNORDERED_ACCESS_VIEW for that format
reject an R9G9B9E5 texture with ALLOW_UNORDERED_ACCESS with E_INVALIDARG.

Measured on this machine with CheckFeatureSupport(FORMAT_SUPPORT):
RTX 5090 reports Support1=0x8013f0 for R9G9B9E5 (no typed UAV) and rejects
the texture; WARP reports 0x2ecd3f1 and accepts it, so nothing changes there.

R16G16B16A16_FLOAT holds every RGB9E5 texel exactly: a channel is
m*2^(e-24) with m<512 and e<=31, at most 9 significant bits, a multiple of
the f16 subnormal step, and at most 65408. rgb9e5_channels_are_exact_f16
checks all 16384 channel values.

What this commit does (uav_subst.rs):
- Decides from the host's real Support1, queried with CheckFeatureSupport on
  the device that creates the resource. Unknown support never substitutes.
  Only 1D/2D/3D textures with ALLOW_UNORDERED_ACCESS, without RT or DS flags
  and with one sample are candidates.
- CreateCommittedResource (slot 27, also reached from 76/83): decided after
  depth_uav. depth_uav only claims DSV|UAV descs and its plan strips the UAV
  flag from the host desc, and the decision refuses DSV descs, so the two
  never act on one resource. The substituted desc then goes to
  res_pool::try_create, which sizes and places it from the desc it is given,
  so a pooled texture has the substitute format and size.
- CreatePlacedResource (slot 29): the substituted texture is twice the
  console layout the title reserved at that heap offset, so placing it there
  would overlap the title's next placement. It is created committed with the
  heap's properties, the fallback alias::committed_when_too_big already uses.
  The 4 KiB retry and committed_when_too_big are skipped for it.
- CreatePlacedResourceX (slot 44): the substituted desc goes through
  placed_offset::create (buffers only, so unaffected) and
  alias::create_placed_x, which sizes from the PC desc and gives a texture
  that outgrows the title layout its own heap limited to the title VA range
  (oversize_span). gpu_va and placed keep the console desc, because the
  title's memory holds console texels.
- The registry is a private-data mark on the resource, so it dies with the
  resource and a reused address is never mistaken for a substituted texture.
  If the mark or the view hook cannot be set, the resource is released and
  creation returns E_FAIL.
- SRV/UAV/RTV creation is hooked on the real device's method table (18/19/20)
  when the first substitution happens; every view path (wrapper slots,
  placed-view slots, title_heap, titles holding the real device) reaches it.
  A view with format R9G9B9E5 on a substituted texture gets RGBA16F. An SRV
  with format UNKNOWN or a null desc gets an explicit RGBA16F view. SRV
  swizzles that read source alpha are forced to 1, as an RGB9E5 read
  returns. Views with any other format are forwarded unchanged.

What this commit refuses:
- Textures in a CPU-visible heap are not substituted (CPU access would see
  8-byte texels); the host rejects them as before.
- upload.rs does not mirror title memory into a substituted texture yet: the
  adoption is refused and counted in the existing "NOT mirrored" log.
- Every copy on the Xbox command list (slots 16/17/83/84) with a substituted
  texture on either side is refused, counted and logged.

GetResourceAllocationInfo is not changed: it answers with the console layout,
which is what the title's memory holds, and the two placement paths above
handle a PC texture larger than that layout.

Not mapped: shader UAV stores keep f16 values (never less precise, within one
RGB9E5 quantum for inputs in [0, 65408], no clamp of negatives, NaN or larger
values); typed UAV loads return the stored alpha; reserved resources are not
substituted; ID3D12Resource::GetDesc on a substituted texture returns the host
format (R16G16B16A16_FLOAT), not the one the title asked for; the view hook
covers at most four device method tables.

Tests:
- Unit tests: decision table, view rewrite, default SRV, swizzle, copy rule,
  exactness, reference encoding, f16 rounding.
- hw_rgb9e5_typed_uav_texture_is_substituted (slot 76), RTX 5090: the host
  rejects the texture directly; through d3d12_xs it is RGBA16F; a compute UAV
  write read back through R9G9B9E5, UNKNOWN and null-desc SRVs gives 512 exact
  texels and 512 within one RGB9E5 quantum, alpha 1.0; both copies out of it
  are refused. Also passes with TOMBOX_RES_POOL=1 (log shows the pooled path).
- hw_rgb9e5_placed_textures_are_substituted_and_cpu_visible_heaps_are_not:
  slot 29 and slot 44 give RGBA16F textures, slot 44 keeps the console desc
  for title memory, a CUSTOM write-back heap stays rejected. RTX 5090.
- hw_uav_subst_view_hook_cost_per_call, RTX 5090, best of 9 rounds of
  100000 calls on a non-R9G9B9E5 texture: SRV with an explicit format 162 ns
  hooked vs 147 ns unhooked, UAV 156 vs 151 ns, SRV with a null desc (reads
  the private-data mark) 163 vs 140 ns. Over six runs the per-call
  difference ranged from -34 to +54 ns and the absolute numbers from 80 to
  170 ns: run-to-run noise is larger than the hook's cost, so this test
  only bounds it to tens of nanoseconds per view.
- All three skip on adapters with native typed UAV support (WARP).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The previous commit stores an R9G9B9E5 UAV texture as R16G16B16A16_FLOAT
when the host has no typed UAV for R9G9B9E5, and refused every copy and
every upload that touched it. This commit converts where the console
meaning is defined.

Conversion (uav_subst_copy.rs):
- Copies on the Xbox command list (slots 16, 17, 83, 84) are staged
  through a DEFAULT-heap scratch buffer. Title resources are only read or
  written by CopyTextureRegion/CopyBufferRegion, in the states the title
  set. The scratch goes COMMON, COPY_DEST, UNORDERED_ACCESS, COPY_SOURCE,
  COMMON.
- A cs_6_0 shader compiled with DXC, with an embedded root signature
  (9 root constants and one root UAV), converts the scratch in place in
  raw-buffer form: decode reads 4-byte RGB9E5 words and writes 8-byte
  RGBA16F texels, encode the reverse.
- Copy-out to a footprint writes merged per-row CopyBufferRegion runs,
  so bytes between rows and outside the box are never written.
- After the pass, the title's root signature, PSO, root arguments and
  descriptor heaps are restored with cl2_state::reapply, the same path
  depth_uav uses. Predication is not touched.
- One scratch buffer per list origin, grown by powers of two from
  64 KiB. A replaced scratch is kept alive, never freed, because a list
  already recorded may still reference it.
- Every converted copy is logged and counted; note_gpu_write is called on
  the destination.

Encode follows the Khronos EXT_texture_shared_exponent specification
(N=9, B=15, Emax=31, sharedexp_max=65408, negative and NaN clamp to 0,
round to nearest with half up), computed with exact integer arithmetic
on the f16 bits. Decode builds the exact f16 value with integer
arithmetic (rgb9e5_half, rgb9e5_to_rgba16f), alpha 1.0. No code was
taken from any other project.

What each former refusal became:
- Copy out of a substituted texture into an R9G9B9E5 footprint or an
  unsubstituted R9G9B9E5 texture (slots 16 and 83): encoded.
- Copy into a substituted texture from an R9G9B9E5 footprint or an
  unsubstituted R9G9B9E5 texture (slots 16 and 83): decoded.
- Substituted to substituted with the same host format: forwarded
  unchanged, the bytes are already the same representation.
- CopyResource (slot 17) and CopyResourceX (slot 84) between a
  substituted and an R9G9B9E5 texture with the same dimensions and mips:
  converted subresource by subresource. Slot 84 flags first go through
  the existing copy_resource_x_plan validation.
- upload.rs mirroring of title memory into a substituted texture: no
  longer refused. The detiler widens each RGB9E5 texel to RGBA16F while
  writing the host layout (widen_span), and all host-side sizes use
  8 bytes per texel.

Still refused, logged and counted (nothing copied):
- Conversion on a copy-queue list: the pass needs a compute dispatch.
- Copies whose other side is not R9G9B9E5, for example an RGBA16F
  footprint: the console has no such copy for an R9G9B9E5 texture.
- Copies between different substitutes.
- CopyResource with a buffer on one side, or with mismatched
  dimensions, mips or array size.
- CopyResourceX whose flags fail the console validation.
- DXC, PSO, root signature or scratch creation failure, a region past
  32-bit scratch size, or depth over 65535.
- upload.rs: a substitute other than RGBA16F for RGB9E5, or an XG
  element size other than 4 bytes.
- Textures in CPU-visible heaps are still not substituted.

Limitations:
- The scratch is per list origin; a list executed on two queues at once
  would share it.
- Slot 83 flags are ignored, as the chain bottom already does.
- Non-canonical RGB9E5 words (a value with several encodings) come back
  canonical after a decode and encode round trip: the value is exact,
  the bits may differ.
- Console hardware rounding for its own RGB9E5 UAV stores is not known;
  this encode is the specification's.

Tests:
- Unit: 21 tests matching uav_subst/rgb9e5 pass, among them
  decode_matches_the_exact_value_of_every_channel (all 16384 channel
  values and 100000 random words), copy and resource-copy rule tables,
  scratch layout and run merging, and
  rgb9e5_texels_are_widened_to_rgba16f_while_detiling. upload: 15 pass.
- Hardware, run on WARP (TOMBOX_HW_ADAPTER=warp) and on the RTX 5090.
  WARP binds R9G9B9E5 as a typed UAV, so a test-only flag
  (FORCE_NO_TYPED_UAV) clears that bit and the conversion path runs
  there too.
  - hw_rgb9e5_copies_out_of_a_substituted_texture_are_encoded_bit_exact:
    256x256 texels covering every f16 value per channel; whole
    footprint, boxed slot 83 copy with untouched padding, texture copy,
    CopyResource and CopyResourceX, compared bit-exact with a reference
    written in the test from the specification.
  - hw_rgb9e5_copies_into_a_substituted_texture_are_decoded_exact:
    every mantissa and exponent; footprint, boxed footprint with a
    marker kept outside the box, texture via slot 83, CopyResource.
  - hw_rgb9e5_conversions_on_a_copy_queue_list_are_refused.
  - The three tests from the previous commit, adjusted: the slot 16 copy
    to an R9G9B9E5 footprint is checked bit-exact, the RGBA16F footprint
    copy is refused.
  6 of 7 pass on WARP and 6 of 7 on the RTX 5090.
  hw_rgb9e5_title_memory_is_mirrored_into_a_substituted_texture needs
  xg_xs.dll, which this machine does not have; it fails at load on both,
  as the existing upload_ww_hw tests do here. The upload path is covered
  only by the unit test.
- Mutation checks: dropping the half-up rounding term in the HLSL encode
  made the encode test fail on WARP (33027 of 65536 texels differ);
  changing the subnormal bound in rgb9e5_half made the exact decode unit
  test fail. Both restored.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:17:00 +00:00
Author
Owner

@⁠omonkeyz on GitHub · 2026-11-23 13:31 UTC · original

Review, changes needed: (1) the commit message cites a GPL-2.0 project; that code can't come into a GPL-3 tree, and the name must not be in the history, so please reword it. (2) Copies on slots 16/17/83/84 that touch a substituted texture, and title-memory mirroring into it, are refused. Those calls return void, so the title sees success while the data never moves. That is accept-and-drop, which the project rules out. Copies and uploads need a real RGB9E5<->RGBA16F conversion. Also re-check device_wrap.rs once #239 lands.

**@⁠omonkeyz** on GitHub · 2026-11-23 13:31 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/277#issuecomment-7102656054) Review, changes needed: (1) the commit message cites a GPL-2.0 project; that code can't come into a GPL-3 tree, and the name must not be in the history, so please reword it. (2) Copies on slots 16/17/83/84 that touch a substituted texture, and title-memory mirroring into it, are refused. Those calls return void, so the title sees success while the data never moves. That is accept-and-drop, which the project rules out. Copies and uploads need a real RGB9E5<->RGBA16F conversion. Also re-check device_wrap.rs once #239 lands.
Author
Owner

@⁠QuentinDanblon on GitHub · 2026-11-23 13:58 UTC · original

Thanks for the review, both points are fair. As I said on #279, I've stopped writing code and PRs for now, so I won't make these changes. Feel free to close this PR, or leave it open if someone wants to take it over. Since its commit is only on this branch, closing it keeps that name out of the history.

**@⁠QuentinDanblon** on GitHub · 2026-11-23 13:58 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/277#issuecomment-7103289437) Thanks for the review, both points are fair. As I said on #279, I've stopped writing code and PRs for now, so I won't make these changes. Feel free to close this PR, or leave it open if someone wants to take it over. Since its commit is only on this branch, closing it keeps that name out of the history.
Author
Owner

@⁠QuentinDanblon on GitHub · 2026-11-23 17:30 UTC · original

Correction to my earlier reply: I picked this back up, so please disregard "I won't make these changes". Both points of your review are addressed in the force-pushed branch (7fff05a, base f89e410):

  1. The commit message is reworded. The GPL-2.0 project is no longer named anywhere in the branch history (git log origin/main.. has no match). The source for the format is now the FidelityFX SDK (MIT) DX12 backend, facts only.
  2. Copies and uploads now convert. A second commit stages slot 16/17/83/84 copies through a scratch buffer and converts with a compute pass (RGB9E5 to RGBA16F and back, bit-exact against a reference written from the Khronos spec), and upload.rs widens each texel while detiling. Hardware tests pass on WARP and the RTX 5090; the upload one needs xg_xs.dll here, so that path is covered by a unit test only.

What is still refused, since those calls return void too:

  • Conversion on a copy-queue list (no compute dispatch there). The console would do this copy, so it is a drop. If you prefer, I can make the list fail at Close instead, or run the pass on a compute list of our own.
  • Copies whose other side is not R9G9B9E5, mismatched CopyResource shapes, CopyResourceX flags that fail the console validation. As far as I know these are not valid copies for an R9G9B9E5 texture on the console either.
  • Internal failures (DXC, PSO, scratch creation).

#239 is still open, so device_wrap.rs is not re-checked against it yet. I will rebase and re-check when it lands. The PR body has the full list of what is done, refused and not claimed.

**@⁠QuentinDanblon** on GitHub · 2026-11-23 17:30 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/277#issuecomment-7108760869) Correction to my earlier reply: I picked this back up, so please disregard "I won't make these changes". Both points of your review are addressed in the force-pushed branch (`7fff05a`, base `f89e410`): 1. The commit message is reworded. The GPL-2.0 project is no longer named anywhere in the branch history (`git log origin/main..` has no match). The source for the format is now the FidelityFX SDK (MIT) DX12 backend, facts only. 2. Copies and uploads now convert. A second commit stages slot 16/17/83/84 copies through a scratch buffer and converts with a compute pass (RGB9E5 to RGBA16F and back, bit-exact against a reference written from the Khronos spec), and `upload.rs` widens each texel while detiling. Hardware tests pass on WARP and the RTX 5090; the upload one needs `xg_xs.dll` here, so that path is covered by a unit test only. What is still refused, since those calls return void too: - Conversion on a copy-queue list (no compute dispatch there). The console would do this copy, so it is a drop. If you prefer, I can make the list fail at `Close` instead, or run the pass on a compute list of our own. - Copies whose other side is not R9G9B9E5, mismatched `CopyResource` shapes, `CopyResourceX` flags that fail the console validation. As far as I know these are not valid copies for an R9G9B9E5 texture on the console either. - Internal failures (DXC, PSO, scratch creation). #239 is still open, so `device_wrap.rs` is not re-checked against it yet. I will rebase and re-check when it lands. The PR body has the full list of what is done, refused and not claimed.
Author
Owner

@⁠QuentinDanblon on GitHub · 2026-11-23 18:07 UTC · original

Update on the one hardware test I could not run: hw_rgb9e5_title_memory_is_mirrored_into_a_substituted_texture only needs an xg_xs.dll on the search path, and the workspace builds one. With cargo build --release -p xg_xs and target/release on PATH, it passes on the RTX 5090 and on WARP: 8192 title texels widened from RGB9E5 to RGBA16F on upload, twice, no CPU write lost. So 7 of 7 hardware tests pass on both. The layout in that run comes from the workspace xg_xs, not a console DLL. PR body updated.

**@⁠QuentinDanblon** on GitHub · 2026-11-23 18:07 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/277#issuecomment-7109690232) Update on the one hardware test I could not run: `hw_rgb9e5_title_memory_is_mirrored_into_a_substituted_texture` only needs an `xg_xs.dll` on the search path, and the workspace builds one. With `cargo build --release -p xg_xs` and `target/release` on `PATH`, it passes on the RTX 5090 and on WARP: 8192 title texels widened from RGB9E5 to RGBA16F on upload, twice, no CPU write lost. So 7 of 7 hardware tests pass on both. The layout in that run comes from the workspace xg_xs, not a console DLL. PR body updated.
Author
Owner

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

Thanks, the conversion work looks right and the history is clean now. One drop is left: a copy on a copy-queue list that needs conversion is refused while the void call reports nothing. Please take one of the two options you offered, either running the pass on an internal compute list and syncing the copy queue to it, or failing the list at Close with the reason logged. Then it can be applied.

**@⁠omonkeyz** on GitHub · 2026-11-25 13:51 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/277#issuecomment-7164382362) Thanks, the conversion work looks right and the history is clean now. One drop is left: a copy on a copy-queue list that needs conversion is refused while the void call reports nothing. Please take one of the two options you offered, either running the pass on an internal compute list and syncing the copy queue to it, or failing the list at Close with the reason logged. Then it can be applied.
github-bot closed this pull request 2026-11-27 11:59:30 +00:00

Pull request closed

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