@@ -153,49 +153,49 @@ class NBL_API IDescriptorSetLayout : public virtual core::IReferenceCounted
153
153
uint32_t data;
154
154
};
155
155
156
- inline uint32_t getBindingCount () const { return count ; }
156
+ inline uint32_t getBindingCount () const { return m_count ; }
157
157
158
- // Returns index into the binding property arrays below (including `storageOffsets `), for the given binding number `binding`.
159
- // Assumes `bindingNumbers ` is sorted and that there are no duplicate values in it.
158
+ // Returns index into the binding property arrays below (including `m_storageOffsets `), for the given binding number `binding`.
159
+ // Assumes `m_bindingNumbers ` is sorted and that there are no duplicate values in it.
160
160
inline uint32_t searchForBinding (const binding_number_t binding) const
161
161
{
162
- if (!bindingNumbers )
162
+ if (!m_bindingNumbers )
163
163
return Invalid;
164
164
165
- assert (storageOffsets && (count != 0u ));
165
+ assert (m_storageOffsets && (m_count != 0u ));
166
166
167
- auto found = std::lower_bound (bindingNumbers, bindingNumbers + count , binding, [](binding_number_t a, binding_number_t b) -> bool {return a.data < b.data ; });
167
+ auto found = std::lower_bound (m_bindingNumbers, m_bindingNumbers + m_count , binding, [](binding_number_t a, binding_number_t b) -> bool {return a.data < b.data ; });
168
168
169
- if ((found >= bindingNumbers + count ) || (found->data != binding.data ))
169
+ if ((found >= m_bindingNumbers + m_count ) || (found->data != binding.data ))
170
170
return Invalid;
171
171
172
- const uint32_t foundIndex = found - bindingNumbers ;
173
- assert (foundIndex < count );
172
+ const uint32_t foundIndex = found - m_bindingNumbers ;
173
+ assert (foundIndex < m_count );
174
174
return foundIndex;
175
175
}
176
176
177
177
inline binding_number_t getBindingNumber (const uint32_t index) const
178
178
{
179
- assert (index < count );
180
- return bindingNumbers [index];
179
+ assert (index < m_count );
180
+ return m_bindingNumbers [index];
181
181
}
182
182
183
183
inline core::bitflag<IShader::E_SHADER_STAGE> getStageFlags (const uint32_t index) const
184
184
{
185
- assert (index < count );
186
- return stageFlags [index];
185
+ assert (index < m_count );
186
+ return m_stageFlags [index];
187
187
}
188
188
189
189
inline uint32_t getCount (const uint32_t index) const
190
190
{
191
- assert (index < count );
192
- return (index == 0u ) ? storageOffsets [index].data : storageOffsets [index].data - storageOffsets [index - 1 ].data ;
191
+ assert (index < m_count );
192
+ return (index == 0u ) ? m_storageOffsets [index].data : m_storageOffsets [index].data - m_storageOffsets [index - 1 ].data ;
193
193
}
194
194
195
195
inline storage_offset_t getStorageOffset (const uint32_t index) const
196
196
{
197
- assert (index < count );
198
- return (index == 0u ) ? 0u : storageOffsets [index - 1 ];
197
+ assert (index < m_count );
198
+ return (index == 0u ) ? 0u : m_storageOffsets [index - 1 ];
199
199
}
200
200
201
201
@@ -229,7 +229,7 @@ class NBL_API IDescriptorSetLayout : public virtual core::IReferenceCounted
229
229
return getStorageOffset (index);
230
230
}
231
231
232
- inline uint32_t getTotalCount () const { return (count == 0ull ) ? 0u : storageOffsets[count - 1 ].data ; }
232
+ inline uint32_t getTotalCount () const { return (m_count == 0ull ) ? 0u : m_storageOffsets[m_count - 1 ].data ; }
233
233
234
234
private:
235
235
friend class IDescriptorSetLayout ;
@@ -245,81 +245,87 @@ class NBL_API IDescriptorSetLayout : public virtual core::IReferenceCounted
245
245
246
246
inline CBindingRedirect () = default;
247
247
248
- CBindingRedirect (core::vector<SBuildInfo>&& info) : count (static_cast <uint32_t >(info.size()))
248
+ CBindingRedirect (core::vector<SBuildInfo>&& info) : m_count (static_cast <uint32_t >(info.size()))
249
249
{
250
- if (count <= 0 )
250
+ if (m_count <= 0 )
251
251
return ;
252
252
253
- const size_t requiredMemSize = count * (
254
- sizeof (binding_number_t ) +
255
- sizeof (core::bitflag<typename SBinding::E_CREATE_FLAGS>) +
256
- sizeof (core::bitflag<IShader::E_SHADER_STAGE>) +
257
- sizeof (storage_offset_t ));
253
+ init ();
254
+
255
+ std::sort (info.begin (), info.end ());
258
256
259
- data = std::make_unique< uint8_t []>(requiredMemSize);
257
+ for ( size_t i = 0 ; i < info. size (); ++i)
260
258
{
261
- uint64_t offset = 0ull ;
259
+ m_bindingNumbers[i].data = info[i].binding ;
260
+ m_createFlags[i] = info[i].createFlags ;
261
+ m_stageFlags[i] = info[i].stageFlags ;
262
+ m_storageOffsets[i].data = info[i].count ;
263
+ }
264
+
265
+ std::inclusive_scan (m_storageOffsets, m_storageOffsets + m_count, m_storageOffsets,
266
+ [](storage_offset_t a, storage_offset_t b) -> storage_offset_t { return storage_offset_t { a.data + b.data }; }, storage_offset_t { 0u });
267
+ }
262
268
263
- bindingNumbers = reinterpret_cast <binding_number_t *>(data.get () + offset);
264
- offset += count * sizeof (binding_number_t );
269
+ inline void init ()
270
+ {
271
+ const size_t requiredMemSize = getRequiredMemorySize ();
272
+ m_data = std::make_unique<uint8_t []>(requiredMemSize);
273
+ {
274
+ assert (m_count > 0 );
265
275
266
- createFlags = reinterpret_cast <core::bitflag<typename SBinding::E_CREATE_FLAGS>*>(data.get () + offset);
267
- offset += count * sizeof (core::bitflag<typename SBinding::E_CREATE_FLAGS>);
276
+ uint64_t offset = 0ull ;
268
277
269
- stageFlags = reinterpret_cast <core::bitflag<IShader::E_SHADER_STAGE> *>(data .get () + offset);
270
- offset += count * sizeof (core::bitflag<IShader::E_SHADER_STAGE> );
278
+ m_bindingNumbers = reinterpret_cast <binding_number_t *>(m_data .get () + offset);
279
+ offset += m_count * sizeof (binding_number_t );
271
280
272
- storageOffsets = reinterpret_cast <storage_offset_t *>(data .get () + offset);
273
- offset += count * sizeof (storage_offset_t );
281
+ m_createFlags = reinterpret_cast <core::bitflag< typename SBinding::E_CREATE_FLAGS> *>(m_data .get () + offset);
282
+ offset += m_count * sizeof (core::bitflag< typename SBinding::E_CREATE_FLAGS> );
274
283
275
- assert (offset == requiredMemSize );
276
- }
284
+ m_stageFlags = reinterpret_cast <core::bitflag<IShader::E_SHADER_STAGE>*>(m_data. get () + offset );
285
+ offset += m_count * sizeof (core::bitflag<IShader::E_SHADER_STAGE>);
277
286
278
- std::sort (info.begin (), info.end ());
287
+ m_storageOffsets = reinterpret_cast <storage_offset_t *>(m_data.get () + offset);
288
+ offset += m_count * sizeof (storage_offset_t );
279
289
280
- for (size_t i = 0 ; i < info.size (); ++i)
281
- {
282
- bindingNumbers[i].data = info[i].binding ;
283
- createFlags[i] = info[i].createFlags ;
284
- stageFlags[i] = info[i].stageFlags ;
285
- storageOffsets[i].data = info[i].count ;
290
+ assert (offset == requiredMemSize);
286
291
}
292
+ }
287
293
288
- std::inclusive_scan (storageOffsets, storageOffsets + count, storageOffsets,
289
- [](storage_offset_t a, storage_offset_t b) -> storage_offset_t { return storage_offset_t { a.data + b.data }; }, storage_offset_t { 0u });
294
+ inline size_t getRequiredMemorySize () const
295
+ {
296
+ const size_t result = m_count * (
297
+ sizeof (binding_number_t ) +
298
+ sizeof (core::bitflag<typename SBinding::E_CREATE_FLAGS>) +
299
+ sizeof (core::bitflag<IShader::E_SHADER_STAGE>) +
300
+ sizeof (storage_offset_t ));
301
+ return result;
290
302
}
291
303
292
304
friend class ICPUDescriptorSetLayout ;
293
- #if 0
294
305
inline CBindingRedirect clone () const
295
306
{
296
307
CBindingRedirect result;
297
- result.count = count;
298
-
299
- const size_t requiredMemSize = dataAllocator.get_total_size();
300
- assert(requiredMemSize == dataAllocator.get_allocated_size());
301
- result.data = std::make_unique<uint8_t[]>(requiredMemSize);
302
- result.dataAllocator = core::LinearAddressAllocator<uint32_t>(nullptr, 0u, 0u, 1u, requiredMemSize);
308
+ result.m_count = m_count;
303
309
304
- memcpy(result.data.get(), data.get(), requiredMemSize);
305
-
306
- result.bindingNumbers = reinterpret_cast<binding_number_t*>(result.data.get() + result.dataAllocator.alloc_addr(result.count * sizeof(binding_number_t), 1u));
307
- result.createFlags = reinterpret_cast<core::bitflag<typename SBinding::E_CREATE_FLAGS>*>(result.data.get() + result.dataAllocator.alloc_addr(result.count * sizeof(core::bitflag<typename SBinding::E_CREATE_FLAGS>), 1u));
308
- result.stageFlags = reinterpret_cast<core::bitflag<IShader::E_SHADER_STAGE>*>(result.data.get() + result.dataAllocator.alloc_addr(result.count * sizeof(core::bitflag<IShader::E_SHADER_STAGE>), 1u));
309
- result.storageOffsets = reinterpret_cast<storage_offset_t*>(result.data.get() + result.dataAllocator.alloc_addr(result.count * sizeof(storage_offset_t), 1u));
310
+ if (result.m_count > 0 )
311
+ {
312
+ result.init ();
313
+ memcpy (result.m_data .get (), m_data.get (), getRequiredMemorySize ());
314
+ }
310
315
311
316
return result;
312
317
}
313
- #endif
314
318
315
- uint32_t count = 0u ;
319
+ inline size_t conservativeSizeEstimate () const { return getRequiredMemorySize () + sizeof (*this ); }
320
+
321
+ uint32_t m_count = 0u ;
316
322
317
- binding_number_t * bindingNumbers = nullptr ;
318
- core::bitflag<typename SBinding::E_CREATE_FLAGS>* createFlags = nullptr ;
319
- core::bitflag<IShader::E_SHADER_STAGE>* stageFlags = nullptr ;
320
- storage_offset_t * storageOffsets = nullptr ;
323
+ binding_number_t * m_bindingNumbers = nullptr ;
324
+ core::bitflag<typename SBinding::E_CREATE_FLAGS>* m_createFlags = nullptr ;
325
+ core::bitflag<IShader::E_SHADER_STAGE>* m_stageFlags = nullptr ;
326
+ storage_offset_t * m_storageOffsets = nullptr ;
321
327
322
- std::unique_ptr<uint8_t []> data = nullptr ;
328
+ std::unique_ptr<uint8_t []> m_data = nullptr ;
323
329
};
324
330
325
331
// utility functions
@@ -335,8 +341,7 @@ class NBL_API IDescriptorSetLayout : public virtual core::IReferenceCounted
335
341
}
336
342
}
337
343
338
- IDescriptorSetLayout (const SBinding* const _begin, const SBinding* const _end) :
339
- m_bindings ((_end-_begin) ? core::make_refctd_dynamic_array<core::smart_refctd_dynamic_array<SBinding>>(_end-_begin) : nullptr )
344
+ IDescriptorSetLayout (const SBinding* const _begin, const SBinding* const _end)
340
345
{
341
346
core::vector<CBindingRedirect::SBuildInfo> buildInfo_descriptors[asset::EDT_COUNT];
342
347
core::vector<CBindingRedirect::SBuildInfo> buildInfo_immutableSamplers;
@@ -364,6 +369,18 @@ class NBL_API IDescriptorSetLayout : public virtual core::IReferenceCounted
364
369
const uint32_t immutableSamplerCount = m_immutableSamplerRedirect.getTotalCount ();
365
370
m_samplers = immutableSamplerCount ? core::make_refctd_dynamic_array<core::smart_refctd_dynamic_array<core::smart_refctd_ptr<sampler_type>>>(immutableSamplerCount) : nullptr ;
366
371
372
+ for (auto b = _begin; b != _end; ++b)
373
+ {
374
+ if (b->type == EDT_COMBINED_IMAGE_SAMPLER && b->samplers )
375
+ {
376
+ const auto localOffset = m_immutableSamplerRedirect.getStorageOffset (CBindingRedirect::binding_number_t (b->binding )).data ;
377
+ assert (localOffset != m_immutableSamplerRedirect.Invalid );
378
+
379
+ auto * dst = m_samplers->begin () + localOffset;
380
+ std::copy_n (b->samplers , b->count , dst);
381
+ }
382
+ }
383
+ #if 0
367
384
size_t bndCount = _end-_begin;
368
385
size_t immSamplersOffset = 0u;
369
386
for (size_t i = 0ull; i < bndCount; ++i)
@@ -402,12 +419,12 @@ class NBL_API IDescriptorSetLayout : public virtual core::IReferenceCounted
402
419
// TODO: check for overlapping bindings (bad `SBinding` definitions)
403
420
std::sort(m_bindings->begin(), m_bindings->end());
404
421
}
422
+ #endif
405
423
}
406
424
407
425
virtual ~IDescriptorSetLayout () = default ;
408
426
409
- core::smart_refctd_dynamic_array<SBinding> m_bindings; // TODO(achal): Shoudn't need this anymore.
410
- core::smart_refctd_dynamic_array<core::smart_refctd_ptr<sampler_type>> m_samplers;
427
+ core::smart_refctd_dynamic_array<core::smart_refctd_ptr<sampler_type>> m_samplers = nullptr ;
411
428
412
429
public:
413
430
bool isIdenticallyDefined (const IDescriptorSetLayout<sampler_type>* _other) const
@@ -425,7 +442,7 @@ class NBL_API IDescriptorSetLayout : public virtual core::IReferenceCounted
425
442
426
443
for (uint32_t i = 0u ; i < bindingCount; ++i)
427
444
{
428
- const bool equal = (lhs.bindingNumbers [i].data == rhs.bindingNumbers [i].data ) && (lhs.createFlags [i].value == rhs.createFlags [i].value ) && (lhs.stageFlags [i].value == rhs.stageFlags [i].value ) && (lhs.getCount (i) == rhs.getCount (i));
445
+ const bool equal = (lhs.m_bindingNumbers [i].data == rhs.m_bindingNumbers [i].data ) && (lhs.m_createFlags [i].value == rhs.m_createFlags [i].value ) && (lhs.m_stageFlags [i].value == rhs.m_stageFlags [i].value ) && (lhs.getCount (i) == rhs.getCount (i));
429
446
if (!equal)
430
447
return false ;
431
448
}
0 commit comments