Commit Graph

1550 Commits

Author SHA1 Message Date
Elabajaba
c7a16b36b1 change create_validator to a free function so it's usable 2024-05-20 11:02:23 +02:00
Erich Gubler
447e3eee8d fix: ensure render pipelines have at least 1 target 2024-05-17 17:45:03 -04:00
Daniel McNab
4902e470ce
Pipeline cache API and implementation for Vulkan (#5319)
Co-authored-by: Connor Fitzgerald <connorwadefitzgerald@gmail.com>
2024-05-16 13:52:56 +00:00
Connor Fitzgerald
eeb1a9d7b7
Add Benchmarks (#5694) 2024-05-16 09:05:41 -04:00
Teodor Tanasoaia
3a798859cd remove old depth and/or stencil texture copy validation
This was previously added in #2230 but I don't think it was necessary. #901 already implemented the buffer <-> texture validation for those formats. It's also not a requirement in the spec.
2024-05-15 17:24:37 +02:00
Andreas Reich
77a83fb0dd
Remove lifetime constraints from wgpu::ComputePass methods (#5570)
* basic test setup

* remove lifetime and drop resources on test - test fails now just as expected

* compute pass recording is now hub dependent (needs gfx_select)

* compute pass recording now bumps reference count of uses resources directly on recording

TODO:
* bind groups don't work because the Binder gets an id only
* wgpu level error handling is missing

* simplify compute pass state flush, compute pass execution no longer needs to lock bind_group storage

* wgpu sided error handling

* make ComputePass hal dependent, removing command cast hack. Introduce DynComputePass on wgpu side

* remove stray repr(C)

* changelog entry

* fix deno issues -> move DynComputePass into wgc

* split out resources setup from test
2024-05-14 20:05:17 +00:00
Kevin Reid
9b70254437
Reduce string allocations related to labels and logging. (#5690) 2024-05-14 04:39:28 -04:00
Jim Blandy
ffd96a0a53 [core] Use a for loop in LifetimeTracker triage code.
A `for` loop is less noisy than a `drain`, which requires:

- a `mut` qualifier for a variable whose modified value we never
  consult

- a method name appearing mid-line instead of a control structure name
  at the front of the line

- a range which is always `..`, establishing no restriction at all

- a closure instead of a block

Structured control flow syntax has a fine pedigree, originating in,
among other places, Dijkstrsa's efforts at designing languages in a
way that made it easier to formally verify programs written in
them (see "A Discipline Of Programming"). There is nothing "more
mathematical" about a method call that takes a closure than a `for`
loop. Since `for_each` is useless unless the closure has side effects,
there's nothing "more functional" about `for_each` here, either.
Obsessive use of `for_each` suggests that the author loves Haskell
without understanding it.
2024-05-14 04:38:43 -04:00
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