Skip to content

Commit 2802d61

Browse files
DXCompiler: don't use auto where unnecessary
1 parent a65fdaa commit 2802d61

File tree

1 file changed

+30
-30
lines changed

1 file changed

+30
-30
lines changed

Graphics/ShaderTools/src/DXCompiler.cpp

Lines changed: 30 additions & 30 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");
@@ -213,7 +213,7 @@ class DxcIncludeHandlerImpl final : public IDxcIncludeHandler
213213
return E_FAIL;
214214
}
215215

216-
auto pFileData = DataBlobImpl::Create();
216+
RefCntAutoPtr<DataBlobImpl> pFileData = DataBlobImpl::Create();
217217
pSourceStream->ReadBlob(pFileData);
218218

219219
CComPtr<IDxcBlobEncoding> pSourceBlob;
@@ -259,7 +259,7 @@ class DxcBlobWrapper final : public IDxcBlob
259259
public:
260260
static void Create(IDataBlob* pDataBlob, IDxcBlob** ppBlob)
261261
{
262-
auto* pBlob = new DxcBlobWrapper{pDataBlob};
262+
DxcBlobWrapper* pBlob = new DxcBlobWrapper{pDataBlob};
263263
pBlob->QueryInterface(__uuidof(IDxcBlob), reinterpret_cast<void**>(ppBlob));
264264
}
265265

@@ -290,7 +290,7 @@ class DxcBlobWrapper final : public IDxcBlob
290290

