Skip to content
This repository has been archived by the owner on Jun 18, 2021. It is now read-only.

Commit

Permalink
Update to latest WebIDL
Browse files Browse the repository at this point in the history
  • Loading branch information
grovesNL committed Apr 11, 2020
1 parent ae3ee34 commit 7d84bd6
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 21 deletions.
18 changes: 12 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,18 @@ test = true
#gfx-descriptor = { version = "0.1.0", path = "../gfx-extras/gfx-descriptor" }
#gfx-memory = { version = "0.1.0", path = "../gfx-extras/gfx-memory" }

[patch.crates-io]
wasm-bindgen = { path = "../wasm-bindgen" }
wasm-bindgen-futures = { path = "../wasm-bindgen/crates/futures" }
web-sys = { path = "../wasm-bindgen/crates/web-sys" }
js-sys = { path = "../wasm-bindgen/crates/js-sys" }

[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",
Expand All @@ -87,10 +93,10 @@ web-sys = { version = "0.3.36", features = [
"GpuAdapter",
"GpuAddressMode",
"GpuBindGroup",
"GpuBindGroupBinding",
"GpuBindGroupEntry",
"GpuBindGroupDescriptor",
"GpuBindGroupLayout",
"GpuBindGroupLayoutBinding",
"GpuBindGroupLayoutEntry",
"GpuBindGroupLayoutDescriptor",
"GpuBlendDescriptor",
"GpuBlendFactor",
Expand Down Expand Up @@ -164,8 +170,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"
Expand Down
29 changes: 15 additions & 14 deletions src/backend/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,14 @@ pub(crate) fn create_bind_group_layout(device: &DeviceId, desc: &BindGroupLayout
_ => web_sys::GpuTextureViewDimension::N2d,
};

let mut mapped_binding = web_sys::GpuBindGroupLayoutBinding::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);
let mut mapped_entry = web_sys::GpuBindGroupLayoutEntry::new(bind.binding, mapped_type, bind.visibility.bits());
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::<js_sys::Array>();

Expand All @@ -130,7 +130,7 @@ pub(crate) fn create_bind_group_layout(device: &DeviceId, desc: &BindGroupLayout
}

pub(crate) fn create_bind_group(device: &DeviceId, desc: &BindGroupDescriptor) -> BindGroupId {
let mapped_bindings = desc
let mapped_entries = desc
.bindings
.iter()
.map(|binding| {
Expand All @@ -148,11 +148,11 @@ pub(crate) fn create_bind_group(device: &DeviceId, desc: &BindGroupDescriptor) -
BindingResource::TextureView(ref texture_view) => JsValue::from(texture_view.id.clone()),
};

web_sys::GpuBindGroupBinding::new(binding.binding, &mapped_resource)
web_sys::GpuBindGroupEntry::new(binding.binding, &mapped_resource)
})
.collect::<js_sys::Array>();

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)
}

Expand Down Expand Up @@ -454,7 +454,8 @@ fn map_texture_view_dimension(texture_view_dimension: wgt::TextureViewDimension)
}

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
}
Expand Down Expand Up @@ -621,13 +622,13 @@ 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 extent = map_extent_3d(desc.size);
// TODO: Remove `array_layer_count` for existing descriptors
extent.depth(desc.size.depth * desc.array_layer_count);
let mut mapped_desc = web_sys::GpuTextureDescriptor::new(map_texture_format(desc.format), &extent, 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)
}

Expand Down Expand Up @@ -929,7 +930,7 @@ pub(crate) fn render_pass_draw(
vertices: Range<u32>,
instances: Range<u32>,
) {
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,
Expand All @@ -943,7 +944,7 @@ pub(crate) fn render_pass_draw_indexed(
base_vertex: i32,
instances: Range<u32>,
) {
render_pass.draw_indexed(
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,
Expand Down
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1251,7 +1251,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),
}
Expand Down

0 comments on commit 7d84bd6

Please sign in to comment.