diff --git a/openVulkanoCpp/Scene/Shader/PushConstant.hpp b/openVulkanoCpp/Scene/Shader/PushConstant.hpp new file mode 100644 index 0000000..dcb90bc --- /dev/null +++ b/openVulkanoCpp/Scene/Shader/PushConstant.hpp @@ -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) + {} + }; +} diff --git a/openVulkanoCpp/Scene/Shader/Shader.hpp b/openVulkanoCpp/Scene/Shader/Shader.hpp index c138a03..4bc87b3 100644 --- a/openVulkanoCpp/Scene/Shader/Shader.hpp +++ b/openVulkanoCpp/Scene/Shader/Shader.hpp @@ -11,6 +11,7 @@ #include "VertexInputDescription.hpp" #include "ShaderProgramType.hpp" #include "DescriptorInputDescription.hpp" +#include "PushConstant.hpp" #include #include @@ -72,6 +73,7 @@ namespace OpenVulkano::Scene std::vector shaderPrograms{}; std::vector vertexInputDescriptions{}; std::vector> descriptorSets; + std::vector 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(); diff --git a/openVulkanoCpp/Vulkan/Scene/VulkanShader.cpp b/openVulkanoCpp/Vulkan/Scene/VulkanShader.cpp index 6187934..5ad6966 100644 --- a/openVulkanoCpp/Vulkan/Scene/VulkanShader.cpp +++ b/openVulkanoCpp/Vulkan/Scene/VulkanShader.cpp @@ -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(set.size()), reinterpret_cast(set.data()) }; descriptorSetLayouts.push_back(device.createDescriptorSetLayout(createInfo)); } - - - vk::PipelineLayoutCreateInfo plci = { {}, static_cast(descriptorSetLayouts.size()), descriptorSetLayouts.data(), 0, nullptr }; + vk::PushConstantRange* pcRanges = reinterpret_cast(shader->pushConstantRanges.data()); + vk::PipelineLayoutCreateInfo plci = {{}, static_cast(descriptorSetLayouts.size()), descriptorSetLayouts.data(), static_cast(shader->pushConstantRanges.size()), pcRanges }; pipelineLayout = this->device.createPipelineLayout(plci); } }