Commit Graph

40 Commits

Author SHA1 Message Date
tf
6946344eb0 d3d12_xs: derive pipeline states for device slot 55
Slot 55 is the console's CreateDerivedPipelineState(pBasePSO, n, pRecords,
riid, ppv): n = 1..4 records of 0x14c bytes (a u32 tag, payload at +4) that
patch the base PSO's state before a new PSO is created.

- Slot 86 keeps a deep copy of the stream it creates on the returned PSO
  (ID3D12Object private data, released with the PSO): shader bytecode,
  stream-output and input-layout arrays and strings, cached blobs, and
  AddRef'd root signatures.
- Slot 55 patches a copy of the base stream and creates the PSO through the
  slot 86 path, so a derived PSO can itself be a base.
- Tags: 0 = DEPTH_STENCIL (or the DEPTH_STENCIL1 prefix), 1 = RASTERIZER,
  2 = BLEND, 3 = sample mask (TomBox layout; the 1.0.2.1 title does not write
  it), 5 = StencilReadMask and StencilWriteMask bytes overlaid on the base's
  DEPTH_STENCIL, applied in record order. Other tags are refused.
- A base not created through slots 86/55, a base without the matching
  subobject, malformed records, and n outside 1..4 are refused with E_FAIL or
  E_INVALIDARG and a null output, each logged once.
- Slot 55 shadows PC CreateReservedResource1 (PC slot 55) on the proxy, as
  slot 78 shadows PC CreateReservedResource2 in #7125; the vulkan device test
  calls the PC method on the real device behind the proxy.

Tests: pso_stream_test (synthetic streams: console subobject offsets, deep
copy, patching, tag 5 overlay and record order, refusals) and
device_proxy_test over WARP (refusals, graphics base via slot 86, n = 3 and
n = 4 derivations, a derivation from a derived PSO).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LwHrL5Lxc1rum25b6tnpo8
(cherry picked from commit d80c40845d7eca9163f937de943b65482b7f0657)
2026-11-23 21:10:16 +00:00
ed7efccf31 d3d12: strip incompatible UAV flags from Xbox resource descriptions
(cherry picked from commit a9c59607b8ad94f7982bc5d63dd22a9fe41cb58e)
2026-11-23 21:09:19 +00:00
49dd742828 Merge branch 'pr7685' into ladder-frame
# Conflicts:
#	runtime/shims/d3d12_xs_device.cpp
#	runtime/shims/d3d12_xs_device.h
2026-11-23 19:56:00 +01:00
bd6b147b16 Merge branch 'pr7880' into ladder-frame
# Conflicts:
#	runtime/shims/d3d12_xs_device.cpp
#	runtime/shims/d3d12_xs_device.h
#	runtime/test/xs_proxy_mock_test.cpp
2026-11-23 19:55:34 +01:00
54840e3e92 Merge branch 'pr7201' into ladder-frame
# Conflicts:
#	runtime/shims/d3d12_xs_device.cpp
#	runtime/shims/d3d12_xs_device.h
#	runtime/test/xs_proxy_mock_test.cpp
2026-11-23 19:29:28 +01:00
f5b7ebf918 Merge branch 'pr7679' into ladder-frame 2026-11-23 19:23:16 +01:00
297d0f64a0 Merge branch 'pr7110' into ladder
# Conflicts:
#	runtime/shims/d3d12_xs_device.cpp
#	runtime/shims/d3d12_xs_device.h
#	runtime/test/xs_proxy_mock_test.cpp
2026-11-23 18:54:43 +01:00
4081189163 Merge branch 'pr7021' into ladder
# Conflicts:
#	runtime/shims/d3d12_xs_device.cpp
#	runtime/shims/d3d12_xs_device.h
#	runtime/test/xs_proxy_mock_test.cpp
2026-11-23 18:53:28 +01:00
ec75996541 Merge branch 'pr6954' into ladder
# Conflicts:
#	runtime/shims/d3d12_xs_device.cpp
#	runtime/test/xs_proxy_mock_test.cpp
2026-11-23 18:52:17 +01:00
0aba6c3611 d3d12_xs: translate title-owned CPU descriptor handles in ListProxy and preserve ClearDepthStencilView FLOAT Depth
#7021 translates title-owned CPU descriptor handles (__XMemAllocationHooks__) on
device slots 17-24, and #2490 wraps console-ABI command lists in ListProxy, but
neither wires translate_cpu_handle into the five graphics command-list methods
that consume CPU descriptor handles:
- console slot 50 (PC 46): OMSetRenderTargets (RTV array / single-range + DSV)
- console slot 51 (PC 47): ClearDepthStencilView (DSV handle)
- console slot 52 (PC 48): ClearRenderTargetView (RTV handle)
- console slot 53 (PC 49): ClearUnorderedAccessViewUint (CPU handle; GPU kept)
- console slot 54 (PC 50): ClearUnorderedAccessViewFloat (CPU handle; GPU kept)

