From ae74f89d1e149a7b7a3b24c1e64a705839755311 Mon Sep 17 00:00:00 2001 From: d7ommy Date: Wed, 25 Nov 2026 19:19:20 +0300 Subject: [PATCH] test: respect LEONIDA_HOST_ADAPTER and layer LUID in d3d12_texture_tiles (RT-TEXTURE-TILES-HOST-ADAPTER) runtime/test/d3d12_texture_tiles_test.cpp previously used an unguided native_device() adapter loop that ignored LEONIDA_HOST_ADAPTER and the layer's Vulkan device LUID, defaulting to an integrated GPU (e.g. Intel UHD) on dual-GPU laptops even when configured for discrete GPU testing. Pass vulkan->GetAdapterLuid() to native_device() and query LEONIDA_HOST_ADAPTER matching the pattern in d3d12_buffer_tiles_test.cpp, skipping the native reference comparison cleanly when the requested adapter lacks tier 2 tiled resources instead of failing on the wrong hardware. AI-assisted (Claude Code) --- runtime/test/d3d12_texture_tiles_test.cpp | 70 +++++++++++++++++++++-- 1 file changed, 66 insertions(+), 4 deletions(-) diff --git a/runtime/test/d3d12_texture_tiles_test.cpp b/runtime/test/d3d12_texture_tiles_test.cpp index fc08c34220..4d15415f30 100644 --- a/runtime/test/d3d12_texture_tiles_test.cpp +++ b/runtime/test/d3d12_texture_tiles_test.cpp @@ -6,9 +6,11 @@ #include #include +#include #include #include #include +#include #include #define EXPECT(condition) do { \ @@ -248,14 +250,55 @@ bool run(ID3D12Device& device, UINT width, UINT height, UINT64 tile_copy_offset, return true; } -ComPtr native_device() { +// D3D12 on the adapter `luid` names, when it has tiled resources tier 2 or more; null otherwise. +ComPtr tiled_device(IDXGIFactory4& factory, LUID luid, bool print = true) { + ComPtr adapter; + if (!luid.LowPart && !luid.HighPart) return {}; + if (FAILED(factory.EnumAdapterByLuid(luid, IID_PPV_ARGS(&adapter)))) return {}; + DXGI_ADAPTER_DESC1 desc{}; + ComPtr device; + D3D12_FEATURE_DATA_D3D12_OPTIONS options{}; + if (FAILED(adapter->GetDesc1(&desc)) || (desc.Flags & DXGI_ADAPTER_FLAG_SOFTWARE) || + FAILED(D3D12CreateDevice(adapter.Get(), D3D_FEATURE_LEVEL_11_0, IID_PPV_ARGS(&device))) || + FAILED(device->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS, &options, sizeof(options))) || + options.TiledResourcesTier < D3D12_TILED_RESOURCES_TIER_2) + return {}; + if (print) + std::printf("Native D3D12: %ls (the layer's adapter), tiled resources tier %u\n", desc.Description, + unsigned(options.TiledResourcesTier)); + return device; +} + +// The host adapter for the native half. LEONIDA_HOST_ADAPTER picks it as in d3d12_copy_compare.h: "warp", or part of +// an adapter name (case-insensitive); a value that names no adapter with tiled resources tier 2 skips the native half +// rather than testing another GPU. Unset: the adapter behind the layer's Vulkan device (`layer_luid`, as +// host_adapter.h picks it), so a PC with two GPUs compares the layer with its own GPU's driver; when that adapter +// has no tier 2, the first hardware adapter with tier 2 or more. +ComPtr native_device(LUID layer_luid) { ComPtr factory; if (FAILED(CreateDXGIFactory1(IID_PPV_ARGS(&factory)))) return {}; + char want[128] = {}; + GetEnvironmentVariableA("LEONIDA_HOST_ADAPTER", want, sizeof(want)); + std::string needle(want); + std::transform(needle.begin(), needle.end(), needle.begin(), [](unsigned char c) { return char(std::tolower(c)); }); + if (needle.empty()) + if (auto device = tiled_device(*factory.Get(), layer_luid)) return device; for (UINT i = 0;; ++i) { ComPtr adapter; - if (factory->EnumAdapters1(i, &adapter) != S_OK) return {}; + if (needle == "warp") { + if (i > 0 || FAILED(factory->EnumWarpAdapter(IID_PPV_ARGS(&adapter)))) break; + } else if (factory->EnumAdapters1(i, &adapter) != S_OK) { + break; + } DXGI_ADAPTER_DESC1 desc{}; - if (FAILED(adapter->GetDesc1(&desc)) || (desc.Flags & DXGI_ADAPTER_FLAG_SOFTWARE)) continue; + if (FAILED(adapter->GetDesc1(&desc))) continue; + if (needle.empty()) { + if (desc.Flags & DXGI_ADAPTER_FLAG_SOFTWARE) continue; + } else if (needle != "warp") { + std::string name; + for (const wchar_t* c = desc.Description; *c; ++c) name += char(std::tolower(*c < 128 ? *c : '?')); + if (name.find(needle) == std::string::npos) continue; + } ComPtr device; if (FAILED(D3D12CreateDevice(adapter.Get(), D3D_FEATURE_LEVEL_11_0, IID_PPV_ARGS(&device)))) continue; D3D12_FEATURE_DATA_D3D12_OPTIONS options{}; @@ -264,6 +307,10 @@ ComPtr native_device() { std::printf("Native D3D12: %ls, tiled resources tier %u\n", desc.Description, unsigned(options.TiledResourcesTier)); return device; } + if (!needle.empty()) + std::printf("Native D3D12: no adapter matching LEONIDA_HOST_ADAPTER=%s with tiled resources tier 2 or more; " + "native half skipped\n", want); + return {}; } } // namespace @@ -283,7 +330,22 @@ int main() { std::fputs("A texture with multiple mips did not use the committed fallback\n", stderr); return 1; } - auto native = native_device(); + const LUID layer_luid = vulkan->GetAdapterLuid(); + auto native = native_device(layer_luid); + if (native) { + // Unset LEONIDA_HOST_ADAPTER means the layer's own GPU whenever its driver can run the cases: comparing with + // another GPU's driver measures that driver, not the layer. + char want[2] = {}; + const LUID host_luid = native->GetAdapterLuid(); + ComPtr factory; + if (!GetEnvironmentVariableA("LEONIDA_HOST_ADAPTER", want, sizeof(want)) && + SUCCEEDED(CreateDXGIFactory1(IID_PPV_ARGS(&factory))) && tiled_device(*factory.Get(), layer_luid, false) && + (host_luid.LowPart != layer_luid.LowPart || host_luid.HighPart != layer_luid.HighPart)) { + std::fprintf(stderr, "Native D3D12 runs on another adapter than the layer's, which has tiled resources " + "tier 2 or more\n"); + return 1; + } + } const auto* info = rt::d3d12::vulkan_device_info(vulkan.Get()); const bool dedicated_copy = info && !info->copy_queues.empty() && info->copy_family != info->queue_family; struct ReplayCase {