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

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

Closed
Silverlan opened this issue Mar 15, 2018 · 3 comments
Closed

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

Silverlan opened this issue Mar 15, 2018 · 3 comments
Assignees
Labels

Comments

@Silverlan
Copy link
Contributor

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.

@DominikWitczakAMD
Copy link
Contributor

They should be fine, as long as you do not try to access corresponding bindings from the shader level.. Let me have a look at this now.

@DominikWitczakAMD DominikWitczakAMD self-assigned this Mar 15, 2018
@DominikWitczakAMD
Copy link
Contributor

Fixed internally. An update containing the patch will be pushed to this repo early next week.

DominikWitczakAMD added a commit that referenced this issue Mar 27, 2018
* #62: Exception when trying to bake a descriptor set with null bindings
* Descriptor set write support can now handle arrayed bindings with gaps.
* Fix an issue where RenderPassInfo would use obsolete pointers under certain
  circumstances.
* Fix an issue where bindings would not be marked as clean at update time
* Fix broken sampler descriptor support.
* Fix VK_AMD_texture_gather_bias_lod support regression
@DominikWitczakAMD
Copy link
Contributor

Addresse

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants