Skip to content
Snippets Groups Projects
Commit feeb4789 authored by Artur Wasmut's avatar Artur Wasmut
Browse files

add ToDos for descriptor set management.

parent 129b7ea6
No related branches found
No related tags found
1 merge request!3Resolve "Descriptor Set Managment"
Pipeline #24990 passed
......@@ -51,4 +51,10 @@ set(vkcv_sources
${vkcv_source}/vkcv/Framebuffer.hpp
${vkcv_source}/vkcv/Framebuffer.cpp
${vkcv_source}/vkcv/DescriptorManager.hpp
${vkcv_source}/vkcv/DescriptorManager.cpp
${vkcv_include}/vkcv/ResourcesConfig.hpp
${vkcv_source}/vkcv/ResourcesConfig.cpp
)
......@@ -17,12 +17,14 @@
#include "CommandResources.hpp"
#include "SyncResources.hpp"
#include "Result.hpp"
#include "vkcv/ResourcesConfig.hpp"
namespace vkcv
{
// forward declarations
class PassManager;
class PipelineManager;
class DescriptorManager;
class Core final
{
......@@ -147,6 +149,12 @@ namespace vkcv
return Buffer<T>::create(m_Context.getDevice(), m_Context.getPhysicalDevice(), bufferType, size);
}
/** TODO:
* @param setDescriptions
* @return
*/
ResourcesHandle createResourceDescription(const std::vector<SetDescription> &setDescriptions);
/**
* @brief start recording command buffers and increment frame index
*/
......
#include <vulkan/vulkan.hpp>
namespace vkcv {
class Descriptor
{
friend class Core;
public:
//Die verschiedenen Pool Sizes fr die verschiedenen Arten von Buffern
struct PoolSizes {
std::vector<std::pair<VkDescriptorType, float>> sizes =
{
{ VK_DESCRIPTOR_TYPE_SAMPLER, 0.5f },
{ VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 4.f },
{ VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 4.f },
{ VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, 1.f },
{ VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER, 1.f },
{ VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER, 1.f },
{ VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 2.f },
{ VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 2.f }
};
};
void createDescriptors(VkDevice device/*, int buffer_size*/);
const void destroyDescriptor(VkDevice device, VkDescriptorSetLayout descriptorSetLayout, VkDescriptorPool descriptorPool);
const VkDescriptorPool createDescPool(VkDescriptorPool descriptorPool, VkDevice device, const PoolSizes& poolSizes, int count);
const VkDescriptorSetLayout createDescSetLayout(VkDevice device, VkDescriptorSetLayout descriptorSetLayout, VkDescriptorSetLayoutCreateInfo* info);
struct DescriptorLayoutInfo;
struct PoolSizes;
private:
//Layout Info
struct DescriptorLayoutInfo {
std::vector<VkDescriptorSetLayoutBinding> bindings;
bool operator==(const DescriptorLayoutInfo& other) const;
size_t hash() const;
};
//Informationen zum Set Layout
typedef struct VkDescriptorSetLayoutCreateInfo {
VkStructureType sType;
const void* pNext;
VkDescriptorSetLayoutCreateFlags flags;
uint32_t bindingCount;
const VkDescriptorSetLayoutBinding* pBindings;
} VkDescriptorSetLayoutCreateInfo;
};
}
\ No newline at end of file
......@@ -13,4 +13,5 @@ namespace vkcv
struct BufferHandle {uint64_t id;};
struct PassHandle {uint64_t id;};
struct PipelineHandle {uint64_t id;};
struct ResourcesHandle {uint64_t id;};
}
#pragma once
namespace vkcv
{
enum class ResourceType
{
// TODO:
// uniform buffers, samplers, images should be supported for now!
};
struct BindingDescription
{
// TODO:
// should contain something like the binding ID,
// and the descriptor/resource type
};
struct SetDescription
{
// TODO:
// should contain a collection of BindingDescriptions
};
}
......@@ -9,6 +9,7 @@
#include "vkcv/Core.hpp"
#include "PassManager.hpp"
#include "PipelineManager.hpp"
#include "DescriptorManager.hpp"
#include "Surface.hpp"
#include "ImageLayoutTransitions.hpp"
#include "Framebuffer.hpp"
......@@ -213,4 +214,12 @@ namespace vkcv
vk::Format Core::getSwapchainImageFormat() {
return m_swapchain.getSurfaceFormat().format;
}
ResourcesHandle Core::createResourceDescription(const std::vector<SetDescription> &setDescriptions)
{
// TODO:
// call DescriptorManager's createResourceDescription
// let it do the actual work! No vulkan stuff here.
return ResourcesHandle{0};
}
}
#include "vkcv/Descriptor.hpp"
namespace vkcv
{
const VkDescriptorSetLayout createDescSetLayout(VkDevice device, VkDescriptorSetLayout descriptorSetLayout, VkDescriptorSetLayoutCreateInfo* info)
{
/* Code, falls nur ein Set mit nur einem Binding erstellt wird
VkDescriptorSetLayoutBinding layoutBinding = {};
layoutBinding.binding = 0;
layoutBinding.descriptorType = VkDescriptorType::VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
layoutBinding.descriptorCount = 1;
layoutBinding.stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
VkDescriptorSetLayoutCreateInfo layoutInfo = {};
layoutInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
layoutInfo.bindingCount = 1;
layoutInfo.pBindings = &layoutBinding;*/
//Erstellen von der Layout Info
DescriptorLayoutInfo layoutinfo;
layoutinfo.bindings.reserve(info->bindingCount);
bool isSorted = true;
int lastBinding = -1;
//Sortieren und pushen von Bindings fr Ordnung
for (int i = 0; i < info->bindingCount; i++) {
layoutinfo.bindings.push_back(info->pBindings[i]);
//Bindings mssen aufsteigend sortiert sein
if (info->pBindings[i].binding > lastBinding) {
lastBinding = info->pBindings[i].binding;
}
else {
isSorted = false;
}
}
//Sortieren, falls Bindings noch nicht sortiert sind
if (!isSorted) {
std::sort(layoutinfo.bindings.begin(), layoutinfo.bindings.end(), [](VkDescriptorSetLayoutBinding& a, VkDescriptorSetLayoutBinding& b) {
return a.binding < b.binding;
});
}
//Test, ob es funktioniert
VkResult result = vkCreateDescriptorSetLayout(
device,
&layoutInfo,
nullptr,
&descriptorSetLayout
);
assert(result == VK_SUCCESS);
}
const VkDescriptorPool createDescPool(VkDescriptorPool descriptorPool, VkDevice device, const PoolSizes& poolSizes, int count)
{
//Gre des Pools bestimmen
std::vector<VkDescriptorPoolSize> poolSize;
poolSize.reserve(poolSizes.sizes.size());
for (auto sz : poolSizes.sizes) {
poolSize.push_back({ sz.first, uint32_t(sz.second * count) });
}
//Erstelle das createInfo zu den Pools
VkDescriptorPoolCreateInfo createInfo = {};
createInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
createInfo.poolSizeCount = (uint32_t)poolSizes.sizes.size();
createInfo.pPoolSizes = poolSize.data();
createInfo.maxSets = count;
//Teste, ob der Pool erstellt werden kann
VkResult createDescriptorPool = vkCreateDescriptorPool(
device,
&createInfo,
nullptr,
&descriptorPool
);
assert(createDescriptorPool == VK_SUCCESS);
}
const void destroyDescriptor(VkDevice device, VkDescriptorSetLayout descriptorSetLayout, VkDescriptorPool descriptorPool)
{
//Destruktor fr Layout und Pool
vkDestroyDescriptorSetLayout(
device,
descriptorSetLayout,
nullptr
);
vkDestroyDescriptorPool(
device,
descriptorPool,
nullptr
);
}
void Descriptor::createDescriptors(VkDevice device/*, int buffer_size*/)
{
//Bentigte Variablen
VkDescriptorPool descriptorPool;
VkDescriptorSetLayout descriptorSetLayout;
VkDescriptorSet descriptorSet;
VkWriteDescriptorSet descriptorWriteSet;
PoolSizes descriptorSizes;
int count = 1000;
//Erstellung des Pools
descriptorPool = createDescPool(descriptorPool, device, descriptorSizes, count);
//Erstellung der Set Layouts
descriptorSetLayout = createDescSetLayout(device, descriptorSetLayout);
{
//Sets erstellen
VkDescriptorSetAllocateInfo allocInfo = {};
allocInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
allocInfo.descriptorPool = descriptorPool;
allocInfo.descriptorSetCount = count;
allocInfo.pSetLayouts = &descriptorSetLayout;
//Teste, ob Sets erstellt wurden
VkResult result = vkAllocateDescriptorSets(
device,
&allocInfo,
&descriptorSet
);
assert (result == VK_SUCCESS);
}
{ /*Buffer Date in Descriptor schreiben
VkDescriptorBufferInfo bufferInfo = {};
bufferInfo.buffer = buffer;
bufferInfo.offset = 0;
bufferInfo.range = buffer_size;
descriptorWriteSet = {};
descriptorWriteSet.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
descriptorWriteSet.dstSet = descriptorSet;
descriptorWriteSet.dstBinding = 0;
descriptorWriteSet.dstArrayElement = 0;
descriptorWriteSet.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
descriptorWriteSet.descriptorCount = 1;
descriptorWriteSet.pBufferInfo = &bufferInfo;
vkUpdateDescriptorSets(
device,
1,
&descriptorWriteSet,
0,
NULL
);*/
}
}
}
\ No newline at end of file
#include "DescriptorManager.hpp"
namespace vkcv
{
ResourcesHandle vkcv::DescriptorManager::createResourceDescription(const std::vector<SetDescription> &setDescriptions)
{
// TODO: create all vk::DescriptorSets and allocate them from the pool
// put them into a ResourceDescription struct
// push that struct into m_Resources;
// return the index into that object as ResourcesHandle;
return ResourcesHandle{0};
}
}
\ No newline at end of file
#include <vulkan/vulkan.hpp>
#include "vkcv/Handles.hpp"
#include "vkcv/ResourcesConfig.hpp"
namespace vkcv
{
class DescriptorManager
{
public:
explicit DescriptorManager(vk::Device) noexcept;
~DescriptorManager();
// TODO: Interface
// user wishes to create descriptor sets {X,Y,Z} each with different descriptions {A,B,C}
// returns a resource
ResourcesHandle createResourceDescription(const std::vector<SetDescription> &setDescriptions);
private:
vk::DescriptorPool m_Pool;
// TODO: container for all resources requested by the user
struct ResourceDescription
{
std::vector<vk::DescriptorSet> descriptorSets;
std::vector<vk::DescriptorSetLayout> descriptorSetLayouts;
};
std::vector<ResourceDescription> m_Resources;
};
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment