Skip to content

Commit db996a1

Browse files
committed
More cleanups.
1 parent f8f2447 commit db996a1

File tree

3 files changed

+37
-41
lines changed

3 files changed

+37
-41
lines changed

include/nbl/asset/IDescriptorSetLayout.h

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -273,22 +273,30 @@ class NBL_API IDescriptorSetLayout : public virtual core::IReferenceCounted
273273
if (!_other || getTotalBindingCount() != _other->getTotalBindingCount())
274274
return false;
275275

276-
for (uint32_t t = 0u; t < static_cast<uint32_t>(IDescriptor::E_TYPE::ET_COUNT); ++t)
276+
auto areRedirectsEqual = [](const CBindingRedirect& lhs, const CBindingRedirect& rhs) -> bool
277277
{
278-
const auto& lhs = m_descriptorRedirects[t];
279-
const auto& rhs = _other->m_descriptorRedirects[t];
278+
const auto memSize = lhs.getRequiredMemorySize();
279+
if (memSize != rhs.getRequiredMemorySize())
280+
return false;
280281

281-
const auto bindingCount = lhs.getBindingCount();
282-
assert(bindingCount==rhs.getBindingCount());
282+
if (std::memcmp(lhs.m_data.get(), rhs.m_data.get(), memSize) != 0)
283+
return false;
283284

284-
for (uint32_t i = 0u; i < bindingCount; ++i)
285-
{
286-
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));
287-
if (!equal)
288-
return false;
289-
}
285+
return true;
286+
};
287+
288+
for (uint32_t t = 0u; t < static_cast<uint32_t>(IDescriptor::E_TYPE::ET_COUNT); ++t)
289+
{
290+
if (!areRedirectsEqual(m_descriptorRedirects[t], _other->m_descriptorRedirects[t]))
291+
return false;
290292
}
291293

