-
Notifications
You must be signed in to change notification settings - Fork 547
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RFC: Clone-ability Guidelines #2457
Comments
Command buffer is only clonable type and you want to make it nonclonnable and other types clonnable... |
Command buffers being clon-eable is a very unfortunate artifact, as I've been complaining about it since the beginning. Why do you want them to be clone-able? |
Because you want them in at least two places. Near command pool to reuse next time. Near queue to submit when all command buffers for submission are ready. Maybe even store submission objects and resubmit them each frame after recording. |
Being able to clone synchronizers would allow something like below without using let mut acquire_semaphores =
iter::repeat(device.borrow().get_device().create_semaphore().unwrap())
.take(image_count as _)
.collect(); I think a lot of other types could benefit from similar initialization. |
@bbrown683 Cloning resource gives you new value that represent the very same resource. |
This is an RFC for #2454, also related to #2452
There has been a lot of discussion about gfx-hal types having move semantics. More often than not, it stands in a way of working with the API. The type system integration that the move semantics provides isn't helping much because of the overall level unsafety we expose. The reason for types to not being
Clone
at the API level is because it allows the backends to use non-clonable data in the implementation. In practice, dealing with native API often involves some sort of sharing: Vulkan handles are just copyable machine words, D3D12 has ComPtr, and Metal's objects are refcounted internally. At the end of the day, if none of the backends require the move semantics for a particular type, there is one less reason to not haveClone
on it. One particularly annoying aspect of the move semantics is that it doesn't play well with Rust'sdrop(&mut self)
. Thus, if a structure owns some graphics objects, and it wants to clean up after itself, it needs to resort to some run-time owning tricks likeOption
orManuallyDrop
.This aspect of the API affects both gfx-hal and wgpu-rs, and it's very important to get right.
Proposed Guideline
Enable
Clone
on objects (at the API level) if all the conditions are met:Clone
In order to see how this would be applied, let's split all graphics objects in the following groups:
&mut self
method. For this reason, I suggest them to keep the move semantics.Clone
on them.Clone
as well, although I'm not sure if anybody would benefit from them.Note: this is a proposal! comments are welcome.
The text was updated successfully, but these errors were encountered: