diff options
| author | adonizm <250916442+adonizm@users.noreply.github.com> | 2026-11-22 04:44:50 +0100 |
|---|---|---|
| committer | adonizm <250916442+adonizm@users.noreply.github.com> | 2026-11-22 04:56:45 +0100 |
| commit | 77f42e09c09e74d21603c448bc2a1c766bb51597 (patch) | |
| tree | dc9a995e77e6de049680b112755cd7ef11fd35b7 /runtime/src | |
| parent | 4a36bb19979b611f525d027f92e0fefad1626546 (diff) | |
Runtime tests: LEONIDA_VK_DEVICE picks the Vulkan GPU by name
Two GPUs of one vendor share one driver, so the loader's driver filters
cannot tell them apart, and the D3D12 tests always took the last discrete
GPU (an RTX 3060 next to an RTX 5070 Ti). LEONIDA_VK_DEVICE is part of the
device name, compared without case, read by vk_test_device.h and by the
layer's standalone device. A value that matches no device fails the run
instead of testing another GPU, as LEONIDA_HOST_ADAPTER does. The shader GPU
tools (vk_compute_test, vk_harness, ...) keep their own pickers for now.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'runtime/src')
| -rw-r--r-- | runtime/src/vulkan_device_filter.h | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/runtime/src/vulkan_device_filter.h b/runtime/src/vulkan_device_filter.h new file mode 100644 index 000000000..1e7a12e37 --- /dev/null +++ b/runtime/src/vulkan_device_filter.h | |||
| @@ -0,0 +1,39 @@ | |||
| 1 | #pragma once | ||
| 2 | |||
| 3 | // LEONIDA_VK_DEVICE: which Vulkan GPU the runtime and its tests take on a machine with more than one. The value is | ||
| 4 | // part of the device name, compared without case ("5070", "radeon"); unset or empty takes every device, and the | ||
| 5 | // caller then picks as before (the last discrete GPU, else the first that fits). Several GPUs of one vendor share | ||
| 6 | // one driver, so the loader's own driver filters cannot tell them apart. A value that matches no device must fail | ||
| 7 | // the caller, not fall back, so a typo cannot silently test another GPU (as LEONIDA_HOST_ADAPTER does). | ||
| 8 | |||
| 9 | #include <cctype> | ||
| 10 | #include <cstdlib> | ||
| 11 | #include <string> | ||
| 12 | |||
| 13 | namespace leonida { | ||
| 14 | |||
| 15 | // The filter, lower-cased; empty when unset. | ||
| 16 | inline std::string vulkan_device_filter() { | ||
| 17 | #ifdef _MSC_VER | ||
| 18 | #pragma warning(push) | ||
| 19 | #pragma warning(disable : 4996) // getenv: read at device selection only | ||
| 20 | #endif | ||
| 21 | const char* value = std::getenv("LEONIDA_VK_DEVICE"); | ||
| 22 | #ifdef _MSC_VER | ||
| 23 | #pragma warning(pop) | ||
| 24 | #endif | ||
| 25 | std::string out = value ? value : ""; | ||
| 26 | for (char& c : out) c = char(std::tolower(static_cast<unsigned char>(c))); | ||
| 27 | return out; | ||
| 28 | } | ||
| 29 | |||
| 30 | // True when `device_name` (VkPhysicalDeviceProperties::deviceName) is wanted. | ||
| 31 | inline bool vulkan_device_wanted(const char* device_name) { | ||
| 32 | const std::string filter = vulkan_device_filter(); | ||
| 33 | if (filter.empty()) return true; | ||
| 34 | std::string name = device_name ? device_name : ""; | ||
| 35 | for (char& c : name) c = char(std::tolower(static_cast<unsigned char>(c))); | ||
| 36 | return name.find(filter) != std::string::npos; | ||
| 37 | } | ||
| 38 | |||
| 39 | } // namespace leonida | ||