Repository navigation
webgpu: Proper cleanup in GPUBuffer - #46415
Conversation
…s automatically) Signed-off-by: sagudev <[email protected]>
Signed-off-by: sagudev <[email protected]>
Signed-off-by: sagudev <[email protected]>
Signed-off-by: sagudev <[email protected]>
| // we need to pop one by one so we can root one by one for detach | ||
| while let Some(DataView { buffer, .. }) = self.data_views.pop() { | ||
| rooted!(&in(cx) let b = unsafe { buffer.underlying_object().get() }); | ||
| assert!(unsafe { DetachArrayBuffer(cx, b.handle()) }) |
There was a problem hiding this comment.
This carries many important lessons:
- destruct can be useful (so drop should be prevented not dummy implemented)
- containers are hard
- esp when you can get content out of them (pop, drain), cut it's not rooted really and it's not typed to be rooted/unrooted.
- so removing crown is hard, but we could do this using own container types (would that cover all cases?)
- esp when you can get content out of them (pop, drain), cut it's not rooted really and it's not typed to be rooted/unrooted.
| #[dom_struct] | ||
| pub(crate) struct GPUBuffer { | ||
| reflector_: Reflector, | ||
| #[derive(JSTraceable, MallocSizeOf)] |
There was a problem hiding this comment.
I noticed other instances in the codebase where structs derives JSTraceable, don't contain any field that needs to be traced by mozjs and are filled with #[no_trace], could we avoid it?
There was a problem hiding this comment.
As I said many times I hate what JSTraceable is and I do plan to work on JSManaged which should be more fine grained. As for why we do this is simply because this is currently the only to ensure all fields that needed are traced (w.r.t adding new fields in the future - future proofing). If we make droppable field #[no_trace] and if one adds JSManaged (read type with actual tracer that is not nop) field into droppable struct it would not be traced. Now the proper solution is to somehow bubble the JSManaged property (if type contains JSMnaged type then itself must be jsmanaged). Why this does not work with JSTraceable? Because non JSManaged types are also traceable with nop tracers (like rust primitive types). And that is the main rational behind JSManaged trait/derive I am planning (apart from forbidding drops).
jdm
left a comment
There was a problem hiding this comment.
We just need
to be cleaned up and this can merge.Signed-off-by: sagudev <[email protected]>
In first commit we remove drop from DataView (JSTraceable should have no drop). This is safe because on GC SM will take care for calling freeFunc of externalArrayBuffer. For manual destruction (detach array buffer) we simply pass
&mut JSContext. In second commit we add droppable struct.Testing: Should be covered by WebGPU CTS.
Fixes: #45504
Fixes: #44640