* Introduce `dx12` and `metal` crate features to `wgpu`
* Implement dummy `Context` to allow compilation with `--no-default-features`
* Address review
* Remove `dummy::Context` in favor of `hal::api::Empty`
* Add changelog entry
* Panic early in `Instance::new()` if no backend is enabled
Co-Authored-By: Andreas Reich <1220815+Wumpf@users.noreply.github.com>
---------
Co-authored-by: Andreas Reich <1220815+Wumpf@users.noreply.github.com>
Without the suffix, `Expression::Literal(Literal::F32)` expressions
get written without any suffix on the number, meaning that they get
re-parsed as `AbstractFloat` values. In theory, this should always be
fine, but since we don't actually support abstract types yet in all
the places we should, having them appear in the output causes
validation problems.
See also: #4863, which did the same for `i32` literals.
Without the suffix, `Expression::Literal(Literal::I32)` expressions
get written without any suffix on the decimal number, meaning that
they get re-parsed as AbstractInt values. In theory, this should
always be fine, but since we don't actually support abstract types yet
in all the places we should, having them appear in the output causes
validation problems.
* Make `BufferMappedRange` trait WasmNotSendSync
* make QueueWriteBuffer trait Debug
* add changelog
* fix pr numbers in changelog
* missing send/sync on web.rs on BufferMappedRange for fragile-send-sync-non-atomic-wasm + !atomics
* Downgrade resource lifetime management log level to trace.
Allow promoting it back to info via an feature flag.
* Don't filter out info and warning log in the examples.
* Changelog entry.
Have `compact::compact` preserve entries in the `Module::types` arena
if they have names.
Future abstract type support will require the WGSL front end to
compact the module before validation. Without this change, that will
drop `alias` declarations, making it harder to test type validation.
Previously, implicit padding members of `struct`s were suppressed from
structure definitions in Metal output if they had a binding specified
for them (i.e., `@location(0)`). This padding is, however, is necessary
for correct access of member fields passed into shaders by uniform and
storage buffers. Unconditionally emit padding members for `struct`s.
Resolves
[`gfx-rs/wgpu`#4701](https://github.com/gfx-rs/wgpu/pull/4701).
Let `naga::TypeInner::Matrix` hold a full `Scalar`, with a kind and
byte width, not merely a byte width, to make it possible to represent
matrices of AbstractFloats for WGSL.
Add an `I64` variant to `crate::Literal`, making `crate::Expression`
suitable for representing `AbstractFloat` and `AbstractInt` values in
the WGSL front end.
Make validation reject uses of `Literal::I64` in constant and function
expression arenas unconditionally. Add tests for this.
Let the frontends and backends for languages that have 64-bit integers
read/write them.
Identify reachable function expressions, constant expressions, and
types using a single pass over each arena, taking advantage of the
fact that expressions and types may only refer to other entries that
precede them within their arena. Only walking the statement tree still
requires a worklist/recursion.
In addition to presumably being faster, this change slightly reduces
the number of non-comment lines of code in `src/compact`.
Introduce a new struct type, `Scalar`, combining a `ScalarKind` and a
`Bytes` width, and use this whenever such pairs of values are passed
around.
In particular, use `Scalar` in `TypeInner` variants `Scalar`, `Vector`,
`Atomic`, and `ValuePointer`.
Introduce associated `Scalar` constants `I32`, `U32`, `F32`, `BOOL`
and `F64`, for common cases.
Introduce a helper function `Scalar::float` for constructing `Float`
scalars of a given width, for dealing with `TypeInner::Matrix`, which
only supplies the scalar width of its elements, not a kind.
Introduce helper functions on `Literal` and `TypeInner`, to produce
the `Scalar` describing elements' values.
Use `Scalar` in `wgpu_core::validation::NumericType` as well.
* Better handle destroying textures and buffers
Before this commit, explicitly destroying a texture or a buffer (without dropping it)
schedules the asynchronous destruction of its raw resources but does not actually mark
it as destroyed. This can cause some incorrect behavior, for example mapping a buffer
after destroying it does not cause a validation error (and later panics due to the
map callback being dropped without being called).
This Commit adds `Storage::take_and_mark_destroyed` for use in `destroy` methods.
Since it puts the resource in the error state, other methods properly catch that
the resource is no longer usable when attempting to access it and raise validation
errors.
There are other resource types that require similar treatment and will be addressed
in followup work.
* Add a changelog entry
* More complete implementation of "lose the device".
This provides a way for wgpu-core to specify a callback on "lose the
device". It ensures this callback is called at the appropriate times:
either after device.destroy has empty queues, or on demand from
device.lose.
A test has been added to device.rs.
* Updated CHANGELOG.md.
* Fix conversion to *const c_char.
* Use an allow lint to permit trivial_casts.
* rustfmt changes.
Since the pipeline id is provided by the caller, the caller may presume
that an implicit pipeline layout id is also created, even in error
conditions such as with an invalid device. Since our registry system
will panic if asked to retrieve a pipeline layout id that has never been
registered, it's dangerous to leave that id unregistered. This ensures
that the layout ids also get error values when the pipeline creation
returns an error.
This appears to match other backends, and fixes
fix the case where expressions which were named in earlier
functions are used in local variable declarations
* Add `BGRA8UNORM_STORAGE` extension
* Leave a comment in the backends that don't support bgra8unorm-storage
* Pass the appropriate storage format to naga
* Check for bgra8unorm storage support in the vulkan backend
* Add a test
Co-authored-by: Jinlei Li <jinleili0@outlook.com>
Co-authored-by: Teodor Tanasoaia <28601907+teoxoy@users.noreply.github.com>
* Add the base of the example. May need refining and definitely fact-checking.
* Start change to changelog.
* Complete changelog change for repeated-compute.
* Apply suggestion to fix typos.
Co-authored-by: Alphyr <47725341+a1phyr@users.noreply.github.com>
* Add storage-texture example which currently works native but needs to be changed to work for wasm. [no ci]
* repeated-compute now works on the web. [no ci]
* `storage-texture` now works on the web as well as native.
* Format because I forgot to do that (ugh).
* Add `storage-texture` to changelog.
* Add `render-to-texture` example.
* Not all the files got git added. Fixed it.
* Add `render-to-texture` to changelog.
* Make better readme's and add examples to said readme's.
* Oops. Put the example updates in the wrong place.
* Add `uniform-values` example.
* Apply clippy suggestions.
* Improved readme's and documentation.
* Fmt. Turning into the Joker rn.
* Make instructions for examples on the web more clear. \(Fmt and clippy happy\)
* hello-workgroups It doesn't work.
* Add basic comments and readme to hello-workgroups.
* Add hello-synchronization example. Currently doesn't have any tests but those should be added later.
* Forgot to check wasm compatibility for hello-synchronization. Fixed it.
* Add test for hello-synchronization.
* Make my examples downlevel defaults.
* Make uniform-values downlevel defaults. (Forgot to do that last commit.)
* Fix clippy doc complaints.
* Didn't fully fix the docs last commit. Got it here I think.
* Fix redundant bullet point in examples/hello-workgroups/README.md.
* Trim down the introduction section of examples/hello-workgroups/README.md.
* Add technical links section to examples/hello-workgroups/README.md.
* Use idiomatic Rust comments, break up big text wall into paragraphs, and fix some spelling errors.
* Move output image functions into examples/common and give output_image_wasm some upgrades.
* Modify changelog for moving output_image_native and output_image_wasm into wgpu-example.
* Fix output_image_wasm. (Formerly did not handle pre-existing output image targets.)
* Make a multiline comment be made of single lines to be more ideomatic.
* "Fix" more multiline comments. I think this is actually the last of them.
* Make the window a consistant, square size that's convenient for viewing.
* Make the window on uniform-values not endlessly poll, taking up 100% of the main thread in background at idle. Also, change layout a little and make native use nanos by default for logging.
* Make execute in hello-synchronization return a struct of vecs instead of using out parameters.
* Didn't realize the naming of wgpu_example::framework so I moved my common example utility functions into wgpu_example::utils.
* Add add_web_nothing_to_see_msg function to replace all the instances of adding "open the console" messages across the examples.
* Add small documentation to add_web_nothing_to_see_msg and change it to use h1 instead of p.
* Add documentation to output_image_native and output_image_wasm in examples/common.
* Do better logging for output image functions in wgpu-example::utils.
* Remove redundant append_child'ing of the output image element in wgpu-example::utils::output_image_wasm.
* Fix error regarding log message for having written the image in wgpu-example::utils::output_image_native.
* Fmt.
* In examples/README.md, re-arrange the examples in the graph to be in alphabetical order.
* Fix changlog item regarding wgpu-example::utils and the output image functions.
* Move all the added examples into one changelog item that lists all of them.
* Updated table in examples/README.md with new examples. Added new features to the table to accurately represent the examples.\n\nFor the new features, not all old examples may be fully represented.
* Fix inaccurate comment in hello-workgroups/src/shader.wgsl.
* Update examples/README.md to include basic descriptions of the basic examples as well as hints on how examples build off of each other.
* Remove `capture` example. See changelog entry for reasoning.
* Fix typo in hello-workgroups/shader.wgsl
* Change the method of vertex generation in the shader code of render-to-texture to make it more clear.
* Modify/correct message in repeated-compute/main.rs regarding the output staging buffer.
* Update message in uniform-values/main.rs about writing the app state struct to the input WGSL buffer.
* Add notice in repeated-compute/main.rs about why async channels are necessary (portability to WASM).
* Revise comment in uniform-values/main.rs about why we don't cast the struct using POD to be more clear.
* Change uniform-values to use encase for translating AppState to WGSL bytes.
* Cargo & Clippy: My two best friends.
* Add MIT-0 to the list of allowed liscences.
* Fix docs for wasm.
---------
Co-authored-by: Alphyr <47725341+a1phyr@users.noreply.github.com>
* Make buffer_unmap check for device validity, add tests.
This patch makes buffer_unmap check for a valid device, and corrects
buffer_map to return the appropriate error for an invalid device.
Tests are added for both operations.
It also adds device validity checks to device_maintain_ids and to the
functions that get and set buffer sub data.
* Update changelog and test comment.
* Run rustfmt.
* Update test device_lose_then_more to specify more buffer usages to keep Vulkan happy.
* wgpu-core: Only produce StageError::InputNotConsumed on DX11/DX12
This error only exists due to an issue with naga's HLSL support:
https://github.com/gfx-rs/naga/issues/1945
The WGPU spec itself allows vertex shader outputs that are
not consumed by the fragment shader.
Until the issue is fixed, we can allow unconsumed outputs on
all platforms other than DX11/DX12.
* Add Features::SHADER_UNUSED_VERTEX_OUTPUT to allow disabling check
* Pick an unused feature id
Implements timer queries via write_timestamp on Metal for encoders (whenever timer queries are available) and passes (for Intel/AMD GPUs, where we should advertise TIMESTAMP_QUERY_INSIDE_PASSES now).
Due to some bugs in Metal this was a lot harder than expected. I believe the solution is close to optimal with the current restrictions in place. For details see code comments.
Due to an issue with Mesa versions less than 21.2 presentation on Vulkan
was forced to Nvidia only. This in itself brought new issues around the
Nvidia driver specfic format modifers.
As of Mesa 21.2 the Intel vulkan issue is fixed. This commit enables
presentation on versions 21.2 and above for Intel.
References:
- https://github.com/NVIDIA/egl-wayland/issues/72
Closes [#4101](https://github.com/gfx-rs/wgpu/issues/4101)
Calling `vkDestroyCommandPool` automatically frees all command buffers allocated
from that pool, so there is no need for `Device::destroy_command_encoder` to
explicitly call `vkFreeCommandBuffers` on the `CommandEncoder`'s `free` and
`discarded` lists.
* Add validation in accordance with WebGPU `setViewport` valid usage for `x`, `y` and `this.[[attachment_size]]`.
`x` and `y` must not be negative, and the rect must be contained in the render target.
* Add changelog entry.
* 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.
* Add the docs. (And change max_buffer_size for default and downlevel_default to be more readable.)
* Put limits listed in documentation on seperate lines via bullet points.
* Update changelog.
* Fix fmt.
* Turn doc lists into testable code blocks with markers for changed values.
* Update glow to a new minor version, improve gles adapter astc feature selection
* Update Cargo.lock
* Add changelog entry
* Improve cfg flags to filter out emscripten
Introduces a DisplayOwner struct to own both the library
and associated display pointer; their lifetimes are combined
in that struct.
The display pointer is encapsulated in a DisplayRef.
When DisplayOwner is dropped, it ensures that the DisplayRef
is correctly closed prior to unloading the library.
refs: https://github.com/gfx-rs/wgpu/issues/3813
* Make initialize_adapter_from_env take a compatible surface
Add a compatible surface parameter to initialize_adapter_from_env, and
use that to make initialize_adapter_from_env_or_default always respect
its compatible_surface parameter.
---------
Co-authored-by: Andreas Reich <r_andreas2@web.de>
* web: use `get_preferred_canvas_format()` to fill `formats` of `SurfaceCapabilities`
* Only keep preferred format as the first element
* Update CHANGELOG
* Find preferred format and move it to the first position in the formats.
* Add a note to preferred_format.
* Remove the unnecessary allocation.
* EGL: respect the user requesting a non-sRGB surface format
What used to happen was that sRGB was used whether you requested it or not.
This commit fixes that and now passing in a non-sRGB texture format in SurfaceConfiguration will result in a non-sRGB surface being created.
* add changelog entry about the EGL non-sRGB support change
As described in [Vulkan-ValidationLayers#5671], the validation layers don't understand debug ranges paired across different command buffers on the same queue, even though the Vulkan spec says:
> An application may open a debug label region in one command buffer and close it in another, or otherwise split debug label regions across multiple command buffers or multiple queue submissions. When viewed from the linear series of submissions to a single queue, the calls to vkCmdBeginDebugUtilsLabelEXT and vkCmdEndDebugUtilsLabelEXT must be matched and balanced.
Until this is fixed, wgpu should ignore this validation error to reduce noise in test runs.
Fixes#3733.
[Vulkan-ValidationLayers#5671]: https://github.com/KhronosGroup/Vulkan-ValidationLayers/issues/5671
* enable debug extension on emscripten
* update changelog
* extract emscripten stuff into a separate module
* use unmasked queries on w-u-u, and only enable extension on emscripten
* fix docs
* remove redundant flag
* set the `MULTISAMPLED_SHADING` downlevel flag for gles and dx11
* set the right naga capabilities
add `Features::SHADER_EARLY_DEPTH_TEST`
* add changelog entry
* remove `@early_depth_test` from water example
* Fix dx12 shader validation errors when dxil.dll isn't available in the local scope.
* changelog
* clippy
* always explicitly validate shaders to simplify code
* destructor ordering
wgpu currently checks if the `write_mask` is 0 to determine wether a
stencil is used as readonly or not. However Webgpu contains a more
complex ruleset that also checks the cull mode and face operations to
determine if the stencil is readonly or not.
This commit brings these new rules to wgpu.
* Cache programs in GLES backend by their stage info, to avoid recreating the same program untold many times
* Don't duplicate an arcs ref count in gles programs
* Extract ProgramCacheKey from gles ProgramCache
* gles: Panic if we can't acquire program_cache lock
* Clarify why the program cache is safe
* Add validation in accordance with WebGPU `GPUSamplerDescriptor` valid usage for `lodMinClamp` and `lodMaxClamp`.
`lodMinClamp` must not be negative, and `lodMaxClamp` must be >= `lodMinClamp`
* Add changelog entry.
* Run `cargo fmt`.
* update to ash 0.37.1 to fix CI
* changelog
* Use equals for ash version
Co-authored-by: Connor Fitzgerald <connorwadefitzgerald@gmail.com>
Co-authored-by: Connor Fitzgerald <connorwadefitzgerald@gmail.com>