From b44c79e11ba574c74ae650e1430b1d173aacc910 Mon Sep 17 00:00:00 2001 From: Frederico Linhares Date: Fri, 29 Sep 2023 14:57:40 -0300 Subject: refa Move all descriptor sets to a new class * src/vk/descriptor_set_layout.hpp: Moving all descriptor sets in the same class makes it easier to identify code duplication. * src/vk/graphics_pipeline_2d_solid_layout.cpp, src/vk/graphics_pipeline_2d_wired_layout.cpp, src/vk/graphics_pipeline_3d_layout.cpp: Remove redundant descriptor set layouts. --- src/core.cpp | 20 +++ src/core.hpp | 2 + src/vk/descriptor_set_layout.cpp | 203 +++++++++++++++++++++++++++ src/vk/descriptor_set_layout.hpp | 38 +++++ src/vk/graphics_pipeline_2d_solid_layout.cpp | 80 +---------- src/vk/graphics_pipeline_2d_solid_layout.hpp | 4 +- src/vk/graphics_pipeline_2d_wired_layout.cpp | 40 +----- src/vk/graphics_pipeline_2d_wired_layout.hpp | 8 +- src/vk/graphics_pipeline_3d.cpp | 2 +- src/vk/graphics_pipeline_3d_layout.cpp | 129 +---------------- src/vk/graphics_pipeline_3d_layout.hpp | 3 - src/vk/graphics_pipeline_3d_skeletal.cpp | 2 +- src/vk/renderer.cpp | 1 + src/vk/skeletal_model.cpp | 2 +- src/vk/sprite.cpp | 2 +- src/vk/static_model.cpp | 2 +- src/vk/view_2d.cpp | 2 +- src/vk/view_3d.cpp | 2 +- 18 files changed, 279 insertions(+), 263 deletions(-) create mode 100644 src/vk/descriptor_set_layout.cpp create mode 100644 src/vk/descriptor_set_layout.hpp diff --git a/src/core.cpp b/src/core.cpp index 986ecc1..34271bc 100644 --- a/src/core.cpp +++ b/src/core.cpp @@ -524,6 +524,25 @@ unload_vk_swapchain(void *obj) delete cg_core.vk_swapchain; } +void +load_vk_descriptor_set_layout(void *obj) +{ + try + { + cg_core.vk_descriptor_set_layout = new VK::DescriptorSetLayout(); + } + catch(const CommandError &e) + { + throw CommandError{"Failed to create descriptor set layouts."}; + } +} + +void +unload_vk_descriptor_set_layout(void *obj) +{ + delete cg_core.vk_descriptor_set_layout; +} + void load_vk_graphics_pipeline_3d_layout(void *obj) { @@ -728,6 +747,7 @@ const CommandChain cg_sCore::loader{ {&load_vk_devices, &unload_vk_devices}, {&load_vk_swapchain, &unload_vk_swapchain}, + {&load_vk_descriptor_set_layout, &unload_vk_descriptor_set_layout}, {&load_vk_graphics_pipeline_3d_layout, &unload_vk_graphics_pipeline_3d_layout}, {&load_vk_graphics_pipeline_2d_solid_layout, diff --git a/src/core.hpp b/src/core.hpp index d9e3c9e..3f5edae 100644 --- a/src/core.hpp +++ b/src/core.hpp @@ -48,6 +48,7 @@ #include "worker.hpp" #include "vk/device.hpp" +#include "vk/descriptor_set_layout.hpp" #include "vk/graphics_pipeline_2d_solid_layout.hpp" #include "vk/graphics_pipeline_2d_wired_layout.hpp" #include "vk/graphics_pipeline_2d_solid.hpp" @@ -117,6 +118,7 @@ struct cg_sCore VK::Device *vk_device_with_swapchain; VK::Swapchain *vk_swapchain; + VK::DescriptorSetLayout *vk_descriptor_set_layout; VK::GraphicsPipeline3DLayout *vk_graphics_pipeline_3d_layout; VK::GraphicsPipeline2DSolidLayout *vk_graphics_pipeline_2d_solid_layout; VK::GraphicsPipeline2DWiredLayout *vk_graphics_pipeline_2d_wired_layout; diff --git a/src/vk/descriptor_set_layout.cpp b/src/vk/descriptor_set_layout.cpp new file mode 100644 index 0000000..0a96a56 --- /dev/null +++ b/src/vk/descriptor_set_layout.cpp @@ -0,0 +1,203 @@ +/* + * Copyright 2022-2023 Frederico de Oliveira Linhares + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "descriptor_set_layout.hpp" + +#include + +#include "../core.hpp" + +namespace +{ + +void +load_world(void *obj) +{ + auto self = static_cast(obj); + + std::array set_layouts{}; + set_layouts[0].binding = 0; + set_layouts[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; + set_layouts[0].descriptorCount = 1; + set_layouts[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT; + set_layouts[0].pImmutableSamplers = nullptr; + + set_layouts[1].binding = 1; + set_layouts[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; + set_layouts[1].descriptorCount = 1; + set_layouts[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; + set_layouts[1].pImmutableSamplers = nullptr; + + VkDescriptorSetLayoutCreateInfo layout_info{}; + layout_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; + layout_info.pNext = nullptr; + layout_info.flags = 0; + layout_info.bindingCount = set_layouts.size(); + layout_info.pBindings = set_layouts.data(); + + if(vkCreateDescriptorSetLayout( + cg_core.vk_device_with_swapchain->device, &layout_info, nullptr, + &self->world) != VK_SUCCESS) + throw CommandError{ + "Failed to create Vulkan descriptor set layout for world view."}; +} + +void +unload_world(void *obj) +{ + auto self = static_cast(obj); + + vkDestroyDescriptorSetLayout( + cg_core.vk_device_with_swapchain->device, self->world, nullptr); +} + +void +load_view(void *obj) +{ + auto self = static_cast(obj); + + std::array layout_bindings{}; + + layout_bindings[0].binding = 0; + layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; + layout_bindings[0].descriptorCount = 1; + layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT; + layout_bindings[0].pImmutableSamplers = nullptr; + + VkDescriptorSetLayoutCreateInfo layout_info{}; + layout_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; + layout_info.pNext = nullptr; + layout_info.flags = 0; + layout_info.bindingCount = static_cast(layout_bindings.size()); + layout_info.pBindings = layout_bindings.data(); + + if(vkCreateDescriptorSetLayout( + cg_core.vk_device_with_swapchain->device, &layout_info, nullptr, + &self->view) != VK_SUCCESS) + throw CommandError{ + "Failed to create Vulkan descriptor set layout for view."}; +} + +void +unload_view(void *obj) +{ + auto self = static_cast(obj); + + vkDestroyDescriptorSetLayout( + cg_core.vk_device_with_swapchain->device, self->view, nullptr); +} + +void +load_model(void *obj) +{ + auto self = static_cast(obj); + + std::array layout_bindings; + layout_bindings[0].binding = 0; + layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; + layout_bindings[0].descriptorCount = 1; + layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT; + layout_bindings[0].pImmutableSamplers = nullptr; + layout_bindings[1].binding = 1; + layout_bindings[1].descriptorType = + VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; + layout_bindings[1].descriptorCount = 1; + layout_bindings[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; + layout_bindings[1].pImmutableSamplers = nullptr; + + VkDescriptorSetLayoutCreateInfo layout_info{}; + layout_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; + layout_info.pNext = nullptr; + layout_info.flags = 0; + layout_info.bindingCount = static_cast(layout_bindings.size()); + layout_info.pBindings = layout_bindings.data(); + + if(vkCreateDescriptorSetLayout( + cg_core.vk_device_with_swapchain->device, &layout_info, nullptr, + &self->model) != VK_SUCCESS) + throw CommandError{ + "Failed to create Vulkan descriptor set layout for model instance."}; +} + +void +unload_model(void *obj) +{ + auto self = static_cast(obj); + + vkDestroyDescriptorSetLayout( + cg_core.vk_device_with_swapchain->device, self->model, nullptr); +} + +void +load_sprite(void *obj) +{ + auto self = static_cast(obj); + + std::array layout_bindings{}; + + layout_bindings[0].binding = 0; + layout_bindings[0].descriptorType = + VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; + layout_bindings[0].descriptorCount = 1; + layout_bindings[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; + layout_bindings[0].pImmutableSamplers = nullptr; + + VkDescriptorSetLayoutCreateInfo layout_info{}; + layout_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; + layout_info.pNext = nullptr; + layout_info.flags = 0; + layout_info.bindingCount = static_cast(layout_bindings.size()); + layout_info.pBindings = layout_bindings.data(); + + if(vkCreateDescriptorSetLayout( + cg_core.vk_device_with_swapchain->device, &layout_info, nullptr, + &self->sprite) != VK_SUCCESS) + throw CommandError{ + "Failed to create Vulkan descriptor set layout for sprites."}; +} + +void +unload_sprite(void *obj) +{ + auto self = static_cast(obj); + + vkDestroyDescriptorSetLayout( + cg_core.vk_device_with_swapchain->device, self->sprite, nullptr); +} + +const CommandChain loader{ + {&load_world, &unload_world}, + {&load_view, &unload_view}, + {&load_model, &unload_model}, + {&load_sprite, &unload_sprite}, +}; + +} + +namespace VK +{ + +DescriptorSetLayout::DescriptorSetLayout() +{ + loader.execute(this); +} + +DescriptorSetLayout::~DescriptorSetLayout() +{ + loader.revert(this); +} + +} diff --git a/src/vk/descriptor_set_layout.hpp b/src/vk/descriptor_set_layout.hpp new file mode 100644 index 0000000..5401fed --- /dev/null +++ b/src/vk/descriptor_set_layout.hpp @@ -0,0 +1,38 @@ +/* + * Copyright 2022-2023 Frederico de Oliveira Linhares + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef CANDY_GEAR_VK_DESCRIPTOR_SET_LAYOUT_H +#define CANDY_GEAR_VK_DESCRIPTOR_SET_LAYOUT_H 1 + +#include "core.hpp" + +namespace VK +{ + +struct DescriptorSetLayout +{ + VkDescriptorSetLayout world; + VkDescriptorSetLayout view; + VkDescriptorSetLayout model; + VkDescriptorSetLayout sprite; + + DescriptorSetLayout(); + ~DescriptorSetLayout(); +}; + +} + +#endif /* CANDY_GEAR_VK_DESCRIPTOR_SET_LAYOUT_H */ diff --git a/src/vk/graphics_pipeline_2d_solid_layout.cpp b/src/vk/graphics_pipeline_2d_solid_layout.cpp index e6c871f..cbd656a 100644 --- a/src/vk/graphics_pipeline_2d_solid_layout.cpp +++ b/src/vk/graphics_pipeline_2d_solid_layout.cpp @@ -24,88 +24,14 @@ namespace { -void -load_descriptor_set_view(void *obj) -{ - auto self = static_cast(obj); - - std::array layout_bindings{}; - - layout_bindings[0].binding = 0; - layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; - layout_bindings[0].descriptorCount = 1; - layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT; - layout_bindings[0].pImmutableSamplers = nullptr; - - VkDescriptorSetLayoutCreateInfo layout_info{}; - layout_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; - layout_info.pNext = nullptr; - layout_info.flags = 0; - layout_info.bindingCount = static_cast(layout_bindings.size()); - layout_info.pBindings = layout_bindings.data(); - - if(vkCreateDescriptorSetLayout( - cg_core.vk_device_with_swapchain->device, &layout_info, nullptr, - &self->descriptor_set_view) != VK_SUCCESS) - throw CommandError{ - "Failed to create Vulkan descriptor set layout for projection."}; -} - -void -unload_descriptor_set_view(void *obj) -{ - auto self = static_cast(obj); - - vkDestroyDescriptorSetLayout( - cg_core.vk_device_with_swapchain->device, self->descriptor_set_view, - nullptr); -} - -void -load_descriptor_set_sprite(void *obj) -{ - auto self = static_cast(obj); - - std::array layout_bindings{}; - - layout_bindings[0].binding = 0; - layout_bindings[0].descriptorType = - VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; - layout_bindings[0].descriptorCount = 1; - layout_bindings[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; - layout_bindings[0].pImmutableSamplers = nullptr; - - VkDescriptorSetLayoutCreateInfo layout_info{}; - layout_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; - layout_info.pNext = nullptr; - layout_info.flags = 0; - layout_info.bindingCount = static_cast(layout_bindings.size()); - layout_info.pBindings = layout_bindings.data(); - - if(vkCreateDescriptorSetLayout( - cg_core.vk_device_with_swapchain->device, &layout_info, nullptr, - &self->descriptor_set_sprite) != VK_SUCCESS) - throw CommandError{ - "Failed to create Vulkan descriptor set layout for sprites."}; -} - -void -unload_descriptor_set_sprite(void *obj) -{ - auto self = static_cast(obj); - - vkDestroyDescriptorSetLayout( - cg_core.vk_device_with_swapchain->device, self->descriptor_set_sprite, - nullptr); -} - void load_pipeline(void *obj) { auto self = static_cast(obj); std::array set_layouts{ - self->descriptor_set_view, self->descriptor_set_sprite + cg_core.vk_descriptor_set_layout->view, + cg_core.vk_descriptor_set_layout->sprite }; std::array push_constants; @@ -207,8 +133,6 @@ unload_render_pass(void *obj) } const CommandChain loader{ - {&load_descriptor_set_view, &unload_descriptor_set_view}, - {&load_descriptor_set_sprite, &unload_descriptor_set_sprite}, {&load_pipeline, &unload_pipeline}, {&load_render_pass, &unload_render_pass} }; diff --git a/src/vk/graphics_pipeline_2d_solid_layout.hpp b/src/vk/graphics_pipeline_2d_solid_layout.hpp index b04d239..59a5c5e 100644 --- a/src/vk/graphics_pipeline_2d_solid_layout.hpp +++ b/src/vk/graphics_pipeline_2d_solid_layout.hpp @@ -1,5 +1,5 @@ /* - * Copyright 2022 Frederico de Oliveira Linhares + * Copyright 2022-2023 Frederico de Oliveira Linhares * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,8 +24,6 @@ namespace VK struct GraphicsPipeline2DSolidLayout { - VkDescriptorSetLayout descriptor_set_view; - VkDescriptorSetLayout descriptor_set_sprite; VkPipelineLayout pipeline; VkRenderPass render_pass; diff --git a/src/vk/graphics_pipeline_2d_wired_layout.cpp b/src/vk/graphics_pipeline_2d_wired_layout.cpp index 3f259e3..fe935eb 100644 --- a/src/vk/graphics_pipeline_2d_wired_layout.cpp +++ b/src/vk/graphics_pipeline_2d_wired_layout.cpp @@ -25,50 +25,13 @@ namespace { -void -load_descriptor_set_view(void *obj) -{ - auto self = static_cast(obj); - - std::array layout_bindings{}; - - layout_bindings[0].binding = 0; - layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; - layout_bindings[0].descriptorCount = 1; - layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT; - layout_bindings[0].pImmutableSamplers = nullptr; - - VkDescriptorSetLayoutCreateInfo layout_info{}; - layout_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; - layout_info.pNext = nullptr; - layout_info.flags = 0; - layout_info.bindingCount = static_cast(layout_bindings.size()); - layout_info.pBindings = layout_bindings.data(); - - if(vkCreateDescriptorSetLayout( - cg_core.vk_device_with_swapchain->device, &layout_info, nullptr, - &self->descriptor_set_view) != VK_SUCCESS) - throw CommandError{ - "Failed to create Vulkan descriptor set layout for projection."}; -} - -void -unload_descriptor_set_view(void *obj) -{ - auto self = static_cast(obj); - - vkDestroyDescriptorSetLayout( - cg_core.vk_device_with_swapchain->device, self->descriptor_set_view, - nullptr); -} - void load_pipeline(void *obj) { auto self = static_cast(obj); std::array set_layouts{ - self->descriptor_set_view + cg_core.vk_descriptor_set_layout->view }; std::array push_constants; @@ -174,7 +137,6 @@ unload_render_pass(void *obj) } const CommandChain loader{ - {&load_descriptor_set_view, &unload_descriptor_set_view}, {&load_pipeline, &unload_pipeline}, {&load_render_pass, &unload_render_pass} }; diff --git a/src/vk/graphics_pipeline_2d_wired_layout.hpp b/src/vk/graphics_pipeline_2d_wired_layout.hpp index 339aebe..f08aeaa 100644 --- a/src/vk/graphics_pipeline_2d_wired_layout.hpp +++ b/src/vk/graphics_pipeline_2d_wired_layout.hpp @@ -1,5 +1,5 @@ /* - * Copyright 2022 Frederico de Oliveira Linhares + * Copyright 2022-2023 Frederico de Oliveira Linhares * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,14 +22,8 @@ namespace VK { -struct UBOModel2D -{ - glm::vec3 color; -}; - struct GraphicsPipeline2DWiredLayout { - VkDescriptorSetLayout descriptor_set_view; VkPipelineLayout pipeline; VkRenderPass render_pass; diff --git a/src/vk/graphics_pipeline_3d.cpp b/src/vk/graphics_pipeline_3d.cpp index f96b082..3d4b7cd 100644 --- a/src/vk/graphics_pipeline_3d.cpp +++ b/src/vk/graphics_pipeline_3d.cpp @@ -123,7 +123,7 @@ load_descriptor_sets_world(void *obj) std::vector layouts( cg_core.vk_swapchain->images_count, - cg_core.vk_graphics_pipeline_3d_layout->descriptor_set_world); + cg_core.vk_descriptor_set_layout->world); VkDescriptorSetAllocateInfo alloc_info{}; alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; diff --git a/src/vk/graphics_pipeline_3d_layout.cpp b/src/vk/graphics_pipeline_3d_layout.cpp index 644aac9..e5a0c82 100644 --- a/src/vk/graphics_pipeline_3d_layout.cpp +++ b/src/vk/graphics_pipeline_3d_layout.cpp @@ -24,135 +24,15 @@ namespace { -void -load_descriptor_set_world(void *obj) -{ - auto self = static_cast(obj); - - std::array set_layouts{}; - set_layouts[0].binding = 0; - set_layouts[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; - set_layouts[0].descriptorCount = 1; - set_layouts[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT; - set_layouts[0].pImmutableSamplers = nullptr; - - set_layouts[1].binding = 1; - set_layouts[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; - set_layouts[1].descriptorCount = 1; - set_layouts[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; - set_layouts[1].pImmutableSamplers = nullptr; - - VkDescriptorSetLayoutCreateInfo layout_info{}; - layout_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; - layout_info.pNext = nullptr; - layout_info.flags = 0; - layout_info.bindingCount = set_layouts.size(); - layout_info.pBindings = set_layouts.data(); - - if(vkCreateDescriptorSetLayout( - cg_core.vk_device_with_swapchain->device, &layout_info, nullptr, - &self->descriptor_set_world) != VK_SUCCESS) - throw CommandError{ - "Failed to create Vulkan descriptor set layout for world view."}; -} - -void -unload_descriptor_set_world(void *obj) -{ - auto self = static_cast(obj); - - vkDestroyDescriptorSetLayout( - cg_core.vk_device_with_swapchain->device, self->descriptor_set_world, - nullptr); -} - -void -load_descriptor_set_view(void *obj) -{ - auto self = static_cast(obj); - - std::array set_layouts{}; - set_layouts[0].binding = 0; - set_layouts[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; - set_layouts[0].descriptorCount = 1; - set_layouts[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT; - set_layouts[0].pImmutableSamplers = nullptr; - - VkDescriptorSetLayoutCreateInfo layout_info{}; - layout_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; - layout_info.pNext = nullptr; - layout_info.flags = 0; - layout_info.bindingCount = set_layouts.size(); - layout_info.pBindings = set_layouts.data(); - - if(vkCreateDescriptorSetLayout( - cg_core.vk_device_with_swapchain->device, &layout_info, nullptr, - &self->descriptor_set_view) != VK_SUCCESS) - throw CommandError{ - "Failed to create Vulkan descriptor set layout for world view."}; -} - -void -unload_descriptor_set_view(void *obj) -{ - auto self = static_cast(obj); - - vkDestroyDescriptorSetLayout( - cg_core.vk_device_with_swapchain->device, self->descriptor_set_view, - nullptr); -} - -void -load_descriptor_set_model(void *obj) -{ - auto self = static_cast(obj); - - std::array layout_bindings; - layout_bindings[0].binding = 0; - layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; - layout_bindings[0].descriptorCount = 1; - layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT; - layout_bindings[0].pImmutableSamplers = nullptr; - layout_bindings[1].binding = 1; - layout_bindings[1].descriptorType = - VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; - layout_bindings[1].descriptorCount = 1; - layout_bindings[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; - layout_bindings[1].pImmutableSamplers = nullptr; - - VkDescriptorSetLayoutCreateInfo layout_info{}; - layout_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; - layout_info.pNext = nullptr; - layout_info.flags = 0; - layout_info.bindingCount = static_cast(layout_bindings.size()); - layout_info.pBindings = layout_bindings.data(); - - if(vkCreateDescriptorSetLayout( - cg_core.vk_device_with_swapchain->device, &layout_info, nullptr, - &self->descriptor_set_model) != VK_SUCCESS) - throw CommandError{ - "Failed to create Vulkan descriptor set layout for model instance."}; -} - -void -unload_descriptor_set_model(void *obj) -{ - auto self = static_cast(obj); - - vkDestroyDescriptorSetLayout( - cg_core.vk_device_with_swapchain->device, - self->descriptor_set_model, nullptr); -} - void load_pipeline(void *obj) { auto self = static_cast(obj); std::array set_layouts{ - self->descriptor_set_world, - self->descriptor_set_view, - self->descriptor_set_model}; + cg_core.vk_descriptor_set_layout->world, + cg_core.vk_descriptor_set_layout->view, + cg_core.vk_descriptor_set_layout->model}; VkPipelineLayoutCreateInfo pipeline_layout_info{}; pipeline_layout_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; @@ -263,9 +143,6 @@ unload_render_pass(void *obj) } const CommandChain loader{ - {&load_descriptor_set_world, &unload_descriptor_set_world}, - {&load_descriptor_set_view, &unload_descriptor_set_view}, - {&load_descriptor_set_model, &unload_descriptor_set_model}, {&load_pipeline, &unload_pipeline}, {&load_render_pass, &unload_render_pass} }; diff --git a/src/vk/graphics_pipeline_3d_layout.hpp b/src/vk/graphics_pipeline_3d_layout.hpp index f69e3ab..2117fb6 100644 --- a/src/vk/graphics_pipeline_3d_layout.hpp +++ b/src/vk/graphics_pipeline_3d_layout.hpp @@ -24,9 +24,6 @@ namespace VK struct GraphicsPipeline3DLayout { - VkDescriptorSetLayout descriptor_set_world; - VkDescriptorSetLayout descriptor_set_view; - VkDescriptorSetLayout descriptor_set_model; VkPipelineLayout pipeline; VkRenderPass render_pass; diff --git a/src/vk/graphics_pipeline_3d_skeletal.cpp b/src/vk/graphics_pipeline_3d_skeletal.cpp index 43f21d6..7bf2521 100644 --- a/src/vk/graphics_pipeline_3d_skeletal.cpp +++ b/src/vk/graphics_pipeline_3d_skeletal.cpp @@ -123,7 +123,7 @@ load_descriptor_sets_world(void *obj) std::vector layouts( cg_core.vk_swapchain->images_count, - cg_core.vk_graphics_pipeline_3d_layout->descriptor_set_world); + cg_core.vk_descriptor_set_layout->world); VkDescriptorSetAllocateInfo alloc_info{}; alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; diff --git a/src/vk/renderer.cpp b/src/vk/renderer.cpp index c7eda2e..753b5f7 100644 --- a/src/vk/renderer.cpp +++ b/src/vk/renderer.cpp @@ -374,6 +374,7 @@ Renderer::draw() { // Clear images for the current frame because we are skipping this frame. this->skeletal_models_to_draw[cg_core.vk_swapchain->current_frame].clear(); + this->static_models_to_draw[cg_core.vk_swapchain->current_frame].clear(); for(auto &view: this->views_2d) view->sprites_to_draw[cg_core.vk_swapchain->current_frame].clear(); for(auto &view: this->views_3d) diff --git a/src/vk/skeletal_model.cpp b/src/vk/skeletal_model.cpp index b201b25..71957f9 100644 --- a/src/vk/skeletal_model.cpp +++ b/src/vk/skeletal_model.cpp @@ -92,7 +92,7 @@ load_descriptor_sets(void *obj) std::vector layouts( cg_core.vk_swapchain->images_count, - cg_core.vk_graphics_pipeline_3d_layout->descriptor_set_model); + cg_core.vk_descriptor_set_layout->model); VkDescriptorSetAllocateInfo alloc_info{}; alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; diff --git a/src/vk/sprite.cpp b/src/vk/sprite.cpp index 069bf6a..146d07d 100644 --- a/src/vk/sprite.cpp +++ b/src/vk/sprite.cpp @@ -115,7 +115,7 @@ load_descriptor_sets(void *obj) std::vector layouts( cg_core.vk_swapchain->images_count, - cg_core.vk_graphics_pipeline_2d_solid_layout->descriptor_set_sprite); + cg_core.vk_descriptor_set_layout->sprite); VkDescriptorSetAllocateInfo alloc_info{}; alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; diff --git a/src/vk/static_model.cpp b/src/vk/static_model.cpp index 91f44ab..4de0302 100644 --- a/src/vk/static_model.cpp +++ b/src/vk/static_model.cpp @@ -92,7 +92,7 @@ load_descriptor_sets(void *obj) std::vector layouts( cg_core.vk_swapchain->images_count, - cg_core.vk_graphics_pipeline_3d_layout->descriptor_set_model); + cg_core.vk_descriptor_set_layout->model); VkDescriptorSetAllocateInfo alloc_info{}; alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; diff --git a/src/vk/view_2d.cpp b/src/vk/view_2d.cpp index 799327f..c628a18 100644 --- a/src/vk/view_2d.cpp +++ b/src/vk/view_2d.cpp @@ -57,7 +57,7 @@ load_descriptor_sets_2d(void *obj) std::vector layouts( cg_core.vk_swapchain->images_count, - cg_core.vk_graphics_pipeline_2d_solid_layout->descriptor_set_view); + cg_core.vk_descriptor_set_layout->view); VkDescriptorSetAllocateInfo alloc_info{}; alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; diff --git a/src/vk/view_3d.cpp b/src/vk/view_3d.cpp index eb2421e..9040545 100644 --- a/src/vk/view_3d.cpp +++ b/src/vk/view_3d.cpp @@ -57,7 +57,7 @@ load_descriptor_sets_3d(void *obj) std::vector layouts( cg_core.vk_swapchain->images_count, - cg_core.vk_graphics_pipeline_3d_layout->descriptor_set_view); + cg_core.vk_descriptor_set_layout->view); VkDescriptorSetAllocateInfo alloc_info{}; alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; -- cgit v1.2.3