Skip to content

Commit 0aff5d9

Browse files
GraphicsTools: don't use auto where unnecessary
1 parent f8f37a6 commit 0aff5d9

19 files changed

+224
-220
lines changed

Graphics/GraphicsTools/src/BufferSuballocator.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2024 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");
@@ -176,7 +176,7 @@ class BufferSuballocatorImpl final : public ObjectBase<IBufferSuballocator>
176176
virtual IBuffer* Update(IRenderDevice* pDevice, IDeviceContext* pContext) override final
177177
{
178178
// NB: mutex must not be locked here to avoid stalling render thread
179-
const auto MgrSize = m_MgrSize.load();
179+
const OffsetType MgrSize = m_MgrSize.load();
180180
VERIFY_EXPR(m_BufferSize.load() == m_Buffer.GetDesc().Size);
181181
if (MgrSize > m_Buffer.GetDesc().Size)
182182
{
@@ -224,8 +224,8 @@ class BufferSuballocatorImpl final : public ObjectBase<IBufferSuballocator>
224224
{
225225
// After the resize, the actual buffer size may be larger due to alignment
226226
// requirements (for sparse buffers, the size is aligned by the memory page size).
227-
const auto BufferSize = m_BufferSize.load();
228-
const auto MgrSize = m_Mgr.GetMaxSize();
227+
const Uint64 BufferSize = m_BufferSize.load();
228+
const OffsetType MgrSize = m_Mgr.GetMaxSize();
229229
if (BufferSize > MgrSize)
230230
{
231231
m_Mgr.Extend(StaticCast<size_t>(BufferSize - MgrSize));
@@ -309,7 +309,8 @@ class BufferSuballocatorImpl final : public ObjectBase<IBufferSuballocator>
309309
std::mutex m_MgrMtx;
310310
VariableSizeAllocationsManager m_Mgr;
311311

312-
std::atomic<VariableSizeAllocationsManager::OffsetType> m_MgrSize{0};
312+
using OffsetType = VariableSizeAllocationsManager::OffsetType;
313+
std::atomic<OffsetType> m_MgrSize{0};
313314

314315
DynamicBuffer m_Buffer;
315316
std::atomic<Uint64> m_BufferSize{0};
@@ -349,7 +350,7 @@ void CreateBufferSuballocator(IRenderDevice* pDevice,
349350
{
350351
try
351352
{
352-
auto* pAllocator = MakeNewRCObj<BufferSuballocatorImpl>()(pDevice, CreateInfo);
353+
BufferSuballocatorImpl* pAllocator = MakeNewRCObj<BufferSuballocatorImpl>()(pDevice, CreateInfo);
353354
pAllocator->QueryInterface(IID_BufferSuballocator, reinterpret_cast<IObject**>(ppBufferSuballocator));
354355
}
355356
catch (...)

Graphics/GraphicsTools/src/BytecodeCache.cpp

Lines changed: 11 additions & 9 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
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -111,7 +111,7 @@ class BytecodeCacheImpl final : public ObjectBase<IBytecodeCache>
111111
BytecodeCacheElementHeader ElementHeader;
112112
ElementHeader.Serialize(Stream);
113113

114-
auto pBytecode = DataBlobImpl::Create(ElementHeader.DataSize);
114+
RefCntAutoPtr<DataBlobImpl> pBytecode = DataBlobImpl::Create(ElementHeader.DataSize);
115115
Stream.CopyBytes(pBytecode->GetDataPtr(), ElementHeader.DataSize);
116116
m_HashMap.emplace(ElementHeader.Hash, pBytecode);
117117
}
@@ -123,27 +123,29 @@ class BytecodeCacheImpl final : public ObjectBase<IBytecodeCache>
123123
{
124124
DEV_CHECK_ERR(ppByteCode != nullptr, "ppByteCode must not be null.");
125125
DEV_CHECK_ERR(*ppByteCode == nullptr, "*ppByteCode is not null. Make sure you are not overwriting reference to an existing object as this may result in memory leaks.");
126-
const auto Hash = ComputeHash(ShaderCI);
126+
const XXH128Hash Hash = ComputeHash(ShaderCI);
127+
127128
const auto Iter = m_HashMap.find(Hash);
128129
if (Iter != m_HashMap.end())
129130
{
130-
auto pObject = Iter->second;
131-
*ppByteCode = pObject.Detach();
131+
RefCntAutoPtr<IDataBlob> pObject = Iter->second;
132+
*ppByteCode = pObject.Detach();
132133
}
133134
}
134135

135136
virtual void DILIGENT_CALL_TYPE AddBytecode(const ShaderCreateInfo& ShaderCI, IDataBlob* pByteCode) override final
136137
{
137138
DEV_CHECK_ERR(pByteCode != nullptr, "pByteCode must not be null.");
138-
const auto Hash = ComputeHash(ShaderCI);
139+
const XXH128Hash Hash = ComputeHash(ShaderCI);
140+
139141
const auto Iter = m_HashMap.emplace(Hash, pByteCode);
140142
if (!Iter.second)
141143
Iter.first->second = pByteCode;
142144
}
143145

144146
virtual void DILIGENT_CALL_TYPE RemoveBytecode(const ShaderCreateInfo& ShaderCI) override final
145147
{
146-
const auto Hash = ComputeHash(ShaderCI);
148+
const XXH128Hash Hash = ComputeHash(ShaderCI);
147149
m_HashMap.erase(Hash);
148150
}
149151

@@ -160,7 +162,7 @@ class BytecodeCacheImpl final : public ObjectBase<IBytecodeCache>
160162

161163
for (auto const& Pair : m_HashMap)
162164
{
163-
const auto& pBytecode = Pair.second;
165+
const RefCntAutoPtr<IDataBlob>& pBytecode = Pair.second;
164166

165167
BytecodeCacheElementHeader ElementHeader;
166168
ElementHeader.Hash = Pair.first;
@@ -174,7 +176,7 @@ class BytecodeCacheImpl final : public ObjectBase<IBytecodeCache>
174176
Serializer<SerializerMode::Measure> MeasureStream{};
175177
WriteData(MeasureStream);
176178

177-
const auto Memory = MeasureStream.AllocateData(DefaultRawMemoryAllocator::GetAllocator());
179+
const SerializedData Memory = MeasureStream.AllocateData(DefaultRawMemoryAllocator::GetAllocator());
178180

179181
Serializer<SerializerMode::Write> WriteStream{Memory};
180182
WriteData(WriteStream);

Graphics/GraphicsTools/src/DurationQueryHelper.cpp

Lines changed: 6 additions & 6 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");
@@ -63,11 +63,11 @@ void DurationQueryHelper::Begin(IDeviceContext* pCtx)
6363
m_AvailableQueries.emplace_back(m_pDevice);
6464
}
6565

66-
auto DurationQuery = std::move(m_AvailableQueries.back());
66+
DurationQuery Query = std::move(m_AvailableQueries.back());
6767
m_AvailableQueries.pop_back();
6868

69-
pCtx->EndQuery(DurationQuery.StartTimestamp);
70-
m_PendingQueries.push_front(std::move(DurationQuery));
69+
pCtx->EndQuery(Query.StartTimestamp);
70+
m_PendingQueries.push_front(std::move(Query));
7171
}
7272

7373
bool DurationQueryHelper::End(IDeviceContext* pCtx, double& Duration)
@@ -85,12 +85,12 @@ bool DurationQueryHelper::End(IDeviceContext* pCtx, double& Duration)
8585

8686
pCtx->EndQuery(m_PendingQueries.front().EndTimestamp);
8787

88-
auto& LastQuery = m_PendingQueries.back();
88+
DurationQuery& LastQuery = m_PendingQueries.back();
8989

9090
QueryDataTimestamp StartTimestampData;
9191

9292
// Do not invalidate the query until we also get end timestamp
93-
auto DataAvailable = LastQuery.StartTimestamp->GetData(&StartTimestampData, sizeof(StartTimestampData), false);
93+
bool DataAvailable = LastQuery.StartTimestamp->GetData(&StartTimestampData, sizeof(StartTimestampData), false);
9494
if (DataAvailable)
9595
{
9696
QueryDataTimestamp EndTimestampData;

Graphics/GraphicsTools/src/DynamicTextureArray.cpp

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2023 Diligent Graphics LLC
2+
* Copyright 2019-2025 Diligent Graphics LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -44,21 +44,21 @@ bool VerifySparseTextureCompatibility(IRenderDevice* pDevice, const TextureDesc&
4444
{
4545
VERIFY_EXPR(pDevice != nullptr);
4646

47-
const auto& DeviceInfo = pDevice->GetDeviceInfo().Features;
47+
const DeviceFeatures& DeviceInfo = pDevice->GetDeviceInfo().Features;
4848
if (!DeviceInfo.SparseResources)
4949
{
5050
LOG_WARNING_MESSAGE("SparseResources device feature is not enabled.");
5151
return false;
5252
}
5353

54-
const auto& SparseRes = pDevice->GetAdapterInfo().SparseResources;
54+
const SparseResourceProperties& SparseRes = pDevice->GetAdapterInfo().SparseResources;
5555
if ((SparseRes.CapFlags & SPARSE_RESOURCE_CAP_FLAG_TEXTURE_2D_ARRAY_MIP_TAIL) == 0)
5656
{
5757
LOG_WARNING_MESSAGE("This device does not support sparse texture 2D arrays with mip tails.");
5858
return false;
5959
}
6060

61-
const auto& SparseInfo = pDevice->GetSparseTextureFormatInfo(Desc.Format, Desc.Type, Desc.SampleCount);
61+
const SparseTextureFormatInfo& SparseInfo = pDevice->GetSparseTextureFormatInfo(Desc.Format, Desc.Type, Desc.SampleCount);
6262
if ((SparseInfo.BindFlags & Desc.BindFlags) != Desc.BindFlags)
6363
{
6464
LOG_WARNING_MESSAGE("The following bind flags requested for the sparse dynamic texture array are not supported by device: ", GetBindFlagsString(Desc.BindFlags & ~SparseInfo.BindFlags, ", "));
@@ -114,16 +114,16 @@ void DynamicTextureArray::CreateSparseTexture(IRenderDevice* pDevice)
114114
return;
115115
}
116116

117-
const auto& AdapterInfo = pDevice->GetAdapterInfo();
118-
const auto& DeviceInfo = pDevice->GetDeviceInfo();
117+
const GraphicsAdapterInfo& AdapterInfo = pDevice->GetAdapterInfo();
118+
const RenderDeviceInfo& DeviceInfo = pDevice->GetDeviceInfo();
119119

120120
{
121121
// Some implementations may return UINT64_MAX, so limit the maximum memory size per resource.
122122
// Some implementations will fail to create texture even if size is less than ResourceSpaceSize.
123-
const auto MaxMemorySize = std::min(Uint64{1} << 40, AdapterInfo.SparseResources.ResourceSpaceSize) >> 1;
124-
const auto MipProps = GetMipLevelProperties(m_Desc, 0);
123+
const Uint64 MaxMemorySize = std::min(Uint64{1} << 40, AdapterInfo.SparseResources.ResourceSpaceSize) >> 1;
124+
const MipLevelProperties MipProps = GetMipLevelProperties(m_Desc, 0);
125125

126-
auto TmpDesc = m_Desc;
126+
TextureDesc TmpDesc = m_Desc;
127127
// Reserve the maximum available number of slices
128128
TmpDesc.ArraySize = AdapterInfo.Texture.MaxTexture2DArraySlices;
129129
// Account for the maximum virtual space size
@@ -157,7 +157,7 @@ void DynamicTextureArray::CreateSparseTexture(IRenderDevice* pDevice)
157157
m_Desc.ArraySize = 0;
158158
}
159159

160-
const auto& TexSparseProps = m_pTexture->GetSparseProperties();
160+
const SparseTextureProperties& TexSparseProps = m_pTexture->GetSparseProperties();
161161
if ((TexSparseProps.Flags & SPARSE_TEXTURE_FLAG_SINGLE_MIPTAIL) != 0)
162162
{
163163
LOG_WARNING_MESSAGE("This device requires single mip tail for the sparse texture 2D array, which is not suitable for the dynamic array.");
@@ -166,12 +166,12 @@ void DynamicTextureArray::CreateSparseTexture(IRenderDevice* pDevice)
166166
return;
167167
}
168168

169-
const auto NumNormalMips = std::min(m_Desc.MipLevels, TexSparseProps.FirstMipInTail);
169+
const Uint32 NumNormalMips = std::min(m_Desc.MipLevels, TexSparseProps.FirstMipInTail);
170170
// Compute the total number of blocks in one slice
171171
Uint64 NumBlocksInSlice = 0;
172172
for (Uint32 Mip = 0; Mip < NumNormalMips; ++Mip)
173173
{
174-
const auto NumTilesInMip = GetNumSparseTilesInMipLevel(m_Desc, TexSparseProps.TileSize, Mip);
174+
const uint3 NumTilesInMip = GetNumSparseTilesInMipLevel(m_Desc, TexSparseProps.TileSize, Mip);
175175
NumBlocksInSlice += Uint64{NumTilesInMip.x} * Uint64{NumTilesInMip.y} * Uint64{NumTilesInMip.z};
176176
}
177177

@@ -234,8 +234,8 @@ void DynamicTextureArray::CreateResources(IRenderDevice* pDevice)
234234
// NB: m_Desc.Usage may be changed by CreateSparseTexture()
235235
if (m_Desc.Usage == USAGE_DEFAULT && m_PendingSize > 0)
236236
{
237-
auto Desc = m_Desc;
238-
Desc.ArraySize = m_PendingSize;
237+
TextureDesc Desc = m_Desc;
238+
Desc.ArraySize = m_PendingSize;
239239
pDevice->CreateTexture(Desc, nullptr, &m_pTexture);
240240
if (m_Desc.ArraySize == 0)
241241
{
@@ -256,28 +256,28 @@ void DynamicTextureArray::ResizeSparseTexture(IDeviceContext* pContext)
256256

257257
m_PendingSize = AlignUp(m_PendingSize, m_NumSlicesInPage);
258258

259-
const auto RequiredMemSize = (m_PendingSize / m_NumSlicesInPage) * m_MemoryPageSize;
259+
const Uint64 RequiredMemSize = (m_PendingSize / m_NumSlicesInPage) * m_MemoryPageSize;
260260
if (RequiredMemSize > m_pMemory->GetCapacity())
261261
m_pMemory->Resize(RequiredMemSize); // Allocate additional memory
262262

263-
const auto NumSlicesToBind = m_PendingSize > m_Desc.ArraySize ?
263+
const Uint32 NumSlicesToBind = m_PendingSize > m_Desc.ArraySize ?
264264
m_PendingSize - m_Desc.ArraySize :
265265
m_Desc.ArraySize - m_PendingSize;
266266

267-
auto CurrMemOffset = Uint64{(m_PendingSize > m_Desc.ArraySize ? m_Desc.ArraySize : m_PendingSize) / m_NumSlicesInPage} * m_MemoryPageSize;
267+
Uint64 CurrMemOffset = Uint64{(m_PendingSize > m_Desc.ArraySize ? m_Desc.ArraySize : m_PendingSize) / m_NumSlicesInPage} * m_MemoryPageSize;
268268

269-
const auto& TexSparseProps = m_pTexture->GetSparseProperties();
270-
const auto NumNormalMips = std::min(m_Desc.MipLevels, TexSparseProps.FirstMipInTail);
271-
const auto HasMipTail = m_Desc.MipLevels > TexSparseProps.FirstMipInTail;
269+
const SparseTextureProperties& TexSparseProps = m_pTexture->GetSparseProperties();
270+
const Uint32 NumNormalMips = std::min(m_Desc.MipLevels, TexSparseProps.FirstMipInTail);
271+
const bool HasMipTail = m_Desc.MipLevels > TexSparseProps.FirstMipInTail;
272272

273273
std::vector<SparseTextureMemoryBindInfo> TexBinds;
274274
TexBinds.reserve(size_t{NumSlicesToBind} * (HasMipTail ? 2 : 1));
275275
std::vector<SparseTextureMemoryBindRange> MipRanges(size_t{NumSlicesToBind} * (size_t{NumNormalMips} + (HasMipTail ? 1 : 0)));
276276

277-
auto range_it = MipRanges.begin();
278-
auto StartSlice = std::min(m_Desc.ArraySize, m_PendingSize);
279-
auto EndSlice = std::max(m_Desc.ArraySize, m_PendingSize);
280-
for (auto Slice = StartSlice; Slice != EndSlice; ++Slice)
277+
auto range_it = MipRanges.begin();
278+
Uint32 StartSlice = std::min(m_Desc.ArraySize, m_PendingSize);
279+
Uint32 EndSlice = std::max(m_Desc.ArraySize, m_PendingSize);
280+
for (Uint32 Slice = StartSlice; Slice != EndSlice; ++Slice)
281281
{
282282
// Bind normal mip levels
283283
{
@@ -287,18 +287,18 @@ void DynamicTextureArray::ResizeSparseTexture(IDeviceContext* pContext)
287287
NormalMipBindInfo.NumRanges = NumNormalMips;
288288
for (Uint32 Mip = 0; Mip < NumNormalMips; ++Mip, ++range_it)
289289
{
290-
const auto MipProps = GetMipLevelProperties(m_Desc, Mip);
290+
const MipLevelProperties MipProps = GetMipLevelProperties(m_Desc, Mip);
291291

292292
range_it->ArraySlice = Slice;
293293
range_it->MipLevel = Mip;
294294
range_it->Region = Box{0, MipProps.StorageWidth, 0, MipProps.StorageHeight, 0, MipProps.Depth};
295295

296296
if (Slice >= m_Desc.ArraySize)
297297
{
298-
const auto NumTilesInMip = GetNumSparseTilesInBox(range_it->Region, TexSparseProps.TileSize);
299-
range_it->pMemory = m_pMemory;
300-
range_it->MemoryOffset = CurrMemOffset;
301-
range_it->MemorySize = Uint64{NumTilesInMip.x} * NumTilesInMip.y * NumTilesInMip.z * TexSparseProps.BlockSize;
298+
const uint3 NumTilesInMip = GetNumSparseTilesInBox(range_it->Region, TexSparseProps.TileSize);
299+
range_it->pMemory = m_pMemory;
300+
range_it->MemoryOffset = CurrMemOffset;
301+
range_it->MemorySize = Uint64{NumTilesInMip.x} * NumTilesInMip.y * NumTilesInMip.z * TexSparseProps.BlockSize;
302302

303303
CurrMemOffset += range_it->MemorySize;
304304
}
@@ -383,8 +383,8 @@ void DynamicTextureArray::ResizeDefaultTexture(IDeviceContext* pContext)
383383
{
384384
VERIFY_EXPR(m_PendingSize != m_Desc.ArraySize);
385385
VERIFY_EXPR(m_pTexture && m_pStaleTexture);
386-
const auto& SrcTexDesc = m_pStaleTexture->GetDesc();
387-
const auto& DstTexDesc = m_pTexture->GetDesc();
386+
const TextureDesc& SrcTexDesc = m_pStaleTexture->GetDesc();
387+
const TextureDesc& DstTexDesc = m_pTexture->GetDesc();
388388
VERIFY_EXPR(SrcTexDesc.MipLevels == DstTexDesc.MipLevels);
389389

390390
CopyTextureAttribs CopyAttribs;
@@ -393,7 +393,7 @@ void DynamicTextureArray::ResizeDefaultTexture(IDeviceContext* pContext)
393393
CopyAttribs.SrcTextureTransitionMode = RESOURCE_STATE_TRANSITION_MODE_TRANSITION;
394394
CopyAttribs.DstTextureTransitionMode = RESOURCE_STATE_TRANSITION_MODE_TRANSITION;
395395

396-
const auto NumSlicesToCopy = std::min(SrcTexDesc.ArraySize, DstTexDesc.ArraySize);
396+
const Uint32 NumSlicesToCopy = std::min(SrcTexDesc.ArraySize, DstTexDesc.ArraySize);
397397
for (Uint32 slice = 0; slice < NumSlicesToCopy; ++slice)
398398
{
399399
for (Uint32 mip = 0; mip < SrcTexDesc.MipLevels; ++mip)

0 commit comments

Comments
 (0)