diff --git a/docs/pipeline_check.md b/docs/pipeline_check.md index d5d76cb931..b0cad7327b 100644 --- a/docs/pipeline_check.md +++ b/docs/pipeline_check.md @@ -447,9 +447,13 @@ The runtime seeds its `VkPipelineCache` from the cache this tool saves, so a pip 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 first two are +- `robustBufferAccess`, `scalarBlockLayout` and `robustImageAccess` are each part of the key. `scalarBlockLayout` is disabled on both devices; the runtime's device enables supported core image robustness for storage views, and so - does the checker. Nothing else that differs between the two devices changed the key on RX 9070 XT: the checker's + does the checker. Since `ba626820e` (#1723) the runtime's device enables `robustBufferAccess`, with `VK_EXT_robustness2`'s + `robustBufferAccess2`, for bounded indexed indirect draws (`leonida::can_enable_robust_index_view`), and + `nullDescriptor` wherever it is offered. The checker makes the same choice with the same helper. On an RX 7900 XT + (driver 32.0.32029.2010) a checker that left `robustBufferAccess` off missed the runtime's cache, and matching + `nullDescriptor` alone was not enough. 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 diff --git a/runtime/test/vk_pipeline_check.cpp b/runtime/test/vk_pipeline_check.cpp index 0e39d0f621..87378bec86 100644 --- a/runtime/test/vk_pipeline_check.cpp +++ b/runtime/test/vk_pipeline_check.cpp @@ -56,6 +56,7 @@ #include "../src/spirv_words.h" #include "../src/subgroup_size.h" #include "../src/vulkan_bindless.h" +#include "../src/vulkan_index_view.h" #include #include @@ -1144,6 +1145,52 @@ int main(int argc, char** argv) { link(&f12, reinterpret_cast(&f12), nullptr, true); link(&f13, reinterpret_cast(&f13), nullptr, true); const bool ext_mesh = link(&mesh, reinterpret_cast(&mesh), VK_EXT_MESH_SHADER_EXTENSION_NAME, true); + // VK_EXT_robustness2 and robustBufferAccess as the runtime's device chooses them (create_vulkan_device_standalone): + // nullDescriptor wherever it is offered, and robustBufferAccess with robustBufferAccess2 for bounded indexed + // indirect draws (leonida::can_enable_robust_index_view, with maintenance5). A driver makes robust buffer access part + // of a pipeline's cache key (AMD does), so the cache only hits in gta6rt when this device chooses the same. + // (The runtime also enables maintenance5 for A8 render targets alone; that is not mirrored, as before.) + VkPhysicalDeviceRobustness2FeaturesEXT robustness2{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ROBUSTNESS_2_FEATURES_EXT}; + bool null_descriptor = false, robust_index_view = false; +#ifdef VK_KHR_MAINTENANCE_5_EXTENSION_NAME + VkPhysicalDeviceMaintenance5FeaturesKHR maintenance5{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_5_FEATURES_KHR}; +#endif + if (has(VK_EXT_ROBUSTNESS_2_EXTENSION_NAME)) { + VkPhysicalDeviceVulkan12Features q12{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES}; + robustness2.pNext = &q12; + bool sized_indirect = false; +#ifdef VK_KHR_MAINTENANCE_5_EXTENSION_NAME + if (has(VK_KHR_MAINTENANCE_5_EXTENSION_NAME)) q12.pNext = &maintenance5; +#endif + VkPhysicalDeviceFeatures2 query{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2, &robustness2}; + vkGetPhysicalDeviceFeatures2(pd, &query); + null_descriptor = robustness2.nullDescriptor == VK_TRUE; +#ifdef VK_KHR_MAINTENANCE_5_EXTENSION_NAME + // The runtime only decides this where the SDK has maintenance5, as here. + sized_indirect = query.features.drawIndirectFirstInstance && maintenance5.maintenance5; + robust_index_view = leonida::can_enable_robust_index_view( + pd, vkGetPhysicalDeviceProperties2, sized_indirect, + query.features.robustBufferAccess && robustness2.robustBufferAccess2, + // Same predicate as the runtime's VulkanDeviceInfo::bindless (create_vulkan_device_standalone). The OR of + // update-after-bind flags is not equivalent: it can be true where the runtime's AND is false (a device + // with some update-after-bind feature but not the sampled/storage-image ones), which flips + // robust_index_view and therefore robustBufferAccess, and breaks the cache key again. + q12.runtimeDescriptorArray && query.features.shaderSampledImageArrayDynamicIndexing && + query.features.shaderStorageImageArrayDynamicIndexing && + q12.descriptorBindingSampledImageUpdateAfterBind && + q12.descriptorBindingStorageImageUpdateAfterBind && + q12.descriptorBindingStorageBufferUpdateAfterBind); + maintenance5.pNext = nullptr; +#endif + (void)sized_indirect; + robustness2 = {VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ROBUSTNESS_2_FEATURES_EXT}; + } + if (null_descriptor || robust_index_view) + link(&robustness2, reinterpret_cast(&robustness2), VK_EXT_ROBUSTNESS_2_EXTENSION_NAME, true); +#ifdef VK_KHR_MAINTENANCE_5_EXTENSION_NAME + if (robust_index_view) + link(&maintenance5, reinterpret_cast(&maintenance5), VK_KHR_MAINTENANCE_5_EXTENSION_NAME, true); +#endif const bool ext_bary = link(&bary, reinterpret_cast(&bary), VK_KHR_FRAGMENT_SHADER_BARYCENTRIC_EXTENSION_NAME, want_bary); const bool ext_lock = link(&lock, reinterpret_cast(&lock), VK_EXT_FRAGMENT_SHADER_INTERLOCK_EXTENSION_NAME, want_lock); #ifdef VK_KHR_MAINTENANCE_8_EXTENSION_NAME @@ -1176,12 +1223,17 @@ 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 the first two, and a driver makes them part - // of a pipeline's cache key: with either 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"). The runtime enables - // robustImageAccess where supported (for 1D and 3D storage views), so its queried value is kept. - f2.features.robustBufferAccess = VK_FALSE; + // A driver makes these part of a pipeline's cache key, so they must be what the runtime's device + // (create_vulkan_device_standalone) enables, or 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"). The runtime never enables + // scalarBlockLayout, and enables robustBufferAccess (and robustBufferAccess2) only for the robust index view chosen + // above. It enables robustImageAccess where supported (for 1D and 3D storage views), so its queried value is kept. + f2.features.robustBufferAccess = robust_index_view ? VK_TRUE : VK_FALSE; f12.scalarBlockLayout = VK_FALSE; + // The query above filled the linked robustness2 struct with what is supported; keep only the runtime's choice. + robustness2.nullDescriptor = null_descriptor ? VK_TRUE : VK_FALSE; + robustness2.robustBufferAccess2 = robust_index_view ? VK_TRUE : VK_FALSE; + robustness2.robustImageAccess2 = 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};