upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/runtime
diff options
context:
space:
mode:
authormrp1no <137657338+mrp1no@users.noreply.github.com>2026-11-23 17:05:11 +0100
committermrp1no <137657338+mrp1no@users.noreply.github.com>2026-11-23 17:05:11 +0100
commit4c04c0f4e36476a6bbf309e2f0f4d6cfcbe9f045 (patch)
treede209f2192e894a58af2b8eef2f8faaa631b1e7a /runtime
parent464887b4f448bdfbfc658e0acf21594b041ae1a7 (diff)
d3d12_xs: a console indirect argument of type 105 is created as DISPATCH (slot 41)
The retail title creates five one-argument command signatures with no root signature at startup (device slot 41, CreateCommandSignature at its PC position). One has the console argument type 105 and a 12-byte stride, next to a DISPATCH and a DISPATCH_MESH of 12 bytes. The PC layer refuses the unknown type, which is stop 19 of the RT-5 boot measurements. Read statically from the title's call sites (shapes only): the two ExecuteIndirect sites of that signature pass MaxCommandCount 1 and an offset into the same argument buffer as the DISPATCH sites. Right before, they set the same compute state as the DISPATCH path (pipeline, compute root signature, tables, constants, SRV and UAV); they record on a second command list of the title's context. So the argument is taken as a D3D12_DISPATCH_ARGUMENTS. Slot 41 now has its own handler. A description that holds type 105 is copied with that type replaced by DISPATCH (logged once). Any other description is forwarded as the same pointer. What the console does differently for type 105 is left open in docs/d3d12_vulkan.md (section 4.9). xs_proxy_mock_test: a two-argument description (a root constant, then type 105) reaches the PC slot 41 as a copy with DISPATCH, the same stride, count, root signature, IID and output, and the caller's description is untouched; a PC description is passed through unchanged. With main's d3d12_xs_device.cpp the new check fails. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'runtime')
-rw-r--r--runtime/shims/d3d12_xs_device.cpp49
-rw-r--r--runtime/shims/d3d12_xs_device.h2
-rw-r--r--runtime/test/xs_proxy_mock_test.cpp40
3 files changed, 86 insertions, 5 deletions
diff --git a/runtime/shims/d3d12_xs_device.cpp b/runtime/shims/d3d12_xs_device.cpp
index e17a80353..bf5583d26 100644
--- a/runtime/shims/d3d12_xs_device.cpp
+++ b/runtime/shims/d3d12_xs_device.cpp
@@ -134,6 +134,7 @@ const char* slot_name(unsigned slot) {
134 case 34: return "MakeResident (proxies unwrapped)"; 134 case 34: return "MakeResident (proxies unwrapped)";
135 case 35: return "Evict (proxies unwrapped)"; 135 case 35: return "Evict (proxies unwrapped)";
136 case 36: return "CreateFence -> fence proxy"; 136 case 36: return "CreateFence -> fence proxy";
137 case 41: return "CreateCommandSignature (Xbox argument type 105 as DISPATCH)";
137 case 43: return "GetAdapterLuid"; 138 case 43: return "GetAdapterLuid";
138 case 45: return "SetEventOnMultipleFenceCompletion (fence proxies unwrapped)"; 139 case 45: return "SetEventOnMultipleFenceCompletion (fence proxies unwrapped)";
139 case 46: return "SetResidencyPriority (proxies unwrapped)"; 140 case 46: return "SetResidencyPriority (proxies unwrapped)";
@@ -1370,6 +1371,48 @@ HRESULT proxy_create_compute_pipeline_state(DeviceProxy* self, const D3D12_COMPU
1370 return self->real->CreateComputePipelineState(desc, *riid, out); 1371 return self->real->CreateComputePipelineState(desc, *riid, out);
1371} 1372}
1372 1373
1374// The Xbox slot 41 is CreateCommandSignature at its PC position, (desc, root signature, riid, out), but a console
1375// description can hold an argument type the PC does not have. The retail title creates five one-argument signatures
1376// with no root signature at startup; one has type 105 (0x69) and a 12-byte stride, next to a DISPATCH and a
1377// DISPATCH_MESH of 12 bytes. Read statically from its call sites (counts and shapes only): its two ExecuteIndirect
1378// sites pass MaxCommandCount 1 and an argument offset into the same upload buffer as the DISPATCH ones, and set the
1379// compute state (pipeline, compute root signature, tables, constants, SRV/UAV) right before, as the DISPATCH path
1380// does; they record on a second command list of the title's context. So type 105 is taken as a dispatch whose
1381// arguments are a D3D12_DISPATCH_ARGUMENTS. HYPOTHESIS: what the console does differently for it (which command
1382// stream it feeds) is not known; the PC layer has one compute path. Other descriptions are forwarded unchanged.
1383constexpr D3D12_INDIRECT_ARGUMENT_TYPE kXboxIndirectArgumentDispatch105 = static_cast<D3D12_INDIRECT_ARGUMENT_TYPE>(105);
1384
1385HRESULT proxy_create_command_signature(DeviceProxy* self, const D3D12_COMMAND_SIGNATURE_DESC* desc,
1386 std::uint64_t root_signature, const IID* riid, void** out) {
1387 note_slot(41);
1388 using Fn = HRESULT(STDMETHODCALLTYPE*)(ID3D12Device*, const D3D12_COMMAND_SIGNATURE_DESC*, std::uint64_t,
1389 const IID*, void**);
1390 const auto forward = reinterpret_cast<Fn>(self->real_vtable[41]);
1391 bool console = false;
1392 if (desc && desc->pArgumentDescs)
1393 for (UINT i = 0; i < desc->NumArgumentDescs && !console; ++i)
1394 console = desc->pArgumentDescs[i].Type == kXboxIndirectArgumentDispatch105;
1395 if (!console) return forward(self->real, desc, root_signature, riid, out);
1396
1397 std::unique_ptr<D3D12_INDIRECT_ARGUMENT_DESC[]> args(new (std::nothrow)
1398 D3D12_INDIRECT_ARGUMENT_DESC[desc->NumArgumentDescs]);
1399 if (!args) {
1400 if (out) *out = nullptr;
1401 return E_OUTOFMEMORY;
1402 }
1403 for (UINT i = 0; i < desc->NumArgumentDescs; ++i) {
1404 args[i] = desc->pArgumentDescs[i];
1405 if (args[i].Type == kXboxIndirectArgumentDispatch105) args[i].Type = D3D12_INDIRECT_ARGUMENT_TYPE_DISPATCH;
1406 }
1407 static std::atomic<bool> logged{false};
1408 if (!logged.exchange(true, std::memory_order_relaxed))
1409 std::fprintf(stderr, "[rt] d3d12_xs: slot 41 argument type 105 (stride %u) created as DISPATCH\n",
1410 desc->ByteStride);
1411 D3D12_COMMAND_SIGNATURE_DESC pc = *desc;
1412 pc.pArgumentDescs = args.get();
1413 return forward(self->real, &pc, root_signature, riid, out);
1414}
1415
1373// The Xbox slot 67 creates a compute pipeline from native GPU code: (desc, riid, out), named 1416// The Xbox slot 67 creates a compute pipeline from native GPU code: (desc, riid, out), named
1374// DeserializeComputePipelineStateX in amd_fidelityfx_upscaler_xbox.dll's messages (call at RVA 0x56d9). The desc 1417// DeserializeComputePipelineStateX in amd_fidelityfx_upscaler_xbox.dll's messages (call at RVA 0x56d9). The desc
1375// passes the root signature at +0x00, followed by pointer/size pairs for the shader's FSPX entries (docs/fspx.md): 1418// passes the root signature at +0x00, followed by pointer/size pairs for the shader's FSPX entries (docs/fspx.md):
@@ -1517,6 +1560,10 @@ std::uint64_t WINAPI proxy_slot(DeviceProxy* self, std::uint64_t a1, std::uint64
1517 return hr_to_u64(proxy_create_compute_pipeline_state( 1560 return hr_to_u64(proxy_create_compute_pipeline_state(
1518 self, reinterpret_cast<const D3D12_COMPUTE_PIPELINE_STATE_DESC*>(a1), a2, a3, 1561 self, reinterpret_cast<const D3D12_COMPUTE_PIPELINE_STATE_DESC*>(a1), a2, a3,
1519 reinterpret_cast<const IID*>(a4), reinterpret_cast<void**>(a5))); 1562 reinterpret_cast<const IID*>(a4), reinterpret_cast<void**>(a5)));
1563 } else if constexpr (Slot == 41) {
1564 return hr_to_u64(proxy_create_command_signature(
1565 self, reinterpret_cast<const D3D12_COMMAND_SIGNATURE_DESC*>(a1), a2, reinterpret_cast<const IID*>(a3),
1566 reinterpret_cast<void**>(a4)));
1520 } else if constexpr (Slot == 67) { 1567 } else if constexpr (Slot == 67) {
1521 return hr_to_u64(proxy_create_compute_pipeline_from_native_code( 1568 return hr_to_u64(proxy_create_compute_pipeline_from_native_code(
1522 self, reinterpret_cast<const void*>(a1), reinterpret_cast<const IID*>(a2), 1569 self, reinterpret_cast<const void*>(a1), reinterpret_cast<const IID*>(a2),
@@ -1705,7 +1752,7 @@ ID3D12Device* device_proxy_real_device(const void* device) {
1705 1752
1706bool device_slot_overridden(unsigned slot) { 1753bool device_slot_overridden(unsigned slot) {
1707 if (slot <= 2 || slot == 8 || slot == 9 || slot == 14 || slot == 31 || slot == 32 || slot == 34 || slot == 35 || 1754 if (slot <= 2 || slot == 8 || slot == 9 || slot == 14 || slot == 31 || slot == 32 || slot == 34 || slot == 35 ||
1708 slot == 36 || slot == 45 || slot == 46 || slot == 50 || slot == 62 || slot == 67 || 1755 slot == 36 || slot == 41 || slot == 45 || slot == 46 || slot == 50 || slot == 62 || slot == 67 ||
1709 slot == 75 || slot == 76) 1756 slot == 75 || slot == 76)
1710 return true; 1757 return true;
1711 const XboxDeviceSlotRoutes& routes = xbox_device_slot_routes(); 1758 const XboxDeviceSlotRoutes& routes = xbox_device_slot_routes();
diff --git a/runtime/shims/d3d12_xs_device.h b/runtime/shims/d3d12_xs_device.h
index 0019ec506..38a748702 100644
--- a/runtime/shims/d3d12_xs_device.h
+++ b/runtime/shims/d3d12_xs_device.h
@@ -1,6 +1,8 @@
1// Xbox-ABI proxy around a PC ID3D12Device. 1// Xbox-ABI proxy around a PC ID3D12Device.
2// 2//
3// Measured Xbox device deviations used here (vtable indices, x64): 3// Measured Xbox device deviations used here (vtable indices, x64):
4// slot 41 CreateCommandSignature at its PC position; a console argument of type 105 (a 12-byte dispatch, read
5// from the retail title's call sites) is created as D3D12_INDIRECT_ARGUMENT_TYPE_DISPATCH.
4// slot 62 CreateComputePipelineState(desc, w2, w3, iid, out): two words (0 from XboxBvhBuilder, meaning unknown) 6// slot 62 CreateComputePipelineState(desc, w2, w3, iid, out): two words (0 from XboxBvhBuilder, meaning unknown)
5// before the IID. The PC slot 62 is CreateStateObject. 7// before the IID. The PC slot 62 is CreateStateObject.
6// slot 67 CreateComputePipelineState from native code (desc, iid, out): converts the Xbox native-code desc 8// slot 67 CreateComputePipelineState from native code (desc, iid, out): converts the Xbox native-code desc
diff --git a/runtime/test/xs_proxy_mock_test.cpp b/runtime/test/xs_proxy_mock_test.cpp
index f0030116b..107c29d55 100644
--- a/runtime/test/xs_proxy_mock_test.cpp
+++ b/runtime/test/xs_proxy_mock_test.cpp
@@ -196,6 +196,13 @@ std::uint64_t mock_call(Mock* m, unsigned slot, const std::uint64_t* words) {
196 return static_cast<std::uint32_t>(E_INVALIDARG); 196 return static_cast<std::uint32_t>(E_INVALIDARG);
197 case 34: case 35: case 46: copy_array(m, slot, a2, a1); break; // (count, objects, ...) 197 case 34: case 35: case 46: copy_array(m, slot, a2, a1); break; // (count, objects, ...)
198 case 45: copy_array(m, slot, a1, a3); break; // (fences, values, count, ...) 198 case 45: copy_array(m, slot, a1, a3); break; // (fences, values, count, ...)
199 case 41: // CreateCommandSignature(desc, ...)
200 if (const auto* desc = reinterpret_cast<const D3D12_COMMAND_SIGNATURE_DESC*>(a1)) {
201 m->array[41][0] = desc->ByteStride | std::uint64_t{desc->NumArgumentDescs} << 32;
202 for (UINT i = 0; desc->pArgumentDescs && i < desc->NumArgumentDescs && i < 3; ++i)
203 m->array[41][i + 1] = static_cast<std::uint32_t>(desc->pArgumentDescs[i].Type);
204 }
205 break;
199 case 50: copy_array(m, slot, a3, a2); break; // (flags, count, objects, fence, value) 206 case 50: copy_array(m, slot, a3, a2); break; // (flags, count, objects, fence, value)
200 default: break; 207 default: break;
201 } 208 }
@@ -687,7 +694,7 @@ int check_allocators() {
687 return 0; 694 return 0;
688} 695}
689 696
690// ---- 7. Xbox device slots from the public HLE (48, 73, 78, 79, 80) ---- 697// ---- 7. Xbox device slots from the public HLE (48, 73, 78, 79, 80) and the retail title (41) ----
691// 698//
692// A device that answers ID3D12Device11 (80 PC slots) is the Vulkan layer's shape: slots 78/79 are inside its table 699// A device that answers ID3D12Device11 (80 PC slots) is the Vulkan layer's shape: slots 78/79 are inside its table
693// (CreateReservedResource2/CreateSampler2 there) and 80 is just past it. None of the five may reach the mock's own 700// (CreateReservedResource2/CreateSampler2 there) and 80 is just past it. None of the five may reach the mock's own
@@ -752,14 +759,39 @@ int check_xbox_slots() {
752 EXPECT(hr_of(raw(device, 73, word(&desc), 0, 0, word(&list_iid), word(&list))) == E_INVALIDARG); 759 EXPECT(hr_of(raw(device, 73, word(&desc), 0, 0, word(&list_iid), word(&list))) == E_INVALIDARG);
753 EXPECT(hr_of(raw(device, 73, word(&desc), word(allocator), 0, word(&list_iid), 0)) == E_POINTER); 760 EXPECT(hr_of(raw(device, 73, word(&desc), word(allocator), 0, word(&list_iid), 0)) == E_POINTER);
754 761
755 EXPECT(xs::device_slot_overridden(48) && xs::device_slot_overridden(73) && xs::device_slot_overridden(78) && 762 // 41 CreateCommandSignature: a console argument of type 105 reaches the PC slot 41 as DISPATCH, in a copy of the
756 xs::device_slot_overridden(79) && xs::device_slot_overridden(80)); 763 // description (stride, count, the root argument before it and the root signature kept). A PC description is
764 // passed as the same pointer.
765 D3D12_INDIRECT_ARGUMENT_DESC console_args[2]{};
766 console_args[0].Type = D3D12_INDIRECT_ARGUMENT_TYPE_CONSTANT;
767 console_args[0].Constant.Num32BitValuesToSet = 1;
768 console_args[1].Type = static_cast<D3D12_INDIRECT_ARGUMENT_TYPE>(105);
769 const D3D12_COMMAND_SIGNATURE_DESC console_sig{16, 2, console_args, 0};
770 const IID sig_iid = __uuidof(ID3D12CommandSignature);
771 void* sig = nullptr;
772 EXPECT(hr_of(raw(device, 41, word(&console_sig), 0x5150, word(&sig_iid), word(&sig))) == S_OK);
773 EXPECT(mock->calls[41] == 1 && xs::device_slot_hits(41) == 1);
774 EXPECT(mock->args[41][0] != word(&console_sig) && mock->args[41][1] == 0x5150);
775 EXPECT(mock->args[41][2] == word(&sig_iid) && mock->args[41][3] == word(&sig));
776 EXPECT(mock->array[41][0] == (16 | std::uint64_t{2} << 32));
777 EXPECT(mock->array[41][1] == D3D12_INDIRECT_ARGUMENT_TYPE_CONSTANT &&
778 mock->array[41][2] == D3D12_INDIRECT_ARGUMENT_TYPE_DISPATCH);
779 EXPECT(console_args[1].Type == static_cast<D3D12_INDIRECT_ARGUMENT_TYPE>(105)); // the caller's copy is untouched
780 D3D12_INDIRECT_ARGUMENT_DESC pc_arg{};
781 pc_arg.Type = D3D12_INDIRECT_ARGUMENT_TYPE_DISPATCH_MESH;
782 const D3D12_COMMAND_SIGNATURE_DESC pc_sig{12, 1, &pc_arg, 0};
783 EXPECT(hr_of(raw(device, 41, word(&pc_sig), 0, word(&sig_iid), word(&sig))) == S_OK);
784 EXPECT(mock->calls[41] == 2 && mock->args[41][0] == word(&pc_sig));
785 EXPECT(mock->array[41][1] == D3D12_INDIRECT_ARGUMENT_TYPE_DISPATCH_MESH);
786
787 EXPECT(xs::device_slot_overridden(41) && xs::device_slot_overridden(48) && xs::device_slot_overridden(73) &&
788 xs::device_slot_overridden(78) && xs::device_slot_overridden(79) && xs::device_slot_overridden(80));
757 789
758 EXPECT(release(allocator) == 0 && real_allocator->refs == 0); 790 EXPECT(release(allocator) == 0 && real_allocator->refs == 0);
759 EXPECT(release(queue) == 0); 791 EXPECT(release(queue) == 0);
760 EXPECT(release(device) == 0 && mock->refs == 0); 792 EXPECT(release(device) == 0 && mock->refs == 0);
761 std::printf("%s: device slots 48/73/78/79/80 route to a queue, a list and frame-event tokens without reaching " 793 std::printf("%s: device slots 48/73/78/79/80 route to a queue, a list and frame-event tokens without reaching "
762 "the mock's own PC slots\n", g_label); 794 "the mock's own PC slots; slot 41 creates argument type 105 as DISPATCH\n", g_label);
763 return 0; 795 return 0;
764#else 796#else
765 std::printf("%s: ID3D12Device11 is not in this SDK; Xbox slot 80's beyond-table case is not built\n", g_label); 797 std::printf("%s: ID3D12Device11 is not in this SDK; Xbox slot 80's beyond-table case is not built\n", g_label);