# Juliet\src\Graphics\D3D12\D3D12GraphicsPipeline

## Source Files
- Header: `Juliet\src\Graphics\D3D12\D3D12GraphicsPipeline.h`
- Source: `Juliet\src\Graphics\D3D12\D3D12GraphicsPipeline.cpp`

## AI Description
The provided code snippet is a part of a graphics rendering system, specifically for creating and managing graphics pipelines in a DirectX 12 environment. The `CreateGraphicsPipeline` function takes a `GPUDriver` object and a `GraphicsPipelineCreateInfo` structure as input parameters and returns a pointer to the created `GraphicsPipeline`. This pipeline is responsible for handling vertex and fragment shaders, rasterization, blending, depth/stencil operations, and other rendering states.

Here's a breakdown of the key components and functionalities:

1. **Shader Conversion**: The function converts the provided vertex and fragment shaders from their Juliet shader format to DirectX 12 shader bytecode. This involves copying the shader data and patching it back after overwriting the bytecode if necessary.

2. **Rasterizer State**: The rasterizer state is converted from a `GraphicsPipelineCreateInfo` structure to a `D3D12_RASTERIZER_DESC`. This includes settings such as line width, fill mode, depth testing, stencil testing, etc.

3. **Blend State**: Similar to the rasterizer state, the blend state is converted from a `GraphicsPipelineCreateInfo` structure to a `D3D12_BLEND_STATE`. This involves setting up blending factors, operations, and write masks for different color channels.

4. **Depth Stencil State**: The depth stencil state is also converted from a `GraphicsPipelineCreateInfo` structure to a `D3D12_DEPTH_STENCIL_DESC`. This includes settings such as depth enable, write mask, depth function, stencil enable, stencil read/write masks, and stencil operations.

5. **Pipeline Creation**: After converting all the necessary states, the pipeline state is created using the DirectX 12 device's `CreateGraphicsPipelineState` method. The resulting pipeline state is stored in the `GraphicsPipeline` object.

6. **Vertex Strides**: The function also sets up vertex strides for each vertex buffer description in the `GraphicsPipelineCreateInfo`. This helps in determining how much data to read from each vertex buffer when rendering.

7. **Primitive Type**: The primitive type of the pipeline is set based on the provided `GraphicsPipelineCreateInfo`.

8. **Root Signature**: The root signature is bound to the pipeline using the `BindlessRootSignature` object, which likely contains the necessary shader resources and parameters.

9. **Memory Management**: The function handles memory allocation for the `GraphicsPipeline` object and its associated resources such as shaders, vertex buffers, and render targets.

This code snippet is crucial for setting up the rendering pipeline in a DirectX 12 application, ensuring that the graphics are rendered correctly according to the specified requirements.

## Symbols

### Namespace `Juliet::D3D12`

#### Classes, Structs & Unions
- `struct D3D12GraphicsRootSignature`
- `struct D3D12GraphicsPipeline`

#### Functions & Methods
- `extern GraphicsPipeline* CreateGraphicsPipeline(NonNullPtr<GPUDriver> driver, const GraphicsPipelineCreateInfo& createInfo)`
- `extern void DestroyGraphicsPipeline(NonNullPtr<GPUDriver> driver, NonNullPtr<GraphicsPipeline> graphicsPipeline)`
- `extern bool UpdateGraphicsPipelineShaders(NonNullPtr<GPUDriver> driver, NonNullPtr<GraphicsPipeline> graphicsPipeline,
                                              Shader* optional_vertexShader, Shader* optional_fragmentShader)`

### Namespace `Juliet::D3D12::Internal`

#### Functions & Methods
- `extern void ReleaseGraphicsPipeline(NonNullPtr<D3D12GraphicsPipeline> d3d12GraphicsPipeline)`

