> ## Documentation Index
> Fetch the complete documentation index at: https://devdocs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# CreatePipelineLibrary

> Creates a cached pipeline library.

Creates a cached pipeline library. For pipeline state objects (PSOs) that are expected to share data together, grouping them into a library before serializing them means that there's less overhead due to metadata, as well as the opportunity to avoid redundant or duplicated data being written to disk.

You can query for **ID3D12PipelineLibrary** support with [**ID3D12Device::CheckFeatureSupport**](/reference/graphics/d3d12/interfaces/id3d12device/methods/id3d12device_checkfeaturesupport_public), with [**D3D12\_FEATURE\_SHADER\_CACHE**](/reference/graphics/d3d12/enums/d3d12_feature_public) and [**D3D12\_FEATURE\_DATA\_SHADER\_CACHE**](/reference/graphics/d3d12/structs/d3d12_feature_data_shader_cache_public). If the *Flags* member of [**D3D12\_FEATURE\_DATA\_SHADER\_CACHE**](/reference/graphics/d3d12/structs/d3d12_feature_data_shader_cache_public) contains the flag [**D3D12\_SHADER\_CACHE\_SUPPORT\_LIBRARY**](/reference/graphics/d3d12/enums/d3d12_shader_cache_support_flags_public), the **ID3D12PipelineLibrary** interface is supported. If not, then **DXGI\_ERROR\_NOT\_SUPPORTED** will always be returned when this function is called.

## Syntax

```cpp theme={null}
HRESULT CreatePipelineLibrary(
    const void  pLibraryBlob,
    SIZE_T BlobLength,
    const IID & riid,
    void  ppPipelineLibrary
)
```

### Parameters

*pLibraryBlob*<br />Type: const void \*

If the input library blob is empty, then the initial content of the library is empty. If the input library blob is not empty, then it is validated for integrity, parsed, and the pointer is stored. The pointer provided as input to this method must remain valid for the lifetime of the object returned. For efficiency reasons, the data is not copied.

*BlobLength*<br />Type: SIZE\_T

Specifies the length of *pLibraryBlob* in bytes.

*riid*<br />Type: const IID &

Specifies a unique REFIID for the [ID3D12PipelineLibrary](/reference/graphics/d3d12/interfaces/id3d12pipelinelibrary/id3d12pipelinelibrary_public) object. Typically set this and the following parameter with the macro `IID_PPV_ARGS(&Library)`, where **Library** is the name of the object.

*ppPipelineLibrary*<br />Type: void \*\*

Returns a pointer to the created library.

### Return value

Type: HRESULT

If the function succeeds, it returns **S\_OK**. Otherwise, it returns an [**HRESULT**](https://learn.microsoft.com/en-us/windows/win32/com/structure-of-com-error-codes) [error code](https://learn.microsoft.com/en-us/windows/win32/com/com-error-codes-10), including **E\_INVALIDARG** if the blob is corrupted or unrecognized, **D3D12\_ERROR\_DRIVER\_VERSION\_MISMATCH** if the provided data came from an old driver or runtime, and **D3D12\_ERROR\_ADAPTER\_NOT\_FOUND** if the data came from different hardware.

If you pass `nullptr` for *pPipelineLibrary* then the runtime still performs the validation of the blob but avoid creating the actual library and returns S\_FALSE if the library would have been created.

Also, the feature requires an updated driver, and attempting to use it on old drivers will return DXGI\_ERROR\_UNSUPPORTED.

## Remarks

A pipeline library enables the following operations.

* Adding pipeline state objects (PSOs) to an existing library object (refer to [StorePipeline](/reference/graphics/d3d12/interfaces/id3d12pipelinelibrary/methods/id3d12pipelinelibrary_storepipeline_public)).
* Serializing a PSO library into a contiguous block of memory for disk storage (refer to [Serialize](/reference/graphics/d3d12/interfaces/id3d12pipelinelibrary/methods/id3d12pipelinelibrary_serialize_public)).
* De-serializing a PSO library from persistent storage (this is handled by **CreatePipelineLibrary**).
* Retrieving individual PSOs from the library (refer to [LoadComputePipeline](/reference/graphics/d3d12/interfaces/id3d12pipelinelibrary/methods/id3d12pipelinelibrary_loadcomputepipeline_public) and [LoadGraphicsPipeline](/reference/graphics/d3d12/interfaces/id3d12pipelinelibrary/methods/id3d12pipelinelibrary_loadgraphicspipeline_public)).

At no point in the lifecycle of a pipeline library is there duplication between PSOs with identical sub-components.

A recommended solution for managing the lifetime of the provided pointer while only having to ref-count the returned interface is to leverage [ID3D12Object::SetPrivateDataInterface](/reference/graphics/d3d12/interfaces/id3d12object/methods/id3d12object_setprivatedatainterface_public), and use an object which implements **IUnknown**, and frees the memory when the ref-count reaches 0.

### Thread Safety

The pipeline library is thread-safe to use, and will internally synchronize as necessary, with one exception: multiple threads loading the same PSO (via [**LoadComputePipeline**](/reference/graphics/d3d12/interfaces/id3d12pipelinelibrary/methods/id3d12pipelinelibrary_loadcomputepipeline_public), [**LoadGraphicsPipeline**](/reference/graphics/d3d12/interfaces/id3d12pipelinelibrary/methods/id3d12pipelinelibrary_loadgraphicspipeline_public), or [**LoadPipeline**](/reference/graphics/d3d12/interfaces/id3d12pipelinelibrary1/methods/id3d12pipelinelibrary1_loadpipeline_public)) should synchronize themselves, as this act may modify the state of that pipeline within the library in a non-thread-safe manner.

## Examples

See the [Direct3D 12 pipeline state cache sample](https://github.com/microsoft/DirectX-Graphics-Samples/tree/master/Samples/Desktop/D3D12PipelineStateCache).

## Requirements

**Header:** d3d12\_xs.h or d3d12\_x.h<br />**Library:** d3d12\_xs.lib or d3d12\_x.lib<br />**Supported Platforms**: XBOX Series consoles and XBOX One family

## See Also

* [ID3D12Device1](/reference/graphics/d3d12/interfaces/id3d12device1/id3d12device1_public)
* [Direct3D 12 pipeline state cache sample](https://github.com/microsoft/DirectX-Graphics-Samples/tree/master/Samples/Desktop/D3D12PipelineStateCache)


## Related topics

- [ID3D12PipelineLibrary](/reference/graphics/d3d12/interfaces/id3d12pipelinelibrary/id3d12pipelinelibrary_public.md)
- [StorePipeline](/reference/graphics/d3d12/interfaces/id3d12pipelinelibrary/methods/id3d12pipelinelibrary_storepipeline_public.md)
- [LoadComputePipeline](/reference/graphics/d3d12/interfaces/id3d12pipelinelibrary/methods/id3d12pipelinelibrary_loadcomputepipeline_public.md)
- [LoadGraphicsPipeline](/reference/graphics/d3d12/interfaces/id3d12pipelinelibrary/methods/id3d12pipelinelibrary_loadgraphicspipeline_public.md)
- [GetSerializedSize](/reference/graphics/d3d12/interfaces/id3d12pipelinelibrary/methods/id3d12pipelinelibrary_getserializedsize_public.md)
