From a5bb4b9b8cc412988d74fa8827aa560601397bda Mon Sep 17 00:00:00 2001 From: tedin7 Date: Mon, 23 Nov 2026 21:52:58 +0100 Subject: [PATCH 1/2] feat: d3d12_xs exports D3D12CreateVersionedRootSignatureDeserializer, clearing the Xbox RTS0 flags Upstream PR #8814 --- docs/d3d12_xs_surface.md | 2 +- runtime/shims/d3d12_xs.cpp | 23 +++++++++++++++++++++++ runtime/test/root_sig_test.cpp | 31 +++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 1 deletion(-) diff --git a/docs/d3d12_xs_surface.md b/docs/d3d12_xs_surface.md index 4e4b018d4b..0a85e13a93 100644 --- a/docs/d3d12_xs_surface.md +++ b/docs/d3d12_xs_surface.md @@ -67,7 +67,7 @@ and the individual stubs in | 4 | `D3D12ConfigureVirtualMemoryX` | console | present (returns `S_OK`) | VM policy; PC/Vulkan owns it. Measured: one pointer argument (a zeroed 32-byte block, dword +4 set to a count); the title only tests the result for failure | | 5 | `D3D12CreateDevice` | standard | **absent** | Leonida exports only the Xbox entry point; see ยง2.3 | | 6 | `D3D12CreateRootSignatureDeserializer` | standard | present | forwarded | -| 7 | `D3D12CreateVersionedRootSignatureDeserializer` | standard | absent | forward if imported | +| 7 | `D3D12CreateVersionedRootSignatureDeserializer` | standard | present | forwarded, Xbox flags cleared on a copy | | 8 | `D3D12EnableExperimentalFeatures` | standard | absent | forward if imported | | 9 | `D3D12GetDebugInterface` | standard | absent | forward if imported | | 10 | `D3D12SerializeRootSignature` | standard | present | forwarded, flags cleared on a copy | diff --git a/runtime/shims/d3d12_xs.cpp b/runtime/shims/d3d12_xs.cpp index 8e54c3fd56..ce44a2106b 100644 --- a/runtime/shims/d3d12_xs.cpp +++ b/runtime/shims/d3d12_xs.cpp @@ -34,6 +34,7 @@ FARPROC host(const char* name) { using SerializeFn = decltype(&::D3D12SerializeVersionedRootSignature); using DeserializerFn = decltype(&::D3D12CreateRootSignatureDeserializer); +using VersionedDeserializerFn = decltype(&::D3D12CreateVersionedRootSignatureDeserializer); using LegacySerializeFn = decltype(&::D3D12SerializeRootSignature); using CreateDeviceFn = decltype(&::D3D12CreateDevice); @@ -117,6 +118,24 @@ HRESULT WINAPI create_root_signature_deserializer(const void* data, SIZE_T size, return fn(data, size, iid, out); } +HRESULT WINAPI create_versioned_root_signature_deserializer(const void* data, SIZE_T size, REFIID iid, void** out) { + static auto fn = reinterpret_cast(host("D3D12CreateVersionedRootSignatureDeserializer")); + if (!fn) return E_NOTIMPL; + + std::vector cleared; + if (rt::d3d12_xs::copy_rts0_blob_clear_xbox_flags(data, static_cast(size), cleared)) { + uint32_t hash[4]; + const auto* bytes = static_cast(data); + rt::d3d12_xs::dxbc_checksum(bytes, static_cast(size), hash); + if (std::memcmp(bytes + 4, hash, sizeof(hash)) != 0) { + if (out) *out = nullptr; + return E_INVALIDARG; + } + return fn(cleared.data(), cleared.size(), iid, out); + } + return fn(data, size, iid, out); +} + // Measured shape: D3D12XboxCreateDevice(adapter, params, riid, out), where params is a 24-word block that is only // logged and not used to create the device. The struct's total size is unknown, so the log reads 24 x 32-bit words // (96 bytes) and no more. The PC D3D12CreateDevice needs a minimum feature level instead, so 12_0 is used as the @@ -215,6 +234,7 @@ HRESULT WINAPI D3D12XboxCreateDevice(IUnknown* adapter, const void* params, cons static_assert(std::is_same_v); static_assert(std::is_same_v); +static_assert(std::is_same_v); static_assert(std::is_same_v); // Measured call (RT-5, 1.0.2.1): the title calls it once at startup with one pointer to a zeroed 32-byte block whose @@ -229,6 +249,9 @@ SHIM_TABLE(d3d12_xs, {"d3d12_xs.dll", "D3D12SerializeRootSignature", reinterpret_cast(&serialize_root_signature_legacy)}, {"d3d12_xs.dll", "D3D12CreateRootSignatureDeserializer", reinterpret_cast(&create_root_signature_deserializer)}, + {"d3d12_xs.dll", "D3D12CreateVersionedRootSignatureDeserializer", + reinterpret_cast(&create_versioned_root_signature_deserializer)}, + {"d3d12_xs.dll", "#7", reinterpret_cast(&create_versioned_root_signature_deserializer)}, {"d3d12_xs.dll", "D3D12XboxCreateDevice", reinterpret_cast(&D3D12XboxCreateDevice)}, {"d3d12_xs.dll", "D3D12ConfigureVirtualMemoryX", reinterpret_cast(&configure_virtual_memory)}, ); diff --git a/runtime/test/root_sig_test.cpp b/runtime/test/root_sig_test.cpp index ac65075eed..9cdf0dd26f 100644 --- a/runtime/test/root_sig_test.cpp +++ b/runtime/test/root_sig_test.cpp @@ -479,6 +479,37 @@ void test_deserializer() { auto deserialize = reinterpret_cast( rt::shims::find("d3d12_xs.dll", "D3D12CreateRootSignatureDeserializer")); check(deserialize != nullptr, "shim registry exposes d3d12_xs!D3D12CreateRootSignatureDeserializer"); + auto versioned = reinterpret_cast( + rt::shims::find("d3d12_xs.dll", "D3D12CreateVersionedRootSignatureDeserializer")); + check(versioned != nullptr, "shim registry exposes the versioned deserializer"); + check(versioned && rt::shims::find("d3d12_xs.dll", "#7") == reinterpret_cast(versioned), + "ordinal 7 resolves to the versioned deserializer"); + if (versioned) { + ID3D12VersionedRootSignatureDeserializer* de = nullptr; + auto bad_checksum = tampered; + bad_checksum[4] ^= 1; + HRESULT bad_hr = versioned(bad_checksum.data(), bad_checksum.size(), IID_PPV_ARGS(&de)); + check(FAILED(bad_hr) && !de, "versioned shim rejects Xbox flags with corrupt checksum"); + if (de) de->Release(); + de = nullptr; + HRESULT versioned_hr = versioned(tampered.data(), tampered.size(), IID_PPV_ARGS(&de)); + check(SUCCEEDED(versioned_hr) && de, "versioned shim accepts Xbox flags"); + if (de) { + const auto* desc = de->GetUnconvertedRootSignatureDesc(); + check(desc && desc->Version == D3D_ROOT_SIGNATURE_VERSION_1_0 && desc->Desc_1_0.Flags == 0, + "versioned shim clears Xbox flags"); + de->Release(); + } + de = nullptr; + versioned_hr = versioned(bytes, size, IID_PPV_ARGS(&de)); + check(SUCCEEDED(versioned_hr) && de, "versioned shim accepts clean blob"); + if (de) de->Release(); + const uint8_t garbage[] = {1, 2, 3, 4}; + de = nullptr; + versioned_hr = versioned(garbage, sizeof(garbage), IID_PPV_ARGS(&de)); + check(FAILED(versioned_hr), "versioned shim rejects garbage"); + if (de) de->Release(); + } if (!deserialize) return; ID3D12RootSignatureDeserializer* shim_de = nullptr; From 3ff887f9621a20ba99dcaba14023364c8703dd05 Mon Sep 17 00:00:00 2001 From: d7ommy Date: Tue, 24 Nov 2026 21:43:04 +0300 Subject: [PATCH 2/2] d3d12_xs: preserve all-zero DXBC checksum compatibility in versioned deserializer --- runtime/shims/d3d12_xs.cpp | 7 ------- runtime/test/root_sig_test.cpp | 10 ++++++++++ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/runtime/shims/d3d12_xs.cpp b/runtime/shims/d3d12_xs.cpp index ce44a2106b..3d8cccfa2f 100644 --- a/runtime/shims/d3d12_xs.cpp +++ b/runtime/shims/d3d12_xs.cpp @@ -124,13 +124,6 @@ HRESULT WINAPI create_versioned_root_signature_deserializer(const void* data, SI std::vector cleared; if (rt::d3d12_xs::copy_rts0_blob_clear_xbox_flags(data, static_cast(size), cleared)) { - uint32_t hash[4]; - const auto* bytes = static_cast(data); - rt::d3d12_xs::dxbc_checksum(bytes, static_cast(size), hash); - if (std::memcmp(bytes + 4, hash, sizeof(hash)) != 0) { - if (out) *out = nullptr; - return E_INVALIDARG; - } return fn(cleared.data(), cleared.size(), iid, out); } return fn(data, size, iid, out); diff --git a/runtime/test/root_sig_test.cpp b/runtime/test/root_sig_test.cpp index 9cdf0dd26f..cc828b36cc 100644 --- a/runtime/test/root_sig_test.cpp +++ b/runtime/test/root_sig_test.cpp @@ -595,6 +595,16 @@ void test_deserializer() { check(SUCCEEDED(hr_zero) && shim_zero && shim_zero->GetRootSignatureDesc()->Flags == 0, "shim deserializer accepts an all-zero-checksum Xbox blob with the high byte cleared"); if (shim_zero) shim_zero->Release(); + + if (versioned) { + ID3D12VersionedRootSignatureDeserializer* v_zero = nullptr; + const HRESULT v_hr_zero = versioned(zero_hash.data(), zero_hash.size(), IID_PPV_ARGS(&v_zero)); + const auto* desc = v_zero ? v_zero->GetUnconvertedRootSignatureDesc() : nullptr; + check(SUCCEEDED(v_hr_zero) && v_zero && desc && + desc->Version == D3D_ROOT_SIGNATURE_VERSION_1_0 && desc->Desc_1_0.Flags == 0, + "versioned shim accepts an all-zero-checksum Xbox blob with the high byte cleared"); + if (v_zero) v_zero->Release(); + } } }