2023-09-26 19:35:08 +00:00
|
|
|
use crate::renderer::{
|
|
|
|
RenderAdapter, RenderAdapterInfo, RenderDevice, RenderInstance, RenderQueue,
|
|
|
|
};
|
2024-09-27 00:59:59 +00:00
|
|
|
use alloc::borrow::Cow;
|
|
|
|
use std::path::PathBuf;
|
2021-12-09 21:14:17 +00:00
|
|
|
|
Wgpu 0.15 (#7356)
# Objective
Update Bevy to wgpu 0.15.
## Changelog
- Update to wgpu 0.15, wgpu-hal 0.15.1, and naga 0.11
- Users can now use the [DirectX Shader Compiler](https://github.com/microsoft/DirectXShaderCompiler) (DXC) on Windows with DX12 for faster shader compilation and ShaderModel 6.0+ support (requires `dxcompiler.dll` and `dxil.dll`, which are included in DXC downloads from [here](https://github.com/microsoft/DirectXShaderCompiler/releases/latest))
## Migration Guide
### WGSL Top-Level `let` is now `const`
All top level constants are now declared with `const`, catching up with the wgsl spec.
`let` is no longer allowed at the global scope, only within functions.
```diff
-let SOME_CONSTANT = 12.0;
+const SOME_CONSTANT = 12.0;
```
#### `TextureDescriptor` and `SurfaceConfiguration` now requires a `view_formats` field
The new `view_formats` field in the `TextureDescriptor` is used to specify a list of formats the texture can be re-interpreted to in a texture view. Currently only changing srgb-ness is allowed (ex. `Rgba8Unorm` <=> `Rgba8UnormSrgb`). You should set `view_formats` to `&[]` (empty) unless you have a specific reason not to.
#### The DirectX Shader Compiler (DXC) is now supported on DX12
DXC is now the default shader compiler when using the DX12 backend. DXC is Microsoft's replacement for their legacy FXC compiler, and is faster, less buggy, and allows for modern shader features to be used (ShaderModel 6.0+). DXC requires `dxcompiler.dll` and `dxil.dll` to be available, otherwise it will log a warning and fall back to FXC.
You can get `dxcompiler.dll` and `dxil.dll` by downloading the latest release from [Microsoft's DirectXShaderCompiler github repo](https://github.com/microsoft/DirectXShaderCompiler/releases/latest) and copying them into your project's root directory. These must be included when you distribute your Bevy game/app/etc if you plan on supporting the DX12 backend and are using DXC.
`WgpuSettings` now has a `dx12_shader_compiler` field which can be used to choose between either FXC or DXC (if you pass None for the paths for DXC, it will check for the .dlls in the working directory).
2023-01-29 20:27:30 +00:00
|
|
|
pub use wgpu::{
|
2023-12-14 02:45:47 +00:00
|
|
|
Backends, Dx12Compiler, Features as WgpuFeatures, Gles3MinorVersion, InstanceFlags,
|
2024-08-12 16:55:18 +00:00
|
|
|
Limits as WgpuLimits, MemoryHints, PowerPreference,
|
Wgpu 0.15 (#7356)
# Objective
Update Bevy to wgpu 0.15.
## Changelog
- Update to wgpu 0.15, wgpu-hal 0.15.1, and naga 0.11
- Users can now use the [DirectX Shader Compiler](https://github.com/microsoft/DirectXShaderCompiler) (DXC) on Windows with DX12 for faster shader compilation and ShaderModel 6.0+ support (requires `dxcompiler.dll` and `dxil.dll`, which are included in DXC downloads from [here](https://github.com/microsoft/DirectXShaderCompiler/releases/latest))
## Migration Guide
### WGSL Top-Level `let` is now `const`
All top level constants are now declared with `const`, catching up with the wgsl spec.
`let` is no longer allowed at the global scope, only within functions.
```diff
-let SOME_CONSTANT = 12.0;
+const SOME_CONSTANT = 12.0;
```
#### `TextureDescriptor` and `SurfaceConfiguration` now requires a `view_formats` field
The new `view_formats` field in the `TextureDescriptor` is used to specify a list of formats the texture can be re-interpreted to in a texture view. Currently only changing srgb-ness is allowed (ex. `Rgba8Unorm` <=> `Rgba8UnormSrgb`). You should set `view_formats` to `&[]` (empty) unless you have a specific reason not to.
#### The DirectX Shader Compiler (DXC) is now supported on DX12
DXC is now the default shader compiler when using the DX12 backend. DXC is Microsoft's replacement for their legacy FXC compiler, and is faster, less buggy, and allows for modern shader features to be used (ShaderModel 6.0+). DXC requires `dxcompiler.dll` and `dxil.dll` to be available, otherwise it will log a warning and fall back to FXC.
You can get `dxcompiler.dll` and `dxil.dll` by downloading the latest release from [Microsoft's DirectXShaderCompiler github repo](https://github.com/microsoft/DirectXShaderCompiler/releases/latest) and copying them into your project's root directory. These must be included when you distribute your Bevy game/app/etc if you plan on supporting the DX12 backend and are using DXC.
`WgpuSettings` now has a `dx12_shader_compiler` field which can be used to choose between either FXC or DXC (if you pass None for the paths for DXC, it will check for the .dlls in the working directory).
2023-01-29 20:27:30 +00:00
|
|
|
};
|
2021-12-09 21:14:17 +00:00
|
|
|
|
2022-02-16 21:17:37 +00:00
|
|
|
/// Configures the priority used when automatically configuring the features/limits of `wgpu`.
|
2022-01-04 20:08:12 +00:00
|
|
|
#[derive(Clone)]
|
2022-02-16 21:17:37 +00:00
|
|
|
pub enum WgpuSettingsPriority {
|
|
|
|
/// WebGPU default features and limits
|
2022-01-04 20:08:12 +00:00
|
|
|
Compatibility,
|
2022-02-16 21:17:37 +00:00
|
|
|
/// The maximum supported features and limits of the adapter and backend
|
2022-01-04 20:08:12 +00:00
|
|
|
Functionality,
|
2022-02-16 21:17:37 +00:00
|
|
|
/// WebGPU default limits plus additional constraints in order to be compatible with WebGL2
|
2022-01-04 20:08:12 +00:00
|
|
|
WebGL2,
|
|
|
|
}
|
|
|
|
|
2023-11-28 23:43:40 +00:00
|
|
|
/// Provides configuration for renderer initialization. Use [`RenderDevice::features`](RenderDevice::features),
|
|
|
|
/// [`RenderDevice::limits`](RenderDevice::limits), and the [`RenderAdapterInfo`]
|
2022-02-16 21:17:37 +00:00
|
|
|
/// resource to get runtime information about the actual adapter, backend, features, and limits.
|
2022-06-25 16:22:28 +00:00
|
|
|
/// NOTE: [`Backends::DX12`](Backends::DX12), [`Backends::METAL`](Backends::METAL), and
|
|
|
|
/// [`Backends::VULKAN`](Backends::VULKAN) are enabled by default for non-web and the best choice
|
|
|
|
/// is automatically selected. Web using the `webgl` feature uses [`Backends::GL`](Backends::GL).
|
2022-12-26 19:47:01 +00:00
|
|
|
/// NOTE: If you want to use [`Backends::GL`](Backends::GL) in a native app on `Windows` and/or `macOS`, you must
|
2022-06-25 16:22:28 +00:00
|
|
|
/// use [`ANGLE`](https://github.com/gfx-rs/wgpu#angle). This is because wgpu requires EGL to
|
|
|
|
/// create a GL context without a window and only ANGLE supports that.
|
2022-12-20 16:17:11 +00:00
|
|
|
#[derive(Clone)]
|
2022-02-16 21:17:37 +00:00
|
|
|
pub struct WgpuSettings {
|
2021-12-09 21:14:17 +00:00
|
|
|
pub device_label: Option<Cow<'static, str>>,
|
2022-01-08 10:39:43 +00:00
|
|
|
pub backends: Option<Backends>,
|
2021-12-09 21:14:17 +00:00
|
|
|
pub power_preference: PowerPreference,
|
2022-02-16 21:17:37 +00:00
|
|
|
pub priority: WgpuSettingsPriority,
|
|
|
|
/// The features to ensure are enabled regardless of what the adapter/backend supports.
|
|
|
|
/// Setting these explicitly may cause renderer initialization to fail.
|
2021-12-14 03:58:23 +00:00
|
|
|
pub features: WgpuFeatures,
|
2022-02-13 04:24:52 +00:00
|
|
|
/// The features to ensure are disabled regardless of what the adapter/backend supports
|
|
|
|
pub disabled_features: Option<WgpuFeatures>,
|
2022-02-16 21:17:37 +00:00
|
|
|
/// The imposed limits.
|
2021-12-14 03:58:23 +00:00
|
|
|
pub limits: WgpuLimits,
|
2022-02-13 04:24:52 +00:00
|
|
|
/// The constraints on limits allowed regardless of what the adapter/backend supports
|
|
|
|
pub constrained_limits: Option<WgpuLimits>,
|
Wgpu 0.15 (#7356)
# Objective
Update Bevy to wgpu 0.15.
## Changelog
- Update to wgpu 0.15, wgpu-hal 0.15.1, and naga 0.11
- Users can now use the [DirectX Shader Compiler](https://github.com/microsoft/DirectXShaderCompiler) (DXC) on Windows with DX12 for faster shader compilation and ShaderModel 6.0+ support (requires `dxcompiler.dll` and `dxil.dll`, which are included in DXC downloads from [here](https://github.com/microsoft/DirectXShaderCompiler/releases/latest))
## Migration Guide
### WGSL Top-Level `let` is now `const`
All top level constants are now declared with `const`, catching up with the wgsl spec.
`let` is no longer allowed at the global scope, only within functions.
```diff
-let SOME_CONSTANT = 12.0;
+const SOME_CONSTANT = 12.0;
```
#### `TextureDescriptor` and `SurfaceConfiguration` now requires a `view_formats` field
The new `view_formats` field in the `TextureDescriptor` is used to specify a list of formats the texture can be re-interpreted to in a texture view. Currently only changing srgb-ness is allowed (ex. `Rgba8Unorm` <=> `Rgba8UnormSrgb`). You should set `view_formats` to `&[]` (empty) unless you have a specific reason not to.
#### The DirectX Shader Compiler (DXC) is now supported on DX12
DXC is now the default shader compiler when using the DX12 backend. DXC is Microsoft's replacement for their legacy FXC compiler, and is faster, less buggy, and allows for modern shader features to be used (ShaderModel 6.0+). DXC requires `dxcompiler.dll` and `dxil.dll` to be available, otherwise it will log a warning and fall back to FXC.
You can get `dxcompiler.dll` and `dxil.dll` by downloading the latest release from [Microsoft's DirectXShaderCompiler github repo](https://github.com/microsoft/DirectXShaderCompiler/releases/latest) and copying them into your project's root directory. These must be included when you distribute your Bevy game/app/etc if you plan on supporting the DX12 backend and are using DXC.
`WgpuSettings` now has a `dx12_shader_compiler` field which can be used to choose between either FXC or DXC (if you pass None for the paths for DXC, it will check for the .dlls in the working directory).
2023-01-29 20:27:30 +00:00
|
|
|
/// The shader compiler to use for the DX12 backend.
|
|
|
|
pub dx12_shader_compiler: Dx12Compiler,
|
2023-12-14 02:45:47 +00:00
|
|
|
/// Allows you to choose which minor version of GLES3 to use (3.0, 3.1, 3.2, or automatic)
|
|
|
|
/// This only applies when using ANGLE and the GL backend.
|
|
|
|
pub gles3_minor_version: Gles3MinorVersion,
|
|
|
|
/// These are for controlling WGPU's debug information to eg. enable validation and shader debug info in release builds.
|
|
|
|
pub instance_flags: InstanceFlags,
|
2024-08-12 16:55:18 +00:00
|
|
|
/// This hints to the WGPU device about the preferred memory allocation strategy.
|
|
|
|
pub memory_hints: MemoryHints,
|
Replace the `wgpu_trace` feature with a field in `bevy_render::settings::WgpuSettings` (#14842)
# Objective
- Remove the `wgpu_trace` feature while still making it easy/possible to
record wgpu traces for debugging.
- Close #14725.
- Get a taste of the bevy codebase. :P
## Solution
This PR performs the above objective by removing the `wgpu_trace`
feature from all `Cargo.toml` files.
However, wgpu traces are still useful for debugging - but to record
them, you need to pass in a directory path to store the traces in. To
avoid forcing users into manually creating the renderer,
`bevy_render::settings::WgpuSettings` now has a `trace_path` field, so
that all of Bevy's automatic initialization can happen while still
allowing for tracing.
## Testing
- Did you test these changes? If so, how?
- I have tested these changes, but only via running `cargo run -p ci`. I
am hoping the Github Actions workflows will catch anything I missed.
- Are there any parts that need more testing?
- I do not believe so.
- How can other people (reviewers) test your changes? Is there anything
specific they need to know?
- If you want to test these changes, I have updated the debugging guide
(`docs/debugging.md`) section on WGPU Tracing.
- If relevant, what platforms did you test these changes on, and are
there any important ones you can't test?
- I ran the above command on a Windows 10 64-bit (x64) machine, using
the `stable-x86_64-pc-windows-msvc` toolchain. I do not have anything
set up for other platforms or targets (though I can't imagine this needs
testing on other platforms).
---
## Migration Guide
1. The `bevy/wgpu_trace`, `bevy_render/wgpu_trace`, and
`bevy_internal/wgpu_trace` features no longer exist. Remove them from
your `Cargo.toml`, CI, tooling, and what-not.
2. Follow the instructions in the updated `docs/debugging.md` file in
the repository, under the WGPU Tracing section.
Because of the changes made, you can now generate traces to any path,
rather than the hardcoded `%WorkspaceRoot%/wgpu_trace` (where
`%WorkspaceRoot%` is... the root of your crate's workspace) folder.
(If WGPU hasn't restored tracing functionality...) Do note that WGPU has
not yet restored tracing functionality. However, once it does, the above
should be sufficient to generate new traces.
---------
Co-authored-by: TrialDragon <31419708+TrialDragon@users.noreply.github.com>
2024-08-25 14:16:11 +00:00
|
|
|
/// The path to pass to wgpu for API call tracing. This only has an effect if wgpu's tracing functionality is enabled.
|
|
|
|
pub trace_path: Option<PathBuf>,
|
2021-12-09 21:14:17 +00:00
|
|
|
}
|
|
|
|
|
2022-02-16 21:17:37 +00:00
|
|
|
impl Default for WgpuSettings {
|
2021-12-09 21:14:17 +00:00
|
|
|
fn default() -> Self {
|
Update to wgpu 0.19 and raw-window-handle 0.6 (#11280)
# Objective
Keep core dependencies up to date.
## Solution
Update the dependencies.
wgpu 0.19 only supports raw-window-handle (rwh) 0.6, so bumping that was
included in this.
The rwh 0.6 version bump is just the simplest way of doing it. There
might be a way we can take advantage of wgpu's new safe surface creation
api, but I'm not familiar enough with bevy's window management to
untangle it and my attempt ended up being a mess of lifetimes and rustc
complaining about missing trait impls (that were implemented). Thanks to
@MiniaczQ for the (much simpler) rwh 0.6 version bump code.
Unblocks https://github.com/bevyengine/bevy/pull/9172 and
https://github.com/bevyengine/bevy/pull/10812
~~This might be blocked on cpal and oboe updating their ndk versions to
0.8, as they both currently target ndk 0.7 which uses rwh 0.5.2~~ Tested
on android, and everything seems to work correctly (audio properly stops
when minimized, and plays when re-focusing the app).
---
## Changelog
- `wgpu` has been updated to 0.19! The long awaited arcanization has
been merged (for more info, see
https://gfx-rs.github.io/2023/11/24/arcanization.html), and Vulkan
should now be working again on Intel GPUs.
- Targeting WebGPU now requires that you add the new `webgpu` feature
(setting the `RUSTFLAGS` environment variable to
`--cfg=web_sys_unstable_apis` is still required). This feature currently
overrides the `webgl2` feature if you have both enabled (the `webgl2`
feature is enabled by default), so it is not recommended to add it as a
default feature to libraries without putting it behind a flag that
allows library users to opt out of it! In the future we plan on
supporting wasm binaries that can target both webgl2 and webgpu now that
wgpu added support for doing so (see
https://github.com/bevyengine/bevy/issues/11505).
- `raw-window-handle` has been updated to version 0.6.
## Migration Guide
- `bevy_render::instance_index::get_instance_index()` has been removed
as the webgl2 workaround is no longer required as it was fixed upstream
in wgpu. The `BASE_INSTANCE_WORKAROUND` shaderdef has also been removed.
- WebGPU now requires the new `webgpu` feature to be enabled. The
`webgpu` feature currently overrides the `webgl2` feature so you no
longer need to disable all default features and re-add them all when
targeting `webgpu`, but binaries built with both the `webgpu` and
`webgl2` features will only target the webgpu backend, and will only
work on browsers that support WebGPU.
- Places where you conditionally compiled things for webgl2 need to be
updated because of this change, eg:
- `#[cfg(any(not(feature = "webgl"), not(target_arch = "wasm32")))]`
becomes `#[cfg(any(not(feature = "webgl") ,not(target_arch = "wasm32"),
feature = "webgpu"))]`
- `#[cfg(all(feature = "webgl", target_arch = "wasm32"))]` becomes
`#[cfg(all(feature = "webgl", target_arch = "wasm32", not(feature =
"webgpu")))]`
- `if cfg!(all(feature = "webgl", target_arch = "wasm32"))` becomes `if
cfg!(all(feature = "webgl", target_arch = "wasm32", not(feature =
"webgpu")))`
- `create_texture_with_data` now also takes a `TextureDataOrder`. You
can probably just set this to `TextureDataOrder::default()`
- `TextureFormat`'s `block_size` has been renamed to `block_copy_size`
- See the `wgpu` changelog for anything I might've missed:
https://github.com/gfx-rs/wgpu/blob/trunk/CHANGELOG.md
---------
Co-authored-by: François <mockersf@gmail.com>
2024-01-26 18:14:21 +00:00
|
|
|
let default_backends = if cfg!(all(
|
|
|
|
feature = "webgl",
|
|
|
|
target_arch = "wasm32",
|
|
|
|
not(feature = "webgpu")
|
|
|
|
)) {
|
2021-12-09 21:14:17 +00:00
|
|
|
Backends::GL
|
Update to wgpu 0.19 and raw-window-handle 0.6 (#11280)
# Objective
Keep core dependencies up to date.
## Solution
Update the dependencies.
wgpu 0.19 only supports raw-window-handle (rwh) 0.6, so bumping that was
included in this.
The rwh 0.6 version bump is just the simplest way of doing it. There
might be a way we can take advantage of wgpu's new safe surface creation
api, but I'm not familiar enough with bevy's window management to
untangle it and my attempt ended up being a mess of lifetimes and rustc
complaining about missing trait impls (that were implemented). Thanks to
@MiniaczQ for the (much simpler) rwh 0.6 version bump code.
Unblocks https://github.com/bevyengine/bevy/pull/9172 and
https://github.com/bevyengine/bevy/pull/10812
~~This might be blocked on cpal and oboe updating their ndk versions to
0.8, as they both currently target ndk 0.7 which uses rwh 0.5.2~~ Tested
on android, and everything seems to work correctly (audio properly stops
when minimized, and plays when re-focusing the app).
---
## Changelog
- `wgpu` has been updated to 0.19! The long awaited arcanization has
been merged (for more info, see
https://gfx-rs.github.io/2023/11/24/arcanization.html), and Vulkan
should now be working again on Intel GPUs.
- Targeting WebGPU now requires that you add the new `webgpu` feature
(setting the `RUSTFLAGS` environment variable to
`--cfg=web_sys_unstable_apis` is still required). This feature currently
overrides the `webgl2` feature if you have both enabled (the `webgl2`
feature is enabled by default), so it is not recommended to add it as a
default feature to libraries without putting it behind a flag that
allows library users to opt out of it! In the future we plan on
supporting wasm binaries that can target both webgl2 and webgpu now that
wgpu added support for doing so (see
https://github.com/bevyengine/bevy/issues/11505).
- `raw-window-handle` has been updated to version 0.6.
## Migration Guide
- `bevy_render::instance_index::get_instance_index()` has been removed
as the webgl2 workaround is no longer required as it was fixed upstream
in wgpu. The `BASE_INSTANCE_WORKAROUND` shaderdef has also been removed.
- WebGPU now requires the new `webgpu` feature to be enabled. The
`webgpu` feature currently overrides the `webgl2` feature so you no
longer need to disable all default features and re-add them all when
targeting `webgpu`, but binaries built with both the `webgpu` and
`webgl2` features will only target the webgpu backend, and will only
work on browsers that support WebGPU.
- Places where you conditionally compiled things for webgl2 need to be
updated because of this change, eg:
- `#[cfg(any(not(feature = "webgl"), not(target_arch = "wasm32")))]`
becomes `#[cfg(any(not(feature = "webgl") ,not(target_arch = "wasm32"),
feature = "webgpu"))]`
- `#[cfg(all(feature = "webgl", target_arch = "wasm32"))]` becomes
`#[cfg(all(feature = "webgl", target_arch = "wasm32", not(feature =
"webgpu")))]`
- `if cfg!(all(feature = "webgl", target_arch = "wasm32"))` becomes `if
cfg!(all(feature = "webgl", target_arch = "wasm32", not(feature =
"webgpu")))`
- `create_texture_with_data` now also takes a `TextureDataOrder`. You
can probably just set this to `TextureDataOrder::default()`
- `TextureFormat`'s `block_size` has been renamed to `block_copy_size`
- See the `wgpu` changelog for anything I might've missed:
https://github.com/gfx-rs/wgpu/blob/trunk/CHANGELOG.md
---------
Co-authored-by: François <mockersf@gmail.com>
2024-01-26 18:14:21 +00:00
|
|
|
} else if cfg!(all(feature = "webgpu", target_arch = "wasm32")) {
|
|
|
|
Backends::BROWSER_WEBGPU
|
2021-12-09 21:14:17 +00:00
|
|
|
} else {
|
2023-02-04 23:20:20 +00:00
|
|
|
Backends::all()
|
2021-12-09 21:14:17 +00:00
|
|
|
};
|
|
|
|
|
2022-01-08 10:39:43 +00:00
|
|
|
let backends = Some(wgpu::util::backend_bits_from_env().unwrap_or(default_backends));
|
2021-12-09 21:14:17 +00:00
|
|
|
|
2023-08-18 20:18:15 +00:00
|
|
|
let power_preference =
|
|
|
|
wgpu::util::power_preference_from_env().unwrap_or(PowerPreference::HighPerformance);
|
|
|
|
|
2022-02-16 21:17:37 +00:00
|
|
|
let priority = settings_priority_from_env().unwrap_or(WgpuSettingsPriority::Functionality);
|
2022-01-04 20:08:12 +00:00
|
|
|
|
Update to wgpu 0.19 and raw-window-handle 0.6 (#11280)
# Objective
Keep core dependencies up to date.
## Solution
Update the dependencies.
wgpu 0.19 only supports raw-window-handle (rwh) 0.6, so bumping that was
included in this.
The rwh 0.6 version bump is just the simplest way of doing it. There
might be a way we can take advantage of wgpu's new safe surface creation
api, but I'm not familiar enough with bevy's window management to
untangle it and my attempt ended up being a mess of lifetimes and rustc
complaining about missing trait impls (that were implemented). Thanks to
@MiniaczQ for the (much simpler) rwh 0.6 version bump code.
Unblocks https://github.com/bevyengine/bevy/pull/9172 and
https://github.com/bevyengine/bevy/pull/10812
~~This might be blocked on cpal and oboe updating their ndk versions to
0.8, as they both currently target ndk 0.7 which uses rwh 0.5.2~~ Tested
on android, and everything seems to work correctly (audio properly stops
when minimized, and plays when re-focusing the app).
---
## Changelog
- `wgpu` has been updated to 0.19! The long awaited arcanization has
been merged (for more info, see
https://gfx-rs.github.io/2023/11/24/arcanization.html), and Vulkan
should now be working again on Intel GPUs.
- Targeting WebGPU now requires that you add the new `webgpu` feature
(setting the `RUSTFLAGS` environment variable to
`--cfg=web_sys_unstable_apis` is still required). This feature currently
overrides the `webgl2` feature if you have both enabled (the `webgl2`
feature is enabled by default), so it is not recommended to add it as a
default feature to libraries without putting it behind a flag that
allows library users to opt out of it! In the future we plan on
supporting wasm binaries that can target both webgl2 and webgpu now that
wgpu added support for doing so (see
https://github.com/bevyengine/bevy/issues/11505).
- `raw-window-handle` has been updated to version 0.6.
## Migration Guide
- `bevy_render::instance_index::get_instance_index()` has been removed
as the webgl2 workaround is no longer required as it was fixed upstream
in wgpu. The `BASE_INSTANCE_WORKAROUND` shaderdef has also been removed.
- WebGPU now requires the new `webgpu` feature to be enabled. The
`webgpu` feature currently overrides the `webgl2` feature so you no
longer need to disable all default features and re-add them all when
targeting `webgpu`, but binaries built with both the `webgpu` and
`webgl2` features will only target the webgpu backend, and will only
work on browsers that support WebGPU.
- Places where you conditionally compiled things for webgl2 need to be
updated because of this change, eg:
- `#[cfg(any(not(feature = "webgl"), not(target_arch = "wasm32")))]`
becomes `#[cfg(any(not(feature = "webgl") ,not(target_arch = "wasm32"),
feature = "webgpu"))]`
- `#[cfg(all(feature = "webgl", target_arch = "wasm32"))]` becomes
`#[cfg(all(feature = "webgl", target_arch = "wasm32", not(feature =
"webgpu")))]`
- `if cfg!(all(feature = "webgl", target_arch = "wasm32"))` becomes `if
cfg!(all(feature = "webgl", target_arch = "wasm32", not(feature =
"webgpu")))`
- `create_texture_with_data` now also takes a `TextureDataOrder`. You
can probably just set this to `TextureDataOrder::default()`
- `TextureFormat`'s `block_size` has been renamed to `block_copy_size`
- See the `wgpu` changelog for anything I might've missed:
https://github.com/gfx-rs/wgpu/blob/trunk/CHANGELOG.md
---------
Co-authored-by: François <mockersf@gmail.com>
2024-01-26 18:14:21 +00:00
|
|
|
let limits = if cfg!(all(
|
|
|
|
feature = "webgl",
|
|
|
|
target_arch = "wasm32",
|
|
|
|
not(feature = "webgpu")
|
|
|
|
)) || matches!(priority, WgpuSettingsPriority::WebGL2)
|
2022-02-16 21:17:37 +00:00
|
|
|
{
|
2021-12-09 21:14:17 +00:00
|
|
|
wgpu::Limits::downlevel_webgl2_defaults()
|
|
|
|
} else {
|
2021-12-14 03:58:23 +00:00
|
|
|
#[allow(unused_mut)]
|
|
|
|
let mut limits = wgpu::Limits::default();
|
|
|
|
#[cfg(feature = "ci_limits")]
|
|
|
|
{
|
|
|
|
limits.max_storage_textures_per_shader_stage = 4;
|
|
|
|
limits.max_texture_dimension_3d = 1024;
|
|
|
|
}
|
|
|
|
limits
|
2021-12-09 21:14:17 +00:00
|
|
|
};
|
|
|
|
|
Wgpu 0.15 (#7356)
# Objective
Update Bevy to wgpu 0.15.
## Changelog
- Update to wgpu 0.15, wgpu-hal 0.15.1, and naga 0.11
- Users can now use the [DirectX Shader Compiler](https://github.com/microsoft/DirectXShaderCompiler) (DXC) on Windows with DX12 for faster shader compilation and ShaderModel 6.0+ support (requires `dxcompiler.dll` and `dxil.dll`, which are included in DXC downloads from [here](https://github.com/microsoft/DirectXShaderCompiler/releases/latest))
## Migration Guide
### WGSL Top-Level `let` is now `const`
All top level constants are now declared with `const`, catching up with the wgsl spec.
`let` is no longer allowed at the global scope, only within functions.
```diff
-let SOME_CONSTANT = 12.0;
+const SOME_CONSTANT = 12.0;
```
#### `TextureDescriptor` and `SurfaceConfiguration` now requires a `view_formats` field
The new `view_formats` field in the `TextureDescriptor` is used to specify a list of formats the texture can be re-interpreted to in a texture view. Currently only changing srgb-ness is allowed (ex. `Rgba8Unorm` <=> `Rgba8UnormSrgb`). You should set `view_formats` to `&[]` (empty) unless you have a specific reason not to.
#### The DirectX Shader Compiler (DXC) is now supported on DX12
DXC is now the default shader compiler when using the DX12 backend. DXC is Microsoft's replacement for their legacy FXC compiler, and is faster, less buggy, and allows for modern shader features to be used (ShaderModel 6.0+). DXC requires `dxcompiler.dll` and `dxil.dll` to be available, otherwise it will log a warning and fall back to FXC.
You can get `dxcompiler.dll` and `dxil.dll` by downloading the latest release from [Microsoft's DirectXShaderCompiler github repo](https://github.com/microsoft/DirectXShaderCompiler/releases/latest) and copying them into your project's root directory. These must be included when you distribute your Bevy game/app/etc if you plan on supporting the DX12 backend and are using DXC.
`WgpuSettings` now has a `dx12_shader_compiler` field which can be used to choose between either FXC or DXC (if you pass None for the paths for DXC, it will check for the .dlls in the working directory).
2023-01-29 20:27:30 +00:00
|
|
|
let dx12_compiler =
|
|
|
|
wgpu::util::dx12_shader_compiler_from_env().unwrap_or(Dx12Compiler::Dxc {
|
|
|
|
dxil_path: None,
|
|
|
|
dxc_path: None,
|
|
|
|
});
|
|
|
|
|
2023-12-14 02:45:47 +00:00
|
|
|
let gles3_minor_version = wgpu::util::gles_minor_version_from_env().unwrap_or_default();
|
|
|
|
|
|
|
|
let instance_flags = InstanceFlags::default().with_env();
|
|
|
|
|
2021-12-09 21:14:17 +00:00
|
|
|
Self {
|
|
|
|
device_label: Default::default(),
|
|
|
|
backends,
|
2023-08-18 20:18:15 +00:00
|
|
|
power_preference,
|
2022-01-04 20:08:12 +00:00
|
|
|
priority,
|
2021-12-09 21:14:17 +00:00
|
|
|
features: wgpu::Features::TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES,
|
2022-02-13 04:24:52 +00:00
|
|
|
disabled_features: None,
|
2021-12-09 21:14:17 +00:00
|
|
|
limits,
|
2022-02-13 04:24:52 +00:00
|
|
|
constrained_limits: None,
|
Wgpu 0.15 (#7356)
# Objective
Update Bevy to wgpu 0.15.
## Changelog
- Update to wgpu 0.15, wgpu-hal 0.15.1, and naga 0.11
- Users can now use the [DirectX Shader Compiler](https://github.com/microsoft/DirectXShaderCompiler) (DXC) on Windows with DX12 for faster shader compilation and ShaderModel 6.0+ support (requires `dxcompiler.dll` and `dxil.dll`, which are included in DXC downloads from [here](https://github.com/microsoft/DirectXShaderCompiler/releases/latest))
## Migration Guide
### WGSL Top-Level `let` is now `const`
All top level constants are now declared with `const`, catching up with the wgsl spec.
`let` is no longer allowed at the global scope, only within functions.
```diff
-let SOME_CONSTANT = 12.0;
+const SOME_CONSTANT = 12.0;
```
#### `TextureDescriptor` and `SurfaceConfiguration` now requires a `view_formats` field
The new `view_formats` field in the `TextureDescriptor` is used to specify a list of formats the texture can be re-interpreted to in a texture view. Currently only changing srgb-ness is allowed (ex. `Rgba8Unorm` <=> `Rgba8UnormSrgb`). You should set `view_formats` to `&[]` (empty) unless you have a specific reason not to.
#### The DirectX Shader Compiler (DXC) is now supported on DX12
DXC is now the default shader compiler when using the DX12 backend. DXC is Microsoft's replacement for their legacy FXC compiler, and is faster, less buggy, and allows for modern shader features to be used (ShaderModel 6.0+). DXC requires `dxcompiler.dll` and `dxil.dll` to be available, otherwise it will log a warning and fall back to FXC.
You can get `dxcompiler.dll` and `dxil.dll` by downloading the latest release from [Microsoft's DirectXShaderCompiler github repo](https://github.com/microsoft/DirectXShaderCompiler/releases/latest) and copying them into your project's root directory. These must be included when you distribute your Bevy game/app/etc if you plan on supporting the DX12 backend and are using DXC.
`WgpuSettings` now has a `dx12_shader_compiler` field which can be used to choose between either FXC or DXC (if you pass None for the paths for DXC, it will check for the .dlls in the working directory).
2023-01-29 20:27:30 +00:00
|
|
|
dx12_shader_compiler: dx12_compiler,
|
2023-12-14 02:45:47 +00:00
|
|
|
gles3_minor_version,
|
|
|
|
instance_flags,
|
2024-08-12 16:55:18 +00:00
|
|
|
memory_hints: MemoryHints::default(),
|
Replace the `wgpu_trace` feature with a field in `bevy_render::settings::WgpuSettings` (#14842)
# Objective
- Remove the `wgpu_trace` feature while still making it easy/possible to
record wgpu traces for debugging.
- Close #14725.
- Get a taste of the bevy codebase. :P
## Solution
This PR performs the above objective by removing the `wgpu_trace`
feature from all `Cargo.toml` files.
However, wgpu traces are still useful for debugging - but to record
them, you need to pass in a directory path to store the traces in. To
avoid forcing users into manually creating the renderer,
`bevy_render::settings::WgpuSettings` now has a `trace_path` field, so
that all of Bevy's automatic initialization can happen while still
allowing for tracing.
## Testing
- Did you test these changes? If so, how?
- I have tested these changes, but only via running `cargo run -p ci`. I
am hoping the Github Actions workflows will catch anything I missed.
- Are there any parts that need more testing?
- I do not believe so.
- How can other people (reviewers) test your changes? Is there anything
specific they need to know?
- If you want to test these changes, I have updated the debugging guide
(`docs/debugging.md`) section on WGPU Tracing.
- If relevant, what platforms did you test these changes on, and are
there any important ones you can't test?
- I ran the above command on a Windows 10 64-bit (x64) machine, using
the `stable-x86_64-pc-windows-msvc` toolchain. I do not have anything
set up for other platforms or targets (though I can't imagine this needs
testing on other platforms).
---
## Migration Guide
1. The `bevy/wgpu_trace`, `bevy_render/wgpu_trace`, and
`bevy_internal/wgpu_trace` features no longer exist. Remove them from
your `Cargo.toml`, CI, tooling, and what-not.
2. Follow the instructions in the updated `docs/debugging.md` file in
the repository, under the WGPU Tracing section.
Because of the changes made, you can now generate traces to any path,
rather than the hardcoded `%WorkspaceRoot%/wgpu_trace` (where
`%WorkspaceRoot%` is... the root of your crate's workspace) folder.
(If WGPU hasn't restored tracing functionality...) Do note that WGPU has
not yet restored tracing functionality. However, once it does, the above
should be sufficient to generate new traces.
---------
Co-authored-by: TrialDragon <31419708+TrialDragon@users.noreply.github.com>
2024-08-25 14:16:11 +00:00
|
|
|
trace_path: None,
|
2021-12-09 21:14:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-01-04 20:08:12 +00:00
|
|
|
|
2024-11-22 22:32:04 +00:00
|
|
|
#[derive(Clone)]
|
|
|
|
pub struct RenderResources(
|
|
|
|
pub RenderDevice,
|
|
|
|
pub RenderQueue,
|
|
|
|
pub RenderAdapterInfo,
|
|
|
|
pub RenderAdapter,
|
|
|
|
pub RenderInstance,
|
|
|
|
);
|
|
|
|
|
2023-09-26 19:35:08 +00:00
|
|
|
/// An enum describing how the renderer will initialize resources. This is used when creating the [`RenderPlugin`](crate::RenderPlugin).
|
|
|
|
pub enum RenderCreation {
|
|
|
|
/// Allows renderer resource initialization to happen outside of the rendering plugin.
|
2024-11-22 22:32:04 +00:00
|
|
|
Manual(RenderResources),
|
2023-09-26 19:35:08 +00:00
|
|
|
/// Lets the rendering plugin create resources itself.
|
|
|
|
Automatic(WgpuSettings),
|
|
|
|
}
|
|
|
|
|
|
|
|
impl RenderCreation {
|
|
|
|
/// Function to create a [`RenderCreation::Manual`] variant.
|
|
|
|
pub fn manual(
|
|
|
|
device: RenderDevice,
|
|
|
|
queue: RenderQueue,
|
|
|
|
adapter_info: RenderAdapterInfo,
|
|
|
|
adapter: RenderAdapter,
|
|
|
|
instance: RenderInstance,
|
|
|
|
) -> Self {
|
2024-11-22 22:32:04 +00:00
|
|
|
RenderResources(device, queue, adapter_info, adapter, instance).into()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<RenderResources> for RenderCreation {
|
|
|
|
fn from(value: RenderResources) -> Self {
|
|
|
|
Self::Manual(value)
|
2023-09-26 19:35:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for RenderCreation {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self::Automatic(Default::default())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<WgpuSettings> for RenderCreation {
|
|
|
|
fn from(value: WgpuSettings) -> Self {
|
|
|
|
Self::Automatic(value)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-16 21:17:37 +00:00
|
|
|
/// Get a features/limits priority from the environment variable `WGPU_SETTINGS_PRIO`
|
|
|
|
pub fn settings_priority_from_env() -> Option<WgpuSettingsPriority> {
|
2022-01-04 20:08:12 +00:00
|
|
|
Some(
|
2022-02-16 21:17:37 +00:00
|
|
|
match std::env::var("WGPU_SETTINGS_PRIO")
|
2022-01-04 20:08:12 +00:00
|
|
|
.as_deref()
|
|
|
|
.map(str::to_lowercase)
|
|
|
|
.as_deref()
|
|
|
|
{
|
2022-02-16 21:17:37 +00:00
|
|
|
Ok("compatibility") => WgpuSettingsPriority::Compatibility,
|
|
|
|
Ok("functionality") => WgpuSettingsPriority::Functionality,
|
|
|
|
Ok("webgl2") => WgpuSettingsPriority::WebGL2,
|
2022-01-04 20:08:12 +00:00
|
|
|
_ => return None,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
}
|