gfx-rs / gfx

[maintenance mode] A low-overhead Vulkan-like GPU API for Rust.
http://gfx-rs.github.io/
Apache License 2.0
5.35k stars 549 forks source link

Externally synchronized parameter lists #3551

Closed kvark closed 3 years ago

kvark commented 3 years ago

In Vulkan, there is a section for "Externally Synchronized Parameter Lists":

There are also a few instances where a command can take in a user allocated list whose contents are externally synchronized parameters. In these cases, the caller must guarantee that at most one thread is using a given element within the list at a given time.

Rust semantics for this may be a little bit tricky. It can't be &mut strictly speaking. Could they be BorrowMut<>?

For example, descriptor set writes should be:

struct DescriptorSetWrite {
  set: &'a mut B::DescriptorSet,
  ...
}
kvark commented 3 years ago

This looks more complicated than I hoped...

If descriptor write is &mut DescriptorSet, then the user can no longer have multiple writes into the same descriptor in this API. But it's fine in Vulkan. So unfortunately sounds like we can't have &mut Descriptor Set. We basically need something that locks an element in place while it's being processed, like a user-visible Arc<Mutex<..>>, or a trait that hides it.

Or, more concretely, the user should be able to pass one of the following:

kvark commented 3 years ago

I'm thinking about just making it so write_descriptor_sets works with a single set (and is renamed). That would mean &mut clearly, without any borrowing crap. Any concerns - @msiglreith @grovesNL @cwfitzgerald ?