mirror of
https://github.com/PancakeTAS/lsfg-vk.git
synced 2025-10-30 07:01:10 +00:00
cache pipelines to improve loading speeds
This commit is contained in:
parent
180256a222
commit
192f5e4e9f
12 changed files with 78 additions and 34 deletions
|
|
@ -2,6 +2,7 @@
|
|||
#define SHADERPOOL_HPP
|
||||
|
||||
#include "core/device.hpp"
|
||||
#include "core/pipeline.hpp"
|
||||
#include "core/shadermodule.hpp"
|
||||
#include "pool/extract.hpp"
|
||||
|
||||
|
|
@ -39,9 +40,22 @@ namespace LSFG::Pool {
|
|||
Core::ShaderModule getShader(
|
||||
const Core::Device& device, const std::string& name,
|
||||
const std::vector<std::pair<size_t, VkDescriptorType>>& types);
|
||||
|
||||
///
|
||||
/// Retrieve a pipeline shader module by name or create it.
|
||||
///
|
||||
/// @param device Vulkan device
|
||||
/// @param name Name of the shader module
|
||||
/// @return Pipeline shader module or empty
|
||||
///
|
||||
/// @throws LSFG::vulkan_error if the shader module cannot be created.
|
||||
///
|
||||
Core::Pipeline getPipeline(
|
||||
const Core::Device& device, const std::string& name);
|
||||
private:
|
||||
Extractor extractor;
|
||||
std::unordered_map<std::string, Core::ShaderModule> shaders;
|
||||
std::unordered_map<std::string, Core::Pipeline> pipelines;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,3 +63,18 @@ Core::ShaderModule ShaderPool::getShader(
|
|||
shaders[name] = shader;
|
||||
return shader;
|
||||
}
|
||||
|
||||
Core::Pipeline ShaderPool::getPipeline(
|
||||
const Core::Device& device, const std::string& name) {
|
||||
auto it = pipelines.find(name);
|
||||
if (it != pipelines.end())
|
||||
return it->second;
|
||||
|
||||
// grab the shader module
|
||||
auto shader = this->getShader(device, name, {});
|
||||
|
||||
// create the pipeline
|
||||
Core::Pipeline pipeline(device, shader);
|
||||
pipelines[name] = pipeline;
|
||||
return pipeline;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,13 +25,15 @@ Alpha::Alpha(const Core::Device& device, Pool::ShaderPool& shaderpool,
|
|||
{ 4, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE },
|
||||
{ 4, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE } })
|
||||
}};
|
||||
for (size_t i = 0; i < 4; i++) {
|
||||
this->pipelines.at(i) = Core::Pipeline(device,
|
||||
this->shaderModules.at(i));
|
||||
if (i == 3) continue; // last shader is special
|
||||
this->pipelines = {{
|
||||
shaderpool.getPipeline(device, "alpha/0.spv"),
|
||||
shaderpool.getPipeline(device, "alpha/1.spv"),
|
||||
shaderpool.getPipeline(device, "alpha/2.spv"),
|
||||
shaderpool.getPipeline(device, "alpha/3.spv")
|
||||
}};
|
||||
for (size_t i = 0; i < 3; i++)
|
||||
this->descriptorSets.at(i) = Core::DescriptorSet(device, pool,
|
||||
this->shaderModules.at(i));
|
||||
}
|
||||
for (size_t i = 0; i < 3; i++)
|
||||
this->specialDescriptorSets.at(i) = Core::DescriptorSet(device, pool,
|
||||
this->shaderModules.at(3));
|
||||
|
|
|
|||
|
|
@ -35,13 +35,16 @@ Beta::Beta(const Core::Device& device, Pool::ShaderPool& shaderpool,
|
|||
{ 2, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE },
|
||||
{ 6, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE } })
|
||||
}};
|
||||
for (size_t i = 0; i < 5; i++) {
|
||||
this->pipelines.at(i) = Core::Pipeline(device,
|
||||
this->shaderModules.at(i));
|
||||
if (i == 0 || i == 4) continue; // first shader has special logic
|
||||
this->pipelines = {{
|
||||
shaderpool.getPipeline(device, "beta/0.spv"),
|
||||
shaderpool.getPipeline(device, "beta/1.spv"),
|
||||
shaderpool.getPipeline(device, "beta/2.spv"),
|
||||
shaderpool.getPipeline(device, "beta/3.spv"),
|
||||
shaderpool.getPipeline(device, "beta/4.spv")
|
||||
}};
|
||||
for (size_t i = 1; i < 4; i++)
|
||||
this->descriptorSets.at(i - 1) = Core::DescriptorSet(device, pool,
|
||||
this->shaderModules.at(i));
|
||||
}
|
||||
for (size_t i = 0; i < 3; i++)
|
||||
this->specialDescriptorSets.at(i) = Core::DescriptorSet(device, pool,
|
||||
this->shaderModules.at(0));
|
||||
|
|
|
|||
|
|
@ -29,13 +29,15 @@ Delta::Delta(const Core::Device& device, Pool::ShaderPool& shaderpool,
|
|||
{ 3, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE },
|
||||
{ 1, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE } })
|
||||
}};
|
||||
for (size_t i = 0; i < 4; i++) {
|
||||
this->pipelines.at(i) = Core::Pipeline(device,
|
||||
this->shaderModules.at(i));
|
||||
if (i == 3) continue;
|
||||
this->pipelines = {{
|
||||
shaderpool.getPipeline(device, "delta/0.spv"),
|
||||
shaderpool.getPipeline(device, "delta/1.spv"),
|
||||
shaderpool.getPipeline(device, "delta/2.spv"),
|
||||
shaderpool.getPipeline(device, "delta/3.spv")
|
||||
}};
|
||||
for (size_t i = 0; i < 3; i++)
|
||||
this->descriptorSets.at(i) = Core::DescriptorSet(device, pool,
|
||||
this->shaderModules.at(i));
|
||||
}
|
||||
for (size_t i = 0; i < genc; i++)
|
||||
this->nDescriptorSets.emplace_back(device, pool,
|
||||
this->shaderModules.at(3));
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ Downsample::Downsample(const Core::Device& device, Pool::ShaderPool& shaderpool,
|
|||
{ 1, VK_DESCRIPTOR_TYPE_SAMPLER },
|
||||
{ 1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE },
|
||||
{ 7, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE } });
|
||||
this->pipeline = Core::Pipeline(device, this->shaderModule);
|
||||
this->pipeline = shaderpool.getPipeline(device, "downsample.spv");
|
||||
for (size_t i = 0; i < 2; i++)
|
||||
this->descriptorSets.at(i) = Core::DescriptorSet(device, pool, this->shaderModule);
|
||||
|
||||
|
|
|
|||
|
|
@ -31,13 +31,15 @@ Epsilon::Epsilon(const Core::Device& device, Pool::ShaderPool& shaderpool,
|
|||
{ 6, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE },
|
||||
{ 1, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE } })
|
||||
}};
|
||||
for (size_t i = 0; i < 4; i++) {
|
||||
this->pipelines.at(i) = Core::Pipeline(device,
|
||||
this->shaderModules.at(i));
|
||||
if (i == 3) continue;
|
||||
this->pipelines = {{
|
||||
shaderpool.getPipeline(device, "epsilon/0.spv"),
|
||||
shaderpool.getPipeline(device, "epsilon/1.spv"),
|
||||
shaderpool.getPipeline(device, "epsilon/2.spv"),
|
||||
shaderpool.getPipeline(device, "epsilon/3.spv")
|
||||
}};
|
||||
for (size_t i = 0; i < 3; i++)
|
||||
this->descriptorSets.at(i) = Core::DescriptorSet(device, pool,
|
||||
this->shaderModules.at(i));
|
||||
}
|
||||
for (size_t i = 0; i < genc; i++)
|
||||
this->nDescriptorSets.emplace_back(device, pool,
|
||||
this->shaderModules.at(3));
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ Extract::Extract(const Core::Device& device, Pool::ShaderPool& shaderpool,
|
|||
{ 2, VK_DESCRIPTOR_TYPE_SAMPLER },
|
||||
{ 3, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE },
|
||||
{ 1, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE } });
|
||||
this->pipeline = Core::Pipeline(device, this->shaderModule);
|
||||
this->pipeline = shaderpool.getPipeline(device, "extract.spv");
|
||||
for (size_t i = 0; i < genc; i++)
|
||||
this->nDescriptorSets.emplace_back(device, pool,
|
||||
this->shaderModule);
|
||||
|
|
|
|||
|
|
@ -47,13 +47,17 @@ Gamma::Gamma(const Core::Device& device, Pool::ShaderPool& shaderpool,
|
|||
{ 2, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE },
|
||||
{ 1, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE } })
|
||||
}};
|
||||
for (size_t i = 0; i < 6; i++) {
|
||||
this->pipelines.at(i) = Core::Pipeline(device,
|
||||
this->shaderModules.at(i));
|
||||
if (i == 0 || i >= 4) continue; // first shader has special logic
|
||||
this->pipelines = {{
|
||||
shaderpool.getPipeline(device, "gamma/0.spv"),
|
||||
shaderpool.getPipeline(device, "gamma/1.spv"),
|
||||
shaderpool.getPipeline(device, "gamma/2.spv"),
|
||||
shaderpool.getPipeline(device, "gamma/3.spv"),
|
||||
shaderpool.getPipeline(device, "gamma/4.spv"),
|
||||
shaderpool.getPipeline(device, "gamma/5.spv")
|
||||
}};
|
||||
for (size_t i = 1; i < 4; i++)
|
||||
this->descriptorSets.at(i - 1) = Core::DescriptorSet(device, pool,
|
||||
this->shaderModules.at(i));
|
||||
}
|
||||
for (size_t i = 0; i < genc; i++)
|
||||
this->n1DescriptorSets.emplace_back(device, pool,
|
||||
this->shaderModules.at(4));
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ Magic::Magic(const Core::Device& device, Pool::ShaderPool& shaderpool,
|
|||
{ 2, VK_DESCRIPTOR_TYPE_SAMPLER },
|
||||
{ 4+4+2+1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE },
|
||||
{ 3+3+2, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE } });
|
||||
this->pipeline = Core::Pipeline(device, this->shaderModule);
|
||||
this->pipeline = shaderpool.getPipeline(device, "magic.spv");
|
||||
for (size_t i = 0; i < genc; i++) {
|
||||
this->nDescriptorSets.emplace_back();
|
||||
for (size_t j = 0; j < 3; j++)
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ Merge::Merge(const Core::Device& device, Pool::ShaderPool& shaderpool,
|
|||
{ 2, VK_DESCRIPTOR_TYPE_SAMPLER },
|
||||
{ 5, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE },
|
||||
{ 1, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE } });
|
||||
this->pipeline = Core::Pipeline(device, this->shaderModule);
|
||||
this->pipeline = shaderpool.getPipeline(device, "merge.spv");
|
||||
for (size_t i = 0; i < genc; i++) {
|
||||
this->nDescriptorSets.emplace_back();
|
||||
for (size_t j = 0; j < 2; j++)
|
||||
|
|
|
|||
|
|
@ -31,13 +31,15 @@ Zeta::Zeta(const Core::Device& device, Pool::ShaderPool& shaderpool,
|
|||
{ 6, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE },
|
||||
{ 1, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE } })
|
||||
}};
|
||||
for (size_t i = 0; i < 4; i++) {
|
||||
this->pipelines.at(i) = Core::Pipeline(device,
|
||||
this->shaderModules.at(i));
|
||||
if (i == 3) continue;
|
||||
this->pipelines = {{
|
||||
shaderpool.getPipeline(device, "zeta/0.spv"),
|
||||
shaderpool.getPipeline(device, "zeta/1.spv"),
|
||||
shaderpool.getPipeline(device, "zeta/2.spv"),
|
||||
shaderpool.getPipeline(device, "zeta/3.spv")
|
||||
}};
|
||||
for (size_t i = 0; i < 3; i++)
|
||||
this->descriptorSets.at(i) = Core::DescriptorSet(device, pool,
|
||||
this->shaderModules.at(i));
|
||||
}
|
||||
for (size_t i = 0; i < genc; i++)
|
||||
this->nDescriptorSets.emplace_back(device, pool,
|
||||
this->shaderModules.at(3));
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue