diff --git a/docs/pipeline_check.md b/docs/pipeline_check.md index 4d5be5e352..44b206796e 100644 --- a/docs/pipeline_check.md +++ b/docs/pipeline_check.md @@ -447,9 +447,17 @@ 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 and the same inputs, + the update-after-bind one being the runtime's `VulkanDeviceInfo::bindless`, and enables update-after-bind as the + runtime does: the sampled-image, storage-image and storage-buffer bits only where `bindless` holds, never the + uniform or texel buffer ones (with `robustBufferAccess` on, a device without `robustBufferAccessUpdateAfterBind` + may not enable any buffer one, VUID-VkDeviceCreateInfo-robustBufferAccess-10247). 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 3ff89524fc..e5df9df282 100644 --- a/runtime/test/vk_pipeline_check.cpp +++ b/runtime/test/vk_pipeline_check.cpp @@ -59,6 +59,7 @@ #include "../src/spirv_words.h" #include "../src/subgroup_size.h" #include "../src/vulkan_bindless.h" +#include "../src/vulkan_index_view.h" #include #include @@ -789,6 +790,14 @@ ChildRun run_child(const std::filesystem::path& exe, const std::string& dir, return r; } +// The runtime's VulkanDeviceInfo::bindless (create_vulkan_device_standalone), from the supported features: what its +// bindless set 0 needs, and whether its device enables the update-after-bind features that set uses. +bool runtime_bindless(const VkPhysicalDeviceFeatures& f, const VkPhysicalDeviceVulkan12Features& f12) { + return f12.runtimeDescriptorArray && f.shaderSampledImageArrayDynamicIndexing && + f.shaderStorageImageArrayDynamicIndexing && f12.descriptorBindingSampledImageUpdateAfterBind && + f12.descriptorBindingStorageImageUpdateAfterBind && f12.descriptorBindingStorageBufferUpdateAfterBind; +} + } // namespace int main(int argc, char** argv) { @@ -1149,6 +1158,45 @@ 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; + // The last input is the runtime's VulkanDeviceInfo::bindless, the update-after-bind features its device + // enables; this device enables the same ones below (VUID-VkDeviceCreateInfo-robustBufferAccess-10247). + robust_index_view = leonida::can_enable_robust_index_view( + pd, vkGetPhysicalDeviceProperties2, sized_indirect, + query.features.robustBufferAccess && robustness2.robustBufferAccess2, runtime_bindless(query.features, q12)); + 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 // The runtime's device enables VK_EXT_transform_feedback (transformFeedback, and geometryStreams when the device // offers it) whenever the extension is present (D3D-302), and a driver makes it part of a pipeline's cache key, so // the checker enables it too (docs/pipeline_check.md, "The cache and the runtime's device"). @@ -1192,12 +1240,27 @@ 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; + // Update-after-bind as the runtime enables it: the three its bindless set 0 uses, only where the whole bindless + // feature set is there, and never the uniform or texel buffer ones. With robustBufferAccess on and no + // robustBufferAccessUpdateAfterBind property, no buffer update-after-bind feature may be enabled (VUID above). + const bool set0_update_after_bind = runtime_bindless(f2.features, f12); + f12.descriptorBindingSampledImageUpdateAfterBind = set0_update_after_bind ? VK_TRUE : VK_FALSE; + f12.descriptorBindingStorageImageUpdateAfterBind = set0_update_after_bind ? VK_TRUE : VK_FALSE; + f12.descriptorBindingStorageBufferUpdateAfterBind = set0_update_after_bind ? VK_TRUE : VK_FALSE; + f12.descriptorBindingUniformBufferUpdateAfterBind = VK_FALSE; + f12.descriptorBindingUniformTexelBufferUpdateAfterBind = VK_FALSE; + f12.descriptorBindingStorageTexelBufferUpdateAfterBind = 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};