Commit Graph

1542 Commits

Author SHA1 Message Date
Jim Blandy
8981058ad1 [core] In LifetimeTrackers triage code, use more specific names.
Rename `LifetimeTracker::triage_resources`'s `resources_map` argument
to `suspected_resources`, since this always points to a field of
`LifetimeTracker::suspected_resources`.

In the various `triage_suspected_foo` functions, name the map
`suspected_foos`.
2024-05-14 04:38:43 -04:00
Jim Blandy
8d73e5a9cd [core] Refactor LifetimeTracker::triage_resources.
Check whether the resource is abandoned first, since none of the rest
of the work is necessary otherwise.

Rename `non_referenced_resources` to `last_resources`. This function
copes with various senses in which the resource might be referenced or
not. Instead, `last_resources` is the name of the `ActiveSubmission`
member this may point to, which is more specific.

Move the use of `last_resources` immediately after its production.
2024-05-14 04:38:43 -04:00
Jim Blandy
64777d4fd8 [core] Doc fixes for lifetime management, minor typos.
- Document `LifetimeTracker::triage_resources`.

- Fix various typos and bad grammar.
2024-05-14 04:38:43 -04:00
Erich Gubler
ca91744955 chore: apply unused_qualifications lint via cargo +1.78.0 fix && cargo fmt 2024-05-13 10:10:54 -04:00
Andreas Reich
452cf24fa1
Remove unnecessary Cargo.toml dependencies via cargo machete (#5692) 2024-05-12 19:05:00 -04:00
bjorn3
fa48562229
Avoid introducing spurious features for optional dependencies (#5691)
* Avoid introducing spurious features for optional dependencies

If a feature depends on an optional dependency without using the dep:
prefix, a feature with the same name as the optional dependency is
introduced. This feature almost certainly won't have any effect when
enabled other than increasing compile times and polutes the feature list
shown by cargo add. Consistently use dep: for all optional dependencies
to avoid this problem.

* Add changelog entry
2024-05-12 08:45:35 +02:00
Xiaopeng Li
d5d683d3c4
Clean up weak references to texture views and bind groups (#5595)
* Clean up weak references to texture views

* add change to CHANGELOG.md

* drop texture view before clean up

* cleanup weak ref to bind groups

* update changelog

* Trim weak backlinks in their holders' triage functions.

---------

Co-authored-by: Jim Blandy <jimb@red-bean.com>
2024-05-06 12:53:03 +02:00
Jim Blandy
0d70a7361d [core] Properly recycle Device::temp_suspected.
Change `Device::untrack` to properly reuse the `ResourceMap` allocated
for prior calls. The prior code tries to do this but always leaves
`Device::temp_suspected` set to a new empty `ResourceMap`, leaving the
previous value to be dropped by `ResourceMap::extend`.

Change `ResourceMap::extend` to take `other` by reference, rather than
taking it by value and dropping it.
2024-05-04 00:28:46 -04:00
Jim Blandy
5f464688e6 [core] Don't check for uniquely referenced resources at submission.
Remove unreachable code from `Global::queue_submit` that checks
whether the resources used by the command buffer have a reference
count of one, and adds them to `Device::temp_suspected` if so.

When `queue_submit` is called, all the `Arc`s processed by this code
have a reference count of at least three, even when the user has
dropped the resource:

- `Device::trackers` holds strong references to all the device's
  resources.

- `CommandBufferMutable::trackers` holds strong references to all
  resources used by the command buffer.

- The `used_resources` methods of the various members of
  `CommandBufferMutable::trackers` all return iterators of owned
  `Arc`s.

Fortunately, since the `Global::device_drop_foo` methods all add the
`foo` being dropped to `Device::suspected_resources`, and
`LifetimeTracker::triage_suspected` does an adequate job of accounting
for the uninteresting `Arc`s and leaves the resources there until
they're actually dead, things do get cleaned up without the checks in
`Global::queue_submit`.

This allows `Device::temp_suspected` to be private to
`device::resource`, with a sole remaining use in `Device::untrack`.

Fixes #5647.
2024-05-03 17:00:07 -04:00
Jim Blandy
4a07ab2b57 [core] Ensure all lock guards are properly nested.
The lock analyzers in the `wgpu_core::lock` module can be a bit
simpler if they can assume that locks are acquired and released in a
stack-like order: that a guard is only dropped when it is the most
recently acquired lock guard still held. So:

- Change `Device::maintain` to take a `RwLockReadGuard` for the device's
  hal fence, rather than just a reference to it.

- Adjust the order in which guards are dropped in `Device::maintain`
  and `Queue::submit`.

Fixes #5610.
2024-05-03 13:06:00 -04:00
Jim Blandy
7c842a3b48 [core] Implement downgrade for the lock module's RwLocks.
Implement `RwLockWriteGuard::downgrade` for `lock::vanilla` and
`lock::ranked`, to downgrade a write lock to a read lock.
2024-05-03 13:06:00 -04:00
Jim Blandy
651214ef74 [core] Refactor lock::ranked to use LockStateGuard.
Rather than implementing `Drop` for all three lock guard types to
restore the lock analysis' per-thread state, let lock guards own
values of a new type, `LockStateGuard`, with the appropriate `Drop`
implementation. This is cleaner and shorter, and helps us implement
`RwLock::downgrade` in a later commit.
2024-05-03 13:06:00 -04:00
Samson
5fa537bfd9
Cast ptr to Device not Surface (#5640) 2024-04-30 11:39:56 -04:00
Jim Blandy
b765eeb474
[core] Removed outdated safety comments from no-longer-unsafe fns. (#5633) 2024-04-29 13:34:06 -04:00
stefnotch
f874ed061c
Add get_compilation_info (#5410)
* Add get_compilation_info API

* Rename glsl ParseError to ParseErrors

* Document ParseError label order

* Update line_position to count UTF-8 bytes
2024-04-29 11:35:36 +02:00
Connor Fitzgerald
4521502da6
Release v0.20.0 (#5619) 2024-04-28 18:06:35 -04:00
vero
739905e73c
Extract a naga pub create_validator function for use in Bevy (#5606) 2024-04-26 10:19:45 +02:00
Jim Blandy
d4f30638b7 [core] Fix caller location tracking in lock::ranked.
Properly track the location of callers of `Mutex::lock`,
`RwLock::read`, and `RwLock::write`, for use in panic messages.
2024-04-25 12:46:05 -07:00
Samson
5735f85720
CreateBindGroup validation error on device mismatch (#5596)
* Fix cts_runner command invocation in readme

* Remove assertDeviceMatch from deno_webgpu in createBindGroup

This should be done as verification in wgpu-core.

* Add device mismatched check to create_buffer_binding

* Extract common logic to create_sampler_binding

* Move common logic to create_texture_binding and add device mismatch check
2024-04-25 12:17:00 +02:00
Jim Blandy
a364e566cd [core] Use lock::RwLock in RenderBundleScope.
This requires bumping the `LockRankSet` bitset from `u32` to `u64`.
2024-04-25 01:28:21 -04:00
Jim Blandy
927b7e96fe [core] Use lock::RwLock in Registry. 2024-04-25 01:28:21 -04:00
Jim Blandy
36e0a135f5 [core] Use lock::RwLock in Buffer and Texture. 2024-04-25 01:28:21 -04:00
Jim Blandy
d089b86c59 [core] Include SnatchLock in lock rankings. 2024-04-25 01:28:21 -04:00
Jim Blandy
43f2315753 [core] Add checked RwLock. 2024-04-25 01:28:21 -04:00
Jim Blandy
7d9a8beff3 [core] Abstract out checking code in lock::ranked.
Introduce two new private functions, `acquire` and `release`, to the
`lock::ranked` module, to perform validation for acquiring and
releasing locks. Change `Mutex::lock` and `MutexGuard::drop` to use
those functions, rather than writing out their contents.
2024-04-25 01:28:21 -04:00
Jim Blandy
d719373989 [core] Remove unnecessary #[inline] attributes in lock module. 2024-04-25 01:28:21 -04:00
Jim Blandy
3c21a98697 [core] Remove semicolon from lock rank macro syntax.
In `define_lock_ranks!` macro invocations, don't require a semicolon
after each rank's "followed by" list.
2024-04-25 01:28:21 -04:00
Andreas Reich
edf1a86148
Separate out ComputeCommand id->arc resolve (a step towards no lifetimes on wgpu::ComputePass) (#5432)
* move out compute command to separate module

* introduce ArcComputeCommand

* stateless tracker now returns reference to arc upon insertion

* add insert_merge_single to buffer tracker

* compute pass execution now works internally with an ArcComputeCommand

* compute pass execution now translates Command to ArcCommand ahead of time

* don't clone commands in compute pass execution

* remove doc hiding

* use option insert

* clippy fix

* fix private doc issue

* remove unnecessary copied over doc hide
2024-04-23 07:01:29 +00:00
Jim Blandy
b3c5a6fb84 [core] Enforce a deadlock-free locking order for Mutexes.
If `debug_assertions` or the `"validate-locks"` feature are enabled,
change `wgpu-core` to use a wrapper around `parking_lot::Mutex` that
checks for potential deadlocks.

At the moment, `wgpu-core` does contain deadlocks, so the ranking in
the `lock::rank` module is incomplete, in the interests of keeping it
acyclic. #5572 tracks the work needed to complete the ranking.
2024-04-22 18:49:03 -07:00
Jim Blandy
4f3d9a2af5 [core] Also trace snatch lock write guard acquisitions.
In debug builds, check for attempts to acquire snatch lock read guards
while holding write guards, not just attempts to acquire a second read
guard.
2024-04-21 21:09:48 -07:00
Daniel McNab
54d22a89d3
Fix the ordering of id freeing and deleting (#5554) 2024-04-19 12:59:09 -04:00
Jim Blandy
54740d5982 [core] Make cargo doc --document-private-items work again.
Add a CI job to check it, for the future.
2024-04-18 18:36:47 -07:00
Jim Blandy
543a746023
[core] Document deferred retention strategy for ActiveSubmission. (#5561)
* [core] Document deferred retention strategy for `ActiveSubmission`.

* Update wgpu-core/src/device/life.rs

---------

Co-authored-by: Connor Fitzgerald <connorwadefitzgerald@gmail.com>
2024-04-19 00:08:27 +00:00
Connor Fitzgerald
152fd0930a
Fix Buffer Mapping Deadlock (#5518) 2024-04-17 20:41:51 -04:00
Andreas Reich
ad6774f7bb
Remove exposed C symbols from renderpass/computepass recording (#5409)
Co-authored-by: Connor Fitzgerald <connorwadefitzgerald@gmail.com>
2024-04-17 20:48:45 +00:00
Daniel McNab
965b00c06b
Allow configuring whether workgroup memory is zero initialised (#5508) 2024-04-17 15:50:31 -04:00
Andreas Reich
cbace631ec
Fix surfaces only compatible with first enabled backend (#5535) 2024-04-17 15:32:04 -04:00
Alexander Meißner
ea77d5674d
Subgroup Operations (#5301)
Co-authored-by: Jacob Hughes <j@distanthills.org>
Co-authored-by: Connor Fitzgerald <connorwadefitzgerald@gmail.com>
Co-authored-by: atlas dostal <rodol@rivalrebels.com>
2024-04-17 15:25:52 -04:00
Jim Blandy
2b0e3ed01c [core] Don't derive Default for ResourceMaps.
The derivation is only effective if the generic type parameter `A`
also implements `Default`, which `HalApi` implementations generally
don't, so this derivation never actually took place. (This is why
`ResourceMaps::new` is written out the way it is.)
2024-04-16 15:04:25 +02:00
teoxoy
895879b8c6 [wgpu-core] validate that all resources passed to encoder commands belong to the same device as the encoder 2024-04-16 15:02:41 +02:00
Jim Blandy
a61c872269 [core] Rename com_alloc to command_allocator in Device::new. 2024-04-15 16:37:08 -04:00
Jim Blandy
bab6f53e86 [core] Use internal locking in CommandAllocator.
Move the `Mutex` in `Device::command_allocator` inside the
`CommandAllocator` type itself, allowing it to be passed by shared
reference instead of mutable reference.

Passing `CommandAllocator` to functions like
`PendingWrites::post_submit` by mutable reference requires the caller
to acquire and hold the mutex for the entire time the callee runs, but
`CommandAllocator` is just a recycling pool, with very simple
invariants; there's no reason to hold the lock for a long time.
2024-04-15 16:37:08 -04:00
Jim Blandy
b9781ee6e2 [core] Move CommandAllocator into its own module.
No intended change in behavior.
2024-04-15 16:37:08 -04:00
Jim Blandy
c9212c6d46 [core] Document command encoding and command buffers.
Flesh out the documentation for `wgpu_core`'s `CommandBuffer`,
`CommandEncoder`, and associated types.

Allow doc links to private items. `wgpu-core` isn't entirely
user-facing, so it's useful to document internal items.
2024-04-14 20:53:15 -07:00
dependabot[bot]
6756601089
build(deps): bump crate-ci/typos from 1.19.0 to 1.20.4 (#5506)
* build(deps): bump crate-ci/typos from 1.19.0 to 1.20.4

Bumps [crate-ci/typos](https://github.com/crate-ci/typos) from 1.19.0 to 1.20.4.
- [Release notes](https://github.com/crate-ci/typos/releases)
- [Changelog](https://github.com/crate-ci/typos/blob/master/CHANGELOG.md)
- [Commits](https://github.com/crate-ci/typos/compare/v1.19.0...v1.20.4)

---
updated-dependencies:
- dependency-name: crate-ci/typos
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

* update to typoes 1.20.8 since it has a few important fixes

* typo fixes & exceptions

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Andreas Reich <r_andreas2@web.de>
2024-04-14 09:28:36 +00:00
Jim Blandy
0b7f91c4a9
[core] Make wgpu_core::command::BakedCommands pub(crate), not pub. (#5526) 2024-04-14 09:40:50 +02:00
Jim Blandy
b7519bb73b
[core] Make Hub members and related types pub(crate), not pub. (#5502) 2024-04-10 19:52:16 -04:00
Jim Blandy
8289711b65
[core] Provide an explicit type for some CommandBuffer pointers. (#5512) 2024-04-10 19:51:56 -04:00
Jim Blandy
f8deb0317f
[core] Use expect instead of "if let else panic". (#5513)
Use `Option::expect` to check the result from `Arc::into_inner`,
rather than `if let Some ... else panic!`.
2024-04-10 03:53:10 -04:00
Andreas Reich
82dead09e4
Bump wgpu-core/hal/types & naga versions to match latest released patch versions (#5404) 2024-04-09 00:33:43 -04:00