-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add DestroyedResourceError
as a possible result from Fallible::get
#8129
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
base: trunk
Are you sure you want to change the base?
Conversation
Will be used in a subsequent change. Since the `InvalidResource` and `DestroyedResoure` variants of various error enums are part of the external API, I chose to keep them and provide a special `From` implementation for `BadResourceError`s, rather than nest `BadResourceError` within the error enums.
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.
I have 2 high-level concerns with this approach:
- operations on destroyed objects should still succeed (eg. creating views on a destroyed texture, bind groups with destroyed buffers, ...) but moving this state in the registry makes that difficult.
- the following changes in the branch make wgpu-core more dependent on the registries but we plan to remove them (#5121)
We can say these changes are ok and let the Firefox bindings deal with the consequences. Once we move the registries in our bindings wgpu-core will lose the ability to destroy resources early but IIRC @cwfitzgerald was not happy with the .destroy()
complexity anyway; I don't think anyone was by it was a necessity at the time.
I think keeping the .destroy()
complexity in our bindings makes sense but the bindings need more changes to cope with the fact that creating and using destroyed resources should be valid (unless we are submitting). cc @jimblandy
Actually, I don't think we can move the |
There are definitely issues with maintaining the necessary information to implement the WebGPU-specified behavior for destroyed resources. I had been thinking that the changes in this PR and the associated branch are moving in the right direction, because we mostly don't make any attempt to do the right thing for destroyed resources now. For example, the But as you've pointed out, disconnecting the object reference in the hub from the metadata seems wrong. Even if it doesn't cause us to regress from our current state, it gives up information that will be useful or necessary to get spec-correct behavior on errors in the future. You did point me to that issue about getting rid of registries and I thought about it, but I may have drawn some bad conclusions. I was thinking that wgpu-using and wgpu-core-using clients might have different approaches to resource management e.g. wgpu clients do explicit memory management with One possible revision would be to keep metadata in the hub for deleted resources. I started mocking this up but it's not complete yet. Probably it would still be an |
I thought the status quo was better but you are right, right now the issue is that most objects derived from possibly-destroyed objects can't even be created since we try to create hal resources and will fail.
Some references: https://github.com/gfx-rs/wgpu-native/blob/a2f5109b0da3c87d356a6a876f5b203c6a68924a/src/lib.rs#L1826-L1829 The ownership docs for the C headers mention: "Objects in webgpu.h are refcounted via the AddRef and Release functions.".
I'm not sure I understand this part, WebGPU objects in Firefox only hold the ID of an equivalent wgpu object, we don't need to model JS references.
I think it's important to use the hub/registries only for ID ->
This seems similar to what I also had in mind (outlined above), just with the enum moved inside the resource to make it compatible with the needs of Example with struct Texture {
label: String,
width: u32,
height: u32,
state: ResourceState<TextureState>,
}
struct TextureState {
raw: hal::Texture,
...
}
enum ResourceState<T> {
Valid(T),
Invalid,
Destroyed,
} With the |
One other option I'll put out there: we could define
and use this for resource references in the hub and in bind groups / texture views. The reference would be strong until the resource is destroyed, then downgraded to weak. It doesn't fundamentally change what this PR looks like, and it still has the problem that the weak references allow the resource metadata to go away when we may still need it to generate proper errors. But it looks more similar to the current state of things where the hub holds But, that doesn't change the characteristics of the solution very much, it just changes what it looks like. There is a fundamental question here of how important we think it is to provide a strong assurance that if a resource reference in the tracker is still alive, then the resource itself must still be alive. (Which is not the case right now, since I did experiment with the following checked reference (changing trackers to hold
Having this as a double-check would make me more comfortable keeping the behavior where I have also started working on the changes to encode commands on finish. |
This will be used in subsequent changes to mark buffers, textures, texture views, and bind groups as destroyed in the hub, when they are destroyed (or in the case of texture views and bind groups, when a resource they reference is destroyed).
Since the
InvalidResource
andDestroyedResoure
variants of various error enums are part of the external API, I chose to keep them and provide a specialFrom
implementation forBadResourceError
s, rather than nestBadResourceError
within the error enums.This is part of a series of PRs that will address #7854. The full set of changes can be found here, and some additional changes after that to remove code for the previous way of managing resource destruction here.
Testing
No tests for this change by itself, tests will be in an upcoming PR.
Squash or Rebase? Squash
Checklist
cargo fmt
.taplo format
.cargo clippy --tests
. If applicable, add:--target wasm32-unknown-unknown
cargo xtask test
to run tests.CHANGELOG.md
entry.