d3d12: preserve PC descriptor validation in slot 25

This commit is contained in:
Johan John Joji
2026-11-23 11:37:29 -05:00
parent d7451f9d9b
commit b4d1ba1794
5 changed files with 32 additions and 11 deletions

View File

@ -2223,8 +2223,9 @@ The trace will enumerate them.
retail title's own sizes are not measured (#6982, stop 17), so that its allocation is these shapes and no DCC or
CMask memory is open until they are.
The descriptions the title passes to slot 25 carry console values (layout word `0x101`/`0x1`, flag bits above the PC
ones). The proxy gives the PC device a copy with the PC flags only and ROW_MAJOR (buffer) or UNKNOWN (texture); the
title's array is never written (`d3d12_xs_desc_clean.h`, the same cleaning as slot 76; #6982 section 3.7).
ones). For console-form calls or descriptors explicitly using layout `0x101`, the proxy strips Xbox-only flags and
translates layout `0x101` to ROW_MAJOR for buffers or UNKNOWN for textures. Other PC-form descriptors reach the host
unchanged for validation (`d3d12_xs_desc_clean.h`; #6982 section 3.7).
- `GetAdapterLuid` (implemented): `VkPhysicalDeviceIDProperties::deviceLUID`, which on Windows is the DXGI
adapter's LUID; `d3d12_fence_timing_test` finds it with `IDXGIFactory4::EnumAdapterByLuid` (RTX 4090, driver
621.14). A driver that reports `deviceLUIDValid = VK_FALSE` gets a zero LUID, logged.

View File

@ -21,12 +21,15 @@ constexpr std::uint32_t kPcResourceFlagsMask =
D3D12_RESOURCE_FLAG_VIDEO_DECODE_REFERENCE_ONLY | D3D12_RESOURCE_FLAG_VIDEO_ENCODE_REFERENCE_ONLY |
D3D12_RESOURCE_FLAG_RAYTRACING_ACCELERATION_STRUCTURE;
// A copy of the title's description with the PC flags only and a PC layout: ROW_MAJOR for a buffer, UNKNOWN for a
// texture (the layout the PC device picks itself).
constexpr auto kXboxTiledResourceLayout = static_cast<D3D12_TEXTURE_LAYOUT>(0x101);
// Strip Xbox-only flags and translate the Xbox tiled layout. Preserve all other layouts so the host can validate them.
inline D3D12_RESOURCE_DESC pc_resource_desc(const D3D12_RESOURCE_DESC& xbox) {
D3D12_RESOURCE_DESC pc = xbox;
pc.Layout = xbox.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER ? D3D12_TEXTURE_LAYOUT_ROW_MAJOR
: D3D12_TEXTURE_LAYOUT_UNKNOWN;
if (pc.Layout == kXboxTiledResourceLayout) {
pc.Layout = pc.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER ? D3D12_TEXTURE_LAYOUT_ROW_MAJOR
: D3D12_TEXTURE_LAYOUT_UNKNOWN;
}
pc.Flags = static_cast<D3D12_RESOURCE_FLAGS>(static_cast<std::uint32_t>(xbox.Flags) & kPcResourceFlagsMask);
return pc;
}

View File

@ -1631,13 +1631,14 @@ void** get_vtable();
struct StructReturnCall {
DeviceProxy* self;
void* ret;
bool console_abi;
};
StructReturnCall struct_return_call(std::uint64_t a0, std::uint64_t a1) {
void** const vtable = get_vtable();
if (a0 && *reinterpret_cast<void***>(a0) == vtable) // PC form: this, return buffer
return {reinterpret_cast<DeviceProxy*>(a0), reinterpret_cast<void*>(a1)};
return {reinterpret_cast<DeviceProxy*>(a1), reinterpret_cast<void*>(a0)}; // C form: return buffer, this
return {reinterpret_cast<DeviceProxy*>(a0), reinterpret_cast<void*>(a1), false};
return {reinterpret_cast<DeviceProxy*>(a1), reinterpret_cast<void*>(a0), true}; // C form: return buffer, this
}
// The console size of a list of descriptions (d3d12_xs_alloc_size.h): the PC device's answer with every console render
@ -1664,8 +1665,8 @@ void* WINAPI proxy_get_resource_allocation_info(std::uint64_t a0, std::uint64_t
note_slot(25);
const StructReturnCall call = struct_return_call(a0, a1);
ID3D12Device* const real = call.self->real;
// The descriptions are the console's. The PC device gets a copy with PC flags and layout; the title's array is
// read only. A copy that cannot be made answers as an invalid description.
// Normalize console descriptors in a copy. PC calls can also pass the Xbox tiled layout explicitly. Otherwise
// their flags and layout reach the host unchanged so the host can validate them.
const UINT desc_count = static_cast<UINT>(count);
std::unique_ptr<D3D12_RESOURCE_DESC[]> clean;
if (descs && desc_count) {
@ -1674,7 +1675,10 @@ void* WINAPI proxy_get_resource_allocation_info(std::uint64_t a0, std::uint64_t
*static_cast<D3D12_RESOURCE_ALLOCATION_INFO*>(call.ret) = {UINT64_MAX, D3D12_DEFAULT_RESOURCE_PLACEMENT_ALIGNMENT};
return call.ret;
}
for (UINT i = 0; i < desc_count; ++i) clean[i] = pc_resource_desc(descs[i]);
for (UINT i = 0; i < desc_count; ++i) {
const auto& desc = descs[i];
clean[i] = call.console_abi || desc.Layout == kXboxTiledResourceLayout ? pc_resource_desc(desc) : desc;
}
descs = clean.get();
}
const UINT mask = static_cast<UINT>(visible_mask);

View File

@ -217,6 +217,7 @@ int main(int argc, char** argv) {
// the PC device's for the cleaned description (the raw 0x101 layout makes WARP answer UINT64_MAX).
const D3D12_RESOURCE_DESC clean = rt::d3d12_xs::pc_resource_desc(desc);
const D3D12_RESOURCE_ALLOCATION_INFO want = real->GetResourceAllocationInfo(0, 1, &clean);
check(want.SizeInBytes != UINT64_MAX, "WARP accepts the normalized slot-25 buffer description");
check(returned == &got, "slot 25 returns the caller's buffer in RAX");
check(got.SizeInBytes == want.SizeInBytes && got.Alignment == want.Alignment,
"slot 25 (C ABI) writes the PC device's GetResourceAllocationInfo into the caller's buffer");

View File

@ -892,6 +892,18 @@ int check_allocation_descriptions_cleaned() {
EXPECT(std::memcmp(kept, titles, sizeof(kept)) == 0);
EXPECT(info.SizeInBytes == 8847360 + 131072);
// PC calls must keep their layout and flags so the host can reject an invalid descriptor.
using PcFn = D3D12_RESOURCE_ALLOCATION_INFO*(WINAPI*)(void*, D3D12_RESOURCE_ALLOCATION_INFO*, UINT, UINT,
const D3D12_RESOURCE_DESC*);
const auto get_pc_info = reinterpret_cast<PcFn>(vtable[25]);
D3D12_RESOURCE_DESC pc_buffer = titles[1];
pc_buffer.Layout = D3D12_TEXTURE_LAYOUT_64KB_UNDEFINED_SWIZZLE;
pc_buffer.Flags = static_cast<D3D12_RESOURCE_FLAGS>(0x1000);
g_seen_calls = 0;
EXPECT(get_pc_info(device, &info, 0, 1, &pc_buffer) == &info);
EXPECT(g_seen_desc_count == 1 && g_seen_descs[0].Layout == D3D12_TEXTURE_LAYOUT_64KB_UNDEFINED_SWIZZLE);
EXPECT(g_seen_descs[0].Flags == pc_buffer.Flags);
// A null array with a zero count reaches the PC device as it came.
g_seen_desc_count = 99;
g_seen_calls = 0;