From 772ef0e6cfbb218814ad4e7d25dd94b697a6b4f3 Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Tue, 5 Mar 2019 22:05:17 -0800 Subject: Keep fixing Metal backend + few other minor changes --- Graphics/GLSLTools/include/SPIRVShaderResources.h | 6 ++++-- Graphics/GLSLTools/src/SPIRVShaderResources.cpp | 9 ++++++--- 2 files changed, 10 insertions(+), 5 deletions(-) (limited to 'Graphics/GLSLTools') diff --git a/Graphics/GLSLTools/include/SPIRVShaderResources.h b/Graphics/GLSLTools/include/SPIRVShaderResources.h index 523ccc29..b117c05a 100644 --- a/Graphics/GLSLTools/include/SPIRVShaderResources.h +++ b/Graphics/GLSLTools/include/SPIRVShaderResources.h @@ -28,8 +28,8 @@ // SPIRVShaderResources class uses continuous chunk of memory to store all resources, as follows: // -// m_MemoryBuffer m_TotalResources -// | | +// m_MemoryBuffer m_TotalResources end of names data may not be aligned +// | | | // | Uniform Buffers | Storage Buffers | Storage Images | Sampled Images | Atomic Counters | Separate Samplers | Separate Images | Stage Inputs | Resource Names | #include @@ -333,6 +333,8 @@ private: // Memory buffer that holds all resources as continuous chunk of memory: // | UBs | SBs | StrgImgs | SmplImgs | ACs | SepSamplers | SepImgs | Stage Inputs | Resource Names | + // | + // end of names data may not be aligned std::unique_ptr< void, STDDeleterRawMem > m_MemoryBuffer; StringPool m_ResourceNames; diff --git a/Graphics/GLSLTools/src/SPIRVShaderResources.cpp b/Graphics/GLSLTools/src/SPIRVShaderResources.cpp index 7289e9fd..82743cfd 100644 --- a/Graphics/GLSLTools/src/SPIRVShaderResources.cpp +++ b/Graphics/GLSLTools/src/SPIRVShaderResources.cpp @@ -28,6 +28,7 @@ #include "ShaderBase.h" #include "GraphicsAccessories.h" #include "StringTools.h" +#include "Align.h" namespace Diligent { @@ -439,10 +440,12 @@ void SPIRVShaderResources::Initialize(IMemoryAllocator& Allocator, VERIFY(NumShaderStageInputs <= MaxOffset, "Max offset exceeded"); m_NumShaderStageInputs = static_cast(NumShaderStageInputs); + auto AlignedResourceNamesPoolSize = Align(ResourceNamesPoolSize, sizeof(void*)); + static_assert(sizeof(SPIRVShaderResourceAttribs) % sizeof(void*) == 0, "Size of SPIRVShaderResourceAttribs struct must be multiple of sizeof(void*)"); - auto MemorySize = m_TotalResources * sizeof(SPIRVShaderResourceAttribs) + - m_NumShaderStageInputs * sizeof(SPIRVShaderStageInputAttribs) + - ResourceNamesPoolSize * sizeof(char); + auto MemorySize = m_TotalResources * sizeof(SPIRVShaderResourceAttribs) + + m_NumShaderStageInputs * sizeof(SPIRVShaderStageInputAttribs) + + AlignedResourceNamesPoolSize * sizeof(char); VERIFY_EXPR(GetNumUBs() == Counters.NumUBs); VERIFY_EXPR(GetNumSBs() == Counters.NumSBs); -- cgit v1.2.3