### Initialize Index Buffer View Example Source: https://learn.microsoft.com/en-us/windows/win32/direct3d12/creating-descriptors Example of initializing a D3D12_INDEX_BUFFER_VIEW structure with buffer location, size, and format. Ensure the buffer and its properties are correctly set up before this step. ```c++ // Initialize the index buffer view. m_indexBufferView.BufferLocation = m_indexBuffer->GetGPUVirtualAddress(); m_indexBufferView.SizeInBytes = SampleAssets::IndexDataSize; m_indexBufferView.Format = SampleAssets::StandardIndexFormat; ``` -------------------------------- ### Create Sampler Example Source: https://learn.microsoft.com/en-us/windows/win32/direct3d12/creating-descriptors Example of creating a sampler using D3D12_SAMPLER_DESC and ID3D12Device::CreateSampler. Refer to Direct3D 12 enums for valid filter and address mode settings. ```c++ // Describe and create a sampler. D3D12_SAMPLER_DESC samplerDesc = {}; samplerDesc.Filter = D3D12_FILTER_MIN_MAG_MIP_LINEAR; samplerDesc.AddressU = D3D12_TEXTURE_ADDRESS_MODE_WRAP; samplerDesc.AddressV = D3D12_TEXTURE_ADDRESS_MODE_WRAP; samplerDesc.AddressW = D3D12_TEXTURE_ADDRESS_MODE_WRAP; samplerDesc.MinLOD = 0; samplerDesc.MaxLOD = D3D12_FLOAT32_MAX; samplerDesc.MipLODBias = 0.0f; samplerDesc.MaxAnisotropy = 1; samplerDesc.ComparisonFunc = D3D12_COMPARISON_FUNC_ALWAYS; m_device->CreateSampler(&samplerDesc, m_samplerHeap->GetCPUDescriptorHandleForHeapStart()); ``` -------------------------------- ### Initialize CD3DX12_PACKED_MIP_INFO Source: https://learn.microsoft.com/en-us/windows/win32/direct3d12/cd3dx12-packed-mip-info Use this constructor to create a CD3DX12_PACKED_MIP_INFO with specific values for standard mips, packed mips, tiles for packed mips, and the starting tile index. ```cpp CD3DX12_PACKED_MIP_INFO(UINT8 numStandardMips, UINT8 numPackedMips, UINT numTilesForPackedMips, UINT startTileIndexInOverallResource); ``` -------------------------------- ### CD3DX12_CPU_DESCRIPTOR_HANDLE Constructor Example Source: https://learn.microsoft.com/en-us/windows/win32/direct3d12/cd3dx12-default This C++ code shows an example constructor for CD3DX12_CPU_DESCRIPTOR_HANDLE that accepts CD3DX12_DEFAULT. Passing D3D12_DEFAULT to this constructor initializes the handle's pointer to 0. ```cpp CD3DX12_CPU_DESCRIPTOR_HANDLE(CD3DX12_DEFAULT) { ptr = 0; } ``` -------------------------------- ### Create Constant Buffer View Example Source: https://learn.microsoft.com/en-us/windows/win32/direct3d12/creating-descriptors Example of creating a constant buffer view using D3D12_CONSTANT_BUFFER_VIEW_DESC and ID3D12Device::CreateConstantBufferView. Ensure the constant buffer size is 256-byte aligned. ```c++ // Describe and create a constant buffer view. D3D12_CONSTANT_BUFFER_VIEW_DESC cbvDesc = {}; cbvDesc.BufferLocation = m_constantBuffer->GetGPUVirtualAddress(); cbvDesc.SizeInBytes = (sizeof(ConstantBuffer) + 255) & ~255; // CB size is required to be 256-byte aligned. m_device->CreateConstantBufferView(&cbvDesc, m_cbvHeap->GetCPUDescriptorHandleForHeapStart()); ``` -------------------------------- ### CD3DX12_STATIC_SAMPLER_DESC Constructors and Initialization Source: https://learn.microsoft.com/en-us/windows/win32/direct3d12/cd3dx12-static-sampler-desc Provides constructors and initialization methods for the CD3DX12_STATIC_SAMPLER_DESC structure, allowing for easy setup of static sampler descriptions. ```APIDOC ## CD3DX12_STATIC_SAMPLER_DESC A helper structure to enable easy initialization of a **D3D12_STATIC_SAMPLER_DESC** structure. ### Syntax ```cpp struct CD3DX12_STATIC_SAMPLER_DESC : public D3D12_STATIC_SAMPLER_DESC{ CD3DX12_STATIC_SAMPLER_DESC(); explicit CD3DX12_STATIC_SAMPLER_DESC(const D3D12_STATIC_SAMPLER_DESC &o); CD3DX12_STATIC_SAMPLER_DESC(UINT shaderRegister, D3D12_FILTER filter = D3D12_FILTER_ANISOTROPIC, D3D12_TEXTURE_ADDRESS_MODE addressU = D3D12_TEXTURE_ADDRESS_MODE_WRAP, D3D12_TEXTURE_ADDRESS_MODE addressV = D3D12_TEXTURE_ADDRESS_MODE_WRAP, D3D12_TEXTURE_ADDRESS_MODE addressW = D3D12_TEXTURE_ADDRESS_MODE_WRAP, FLOAT mipLODBias = 0, UINT maxAnisotropy = 16, D3D12_COMPARISON_FUNC comparisonFunc = D3D12_COMPARISON_FUNC_LESS_EQUAL, D3D12_STATIC_BORDER_COLOR borderColor = D3D12_STATIC_BORDER_COLOR_OPAQUE_WHITE, FLOAT minLOD = 0.f, FLOAT maxLOD = D3D12_FLOAT32_MAX, D3D12_SHADER_VISIBILITY shaderVisibility = D3D12_SHADER_VISIBILITY_ALL, UINT registerSpace = 0); void static inline Init(D3D12_STATIC_SAMPLER_DESC &samplerDesc, UINT shaderRegister, D3D12_FILTER filter = D3D12_FILTER_ANISOTROPIC, D3D12_TEXTURE_ADDRESS_MODE addressU = D3D12_TEXTURE_ADDRESS_MODE_WRAP, D3D12_TEXTURE_ADDRESS_MODE addressV = D3D12_TEXTURE_ADDRESS_MODE_WRAP, D3D12_TEXTURE_ADDRESS_MODE addressW = D3D12_TEXTURE_ADDRESS_MODE_WRAP, FLOAT mipLODBias = 0, UINT maxAnisotropy = 16, D3D12_COMPARISON_FUNC comparisonFunc = D3D12_COMPARISON_FUNC_LESS_EQUAL, D3D12_STATIC_BORDER_COLOR borderColor = D3D12_STATIC_BORDER_COLOR_OPAQUE_WHITE, FLOAT minLOD = 0.f, FLOAT maxLOD = D3D12_FLOAT32_MAX, D3D12_SHADER_VISIBILITY shaderVisibility = D3D12_SHADER_VISIBILITY_ALL, UINT registerSpace = 0); void inline Init(UINT shaderRegister, D3D12_FILTER filter = D3D12_FILTER_ANISOTROPIC, D3D12_TEXTURE_ADDRESS_MODE addressU = D3D12_TEXTURE_ADDRESS_MODE_WRAP, D3D12_TEXTURE_ADDRESS_MODE addressV = D3D12_TEXTURE_ADDRESS_MODE_WRAP, D3D12_TEXTURE_ADDRESS_MODE addressW = D3D12_TEXTURE_ADDRESS_MODE_WRAP, FLOAT mipLODBias = 0, UINT maxAnisotropy = 16, D3D12_COMPARISON_FUNC comparisonFunc = D3D12_COMPARISON_FUNC_LESS_EQUAL, D3D12_STATIC_BORDER_COLOR borderColor = D3D12_STATIC_BORDER_COLOR_OPAQUE_WHITE, FLOAT minLOD = 0.f, FLOAT maxLOD = D3D12_FLOAT32_MAX, D3D12_SHADER_VISIBILITY shaderVisibility = D3D12_SHADER_VISIBILITY_ALL, UINT registerSpace = 0); }; ``` ### Constructors * **CD3DX12_STATIC_SAMPLER_DESC()** Default constructor. * **explicit CD3DX12_STATIC_SAMPLER_DESC(const D3D12_STATIC_SAMPLER_DESC &o)** Copy constructor. * **CD3DX12_STATIC_SAMPLER_DESC(UINT shaderRegister, D3D12_FILTER filter = D3D12_FILTER_ANISOTROPIC, D3D12_TEXTURE_ADDRESS_MODE addressU = D3D12_TEXTURE_ADDRESS_MODE_WRAP, D3D12_TEXTURE_ADDRESS_MODE addressV = D3D12_TEXTURE_ADDRESS_MODE_WRAP, D3D12_TEXTURE_ADDRESS_MODE addressW = D3D12_TEXTURE_ADDRESS_MODE_WRAP, FLOAT mipLODBias = 0, UINT maxAnisotropy = 16, D3D12_COMPARISON_FUNC comparisonFunc = D3D12_COMPARISON_FUNC_LESS_EQUAL, D3D12_STATIC_BORDER_COLOR borderColor = D3D12_STATIC_BORDER_COLOR_OPAQUE_WHITE, FLOAT minLOD = 0.f, FLOAT maxLOD = D3D12_FLOAT32_MAX, D3D12_SHADER_VISIBILITY shaderVisibility = D3D12_SHADER_VISIBILITY_ALL, UINT registerSpace = 0)** Constructor that initializes the sampler with specified parameters. ### Initialization Methods * **void static inline Init(D3D12_STATIC_SAMPLER_DESC &samplerDesc, UINT shaderRegister, D3D12_FILTER filter = D3D12_FILTER_ANISOTROPIC, D3D12_TEXTURE_ADDRESS_MODE addressU = D3D12_TEXTURE_ADDRESS_MODE_WRAP, D3D12_TEXTURE_ADDRESS_MODE addressV = D3D12_TEXTURE_ADDRESS_MODE_WRAP, D3D12_TEXTURE_ADDRESS_MODE addressW = D3D12_TEXTURE_ADDRESS_MODE_WRAP, FLOAT mipLODBias = 0, UINT maxAnisotropy = 16, D3D12_COMPARISON_FUNC comparisonFunc = D3D12_COMPARISON_FUNC_LESS_EQUAL, D3D12_STATIC_BORDER_COLOR borderColor = D3D12_STATIC_BORDER_COLOR_OPAQUE_WHITE, FLOAT minLOD = 0.f, FLOAT maxLOD = D3D12_FLOAT32_MAX, D3D12_SHADER_VISIBILITY shaderVisibility = D3D12_SHADER_VISIBILITY_ALL, UINT registerSpace = 0)** Static method to initialize a given **D3D12_STATIC_SAMPLER_DESC** structure. * **void inline Init(UINT shaderRegister, D3D12_FILTER filter = D3D12_FILTER_ANISOTROPIC, D3D12_TEXTURE_ADDRESS_MODE addressU = D3D12_TEXTURE_ADDRESS_MODE_WRAP, D3D12_TEXTURE_ADDRESS_MODE addressV = D3D12_TEXTURE_ADDRESS_MODE_WRAP, D3D12_TEXTURE_ADDRESS_MODE addressW = D3D12_TEXTURE_ADDRESS_MODE_WRAP, FLOAT mipLODBias = 0, UINT maxAnisotropy = 16, D3D12_COMPARISON_FUNC comparisonFunc = D3D12_COMPARISON_FUNC_LESS_EQUAL, D3D12_STATIC_BORDER_COLOR borderColor = D3D12_STATIC_BORDER_COLOR_OPAQUE_WHITE, FLOAT minLOD = 0.f, FLOAT maxLOD = D3D12_FLOAT32_MAX, D3D12_SHADER_VISIBILITY shaderVisibility = D3D12_SHADER_VISIBILITY_ALL, UINT registerSpace = 0)** Inline method to initialize the **CD3DX12_STATIC_SAMPLER_DESC** structure. ### Parameters * **shaderRegister** (UINT) - The shader register to bind the sampler to. * **filter** (D3D12_FILTER) - The filtering method to use. Defaults to **D3D12_FILTER_ANISOTROPIC**. * **addressU** (D3D12_TEXTURE_ADDRESS_MODE) - The texture address mode for the U coordinate. Defaults to **D3D12_TEXTURE_ADDRESS_MODE_WRAP**. * **addressV** (D3D12_TEXTURE_ADDRESS_MODE) - The texture address mode for the V coordinate. Defaults to **D3D12_TEXTURE_ADDRESS_MODE_WRAP**. * **addressW** (D3D12_TEXTURE_ADDRESS_MODE) - The texture address mode for the W coordinate. Defaults to **D3D12_TEXTURE_ADDRESS_MODE_WRAP**. * **mipLODBias** (FLOAT) - The mipmap level-of-detail bias. Defaults to 0. * **maxAnisotropy** (UINT) - The maximum anisotropy for anisotropic filtering. Defaults to 16. * **comparisonFunc** (D3D12_COMPARISON_FUNC) - The comparison function for depth or stencil testing. Defaults to **D3D12_COMPARISON_FUNC_LESS_EQUAL**. * **borderColor** (D3D12_STATIC_BORDER_COLOR) - The border color for texture sampling. Defaults to **D3D12_STATIC_BORDER_COLOR_OPAQUE_WHITE**. * **minLOD** (FLOAT) - The minimum level of detail. Defaults to 0.f. * **maxLOD** (FLOAT) - The maximum level of detail. Defaults to **D3D12_FLOAT32_MAX**. * **shaderVisibility** (D3D12_SHADER_VISIBILITY) - The shader stages that can access this sampler. Defaults to **D3D12_SHADER_VISIBILITY_ALL**. * **registerSpace** (UINT) - The register space. Defaults to 0. * **o** (const D3D12_STATIC_SAMPLER_DESC &) - The **D3D12_STATIC_SAMPLER_DESC** structure to copy from. ``` -------------------------------- ### Create Depth Stencil View Example Source: https://learn.microsoft.com/en-us/windows/win32/direct3d12/creating-descriptors This example demonstrates how to create a depth stencil view using Direct3D 12. It initializes the D3D12_DEPTH_STENCIL_VIEW_DESC structure and uses ID3D12Device::CreateCommittedResource and ID3D12Device::CreateDepthStencilView. ```c++ // Create the depth stencil view. { D3D12_DEPTH_STENCIL_VIEW_DESC depthStencilDesc = {}; depthStencilDesc.Format = DXGI_FORMAT_D32_FLOAT; depthStencilDesc.ViewDimension = D3D12_DSV_DIMENSION_TEXTURE2D; depthStencilDesc.Flags = D3D12_DSV_FLAG_NONE; D3D12_CLEAR_VALUE depthOptimizedClearValue = {}; depthOptimizedClearValue.Format = DXGI_FORMAT_D32_FLOAT; depthOptimizedClearValue.DepthStencil.Depth = 1.0f; depthOptimizedClearValue.DepthStencil.Stencil = 0; ThrowIfFailed(m_device->CreateCommittedResource( &CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_DEFAULT), D3D12_HEAP_FLAG_NONE, &CD3DX12_RESOURCE_DESC::Tex2D(DXGI_FORMAT_D32_FLOAT, m_width, m_height, 1, 0, 1, 0, D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL), D3D12_RESOURCE_STATE_DEPTH_WRITE, &depthOptimizedClearValue, IID_PPV_ARGS(&m_depthStencil) )); m_device->CreateDepthStencilView(m_depthStencil.Get(), &depthStencilDesc, m_dsvHeap->GetCPUDescriptorHandleForHeapStart()); } ``` -------------------------------- ### Setup 3D Tiled Resource (Most Detailed Mip) - Direct3D 12 Source: https://learn.microsoft.com/en-us/windows/win32/direct3d12/volume-tiled-resources Sets up a 3D tiled resource at its most detailed mip level. Ensure D3D12_TILED_RESOURCES_TIER is supported. ```cpp D3D12_TILED_RESOURCE_COORDINATE trCoord{}; trCoord.X = 1; trCoord.Y = 0; trCoord.Z = 0; trCoord.Subresource = 0; D3D12_TILE_REGION_SIZE trSize{}; trSize.bUseBox = false; trSize.NumTiles = 63; ``` -------------------------------- ### Initialize Vertex Buffer View Source: https://learn.microsoft.com/en-us/windows/win32/direct3d12/creating-descriptors Example of initializing a D3D12_VERTEX_BUFFER_VIEW structure. Ensure the BufferLocation is obtained via GetGPUVirtualAddress, SizeInBytes matches the buffer's data size, and StrideInBytes is the size of a single vertex. ```c++ // Initialize the vertex buffer view. m_vertexBufferView.BufferLocation = m_vertexBuffer->GetGPUVirtualAddress(); m_vertexBufferView.SizeInBytes = SampleAssets::VertexDataSize; m_vertexBufferView.StrideInBytes = SampleAssets::StandardVertexStride; ``` -------------------------------- ### Setup 3D Tiled Resource (Uniform Box) - Direct3D 12 Source: https://learn.microsoft.com/en-us/windows/win32/direct3d12/volume-tiled-resources Configures a 3D tiled resource as a uniform box. The `bUseBox` flag must be set to true for this configuration. ```cpp D3D12_TILED_RESOURCE_COORDINATE trCoord; trCoord.X = 0; trCoord.Y = 1; trCoord.Z = 0; trCoord.Subresource = 0; D3D12_TILE_REGION_SIZE trSize; trSize.bUseBox = true; trSize.NumTiles = 27; trSize.Width = 3; trSize.Height = 3; trSize.Depth = 3; ``` -------------------------------- ### Setup 3D Tiled Resource (Second Most Detailed Mip) - Direct3D 12 Source: https://learn.microsoft.com/en-us/windows/win32/direct3d12/volume-tiled-resources Configures a 3D tiled resource for its second most detailed mip level. Requires Direct3D 12 support for tiled resources. ```cpp D3D12_TILED_RESOURCE_COORDINATE trCoord; trCoord.X = 1; trCoord.Y = 0; trCoord.Z = 0; trCoord.Subresource = 1; D3D12_TILE_REGION_SIZE trSize; trSize.bUseBox = false; trSize.NumTiles = 6; ``` -------------------------------- ### Setup 3D Tiled Resource (Single Tile) - Direct3D 12 Source: https://learn.microsoft.com/en-us/windows/win32/direct3d12/volume-tiled-resources Initializes a 3D tiled resource to occupy a single tile. This configuration is useful for specific, localized texture data. ```cpp D3D12_TILED_RESOURCE_COORDINATE trCoord; trCoord.X = 1; trCoord.Y = 1; trCoord.Z = 1; trCoord.Subresource = 0; D3D12_TILE_REGION_SIZE trSize; trSize.bUseBox = true; trSize.NumTiles = 27; trSize.Width = 3; trSize.Height = 3; trSize.Depth = 3; ``` -------------------------------- ### Example Root-Level UAV (HLSL) Source: https://learn.microsoft.com/en-us/windows/win32/direct3d12/specifying-root-signatures-in-hlsl A simple example of specifying a root-level UAV. ```hlsl UAV(u3) ``` -------------------------------- ### Command List and Bundle Execution Flow Source: https://learn.microsoft.com/en-us/windows/win32/direct3d12/using-a-root-signature Demonstrates how a command list sets up root signature bindings and then executes a bundle, which may inherit or modify these bindings. ```cpp // Command List ... pCmdList->SetGraphicsRootSignature(pRootSig); // new parameter space MyEngine_SetTextures(); // bundle inherits descriptor table setting MyEngine_SetAnimationFactor(fTime); // bundle inherits root constant pCmdList->ExecuteBundle(...); ... // Bundle pBundle->SetGraphicsRootSignature(pRootSig); // same as caller, in order to inherits bindings pBundle->SetPipelineState(pPS); pBundle->SetGraphicsRoot32BitConstant(drawConstantsSlot,0,drawIDOffset); pBundle->Draw(...); // using inherited textures / animation factor pBundle->SetGraphicsRoot32BitConstant(drawConstantsSlot,1,drawIDOffset); pBundle->Draw(...); ... ``` -------------------------------- ### HLSL Static Sampler Example Source: https://learn.microsoft.com/en-us/windows/win32/direct3d12/specifying-root-signatures-in-hlsl An example of defining a static sampler with a specific filter. ```hlsl StaticSampler(s4, filter=FILTER_MIN_MAG_MIP_LINEAR) ``` -------------------------------- ### Example Descriptor Table with CBV and SRV (HLSL) Source: https://learn.microsoft.com/en-us/windows/win32/direct3d12/specifying-root-signatures-in-hlsl An example of a descriptor table containing a CBV and an SRV with an unbounded number of descriptors. ```hlsl DescriptorTable(CBV(b0),SRV(t3, numDescriptors=unbounded)) ``` -------------------------------- ### Create Render Target View Descriptor Heap and Frame Resources Source: https://learn.microsoft.com/en-us/windows/win32/direct3d12/creating-descriptors Example demonstrating the creation of a render target view (RTV) descriptor heap and then creating an RTV for each frame in the swap chain. Requires a D3D12 device and swap chain. ```cpp // Create descriptor heaps. { // Describe and create a render target view (RTV) descriptor heap. D3D12_DESCRIPTOR_HEAP_DESC rtvHeapDesc = {}; rtvHeapDesc.NumDescriptors = FrameCount; rtvHeapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_RTV; rtvHeapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_NONE; ThrowIfFailed(m_device->CreateDescriptorHeap(&rtvHeapDesc, IID_PPV_ARGS(&m_rtvHeap))); m_rtvDescriptorSize = m_device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_RTV); } // Create frame resources. { CD3DX12_CPU_DESCRIPTOR_HANDLE rtvHandle(m_rtvHeap->GetCPUDescriptorHandleForHeapStart()); // Create a RTV for each frame. for (UINT n = 0; n < FrameCount; n++) { ThrowIfFailed(m_swapChain->GetBuffer(n, IID_PPV_ARGS(&m_renderTargets[n]))); m_device->CreateRenderTargetView(m_renderTargets[n].Get(), nullptr, rtvHandle); rtvHandle.Offset(1, m_rtvDescriptorSize); } } ``` -------------------------------- ### Typed UAV Load Example Source: https://learn.microsoft.com/en-us/windows/win32/direct3d12/typed-unordered-access-view-loads Example HLSL shader code demonstrating a typed UAV load operation. This requires the D3D_SHADER_REQUIRES_TYPED_UAV_LOAD_ADDITIONAL_FORMATS flag. ```hlsl RWTexture2D uav1; uint2 coord; float4 main() : SV_Target { return uav1.Load(coord); } ``` -------------------------------- ### Default Initialization of CD3DX12_ROOT_SIGNATURE_DESC Source: https://learn.microsoft.com/en-us/windows/win32/direct3d12/cd3dx12-root-signature-desc Demonstrates initializing a CD3DX12_ROOT_SIGNATURE_DESC with default parameters. This is useful for creating a basic root signature when no specific parameters are needed initially. ```cpp CD3DX12_ROOT_SIGNATURE_DESC(0,NULL,0,NULL,D3D12_ROOT_SIGNATURE_FLAG_NONE) ``` -------------------------------- ### Creating and Configuring a State Object Collection Source: https://learn.microsoft.com/en-us/windows/win32/direct3d12/cd3dx12-state-object-desc Demonstrates how to instantiate a CD3DX12_STATE_OBJECT_DESC for a collection and use CreateSubobject to add a DXIL library, defining specific exports. ```cpp CD3DX12_STATE_OBJECT_DESC Collection1(D3D12_STATE_OBJECT_TYPE_COLLECTION); auto Lib0 = Collection1.CreateSubobject(); Lib0->SetDXILLibrary(&pMyAppDxilLibs[0]); Lib0->DefineExport(L"rayGenShader0"); // In practice, these export listings might be data/engine-driven. ... ``` -------------------------------- ### Initialize Frame Resource and Transition Back Buffer Source: https://learn.microsoft.com/en-us/windows/win32/direct3d12/using-resource-barriers-to-synchronize-resource-states-in-direct3d-12 This snippet demonstrates initializing a frame resource and using a resource barrier to transition the back buffer from the present state to the render target state for rendering. It also includes clearing the render target and depth stencil views. ```C++ // Assemble the CommandListPre command list. void D3D12Multithreading::BeginFrame() { m_pCurrentFrameResource->Init(); // Indicate that the back buffer will be used as a render target. m_pCurrentFrameResource->m_commandLists[CommandListPre]->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(m_renderTargets[m_frameIndex].Get(), D3D12_RESOURCE_STATE_PRESENT, D3D12_RESOURCE_STATE_RENDER_TARGET)); // Clear the render target and depth stencil. const float clearColor[] = { 0.0f, 0.0f, 0.0f, 1.0f }; CD3DX12_CPU_DESCRIPTOR_HANDLE rtvHandle(m_rtvHeap->GetCPUDescriptorHandleForHeapStart(), m_frameIndex, m_rtvDescriptorSize); m_pCurrentFrameResource->m_commandLists[CommandListPre]->ClearRenderTargetView(rtvHandle, clearColor, 0, nullptr); m_pCurrentFrameResource->m_commandLists[CommandListPre]->ClearDepthStencilView(m_dsvHeap->GetCPUDescriptorHandleForHeapStart(), D3D12_CLEAR_FLAG_DEPTH, 1.0f, 0, 0, nullptr); ThrowIfFailed(m_pCurrentFrameResource->m_commandLists[CommandListPre]->Close()); } ``` -------------------------------- ### CD3DX12_ROOT_PARAMETER1 Initialization Methods Source: https://learn.microsoft.com/en-us/windows/win32/direct3d12/cd3dx12-root-parameter1 Provides static and inline methods for initializing CD3DX12_ROOT_PARAMETER1 structures for various root parameter types like descriptor tables, constants, constant buffer views, shader resource views, and unordered access views. ```APIDOC ## CD3DX12_ROOT_PARAMETER1 Structure A helper structure to enable easy initialization of a **D3D12_ROOT_PARAMETER1** structure. ### Syntax ```cpp struct CD3DX12_ROOT_PARAMETER1 : public D3D12_ROOT_PARAMETER1{ CD3DX12_ROOT_PARAMETER1(); explicit CD3DX12_ROOT_PARAMETER1(const D3D12_ROOT_PARAMETER1 &o); void static inline InitAsDescriptorTable(D3D12_ROOT_PARAMETER1 &rootParam, UINT numDescriptorRanges, const D3D12_DESCRIPTOR_RANGE1* pDescriptorRanges, D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL); void static inline InitAsConstants(D3D12_ROOT_PARAMETER1 &rootParam, UINT num32BitValues, UINT shaderRegister, UINT registerSpace = 0, D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL); void static inline InitAsConstantBufferView(D3D12_ROOT_PARAMETER1 &rootParam, UINT shaderRegister, UINT registerSpace = 0, D3D12_ROOT_DESCRIPTOR_FLAGS flags = D3D12_ROOT_DESCRIPTOR_FLAG_NONE, D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL); void static inline InitAsShaderResourceView(D3D12_ROOT_PARAMETER1 &rootParam, UINT shaderRegister, UINT registerSpace = 0, D3D12_ROOT_DESCRIPTOR_FLAGS flags = D3D12_ROOT_DESCRIPTOR_FLAG_NONE, D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL); void static inline InitAsUnorderedAccessView(D3D12_ROOT_PARAMETER1 &rootParam, UINT shaderRegister, UINT registerSpace = 0, D3D12_ROOT_DESCRIPTOR_FLAGS flags = D3D12_ROOT_DESCRIPTOR_FLAG_NONE, D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL); void inline InitAsDescriptorTable(UINT numDescriptorRanges, const D3D12_DESCRIPTOR_RANGE1* pDescriptorRanges, D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL); void inline InitAsConstants(UINT num32BitValues, UINT shaderRegister, UINT registerSpace = 0, D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL); void inline InitAsConstantBufferView(UINT shaderRegister, UINT registerSpace = 0, D3D12_ROOT_DESCRIPTOR_FLAGS flags = D3D12_ROOT_DESCRIPTOR_FLAG_NONE, D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL); void inline InitAsShaderResourceView(UINT shaderRegister, UINT registerSpace = 0, D3D12_ROOT_DESCRIPTOR_FLAGS flags = D3D12_ROOT_DESCRIPTOR_FLAG_NONE, D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL); void inline InitAsUnorderedAccessView(UINT shaderRegister, UINT registerSpace = 0, D3D12_ROOT_DESCRIPTOR_FLAGS flags = D3D12_ROOT_DESCRIPTOR_FLAG_NONE, D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL); }; ``` ``` -------------------------------- ### Shader Texture Binding Example Source: https://learn.microsoft.com/en-us/windows/win32/direct3d12/creating-a-root-signature Illustrates how different shader stages can declare textures using the same register binding. This example shows a vertex shader and a pixel shader both declaring a texture at register t0. ```hlsl Texture2D foo : register(t0); ``` ```hlsl Texture2D bar : register(t0); ``` -------------------------------- ### CD3DX12_STATIC_SAMPLER_DESC Constructors and Initialization Source: https://learn.microsoft.com/en-us/windows/win32/direct3d12/cd3dx12-static-sampler-desc Provides constructors and an initialization method for the CD3DX12_STATIC_SAMPLER_DESC structure. Use these to easily set up static sampler descriptions with default or custom values. ```cpp struct CD3DX12_STATIC_SAMPLER_DESC : public D3D12_STATIC_SAMPLER_DESC{ CD3DX12_STATIC_SAMPLER_DESC(); explicit CD3DX12_STATIC_SAMPLER_DESC(const D3D12_STATIC_SAMPLER_DESC &o); CD3DX12_STATIC_SAMPLER_DESC(UINT shaderRegister, D3D12_FILTER filter = D3D12_FILTER_ANISOTROPIC, D3D12_TEXTURE_ADDRESS_MODE addressU = D3D12_TEXTURE_ADDRESS_MODE_WRAP, D3D12_TEXTURE_ADDRESS_MODE addressV = D3D12_TEXTURE_ADDRESS_MODE_WRAP, D3D12_TEXTURE_ADDRESS_MODE addressW = D3D12_TEXTURE_ADDRESS_MODE_WRAP, FLOAT mipLODBias = 0, UINT maxAnisotropy = 16, D3D12_COMPARISON_FUNC comparisonFunc = D3D12_COMPARISON_FUNC_LESS_EQUAL, D3D12_STATIC_BORDER_COLOR borderColor = D3D12_STATIC_BORDER_COLOR_OPAQUE_WHITE, FLOAT minLOD = 0.f, FLOAT maxLOD = D3D12_FLOAT32_MAX, D3D12_SHADER_VISIBILITY shaderVisibility = D3D12_SHADER_VISIBILITY_ALL, UINT registerSpace = 0); void static inline Init(D3D12_STATIC_SAMPLER_DESC &samplerDesc, UINT shaderRegister, D3D12_FILTER filter = D3D12_FILTER_ANISOTROPIC, D3D12_TEXTURE_ADDRESS_MODE addressU = D3D12_TEXTURE_ADDRESS_MODE_WRAP, D3D12_TEXTURE_ADDRESS_MODE addressV = D3D12_TEXTURE_ADDRESS_MODE_WRAP, D3D12_TEXTURE_ADDRESS_MODE addressW = D3D12_TEXTURE_ADDRESS_MODE_WRAP, FLOAT mipLODBias = 0, UINT maxAnisotropy = 16, D3D12_COMPARISON_FUNC comparisonFunc = D3D12_COMPARISON_FUNC_LESS_EQUAL, D3D12_STATIC_BORDER_COLOR borderColor = D3D12_STATIC_BORDER_COLOR_OPAQUE_WHITE, FLOAT minLOD = 0.f, FLOAT maxLOD = D3D12_FLOAT32_MAX, D3D12_SHADER_VISIBILITY shaderVisibility = D3D12_SHADER_VISIBILITY_ALL, UINT registerSpace = 0); void inline Init(UINT shaderRegister, D3D12_FILTER filter = D3D12_FILTER_ANISOTROPIC, D3D12_TEXTURE_ADDRESS_MODE addressU = D3D12_TEXTURE_ADDRESS_MODE_WRAP, D3D12_TEXTURE_ADDRESS_MODE addressV = D3D12_TEXTURE_ADDRESS_MODE_WRAP, D3D12_TEXTURE_ADDRESS_MODE addressW = D3D12_TEXTURE_ADDRESS_MODE_WRAP, FLOAT mipLODBias = 0, UINT maxAnisotropy = 16, D3D12_COMPARISON_FUNC comparisonFunc = D3D12_COMPARISON_FUNC_LESS_EQUAL, D3D12_STATIC_BORDER_COLOR borderColor = D3D12_STATIC_BORDER_COLOR_OPAQUE_WHITE, FLOAT minLOD = 0.f, FLOAT maxLOD = D3D12_FLOAT32_MAX, D3D12_SHADER_VISIBILITY shaderVisibility = D3D12_SHADER_VISIBILITY_ALL, UINT registerSpace = 0); }; ``` -------------------------------- ### D3D12GetDebugInterface Source: https://learn.microsoft.com/en-us/windows/win32/direct3d12/direct3d-12-functions Gets a debug interface. ```APIDOC ## D3D12GetDebugInterface ### Description Gets a debug interface. ### Method [Not specified in source] ### Endpoint [Not specified in source] ### Parameters [Not specified in source] ### Request Example [Not specified in source] ### Response [Not specified in source] ``` -------------------------------- ### Callable Shader Implementation Example Source: https://learn.microsoft.com/en-us/windows/win32/direct3d12/callable-shader An example of a callable shader implementation. It uses the [shader("callable")] attribute and declares an 'inout' parameter structure. It may optionally call other shaders using CallShader. ```hlsl [shader("callable")] void callable_main(inout MyParams params) { // Perform some common operations and update params CallShader( ... ); // maybe } ``` -------------------------------- ### Populating Command Lists in D3D12 Source: https://learn.microsoft.com/en-us/windows/win32/direct3d12/notes-on-example-code Demonstrates the process of resetting command allocators and lists, setting graphics state, recording rendering commands, and transitioning resource states for presentation. Ensure command lists are finished executing on the GPU before resetting them. ```cpp // Command list allocators can only be reset when the associated // command lists have finished execution on the GPU; apps should use // fences to determine GPU execution progress. ThrowIfFailed(m_commandAllocator->Reset()); // However, when ExecuteCommandList() is called on a particular command // list, that command list can then be reset at any time and must be before // re-recording. ThrowIfFailed(m_commandList->Reset(m_commandAllocator.Get(), m_pipelineState.Get())); // Set necessary state. m_commandList->SetGraphicsRootSignature(m_rootSignature.Get()); m_commandList->RSSetViewports(1, &m_viewport); m_commandList->RSSetScissorRects(1, &m_scissorRect); // Indicate that the back buffer will be used as a render target. auto barrier = CD3DX12_RESOURCE_BARRIER::Transition(m_renderTargets[m_frameIndex].Get(), D3D12_RESOURCE_STATE_PRESENT, D3D12_RESOURCE_STATE_RENDER_TARGET); m_commandList->ResourceBarrier(1, &barrier); CD3DX12_CPU_DESCRIPTOR_HANDLE rtvHandle(m_rtvHeap->GetCPUDescriptorHandleForHeapStart(), m_frameIndex, m_rtvDescriptorSize); m_commandList->OMSetRenderTargets(1, &rtvHandle, FALSE, nullptr); // Record commands. const float clearColor[] = { 0.0f, 0.2f, 0.4f, 1.0f }; m_commandList->ClearRenderTargetView(rtvHandle, clearColor, 0, nullptr); m_commandList->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST); m_commandList->IASetVertexBuffers(0, 1, &m_vertexBufferView); m_commandList->DrawInstanced(3, 1, 0, 0); // Indicate that the back buffer will now be used to present. m_commandList->ResourceBarrier(1, &barrier); barrier = CD3DX12_RESOURCE_BARRIER::Transition(m_renderTargets[m_frameIndex].Get(), D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_PRESENT); ThrowIfFailed(m_commandList->Close()); ``` -------------------------------- ### RayTMin() Source: https://learn.microsoft.com/en-us/windows/win32/direct3d12/raytmin Retrieves the current parametric starting point for a ray. This value, along with the ray's origin and direction, determines the ray's starting position. It is set during the TraceRay call and remains constant for its duration. ```APIDOC ## RayTMin() ### Description Returns a float representing the current parametric starting point for the ray. This value is used in the formula: Origin + (Direction * RayTMin) to define the ray's starting point. ### Syntax ``` float RayTMin(); ``` ### Remarks **RayTMin** defines the starting point of the ray. The Origin and Direction can be in either world or object space, resulting in a world or object space starting point, respectively. **RayTMin** is specified in the call to **TraceRay** and is constant for the duration of that call. This function can be called from the following raytracing shader types: * Any Hit Shader * Closest Hit Shader * Intersection Shader * Miss Shader ``` -------------------------------- ### Closest Hit Shader Example Source: https://learn.microsoft.com/en-us/windows/win32/direct3d12/closest-hit-shader An example of a closest hit shader. This shader updates the payload, traces a reflection ray, and combines contributions. It demonstrates typical operations like calculating world normal and setting up a reflected ray. ```hlsl [shader("closesthit")] void closesthit_main(inout MyPayload payload, in MyAttributes attr) { CallShader( ... ); // maybe // update payload for surface // trace reflection float3 worldRayOrigin = WorldRayOrigin() + WorldRayDirection() * RayTCurrent(); float3 worldNormal = mul(attr.normal, (float3x3)ObjectToWorld3x4()); RayDesc reflectedRay = { worldRayOrigin, SceneConstants.Epsilon, ReflectRay(WorldRayDirection(), worldNormal), SceneConstants.TMax }; TraceRay(MyAccelerationStructure, SceneConstants.RayFlags, SceneConstants.InstanceInclusionMask, SceneConstants.RayContributionToHitGroupIndex, SceneConstants.MultiplierForGeometryContributionToHitGroupIndex, SceneConstants.MissShaderIndex, reflectedRay, payload); // Combine final contributions into ray payload // this ray query is now complete. // Alternately, could look at data in payload result based on that make other TraceRay // calls. No constraints on the code structure. } ``` -------------------------------- ### CD3DX12_STATIC_SAMPLER_DESC(UINT shaderRegister, ...) Source: https://learn.microsoft.com/en-us/windows/win32/direct3d12/cd3dx12-static-sampler-desc Creates a new instance of a CD3DX12_STATIC_SAMPLER_DESC, initializing it with the provided parameters. Many parameters have default values. ```APIDOC ## CD3DX12_STATIC_SAMPLER_DESC(UINT shaderRegister, D3D12_FILTER filter = D3D12_FILTER_ANISOTROPIC, D3D12_TEXTURE_ADDRESS_MODE addressU = D3D12_TEXTURE_ADDRESS_MODE_WRAP, D3D12_TEXTURE_ADDRESS_MODE addressV = D3D12_TEXTURE_ADDRESS_MODE_WRAP, D3D12_TEXTURE_ADDRESS_MODE addressW = D3D12_TEXTURE_ADDRESS_MODE_WRAP, FLOAT mipLODBias = 0, UINT maxAnisotropy = 16, D3D12_COMPARISON_FUNC comparisonFunc = D3D12_COMPARISON_FUNC_LESS_EQUAL, D3D12_STATIC_BORDER_COLOR borderColor = D3D12_STATIC_BORDER_COLOR_OPAQUE_WHITE, FLOAT minLOD = 0.f, FLOAT maxLOD = D3D12_FLOAT32_MAX, D3D12_SHADER_VISIBILITY shaderVisibility = D3D12_SHADER_VISIBILITY_ALL, UINT registerSpace = 0) ### Description Creates a new instance of a CD3DX12_STATIC_SAMPLER_DESC, initializing the specified parameters. Optional parameters have default values. ### Method Constructor ### Parameters #### Path Parameters - **shaderRegister** (UINT) - Required - The shader register for the sampler. - **filter** (D3D12_FILTER) - Optional - The filtering mode. Defaults to D3D12_FILTER_ANISOTROPIC. - **addressU** (D3D12_TEXTURE_ADDRESS_MODE) - Optional - The texture address mode for the U coordinate. Defaults to D3D12_TEXTURE_ADDRESS_MODE_WRAP. - **addressV** (D3D12_TEXTURE_ADDRESS_MODE) - Optional - The texture address mode for the V coordinate. Defaults to D3D12_TEXTURE_ADDRESS_MODE_WRAP. - **addressW** (D3D12_TEXTURE_ADDRESS_MODE) - Optional - The texture address mode for the W coordinate. Defaults to D3D12_TEXTURE_ADDRESS_MODE_WRAP. - **mipLODBias** (FLOAT) - Optional - The mipmap level-of-detail bias. Defaults to 0. - **maxAnisotropy** (UINT) - Optional - The maximum anisotropy. Defaults to 16. - **comparisonFunc** (D3D12_COMPARISON_FUNC) - Optional - The comparison function. Defaults to D3D12_COMPARISON_FUNC_LESS_EQUAL. - **borderColor** (D3D12_STATIC_BORDER_COLOR) - Optional - The border color. Defaults to D3D12_STATIC_BORDER_COLOR_OPAQUE_WHITE. - **minLOD** (FLOAT) - Optional - The minimum level of detail. Defaults to 0.f. - **maxLOD** (FLOAT) - Optional - The maximum level of detail. Defaults to D3D12_FLOAT32_MAX. - **shaderVisibility** (D3D12_SHADER_VISIBILITY) - Optional - The shader visibility. Defaults to D3D12_SHADER_VISIBILITY_ALL. - **registerSpace** (UINT) - Optional - The register space. Defaults to 0. ``` -------------------------------- ### Any-hit Shader Implementation Example Source: https://learn.microsoft.com/en-us/windows/win32/direct3d12/any-hit-shader This example demonstrates a typical any-hit shader. It shows how to access ray information, process intersection attributes, and conditionally call intrinsics like AcceptHitAndEndSearch or IgnoreHit to control ray tracing behavior. ```csharp [shader("anyhit")] void anyhit_main( inout MyPayload payload, in MyAttributes attr ) { float3 hitLocation = ObjectRayOrigin() + ObjectRayDirection() * RayTCurrent(); float alpha = computeAlpha(hitLocation, attr, ...); // Processing shadow and only care if a hit is registered? if (TerminateShadowRay(alpha)) AcceptHitAndEndSearch(); // aborts function // Save alpha contribution and ignoring hit? if (SaveAndIgnore(payload, RayTCurrent(), alpha, attr, ...)) IgnoreHit(); // aborts function // do something else. // return to accept and update closest hit } ``` -------------------------------- ### Default Initialization with CD3DX12_DEFAULT Source: https://learn.microsoft.com/en-us/windows/win32/direct3d12/cd3dx12-pipeline-state-stream-subobject Highlights specific structures that can be initialized with common defaults using CD3DX12_DEFAULT. ```APIDOC ## Remarks The **CD3DX12_PIPELINE_STATE_STREAM_BLEND_DESC**, **CD3DX12_PIPELINE_STATE_STREAM_DEPTH_STENCIL**, **CD3DX12_PIPELINE_STATE_STREAM_DEPTH_STENCIL1**, and **CD3DX12_PIPELINE_STATE_STREAM_RASTERIZER** structures are defined to initialize their subobject data with common defaults using **CD3DX12_DEFAULT**. ``` -------------------------------- ### Ray Generation Shader Example Source: https://learn.microsoft.com/en-us/windows/win32/direct3d12/ray-generation-shader This example demonstrates a typical ray generation shader. It initializes a ray description and payload, then calls TraceRay to generate a ray and WriteFinalPixel to output the result. Ensure SceneConstants, MyAccelerationStructure, and MyPayload are defined appropriately. ```csharp struct SceneConstantStructure { ... }; ConstantBuffer SceneConstants; RaytracingAccelerationStructure MyAccelerationStructure : register(t3); struct MyPayload { ... }; [shader("raygeneration")] void raygen_main() { RayDesc myRay = { SceneConstants.CameraOrigin, SceneConstants.TMin, computeRayDirection(SceneConstants.LensParams, DispatchRaysIndex(), DispatchRaysDimensions()), SceneConstants.TMax}; MyPayload payload = { ... }; // init payload TraceRay( MyAccelerationStructure, SceneConstants.RayFlags, SceneConstants.InstanceInclusionMask, SceneConstants.RayContributionToHitGroupIndex, SceneConstants.MultiplierForGeometryContributionToHitGroupIndex, SceneConstants.MissShaderIndex, myRay, payload); WriteFinalPixel(DispatchRaysIndex(), payload); } ``` -------------------------------- ### Constructor with D3D12_RANGE_UINT64 for CD3DX12_SUBRESOURCE_RANGE_UINT64 Source: https://learn.microsoft.com/en-us/windows/win32/direct3d12/cd3dx12-subresource-range-uint64 Initializes a new CD3DX12_SUBRESOURCE_RANGE_UINT64 with a specified subresource index and a D3D12_RANGE_UINT64 structure. ```cpp CD3DX12_SUBRESOURCE_RANGE_UINT64(UINT subresource, const D3D12_RANGE_UINT64& range); ``` -------------------------------- ### Miss Shader Implementation Example Source: https://learn.microsoft.com/en-us/windows/win32/direct3d12/miss-shader An example of a miss shader function. It can use ray system values to compute background contributions and optionally call other shaders or trace new rays. The payload structure must match the one provided to TraceRay. ```csharp [shader("miss")] void miss_main(inout MyPayload payload) { // Use ray system values to compute contributions of background, sky, etc... // Combine contributions into ray payload CallShader( ... ); // if desired TraceRay( ... ); // if desired // this ray query is now complete } ``` -------------------------------- ### Create and Transition Texture Resources Source: https://learn.microsoft.com/en-us/windows/win32/direct3d12/using-resource-barriers-to-synchronize-resource-states-in-direct3d-12 This snippet shows how to create default textures, upload data to them using an intermediate upload heap, and then transition their state from copy destination to pixel shader resource. It also demonstrates creating Shader Resource Views (SRVs). ```C++ // Create each texture and SRV descriptor. const UINT srvCount = _countof(SampleAssets::Textures); PIXBeginEvent(commandList.Get(), 0, L"Copy diffuse and normal texture data to default resources..."); for (int i = 0; i < srvCount; i++) { // Describe and create a Texture2D. const SampleAssets::TextureResource &tex = SampleAssets::Textures[i]; CD3DX12_RESOURCE_DESC texDesc( D3D12_RESOURCE_DIMENSION_TEXTURE2D, 0, tex.Width, tex.Height, 1, static_cast(tex.MipLevels), tex.Format, 1, 0, D3D12_TEXTURE_LAYOUT_UNKNOWN, D3D12_RESOURCE_FLAG_NONE); ThrowIfFailed(m_device->CreateCommittedResource( &CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_DEFAULT), D3D12_HEAP_FLAG_NONE, &texDesc, D3D12_RESOURCE_STATE_COPY_DEST, nullptr, IID_PPV_ARGS(&m_textures[i]))); { const UINT subresourceCount = texDesc.DepthOrArraySize * texDesc.MipLevels; UINT64 uploadBufferSize = GetRequiredIntermediateSize(m_textures[i].Get(), 0, subresourceCount); ThrowIfFailed(m_device->CreateCommittedResource( &CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_UPLOAD), D3D12_HEAP_FLAG_NONE, &CD3DX12_RESOURCE_DESC::Buffer(uploadBufferSize), D3D12_RESOURCE_STATE_GENERIC_READ, nullptr, IID_PPV_ARGS(&m_textureUploads[i]))); // Copy data to the intermediate upload heap and then schedule a copy // from the upload heap to the Texture2D. D3D12_SUBRESOURCE_DATA textureData = {}; textureData.pData = pAssetData + tex.Data->Offset; textureData.RowPitch = tex.Data->Pitch; textureData.SlicePitch = tex.Data->Size; UpdateSubresources(commandList.Get(), m_textures[i].Get(), m_textureUploads[i].Get(), 0, 0, subresourceCount, &textureData); commandList->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(m_textures[i].Get(), D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE)); } // Describe and create an SRV. D3D12_SHADER_RESOURCE_VIEW_DESC srvDesc = {}; srvDesc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D; srvDesc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING; srvDesc.Format = tex.Format; srvDesc.Texture2D.MipLevels = tex.MipLevels; srvDesc.Texture2D.MostDetailedMip = 0; srvDesc.Texture2D.ResourceMinLODClamp = 0.0f; m_device->CreateShaderResourceView(m_textures[i].Get(), &srvDesc, cbvSrvHandle); // Move to the next descriptor slot. cbvSrvHandle.Offset(cbvSrvDescriptorSize); } ``` -------------------------------- ### Example Descriptor Table Source: https://learn.microsoft.com/en-us/windows/win32/direct3d12/resource-binding-in-hlsl A descriptor table compatible with texture slots t0 through t98. ```hlsl DescriptorTable( CBV(b1), SRV(t0,numDescriptors=99), CBV(b2) ) ```