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
10 changes: 8 additions & 2 deletions runtime/shims/d3d12_vulkan_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5500,6 +5500,13 @@ class Device final
const leonida::BindlessSet* bindless() const { return state_.bindless.get(); }
const DeviceState& state() const { return state_; }
IUnknown* holder() { return identity(); }
// A descriptor heap whose handle starts report the console's address (create_console_descriptor_heap).
DescriptorHeap* new_console_descriptor_heap(const D3D12_DESCRIPTOR_HEAP_DESC& desc, std::uint64_t address,
std::uint64_t size) {
auto* heap = new DescriptorHeap(state_, desc, address, size);
heap->attach_device(identity());
return heap;
}
bool bind_sampler(const leonida::gfx10::SamplerWords& words) { return state_.bind_sampler(words); }
void own(const OwnedRuntime& owned) { owned_ = owned; }
void set_outer(IUnknown* outer) { outer_ = outer; }
Expand Down Expand Up @@ -9998,8 +10005,7 @@ HRESULT create_console_descriptor_heap(ID3D12Device* device, const D3D12_DESCRIP
auto* d = Device::from<Device>(real ? real : device);
if (!d) return E_INVALIDARG;

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

// Registered by the Vulkan layer (set_console_descriptor_heap_handler).
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 @@ -1601,9 +1604,11 @@ HRESULT proxy_create_descriptor_heap(DeviceProxy* self, const D3D12_DESCRIPTOR_H
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) {
const ConsoleDescriptorHeapHandler handler =
g_console_descriptor_heap.load(std::memory_order_acquire);
if (address != 0 && handler) {
console_extended = true;
hr = rt::d3d12::create_console_descriptor_heap(
hr = handler(
self->real, desc, static_cast<D3D12_GPU_VIRTUAL_ADDRESS>(address), size,
__uuidof(ID3D12DescriptorHeap), &created);
}
Expand Down Expand Up @@ -2033,6 +2038,10 @@ unsigned device_proxy_slot_count(const void* device) {
return static_cast<const DeviceProxy*>(device)->slot_count;
}

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

void set_placed_at_va_handler(PlacedAtVaHandler handler) {
g_placed_at_va.store(handler, std::memory_order_release);
}
Expand Down
11 changes: 11 additions & 0 deletions runtime/shims/d3d12_xs_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,17 @@ using PlacedAtVaHandler = HRESULT (*)(ID3D12Device* real, void* va, const D3D12_
std::uint32_t layout, REFIID riid, void** out);
void set_placed_at_va_handler(PlacedAtVaHandler handler);

// Device slot 14 with the console's extended descriptor (address and size after the PC D3D12_DESCRIPTOR_HEAP_DESC,
// issue #313) is created by the device behind the proxy through this handler (rt::d3d12::create_console_descriptor_heap).
// A handler keeps this file free of a link dependency on the Vulkan layer: it is also built into tests without it.
// Nothing registers it by default: the slot reads 16 bytes past a PC descriptor and takes any non-zero word there
// for a console address, which a PC caller's stack can hold (d3d12_f16_halves crashed that way). With none
// registered the slot creates a plain PC heap, as before #9576.
using ConsoleDescriptorHeapHandler = HRESULT (*)(ID3D12Device* real, const D3D12_DESCRIPTOR_HEAP_DESC* desc,
D3D12_GPU_VIRTUAL_ADDRESS address, std::uint64_t size,
REFIID riid, void** out);
void set_console_descriptor_heap_handler(ConsoleDescriptorHeapHandler handler);

// Called by slot 133 for a buffer, before the handler, with the buffer's range [va, va + width). gta6rt registers
// rt::xmem::commit_physical_range: xmem commits physical pages on first touch, so a range the title has mapped but
// not written yet is still reserved, and the handler's import refuses reserved pages (it would answer with its
Expand Down
5 changes: 4 additions & 1 deletion 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 @@ -65,7 +66,7 @@ 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) {
if (FAILED(rt::d3d12_xs::create_device_proxy(real_device, __uuidof(ID3D12Device), &proxy_raw)) || !proxy_raw) {
std::fprintf(stderr, "create_device_proxy failed\n");
return false;
}
Expand Down Expand Up @@ -126,6 +127,8 @@ int main() {
const auto status = vk.initialize();
if (status == vktest::DeviceStatus::unavailable) return 77;
if (status != vktest::DeviceStatus::ready) return 1;
// The console slot 14 path is opt-in (d3d12_xs_device.h); this test exercises it.
rt::d3d12_xs::set_console_descriptor_heap_handler(&rt::d3d12::create_console_descriptor_heap);

Ref<ID3D12Device> device;
rt::d3d12::VulkanDeviceInfo info{};
Expand Down