Skip to content

RT-24: FSR's Xbox backend descriptor, the console command-list map, and two runtime fixes (XMem, device slot 67) - #864

Merged
ItsNotRexed merged 3 commits into
ItsNotRexed:mainfrom
omardev29:rt-fsr-xbox-backend
Nov 22, 2026
Merged

ItsNotRexed merged 3 commits into
ItsNotRexed:mainfrom
omardev29:rt-fsr-xbox-backend

Conversation

@omardev29

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: RT-24 (#634 (comment))

What and why

The package ships AMD's FSR upscaler built for the console, amd_fidelityfx_upscaler_xbox.dll. It is compiled against the console D3D12, so every call it makes is evidence of the console ABI. RT-3 (#302) could not get it past ffxCreateContext: the Xbox backend descriptor was unknown, and the DLL failed before it touched the device.

This PR finds that descriptor in the DLL (Ghidra 12.2 through REA), runs the DLL through the Xbox-ABI device proxy, and records one ffxDispatch into a logging command list. That gives the first measured map of the console command list, and it turned up two runtime bugs.

What it finds

Result
Backend descriptor Type 0x01000002, {header, device} with the device at +0x10 (RT-3 tried 0x0200000x). With it, the DLL creates its backend through the proxy.
Console device Slots 14, 15, 18, 19, 27, 38 and 76 and heap slot 9 have the shapes the PC order and the measured overrides predict. Slot 76 takes the 7 CreateCommittedResource arguments. Slot 67 is a console-only compute-pipeline call, not the PC method at that index.
Console command list Not the PC order after ResourceBarrier (26). SetDescriptorHeaps is at 32 (PC 28), the compute root setters follow four slots later, ExecuteIndirect is at 61 (PC 59, two later), and 85 and 141 are console-only. Full table in docs/d3d12_command_objects.md §3.5a.
"Fast path" The list object has a write cursor at +0x18 with limits at +0x28/+0x30. While there is room, the DLL writes root arguments and dispatches into that buffer itself instead of calling the vtable. With the cursor at the limit, every command goes through the vtable. These are the fields §3.4 measured in the BVH builder without knowing what they were for.
Where a PC device stops The DLL's 29 shaders are DXBC with an ACCC part (payload tag FSPX) and no DXIL, so the PC runtime refuses its compute pipeline (slot 62). Running FSR needs that code translated; it does not need the executable.

Why it matters for the layer: Leonida's command list (d3d12_com.cpp) uses the PC ID3D12GraphicsCommandList8 vtable order. If the game is built like these two shipped DLLs (Microsoft's BVH builder and AMD's FSR), its SetDescriptorHeaps and root-argument calls would land on other methods. That is silent corruption from the first recorded frame. §3.4 said a public-order list was safe for the game's own public calls; that sentence is corrected here.

Runtime fixes

  • XMemGetWorkingSetStatistics takes (kind, stats*). All seven FSR call sites pass 0x20000001 in ECX and a stack buffer in RDX. The one-argument shim wrote to address 0x20000001.
  • Device slot 67 is refused (E_NOTIMPL) instead of being forwarded to the PC CreateProtectedResourceSession1.

What is measured and what is not

  • Each command-list row says whether it was seen in the run or comes only from the call's argument shape. Two rows (33 SetComputeRootSignature, 41 SetComputeRootConstantBufferView) are marked inferred.
  • About 12 of the console list's ~150 slots are mapped. The rest, plus queue, fence and present, still need the executable.
  • Whether the game uses the same fast-path check is unknown until the executable is available.
  • On an RTX 2000 Ada (driver 597.06) the context needs one PC stand-in: the driver refuses an R9G9B9E5_SHAREDEXP texture with ALLOW_UNORDERED_ACCESS, so the test creates it as R32_UINT. WARP takes it as is. Vulkan on the same GPU has no storage support for that format either, so the layer will need an emulation.
  • Docs give RVAs, offsets and values only; nothing from the DLL is quoted.

What's in it

File Change
runtime/test/fsr_dispatch_test.cpp The measured backend descriptor; a stand-in for the refused texture; a logging command list (forwards only measured slots, never executed); fault reports with module/RVA, the C++ throw and unwound stack, and the HRESULT the DLL's error check formats
runtime/test/ffx_api_min.h Public FidelityFX dispatch and resource declarations (MIT SDK headers)
runtime/shims/xmem.cpp, xmem_test.cpp, test_runtime_types.cpp The two-argument XMemGetWorkingSetStatistics
runtime/shims/d3d12_xs_device.cpp, device_proxy_test.cpp Device slot 67 refused
docs/d3d12_command_objects.md §3.5a (the map, the fast path, the pipeline paths), a correction in §3.4
docs/d3d12_vulkan.md Appendix A.3 and open question 2
docs/design.md, runtime/README.md The XMem signature

Tested

  • Windows 11, MSVC 14.51, Vulkan SDK 1.4.363.1: full runtime build, ctest 32/32 after rebasing on 4a36bb1.
  • fsr_dispatch_test with LEONIDA_GAME_DIR on my own 1.0.2.1 copy (SHA-256 matches game/xbox-1.0.2.1.json): OK on an RTX 2000 Ada (597.06), OK with LEONIDA_FSR_WARP=1, OK with LEONIDA_FSR_NO_STANDIN=1, and SKIP (no package) without the package. Both devices record the same 13 command-list calls in the same order.
  • bvh_builder_test fails on this GPU the same way on main without this PR (0xC0000409 after slot 62), so that is not from this change.

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (Not a translator change.)

AI-assisted.

…gSetStatistics and device slot 67

amd_fidelityfx_upscaler_xbox.dll, measured with Ghidra 12.2 (through REA)
and run by fsr_dispatch_test on PC devices (RTX 2000 Ada and WARP) behind
the Xbox-ABI proxy.

Backend descriptor: the provider's create walks the chain for type
0x01000002, {header, device} with the device at +0x10, and ends in
FFX_API_RETURN_ERROR without it (what RT-3 got with 0x0200000x). With it
the DLL creates its backend through the proxy: device slots 14, 15, 18, 19,
27, 38 and 76 and heap slot 9, at the shapes the PC order and the measured
overrides predict; slot 76 takes the seven CreateCommittedResource
arguments. No earlier test here reached slot 76 or heap slot 9.

Two runtime bugs it found:
- XMemGetWorkingSetStatistics takes (kind, stats*): all seven call sites
  pass kind 0x20000001 in ECX and a stack buffer in RDX. The one-argument
  shim wrote to address 0x20000001.
- Device slot 67 is a console-only compute-pipeline call (a code blob in its
  desc), not the PC CreateProtectedResourceSession1 the proxy forwarded it
  to. The proxy now refuses it (E_NOTIMPL).

The context: on the RTX 2000 Ada the create stops at the DLL's HRESULT
check, because the driver refuses its R9G9B9E5_SHAREDEXP texture with
ALLOW_UNORDERED_ACCESS (WARP takes it). The test reports that stop and
retries with one PC stand-in (that texture as R32_UINT). On the context it
records one ffxDispatch into a logging command list that is never executed.

The console command list, from that run and the DLL's recorder (RVA
0x59a0), the same 13 calls on both devices: slots 14, 15, 25 and 26 at
their PC positions, then SetDescriptorHeaps at 32 (PC 28, seen in the run),
SetComputeRootDescriptorTable at 35 (PC 31), ClearUnorderedAccessViewUint
at 53 (PC 49, seen in the run), ExecuteIndirect at 61 (PC 59), and
console-only methods at 85 and 141. 33 and 41 fit SetComputeRootSignature
and SetComputeRootConstantBufferView by shape; the docs mark them inferred.
The logging list forwards only measured slots. The list object also carries
a write cursor and limits (+0x18, +0x28, +0x30) the DLL writes root
arguments and dispatches through while there is room; with the cursor at
the limit every command takes the vtable. These are the fields docs section
3.4 measured in the BVH builder without a meaning.

