microsoft / DirectXTK12

The DirectX Tool Kit (aka DirectXTK12) is a collection of helper classes for writing DirectX 12 code in C++
https://walbourn.github.io/directx-tool-kit-for-directx-12/
MIT License
1.45k stars 371 forks source link

How do I return an allocation to DescriptorPile? #118

Closed trojanfoe closed 2 years ago

trojanfoe commented 2 years ago

I am just starting out with DirectX 12, so this request might just be nonsense, but my current strategy is to create a large CBV/SRV/UAV DescriptorPile in the DeviceResources class and have my resource-based classes (like Texture) request a descriptor heap slot via Allocate(). However I want to support destroying the resource so would have expected to see a DescriptorPile::Free() method to make a slot available to later allocations. What are my options here?

walbourn commented 2 years ago

Heap "slots" are an important resource in a given heap, so it's important to reuse them as much as possible.

The DescriptorHeap class was designed for a 'static assignment' model where you knew all the slots you'd need up-front. The DescriptorPile class was added to provide a set of 'static assignment' slots and then you can allocate more 'dynamic' slots at runtime up to the provided maximum.

As such, you should really have a system on-top of that you use to manage texture lifetime and reuse those slots. You'd only go back to DescriptorPile when you needed more of them.

trojanfoe commented 2 years ago

That's cool thanks, I have a simple allocator I can use in place of the DescriptorPile class. Thanks for the clarification.

walbourn commented 2 years ago

The motivation for DescriptorPile was supporting Model where you don't know the number of SRV slots you need until runtime.

For 'streaming' scenarios where assets come and go, you should do something fancier yourself. You can of course you DescriptorPile in your implementation if you want :)