Files
Juliet/Romeo/docs/Juliet_src_Graphics_D3D12_D3D12Texture.md

5.6 KiB

Juliet\src\Graphics\D3D12\D3D12Texture

Source Files

  • Header: Juliet\src\Graphics\D3D12\D3D12Texture.h
  • Source: Juliet\src\Graphics\D3D12\D3D12Texture.cpp

AI Description

It looks like you're working with a graphics library that handles DirectX 12 resources, specifically textures. The code snippet provided is part of a class TextureManager within this library, which manages the creation and management of textures in a game engine.

Here's a breakdown of what the code does:

Texture Management

  1. Texture Formats:

    • The JulietToD3D12_DepthFormat array maps Juliet texture formats to their corresponding D3D12 depth formats.
    • The ComputeSubresourceIndex function calculates the index of a subresource within a texture.
  2. Resource States:

    • The GetDefaultTextureResourceState function determines the default resource state based on the usage flags of the texture.
    • The PrepareTextureSubresourceForWrite function prepares a texture subresource for writing by transitioning it from its default state to the new specified state.
  3. Fetching Subresources:

    • The FetchTextureSubresource function retrieves a specific subresource from a texture container.
  4. Resource Barriers:

    • The TextureSubresourceBarrier function applies a resource barrier to transition between different resource states.
    • The TextureSubresourceTransitionFromDefaultUsage and TextureSubresourceTransitionToDefaultUsage functions handle the transition of individual subresources or entire textures from their default state.

Usage

  • Prepare Texture Subresource for Write: This function prepares a texture subresource for writing by transitioning it to the specified usage state.
  • Fetch Texture Subresource: This function retrieves a specific subresource from a texture container.
  • Texture Subresource Barrier: This function applies a resource barrier to transition between different resource states.

Example Usage

Here's an example of how you might use these functions in a game engine:

NonNullPtr?D3D12CommandList? commandList = ...; // Get the command list
NonNullPtr?D3D12TextureContainer? container = ...; // Get the texture container

// Prepare a texture subresource for writing
NonNullPtr?D3D12TextureSubresource? subresource = Internal::PrepareTextureSubresourceForWrite(commandList, container, 0, 0, true, D3D12_RESOURCE_STATE_RENDER_TARGET);

// Fetch a specific subresource from the texture container
NonNullPtr?D3D12TextureSubresource? fetchedSubresource = Internal::FetchTextureSubresource(container, 0, 0);

// Apply a resource barrier to transition the subresource to render target state
Internal::TextureSubresourceBarrier(commandList, D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_UNORDERED_ACCESS, fetchedSubresource);

This code snippet demonstrates how to prepare and manage texture resources in a game engine using DirectX 12.

Symbols

Namespace Juliet::D3D12

Classes, Structs & Unions

  • struct D3D12TextureContainer
  • struct D3D12TextureSubresource
  • struct D3D12Texture

Functions & Methods

  • `// namespace Internal

    extern Texture* CreateTexture(NonNullPtr driver, const TextureCreateInfo& createInfo)`

  • extern void DestroyTexture(NonNullPtr<GPUDriver> driver, NonNullPtr<Texture> texture)

Namespace Juliet::D3D12::Internal

Functions & Methods

  • extern D3D12TextureSubresource* PrepareTextureSubresourceForWrite(NonNullPtr<D3D12CommandList>, NonNullPtr<D3D12TextureContainer> container, uint32 layer, uint32 level, bool shouldCycle, D3D12_RESOURCE_STATES newTextureUsage)
  • extern D3D12TextureSubresource* FetchTextureSubresource(NonNullPtr<D3D12TextureContainer> container, uint32 layer, uint32 level)
  • extern void TextureSubresourceBarrier(NonNullPtr<D3D12CommandList> commandList, D3D12_RESOURCE_STATES sourceState, D3D12_RESOURCE_STATES destinationState, NonNullPtr<D3D12TextureSubresource> textureSubresource)
  • // Texture usage transition extern void TextureSubresourceTransitionFromDefaultUsage(NonNullPtr<D3D12CommandList> commandList, NonNullPtr<D3D12TextureSubresource> subresource, D3D12_RESOURCE_STATES toTextureUsage)
  • extern void TextureTransitionFromDefaultUsage(NonNullPtr<D3D12CommandList> commandList, NonNullPtr<D3D12Texture> texture, D3D12_RESOURCE_STATES toTextureUsage)
  • extern void TextureSubresourceTransitionToDefaultUsage(NonNullPtr<D3D12CommandList> commandList, NonNullPtr<D3D12TextureSubresource> subresource, D3D12_RESOURCE_STATES fromTextureUsage)
  • extern void TextureTransitionToDefaultUsage(NonNullPtr<D3D12CommandList> commandList, NonNullPtr<D3D12Texture> texture, D3D12_RESOURCE_STATES fromTextureUsage)
  • // Utils extern DXGI_FORMAT ConvertToD3D12TextureFormat(TextureFormat format)
  • extern DXGI_FORMAT ConvertToD3D12DepthFormat(TextureFormat format)