21 compute_service->create_shader_module = [
this](
const std::string& path, uint32_t stage) -> std::shared_ptr<void> {
24 compute_service->create_descriptor_manager = [
this](uint32_t pool_size) -> std::shared_ptr<void> {
27 compute_service->create_descriptor_layout = [
this](
const std::shared_ptr<void>& mgr,
28 const std::vector<std::pair<uint32_t, uint32_t>>& bindings) ->
void* {
29 auto manager = std::static_pointer_cast<VKDescriptorManager>(mgr);
31 return reinterpret_cast<void*
>(
static_cast<VkDescriptorSetLayout
>(layout));
33 compute_service->create_compute_pipeline = [
this](
const std::shared_ptr<void>& shdr,
34 const std::vector<void*>& layouts,
35 uint32_t push_size) -> std::shared_ptr<void> {
36 auto shader = std::static_pointer_cast<VKShaderModule>(shdr);
37 std::vector<vk::DescriptorSetLayout> vk_layouts;
39 vk_layouts.reserve(layouts.size());
40 for (
auto* ptr : layouts) {
41 vk_layouts.emplace_back(
reinterpret_cast<VkDescriptorSetLayout
>(ptr));
46 compute_service->cleanup_resource = [
this](
const std::shared_ptr<void>& res) {
53 auto shader = std::make_shared<VKShaderModule>();
54 shader->create_from_spirv_file(
m_context.
get_device(), spirv_path, vk::ShaderStageFlagBits(stage));
62 auto manager = std::make_shared<VKDescriptorManager>();
70 const std::shared_ptr<VKDescriptorManager>& manager,
71 const std::vector<std::pair<uint32_t, uint32_t>>& bindings)
74 for (
const auto& [binding, type] : bindings) {
75 vk_bindings.
add_binding(binding, vk::DescriptorType(type), vk::ShaderStageFlagBits::eCompute);
82 const std::shared_ptr<VKShaderModule>& shader,
83 const std::vector<vk::DescriptorSetLayout>& layouts,
84 uint32_t push_constant_size)
86 auto pipeline = std::make_shared<VKComputePipeline>();
90 if (push_constant_size > 0) {
103 auto pipeline = std::make_shared<VKGraphicsPipeline>();
107 "Failed to create graphics pipeline");
114 "Created graphics pipeline");
124 "Cleanup compute resource requested (handled by shared_ptr)");
135 "Pipeline manager cleanup completed");
#define MF_INFO(comp, ctx,...)
#define MF_ERROR(comp, ctx,...)
#define MF_DEBUG(comp, ctx,...)
void setup_backend_service(const std::shared_ptr< Registry::Service::ComputeService > &compute_service)
std::vector< std::shared_ptr< VKComputePipeline > > m_managed_compute_pipelines
vk::DescriptorSetLayout create_descriptor_layout(const std::shared_ptr< VKDescriptorManager > &manager, const std::vector< std::pair< uint32_t, uint32_t > > &bindings)
Create a descriptor set layout.
void track_shader(const std::shared_ptr< VKShaderModule > &shader)
void cleanup_compute_resource(void *resource)
Cleanup a compute resource allocated by the backend.
std::vector< std::shared_ptr< VKDescriptorManager > > m_managed_descriptor_managers
std::shared_ptr< VKDescriptorManager > create_descriptor_manager(uint32_t pool_size)
Create a descriptor manager for managing descriptor sets.
BackendPipelineManager(VKContext &context)
std::vector< std::shared_ptr< VKGraphicsPipeline > > m_managed_graphics_pipelines
void track_descriptor_manager(const std::shared_ptr< VKDescriptorManager > &manager)
std::vector< std::shared_ptr< VKShaderModule > > m_managed_shaders
void track_graphics_pipeline(const std::shared_ptr< VKGraphicsPipeline > &pipeline)
std::shared_ptr< VKShaderModule > create_shader_module(const std::string &spirv_path, uint32_t stage)
Create a shader module from SPIR-V binary.
std::shared_ptr< VKComputePipeline > create_compute_pipeline(const std::shared_ptr< VKShaderModule > &shader, const std::vector< vk::DescriptorSetLayout > &layouts, uint32_t push_constant_size)
Create a compute pipeline.
void track_compute_pipeline(const std::shared_ptr< VKComputePipeline > &pipeline)
std::shared_ptr< VKGraphicsPipeline > create_graphics_pipeline(const GraphicsPipelineConfig &config)
Create graphics pipeline.
vk::Device get_device() const
Get logical device.
High-level wrapper for Vulkan instance and device.
@ GraphicsBackend
Graphics/visual rendering backend (Vulkan, OpenGL)
@ Core
Core engine, backend, subsystems.
std::vector< vk::DescriptorSetLayout > set_layouts
Descriptor layouts.
std::shared_ptr< VKShaderModule > shader
Compute shader.
void add_push_constant(vk::ShaderStageFlags stages, uint32_t size, uint32_t offset=0)
Configuration for creating a compute pipeline.
void add_binding(uint32_t binding, vk::DescriptorType type, vk::ShaderStageFlags stages, uint32_t count=1)
Configuration for creating a descriptor set layout.
Configuration for creating a graphics pipeline.