Files
mandy/runtime/test/d3d12_fence_events_test.cpp
lloyd 806ee523c4 tests: D3D12 host comparisons skip under Wine (TEST-105 follow-up)
The host-comparison tests added since #869 create their host devices with
D3D12CreateDevice themselves, so copycmp::try_create_host's Wine check never
reached them. Under Wine the reference is vkd3d, not Microsoft's runtime,
and they failed on a real GPU for that reason alone.

runtime/test/host_wine.h has the same check (ntdll's wine_get_version) for
them. Under Wine:
- d3d12_fence_events, d3d12_query_rules: the layer's own expectations
  still run; only the host references are skipped.
- d3d12_depth_resolve: the layer is still checked against the clears; a
  host reference is no longer required.
- d3d12_resource_desc, d3d12_node_mask, d3d12_copy_xfmt,
  d3d12_typeless_rtv, d3d12_predicated_copy: every case compares with the
  host (or WARP), so they exit 77, which ctest already reads as a skip.
Windows runs them all as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 12:25:32 +02:00

110 lines
4.8 KiB
C++

// Fence events the host D3D12 runtime (RTX 5070 and WARP) sets or refuses, checked on the Vulkan-backed device and,
// when present, on the host devices too: releasing a fence completes the events still waiting on it (ALL counts it
// as one fence reached, ANY is satisfied), and SetEventOnMultipleFenceCompletion with no fences is E_INVALIDARG and
// sets nothing. No shaders or game data. LEONIDA_VK_VALIDATION=1 fails the test on any validation error.
#include "vk_test_device.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)
namespace {
template<class T>
struct Ref {
T* p = nullptr;
~Ref() { if (p) p->Release(); }
T* operator->() const { return p; }
};
struct Event {
HANDLE h = CreateEventW(nullptr, FALSE, FALSE, nullptr);
~Event() { CloseHandle(h); }
bool set_within(DWORD ms) const { return WaitForSingleObject(h, ms) == WAIT_OBJECT_0; }
};
int check(ID3D12Device* device, const char* who) {
Ref<ID3D12Device1> device1;
EXPECT(SUCCEEDED(device->QueryInterface(IID_PPV_ARGS(&device1.p))));
constexpr auto ALL = D3D12_MULTIPLE_FENCE_WAIT_FLAG_ALL, ANY = D3D12_MULTIPLE_FENCE_WAIT_FLAG_ANY;
{ // A fence released before its value is reached sets the event.
ID3D12Fence* fence = nullptr;
EXPECT(SUCCEEDED(device->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&fence))));
Event event;
EXPECT(SUCCEEDED(fence->SetEventOnCompletion(5, event.h)));
fence->Release();
EXPECT(event.set_within(2000));
}
for (const auto flags : {ALL, ANY}) { // Released with a multi-fence wait pending: one fence counted as reached.
ID3D12Fence* released = nullptr;
Ref<ID3D12Fence> other;
EXPECT(SUCCEEDED(device->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&released))));
EXPECT(SUCCEEDED(device->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&other.p))));
ID3D12Fence* fences[2] = {released, other.p};
const UINT64 values[2] = {5, 1};
Event event;
EXPECT(SUCCEEDED(device1->SetEventOnMultipleFenceCompletion(fences, values, 2, flags, event.h)));
released->Release();
if (flags == ANY) {
EXPECT(event.set_within(2000));
} else {
EXPECT(!event.set_within(100)); // still waiting for the other fence
EXPECT(SUCCEEDED(other->Signal(1)));
EXPECT(event.set_within(2000));
}
}
{ // No fences: refused, with or without an event, and the event is left alone.
Ref<ID3D12Fence> fence;
EXPECT(SUCCEEDED(device->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&fence.p))));
ID3D12Fence* fences[1] = {fence.p};
const UINT64 values[1] = {1};
Event event;
for (const auto flags : {ALL, ANY}) {
EXPECT(device1->SetEventOnMultipleFenceCompletion(fences, values, 0, flags, event.h) == E_INVALIDARG);
EXPECT(device1->SetEventOnMultipleFenceCompletion(nullptr, nullptr, 0, flags, event.h) == E_INVALIDARG);
EXPECT(device1->SetEventOnMultipleFenceCompletion(fences, values, 0, flags, nullptr) == E_INVALIDARG);
}
EXPECT(!event.set_within(0));
}
std::printf("%s: fence events 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}) { // the reference the expectations were measured on
Ref<IDXGIAdapter> adapter;
Ref<ID3D12Device> host;
if (warp && FAILED(factory->EnumWarpAdapter(IID_PPV_ARGS(&adapter.p)))) continue;
if (FAILED(D3D12CreateDevice(adapter.p, D3D_FEATURE_LEVEL_11_0, IID_PPV_ARGS(&host.p)))) continue;
failures += check(host.p, warp ? "host WARP" : "host default adapter");
}
}
}
if (vk.validation_errors()) {
std::fprintf(stderr, "%u validation errors\n", vk.validation_errors());
return 1;
}
return failures ? 1 : 0;
}