Also installs a typed WINAPI thunk for console slot 51 (ClearDepthStencilView):
on the Windows x64 ABI, FLOAT Depth (4th argument) is passed in XMM3 rather than
R9, so the generic all-uint64_t list_slot template dropped/clobbered Depth before
forwarding to the real list.

Adds synthetic mock coverage across all five slots (including single-range RTVs,
null/zero-RTV cases, count > 8 bounds safety, outside-range passthrough, and
XMM3 float preservation) plus an end-to-end WARP/Vulkan GPU clear and readback
check in device_proxy_test.
2026-11-23 17:41:55 +00:00
ce3f2dbdef Merge #7021 (descriptor heap XMem hooks) into #2490 (console command-list proxy) 2026-11-23 17:34:26 +00:00
4a86034367 d3d12_xs: a console depth-stencil texture with unordered access is sized and created without it (stand-in)
The console allows ALLOW_DEPTH_STENCIL | ALLOW_UNORDERED_ACCESS on a texture; the PC runtime refuses the pair and
slot 25 answered UINT64_MAX for it. pc_resource_flags drops the UAV bit from depth-stencil textures (slot 25 through
pc_resource_desc, and slot 76). Their UAV views then write no descriptor.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 18:19:14 +01:00
afb14d56c6 PresentX: device-side WaitFrameEventX and the frame pacer share one token source
Device slot 80 (WaitFrameEventX, from #6935) numbered its tokens with a
counter of its own, while XboxPresentation's pacer refuses any token above
the ones it issued itself. A title that waits through the device and
presents through the device's XboxPresentation therefore had every
PresentX refused with E_INVALIDARG once its tokens ran ahead of the
pacer's.

leonida::FrameTokenSource is now the counter both use: a pacer takes an
optional shared source (a standalone pacer still owns its own and numbers
as before), the device proxy owns one and exposes it through
rt::d3d12_xs::device_frame_tokens, and XboxPresentation passes a given
source to its pacer. A token that was never issued is still refused.

Reported by rafaelpssz in #7496.
2026-11-23 12:16:11 -05:00
b4d1ba1794 d3d12: preserve PC descriptor validation in slot 25 2026-11-23 11:37:29 -05:00
d7451f9d9b test: device_proxy_test expects slot 25 to answer for the cleaned description, the PC device's answer for the console layout word is UINT64_MAX (found by devnull34 on #7110) 2026-11-23 17:34:42 +01:00
a2efc80b93 d3d12_xs: use 56-byte D3D12_RESOURCE_DESC stride for slot 108 descriptor array 2026-11-23 17:26:35 +01:00
40360ccb4f Merge #6964 (slot 26 console form) into fast-rtbudget: slot 26 from #6964, slot 25 return-buffer form kept from #6973 2026-11-23 17:18:32 +01:00
824a17f01a Merge origin/main into fast-rtbudget 2026-11-23 17:17:50 +01:00
dc29ee3471 d3d12_xs: route device slots 86, 101, and 108 to PC Device2/Device5/Device8 2026-11-23 17:10:24 +01:00
0d73e8b95d Merge origin/main: slot 26 next to the Xbox slot routes
AI-assisted.
2026-11-23 16:59:58 +01:00
f20e99a528 Merge main 108c36ef7 into #6954
Slot 48 goes through proxy_create_command_queue_xbox (filtered 16-byte prefix) via main's
queue_x route; the explicit slot 48 branch and the duplicate note_slot are gone. The
slot-48 header, slot name and tests follow, and device_proxy_test passes a 32-byte desc.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 16:56:08 +01:00
2dbcb882c9 d3d12_xs: route the public HLE's Xbox device slots 48/73/78/79/80 (#6935)
Squash-merged after diff review of PR #6935 - d3d12_xs: route the public HLE's Xbox device slots 48/73/78/79/80
2026-11-23 09:42:42 -06:00
355201c51e d3d12_xs: honour __XMemAllocationHooks__ for descriptor heaps and translate CPU handles 2026-11-23 23:42:40 +08:00
86b8e04e4c d3d12_xs: device slot 26 takes the console's struct-return form
The retail executable calls GetCustomHeapProperties with the return buffer in RCX and the device in RDX. The forwarder took RCX for the proxy and faulted.

AI-assisted.
2026-11-23 16:33:12 +01:00
5dbc30bed7 d3d12_xs: device slots 25/26 take the title's C-ABI struct return
The retail executable calls GetCustomHeapProperties (device slot 26) with the
C convention: the hidden return buffer in RCX and the device in RDX. The
proxy's generic forwarder assumed the PC C++ form (this in RCX, buffer in
RDX), took the buffer for the device and crashed on its vtable right after
D3D12XboxCreateDevice.

