@@ -894,7 +894,7 @@ namespace nbl::ext::imgui
894
894
template <typename T>
895
895
concept ImDrawBufferType = std::same_as<T, ImDrawVert> || std::same_as<T, ImDrawIdx>;
896
896
897
- bool UI::render (nbl::video::IGPUCommandBuffer* commandBuffer, nbl::video::ISemaphore::SWaitInfo waitInfo, const std::span<const VkRect2D> scissors)
897
+ bool UI::render (nbl::video::IGPUCommandBuffer* commandBuffer, const std::span<const VkRect2D> scissors)
898
898
{
899
899
if (!commandBuffer)
900
900
{
@@ -1063,7 +1063,10 @@ namespace nbl::ext::imgui
1063
1063
{
1064
1064
static constexpr auto ALIGN_OFFSET_NEEDED = 0u ;
1065
1065
MDI::SUBALLOCATOR_TRAITS_T::allocator_type fillSubAllocator (mdiData, requestState.offset , ALIGN_OFFSET_NEEDED, MDI_MAX_ALIGNMENT, requestState.multiAllocationSize );
1066
- MDI::SUBALLOCATOR_TRAITS_T::multi_alloc_addr (fillSubAllocator, mdiOffsets.size (), mdiOffsets.data (), mdiParams.bytesToFill .data (), MDI_ALIGNMENTS.data ());
1066
+
1067
+ std::array<typename MDI::ALLOCATOR_TRAITS_T::size_type, MDI_COMPONENT_COUNT> offsets;
1068
+ std::fill (offsets.data (), offsets.data () + MDI_COMPONENT_COUNT, MDI::ALLOCATOR_TRAITS_T::allocator_type::invalid_address);
1069
+ MDI::SUBALLOCATOR_TRAITS_T::multi_alloc_addr (fillSubAllocator, offsets.size (), offsets.data (), mdiParams.bytesToFill .data (), MDI_ALIGNMENTS.data ());
1067
1070
1068
1071
// ! linear allocator is used to fill the mdi data within suballocation memory range,
1069
1072
// ! there are a few restrictions regarding how MDI::E_BUFFER_CONTENT(s) can be packed,
@@ -1073,45 +1076,46 @@ namespace nbl::ext::imgui
1073
1076
1074
1077
auto fillDrawBuffers = [&]<MDI::E_BUFFER_CONTENT type>()
1075
1078
{
1076
- const typename MDI::ALLOCATOR_TRAITS_T::size_type blockOffset = mdiOffsets [type];
1079
+ const typename MDI::ALLOCATOR_TRAITS_T::size_type globalBlockOffset = offsets [type];
1077
1080
1078
- if (blockOffset == MDI::ALLOCATOR_TRAITS_T::allocator_type::invalid_address or mdiBytesFilled[type])
1081
+ if (globalBlockOffset == MDI::ALLOCATOR_TRAITS_T::allocator_type::invalid_address or mdiBytesFilled[type])
1079
1082
return 0u ;
1080
1083
1081
- auto * const data = mdiData + blockOffset;
1082
- size_t localOffset = {};
1084
+ auto * data = mdiData + globalBlockOffset;
1083
1085
1084
1086
for (int n = 0 ; n < drawData->CmdListsCount ; n++)
1085
1087
{
1086
1088
auto * cmd_list = drawData->CmdLists [n];
1087
1089
1088
1090
if constexpr (type == MDI::EBC_INDEX_BUFFERS)
1089
1091
{
1090
- ::memcpy (data + localOffset, cmd_list->IdxBuffer.Data, cmd_list->IdxBuffer.Size * sizeof (ImDrawIdx));
1091
- localOffset += cmd_list->IdxBuffer .Size ;
1092
+ const auto localInputBlockOffset = cmd_list->IdxBuffer .Size * sizeof (ImDrawIdx);
1093
+ ::memcpy (data, cmd_list->IdxBuffer.Data, localInputBlockOffset);
1094
+ data += localInputBlockOffset;
1092
1095
}
1093
1096
else if (type == MDI::EBC_VERTEX_BUFFERS)
1094
1097
{
1095
- ::memcpy (data, cmd_list->VtxBuffer.Data, cmd_list->VtxBuffer.Size * sizeof (ImDrawVert));
1096
- localOffset += cmd_list->VtxBuffer .Size ;
1098
+ const auto localInputBlockOffset = cmd_list->VtxBuffer .Size * sizeof (ImDrawVert);
1099
+ ::memcpy (data, cmd_list->VtxBuffer.Data, localInputBlockOffset);
1100
+ data += localInputBlockOffset;
1097
1101
}
1098
1102
}
1099
1103
1100
1104
mdiBytesFilled[type] = true ;
1105
+ mdiOffsets[type] = globalBlockOffset;
1101
1106
return mdiParams.bytesToFill [type];
1102
1107
};
1103
1108
1104
1109
auto fillIndirectStructures = [&]<MDI::E_BUFFER_CONTENT type>()
1105
1110
{
1106
- const typename MDI::ALLOCATOR_TRAITS_T::size_type blockOffset = mdiOffsets [type];
1111
+ const typename MDI::ALLOCATOR_TRAITS_T::size_type globalBlockOffset = offsets [type];
1107
1112
1108
- if (blockOffset == MDI::ALLOCATOR_TRAITS_T::allocator_type::invalid_address or mdiBytesFilled[type])
1113
+ if (globalBlockOffset == MDI::ALLOCATOR_TRAITS_T::allocator_type::invalid_address or mdiBytesFilled[type])
1109
1114
return 0u ;
1110
1115
1111
- auto * const data = mdiData + blockOffset;
1112
- size_t localOffset = {};
1116
+ auto * const data = mdiData + globalBlockOffset;
1113
1117
1114
- size_t cmdListIndexOffset = {}, cmdListVertexOffset = {}, drawID = {};
1118
+ size_t cmdListIndexObjectOffset = {}, cmdListVertexObjectOffset = {}, drawID = {};
1115
1119
1116
1120
for (int n = 0 ; n < drawData->CmdListsCount ; n++)
1117
1121
{
@@ -1127,8 +1131,8 @@ namespace nbl::ext::imgui
1127
1131
indirect->firstInstance = drawID; // use base instance as draw ID
1128
1132
indirect->indexCount = pcmd->ElemCount ;
1129
1133
indirect->instanceCount = 1u ;
1130
- indirect->firstIndex = pcmd->IdxOffset + cmdListIndexOffset ;
1131
- indirect->vertexOffset = pcmd->VtxOffset + cmdListVertexOffset ;
1134
+ indirect->firstIndex = pcmd->IdxOffset + cmdListIndexObjectOffset ;
1135
+ indirect->vertexOffset = pcmd->VtxOffset + cmdListVertexObjectOffset ;
1132
1136
}
1133
1137
else if (type == MDI::EBC_ELEMENT_STRUCTURES)
1134
1138
{
@@ -1155,11 +1159,12 @@ namespace nbl::ext::imgui
1155
1159
++drawID;
1156
1160
}
1157
1161
1158
- cmdListIndexOffset += cmd_list->IdxBuffer .Size ;
1159
- cmdListVertexOffset += cmd_list->VtxBuffer .Size ;
1162
+ cmdListIndexObjectOffset += cmd_list->IdxBuffer .Size ;
1163
+ cmdListVertexObjectOffset += cmd_list->VtxBuffer .Size ;
1160
1164
}
1161
1165
1162
1166
mdiBytesFilled[type] = true ;
1167
+ mdiOffsets[type] = globalBlockOffset;
1163
1168
return mdiParams.bytesToFill [type];
1164
1169
};
1165
1170
@@ -1175,6 +1180,15 @@ namespace nbl::ext::imgui
1175
1180
}
1176
1181
}
1177
1182
1183
+ assert ([&mdiOffsets]() -> bool
1184
+ {
1185
+ for (const auto & offset : mdiOffsets)
1186
+ if (offset == MDI::ALLOCATOR_TRAITS_T::allocator_type::invalid_address)
1187
+ return false ; // we should never hit this at this point
1188
+
1189
+ return true ;
1190
+ }()); // debug check only
1191
+
1178
1192
const auto offset = mdiBuffer->getBoundMemory ().offset ;
1179
1193
{
1180
1194
const asset::SBufferBinding<const video::IGPUBuffer> binding =
0 commit comments