2021-12-09 21:14:17 +00:00
|
|
|
use std::borrow::Cow;
|
|
|
|
|
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::{
|
|
|
|
Backends, Dx12Compiler, Features as WgpuFeatures, Limits as WgpuLimits, PowerPreference,
|
|
|
|
};
|
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,
|
|
|
|
}
|
|
|
|
|
2022-02-16 21:17:37 +00:00
|
|
|
/// Provides configuration for renderer initialization. Use [`RenderDevice::features`](crate::renderer::RenderDevice::features),
|
2022-12-26 19:47:01 +00:00
|
|
|
/// [`RenderDevice::limits`](crate::renderer::RenderDevice::limits), and the [`RenderAdapterInfo`](crate::renderer::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,
|
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 {
|
2021-12-29 21:04:28 +00:00
|
|
|
let default_backends = if cfg!(feature = "webgl") {
|
2021-12-09 21:14:17 +00:00
|
|
|
Backends::GL
|
|
|
|
} else {
|
|
|
|
Backends::PRIMARY
|
|
|
|
};
|
|
|
|
|
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
|
|
|
|
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
|
|
|
|
2022-02-16 21:17:37 +00:00
|
|
|
let limits = if cfg!(feature = "webgl") || matches!(priority, WgpuSettingsPriority::WebGL2)
|
|
|
|
{
|
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,
|
|
|
|
});
|
|
|
|
|
2021-12-09 21:14:17 +00:00
|
|
|
Self {
|
|
|
|
device_label: Default::default(),
|
|
|
|
backends,
|
|
|
|
power_preference: PowerPreference::HighPerformance,
|
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,
|
2021-12-09 21:14:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-01-04 20:08:12 +00:00
|
|
|
|
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,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
}
|