Speeding up vez
Want to trivially speed up vez?
Just for interest topic, though I'd consider some of the potential code changes bug fixes...
1. Replace accidental copy by instance with references (before and after pairs)
StreamEncoder::BindPipeline()
auto sets = pipeline->GetBindings();
const auto& sets = pipeline->GetBindings();
StreamEncoder::BindDescriptorSet()
for (auto it : pipelineBindings)
for (const auto& it : pipelineBindings)
for (auto setBindingsItr : m_resourceBindings.GetSetBindings())
for (auto& setBindingsItr : const_cast<std::unordered_map<uint32_t, SetBindings>&>(m_resourceBindings.GetSetBindings())) // Need to modify via const
for (auto bindingItr : setBindings.bindings)
for (auto& bindingItr : setBindings.bindings)
for (auto arrayElementItr : arrayElementBindings)
for (auto& arrayElementItr : arrayElementBindings)
Note, some more changes may be required to support the above if copied and pasted directly.
This is just an example, not an exhaustive set.
2. Use a fast stack based array to replace std::vector use throughout the runtime code which deals with small vectors.
You can just use SmallVector from the spirv cross header:
VulkanSDK\Include\spirv_cross\spirv_cross_containers.hpp
eg. StreamEncoder::BindDescriptorSet()
std::vector<VkDescriptorBufferInfo> bufferInfos;
std::vector<VkDescriptorImageInfo> imageInfos;
std::vector<VkWriteDescriptorSet> descriptorWrites;
become
SmallVector<VkDescriptorBufferInfo> bufferInfos;
SmallVector<VkDescriptorImageInfo> imageInfos;
SmallVector<VkWriteDescriptorSet> descriptorWrites;
There's plenty more in the code than these examples. The goal is to reduce memory allocations and copies. The references should replace any unnecessary copy of a structure, container or even std::pair.
How much benefit does this make? After making a lot of these changes, I benchmarked a reduction of about 20% CPU time spent in vez code.