@@ -121,20 +121,22 @@ namespace nbl::ext::debug_draw
121121 asset::SBufferBinding<video::IGPUBuffer> indexBinding = { .offset = 0 , .buffer = m_indicesBuffer };
122122 commandBuffer->bindIndexBuffer (indexBinding, asset::EIT_32BIT);
123123
124- std::vector<InstanceData> instances (aabbInstances.size ());
125- for (uint32_t i = 0 ; i < aabbInstances.size (); i++)
126- {
127- auto & inst = instances[i];
128- inst = aabbInstances[i];
129- inst.transform = hlsl::mul (params.cameraMat , inst.transform );
130- }
124+ auto setInstancesRange = [&](InstanceData* data, uint32_t count) -> void {
125+ for (uint32_t i = 0 ; i < count; i++)
126+ {
127+ auto inst = data + i;
128+ *inst = aabbInstances[i];
129+ inst->transform = hlsl::mul (params.cameraMat , inst->transform );
130+ }
131+ };
131132
132- auto instancesIt = instances. begin ();
133+ const uint32_t numInstances = aabbInstances. size ();
133134 const uint32_t instancesPerIter = streaming->getBuffer ()->getSize () / sizeof (InstanceData);
134135 using suballocator_t = core::LinearAddressAllocatorST<offset_t >;
135- while (instancesIt != instances.end ())
136+ uint32_t beginOffset = 0 ;
137+ while (beginOffset < numInstances)
136138 {
137- const uint32_t instanceCount = hlsl::min<uint32_t >(instancesPerIter, instances. size () );
139+ const uint32_t instanceCount = hlsl::min<uint32_t >(instancesPerIter, numInstances );
138140 offset_t inputOffset = 0u ;
139141 offset_t ImaginarySizeUpperBound = 0x1 << 30 ;
140142 suballocator_t imaginaryChunk (nullptr , inputOffset, 0 , hlsl::roundUpToPoT (MaxAlignment), ImaginarySizeUpperBound);
@@ -145,8 +147,9 @@ namespace nbl::ext::debug_draw
145147 std::chrono::steady_clock::time_point waitTill = std::chrono::steady_clock::now () + std::chrono::milliseconds (1u );
146148 streaming->multi_allocate (waitTill, 1 , &inputOffset, &totalSize, &MaxAlignment);
147149
148- memcpy (streamingPtr + instancesByteOffset, std::addressof (*instancesIt), sizeof (InstanceData) * instanceCount);
149- instancesIt += instanceCount;
150+ auto * const streamingInstancesPtr = reinterpret_cast <InstanceData*>(streamingPtr + instancesByteOffset);
151+ setInstancesRange (streamingInstancesPtr, instanceCount);
152+ beginOffset += instanceCount;
150153
151154 assert (!streaming->needsManualFlushOrInvalidate ());
152155
0 commit comments