Update wgpu to 0.15
This commit is contained in:
parent
adb70d232a
commit
d5453c62e9
5 changed files with 50 additions and 20 deletions
|
|
@ -23,18 +23,17 @@ use web_sys::HtmlCanvasElement;
|
||||||
#[cfg(target_arch = "wasm32")]
|
#[cfg(target_arch = "wasm32")]
|
||||||
use winit::platform::web::WindowBuilderExtWebSys;
|
use winit::platform::web::WindowBuilderExtWebSys;
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
#[cfg(target_arch = "wasm32")]
|
#[cfg(target_arch = "wasm32")]
|
||||||
let canvas_element = {
|
let canvas_element = {
|
||||||
console_log::init_with_level(log::Level::Debug)
|
console_log::init_with_level(log::Level::Debug)?;
|
||||||
.expect("could not initialize logger");
|
|
||||||
std::panic::set_hook(Box::new(console_error_panic_hook::hook));
|
std::panic::set_hook(Box::new(console_error_panic_hook::hook));
|
||||||
|
|
||||||
web_sys::window()
|
web_sys::window()
|
||||||
.and_then(|win| win.document())
|
.and_then(|win| win.document())
|
||||||
.and_then(|doc| doc.get_element_by_id("iced_canvas"))
|
.and_then(|doc| doc.get_element_by_id("iced_canvas"))
|
||||||
.and_then(|element| element.dyn_into::<HtmlCanvasElement>().ok())
|
.and_then(|element| element.dyn_into::<HtmlCanvasElement>().ok())?
|
||||||
.expect("Canvas with id `iced_canvas` is missing")
|
|
||||||
};
|
};
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
env_logger::init();
|
env_logger::init();
|
||||||
|
|
@ -45,11 +44,10 @@ pub fn main() {
|
||||||
#[cfg(target_arch = "wasm32")]
|
#[cfg(target_arch = "wasm32")]
|
||||||
let window = winit::window::WindowBuilder::new()
|
let window = winit::window::WindowBuilder::new()
|
||||||
.with_canvas(Some(canvas_element))
|
.with_canvas(Some(canvas_element))
|
||||||
.build(&event_loop)
|
.build(&event_loop)?;
|
||||||
.expect("Failed to build winit window");
|
|
||||||
|
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
#[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 physical_size = window.inner_size();
|
||||||
let mut viewport = Viewport::with_physical_size(
|
let mut viewport = Viewport::with_physical_size(
|
||||||
|
|
@ -61,7 +59,6 @@ pub fn main() {
|
||||||
let mut clipboard = Clipboard::connect(&window);
|
let mut clipboard = Clipboard::connect(&window);
|
||||||
|
|
||||||
// Initialize wgpu
|
// Initialize wgpu
|
||||||
|
|
||||||
#[cfg(target_arch = "wasm32")]
|
#[cfg(target_arch = "wasm32")]
|
||||||
let default_backend = wgpu::Backends::GL;
|
let default_backend = wgpu::Backends::GL;
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
|
|
@ -70,8 +67,12 @@ pub fn main() {
|
||||||
let backend =
|
let backend =
|
||||||
wgpu::util::backend_bits_from_env().unwrap_or(default_backend);
|
wgpu::util::backend_bits_from_env().unwrap_or(default_backend);
|
||||||
|
|
||||||
let instance = wgpu::Instance::new(backend);
|
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor {
|
||||||
let surface = unsafe { instance.create_surface(&window) };
|
backends: backend,
|
||||||
|
..Default::default()
|
||||||
|
});
|
||||||
|
|
||||||
|
let surface = unsafe { instance.create_surface(&window) }?;
|
||||||
|
|
||||||
let (format, (device, queue)) = futures::executor::block_on(async {
|
let (format, (device, queue)) = futures::executor::block_on(async {
|
||||||
let adapter = wgpu::util::initialize_adapter_from_env_or_default(
|
let adapter = wgpu::util::initialize_adapter_from_env_or_default(
|
||||||
|
|
@ -93,9 +94,15 @@ pub fn main() {
|
||||||
|
|
||||||
(
|
(
|
||||||
surface
|
surface
|
||||||
.get_supported_formats(&adapter)
|
.get_capabilities(&adapter)
|
||||||
.first()
|
.formats
|
||||||
|
.iter()
|
||||||
|
.filter(|format| format.describe().srgb)
|
||||||
.copied()
|
.copied()
|
||||||
|
.next()
|
||||||
|
.or_else(|| {
|
||||||
|
surface.get_capabilities(&adapter).formats.first().copied()
|
||||||
|
})
|
||||||
.expect("Get preferred format"),
|
.expect("Get preferred format"),
|
||||||
adapter
|
adapter
|
||||||
.request_device(
|
.request_device(
|
||||||
|
|
@ -120,6 +127,7 @@ pub fn main() {
|
||||||
height: physical_size.height,
|
height: physical_size.height,
|
||||||
present_mode: wgpu::PresentMode::AutoVsync,
|
present_mode: wgpu::PresentMode::AutoVsync,
|
||||||
alpha_mode: wgpu::CompositeAlphaMode::Auto,
|
alpha_mode: wgpu::CompositeAlphaMode::Auto,
|
||||||
|
view_formats: vec![],
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -214,7 +222,8 @@ pub fn main() {
|
||||||
width: size.width,
|
width: size.width,
|
||||||
height: size.height,
|
height: size.height,
|
||||||
present_mode: wgpu::PresentMode::AutoVsync,
|
present_mode: wgpu::PresentMode::AutoVsync,
|
||||||
alpha_mode: wgpu::CompositeAlphaMode::Auto
|
alpha_mode: wgpu::CompositeAlphaMode::Auto,
|
||||||
|
view_formats: vec![]
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -28,8 +28,8 @@ spirv = ["wgpu/spirv"]
|
||||||
webgl = ["wgpu/webgl"]
|
webgl = ["wgpu/webgl"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
wgpu = "0.14"
|
wgpu = "0.15"
|
||||||
wgpu_glyph = "0.18"
|
wgpu_glyph = "0.19"
|
||||||
glyph_brush = "0.7"
|
glyph_brush = "0.7"
|
||||||
raw-window-handle = "0.5"
|
raw-window-handle = "0.5"
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,7 @@ impl Atlas {
|
||||||
sample_count: 1,
|
sample_count: 1,
|
||||||
dimension: wgpu::TextureDimension::D2,
|
dimension: wgpu::TextureDimension::D2,
|
||||||
format: wgpu::TextureFormat::Rgba8UnormSrgb,
|
format: wgpu::TextureFormat::Rgba8UnormSrgb,
|
||||||
|
view_formats: &[],
|
||||||
usage: wgpu::TextureUsages::COPY_DST
|
usage: wgpu::TextureUsages::COPY_DST
|
||||||
| wgpu::TextureUsages::COPY_SRC
|
| wgpu::TextureUsages::COPY_SRC
|
||||||
| wgpu::TextureUsages::TEXTURE_BINDING,
|
| wgpu::TextureUsages::TEXTURE_BINDING,
|
||||||
|
|
@ -247,6 +248,7 @@ impl Atlas {
|
||||||
sample_count: 1,
|
sample_count: 1,
|
||||||
dimension: wgpu::TextureDimension::D2,
|
dimension: wgpu::TextureDimension::D2,
|
||||||
format: wgpu::TextureFormat::Rgba8UnormSrgb,
|
format: wgpu::TextureFormat::Rgba8UnormSrgb,
|
||||||
|
view_formats: &[],
|
||||||
usage: wgpu::TextureUsages::COPY_DST
|
usage: wgpu::TextureUsages::COPY_DST
|
||||||
| wgpu::TextureUsages::COPY_SRC
|
| wgpu::TextureUsages::COPY_SRC
|
||||||
| wgpu::TextureUsages::TEXTURE_BINDING,
|
| wgpu::TextureUsages::TEXTURE_BINDING,
|
||||||
|
|
|
||||||
|
|
@ -222,6 +222,7 @@ impl Targets {
|
||||||
sample_count,
|
sample_count,
|
||||||
dimension: wgpu::TextureDimension::D2,
|
dimension: wgpu::TextureDimension::D2,
|
||||||
format,
|
format,
|
||||||
|
view_formats: &[],
|
||||||
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
|
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -232,6 +233,7 @@ impl Targets {
|
||||||
sample_count: 1,
|
sample_count: 1,
|
||||||
dimension: wgpu::TextureDimension::D2,
|
dimension: wgpu::TextureDimension::D2,
|
||||||
format,
|
format,
|
||||||
|
view_formats: &[],
|
||||||
usage: wgpu::TextureUsages::RENDER_ATTACHMENT
|
usage: wgpu::TextureUsages::RENDER_ATTACHMENT
|
||||||
| wgpu::TextureUsages::TEXTURE_BINDING,
|
| wgpu::TextureUsages::TEXTURE_BINDING,
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,10 @@ impl<Theme> Compositor<Theme> {
|
||||||
settings: Settings,
|
settings: Settings,
|
||||||
compatible_window: Option<&W>,
|
compatible_window: Option<&W>,
|
||||||
) -> Option<Self> {
|
) -> 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);
|
log::info!("{:#?}", settings);
|
||||||
|
|
||||||
|
|
@ -46,7 +49,7 @@ impl<Theme> Compositor<Theme> {
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
let compatible_surface = compatible_window
|
let compatible_surface = compatible_window
|
||||||
.map(|window| unsafe { instance.create_surface(window) });
|
.and_then(|window| unsafe { instance.create_surface(window).ok() });
|
||||||
|
|
||||||
let adapter = instance
|
let adapter = instance
|
||||||
.request_adapter(&wgpu::RequestAdapterOptions {
|
.request_adapter(&wgpu::RequestAdapterOptions {
|
||||||
|
|
@ -63,7 +66,18 @@ impl<Theme> Compositor<Theme> {
|
||||||
log::info!("Selected: {:#?}", adapter.get_info());
|
log::info!("Selected: {:#?}", adapter.get_info());
|
||||||
|
|
||||||
let format = compatible_surface.as_ref().and_then(|surface| {
|
let format = compatible_surface.as_ref().and_then(|surface| {
|
||||||
surface.get_supported_formats(&adapter).first().copied()
|
surface
|
||||||
|
.get_capabilities(&adapter)
|
||||||
|
.formats
|
||||||
|
.iter()
|
||||||
|
.filter(|format| format.describe().srgb)
|
||||||
|
.copied()
|
||||||
|
.next()
|
||||||
|
.or_else(|| {
|
||||||
|
log::warn!("No sRGB format found!");
|
||||||
|
|
||||||
|
surface.get_capabilities(&adapter).formats.first().copied()
|
||||||
|
})
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
log::info!("Selected format: {:?}", format);
|
log::info!("Selected format: {:?}", format);
|
||||||
|
|
@ -144,7 +158,9 @@ impl<Theme> iced_graphics::window::Compositor for Compositor<Theme> {
|
||||||
) -> wgpu::Surface {
|
) -> wgpu::Surface {
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
unsafe {
|
unsafe {
|
||||||
self.instance.create_surface(window)
|
self.instance
|
||||||
|
.create_surface(window)
|
||||||
|
.expect("Create surface")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -163,6 +179,7 @@ impl<Theme> iced_graphics::window::Compositor for Compositor<Theme> {
|
||||||
width,
|
width,
|
||||||
height,
|
height,
|
||||||
alpha_mode: wgpu::CompositeAlphaMode::Auto,
|
alpha_mode: wgpu::CompositeAlphaMode::Auto,
|
||||||
|
view_formats: vec![],
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue