[WIP] Refactor creation of descriptorsets

This commit is contained in:
2023-08-30 23:11:11 +02:00
parent 5aec41ead4
commit 93c75763c7
19 changed files with 201 additions and 173 deletions

View File

@@ -8,9 +8,12 @@
#include "Vulkan/Context.hpp"
#include "Scene/Shader/Shader.hpp"
#include "Vulkan/Resources/IShaderOwner.hpp"
#include "Scene/Shader/DescriptorInputDescription.hpp"
namespace openVulkanoCpp::Vulkan
{
static_assert(sizeof(vk::DescriptorSetLayoutBinding) == sizeof(DescriptorSetLayoutBinding));
VulkanShader::~VulkanShader()
{
if (!shader) return;
@@ -19,6 +22,8 @@ namespace openVulkanoCpp::Vulkan
{
device.destroyShaderModule(shaderModule);
}
device.destroyPipelineLayout(pipelineLayout);
device.destroyDescriptorSetLayout(descriptorSetLayout);
}
void VulkanShader::Init(Context* context, Scene::Shader* shader, IShaderOwner* owner)
@@ -98,10 +103,10 @@ namespace openVulkanoCpp::Vulkan
colorInfo.attachmentCount = 1;
colorInfo.pAttachments = &colorBlendAttachment;
CreatePipelineLayout();
vk::GraphicsPipelineCreateInfo pipelineCreateInfo = { {}, static_cast<uint32_t>(shaderStageCreateInfo.size()), shaderStageCreateInfo.data(), &pipelineVertexInputStateCreateInfo, &inputAssembly,
nullptr, &viewportStateCreateInfo, &rasterizer, &msaa, &depth, &colorInfo, nullptr, context->pipeline.pipelineLayout, context->swapChainRenderPass.renderPass };
nullptr, &viewportStateCreateInfo, &rasterizer, &msaa, &depth, &colorInfo, nullptr, pipelineLayout, context->swapChainRenderPass.renderPass };
pipeline = this->device.createGraphicsPipeline({}, pipelineCreateInfo).value;
}
@@ -111,13 +116,24 @@ namespace openVulkanoCpp::Vulkan
BuildPipeline();
}
void VulkanShader::Record(vk::CommandBuffer& cmdBuffer, uint32_t bufferId)
void VulkanShader::Record(VulkanDrawContext* context)
{
cmdBuffer.bindPipeline(vk::PipelineBindPoint::eGraphics, pipeline);
context->commandBuffer.bindPipeline(vk::PipelineBindPoint::eGraphics, pipeline);
}
void VulkanShader::Close()
{
owner->RemoveShader(this);
}
void VulkanShader::CreatePipelineLayout()
{
vk::PushConstantRange camPushConstantDesc = { vk::ShaderStageFlagBits::eVertex | vk::ShaderStageFlagBits::eFragment, 0, 3 * sizeof(Math::Matrix4f) + sizeof(Math::Vector4f) + 8 * sizeof(float) };
std::array<vk::PushConstantRange, 1> camPushConstantDescs = { camPushConstantDesc };
std::array<vk::DescriptorSetLayoutBinding, 1> layoutBindings = { reinterpret_cast<const vk::DescriptorSetLayoutBinding&>(NODE_LAYOUT_BINDING) };
vk::DescriptorSetLayoutCreateInfo dslci = { {}, layoutBindings.size(), layoutBindings.data() };
descriptorSetLayout = device.createDescriptorSetLayout(dslci);
vk::PipelineLayoutCreateInfo plci = { {}, 1, &descriptorSetLayout, camPushConstantDescs.size(), camPushConstantDescs.data() };
pipelineLayout = this->device.createPipelineLayout(plci);
}
}