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.64k stars 402 forks source link

WIP: Calculate argument buffer allocation size taking variable counts into account. #2199

Open js6i opened 3 months ago

js6i commented 3 months ago

When allocating descriptors from the pool, we should only request as much as needed for the variable number of descriptors, if applicable.

It looks slightly dicey to use the fixed size argument encoder when encoding variable sized bindings. Since here we're creating the encoder to calculate the size, maybe we could use it for encoding too..

js6i commented 3 months ago

Having each descriptor set carry its own encoder sounds like a lot. Perhaps we could have the descriptor set defer to the layout's encoder, unless the variable descriptor count is less than the descriptor count of the variable-length binding.

I think we could do that. Are they expensive though? I would have thought it's fine to create them on demand, for single use.

However, we are going to move away from argument encoders very soon. So, I don't think we should bother making things that complex unless we actually determine it is causing a problem.

It's causing a validation error. That said, there's also another one, when the shader has the maximum size array declared, but the buffer that gets bound is smaller. Let's hold off merging for now, I'll see what can be done about the other one.

js6i commented 2 months ago

I updated the PR with commits that fix the validation errors. However now, in a number of tests, I'm getting GPU crashes instead - which seem to be triggered by having flexible arrays in the shaders. Marking as WIP..