Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/d3d12_xs_surface.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
23 changes: 23 additions & 0 deletions runtime/shims/d3d12_xs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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<VersionedDeserializerFn>(host("D3D12CreateVersionedRootSignatureDeserializer"));
if (!fn) return E_NOTIMPL;

std::vector<uint8_t> cleared;
if (rt::d3d12_xs::copy_rts0_blob_clear_xbox_flags(data, static_cast<size_t>(size), cleared)) {
uint32_t hash[4];
const auto* bytes = static_cast<const uint8_t*>(data);
rt::d3d12_xs::dxbc_checksum(bytes, static_cast<size_t>(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
Expand Down Expand Up @@ -215,6 +234,7 @@ HRESULT WINAPI D3D12XboxCreateDevice(IUnknown* adapter, const void* params, cons

static_assert(std::is_same_v<decltype(&serialize_root_signature), SerializeFn>);
static_assert(std::is_same_v<decltype(&create_root_signature_deserializer), DeserializerFn>);
static_assert(std::is_same_v<decltype(&create_versioned_root_signature_deserializer), VersionedDeserializerFn>);
static_assert(std::is_same_v<decltype(&serialize_root_signature_legacy), LegacySerializeFn>);

// 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
Expand All @@ -229,6 +249,9 @@ SHIM_TABLE(d3d12_xs,
{"d3d12_xs.dll", "D3D12SerializeRootSignature", reinterpret_cast<void*>(&serialize_root_signature_legacy)},
{"d3d12_xs.dll", "D3D12CreateRootSignatureDeserializer",
reinterpret_cast<void*>(&create_root_signature_deserializer)},
{"d3d12_xs.dll", "D3D12CreateVersionedRootSignatureDeserializer",
reinterpret_cast<void*>(&create_versioned_root_signature_deserializer)},
{"d3d12_xs.dll", "#7", reinterpret_cast<void*>(&create_versioned_root_signature_deserializer)},
{"d3d12_xs.dll", "D3D12XboxCreateDevice", reinterpret_cast<void*>(&D3D12XboxCreateDevice)},
{"d3d12_xs.dll", "D3D12ConfigureVirtualMemoryX", reinterpret_cast<void*>(&configure_virtual_memory)},
);
31 changes: 31 additions & 0 deletions runtime/test/root_sig_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,37 @@ void test_deserializer() {
auto deserialize = reinterpret_cast<DeserializeFn>(
rt::shims::find("d3d12_xs.dll", "D3D12CreateRootSignatureDeserializer"));
check(deserialize != nullptr, "shim registry exposes d3d12_xs!D3D12CreateRootSignatureDeserializer");
auto versioned = reinterpret_cast<decltype(&D3D12CreateVersionedRootSignatureDeserializer)>(
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<void*>(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;
Expand Down
Loading