KhronosGroup / MoltenVK

MoltenVK is a Vulkan Portability implementation. It layers a subset of the high-performance, industry-standard Vulkan graphics and compute API over Apple's Metal graphics framework, enabling Vulkan applications to run on macOS, iOS and tvOS.
Apache License 2.0
4.63k stars 402 forks source link

Question: Does MVK support VK_DESCRIPTOR_BINDING_VARIABLE_DESCRIPTOR_COUNT_BIT_EXT? #2246

Open SRSaunders opened 1 month ago

SRSaunders commented 1 month ago

The _descriptorindexing sample in the official Khronos Vulkan-Samples repo fails (https://github.com/KhronosGroup/Vulkan-Samples/blob/main/samples/extensions/descriptor_indexing/descriptor_indexing.cpp), even with argument buffers enabled.

I have tracked down the issue, and it relates to exhaustion of the descriptor pool. The sample defines bindings with set_layout_binding.descriptorCount = maxDescriptorSetUpdateAfterBindSampledImages, i.e. the max. This seems excessive, but may not be an issue for other platforms that respect the VK_DESCRIPTOR_BINDING_VARIABLE_DESCRIPTOR_COUNT_BIT_EXT flag which is set by the sample.

The problem arises when actually allocating descriptor sets, i.e. when calling vkAllocateDescriptorSets() extended by the VkDescriptorSetVariableDescriptorCountAllocateInfoEXT structure. The structure properly defines the number of descriptors to be allocated (i.e. NumDescriptorsStreaming and NumDescriptorsNonUniform in two separate allocations), but MoltenVK's allocate action seems to check if there are set_layout_binding.descriptorCount resources available in the pool, which in this case is 500,000 (the max) and of course this fails since it exceeds the pool size.

I have been able to verify this and get the sample working by using NumDescriptorsStreaming in the binding definition, and by increasing the pool size to 2 x NumDescriptorsStreaming (for 2 allocation calls). However, I suspect this may violate the spirit of the sample where variable descriptor count allocations are used.

I am wondering whether MoltenVK supports the variable descriptor count flag and structure, and if so, should it instead be checking for variable_info.pDescriptorCounts resources in the pool when the variable bit is enabled and the variable descriptor count structure is present in the pNext chain of allocate_info.

I am putting this forward as a question, since I may not have this right. However, I wanted to report it here before going back to the official sample repo and offering any solutions for MoltenVK in that forum.

billhollings commented 6 days ago

The use of Metal Argument Buffers in MoltenVK is currently being overhauled. It should be published in the next week or so. At that point, you can retest this, and if it's still an issue, we can fix it within the new argument buffer environment.

SRSaunders commented 6 days ago

Thanks for the heads up and I will retest when you release your new argument buffer code.