From a0488c54c6c5017c71198d8b13c9ed75894791de Mon Sep 17 00:00:00 2001 From: azhirnov Date: Wed, 16 Sep 2020 22:41:57 +0300 Subject: use NUM_SHADER_TYPES constant instead of magic number, use std::array instead of c-style array. --- Graphics/GraphicsEngineD3D11/include/PipelineStateD3D11Impl.hpp | 4 ++-- .../GraphicsEngineD3D11/include/ShaderResourceBindingD3D11Impl.hpp | 7 ++++--- Graphics/GraphicsEngineD3D11/src/PipelineStateD3D11Impl.cpp | 2 ++ .../GraphicsEngineD3D11/src/ShaderResourceBindingD3D11Impl.cpp | 7 ++++--- 4 files changed, 12 insertions(+), 8 deletions(-) (limited to 'Graphics/GraphicsEngineD3D11') diff --git a/Graphics/GraphicsEngineD3D11/include/PipelineStateD3D11Impl.hpp b/Graphics/GraphicsEngineD3D11/include/PipelineStateD3D11Impl.hpp index 515f6640..10921348 100644 --- a/Graphics/GraphicsEngineD3D11/include/PipelineStateD3D11Impl.hpp +++ b/Graphics/GraphicsEngineD3D11/include/PipelineStateD3D11Impl.hpp @@ -142,9 +142,9 @@ private: // SRB memory allocator must be defined before the default shader res binding SRBMemoryAllocator m_SRBMemAllocator; - Int8 m_ResourceLayoutIndex[6] = {-1, -1, -1, -1, -1, -1}; + std::array m_ResourceLayoutIndex; - Uint16 m_StaticSamplerOffsets[MAX_SHADERS_IN_PIPELINE + 1] = {}; + std::array m_StaticSamplerOffsets = {}; struct StaticSamplerInfo { const D3DShaderResourceAttribs& Attribs; diff --git a/Graphics/GraphicsEngineD3D11/include/ShaderResourceBindingD3D11Impl.hpp b/Graphics/GraphicsEngineD3D11/include/ShaderResourceBindingD3D11Impl.hpp index b5704f96..86daad77 100644 --- a/Graphics/GraphicsEngineD3D11/include/ShaderResourceBindingD3D11Impl.hpp +++ b/Graphics/GraphicsEngineD3D11/include/ShaderResourceBindingD3D11Impl.hpp @@ -36,6 +36,7 @@ #include "ShaderResourceCacheD3D11.hpp" #include "ShaderResourceLayoutD3D11.hpp" #include "STDAllocator.hpp" +#include namespace Diligent { @@ -98,11 +99,11 @@ private: ShaderResourceCacheD3D11* m_pBoundResourceCaches = nullptr; ShaderResourceLayoutD3D11* m_pResourceLayouts = nullptr; - Int8 m_ShaderTypeIndex[6] = {}; + std::array m_ShaderTypeIndex = {}; // Resource layout index in m_ResourceLayouts[] array for every shader stage - Int8 m_ResourceLayoutIndex[6] = {-1, -1, -1, -1, -1, -1}; - Uint8 m_NumActiveShaders = 0; + std::array m_ResourceLayoutIndex; + Uint8 m_NumActiveShaders = 0; bool m_bIsStaticResourcesBound = false; }; diff --git a/Graphics/GraphicsEngineD3D11/src/PipelineStateD3D11Impl.cpp b/Graphics/GraphicsEngineD3D11/src/PipelineStateD3D11Impl.cpp index f0625c7b..87294ce1 100644 --- a/Graphics/GraphicsEngineD3D11/src/PipelineStateD3D11Impl.cpp +++ b/Graphics/GraphicsEngineD3D11/src/PipelineStateD3D11Impl.cpp @@ -50,6 +50,8 @@ PipelineStateD3D11Impl::PipelineStateD3D11Impl(IReferenceCounters* pR m_StaticSamplers (STD_ALLOCATOR_RAW_MEM(StaticSamplerInfo, GetRawAllocator(), "Allocator for vector")) // clang-format on { + m_ResourceLayoutIndex.fill(-1); + if (m_Desc.IsComputePipeline()) { auto* pCS = ValidatedCast(m_Desc.ComputePipeline.pCS); diff --git a/Graphics/GraphicsEngineD3D11/src/ShaderResourceBindingD3D11Impl.cpp b/Graphics/GraphicsEngineD3D11/src/ShaderResourceBindingD3D11Impl.cpp index ae51f277..5769d949 100644 --- a/Graphics/GraphicsEngineD3D11/src/ShaderResourceBindingD3D11Impl.cpp +++ b/Graphics/GraphicsEngineD3D11/src/ShaderResourceBindingD3D11Impl.cpp @@ -49,6 +49,7 @@ ShaderResourceBindingD3D11Impl::ShaderResourceBindingD3D11Impl(IReferenceCounter m_bIsStaticResourcesBound{false} // clang-format on { + m_ResourceLayoutIndex.fill(-1); m_NumActiveShaders = static_cast(pPSO->GetNumShaders()); // clang-format off @@ -183,7 +184,7 @@ void ShaderResourceBindingD3D11Impl::InitializeStaticResources(const IPipelineSt IShaderResourceVariable* ShaderResourceBindingD3D11Impl::GetVariableByName(SHADER_TYPE ShaderType, const char* Name) { auto Ind = GetShaderTypeIndex(ShaderType); - VERIFY_EXPR(Ind >= 0 && Ind < _countof(m_ResourceLayoutIndex)); + VERIFY_EXPR(Ind >= 0 && Ind < m_ResourceLayoutIndex.size()); auto ResLayoutIndex = m_ResourceLayoutIndex[Ind]; if (ResLayoutIndex < 0) { @@ -199,7 +200,7 @@ IShaderResourceVariable* ShaderResourceBindingD3D11Impl::GetVariableByName(SHADE Uint32 ShaderResourceBindingD3D11Impl::GetVariableCount(SHADER_TYPE ShaderType) const { auto Ind = GetShaderTypeIndex(ShaderType); - VERIFY_EXPR(Ind >= 0 && Ind < _countof(m_ResourceLayoutIndex)); + VERIFY_EXPR(Ind >= 0 && Ind < m_ResourceLayoutIndex.size()); auto ResLayoutIndex = m_ResourceLayoutIndex[Ind]; if (ResLayoutIndex < 0) { @@ -215,7 +216,7 @@ Uint32 ShaderResourceBindingD3D11Impl::GetVariableCount(SHADER_TYPE ShaderType) IShaderResourceVariable* ShaderResourceBindingD3D11Impl::GetVariableByIndex(SHADER_TYPE ShaderType, Uint32 Index) { auto Ind = GetShaderTypeIndex(ShaderType); - VERIFY_EXPR(Ind >= 0 && Ind < _countof(m_ResourceLayoutIndex)); + VERIFY_EXPR(Ind >= 0 && Ind < m_ResourceLayoutIndex.size()); auto ResLayoutIndex = m_ResourceLayoutIndex[Ind]; if (ResLayoutIndex < 0) { -- cgit v1.2.3