-
Notifications
You must be signed in to change notification settings - Fork 185
Conversation
I think this will have the same issue as mentioned in #202 |
@grovesNL I'm not sure I understand how adding Hash implementations to these handle types causes an issue with the web backend. I can understand that unique IDs for javascript objects could be a problem, but I don't see how they are related. Wouldn't the javascript object reference the handle, not the other way around? |
I'd like to get a better understanding as to why adding In any case, I think we could ultimately get around it with something like: #[cfg_attr(not(target_arch = "wasm32"), derive(Hash))] |
Types like Line 6 in 1084bbd
GpuAdapter , but GpuAdapter isn't able to derive Hash because the GpuAdapter JS object is an opaque handle. We could add a layer of indirection to map ID<->JS object for the web backend but it would be nice to avoid this if possible.
|
@grovesNL Thank you, now I understand how it's an issue. I've pushed a new commit that will conditionally implement |
Ok great, thanks! I'm still not sure whether it's best to hide it behind For example, it would be a bit unfortunate for portability if crates tend to rely on this, then later realize they can't easily target the web just by switching targets. |
You could give every object a unique ID using |
Another option is to just use a non-atomic incrementing Would you be comfortable to merge if I commented out the |
Yeah that sounds good to me 👍 I think these are interesting ideas and worth exploring, but it might be safer to remove the |
Are the |
Right, because |
@grovesNL I've removed the Hash derives. |
Thanks! It looks like CI has some build errors |
Yeah, it depends the changes here: gfx-rs/wgpu#535 |
Oh whoops, sorry – I thought we already updated to a newer |
please rebase |
@aloucks would you want to snuck this in for 0.5 or follow-up? |
@kvark Yes. I'll rebase and push this evening. |
@kvark should be good now. |
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.
Thank you! Please squash as well as remove the debug leftovers :)
src/lib.rs
Outdated
@@ -81,11 +81,25 @@ struct Temp { | |||
//vertex_buffers: Vec<wgn::VertexBufferDescriptor>, | |||
} | |||
|
|||
impl PartialEq for Temp { |
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.
please remove
@kvark - That Temp struct still exists. If I remove the PartialEq impl it will break the PartialEq impl for Device. Do you want me to remove Temp and any references to it? |
Don't implement Hash on handle id types for wasm32 Unlike the native handle ids that are effectively wrappers around an intetger type, the handle id types for the wasm32 backend are redefined to point at web_sys structures that may not have Hash implemented. Remove Hash implementations for now but keep PartialEq and Eq Remove Hash on more descriptors Remove Temp
@kvark I've removed |
@aloucks wow, Main question is: where is it useful to compare any ObjectId for equality? |
You can't clone them but you can have multiple references to them. The original PR included Missing |
Yes, thinking about this more, I feel stronger that these derives are not necessary. PartialEq only makes sense for things that you can have multiple instances of. If you have unique instances, and just different references, then you should be comparing the references. struct RefKey<'a, T: 'a>(&'a T);
impl PartialEq for RefKey<'_, _> {
fn eq(&self, other: &Self) -> bool {
std::ptr::eq(self.0, other.0)
}
} Similarly can be done for |
Not having And:
|
I strongly disagree with this. It's makes comparison with |
Yes, and is it any different from
If your struct contains |
But how and why is this of any value? Now I need to add to also create a |
Our object wrappers currently are mostly just carrying an ID, but this isn't necessarily the case. For example, So in the end we are likely going to have 3 different backends, or implementations of these types (wgpu-core, wgpu-native, and web-sys). Putting any derive on them means more friction and less freedom (i.e. it will be less straightforward to extend the structs) to these implementations. The amount of code that would go into wgpu-rs itself (manual implementation of the traits for 5+ types, potentially growing) would then exceed the amount of code that an application would need to have (i.e. So in the end, it seems to me that this task is not obviously better solved by wgpu-rs in practice. And in theory, |
Just my 2c, since you pinged me: We currently have no need for Eq or PartialEq implementations for any of the opaque, unique handle types like I'd rather the API be consistent, and I definitely think If making a unique (non-Clone) handle type Eq or PartialEq is a compatibility or maintenance hazard then that seems like a good idea not to have those impls. Now, if there is definitely no compatibility hazard or maintenance burden then I suppose it's not harmful to have those impls, but I can't foresee using them for anything (again, just talking about the unique handle-to-resources types like |
The Example: |
True. It's easy to see why this is the case though: JS objects on the web in general are refcounted, so web-sys has the semantics of |
I think we reached the conclusion that so far the PartialEq/Eq are not needed. Please feel free to raise this topic again for a follow-up! |
Depends on gfx-rs/wgpu#535