diff --git a/include/vkcv/DescriptorConfig.hpp b/include/vkcv/DescriptorConfig.hpp index c4666b18798d5b71393d9b37e74b3187cc96583f..60175a87b8d88578a9e4c7ce006fb47d4cffe9e0 100644 --- a/include/vkcv/DescriptorConfig.hpp +++ b/include/vkcv/DescriptorConfig.hpp @@ -3,20 +3,33 @@ namespace vkcv { + /* + * All the types of descriptors (resources) that can be retrieved by the shaders + */ enum class DescriptorType { - // TODO: - // uniform buffers, samplers, images should be supported for now! UNIFORM_BUFFER, SAMPLER, IMAGE - }; - + }; + + /* + * One binding for a descriptor set + * @param[in] a unique binding ID + * @param[in] a descriptor type + * @param[in] the number of descriptors of this type (arrays of the same type possible) + * @param[in] the shader stage where the descriptor is supposed to be retrieved + */ struct DescriptorBinding { - // TODO: - // should contain something like the binding ID, - // and the descriptor/resource type + DescriptorBinding() = delete; + + DescriptorBinding( + uint32_t p_bindingID, + DescriptorType p_descriptorType, + uint32_t p_descriptorCount, + ShaderStage p_shaderStage + ) noexcept; uint32_t bindingID; DescriptorType descriptorType; @@ -24,10 +37,19 @@ namespace vkcv ShaderStage shaderStage; }; + /* + * One descriptor set struct that contains all the necessary information for the actual creation. + * @param[in] a number of bindings that were created beforehand + * @param[in] the number of (identical) sets that should be created from the attached bindings + */ struct DescriptorSet { - // TODO: - // should contain a collection of DescriptorBindings and the number of instances to be created from the set + DescriptorSet() = delete; + + DescriptorSet( + std::vector<DescriptorBinding> p_bindings, + uint32_t p_setCount) noexcept; + std::vector<DescriptorBinding> bindings; uint32_t setCount; }; diff --git a/projects/first_triangle/src/main.cpp b/projects/first_triangle/src/main.cpp index ae0f4f8abb900bec54f70b222b837cfb6246ff15..7b35fa18e96cbbc2ad822e2d84a69307b7ee7b01 100644 --- a/projects/first_triangle/src/main.cpp +++ b/projects/first_triangle/src/main.cpp @@ -20,7 +20,7 @@ int main(int argc, const char** argv) { window, applicationName, VK_MAKE_VERSION(0, 0, 1), - {vk::QueueFlagBits::eTransfer,vk::QueueFlagBits::eGraphics, vk::QueueFlagBits::eCompute}, + {vk::QueueFlagBits::eGraphics}, {}, {"VK_KHR_swapchain"} ); @@ -90,23 +90,19 @@ int main(int argc, const char** argv) { vkcv::DescriptorType typeB = vkcv::DescriptorType::IMAGE; vkcv::DescriptorType typeC = vkcv::DescriptorType::SAMPLER; std::vector<vkcv::DescriptorType> types = { typeA, typeB, typeC }; - for (int i = 0; i < types.size(); i++) + for (uint32_t i = 0; i < types.size(); i++) { - vkcv::DescriptorBinding bind{}; - bind.bindingID = i; - bind.descriptorType = types[i]; - bind.descriptorCount = 1; - bind.shaderStage = vkcv::ShaderStage::VERTEX; + vkcv::DescriptorBinding bind(i, types[i], static_cast<uint32_t>(1), vkcv::ShaderStage::VERTEX); - vkcv::DescriptorSet set{}; std::vector<vkcv::DescriptorBinding> bindings = { bind }; - set.bindings = bindings; - set.setCount = 1; + vkcv::DescriptorSet set(bindings, static_cast<uint32_t>(1)); sets.push_back(set); } core.createResourceDescription(sets); +//------------END CREATION OF RESOURCES/DESCRIPTORS------------------ + /* * BufferHandle triangleVertices = core.createBuffer(vertices); * BufferHandle triangleIndices = core.createBuffer(indices); diff --git a/src/vkcv/DescriptorConfig.cpp b/src/vkcv/DescriptorConfig.cpp index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..de42fe22eb073a78490a85c0eb7f23e421e566a4 100644 --- a/src/vkcv/DescriptorConfig.cpp +++ b/src/vkcv/DescriptorConfig.cpp @@ -0,0 +1,25 @@ +#include "vkcv/DescriptorConfig.hpp" + +namespace vkcv { + + DescriptorBinding::DescriptorBinding( + uint32_t p_bindingID, + DescriptorType p_descriptorType, + uint32_t p_descriptorCount, + ShaderStage p_shaderStage + ) noexcept : + bindingID{ p_bindingID }, + descriptorType{ p_descriptorType }, + descriptorCount{ p_descriptorCount }, + shaderStage{ p_shaderStage } + {}; + + DescriptorSet::DescriptorSet( + std::vector<DescriptorBinding> p_bindings, + uint32_t p_setCount + ) noexcept : + bindings{ p_bindings }, + setCount{ p_setCount } + {}; + +} \ No newline at end of file diff --git a/src/vkcv/DescriptorManager.cpp b/src/vkcv/DescriptorManager.cpp index b19c2e54f44cd79c04bc81bf58767d74bc27d3ce..f4f2de16c5cefc07ab0ba9488e28c3a894e99dac 100644 --- a/src/vkcv/DescriptorManager.cpp +++ b/src/vkcv/DescriptorManager.cpp @@ -4,7 +4,6 @@ namespace vkcv { - DescriptorManager::DescriptorManager(vk::Device device) noexcept: m_Device{ device }, m_NextDescriptorSetID{ 1 } { @@ -24,11 +23,6 @@ namespace vkcv ResourcesHandle DescriptorManager::createResourceDescription(const std::vector<DescriptorSet> &p_descriptorSets) { - // 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; - ResourceDescription resource{}; for (int i = 0; i < p_descriptorSets.size(); i++) { @@ -58,11 +52,11 @@ namespace vkcv resource.descriptorSetLayouts.insert(resource.descriptorSetLayouts.begin(), allocLayouts.begin(), allocLayouts.end()); resource.descriptorSets.insert(resource.descriptorSets.end(), allocSets.begin(), allocSets.end()); } - m_Resources.push_back(resource); + m_ResourceDescriptions.push_back(resource); return ResourcesHandle{m_NextDescriptorSetID++}; } - vk::DescriptorType vkcv::DescriptorManager::convertDescriptorTypeFlag(DescriptorType type) { + vk::DescriptorType DescriptorManager::convertDescriptorTypeFlag(DescriptorType type) { switch (type) { case vkcv::DescriptorType::UNIFORM_BUFFER: @@ -74,7 +68,7 @@ namespace vkcv } } - vk::ShaderStageFlagBits vkcv::DescriptorManager::convertShaderStageFlag(ShaderStage stage) { + vk::ShaderStageFlagBits DescriptorManager::convertShaderStageFlag(ShaderStage stage) { switch (stage) { case vkcv::ShaderStage::VERTEX: diff --git a/src/vkcv/DescriptorManager.hpp b/src/vkcv/DescriptorManager.hpp index d906c73ae987d4d1fc460f7b08509f20a03060e2..b699d259da23d3de64fc671956ca4d57ddd7d88a 100644 --- a/src/vkcv/DescriptorManager.hpp +++ b/src/vkcv/DescriptorManager.hpp @@ -11,10 +11,13 @@ namespace vkcv explicit DescriptorManager(vk::Device device) noexcept; ~DescriptorManager() = default; - - // TODO: Interface - // user wishes to create descriptor sets {X,Y,Z} each with different descriptions {A,B,C} - // returns a resource + /** + * Creates all vk::DescriptorSets and allocates them from the pool. + * DescriptorSets are put inside a ResourceDescription struct. + * Structs are then put into m_ResourceDescriptions. + * @param[in] vector of filled vkcv::DescriptorSet structs + * @return index into that objects a resource handle + */ ResourcesHandle createResourceDescription(const std::vector<DescriptorSet> & p_descriptorSets); private: @@ -22,24 +25,35 @@ namespace vkcv vk::DescriptorPool m_Pool; uint64_t m_NextDescriptorSetID; - // TODO: container for all resources requested by the user + /** + * Container for all resources requested by the user in one call of createResourceDescription. + * Includes descriptor sets and the respective descriptor set layouts. + */ struct ResourceDescription { std::vector<vk::DescriptorSet> descriptorSets; std::vector<vk::DescriptorSetLayout> descriptorSetLayouts; }; - std::vector<ResourceDescription> m_Resources; + /** + * Contains all the resource descriptions that were requested by the user in calls of createResourceDescription. + */ + std::vector<ResourceDescription> m_ResourceDescriptions; + + /** + * Contains all the allowed vkcv::DescriptorTypes that were also pre-defined in the DescriptorConfig class. + * Allowed types are defined in the constructor of DescriptorManager. + */ std::vector<DescriptorType> m_DescriptorTypes; /** - * converts the flags of the descriptor types from VulkanCV (vkcv) to Vulkan (vk) + * Converts the flags of the descriptor types from VulkanCV (vkcv) to Vulkan (vk). * @param[in] vkcv flag of the DescriptorType (see DescriptorConfig.hpp) * @return vk flag of the DescriptorType */ vk::DescriptorType convertDescriptorTypeFlag(DescriptorType type); /** - * converts the flags of the shader stages from VulkanCV (vkcv) to Vulkan (vk) + * Converts the flags of the shader stages from VulkanCV (vkcv) to Vulkan (vk). * @param[in] vkcv flag of the ShaderStage (see ShaderProgram.hpp) * @return vk flag of the ShaderStage */