Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sub-allocated descriptor sets #95

Draft
wants to merge 13 commits into
base: master
Choose a base branch
from
61 changes: 27 additions & 34 deletions 67_SubAllocatedDescriptorSet/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,62 +67,55 @@ class SubAllocatedDescriptorSetApp final : public examples::MonoDeviceApplicatio

// Descriptor set sub allocator

video::IGPUDescriptorSetLayout::SBinding bindings[1];
video::IGPUDescriptorSetLayout::SBinding bindings[12];
{
bindings[0].binding = 0;
bindings[0].count = 65536u;
bindings[0].createFlags = core::bitflag(IGPUDescriptorSetLayout::SBinding::E_CREATE_FLAGS::ECF_UPDATE_AFTER_BIND_BIT)
| IGPUDescriptorSetLayout::SBinding::E_CREATE_FLAGS::ECF_UPDATE_UNUSED_WHILE_PENDING_BIT
| IGPUDescriptorSetLayout::SBinding::E_CREATE_FLAGS::ECF_PARTIALLY_BOUND_BIT;
bindings[0].type = asset::IDescriptor::E_TYPE::ET_STORAGE_IMAGE;
bindings[0].stageFlags = asset::IShader::E_SHADER_STAGE::ESS_COMPUTE;
for (uint32_t i = 0; i < 12; i++)
{
bindings[i].binding = i;
bindings[i].count = 16000;
bindings[i].createFlags = core::bitflag(IGPUDescriptorSetLayout::SBinding::E_CREATE_FLAGS::ECF_UPDATE_AFTER_BIND_BIT)
| IGPUDescriptorSetLayout::SBinding::E_CREATE_FLAGS::ECF_UPDATE_UNUSED_WHILE_PENDING_BIT
| IGPUDescriptorSetLayout::SBinding::E_CREATE_FLAGS::ECF_PARTIALLY_BOUND_BIT;
if (i % 2 == 0) bindings[i].type = asset::IDescriptor::E_TYPE::ET_STORAGE_IMAGE;
else if (i % 2 == 1) bindings[i].type = asset::IDescriptor::E_TYPE::ET_STORAGE_BUFFER;
Comment on lines +168 to +169

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you might want to try all descriptor types just to make the testing complete

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

enable acceleration structure if available, and even test that if its there

(can be done as separate PR, no clue if the AS refactor works without stupid typos yet)

bindings[i].stageFlags = asset::IShader::E_SHADER_STAGE::ESS_COMPUTE;
}
}

std::span<video::IGPUDescriptorSetLayout::SBinding> bindingsSpan(bindings);

auto descriptorSetLayout = m_device->createDescriptorSetLayout(bindings);

// TODO: I don't think these are needed for sub allocated descriptor sets (alignment isn't needed, and min size is 1)
auto subAllocatedDescriptorSet = core::make_smart_refctd_ptr<nbl::video::SubAllocatedDescriptorSet>(
bindings, MaxDescriptorSetAllocationAlignment, MinDescriptorSetAllocationSize
descriptorSetLayout.get(), MaxDescriptorSetAllocationAlignment, MinDescriptorSetAllocationSize
);

std::vector<uint32_t> allocation, size;
std::vector<uint32_t> allocation(128, core::PoolAddressAllocator<uint32_t>::invalid_address);
{
for (uint32_t i = 0; i < 512; i++)
{
allocation.push_back(core::GeneralpurposeAddressAllocator<uint32_t>::invalid_address);
size.push_back(4);
}
subAllocatedDescriptorSet->multi_allocate(0, allocation.size(), &allocation[0], &size[0]);
subAllocatedDescriptorSet->multi_allocate(0, allocation.size(), &allocation[0]);
for (uint32_t i = 0; i < allocation.size(); i++)
{
m_logger->log("allocation[%d]: %d", system::ILogger::ELL_INFO, i, allocation[i]);
assert(allocation[i] != core::GeneralpurposeAddressAllocator<uint32_t>::invalid_address);
assert(allocation[i] != core::PoolAddressAllocator<uint32_t>::invalid_address);
}
}
{
std::vector<uint32_t> addr, freeSize;
for (uint32_t i = 0; i < 512; i+=2)
std::vector<uint32_t> addr;
for (uint32_t i = 0; i < allocation.size(); i+=2)
{
addr.push_back(allocation[i]);
freeSize.push_back(4);
}
subAllocatedDescriptorSet->multi_deallocate(0, addr.size(), &addr[0], &freeSize[0]);
subAllocatedDescriptorSet->multi_deallocate(0, addr.size(), &addr[0]);
}

m_logger->log("Freed some allocations", system::ILogger::ELL_INFO);
allocation.clear();
size.clear();
m_logger->log("freed half the descriptors", system::ILogger::ELL_INFO);
std::vector<uint32_t> allocation2(128, core::PoolAddressAllocator<uint32_t>::invalid_address);
{
for (uint32_t i = 0; i < 512; i++)
subAllocatedDescriptorSet->multi_allocate(0, allocation2.size(), &allocation2[0]);
for (uint32_t i = 0; i < allocation2.size(); i++)
{
allocation.push_back(core::GeneralpurposeAddressAllocator<uint32_t>::invalid_address);
size.push_back(2);
}
subAllocatedDescriptorSet->multi_allocate(0, allocation.size(), &allocation[0], &size[0]);
for (uint32_t i = 0; i < allocation.size(); i++)
{
m_logger->log("allocation[%d]: %d", system::ILogger::ELL_INFO, i, allocation[i]);
assert(allocation[i] != core::GeneralpurposeAddressAllocator<uint32_t>::invalid_address);
m_logger->log("allocation[%d]: %d", system::ILogger::ELL_INFO, i, allocation2[i]);
assert(allocation2[i] != core::PoolAddressAllocator<uint32_t>::invalid_address);
}
}

Expand Down