Skip to content
Snippets Groups Projects
Verified Commit 746db64c authored by Tobias Frisch's avatar Tobias Frisch
Browse files

Fix loading layout bindings from shaders

parent 036a31e7
No related branches found
No related tags found
No related merge requests found
...@@ -53,17 +53,15 @@ int main(int argc, const char** argv) { ...@@ -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) // 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); const vkcv::DescriptorBindings& set0Bindings = firstMeshProgram.getReflectedDescriptors().at(0);
vkcv::DescriptorSetLayoutHandle setLayoutHandle = core.createDescriptorSetLayout(set0Bindings); vkcv::DescriptorSetLayoutHandle descriptorSetLayout = core.createDescriptorSetLayout(set0Bindings);
vkcv::DescriptorSetLayoutHandle setLayoutHandleCopy = core.createDescriptorSetLayout(set0Bindings); vkcv::DescriptorSetHandle descriptorSet = core.createDescriptorSet(descriptorSetLayout);
vkcv::DescriptorSetHandle descriptorSet = core.createDescriptorSet(setLayoutHandle);
vkcv::GraphicsPipelineHandle firstMeshPipeline = core.createGraphicsPipeline( vkcv::GraphicsPipelineHandle firstMeshPipeline = core.createGraphicsPipeline(
vkcv::GraphicsPipelineConfig( vkcv::GraphicsPipelineConfig(
firstMeshProgram, firstMeshProgram,
firstMeshPass, firstMeshPass,
{ firstMeshLayout }, { firstMeshLayout },
{ setLayoutHandle } { descriptorSetLayout }
) )
); );
......
...@@ -22,19 +22,27 @@ namespace vkcv { ...@@ -22,19 +22,27 @@ namespace vkcv {
*/ */
m_PoolSizes.clear(); m_PoolSizes.clear();
m_PoolSizes.emplace_back(vk::DescriptorType::eSampler, 1000); 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::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::eUniformBuffer, 1000);
m_PoolSizes.emplace_back(vk::DescriptorType::eStorageBuffer, 1000); m_PoolSizes.emplace_back(vk::DescriptorType::eStorageBuffer, 1000);
m_PoolSizes.emplace_back(vk::DescriptorType::eUniformBufferDynamic, 1000); m_PoolSizes.emplace_back(vk::DescriptorType::eUniformBufferDynamic, 1000);
m_PoolSizes.emplace_back(vk::DescriptorType::eStorageBufferDynamic, 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)) { if (core.getContext().getFeatureManager().isExtensionActive(VK_KHR_ACCELERATION_STRUCTURE_EXTENSION_NAME)) {
m_PoolSizes.emplace_back(vk::DescriptorType::eAccelerationStructureKHR, 1000); m_PoolSizes.emplace_back(vk::DescriptorType::eAccelerationStructureKHR, 1000);
} }
m_PoolInfo = vk::DescriptorPoolCreateInfo( m_PoolInfo = vk::DescriptorPoolCreateInfo(
vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet, 1000, vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet,
static_cast<uint32_t>(m_PoolSizes.size()), m_PoolSizes.data() 1000,
static_cast<uint32_t>(m_PoolSizes.size()),
m_PoolSizes.data()
); );
return allocateDescriptorPool(); return allocateDescriptorPool();
...@@ -50,11 +58,16 @@ namespace vkcv { ...@@ -50,11 +58,16 @@ namespace vkcv {
} }
void DescriptorSetManager::destroyById(uint64_t id) { void DescriptorSetManager::destroyById(uint64_t id) {
const auto& device = getCore().getContext().getDevice();
auto &set = getById(id); auto &set = getById(id);
if (set.vulkanHandle) { if (set.vulkanHandle) {
getCore().getContext().getDevice().freeDescriptorSets(m_Pools [set.poolIndex], 1, device.freeDescriptorSets(
&(set.vulkanHandle)); m_Pools[set.poolIndex],
1,
&(set.vulkanHandle)
);
set.vulkanHandle = nullptr; set.vulkanHandle = nullptr;
} }
...@@ -62,8 +75,10 @@ namespace vkcv { ...@@ -62,8 +75,10 @@ namespace vkcv {
} }
bool DescriptorSetManager::allocateDescriptorPool() { bool DescriptorSetManager::allocateDescriptorPool() {
const auto& device = getCore().getContext().getDevice();
vk::DescriptorPool pool; vk::DescriptorPool pool;
if (getCore().getContext().getDevice().createDescriptorPool(&m_PoolInfo, nullptr, &pool) if (device.createDescriptorPool(&m_PoolInfo, nullptr, &pool)
!= vk::Result::eSuccess) { != vk::Result::eSuccess) {
vkcv_log(LogLevel::WARNING, "Failed to allocate descriptor pool"); vkcv_log(LogLevel::WARNING, "Failed to allocate descriptor pool");
return false; return false;
...@@ -77,11 +92,13 @@ namespace vkcv { ...@@ -77,11 +92,13 @@ namespace vkcv {
HandleManager<DescriptorSetEntry, DescriptorSetHandle>() {} HandleManager<DescriptorSetEntry, DescriptorSetHandle>() {}
DescriptorSetManager::~DescriptorSetManager() noexcept { DescriptorSetManager::~DescriptorSetManager() noexcept {
const auto& device = getCore().getContext().getDevice();
clear(); clear();
for (const auto &pool : m_Pools) { for (const auto &pool : m_Pools) {
if (pool) { if (pool) {
getCore().getContext().getDevice().destroy(pool); device.destroy(pool);
} }
} }
} }
...@@ -90,9 +107,15 @@ namespace vkcv { ...@@ -90,9 +107,15 @@ namespace vkcv {
DescriptorSetManager::createDescriptorSet(const DescriptorSetLayoutHandle &layout) { DescriptorSetManager::createDescriptorSet(const DescriptorSetLayoutHandle &layout) {
// create and allocate the set based on the layout provided // create and allocate the set based on the layout provided
const auto &setLayout = m_DescriptorSetLayoutManager->getDescriptorSetLayout(layout); const auto &setLayout = m_DescriptorSetLayoutManager->getDescriptorSetLayout(layout);
const auto &device = getCore().getContext().getDevice();
vk::DescriptorSet vulkanHandle; 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; uint32_t sumVariableDescriptorCounts = 0;
for (auto bindingElem : setLayout.descriptorBindings) { for (auto bindingElem : setLayout.descriptorBindings) {
...@@ -109,15 +132,21 @@ namespace vkcv { ...@@ -109,15 +132,21 @@ namespace vkcv {
allocInfo.setPNext(&variableAllocInfo); allocInfo.setPNext(&variableAllocInfo);
} }
auto result = auto result = device.allocateDescriptorSets(
getCore().getContext().getDevice().allocateDescriptorSets(&allocInfo, &vulkanHandle); &allocInfo,
&vulkanHandle
);
if (result != vk::Result::eSuccess) { if (result != vk::Result::eSuccess) {
// create a new descriptor pool if the previous one ran out of memory // create a new descriptor pool if the previous one ran out of memory
if (result == vk::Result::eErrorOutOfPoolMemory) { if ((result == vk::Result::eErrorOutOfPoolMemory) &&
allocateDescriptorPool(); (allocateDescriptorPool())) {
allocInfo.setDescriptorPool(m_Pools.back()); allocInfo.setDescriptorPool(m_Pools.back());
result = getCore().getContext().getDevice().allocateDescriptorSets(&allocInfo,
&vulkanHandle); result = device.allocateDescriptorSets(
&allocInfo,
&vulkanHandle
);
} }
if (result != vk::Result::eSuccess) { if (result != vk::Result::eSuccess) {
......
...@@ -123,7 +123,6 @@ namespace vkcv { ...@@ -123,7 +123,6 @@ namespace vkcv {
bool variableCount = false; bool variableCount = false;
// query whether reflected resources are qualified as one-dimensional array // query whether reflected resources are qualified as one-dimensional array
if (type.array_size_literal [0]) { if (type.array_size_literal [0]) {
descriptorCount = type.array [0];
if (type.array [0] == 0) if (type.array [0] == 0)
variableCount = true; variableCount = true;
} }
...@@ -157,7 +156,6 @@ namespace vkcv { ...@@ -157,7 +156,6 @@ namespace vkcv {
bool variableCount = false; bool variableCount = false;
// query whether reflected resources are qualified as one-dimensional array // query whether reflected resources are qualified as one-dimensional array
if (type.array_size_literal [0]) { if (type.array_size_literal [0]) {
descriptorCount = type.array [0];
if (type.array [0] == 0) if (type.array [0] == 0)
variableCount = true; variableCount = true;
} }
...@@ -191,7 +189,6 @@ namespace vkcv { ...@@ -191,7 +189,6 @@ namespace vkcv {
bool variableCount = false; bool variableCount = false;
// query whether reflected resources are qualified as one-dimensional array // query whether reflected resources are qualified as one-dimensional array
if (type.array_size_literal [0]) { if (type.array_size_literal [0]) {
descriptorCount = type.array [0];
if (type.array [0] == 0) if (type.array [0] == 0)
variableCount = true; variableCount = true;
} }
...@@ -224,7 +221,6 @@ namespace vkcv { ...@@ -224,7 +221,6 @@ namespace vkcv {
bool variableCount = false; bool variableCount = false;
// query whether reflected resources are qualified as one-dimensional array // query whether reflected resources are qualified as one-dimensional array
if (type.array_size_literal [0]) { if (type.array_size_literal [0]) {
descriptorCount = type.array [0];
if (type.array [0] == 0) if (type.array [0] == 0)
variableCount = true; variableCount = true;
} }
...@@ -258,7 +254,6 @@ namespace vkcv { ...@@ -258,7 +254,6 @@ namespace vkcv {
bool variableCount = false; bool variableCount = false;
// query whether reflected resources are qualified as one-dimensional array // query whether reflected resources are qualified as one-dimensional array
if (type.array_size_literal [0]) { if (type.array_size_literal [0]) {
descriptorCount = type.array [0];
if (type.array [0] == 0) if (type.array [0] == 0)
variableCount = true; variableCount = true;
} }
......
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