Open 3D Engine Atom Gem API Reference 23.10.0
O3DE is an open-source, fully-featured, high-fidelity, modular 3D engine for building games and simulations, available to every industry.
AZ::RHI::PipelineLibrary Class Reference

#include <PipelineLibrary.h>

Inherits AZ::RHI::DeviceObject.

Inherited by AZ::DX12::PipelineLibrary, AZ::Metal::PipelineLibrary, AZ::Null::PipelineLibrary, and AZ::Vulkan::PipelineLibrary.

Public Member Functions

 AZ_RTTI (PipelineLibrary, "{843579BE-57E4-4527-AB00-C0217885AEA9}")
 
ResultCode Init (Device &device, const PipelineLibraryDescriptor &descriptor)
 
ResultCode MergeInto (AZStd::span< const PipelineLibrary *const > librariesToMerge)
 
ConstPtr< PipelineLibraryDataGetSerializedData () const
 
bool SaveSerializedData (const AZStd::string &filePath) const
 Saves the platform-specific data to disk using the filePath provided. This is done through RHI backend drivers.
 
virtual bool IsMergeRequired () const
 Returns whether the current library need to be merged.
 
- Public Member Functions inherited from AZ::RHI::DeviceObject
 AZ_RTTI (DeviceObject, "{17D34F71-944C-4AF5-9823-627474C4C0A6}", Object)
 
bool IsInitialized () const
 Returns whether the device object is initialized.
 
DeviceGetDevice () const
 
- Public Member Functions inherited from AZ::RHI::Object
 AZ_RTTI (Object, "{E43378F1-2331-4173-94B8-990ED20E6003}")
 
void SetName (const Name &name)
 Sets the name of the object.
 
const Name & GetName () const
 Returns the name set on the object by SetName.
 
uint32_t use_count ()
 Returns the current use count of the object.
 

Additional Inherited Members

- Protected Member Functions inherited from AZ::RHI::DeviceObject
void Init (Device &device)
 The derived class should call this method to assign the device.
 
void Shutdown () override
 Clears the current bound device to null.
 
- Protected Member Functions inherited from AZ::RHI::Object
void add_ref () const
 
void release () const
 
- Protected Attributes inherited from AZ::RHI::Object
AZStd::atomic_int m_useCount = 0
 

Detailed Description

PipelineState initialization is an expensive operation on certain platforms. If multiple pipeline states are created with little variation between them, the contents are still duplicated. This class is an allocation context for pipeline states, provided at PipelineState::Init, which will perform de-duplication of internal pipeline state components and cache the results.

Practically speaking, if many pipeline states are created with shared data between them (e.g. permutations of the same shader), then providing a PipelineLibrary instance will reduce the memory footprint and cost of compilation.

Additionally, the PipelineLibrary is able to serialize the internal driver-contents to and from an opaque data blob. This enables building up a pipeline state cache on disk, which can dramatically reduce pipeline state compilation cost when run from a pre-warmed cache.

PipelineLibrary is thread-safe, in the sense that it will take a lock during compilation. It is possible to initialize pipeline states across threads using the same PipelineLibrary instance, but this will result in the two calls serializing on the mutex. Instead, see PipelineStateCache which stores a PipelineLibrary instance per thread to avoid this contention.

Member Function Documentation

◆ GetSerializedData()

ConstPtr< PipelineLibraryData > AZ::RHI::PipelineLibrary::GetSerializedData ( ) const

Serializes the platform-specific data and returns it as a new PipelineLibraryData instance. The data is opaque to the user and can only be used to re-initialize the library. Use this method to extract serialized data prior to application shutdown, save it to disk, and use it when initializing on subsequent runs.

◆ Init()

ResultCode AZ::RHI::PipelineLibrary::Init ( Device device,
const PipelineLibraryDescriptor descriptor 
)

Initializes the pipeline library from a platform-specific data payload. This data is generated by calling GetSerializedData in a previous run of the application. When run for the first time, the serialized data should be empty. When the application completes, the library can be serialized and the contents saved to disk. Subsequent loads will experience much faster pipeline state creation times (on supported platforms). On success, the library is transitioned to the initialized state. On failure, the library remains uninitialized.

Parameters
descriptorThe descriptor needed to init the PipelineLibrary.

◆ MergeInto()

ResultCode AZ::RHI::PipelineLibrary::MergeInto ( AZStd::span< const PipelineLibrary *const >  librariesToMerge)

Merges the contents of other libraries into this library. This method must be called on an initialized library. A common use case for this method is to construct thread-local libraries and merge them into a single unified library. The serialized data can then be extracted from the unified library. An error code is returned on failure and the behavior is as if the method was never called.


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