Diligent Engine  v.2.4.g
SRBMemoryAllocator.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2019-2021 Diligent Graphics LLC
3  * Copyright 2015-2019 Egor Yusov
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * In no event and under no legal theory, whether in tort (including negligence),
18  * contract, or otherwise, unless required by applicable law (such as deliberate
19  * and grossly negligent acts) or agreed to in writing, shall any Contributor be
20  * liable for any damages, including any direct, indirect, special, incidental,
21  * or consequential damages of any character arising as a result of this License or
22  * out of the use or inability to use the software (including but not limited to damages
23  * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
24  * all other commercial damages or losses), even if such Contributor has been advised
25  * of the possibility of such damages.
26  */
27 
28 // Helper class that handles memory allocation for shader resource binding objects
29 
30 #pragma once
31 
32 #include "../../../Common/interface/FixedBlockMemoryAllocator.hpp"
33 
34 namespace Diligent
35 {
36 
38 {
39 public:
41  m_RawMemAllocator(RawMemAllocator)
42  {}
43 
45 
46  void Initialize(Uint32 SRBAllocationGranularity,
47  Uint32 ShaderVariableDataAllocatorCount,
48  const size_t* const ShaderVariableDataSizes,
49  Uint32 ResourceCacheDataAllocatorCount,
50  const size_t* const ResourceCacheDataSizes);
51 
53  {
54  VERIFY_EXPR(m_DataAllocators == nullptr || Ind < m_ShaderVariableDataAllocatorCount);
55  return m_DataAllocators != nullptr ? m_DataAllocators[Ind] : m_RawMemAllocator;
56  }
57 
59  {
60  VERIFY_EXPR(m_DataAllocators == nullptr || Ind < m_ResourceCacheDataAllocatorCount);
61  return m_DataAllocators != nullptr ? m_DataAllocators[m_ShaderVariableDataAllocatorCount + Ind] : m_RawMemAllocator;
62  }
63 
64 private:
65  IMemoryAllocator& m_RawMemAllocator;
66 
67  // Fixed-block allocators for every shader stage
68  FixedBlockMemoryAllocator* m_DataAllocators = nullptr;
69 
70  Uint32 m_ShaderVariableDataAllocatorCount = 0;
71  Uint32 m_ResourceCacheDataAllocatorCount = 0;
72 };
73 
74 } // namespace Diligent
Diligent::SRBMemoryAllocator
Definition: SRBMemoryAllocator.hpp:37
Diligent::SRBMemoryAllocator::GetShaderVariableDataAllocator
IMemoryAllocator & GetShaderVariableDataAllocator(Uint32 Ind)
Definition: SRBMemoryAllocator.hpp:52
Diligent::SRBMemoryAllocator::~SRBMemoryAllocator
~SRBMemoryAllocator()
Definition: SRBMemoryAllocator.cpp:33
Diligent::Uint32
uint32_t Uint32
32-bit unsigned integer
Definition: BasicTypes.h:51
Diligent::SRBMemoryAllocator::SRBMemoryAllocator
SRBMemoryAllocator(IMemoryAllocator &RawMemAllocator)
Definition: SRBMemoryAllocator.hpp:40
Diligent::SRBMemoryAllocator::GetResourceCacheDataAllocator
IMemoryAllocator & GetResourceCacheDataAllocator(Uint32 Ind)
Definition: SRBMemoryAllocator.hpp:58
Diligent::IMemoryAllocator
Base interface for a raw memory allocator.
Definition: MemoryAllocator.h:41
VERIFY_EXPR
#define VERIFY_EXPR(...)
Definition: DebugUtilities.hpp:79
Diligent::SRBMemoryAllocator::Initialize
void Initialize(Uint32 SRBAllocationGranularity, Uint32 ShaderVariableDataAllocatorCount, const size_t *const ShaderVariableDataSizes, Uint32 ResourceCacheDataAllocatorCount, const size_t *const ResourceCacheDataSizes)
Definition: SRBMemoryAllocator.cpp:46
Diligent::FixedBlockMemoryAllocator
Memory allocator that allocates memory in a fixed-size chunks.
Definition: FixedBlockMemoryAllocator.hpp:56
Diligent
The library uses Direct3D-style math:
Definition: AdvancedMath.hpp:37