Slots 25 (GetResourceAllocationInfo, same rule, inferred) and 26 (measured)
now get thunks that accept either form: whichever of the first two arguments
is the device proxy is `this`. The runtime's own code still calls the proxy
through d3d12.h in the PC form. device_proxy_test calls both slots in both
forms against WARP.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 16:32:28 +01:00
21f3da2621 Merge pull request #4650 from kingzzim7-create
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 23:16:49 -05:00
0eb3a7698c d3d12_xs: print D3D12XboxCreateDevice's parameter words with --trace-d3d12 too (RT-310) 2026-11-23 08:42:50 +05:00
a1ec0cbca9 d3d12_xs: a proxied call writes no shared atomic after the first call of its slot
note_slot, note_heap_slot and note_child_slot did a fetch_add on the slot's hit
counter and a compare_exchange_strong on its first-call flag for each proxied
call. The compare-exchange takes the cache line for writing also when it
fails, and the flags of all slots share one or two lines, so threads that
call different slots slowed each other.

The first-call flag is now read before the compare-exchange. The hit counters
are test helpers: they count from the first call of a *_slot_hits reader or
of reset_device_proxy_stats, so a title's calls do not write them.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-23 04:50:46 +03:00
f61946cfe1 Merge pull request #1795 from AimLogin 2026-11-22 09:15:24 -05:00
2123a02506 Runtime: Xbox-ABI proxy for the command allocator (device slot 9)
Device slot 9 (CreateCommandAllocator) now returns an allocator proxy,
the fourth command object after the queue and fence (BUILD-231) and the
list (D3D-136): the public chain (9 slots, Reset at 8) is forwarded, a
slot past it up to the end of a 64-slot table is logged and refused with
E_NOTIMPL, and a read past the table faults in its own guard region. The
console allocator's extra methods are not measured and not guessed.

A list takes the title's allocator in CreateCommandList and Reset, so a
proxy is only safe where the list side resolves it. Slot 9 therefore
wraps an allocator only when it answers kLeonidaCommandAllocatorTag (the
Vulkan layer's CommandAllocator, whose from() resolves the proxy for both
calls); a PC runtime allocator is handed out unchanged, logged once,
until a command-list proxy unwraps it at Reset. Allocator proxies are
unwrapped in the residency calls like heap, queue and fence proxies.
Device slot 12 is not touched.

