diff options
| author | mrp1no <137657338+mrp1no@users.noreply.github.com> | 2026-11-23 17:17:22 +0100 |
|---|---|---|
| committer | mrp1no <137657338+mrp1no@users.noreply.github.com> | 2026-11-23 17:17:22 +0100 |
| commit | 084c8c60e7e839d0caefaaeccf41a6348b062cf1 (patch) | |
| tree | 4efa9ed779a6a371eb3d87fb63f98a9fd5aeaf92 /runtime | |
| parent | 4c04c0f4e36476a6bbf309e2f0f4d6cfcbe9f045 (diff) | |
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 <noreply@anthropic.com>
Diffstat (limited to 'runtime')
| -rw-r--r-- | runtime/shims/d3d12_xs_device.cpp | 15 | ||||
| -rw-r--r-- | 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 bf5583d26..a285b5878 100644 --- a/runtime/shims/d3d12_xs_device.cpp +++ b/runtime/shims/d3d12_xs_device.cpp | |||
| @@ -1380,7 +1380,15 @@ HRESULT proxy_create_compute_pipeline_state(DeviceProxy* self, const D3D12_COMPU | |||
| 1380 | // does; they record on a second command list of the title's context. So type 105 is taken as a dispatch whose | 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 | 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. | 1382 | // stream it feeds) is not known; the PC layer has one compute path. Other descriptions are forwarded unchanged. |
| 1383 | constexpr D3D12_INDIRECT_ARGUMENT_TYPE kXboxIndirectArgumentDispatch105 = static_cast<D3D12_INDIRECT_ARGUMENT_TYPE>(105); | 1383 | // 105 is outside D3D12_INDIRECT_ARGUMENT_TYPE's range, so the field is read as its 32 bits (a constant expression that |
| 1384 | // casts 105 to the enum does not compile with clang-cl). | ||
| 1385 | constexpr std::uint32_t kXboxIndirectArgumentDispatch105 = 105; | ||
| 1386 | |||
| 1387 | std::uint32_t argument_type(const D3D12_INDIRECT_ARGUMENT_DESC& arg) { | ||
| 1388 | std::uint32_t type = 0; | ||
| 1389 | std::memcpy(&type, &arg.Type, sizeof(type)); | ||
| 1390 | return type; | ||
| 1391 | } | ||
| 1384 | 1392 | ||
| 1385 | HRESULT proxy_create_command_signature(DeviceProxy* self, const D3D12_COMMAND_SIGNATURE_DESC* desc, | 1393 | HRESULT proxy_create_command_signature(DeviceProxy* self, const D3D12_COMMAND_SIGNATURE_DESC* desc, |
| 1386 | std::uint64_t root_signature, const IID* riid, void** out) { | 1394 | std::uint64_t root_signature, const IID* riid, void** out) { |
| @@ -1391,7 +1399,7 @@ HRESULT proxy_create_command_signature(DeviceProxy* self, const D3D12_COMMAND_SI | |||
| 1391 | bool console = false; | 1399 | bool console = false; |
| 1392 | if (desc && desc->pArgumentDescs) | 1400 | if (desc && desc->pArgumentDescs) |
| 1393 | for (UINT i = 0; i < desc->NumArgumentDescs && !console; ++i) | 1401 | for (UINT i = 0; i < desc->NumArgumentDescs && !console; ++i) |
| 1394 | console = desc->pArgumentDescs[i].Type == kXboxIndirectArgumentDispatch105; | 1402 | console = argument_type(desc->pArgumentDescs[i]) == kXboxIndirectArgumentDispatch105; |
| 1395 | if (!console) return forward(self->real, desc, root_signature, riid, out); | 1403 | if (!console) return forward(self->real, desc, root_signature, riid, out); |
| 1396 | 1404 | ||
| 1397 | std::unique_ptr<D3D12_INDIRECT_ARGUMENT_DESC[]> args(new (std::nothrow) | 1405 | std::unique_ptr<D3D12_INDIRECT_ARGUMENT_DESC[]> args(new (std::nothrow) |
| @@ -1402,7 +1410,8 @@ HRESULT proxy_create_command_signature(DeviceProxy* self, const D3D12_COMMAND_SI | |||
| 1402 | } | 1410 | } |
| 1403 | for (UINT i = 0; i < desc->NumArgumentDescs; ++i) { | 1411 | for (UINT i = 0; i < desc->NumArgumentDescs; ++i) { |
| 1404 | args[i] = desc->pArgumentDescs[i]; | 1412 | args[i] = desc->pArgumentDescs[i]; |
| 1405 | if (args[i].Type == kXboxIndirectArgumentDispatch105) args[i].Type = D3D12_INDIRECT_ARGUMENT_TYPE_DISPATCH; | 1413 | if (argument_type(args[i]) == kXboxIndirectArgumentDispatch105) |
| 1414 | args[i].Type = D3D12_INDIRECT_ARGUMENT_TYPE_DISPATCH; | ||
| 1406 | } | 1415 | } |
| 1407 | static std::atomic<bool> logged{false}; | 1416 | static std::atomic<bool> logged{false}; |
| 1408 | if (!logged.exchange(true, std::memory_order_relaxed)) | 1417 | 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 107c29d55..1777f15ce 100644 --- a/runtime/test/xs_proxy_mock_test.cpp +++ b/runtime/test/xs_proxy_mock_test.cpp | |||
| @@ -199,8 +199,11 @@ std::uint64_t mock_call(Mock* m, unsigned slot, const std::uint64_t* words) { | |||
| 199 | case 41: // CreateCommandSignature(desc, ...) | 199 | case 41: // CreateCommandSignature(desc, ...) |
| 200 | if (const auto* desc = reinterpret_cast<const D3D12_COMMAND_SIGNATURE_DESC*>(a1)) { | 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; | 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) | 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); | 203 | std::uint32_t type = 0; // read as its 32 bits: a console type is outside the enum's range |
| 204 | std::memcpy(&type, &desc->pArgumentDescs[i].Type, sizeof(type)); | ||
| 205 | m->array[41][i + 1] = type; | ||
| 206 | } | ||
| 204 | } | 207 | } |
| 205 | break; | 208 | break; |
| 206 | case 50: copy_array(m, slot, a3, a2); break; // (flags, count, objects, fence, value) | 209 | case 50: copy_array(m, slot, a3, a2); break; // (flags, count, objects, fence, value) |
| @@ -765,7 +768,8 @@ int check_xbox_slots() { | |||
| 765 | D3D12_INDIRECT_ARGUMENT_DESC console_args[2]{}; | 768 | D3D12_INDIRECT_ARGUMENT_DESC console_args[2]{}; |
| 766 | console_args[0].Type = D3D12_INDIRECT_ARGUMENT_TYPE_CONSTANT; | 769 | console_args[0].Type = D3D12_INDIRECT_ARGUMENT_TYPE_CONSTANT; |
| 767 | console_args[0].Constant.Num32BitValuesToSet = 1; | 770 | console_args[0].Constant.Num32BitValuesToSet = 1; |
| 768 | console_args[1].Type = static_cast<D3D12_INDIRECT_ARGUMENT_TYPE>(105); | 771 | constexpr std::uint32_t kType105 = 105; // outside the enum's range: written and read as its 32 bits |
| 772 | std::memcpy(&console_args[1].Type, &kType105, sizeof(kType105)); | ||
| 769 | const D3D12_COMMAND_SIGNATURE_DESC console_sig{16, 2, console_args, 0}; | 773 | const D3D12_COMMAND_SIGNATURE_DESC console_sig{16, 2, console_args, 0}; |
| 770 | const IID sig_iid = __uuidof(ID3D12CommandSignature); | 774 | const IID sig_iid = __uuidof(ID3D12CommandSignature); |
| 771 | void* sig = nullptr; | 775 | void* sig = nullptr; |
| @@ -776,7 +780,9 @@ int check_xbox_slots() { | |||
| 776 | EXPECT(mock->array[41][0] == (16 | std::uint64_t{2} << 32)); | 780 | EXPECT(mock->array[41][0] == (16 | std::uint64_t{2} << 32)); |
| 777 | EXPECT(mock->array[41][1] == D3D12_INDIRECT_ARGUMENT_TYPE_CONSTANT && | 781 | EXPECT(mock->array[41][1] == D3D12_INDIRECT_ARGUMENT_TYPE_CONSTANT && |
| 778 | mock->array[41][2] == D3D12_INDIRECT_ARGUMENT_TYPE_DISPATCH); | 782 | 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 | 783 | std::uint32_t caller_type = 0; |
| 784 | std::memcpy(&caller_type, &console_args[1].Type, sizeof(caller_type)); | ||
| 785 | EXPECT(caller_type == kType105); // the caller's description is untouched | ||
| 780 | D3D12_INDIRECT_ARGUMENT_DESC pc_arg{}; | 786 | D3D12_INDIRECT_ARGUMENT_DESC pc_arg{}; |
| 781 | pc_arg.Type = D3D12_INDIRECT_ARGUMENT_TYPE_DISPATCH_MESH; | 787 | pc_arg.Type = D3D12_INDIRECT_ARGUMENT_TYPE_DISPATCH_MESH; |
| 782 | const D3D12_COMMAND_SIGNATURE_DESC pc_sig{12, 1, &pc_arg, 0}; | 788 | const D3D12_COMMAND_SIGNATURE_DESC pc_sig{12, 1, &pc_arg, 0}; |