-
Notifications
You must be signed in to change notification settings - Fork 968
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
Implement Clone on Api Types and Arc Dispatcher #6665
Conversation
f01ebb7
to
eb3ebd0
Compare
I picked basically the worst way to implement this, will do it better tomorrow |
This will complicate #6658 as it uses |
@sagudev the things you use get_mut for aren't clonable - only types with only Probably those shouldn't be Arc though, but Box? |
2943022
to
8cf40e9
Compare
Then we have the problem of impl PartialEq, Hash and others, I think we need trait for DynCompare and DynHashable or some other black magic, this will not be as easy as I initially thought. |
Actually if this PR wraps all internal dispatch types into Arcs and we use this arc for clone/eq/hash then there is no need for dispatch types to impl eq/hash. |
Yeah I was thinking that - the one problem is the non & types which aren't clone. Those could just use normal ID generation. Can tackle that in a followup. |
Don't the websys types impl With the approach in this PR, once we remove the registries we will end up with 2 |
I'm theory we could, but Buffers/Textures contain a decent amount of state that just hangs out in the frontend and needs to be shared as well. This isn't a regression from v23, as they had everything boxed already. More generally, to me the interesting part isn't the internals, which we can iterate on , but that we're now advertising Clone support and will continue to support that. I do believe that cloning a web_sys value requires calling out to JS, so I was trying to avoid it. |
2555d99
to
35c3673
Compare
Resolution: Merge and Iterate
|
@cwfitzgerald any reason not to undraft and land? |
No, just need to do it. |
35c3673
to
f78e635
Compare
Alright, this implementation of clone makes things slightly slower, but I think some impl changes will cause that to go away. Benchmark results. This is inverted, so this is the speed of trunk compared to this PR.
|
This implements clone on all api types and on the arc dispatcher.
Because the new context api moves the drop logic into the backends, this is totally fine, and to wgpu_core it acts like someone is using the standard
Arc<wgpu::Buffer>
.Still needs some tests and stuff, but this would be a huge usability improvement, and will help in the development of better surface apis.
Checklist
cargo fmt
.taplo format
.cargo clippy
. If applicable, add:--target wasm32-unknown-unknown
--target wasm32-unknown-emscripten
cargo xtask test
to run tests.CHANGELOG.md
. See simple instructions inside file.