adding pixel put pipeline

This commit is contained in:
2023-03-31 22:16:21 +02:00
parent 3b29305936
commit 88404afb2b
23 changed files with 8443 additions and 165 deletions

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/23 18:40:44 by maldavid #+# #+# */
/* Updated: 2023/01/23 18:54:28 by maldavid ### ########.fr */
/* Updated: 2023/03/31 17:54:38 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -18,25 +18,30 @@
namespace mlx
{
void DescriptorSet::init(Renderer* renderer, UBO* ubo, DescriptorSetLayout& layout, DescriptorPool& pool)
void DescriptorSet::init(Renderer* renderer, DescriptorPool* pool, DescriptorSetLayout* layout)
{
_renderer = renderer;
_layout = layout;
_pool = pool;
auto device = Render_Core::get().getDevice().get();
_pool = pool.get();
std::array<VkDescriptorSetLayout, MAX_FRAMES_IN_FLIGHT> layouts;
layouts.fill(layout.get());
layouts.fill(layout->get());
VkDescriptorSetAllocateInfo allocInfo{};
allocInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
allocInfo.descriptorPool = _pool;
allocInfo.descriptorSetCount = MAX_FRAMES_IN_FLIGHT;
allocInfo.descriptorPool = _pool->get();
allocInfo.descriptorSetCount = static_cast<uint32_t>(MAX_FRAMES_IN_FLIGHT);
allocInfo.pSetLayouts = layouts.data();
if(vkAllocateDescriptorSets(device, &allocInfo, _desc_set.data()) != VK_SUCCESS)
core::error::report(e_kind::fatal_error, "Vulkan : failed to allocate descriptor set");
}
void DescriptorSet::writeDescriptor(int binding, UBO* ubo) noexcept
{
auto device = Render_Core::get().getDevice().get();
for(int i = 0; i < MAX_FRAMES_IN_FLIGHT; i++)
{
@@ -48,7 +53,7 @@ namespace mlx
VkWriteDescriptorSet descriptorWrite{};
descriptorWrite.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
descriptorWrite.dstSet = _desc_set[i];
descriptorWrite.dstBinding = 0;
descriptorWrite.dstBinding = binding;
descriptorWrite.dstArrayElement = 0;
descriptorWrite.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
descriptorWrite.descriptorCount = 1;
@@ -58,6 +63,34 @@ namespace mlx
}
}
void DescriptorSet::writeDescriptor(int binding, VkImageView view, VkSampler sampler) noexcept
{
auto device = Render_Core::get().getDevice().get();
VkDescriptorImageInfo imageInfo{};
imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
imageInfo.imageView = view;
imageInfo.sampler = sampler;
VkWriteDescriptorSet descriptorWrite{};
descriptorWrite.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
descriptorWrite.dstSet = _desc_set[_renderer->getActiveImageIndex()];
descriptorWrite.dstBinding = binding;
descriptorWrite.dstArrayElement = 0;
descriptorWrite.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
descriptorWrite.descriptorCount = 1;
descriptorWrite.pImageInfo = &imageInfo;
vkUpdateDescriptorSets(device, 1, &descriptorWrite, 0, nullptr);
}
DescriptorSet DescriptorSet::duplicate()
{
DescriptorSet set;
set.init(_renderer, _pool, _layout);
return set;
}
VkDescriptorSet& DescriptorSet::operator()() noexcept
{
return _desc_set[_renderer->getActiveImageIndex()];
@@ -66,9 +99,4 @@ namespace mlx
{
return _desc_set[_renderer->getActiveImageIndex()];
}
void DescriptorSet::destroy() noexcept
{
vkFreeDescriptorSets(Render_Core::get().getDevice().get(), _pool, MAX_FRAMES_IN_FLIGHT, _desc_set.data());
}
}

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/23 18:39:36 by maldavid #+# #+# */
/* Updated: 2023/01/23 18:54:22 by maldavid ### ########.fr */
/* Updated: 2023/03/31 17:28:36 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -22,15 +22,22 @@ namespace mlx
class DescriptorSet
{
public:
void init(class Renderer* renderer, class UBO* ubo, class DescriptorSetLayout& layout, class DescriptorPool& pool);
void destroy() noexcept;
void init(class Renderer* renderer, class DescriptorPool* pool, class DescriptorSetLayout* layout);
void writeDescriptor(int binding, class UBO* ubo) noexcept;
void writeDescriptor(int binding, VkImageView view, VkSampler sampler) noexcept;
inline bool isInit() noexcept { return _pool != nullptr && _renderer != nullptr; }
DescriptorSet duplicate();
VkDescriptorSet& operator()() noexcept;
VkDescriptorSet& get() noexcept;
private:
std::array<VkDescriptorSet, MAX_FRAMES_IN_FLIGHT> _desc_set;
VkDescriptorPool _pool = VK_NULL_HANDLE;
class DescriptorPool* _pool = nullptr;
class DescriptorSetLayout* _layout = nullptr;
class Renderer* _renderer = nullptr;
};
}

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/23 18:37:28 by maldavid #+# #+# */
/* Updated: 2023/01/23 18:45:32 by maldavid ### ########.fr */
/* Updated: 2023/03/31 16:37:09 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -15,19 +15,24 @@
namespace mlx
{
void DescriptorSetLayout::init(VkDescriptorType t, std::size_t n, int binding, VkShaderStageFlagBits stage)
void DescriptorSetLayout::init(std::vector<std::pair<int, VkDescriptorType>> binds, VkShaderStageFlagBits stage)
{
VkDescriptorSetLayoutBinding bindings{};
bindings.binding = binding;
bindings.descriptorCount = 1;
bindings.descriptorType = t;
bindings.pImmutableSamplers = nullptr;
bindings.stageFlags = stage;
std::vector<VkDescriptorSetLayoutBinding> bindings(binds.size());
for(int i = 0; i < binds.size(); i++)
{
bindings[i].binding = binds[i].first;
bindings[i].descriptorCount = 1;
bindings[i].descriptorType = binds[i].second;
bindings[i].pImmutableSamplers = nullptr;
bindings[i].stageFlags = stage;
}
_bindings = std::move(binds);
VkDescriptorSetLayoutCreateInfo layoutInfo{};
layoutInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
layoutInfo.bindingCount = n;
layoutInfo.pBindings = &bindings;
layoutInfo.bindingCount = _bindings.size();
layoutInfo.pBindings = bindings.data();
if(vkCreateDescriptorSetLayout(Render_Core::get().getDevice().get(), &layoutInfo, nullptr, &_layout) != VK_SUCCESS)
core::error::report(e_kind::fatal_error, "Vulkan : failed to create descriptor set layout");

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/23 18:36:22 by maldavid #+# #+# */
/* Updated: 2023/01/23 18:45:44 by maldavid ### ########.fr */
/* Updated: 2023/03/31 17:54:03 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -15,20 +15,24 @@
#include <volk.h>
#include <cstddef>
#include <vector>
#include <map>
namespace mlx
{
class DescriptorSetLayout
{
public:
void init(VkDescriptorType t = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, std::size_t n = 1, int binding = 0, VkShaderStageFlagBits stage = VK_SHADER_STAGE_VERTEX_BIT);
void init(std::vector<std::pair<int, VkDescriptorType>> binds, VkShaderStageFlagBits stage);
void destroy() noexcept;
inline VkDescriptorSetLayout& operator()() noexcept { return _layout; }
inline VkDescriptorSetLayout& get() noexcept { return _layout; }
inline const std::vector<std::pair<int, VkDescriptorType>>& getBindings() const noexcept { return _bindings; }
private:
VkDescriptorSetLayout _layout = VK_NULL_HANDLE;
std::vector<std::pair<int, VkDescriptorType>> _bindings;
};
}