mirror of
https://github.com/ProjectLeonida/mandy.git
synced 2026-12-06 22:58:37 +00:00
89 lines
3.8 KiB
C++
89 lines
3.8 KiB
C++
// ID3D12Device3::OpenExistingHeapFromAddress, OpenExistingHeapFromFileMapping and ID3D12Device5::CreateLifetimeTracker
|
|
// on arguments the host D3D12 runtime refuses (null address, a file mapping that is not a handle, a null owner), all
|
|
// E_INVALIDARG on the RTX 4080 SUPER, Intel UHD 770 and WARP. Checked on the Vulkan-backed device and, when present,
|
|
// on the host devices too; a call the host accepts is not compared (this device reports EXISTING_HEAPS unsupported).
|
|
// No shaders or game data.
|
|
// https://learn.microsoft.com/en-us/windows/win32/api/d3d12/nf-d3d12-id3d12device3-openexistingheapfromaddress
|
|
#include "vk_test_device.h"
|
|
#include "host_adapter.h"
|
|
#include "host_wine.h"
|
|
#include "../shims/d3d12_com.h"
|
|
#include <dxgi1_4.h>
|
|
|
|
#define EXPECT(condition) do { \
|
|
if (!(condition)) { std::fprintf(stderr, "%s line %d: %s\n", who, __LINE__, #condition); return 1; } \
|
|
} while (0)
|
|
#define EXPECT_HR(expr, want) do { \
|
|
const HRESULT got_ = (expr); \
|
|
if (got_ != (want)) { \
|
|
std::fprintf(stderr, "%s line %d: %s = 0x%08lX, expected 0x%08lX\n", who, __LINE__, #expr, \
|
|
static_cast<unsigned long>(got_), static_cast<unsigned long>(want)); \
|
|
return 1; \
|
|
} \
|
|
} while (0)
|
|
|
|
namespace {
|
|
template<class T>
|
|
struct Ref {
|
|
T* p = nullptr;
|
|
~Ref() { if (p) p->Release(); }
|
|
T* operator->() const { return p; }
|
|
};
|
|
|
|
int check(ID3D12Device* device, const char* who) {
|
|
Ref<ID3D12Device3> device3;
|
|
EXPECT(SUCCEEDED(device->QueryInterface(IID_PPV_ARGS(&device3.p))));
|
|
Ref<ID3D12Heap> heap;
|
|
EXPECT_HR(device3->OpenExistingHeapFromAddress(nullptr, IID_PPV_ARGS(&heap.p)), E_INVALIDARG);
|
|
EXPECT(heap.p == nullptr);
|
|
EXPECT_HR(device3->OpenExistingHeapFromFileMapping(nullptr, IID_PPV_ARGS(&heap.p)), E_INVALIDARG);
|
|
EXPECT_HR(device3->OpenExistingHeapFromFileMapping(reinterpret_cast<HANDLE>(0x1234), IID_PPV_ARGS(&heap.p)),
|
|
E_INVALIDARG);
|
|
EXPECT(heap.p == nullptr);
|
|
Ref<ID3D12Device5> device5;
|
|
if (SUCCEEDED(device->QueryInterface(IID_PPV_ARGS(&device5.p)))) {
|
|
Ref<ID3D12LifetimeTracker> tracker;
|
|
EXPECT_HR(device5->CreateLifetimeTracker(nullptr, IID_PPV_ARGS(&tracker.p)), E_INVALIDARG);
|
|
EXPECT(tracker.p == nullptr);
|
|
}
|
|
std::printf("%s: existing-heap and lifetime-tracker refusals match the host runtime\n", who);
|
|
return 0;
|
|
}
|
|
} // namespace
|
|
|
|
int main() {
|
|
vktest::Device vk;
|
|
const auto status = vk.initialize();
|
|
if (status == vktest::DeviceStatus::unavailable) return 77;
|
|
if (status != vktest::DeviceStatus::ready) return 1;
|
|
int failures = 0;
|
|
{
|
|
Ref<ID3D12Device> ours;
|
|
rt::d3d12::VulkanDeviceInfo info{};
|
|
info.get_instance_proc = vk.instance_proc;
|
|
info.instance = vk.instance;
|
|
info.physical = vk.physical;
|
|
info.device = vk.device;
|
|
info.queue = vk.queue;
|
|
info.queue_family = vk.family;
|
|
if (FAILED(rt::d3d12::create_vulkan_device(info, IID_PPV_ARGS(&ours.p)))) return 1;
|
|
failures += check(ours.p, "vulkan");
|
|
Ref<IDXGIFactory4> factory;
|
|
if (!hostwine::host_is_wine() && SUCCEEDED(CreateDXGIFactory1(IID_PPV_ARGS(&factory.p)))) {
|
|
for (const bool warp : {false, true}) {
|
|
Ref<IDXGIAdapter> adapter;
|
|
Ref<ID3D12Device> host;
|
|
std::string adapter_name;
|
|
if (!hostadapter::reference(factory.p, vk, warp, &adapter.p, adapter_name)) continue;
|
|
if (FAILED(D3D12CreateDevice(adapter.p, D3D_FEATURE_LEVEL_11_0, IID_PPV_ARGS(&host.p)))) continue;
|
|
failures += check(host.p, ("host " + adapter_name).c_str());
|
|
}
|
|
}
|
|
}
|
|
if (vk.validation_errors()) {
|
|
std::fprintf(stderr, "%u validation errors\n", vk.validation_errors());
|
|
return 1;
|
|
}
|
|
return failures ? 1 : 0;
|
|
}
|