-
Notifications
You must be signed in to change notification settings - Fork 969
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
Make wgpu-hal resources copyable (Metal and GL only) #3199
Conversation
Codecov Report
@@ Coverage Diff @@
## master #3199 +/- ##
==========================================
- Coverage 64.66% 64.62% -0.04%
==========================================
Files 81 81
Lines 38956 38976 +20
==========================================
Hits 25190 25190
- Misses 13766 13786 +20
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
Based on #3195 (comment) it may be the case that the idea to make them copyable is wrong to start with. But the code here is very useful to merge nevertheless. |
This is on my list to look at on Wednesday. |
@jimblandy wow, much conflicts. Is this clear to go otherwise, or we have concerns? |
@kvark I have concerns about not using the owning types. I'm having a hard time persuading myself that the changes in If you have time to add some comments about ownership and internal retention in the mean time, that'd be great. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got some time to look at this today.
@@ -333,7 +336,7 @@ impl crate::Device<super::Api> for super::Device { | |||
} | |||
|
|||
Ok(super::Texture { | |||
raw, | |||
raw: AsNative::own_from(raw.as_ref()), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we call AsNative::own_from
here and in texture_from_raw
, shouldn't destroy_texture
call AsNative::destroy
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Definitely. I just missed this, thanks for spotting!
de5be54
to
ad1df30
Compare
Rebased. |
ad1df30
to
9163f9d
Compare
@kvark I'm not convinced that making the resource types In the Metal case, we've already got idiomatic integration of Rust clone/drop behavior into Objective-C retain/release. Removing that just seems like a step backwards for no good reason. It's true, using And if my concern here is correct, then I think it's beyond debate that this is error-prone. Summary:
|
For what it's worth, in general we've seen retain/release show up on profiles in real use cases because of this, especially back when we were running Dota 2 on top of gfx-portability. Switching to raw pointers for some temporary resources helped significantly there (gfx-rs/gfx#2175). Based on that experience, it might be worth avoiding extra refcounting on the Metal side for some resources if we already track lifetimes internally (either manually or through other containers like |
I can certainly believe that refcounting shows up in profiles in general. But except for the And in the case of the gfx-rs/gfx#2175 seems apt: there, @jrmuizel said it would be error prone (indeed), and you said you would look into restricting pointer usage to high-frequency cases. So our values haven't changed here. |
@jimblandy agreed, I just wanted to add some context in case you (or anyone else) might be curious why we avoid extra Objective-C refcounting in some other places |
@grovesNL was the reference counting performance problem happening when doing doing |
@jrmuizel I think we only ever tried it with |
@jimblandy thanks for looking!
It's clear that wgpu-hal internals require good care and are generally easy to screw up. This applies to many places. Having a proper texture destructor is one of the easier ones. The desire to make this particular bit in the metal backend a tiny bit safer inside has a very marginal effect on wgpu-hal as a whole. On the other hand, making Metal's objects to do manual refcounting would be more consistent with the rest of the code base:
As for the user of wgpu-hal - there is a million ways to screw up object lifetime even if the object is not I'm describing both inside wgpu-hal and external factors because I'm not sure which one you are most concerned with :) |
It's certainly true that using a ref-counting type here does not magically make everything else that hal does safe.
This is the part I don't understand: what is the upside? Two questions:
In short, I think you've got some plans, or some experiences, behind this change that I'm not seeing. Without understanding the advantages, I don't want to take the change. |
Let's get the |
You know, maybe there's an easy compromise here: how about just making them |
Due to serious safety concerns (especially after a vulnerability directly related to copyable handles), I don't think we can land this in its current form. |
Checklist
cargo clippy
.RUSTFLAGS=--cfg=web_sys_unstable_apis cargo clippy --target wasm32-unknown-unknown
if applicable.Connections
Closes #3195
Description
See #3195
Testing
Examples.