Skip to content

Exception when trying to bake descriptor set with NULL bindings #62

Description

@Silverlan

Example:

auto dsgInfos = std::vector<std::unique_ptr<Anvil::DescriptorSetInfo>>{};
auto descSetInfo = Anvil::DescriptorSetInfo::create();
const auto numBindings = 5u;
for(auto i=0u;i<numBindings;++i)
{
	descSetInfo->add_binding(
		i, /* binding    */
		static_cast<VkDescriptorType>(vk::DescriptorType::eCombinedImageSampler),
		1u, /* n_elements */
		static_cast<VkShaderStageFlags>(vk::ShaderStageFlagBits::eFragment)
	);
}
dsgInfos.push_back(std::move(descSetInfo));
auto dsg = Anvil::DescriptorSetGroup::create(dev,dsgInfos,false);
auto ds = dsg->get_descriptor_set(0u);
for(auto i=0u;i<5u;++i)
{
	ds->set_binding_item(i,Anvil::DescriptorSet::CombinedImageSamplerBindingElement{
		static_cast<VkImageLayout>(vk::ImageLayout::eShaderReadOnlyOptimal),
		imgView,sampler
	});
}
drawCmd->record_bind_descriptor_sets(
	static_cast<VkPipelineBindPoint>(vk::PipelineBindPoint::eGraphics),
	GetPipelineLayout(),
	0u, /* first set */
	1u, /* set count */
	&ds,
	0u, /* dynamic offset count */
	nullptr
);

The code above works fine, both baking and binding run without issues.
However, if you change the second loop so it only binds 4 elements (i.e. one of the bindings is NULL):

for(auto i=0u;i<4u;++i)
{
	ds->set_binding_item(i,Anvil::DescriptorSet::CombinedImageSamplerBindingElement{
		static_cast<VkImageLayout>(vk::ImageLayout::eShaderReadOnlyOptimal),
		imgView,sampler
	});
}

then you get an exception during the baking process when trying to bind the descriptor set. The exception is caused in src/wrappers/descriptor_set.cpp (Anvil::DescriptorSet::bake()), in the vkUpdateDescriptorSets-call of this code block:

/* Issue the Vulkan call */
if (m_cached_ds_write_items_vk.size() > 0)
{
    std::shared_ptr<Anvil::BaseDevice> device_locked_ptr(m_device_ptr);

    lock();
    {
        vkUpdateDescriptorSets(device_locked_ptr->get_device_vk(),
                                static_cast<uint32_t>(m_cached_ds_write_items_vk.size() ),
                                &m_cached_ds_write_items_vk[0],
                                0,        /* copyCount         */
                                nullptr); /* pDescriptorCopies */
    }
    unlock();
}

I'm not actually sure if it is valid to have NULL bindings in a descriptor set when binding it, but I can't find anything in the vulkan specification that says otherwise.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions