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
4 changes: 2 additions & 2 deletions runtime/shims/acphal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ struct SHAPE_XMA_CONTEXT {
uint32_t reserved1 : 6;
uint32_t loopStartOffset : 26;
uint32_t loopEndOffset : 6;
uint32_t reserved[10];
uint32_t reserved[11];
};
static_assert(sizeof(SHAPE_XMA_CONTEXT) == 64, "SHAPE_XMA_CONTEXT is 64 bytes per GDK");

Expand All @@ -162,7 +162,7 @@ struct SHAPE_PCM_CONTEXT {
uint32_t reserved6 : 15;
uint32_t format : 2;
uint32_t reserved7 : 14;
uint32_t reserved[1];
uint32_t reserved[2];
};
static_assert(sizeof(SHAPE_PCM_CONTEXT) == 32, "SHAPE_PCM_CONTEXT is 32 bytes per GDK");

Expand Down
4 changes: 3 additions & 1 deletion runtime/shims/d3d12_vulkan_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5008,6 +5008,7 @@ class Device final
// standalone device gta6rt --run uses both come through here (found in review: registering only in
// create_vulkan_device left the retail path without it).
rt::d3d12_xs::set_placed_at_va_handler(&create_buffer_at_host_address);
rt::d3d12_xs::set_console_descriptor_heap_handler(&create_console_descriptor_heap);
state_.info = info;
queue_users_.resize(info.command_queues.size(), 0);
compute_users_.resize(info.compute_queues.size(), 0);
Expand Down Expand Up @@ -5499,6 +5500,7 @@ class Device final
leonida::VulkanContext& context() { return *state_.context; }
const leonida::BindlessSet* bindless() const { return state_.bindless.get(); }
const DeviceState& state() const { return state_; }
DeviceState& state() { return state_; }
IUnknown* holder() { return identity(); }
bool bind_sampler(const leonida::gfx10::SamplerWords& words) { return state_.bind_sampler(words); }
void own(const OwnedRuntime& owned) { owned_ = owned; }
Expand Down Expand Up @@ -9999,7 +10001,7 @@ HRESULT create_console_descriptor_heap(ID3D12Device* device, const D3D12_DESCRIP
if (!d) return E_INVALIDARG;

auto* heap = new DescriptorHeap(d->state(), *desc, console_address, console_size);
heap->attach_device(d->identity());
heap->attach_device(d->holder());
if (!heap->ok()) {
heap->Release();
return E_OUTOFMEMORY;
Expand Down
28 changes: 21 additions & 7 deletions runtime/shims/d3d12_xs_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1579,6 +1579,8 @@ static bool readable_range(const void* ptr, std::size_t bytes) {
return true;
}

static std::atomic<ConsoleDescriptorHeapHandler> g_console_descriptor_heap{nullptr};

HRESULT proxy_create_descriptor_heap(DeviceProxy* self, const D3D12_DESCRIPTOR_HEAP_DESC* desc, const IID* riid,
void** out) {
note_slot(14);
Expand All @@ -1599,13 +1601,21 @@ HRESULT proxy_create_descriptor_heap(DeviceProxy* self, const D3D12_DESCRIPTOR_H
std::uint64_t size = 0;
std::memcpy(&address, tail, sizeof(address));
std::memcpy(&size, bytes + sizeof(D3D12_DESCRIPTOR_HEAP_DESC) + sizeof(address), sizeof(size));
// Console-extended slot 14 (issue #313): address/size follow the PC desc. Only take this path when a
// non-zero console VA is present; normal PC 16-byte descs never enter it.
if (address != 0) {
console_extended = true;
hr = rt::d3d12::create_console_descriptor_heap(
self->real, desc, static_cast<D3D12_GPU_VIRTUAL_ADDRESS>(address), size,
__uuidof(ID3D12DescriptorHeap), &created);
// Console-extended slot 14 (issue #313): address/size follow the PC desc. Require a plausible aligned
// canonical VA and a matching non-zero heap byte size so normal stack-allocated 16-byte PC descs with
// adjacent stack data never enter this path by accident.
const std::uint64_t min_size = std::uint64_t(desc->NumDescriptors) * 16ull;
const std::uint64_t max_size = std::uint64_t(desc->NumDescriptors) * 128ull;
const bool plausible_console_va = address >= 0x10000ull && address < 0x0000800000000000ull &&
(address & 0xffull) == 0;
const bool plausible_size = desc->NumDescriptors > 0 && size >= min_size && size <= max_size &&
(size & 0xfull) == 0;
if (plausible_console_va && plausible_size) {
if (const auto handler = g_console_descriptor_heap.load(std::memory_order_acquire)) {
console_extended = true;
hr = handler(self->real, desc, static_cast<D3D12_GPU_VIRTUAL_ADDRESS>(address), size,
__uuidof(ID3D12DescriptorHeap), &created);
}
}
}
}
Expand Down Expand Up @@ -2041,6 +2051,10 @@ void set_placed_at_va_pages_hook(PlacedAtVaPagesHook hook) {
g_placed_at_va_pages.store(hook, std::memory_order_release);
}

void set_console_descriptor_heap_handler(ConsoleDescriptorHeapHandler handler) {
g_console_descriptor_heap.store(handler, std::memory_order_release);
}

ID3D12Device* device_proxy_real_device(const void* device) {
if (!is_device_proxy(device)) return nullptr;
return static_cast<const DeviceProxy*>(device)->real;
Expand Down
8 changes: 8 additions & 0 deletions runtime/shims/d3d12_xs_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,14 @@ void set_placed_at_va_handler(PlacedAtVaHandler handler);
using PlacedAtVaPagesHook = bool (*)(const void* va, std::size_t bytes);
void set_placed_at_va_pages_hook(PlacedAtVaPagesHook hook);

// Device slot 14 with a console-extended descriptor heap desc (address/size after the PC 16-byte desc, issue #313)
// delegates creation to this handler, which the Vulkan layer registers (rt::d3d12::create_console_descriptor_heap).
// With none registered (e.g. standalone proxy tests without the Vulkan layer), slot 14 falls back to the PC path.
using ConsoleDescriptorHeapHandler = HRESULT (*)(ID3D12Device* real, const D3D12_DESCRIPTOR_HEAP_DESC* desc,
D3D12_GPU_VIRTUAL_ADDRESS console_address,
std::uint64_t console_size, REFIID riid, void** out);
void set_console_descriptor_heap_handler(ConsoleDescriptorHeapHandler handler);

// True for slots the proxy handles itself rather than forwarding verbatim: IUnknown (0-2), 8 and 75 (queue
// proxies), 9 (allocator proxies), 14, 31/34/35/45/46/50 (proxies unwrapped), 32 and 36 (fence proxies), 48/73 and
// 78/79/80 (the Xbox slots above, at their configured indices), 62, 67 and 76. Slot 10 is intentionally false: the
Expand Down
18 changes: 11 additions & 7 deletions runtime/test/d3d12_console_descriptor_heap_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ struct Ref {
return &p;
}
T* get() const { return p; }
T* operator->() const { return p; }
};

bool check_console_addressed_heap(ID3D12Device* device) {
Expand Down Expand Up @@ -64,13 +65,13 @@ bool check_console_addressed_heap(ID3D12Device* device) {
}

bool check_xs_proxy_slot14(ID3D12Device* real_device) {
void* proxy_raw = nullptr;
if (FAILED(rt::d3d12_xs::create_device_proxy(real_device, IID_PPV_ARGS(&proxy_raw))) || !proxy_raw) {
Ref<ID3D12Device> proxy;
real_device->AddRef();
if (FAILED(rt::d3d12_xs::create_device_proxy(real_device, IID_PPV_ARGS(proxy.put()))) || !proxy.get()) {
real_device->Release();
std::fprintf(stderr, "create_device_proxy failed\n");
return false;
}
Ref<ID3D12Device> proxy;
proxy.p = static_cast<ID3D12Device*>(proxy_raw);

struct ConsoleDescriptorHeapDesc {
D3D12_DESCRIPTOR_HEAP_DESC desc{};
Expand All @@ -90,10 +91,13 @@ bool check_xs_proxy_slot14(ID3D12Device* real_device) {
static_cast<unsigned long>(hr));
return false;
}
const auto cpu = heap->GetCPUDescriptorHandleForHeapStart();
if (cpu.ptr != static_cast<SIZE_T>(console.address)) {
// Heap proxy slot 9 uses the Xbox ABI (returns the 8-byte handle in RAX, not via hidden RDX pointer).
auto** vtbl = *reinterpret_cast<void***>(heap.get());
using XboxGetHandleFn = std::uint64_t(STDMETHODCALLTYPE*)(void*);
const std::uint64_t cpu = reinterpret_cast<XboxGetHandleFn>(vtbl[9])(heap.get());
if (cpu != console.address) {
std::fprintf(stderr, "proxy CPU heap start mismatch: got 0x%llx want 0x%llx\n",
static_cast<unsigned long long>(cpu.ptr),
static_cast<unsigned long long>(cpu),
static_cast<unsigned long long>(console.address));
return false;
}
Expand Down