Vulkan: Pipeline Cache
This PR adds the default vulkan pipeline cache to when creating pipelines. Pipeline caching reuses pipelines that have already been created. Pipeline creation can be somewhat costly - it has to compile the shaders at creation time for example. The cache is recreated at each run of Blender. Pull Request: https://projects.blender.org/blender/blender/pulls/115346
This commit is contained in:
@@ -23,6 +23,7 @@ namespace blender::gpu {
|
||||
|
||||
void VKDevice::deinit()
|
||||
{
|
||||
VK_ALLOCATION_CALLBACKS
|
||||
if (!is_initialized()) {
|
||||
return;
|
||||
}
|
||||
@@ -34,8 +35,10 @@ void VKDevice::deinit()
|
||||
}
|
||||
samplers_.free();
|
||||
destroy_discarded_resources();
|
||||
vkDestroyPipelineCache(vk_device_, vk_pipeline_cache_, vk_allocation_callbacks);
|
||||
vmaDestroyAllocator(mem_allocator_);
|
||||
mem_allocator_ = VK_NULL_HANDLE;
|
||||
|
||||
debugging_tools_.deinit(vk_instance_);
|
||||
|
||||
vk_instance_ = VK_NULL_HANDLE;
|
||||
@@ -68,6 +71,7 @@ void VKDevice::init(void *ghost_context)
|
||||
VKBackend::capabilities_init(*this);
|
||||
init_debug_callbacks();
|
||||
init_memory_allocator();
|
||||
init_pipeline_cache();
|
||||
|
||||
samplers_.init();
|
||||
|
||||
@@ -122,6 +126,14 @@ void VKDevice::init_memory_allocator()
|
||||
vmaCreateAllocator(&info, &mem_allocator_);
|
||||
}
|
||||
|
||||
void VKDevice::init_pipeline_cache()
|
||||
{
|
||||
VK_ALLOCATION_CALLBACKS;
|
||||
VkPipelineCacheCreateInfo create_info = {};
|
||||
create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
|
||||
vkCreatePipelineCache(vk_device_, &create_info, vk_allocation_callbacks, &vk_pipeline_cache_);
|
||||
}
|
||||
|
||||
void VKDevice::init_dummy_buffer(VKContext &context)
|
||||
{
|
||||
if (dummy_buffer_.is_allocated()) {
|
||||
|
||||
@@ -74,6 +74,7 @@ class VKDevice : public NonCopyable {
|
||||
|
||||
/** Allocator used for texture and buffers and other resources. */
|
||||
VmaAllocator mem_allocator_ = VK_NULL_HANDLE;
|
||||
VkPipelineCache vk_pipeline_cache_ = VK_NULL_HANDLE;
|
||||
|
||||
/** Limits of the device linked to this context. */
|
||||
VkPhysicalDeviceProperties vk_physical_device_properties_ = {};
|
||||
@@ -150,6 +151,11 @@ class VKDevice : public NonCopyable {
|
||||
return mem_allocator_;
|
||||
}
|
||||
|
||||
VkPipelineCache vk_pipeline_cache_get() const
|
||||
{
|
||||
return vk_pipeline_cache_;
|
||||
}
|
||||
|
||||
debug::VKDebuggingTools &debugging_tools_get()
|
||||
{
|
||||
return debugging_tools_;
|
||||
@@ -222,6 +228,7 @@ class VKDevice : public NonCopyable {
|
||||
void init_physical_device_features();
|
||||
void init_debug_callbacks();
|
||||
void init_memory_allocator();
|
||||
void init_pipeline_cache();
|
||||
|
||||
/* During initialization the backend requires access to update the workarounds. */
|
||||
friend VKBackend;
|
||||
|
||||
@@ -57,7 +57,7 @@ VKPipeline VKPipeline::create_compute_pipeline(
|
||||
|
||||
VkPipeline vk_pipeline;
|
||||
if (vkCreateComputePipelines(device.device_get(),
|
||||
nullptr,
|
||||
device.vk_pipeline_cache_get(),
|
||||
1,
|
||||
&pipeline_info,
|
||||
vk_allocation_callbacks,
|
||||
@@ -182,7 +182,7 @@ void VKPipeline::finalize(VKContext &context,
|
||||
|
||||
const VKDevice &device = VKBackend::get().device_get();
|
||||
vkCreateGraphicsPipelines(device.device_get(),
|
||||
VK_NULL_HANDLE,
|
||||
device.vk_pipeline_cache_get(),
|
||||
1,
|
||||
&pipeline_create_info,
|
||||
vk_allocation_callbacks,
|
||||
|
||||
Reference in New Issue
Block a user