Skip to content

Commit

Permalink
Updated wgpu to 0.15 in iced_wgpu and integration_wgpu
Browse files Browse the repository at this point in the history
  • Loading branch information
ElhamAryanpur committed Apr 12, 2023
1 parent adb70d2 commit 56db032
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 15 deletions.
9 changes: 7 additions & 2 deletions examples/integration_wgpu/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,19 @@ publish = false
[dependencies]
iced_winit = { path = "../../winit" }
iced_wgpu = { path = "../../wgpu", features = ["webgl"] }
env_logger = "0.8"
env_logger = "0.10.0"

[target.'cfg(target_arch = "wasm32")'.dependencies]
console_error_panic_hook = "0.1.7"
console_log = "0.2.0"
log = "0.4"
wasm-bindgen = "0.2"
web-sys = { version = "0.3", features = ["Element", "HtmlCanvasElement", "Window", "Document"] }
web-sys = { version = "0.3", features = [
"Element",
"HtmlCanvasElement",
"Window",
"Document",
] }
# This dependency a little bit quirky, it is deep in the tree and without `js` feature it
# refuses to work with `wasm32-unknown-unknown target`. Unfortunately, we need this patch
# to make it work
Expand Down
35 changes: 29 additions & 6 deletions examples/integration_wgpu/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,15 @@ pub fn main() {
let backend =
wgpu::util::backend_bits_from_env().unwrap_or(default_backend);

let instance = wgpu::Instance::new(backend);
let surface = unsafe { instance.create_surface(&window) };
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor {
backends: backend,
..Default::default()
});
let surface = unsafe {
instance
.create_surface(&window)
.expect("Couldn't create surface")
};

let (format, (device, queue)) = futures::executor::block_on(async {
let adapter = wgpu::util::initialize_adapter_from_env_or_default(
Expand All @@ -91,12 +98,26 @@ pub fn main() {
#[cfg(not(target_arch = "wasm32"))]
let needed_limits = wgpu::Limits::default();

/*
formerly:
surface
.get_supported_formats(&adapter)
.first()
.copied()
.expect("Get preferred format"),
*/

let surface_caps = surface.get_capabilities(&adapter);
(
surface
.get_supported_formats(&adapter)
.first()
.get_capabilities(&adapter)
.formats
.iter()
.copied()
.expect("Get preferred format"),
.filter(|f| f.describe().srgb)
.next()
.unwrap_or(surface_caps.formats[0]),
adapter
.request_device(
&wgpu::DeviceDescriptor {
Expand All @@ -120,6 +141,7 @@ pub fn main() {
height: physical_size.height,
present_mode: wgpu::PresentMode::AutoVsync,
alpha_mode: wgpu::CompositeAlphaMode::Auto,
view_formats: vec![],
},
);

Expand Down Expand Up @@ -214,7 +236,8 @@ pub fn main() {
width: size.width,
height: size.height,
present_mode: wgpu::PresentMode::AutoVsync,
alpha_mode: wgpu::CompositeAlphaMode::Auto
alpha_mode: wgpu::CompositeAlphaMode::Auto,
view_formats: vec![]
},
);

Expand Down
4 changes: 2 additions & 2 deletions wgpu/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ spirv = ["wgpu/spirv"]
webgl = ["wgpu/webgl"]

[dependencies]
wgpu = "0.14"
wgpu_glyph = "0.18"
wgpu = "0.15"
wgpu_glyph = "0.19"
glyph_brush = "0.7"
raw-window-handle = "0.5"
log = "0.4"
Expand Down
2 changes: 2 additions & 0 deletions wgpu/src/image/atlas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ impl Atlas {
sample_count: 1,
dimension: wgpu::TextureDimension::D2,
format: wgpu::TextureFormat::Rgba8UnormSrgb,
view_formats: &[wgpu::TextureFormat::Rgba8UnormSrgb],
usage: wgpu::TextureUsages::COPY_DST
| wgpu::TextureUsages::COPY_SRC
| wgpu::TextureUsages::TEXTURE_BINDING,
Expand Down Expand Up @@ -247,6 +248,7 @@ impl Atlas {
sample_count: 1,
dimension: wgpu::TextureDimension::D2,
format: wgpu::TextureFormat::Rgba8UnormSrgb,
view_formats: &[wgpu::TextureFormat::Rgba8UnormSrgb],
usage: wgpu::TextureUsages::COPY_DST
| wgpu::TextureUsages::COPY_SRC
| wgpu::TextureUsages::TEXTURE_BINDING,
Expand Down
2 changes: 2 additions & 0 deletions wgpu/src/triangle/msaa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ impl Targets {
sample_count,
dimension: wgpu::TextureDimension::D2,
format,
view_formats: &[format],
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
});

Expand All @@ -232,6 +233,7 @@ impl Targets {
sample_count: 1,
dimension: wgpu::TextureDimension::D2,
format,
view_formats: &[format],
usage: wgpu::TextureUsages::RENDER_ATTACHMENT
| wgpu::TextureUsages::TEXTURE_BINDING,
});
Expand Down
27 changes: 22 additions & 5 deletions wgpu/src/window/compositor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ impl<Theme> Compositor<Theme> {
settings: Settings,
compatible_window: Option<&W>,
) -> Option<Self> {
let instance = wgpu::Instance::new(settings.internal_backend);
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor {
backends: settings.internal_backend,
..Default::default()
});

log::info!("{:#?}", settings);

Expand All @@ -45,8 +48,11 @@ impl<Theme> Compositor<Theme> {
}

#[allow(unsafe_code)]
let compatible_surface = compatible_window
.map(|window| unsafe { instance.create_surface(window) });
let compatible_surface = compatible_window.map(|window| unsafe {
instance
.create_surface(window)
.expect("Couldn't create surface")
});

let adapter = instance
.request_adapter(&wgpu::RequestAdapterOptions {
Expand All @@ -63,7 +69,15 @@ impl<Theme> Compositor<Theme> {
log::info!("Selected: {:#?}", adapter.get_info());

let format = compatible_surface.as_ref().and_then(|surface| {
surface.get_supported_formats(&adapter).first().copied()
// formerly: surface.get_supported_formats(&adapter).first().copied()
// now have to get capacities to get format
let surface_caps = surface.get_capabilities(&adapter);
surface_caps
.formats
.iter()
.copied()
.filter(|f| f.describe().srgb)
.next()
})?;

log::info!("Selected format: {:?}", format);
Expand Down Expand Up @@ -144,7 +158,9 @@ impl<Theme> iced_graphics::window::Compositor for Compositor<Theme> {
) -> wgpu::Surface {
#[allow(unsafe_code)]
unsafe {
self.instance.create_surface(window)
self.instance
.create_surface(window)
.expect("Couldn't create surface")
}
}

Expand All @@ -163,6 +179,7 @@ impl<Theme> iced_graphics::window::Compositor for Compositor<Theme> {
width,
height,
alpha_mode: wgpu::CompositeAlphaMode::Auto,
view_formats: vec![],
},
);
}
Expand Down

0 comments on commit 56db032

Please sign in to comment.