Update how camera data is communicated to shader

This commit is contained in:
2023-08-31 21:16:11 +02:00
parent 93c75763c7
commit df4194be51
21 changed files with 265 additions and 177 deletions

View File

@@ -0,0 +1,38 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#pragma once
#include "Base/ICloseable.hpp"
#include "IRecordable.hpp"
#include "Vulkan/Resources/UniformBuffer.hpp"
namespace openVulkanoCpp::Vulkan
{
class VulkanCamera : public ICloseable, public IRecordable
{
Scene::Camera* camera = nullptr;
UniformBuffer* buffer = nullptr;
public:
void Init(Scene::Camera* camera, UniformBuffer* uniformBuffer)
{
this->camera = camera;
buffer = uniformBuffer;
}
void Record(VulkanDrawContext* context) override
{
buffer->Update(camera->GetData(), Scene::Camera::SIZE, context->currentImageId);
buffer->Record(context);
}
void Close() override
{
buffer->Close();
}
};
}

View File

@@ -23,7 +23,8 @@ namespace openVulkanoCpp::Vulkan
device.destroyShaderModule(shaderModule);
}
device.destroyPipelineLayout(pipelineLayout);
device.destroyDescriptorSetLayout(descriptorSetLayout);
for(auto& descriptorSetLayout : descriptorSetLayouts)
device.destroyDescriptorSetLayout(descriptorSetLayout);
}
void VulkanShader::Init(Context* context, Scene::Shader* shader, IShaderOwner* owner)
@@ -128,12 +129,15 @@ namespace openVulkanoCpp::Vulkan
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() };
//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> layoutBindings1 = { reinterpret_cast<const vk::DescriptorSetLayoutBinding&>(NODE_LAYOUT_BINDING) };
std::array<vk::DescriptorSetLayoutBinding, 1> layoutBindings2 = { reinterpret_cast<const vk::DescriptorSetLayoutBinding&>(CAM_LAYOUT_BINDING) };
vk::DescriptorSetLayoutCreateInfo dslci = { {}, layoutBindings1.size(), layoutBindings1.data() };
vk::DescriptorSetLayoutCreateInfo dslci2 = { {}, layoutBindings2.size(), layoutBindings2.data() };
descriptorSetLayouts.push_back(device.createDescriptorSetLayout(dslci));
descriptorSetLayouts.push_back(device.createDescriptorSetLayout(dslci2));
vk::PipelineLayoutCreateInfo plci = { {}, static_cast<uint32_t>(descriptorSetLayouts.size()), descriptorSetLayouts.data(), 0, nullptr };
pipelineLayout = this->device.createPipelineLayout(plci);
}
}

View File

@@ -30,7 +30,7 @@ namespace openVulkanoCpp
std::vector<vk::ShaderModule> shaderModules; // TODO manage live time somewhere else to allow sharing of shader programs
std::vector<vk::PipelineShaderStageCreateInfo> shaderStageCreateInfo;
vk::Pipeline pipeline; // TODO pipeline and shader config should be split
vk::DescriptorSetLayout descriptorSetLayout;
std::vector<vk::DescriptorSetLayout> descriptorSetLayouts;
vk::PipelineLayout pipelineLayout;
IShaderOwner* owner = nullptr;
Context* context = nullptr;