Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit a627d46

Browse files
author
Jonah Williams
authored
[Impeller] avoid hashing and std::vector growth when binding descriptor sets. (#45070)
We call allocateAndBindDescriptorSets once for every cmd rendered, so this time can bubble up quite a bit. From the traces I've gathered map emplacement (emplace_unique_key_args) and std::vector growth (__push_back_slow_path) contribute the most to this trace. I think we have physical limits on the number of descriptors we can bind, though I'm not sure if we enforce that anywhere?
1 parent 3dcd217 commit a627d46

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

impeller/renderer/backend/vulkan/render_pass_vk.cc

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
#include <array>
88
#include <cstdint>
9-
#include <unordered_map>
109
#include <vector>
1110

1211
#include "flutter/fml/logging.h"
@@ -339,9 +338,15 @@ static bool AllocateAndBindDescriptorSets(const ContextVK& context,
339338

340339
auto& allocator = *context.GetResourceAllocator();
341340

342-
std::unordered_map<uint32_t, vk::DescriptorBufferInfo> buffers;
343-
std::unordered_map<uint32_t, vk::DescriptorImageInfo> images;
341+
std::vector<vk::DescriptorImageInfo> images;
342+
std::vector<vk::DescriptorBufferInfo> buffers;
344343
std::vector<vk::WriteDescriptorSet> writes;
344+
writes.reserve(command.vertex_bindings.buffers.size() +
345+
command.fragment_bindings.buffers.size() +
346+
command.fragment_bindings.sampled_images.size());
347+
images.reserve(command.fragment_bindings.sampled_images.size());
348+
buffers.reserve(command.vertex_bindings.buffers.size() +
349+
command.fragment_bindings.buffers.size());
345350

346351
auto bind_images = [&encoder, //
347352
&images, //
@@ -364,13 +369,14 @@ static bool AllocateAndBindDescriptorSets(const ContextVK& context,
364369
image_info.imageLayout = vk::ImageLayout::eShaderReadOnlyOptimal;
365370
image_info.sampler = sampler.GetSampler();
366371
image_info.imageView = texture_vk.GetImageView();
372+
images.push_back(image_info);
367373

368374
vk::WriteDescriptorSet write_set;
369375
write_set.dstSet = vk_desc_set.value();
370376
write_set.dstBinding = slot.binding;
371377
write_set.descriptorCount = 1u;
372378
write_set.descriptorType = vk::DescriptorType::eCombinedImageSampler;
373-
write_set.pImageInfo = &(images[slot.binding] = image_info);
379+
write_set.pImageInfo = &images.back();
374380

375381
writes.push_back(write_set);
376382
}
@@ -409,6 +415,7 @@ static bool AllocateAndBindDescriptorSets(const ContextVK& context,
409415
buffer_info.buffer = buffer;
410416
buffer_info.offset = offset;
411417
buffer_info.range = data.view.resource.range.length;
418+
buffers.push_back(buffer_info);
412419

413420
const ShaderUniformSlot& uniform = data.slot;
414421
auto layout_it = std::find_if(desc_set.begin(), desc_set.end(),
@@ -427,7 +434,7 @@ static bool AllocateAndBindDescriptorSets(const ContextVK& context,
427434
write_set.dstBinding = uniform.binding;
428435
write_set.descriptorCount = 1u;
429436
write_set.descriptorType = ToVKDescriptorType(layout.descriptor_type);
430-
write_set.pBufferInfo = &(buffers[uniform.binding] = buffer_info);
437+
write_set.pBufferInfo = &buffers.back();
431438

432439
writes.push_back(write_set);
433440
}

0 commit comments

Comments
 (0)