Tests: allocator_proxy_test (WARP, a hardware adapter, the Vulkan device:
forwarding, refused tail, guard region, identity, D3D12's allocator rules,
a list created and Reset on the proxy with GPU copies through the queue
and fence proxies read back), mock cases for allocators with and without
the tag and their failure paths, and device_proxy_test's slot-9
expectations. No game files.

AI-assisted (Claude Code).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 15:11:53 +01:00
400d976f43 d3d12_xs: name slot 67 descriptor fields as FSPX kinds 0, 1, 6, 7
Name all four pointer and size pairs in the XboxNativeComputePipelineStateDesc
struct as kinds 0, 1, 6, 7 per docs/fspx.md and name the slot
DeserializeComputePipelineStateX in slot_name, matching the DLL's messages.
This prepares the description struct for the runtime FSPX resolver follow-up.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 19:34:10 +05:30
af236e196b d3d12_xs: route slot 67 compute pipeline from native code to CreateComputePipelineState (RT-99)
Xbox device slot 67 takes (desc, riid, out) with IID_ID3D12PipelineState and a console-only
descriptor with the root signature at +0x00 and code blob pointer/size at +0x28/+0x30.
Previously it logged and returned E_NOTIMPL.

Route it to CreateComputePipelineState on the PC device (slot 11) like slot 62, mapping the
console descriptor to D3D12_COMPUTE_PIPELINE_STATE_DESC. On the Vulkan device this resolves
through the translator via fssm_program and ShaderLibrary.

