Add missing automatic usage of D3D12_HEAP_FLAG_ALLOW_SHADER_ATOMICS in custom pools

Also improvements in documentation.
diff --git a/src/D3D12MemAlloc.cpp b/src/D3D12MemAlloc.cpp
index 60c1d22..4871e45 100644
--- a/src/D3D12MemAlloc.cpp
+++ b/src/D3D12MemAlloc.cpp
@@ -3701,16 +3701,7 @@
 class PoolPimpl

 {

 public:

-    PoolPimpl(AllocatorPimpl* allocator, const POOL_DESC& desc) :

-        m_Allocator(allocator),

-        m_Desc(desc),

-        m_BlockVector(D3D12MA_NEW(allocator->GetAllocs(), BlockVector)(

-            allocator, desc.HeapType, desc.HeapFlags,

-            desc.BlockSize != 0 ? desc.BlockSize : D3D12MA_DEFAULT_BLOCK_SIZE, // preferredBlockSize

-            desc.MinBlockCount, desc.MaxBlockCount,

-            desc.BlockSize != 0)) // explicitBlockSize

-    {

-    }

+    PoolPimpl(AllocatorPimpl* allocator, const POOL_DESC& desc);

     ~PoolPimpl()

     {

         D3D12MA_DELETE(m_Allocator->GetAllocs(), m_BlockVector);

@@ -3734,6 +3725,30 @@
     return m_BlockVector->CreateMinBlocks();

 }

 

+PoolPimpl::PoolPimpl(AllocatorPimpl* allocator, const POOL_DESC& desc) :

+    m_Allocator(allocator),

+    m_Desc(desc),

+    m_BlockVector(NULL)

+{

+    const bool explicitBlockSize = desc.BlockSize != 0;

+    const UINT64 preferredBlockSize = explicitBlockSize ? desc.BlockSize : D3D12MA_DEFAULT_BLOCK_SIZE;

+

+    D3D12_HEAP_FLAGS heapFlags = desc.HeapFlags;

+#if D3D12MA_ALLOW_SHADER_ATOMICS

+    if(desc.HeapType == D3D12_HEAP_TYPE_DEFAULT)

+    {

+        heapFlags |= D3D12_HEAP_FLAG_ALLOW_SHADER_ATOMICS;

+    }

+#endif

+

+    m_BlockVector = D3D12MA_NEW(allocator->GetAllocs(), BlockVector)(

+        allocator, desc.HeapType, heapFlags,

+        preferredBlockSize,

+        desc.MinBlockCount, desc.MaxBlockCount,

+        explicitBlockSize);

+}

+

+

 ////////////////////////////////////////////////////////////////////////////////

 // Public class Pool implementation

 

diff --git a/src/D3D12MemAlloc.h b/src/D3D12MemAlloc.h
index 3466397..7023fa0 100644
--- a/src/D3D12MemAlloc.h
+++ b/src/D3D12MemAlloc.h
@@ -300,7 +300,6 @@
 

 Near future: feature parity with [Vulkan Memory Allocator](https://github.com/GPUOpen-LibrariesAndSDKs/VulkanMemoryAllocator/), including:

 

-- Custom memory pools

 - Alternative allocation algorithms: linear allocator, buddy allocator

 - JSON dump that can be visualized on a picture

 - Support for priorities using `ID3D12Device1::SetResidencyPriority`

@@ -423,8 +422,8 @@
     If new allocation cannot be placed in any of the existing heaps, allocation

     fails with `E_OUTOFMEMORY` error.

 

-    You should not use #ALLOCATION_FLAG_COMMITTED and

-    #ALLOCATION_FLAG_NEVER_ALLOCATE at the same time. It makes no sense.

+    You should not use D3D12MA::ALLOCATION_FLAG_COMMITTED and

+    D3D12MA::ALLOCATION_FLAG_NEVER_ALLOCATE at the same time. It makes no sense.

     */

     ALLOCATION_FLAG_NEVER_ALLOCATE = 0x2,

 

@@ -434,7 +433,7 @@
     ALLOCATION_FLAG_WITHIN_BUDGET = 0x4,

 } ALLOCATION_FLAGS;

 

-/// \brief Parameters of created Allocation object. To be used with Allocator::CreateResource.

+/// \brief Parameters of created D3D12MA::Allocation object. To be used with Allocator::CreateResource.

 struct ALLOCATION_DESC

 {

     /// Flags.

@@ -635,6 +634,7 @@
     D3D12MA_CLASS_NO_COPY(Allocation)

 };

 

+/// \brief Parameters of created D3D12MA::Pool object. To be used with D3D12MA::Allocator::CreatePool.

 struct POOL_DESC

 {

     /** \brief The type of memory heap where allocations of this pool should be placed.

@@ -664,7 +664,7 @@
     Then sizes of particular blocks may vary.

     */

     UINT64 BlockSize;

-    /** \brief Minimum number of heaps (memory blocks) to be always allocated in this pool, even if they stay empty.

+    /** \brief Minimum number of heaps (memory blocks) to be always allocated in this pool, even if they stay empty. Optional.

 

     Set to 0 to have no preallocated blocks and allow the pool be completely empty.

     */

@@ -679,10 +679,27 @@
     UINT MaxBlockCount;

 };

 

+/** \brief Custom memory pool

+

+Represents a separate set of heaps (memory blocks) that can be used to create

+D3D12MA::Allocation-s and resources in it. Usually there is no need to create custom

+pools - creating resources in default pool is sufficient.

+

+To create custom pool, fill D3D12MA::POOL_DESC and call D3D12MA::Allocator::CreatePool.

+*/

 class Pool

 {

 public:

+    /** \brief Deletes pool object, frees D3D12 heaps (memory blocks) managed by it. Allocations and resources must already be released!

+

+    It doesn't delete allocations and resources created in this pool. They must be all

+    released before calling this function!

+    */

     void Release();

+    /** \brief Returns copy of parameters of the pool.

+

+    These are the same parameters as passed to D3D12MA::Allocator::CreatePool.

+    */

     POOL_DESC GetDesc();

 

 private:

@@ -902,7 +919,7 @@
     `pAllocInfo->SizeInBytes` must be multiply of 64KB.

     `pAllocInfo->Alignment` must be one of the legal values as described in documentation of `D3D12_HEAP_DESC`.

 

-    If you use #ALLOCATION_FLAG_COMMITTED you will get a separate memory block -

+    If you use D3D12MA::ALLOCATION_FLAG_COMMITTED you will get a separate memory block -

     a heap that always has offset 0.

     */

     HRESULT AllocateMemory(

@@ -941,6 +958,8 @@
         REFIID riidResource,

         void** ppvResource);

 

+    /** \brief Creates custom pool.

+    */

     HRESULT CreatePool(

         const POOL_DESC* pPoolDesc,

         Pool** ppPool);