Commit Graph
40 Commits
Author SHA1 Message Date
Kevin Reid 3e4d24ea98 Remove dead code from naga::back. (#7350)
The `#![allow(dead_code)]` on the module was hiding dead code in the
child modules. I changed it to be conditional on actually having no
backends enabled. (Note that with #7349, there would actually be no
warnings and we could remove the `allow(dead_code)` entirely, but I
expect that state of affairs won’t necessarily persist.)
2025-03-17 08:23:51 -04:00
Kevin Reid 03ab3a27d8 Make buffer mapping example runnable and remove obsolete Arc. 2025-03-14 20:59:28 -04:00
Kevin Reid fcac8a9b28 Add Device::noop().
This is a useful shortcut for tests and example code, allowing it to
create a noop device without needing to deal with nonexistent
fallibility and asynchrony.
2025-03-14 20:59:28 -04:00
Kevin Reid 029bdb107a docs: Add links and examples for VertexAttribute and friends.
* Added “upward” links from `VertexAttribute` and `VertexBufferLayout`
  to the places they are used.
* Documented the exact expected inputs of `vertex_attr_array!` and hid
  the internal implementation.
* Added doc-test examples for:
    * `VertexBufferLayout`, demonstrating how to construct a
      `VertexBufferLayout` that corresponds to a `struct`.
    * `vertex_attr_array!`, demonstrating exactly what the output of the
      macro is.
2025-03-14 18:31:30 -04:00
Kevin Reid fbe005f11a Make request_adapter() report which backends were tried.
This will help users determine whether the problem is:

* a backend is not statically enabled
* a backend is not dynamically enabled
* no drivers or physical adapters are present for that backend
  (further distinction would be useful here)
* no adapters met the required criteria

There are deficiencies in the reporting of WebGPU vs. WebGL support.
Those would best be fixed by also fixing the mutual exclusion of those
backends.
2025-03-14 11:45:49 +01:00
Kevin Reid a369bfa8d1 Revise documentation for write_buffer(), write_buffer_with(), and write_texture().
* Add `# Performance considerations` heading, to separate the facts
  about how to use the method from the advice about how best to use the
  method.

  Back when I was learning `wgpu`, I thought that “does *not* submit the
  transfer to the GPU immediately” was a claim about *ordering* relevant
  to correctness, not just performance. This reorganization and
  rewording should help future readers build an accurate model quicker.

* Clarify when it is best to use `write_buffer_with()` — in particular,
  if you just copy from other memory, then you aren't making any
  improvement over `write_buffer()`, and the advantage comes from being
  able to assemble your data in-place.

* Flesh out the first `queue.submit([])` example code block,
  and trim back the second one.

* Mention what techniques you might use for writing to a texture other
  other than `write_texture()`.
2025-03-14 11:33:39 +01:00
Kevin Reid 326ad03ce1 Move trace_dir/trace_path to a custom enum inside DeviceDescriptor.
This allows `wgpu` to not unconditionally depend on `std::path::Path`.
It’s also, in my opinion, more user-friendly, because the feature which
most users will not use (and is not currently functional) is now a
defaultable struct field instead of a required parameter.

The disadvantage is that `wgpu-types` now has to know about tracing.
2025-03-10 22:17:06 -04:00
Kevin Reid 7319512778 Additional documentation for buffer mapping, types, and constants. (#7283)
* Additional documentation for buffer mapping, types, and constants.

* Clarify `Snorm` texture format conversion.

* Fix typo.
2025-03-06 19:08:34 +00:00
Kevin Reid 16d41cfaf3 Make std usage optional for wgpu-core. (#7279)
* Make `wgpu_core::snatch::LockTrace` fully instead of partially conditional.

Now, when `cfg(not(debug_assertions))`, there is no `SNATCH_LOCK_TRACE`
thread local, and `LockTrace` has no data fields.

* Make `std` usage optional for `wgpu-core`.

Adds a `std` feature, enabled by default, to `wgpu-core`. When that
feature is disabled, the following functionality is not available:

* `Send + Sync` for resources.
* `trace` feature.
* `observe_locks` feature.
* Snatch lock recursive locking assertion.
2025-03-06 14:07:38 -05:00
Kevin Reid 289d0e5c5a Allow the "gles" backend to (theoretically) compile on no_std targets.
This entirely consists of conditionally replacing `Mutex` with `RefCell`,
then making sure that this doesn’t accidentally happen if we are also
exposing `Send + Sync`.
2025-03-05 11:48:42 +01:00
Kevin Reid 67f1554e77 Fix build of wgpu-hal on macOS with features = ["gles"]. (#7266)
Without this change, `cargo build -p wgpu-hal --features=gles` will fail
if `target_os = "macos"`.
2025-03-05 00:12:43 -05:00
Kevin Reid 177205b3be Make lack of spirv-as non-fatal for testing. 2025-02-26 19:19:46 -05:00
Kevin Reid 3447b3e7b6 Polish documentation of PresentMode.
* Link to where it is used and how to check support.
* Link from `Auto*` to the variants they refer to.
* Organize mode information into lists.
* Document which value is the default value.
* Various wording changes.

I mostly did not touch the descriptions of the individual modes.
I think that they could use some explanation of jargon (what is a
“presentation engine”, really?) but I am not the person to write that.
2025-02-24 10:15:40 +01:00
Kevin Reid 12ec5fd16f wgpu: Make macros usable from no_std and use strictly $crate paths. 2025-02-21 08:47:16 +01:00
Kevin Reid b3b54b6941 wgpu: Adjust imports to allow no_std.
Remaining uses of `std`:
* `trace_path` / `trace_dir`
* `std::error::Error` (waiting for Rust 1.81)
* `std::ffi::c_void`
* Various uses in `util`
2025-02-21 08:47:16 +01:00
Kevin Reid 7bcbfe0712 wgpu-core: Adjust imports to allow no_std.
Dependencies on `std` that still exist:
* Locks
* `std::error::Error` (waiting for Rust 1.81)
* `std::os::raw::c_char` for FFI
* `thread_local` and `Backtrace` in `snatch`
2025-02-21 08:47:16 +01:00
Kevin Reid bea4fb9e2d wgpu-hal: Adjust imports to eventually allow no_std.
We need `core::error::Error` (Rust 1.81) to make it a reality.
2025-02-21 08:47:16 +01:00
Kevin Reid 9c0fa2975f Use BufferSlice in StagingBelt::allocate(). (#7179)
* Use `BufferSlice` in `StagingBelt::allocate()`.

* Make `StagingBelt::allocate()` return just the slice.
2025-02-20 10:05:30 +01:00
Kevin Reid 9da04c2b0b Add getters and From implementations to BufferSlice. (#7148)
* Add getters to `BufferSlice` to obtain its parts.

* Add conversions from `BufferSlice` to `BufferBinding` and `BindingResource`.
2025-02-17 11:06:13 +01:00
Kevin Reid 2f50426b35 Remove unnecessary chunk size field from StagingBelt. 2025-02-13 12:46:29 -05:00
Kevin Reid ec6c7225da Remove unnecessary Arc from StagingBelt.
`Buffer` now implements `Clone` on its own.
2025-02-13 12:46:29 -05:00
Kevin Reid fd896695d5 Expose StagingBelt allocation directly.
This allows using `StagingBelt` for copying to textures or any other
operation where copying to an existing buffer is not the desired outcome.

One unfortunate feature of the API is that `allocate()` returns the entire
buffer and an offset, so applications could accidentally touch parts of
the belt buffer outside the intended allocation. It might make more sense
to return `wgpu::BufferSlice`, but that struct cannot be used in
operations like `copy_buffer_to_texture` and does not have getters, so it
is not currently suitable for that purpose.

I also moved `Exclusive` into a module so that its unsafe-to-access field
is properly private, and made various improvements to the `StagingBelt`
documentation, such as acknowledging that `write_buffer_with()` exists.
2025-02-13 12:46:29 -05:00
Kevin Reid c4b25b8794 Duplicate BufferSlice methods onto Buffer and vice versa. (#7123)
This allows users to skip creation of `BufferSlice` if they have no use
for it, and brings `wgpu` closer to the WebGPU API without removing any
Rust convenience. New functions:

* `BufferSlice::slice()`
* `Buffer::map_async()`
* `Buffer::get_mapped_range()`
* `Buffer::get_mapped_range_mut()`
* `Buffer::get_mapped_range()`
2025-02-13 14:40:09 +01:00
Kevin Reid 0f111cb27c Add a test for the noop backend. 2025-02-12 22:31:47 -05:00
Kevin Reid 118a985ccd Allow creating Noop backend through the normal mechanisms. 2025-02-12 22:31:47 -05:00
Kevin Reid 7293a13a97 Extend the capabilities of the Noop backend.
This will allow using it in tests of wgpu resource management code
that does not actually require a backend.

* `enumerate_adapters()` returns an adapter instead of failing.
* `open()` returns a device instead of failing.
* `create_buffer()` allocates actual memory.
* `map_buffer()` actually provides access to that memory.
* `clear_buffer()` actually clears the buffer.
* `copy_buffer_to_buffer()` actually copies data.
* Fences actually work (trivially, because all operations are
  synchronous).

Future work could include implementing texture copies,
timestamp queries, and the clearing part of render passes.
2025-02-12 22:31:47 -05:00
Kevin Reid 0143b4aaa0 Rename Empty backend to Noop.
This is in preparation for making it a more substantial test stub,
able to execute nontrivial code, and usable from the safe `wgpu` API.
2025-02-12 22:31:47 -05:00
Kevin Reid d59dce5eea More documentation for TextureView. (#7069)
Explain how to make one and what its properties are.
2025-02-06 16:42:10 -05:00
Kevin Reid 98e080410f Fix compatibility issues in hello_window example. (#7009) 2025-01-27 12:14:20 -05:00
Kevin Reid 321ee42771 Don’t copy buffer data back to JS if unnecessary, in WebGPU backend. (#7007) 2025-01-27 12:14:09 -05:00
Kevin Reid 56d418f121 Partial revert "disable rustdoc in CI (#5839)"
This reverts most of the changes in a2fcd72606,
but the "document private features" step is still disabled since it
operates only on wgpu-core which is exactly the problem.
2024-07-19 11:37:00 -04:00
Kevin Reid b5934e89f7 Disable wgpu-core documentation as a workaround for #4905.
This enables `cargo doc` to succeed in a reasonable amount of time,
as long as the reader isn't looking for documentation for `wgpu-core`
itself.
2024-07-19 11:37:00 -04:00
Kevin Reid e7a528b62b Document WebGPU spec rule that an Adapter should be used only once. (#5764) 2024-06-01 01:25:42 +00:00
Kevin Reid 9b70254437 Reduce string allocations related to labels and logging. (#5690) 2024-05-14 04:39:28 -04:00
Kevin Reid e0341c52cf Document nonzero surface size requirement. (#4609) 2023-10-29 23:22:38 -04:00
Kevin Reid 7c575a0b40 Add details to RequestDeviceError. (#4145) 2023-09-16 00:16:49 -04:00
Kevin ReidandConnor Fitzgerald 332cd0325d Add details to InstanceError and CreateSurfaceError. (#4066)
Co-authored-by: Connor Fitzgerald <connorwadefitzgerald@gmail.com>
2023-09-01 01:48:31 -04:00
Kevin Reid a2c929427b webgl: Comment why it's okay to overwrite webgl2_context. (#4064) 2023-08-16 17:11:30 -04:00
Kevin Reid 2bdb3196f9 Add an overview of RenderPass and how render state works. (#4055)
* Explain the general relationship of `set` and `draw` methods.
* Explain render state changes and that you can have lots of them.
* Specify default values of render state.
2023-08-14 22:24:27 +02:00
Kevin Reid fab11dcc76 impl Debug for StagingBelt (#2572) 2022-04-02 16:06:51 +00:00