-
Notifications
You must be signed in to change notification settings - Fork 409
DescriptorPile
The DescriptorHeap manages heaps of metadata descriptors, but is generally used with static indices (typically in the form of an enumeration). This is useful for many scenarios, but is difficult to use when descriptors usage is data-driven (such as when loading models). To help with this, the DescriptorPile class extends the basic DescriptorHeap
with dynamic index allocation.
#include "DescriptorHeap.h"
Creation of a descriptor pile is identical to DescriptorHeap
, but typically with a large maximum capability. For example, this is a pile that can have up to 128 descriptors.
srvPile = std::make_unique<DescriptorPile>(device,
D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV,
D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE,
128);
It's often useful to mix static descriptor indices with dynamically allocated descriptors, so you can provide an optional parameter to reserve part of the range for use with static descriptors:
enum StaticDescriptors
{
Font,
CtrlFont,
SceneTex,
RadianceTex,
IrradianceTex,
Reserve
};
srvPile = std::make_unique<DescriptorPile>(device,
D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV,
D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE,
128,
StaticDescriptors::Reserve);
If more descriptors are reserved or allocated than the capacity, then an exception is thrown.
In addition to the methods and properties on a DescriptorHeap
, a descriptor pile supports the following methods:
-
Allocate: Allocates a single descriptor from the pile.
-
AllocateRange: Allocates 1 or more descriptors from the pile.
Here is an example of using the pile with model loading:
int txtOffset = 0;
{
size_t start, end;
resourceDescriptors->AllocateRange(cup->textureNames.size(), start, end);
txtOffset = static_cast<int>(start);
}
cup->LoadTextures(*m_modelResources, txtOffset);
All content and source code for this package are subject to the terms of the MIT License.
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.
- Universal Windows Platform apps
- Windows desktop apps
- Windows 11
- Windows 10
- Xbox One
- Xbox Series X|S
- x86
- x64
- ARM64
- Visual Studio 2022
- Visual Studio 2019 (16.11)
- clang/LLVM v12 - v18
- MinGW 12.2, 13.2
- CMake 3.20