Skip to content
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

Remove the Destroyed state from Storage #4970

Merged
merged 3 commits into from
Jan 11, 2024
Merged

Conversation

nical
Copy link
Contributor

@nical nical commented Jan 3, 2024

Connections

Depends on #4896

Description

Removes the logic to express destroyed resources in the registry, since we have moved to handling it in the resources themselves.

Checklist

  • Run cargo fmt.
  • Run cargo clippy.
  • Run cargo xtask test to run tests.

@nical nical requested a review from a team as a code owner January 3, 2024 13:55
@nical nical force-pushed the mark-destroyed branch 3 times, most recently from 0791cd6 to 3c1c78e Compare January 5, 2024 10:58
Copy link
Member

@teoxoy teoxoy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We were previously marking the resources as destroyed immediately after the destroy fn was called and subsequent attempts at getting the resources would fail.

We are now manually checking if the hal resource was destroyed which won't be the case until later. It also looks like we don't check this after every {textures,buffers}.get(id) anymore.

It seemed that Element::Destroyed and Element::Error were both equivalent with the invalid flag in the spec and we haven't yet fully moved invalidity inside objects.

@nical
Copy link
Contributor Author

nical commented Jan 5, 2024

There are a lot of places where the check is now happening by getting an Option out of resource.raw(&snatch_guard) which is None if the resource is destroyed (basically anywhere we actually use the thing). So we only need to manually check when usage of the resource is deferred to some time after the validation is supposed to happen.

I personally preferred the way the registry was providing this check transparently, but since our plan is to get rid of the registry altogether, doing the checks manually is the the way forward.
If you see places where the check is missing, let me know.

Moving the Element::Error state to the object is going to be a rather tedious task but we'll have to do that too at some point.

@teoxoy
Copy link
Member

teoxoy commented Jan 5, 2024

I see. I think that removing Element::Destroyed while we still don't have proper object invalidation makes things harder to reason about for those cases that we have to manually check if the resource hasn't been destroyed earlier than accessing said resource.

I'm not very well-versed in this area of the code, I'll let someone else also chime in.

@nical
Copy link
Contributor Author

nical commented Jan 5, 2024

What do you envision for proper object validation? Is it some missing if resource.is_destroyed(&snatch_guard) { branches or are you thinking of some system for checking it in a more automatic way?

@teoxoy
Copy link
Member

teoxoy commented Jan 5, 2024

I think we'll need a system to do it in a more generic way since almost all API calls check for validity (and almost all objects can be invalid).

https://gpuweb.github.io/gpuweb/#abstract-opdef-valid-to-use-with

Element::Destroyed & Element::Error seemed to be equivalent to object validity but we now (with the plan of moving the storages out) need to move this state in the objects themselves (as Arc<Option<T>>?).

@nical
Copy link
Contributor Author

nical commented Jan 5, 2024

Element::Destroyed & Element::Error seemed to be equivalent to object validity but we now (with the plan of moving the storages out) need to move this state in the objects themselves (as Arc<Option>?).

Yep. Probably something like that, or something along the lines of Option<Arc<T>> to encourage checking early and keeping the arc which we don't need to check again in later stages. The initial error state is easier because it is set once at creation.
Texture and buffer destroyed state is more complicated because we have to check it everywhere it is used in addition to where standard validation happens, because the resource may be marked destroyed at any time.

@cwfitzgerald cwfitzgerald requested a review from a team January 10, 2024 02:44
@nical
Copy link
Contributor Author

nical commented Jan 10, 2024

Ci is stuck because github had a cold the other day but this is ready to land.

@teoxoy
Copy link
Member

teoxoy commented Jan 10, 2024

It probably needs a rebase since it's waiting for "Test Mac aarch64" which was recently added.

Copy link
Member

@cwfitzgerald cwfitzgerald left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor comment - take or leave, g2g after.

wgpu-core/src/device/global.rs Show resolved Hide resolved
It used to be how we handled destroying buffers and textures but we moved to different approach.
This used to be checked automatically when getting the resource from the registry, but has to be done manually now that we track we track the destroyed state in the resources.
@nical nical merged commit bc65d84 into gfx-rs:trunk Jan 11, 2024
27 checks passed
@nical nical deleted the mark-destroyed branch January 11, 2024 11:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants