Skip to content

Commit 6ff47e3

Browse files
committed
Fix bug that getPrimitiveRenderer function redundantly creates the pipeline even if it doesn't have to.
1 parent 9f40cfb commit 6ff47e3

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

interface/vulkan/SharedData.cppm

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import :vulkan.sampler.SingleTexelSampler;
2727
* It combines the hash of each field using <tt>boost::hash_combine</tt>.
2828
*
2929
* @tparam T Aggregate struct type.
30-
* @note Currently this is only for <tt>SharedData::PrimitivePipelineKey</tt> (whose members are 3), therefore number of the structured bindings is assumed as 3. Need fix.
30+
* @note Currently this is only for <tt>SharedData::PrimitivePipelineKey</tt> (whose members are 4), therefore number of the structured bindings is assumed as 4. Need fix.
3131
*/
3232
template <typename T> requires std::is_aggregate_v<T>
3333
struct AggregateHasher {
@@ -129,13 +129,16 @@ namespace vk_gltf_viewer::vulkan {
129129
* @return Vulkan pipeline for the given key.
130130
*/
131131
[[nodiscard]] vk::Pipeline getPrimitiveRenderer(const PrimitivePipelineKey &key) const {
132-
if (key.unlit) {
133-
return primitivePipelines.try_emplace(key, createUnlitPrimitiveRenderer(
134-
gpu.device, primitivePipelineLayout, sceneRenderPass, key.alphaMode)).first->second;
132+
if (auto it = primitivePipelines.find(key); it != primitivePipelines.end()) {
133+
return it->second;
134+
}
135+
else if (key.unlit) {
136+
return primitivePipelines.try_emplace(it, key, createUnlitPrimitiveRenderer(
137+
gpu.device, primitivePipelineLayout, sceneRenderPass, key.alphaMode))->second;
135138
}
136139
else {
137-
return primitivePipelines.try_emplace(key, createPrimitiveRenderer(
138-
gpu.device, primitivePipelineLayout, sceneRenderPass, key.fragmentShaderGeneratedTBN, key.alphaMode)).first->second;
140+
return primitivePipelines.try_emplace(it, key, createPrimitiveRenderer(
141+
gpu.device, primitivePipelineLayout, sceneRenderPass, key.fragmentShaderGeneratedTBN, key.alphaMode))->second;
139142
}
140143
}
141144

0 commit comments

Comments
 (0)