VkPipelineCache data invalidation after driver updates
0 reputation · 15 Sept 2020, 15:28 UTC
0 reputation · 15 Sept 2020, 15:28 UTC
Vulkan applications use VkPipelineCache to store compiled pipeline state object (PSO) data, reducing the overhead of vkCreateGraphicsPipelines in subsequent sessions by providing a pre-populated data blob.
The Vulkan specification allows drivers to silently ignore cache data if it is deemed incompatible. This creates uncertainty when managing persistent cache files across minor driver versions or vendor-specific updates, as there is no standardized mechanism to programmatically detect if the driver has discarded the provided blob in favor of a full re-compile.
Given that the internal format of the cache blob is implementation-dependent, what are the specific criteria drivers use to determine cache staleness during a version transition? Is there a documented way to verify if a provided VkPipelineCache blob was successfully utilized or ignored by the driver?
Drivers decide cache staleness by checking the values stored in the cache header against the current device state. If any of those values differ, the driver silently discards the cache and recompiles the pipeline. There is no standard API to report whether the cache was actually used.
apiVersion field in the cache header must match the device’s apiVersion returned by vkGetPhysicalDeviceProperties2.driverVersion field in the header must equal the current driver’s driverVersion (or fall within a vendor‑defined compatibility window). Many vendors bump this field with each major/minor update.VkPipelineCacheHeaderVersion value (currently VK_PIPELINE_CACHE_HEADER_VERSION_ONE) must match. Vendors may introduce new header versions that carry additional data.vendorID and deviceID are compared to ensure the cache was built for the same GPU.If any of the above checks fail, the driver silently drops the cache data and compiles the pipeline from scratch. The API does not expose a flag or return value that explicitly says “cache ignored.”
vkGetPhysicalDeviceProperties2 to fetch apiVersion, driverVersion, and vendorID/deviceID.VkPipelineCache from the file data.vkCreateGraphicsPipelines with the cache attached.VK_ERROR_INVALID_SHADER_NV or VK_ERROR_OUT_OF_DEVICE_MEMORY usually indicate the cache was discarded. A successful return means the cache was accepted.vkGetPipelineCacheData. If the returned size is larger than the original, the driver has added data, suggesting the cache was used. If the size is unchanged or the data is identical, it may have been ignored.driverVersion and apiVersion you used.VkPhysicalDevicePipelineCacheCompatibilityProperties via an extension; you can query that to get a compatibility string. If present, compare it with the stored string.Because the Vulkan spec leaves cache format entirely vendor‑specific, there is no universal way to ask the driver “Did you use this cache?” The only reliable signals are error codes and changes in cache size after pipeline creation.
Did you observe any pipeline‑creation errors after updating the driver? If not, let us know so we can refine the recommendation.
Use comments to ask for clarification. Post a solution as an answer.
32,275 reputation · 15 Sept 2020, 16:40 UTC
If you need to know whether a supplied VkPipelineCache blob was actually used, enable the VK_EXT_pipeline_creation_feedback extension and attach a VkPipelineCreationFeedbackEXT structure to each VkGraphicsPipelineCreateInfo via its pNext chain. After vkCreateGraphicsPipelines returns, check the flags field for VK_PIPELINE_CREATION_FEEDBACK_APPLICATION_PIPELINE_CACHE_HIT_BIT. A set bit indicates the driver satisfied the request from the cache; an unset bit (with VK_PIPELINE_CREATION_FEEDBACK_VALID_BIT still set) means the driver ignored the blob and recompiled. Note that this extension is optional—verify its presence with vkEnumerateDeviceExtensionProperties before relying on it.