The dispatch stops at the DLL's compute pipeline: its 29 shaders are DXBC
with an ACCC part (payload tag FSPX) and no DXIL, and the PC runtime
refuses them at slot 62; the dispatch goes on with the null pipeline and
faults, which the test reports as the documented PC limit. Its C++ `throw`
also shows the loader gap: _CxxThrowException finds no image base for a
manually mapped image.

The test's fault report gives the faulting module and RVA, the access, the
C++ throw's ThrowInfo, image base and unwound stack, and the HRESULT the
DLL formatted with the DLL frames that made the failing call.

Docs: d3d12_vulkan.md Appendix A.3 and open question 2,
d3d12_command_objects.md 3.4 and 3.5a, design.md and runtime/README.md.
@Vonsek

Vonsek commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

I checked the RGB9E5 resource requirement described on 3da355d with synthetic compute shaders and textures. For a 1920×1080 R9G9B9E5_SHAREDEXP default-heap texture with ALLOW_UNORDERED_ACCESS, native D3D12 returned:

Device CreateCommittedResource Advertised typed UAV view / load / store
RTX 5080 (616.92) E_INVALIDARG no / no / no
AMD Radeon Graphics (32.0.21045.16010) S_OK yes / yes / yes
WARP S_OK yes / yes / yes

On Radeon and WARP I also wrote 32 representable RGB triples through an actual typed float UAV on an 8×4 texture, transitioned it to an SRV, and point-sampled it. All 128 float channel bit patterns matched the CPU expectations on each device. Vulkan likewise reports native packed-format storage support on this Radeon. On the RTX, the packed format supports sampling, while requesting combined storage+sampled usage returns VK_ERROR_FORMAT_NOT_SUPPORTED.

