Skip to content

Commit 78d36ed

Browse files
Grpahics Accessories: a bit more documentation updates + minor code cleanup
1 parent 0360fca commit 78d36ed

File tree

4 files changed

+33
-23
lines changed

4 files changed

+33
-23
lines changed

Graphics/GraphicsAccessories/interface/ResourceReleaseQueue.hpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2022 Diligent Graphics LLC
2+
* Copyright 2019-2025 Diligent Graphics LLC
33
* Copyright 2015-2019 Egor Yusov
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -218,7 +218,7 @@ class StaticStaleResourceWrapper
218218
/// * When command list is submitted to the command queue, all stale objects associated with this
219219
/// and earlier command lists are moved to the release queue, along with the fence value associated with
220220
/// the command list
221-
/// * Resources are removed and actually destroyed from the queue when fence is signaled and the queue is Purged
221+
/// * Resources are removed and actually destroyed from the queue when fence is signaled and the queue is purged
222222
///
223223
/// \tparam ResourceWrapperType - Type of the resource wrapper used by the release queue.
224224
template <typename ResourceWrapperType>
@@ -239,6 +239,7 @@ class ResourceReleaseQueue
239239
}
240240

241241
/// Creates a resource wrapper for the specific resource type
242+
242243
/// \param [in] Resource - Resource to be released
243244
/// \param [in] NumReferences - Number of references to the resource
244245
template <typename ResourceType, typename = typename std::enable_if<std::is_object<ResourceType>::value>::type>
@@ -248,6 +249,7 @@ class ResourceReleaseQueue
248249
}
249250

250251
/// Moves a resource to the stale resources queue
252+
251253
/// \param [in] Resource - Resource to be released
252254
/// \param [in] NextCommandListNumber - Number of the command list that will be submitted to the queue next
253255
template <typename ResourceType, typename = typename std::enable_if<std::is_object<ResourceType>::value>::type>
@@ -257,6 +259,7 @@ class ResourceReleaseQueue
257259
}
258260

259261
/// Moves a resource wrapper to the stale resources queue
262+
260263
/// \param [in] Wrapper - Resource wrapper containing the resource to be released
261264
/// \param [in] NextCommandListNumber - Number of the command list that will be submitted to the queue next
262265
void SafeReleaseResource(ResourceWrapperType&& Wrapper, Uint64 NextCommandListNumber)
@@ -266,6 +269,7 @@ class ResourceReleaseQueue
266269
}
267270

268271
/// Moves a copy of the resource wrapper to the stale resources queue
272+
269273
/// \param [in] Wrapper - Resource wrapper containing the resource to be released
270274
/// \param [in] NextCommandListNumber - Number of the command list that will be submitted to the queue next
271275
void SafeReleaseResource(const ResourceWrapperType& Wrapper, Uint64 NextCommandListNumber)
@@ -275,6 +279,7 @@ class ResourceReleaseQueue
275279
}
276280

277281
/// Adds a resource directly to the release queue
282+
278283
/// \param [in] Resource - Resource to be released.
279284
/// \param [in] FenceValue - Fence value indicating when the resource was used last time.
280285
template <typename ResourceType, typename = typename std::enable_if<std::is_object<ResourceType>::value>::type>
@@ -284,6 +289,7 @@ class ResourceReleaseQueue
284289
}
285290

286291
/// Adds a resource wrapper directly to the release queue
292+
287293
/// \param [in] Wrapper - Resource wrapper containing the resource to be released.
288294
/// \param [in] FenceValue - Fence value indicating when the resource was used last time.
289295
void DiscardResource(ResourceWrapperType&& Wrapper, Uint64 FenceValue)
@@ -293,6 +299,7 @@ class ResourceReleaseQueue
293299
}
294300

295301
/// Adds a copy of the resource wrapper directly to the release queue
302+
296303
/// \param [in] Wrapper - Resource wrapper containing the resource to be released.
297304
/// \param [in] FenceValue - Fence value indicating when the resource was used last time.
298305
void DiscardResource(const ResourceWrapperType& Wrapper, Uint64 FenceValue)
@@ -302,6 +309,7 @@ class ResourceReleaseQueue
302309
}
303310

304311
/// Adds multiple resources directly to the release queue
312+
305313
/// \param [in] FenceValue - Fence value indicating when the resource was used last time.
306314
/// \param [in] Iterator - Iterator that returns resources to be released.
307315
template <typename ResourceType, typename IteratorType>
@@ -316,6 +324,7 @@ class ResourceReleaseQueue
316324
}
317325

