diff --git a/projects/first_mesh/src/main.cpp b/projects/first_mesh/src/main.cpp index f98b6209cca74011ec8170236f0eb1d20c0c83ef..e01949c8bf89573983f188cb715ac0a8d9bdb6db 100644 --- a/projects/first_mesh/src/main.cpp +++ b/projects/first_mesh/src/main.cpp @@ -53,17 +53,15 @@ int main(int argc, const char** argv) { // recreate copies of the bindings and the handles (to check whether they are properly reused instead of actually recreated) const vkcv::DescriptorBindings& set0Bindings = firstMeshProgram.getReflectedDescriptors().at(0); - vkcv::DescriptorSetLayoutHandle setLayoutHandle = core.createDescriptorSetLayout(set0Bindings); - vkcv::DescriptorSetLayoutHandle setLayoutHandleCopy = core.createDescriptorSetLayout(set0Bindings); - - vkcv::DescriptorSetHandle descriptorSet = core.createDescriptorSet(setLayoutHandle); + vkcv::DescriptorSetLayoutHandle descriptorSetLayout = core.createDescriptorSetLayout(set0Bindings); + vkcv::DescriptorSetHandle descriptorSet = core.createDescriptorSet(descriptorSetLayout); vkcv::GraphicsPipelineHandle firstMeshPipeline = core.createGraphicsPipeline( vkcv::GraphicsPipelineConfig( firstMeshProgram, firstMeshPass, { firstMeshLayout }, - { setLayoutHandle } + { descriptorSetLayout } ) ); diff --git a/src/vkcv/DescriptorSetManager.cpp b/src/vkcv/DescriptorSetManager.cpp index 0c16267e82d3f5c39c7ca495a805295793d04c02..6c21cd9dcd00a4df5725cfde1c5bf3b1d2103129 100644 --- a/src/vkcv/DescriptorSetManager.cpp +++ b/src/vkcv/DescriptorSetManager.cpp @@ -22,19 +22,27 @@ namespace vkcv { */ m_PoolSizes.clear(); m_PoolSizes.emplace_back(vk::DescriptorType::eSampler, 1000); + m_PoolSizes.emplace_back(vk::DescriptorType::eCombinedImageSampler, 1000); m_PoolSizes.emplace_back(vk::DescriptorType::eSampledImage, 1000); + m_PoolSizes.emplace_back(vk::DescriptorType::eStorageImage, 1000); + m_PoolSizes.emplace_back(vk::DescriptorType::eUniformTexelBuffer, 1000); + m_PoolSizes.emplace_back(vk::DescriptorType::eStorageTexelBuffer, 1000); m_PoolSizes.emplace_back(vk::DescriptorType::eUniformBuffer, 1000); m_PoolSizes.emplace_back(vk::DescriptorType::eStorageBuffer, 1000); m_PoolSizes.emplace_back(vk::DescriptorType::eUniformBufferDynamic, 1000); m_PoolSizes.emplace_back(vk::DescriptorType::eStorageBufferDynamic, 1000); + m_PoolSizes.emplace_back(vk::DescriptorType::eInputAttachment, 1000); + m_PoolSizes.emplace_back(vk::DescriptorType::eInlineUniformBlock, 1000); if (core.getContext().getFeatureManager().isExtensionActive(VK_KHR_ACCELERATION_STRUCTURE_EXTENSION_NAME)) { m_PoolSizes.emplace_back(vk::DescriptorType::eAccelerationStructureKHR, 1000); } m_PoolInfo = vk::DescriptorPoolCreateInfo( - vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet, 1000, - static_cast<uint32_t>(m_PoolSizes.size()), m_PoolSizes.data() + vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet, + 1000, + static_cast<uint32_t>(m_PoolSizes.size()), + m_PoolSizes.data() ); return allocateDescriptorPool(); @@ -50,11 +58,16 @@ namespace vkcv { } void DescriptorSetManager::destroyById(uint64_t id) { + const auto& device = getCore().getContext().getDevice(); auto &set = getById(id); if (set.vulkanHandle) { - getCore().getContext().getDevice().freeDescriptorSets(m_Pools [set.poolIndex], 1, - &(set.vulkanHandle)); + device.freeDescriptorSets( + m_Pools[set.poolIndex], + 1, + &(set.vulkanHandle) + ); + set.vulkanHandle = nullptr; } @@ -62,8 +75,10 @@ namespace vkcv { } bool DescriptorSetManager::allocateDescriptorPool() { + const auto& device = getCore().getContext().getDevice(); + vk::DescriptorPool pool; - if (getCore().getContext().getDevice().createDescriptorPool(&m_PoolInfo, nullptr, &pool) + if (device.createDescriptorPool(&m_PoolInfo, nullptr, &pool) != vk::Result::eSuccess) { vkcv_log(LogLevel::WARNING, "Failed to allocate descriptor pool"); return false; @@ -77,11 +92,13 @@ namespace vkcv { HandleManager<DescriptorSetEntry, DescriptorSetHandle>() {} DescriptorSetManager::~DescriptorSetManager() noexcept { + const auto& device = getCore().getContext().getDevice(); + clear(); for (const auto &pool : m_Pools) { if (pool) { - getCore().getContext().getDevice().destroy(pool); + device.destroy(pool); } } } @@ -90,9 +107,15 @@ namespace vkcv { DescriptorSetManager::createDescriptorSet(const DescriptorSetLayoutHandle &layout) { // create and allocate the set based on the layout provided const auto &setLayout = m_DescriptorSetLayoutManager->getDescriptorSetLayout(layout); + const auto &device = getCore().getContext().getDevice(); + vk::DescriptorSet vulkanHandle; - vk::DescriptorSetAllocateInfo allocInfo(m_Pools.back(), 1, &setLayout.vulkanHandle); + vk::DescriptorSetAllocateInfo allocInfo( + m_Pools.back(), + 1, + &setLayout.vulkanHandle + ); uint32_t sumVariableDescriptorCounts = 0; for (auto bindingElem : setLayout.descriptorBindings) { @@ -109,15 +132,21 @@ namespace vkcv { allocInfo.setPNext(&variableAllocInfo); } - auto result = - getCore().getContext().getDevice().allocateDescriptorSets(&allocInfo, &vulkanHandle); + auto result = device.allocateDescriptorSets( + &allocInfo, + &vulkanHandle + ); + if (result != vk::Result::eSuccess) { // create a new descriptor pool if the previous one ran out of memory - if (result == vk::Result::eErrorOutOfPoolMemory) { - allocateDescriptorPool(); + if ((result == vk::Result::eErrorOutOfPoolMemory) && + (allocateDescriptorPool())) { allocInfo.setDescriptorPool(m_Pools.back()); - result = getCore().getContext().getDevice().allocateDescriptorSets(&allocInfo, - &vulkanHandle); + + result = device.allocateDescriptorSets( + &allocInfo, + &vulkanHandle + ); } if (result != vk::Result::eSuccess) { diff --git a/src/vkcv/ShaderProgram.cpp b/src/vkcv/ShaderProgram.cpp index 2deeeb813ad51e60b98a0c74f78b0cb0afa73039..5ad185d950de7e2e75ccb4cb34804251b0d97c9b 100644 --- a/src/vkcv/ShaderProgram.cpp +++ b/src/vkcv/ShaderProgram.cpp @@ -123,7 +123,6 @@ namespace vkcv { bool variableCount = false; // query whether reflected resources are qualified as one-dimensional array if (type.array_size_literal [0]) { - descriptorCount = type.array [0]; if (type.array [0] == 0) variableCount = true; } @@ -157,7 +156,6 @@ namespace vkcv { bool variableCount = false; // query whether reflected resources are qualified as one-dimensional array if (type.array_size_literal [0]) { - descriptorCount = type.array [0]; if (type.array [0] == 0) variableCount = true; } @@ -191,7 +189,6 @@ namespace vkcv { bool variableCount = false; // query whether reflected resources are qualified as one-dimensional array if (type.array_size_literal [0]) { - descriptorCount = type.array [0]; if (type.array [0] == 0) variableCount = true; } @@ -224,7 +221,6 @@ namespace vkcv { bool variableCount = false; // query whether reflected resources are qualified as one-dimensional array if (type.array_size_literal [0]) { - descriptorCount = type.array [0]; if (type.array [0] == 0) variableCount = true; } @@ -258,7 +254,6 @@ namespace vkcv { bool variableCount = false; // query whether reflected resources are qualified as one-dimensional array if (type.array_size_literal [0]) { - descriptorCount = type.array [0]; if (type.array [0] == 0) variableCount = true; }