Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use VkPipelineCache?

Tags:

vulkan

If I understand it correctly, I'm supposed to create an empty VkPipelineCache object, pass it into vkCreateGraphicsPipelinesand data will be written into it. I can then reuse it with other pipelines I'm creating or save it to a file and use it on the next run.

I've tried following the LunarG example to extra the info:

uint32_t headerLength = pData[0];
uint32_t cacheHeaderVersion = pData[1];
uint32_t vendorID = pData[2];
uint32_t deviceID = pData[3];

But I always get headerLength is 32 and the rest 0. Looking at the spec (https://vulkan.lunarg.com/doc/view/1.0.26.0/linux/vkspec.chunked/ch09s06.html Table 9.1), the cacheHeaderVersion should always be 1, as the only available cache header version is VK_PIPELINE_CACHE_HEADER_VERSION_ONE = 1.

Also the size of pData is usually only 32 bytes, even when I create 10 pipelines with it. What am I doing wrong?

like image 713
Rhu Mage Avatar asked Feb 08 '19 18:02

Rhu Mage


1 Answers

A Vulkan pipeline cache is an opaque object that's only meaningful to the driver. There are very few operations that you're supposed to use on it.

  • Creating a pipeline cache, optionally with a block of opaque binary data that was saved from an earlier run
  • Getting the opaque binary data from an existing pipeline cache, typically to serialize to disk before exiting your application
  • Destroying a pipeline cache as part of the proper shutdown process.

The idea is that the driver can use the cache to speed up creation of pipelines within your program, and also to speed up pipeline creation on subsequent runs of your application.

You should not be attempting to interpret the cache data returned from vkGetPipelineCacheData at all. The only purpose for that data is to be passed into a later call to vkCreatePipelineCache.

Also the size of pData is usually only 32 bytes, even when I create 10 pipelines with it. What am I doing wrong?

Drivers must implement vkCreatePipelineCache, vkGetPipelineCacheData, etc. But they don't actually have to support caching. So if you're working with a driver that doesn't have anything it can cache, or hasn't done the work to support caching, then you'd naturally get back an empty cache (other than the header).

like image 149
Jherico Avatar answered Oct 11 '22 07:10

Jherico