From c8247cdfa384189ed28512aa157663f4db152273 Mon Sep 17 00:00:00 2001 From: mrp1no <137657338+mrp1no@users.noreply.github.com> Date: Mon, 23 Nov 2026 17:05:11 +0100 Subject: [PATCH 1/4] 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 (cherry picked from commit 4c04c0f4e36476a6bbf309e2f0f4d6cfcbe9f045) --- docs/d3d12_vulkan.md | 1 + runtime/shims/d3d12_xs_device.cpp | 49 ++++++++++++++++++++++++++++- runtime/shims/d3d12_xs_device.h | 2 ++ runtime/test/xs_proxy_mock_test.cpp | 40 ++++++++++++++++++++--- 4 files changed, 87 insertions(+), 5 deletions(-) diff --git a/docs/d3d12_vulkan.md b/docs/d3d12_vulkan.md index 5979e22f56..251bc27916 100644 --- a/docs/d3d12_vulkan.md +++ b/docs/d3d12_vulkan.md @@ -3531,6 +3531,7 @@ to be recovered from call sites (or the NDA GDK headers, if a developer has acce | DCC / texture compatibility | Public release note for `D3D12XBOX_RESOURCE_FLAG_FORCE_TEXTURE_COMPATIBILITY` | Let Vulkan choose compression; fail if the game aliases/reads raw compressed data. | | PresentX / present planes / frame events | Public GDK samples (MIT/zlib), ยง4.5 | Likely the only present path of a GDKX title. Presenter + vblank-timed frame events; 1-2 planes composed into the Vulkan swapchain (placement, filter, alpha overlay, HDR10 conversions). Call shapes known; slots/layouts **Open**. | | Device slots 48/73/78/79/80 | Public HLE `Freminet`/`ScarlettX` (third-party, not Microsoft documentation) | `d3d12_xs_device.cpp` routes `CreateCommandQueueX` (48), `CreateCommandListX` (73), `SetFrameIntervalX` (78), `ScheduleFrameEventX` (79) and `WaitFrameEventX` (80) before it indexes the PC vtable. Queue and list creation use the existing create paths. The frame-event calls are a per-device token counter: `WaitFrameEventX` returns at once with a fresh non-zero token, because there is no vblank source before a presenter exists. The five indices can be moved with `LEONIDA_XS_QUEUE_X_SLOT`, `LEONIDA_XS_LIST_X_SLOT`, `LEONIDA_XS_FRAME_INTERVAL_SLOT`, `LEONIDA_XS_SCHEDULE_EVENT_SLOT` and `LEONIDA_XS_WAIT_EVENT_SLOT` (3..127; a value that names a slot the proxy already handles keeps that slot's handler); a trace that disagrees wins. | +| Indirect argument type 105 | The retail title's startup creates five one-argument command signatures (device slot 41) with no root signature; one has type 105 and a 12-byte stride. Its two `ExecuteIndirect` sites, read statically, set the compute state first, as the `DISPATCH` sites do, and pass one command from the same argument buffer, on a second command list | `d3d12_xs_device.cpp` creates it as `DISPATCH` (`D3D12_DISPATCH_ARGUMENTS`). What the console does differently for it is **Open**. | | VRS | Public `D3D12_SHADING_RATE` / `D3D12_AXIS_SHADING_RATE` | `VK_KHR_fragment_shading_rate`; `RSSetShadingRate`/image-based rate map to `vkCmdSetFragmentShadingRateKHR`. | | Mesh shader tier | Public `D3D12_MESH_SHADER_TIER` | `VK_EXT_mesh_shader`; the 9,282 translated mesh shaders make this a hard requirement for any content that uses them. | | Wave MMA | Public `D3D12_WAVE_MMA_TIER` | Not used: no shader sets `WAVE_MMA` in SFI0 and none contains `v_mfma`/`v_wmma` (all 26,503, `tools/feature_scan.py`). Answer the tier query truthfully; no cooperative-matrix mapping is needed. | diff --git a/runtime/shims/d3d12_xs_device.cpp b/runtime/shims/d3d12_xs_device.cpp index b66175ac87..9d09ab5662 100644 --- a/runtime/shims/d3d12_xs_device.cpp +++ b/runtime/shims/d3d12_xs_device.cpp @@ -233,6 +233,7 @@ const char* slot_name(unsigned slot) { case 34: return "MakeResident (proxies unwrapped)"; case 35: return "Evict (proxies unwrapped)"; case 36: return "CreateFence -> fence proxy"; + case 41: return "CreateCommandSignature (Xbox argument type 105 as DISPATCH)"; case 43: return "GetAdapterLuid"; case 45: return "SetEventOnMultipleFenceCompletion (fence proxies unwrapped)"; case 46: return "SetResidencyPriority (proxies unwrapped)"; @@ -1933,6 +1934,48 @@ HRESULT proxy_create_compute_pipeline_state(DeviceProxy* self, const D3D12_COMPU return self->real->CreateComputePipelineState(desc, *riid, out); } +// The Xbox slot 41 is CreateCommandSignature at its PC position, (desc, root signature, riid, out), but a console +// description can hold an argument type the PC does not have. The retail title creates five one-argument signatures +// with no root signature at startup; one has type 105 (0x69) and a 12-byte stride, next to a DISPATCH and a +// DISPATCH_MESH of 12 bytes. Read statically from its call sites (counts and shapes only): its two ExecuteIndirect +// sites pass MaxCommandCount 1 and an argument offset into the same upload buffer as the DISPATCH ones, and set the +// compute state (pipeline, compute root signature, tables, constants, SRV/UAV) right before, as the DISPATCH path +// does; they record on a second command list of the title's context. So type 105 is taken as a dispatch whose +// arguments are a D3D12_DISPATCH_ARGUMENTS. HYPOTHESIS: what the console does differently for it (which command +// stream it feeds) is not known; the PC layer has one compute path. Other descriptions are forwarded unchanged. +constexpr D3D12_INDIRECT_ARGUMENT_TYPE kXboxIndirectArgumentDispatch105 = static_cast(105); + +HRESULT proxy_create_command_signature(DeviceProxy* self, const D3D12_COMMAND_SIGNATURE_DESC* desc, + std::uint64_t root_signature, const IID* riid, void** out) { + note_slot(41); + using Fn = HRESULT(STDMETHODCALLTYPE*)(ID3D12Device*, const D3D12_COMMAND_SIGNATURE_DESC*, std::uint64_t, + const IID*, void**); + const auto forward = reinterpret_cast(self->real_vtable[41]); + bool console = false; + if (desc && desc->pArgumentDescs) + for (UINT i = 0; i < desc->NumArgumentDescs && !console; ++i) + console = desc->pArgumentDescs[i].Type == kXboxIndirectArgumentDispatch105; + if (!console) return forward(self->real, desc, root_signature, riid, out); + + std::unique_ptr args(new (std::nothrow) + D3D12_INDIRECT_ARGUMENT_DESC[desc->NumArgumentDescs]); + if (!args) { + if (out) *out = nullptr; + return E_OUTOFMEMORY; + } + for (UINT i = 0; i < desc->NumArgumentDescs; ++i) { + args[i] = desc->pArgumentDescs[i]; + if (args[i].Type == kXboxIndirectArgumentDispatch105) args[i].Type = D3D12_INDIRECT_ARGUMENT_TYPE_DISPATCH; + } + static std::atomic logged{false}; + if (!logged.exchange(true, std::memory_order_relaxed)) + std::fprintf(stderr, "[rt] d3d12_xs: slot 41 argument type 105 (stride %u) created as DISPATCH\n", + desc->ByteStride); + D3D12_COMMAND_SIGNATURE_DESC pc = *desc; + pc.pArgumentDescs = args.get(); + return forward(self->real, &pc, root_signature, riid, out); +} + // The Xbox slot 67 creates a compute pipeline from native GPU code: (desc, riid, out), named // DeserializeComputePipelineStateX in amd_fidelityfx_upscaler_xbox.dll's messages (call at RVA 0x56d9). The desc // passes the root signature at +0x00, followed by pointer/size pairs for the shader's FSPX entries (docs/fspx.md): @@ -2382,6 +2425,10 @@ std::uint64_t WINAPI proxy_slot(DeviceProxy* self, std::uint64_t a1, std::uint64 return hr_to_u64(proxy_create_compute_pipeline_state( self, reinterpret_cast(a1), a2, a3, reinterpret_cast(a4), reinterpret_cast(a5))); + } else if constexpr (Slot == 41) { + return hr_to_u64(proxy_create_command_signature( + self, reinterpret_cast(a1), a2, reinterpret_cast(a3), + reinterpret_cast(a4))); } else if constexpr (Slot == 67) { return hr_to_u64(proxy_create_compute_pipeline_from_native_code( self, reinterpret_cast(a1), reinterpret_cast(a2), @@ -2733,7 +2780,7 @@ ID3D12Device* device_proxy_real_device(const void* device) { bool device_slot_overridden(unsigned slot) { if (slot <= 2 || slot == 8 || slot == 9 || slot == 14 || (slot >= 17 && slot <= 24) || slot == 25 || slot == 26 || slot == 31 || slot == 32 || slot == 34 || slot == 35 || - slot == 36 || slot == 45 || slot == 46 || slot == 50 || slot == 56 || slot == 62 || slot == 67 || + slot == 36 || slot == 41 || slot == 45 || slot == 46 || slot == 50 || slot == 56 || slot == 62 || slot == 67 || slot == 70 || slot == 75 || slot == 76 || slot == 133 || slot == kCreateCommittedResource3X) return true; const XboxDeviceSlotRoutes& routes = xbox_device_slot_routes(); diff --git a/runtime/shims/d3d12_xs_device.h b/runtime/shims/d3d12_xs_device.h index 8d474dd1d5..5841656967 100644 --- a/runtime/shims/d3d12_xs_device.h +++ b/runtime/shims/d3d12_xs_device.h @@ -6,6 +6,8 @@ // the device in RCX and the buffer in RDX. The thunk takes the console form when RDX holds a device // proxy, and forwards the PC form otherwise. Slots 25 and 43 return structs too; no call of them by // the executable has been seen yet, so they are forwarded in the PC form. +// slot 41 CreateCommandSignature at its PC position; a console argument of type 105 (a 12-byte dispatch, read +// from the retail title's call sites) is created as D3D12_INDIRECT_ARGUMENT_TYPE_DISPATCH. // slot 62 CreateComputePipelineState(desc, w2, w3, iid, out): two words (0 from XboxBvhBuilder, meaning unknown) // before the IID. The PC slot 62 is CreateStateObject. // 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 fa5f6812af..220c12cdea 100644 --- a/runtime/test/xs_proxy_mock_test.cpp +++ b/runtime/test/xs_proxy_mock_test.cpp @@ -290,6 +290,13 @@ std::uint64_t mock_call(Mock* m, unsigned slot, const std::uint64_t* words) { out->VisibleNodeMask = kHeapMarker; return a1; // a struct-returning method hands the buffer's address back in RAX } + case 41: // CreateCommandSignature(desc, ...) + if (const auto* desc = reinterpret_cast(a1)) { + m->array[41][0] = desc->ByteStride | std::uint64_t{desc->NumArgumentDescs} << 32; + for (UINT i = 0; desc->pArgumentDescs && i < desc->NumArgumentDescs && i < 3; ++i) + m->array[41][i + 1] = static_cast(desc->pArgumentDescs[i].Type); + } + break; case 50: copy_array(m, slot, a3, a2); break; // (flags, count, objects, fence, value) default: break; } @@ -987,7 +994,7 @@ int check_allocators() { return 0; } -// ---- 7. Xbox device slots from the public HLE (48, 73, 78, 79, 80) ---- +// ---- 7. Xbox device slots from the public HLE (48, 73, 78, 79, 80) and the retail title (41) ---- // // A device that answers ID3D12Device11 (80 PC slots) is the Vulkan layer's shape: slots 78/79 are inside its table // (CreateReservedResource2/CreateSampler2 there) and 80 is just past it. None of the five may reach the mock's own @@ -1055,14 +1062,39 @@ int check_xbox_slots() { EXPECT(hr_of(raw(device, 73, word(&desc), 0, 0, word(&list_iid), word(&list))) == E_INVALIDARG); EXPECT(hr_of(raw(device, 73, word(&desc), word(allocator), 0, word(&list_iid), 0)) == E_POINTER); - EXPECT(xs::device_slot_overridden(48) && xs::device_slot_overridden(73) && xs::device_slot_overridden(78) && - xs::device_slot_overridden(79) && xs::device_slot_overridden(80)); + // 41 CreateCommandSignature: a console argument of type 105 reaches the PC slot 41 as DISPATCH, in a copy of the + // description (stride, count, the root argument before it and the root signature kept). A PC description is + // passed as the same pointer. + D3D12_INDIRECT_ARGUMENT_DESC console_args[2]{}; + console_args[0].Type = D3D12_INDIRECT_ARGUMENT_TYPE_CONSTANT; + console_args[0].Constant.Num32BitValuesToSet = 1; + console_args[1].Type = static_cast(105); + const D3D12_COMMAND_SIGNATURE_DESC console_sig{16, 2, console_args, 0}; + const IID sig_iid = __uuidof(ID3D12CommandSignature); + void* sig = nullptr; + EXPECT(hr_of(raw(device, 41, word(&console_sig), 0x5150, word(&sig_iid), word(&sig))) == S_OK); + EXPECT(mock->calls[41] == 1 && xs::device_slot_hits(41) == 1); + EXPECT(mock->args[41][0] != word(&console_sig) && mock->args[41][1] == 0x5150); + EXPECT(mock->args[41][2] == word(&sig_iid) && mock->args[41][3] == word(&sig)); + EXPECT(mock->array[41][0] == (16 | std::uint64_t{2} << 32)); + EXPECT(mock->array[41][1] == D3D12_INDIRECT_ARGUMENT_TYPE_CONSTANT && + mock->array[41][2] == D3D12_INDIRECT_ARGUMENT_TYPE_DISPATCH); + EXPECT(console_args[1].Type == static_cast(105)); // the caller's copy is untouched + D3D12_INDIRECT_ARGUMENT_DESC pc_arg{}; + pc_arg.Type = D3D12_INDIRECT_ARGUMENT_TYPE_DISPATCH_MESH; + const D3D12_COMMAND_SIGNATURE_DESC pc_sig{12, 1, &pc_arg, 0}; + EXPECT(hr_of(raw(device, 41, word(&pc_sig), 0, word(&sig_iid), word(&sig))) == S_OK); + EXPECT(mock->calls[41] == 2 && mock->args[41][0] == word(&pc_sig)); + EXPECT(mock->array[41][1] == D3D12_INDIRECT_ARGUMENT_TYPE_DISPATCH_MESH); + + EXPECT(xs::device_slot_overridden(41) && xs::device_slot_overridden(48) && xs::device_slot_overridden(73) && + xs::device_slot_overridden(78) && xs::device_slot_overridden(79) && xs::device_slot_overridden(80)); EXPECT(release(allocator) == 0 && real_allocator->refs == 0); EXPECT(release(queue) == 0); EXPECT(release(device) == 0 && mock->refs == 0); std::printf("%s: device slots 48/73/78/79/80 route to a queue, a list and frame-event tokens without reaching " - "the mock's own PC slots\n", g_label); + "the mock's own PC slots; slot 41 creates argument type 105 as DISPATCH\n", g_label); return 0; #else std::printf("%s: ID3D12Device11 is not in this SDK; Xbox slot 80's beyond-table case is not built\n", g_label); From 69b46dfccbb84c55db31c41be6c752526c2160bd Mon Sep 17 00:00:00 2001 From: mrp1no <137657338+mrp1no@users.noreply.github.com> Date: Mon, 23 Nov 2026 17:17:22 +0100 Subject: [PATCH 2/4] d3d12_xs: read the console argument type as its 32 bits (clang-cl) 105 is outside D3D12_INDIRECT_ARGUMENT_TYPE's range [0, 15], so clang-cl rejects a constant expression that casts it to the enum (reported by umnitus on #7163). The handler now reads each argument's Type field as a uint32_t through memcpy and compares it with 105; the test writes and reads the raw value the same way, and the mock records it the same way. Co-Authored-By: Claude Opus 5.5 (cherry picked from commit 084c8c60e7e839d0caefaaeccf41a6348b062cf1) --- runtime/shims/d3d12_xs_device.cpp | 15 ++++++++++++--- runtime/test/xs_proxy_mock_test.cpp | 14 ++++++++++---- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/runtime/shims/d3d12_xs_device.cpp b/runtime/shims/d3d12_xs_device.cpp index 9d09ab5662..2f307ea16e 100644 --- a/runtime/shims/d3d12_xs_device.cpp +++ b/runtime/shims/d3d12_xs_device.cpp @@ -1943,7 +1943,15 @@ HRESULT proxy_create_compute_pipeline_state(DeviceProxy* self, const D3D12_COMPU // does; they record on a second command list of the title's context. So type 105 is taken as a dispatch whose // arguments are a D3D12_DISPATCH_ARGUMENTS. HYPOTHESIS: what the console does differently for it (which command // stream it feeds) is not known; the PC layer has one compute path. Other descriptions are forwarded unchanged. -constexpr D3D12_INDIRECT_ARGUMENT_TYPE kXboxIndirectArgumentDispatch105 = static_cast(105); +// 105 is outside D3D12_INDIRECT_ARGUMENT_TYPE's range, so the field is read as its 32 bits (a constant expression that +// casts 105 to the enum does not compile with clang-cl). +constexpr std::uint32_t kXboxIndirectArgumentDispatch105 = 105; + +std::uint32_t argument_type(const D3D12_INDIRECT_ARGUMENT_DESC& arg) { + std::uint32_t type = 0; + std::memcpy(&type, &arg.Type, sizeof(type)); + return type; +} HRESULT proxy_create_command_signature(DeviceProxy* self, const D3D12_COMMAND_SIGNATURE_DESC* desc, std::uint64_t root_signature, const IID* riid, void** out) { @@ -1954,7 +1962,7 @@ HRESULT proxy_create_command_signature(DeviceProxy* self, const D3D12_COMMAND_SI bool console = false; if (desc && desc->pArgumentDescs) for (UINT i = 0; i < desc->NumArgumentDescs && !console; ++i) - console = desc->pArgumentDescs[i].Type == kXboxIndirectArgumentDispatch105; + console = argument_type(desc->pArgumentDescs[i]) == kXboxIndirectArgumentDispatch105; if (!console) return forward(self->real, desc, root_signature, riid, out); std::unique_ptr args(new (std::nothrow) @@ -1965,7 +1973,8 @@ HRESULT proxy_create_command_signature(DeviceProxy* self, const D3D12_COMMAND_SI } for (UINT i = 0; i < desc->NumArgumentDescs; ++i) { args[i] = desc->pArgumentDescs[i]; - if (args[i].Type == kXboxIndirectArgumentDispatch105) args[i].Type = D3D12_INDIRECT_ARGUMENT_TYPE_DISPATCH; + if (argument_type(args[i]) == kXboxIndirectArgumentDispatch105) + args[i].Type = D3D12_INDIRECT_ARGUMENT_TYPE_DISPATCH; } static std::atomic logged{false}; if (!logged.exchange(true, std::memory_order_relaxed)) diff --git a/runtime/test/xs_proxy_mock_test.cpp b/runtime/test/xs_proxy_mock_test.cpp index 220c12cdea..bf4e0b015d 100644 --- a/runtime/test/xs_proxy_mock_test.cpp +++ b/runtime/test/xs_proxy_mock_test.cpp @@ -293,8 +293,11 @@ std::uint64_t mock_call(Mock* m, unsigned slot, const std::uint64_t* words) { case 41: // CreateCommandSignature(desc, ...) if (const auto* desc = reinterpret_cast(a1)) { m->array[41][0] = desc->ByteStride | std::uint64_t{desc->NumArgumentDescs} << 32; - for (UINT i = 0; desc->pArgumentDescs && i < desc->NumArgumentDescs && i < 3; ++i) - m->array[41][i + 1] = static_cast(desc->pArgumentDescs[i].Type); + for (UINT i = 0; desc->pArgumentDescs && i < desc->NumArgumentDescs && i < 3; ++i) { + std::uint32_t type = 0; // read as its 32 bits: a console type is outside the enum's range + std::memcpy(&type, &desc->pArgumentDescs[i].Type, sizeof(type)); + m->array[41][i + 1] = type; + } } break; case 50: copy_array(m, slot, a3, a2); break; // (flags, count, objects, fence, value) @@ -1068,7 +1071,8 @@ int check_xbox_slots() { D3D12_INDIRECT_ARGUMENT_DESC console_args[2]{}; console_args[0].Type = D3D12_INDIRECT_ARGUMENT_TYPE_CONSTANT; console_args[0].Constant.Num32BitValuesToSet = 1; - console_args[1].Type = static_cast(105); + constexpr std::uint32_t kType105 = 105; // outside the enum's range: written and read as its 32 bits + std::memcpy(&console_args[1].Type, &kType105, sizeof(kType105)); const D3D12_COMMAND_SIGNATURE_DESC console_sig{16, 2, console_args, 0}; const IID sig_iid = __uuidof(ID3D12CommandSignature); void* sig = nullptr; @@ -1079,7 +1083,9 @@ int check_xbox_slots() { EXPECT(mock->array[41][0] == (16 | std::uint64_t{2} << 32)); EXPECT(mock->array[41][1] == D3D12_INDIRECT_ARGUMENT_TYPE_CONSTANT && mock->array[41][2] == D3D12_INDIRECT_ARGUMENT_TYPE_DISPATCH); - EXPECT(console_args[1].Type == static_cast(105)); // the caller's copy is untouched + std::uint32_t caller_type = 0; + std::memcpy(&caller_type, &console_args[1].Type, sizeof(caller_type)); + EXPECT(caller_type == kType105); // the caller's description is untouched D3D12_INDIRECT_ARGUMENT_DESC pc_arg{}; pc_arg.Type = D3D12_INDIRECT_ARGUMENT_TYPE_DISPATCH_MESH; const D3D12_COMMAND_SIGNATURE_DESC pc_sig{12, 1, &pc_arg, 0}; From d1f8a6566d2c3a352603c0e72d3b00f6d2d7907d Mon Sep 17 00:00:00 2001 From: NiiRoZz Date: Mon, 23 Nov 2026 17:29:49 +0100 Subject: [PATCH 3/4] d3d12: CreateCommandSignature creates a DISPATCH_MESH signature on a device with mesh shaders The Vulkan layer created signatures for draw, draw-indexed and dispatch only and answered E_NOTIMPL for DISPATCH_MESH, which the PC runtime creates on any mesh-shader tier 1 device. A title that creates such a signature at startup and asserts on the result stopped there. The signature is created when the device has VK_EXT_mesh_shader (MeshShaderTier 1), as a new IndirectKind::dispatch_mesh (the name and value #3777 uses, so the two merge). ExecuteIndirect with it records nothing yet and says so once; #3777 replays it as vkCmdDrawMeshTasksIndirectEXT. Co-Authored-By: Claude Opus 5.5 (cherry picked from commit efc347830b9ccf1461baf9a764ac9e5e911de8f6) --- runtime/shims/d3d12_com.cpp | 22 +++++++++------------- runtime/shims/d3d12_vulkan_device.cpp | 5 +++++ runtime/src/command_list.h | 3 +++ runtime/test/d3d12_mesh_test.cpp | 22 ++++++++++++++++++++++ 4 files changed, 39 insertions(+), 13 deletions(-) diff --git a/runtime/shims/d3d12_com.cpp b/runtime/shims/d3d12_com.cpp index 4f4904e965..55fea20c91 100644 --- a/runtime/shims/d3d12_com.cpp +++ b/runtime/shims/d3d12_com.cpp @@ -834,19 +834,15 @@ class GraphicsCommandList final } else if (count_buffer_offset != 0) { return check(false); } - // The record size is checked for every call: D3D12 rejects a signature whose stride cannot hold a record - // even when no command runs. The argument span is what the signature can walk, max_command_count * stride: - // the host refuses a range that ends past the buffer (`240` with stride `20` in a `256`-byte buffer), and - // it checks the offset itself when max_command_count is 0, where the required bytes are none. - const UINT64 record_size = - kind == leonida::IndirectKind::draw ? sizeof(D3D12_DRAW_ARGUMENTS) - : kind == leonida::IndirectKind::draw_indexed ? sizeof(D3D12_DRAW_INDEXED_ARGUMENTS) - : kind == leonida::IndirectKind::dispatch ? sizeof(D3D12_DISPATCH_ARGUMENTS) - : 0; - if (!record_size || stride < record_size || stride % 4 != 0) return check(false); - if (argument_buffer_offset > arg_desc.Width || - UINT64(max_command_count) > (arg_desc.Width - argument_buffer_offset) / stride) - return check(false); + if (kind == leonida::IndirectKind::dispatch_mesh) { + // Not replayed yet (#3777 replays it as vkCmdDrawMeshTasksIndirectEXT): nothing is recorded, and the + // first such call says so. The list stays valid. + static std::atomic logged{false}; + if (!logged.exchange(true, std::memory_order_relaxed)) + std::fprintf(stderr, "[rt] d3d12: ExecuteIndirect with a DISPATCH_MESH signature is not replayed yet; " + "nothing was recorded\n"); + return; + } leonida::ExecuteIndirect cmd{}; cmd.kind = kind; cmd.stride = stride; diff --git a/runtime/shims/d3d12_vulkan_device.cpp b/runtime/shims/d3d12_vulkan_device.cpp index 0273f9339b..6cc357c87e 100644 --- a/runtime/shims/d3d12_vulkan_device.cpp +++ b/runtime/shims/d3d12_vulkan_device.cpp @@ -5833,6 +5833,11 @@ class Device final case D3D12_INDIRECT_ARGUMENT_TYPE_DRAW: kind = leonida::IndirectKind::draw; break; case D3D12_INDIRECT_ARGUMENT_TYPE_DRAW_INDEXED: kind = leonida::IndirectKind::draw_indexed; break; case D3D12_INDIRECT_ARGUMENT_TYPE_DISPATCH: kind = leonida::IndirectKind::dispatch; break; + case D3D12_INDIRECT_ARGUMENT_TYPE_DISPATCH_MESH: + // As DispatchMesh: only a device with mesh shaders (MeshShaderTier 1) takes it. + if (!state_.info.mesh_shader) return E_NOTIMPL; + kind = leonida::IndirectKind::dispatch_mesh; + break; default: return E_NOTIMPL; } return create_command_signature(kind, desc->ByteStride, riid, out, identity()); diff --git a/runtime/src/command_list.h b/runtime/src/command_list.h index 7c5c09e0ac..595110f360 100644 --- a/runtime/src/command_list.h +++ b/runtime/src/command_list.h @@ -587,6 +587,9 @@ enum class IndirectKind : std::uint8_t { draw = 0, draw_indexed = 1, dispatch = 2, + // D3D12_DISPATCH_MESH_ARGUMENTS. Created on a device with mesh shaders; ExecuteIndirect with it records nothing + // yet (the replay is #3777's), so a title that only creates such a signature at startup goes on. + dispatch_mesh = 3, }; struct ExecuteIndirect { diff --git a/runtime/test/d3d12_mesh_test.cpp b/runtime/test/d3d12_mesh_test.cpp index df430c11a6..590d3507b9 100644 --- a/runtime/test/d3d12_mesh_test.cpp +++ b/runtime/test/d3d12_mesh_test.cpp @@ -12,6 +12,8 @@ // bottom-left quadrant (yellow). Each pixel is read back and compared. // - A vertex draw with the mesh PSO, and DispatchMesh with the VS one, fail at execution (ReplayResult:: // invalid_draw); a mesh grid beyond D3D12's limits fails at Close; an empty grid records nothing. +// - A DISPATCH_MESH command signature is created only with the extension; ExecuteIndirect with it records nothing +// yet, so its list closes. // The shaders are GLSL written to the translator's contract (test/glsl/ms_draw.mesh, ps_draw.frag, vs_fullscreen.vert). // No game data. Set LEONIDA_VK_VALIDATION=1 to run under VK_LAYER_KHRONOS_validation. #include "vk_test_device.h" @@ -180,6 +182,11 @@ int main() { stream.add(TargetsSubobject{.inner = one_target()}); Ref pso; EXPECT(create(device.p, stream, pso) == E_NOTIMPL && !pso.p); + // A DISPATCH_MESH command signature is refused the same way. + const D3D12_INDIRECT_ARGUMENT_DESC mesh_arg{D3D12_INDIRECT_ARGUMENT_TYPE_DISPATCH_MESH}; + const D3D12_COMMAND_SIGNATURE_DESC mesh_sig{12, 1, &mesh_arg, 0}; + Ref sig; + EXPECT(device->CreateCommandSignature(&mesh_sig, nullptr, IID_PPV_ARGS(&sig.p)) == E_NOTIMPL && !sig.p); root.reset(); EXPECT(rt::d3d12_xs::device_proxy_ref_count(device.p) == 1); } @@ -398,6 +405,21 @@ int main() { list->RSSetViewports(1, &viewport); list6->DispatchMesh(4096, 1025, 1); EXPECT(list->Close() == E_INVALIDARG); + // A DISPATCH_MESH command signature (D3D12_DISPATCH_MESH_ARGUMENTS, 12 bytes) is created; a stride below its + // 12 bytes is refused as the PC runtime refuses it. ExecuteIndirect with it records nothing yet (#3777 replays + // it), so the list still closes. + { + const D3D12_INDIRECT_ARGUMENT_DESC mesh_arg{D3D12_INDIRECT_ARGUMENT_TYPE_DISPATCH_MESH}; + const D3D12_COMMAND_SIGNATURE_DESC mesh_sig{12, 1, &mesh_arg, 0}; + const D3D12_COMMAND_SIGNATURE_DESC short_sig{8, 1, &mesh_arg, 0}; + Ref sig, short_one; + EXPECT(SUCCEEDED(device->CreateCommandSignature(&mesh_sig, nullptr, IID_PPV_ARGS(&sig.p))) && sig.p); + EXPECT(device->CreateCommandSignature(&short_sig, nullptr, IID_PPV_ARGS(&short_one.p)) == E_INVALIDARG); + EXPECT(SUCCEEDED(list->Reset(allocator.p, mesh_pso.p))); + list->SetGraphicsRootSignature(root.p); + list->ExecuteIndirect(sig.p, 1, upload.p, 0, nullptr, 0); + EXPECT(list->Close() == S_OK); + } EXPECT(SUCCEEDED(queue->Signal(fence.p, 2)) && SUCCEEDED(fence->SetEventOnCompletion(2, nullptr))); // D3D-291: pipeline statistics around mesh draws. Query 0 holds a vertex draw, two mesh draws and another From 88b8dbad9d59aab22da34c49035bd7841c822633 Mon Sep 17 00:00:00 2001 From: Mumogg <104529023+Mumogg@users.noreply.github.com> Date: Tue, 24 Nov 2026 03:51:27 -0600 Subject: [PATCH 4/4] d3d12: ExecuteIndirect keeps main's argument validation; DISPATCH_MESH has a record size and returns after it Resolving the cherry-pick of efc347830 I dropped main's record-size, stride and span checks (e1ec785b2), which d3d12_execute_indirect_validation_test depends on and which matter to every D3D12 user (found in review on #377). They are back as on main, the record-size chain knows D3D12_DISPATCH_MESH_ARGUMENTS, and the early return for a DISPATCH_MESH signature comes after the checks. Co-Authored-By: Claude Fable 5.2 Claude-Session: https://claude.ai/code/session_01HxBQf4pXH8PWpC5oZsM4bt --- runtime/shims/d3d12_com.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/runtime/shims/d3d12_com.cpp b/runtime/shims/d3d12_com.cpp index 55fea20c91..cf02df5193 100644 --- a/runtime/shims/d3d12_com.cpp +++ b/runtime/shims/d3d12_com.cpp @@ -834,6 +834,20 @@ class GraphicsCommandList final } else if (count_buffer_offset != 0) { return check(false); } + // The record size is checked for every call: D3D12 rejects a signature whose stride cannot hold a record + // even when no command runs. The argument span is what the signature can walk, max_command_count * stride: + // the host refuses a range that ends past the buffer (`240` with stride `20` in a `256`-byte buffer), and + // it checks the offset itself when max_command_count is 0, where the required bytes are none. + const UINT64 record_size = + kind == leonida::IndirectKind::draw ? sizeof(D3D12_DRAW_ARGUMENTS) + : kind == leonida::IndirectKind::draw_indexed ? sizeof(D3D12_DRAW_INDEXED_ARGUMENTS) + : kind == leonida::IndirectKind::dispatch ? sizeof(D3D12_DISPATCH_ARGUMENTS) + : kind == leonida::IndirectKind::dispatch_mesh ? sizeof(D3D12_DISPATCH_MESH_ARGUMENTS) + : 0; + if (!record_size || stride < record_size || stride % 4 != 0) return check(false); + if (argument_buffer_offset > arg_desc.Width || + UINT64(max_command_count) > (arg_desc.Width - argument_buffer_offset) / stride) + return check(false); if (kind == leonida::IndirectKind::dispatch_mesh) { // Not replayed yet (#3777 replays it as vkCmdDrawMeshTasksIndirectEXT): nothing is recorded, and the // first such call says so. The list stays valid.