Skip to content

Commit 164e9d6

Browse files
BufferD3D12 and TextureD3D12: don't use auto where unnecessary
1 parent 23dbd88 commit 164e9d6

File tree

4 files changed

+73
-73
lines changed

4 files changed

+73
-73
lines changed

Graphics/GraphicsEngineD3D12/src/BufferD3D12Impl.cpp

Lines changed: 29 additions & 29 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");
@@ -114,13 +114,13 @@ BufferD3D12Impl::BufferD3D12Impl(IReferenceCounters* pRefCounters,
114114
if (!(m_Desc.BindFlags & BIND_SHADER_RESOURCE) && !(m_Desc.BindFlags & BIND_RAY_TRACING))
115115
d3d12BuffDesc.Flags |= D3D12_RESOURCE_FLAG_DENY_SHADER_RESOURCE;
116116

117-
auto* pd3d12Device = pRenderDeviceD3D12->GetD3D12Device();
117+
ID3D12Device* pd3d12Device = pRenderDeviceD3D12->GetD3D12Device();
118118

119119
if (m_Desc.Usage == USAGE_SPARSE)
120120
{
121-
auto hr = pd3d12Device->CreateReservedResource(&d3d12BuffDesc, D3D12_RESOURCE_STATE_COMMON, nullptr,
122-
__uuidof(m_pd3d12Resource),
123-
reinterpret_cast<void**>(static_cast<ID3D12Resource**>(&m_pd3d12Resource)));
121+
HRESULT hr = pd3d12Device->CreateReservedResource(&d3d12BuffDesc, D3D12_RESOURCE_STATE_COMMON, nullptr,
122+
__uuidof(m_pd3d12Resource),
123+
reinterpret_cast<void**>(static_cast<ID3D12Resource**>(&m_pd3d12Resource)));
124124
if (FAILED(hr))
125125
LOG_ERROR_AND_THROW("Failed to create D3D12 buffer");
126126

@@ -146,7 +146,7 @@ BufferD3D12Impl::BufferD3D12Impl(IReferenceCounters* pRefCounters,
146146
HeapProps.CreationNodeMask = 1;
147147
HeapProps.VisibleNodeMask = 1;
148148

149-
const auto InitialDataSize = (pBuffData != nullptr && pBuffData->pData != nullptr) ?
149+
const Uint64 InitialDataSize = (pBuffData != nullptr && pBuffData->pData != nullptr) ?
150150
std::min(pBuffData->DataSize, d3d12BuffDesc.Width) :
151151
0;
152152

@@ -156,24 +156,24 @@ BufferD3D12Impl::BufferD3D12Impl(IReferenceCounters* pRefCounters,
156156
if (!IsInKnownState())
157157
SetState(RESOURCE_STATE_UNDEFINED);
158158

159-
const auto CmdQueueInd = pBuffData && pBuffData->pContext ?
159+
const SoftwareQueueIndex CmdQueueInd = pBuffData && pBuffData->pContext ?
160160
ClassPtrCast<DeviceContextD3D12Impl>(pBuffData->pContext)->GetCommandQueueId() :
161161
SoftwareQueueIndex{PlatformMisc::GetLSB(m_Desc.ImmediateContextMask)};
162162

163-
const auto StateMask = InitialDataSize > 0 ?
163+
const D3D12_RESOURCE_STATES StateMask = InitialDataSize > 0 ?
164164
GetSupportedD3D12ResourceStatesForCommandList(pRenderDeviceD3D12->GetCommandQueueType(CmdQueueInd)) :
165165
static_cast<D3D12_RESOURCE_STATES>(~0u);
166166

167-
const auto d3d12State = ResourceStateFlagsToD3D12ResourceStates(GetState()) & StateMask;
167+
const D3D12_RESOURCE_STATES d3d12State = ResourceStateFlagsToD3D12ResourceStates(GetState()) & StateMask;
168168

169169
// By default, committed resources and heaps are almost always zeroed upon creation.
170170
// CREATE_NOT_ZEROED flag allows this to be elided in some scenarios to lower the overhead
171171
// of creating the heap. No need to zero the resource if we initialize it.
172-
const auto d3d12HeapFlags = InitialDataSize > 0 ?
172+
const D3D12_HEAP_FLAGS d3d12HeapFlags = InitialDataSize > 0 ?
173173
D3D12_HEAP_FLAG_CREATE_NOT_ZEROED :
174174
D3D12_HEAP_FLAG_NONE;
175175

176-
auto hr = pd3d12Device->CreateCommittedResource(
176+
HRESULT hr = pd3d12Device->CreateCommittedResource(
177177
&HeapProps, d3d12HeapFlags, &d3d12BuffDesc, d3d12State,
178178
nullptr, // pOptimizedClearValue
179179
__uuidof(m_pd3d12Resource),
@@ -203,7 +203,7 @@ BufferD3D12Impl::BufferD3D12Impl(IReferenceCounters* pRefCounters,
203203
if (FAILED(hr))
204204
LOG_ERROR_AND_THROW("Failed to create upload buffer");
205205

206-
const auto UploadBufferName = std::wstring{L"Upload buffer for buffer '"} + WidenString(m_Desc.Name) + L'\'';
206+
const std::wstring UploadBufferName = std::wstring{L"Upload buffer for buffer '"} + WidenString(m_Desc.Name) + L'\'';
207207
UploadBuffer->SetName(UploadBufferName.c_str());
208208

209209
void* DestAddress = nullptr;
@@ -214,7 +214,7 @@ BufferD3D12Impl::BufferD3D12Impl(IReferenceCounters* pRefCounters,
214214
memcpy(DestAddress, pBuffData->pData, StaticCast<size_t>(InitialDataSize));
215215
UploadBuffer->Unmap(0, nullptr);
216216

217-
auto InitContext = pRenderDeviceD3D12->AllocateCommandContext(CmdQueueInd);
217+
RenderDeviceD3D12Impl::PooledCommandContext InitContext = pRenderDeviceD3D12->AllocateCommandContext(CmdQueueInd);
218218
// copy data to the intermediate upload heap and then schedule a copy from the upload heap to the default buffer
219219
VERIFY_EXPR(CheckState(RESOURCE_STATE_COPY_DEST));
220220
// We MUST NOT call TransitionResource() from here, because
@@ -263,7 +263,7 @@ static BufferDesc BufferDescFromD3D12Resource(BufferDesc BuffDesc, ID3D12Resourc
263263
{
264264
DEV_CHECK_ERR(BuffDesc.Usage != USAGE_DYNAMIC, "Dynamic buffers cannot be attached to native d3d12 resource");
265265

266-
auto d3d12BuffDesc = pd3d12Buffer->GetDesc();
266+
D3D12_RESOURCE_DESC d3d12BuffDesc = pd3d12Buffer->GetDesc();
267267
DEV_CHECK_ERR(d3d12BuffDesc.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER, "D3D12 resource is not a buffer");
268268

269269
DEV_CHECK_ERR(BuffDesc.Size == 0 || BuffDesc.Size == d3d12BuffDesc.Width, "Buffer size specified by the BufferDesc (", BuffDesc.Size, ") does not match d3d12 resource size (", d3d12BuffDesc.Width, ")");
@@ -353,20 +353,20 @@ void BufferD3D12Impl::CreateViewInternal(const BufferViewDesc& OrigViewDesc, IBu
353353

354354
try
355355
{
356-
auto* pDeviceD3D12Impl = GetDevice();
357-
auto& BuffViewAllocator = pDeviceD3D12Impl->GetBuffViewObjAllocator();
356+
RenderDeviceD3D12Impl* pDeviceD3D12Impl = GetDevice();
357+
FixedBlockMemoryAllocator& BuffViewAllocator = pDeviceD3D12Impl->GetBuffViewObjAllocator();
358358
VERIFY(&BuffViewAllocator == &m_dbgBuffViewAllocator, "Buff view allocator does not match allocator provided at buffer initialization");
359359

360360
BufferViewDesc ViewDesc = OrigViewDesc;
361361
if (ViewDesc.ViewType == BUFFER_VIEW_UNORDERED_ACCESS)
362362
{
363-
auto UAVHandleAlloc = pDeviceD3D12Impl->AllocateDescriptors(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV);
363+
DescriptorHeapAllocation UAVHandleAlloc = pDeviceD3D12Impl->AllocateDescriptors(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV);
364364
CreateUAV(ViewDesc, UAVHandleAlloc.GetCpuHandle());
365365
*ppView = NEW_RC_OBJ(BuffViewAllocator, "BufferViewD3D12Impl instance", BufferViewD3D12Impl, bIsDefaultView ? this : nullptr)(GetDevice(), ViewDesc, this, std::move(UAVHandleAlloc), bIsDefaultView);
366366
}
367367
else if (ViewDesc.ViewType == BUFFER_VIEW_SHADER_RESOURCE)
368368
{
369-
auto SRVHandleAlloc = pDeviceD3D12Impl->AllocateDescriptors(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV);
369+
DescriptorHeapAllocation SRVHandleAlloc = pDeviceD3D12Impl->AllocateDescriptors(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV);
370370
CreateSRV(ViewDesc, SRVHandleAlloc.GetCpuHandle());
371371
*ppView = NEW_RC_OBJ(BuffViewAllocator, "BufferViewD3D12Impl instance", BufferViewD3D12Impl, bIsDefaultView ? this : nullptr)(GetDevice(), ViewDesc, this, std::move(SRVHandleAlloc), bIsDefaultView);
372372
}
@@ -376,7 +376,7 @@ void BufferD3D12Impl::CreateViewInternal(const BufferViewDesc& OrigViewDesc, IBu
376376
}
377377
catch (const std::runtime_error&)
378378
{
379-
const auto* ViewTypeName = GetBufferViewTypeLiteralName(OrigViewDesc.ViewType);
379+
const char* ViewTypeName = GetBufferViewTypeLiteralName(OrigViewDesc.ViewType);
380380
LOG_ERROR("Failed to create view \"", OrigViewDesc.Name ? OrigViewDesc.Name : "", "\" (", ViewTypeName, ") for buffer \"", m_Desc.Name, "\"");
381381
}
382382
}
@@ -388,7 +388,7 @@ void BufferD3D12Impl::CreateUAV(BufferViewDesc& UAVDesc, D3D12_CPU_DESCRIPTOR_HA
388388
D3D12_UNORDERED_ACCESS_VIEW_DESC D3D12_UAVDesc;
389389
BufferViewDesc_to_D3D12_UAV_DESC(m_Desc, UAVDesc, D3D12_UAVDesc);
390390

391-
auto* pd3d12Device = GetDevice()->GetD3D12Device();
391+
ID3D12Device* pd3d12Device = GetDevice()->GetD3D12Device();
392392
pd3d12Device->CreateUnorderedAccessView(m_pd3d12Resource, nullptr, &D3D12_UAVDesc, UAVDescriptor);
393393
}
394394

@@ -399,7 +399,7 @@ void BufferD3D12Impl::CreateSRV(struct BufferViewDesc& SRVDesc, D3D12_CPU_DESCRI
399399
D3D12_SHADER_RESOURCE_VIEW_DESC D3D12_SRVDesc;
400400
BufferViewDesc_to_D3D12_SRV_DESC(m_Desc, SRVDesc, D3D12_SRVDesc);
401401

402-
auto* pd3d12Device = GetDevice()->GetD3D12Device();
402+
ID3D12Device* pd3d12Device = GetDevice()->GetD3D12Device();
403403
pd3d12Device->CreateShaderResourceView(m_pd3d12Resource, &D3D12_SRVDesc, SRVDescriptor);
404404
}
405405

@@ -419,13 +419,13 @@ void BufferD3D12Impl::CreateCBV(D3D12_CPU_DESCRIPTOR_HANDLE CBVDescriptor,
419419
D3D12_CBVDesc.BufferLocation = m_pd3d12Resource->GetGPUVirtualAddress() + Offset;
420420
D3D12_CBVDesc.SizeInBytes = StaticCast<UINT>(AlignUp(Size, Uint32{D3D12_TEXTURE_DATA_PITCH_ALIGNMENT}));
421421

422-
auto* pd3d12Device = GetDevice()->GetD3D12Device();
422+
ID3D12Device* pd3d12Device = GetDevice()->GetD3D12Device();
423423
pd3d12Device->CreateConstantBufferView(&D3D12_CBVDesc, CBVDescriptor);
424424
}
425425

426426
ID3D12Resource* BufferD3D12Impl::GetD3D12Buffer(Uint64& DataStartByteOffset, IDeviceContext* pContext)
427427
{
428-
auto* pd3d12Resource = GetD3D12Resource();
428+
ID3D12Resource* pd3d12Resource = GetD3D12Resource();
429429
if (pd3d12Resource != nullptr)
430430
{
431431
VERIFY(m_Desc.Usage != USAGE_DYNAMIC || (m_Desc.BindFlags & (BIND_SHADER_RESOURCE | BIND_UNORDERED_ACCESS)) != 0, "Expected non-dynamic buffer or a buffer with SRV or UAV bind flags");
@@ -435,21 +435,21 @@ ID3D12Resource* BufferD3D12Impl::GetD3D12Buffer(Uint64& DataStartByteOffset, IDe
435435
else
436436
{
437437
VERIFY(m_Desc.Usage == USAGE_DYNAMIC, "Dynamic buffer is expected");
438-
auto* pCtxD3D12 = ClassPtrCast<DeviceContextD3D12Impl>(pContext);
438+
DeviceContextD3D12Impl* pCtxD3D12 = ClassPtrCast<DeviceContextD3D12Impl>(pContext);
439439
#ifdef DILIGENT_DEVELOPMENT
440440
DvpVerifyDynamicAllocation(pCtxD3D12);
441441
#endif
442-
auto ContextId = pCtxD3D12->GetContextId();
443-
DataStartByteOffset = m_DynamicData[ContextId].Offset;
442+
DeviceContextIndex ContextId = pCtxD3D12->GetContextId();
443+
DataStartByteOffset = m_DynamicData[ContextId].Offset;
444444
return m_DynamicData[ContextId].pBuffer;
445445
}
446446
}
447447

448448
#ifdef DILIGENT_DEVELOPMENT
449449
void BufferD3D12Impl::DvpVerifyDynamicAllocation(const DeviceContextD3D12Impl* pCtx) const
450450
{
451-
auto ContextId = pCtx->GetContextId();
452-
auto CurrentFrame = pCtx->GetFrameNumber();
451+
DeviceContextIndex ContextId = pCtx->GetContextId();
452+
Uint64 CurrentFrame = pCtx->GetFrameNumber();
453453
DEV_CHECK_ERR(m_DynamicData[ContextId].GPUAddress != 0, "Dynamic buffer '", m_Desc.Name, "' has not been mapped before its first use. Context Id: ", ContextId, ". Note: memory for dynamic buffers is allocated when a buffer is mapped.");
454454
DEV_CHECK_ERR(m_DynamicData[ContextId].DvpCtxFrameNumber == CurrentFrame, "Dynamic allocation of dynamic buffer '", m_Desc.Name, "' in frame ", CurrentFrame, " is out-of-date. Note: contents of all dynamic resources is discarded at the end of every frame. A buffer must be mapped before its first use in any frame.");
455455
VERIFY(GetState() == RESOURCE_STATE_GENERIC_READ, "Dynamic buffers are expected to always be in RESOURCE_STATE_GENERIC_READ state");
@@ -471,7 +471,7 @@ SparseBufferProperties BufferD3D12Impl::GetSparseProperties() const
471471
DEV_CHECK_ERR(m_Desc.Usage == USAGE_SPARSE,
472472
"IBuffer::GetSparseProperties() must only be used for sparse buffer");
473473

474-
auto* pd3d12Device = m_pDevice->GetD3D12Device();
474+
ID3D12Device* pd3d12Device = m_pDevice->GetD3D12Device();
475475

476476
UINT NumTilesForEntireResource = 0;
477477
D3D12_TILE_SHAPE StandardTileShapeForNonPackedMips{};

0 commit comments

Comments
 (0)