@@ -448,16 +448,21 @@ namespace ZEngine::Hardwares
448448 TextureHandleToUpdates.Enqueue (tex_handle);
449449 return ;
450450 }
451- const auto & image_info = texture->ImageBuffer ->GetDescriptorImageInfo ();
452- std::vector<VkWriteDescriptorSet> write_descriptor_sets = {};
453- write_descriptor_sets.reserve (WriteBindlessDescriptorSetRequests.size ());
451+ const auto & image_info = texture->ImageBuffer ->GetDescriptorImageInfo ();
454452
455- for ( auto & req : WriteBindlessDescriptorSetRequests)
453+ auto scratch = ZGetScratch (Arena);
456454 {
457- write_descriptor_sets.push_back (VkWriteDescriptorSet{.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, .pNext = nullptr , .dstSet = req.DstSet , .dstBinding = req.Binding , .dstArrayElement = (uint32_t ) tex_handle.Index , .descriptorCount = 1 , .descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, .pImageInfo = &(image_info), .pBufferInfo = nullptr , .pTexelBufferView = nullptr });
458- }
455+ Array<VkWriteDescriptorSet> write_descriptor_sets = {};
456+ write_descriptor_sets.init (scratch.Arena , WriteBindlessDescriptorSetRequests.size ());
457+
458+ for (auto & req : WriteBindlessDescriptorSetRequests)
459+ {
460+ write_descriptor_sets.push (VkWriteDescriptorSet{.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, .pNext = nullptr , .dstSet = req.DstSet , .dstBinding = req.Binding , .dstArrayElement = (uint32_t ) tex_handle.Index , .descriptorCount = 1 , .descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, .pImageInfo = &(image_info), .pBufferInfo = nullptr , .pTexelBufferView = nullptr });
461+ }
459462
460- vkUpdateDescriptorSets (LogicalDevice, write_descriptor_sets.size (), write_descriptor_sets.data (), 0 , nullptr );
463+ vkUpdateDescriptorSets (LogicalDevice, write_descriptor_sets.size (), write_descriptor_sets.data (), 0 , nullptr );
464+ }
465+ ZReleaseScratch (scratch);
461466 }
462467
463468 Textures::TextureHandle tex_to_dispose = {};
@@ -1342,6 +1347,7 @@ namespace ZEngine::Hardwares
13421347 */
13431348 CommandBuffer::CommandBuffer (Hardwares::VulkanDevice* device, VkCommandPool command_pool, Rendering::QueueType type, bool one_time_usage) : Device(device), QueueType(type), m_command_pool(command_pool)
13441349 {
1350+ Device->Arena ->CreateSubArena (ZKilo (120 ), &LocalArena);
13451351 Create ();
13461352 }
13471353
@@ -1466,15 +1472,17 @@ namespace ZEngine::Hardwares
14661472 {
14671473 ZENGINE_VALIDATE_ASSERT (m_command_buffer != nullptr , " Command buffer can't be null" )
14681474
1469- const auto & render_pass_spec = render_pass->Specification ;
1470- const uint32_t width = render_pass->GetRenderAreaWidth ();
1471- const uint32_t height = render_pass->GetRenderAreaHeight ();
1475+ const auto & render_pass_spec = render_pass->Specification ;
1476+ const uint32_t width = render_pass->GetRenderAreaWidth ();
1477+ const uint32_t height = render_pass->GetRenderAreaHeight ();
14721478
1473- std::vector<VkClearValue> clear_values = {} ;
1479+ auto scratch = ZGetScratch (&LocalArena) ;
14741480
1481+ Array<VkClearValue> clear_values = {};
1482+ clear_values.init (scratch.Arena , 5 );
14751483 if (render_pass_spec.SwapchainAsRenderTarget )
14761484 {
1477- clear_values.push_back (m_clear_value[0 ]);
1485+ clear_values.push (m_clear_value[0 ]);
14781486 }
14791487 else
14801488 {
@@ -1484,10 +1492,10 @@ namespace ZEngine::Hardwares
14841492 auto texture = Device->GlobalTextures .Access (handle);
14851493 if (texture->IsDepthTexture )
14861494 {
1487- clear_values.push_back (m_clear_value[1 ]);
1495+ clear_values.push (m_clear_value[1 ]);
14881496 continue ;
14891497 }
1490- clear_values.push_back (m_clear_value[0 ]);
1498+ clear_values.push (m_clear_value[0 ]);
14911499 }
14921500
14931501 for (const auto & handle : spec.ExternalOutputs )
@@ -1496,10 +1504,10 @@ namespace ZEngine::Hardwares
14961504
14971505 if (texture->IsDepthTexture )
14981506 {
1499- clear_values.push_back (m_clear_value[1 ]);
1507+ clear_values.push (m_clear_value[1 ]);
15001508 continue ;
15011509 }
1502- clear_values.push_back (m_clear_value[0 ]);
1510+ clear_values.push (m_clear_value[0 ]);
15031511 }
15041512 }
15051513
@@ -1532,6 +1540,8 @@ namespace ZEngine::Hardwares
15321540 vkCmdBindPipeline (m_command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, render_pass->Pipeline ->GetHandle ());
15331541
15341542 m_active_render_pass = render_pass;
1543+
1544+ ZReleaseScratch (scratch);
15351545 }
15361546
15371547 void CommandBuffer::EndRenderPass ()
@@ -1550,18 +1560,21 @@ namespace ZEngine::Hardwares
15501560
15511561 if (auto render_pass = m_active_render_pass)
15521562 {
1553- auto pipeline = render_pass->Pipeline ;
1554- auto pipeline_layout = pipeline->GetPipelineLayout ();
1555- auto shader = pipeline->GetShader ();
1556- const auto & descriptor_set_map = shader->GetDescriptorSetMap ();
1563+ auto pipeline = render_pass->Pipeline ;
1564+ auto pipeline_layout = pipeline->GetPipelineLayout ();
1565+ auto shader = pipeline->GetShader ();
1566+ const auto & descriptor_set_map = shader->GetDescriptorSetMap ();
15571567
1558- std::vector<VkDescriptorSet> frame_sets = {};
1568+ auto scratch = ZGetScratch (&LocalArena);
1569+ Array<VkDescriptorSet> frame_sets = {};
1570+ frame_sets.init (scratch.Arena , 5 );
15591571 for (auto & [_, sets] : descriptor_set_map)
15601572 {
1561- frame_sets.emplace_back (sets[frame_index]);
1573+ frame_sets.push (sets[frame_index]);
15621574 }
15631575
15641576 vkCmdBindDescriptorSets (m_command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0 , frame_sets.size (), frame_sets.data (), 0 , nullptr );
1577+ ZReleaseScratch (scratch);
15651578 }
15661579 }
15671580
0 commit comments