Rendu
A lightweight rendering engine for experimentations
Loading...
Searching...
No Matches
Classes | Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
PipelineCache Class Reference

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.
 

Detailed Description

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.

Member Function Documentation

◆ buildComputePipeline()

VkPipeline PipelineCache::buildComputePipeline ( Program program)
private

Build a compute pipeline from a given compute program.

Parameters
programthe program to use
Returns
the newly created pipeline

◆ buildGraphicsPipeline()

VkPipeline PipelineCache::buildGraphicsPipeline ( const GPUState state)
private

Build a graphics pipeline from a given graphics state.

Parameters
statethe state to use
Returns
the newly created pipeline

◆ clean()

void PipelineCache::clean ( )

Clean all existing pipelines

◆ createNewPipeline()

VkPipeline PipelineCache::createNewPipeline ( const GPUState state,
const uint64_t  hash 
)
private

Create a new pipeline based on a given state and store it in the cache for future use.

Parameters
statethe state to use
hasha hash of the complete state (already computed before)
Returns
the newly created pipeline

◆ getComputePipeline()

VkPipeline PipelineCache::getComputePipeline ( const GPUState state)

Retrieve a pipeline for a given GPU compute state, or create it if needed.

Parameters
statethe state to represent
Returns
the corresponding native pipeline

◆ getGraphicsPipeline()

VkPipeline PipelineCache::getGraphicsPipeline ( const GPUState state)

Retrieve a pipeline for a given GPU graphics state, or create it if needed.

Parameters
statethe state to represent
Returns
the corresponding native pipeline

◆ init()

void PipelineCache::init ( )

Initialize the cache.


The documentation for this class was generated from the following files: