Skip to content

Commit 8cd8075

Browse files
committed
Some tiny changes and cleanups.
1 parent f315ed8 commit 8cd8075

File tree

4 files changed

+21
-30
lines changed

4 files changed

+21
-30
lines changed

include/nbl/video/utilities/IGPUObjectFromAssetConverter.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1772,8 +1772,11 @@ inline created_gpu_object_array<asset::ICPUDescriptorSet> IGPUObjectFromAssetCon
17721772
if (!isStorageImgDesc(type))
17731773
{
17741774
const bool isMutableSamplerBinding = (mutableSamplerBindingRedirect.findBindingStorageIndex(asset::ICPUDescriptorSetLayout::CBindingRedirect::binding_number_t{ write_it->binding }).data != mutableSamplerBindingRedirect.Invalid);
1775-
if (descriptorInfos.begin()[offset + d].info.image.sampler && isMutableSamplerBinding)
1775+
if (isMutableSamplerBinding)
1776+
{
1777+
assert(descriptorInfos.begin()[offset + d].info.image.sampler);
17761778
info->info.image.sampler = gpuSamplers->operator[](smplrRedirs[si++]);
1779+
}
17771780
}
17781781
}
17791782
allDescriptorsPresent = allDescriptorsPresent && info->desc;

src/nbl/video/CVulkanLogicalDevice.h

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -487,57 +487,37 @@ class CVulkanLogicalDevice final : public ILogicalDevice
487487
vk_writeDescriptorSets[i].descriptorType = getVkDescriptorTypeFromDescriptorType(pDescriptorWrites[i].descriptorType);
488488
vk_writeDescriptorSets[i].descriptorCount = pDescriptorWrites[i].count;
489489

490-
assert(pDescriptorWrites[i].info[0].desc);
490+
const auto bindingWriteCount = pDescriptorWrites[i].count;
491491

