vulkano-rs/vulkano

Can we get an example of multiple uniform buffers?

coolcatcoder opened this issue · 8 comments

As far as I can tell there isn't an example in the examples that shows how to have multiple uniform buffers.

In my specific case I want to have both a uniform buffer containing a texture sampler, and a uniform buffer holding the aspect ratio. Alas trying to find any info about this online seems to be futile.

Rua commented

I don't think it's really any different from having one uniform buffer?

I couldn't work out how to do it... If you want to tell me where I went wrong, then my code is here: https://github.com/coolcatcoder/vulkan_fun (Note I'm aware that I'm not actually using the uniform buffer in the shader, and that all my vertices have the same uv. I can fix those problems later. First I just want to get rid of the uniform related panics. Also sorry for the lack of useful comments... I do need to work on commenting more often.)

Rua commented

Where did it go wrong exactly?

You of course need to create a second buffer, just like you created the first one here:
https://github.com/coolcatcoder/vulkan_fun/blob/master/src/main.rs#L407-L419

Then you write both of them to a descriptor set; either to the same descriptor set or each to its own (only do this if you know you need to). Then you bind the descriptor sets as before, and when the shader executes, the uniform buffers should be there.

According to the image example it seems uniform buffers work slightly differently for samplers... I currently do have each one in its own descripter cause I couldn't work out how to combine them. It just doesn't work. Gives me this error:

thread 'main' panicked at 'called Result::unwrap() on an Err value: DescriptorSetUpdateError(InvalidBinding { binding: 1 })', src\main.rs:307:6

Rua commented

Samplers don't use buffers at all, but have their own type of descriptor.

The error you're getting indicates that you're trying to write a descriptor to binding 1, but there is no such binding in the descriptor set layout (and therefore, presumably, no such binding is used in the shader).

Okay thanks a ton! Actually using the sampler in the shader caused me to get a new error message! This led me down the rabbit hole of trying to work out what the different between sets and bindings are. Eventually I managed to work it out (Updated my repository to match), but now I'm getting a new fun error message:

thread 'main' panicked at 'failed to flush future: access to a resource has been denied', src\main.rs:511:25

I can't work out what resource it couldn't get access to, but I'm assuming it has something to do with the uniforms, because this error never appeared before.

Rua commented

I notice that uploads never actually gets built and submitted anywhere. You should probably do that before you start rendering, and then use its future when first setting previous_frame_end. I don't know if that's the cause of the problem, but it's probably not right either way.

That fixed it! Thanks a ton! Comparing my current code with the image example I can see where I went wrong. Next time I'm trying to implement something from an example I'll be more careful and thorough!