summaryrefslogtreecommitdiff
path: root/src/vk
diff options
context:
space:
mode:
authorFrederico Linhares <fred@linhares.blue>2023-09-29 14:57:40 -0300
committerFrederico Linhares <fred@linhares.blue>2023-09-29 14:57:40 -0300
commitb44c79e11ba574c74ae650e1430b1d173aacc910 (patch)
treedca509d3b2c07d6e36039cfd6b7102372d0fbba9 /src/vk
parentfd4279d77fdc64a534a2bbc05b2f5d3852c765f7 (diff)
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.
Diffstat (limited to 'src/vk')
-rw-r--r--src/vk/descriptor_set_layout.cpp203
-rw-r--r--src/vk/descriptor_set_layout.hpp38
-rw-r--r--src/vk/graphics_pipeline_2d_solid_layout.cpp80
-rw-r--r--src/vk/graphics_pipeline_2d_solid_layout.hpp4
-rw-r--r--src/vk/graphics_pipeline_2d_wired_layout.cpp40
-rw-r--r--src/vk/graphics_pipeline_2d_wired_layout.hpp8
-rw-r--r--src/vk/graphics_pipeline_3d.cpp2
-rw-r--r--src/vk/graphics_pipeline_3d_layout.cpp129
-rw-r--r--src/vk/graphics_pipeline_3d_layout.hpp3
-rw-r--r--src/vk/graphics_pipeline_3d_skeletal.cpp2
-rw-r--r--src/vk/renderer.cpp1
-rw-r--r--src/vk/skeletal_model.cpp2
-rw-r--r--src/vk/sprite.cpp2
-rw-r--r--src/vk/static_model.cpp2
-rw-r--r--src/vk/view_2d.cpp2
-rw-r--r--src/vk/view_3d.cpp2
16 files changed, 257 insertions, 263 deletions
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 <array>
+
+#include "../core.hpp"
+
+namespace
+{
+
+void
+load_world(void *obj)
+{
+ auto self = static_cast<VK::DescriptorSetLayout*>(obj);
+
+ std::array<VkDescriptorSetLayoutBinding, 2> 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<VK::DescriptorSetLayout*>(obj);
+
+ vkDestroyDescriptorSetLayout(
+ cg_core.vk_device_with_swapchain->device, self->world, nullptr);
+}
+
+void
+load_view(void *obj)
+{
+ auto self = static_cast<VK::DescriptorSetLayout*>(obj);
+
+ std::array<VkDescriptorSetLayoutBinding, 1> 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<uint32_t>(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<VK::DescriptorSetLayout*>(obj);
+
+ vkDestroyDescriptorSetLayout(
+ cg_core.vk_device_with_swapchain->device, self->view, nullptr);
+}
+
+void
+load_model(void *obj)
+{
+ auto self = static_cast<VK::DescriptorSetLayout*>(obj);
+
+ std::array<VkDescriptorSetLayoutBinding, 2> 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<uint32_t>(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<VK::DescriptorSetLayout*>(obj);
+
+ vkDestroyDescriptorSetLayout(
+ cg_core.vk_device_with_swapchain->device, self->model, nullptr);
+}
+
+void
+load_sprite(void *obj)
+{
+ auto self = static_cast<VK::DescriptorSetLayout*>(obj);
+
+ std::array<VkDescriptorSetLayoutBinding, 1> 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<uint32_t>(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<VK::DescriptorSetLayout*>(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
@@ -25,87 +25,13 @@ namespace
{
void
-load_descriptor_set_view(void *obj)
-{
- auto self = static_cast<VK::GraphicsPipeline2DSolidLayout*>(obj);
-
- std::array<VkDescriptorSetLayoutBinding, 1> 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<uint32_t>(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<VK::GraphicsPipeline2DSolidLayout*>(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<VK::GraphicsPipeline2DSolidLayout*>(obj);
-
- std::array<VkDescriptorSetLayoutBinding, 1> 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<uint32_t>(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<VK::GraphicsPipeline2DSolidLayout*>(obj);
-
- vkDestroyDescriptorSetLayout(
- cg_core.vk_device_with_swapchain->device, self->descriptor_set_sprite,
- nullptr);
-}
-
-void
load_pipeline(void *obj)
{
auto self = static_cast<VK::GraphicsPipeline2DSolidLayout*>(obj);
std::array<VkDescriptorSetLayout, 2> 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<VkPushConstantRange, 1> 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
@@ -26,49 +26,12 @@ namespace
{
void
-load_descriptor_set_view(void *obj)
-{
- auto self = static_cast<VK::GraphicsPipeline2DWiredLayout*>(obj);
-
- std::array<VkDescriptorSetLayoutBinding, 1> 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<uint32_t>(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<VK::GraphicsPipeline2DWiredLayout*>(obj);
-
- vkDestroyDescriptorSetLayout(
- cg_core.vk_device_with_swapchain->device, self->descriptor_set_view,
- nullptr);
-}
-
-void
load_pipeline(void *obj)
{
auto self = static_cast<VK::GraphicsPipeline2DWiredLayout*>(obj);
std::array<VkDescriptorSetLayout, 1> set_layouts{
- self->descriptor_set_view
+ cg_core.vk_descriptor_set_layout->view
};
std::array<VkPushConstantRange, 2> 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<VkDescriptorSetLayout> 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
@@ -25,134 +25,14 @@ namespace
{
void
-load_descriptor_set_world(void *obj)
-{
- auto self = static_cast<VK::GraphicsPipeline3DLayout*>(obj);
-
- std::array<VkDescriptorSetLayoutBinding, 2> 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<VK::GraphicsPipeline3DLayout*>(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<VK::GraphicsPipeline3DLayout*>(obj);
-
- std::array<VkDescriptorSetLayoutBinding, 1> 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<VK::GraphicsPipeline3DLayout*>(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<VK::GraphicsPipeline3DLayout*>(obj);
-
- std::array<VkDescriptorSetLayoutBinding, 2> 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<uint32_t>(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<VK::GraphicsPipeline3DLayout*>(obj);
-
- vkDestroyDescriptorSetLayout(
- cg_core.vk_device_with_swapchain->device,
- self->descriptor_set_model, nullptr);
-}
-
-void
load_pipeline(void *obj)
{
auto self = static_cast<VK::GraphicsPipeline3DLayout*>(obj);
std::array<VkDescriptorSetLayout, 3> 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<VkDescriptorSetLayout> 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<VkDescriptorSetLayout> 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<VkDescriptorSetLayout> 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<VkDescriptorSetLayout> 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<VkDescriptorSetLayout> 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<VkDescriptorSetLayout> 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;