mirror of
https://github.com/gfx-rs/wgpu.git
synced 2026-04-22 03:02:01 -04:00
[rs] Print chosen adapter when running examples
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
<img align="right" width="25%" src="logo.png">
|
||||
|
||||
# wgpu-rs
|
||||
|
||||
[](https://github.com/gfx-rs/wgpu-rs/actions)
|
||||
[](https://crates.io/crates/wgpu)
|
||||
[](https://docs.rs/wgpu)
|
||||
|
||||
[](https://matrix.to/#/#wgpu:matrix.org)
|
||||
[](https://matrix.to/#/#wgpu:matrix.org)
|
||||
[](https://matrix.to/#/#wgpu-users:matrix.org)
|
||||
|
||||
wgpu-rs is an idiomatic Rust wrapper over [wgpu-core](https://github.com/gfx-rs/wgpu). It's designed to be suitable for general purpose graphics and computation needs of Rust community.
|
||||
@@ -32,6 +33,21 @@ The `hello*` examples show bare-bones setup without any helper code. For `hello-
|
||||
cargo run --example hello-compute 1 2 3 4
|
||||
```
|
||||
|
||||
The following environment variables can be used to configure how the framework examples run:
|
||||
|
||||
- `WGPU_BACKEND`
|
||||
|
||||
Options: `vulkan`, `metal`, `dx11`, `dx12`, `gl`, `webgpu`
|
||||
|
||||
If unset a default backend is chosen based on what is supported
|
||||
by your system.
|
||||
|
||||
- `WGPU_POWER_PREF`
|
||||
|
||||
Options: `low`, `high`
|
||||
|
||||
If unset a low power adapter is preferred.
|
||||
|
||||
#### Run Examples on the Web (`wasm32-unknown-unknown`)
|
||||
|
||||
Running on the web is still work-in-progress. You may need to enable experimental flags on your browser. Check browser implementation status on [webgpu.io](https://webgpu.io). Notably, `wgpu-rs` is often ahead in catching up with upstream WebGPU API changes. We keep the `gecko` branch pointing to the code that should work on latest Firefox.
|
||||
@@ -54,8 +70,8 @@ Create an `index.html` file into `target/generated` directory and add the follow
|
||||
```html
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
</head>
|
||||
<body>
|
||||
<script type="module">
|
||||
@@ -78,11 +94,11 @@ For now, the shaders can be compiled to SPIR-V by running `make`, which requires
|
||||
|
||||
## Logging
|
||||
|
||||
`wgpu-core` uses `tracing` for logging and `wgpu-rs` uses `log` for logging.
|
||||
`wgpu-core` uses `tracing` for logging and `wgpu-rs` uses `log` for logging.
|
||||
|
||||
### Simple Setup
|
||||
|
||||
If you just want log messages to show up and to use the chrome tracing infrastructure,
|
||||
If you just want log messages to show up and to use the chrome tracing infrastructure,
|
||||
take a dependency on the `wgpu-subscriber` crate then call `initialize_default_subscriber`. It will
|
||||
set up logging to stdout/stderr based on the `RUST_LOG` environment variable.
|
||||
|
||||
@@ -96,7 +112,7 @@ The `tracing_log` crate has a `log` logger to translate all events into `tracing
|
||||
|
||||
```rust
|
||||
tracing_log::LogTracer::init().unwrap()
|
||||
```
|
||||
```
|
||||
|
||||
#### `tracing` events -> `log` events
|
||||
|
||||
|
||||
@@ -121,6 +121,15 @@ async fn setup<E: Example>(title: &str) -> Setup {
|
||||
} else {
|
||||
wgpu::BackendBit::PRIMARY
|
||||
};
|
||||
let power_preference = if let Ok(power_preference) = std::env::var("WGPU_POWER_PREF") {
|
||||
match power_preference.to_lowercase().as_str() {
|
||||
"low" => wgpu::PowerPreference::LowPower,
|
||||
"high" => wgpu::PowerPreference::HighPerformance,
|
||||
other => panic!("Unknown power preference: {}", other),
|
||||
}
|
||||
} else {
|
||||
wgpu::PowerPreference::default()
|
||||
};
|
||||
let instance = wgpu::Instance::new(backend);
|
||||
let (size, surface) = unsafe {
|
||||
let size = window.inner_size();
|
||||
@@ -129,11 +138,18 @@ async fn setup<E: Example>(title: &str) -> Setup {
|
||||
};
|
||||
let adapter = instance
|
||||
.request_adapter(&wgpu::RequestAdapterOptions {
|
||||
power_preference: wgpu::PowerPreference::default(),
|
||||
power_preference,
|
||||
compatible_surface: Some(&surface),
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
{
|
||||
let adapter_info = adapter.get_info();
|
||||
println!("Using {} ({:?})", adapter_info.name, adapter_info.backend);
|
||||
}
|
||||
|
||||
let optional_features = E::optional_features();
|
||||
let required_features = E::required_features();
|
||||
let adapter_features = adapter.features();
|
||||
|
||||
Reference in New Issue
Block a user