Rendu
A lightweight rendering engine for experimentations
|
Create and reuse GPU pipelines based on a given state. This supports both graphics and compute pipelines. More...
#include <PipelineCache.hpp>
Classes | |
struct | Entry |
Store a pipeline along with part of the information used to generate it. More... | |
struct | PipelineToDelete |
Information for buffered pipeline deletion. More... | |
Public Member Functions | |
void | init () |
VkPipeline | getGraphicsPipeline (const GPUState &state) |
VkPipeline | getComputePipeline (const GPUState &state) |
void | freeOutdatedPipelines () |
Destroy pipelines that are referencing outdated state and are not used anymore. | |
void | clean () |
Private Types | |
using | ProgramPipelines = std::unordered_multimap< uint64_t, Entry > |
Per program pipeline type. | |
using | GraphicCache = std::unordered_map< const Program *, ProgramPipelines > |
Complete cache type. | |
using | ComputeCache = std::unordered_map< const Program *, VkPipeline > |
Complete cache type. | |
Private Member Functions | |
VkPipeline | createNewPipeline (const GPUState &state, const uint64_t hash) |
VkPipeline | buildGraphicsPipeline (const GPUState &state) |
VkPipeline | buildComputePipeline (Program &program) |
Private Attributes | |
GraphicCache | _graphicPipelines |
Graphics pipeline cache. | |
ComputeCache | _computePipelines |
Compute pipeline cache. | |
VkPipelineCache | _vulkanCache = VK_NULL_HANDLE |
Vulkan pipeline cache. | |
std::deque< PipelineToDelete > | _pipelinesToDelete |
List of pipelines to delete once we are sure they are unused. | |
Create and reuse GPU pipelines based on a given state. This supports both graphics and compute pipelines.
We use a two-levels cache, first sorting by Program because each program only has one instance (and thus one pointer adress) that we can use directly to retrieve pipelines. Then we use a hash of the GPU state parameters to retrieve compatible pipelines, and compare mesh and attachments layouts manually as duplicates will be quite rare. (usually a program is used with a specific set of meshes and a fixed set of attachments). We could compare program layouts to share pipelines between similar programs, but it would be more complex. A Vulkan cache is also used internally, saved on disk and restored at loading.
|
private |
Build a compute pipeline from a given compute program.
program | the program to use |
|
private |
Build a graphics pipeline from a given graphics state.
state | the state to use |
void PipelineCache::clean | ( | ) |
Clean all existing pipelines
|
private |
Create a new pipeline based on a given state and store it in the cache for future use.
state | the state to use |
hash | a hash of the complete state (already computed before) |
VkPipeline PipelineCache::getComputePipeline | ( | const GPUState & | state | ) |
Retrieve a pipeline for a given GPU compute state, or create it if needed.
state | the state to represent |
VkPipeline PipelineCache::getGraphicsPipeline | ( | const GPUState & | state | ) |
Retrieve a pipeline for a given GPU graphics state, or create it if needed.
state | the state to represent |
void PipelineCache::init | ( | ) |
Initialize the cache.