Skip to content

Commit

Permalink
cgpu: use Vulkan pipeline cache
Browse files Browse the repository at this point in the history
  • Loading branch information
pablode committed Jul 26, 2024
1 parent bd2faed commit 33ff7eb
Showing 1 changed file with 31 additions and 3 deletions.
34 changes: 31 additions & 3 deletions src/cgpu/src/Cgpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ namespace gtl
CgpuPhysicalDeviceFeatures features;
CgpuPhysicalDeviceProperties properties;
VmaAllocator allocator;
VkPipelineCache pipelineCache;
};

struct CgpuIBuffer
Expand Down Expand Up @@ -1040,6 +1041,28 @@ namespace gtl
CGPU_RETURN_ERROR("failed to create vma allocator");
}

VkPipelineCacheCreateInfo cacheCreateInfo = {
.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO,
.pNext = nullptr,
.flags = VK_PIPELINE_CACHE_CREATE_EXTERNALLY_SYNCHRONIZED_BIT, // no MT access
.initialDataSize = 0,
.pInitialData = nullptr
};

result = idevice->table.vkCreatePipelineCache(
idevice->logicalDevice,
&cacheCreateInfo,
nullptr,
&idevice->pipelineCache
);

if (result != VK_SUCCESS)
{
CGPU_RETURN_ERROR("failed to create pipeline cache");

idevice->pipelineCache = VK_NULL_HANDLE;
}

device->handle = handle;
return true;
}
Expand All @@ -1048,12 +1071,17 @@ namespace gtl
{
CGPU_RESOLVE_OR_RETURN_DEVICE(device, idevice);

vmaDestroyAllocator(idevice->allocator);
if (idevice->pipelineCache != VK_NULL_HANDLE)
{
idevice->table.vkDestroyPipelineCache(idevice->logicalDevice, idevice->pipelineCache, nullptr);
}

idevice->table.vkDestroyQueryPool(idevice->logicalDevice, idevice->timestamp_pool, nullptr);
idevice->table.vkDestroyCommandPool(idevice->logicalDevice, idevice->commandPool, nullptr);
idevice->table.vkDestroyDevice(idevice->logicalDevice, nullptr);

vmaDestroyAllocator(idevice->allocator);

iinstance->ideviceStore.free(device.handle);
return true;
}
Expand Down Expand Up @@ -1716,7 +1744,7 @@ namespace gtl

VkResult result = idevice->table.vkCreateComputePipelines(
idevice->logicalDevice,
VK_NULL_HANDLE,
idevice->pipelineCache,
1,
&pipelineCreateInfo,
nullptr,
Expand Down Expand Up @@ -2002,7 +2030,7 @@ namespace gtl

if (idevice->table.vkCreateRayTracingPipelinesKHR(idevice->logicalDevice,
VK_NULL_HANDLE,
VK_NULL_HANDLE,
idevice->pipelineCache,
1,
&rtPipelineCreateInfo,
nullptr,
Expand Down

0 comments on commit 33ff7eb

Please sign in to comment.