291291
virtual ULONG STDMETHODCALLTYPE Release(void) override final
292292
{
293-
auto RemainingRefs = m_RefCount.fetch_add(-1) - 1;
293+
long RemainingRefs = m_RefCount.fetch_add(-1) - 1;
294294
if (RemainingRefs == 0)
295295
delete this;
296296

@@ -438,8 +438,8 @@ bool DXCompilerImpl::ValidateAndSign(DxcCreateInstanceProc CreateInstance, IDxcL
438438
pdxcResult->GetErrorBuffer(&pdxcOutput);
439439
library->GetBlobAsUtf8(pdxcOutput, &pdxcOutputUtf8);
440440

441-
const auto ValidationMsgLen = pdxcOutputUtf8 ? pdxcOutputUtf8->GetBufferSize() : 0;
442-
const auto* ValidationMsg = ValidationMsgLen > 0 ? static_cast<const char*>(pdxcOutputUtf8->GetBufferPointer()) : "";
441+
const SIZE_T ValidationMsgLen = pdxcOutputUtf8 ? pdxcOutputUtf8->GetBufferSize() : 0;
442+
const char* ValidationMsg = ValidationMsgLen > 0 ? static_cast<const char*>(pdxcOutputUtf8->GetBufferPointer()) : "";
443443

444444
LOG_ERROR_MESSAGE("Shader validation failed: ", ValidationMsg);
445445
return false;
@@ -468,7 +468,7 @@ class ShaderReflectionViaLibraryReflection final : public ID3D12ShaderReflection
468468
ULONG STDMETHODCALLTYPE Release() override
469469
{
470470
VERIFY(m_RefCount > 0, "Inconsistent call to ReleaseStrongRef()");
471-
auto RefCount = m_RefCount.fetch_add(-1) - 1;
471+
long RefCount = m_RefCount.fetch_add(-1) - 1;
472472
if (RefCount == 0)
473473
{
474474
delete this;
@@ -657,7 +657,7 @@ void DXCompilerImpl::GetD3D12ShaderReflection(IDxcBlob* pShaderBy
657657
UINT32 shaderIdx = 0;
658658
CHECK_D3D_RESULT(pdxcReflection->FindFirstPartKind(DXC_PART_DXIL, &shaderIdx), "Failed to get the shader reflection");
659659

660-
auto hr = pdxcReflection->GetPartReflection(shaderIdx, IID_PPV_ARGS(ppShaderReflection));
660+
HRESULT hr = pdxcReflection->GetPartReflection(shaderIdx, IID_PPV_ARGS(ppShaderReflection));
661661
if (SUCCEEDED(hr))
662662
return;
663663

@@ -673,7 +673,7 @@ void DXCompilerImpl::GetD3D12ShaderReflection(IDxcBlob* pShaderBy
673673
}
674674
# endif
675675

676-
if (auto* pFunc = pd3d12LibRefl->GetFunctionByIndex(0))
676+
if (ID3D12FunctionReflection* pFunc = pd3d12LibRefl->GetFunctionByIndex(0))
677677
{
678678
*ppShaderReflection = new ShaderReflectionViaLibraryReflection{std::move(pd3d12LibRefl), pFunc};
679679
(*ppShaderReflection)->AddRef();
@@ -719,7 +719,7 @@ void DXCompilerImpl::Compile(const ShaderCreateInfo& ShaderCI,
719719
ShaderModel = MaxSM;
720720
}
721721

722-
const auto Profile = GetHLSLProfileString(ShaderCI.Desc.ShaderType, ShaderModel);
722+
const String Profile = GetHLSLProfileString(ShaderCI.Desc.ShaderType, ShaderModel);
723723
const std::wstring wstrProfile{Profile.begin(), Profile.end()};
724724
const std::wstring wstrEntryPoint{ShaderCI.EntryPoint, ShaderCI.EntryPoint + strlen(ShaderCI.EntryPoint)};
725725

@@ -781,9 +781,9 @@ void DXCompilerImpl::Compile(const ShaderCreateInfo& ShaderCI,
781781

782782
IDXCompiler::CompileAttribs CA;
783783

784-
const auto Source = BuildHLSLSourceString(ShaderCI, ExtraDefinitions);
784+
const String Source = BuildHLSLSourceString(ShaderCI, ExtraDefinitions);
785785

786-
DxcDefine Defines[] = {{L"DXCOMPILER", L""}};
786+
DxcDefine Defines[] = {{L"DXCOMPILER", L"1"}};
787787

788788
CA.Source = Source.c_str();
789789
CA.SourceLength = static_cast<Uint32>(Source.length());
@@ -797,7 +797,7 @@ void DXCompilerImpl::Compile(const ShaderCreateInfo& ShaderCI,
797797
CA.ppBlobOut = &pDXIL;
798798
CA.ppCompilerOutput = &pDxcLog;
799799

800-
auto result = Compile(CA);
800+
bool result = Compile(CA);
801801
HandleHLSLCompilerResult(result, pDxcLog.p, Source, ShaderCI.Desc.Name, ppCompilerOutput);
802802

803803
if (result && pDXIL && pDXIL->GetBufferSize() > 0)
@@ -880,10 +880,10 @@ bool DXCompilerImpl::RemapResourceBindings(const TResourceBindingMap& ResourceMa
880880
D3D12_SHADER_INPUT_BIND_DESC ResDesc = {};
881881
if (pd3d12Reflection->GetResourceBindingDescByName(NameAndBinding.first.GetStr(), &ResDesc) == S_OK)
882882
{
883-
auto& Ext = ExtResourceMap[&NameAndBinding];
884-
Ext.SrcBindPoint = ResDesc.BindPoint;
885-
Ext.SrcArraySize = ResDesc.BindCount;
886-
Ext.SrcSpace = ResDesc.Space;
883+
ResourceExtendedInfo& Ext = ExtResourceMap[&NameAndBinding];
884+
Ext.SrcBindPoint = ResDesc.BindPoint;
885+
Ext.SrcArraySize = ResDesc.BindCount;
886+
Ext.SrcSpace = ResDesc.Space;
887887

888888
# ifdef NO_D3D_SIT_ACCELSTRUCT_FEEDBACK_TEX
889889
switch (int{ResDesc.Type}) // Prevent "not a valid value for switch of enum '_D3D_SHADER_INPUT_TYPE'" warning
@@ -1208,11 +1208,11 @@ void DXCompilerImpl::PatchResourceDeclarationRT(const TResourceBindingMap& Resou
12081208
//
12091209
// !158 = !{i32 0, %"class.RWTexture2D<vector<float, 4> >"* @"\01?g_ColorBuffer@@3V?$RWTexture2D@V?$vector@M$03@@@@A", !"g_ColorBuffer", i32 -1, i32 -1, i32 1, i32 2, i1 false, i1 false, i1 false, !159}
12101210

1211-
const auto* Name = ResPair.first.GetStr();
1212-
const auto Space = ResPair.second.Space;
1213-
const auto BindPoint = ResPair.second.BindPoint;
1214-
const auto DxilName = String{"!\""} + Name + "\"";
1215-
auto& Ext = ExtResMap[&ResPair];
1211+
const char* Name = ResPair.first.GetStr();
1212+
const Uint32 Space = ResPair.second.Space;
1213+
const Uint32 BindPoint = ResPair.second.BindPoint;
1214+
const String DxilName = String{"!\""} + Name + "\"";
1215+
ResourceExtendedInfo& Ext = ExtResMap[&ResPair];
12161216

12171217
size_t pos = DXIL.find(DxilName);
12181218
if (pos == String::npos)
@@ -1314,7 +1314,7 @@ void DXCompilerImpl::PatchResourceDeclaration(const TResourceBindingMap& Resourc
13141314
// , i32 -1
13151315
// ^
13161316

1317-
auto RecordEndPos = DXIL.find_first_not_of(NumberSymbols, pos);
1317+
size_t RecordEndPos = DXIL.find_first_not_of(NumberSymbols, pos);
13181318
if (pos == String::npos)
13191319
return false;
13201320
// , i32 -1
@@ -2147,9 +2147,9 @@ void DXCompilerImpl::PatchCreateHandleFromBinding(const TResourceBindingMap& Res
21472147

21482148
bool IsDXILBytecode(const void* pBytecode, size_t Size)
21492149
{
2150-
const auto* data_begin = reinterpret_cast<const uint8_t*>(pBytecode);
2151-
const auto* data_end = data_begin + Size;
2152-
const auto* ptr = data_begin;
2150+
const uint8_t* data_begin = static_cast<const uint8_t*>(pBytecode);
2151+
const uint8_t* data_end = data_begin + Size;
2152+
const uint8_t* ptr = data_begin;
21532153

21542154
if (ptr + sizeof(hlsl::DxilContainerHeader) > data_end)
21552155
{
@@ -2159,7 +2159,7 @@ bool IsDXILBytecode(const void* pBytecode, size_t Size)
21592159

21602160
// A DXIL container is composed of a header, a sequence of part lengths, and a sequence of parts.
21612161
// https://github.com/microsoft/DirectXShaderCompiler/blob/master/docs/DXIL.rst#dxil-container-format
2162-
const auto& ContainerHeader = *reinterpret_cast<const hlsl::DxilContainerHeader*>(ptr);
2162+
const hlsl::DxilContainerHeader& ContainerHeader = *reinterpret_cast<const hlsl::DxilContainerHeader*>(ptr);
21632163
if (ContainerHeader.HeaderFourCC != hlsl::DFCC_Container)
21642164
{
21652165
// Incorrect FourCC
@@ -2182,17 +2182,17 @@ bool IsDXILBytecode(const void* pBytecode, size_t Size)
21822182
return false;
21832183
}
21842184

2185-
const auto* PartOffsets = reinterpret_cast<const uint32_t*>(ptr);
2185+
const uint32_t* PartOffsets = reinterpret_cast<const uint32_t*>(ptr);
21862186
for (uint32_t part = 0; part < ContainerHeader.PartCount; ++part)
21872187
{
2188-
const auto Offset = PartOffsets[part];
2188+
const uint32_t Offset = PartOffsets[part];
21892189
if (data_begin + Offset + sizeof(hlsl::DxilPartHeader) > data_end)
21902190
{
21912191
// No space for the part header
21922192
return false;
21932193
}
21942194

2195-
const auto& PartHeader = *reinterpret_cast<const hlsl::DxilPartHeader*>(data_begin + Offset);
2195+
const hlsl::DxilPartHeader& PartHeader = *reinterpret_cast<const hlsl::DxilPartHeader*>(data_begin + Offset);
21962196
if (PartHeader.PartFourCC == hlsl::DFCC_DXIL)
21972197
{
21982198
// We found DXIL part

0 commit comments

Comments
 (0)