Skip to content

Commit

Permalink
Merge pull request #2182 from hannobraun/wgpu
Browse files Browse the repository at this point in the history
Upgrade to wgpu 0.19
  • Loading branch information
hannobraun authored Jan 29, 2024
2 parents a987359 + c99d92d commit a4a5f2c
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 94 deletions.
4 changes: 4 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[build]
# As of wgpu 0.19.1, these are necessary to build for WebGPU.
rustflags = ["--cfg=web_sys_unstable_apis"]
rustdocflags = ["--cfg=web_sys_unstable_apis"]
133 changes: 64 additions & 69 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions crates/fj-viewer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fj-interop.workspace = true
fj-math.workspace = true
nalgebra = "0.32.3"
tobj = "4.0.1"
raw-window-handle = "0.5.2"
raw-window-handle = "0.6.0"
thiserror = "1.0.53"
tracing = "0.1.40"

Expand All @@ -33,7 +33,7 @@ default-features = false
features = ["png", "jpeg"]

[dependencies.wgpu]
version = "0.18.0"
version = "0.19.1"
features = ["webgl"]

# We don't depend on `getrandom` directly, but we need this to enable the `js`
Expand Down
17 changes: 9 additions & 8 deletions crates/fj-viewer/src/graphics/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub struct Device {
impl Device {
pub async fn from_preferred_adapter(
instance: &wgpu::Instance,
surface: &wgpu::Surface,
surface: &wgpu::Surface<'_>,
) -> Result<(Self, wgpu::Adapter, wgpu::Features), DeviceError> {
let adapter = instance
.request_adapter(&wgpu::RequestAdapterOptions {
Expand All @@ -30,8 +30,9 @@ impl Device {
pub async fn try_from_all_adapters(
instance: &wgpu::Instance,
) -> Result<(Self, wgpu::Adapter, wgpu::Features), DeviceError> {
let mut all_adapters =
instance.enumerate_adapters(wgpu::Backends::all());
let mut all_adapters = instance
.enumerate_adapters(wgpu::Backends::all())
.into_iter();

let result = loop {
let Some(adapter) = all_adapters.next() else {
Expand Down Expand Up @@ -67,7 +68,7 @@ impl Device {
pub async fn new(
adapter: &wgpu::Adapter,
) -> Result<(Self, wgpu::Features), DeviceError> {
let features = {
let required_features = {
let desired_features = wgpu::Features::POLYGON_MODE_LINE;
let available_features = adapter.features();

Expand All @@ -82,7 +83,7 @@ impl Device {
desired_features.intersection(available_features)
};

let limits = {
let required_limits = {
// This is the lowest of the available defaults. It should guarantee
// that we can run pretty much everywhere.
let lowest_limits = wgpu::Limits::downlevel_webgl2_defaults();
Expand All @@ -98,14 +99,14 @@ impl Device {
.request_device(
&wgpu::DeviceDescriptor {
label: None,
features,
limits,
required_features,
required_limits,
},
None,
)
.await?;

Ok((Device { device, queue }, features))
Ok((Device { device, queue }, required_features))
}
}

Expand Down
Loading

0 comments on commit a4a5f2c

Please sign in to comment.