492492
switch (pDescriptorWrites[i].info->desc->getTypeCategory())
493493
{
494494
case asset::IDescriptor::EC_BUFFER:
495495
{
496-
VkDescriptorBufferInfo dummyInfo = {};
497-
dummyInfo.buffer = static_cast<const CVulkanBuffer*>(pDescriptorWrites[i].info[0].desc.get())->getInternalObject();
498-
dummyInfo.offset = pDescriptorWrites[i].info[0].info.buffer.offset;
499-
dummyInfo.range = pDescriptorWrites[i].info[0].info.buffer.size;
500-
501496
vk_writeDescriptorSets[i].pBufferInfo = reinterpret_cast<VkDescriptorBufferInfo*>(vk_bufferInfos.size());
502-
for (uint32_t j = 0u; j < pDescriptorWrites[i].count; ++j)
503-
vk_bufferInfos.push_back(dummyInfo);
497+
vk_bufferInfos.resize(vk_bufferInfos.size() + bindingWriteCount);
504498
} break;
505499

506500
case asset::IDescriptor::EC_IMAGE:
507501
{
508-
const auto& firstDescWriteImageInfo = pDescriptorWrites[i].info[0].info.image;
509-
510-
VkDescriptorImageInfo dummyInfo = { VK_NULL_HANDLE };
511-
if (firstDescWriteImageInfo.sampler && (firstDescWriteImageInfo.sampler->getAPIType() == EAT_VULKAN))
512-
dummyInfo.sampler = static_cast<const CVulkanSampler*>(firstDescWriteImageInfo.sampler.get())->getInternalObject();
513-
dummyInfo.imageView = static_cast<const CVulkanImageView*>(pDescriptorWrites[i].info[0].desc.get())->getInternalObject();
514-
dummyInfo.imageLayout = static_cast<VkImageLayout>(pDescriptorWrites[i].info[0].info.image.imageLayout);
515-
516502
vk_writeDescriptorSets[i].pImageInfo = reinterpret_cast<VkDescriptorImageInfo*>(vk_imageInfos.size());
517-
for (uint32_t j = 0u; j < pDescriptorWrites[i].count; ++j)
518-
vk_imageInfos.push_back(dummyInfo);
503+
vk_imageInfos.resize(vk_imageInfos.size() + bindingWriteCount);
519504
} break;
520505

521506
case asset::IDescriptor::EC_BUFFER_VIEW:
522507
{
523-
VkBufferView dummyBufferView = static_cast<const CVulkanBufferView*>(pDescriptorWrites[i].info[0].desc.get())->getInternalObject();
524-
525508
vk_writeDescriptorSets[i].pTexelBufferView = reinterpret_cast<VkBufferView*>(vk_bufferViews.size());
526-
for (uint32_t j = 0u; j < pDescriptorWrites[i].count; ++j)
527-
vk_bufferViews.push_back(dummyBufferView);
509+
vk_bufferViews.resize(vk_bufferViews.size() + bindingWriteCount);
528510
} break;
529511

530512
case asset::IDescriptor::EC_ACCELERATION_STRUCTURE:
531513
{
532514
auto& writeAS = vk_writeDescriptorSetAS[i];
533515
writeAS = { VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET_ACCELERATION_STRUCTURE_KHR, nullptr };
534-
writeAS.accelerationStructureCount = pDescriptorWrites[i].count;
535-
516+
writeAS.accelerationStructureCount = bindingWriteCount;
536517
vk_writeDescriptorSets[i].pNext = &writeAS;
537518

538519
writeAS.pAccelerationStructures = reinterpret_cast<VkAccelerationStructureKHR*>(vk_accelerationStructures.size());
539-
for (uint32_t j = 0u; j < pDescriptorWrites[i].count; ++j)
540-
vk_accelerationStructures.push_back({});
520+
vk_accelerationStructures.resize(vk_accelerationStructures.size() + bindingWriteCount);
541521
} break;
542522

543523
default:

src/nbl/video/IDescriptorPool.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,21 @@ uint32_t IDescriptorPool::createDescriptorSets(uint32_t count, const IGPUDescrip
7272

7373
bool IDescriptorPool::reset()
7474
{
75+
// something else except for the allocated sets needs to be holding onto the pool, so that
76+
// we don't have an implicit call to `~IDescriptorPool` on `this` before we get out of the current stackframe
77+
assert(getReferenceCount() > m_descriptorSetAllocator.get_allocated_size());
78+
7579
const auto& compilerIsRetarded = m_descriptorSetAllocator;
7680
for (const uint32_t setIndex : compilerIsRetarded)
7781
deleteSetStorage(setIndex);
7882

83+
// the `reset` doesn't deallocate anything, but it rearranges the free address stack in order to
84+
// not make the future allocated addresses dependent on what happened before a reset
85+
assert(m_descriptorSetAllocator.get_allocated_size() == 0);
7986
m_descriptorSetAllocator.reset();
8087

88+
// see the comment at the first assert
89+
assert(getReferenceCount() >= 1);
8190
return reset_impl();
8291
}
8392

src/nbl/video/ILogicalDevice.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ bool ILogicalDevice::updateDescriptorSets(uint32_t descriptorWriteCount, const I
3636
const auto& write = pDescriptorWrites[i];
3737
auto* ds = static_cast<IGPUDescriptorSet*>(write.dstSet);
3838

39-
if (!ds->getLayout()->isCompatibleDevicewise(ds))
40-
return false;
39+
assert(ds->getLayout()->isCompatibleDevicewise(ds));
4140

4241
if (!ds->validateWrite(write))
4342
return false;
@@ -49,7 +48,7 @@ bool ILogicalDevice::updateDescriptorSets(uint32_t descriptorWriteCount, const I
4948
const auto* srcDS = static_cast<const IGPUDescriptorSet*>(copy.srcSet);
5049
const auto* dstDS = static_cast<IGPUDescriptorSet*>(copy.dstSet);
5150

52-
if ((!srcDS->getLayout()->isCompatibleDevicewise(srcDS)) || (!dstDS->getLayout()->isCompatibleDevicewise(dstDS)))
51+
if (!dstDS->isCompatibleDevicewise(srcDS))
5352
return false;
5453

5554
if (!dstDS->validateCopy(copy))

0 commit comments

Comments
 (0)