Commit Graph

1079 Commits

Author SHA1 Message Date
Connor Fitzgerald
84633a8b12
Force binding sizes to be multiples of 16 on webgl (#2808) 2022-06-27 02:39:51 +00:00
i509VCB
f041991d0c allow creating wgpu::Instance from wgpu_core::Instance 2022-06-26 15:32:34 -07:00
Connor Fitzgerald
533fc13afe
Properly Barrier Compute Indirect Buffers (#2810) 2022-06-26 21:03:56 +00:00
Connor Fitzgerald
de5fe90f20
Restrict WriteTimestamp Inside Passes (#2802)
* Define feature flags in terms of the previous

* Add WRITE_TIMESTAMP_INSIDE_PASSES feature
2022-06-25 01:23:13 -04:00
victorvde
7375acb230
get_supported_formats: sort like the old get_preferred_format and simplify return type (#2786)
* get_supported_formats: sort srgb first like the old get_preferred_format

* get_supported_formats: simplify return type
2022-06-22 21:04:18 +00:00
Nicolas Silva
5dcd19c167
Add a vulkan workaround for large buffers. (#2796)
* Add Limit::max_buffer_size.

* Prevent very large buffer with some drivers.

Some drivers run into issues when buffer sizes and ranges are larger than what fits signed 32 bit integer. Adapt the maximum buffer size accordingly.
2022-06-22 12:31:53 -04:00
Nicolas Silva
a9f1b4f8e0
Add create_texture_error. (#2800)
Firefox needs it to implement WebGPU's error model (see create_buffer_error).
2022-06-22 12:58:37 +00:00
Kevin Reid
2881a74de9
Fix formatting of TextureDimensionError::LimitExceeded. (#2799)
in the thiserror error format string, `{0:?}` ends up referring to the
first named argument, not the first struct field or a compile error, so
the error was incorrectly
    Dimension 32768 value 32768 exceeds the limit of 16384
instead of
    Dimension X value 32768 exceeds the limit of 16384
2022-06-21 21:46:12 -04:00
Rajveer Malviya
f27a9788fd
fix BufferMapCallbackC & SubmittedWorkDoneClosureC (#2787) 2022-06-18 16:55:24 +00:00
Steven
0d4d3f4ceb
Change get_preferred_format to get_supported_formats (#2783)
* Change all the functions

* Return the set of supported TextureFormat specified by WebGPU

* Remove redundant filtering and use list directly

* Replace pops with first

* Remove now unused function

* Fix doc and clarify preffered format

* Dereference enums

* Remove unused list

* Remove fancy coode

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

Co-authored-by: Connor Fitzgerald <connorwadefitzgerald@gmail.com>

Co-authored-by: Connor Fitzgerald <connorwadefitzgerald@gmail.com>
2022-06-18 00:21:02 -04:00
Jim Blandy
aba7197fe8
Update Naga to 0b60f410 (Thu 2022-6-16). (#2779) 2022-06-17 16:51:22 -04:00
Jinlei Li
f4c01052ef Rename MAX_COLOR_TARGETS to MAX_COLOR_ATTACHMENTS to match spec 2022-06-16 20:36:15 -07:00
Jinlei Li
f2c3d42818 Add InvalidGroupIndex validation at create_shader_module 2022-06-16 10:06:11 -07:00
Nicolas Silva
191537021e
Expose naga span location helpers (#2752)
* Expose the source location in CreateShaderModuleError.

* Bump naga dep to 89bed99.
2022-06-14 23:10:22 -04:00
Jim Blandy
6da57dd4e0
Add type annotation to render pass code, for rust-analyzer. (#2773)
This is a workaround for a limitation in rust-analyzer:
https://github.com/rust-lang/rust-analyzer/issues/12247
2022-06-14 23:06:22 -04:00
Jim Blandy
915be10443
wgpu_core::command::bundle: Consolidate pipeline and vertex state. (#2769)
Refactor `wgpu_core::command::bundle::State` to more closely resemble
the internal slots of a WebGPU `GPURenderBundleEncoder`, and add
validation required by the WebGPU specification.

Use `Option` to represent state that may be left unset on the encoder:
specifically, the pipeline and vertex buffers. (Previous commits have
already addressed index buffers and bind groups.) Use `.ok_or`, etc.
for unwrapping, to ensure that encoding state errors are reported.

Consolidate state derived from the pipeline in a new `PipelineState`
struct.

Remove `wgpu_core::command::bundle::PushConstantState::is_dirty`; just
represent push constant state as a vector of `PushConstantRange`
values. It's sufficient to simply zero the push constants whenever the
vector is non-empty.

Rename `bundle::State::flush_push_constants` to `zero_push_constants`a.
This is not a "flush pending state changes" function like all the
others; it just ensures that each pipeline's push constant state is
initialized.
2022-06-14 23:06:05 -04:00
Jim Blandy
b30b445423
Clarify docs for wgpu_core's Id and gfx_select!. (#2766)
Clarify that `gfx_select!` is not specific to `hub::Global`.

Clarify that the `T` in `id<T>` is not a real resource type.
2022-06-14 00:46:58 -04:00
Jim Blandy
3a193ec3d3
Introduce VertexStep: a stride and a step mode. (#2768)
This is used in various places around render pipelines, passes, and
bundles.

The public `wgpu_core::pipeline::VertexBufferLayout` could use
`VertexStep` as well, but I think it's best to let that continue to
resemble `GPUVertexBufferLayout`.
2022-06-14 00:42:03 -04:00
Jim Blandy
a4352a1dac
Improve push constant documentation, including internal docs. (#2764) 2022-06-11 15:11:06 -04:00
Nicolas Silva
629ccaf4e0
Align the validation of Device::create_texture with the WebGPU spec (#2759) 2022-06-10 16:02:49 -04:00
Jim Blandy
b2cc6ff185
Move RenderBundleEncoder::finish's pipeline layout id into the state. (#2755) 2022-06-10 15:41:32 -04:00
Jim Blandy
f94f25f355 Fix documentation links. 2022-06-09 17:42:03 -07:00
Jinlei Li
f0c7fe3a8e
Improve read-write and read-only texture storage error message (#2745)
* Improve read-write and read-only texture storage error message

* Update wgpu-core/src/binding_model.rs

Co-authored-by: Connor Fitzgerald <connorwadefitzgerald@gmail.com>
2022-06-07 06:21:17 +00:00
Jim Blandy
091e9b1788
Clean up render bundle index buffer tracking. (#2743)
* Remove unused field `bundle::IndexState::pipeline_format`.

* Clean up render bundle index buffer tracking.

Put all state associated with an established index buffer within an
`Option`, so that the Rust types accurately represent value liveness.

Generate `MissingIndexBuffer` errors as needed for `DrawIndexed` and
indexed `MultiDrawIndirect` commands.
2022-06-07 02:17:27 -04:00
Jim Blandy
d26c04c715
Don't dirty the vertex buffer for stride/rate changes on bundles. (#2744)
`wgpu_core::command::bundle::State::set_pipeline` marks a vertex
buffer slot dirty if the pipeline's stride or step mode for that
vertex buffer slot differs from what had been previously established.
The effect of marking the slot dirty is to ensure that a new
`SetVertexBuffer` command is inserted before the next draw command
that uses that vertex buffer. However, this is unnecessary:
`wgpu_hal::CommandEncoder::set_vertex_buffer` does not need to be
called simply because the stride or rate has changed.
2022-06-07 02:10:08 -04:00
Jim Blandy
5bee63e605
Track depth and stencil writability separately. (#2693)
Put some plumbing in place to accomodate the latest definition of
`GPURenderBundleEncoderDescriptor` in the WebGPU spec, which now has
separate `depthReadOnly` and `stencilReadOnly` members.

Rename `RenderPassDepthStencilAttachment::is_read_only` to
`depth_stencil_read_only`, and don't skip validation steps due to
early returns.
2022-06-07 02:02:23 -04:00
Harald Reingruber
25b16d5cc8
OffscreenCanvas Support for WebGL Backend (#2603)
* First attempt of exposing create_surface_from_canvas for webgl

* Test Fix Compile For WebGL Offscreen Canvas

* Only specify web-sys feature version in wgpu-core, so that patch version is taken from workspace

* Reuse already existing fn create_surface_from_canvas

* Remove unnecessary unsafe

* Remove unsafe prefix also from top-level create_surface_from_canvas

* Add create_surface_from_offscreen_canvas() for webgl

* Cargo fmt

* Store webgl2_context instead of canvas, which works also for OffscreenCanvas

* Copy skybox example for OffscreenCanvas example

* Use offscreen_canvas instead in newly created example

* Update skypbox_offscreen readme.md

* Allow enabling OffscreenCanvas in examples via http://localhost:8000/?offscreen_canvas=true

* Fix cargo fmt

* [fix warning] Only import FromStr for wasm32

* [fix warning] Exclude offscreen_canvas_setup from non-wasm32

* [fix warning] Add ImageBitmap feature as well so that all related methods can be used

* Fix cargo fmt

* Fix emscripten build

* Remove `webgl` feature from wgpu-core as webgl is the only wasm32 backend

Co-authored-by: Zicklag <zicklag@katharostech.com>
2022-06-07 01:57:16 -04:00
Connor Fitzgerald
5bd0a6c4ac
Implement submission indexes (#2700)
* Implement submission indexes

* Write some unit tests for poll

* Update wgpu/src/lib.rs

Co-authored-by: Jim Blandy <jimb@red-bean.com>

* Unify Maintain in both wgc and wgpu

Co-authored-by: Jim Blandy <jimb@red-bean.com>
2022-06-05 17:22:25 -04:00
Robert Bragg
444836f747
Acquire texture: Option<std::time::Duration> timeouts (#2724)
* surface.acquire_texture: pass Option<Duration> for timeout

A std::time::Duration allows for timeouts to be specified more clearly in
Rust using whatever units are convenient for the caller, and an Option also
makes it clearer in case no timeout is wanted, as opposed to passing a
bitwise !0 as special timeout value.

Notably there was an impedance mismatch with the Vulkan backend that
takes a 64bit timeout in nanoseconds and uses u64::MAX to indicate no
timeout and the backend was not mapping a given u32::MAX into a u64::MAX

* surface.acquire_texture: ignore timeout for Android < 11

Prior to Android 11 then Android's vkAcquireNextImageKHR implementation was
non-conformant and didn't support timeouts and additionally would log a
verbose warning if a timeout was requested.

For reference this version of AcquireNextImageKHR doesn't support timeouts:
https://android.googlesource.com/platform/frameworks/native/+/refs/tags/android-mainline-10.0.0_r13/vulkan/libvulkan/swapchain.cpp#1426
and this version does:
https://android.googlesource.com/platform/frameworks/native/+/refs/tags/android-mainline-11.0.0_r45/vulkan/libvulkan/swapchain.cpp#1438
(i.e. timeout support was added in Android 11)

This patch adds a dependency on the `android-properties` crate that provides
a simple wrapper for the `__system_property_set` syscall so that the
platform version can be read via the `ro.build.version.sdk` property
and then for versions < 30 (corresponds to Android 11) any timeout
given to `acquire_texture` will be ignored (and `u64::MAX` will be
passed to Vulkan)
2022-06-04 16:05:40 +00:00
Jinlei Li
9e3cd08e59
Improve InvalidViewport error message (#2723) 2022-06-03 01:54:09 -04:00
Jinlei Li
75db572bf7
Improve InvalidScissorRect error message (#2713) 2022-06-02 07:35:13 +00:00
Connor Fitzgerald
32af4f5607
Convert map_async from being async to being callback based (#2698) 2022-05-31 11:22:21 -04:00
Jinlei Li
8063edc648
Add DEPTH24UNORM_STENCIL8 feature (#2689) 2022-05-30 15:29:12 -04:00
Connor Fitzgerald
fd954a2bd6
Stop using storage usage for sampling (#2703) 2022-05-29 19:52:41 -04:00
Connor Fitzgerald
c12ae0880f
Check that all vertex outputs are consumed by the fragment shader (#2704) 2022-05-29 23:38:11 +00:00
Daisuke Kato
16c796578c
Add symlink LICENSE files into crates. (#2604) 2022-05-29 03:07:42 -04:00
Jim Blandy
0c0bbdb3ad
Perform "valid to use with" checks when recording render bundles. (#2690)
* Update module docs for `wgpu_core::commands::bundle`.

* Perform "valid to use with" checks when recording render bundles.
2022-05-28 04:57:06 -04:00
Connor Fitzgerald
9114283707
Tracking Optimization and Rewrite (#2662)
* Texture state full is dead code

* temp

* temp2 - next is lifetime only

* temp3 - all trackers in place

* temp4 - continue muddling along

* temp5 - doodle doodle

* temp6 - continuous progress is continuous

* temp7 - pro-gress

* temp8 - Add refcounts to trackers

* temp9 - Soundness, generics, refcounts, and epochs

* temp10 - Compiling?!1?!1?!1

* temp11 - Add bind group state optimization

* temp12 - Safety and adding size setting

* temp13 - unsafe

* temp14 - Abstract all the state transitions

* temp15 - It verks! kinda...

* temp16 - it more verks!

* temp17 - debugging and unit tests

* temp18 - fixing unfixed things

* temp19 - hmmm

* temp20 - curious about line deltas

* temp21 - working texture trackers

* temp22 - write merge/update/barrier for buffers

* temp23 - cleanup and buffers

* temp24 - clippy cleanup

* temp25 - Add inline markers on buffer functions

* temp26 - Fix buffer trackers

* temp27 - fixed texture insert to handle both sides

* temp28 - document tracker and usages

* temp29 - document track/mod.rs

* temp30 - convert STORAGE_WRITE to STORAGE_READ_WRITE

* temp31 - Add some debug asserts to make sure we can't insert invalid states

* temp32 - clippy is opinionated sometimes

* temp33 - renaming and documentation

* temp34 - logging
2022-05-24 11:36:13 -04:00
Jim Blandy
c7872ab8b5 Eliminate wgpu_core::commands::bundle::State::raw_dynamic_offsets.
This vector's contents always ended up identical to the
`RenderBundleEncoder`'s `BasePass`'s `dynamic_offsets` vector, so
we can just take values from there instead of copying them.
2022-05-22 08:38:47 -07:00
Jim Blandy
87d75d9c7b Document command::BasePass. 2022-05-22 08:38:47 -07:00
Jim Blandy
afed25fa5c Clean up render bundle bind group tracking.
The `dynamic_offsets` and `is_dirty` flags only make sense when the
slot is occupied, so they should be inside the `Option`. This makes
`State::bind` into an `ArrayVec<Option<BindState>>`, and cleans up
various other bits.
2022-05-22 08:38:47 -07:00
Jim Blandy
d3235484f9 Document some parts of wgpu_core's render bundle code. 2022-05-22 08:38:47 -07:00
Jim Blandy
b53a8bcb17
New function: Global::create_buffer_error. (#2673) 2022-05-19 13:10:47 -04:00
Jinlei Li
8b2e6fe3a2
Roll naga to 571302e (50 revisions) (#2672) 2022-05-18 21:09:22 -07:00
i509VCB
f5c2ff11d0
Adapter and Instance as_hal functions (#2663)
These functions are added to allow lower level access to adapter and instance from backends.
2022-05-17 06:13:58 +00:00
Jinlei Li
26f96c7dfe
Add DEPTH32FLOAT_STENCIL8 featue (#2664) 2022-05-17 02:11:05 -04:00
Jim Blandy
b51fd851be Report invalid pipelines in render bundles as errors, not panics.
Fixes #2665.
2022-05-16 14:26:36 -07:00
Jim Blandy
c608ee0bbe
Accept both parking-lot 0.11 and 0.12.*, to avoid windows-rs. (#2660)
In parking_lot 0.12 and parking_lot_core 0.9.0, those crates switched
from the winapi crate to the official Microsoft windows-sys crate.
This is fine, except that windows-sys and its dependencies are even
larger than winapi. Some users may wish to stick with winapi for the
time being; this change allows wgpu to accommodate them.
2022-05-16 01:16:53 -04:00
Jim Blandy
202d81a64a
Move set_index_buffer FFI functions back into wgpu. (#2661)
It's very odd to have almost all the render pass and compute pass ffi
functions in `wgpu` except for the `set_index_buffer` functions, which
live in Firefox. I'd like to remove these from Firefox and put them
back next to their companions.

These functions were originally removed from wgpu in #1077, because
wgpu-native has its own incompatible version of IndexFormat (see that
PR for details). However, with wgpu-native#85, that code was removed,
so having these functions in `wgpu` should be no longer be a problem
for wgpu-native.
2022-05-15 15:18:05 -04:00
Shaye Garg
75b881e636
fix: panic in Storage::get (#2657)
* fix: don't panic on invalid id in Storage::get

* formatting

* removed double matches

* more match removal

* fix formatting

* add fix to Storage::label_for_invalid_id
2022-05-14 14:59:47 +05:30