318326
/// Moves stale objects to the release queue
327+
319328
/// \param [in] SubmittedCmdBuffNumber - number of the last submitted command list.
320329
/// All resources in the stale object list whose command list number is
321330
/// less than or equal to this value are moved to the release queue.
@@ -344,6 +353,7 @@ class ResourceReleaseQueue
344353

345354
/// Removes all objects from the release queue whose fence value is
346355
/// less than or equal to CompletedFenceValue
356+
347357
/// \param [in] CompletedFenceValue - Value of the fence that has been completed by the GPU
348358
void Purge(Uint64 CompletedFenceValue)
349359
{

Graphics/GraphicsAccessories/interface/RingBuffer.hpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2022 Diligent Graphics LLC
2+
* Copyright 2019-2025 Diligent Graphics LLC
33
* Copyright 2015-2019 Egor Yusov
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -123,7 +123,7 @@ class RingBuffer
123123
return InvalidOffset;
124124
}
125125

126-
auto AlignedHead = AlignUp(m_Head, Alignment);
126+
OffsetType AlignedHead = AlignUp(m_Head, Alignment);
127127
if (m_Head >= m_Tail)
128128
{
129129
// AlignedHead
@@ -134,8 +134,8 @@ class RingBuffer
134134
//
135135
if (AlignedHead + Size <= m_MaxSize)
136136
{
137-
auto Offset = AlignedHead;
138-
auto AdjustedSize = Size + (AlignedHead - m_Head);
137+
OffsetType Offset = AlignedHead;
138+
OffsetType AdjustedSize = Size + (AlignedHead - m_Head);
139139
m_Head += AdjustedSize;
140140
m_UsedSize += AdjustedSize;
141141
m_CurrFrameSize += AdjustedSize;
@@ -164,8 +164,8 @@ class RingBuffer
164164
// | | |
165165
// [xxxx... xxxxxxxxxxxxxxxxxxxxxxxxxx]
166166
//
167-
auto Offset = AlignedHead;
168-
auto AdjustedSize = Size + (AlignedHead - m_Head);
167+
OffsetType Offset = AlignedHead;
168+
OffsetType AdjustedSize = Size + (AlignedHead - m_Head);
169169
m_Head += AdjustedSize;
170170
m_UsedSize += AdjustedSize;
171171
m_CurrFrameSize += AdjustedSize;
@@ -199,7 +199,7 @@ class RingBuffer
199199
// We can release all heads whose associated fence value is less than or equal to CompletedFenceValue
200200
while (!m_CompletedFrameHeads.empty() && m_CompletedFrameHeads.front().FenceValue <= CompletedFenceValue)
201201
{
202-
const auto& OldestFrameHead = m_CompletedFrameHeads.front();
202+
const FrameHeadAttribs& OldestFrameHead = m_CompletedFrameHeads.front();
203203
VERIFY_EXPR(OldestFrameHead.Size <= m_UsedSize);
204204
m_UsedSize -= OldestFrameHead.Size;
205205
m_Tail = OldestFrameHead.Offset;
@@ -210,7 +210,7 @@ class RingBuffer
210210
{
211211
#ifdef DILIGENT_DEBUG
212212
VERIFY(m_CompletedFrameHeads.empty(), "Zero-size heads are not added to the list, and since the buffer is empty, there must be no heads in the list");
213-
for (const auto& head : m_CompletedFrameHeads)
213+
for (const FrameHeadAttribs& head : m_CompletedFrameHeads)
214214
VERIFY(head.Size == 0, "Non zero-size head found");
215215
#endif
216216
m_CompletedFrameHeads.clear();

Graphics/GraphicsAccessories/interface/VariableSizeAllocationsManager.hpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2022 Diligent Graphics LLC
2+
* Copyright 2019-2025 Diligent Graphics LLC
33
* Copyright 2015-2019 Egor Yusov
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -26,7 +26,6 @@
2626
*/
2727

2828
// Helper class that handles free memory block management to accommodate variable-size allocation requests
29-
// See http://diligentgraphics.com/diligent-engine/architecture/d3d12/variable-size-memory-allocations-manager/
3029

3130
#pragma once
3231

@@ -40,6 +39,7 @@
4039

4140
namespace Diligent
4241
{
42+
4343
// The class handles free memory block management to accommodate variable-size allocation requests.
4444
// It keeps track of free blocks only and does not record allocation sizes. The class uses two ordered maps
4545
// to facilitate operations. The first map keeps blocks sorted by their offsets. The second multimap keeps blocks
@@ -211,7 +211,7 @@ class VariableSizeAllocationsManager
211211
if (m_FreeSize < Size)
212212
return Allocation::InvalidAllocation();
213213

214-
auto AlignmentReserve = (Alignment > m_CurrAlignment) ? Alignment - m_CurrAlignment : 0;
214+
OffsetType AlignmentReserve = (Alignment > m_CurrAlignment) ? Alignment - m_CurrAlignment : 0;
215215
// Get the first block that is large enough to encompass Size + AlignmentReserve bytes
216216
// lower_bound() returns an iterator pointing to the first element that
217217
// is not less (i.e. >= ) than key
@@ -230,13 +230,13 @@ class VariableSizeAllocationsManager
230230
// | |
231231
// Offset NewOffset
232232
//
233-
auto Offset = SmallestBlockIt->first;
233+
OffsetType Offset = SmallestBlockIt->first;
234234
VERIFY_EXPR(Offset % m_CurrAlignment == 0);
235-
auto AlignedOffset = AlignUp(Offset, Alignment);
236-
auto AdjustedSize = Size + (AlignedOffset - Offset);
235+
OffsetType AlignedOffset = AlignUp(Offset, Alignment);
236+
OffsetType AdjustedSize = Size + (AlignedOffset - Offset);
237237
VERIFY_EXPR(AdjustedSize <= Size + AlignmentReserve);
238-
auto NewOffset = Offset + AdjustedSize;
239-
auto NewSize = SmallestBlockIt->second.Size - AdjustedSize;
238+
OffsetType NewOffset = Offset + AdjustedSize;
239+
OffsetType NewSize = SmallestBlockIt->second.Size - AdjustedSize;
240240
VERIFY_EXPR(SmallestBlockItIt == SmallestBlockIt->second.OrderBySizeIt);
241241
m_FreeBlocksBySize.erase(SmallestBlockItIt);
242242
m_FreeBlocksByOffset.erase(SmallestBlockIt);
@@ -401,8 +401,8 @@ class VariableSizeAllocationsManager
401401
auto LastBlockIt = m_FreeBlocksByOffset.end();
402402
--LastBlockIt;
403403

404-
const auto LastBlockOffset = LastBlockIt->first;
405-
const auto LastBlockSize = LastBlockIt->second.Size;
404+
const OffsetType LastBlockOffset = LastBlockIt->first;
405+
const OffsetType LastBlockSize = LastBlockIt->second.Size;
406406
if (LastBlockOffset + LastBlockSize == m_MaxSize)
407407
{
408408
// Extend the last block

Graphics/GraphicsAccessories/interface/VariableSizeGPUAllocationsManager.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2022 Diligent Graphics LLC
2+
* Copyright 2019-2025 Diligent Graphics LLC
33
* Copyright 2015-2019 Egor Yusov
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -27,7 +27,6 @@
2727

2828

2929
// An GPU-tailored extension of the basic variable-size allocations manager
30-
// See http://diligentgraphics.com/diligent-engine/architecture/d3d12/variable-size-memory-allocations-manager/
3130

3231
#pragma once
3332

@@ -36,6 +35,7 @@
3635

3736
namespace Diligent
3837
{
38+
3939
// Class extends basic variable-size memory block allocator by deferring deallocation
4040
// of freed blocks until the corresponding frame is completed
4141
class VariableSizeGPUAllocationsManager : public VariableSizeAllocationsManager
@@ -101,7 +101,7 @@ class VariableSizeGPUAllocationsManager : public VariableSizeAllocationsManager
101101
// Free all allocations from the beginning of the queue that belong to completed command lists
102102
while (!m_StaleAllocations.empty() && m_StaleAllocations.front().FenceValue <= LastCompletedFenceValue)
103103
{
104-
auto& OldestAllocation = m_StaleAllocations.front();
104+
StaleAllocationAttribs& OldestAllocation = m_StaleAllocations.front();
105105
VariableSizeAllocationsManager::Free(OldestAllocation.Offset, OldestAllocation.Size);
106106
m_StaleAllocationsSize -= OldestAllocation.Size;
107107
m_StaleAllocations.pop_front();

0 commit comments

Comments
 (0)