mirror of
https://github.com/ProjectLeonida/mandy.git
synced 2026-12-06 09:48:38 +00:00
Merge pull request #519 from milk4sale/test/wine-host-guards
Merging. **Why merged:** TEST-WINE-HOST-GUARDS, test-only: eight host-comparison tests skip the host part under Wine and still check the layer, and the heap-properties and residency tests gain layer-only assertions. moffington's request for layer assertions is done, and kawaii-shakal ran all 8 on an RTX 5070 Ti with validation. **Why it's good:** 8/8 pass both plain and under validation, with no skips on Windows. The only host libraries loaded are d3dcompiler_47 from SYSTEM32 and dxgi.dll. Tested on Windows 11 / RTX 4070 SUPER (NVIDIA 621.24), VS 2022 + Ninja RelWithDebInfo, Vulkan SDK 1.4.363.0. Merged alone onto main66d4f5aa3, its ctests pass both plain and with LEONIDA_VK_VALIDATION=1. Cumulative of this batch (13 PRs) on main0b45fdc21: the repo-consistency set gives 573 passed / 5 skipped / 0 failed, compileall is clean, and full ctest is 314/316 with the same 11 skips. The only failures are main's: d3d12_depth_resolve (pre-existing) and d3d12_close_parity (the #510 regression, fixed by #1286). All d3d12_* tests under validation show 0 VUIDs. git merge-tree against current main6261ca916: no conflicts. Security read of the three-dot diff: no binaries, game data, downloads, network calls or CI changes. AI-assisted (Claude Code, Claude Opus 5.5).
This commit is contained in:
@ -5,11 +5,14 @@
|
||||
// the node masks and DENY bits of a few committed resources; this test covers the rest. Every value is recorded,
|
||||
// with whether the call wrote its outputs (they start as a sentinel), and the two records must be the same. A
|
||||
// resource one device refuses to create is reported and its steps aren't compared. No shaders or game data. Skips
|
||||
// (77) without a Vulkan GPU or the standalone device; without a host D3D12 device only the layer's own record is
|
||||
// printed. The host runs on the layer's adapter (host_adapter.h; LEONIDA_HOST_ADAPTER picks another, "warp" WARP).
|
||||
// (77) without a Vulkan GPU or the standalone device. The layer's record is first checked on its own (layer_wrong:
|
||||
// what D3D12 documents for the call), on every host; without a host D3D12 device that is all that is checked, and so
|
||||
// it is under Wine, whose host is vkd3d and reports other heap flags (host_wine.h). The host runs on
|
||||
// the layer's adapter (host_adapter.h; LEONIDA_HOST_ADAPTER picks another, "warp" WARP).
|
||||
// Set LEONIDA_D3D49_VERBOSE=1 to print every value.
|
||||
#include "../shims/d3d12_com.h"
|
||||
#include "host_adapter.h"
|
||||
#include "host_wine.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
@ -227,6 +230,85 @@ void run(ID3D12Device* device, Record& out) {
|
||||
}
|
||||
}
|
||||
|
||||
// What the layer has to answer whatever the host is, checked on its record alone so that a run with no host to
|
||||
// compare with (no host device, or Wine's) still fails on a wrong answer. D3D12 documents GetHeapProperties for
|
||||
// committed and placed resources, with either output optional, and not for reserved ones. So for every committed or
|
||||
// placed resource the layer created: the call succeeds with both outputs, with the properties alone and with the
|
||||
// flags alone; Type is the heap type it was created with and, for a custom heap, so are the CPU page property and the
|
||||
// memory pool; and a call asking for one output reports what the call asking for both does, and every output asked
|
||||
// for is written. For a reserved resource the call fails. The values D3D12 derives itself (the flags a committed
|
||||
// resource reports, the node masks) are the host comparison's. Returns the number of wrong answers; `checked` counts
|
||||
// the resources looked at.
|
||||
int layer_wrong(const Record& ours, int* checked) {
|
||||
int wrong = 0;
|
||||
const auto find = [&](const std::string& name, std::uint64_t* value) {
|
||||
for (std::size_t i = 0; i < ours.names.size(); ++i)
|
||||
if (ours.names[i] == name) {
|
||||
*value = ours.values[i];
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
const auto expect = [&](const std::string& name, std::uint64_t want, const char* why) {
|
||||
std::uint64_t got = 0;
|
||||
const bool found = find(name, &got);
|
||||
if (found && got == want) return;
|
||||
if (found)
|
||||
std::printf("heap properties %s: the layer answers 0x%llx, 0x%llx expected (%s)\n", name.c_str(),
|
||||
static_cast<unsigned long long>(got), static_cast<unsigned long long>(want), why);
|
||||
else
|
||||
std::printf("heap properties %s: missing from the layer's record (%s)\n", name.c_str(), why);
|
||||
++wrong;
|
||||
};
|
||||
// A value from a call asking for one output: it has to be what the call asking for both gave, and the call has
|
||||
// to have written it (the outputs start as the sentinel), which holds the other call to having written it too.
|
||||
const auto same = [&](const std::string& one, const std::string& both) {
|
||||
std::uint64_t a = 0, b = 0;
|
||||
const bool found = find(one, &a) && find(both, &b);
|
||||
if (found && a == b && std::uint32_t(a) != kSentinel) return;
|
||||
if (found && a == b)
|
||||
std::printf("heap properties %s: the layer did not write it, with both outputs asked for either\n",
|
||||
one.c_str());
|
||||
else
|
||||
std::printf("heap properties %s: the layer answers 0x%llx where the call with both outputs gave "
|
||||
"0x%llx\n", one.c_str(), static_cast<unsigned long long>(a),
|
||||
static_cast<unsigned long long>(b));
|
||||
++wrong;
|
||||
};
|
||||
static const char* const kPropertyFields[] = {"Type", "CPUPageProperty", "MemoryPoolPreference",
|
||||
"CreationNodeMask", "VisibleNodeMask"};
|
||||
for (const Case& c : cases()) {
|
||||
const std::string name = c.name;
|
||||
std::uint64_t created = 0;
|
||||
if (!find(name + ": created", &created) || FAILED(HRESULT(std::uint32_t(created)))) continue;
|
||||
if (c.kind == Kind::reserved) {
|
||||
for (const char* shape : {"", ", properties only", ", flags only"}) {
|
||||
std::uint64_t hr = 0;
|
||||
if (find(name + shape + ": hr", &hr) && FAILED(HRESULT(std::uint32_t(hr)))) continue;
|
||||
std::printf("heap properties %s%s: the layer answers 0x%llx for a reserved resource, a failure "
|
||||
"expected\n", name.c_str(), shape, static_cast<unsigned long long>(hr));
|
||||
++wrong;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
++*checked;
|
||||
for (const char* shape : {"", ", properties only", ", flags only"})
|
||||
expect(name + shape + ": hr", std::uint32_t(S_OK), "a committed or placed resource has heap properties");
|
||||
for (const char* shape : {"", ", properties only"}) {
|
||||
expect(name + shape + ": Type", std::uint32_t(c.props.Type), "the heap type it was created with");
|
||||
if (c.props.Type != D3D12_HEAP_TYPE_CUSTOM) continue;
|
||||
expect(name + shape + ": CPUPageProperty", std::uint32_t(c.props.CPUPageProperty),
|
||||
"the custom heap's CPU page property");
|
||||
expect(name + shape + ": MemoryPoolPreference", std::uint32_t(c.props.MemoryPoolPreference),
|
||||
"the custom heap's memory pool");
|
||||
}
|
||||
for (const char* field : kPropertyFields)
|
||||
same(name + ", properties only: " + field, name + ": " + field);
|
||||
same(name + ", flags only: flags", name + ": flags");
|
||||
}
|
||||
return wrong;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
int main() {
|
||||
@ -238,6 +320,20 @@ int main() {
|
||||
const bool verbose = GetEnvironmentVariableA("LEONIDA_D3D49_VERBOSE", nullptr, 0) > 0;
|
||||
Record ours;
|
||||
run(device.p, ours);
|
||||
// The layer's own answers first, on every host: the comparison below needs a host, and Wine's is not one.
|
||||
int layer_checked = 0;
|
||||
const int layer_wrong_answers = layer_wrong(ours, &layer_checked);
|
||||
std::printf("heap properties: the layer's answers for %d committed and placed resources checked on their own, "
|
||||
"%d wrong\n", layer_checked, layer_wrong_answers);
|
||||
EXPECT(layer_checked > 0);
|
||||
EXPECT(layer_wrong_answers == 0);
|
||||
// With no host to compare with, LEONIDA_D3D49_VERBOSE still prints what the layer recorded.
|
||||
const auto print_ours = [&] {
|
||||
if (!verbose) return;
|
||||
for (std::size_t i = 0; i < ours.names.size(); ++i)
|
||||
std::printf("heap properties %s: ours 0x%llx\n", ours.names[i].c_str(),
|
||||
static_cast<unsigned long long>(ours.values[i]));
|
||||
};
|
||||
|
||||
const HMODULE d3d12 = LoadLibraryExA("d3d12.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32);
|
||||
const auto create_host = d3d12 ? reinterpret_cast<PFN_D3D12_CREATE_DEVICE>(
|
||||
@ -251,15 +347,17 @@ int main() {
|
||||
// No factory, or no adapter for the pass (LEONIDA_HOST_ADAPTER=warp without WARP): don't compare, rather than
|
||||
// fall back to the default adapter and compare with a GPU the layer doesn't run on.
|
||||
const bool have_adapter =
|
||||
SUCCEEDED(CreateDXGIFactory1(IID_PPV_ARGS(&factory.p))) &&
|
||||
!hostwine::host_is_wine() && SUCCEEDED(CreateDXGIFactory1(IID_PPV_ARGS(&factory.p))) &&
|
||||
hostadapter::reference(factory.p, &luid, hostadapter::wanted() == "warp", &adapter.p, host_name);
|
||||
Ref<ID3D12Device> host;
|
||||
if (!have_adapter) {
|
||||
std::printf("heap properties: no host adapter to compare with; %zu values recorded, not compared\n",
|
||||
ours.values.size());
|
||||
print_ours();
|
||||
} else if (!create_host || FAILED(create_host(adapter.p, D3D_FEATURE_LEVEL_11_0, IID_PPV_ARGS(&host.p)))) {
|
||||
std::printf("heap properties: no host D3D12 device to compare with; %zu values recorded, not compared\n",
|
||||
ours.values.size());
|
||||
print_ours();
|
||||
} else {
|
||||
Record theirs;
|
||||
run(host.p, theirs);
|
||||
|
||||
@ -1,7 +1,9 @@
|
||||
// D3D12 ExecuteIndirect with a GPU count buffer and one DISPATCH argument per record.
|
||||
// The same synthetic workload runs on native WARP and on the Vulkan layer, with actual GPU readback.
|
||||
// Under Wine the WARP runs are skipped (host_wine.h) and the layer is checked against the expected result alone.
|
||||
// Set LEONIDA_VK_VALIDATION=1 to enable Vulkan core and synchronization validation.
|
||||
#include "vk_test_device.h"
|
||||
#include "host_wine.h"
|
||||
#include "shader_fixture_path.h"
|
||||
#include "d3d12_test_shaders.h"
|
||||
#include "../shims/d3d12_com.h"
|
||||
@ -177,24 +179,35 @@ std::string module_version(const wchar_t* name) {
|
||||
} // namespace
|
||||
|
||||
int main() {
|
||||
using Compile = decltype(&D3DCompile);
|
||||
const HMODULE compiler = LoadLibraryExW(L"d3dcompiler_47.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32);
|
||||
if (!compiler) return 77;
|
||||
const auto compile = reinterpret_cast<Compile>(GetProcAddress(compiler, "D3DCompile"));
|
||||
if (!compile) return 77;
|
||||
Ref<ID3DBlob> native, errors;
|
||||
if (FAILED(compile(native_shader, std::strlen(native_shader), nullptr, nullptr, nullptr,
|
||||
"main", "cs_5_0", 0, 0, &native.p, &errors.p)) || !native.p)
|
||||
return 1;
|
||||
const auto* native_bytes = static_cast<const std::uint8_t*>(native->GetBufferPointer());
|
||||
const std::vector<std::uint8_t> native_code(native_bytes, native_bytes + native->GetBufferSize());
|
||||
// Wine has no WARP (its host is vkd3d on the GPU), and its D3DCompile has no RWByteAddressBuffer::InterlockedAdd
|
||||
// (E5005 on wine-staging 11.21), so the reference shader did not build and the test ended before the layer ran.
|
||||
// The host runs are skipped there; the layer is still checked against expected().
|
||||
const bool compare_host = !hostwine::host_is_wine();
|
||||
std::vector<std::uint8_t> native_code;
|
||||
Ref<IDXGIFactory4> factory;
|
||||
Ref<IDXGIAdapter> warp;
|
||||
Ref<ID3D12Device> host;
|
||||
if (FAILED(CreateDXGIFactory1(IID_PPV_ARGS(&factory.p))) ||
|
||||
FAILED(factory->EnumWarpAdapter(IID_PPV_ARGS(&warp.p))) ||
|
||||
FAILED(D3D12CreateDevice(warp.p, D3D_FEATURE_LEVEL_11_0, IID_PPV_ARGS(&host.p))))
|
||||
return 77;
|
||||
if (compare_host) {
|
||||
using Compile = decltype(&D3DCompile);
|
||||
const HMODULE compiler = LoadLibraryExW(L"d3dcompiler_47.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32);
|
||||
if (!compiler) return 77;
|
||||
const auto compile = reinterpret_cast<Compile>(GetProcAddress(compiler, "D3DCompile"));
|
||||
if (!compile) return 77;
|
||||
Ref<ID3DBlob> native, errors;
|
||||
if (FAILED(compile(native_shader, std::strlen(native_shader), nullptr, nullptr, nullptr,
|
||||
"main", "cs_5_0", 0, 0, &native.p, &errors.p)) || !native.p) {
|
||||
std::fprintf(stderr, "D3DCompile of the reference shader failed%s%.*s\n", errors.p ? ": " : "",
|
||||
errors.p ? int(errors->GetBufferSize()) : 0,
|
||||
errors.p ? static_cast<const char*>(errors->GetBufferPointer()) : "");
|
||||
return 1;
|
||||
}
|
||||
const auto* native_bytes = static_cast<const std::uint8_t*>(native->GetBufferPointer());
|
||||
native_code.assign(native_bytes, native_bytes + native->GetBufferSize());
|
||||
if (FAILED(CreateDXGIFactory1(IID_PPV_ARGS(&factory.p))) ||
|
||||
FAILED(factory->EnumWarpAdapter(IID_PPV_ARGS(&warp.p))) ||
|
||||
FAILED(D3D12CreateDevice(warp.p, D3D_FEATURE_LEVEL_11_0, IID_PPV_ARGS(&host.p))))
|
||||
return 77;
|
||||
}
|
||||
|
||||
vktest::Device vk;
|
||||
vk.request_buffer_device_address = true;
|
||||
@ -237,12 +250,13 @@ int main() {
|
||||
for (bool update : {false, true}) {
|
||||
std::array<UINT, 2> native_result{}, layer_result{};
|
||||
const auto want = expected(count, update);
|
||||
if (!run(host.p, native_code, count, update, native_result, false) ||
|
||||
if (!compare_host) native_result = want; // no host run: the layer alone is held to `want`
|
||||
if ((compare_host && !run(host.p, native_code, count, update, native_result, false)) ||
|
||||
!run(layer.p, container, count, update, layer_result, true) || layer_result != want ||
|
||||
(native_result != want && !(update && native_result == expected(count, update, count)))) {
|
||||
std::fprintf(stderr, "count %u update %d: host %u/%u, layer %u/%u, expected %u/%u\n",
|
||||
std::fprintf(stderr, "count %u update %d: host %u/%u%s, layer %u/%u, expected %u/%u\n",
|
||||
count, int(update), native_result[0], native_result[1],
|
||||
layer_result[0], layer_result[1], want[0], want[1]);
|
||||
compare_host ? "" : " (not run)", layer_result[0], layer_result[1], want[0], want[1]);
|
||||
return 1;
|
||||
}
|
||||
if (native_result != want) {
|
||||
@ -262,7 +276,9 @@ int main() {
|
||||
std::fprintf(stderr, "validation errors: %u\n", vk.validation_errors());
|
||||
return 1;
|
||||
}
|
||||
std::printf("counted ExecuteIndirect(DISPATCH): %u native WARP / Vulkan GPU comparisons passed; "
|
||||
"count=0,1,max,>max, nonzero offsets and GPU count overwrite, no validation errors\n", cases);
|
||||
std::printf("counted ExecuteIndirect(DISPATCH): %u %s passed; "
|
||||
"count=0,1,max,>max, nonzero offsets and GPU count overwrite, no validation errors\n", cases,
|
||||
compare_host ? "native WARP / Vulkan GPU comparisons"
|
||||
: "Vulkan GPU results against the expected values (no WARP runs under Wine)");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
// Legal D3D12 no-op copies must not poison Close or emit invalid Vulkan copy commands.
|
||||
// Synthetic resources and native host WARP comparator; no game content.
|
||||
// Synthetic resources and native host WARP comparator; no game content. Under Wine the comparator is skipped
|
||||
// (host_wine.h) and the layer is still checked.
|
||||
#include "../shims/d3d12_com.h"
|
||||
#include "host_wine.h"
|
||||
#include <dxgi1_4.h>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
@ -118,10 +120,14 @@ int main() {
|
||||
Ref<IDXGIFactory4> factory;
|
||||
Ref<IDXGIAdapter> warp;
|
||||
Ref<ID3D12Device> host;
|
||||
if (FAILED(CreateDXGIFactory1(IID_PPV_ARGS(&factory.p))) ||
|
||||
FAILED(factory->EnumWarpAdapter(IID_PPV_ARGS(&warp.p))) ||
|
||||
FAILED(D3D12CreateDevice(warp.p, D3D_FEATURE_LEVEL_11_0, IID_PPV_ARGS(&host.p)))) return 77;
|
||||
if (check(host.p, "native WARP")) return 1;
|
||||
// Wine's host is vkd3d, which accepts the upload-heap self-copy Microsoft's runtime refuses: check() would stop
|
||||
// there, before the layer is looked at.
|
||||
if (!hostwine::host_is_wine()) {
|
||||
if (FAILED(CreateDXGIFactory1(IID_PPV_ARGS(&factory.p))) ||
|
||||
FAILED(factory->EnumWarpAdapter(IID_PPV_ARGS(&warp.p))) ||
|
||||
FAILED(D3D12CreateDevice(warp.p, D3D_FEATURE_LEVEL_11_0, IID_PPV_ARGS(&host.p)))) return 77;
|
||||
if (check(host.p, "native WARP")) return 1;
|
||||
}
|
||||
Ref<ID3D12Device> layer;
|
||||
if (FAILED(rt::d3d12::create_vulkan_device_standalone(IID_PPV_ARGS(&layer.p)))) return 77;
|
||||
return check(layer.p, "Leonida Vulkan");
|
||||
|
||||
@ -4,10 +4,13 @@
|
||||
// fence): counts of 0, null arrays, null entries, the same object twice, evicting twice, every named priority and a
|
||||
// few others, residency flags, a null fence, and the fence values EnqueueMakeResident signals (the value the fence
|
||||
// reaches is recorded too). Every HRESULT is recorded and the two records must be the same, step by step. A step the
|
||||
// host runtime faults on is reported and not compared. No shaders or game data. Skips (77) without a Vulkan GPU;
|
||||
// without a host D3D12 device only the layer's own record is printed. Set LEONIDA_D3D49_VERBOSE=1 to print every
|
||||
// step.
|
||||
// host runtime faults on is reported and not compared. No shaders or game data. Skips (77) without a Vulkan GPU.
|
||||
// The layer's record is first checked on its own (layer_wrong: the valid calls succeed, the fence reaches the values
|
||||
// asked for), on every host; without a host D3D12 device that is all that is checked, and so it is under Wine, whose
|
||||
// host is vkd3d (host_wine.h: it answers S_OK to calls Microsoft's runtime refuses). Set LEONIDA_D3D49_VERBOSE=1 to
|
||||
// print every step.
|
||||
#include "vk_test_device.h"
|
||||
#include "host_wine.h"
|
||||
#include "../shims/d3d12_com.h"
|
||||
|
||||
#include <cstdint>
|
||||
@ -337,6 +340,68 @@ bool run(ID3D12Device* device, bool host, Record& out) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Steps that are plain, valid use of the API on a committed buffer, a heap and a fence: they have to succeed.
|
||||
bool must_succeed(const char* name) {
|
||||
static const char* const kValid[] = {
|
||||
"MakeResident a resident buffer", "Evict the buffer", "MakeResident the evicted buffer",
|
||||
"SetResidencyPriority the buffer", "SetResidencyPriority the heap", "SetResidencyPriority MINIMUM",
|
||||
"SetResidencyPriority LOW", "SetResidencyPriority HIGH", "SetResidencyPriority MAXIMUM",
|
||||
"EnqueueMakeResident NONE, two objects, value 7", "EnqueueMakeResident all six, value 10",
|
||||
};
|
||||
for (const char* valid : kValid)
|
||||
if (std::strcmp(name, valid) == 0) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
// What the layer has to answer whatever the host is, checked on its record alone (the one run() makes with `host`
|
||||
// false) so that a run with no host to compare with (no host device, or Wine's) still fails on a wrong answer: no
|
||||
// call raises an exception; the valid calls above succeed; the device is never removed (the host removes its own on
|
||||
// some steps, the layer has no reason to); and after an EnqueueMakeResident that succeeded the fence holds the value
|
||||
// asked for, or stays where it was when that value is below it (a Vulkan timeline only goes up, docs/d3d12_vulkan.md),
|
||||
// and after one that failed it has not moved. The HRESULTs of the invalid calls are the host comparison's.
|
||||
// Returns the number of wrong answers.
|
||||
int layer_wrong(const Record& ours) {
|
||||
int wrong = 0;
|
||||
const auto bad = [&](const std::string& name, std::uint64_t got, const char* why) {
|
||||
std::printf("residency %s: the layer answers 0x%llx: %s\n", name.c_str(),
|
||||
static_cast<unsigned long long>(got), why);
|
||||
++wrong;
|
||||
};
|
||||
std::size_t i = 0;
|
||||
const auto next = [&](const std::string& name, std::uint64_t* value) {
|
||||
if (i >= ours.values.size() || ours.names[i] != name) {
|
||||
bad(name, 0, "missing from the layer's record");
|
||||
return false;
|
||||
}
|
||||
*value = ours.values[i++];
|
||||
return true;
|
||||
};
|
||||
UINT64 fence = 0; // make() creates it at 0
|
||||
for (const Step& s : kSteps) {
|
||||
std::uint64_t hr = 0;
|
||||
if (!next(s.name, &hr)) return wrong;
|
||||
if (hr == kFaulted) bad(s.name, hr, "the call raised an exception");
|
||||
else if (must_succeed(s.name) && hr != std::uint32_t(S_OK)) bad(s.name, hr, "a valid call has to succeed");
|
||||
if (s.isolated) continue;
|
||||
std::uint64_t removed = 0;
|
||||
if (!next(std::string(s.name) + " (removed reason)", &removed)) return wrong;
|
||||
if (removed != std::uint32_t(S_OK))
|
||||
bad(std::string(s.name) + " (removed reason)", removed, "the device was removed");
|
||||
if (!s.fence_value) continue;
|
||||
std::uint64_t reached = 0;
|
||||
if (!next(std::string(s.name) + " (fence)", &reached)) return wrong;
|
||||
const bool succeeded = hr != kFaulted && SUCCEEDED(HRESULT(std::uint32_t(hr)));
|
||||
const UINT64 want = succeeded && s.fence_value > fence ? s.fence_value : fence;
|
||||
if (reached != want)
|
||||
bad(std::string(s.name) + " (fence)", reached,
|
||||
succeeded ? "the fence has to hold the value asked for, or stay where it was for a lower one"
|
||||
: "a call that failed must not move the fence");
|
||||
else
|
||||
fence = reached;
|
||||
}
|
||||
return wrong;
|
||||
}
|
||||
|
||||
// --host-step N: one isolated step on a fresh host device; the exit code is its HRESULT.
|
||||
int host_step(std::size_t index) {
|
||||
if (index >= sizeof(kSteps) / sizeof(kSteps[0])) return int(kNoChild);
|
||||
@ -369,12 +434,21 @@ int main(int argc, char** argv) {
|
||||
EXPECT(SUCCEEDED(rt::d3d12::create_vulkan_device(info, IID_PPV_ARGS(&device.p))));
|
||||
Record ours;
|
||||
EXPECT(run(device.p, false, ours));
|
||||
// The layer's own answers first, on every host: the comparison below needs a host, and Wine's is not one.
|
||||
const int layer_wrong_answers = layer_wrong(ours);
|
||||
std::printf("residency: the layer's %zu values checked on their own, %d wrong\n", ours.values.size(),
|
||||
layer_wrong_answers);
|
||||
EXPECT(layer_wrong_answers == 0);
|
||||
|
||||
Ref<ID3D12Device> host;
|
||||
host.p = create_host();
|
||||
host.p = hostwine::host_is_wine() ? nullptr : create_host();
|
||||
if (!host.p) {
|
||||
std::printf("residency: no host D3D12 device to compare with; %zu steps recorded, not compared\n",
|
||||
ours.values.size());
|
||||
if (verbose)
|
||||
for (std::size_t i = 0; i < ours.values.size(); ++i)
|
||||
std::printf("residency %s: ours 0x%llx\n", ours.names[i].c_str(),
|
||||
static_cast<unsigned long long>(ours.values[i]));
|
||||
} else {
|
||||
Record theirs;
|
||||
EXPECT(run(host.p, true, theirs));
|
||||
|
||||
@ -1,11 +1,17 @@
|
||||
// Typeless depth-stencil textures without ALLOW_DEPTH_STENCIL (R24G8_TYPELESS, R32G8X24_TYPELESS), as an application
|
||||
// makes to keep a copy of its depth buffer for sampling: clear a depth buffer of the family, CopyResource it into
|
||||
// the plain texture, read both planes back and compare with Windows D3D12/WARP. No game data or shaders.
|
||||
// the plain texture, read both planes back, check that they hold the cleared values and compare with Windows
|
||||
// D3D12/WARP. No game data or shaders. Under Wine the reference would be vkd3d (host_wine.h), which reads both planes
|
||||
// back as zeros: there the comparison is left out, and the layer's readback is checked against the cleared values
|
||||
// alone.
|
||||
// LEONIDA_VK_VALIDATION=1 checks Vulkan usage.
|
||||
#include "vk_test_device.h"
|
||||
#include "host_wine.h"
|
||||
#include "../shims/d3d12_com.h"
|
||||
#include <dxgi1_4.h>
|
||||
#include <algorithm>
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
|
||||
#define CHECK(condition) do { \
|
||||
@ -155,6 +161,46 @@ bool copy_and_read(ID3D12Device* device, const Family& family, std::vector<unsig
|
||||
return true;
|
||||
}
|
||||
|
||||
// Whether a readback of copy_and_read holds what clear() wrote, texel by texel: depth 0.25 and stencil 0x5a, and
|
||||
// depth 0.75 and stencil 0x3c inside the rectangle (1,1)-(5,3). This needs no reference device, so it is checked on
|
||||
// every host and is the whole check where there is none to compare with (Wine). The depth plane is four bytes a
|
||||
// texel: a float for R32G8X24, and for R24G8 a 24-bit UNORM in the low three bytes (the fourth is not depth, and a
|
||||
// device that keeps D24 as a float may round by one step either way). The stencil plane is one byte a texel.
|
||||
bool holds_cleared_values(const Family& family, const std::vector<unsigned char>& data) {
|
||||
const size_t texels = size_t(width) * height;
|
||||
if (data.size() != texels * 5) {
|
||||
std::fprintf(stderr, "%s: the readback is %zu bytes, %zu expected (4 of depth and 1 of stencil a texel)\n",
|
||||
family.name, data.size(), texels * 5);
|
||||
return false;
|
||||
}
|
||||
for (UINT y = 0; y < height; ++y) {
|
||||
for (UINT x = 0; x < width; ++x) {
|
||||
const bool inside = x >= 1 && x < 5 && y >= 1 && y < 3;
|
||||
const float depth = inside ? 0.75f : 0.25f;
|
||||
const unsigned char stencil = inside ? 0x3c : 0x5a;
|
||||
const size_t texel = size_t(y) * width + x;
|
||||
std::uint32_t word = 0;
|
||||
std::memcpy(&word, data.data() + texel * 4, sizeof(word));
|
||||
bool depth_ok = false;
|
||||
if (family.typeless == DXGI_FORMAT_R24G8_TYPELESS) {
|
||||
const auto want = static_cast<std::int64_t>(double(depth) * 16777215.0 + 0.5);
|
||||
const auto got = static_cast<std::int64_t>(word & 0x00ffffffu);
|
||||
depth_ok = got >= want - 1 && got <= want + 1;
|
||||
} else {
|
||||
std::uint32_t want = 0;
|
||||
std::memcpy(&want, &depth, sizeof(want));
|
||||
depth_ok = word == want;
|
||||
}
|
||||
const unsigned char got_stencil = data[texels * 4 + texel];
|
||||
if (depth_ok && got_stencil == stencil) continue;
|
||||
std::fprintf(stderr, "%s: texel (%u,%u) holds depth word 0x%08x and stencil 0x%02x, cleared to depth %g "
|
||||
"and stencil 0x%02x\n", family.name, x, y, word, got_stencil, double(depth), stencil);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// The first byte where the two readbacks differ, or -1.
|
||||
long first_difference(const std::vector<unsigned char>& a, const std::vector<unsigned char>& b) {
|
||||
if (a.size() != b.size()) return long(std::min(a.size(), b.size()));
|
||||
@ -169,6 +215,9 @@ int main() {
|
||||
const auto device_status = vk.initialize();
|
||||
if (device_status == vktest::DeviceStatus::unavailable) return 77;
|
||||
if (device_status != vktest::DeviceStatus::ready) return 1;
|
||||
// Under Wine the reference would be vkd3d, which reads both planes back as zeros: no comparison there, and the
|
||||
// layer's readback is still checked against the values it was cleared to.
|
||||
const bool compare_with_host = !hostwine::host_is_wine();
|
||||
unsigned failures = 0;
|
||||
{
|
||||
Ref<ID3D12Device> ours;
|
||||
@ -184,15 +233,16 @@ int main() {
|
||||
Ref<IDXGIFactory4> factory;
|
||||
Ref<IDXGIAdapter> adapter;
|
||||
Ref<ID3D12Device> warp;
|
||||
if (FAILED(CreateDXGIFactory1(IID_PPV_ARGS(&factory.p))) ||
|
||||
FAILED(factory->EnumWarpAdapter(IID_PPV_ARGS(&adapter.p))) ||
|
||||
FAILED(D3D12CreateDevice(adapter.p, D3D_FEATURE_LEVEL_11_0, IID_PPV_ARGS(&warp.p)))) {
|
||||
if (compare_with_host &&
|
||||
(FAILED(CreateDXGIFactory1(IID_PPV_ARGS(&factory.p))) ||
|
||||
FAILED(factory->EnumWarpAdapter(IID_PPV_ARGS(&adapter.p))) ||
|
||||
FAILED(D3D12CreateDevice(adapter.p, D3D_FEATURE_LEVEL_11_0, IID_PPV_ARGS(&warp.p))))) {
|
||||
std::fprintf(stderr, "no WARP device, skipped\n");
|
||||
return 77;
|
||||
}
|
||||
for (const Family& family : families) {
|
||||
std::vector<unsigned char> expected, actual;
|
||||
if (!copy_and_read(warp.p, family, expected)) {
|
||||
if (compare_with_host && !copy_and_read(warp.p, family, expected)) {
|
||||
std::fprintf(stderr, "%s: WARP could not run the copy\n", family.name);
|
||||
++failures;
|
||||
continue;
|
||||
@ -202,6 +252,16 @@ int main() {
|
||||
++failures;
|
||||
continue;
|
||||
}
|
||||
if (!holds_cleared_values(family, actual)) {
|
||||
++failures;
|
||||
continue;
|
||||
}
|
||||
if (!compare_with_host) {
|
||||
std::printf("%s without ALLOW_DEPTH_STENCIL: copy of a cleared depth buffer holds the cleared depth "
|
||||
"and stencil at every texel (%zu bytes; not compared with the host)\n",
|
||||
family.name, actual.size());
|
||||
continue;
|
||||
}
|
||||
const long at = first_difference(actual, expected);
|
||||
if (at >= 0) {
|
||||
std::fprintf(stderr, "%s: readback differs from WARP at byte %ld of %zu\n", family.name, at,
|
||||
|
||||
@ -7,9 +7,11 @@
|
||||
// output is S_OK with a null output; on ResizeBuffers NONPREROTATED, FULLSCREEN_VIDEO and every bit from 0x4000 up are
|
||||
// DXGI_ERROR_INVALID_CALL, and FOREGROUND_LAYER, YUV_VIDEO and 0x2000 on a chain created without them E_INVALIDARG;
|
||||
// a null out-pointer is DXGI_ERROR_INVALID_CALL on GetBuffer, GetHwnd, GetLastPresentCount and GetRestrictToOutput.
|
||||
// Exits 77 without an interactive window station, a Vulkan device or a host D3D12 device.
|
||||
// Exits 77 without an interactive window station, a Vulkan device or a host D3D12 device, and under Wine, whose DXGI
|
||||
// is not that reference (host_wine.h; its wined3d faults on the null GetBuffer out-pointer).
|
||||
#include "vk_test_device.h"
|
||||
#include "host_adapter.h"
|
||||
#include "host_wine.h"
|
||||
#include "window_station.h"
|
||||
#include "../shims/d3d12_com.h"
|
||||
|
||||
@ -226,6 +228,7 @@ int main() {
|
||||
std::printf("SKIP: the process has no interactive window station\n");
|
||||
return 77;
|
||||
}
|
||||
if (hostwine::host_is_wine()) return 77; // every row is compared with the host
|
||||
vktest::Device vk;
|
||||
if (!vk.create(true)) {
|
||||
std::printf("SKIP: no Vulkan device\n");
|
||||
|
||||
@ -8,6 +8,7 @@
|
||||
|
||||
#include "../shims/d3d12_com.h"
|
||||
#include "../shims/dxgi_com.h"
|
||||
#include "host_wine.h"
|
||||
#include "vulkan_loader.h"
|
||||
#include "window_station.h"
|
||||
#include "../src/vulkan_device_filter.h"
|
||||
@ -156,8 +157,9 @@ HRESULT create_guarded(IDXGIFactory4* factory, IUnknown* queue, HWND hwnd, const
|
||||
|
||||
// CreateSwapChainForHwnd with descriptions D3D12 refuses (and the valid ones next to them), against the host runtime's
|
||||
// DXGI: each case gets its own window on each side, and the HRESULTs must match. Returns the number of mismatches,
|
||||
// or -1 without a host D3D12 device.
|
||||
// or -1 without a host D3D12 device, or under Wine, whose DXGI is not that reference (host_wine.h).
|
||||
int compare_swap_chain_arguments(IDXGIFactory4* ours, ID3D12Device* our_device, ID3D12CommandQueue* our_queue) {
|
||||
if (hostwine::host_is_wine()) return -1;
|
||||
using CreateDevice = HRESULT(WINAPI*)(IUnknown*, D3D_FEATURE_LEVEL, REFIID, void**);
|
||||
using CreateFactory2 = HRESULT(WINAPI*)(UINT, REFIID, void**);
|
||||
const HMODULE d3d12 = LoadLibraryExA("d3d12.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32);
|
||||
@ -312,8 +314,9 @@ int compare_swap_chain_arguments(IDXGIFactory4* ours, ID3D12Device* our_device,
|
||||
// GetBuffer and Present are DXGI_ERROR_INVALID_CALL, and the next ResizeBuffers to a valid size brings it all back.
|
||||
// A refused call (a back buffer still held) changes nothing. WARP differs (it takes 16385 and fails at 32768 with
|
||||
// E_OUTOFMEMORY), so this compares with the host's default adapter. Returns the number of mismatches, or -1 without
|
||||
// a host D3D12 device.
|
||||
// a host D3D12 device or under Wine (host_wine.h).
|
||||
int compare_failed_resize(IDXGIFactory4* ours, ID3D12CommandQueue* our_queue) {
|
||||
if (hostwine::host_is_wine()) return -1;
|
||||
using CreateDevice = HRESULT(WINAPI*)(IUnknown*, D3D_FEATURE_LEVEL, REFIID, void**);
|
||||
using CreateFactory2 = HRESULT(WINAPI*)(UINT, REFIID, void**);
|
||||
const HMODULE d3d12 = LoadLibraryExA("d3d12.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32);
|
||||
@ -638,11 +641,15 @@ int main() {
|
||||
cl->Close();
|
||||
|
||||
// Before the test's own swap chain: the host comparison creates and releases its own windows and chains.
|
||||
// Why a comparison was left out: under Wine there is a host device, and it is not the reference (host_wine.h).
|
||||
const char* const not_compared = hostwine::host_is_wine()
|
||||
? "the host's DXGI is Wine's, not compared with it"
|
||||
: "no host D3D12 device to compare with, skipped";
|
||||
const int argument_mismatches = compare_swap_chain_arguments(factory, dev, queue);
|
||||
if (argument_mismatches < 0) std::printf("CreateSwapChainForHwnd: no host D3D12 device to compare with, skipped\n");
|
||||
if (argument_mismatches < 0) std::printf("CreateSwapChainForHwnd: %s\n", not_compared);
|
||||
if (argument_mismatches > 0) return fail("CreateSwapChainForHwnd answers differ from the host runtime");
|
||||
const int resize_mismatches = compare_failed_resize(factory, queue);
|
||||
if (resize_mismatches < 0) std::printf("failed ResizeBuffers: no host D3D12 device to compare with, skipped\n");
|
||||
if (resize_mismatches < 0) std::printf("failed ResizeBuffers: %s\n", not_compared);
|
||||
if (resize_mismatches > 0) return fail("a failed ResizeBuffers differs from the host runtime");
|
||||
|
||||
DXGI_SWAP_CHAIN_DESC1 scd{};
|
||||
@ -1256,8 +1263,9 @@ int main() {
|
||||
return fail("Adapter CheckInterfaceSupport(IDXGIDevice) failed");
|
||||
IDXGIFactory4* host_factory = nullptr;
|
||||
IDXGIAdapter1* host_adapter = nullptr;
|
||||
// The host dxgi.dll, loaded at run time: this test doesn't link it, and a Wine run without it skips.
|
||||
HMODULE host_dxgi = LoadLibraryW(L"dxgi.dll");
|
||||
// The host dxgi.dll, loaded at run time: this test doesn't link it. Not under Wine, whose DXGI makes up a
|
||||
// version of its own for the adapter (host_wine.h).
|
||||
HMODULE host_dxgi = hostwine::host_is_wine() ? nullptr : LoadLibraryW(L"dxgi.dll");
|
||||
const auto create_factory = host_dxgi ? reinterpret_cast<decltype(&CreateDXGIFactory1)>(
|
||||
GetProcAddress(host_dxgi, "CreateDXGIFactory1")) : nullptr;
|
||||
if (create_factory && SUCCEEDED(create_factory(IID_PPV_ARGS(&host_factory))) && host_factory &&
|
||||
|
||||
@ -2,7 +2,8 @@
|
||||
// (IDXGISwapChain2::SetMaximumFrameLatency, GetMaximumFrameLatency, GetFrameLatencyWaitableObject,
|
||||
// Present, Present(DXGI_PRESENT_TEST), ResizeBuffers).
|
||||
// Compares Leonida's Vulkan-backed DXGI shim directly against live Windows host d3d12.dll / dxgi.dll
|
||||
// when available, and validates all contracts independently.
|
||||
// when available, and validates all contracts independently. Under Wine the host suite is skipped (host_wine.h: its
|
||||
// dxgi faults on GetMaximumFrameLatency(null)) and the layer's own contracts are still checked.
|
||||
// Set LEONIDA_VK_VALIDATION=1 to run under VK_LAYER_KHRONOS_validation (Core + Synchronization Validation).
|
||||
#ifndef VK_USE_PLATFORM_WIN32_KHR
|
||||
#define VK_USE_PLATFORM_WIN32_KHR
|
||||
@ -11,6 +12,7 @@
|
||||
#include "../shims/d3d12_com.h"
|
||||
#include "../shims/dxgi_com.h"
|
||||
#include "../src/vulkan_device_filter.h"
|
||||
#include "host_wine.h"
|
||||
#include "vulkan_loader.h"
|
||||
#include "window_station.h"
|
||||
|
||||
@ -795,7 +797,7 @@ int main() {
|
||||
reinterpret_cast<void*>(GetProcAddress(host_dxgi, "CreateDXGIFactory2")))
|
||||
: nullptr;
|
||||
bool compared_host = false;
|
||||
if (create_host_dev && create_host_fac) {
|
||||
if (create_host_dev && create_host_fac && !hostwine::host_is_wine()) {
|
||||
IDXGIFactory4* hfac = nullptr;
|
||||
ID3D12Device* hdev = nullptr;
|
||||
ID3D12CommandQueue* hq = nullptr;
|
||||
|
||||
Reference in New Issue
Block a user