From bf49c1a4f1bb0645ab5d448315dcda2c73849e00 Mon Sep 17 00:00:00 2001 From: Joshua Groves Date: Sat, 11 Apr 2020 11:40:47 -0230 Subject: [PATCH] Update to latest winit and wasm-bindgen --- Cargo.toml | 22 ++++++++++++---------- src/backend/web.rs | 42 ++++++++++++++++++++---------------------- src/lib.rs | 3 ++- 3 files changed, 34 insertions(+), 33 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 5ae3444b50..a75ea4be07 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -52,7 +52,7 @@ cgmath = "0.17" #glsl-to-spirv = "0.1" log = "0.4" png = "0.15" -winit = { version = "0.22", features = ["web-sys"] } +winit = { version = "0.22.1", features = ["web-sys"] } rand = { version = "0.7.2", features = ["wasm-bindgen"] } bytemuck = "1" futures = "0.3" @@ -62,12 +62,10 @@ name="hello-compute" path="examples/hello-compute/main.rs" test = true -#[patch.crates-io] +[patch.crates-io] #wgpu-types = { version = "0.5.0", path = "../wgpu/wgpu-types" } #wgpu-core = { version = "0.5.0", path = "../wgpu/wgpu-core" } #wgpu-native = { version = "0.5.0", path = "../wgpu/wgpu-native" } - -#[patch.crates-io] #gfx-hal = { version = "0.5.0", path = "../gfx/src/hal" } #gfx-backend-empty = { version = "0.5.0", path = "../gfx/src/backend/empty" } #gfx-backend-vulkan = { version = "0.5.0", path = "../gfx/src/backend/vulkan" } @@ -75,13 +73,17 @@ test = true #gfx-backend-dx11 = { version = "0.5.0", path = "../gfx/src/backend/dx11" } #gfx-descriptor = { version = "0.1.0", path = "../gfx-extras/gfx-descriptor" } #gfx-memory = { version = "0.1.0", path = "../gfx-extras/gfx-memory" } +wasm-bindgen = { git = "https://github.com/rustwasm/wasm-bindgen" } +wasm-bindgen-futures = { git = "https://github.com/rustwasm/wasm-bindgen" } +web-sys = { git = "https://github.com/rustwasm/wasm-bindgen" } +js-sys = { git = "https://github.com/rustwasm/wasm-bindgen" } [target.'cfg(not(target_arch = "wasm32"))'.dependencies] env_logger = "0.7" [target.'cfg(target_arch = "wasm32")'.dependencies] -wasm-bindgen = "0.2.59" -web-sys = { version = "0.3.36", features = [ +wasm-bindgen = "0.2.60" +web-sys = { version = "0.3.37", features = [ "Document", "Navigator", "Node", @@ -90,10 +92,10 @@ web-sys = { version = "0.3.36", features = [ "GpuAdapter", "GpuAddressMode", "GpuBindGroup", - "GpuBindGroupBinding", + "GpuBindGroupEntry", "GpuBindGroupDescriptor", "GpuBindGroupLayout", - "GpuBindGroupLayoutBinding", + "GpuBindGroupLayoutEntry", "GpuBindGroupLayoutDescriptor", "GpuBlendDescriptor", "GpuBlendFactor", @@ -167,8 +169,8 @@ web-sys = { version = "0.3.36", features = [ "HtmlCanvasElement", "Window", ]} -js-sys = "0.3.36" -wasm-bindgen-futures = "0.4.9" +js-sys = "0.3.37" +wasm-bindgen-futures = "0.4.10" [target.'cfg(target_arch = "wasm32")'.dev-dependencies] console_error_panic_hook = "0.1.6" diff --git a/src/backend/web.rs b/src/backend/web.rs index f067ac8da9..42fa91474f 100644 --- a/src/backend/web.rs +++ b/src/backend/web.rs @@ -132,18 +132,18 @@ pub(crate) fn create_bind_group_layout( _ => web_sys::GpuTextureViewDimension::N2d, }; - let mut mapped_binding = web_sys::GpuBindGroupLayoutBinding::new( + let mut mapped_entry = web_sys::GpuBindGroupLayoutEntry::new( bind.binding, mapped_type, bind.visibility.bits(), ); - mapped_binding.has_dynamic_offset(mapped_dynamic); - mapped_binding.multisampled(mapped_multisampled); - mapped_binding.texture_dimension(mapped_view_dimension); + mapped_entry.has_dynamic_offset(mapped_dynamic); + mapped_entry.multisampled(mapped_multisampled); + mapped_entry.view_dimension(mapped_view_dimension); // TODO: Texture component type, storage texture format - mapped_binding + mapped_entry }) .collect::(); @@ -152,7 +152,7 @@ pub(crate) fn create_bind_group_layout( } pub(crate) fn create_bind_group(device: &DeviceId, desc: &BindGroupDescriptor) -> BindGroupId { - let mapped_bindings = desc + let mapped_entries = desc .bindings .iter() .map(|binding| { @@ -172,11 +172,11 @@ pub(crate) fn create_bind_group(device: &DeviceId, desc: &BindGroupDescriptor) - } }; - web_sys::GpuBindGroupBinding::new(binding.binding, &mapped_resource) + web_sys::GpuBindGroupEntry::new(binding.binding, &mapped_resource) }) .collect::(); - let mapped_desc = web_sys::GpuBindGroupDescriptor::new(&mapped_bindings, &desc.layout.id); + let mapped_desc = web_sys::GpuBindGroupDescriptor::new(&mapped_entries, &desc.layout.id); device.create_bind_group(&mapped_desc) } @@ -500,8 +500,8 @@ fn map_texture_view_dimension( } fn map_buffer_copy_view(view: crate::BufferCopyView<'_>) -> web_sys::GpuBufferCopyView { - let mut mapped = - web_sys::GpuBufferCopyView::new(&view.buffer.id, view.rows_per_image, view.bytes_per_row); + let mut mapped = web_sys::GpuBufferCopyView::new(&view.buffer.id, view.bytes_per_row); + mapped.rows_per_image(view.rows_per_image); mapped.offset(view.offset as f64); mapped } @@ -678,17 +678,14 @@ pub(crate) fn device_create_buffer(device: &DeviceId, desc: &BufferDescriptor) - } pub(crate) fn device_create_texture(device: &DeviceId, desc: &TextureDescriptor) -> TextureId { - let extent = map_extent_3d(desc.size); let mut mapped_desc = web_sys::GpuTextureDescriptor::new( map_texture_format(desc.format), - &extent, + &map_extent_3d(desc.size), desc.usage.bits(), ); - mapped_desc.array_layer_count(desc.array_layer_count); mapped_desc.dimension(map_texture_dimension(desc.dimension)); mapped_desc.mip_level_count(desc.mip_level_count); mapped_desc.sample_count(desc.sample_count); - mapped_desc.array_layer_count(desc.array_layer_count); device.create_texture(&mapped_desc) } @@ -1009,7 +1006,7 @@ pub(crate) fn render_pass_draw( vertices: Range, instances: Range, ) { - render_pass.draw( + render_pass.draw_with_instance_count_and_first_vertex_and_first_instance( vertices.end - vertices.start, instances.end - instances.start, vertices.start, @@ -1023,13 +1020,14 @@ pub(crate) fn render_pass_draw_indexed( base_vertex: i32, instances: Range, ) { - render_pass.draw_indexed( - indices.end - indices.start, - instances.end - instances.start, - indices.start, - base_vertex, - instances.start, - ); + render_pass + .draw_indexed_with_instance_count_and_first_index_and_base_vertex_and_first_instance( + indices.end - indices.start, + instances.end - instances.start, + indices.start, + base_vertex, + instances.start, + ); } pub(crate) fn render_pass_end_pass(render_pass: &RenderPassEncoderId) { diff --git a/src/lib.rs b/src/lib.rs index e95436d073..c18514b143 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1201,7 +1201,8 @@ impl SwapChain { match backend::swap_chain_get_next_texture(&self.id) { Some(id) => Ok(SwapChainOutput { view: TextureView { id, owned: false }, - swap_chain_id: self.id, + // TODO: Remove from web backend + swap_chain_id: self.id.clone(), }), None => Err(TimeOut), }