Add push constants handling for shaders
This commit is contained in:
31
openVulkanoCpp/Scene/Shader/PushConstant.hpp
Normal file
31
openVulkanoCpp/Scene/Shader/PushConstant.hpp
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* 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 "ShaderProgramType.hpp"
|
||||
|
||||
namespace OpenVulkano
|
||||
{
|
||||
struct PushConstantRange
|
||||
{
|
||||
ShaderProgramType::Type stageFlags;
|
||||
uint32_t offset, size;
|
||||
};
|
||||
|
||||
struct PushConstant : PushConstantRange
|
||||
{
|
||||
const void* data;
|
||||
|
||||
PushConstant(ShaderProgramType::Type stages, uint32_t offset, uint32_t size, const void* data)
|
||||
: PushConstantRange(stages, offset, size), data(data)
|
||||
{}
|
||||
|
||||
PushConstant(const void* data, uint32_t size, uint32_t offset = 0, ShaderProgramType::Type stages = ShaderProgramType::ALL_GRAPHICS)
|
||||
: PushConstantRange(stages, offset, size), data(data)
|
||||
{}
|
||||
};
|
||||
}
|
||||
@@ -11,6 +11,7 @@
|
||||
#include "VertexInputDescription.hpp"
|
||||
#include "ShaderProgramType.hpp"
|
||||
#include "DescriptorInputDescription.hpp"
|
||||
#include "PushConstant.hpp"
|
||||
#include <string>
|
||||
#include <stdexcept>
|
||||
|
||||
@@ -72,6 +73,7 @@ namespace OpenVulkano::Scene
|
||||
std::vector<ShaderProgram> shaderPrograms{};
|
||||
std::vector<VertexInputDescription> vertexInputDescriptions{};
|
||||
std::vector<std::vector<DescriptorSetLayoutBinding>> descriptorSets;
|
||||
std::vector<PushConstantRange> pushConstantRanges;
|
||||
Topology topology = Topology::TRIANGLE_LIST;
|
||||
CullMode cullMode = CullMode::BACK;
|
||||
ICloseable* renderShader = nullptr;
|
||||
@@ -138,6 +140,11 @@ namespace OpenVulkano::Scene
|
||||
}
|
||||
#pragma clang diagnostic pop
|
||||
|
||||
void AddPushConstantRange(const PushConstantRange& pushConstantRange)
|
||||
{
|
||||
pushConstantRanges.push_back(pushConstantRange);
|
||||
}
|
||||
|
||||
void Close() override
|
||||
{
|
||||
renderShader->Close();
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
namespace OpenVulkano::Vulkan
|
||||
{
|
||||
static_assert(sizeof(vk::DescriptorSetLayoutBinding) == sizeof(DescriptorSetLayoutBinding));
|
||||
static_assert(sizeof(vk::PushConstantRange) == sizeof(PushConstantRange));
|
||||
|
||||
VulkanShader::~VulkanShader()
|
||||
{
|
||||
@@ -148,9 +149,8 @@ namespace OpenVulkano::Vulkan
|
||||
vk::DescriptorSetLayoutCreateInfo createInfo { {}, static_cast<uint32_t>(set.size()), reinterpret_cast<const vk::DescriptorSetLayoutBinding*>(set.data()) };
|
||||
descriptorSetLayouts.push_back(device.createDescriptorSetLayout(createInfo));
|
||||
}
|
||||
|
||||
|
||||
vk::PipelineLayoutCreateInfo plci = { {}, static_cast<uint32_t>(descriptorSetLayouts.size()), descriptorSetLayouts.data(), 0, nullptr };
|
||||
vk::PushConstantRange* pcRanges = reinterpret_cast<vk::PushConstantRange*>(shader->pushConstantRanges.data());
|
||||
vk::PipelineLayoutCreateInfo plci = {{}, static_cast<uint32_t>(descriptorSetLayouts.size()), descriptorSetLayouts.data(), static_cast<uint32_t>(shader->pushConstantRanges.size()), pcRanges };
|
||||
pipelineLayout = this->device.createPipelineLayout(plci);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user