There is a shared-image option for the RTX fallback. I created a mutable R32_UINT Vulkan image with R32_UINT and E5B9G9R9_UFLOAT_PACK32 in its format list. The storage view restricted its usage to STORAGE, and the shared-exponent view to SAMPLED. A compute dispatch wrote packed integers through the former; a second dispatch point-sampled the latter after a shader write→read barrier. Both physical GPUs reproduced all 128 expected float bit patterns across 32 texels and 12 exponents with zero validation errors. Swapping only the red/blue mantissas in the writer caused exactly 32/32 texels to differ from the original expectation, and all matched the swapped expectation.

This establishes a way to keep the packed storage and sampled view on one allocation when native packed storage is unavailable. The test writer already knows the packed word. An implementation for float shader stores would still need the pack operation and tests for its rounding. These measurements cover the resource and shader-view contract; they do not execute FSR.

@omardev29

omardev29 commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks @Vonsek, that matches what I measured (NVIDIA refuses, WARP takes it) and adds the AMD case and a fallback that keeps one allocation. Added both to Appendix A.3 with credit (3f714d3).

@Vonsek

Vonsek commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

I tested the remaining float-to-RGB9E5 conversion in Appendix A.3. Native Radeon and WARP produced different packed words for 609 of 794 input triples. The earlier 32-colour test used exactly representable values, so it could not distinguish the two rules.

I uploaded the same binary32 input words to separate native D3D12 runs. A compute shader used RWTexture2D<float3> to store them, then CopyTextureRegion copied the texture into a readback buffer. I compared the packed little-endian dwords directly. The 794 cases included one binary32 ULP below, exactly at and above a half-step, shared-exponent rollover, component permutations, saturation and special values, plus 512 deterministic finite triples (seed 864). Six padding texels are excluded.

RGB input Radeon Graphics 32.0.21045.16010 WARP
(0.005859375, 1.30078125, 0.1328125) 0x808a9a01 0x808a9a02
(1.998046875, 0.458984375, 0.033203125) 0x8020ebff (exponent 16) 0x88107700 (exponent 17)

A CPU reference using exact rational values matched all 794 Radeon results when it truncated each nonnegative mantissa at the shared scale. Round-to-nearest-even matched all 794 WARP results, including recomputing all three mantissas when rounding the largest one requires a larger exponent. Both gave the saturated maximum for positive infinity, and zero for the tested quiet-NaN channel while preserving the others.

On RTX 5080, two integer implementations of these rounding rules wrote to the mutable R32_UINT storage image from the earlier experiment. An image-to-buffer copy reproduced the corresponding native reference for every packed word. Exchanging the rules introduced exactly the same 609 mismatches. Khronos validation reported zero errors.

This leaves a target choice before a production fallback. My measurements establish both PC behaviours; they do not establish which one the console FSR shader requires, or that it uses a float store. Would you prefer a source-built rounding regression keyed to a second RDNA2 measurement before choosing a fallback rule?

@omardev29

Copy link
Copy Markdown
Contributor Author

I can't say which rule the console needs yet. The FSR shaders are still undecoded (ACCC/FSPX), so I don't know whether they write that texture with a float store at all or pack the word themselves. I'd leave the fallback rule open until that is known; a measurement on RDNA2 hardware would be the right reference, and I don't have one. Noted the difference in A.3 as open, with credit (582318c).

@quackottu quackottu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested 582318c on NVIDIA GeForce RTX 5070, driver 621.24, Windows 11 Pro (26300), VS 2022 Build Tools, Vulkan SDK 1.4.363.0, with LEONIDA_VK_VALIDATION=1 and LEONIDA_D3D12=vulkan: pass

  • ctest -C RelWithDebInfo: 100% tests passed, 0 tests failed out of 32
  • device_proxy_test (changed here): exit=0 validation=0 | [rt] d3d12_xs: device slot 62 (Xbox CreateComputePipelineState) first call
  • fsr_dispatch_test (changed here): exit=0 validation=0 | SKIP (no package)
  • xmem_test (changed here): exit=0 validation=0 | [rt] xmem: XMemVirtualQuery: fields after MEMORY_BASIC_INFORMATION are unknown; the 64-byte output is zero-filled there
  • 33 test programs in the build pass with 0 validation errors
  • d3d12_clear_test fails (R8G8B8A8_UNORM/SNORM 0.5 ties and a D16 clear byte differ from WARP) exactly as on main 4a36bb1 here, so not from this PR; #521 addresses it

Implicit Vulkan layers (overlays) were off through an empty VK_IMPLICIT_LAYER_PATH.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants