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
7 changes: 6 additions & 1 deletion runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1883,9 +1883,14 @@ if(TARGET Vulkan::Headers)
# device fails the run in vk_descriptor_bench and vk_sandbox too, instead of testing another GPU (TEST-1141).
find_package(Python3 COMPONENTS Interpreter QUIET)
if(Python3_FOUND)
# Python runs on the host, so a cross build passes its emulator for the script to put in front of the tools.
set(_filter_runner)
foreach(_part IN LISTS CMAKE_CROSSCOMPILING_EMULATOR)
list(APPEND _filter_runner "--runner=${_part}")
endforeach()
add_test(NAME vk_device_filter_tools COMMAND "${Python3_EXECUTABLE}" -I
"${CMAKE_CURRENT_SOURCE_DIR}/test/check_device_filter_tools.py" "$<TARGET_FILE:vk_descriptor_bench>"
"$<TARGET_FILE:vk_sandbox>" "${CMAKE_CURRENT_BINARY_DIR}/vk_device_filter_tools")
"$<TARGET_FILE:vk_sandbox>" "${CMAKE_CURRENT_BINARY_DIR}/vk_device_filter_tools" ${_filter_runner})
set_tests_properties(vk_device_filter_tools PROPERTIES SKIP_RETURN_CODE 77)
endif()
if(MSVC)
Expand Down
12 changes: 8 additions & 4 deletions runtime/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#include <filesystem>
#include <map>
#include <mutex>
#include <optional>
#include <stdexcept>
#include <string>
#include <system_error>
#include <vector>
Expand Down Expand Up @@ -497,14 +499,16 @@ int wmain(int argc, wchar_t** argv) {
r.error);
}
if (run) rt::process::set_command_line(image.filename().wstring(), game_args);
std::exception_ptr init_failure;
// A copy, not an exception_ptr: Wine 11.0's rethrow_exception throws the stored object itself, which this
// local frees while the throw unwinds to the handler below (what() then reads "Unknown exception").
std::optional<std::runtime_error> init_failure;
if (init || run) {
try {
loader.initialise(); // TLS callbacks, then DllMain(DLL_PROCESS_ATTACH) for DLLs
std::printf("%zu module(s) initialised\n", loader.modules().size());
} catch (const std::exception&) {
} catch (const std::exception& e) {
// Keep the mapped modules available for the binding report on an attach failure.
init_failure = std::current_exception();
init_failure.emplace(e.what());
}
}
int unimplemented = 0, unimplemented_hresult = 0;
Expand All @@ -531,7 +535,7 @@ int wmain(int argc, wchar_t** argv) {
unimplemented - unimplemented_hresult);
if (init_failure) {
std::fflush(stdout);
std::rethrow_exception(init_failure);
throw *init_failure;
}
if (!run) {
rt::startup_trace::event("exit", "\"code\":0");
Expand Down
24 changes: 15 additions & 9 deletions runtime/test/check_device_filter_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
the other harnesses do (runtime/test/vk_device_pick.h, docs/testing.md "Choosing the GPU"). Before, both tools
ignored the filter and ran on the best-ranked GPU.

python -I check_device_filter_tools.py <vk_descriptor_bench> <vk_sandbox> <work dir>
python -I check_device_filter_tools.py <vk_descriptor_bench> <vk_sandbox> <work dir> [--runner=<word> ...]

A cross build names its emulator (Wine) one word per --runner, as runtime/test/check_d3d12_trace.py does.

Exit 0 when both tools refuse the filter, 1 when one does not or when the device list fails for another reason, and
77 (skip) on a machine with no Vulkan loader, driver or device, where no tool can choose one. Standard library only.
"""
import argparse
import os
import re
import struct
Expand Down Expand Up @@ -38,21 +41,24 @@ def no_vulkan(code, out):


def main(argv):
if len(argv) != 4:
print(__doc__, file=sys.stderr)
return 2
bench, sandbox, work = argv[1:]
parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument("bench")
parser.add_argument("sandbox")
parser.add_argument("work")
parser.add_argument("--runner", action="append", default=[])
options = parser.parse_args(argv[1:])
bench, sandbox, work = [*options.runner, options.bench], [*options.runner, options.sandbox], options.work
os.makedirs(work, exist_ok=True)

# The device list ignores the filter, so it shows whether there is any device to choose from.
plain = {k: v for k, v in os.environ.items() if k != "LEONIDA_VK_DEVICE"}
code, out = run([bench, "--list-devices"], env=plain)
code, out = run([*bench, "--list-devices"], env=plain)
reason = no_vulkan(code, out)
if reason:
print(f"SKIP: no Vulkan device to choose from ({reason})")
return UNSUPPORTED
if code != 0: # anything else is a failure of the tool, not a machine without Vulkan
print(f"FAIL: {bench} --list-devices exit {code}:\n{out.strip()}")
print(f"FAIL: {bench[-1]} --list-devices exit {code}:\n{out.strip()}")
return 1

# The smallest scene vk_sandbox reads: magic, version 1, no textures, meshes or draws, and a centre.
Expand All @@ -63,8 +69,8 @@ def main(argv):

env = dict(plain, LEONIDA_VK_DEVICE=FILTER)
failures = []
for name, cmd in (("vk_descriptor_bench", [bench]),
("vk_sandbox", [sandbox, scene, missing, missing, "--out", os.path.join(work, "out.ppm")])):
for name, cmd in (("vk_descriptor_bench", bench),
("vk_sandbox", [*sandbox, scene, missing, missing, "--out", os.path.join(work, "out.ppm")])):
code, out = run(cmd, env=env)
named = f"LEONIDA_VK_DEVICE={FILTER}" in out
if code == 0 or not named or "device:" in out:
Expand Down
2 changes: 2 additions & 0 deletions runtime/test/d3d12_clear_formats_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// No game data or shaders. Run explicitly (needs Vulkan hardware and WARP); LEONIDA_VK_VALIDATION=1 checks Vulkan
// usage. A format the layer cannot create yet is listed as "not exposed" and does not fail the test; any other
// difference does.
#include "host_wine.h"
#include "vk_test_device.h"
#include "../shims/d3d12_com.h"
#include <dxgi1_4.h>
Expand Down Expand Up @@ -326,6 +327,7 @@ int main() {
const auto device_status = vk.initialize();
if (device_status == vktest::DeviceStatus::unavailable) return 77; // no Vulkan GPU: ctest skips
if (device_status != vktest::DeviceStatus::ready) return 1;
if (hostwine::host_is_wine()) return 77; // every case is compared with WARP, which Wine's vkd3d is not
const unsigned errors_before = vk.validation_errors();
Tally tally;
{
Expand Down
4 changes: 4 additions & 0 deletions runtime/test/d3d12_clear_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// both sides. Covers UNORM/SNORM/FLOAT/UINT/SINT render targets and depth/stencil, full and rectangle clears, and RTVs
// through castable-format lists in the other channel order.
// No game data or shaders. Run explicitly (needs Vulkan hardware); LEONIDA_VK_VALIDATION=1 checks Vulkan usage.
#include "host_wine.h"
#include "vk_test_device.h"
#include "../shims/d3d12_com.h"
#include <dxgi1_4.h>
Expand Down Expand Up @@ -470,6 +471,9 @@ int main(int argc, char** argv) {
}
return check_shared_exponent_target(ours.p) ? 0 : 1;
}
// Wine's WARP is vkd3d, which saturates out-of-range integer clears differently: only the layer's own
// check runs there.
if (hostwine::host_is_wine()) return check_unlisted_rtvs(ours.p) ? 77 : 1;
Ref<IDXGIFactory4> factory;
Ref<IDXGIAdapter> warp;
if (FAILED(CreateDXGIFactory1(IID_PPV_ARGS(&factory.p))) ||
Expand Down
8 changes: 5 additions & 3 deletions runtime/test/d3d12_pipeline_library_host_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
// unknown names and null PSOs, descriptions or outputs, and Serialize with null, short and long buffers. Every HRESULT
// and output pointer state are recorded. The public argument checks must agree step by step. Serialized sizes and
// the result of changing a trailing byte are reported for each device's own format. Host faults are reported
// separately. 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.
// separately. No shaders or game data. Skips (77) without a Vulkan GPU. Without a host D3D12 device, or under Wine
// (whose vkd3d answers differently, see host_wine.h), only the layer's own record is printed. Set
// LEONIDA_D3D49_VERBOSE=1 to print every step.
#include "host_wine.h"
#include "vk_test_device.h"
#include "../shims/d3d12_com.h"

Expand Down Expand Up @@ -376,7 +378,7 @@ int main(int argc, char** argv) {
EXPECT(SUCCEEDED(rt::d3d12::create_vulkan_device(info, IID_PPV_ARGS(&device.p))));

Ref<ID3D12Device1> host;
host.p = create_host();
if (!hostwine::host_is_wine()) host.p = create_host();

// Each device gets the other's serialized empty library as a foreign blob.
std::vector<std::uint8_t> ours_blob, host_blob;
Expand Down
10 changes: 7 additions & 3 deletions runtime/test/dxgi_host_answers_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,13 @@ HWND create_test_window(int w, int h) {
RegisterClassW(&wc);
RECT rc{0, 0, w, h};
AdjustWindowRect(&rc, WS_OVERLAPPEDWINDOW, FALSE);
return CreateWindowExW(0, wc.lpszClassName, L"Leonida DXGI host answers", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT,
CW_USEDEFAULT, rc.right - rc.left, rc.bottom - rc.top, nullptr, nullptr, wc.hInstance,
nullptr);
HWND window = CreateWindowExW(0, wc.lpszClassName, L"Leonida DXGI host answers", WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, rc.right - rc.left, rc.bottom - rc.top, nullptr,
nullptr, wc.hInstance, nullptr);
// Shown: a Wayland compositor never answers a FIFO present on a surface that was never mapped (Wine's
// winewayland), so a hidden window blocks the first vsync present forever.
if (window) ShowWindow(window, SW_SHOWNOACTIVATE);
return window;
}

struct Side {
Expand Down
10 changes: 7 additions & 3 deletions runtime/test/dxgi_waitable_latency_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,13 @@ HWND create_test_window() {
RegisterClassW(&wc);
registered = true;
}
return CreateWindowExW(0, L"LeonidaDxgiWaitableLatencyTestWnd", L"Leonida Waitable Latency Test",
WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 128, 128, nullptr, nullptr,
GetModuleHandleW(nullptr), nullptr);
HWND window = CreateWindowExW(0, L"LeonidaDxgiWaitableLatencyTestWnd", L"Leonida Waitable Latency Test",
WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 128, 128, nullptr, nullptr,
GetModuleHandleW(nullptr), nullptr);
// Shown: a Wayland compositor never answers a FIFO present on a surface that was never mapped (Wine's
// winewayland), so a hidden window blocks the first vsync present forever.
if (window) ShowWindow(window, SW_SHOWNOACTIVATE);
return window;
}

int drain_semaphore(HANDLE h, int limit = 128) {
Expand Down
11 changes: 10 additions & 1 deletion runtime/test/file_system_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,11 @@ void check_read_file_first_touch(const std::filesystem::path& root) {
CloseHandle(h);
return std::make_pair(ok ? got : 0, error);
};
// Wine maps a reserve-only view fully accessible, so its ReadFile simply succeeds.
const bool wine = GetProcAddress(GetModuleHandleW(L"ntdll.dll"), "wine_get_version") != nullptr;
const auto host = read_into_view(&::ReadFile);
check(host.second == ERROR_NOACCESS, "the host ReadFile into uncommitted pages fails with ERROR_NOACCESS");
check(host.second == (wine ? 0 : ERROR_NOACCESS),
"the host ReadFile into uncommitted pages fails with ERROR_NOACCESS (Wine: succeeds)");
const auto shimmed = read_into_view(shim_read);
check(shimmed.second == 0 && shimmed.first == kSize, "the shimmed ReadFile commits the pages and reads it all");
check(std::memcmp(g_first_touch + 0x800, data.data(), kSize) == 0, "the bytes read are the file's");
Expand Down Expand Up @@ -1639,6 +1642,12 @@ void run_checks(const std::filesystem::path& root) {
for (size_t i = 0; i < short_matches.size(); ++i) {
char detail[96];
std::snprintf(detail, sizeof detail, "the long listing matches short Win32 for %ls", masks[i]);
// Wine's short search for *.?. lists mesh.txt, whose three-letter extension one ? cannot match: no
// reference there.
if (std::wcscmp(masks[i], L"*.?.") == 0 && contains(short_matches[i], L"mesh.txt")) {
std::printf("SKIP %s: the host's short search lists mesh.txt\n", detail);
continue;
}
check(long_matches[i] == short_matches[i], detail);
}

Expand Down
11 changes: 9 additions & 2 deletions runtime/test/xbox_present_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1450,12 +1450,19 @@ int main() {
EXPECT(real_frame(i, shown));
if (!shown) ++skipped_presents;
}
EXPECT(skipped_presents > 0);
// Wine's winewayland cannot keep a window minimised: Wayland has no minimised state, so the compositor's
// next configure restores it, and nothing was left to skip.
const bool restored_at_once = skipped_presents == 0 && !IsIconic(window);
EXPECT(skipped_presents > 0 || restored_at_once);
ShowWindow(window, SW_RESTORE);
bool shown = false;
for (int i = 0; i < 3 && !shown; ++i) EXPECT(real_frame((i + 1) % 3, shown)); // stale, then recreated
EXPECT(shown);
std::printf("minimised: %d of 3 presents skipped and not read back; restored: shown again\n", skipped_presents);
if (restored_at_once)
std::printf("minimised: not checked, the window was restored at once (Wine's winewayland)\n");
else
std::printf("minimised: %d of 3 presents skipped and not read back; restored: shown again\n",
skipped_presents);
}
EXPECT(real.PresentX(0, nullptr, nullptr) == S_OK); // the shutdown blank
}
Expand Down