Skip to content

Commit

Permalink
Merge pull request #1789 from ElhamAryanpur/master
Browse files Browse the repository at this point in the history
Update `wgpu` to `0.15`
  • Loading branch information
hecrj authored Apr 13, 2023
2 parents 2be79d7 + db4b899 commit cf35c85
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 20 deletions.
2 changes: 1 addition & 1 deletion examples/integration_wgpu/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ publish = false
[dependencies]
iced_winit = { path = "../../winit" }
iced_wgpu = { path = "../../wgpu", features = ["webgl"] }
env_logger = "0.8"
env_logger = "0.10"

[target.'cfg(target_arch = "wasm32")'.dependencies]
console_error_panic_hook = "0.1.7"
Expand Down
35 changes: 22 additions & 13 deletions examples/integration_wgpu/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ use web_sys::HtmlCanvasElement;
#[cfg(target_arch = "wasm32")]
use winit::platform::web::WindowBuilderExtWebSys;

pub fn main() {
pub fn main() -> Result<(), Box<dyn std::error::Error>> {
#[cfg(target_arch = "wasm32")]
let canvas_element = {
console_log::init_with_level(log::Level::Debug)
.expect("could not initialize logger");
console_log::init_with_level(log::Level::Debug)?;

std::panic::set_hook(Box::new(console_error_panic_hook::hook));

web_sys::window()
Expand All @@ -45,11 +45,10 @@ pub fn main() {
#[cfg(target_arch = "wasm32")]
let window = winit::window::WindowBuilder::new()
.with_canvas(Some(canvas_element))
.build(&event_loop)
.expect("Failed to build winit window");
.build(&event_loop)?;

#[cfg(not(target_arch = "wasm32"))]
let window = winit::window::Window::new(&event_loop).unwrap();
let window = winit::window::Window::new(&event_loop)?;

let physical_size = window.inner_size();
let mut viewport = Viewport::with_physical_size(
Expand All @@ -61,7 +60,6 @@ pub fn main() {
let mut clipboard = Clipboard::connect(&window);

// Initialize wgpu

#[cfg(target_arch = "wasm32")]
let default_backend = wgpu::Backends::GL;
#[cfg(not(target_arch = "wasm32"))]
Expand All @@ -70,8 +68,12 @@ 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) }?;

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

let capabilities = surface.get_capabilities(&adapter);

(
surface
.get_supported_formats(&adapter)
.first()
capabilities
.formats
.iter()
.filter(|format| format.describe().srgb)
.copied()
.next()
.or_else(|| capabilities.formats.first().copied())
.expect("Get preferred format"),
adapter
.request_device(
Expand All @@ -120,6 +127,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 +222,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: &[],
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: &[],
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: &[],
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
});

Expand All @@ -232,6 +233,7 @@ impl Targets {
sample_count: 1,
dimension: wgpu::TextureDimension::D2,
format,
view_formats: &[],
usage: wgpu::TextureUsages::RENDER_ATTACHMENT
| wgpu::TextureUsages::TEXTURE_BINDING,
});
Expand Down
26 changes: 22 additions & 4 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 @@ -46,7 +49,7 @@ impl<Theme> Compositor<Theme> {

#[allow(unsafe_code)]
let compatible_surface = compatible_window
.map(|window| unsafe { instance.create_surface(window) });
.and_then(|window| unsafe { instance.create_surface(window).ok() });

let adapter = instance
.request_adapter(&wgpu::RequestAdapterOptions {
Expand All @@ -63,7 +66,19 @@ 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()
let capabilities = surface.get_capabilities(&adapter);

capabilities
.formats
.iter()
.filter(|format| format.describe().srgb)
.copied()
.next()
.or_else(|| {
log::warn!("No sRGB format found!");

capabilities.formats.first().copied()
})
})?;

log::info!("Selected format: {:?}", format);
Expand Down Expand Up @@ -144,7 +159,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("Create surface")
}
}

Expand All @@ -163,6 +180,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 cf35c85

Please sign in to comment.