Skip to content

Commit 8cde0d0

Browse files
committed
Fixes for CVulkanCommandBuffer::bindDescriptorSets
1 parent 973a07e commit 8cde0d0

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/nbl/video/CVulkanCommandBuffer.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,6 +1071,7 @@ class CVulkanCommandBuffer : public IGPUCommandBuffer
10711071
return false;
10721072

10731073
constexpr uint32_t MAX_DESCRIPTOR_SET_COUNT = 4u;
1074+
assert(descriptorSetCount <= MAX_DESCRIPTOR_SET_COUNT);
10741075

10751076
VkPipelineLayout vk_pipelineLayout = IBackendObject::compatibility_cast<const CVulkanPipelineLayout*>(layout, this)->getInternalObject();
10761077

@@ -1097,9 +1098,10 @@ class CVulkanCommandBuffer : public IGPUCommandBuffer
10971098

10981099
const auto* vk = static_cast<const CVulkanLogicalDevice*>(getOriginDevice())->getFunctionTable();
10991100

1101+
// We allow null descriptor sets in our bind function to skip a certain set number we don't use
11001102
// Will bind [first, last) with one call
11011103
uint32_t dynamicOffsetsBindOffset = 0u;
1102-
uint32_t bindCount = 0u;
1104+
uint32_t bindCallsCount = 0u;
11031105
uint32_t first = ~0u;
11041106
uint32_t last = ~0u;
11051107
for (uint32_t i = 0u; i < descriptorSetCount; ++i)
@@ -1115,7 +1117,7 @@ class CVulkanCommandBuffer : public IGPUCommandBuffer
11151117
++last;
11161118

11171119
// Do a look ahead
1118-
if ((i + 1 > descriptorSetCount - 1) || !pDescriptorSets[i + 1])
1120+
if ((i + 1 >= descriptorSetCount) || !pDescriptorSets[i + 1])
11191121
{
11201122
if (dynamicOffsets)
11211123
{
@@ -1129,7 +1131,7 @@ class CVulkanCommandBuffer : public IGPUCommandBuffer
11291131
vk_pipelineLayout,
11301132
// firstSet + first, last - first, vk_descriptorSets + first, vk_dynamicOffsetCount, vk_dynamicOffsets);
11311133
firstSet + first, last - first, vk_descriptorSets + first,
1132-
dynamicOffsetCount, dynamicOffsets->begin() + dynamicOffsetsBindOffset);
1134+
dynamicOffsetCount, dynamicOffsets + dynamicOffsetsBindOffset);
11331135

11341136
dynamicOffsetsBindOffset += dynamicOffsetCount;
11351137
}
@@ -1144,11 +1146,13 @@ class CVulkanCommandBuffer : public IGPUCommandBuffer
11441146

11451147
first = ~0u;
11461148
last = ~0u;
1147-
++bindCount;
1149+
++bindCallsCount;
11481150
}
11491151
}
11501152
}
1151-
assert(bindCount <= core::ceil(MAX_DESCRIPTOR_SET_COUNT / 2.f));
1153+
1154+
// with K slots you need at most (K+1)/2 calls
1155+
assert(bindCallsCount <= (MAX_DESCRIPTOR_SET_COUNT + 1) / 2);
11521156

11531157
return true;
11541158
}

0 commit comments

Comments
 (0)