Expose camera push constants to fragment shader

This commit is contained in:
2021-02-19 02:28:11 +01:00
parent 8301cd37b5
commit 556d5d8e2b

View File

@@ -1,42 +1,48 @@
/*
* 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 <vulkan/vulkan.hpp>
#include "Base/ICloseable.hpp"
namespace openVulkanoCpp
namespace openVulkanoCpp::Vulkan
{
namespace Vulkan
struct Pipeline : virtual ICloseable
{
struct Pipeline : virtual ICloseable
vk::Device device;
vk::DescriptorSetLayout descriptorSetLayout;
vk::PipelineLayout pipelineLayout;
vk::DescriptorPool descriptorPool;
void Init(const vk::Device& device)
{
vk::Device device;
vk::DescriptorSetLayout descriptorSetLayout;
vk::PipelineLayout pipelineLayout;
vk::DescriptorPool descriptorPool;
this->device = device;
void Init(vk::Device& device)
{
this->device = device;
CreatePipelineLayout();
}
CreatePipelineLayout();
}
void Close() override
{
device.destroyPipelineLayout(pipelineLayout);
device.destroyDescriptorSetLayout(descriptorSetLayout);
}
void Close() override
{
device.destroyPipelineLayout(pipelineLayout);
device.destroyDescriptorSetLayout(descriptorSetLayout);
}
private:
void CreatePipelineLayout()
{
vk::PushConstantRange camPushConstantDesc = { vk::ShaderStageFlagBits::eVertex, 0, 3 * sizeof(Math::Matrix4f) + sizeof(Math::Vector4f) };
vk::DescriptorSetLayoutBinding nodeLayoutBinding = { 0, vk::DescriptorType::eUniformBufferDynamic, 1, vk::ShaderStageFlagBits::eVertex };
std::array<vk::DescriptorSetLayoutBinding, 1> layoutBindings = { nodeLayoutBinding };
vk::DescriptorSetLayoutCreateInfo dslci = { {}, layoutBindings.size(), layoutBindings.data() };
descriptorSetLayout = device.createDescriptorSetLayout(dslci);
vk::PipelineLayoutCreateInfo plci = { {}, 1, &descriptorSetLayout, 1, &camPushConstantDesc };
pipelineLayout = this->device.createPipelineLayout(plci);
}
};
}
private:
void CreatePipelineLayout()
{
vk::PushConstantRange camPushConstantDesc = { vk::ShaderStageFlagBits::eVertex, 0, 3 * sizeof(Math::Matrix4f) + sizeof(Math::Vector4f) };
vk::PushConstantRange camPushConstantDescFrag = { vk::ShaderStageFlagBits::eFragment, 0, 3 * sizeof(Math::Matrix4f) + sizeof(Math::Vector4f) };
std::array<vk::PushConstantRange, 2> camPushConstantDescs = { camPushConstantDesc, camPushConstantDescFrag };
vk::DescriptorSetLayoutBinding nodeLayoutBinding = { 0, vk::DescriptorType::eUniformBufferDynamic, 1, vk::ShaderStageFlagBits::eVertex };
std::array<vk::DescriptorSetLayoutBinding, 1> layoutBindings = { nodeLayoutBinding };
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);
}
};
}