bevy/crates/bevy_render/src/options.rs
Michael Dorst 130953c717 Enable the doc_markdown clippy lint (#3457)
# Objective

CI should check for missing backticks in doc comments.

Fixes #3435

## Solution

`clippy` has a lint for this: `doc_markdown`. This enables that lint in the CI script.

Of course, enabling this lint in CI causes a bunch of lint errors, so I've gone through and fixed all of them. This was a huge edit that touched a ton of files, so I split the PR up by crate.

When all of the following are merged, the CI should pass and this can be merged.

+ [x] #3467
+ [x] #3468
+ [x] #3470 
+ [x] #3469
+ [x] #3471 
+ [x] #3472 
+ [x] #3473 
+ [x] #3474 
+ [x] #3475 
+ [x] #3476 
+ [x] #3477 
+ [x] #3478 
+ [x] #3479 
+ [x] #3480 
+ [x] #3481 
+ [x] #3482 
+ [x] #3483 
+ [x] #3484 
+ [x] #3485 
+ [x] #3486
2022-01-09 23:20:13 +00:00

72 lines
2.2 KiB
Rust

use std::borrow::Cow;
pub use wgpu::{Backends, Features as WgpuFeatures, Limits as WgpuLimits, PowerPreference};
#[derive(Clone)]
pub enum WgpuOptionsPriority {
Compatibility,
Functionality,
WebGL2,
}
#[derive(Clone)]
pub struct WgpuOptions {
pub device_label: Option<Cow<'static, str>>,
pub backends: Option<Backends>,
pub power_preference: PowerPreference,
pub priority: WgpuOptionsPriority,
pub features: WgpuFeatures,
pub limits: WgpuLimits,
}
impl Default for WgpuOptions {
fn default() -> Self {
let default_backends = if cfg!(feature = "webgl") {
Backends::GL
} else {
Backends::PRIMARY
};
let backends = Some(wgpu::util::backend_bits_from_env().unwrap_or(default_backends));
let priority = options_priority_from_env().unwrap_or(WgpuOptionsPriority::Functionality);
let limits = if cfg!(feature = "webgl") || matches!(priority, WgpuOptionsPriority::WebGL2) {
wgpu::Limits::downlevel_webgl2_defaults()
} else {
#[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
};
Self {
device_label: Default::default(),
backends,
power_preference: PowerPreference::HighPerformance,
priority,
features: wgpu::Features::TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES,
limits,
}
}
}
/// Get a features/limits priority from the environment variable `WGPU_OPTIONS_PRIO`
pub fn options_priority_from_env() -> Option<WgpuOptionsPriority> {
Some(
match std::env::var("WGPU_OPTIONS_PRIO")
.as_deref()
.map(str::to_lowercase)
.as_deref()
{
Ok("compatibility") => WgpuOptionsPriority::Compatibility,
Ok("functionality") => WgpuOptionsPriority::Functionality,
Ok("webgl2") => WgpuOptionsPriority::WebGL2,
_ => return None,
},
)
}