2 #include "pipelinecache.h"
3 #include "pipelinestate.h"
4 #include "renderpass.h"
12 PipelineCache::PipelineCache(Device &d):
16 PipelineCache::~PipelineCache()
18 const VulkanFunctions &vk = device.get_functions();
20 for(const auto &kvp: render_passes)
21 vk.DestroyRenderPass(kvp.second);
22 for(const auto &kvp: pipelines)
23 vk.DestroyPipeline(kvp.second);
26 VkRenderPass PipelineCache::get_render_pass(const RenderPass &rp)
28 uint64_t key = rp.compute_hash();
29 auto i = render_passes.find(key);
30 if(i!=render_passes.end())
33 const VulkanFunctions &vk = device.get_functions();
36 rp.fill_creation_info(buffer);
37 const VkRenderPassCreateInfo *creation_info = reinterpret_cast<const VkRenderPassCreateInfo *>(buffer.data());
39 VkRenderPass render_pass;
40 vk.CreateRenderPass(*creation_info, render_pass);
42 render_passes.insert(make_pair(key, render_pass));
47 VkPipeline PipelineCache::get_pipeline(const PipelineState &ps)
49 const VulkanFunctions &vk = device.get_functions();
51 uint64_t key = ps.compute_hash();
52 auto i = pipelines.find(key);
53 if(i!=pipelines.end())
57 ps.fill_creation_info(buffer);
58 const VkGraphicsPipelineCreateInfo *creation_info = reinterpret_cast<const VkGraphicsPipelineCreateInfo *>(buffer.data());
61 vk.CreateGraphicsPipelines(0, 1, creation_info, &pipeline);
63 pipelines.insert(make_pair(key, pipeline));