Merge pull request #821 from Taffyyy-ops/fix/vk-pipeline-cache-seed

vk_pipeline_check: match runtime device features and restore pipeline_cache_seed test (RT-PIPELINE-CACHE-SEED)
This commit is contained in:
aslan2142
2026-11-24 21:31:43 +01:00
committed by GitHub
4 changed files with 473 additions and 13 deletions

View File

@ -439,6 +439,29 @@ On Windows with an RTX 5090 (driver 621.14), a synthetic three-compute, one-vert
sample reported zero application-cache hits on its first run and five on the seeded run. On Mesa
llvmpipe the same five pipelines succeeded both times and neither run reported a hit.
### The cache and the runtime's device
The runtime seeds its `VkPipelineCache` from the cache this tool saves, so a pipeline hits there only when the
driver gives it the same cache key in both programs. Measured on Windows with an RX 9070 XT (driver
32.0.32029.2010) and one synthetic compute shader, reading the application-cache-hit bit:
- `robustBufferAccess`, `scalarBlockLayout` and `robustImageAccess` are each part of the key. The runtime's
device enables none of them, so the checker's does not either. Nothing else that differs between the two
devices changed the key on RX 9070 XT: the checker's other features, the runtime's extensions, the application name.
- On Windows 11 with an Intel RaptorLake-S iGPU, clearing those three features alone makes the checker's cache hit
on the runtime's device. On an NVIDIA GeForce RTX 5060 Laptop GPU (driver 621.24), NVIDIA also hashes
`VK_EXT_mesh_shader` (with `meshShaderQueries` enabled, matching the runtime since `#577`) and
`VK_KHR_maintenance8` into the pipeline cache key even for compute shaders, so the checker enables both whenever
supported and keeps `meshShaderQueries` on.
- The executable's file name is part of the key; its folder is not. A copy of the checker under another name
misses the cache the original wrote, and the runtime's device hits the checker's cache only from a program
with the checker's file name. So on this driver a cache written by `vk_pipeline_check.exe` does not hit in
`gta6rt.exe`, and one written by a copy of the checker named `gta6rt.exe` does.
The `pipeline_cache_seed` test embeds a synthetic minimal compute shader and runs a copy of the checker under the
test program's own file name, then creates the same pipeline on the runtime's device from the saved cache. It is
skipped where the driver reports no hit even for a cache the device wrote itself, as llvmpipe does.
## Wave64-emulated corpus (`--wave64-emulate`)
A GPU that only runs 32-wide subgroups (NVIDIA, Intel) needs the corpus translated with

View File

@ -2233,6 +2233,17 @@ if(TARGET Vulkan::Headers)
set_tests_properties(d3d12_indirect_dispatch_count PROPERTIES SKIP_RETURN_CODE 77)
endif()
# The cache vk_pipeline_check saves has to hit on the runtime's device (docs/pipeline_check.md): the test
# compiles an embedded synthetic compute shader through a same-named copy of the checker, then creates the
# same pipeline on the runtime's device from the saved cache.
add_executable(pipeline_cache_seed_test test/pipeline_cache_seed_test.cpp)
add_dependencies(pipeline_cache_seed_test vk_pipeline_check)
target_link_libraries(pipeline_cache_seed_test PRIVATE gta6rt_d3d12_com)
target_compile_definitions(pipeline_cache_seed_test PRIVATE WIN32_LEAN_AND_MEAN NOMINMAX)
target_compile_options(pipeline_cache_seed_test PRIVATE /W4 /permissive- /utf-8)
add_test(NAME pipeline_cache_seed COMMAND pipeline_cache_seed_test $<TARGET_FILE:vk_pipeline_check>)
set_tests_properties(pipeline_cache_seed PROPERTIES SKIP_RETURN_CODE 77)
# What Close returns after one recorded call, against WARP; today's differences are listed in the test.
add_executable(d3d12_close_parity_test test/d3d12_close_parity_test.cpp)
target_link_libraries(d3d12_close_parity_test PRIVATE gta6rt_d3d12_com d3d12 dxgi)

View File

@ -0,0 +1,418 @@
// The cache vk_pipeline_check saves has to hit on the runtime's device:
// pipeline_cache_seed_test <vk_pipeline_check.exe>
//
// Writes a synthetic minimal compute SPIR-V module and index.json to a temporary directory, runs a copy of
// vk_pipeline_check named after this test executable (a driver can make the executable file name part of the pipeline
// cache key, see docs/pipeline_check.md), and then creates the exact same pipeline on the runtime's own device
// (create_vulkan_device_standalone) from the saved cache. Passes when Vulkan creation feedback reports an
// application pipeline cache hit.
//
// Exit 77 (skipped): no Vulkan device for the runtime, pre-Vulkan 1.3 device without core pipeline creation feedback,
// vk_pipeline_check built no pipeline, cache written for another GPU/driver, or a driver that reports no hit even for
// a cache this device wrote itself a moment before.
#include "../shims/d3d12_com.h"
#include "../src/shader_library.h"
#include <wrl/client.h>
#include <array>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <filesystem>
#include <fstream>
#include <iterator>
#include <string>
#include <system_error>
#include <vector>
namespace {
// Minimal valid SPIR-V 1.0 compute shader: `void main() {}` with LocalSize(1, 1, 1).
constexpr std::array<std::uint32_t, 35> kMinimalComputeSpv = {
0x07230203u, 0x00010000u, 0u, 6u, 0u,
(2u << 16) | 17u, 1u, // OpCapability Shader
(3u << 16) | 14u, 0u, 1u, // OpMemoryModel Logical GLSL450
(5u << 16) | 15u, 5u, 4u, 0x6e69616du, 0x00000000u, // OpEntryPoint GLCompute %4 "main"
(6u << 16) | 16u, 4u, 17u, 1u, 1u, 1u, // OpExecutionMode %4 LocalSize 1 1 1
(2u << 16) | 19u, 2u, // %2 = OpTypeVoid
(3u << 16) | 33u, 3u, 2u, // %3 = OpTypeFunction %2
(5u << 16) | 54u, 2u, 4u, 0u, 3u, // %4 = OpFunction %2 None %3
(2u << 16) | 248u, 5u, // %5 = OpLabel
(1u << 16) | 253u, // OpReturn
(1u << 16) | 56u, // OpFunctionEnd
};
struct TempDirGuard {
std::filesystem::path path;
~TempDirGuard() {
if (!path.empty()) {
std::error_code ec;
std::filesystem::remove_all(path, ec);
}
}
};
struct UniqueHandle {
HANDLE h = nullptr;
UniqueHandle() = default;
explicit UniqueHandle(HANDLE handle) : h(handle) {}
~UniqueHandle() { reset(); }
UniqueHandle(const UniqueHandle&) = delete;
UniqueHandle& operator=(const UniqueHandle&) = delete;
void reset(HANDLE next = nullptr) {
if (h && h != INVALID_HANDLE_VALUE) CloseHandle(h);
h = next;
}
HANDLE get() const { return h; }
};
struct VulkanObjects {
VkDevice device = VK_NULL_HANDLE;
PFN_vkDestroyShaderModule destroy_module = nullptr;
PFN_vkDestroyPipelineLayout destroy_layout = nullptr;
PFN_vkDestroyPipelineCache destroy_cache = nullptr;
VkShaderModule shader = VK_NULL_HANDLE;
VkPipelineLayout layout = VK_NULL_HANDLE;
VkPipelineCache seeded = VK_NULL_HANDLE;
VkPipelineCache first = VK_NULL_HANDLE;
VkPipelineCache second = VK_NULL_HANDLE;
~VulkanObjects() {
if (!device) return;
if (second && destroy_cache) destroy_cache(device, second, nullptr);
if (first && destroy_cache) destroy_cache(device, first, nullptr);
if (seeded && destroy_cache) destroy_cache(device, seeded, nullptr);
if (layout && destroy_layout) destroy_layout(device, layout, nullptr);
if (shader && destroy_module) destroy_module(device, shader, nullptr);
}
};
struct Created {
bool ok = false;
bool hit = false;
};
std::vector<char> read_file(const std::filesystem::path& path) {
std::ifstream file(path, std::ios::binary);
return {std::istreambuf_iterator<char>(file), std::istreambuf_iterator<char>()};
}
bool write_bytes(const std::filesystem::path& path, const void* data, std::size_t size) {
std::ofstream file(path, std::ios::binary | std::ios::trunc);
if (!file) return false;
file.write(static_cast<const char*>(data), static_cast<std::streamsize>(size));
file.flush();
return file.good();
}
std::filesystem::path create_temp_dir() {
std::wstring base(MAX_PATH, L'\0');
const DWORD len = GetTempPathW(static_cast<DWORD>(base.size()), base.data());
std::filesystem::path root;
if (len > 0 && len < base.size()) {
base.resize(len);
root = base;
} else {
std::error_code ec;
root = std::filesystem::temp_directory_path(ec);
if (ec) return {};
}
const std::wstring name =
L"leonida_pipeline_cache_seed_" + std::to_wstring(GetCurrentProcessId()) + L"_" +
std::to_wstring(GetTickCount64());
const std::filesystem::path dir = root / name;
std::error_code ec;
std::filesystem::remove_all(dir, ec);
if (!std::filesystem::create_directories(dir, ec) && !std::filesystem::is_directory(dir, ec)) return {};
return dir;
}
std::wstring self_filename() {
std::wstring path(MAX_PATH, L'\0');
for (;;) {
const DWORD len = GetModuleFileNameW(nullptr, path.data(), static_cast<DWORD>(path.size()));
if (len == 0) return {};
if (len < path.size()) {
path.resize(len);
return std::filesystem::path(path).filename().native();
}
if (path.size() >= 32768) return {};
path.resize(path.size() * 2);
}
}
void append_quoted_arg(std::wstring& out, const std::wstring& arg) {
if (!out.empty()) out.push_back(L' ');
out.push_back(L'"');
std::size_t backslashes = 0;
for (wchar_t ch : arg) {
if (ch == L'\\') {
++backslashes;
} else if (ch == L'"') {
out.append(backslashes * 2 + 1, L'\\');
out.push_back(L'"');
backslashes = 0;
} else {
out.append(backslashes, L'\\');
backslashes = 0;
out.push_back(ch);
}
}
out.append(backslashes * 2, L'\\');
out.push_back(L'"');
}
bool run_checker_process(const std::filesystem::path& exe, const std::filesystem::path& spirv_dir,
const std::filesystem::path& cache_path, const std::filesystem::path& log_path,
DWORD& exit_code) {
SECURITY_ATTRIBUTES sa{};
sa.nLength = sizeof(sa);
sa.bInheritHandle = TRUE;
UniqueHandle log_file(CreateFileW(log_path.c_str(), GENERIC_WRITE, FILE_SHARE_READ, &sa, CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL, nullptr));
if (log_file.get() == INVALID_HANDLE_VALUE) return false;
std::wstring cmd_line;
append_quoted_arg(cmd_line, exe.native());
append_quoted_arg(cmd_line, spirv_dir.native());
append_quoted_arg(cmd_line, cache_path.native());
append_quoted_arg(cmd_line, L"--jobs");
append_quoted_arg(cmd_line, L"1");
STARTUPINFOW si{};
si.cb = sizeof(si);
si.dwFlags = STARTF_USESTDHANDLES;
si.hStdOutput = log_file.get();
si.hStdError = log_file.get();
PROCESS_INFORMATION pi{};
const BOOL started =
CreateProcessW(exe.c_str(), cmd_line.data(), nullptr, nullptr, TRUE, 0, nullptr, nullptr, &si, &pi);
log_file.reset();
if (!started) return false;
UniqueHandle proc(pi.hProcess);
UniqueHandle thread(pi.hThread);
const DWORD wait = WaitForSingleObject(proc.get(), 120000);
if (wait != WAIT_OBJECT_0) {
TerminateProcess(proc.get(), 1);
WaitForSingleObject(proc.get(), 5000);
return false;
}
return GetExitCodeProcess(proc.get(), &exit_code) != FALSE;
}
} // namespace
int wmain(int argc, wchar_t** argv) {
if (argc != 2 || !argv[1] || !*argv[1]) {
std::fprintf(stderr, "usage: pipeline_cache_seed_test <vk_pipeline_check.exe>\n");
return 2;
}
const std::filesystem::path checker_src(argv[1]);
std::error_code ec;
if (!std::filesystem::is_regular_file(checker_src, ec)) {
std::fprintf(stderr, "checker executable not found\n");
return 1;
}
TempDirGuard temp;
temp.path = create_temp_dir();
if (temp.path.empty()) {
std::fprintf(stderr, "failed to create temporary directory\n");
return 1;
}
Microsoft::WRL::ComPtr<ID3D12Device> d3d;
if (FAILED(rt::d3d12::create_vulkan_device_standalone(IID_PPV_ARGS(&d3d))) || !d3d) {
std::printf("SKIP: no Vulkan device for the runtime\n");
return 77;
}
const rt::d3d12::VulkanDeviceInfo* info = rt::d3d12::vulkan_device_info(d3d.Get());
if (!info || !info->get_instance_proc) return 1;
const VkDevice device = info->device;
const auto device_proc = reinterpret_cast<PFN_vkGetDeviceProcAddr>(
info->get_instance_proc(info->instance, "vkGetDeviceProcAddr"));
const auto physical_properties = reinterpret_cast<PFN_vkGetPhysicalDeviceProperties>(
info->get_instance_proc(info->instance, "vkGetPhysicalDeviceProperties"));
if (!device_proc || !physical_properties) return 1;
#define LOAD(name) const auto name = reinterpret_cast<PFN_##name>(device_proc(device, #name))
LOAD(vkCreateShaderModule);
LOAD(vkDestroyShaderModule);
LOAD(vkCreatePipelineLayout);
LOAD(vkDestroyPipelineLayout);
LOAD(vkCreatePipelineCache);
LOAD(vkDestroyPipelineCache);
LOAD(vkGetPipelineCacheData);
LOAD(vkCreateComputePipelines);
LOAD(vkDestroyPipeline);
#undef LOAD
if (!vkCreateShaderModule || !vkDestroyShaderModule || !vkCreatePipelineLayout || !vkDestroyPipelineLayout ||
!vkCreatePipelineCache || !vkDestroyPipelineCache || !vkGetPipelineCacheData || !vkCreateComputePipelines ||
!vkDestroyPipeline) {
return 1;
}
VkPhysicalDeviceProperties properties{};
physical_properties(info->physical, &properties);
if (properties.apiVersion < VK_API_VERSION_1_3) {
std::printf("SKIP: %s is pre-Vulkan 1.3 (no core pipeline creation feedback)\n", properties.deviceName);
return 77;
}
const std::filesystem::path spv_path = temp.path / L"seed.spv";
const std::filesystem::path index_path = temp.path / L"index.json";
const std::filesystem::path cache_path = temp.path / L"pipeline_cache.bin";
const std::filesystem::path log_path = temp.path / L"checker.log";
const std::filesystem::path checker_dir = temp.path / L"checker";
const std::wstring self_name = self_filename();
if (self_name.empty()) {
std::fprintf(stderr, "GetModuleFileNameW failed\n");
return 1;
}
if (!std::filesystem::create_directories(checker_dir, ec) && !std::filesystem::is_directory(checker_dir, ec)) {
std::fprintf(stderr, "failed to create checker staging directory\n");
return 1;
}
const std::filesystem::path checker_copy = checker_dir / self_name;
// CopyFileW rather than std::filesystem::copy_file: Wine 9 lacks CopyFile2.
if (!CopyFileW(checker_src.c_str(), checker_copy.c_str(), FALSE)) {
std::fprintf(stderr, "CopyFileW failed (%lu)\n", static_cast<unsigned long>(GetLastError()));
return 1;
}
if (!write_bytes(spv_path, kMinimalComputeSpv.data(), kMinimalComputeSpv.size() * sizeof(std::uint32_t))) {
std::fprintf(stderr, "failed to write synthetic compute shader\n");
return 1;
}
static_assert(sizeof(leonida::ShaderUserData) == 144,
"synthetic index.json push_constant_bytes must match ShaderUserData");
const char index_json[] =
"{\"seed\":{\"stage\":\"cs\",\"bindings\":[],\"push_constant_bytes\":144,"
"\"local_size\":[1,1,1],\"wave64\":false}}\n";
if (!write_bytes(index_path, index_json, sizeof(index_json) - 1)) {
std::fprintf(stderr, "failed to write synthetic index.json\n");
return 1;
}
DWORD checker_exit = 1;
if (!run_checker_process(checker_copy, temp.path, cache_path, log_path, checker_exit)) {
std::fprintf(stderr, "failed to run copied vk_pipeline_check process\n");
return 1;
}
const std::vector<char> log_bytes = read_file(log_path);
const std::string log_text(log_bytes.begin(), log_bytes.end());
const bool built_ok = log_text.find("cs pipelines: 1 ok, 0 failed, 0 skipped") != std::string::npos;
const bool has_cache = std::filesystem::is_regular_file(cache_path, ec);
if (!built_ok || !has_cache) {
if (log_text.find("no Vulkan physical device") != std::string::npos ||
log_text.find("vulkan-1") != std::string::npos ||
log_text.find("libvulkan") != std::string::npos ||
log_text.find("cs pipelines: 0 ok, 0 failed, 1 skipped") != std::string::npos) {
std::printf("SKIP: vk_pipeline_check built no pipeline here\n");
return 77;
}
std::fprintf(stderr, "vk_pipeline_check did not build the pipeline (exit %lu)\n%s\n",
static_cast<unsigned long>(checker_exit), log_text.c_str());
return 1;
}
const std::vector<char> seed = read_file(cache_path);
if (seed.size() < sizeof(VkPipelineCacheHeaderVersionOne)) {
std::fprintf(stderr, "pipeline_cache.bin is too small (%zu bytes)\n", seed.size());
return 1;
}
VkPipelineCacheHeaderVersionOne header{};
std::memcpy(&header, seed.data(), sizeof(header));
if (header.vendorID != properties.vendorID || header.deviceID != properties.deviceID ||
std::memcmp(header.pipelineCacheUUID, properties.pipelineCacheUUID, VK_UUID_SIZE) != 0) {
std::printf("SKIP: pipeline_cache.bin was written for another GPU or driver than the runtime's %s\n",
properties.deviceName);
return 77;
}
VulkanObjects vk;
vk.device = device;
vk.destroy_module = vkDestroyShaderModule;
vk.destroy_layout = vkDestroyPipelineLayout;
vk.destroy_cache = vkDestroyPipelineCache;
VkShaderModuleCreateInfo module_info{VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO};
module_info.codeSize = kMinimalComputeSpv.size() * sizeof(std::uint32_t);
module_info.pCode = kMinimalComputeSpv.data();
if (vkCreateShaderModule(device, &module_info, nullptr, &vk.shader) != VK_SUCCESS) return 1;
const VkPushConstantRange push{VK_SHADER_STAGE_COMPUTE_BIT, 0, sizeof(leonida::ShaderUserData)};
VkPipelineLayoutCreateInfo layout_info{VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO};
layout_info.pushConstantRangeCount = 1;
layout_info.pPushConstantRanges = &push;
if (vkCreatePipelineLayout(device, &layout_info, nullptr, &vk.layout) != VK_SUCCESS) return 1;
const auto make_cache = [&](const void* data, std::size_t size) {
VkPipelineCacheCreateInfo cache_info{VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO};
cache_info.initialDataSize = size;
cache_info.pInitialData = data;
VkPipelineCache cache = VK_NULL_HANDLE;
if (vkCreatePipelineCache(device, &cache_info, nullptr, &cache) != VK_SUCCESS) return VkPipelineCache{};
return cache;
};
leonida::ShaderEntry entry;
entry.stage = "cs";
entry.local_size = {1, 1, 1};
const auto create = [&](VkPipelineCache cache) {
VkPipelineCreationFeedback feedback{};
const VkPipelineCreationFeedbackCreateInfo feedback_info{
VK_STRUCTURE_TYPE_PIPELINE_CREATION_FEEDBACK_CREATE_INFO, nullptr, &feedback, 0, nullptr};
VkComputePipelineCreateInfo pipeline_info{VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO, &feedback_info};
pipeline_info.stage = {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO};
pipeline_info.stage.stage = VK_SHADER_STAGE_COMPUTE_BIT;
pipeline_info.stage.module = vk.shader;
pipeline_info.stage.pName = "main";
VkPipelineShaderStageRequiredSubgroupSizeCreateInfo required_size{};
leonida::apply_subgroup_request(leonida::decide_subgroup_size(entry, info->subgroup), required_size,
pipeline_info.stage);
pipeline_info.layout = vk.layout;
VkPipeline pipeline = VK_NULL_HANDLE;
Created result;
if (vkCreateComputePipelines(device, cache, 1, &pipeline_info, nullptr, &pipeline) != VK_SUCCESS) return result;
vkDestroyPipeline(device, pipeline, nullptr);
result.ok = true;
result.hit = (feedback.flags & VK_PIPELINE_CREATION_FEEDBACK_VALID_BIT) != 0 &&
(feedback.flags & VK_PIPELINE_CREATION_FEEDBACK_APPLICATION_PIPELINE_CACHE_HIT_BIT) != 0;
return result;
};
vk.seeded = make_cache(seed.data(), seed.size());
const Created from_seed = vk.seeded ? create(vk.seeded) : Created{};
if (!from_seed.ok) {
std::fprintf(stderr, "FAIL: the pipeline was not created from the seeded cache\n");
return 1;
}
if (from_seed.hit) {
std::printf("ok: vk_pipeline_check cache hits on the runtime's device (%s)\n", properties.deviceName);
return 0;
}
// Does this driver report a hit at all? Write a cache on this device and read it back.
vk.first = make_cache(nullptr, 0);
std::vector<char> own;
std::size_t own_size = 0;
if (vk.first && create(vk.first).ok && vkGetPipelineCacheData(device, vk.first, &own_size, nullptr) == VK_SUCCESS) {
own.resize(own_size);
if (vkGetPipelineCacheData(device, vk.first, &own_size, own.data()) != VK_SUCCESS) own.clear();
own.resize(own.empty() ? 0 : own_size);
}
vk.second = own.empty() ? VkPipelineCache{} : make_cache(own.data(), own.size());
const bool reports_hits = vk.second && create(vk.second).hit;
if (reports_hits) {
std::fprintf(stderr,
"FAIL: vk_pipeline_check cache does not hit on the runtime's device (%s), which does hit a "
"cache it wrote itself: vk_pipeline_check's device differs from the runtime's in something the "
"driver makes part of a pipeline's cache key\n",
properties.deviceName);
return 1;
}
std::printf("SKIP: %s reports no cache hit even for a cache it wrote itself\n", properties.deviceName);
return 77;
}

View File

@ -7,8 +7,10 @@
// descriptor-free shaders with the standard push-constant range
// - ps/vs/ms/gs: graphics pipeline via vkCreateGraphicsPipelines (Vulkan 1.3 dynamic rendering, no render pass)
// paired with minimal partner stubs from <spirv dir>/stubs/ (generated by tools/spirv_stubs.py)
// Only optional device extensions needed by the selected shaders (and supported by the GPU) are enabled. Shaders
// whose required features or partner stubs are unavailable are reported as skipped rather than failed.
// VK_EXT_mesh_shader (with meshShaderQueries) and VK_KHR_maintenance8 are always enabled when supported so the
// saved pipeline cache matches the runtime's device key; other optional device extensions are enabled only when
// needed by the selected shaders. Shaders whose required features or partner stubs are unavailable are reported as
// skipped rather than failed.
// [cache.bin] loaded first if it exists (a stopped run resumes: cached pipelines are instant), saved every
// 10 minutes and at the end
// --jobs N compile on up to N worker threads (default: half the hardware threads)
@ -1058,14 +1060,13 @@ int main(int argc, char** argv) {
return failed ? 1 : 0;
}
// Scan selected shaders to request only the optional extensions they actually use.
bool want_mesh = false, want_bary = false, want_lock = false, want_m8 = false, want_fma = false, want_clock = false;
// Scan selected shaders to request the optional shader extensions they use. VK_EXT_mesh_shader and
// VK_KHR_maintenance8 are always enabled when supported (even for compute-only runs), because
// create_vulkan_device_standalone enables both unconditionally and NVIDIA includes them in its cache key.
bool want_bary = false, want_lock = false, want_fma = false, want_clock = false;
for (auto& [_, meta] : work) {
if (meta->stage == "ms") want_mesh = true;
if (meta->needs_maintenance8) want_m8 = true;
for (const auto& feat : meta->features) {
if (feat == "meshShader") want_mesh = true;
else if (feat == "fragmentShaderBarycentric") want_bary = true;
if (feat == "fragmentShaderBarycentric") want_bary = true;
else if (feat == "fragmentShaderPixelInterlock") want_lock = true;
else if (feat == "shaderFmaFloat32" || feat == "shaderFmaFloat64") want_fma = true; // OpFmaKHR (--fma khr)
else if (feat == "shaderSubgroupClock" || feat == "shaderDeviceClock") want_clock = true;
@ -1137,13 +1138,11 @@ int main(int argc, char** argv) {
link(&f11, reinterpret_cast<VkBaseOutStructure*>(&f11), nullptr, true); // shaderDrawParameters (VS v0/v3)
link(&f12, reinterpret_cast<VkBaseOutStructure*>(&f12), nullptr, true);
link(&f13, reinterpret_cast<VkBaseOutStructure*>(&f13), nullptr, true);
const bool ext_mesh = link(&mesh, reinterpret_cast<VkBaseOutStructure*>(&mesh), VK_EXT_MESH_SHADER_EXTENSION_NAME, want_mesh);
const bool ext_mesh = link(&mesh, reinterpret_cast<VkBaseOutStructure*>(&mesh), VK_EXT_MESH_SHADER_EXTENSION_NAME, true);
const bool ext_bary = link(&bary, reinterpret_cast<VkBaseOutStructure*>(&bary), VK_KHR_FRAGMENT_SHADER_BARYCENTRIC_EXTENSION_NAME, want_bary);
const bool ext_lock = link(&lock, reinterpret_cast<VkBaseOutStructure*>(&lock), VK_EXT_FRAGMENT_SHADER_INTERLOCK_EXTENSION_NAME, want_lock);
#ifdef VK_KHR_MAINTENANCE_8_EXTENSION_NAME
const bool ext_m8 = link(&m8, reinterpret_cast<VkBaseOutStructure*>(&m8), VK_KHR_MAINTENANCE_8_EXTENSION_NAME, want_m8);
#else
(void)want_m8;
const bool ext_m8 = link(&m8, reinterpret_cast<VkBaseOutStructure*>(&m8), VK_KHR_MAINTENANCE_8_EXTENSION_NAME, true);
#endif
#ifdef VK_KHR_SHADER_FMA_EXTENSION_NAME
VkPhysicalDeviceShaderFmaFeaturesKHR fma{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_FMA_FEATURES_KHR};
@ -1172,6 +1171,12 @@ int main(int argc, char** argv) {
VkPhysicalDeviceFeatures2 f2{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2};
f2.pNext = chain;
vkGetPhysicalDeviceFeatures2(pd, &f2); // fills every linked struct with what's supported
// The runtime's device (create_vulkan_device_standalone) never enables these three, and a driver makes them part
// of a pipeline's cache key: with any of them on here, the cache this tool saves does not hit in gta6rt
// (pipeline_cache_seed_test; docs/pipeline_check.md, "The cache and the runtime's device").
f2.features.robustBufferAccess = VK_FALSE;
f12.scalarBlockLayout = VK_FALSE;
f13.robustImageAccess = VK_FALSE;
VkPhysicalDeviceMeshShaderPropertiesEXT mesh_props{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MESH_SHADER_PROPERTIES_EXT};
if (ext_mesh && mesh.meshShader) {
VkPhysicalDeviceProperties2 mesh_device_props{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2};
@ -1179,7 +1184,10 @@ int main(int argc, char** argv) {
vkGetPhysicalDeviceProperties2(pd, &mesh_device_props);
}
if (ext_mesh) {
mesh.multiviewMeshShader = mesh.primitiveFragmentShadingRateMeshShader = mesh.meshShaderQueries = VK_FALSE;
// Keep meshShaderQueries as supported: create_vulkan_device_standalone enables it when present (#577),
// and NVIDIA hashes it into the pipeline cache key even for compute pipelines.
if (!f2.features.pipelineStatisticsQuery) mesh.meshShaderQueries = VK_FALSE;
mesh.multiviewMeshShader = mesh.primitiveFragmentShadingRateMeshShader = VK_FALSE;
mesh.taskShader = VK_FALSE;
}
float prio = 1;