Files
Juliet/Romeo/docs/Juliet_src_Graphics_D3D12_D3D12SwapChain.md

81 lines
3.9 KiB
Markdown

# Juliet\src\Graphics\D3D12\D3D12SwapChain
## Source Files
- Header: `Juliet\src\Graphics\D3D12\D3D12SwapChain.h`
- Source: `Juliet\src\Graphics\D3D12\D3D12SwapChain.cpp`
## AI Description
This code snippet is a part of a graphics driver for the Juliet operating system, specifically designed to handle DirectX 12 graphics. It includes functions for creating and managing swapchains, as well as acquiring and releasing textures from these swapchains.
Here's a breakdown of what each function does:
### `AcquireSwapChainTexture`
This function is responsible for acquiring a texture from the swapchain. It takes a command list, a window, and a pointer to a texture pointer. The function first checks if there are any pending fences that need to be waited on before acquiring the texture. If so, it waits for those fences.
Then, it creates a presentation barrier to transition the resource state from `D3D12_RESOURCE_STATE_PRESENT` to `D3D12_RESOURCE_STATE_RENDER_TARGET`. After setting up the barrier, it retrieves the swapchain texture container and acquires the active texture.
Finally, it returns the acquired texture pointer.
### `WaitAndAcquireSwapChainTexture`
This function is similar to `AcquireSwapChainTexture`, but it waits for a fence before acquiring the texture. This can be useful in scenarios where you need to ensure that certain operations are completed before proceeding with rendering.
### `WaitForSwapchain`
This function waits for the current frame to complete by checking if there are any pending fences. It then returns true if the wait was successful, otherwise false.
### `GetSwapChainTextureFormat`
This function retrieves the format of the swapchain texture based on the specified composition and present mode.
### `Internal::CreateSwapChain`
This is a private helper function that creates a swapchain for a given window and composition. It initializes the swapchain descriptor, queries the parent factory to make the window association, and then creates the swapchain object.
### `Internal::DestroySwapChain`
This is another private helper function that destroys the swapchain and frees all associated resources.
### Usage
To use this code, you would typically create a `D3D12Driver` object and pass it to the functions. You would also need to handle the window state and synchronization mechanisms for your application.
```cpp
// Create a D3D12 driver instance
auto driver = new Juliet::D3D12Driver();
// Create a swapchain for a window
NonNullPtr?Window? window = ...; // Initialize your window object
SwapChainComposition composition = SwapChainComposition::SDR;
PresentMode presentMode = PresentMode::FIFO;
if (!Internal::CreateSwapChain(driver, windowData, composition, presentMode))
{
LogError(LogCategory::Graphics, "Failed to create swapchain");
}
// Acquire a texture from the swapchain
NonNullPtr?CommandList? commandList = ...; // Initialize your command list object
Texture* swapChainTexture;
if (!AcquireSwapChainTexture(commandList, window, ?swapChainTexture))
{
LogError(LogCategory::Graphics, "Failed
## Symbols
### Namespace `Juliet::D3D12`
#### Functions & Methods
- `extern bool AcquireSwapChainTexture(NonNullPtr<CommandList> commandList, NonNullPtr<Window> window, Texture** swapChainTexture)`
- `extern bool WaitAndAcquireSwapChainTexture(NonNullPtr<CommandList> commandList, NonNullPtr<Window> window, Texture** swapChainTexture)`
- `extern bool WaitForSwapchain(NonNullPtr<GPUDriver> driver, NonNullPtr<Window> window)`
- `extern TextureFormat GetSwapChainTextureFormat(NonNullPtr<GPUDriver> driver, NonNullPtr<Window> window)`
### Namespace `Juliet::D3D12::Internal`
#### Functions & Methods
- `extern bool CreateSwapChain(NonNullPtr<D3D12Driver> driver, NonNullPtr<D3D12WindowData> windowData,
SwapChainComposition composition, PresentMode presentMode)`
- `extern void DestroySwapChain(NonNullPtr<D3D12Driver> driver, NonNullPtr<D3D12WindowData> windowData)`