@@ -76,31 +76,10 @@ class NBL_API IDescriptorPool : public core::IReferenceCounted, public IBackendO
76
76
m_maxDescriptorCount[static_cast <uint32_t >(poolSizes[i].type )] += poolSizes[i].count ;
77
77
78
78
for (auto i = 0 ; i < static_cast <uint32_t >(asset::IDescriptor::E_TYPE::ET_COUNT); ++i)
79
- {
80
- if (m_maxDescriptorCount[i] > 0 )
81
- {
82
- if (m_flags & ECF_FREE_DESCRIPTOR_SET_BIT)
83
- {
84
- m_generalAllocatorReservedSpace[i] = std::make_unique<uint8_t []>(core::GeneralpurposeAddressAllocator<uint32_t >::reserved_size (1u , m_maxDescriptorCount[i], 1u ));
85
- m_generalAllocators[i] = core::GeneralpurposeAddressAllocator<uint32_t >(m_generalAllocatorReservedSpace[i].get (), 0u , 0u , 1u , m_maxDescriptorCount[i], 1u );
86
- }
87
- else
88
- {
89
- m_linearAllocators[i] = core::LinearAddressAllocator<uint32_t >(nullptr , 0u , 0u , 1u , m_maxDescriptorCount[i]);
90
- }
91
- }
92
- }
79
+ m_descriptorAllocators[i] = std::make_unique<allocator_state_t >(m_maxDescriptorCount[i], m_flags & ECF_FREE_DESCRIPTOR_SET_BIT);
93
80
94
81
// For (possibly) mutable samplers.
95
- if (m_flags & ECF_FREE_DESCRIPTOR_SET_BIT)
96
- {
97
- m_generalAllocatorReservedSpace[static_cast <uint32_t >(asset::IDescriptor::E_TYPE::ET_COUNT)] = std::make_unique<uint8_t []>(core::GeneralpurposeAddressAllocator<uint32_t >::reserved_size (1u , m_maxDescriptorCount[static_cast <uint32_t >(asset::IDescriptor::E_TYPE::ET_COMBINED_IMAGE_SAMPLER)], 1u ));
98
- m_generalAllocators[static_cast <uint32_t >(asset::IDescriptor::E_TYPE::ET_COUNT)] = core::GeneralpurposeAddressAllocator<uint32_t >(m_generalAllocatorReservedSpace[static_cast <uint32_t >(asset::IDescriptor::E_TYPE::ET_COUNT)].get (), 0u , 0u , 1u , m_maxDescriptorCount[static_cast <uint32_t >(asset::IDescriptor::E_TYPE::ET_COMBINED_IMAGE_SAMPLER)], 1u );
99
- }
100
- else
101
- {
102
- m_linearAllocators[static_cast <uint32_t >(asset::IDescriptor::E_TYPE::ET_COUNT)] = core::LinearAddressAllocator<uint32_t >(nullptr , 0u , 0u , 1u , m_maxDescriptorCount[static_cast <uint32_t >(asset::IDescriptor::E_TYPE::ET_COMBINED_IMAGE_SAMPLER)]);
103
- }
82
+ m_descriptorAllocators[static_cast <uint32_t >(asset::IDescriptor::E_TYPE::ET_COUNT)] = std::make_unique<allocator_state_t >(m_maxDescriptorCount[static_cast <uint32_t >(asset::IDescriptor::E_TYPE::ET_COUNT)], m_flags & ECF_FREE_DESCRIPTOR_SET_BIT);
104
83
105
84
// Initialize the storages.
106
85
m_textureStorage = std::make_unique<core::StorageTrivializer<core::smart_refctd_ptr<video::IGPUImageView>>[]>(m_maxDescriptorCount[static_cast <uint32_t >(asset::IDescriptor::E_TYPE::ET_COMBINED_IMAGE_SAMPLER)]);
@@ -124,13 +103,56 @@ class NBL_API IDescriptorPool : public core::IReferenceCounted, public IBackendO
124
103
SDescriptorOffsets allocateDescriptorOffsets (const IGPUDescriptorSetLayout* layout);
125
104
126
105
const IDescriptorPool::E_CREATE_FLAGS m_flags;
106
+
127
107
uint32_t m_maxDescriptorCount[static_cast <uint32_t >(asset::IDescriptor::E_TYPE::ET_COUNT)];
128
- union
108
+
109
+ struct allocator_state_t
129
110
{
130
- core::LinearAddressAllocator<uint32_t > m_linearAllocators[static_cast <uint32_t >(asset::IDescriptor::E_TYPE::ET_COUNT)+1 ];
131
- core::GeneralpurposeAddressAllocator<uint32_t > m_generalAllocators[static_cast <uint32_t >(asset::IDescriptor::E_TYPE::ET_COUNT)+1 ];
111
+ allocator_state_t (const uint32_t maxDescriptorCount, const bool allowsFreeing)
112
+ {
113
+ if (maxDescriptorCount == 0 )
114
+ return ;
115
+
116
+ if (allowsFreeing)
117
+ {
118
+ generalAllocatorReservedSpace = std::make_unique<uint8_t []>(core::GeneralpurposeAddressAllocator<uint32_t >::reserved_size (1u , maxDescriptorCount, 1u ));
119
+ generalAllocator = core::GeneralpurposeAddressAllocator<uint32_t >(generalAllocatorReservedSpace.get (), 0u , 0u , 1u , maxDescriptorCount, 1u );
120
+ }
121
+ else
122
+ {
123
+ linearAllocator = core::LinearAddressAllocator<uint32_t >(nullptr , 0u , 0u , 1u , maxDescriptorCount);
124
+ }
125
+ }
126
+
127
+ ~allocator_state_t () {}
128
+
129
+ inline uint32_t allocate (const uint32_t count, const bool allowsFreeing)
130
+ {
131
+ if (allowsFreeing)
132
+ {
133
+ assert (generalAllocatorReservedSpace);
134
+ return generalAllocator.alloc_addr (count, 1u );
135
+ }
136
+ else
137
+ {
138
+ return linearAllocator.alloc_addr (count, 1u );
139
+ }
140
+ }
141
+
142
+ inline void free (const uint32_t allocatedOffset, const uint32_t count)
143
+ {
144
+ assert (generalAllocatorReservedSpace);
145
+ generalAllocator.free_addr (allocatedOffset, count);
146
+ }
147
+
148
+ union
149
+ {
150
+ core::LinearAddressAllocator<uint32_t > linearAllocator;
151
+ core::GeneralpurposeAddressAllocator<uint32_t > generalAllocator;
152
+ };
153
+ std::unique_ptr<uint8_t []> generalAllocatorReservedSpace = nullptr ;
132
154
};
133
- std::unique_ptr<uint8_t []> m_generalAllocatorReservedSpace [static_cast <uint32_t >(asset::IDescriptor::E_TYPE::ET_COUNT)+ 1 ];
155
+ std::unique_ptr<allocator_state_t > m_descriptorAllocators [static_cast <uint32_t >(asset::IDescriptor::E_TYPE::ET_COUNT) + 1 ];
134
156
135
157
std::unique_ptr<core::StorageTrivializer<core::smart_refctd_ptr<video::IGPUImageView>>[]> m_textureStorage;
136
158
std::unique_ptr<core::StorageTrivializer<core::smart_refctd_ptr<video::IGPUSampler>>[]> m_mutableSamplerStorage;
0 commit comments