attackgoat / screen-13

Screen 13 is an easy-to-use Vulkan rendering engine in the spirit of QBasic.
Apache License 2.0
256 stars 12 forks source link

Improve graph binding patterns #25

Closed attackgoat closed 2 years ago

attackgoat commented 2 years ago

The goal here (see #10) is to make binding easier or transparent. Removing the usize node structs is outside of this goal because they serve a real purpose (among them making the subpass API easy to use, by supporting copy) which I don't see improvements on yet.

Bind by Reference

This change introduces bind-by-reference as opposed to the current design, which is bind-by-value with regard to buffers, images, etc, being used on a render graph.

The new design retains almost entirely the same API as before, and previous concepts carry over.

What is new is that by implication of using a reference to bind nodes we do not need to unbind them, unless it is helpful in your workflow. Unbinding is now totally optional and could potentially be removed.

New example usage

let my_image = Arc::new(Image::create(&device, ImageInfo { ..same as before.. })?);

let my_node = frame.render_graph.bind_node(&my_image);

Upgrade guidance

Description of the change

The first step was to move the state of a resource from the "graph" layer into the "driver" layer; so that state sits on the actual acceleration structure, buffer, or image. Doing this requires a synchronization primitive of some kind, because previously this state was "owned" by the graph and now it is borrowed. I've chosen to use an AtomicU8 for this state.

After moving the state data the only remaining field on the ImageBinding, BufferLeaseBinding, etc types was the actual resource.

The second commit removed these binding types and now you may bind any of Image, Arc<Image> or &Arc<Image>, etc. This means you don't have to provide instances of these resources, just borrows. This should make Screen 13 much easier to use.

TODO