Вынес управление VkRenderPass в отдельный класс
This commit is contained in:
@@ -31,47 +31,6 @@ VkShaderModule UwURenderEngine::create_shader_module(const std::string& code) co
|
||||
}
|
||||
|
||||
|
||||
void UwURenderEngine::create_render_pass()
|
||||
{
|
||||
VkAttachmentDescription attachment_description{};
|
||||
attachment_description.format = swapchain_.get_image_format();
|
||||
attachment_description.samples = VK_SAMPLE_COUNT_1_BIT;
|
||||
attachment_description.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
|
||||
attachment_description.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
|
||||
attachment_description.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
|
||||
attachment_description.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
|
||||
attachment_description.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
|
||||
attachment_description.finalLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
|
||||
|
||||
VkAttachmentReference attachment_reference;
|
||||
attachment_reference.attachment = 0;
|
||||
attachment_reference.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
|
||||
|
||||
VkSubpassDescription subpass_description{};
|
||||
subpass_description.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
|
||||
subpass_description.colorAttachmentCount = 1;
|
||||
subpass_description.pColorAttachments = &attachment_reference;
|
||||
|
||||
VkSubpassDependency dependency{};
|
||||
dependency.srcSubpass = VK_SUBPASS_EXTERNAL;
|
||||
dependency.dstSubpass = 0;
|
||||
dependency.srcStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
|
||||
dependency.srcAccessMask = 0;
|
||||
dependency.dstStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
|
||||
dependency.dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
|
||||
|
||||
VkRenderPassCreateInfo render_pass_info{};
|
||||
render_pass_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
|
||||
render_pass_info.attachmentCount = 1;
|
||||
render_pass_info.pAttachments = &attachment_description;
|
||||
render_pass_info.subpassCount = 1;
|
||||
render_pass_info.pSubpasses = &subpass_description;
|
||||
render_pass_info.dependencyCount = 1;
|
||||
render_pass_info.pDependencies = &dependency;
|
||||
|
||||
VK_CHECK(vkCreateRenderPass(device_.get_native(), &render_pass_info, nullptr, &render_pass_))
|
||||
}
|
||||
|
||||
void UwURenderEngine::create_description_set_layout()
|
||||
{
|
||||
VkDescriptorSetLayoutBinding ubo_layout_binding;
|
||||
@@ -287,7 +246,7 @@ void UwURenderEngine::create_graphics_pipeline()
|
||||
graphics_pipeline_info.pViewportState = &viewport_info;
|
||||
graphics_pipeline_info.pVertexInputState = &vertex_input_info;
|
||||
graphics_pipeline_info.pDepthStencilState = nullptr;
|
||||
graphics_pipeline_info.renderPass = render_pass_;
|
||||
graphics_pipeline_info.renderPass = render_pass_.get_native();
|
||||
graphics_pipeline_info.subpass = 0;
|
||||
graphics_pipeline_info.basePipelineHandle = nullptr;
|
||||
graphics_pipeline_info.basePipelineIndex = -1;
|
||||
@@ -304,7 +263,7 @@ void UwURenderEngine::create_framebuffers()
|
||||
|
||||
VkFramebufferCreateInfo framebuffer_info{};
|
||||
framebuffer_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
|
||||
framebuffer_info.renderPass = render_pass_;
|
||||
framebuffer_info.renderPass = render_pass_.get_native();
|
||||
framebuffer_info.attachmentCount = 1;
|
||||
framebuffer_info.width = swapchain_.get_extent().width;
|
||||
framebuffer_info.height = swapchain_.get_extent().height;
|
||||
@@ -433,7 +392,7 @@ void UwURenderEngine::record_command_buffer(VkCommandBuffer command_buffer, uint
|
||||
constexpr VkClearValue clear_color = {{{0.0f, 0.0f, 0.0f, 1.0f}}};
|
||||
VkRenderPassBeginInfo render_pass_begin_info{};
|
||||
render_pass_begin_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
|
||||
render_pass_begin_info.renderPass = render_pass_;
|
||||
render_pass_begin_info.renderPass = render_pass_.get_native();
|
||||
render_pass_begin_info.framebuffer = framebuffers_[image_index];
|
||||
render_pass_begin_info.renderArea.offset = {0, 0};
|
||||
render_pass_begin_info.renderArea.extent = swapchain_.get_extent();
|
||||
@@ -551,9 +510,9 @@ instance_(core),
|
||||
surface_(instance_, get_window()),
|
||||
physical_device_(instance_, surface_, deviceExtensions),
|
||||
device_(physical_device_, deviceExtensions),
|
||||
swapchain_(surface_, physical_device_, device_, get_window())
|
||||
swapchain_(surface_, physical_device_, device_, get_window()),
|
||||
render_pass_(device_, swapchain_)
|
||||
{
|
||||
create_render_pass();
|
||||
create_description_set_layout();
|
||||
create_uniform_buffers();
|
||||
create_descriptor_pool();
|
||||
@@ -624,9 +583,6 @@ UwURenderEngine::~UwURenderEngine()
|
||||
|
||||
if (ubo_layout_binding_ != VK_NULL_HANDLE)
|
||||
vkDestroyDescriptorSetLayout(device_.get_native(), ubo_layout_binding_, nullptr);
|
||||
|
||||
if (render_pass_ != VK_NULL_HANDLE)
|
||||
vkDestroyRenderPass(device_.get_native(), render_pass_, nullptr);
|
||||
}
|
||||
|
||||
void UwURenderEngine::start()
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include "VkObjects/Device.hpp"
|
||||
#include "VkObjects/Instance.hpp"
|
||||
#include "VkObjects/PhysicalDevice.hpp"
|
||||
#include "VkObjects/RenderPass.hpp"
|
||||
#include "VkObjects/Surface.hpp"
|
||||
#include "VkObjects/Swapchain.hpp"
|
||||
|
||||
@@ -22,7 +23,7 @@ class GPU_GarbageCollector;
|
||||
|
||||
#define GET_RENDER_ENGINE static_cast<UwURenderEngine*>(GetWorld()->GetGameInstance().GetCore().GetRenderEngine())
|
||||
|
||||
class UwURenderEngine : public RenderEngineBase
|
||||
class UwURenderEngine final : public RenderEngineBase
|
||||
{
|
||||
struct UniformBufferObject {
|
||||
glm::mat4 model;
|
||||
@@ -67,7 +68,7 @@ class UwURenderEngine : public RenderEngineBase
|
||||
VkObjects::PhysicalDevice physical_device_;
|
||||
VkObjects::Device device_;
|
||||
VkObjects::Swapchain swapchain_;
|
||||
VkRenderPass render_pass_ = VK_NULL_HANDLE;
|
||||
VkObjects::RenderPass render_pass_;
|
||||
VkDescriptorSetLayout ubo_layout_binding_ = VK_NULL_HANDLE;
|
||||
VkDescriptorPool descriptor_pool_ = VK_NULL_HANDLE;
|
||||
std::vector<VkDescriptorSet> descriptor_sets_;
|
||||
@@ -91,7 +92,6 @@ class UwURenderEngine : public RenderEngineBase
|
||||
|
||||
VkShaderModule create_shader_module(const std::string& code) const;
|
||||
|
||||
void create_render_pass();
|
||||
void create_description_set_layout();
|
||||
void create_uniform_buffers();
|
||||
void create_descriptor_pool();
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace VkObjects
|
||||
{
|
||||
class PhysicalDevice;
|
||||
|
||||
class Device
|
||||
class Device final
|
||||
{
|
||||
VkDevice device_ = nullptr;
|
||||
VkQueue graphics_queue_ = nullptr;
|
||||
|
||||
@@ -7,7 +7,7 @@ class CoreInstance;
|
||||
|
||||
namespace VkObjects
|
||||
{
|
||||
class Instance
|
||||
class Instance final
|
||||
{
|
||||
VkInstance instance_ = nullptr;
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace VkObjects
|
||||
class Surface;
|
||||
class Instance;
|
||||
|
||||
class PhysicalDevice
|
||||
class PhysicalDevice final
|
||||
{
|
||||
public:
|
||||
struct QueueFamilyIndices
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
#include "RenderPass.hpp"
|
||||
|
||||
#include "DeviceFunctions/DeviceFunctions.hpp"
|
||||
#include "Swapchain.hpp"
|
||||
#include "Device.hpp"
|
||||
|
||||
VkObjects::RenderPass::RenderPass(const Device& device, const Swapchain& swapchain):device_(device)
|
||||
{
|
||||
VkAttachmentDescription attachment_description{};
|
||||
attachment_description.format = swapchain.get_image_format();
|
||||
attachment_description.samples = VK_SAMPLE_COUNT_1_BIT;
|
||||
attachment_description.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
|
||||
attachment_description.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
|
||||
attachment_description.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
|
||||
attachment_description.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
|
||||
attachment_description.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
|
||||
attachment_description.finalLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
|
||||
|
||||
VkAttachmentReference attachment_reference;
|
||||
attachment_reference.attachment = 0;
|
||||
attachment_reference.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
|
||||
|
||||
VkSubpassDescription subpass_description{};
|
||||
subpass_description.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
|
||||
subpass_description.colorAttachmentCount = 1;
|
||||
subpass_description.pColorAttachments = &attachment_reference;
|
||||
|
||||
VkSubpassDependency dependency{};
|
||||
dependency.srcSubpass = VK_SUBPASS_EXTERNAL;
|
||||
dependency.dstSubpass = 0;
|
||||
dependency.srcStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
|
||||
dependency.srcAccessMask = 0;
|
||||
dependency.dstStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
|
||||
dependency.dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
|
||||
|
||||
VkRenderPassCreateInfo render_pass_info{};
|
||||
render_pass_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
|
||||
render_pass_info.attachmentCount = 1;
|
||||
render_pass_info.pAttachments = &attachment_description;
|
||||
render_pass_info.subpassCount = 1;
|
||||
render_pass_info.pSubpasses = &subpass_description;
|
||||
render_pass_info.dependencyCount = 1;
|
||||
render_pass_info.pDependencies = &dependency;
|
||||
|
||||
VK_CHECK(vkCreateRenderPass(device_.get_native(), &render_pass_info, nullptr, &render_pass_))
|
||||
}
|
||||
|
||||
VkObjects::RenderPass::~RenderPass()
|
||||
{
|
||||
if (render_pass_ != VK_NULL_HANDLE)
|
||||
vkDestroyRenderPass(device_.get_native(), render_pass_, nullptr);
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#include <vulkan/vulkan.h>
|
||||
|
||||
namespace VkObjects
|
||||
{
|
||||
class Swapchain;
|
||||
class Device;
|
||||
|
||||
class RenderPass final
|
||||
{
|
||||
const Device& device_;
|
||||
VkRenderPass render_pass_;
|
||||
public:
|
||||
explicit RenderPass(const Device& device, const Swapchain& swapchain);
|
||||
~RenderPass();
|
||||
|
||||
inline VkRenderPass get_native() const { return render_pass_; }
|
||||
};
|
||||
}
|
||||
@@ -8,7 +8,7 @@ namespace VkObjects
|
||||
{
|
||||
class Instance;
|
||||
|
||||
class Surface
|
||||
class Surface final
|
||||
{
|
||||
VkSurfaceKHR surface_ = nullptr;
|
||||
const Instance& instance_;
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace VkObjects
|
||||
class PhysicalDevice;
|
||||
class Surface;
|
||||
|
||||
class Swapchain
|
||||
class Swapchain final
|
||||
{
|
||||
struct SwapchainSupportDetails
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user