- Implement proxy_create_compute_pipeline_from_native_code in d3d12_xs_device.cpp
- Update device_proxy_test to verify slot 67 thunk, compute PSO creation over WARP, and argument checks
- Update d3d12_compute_test to verify slot 67 compute PSO creation on the Vulkan device
- Update documentation in d3d12_command_objects.md and d3d12_vulkan.md

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 19:34:10 +05:30
b277512f9b d3d12_xs: name device slot 67 DeserializeComputePipelineStateX
The FidelityFX DLL's messages around the slot-67 call name it
DeserializeComputePipelineStateX ("DeserializeComputePipelineStateX
FAILED ... falling back to NewBE"). The slot name, the one-time log line
and the comment use that name and point at docs/fspx.md for the desc:
the root signature, then pointer/size pairs for the FSPX entries with the
native program at +0x28. Behaviour is unchanged: the proxy still refuses
it with E_NOTIMPL.
2026-11-22 13:42:04 +01:00
62593f47ca Runtime: Xbox-ABI proxies for the command queue and the fence (BUILD-231)
Device slots 8 (CreateCommandQueue), 75 (CreateCommandQueue1), 36
(CreateFence) and 32 (OpenSharedHandle of a fence) now return queue and
fence proxies. They forward the public chain in PC order (19 queue slots,
11 or 12 fence slots), refuse and log a slot past it up to the end of the
proxy's table, and name a read past the table through a guard region and
a vectored handler.

Heap, queue and fence proxies are unwrapped wherever a device or queue
method hands them to the real runtime: queue Signal/Wait, device slots
31/34/35/45/46/50. Arrays are copied without exceptions. QueryInterface
answers only the modelled interfaces, and logs one the real object has
but the proxy does not model. Outputs are cleared on failure as for
slots 14/62/76. --trace-d3d12 records proxy calls in the README grammar.
Every function a thunk hands its words to keeps them in the same
positions, because a title passes only as many as the method takes.

Tests: queue_proxy_test (host WARP, host hardware, Vulkan device;
differential per-process error cases, guard faults, identity, threads,
raw-slot client, child-runner self-test), xs_proxy_mock_test (older
devices, fences without Fence1, OpenSharedHandle branches, allocation
failures; three guard-setup fault modes), and device_proxy_test through
the D3D12XboxCreateDevice shim. No game files.

AI-assisted (Claude Code).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 11:08:53 +01:00
bc59ef4646 d3d12_xs proxy: slots 14/62/76 and heap GetDevice clear the output before failing
d3d12.h declares these outputs _COM_Outptr_ (NULL on failure), and the
inner Vulkan device clears it, but the Xbox-ABI proxy returned an error
with the caller's pointer untouched: slot 14 created into a local, and
slots 62/76 and heap slot 7 checked riid/desc before touching out.
2026-11-22 13:15:37 +05:30
7123be6c5e Merge pull request #869 from Ayoze Torres 2026-11-21 23:15:37 -05:00
3da355d290 FSR: Xbox backend descriptor, console command-list map, XMemGetWorkingSetStatistics 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.
2026-11-22 04:58:12 +01:00
694ae035ad tests: D3D12 tests skip without WARP and on host-dependent serializer checks
device_proxy and d3d12_xs_root_signature need a WARP adapter, which
Wine doesn't have: without one they exit 77, which CTest reads as a
skip (SKIP_RETURN_CODE). A missing DXGI factory still fails.

root_sig_test checked that the host serializer rejects the Xbox flag
byte. Microsoft's d3d12.dll does; Wine's (vkd3d) doesn't validate it.
That is a property of the host, not of the shim, so a host that accepts
it is reported as a skip, as the deserializer check already does.
2026-11-22 03:46:44 +00:00
28cf235061 d3d12_xs device proxy: slot 62 takes (desc, w2, w3, riid, out)
The proxy read device slot 62 as (desc, riid, out), so XboxBvhBuilder's constructor, the only
known caller, got E_POINTER on its first compute PSO and threw it. Recorded on 1.0.2.1: the
DLL calls slot 62 with (desc, 0, 0, &IID_ID3D12PipelineState, out), the shape the prior art
had documented (d3d12_vulkan.md, sections 4.8 and 7). Read the IID and the output from the
fourth and fifth arguments, and log the two extra words once if they are ever non-zero.
device_proxy_test now calls slot 62 in that shape.

AI-assisted (Claude Code).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-21 21:13:10 +01:00
9015a62748 Runtime: Xbox-ABI device proxy (slots 9/10/62/76)
- Wrap the PC ID3D12Device in a copied-vtable proxy: per-slot thunks swap `this` to the PC device, with IUnknown refcounting/QueryInterface, per-slot hit counters and XS_TRACE=1 first-call logging.
- Override Xbox slot 62 to the PC CreateComputePipelineState (PC slot 62 is CreateStateObject) and Xbox slot 76 to CreateCommittedResource (PC slot 27). The 56-byte description prefix is copied and its 0x101/0x1 layout word replaced by ROW_MAJOR for buffers and UNKNOWN for textures.
- Slot 14 wraps the created descriptor heap. On the measured PC runtime the heap getters take the hidden return pointer in RDX, while the Xbox ABI expects the 8-byte handle in RAX; heap slots 9/10 convert between them. Device slots 9/10 stay CreateCommandAllocator/CreateGraphicsPipelineState, because the measured handle getters are ID3D12DescriptorHeap methods.
- Heap slot 7 GetDevice returns the device proxy, not the raw PC device. The heap holds a device-proxy reference, so GetDevice cannot dangle; the device proxy does not reference heap proxies, so there is no cycle.
- Add device_proxy_test (WARP, no game executable): shim-created proxy, QI/refcount, slot 14 heap, heap GetDevice/refcount, raw RAX handles vs the PC hidden-pointer result, slot 9/16/30/43 forwarding, slot 76 buffer and texture, slot 62 compute PSO, and counter checks. Register it with ctest.
- Wire both CMake and scripts/build_runtime.ps1.

Verified against Windows SDK 10.0.26100 d3d12.h (slot counts through ID3D12Device14; no Device15/16 exists there) and a live WARP device. Still unknown: PresentX, queue/fence/command-list extensions, Xbox vtable order beyond the measured slots, and struct returns other than the heap handles.

Clean-room: implemented from the measured ABI-facts spec; no americas-recomp or AnyPS5 source was read or copied.
2026-11-21 18:26:19 +00:00