294+
if (!areRedirectsEqual(m_immutableSamplerRedirect, _other->m_immutableSamplerRedirect))
295+
return false;
296+
297+
if (!areRedirectsEqual(m_mutableSamplerRedirect, _other->m_mutableSamplerRedirect))
298+
return false;
299+
292300
if (!m_samplers && !_other->m_samplers)
293301
{
294302
return true;
@@ -300,7 +308,8 @@ class NBL_API IDescriptorSetLayout : public virtual core::IReferenceCounted
300308
else
301309
{
302310
const auto samplerCount = m_samplers->size();
303-
assert(samplerCount == _other->m_samplers->size());
311+
if (samplerCount != _other->m_samplers->size())
312+
return false;
304313

305314
for (uint32_t i = 0u; i < samplerCount; ++i)
306315
{

include/nbl/video/utilities/IGPUObjectFromAssetConverter.h

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1714,20 +1714,22 @@ inline created_gpu_object_array<asset::ICPUDescriptorSet> IGPUObjectFromAssetCon
17141714
for (uint32_t t = 0u; t < static_cast<uint32_t>(asset::IDescriptor::E_TYPE::ET_COUNT); ++t)
17151715
{
17161716
const auto type = static_cast<asset::IDescriptor::E_TYPE>(t);
1717-
const auto activeBindingCount = cpuds->getLayout()->getDescriptorRedirect(type).getBindingCount();
17181717

1719-
for (uint32_t b = 0u; b < activeBindingCount; ++b)
1718+
const auto& descriptorBindingRedirect = cpuds->getLayout()->getDescriptorRedirect(type);
1719+
const auto& mutableSamplerBindingRedirect = cpuds->getLayout()->getMutableSamplerRedirect();
1720+
1721+
for (uint32_t b = 0u; b < descriptorBindingRedirect.getBindingCount(); ++b)
17201722
{
17211723
write_it->dstSet = gpuds;
1722-
write_it->binding = cpuds->getLayout()->getDescriptorRedirect(type).getBindingNumber(b).data;
1724+
write_it->binding = descriptorBindingRedirect.getBindingNumber(b).data;
17231725
write_it->arrayElement = 0u;
17241726

1725-
const uint32_t descriptorCount = cpuds->getLayout()->getDescriptorRedirect(type).getCount(b);
1727+
const uint32_t descriptorCount = descriptorBindingRedirect.getCount(b);
17261728
write_it->count = descriptorCount;
17271729
write_it->descriptorType = type;
17281730
write_it->info = &(*info);
17291731

1730-
const uint32_t offset = cpuds->getLayout()->getDescriptorRedirect(type).getStorageOffset(b).data;
1732+
const uint32_t offset = descriptorBindingRedirect.getStorageOffset(b).data;
17311733

17321734
// It is better to use getDescriptorInfoStorage over getDescriptorInfos, because the latter does a binary search
17331735
// over the bindings, which is not really required given we have the index of binding number (since we're iterating
@@ -1764,22 +1766,14 @@ inline created_gpu_object_array<asset::ICPUDescriptorSet> IGPUObjectFromAssetCon
17641766
{
17651767
info->desc = imgViewRedirs[ivi] >= gpuImgViews->size() ? nullptr : gpuImgViews->operator[](imgViewRedirs[ivi]);
17661768
++ivi;
1767-
// TODO: This should be set in the loader (or whoever is creating
1768-
// the descriptor)
1769-
if (info->info.image.imageLayout == asset::IImage::EL_UNDEFINED)
1769+
info->info.image.imageLayout = descriptorInfos[offset + d].info.image.imageLayout;
1770+
assert(info->info.image.imageLayout != asset::IImage::EL_UNDEFINED);
1771+
1772+
if (!isStorageImgDesc(type))
17701773
{
1771-
if (isStorageImgDesc(type))
1772-
{
1773-
info->info.image.imageLayout = asset::IImage::EL_GENERAL;
1774-
}
1775-
else
1776-
{
1777-
const auto imageFormat = static_cast<asset::ICPUImageView*>(info->desc.get())->getCreationParameters().format;
1778-
info->info.image.imageLayout = isDepthOrStencilFormat(imageFormat) ? asset::IImage::EL_DEPTH_STENCIL_READ_ONLY_OPTIMAL : asset::IImage::EL_SHADER_READ_ONLY_OPTIMAL;
1779-
1780-
if (descriptorInfos.begin()[offset + d].info.image.sampler)
1781-
info->info.image.sampler = gpuSamplers->operator[](smplrRedirs[si++]);
1782-
}
1774+
const bool isMutableSamplerBinding = (mutableSamplerBindingRedirect.searchForBinding(asset::ICPUDescriptorSetLayout::CBindingRedirect::binding_number_t{ write_it->binding }) != mutableSamplerBindingRedirect.Invalid);
1775+
if (descriptorInfos.begin()[offset + d].info.image.sampler && isMutableSamplerBinding)
1776+
info->info.image.sampler = gpuSamplers->operator[](smplrRedirs[si++]);
17831777
}
17841778
}
17851779
allDescriptorsPresent = allDescriptorsPresent && info->desc;

src/nbl/video/CVulkanCommandBuffer.cpp

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -480,15 +480,8 @@ bool CVulkanCommandBuffer::bindDescriptorSets_impl(asset::E_PIPELINE_BIND_POINT
480480

481481
if (dynamicOffsets) // count dynamic offsets per set, if there are any
482482
{
483-
auto addDynamicOffsetCount = [&dynamicOffsetCountPerSet, i](const IGPUDescriptorSetLayout::CBindingRedirect& descriptorBindingRedirect)
484-
{
485-
const auto declaredBindingCount = descriptorBindingRedirect.getBindingCount();
486-
for (uint32_t b = 0; b < declaredBindingCount; ++b)
487-
dynamicOffsetCountPerSet[i] += descriptorBindingRedirect.getCount(b);
488-
};
489-
490-
addDynamicOffsetCount(pDescriptorSets[i]->getLayout()->getDescriptorRedirect(asset::IDescriptor::E_TYPE::ET_STORAGE_BUFFER_DYNAMIC));
491-
addDynamicOffsetCount(pDescriptorSets[i]->getLayout()->getDescriptorRedirect(asset::IDescriptor::E_TYPE::ET_UNIFORM_BUFFER_DYNAMIC));
483+
dynamicOffsetCountPerSet[i] += pDescriptorSets[i]->getLayout()->getDescriptorRedirect(asset::IDescriptor::E_TYPE::ET_STORAGE_BUFFER_DYNAMIC).getTotalCount();
484+
dynamicOffsetCountPerSet[i] += pDescriptorSets[i]->getLayout()->getDescriptorRedirect(asset::IDescriptor::E_TYPE::ET_UNIFORM_BUFFER_DYNAMIC).getTotalCount();
492485
}
493486
}
494487
}

0 commit comments

Comments
 (0)