|
Blender V4.3
|
#include <vk_pipeline_pool.hh>
Inherits blender::NonCopyable.
Public Member Functions | |
| VKPipelinePool () | |
| void | init () |
| VkPipeline | get_or_create_compute_pipeline (VKComputeInfo &compute_info, bool is_static_shader, VkPipeline vk_pipeline_base) |
| VkPipeline | get_or_create_graphics_pipeline (VKGraphicsInfo &graphics_info, bool is_static_shader, VkPipeline vk_pipeline_base) |
| void | remove (Span< VkShaderModule > vk_shader_modules) |
| void | free_data () |
Persistent cache | |
| void | read_from_disk () |
| void | write_to_disk () |
Public Member Functions inherited from blender::NonCopyable | |
| NonCopyable (const NonCopyable &other)=delete | |
| NonCopyable & | operator= (const NonCopyable &other)=delete |
| NonCopyable ()=default | |
| NonCopyable (NonCopyable &&other)=default | |
| NonCopyable & | operator= (NonCopyable &&other)=default |
Friends | |
| class | VKDevice |
Pipelines are lazy initialized and same pipelines should share their handle.
A requirement of our render graph implementation is that changes of the pipeline can be detected based on the VkPipeline handle. We only want to rebind the pipeline handle when the handle actually changes. This improves performance (especially on NVIDIA) devices where pipeline binds are known to be costly.
Especially for graphics pipelines many parameters are needed to compile a graphics pipeline. Some of the information would be boiler plating; or at least from Blender point of view. To improve lookup performance we use a slimmed down version of the pipeline create info structs. The idea is that we can limit the required data because we control which data we actually use, removing the boiler plating and improve hashing performance better than the VkPipelineCache can give us.
TODO: Extensions like VK_EXT_graphics_pipeline_library should fit in this class and ease the development for graphics pipelines. Geometry in and frame-buffer out could be cached separately to reduce pipeline creation times. Most likely we will add support when we work on graphic pipelines. Recent drivers all support this extension, but the full coverage is still <20%. A fallback should made available for older drivers is required.
TODO: Creation of shader modules needs to be revisited. VK_EXT_graphics_pipeline_library deprecates the use of shader modules and use the spriv bin directly. In this extension the pipeline and shader module are the same. The current approach should also be revisited as the latest drivers all implement pipeline libraries, but there are some platforms where the driver isn't been updated and doesn't implement this extension. In that case shader modules should still be used.
TODO: GPUMaterials (or any other large shader) should be unloaded when the GPUShader is destroyed. Exact details what the best approach is unclear as support for EEVEE is still lacking.
Definition at line 248 of file vk_pipeline_pool.hh.
| blender::gpu::VKPipelinePool::VKPipelinePool | ( | ) |
Definition at line 27 of file vk_pipeline_pool.cc.
| void blender::gpu::VKPipelinePool::free_data | ( | ) |
Destroy all created pipelines.
Function is called just before the device is removed. This cannot be done in the destructor as that would be called after the device is removed.
Definition at line 636 of file vk_pipeline_pool.cc.
References blender::gpu::VKBackend::device, blender::gpu::VKBackend::get(), lock, VK_ALLOCATION_CALLBACKS, and blender::gpu::VKDevice::vk_handle().
Referenced by blender::gpu::VKDevice::deinit().
| VkPipeline blender::gpu::VKPipelinePool::get_or_create_compute_pipeline | ( | VKComputeInfo & | compute_info, |
| bool | is_static_shader, | ||
| VkPipeline | vk_pipeline_base ) |
Get an existing or create a new compute pipeline based on the provided ComputeInfo.
When vk_pipeline_base is a valid pipeline handle, the pipeline base will be used to speed up pipeline creation process.
Definition at line 172 of file vk_pipeline_pool.cc.
References BLI_assert, blender::gpu::VKBackend::device, blender::gpu::VKBackend::get(), lock, result, blender::gpu::VKComputeInfo::specialization_constants, VK_ALLOCATION_CALLBACKS, blender::gpu::VKDevice::vk_handle(), blender::gpu::VKComputeInfo::vk_pipeline_layout, and blender::gpu::VKComputeInfo::vk_shader_module.
Referenced by blender::gpu::VKShader::ensure_and_get_compute_pipeline().
| VkPipeline blender::gpu::VKPipelinePool::get_or_create_graphics_pipeline | ( | VKGraphicsInfo & | graphics_info, |
| bool | is_static_shader, | ||
| VkPipeline | vk_pipeline_base ) |
Get an existing or create a new compute pipeline based on the provided ComputeInfo.
When vk_pipeline_base is a valid pipeline handle, the pipeline base will be used to speed up pipeline creation process.
Definition at line 215 of file vk_pipeline_pool.cc.
References blender::Vector< T, InlineBufferCapacity, Allocator >::append_n_times(), blender::gpu::VKGraphicsInfo::VertexIn::attributes, blender::gpu::VKGraphicsInfo::VertexIn::bindings, blender::gpu::GPUState::blend, BLI_assert, blender::Vector< T, InlineBufferCapacity, Allocator >::clear(), blender::gpu::VKGraphicsInfo::FragmentOut::color_attachment_formats, blender::gpu::GPUState::culling_test, blender::Vector< T, InlineBufferCapacity, Allocator >::data(), blender::gpu::VKGraphicsInfo::FragmentOut::depth_attachment_format, blender::gpu::GPUState::depth_test, blender::gpu::VKBackend::device, ELEM, blender::gpu::VKGraphicsInfo::fragment_out, blender::gpu::VKGraphicsInfo::fragment_shader, blender::gpu::VKBackend::get(), GPU_BLEND_ADDITIVE, GPU_BLEND_ADDITIVE_PREMULT, GPU_BLEND_ALPHA, GPU_BLEND_ALPHA_PREMULT, GPU_BLEND_ALPHA_UNDER_PREMUL, GPU_BLEND_BACKGROUND, GPU_BLEND_CUSTOM, GPU_BLEND_INVERT, GPU_BLEND_MULTIPLY, GPU_BLEND_NONE, GPU_BLEND_OIT, GPU_BLEND_SUBTRACT, GPU_DEPTH_ALWAYS, GPU_DEPTH_EQUAL, GPU_DEPTH_GREATER, GPU_DEPTH_GREATER_EQUAL, GPU_DEPTH_LESS, GPU_DEPTH_LESS_EQUAL, GPU_DEPTH_NONE, GPU_STENCIL_ALWAYS, GPU_STENCIL_EQUAL, GPU_STENCIL_NEQUAL, GPU_STENCIL_NONE, GPU_STENCIL_OP_COUNT_DEPTH_FAIL, GPU_STENCIL_OP_COUNT_DEPTH_PASS, GPU_STENCIL_OP_NONE, GPU_STENCIL_OP_REPLACE, GPU_WRITE_ALPHA, GPU_WRITE_BLUE, GPU_WRITE_DEPTH, GPU_WRITE_GREEN, GPU_WRITE_RED, blender::gpu::GPUState::invert_facing, lock, blender::gpu::VKGraphicsInfo::mutable_state, blender::gpu::VKGraphicsInfo::pre_rasterization, result, blender::gpu::VKGraphicsInfo::FragmentShader::scissors, blender::gpu::GPUState::shadow_bias, blender::Vector< T, InlineBufferCapacity, Allocator >::size(), blender::gpu::VKGraphicsInfo::specialization_constants, blender::gpu::VKGraphicsInfo::state, blender::gpu::VKGraphicsInfo::FragmentOut::stencil_attachment_format, blender::gpu::GPUStateMutable::stencil_compare_mask, blender::gpu::GPUState::stencil_op, blender::gpu::GPUStateMutable::stencil_reference, blender::gpu::GPUState::stencil_test, blender::gpu::GPUStateMutable::stencil_write_mask, blender::gpu::to_vk_cull_mode_flags(), blender::gpu::VKGraphicsInfo::FragmentShader::update_hash(), blender::gpu::VKGraphicsInfo::vertex_in, blender::gpu::VKGraphicsInfo::FragmentShader::viewports, VK_ALLOCATION_CALLBACKS, blender::gpu::VKGraphicsInfo::FragmentShader::vk_fragment_module, blender::gpu::VKGraphicsInfo::PreRasterization::vk_geometry_module, blender::gpu::VKDevice::vk_handle(), blender::gpu::VKGraphicsInfo::vk_pipeline_layout, blender::gpu::VKGraphicsInfo::VertexIn::vk_topology, blender::gpu::VKGraphicsInfo::PreRasterization::vk_vertex_module, and blender::gpu::GPUState::write_mask.
Referenced by blender::gpu::VKShader::ensure_and_get_graphics_pipeline().
| void blender::gpu::VKPipelinePool::init | ( | ) |
Definition at line 130 of file vk_pipeline_pool.cc.
References blender::gpu::VKBackend::device, blender::gpu::VKBackend::get(), VK_ALLOCATION_CALLBACKS, and blender::gpu::VKDevice::vk_handle().
Referenced by blender::gpu::VKDevice::init().
| void blender::gpu::VKPipelinePool::read_from_disk | ( | ) |
Read the static pipeline cache from cache file.
Pipeline caches requires blender to be build with WITH_BUILDINFO enabled . Between commits shader modules can change and shader module identifiers cannot be used. We use the build info to check if the identifiers can be reused.
Previous stored pipeline cache will not be read when G_DEBUG_GPU is enabled. In this case the shader modules will be compiled with other settings and any cached pipeline will not be used during this session.
NOTE: When developing shaders we assume that WITH_BUILDINFO is turned off or G_DEBUG_GPU flag is set.
Definition at line 699 of file vk_pipeline_pool.cc.
References BLI_exists(), BLI_file_touch(), CLOG_INFO, blender::gpu::VKBackend::device, file, G, G_DEBUG_GPU, blender::gpu::VKBackend::get(), blender::gpu::LOG, MEM_freeN(), MEM_mallocN, and blender::gpu::VKDevice::vk_handle().
Referenced by blender::gpu::VKDevice::init().
| void blender::gpu::VKPipelinePool::remove | ( | Span< VkShaderModule > | vk_shader_modules | ) |
Remove all shader pipelines that uses the given shader_module.
Definition at line 607 of file vk_pipeline_pool.cc.
References blender::Vector< T, InlineBufferCapacity, Allocator >::append(), blender::Span< T >::contains(), blender::gpu::VKBackend::device, blender::gpu::VKBackend::get(), lock, VK_ALLOCATION_CALLBACKS, and blender::gpu::VKDevice::vk_handle().
| void blender::gpu::VKPipelinePool::write_to_disk | ( | ) |
Store the static pipeline cache to disk.
Pipeline caches requires blender to be build with WITH_BUILDINFO enabled . Between commits shader modules can change and shader module identifiers cannot be used. We use the build info to check if the identifiers can be reused.
The cache will not be written when G_DEBUG_GPU is active. In this case the shader modules have been generated with debug information and other compiler settings are used. This will clutter the pipeline cache.
NOTE: When developing shaders we assume that WITH_BUILDINFO is turned off or G_DEBUG_GPU flag is set.
Definition at line 755 of file vk_pipeline_pool.cc.
References CLOG_INFO, blender::gpu::VKBackend::device, file, G, G_DEBUG_GPU, blender::gpu::VKBackend::get(), blender::gpu::LOG, MEM_freeN(), MEM_mallocN, and blender::gpu::VKDevice::vk_handle().
Referenced by blender::gpu::VKDevice::deinit().
|
friend |
Definition at line 249 of file vk_pipeline_pool.hh.