Use a global cache for the pipeline.

This commit is contained in:
Adam Treat 2023-07-21 21:53:47 -04:00
parent ae5f122b77
commit 747aab98fc

View file

@ -278,22 +278,25 @@ Algorithm::createPipeline()
"main", "main",
&specializationInfo); &specializationInfo);
static std::shared_ptr<vk::PipelineCache> globalPipelineCache = std::make_shared<vk::PipelineCache>();
if(!*globalPipelineCache) {
vk::PipelineCacheCreateInfo pipelineCacheInfo =
vk::PipelineCacheCreateInfo();
this->mDevice->createPipelineCache(
&pipelineCacheInfo, nullptr, globalPipelineCache.get());
}
vk::ComputePipelineCreateInfo pipelineInfo(vk::PipelineCreateFlags(), vk::ComputePipelineCreateInfo pipelineInfo(vk::PipelineCreateFlags(),
shaderStage, shaderStage,
*this->mPipelineLayout, *this->mPipelineLayout,
vk::Pipeline(), vk::Pipeline(),
0); 0);
vk::PipelineCacheCreateInfo pipelineCacheInfo = this->mFreePipelineCache = false;
vk::PipelineCacheCreateInfo();
this->mPipelineCache = std::make_shared<vk::PipelineCache>();
this->mDevice->createPipelineCache(
&pipelineCacheInfo, nullptr, this->mPipelineCache.get());
this->mFreePipelineCache = true;
#ifdef KOMPUTE_CREATE_PIPELINE_RESULT_VALUE #ifdef KOMPUTE_CREATE_PIPELINE_RESULT_VALUE
vk::ResultValue<vk::Pipeline> pipelineResult = vk::ResultValue<vk::Pipeline> pipelineResult =
this->mDevice->createComputePipeline(*this->mPipelineCache, pipelineInfo); this->mDevice->createComputePipeline(*globalPipelineCache, pipelineInfo);
if (pipelineResult.result != vk::Result::eSuccess) { if (pipelineResult.result != vk::Result::eSuccess) {
throw std::runtime_error("Failed to create pipeline result: " + throw std::runtime_error("Failed to create pipeline result: " +
@ -305,7 +308,7 @@ Algorithm::createPipeline()
this->mFreePipeline = true; this->mFreePipeline = true;
#else #else
vk::Pipeline pipeline = vk::Pipeline pipeline =
this->mDevice->createComputePipeline(*this->mPipelineCache, pipelineInfo) this->mDevice->createComputePipeline(*globalPipelineCache, pipelineInfo)
.value; .value;
this->mPipeline = std::make_shared<vk::Pipeline>(pipeline); this->mPipeline = std::make_shared<vk::Pipeline>(pipeline);
this->mFreePipeline = true; this->mFreePipeline = true;