From 1d4efb48ba904aab93ebad3a2892aed46444088f Mon Sep 17 00:00:00 2001 From: Kunal Mohan Date: Tue, 2 Jun 2020 21:02:06 +0530 Subject: [PATCH 1/2] Implement GPURenderPassEncoder Add webidls for GPURenderPassEncoder and GPURenderEncoderBase and implement relevant methods. --- components/script/dom/gpucommandencoder.rs | 121 +++++++- .../script/dom/gpucomputepassencoder.rs | 22 +- components/script/dom/gpudevice.rs | 9 +- components/script/dom/gpurenderpassencoder.rs | 275 ++++++++++++++++++ components/script/dom/gpurenderpipeline.rs | 6 + components/script/dom/gputextureview.rs | 14 +- components/script/dom/mod.rs | 1 + .../dom/webidls/GPUCommandEncoder.webidl | 47 ++- .../dom/webidls/GPURenderEncoderBase.webidl | 24 ++ .../dom/webidls/GPURenderPassEncoder.webidl | 26 ++ components/webgpu/lib.rs | 14 + 11 files changed, 524 insertions(+), 35 deletions(-) create mode 100644 components/script/dom/gpurenderpassencoder.rs create mode 100644 components/script/dom/webidls/GPURenderEncoderBase.webidl create mode 100644 components/script/dom/webidls/GPURenderPassEncoder.webidl diff --git a/components/script/dom/gpucommandencoder.rs b/components/script/dom/gpucommandencoder.rs index 487bd7fe7ee..6fcd1bc23b6 100644 --- a/components/script/dom/gpucommandencoder.rs +++ b/components/script/dom/gpucommandencoder.rs @@ -6,6 +6,10 @@ use crate::dom::bindings::cell::DomRefCell; use crate::dom::bindings::codegen::Bindings::GPUBufferBinding::GPUSize64; use crate::dom::bindings::codegen::Bindings::GPUCommandEncoderBinding::{ GPUCommandBufferDescriptor, GPUCommandEncoderMethods, GPUComputePassDescriptor, + GPURenderPassDescriptor, GPUStencilLoadValue, GPUStoreOp, +}; +use crate::dom::bindings::codegen::UnionTypes::{ + GPULoadOpOrDoubleSequenceOrGPUColorDict as GPUColorLoad, GPULoadOpOrFloat, }; use crate::dom::bindings::reflector::DomObject; use crate::dom::bindings::reflector::{reflect_dom_object, Reflector}; @@ -15,17 +19,20 @@ use crate::dom::globalscope::GlobalScope; use crate::dom::gpubuffer::GPUBuffer; use crate::dom::gpucommandbuffer::GPUCommandBuffer; use crate::dom::gpucomputepassencoder::GPUComputePassEncoder; +use crate::dom::gpurenderpassencoder::GPURenderPassEncoder; use dom_struct::dom_struct; use std::cell::Cell; use std::collections::HashSet; -use webgpu::wgt::BufferUsage; -use webgpu::{self, WebGPU, WebGPURequest}; +use webgpu::wgpu::command::{ + RawPass, RenderPassColorAttachmentDescriptor, RenderPassDepthStencilAttachmentDescriptor, + RenderPassDescriptor, +}; +use webgpu::{self, wgt, WebGPU, WebGPUDevice, WebGPURequest}; const BUFFER_COPY_ALIGN_MASK: u64 = 3; // https://gpuweb.github.io/gpuweb/#enumdef-encoder-state #[derive(MallocSizeOf, PartialEq)] -#[allow(dead_code)] pub enum GPUCommandEncoderState { Open, EncodingRenderPass, @@ -42,19 +49,22 @@ pub struct GPUCommandEncoder { encoder: webgpu::WebGPUCommandEncoder, buffers: DomRefCell>>, state: DomRefCell, + device: WebGPUDevice, valid: Cell, } impl GPUCommandEncoder { pub fn new_inherited( channel: WebGPU, + device: WebGPUDevice, encoder: webgpu::WebGPUCommandEncoder, valid: bool, - ) -> GPUCommandEncoder { - GPUCommandEncoder { + ) -> Self { + Self { channel, reflector_: Reflector::new(), label: DomRefCell::new(None), + device, encoder, buffers: DomRefCell::new(HashSet::new()), state: DomRefCell::new(GPUCommandEncoderState::Open), @@ -65,11 +75,14 @@ impl GPUCommandEncoder { pub fn new( global: &GlobalScope, channel: WebGPU, + device: WebGPUDevice, encoder: webgpu::WebGPUCommandEncoder, valid: bool, - ) -> DomRoot { + ) -> DomRoot { reflect_dom_object( - Box::new(GPUCommandEncoder::new_inherited(channel, encoder, valid)), + Box::new(GPUCommandEncoder::new_inherited( + channel, device, encoder, valid, + )), global, ) } @@ -113,6 +126,92 @@ impl GPUCommandEncoderMethods for GPUCommandEncoder { GPUComputePassEncoder::new(&self.global(), self.channel.clone(), &self) } + #[allow(unsafe_code)] + /// https://gpuweb.github.io/gpuweb/#dom-gpucommandencoder-beginrenderpass + fn BeginRenderPass( + &self, + descriptor: &GPURenderPassDescriptor, + ) -> DomRoot { + self.set_state( + GPUCommandEncoderState::EncodingRenderPass, + GPUCommandEncoderState::Open, + ); + + let colors = descriptor + .colorAttachments + .iter() + .map(|color| { + let (load_op, clear_color) = match color.loadValue { + GPUColorLoad::GPULoadOp(_) => (wgt::LoadOp::Load, wgt::Color::TRANSPARENT), + GPUColorLoad::DoubleSequence(ref s) => ( + wgt::LoadOp::Clear, + wgt::Color { + r: *s[0], + g: *s[1], + b: *s[2], + a: *s[3], + }, + ), + GPUColorLoad::GPUColorDict(ref d) => ( + wgt::LoadOp::Clear, + wgt::Color { + r: *d.r, + g: *d.g, + b: *d.b, + a: *d.a, + }, + ), + }; + RenderPassColorAttachmentDescriptor { + attachment: color.attachment.id().0, + resolve_target: color.resolveTarget.as_ref().map(|t| t.id().0), + load_op, + store_op: match color.storeOp { + GPUStoreOp::Store => wgt::StoreOp::Store, + GPUStoreOp::Clear => wgt::StoreOp::Clear, + }, + clear_color, + } + }) + .collect::>(); + + let depth_stencil = descriptor.depthStencilAttachment.as_ref().map(|depth| { + let (depth_load_op, clear_depth) = match depth.depthLoadValue { + GPULoadOpOrFloat::GPULoadOp(_) => (wgt::LoadOp::Load, 0.0f32), + GPULoadOpOrFloat::Float(f) => (wgt::LoadOp::Clear, *f), + }; + let (stencil_load_op, clear_stencil) = match depth.stencilLoadValue { + GPUStencilLoadValue::GPULoadOp(_) => (wgt::LoadOp::Load, 0u32), + GPUStencilLoadValue::RangeEnforcedUnsignedLong(l) => (wgt::LoadOp::Clear, l), + }; + RenderPassDepthStencilAttachmentDescriptor { + attachment: depth.attachment.id().0, + depth_load_op, + depth_store_op: match depth.depthStoreOp { + GPUStoreOp::Store => wgt::StoreOp::Store, + GPUStoreOp::Clear => wgt::StoreOp::Clear, + }, + clear_depth, + stencil_load_op, + stencil_store_op: match depth.stencilStoreOp { + GPUStoreOp::Store => wgt::StoreOp::Store, + GPUStoreOp::Clear => wgt::StoreOp::Clear, + }, + clear_stencil, + } + }); + + let desc = RenderPassDescriptor { + color_attachments: colors.as_ptr(), + color_attachments_length: colors.len(), + depth_stencil_attachment: depth_stencil.as_ref(), + }; + + let raw_pass = unsafe { RawPass::new_render(self.id().0, &desc) }; + + GPURenderPassEncoder::new(&self.global(), self.channel.clone(), raw_pass, &self) + } + /// https://gpuweb.github.io/gpuweb/#dom-gpucommandencoder-copybuffertobuffer fn CopyBufferToBuffer( &self, @@ -130,12 +229,12 @@ impl GPUCommandEncoderMethods for GPUCommandEncoder { Some(_) => true, None => false, }; - valid &= match BufferUsage::from_bits(source.usage()) { - Some(usage) => usage.contains(BufferUsage::COPY_SRC), + valid &= match wgt::BufferUsage::from_bits(source.usage()) { + Some(usage) => usage.contains(wgt::BufferUsage::COPY_SRC), None => false, }; - valid &= match BufferUsage::from_bits(destination.usage()) { - Some(usage) => usage.contains(BufferUsage::COPY_DST), + valid &= match wgt::BufferUsage::from_bits(destination.usage()) { + Some(usage) => usage.contains(wgt::BufferUsage::COPY_DST), None => false, }; valid &= (*self.state.borrow() == GPUCommandEncoderState::Open) && diff --git a/components/script/dom/gpucomputepassencoder.rs b/components/script/dom/gpucomputepassencoder.rs index 76c9ec8eea4..f202cc37038 100644 --- a/components/script/dom/gpucomputepassencoder.rs +++ b/components/script/dom/gpucomputepassencoder.rs @@ -2,6 +2,8 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ +#![allow(unsafe_code)] + use crate::dom::bindings::cell::DomRefCell; use crate::dom::bindings::codegen::Bindings::GPUComputePassEncoderBinding::GPUComputePassEncoderMethods; use crate::dom::bindings::reflector::{reflect_dom_object, Reflector}; @@ -12,7 +14,6 @@ use crate::dom::gpubindgroup::GPUBindGroup; use crate::dom::gpucommandencoder::{GPUCommandEncoder, GPUCommandEncoderState}; use crate::dom::gpucomputepipeline::GPUComputePipeline; use dom_struct::dom_struct; -use std::cell::RefCell; use webgpu::{ wgpu::command::{ compute_ffi::{ @@ -31,27 +32,22 @@ pub struct GPUComputePassEncoder { channel: WebGPU, label: DomRefCell>, #[ignore_malloc_size_of = "defined in wgpu-core"] - raw_pass: RefCell>, + raw_pass: DomRefCell>, command_encoder: Dom, } impl GPUComputePassEncoder { - #[allow(unsafe_code)] - fn new_inherited(channel: WebGPU, parent: &GPUCommandEncoder) -> GPUComputePassEncoder { - GPUComputePassEncoder { + fn new_inherited(channel: WebGPU, parent: &GPUCommandEncoder) -> Self { + Self { channel, reflector_: Reflector::new(), label: DomRefCell::new(None), - raw_pass: RefCell::new(Some(unsafe { RawPass::new_compute(parent.id().0) })), + raw_pass: DomRefCell::new(Some(unsafe { RawPass::new_compute(parent.id().0) })), command_encoder: Dom::from_ref(parent), } } - pub fn new( - global: &GlobalScope, - channel: WebGPU, - parent: &GPUCommandEncoder, - ) -> DomRoot { + pub fn new(global: &GlobalScope, channel: WebGPU, parent: &GPUCommandEncoder) -> DomRoot { reflect_dom_object( Box::new(GPUComputePassEncoder::new_inherited(channel, parent)), global, @@ -70,7 +66,6 @@ impl GPUComputePassEncoderMethods for GPUComputePassEncoder { *self.label.borrow_mut() = value; } - #[allow(unsafe_code)] /// https://gpuweb.github.io/gpuweb/#dom-gpucomputepassencoder-dispatch fn Dispatch(&self, x: u32, y: u32, z: u32) { if let Some(raw_pass) = self.raw_pass.borrow_mut().as_mut() { @@ -78,7 +73,6 @@ impl GPUComputePassEncoderMethods for GPUComputePassEncoder { } } - #[allow(unsafe_code)] /// https://gpuweb.github.io/gpuweb/#dom-gpurenderpassencoder-endpass fn EndPass(&self) { if let Some(raw_pass) = self.raw_pass.borrow_mut().take() { @@ -99,7 +93,6 @@ impl GPUComputePassEncoderMethods for GPUComputePassEncoder { } } - #[allow(unsafe_code)] /// https://gpuweb.github.io/gpuweb/#dom-gpuprogrammablepassencoder-setbindgroup fn SetBindGroup(&self, index: u32, bind_group: &GPUBindGroup, dynamic_offsets: Vec) { if let Some(raw_pass) = self.raw_pass.borrow_mut().as_mut() { @@ -115,7 +108,6 @@ impl GPUComputePassEncoderMethods for GPUComputePassEncoder { } } - #[allow(unsafe_code)] /// https://gpuweb.github.io/gpuweb/#dom-gpucomputepassencoder-setpipeline fn SetPipeline(&self, pipeline: &GPUComputePipeline) { if let Some(raw_pass) = self.raw_pass.borrow_mut().as_mut() { diff --git a/components/script/dom/gpudevice.rs b/components/script/dom/gpudevice.rs index ba9f22b5fec..6a4301124b9 100644 --- a/components/script/dom/gpudevice.rs +++ b/components/script/dom/gpudevice.rs @@ -98,7 +98,6 @@ impl GPUDevice { } } - #[allow(unsafe_code)] pub fn new( global: &GlobalScope, channel: WebGPU, @@ -647,7 +646,13 @@ impl GPUDeviceMethods for GPUDevice { let encoder = webgpu::WebGPUCommandEncoder(command_encoder_id); - GPUCommandEncoder::new(&self.global(), self.channel.clone(), encoder, true) + GPUCommandEncoder::new( + &self.global(), + self.channel.clone(), + self.device, + encoder, + true, + ) } /// https://gpuweb.github.io/gpuweb/#dom-gpudevice-createtexture diff --git a/components/script/dom/gpurenderpassencoder.rs b/components/script/dom/gpurenderpassencoder.rs new file mode 100644 index 00000000000..47ac8c6db22 --- /dev/null +++ b/components/script/dom/gpurenderpassencoder.rs @@ -0,0 +1,275 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + +#![allow(unsafe_code)] + +use crate::dom::bindings::cell::DomRefCell; +use crate::dom::bindings::codegen::Bindings::GPUCommandEncoderBinding::GPUColor; +use crate::dom::bindings::codegen::Bindings::GPURenderPassEncoderBinding::GPURenderPassEncoderMethods; +use crate::dom::bindings::num::Finite; +use crate::dom::bindings::reflector::{reflect_dom_object, Reflector}; +use crate::dom::bindings::root::{Dom, DomRoot}; +use crate::dom::bindings::str::DOMString; +use crate::dom::globalscope::GlobalScope; +use crate::dom::gpubindgroup::GPUBindGroup; +use crate::dom::gpubuffer::GPUBuffer; +use crate::dom::gpucommandencoder::{GPUCommandEncoder, GPUCommandEncoderState}; +use crate::dom::gpurenderpipeline::GPURenderPipeline; +use dom_struct::dom_struct; +use webgpu::{ + wgpu::command::{render_ffi as wgpu_render, RawPass}, + wgt, WebGPU, WebGPURequest, +}; + +#[dom_struct] +pub struct GPURenderPassEncoder { + reflector_: Reflector, + #[ignore_malloc_size_of = "defined in webgpu"] + channel: WebGPU, + label: DomRefCell>, + #[ignore_malloc_size_of = "defined in wgpu-core"] + raw_pass: DomRefCell>, + command_encoder: Dom, +} + +impl GPURenderPassEncoder { + fn new_inherited(channel: WebGPU, raw_pass: RawPass, parent: &GPUCommandEncoder) -> Self { + Self { + channel, + reflector_: Reflector::new(), + label: DomRefCell::new(None), + raw_pass: DomRefCell::new(Some(raw_pass)), + command_encoder: Dom::from_ref(parent), + } + } + + pub fn new( + global: &GlobalScope, + channel: WebGPU, + raw_pass: RawPass, + parent: &GPUCommandEncoder, + ) -> DomRoot { + reflect_dom_object( + Box::new(GPURenderPassEncoder::new_inherited( + channel, raw_pass, parent, + )), + global, + ) + } +} + +impl GPURenderPassEncoderMethods for GPURenderPassEncoder { + /// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label + fn GetLabel(&self) -> Option { + self.label.borrow().clone() + } + + /// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label + fn SetLabel(&self, value: Option) { + *self.label.borrow_mut() = value; + } + + /// https://gpuweb.github.io/gpuweb/#dom-gpuprogrammablepassencoder-setbindgroup + fn SetBindGroup(&self, index: u32, bind_group: &GPUBindGroup, dynamic_offsets: Vec) { + if let Some(raw_pass) = self.raw_pass.borrow_mut().as_mut() { + unsafe { + wgpu_render::wgpu_render_pass_set_bind_group( + raw_pass, + index, + bind_group.id().0, + dynamic_offsets.as_ptr(), + dynamic_offsets.len(), + ) + }; + } + } + + /// https://gpuweb.github.io/gpuweb/#dom-gpurenderpassencoder-setviewport + fn SetViewport( + &self, + x: Finite, + y: Finite, + width: Finite, + height: Finite, + min_depth: Finite, + max_depth: Finite, + ) { + if let Some(raw_pass) = self.raw_pass.borrow_mut().as_mut() { + unsafe { + wgpu_render::wgpu_render_pass_set_viewport( + raw_pass, *x, *y, *width, *height, *min_depth, *max_depth, + ) + }; + } + } + + /// https://gpuweb.github.io/gpuweb/#dom-gpurenderpassencoder-setscissorrect + fn SetScissorRect(&self, x: u32, y: u32, width: u32, height: u32) { + if width <= 0 || height <= 0 { + return warn!("Cannot set scissor rect- width and height must greater than 0"); + } + if let Some(raw_pass) = self.raw_pass.borrow_mut().as_mut() { + unsafe { + wgpu_render::wgpu_render_pass_set_scissor_rect(raw_pass, x, y, width, height) + }; + } + } + + /// https://gpuweb.github.io/gpuweb/#dom-gpurenderpassencoder-setblendcolor + fn SetBlendColor(&self, color: GPUColor) { + let colors = match color { + GPUColor::GPUColorDict(d) => wgt::Color { + r: *d.r, + g: *d.g, + b: *d.b, + a: *d.a, + }, + GPUColor::DoubleSequence(s) => wgt::Color { + r: *s[0], + g: *s[1], + b: *s[2], + a: *s[3], + }, + }; + if let Some(raw_pass) = self.raw_pass.borrow_mut().as_mut() { + unsafe { wgpu_render::wgpu_render_pass_set_blend_color(raw_pass, &colors) }; + } + } + + /// https://gpuweb.github.io/gpuweb/#dom-gpurenderpassencoder-setstencilreference + fn SetStencilReference(&self, reference: u32) { + if let Some(raw_pass) = self.raw_pass.borrow_mut().as_mut() { + unsafe { wgpu_render::wgpu_render_pass_set_stencil_reference(raw_pass, reference) }; + } + } + + /// https://gpuweb.github.io/gpuweb/#dom-gpurenderpassencoder-endpass + fn EndPass(&self) { + if let Some(raw_pass) = self.raw_pass.borrow_mut().take() { + let (pass_data, command_encoder_id) = unsafe { raw_pass.finish_render() }; + + self.channel + .0 + .send(WebGPURequest::RunRenderPass { + command_encoder_id, + pass_data, + }) + .unwrap(); + + self.command_encoder.set_state( + GPUCommandEncoderState::Open, + GPUCommandEncoderState::EncodingRenderPass, + ); + } + } + + /// https://gpuweb.github.io/gpuweb/#dom-gpurenderencoderbase-setpipeline + fn SetPipeline(&self, pipeline: &GPURenderPipeline) { + if let Some(raw_pass) = self.raw_pass.borrow_mut().as_mut() { + unsafe { wgpu_render::wgpu_render_pass_set_pipeline(raw_pass, pipeline.id().0) }; + } + } + + /// https://gpuweb.github.io/gpuweb/#dom-gpurenderencoderbase-setindexbuffer + fn SetIndexBuffer(&self, buffer: &GPUBuffer, offset: u64, size: u64) { + let s; + if size == 0 { + s = buffer.size() - offset; + } else { + s = size; + } + + if let Some(raw_pass) = self.raw_pass.borrow_mut().as_mut() { + unsafe { + wgpu_render::wgpu_render_pass_set_index_buffer(raw_pass, buffer.id().0, offset, s) + }; + } + } + + /// https://gpuweb.github.io/gpuweb/#dom-gpurenderencoderbase-setvertexbuffer + fn SetVertexBuffer(&self, slot: u32, buffer: &GPUBuffer, offset: u64, size: u64) { + let s; + if size == 0 { + s = buffer.size() - offset; + } else { + s = size; + } + + if let Some(raw_pass) = self.raw_pass.borrow_mut().as_mut() { + unsafe { + wgpu_render::wgpu_render_pass_set_vertex_buffer( + raw_pass, + slot, + buffer.id().0, + offset, + s, + ) + }; + } + } + + /// https://gpuweb.github.io/gpuweb/#dom-gpurenderencoderbase-draw + fn Draw(&self, vertex_count: u32, instance_count: u32, first_vertex: u32, first_instance: u32) { + if let Some(raw_pass) = self.raw_pass.borrow_mut().as_mut() { + unsafe { + wgpu_render::wgpu_render_pass_draw( + raw_pass, + vertex_count, + instance_count, + first_vertex, + first_instance, + ) + }; + } + } + + /// https://gpuweb.github.io/gpuweb/#dom-gpurenderencoderbase-drawindexed + fn DrawIndexed( + &self, + index_count: u32, + instance_count: u32, + first_index: u32, + base_vertex: i32, + first_instance: u32, + ) { + if let Some(raw_pass) = self.raw_pass.borrow_mut().as_mut() { + unsafe { + wgpu_render::wgpu_render_pass_draw_indexed( + raw_pass, + index_count, + instance_count, + first_index, + base_vertex, + first_instance, + ) + }; + } + } + + /// https://gpuweb.github.io/gpuweb/#dom-gpurenderencoderbase-drawindirect + fn DrawIndirect(&self, indirect_buffer: &GPUBuffer, indirect_offset: u64) { + if let Some(raw_pass) = self.raw_pass.borrow_mut().as_mut() { + unsafe { + wgpu_render::wgpu_render_pass_draw_indirect( + raw_pass, + indirect_buffer.id().0, + indirect_offset, + ) + }; + } + } + + /// https://gpuweb.github.io/gpuweb/#dom-gpurenderencoderbase-drawindexedindirect + fn DrawIndexedIndirect(&self, indirect_buffer: &GPUBuffer, indirect_offset: u64) { + if let Some(raw_pass) = self.raw_pass.borrow_mut().as_mut() { + unsafe { + wgpu_render::wgpu_render_pass_draw_indexed_indirect( + raw_pass, + indirect_buffer.id().0, + indirect_offset, + ) + }; + } + } +} diff --git a/components/script/dom/gpurenderpipeline.rs b/components/script/dom/gpurenderpipeline.rs index c7e56fb253a..68d07820103 100644 --- a/components/script/dom/gpurenderpipeline.rs +++ b/components/script/dom/gpurenderpipeline.rs @@ -54,6 +54,12 @@ impl GPURenderPipeline { } } +impl GPURenderPipeline { + pub fn id(&self) -> WebGPURenderPipeline { + self.render_pipeline + } +} + impl GPURenderPipelineMethods for GPURenderPipeline { /// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label fn GetLabel(&self) -> Option { diff --git a/components/script/dom/gputextureview.rs b/components/script/dom/gputextureview.rs index 7a6f60e3bfb..f3bb4209708 100644 --- a/components/script/dom/gputextureview.rs +++ b/components/script/dom/gputextureview.rs @@ -22,11 +22,7 @@ pub struct GPUTextureView { } impl GPUTextureView { - fn new_inherited( - texture_view: WebGPUTextureView, - device: WebGPUDevice, - valid: bool, - ) -> GPUTextureView { + fn new_inherited(texture_view: WebGPUTextureView, device: WebGPUDevice, valid: bool) -> Self { Self { reflector_: Reflector::new(), device, @@ -41,7 +37,7 @@ impl GPUTextureView { texture_view: WebGPUTextureView, device: WebGPUDevice, valid: bool, - ) -> DomRoot { + ) -> DomRoot { reflect_dom_object( Box::new(GPUTextureView::new_inherited(texture_view, device, valid)), global, @@ -49,6 +45,12 @@ impl GPUTextureView { } } +impl GPUTextureView { + pub fn id(&self) -> WebGPUTextureView { + self.texture_view + } +} + impl GPUTextureViewMethods for GPUTextureView { /// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label fn GetLabel(&self) -> Option { diff --git a/components/script/dom/mod.rs b/components/script/dom/mod.rs index 8c96b3cd9cb..0aa0bd3123a 100644 --- a/components/script/dom/mod.rs +++ b/components/script/dom/mod.rs @@ -333,6 +333,7 @@ pub mod gpucomputepipeline; pub mod gpudevice; pub mod gpupipelinelayout; pub mod gpuqueue; +pub mod gpurenderpassencoder; pub mod gpurenderpipeline; pub mod gpusampler; pub mod gpushadermodule; diff --git a/components/script/dom/webidls/GPUCommandEncoder.webidl b/components/script/dom/webidls/GPUCommandEncoder.webidl index f6801e46e96..6892c5393af 100644 --- a/components/script/dom/webidls/GPUCommandEncoder.webidl +++ b/components/script/dom/webidls/GPUCommandEncoder.webidl @@ -5,7 +5,7 @@ // https://gpuweb.github.io/gpuweb/#gpucommandencoder [Exposed=(Window, DedicatedWorker), Serializable, Pref="dom.webgpu.enabled"] interface GPUCommandEncoder { - // GPURenderPassEncoder beginRenderPass(GPURenderPassDescriptor descriptor); + GPURenderPassEncoder beginRenderPass(GPURenderPassDescriptor descriptor); GPUComputePassEncoder beginComputePass(optional GPUComputePassDescriptor descriptor = {}); void copyBufferToBuffer( @@ -43,3 +43,48 @@ dictionary GPUComputePassDescriptor : GPUObjectDescriptorBase { dictionary GPUCommandBufferDescriptor : GPUObjectDescriptorBase { }; + +dictionary GPURenderPassDescriptor : GPUObjectDescriptorBase { + required sequence colorAttachments; + GPURenderPassDepthStencilAttachmentDescriptor depthStencilAttachment; + //GPUQuerySet occlusionQuerySet; +}; + +dictionary GPURenderPassColorAttachmentDescriptor { + required GPUTextureView attachment; + GPUTextureView resolveTarget; + + required (GPULoadOp or GPUColor) loadValue; + GPUStoreOp storeOp = "store"; +}; + +dictionary GPURenderPassDepthStencilAttachmentDescriptor { + required GPUTextureView attachment; + + required (GPULoadOp or float) depthLoadValue; + required GPUStoreOp depthStoreOp; + boolean depthReadOnly = false; + + required GPUStencilLoadValue stencilLoadValue; + required GPUStoreOp stencilStoreOp; + boolean stencilReadOnly = false; +}; + +typedef (GPULoadOp or GPUStencilValue) GPUStencilLoadValue; + +enum GPULoadOp { + "load" +}; + +enum GPUStoreOp { + "store", + "clear" +}; + +dictionary GPUColorDict { + required double r; + required double g; + required double b; + required double a; +}; +typedef (sequence or GPUColorDict) GPUColor; diff --git a/components/script/dom/webidls/GPURenderEncoderBase.webidl b/components/script/dom/webidls/GPURenderEncoderBase.webidl new file mode 100644 index 00000000000..f0c4532b446 --- /dev/null +++ b/components/script/dom/webidls/GPURenderEncoderBase.webidl @@ -0,0 +1,24 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + +// https://gpuweb.github.io/gpuweb/#gpurenderencoderbase +[Exposed=(Window, DedicatedWorker)] +interface mixin GPURenderEncoderBase { + void setPipeline(GPURenderPipeline pipeline); + + void setIndexBuffer(GPUBuffer buffer, optional GPUSize64 offset = 0, optional GPUSize64 size = 0); + void setVertexBuffer(GPUIndex32 slot, GPUBuffer buffer, optional GPUSize64 offset = 0, optional GPUSize64 size = 0); + + void draw(GPUSize32 vertexCount, optional GPUSize32 instanceCount = 1, + optional GPUSize32 firstVertex = 0, optional GPUSize32 firstInstance = 0); + void drawIndexed(GPUSize32 indexCount, optional GPUSize32 instanceCount = 1, + optional GPUSize32 firstIndex = 0, + optional GPUSignedOffset32 baseVertex = 0, + optional GPUSize32 firstInstance = 0); + + void drawIndirect(GPUBuffer indirectBuffer, GPUSize64 indirectOffset); + void drawIndexedIndirect(GPUBuffer indirectBuffer, GPUSize64 indirectOffset); +}; + +typedef [EnforceRange] long GPUSignedOffset32; diff --git a/components/script/dom/webidls/GPURenderPassEncoder.webidl b/components/script/dom/webidls/GPURenderPassEncoder.webidl new file mode 100644 index 00000000000..2aa6e7c5581 --- /dev/null +++ b/components/script/dom/webidls/GPURenderPassEncoder.webidl @@ -0,0 +1,26 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + +// https://gpuweb.github.io/gpuweb/#gpurenderpassencoder +[Exposed=(Window, DedicatedWorker), Pref="dom.webgpu.enabled"] +interface GPURenderPassEncoder { + void setViewport(float x, float y, + float width, float height, + float minDepth, float maxDepth); + + void setScissorRect(GPUIntegerCoordinate x, GPUIntegerCoordinate y, + GPUIntegerCoordinate width, GPUIntegerCoordinate height); + + void setBlendColor(GPUColor color); + void setStencilReference(GPUStencilValue reference); + + //void beginOcclusionQuery(GPUSize32 queryIndex); + //void endOcclusionQuery(GPUSize32 queryIndex); + + //void executeBundles(sequence bundles); + void endPass(); +}; +GPURenderPassEncoder includes GPUObjectBase; +GPURenderPassEncoder includes GPUProgrammablePassEncoder; +GPURenderPassEncoder includes GPURenderEncoderBase; diff --git a/components/webgpu/lib.rs b/components/webgpu/lib.rs index 884bf0ddfa5..442e2201e18 100644 --- a/components/webgpu/lib.rs +++ b/components/webgpu/lib.rs @@ -155,6 +155,10 @@ pub enum WebGPURequest { command_encoder_id: id::CommandEncoderId, pass_data: Vec, }, + RunRenderPass { + command_encoder_id: id::CommandEncoderId, + pass_data: Vec, + }, Submit { queue_id: id::QueueId, command_buffers: Vec, @@ -586,6 +590,16 @@ impl WGPU { &pass_data )); }, + WebGPURequest::RunRenderPass { + command_encoder_id, + pass_data, + } => { + let global = &self.global; + gfx_select!(command_encoder_id => global.command_encoder_run_render_pass( + command_encoder_id, + &pass_data + )); + }, WebGPURequest::Submit { queue_id, command_buffers, From 3b5ede153d61c2c033326b5df2417e3757dba17b Mon Sep 17 00:00:00 2001 From: Kunal Mohan Date: Thu, 4 Jun 2020 01:19:13 +0530 Subject: [PATCH 2/2] Update wgpu-core and wgpu-types --- Cargo.lock | 5 ++-- components/script/dom/gpuadapter.rs | 10 +++---- components/script/dom/gpubindgroup.rs | 8 ++---- components/script/dom/gpubindgrouplayout.rs | 4 +-- components/script/dom/gpubuffer.rs | 4 +-- components/script/dom/gpucommandbuffer.rs | 6 ++--- components/script/dom/gpucommandencoder.rs | 2 ++ components/script/dom/gpucomputepipeline.rs | 7 ++--- components/script/dom/gpudevice.rs | 24 +++++++++-------- components/script/dom/gpupipelinelayout.rs | 4 +-- components/script/dom/gpuqueue.rs | 4 +-- components/script/dom/gpurenderpassencoder.rs | 18 ++++++------- components/script/dom/gpurenderpipeline.rs | 4 +-- components/script/dom/gpusampler.rs | 4 +-- components/script/dom/gpushadermodule.rs | 7 ++--- components/script/dom/gputexture.rs | 4 +-- .../script/dom/webidls/GPUAdapter.webidl | 7 ++--- components/webgpu/lib.rs | 26 ++----------------- 18 files changed, 58 insertions(+), 90 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fc1c351d2e1..396adc979c7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1895,7 +1895,6 @@ dependencies = [ "raw-window-handle", "smallvec 1.3.0", "winapi", - "x11", ] [[package]] @@ -6592,7 +6591,7 @@ dependencies = [ [[package]] name = "wgpu-core" version = "0.5.0" -source = "git+https://github.com/gfx-rs/wgpu#a203333c3e144cfd431c812213966ee32ae59d98" +source = "git+https://github.com/gfx-rs/wgpu#ac9587e9ced5b043abad68e260cb8c9e812cffb5" dependencies = [ "arrayvec 0.5.1", "bitflags", @@ -6621,7 +6620,7 @@ dependencies = [ [[package]] name = "wgpu-types" version = "0.5.0" -source = "git+https://github.com/gfx-rs/wgpu#a203333c3e144cfd431c812213966ee32ae59d98" +source = "git+https://github.com/gfx-rs/wgpu#ac9587e9ced5b043abad68e260cb8c9e812cffb5" dependencies = [ "bitflags", "peek-poke 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/components/script/dom/gpuadapter.rs b/components/script/dom/gpuadapter.rs index 8420a0058fc..7947a069335 100644 --- a/components/script/dom/gpuadapter.rs +++ b/components/script/dom/gpuadapter.rs @@ -39,8 +39,8 @@ impl GPUAdapter { name: DOMString, extensions: Heap<*mut JSObject>, adapter: WebGPUAdapter, - ) -> GPUAdapter { - GPUAdapter { + ) -> Self { + Self { reflector_: Reflector::new(), channel, name, @@ -55,7 +55,7 @@ impl GPUAdapter { name: DOMString, extensions: Heap<*mut JSObject>, adapter: WebGPUAdapter, - ) -> DomRoot { + ) -> DomRoot { reflect_dom_object( Box::new(GPUAdapter::new_inherited( channel, name, extensions, adapter, @@ -81,9 +81,7 @@ impl GPUAdapterMethods for GPUAdapter { let promise = Promise::new_in_current_realm(&self.global(), comp); let sender = response_async(&promise, self); let desc = wgt::DeviceDescriptor { - extensions: wgt::Extensions { - anisotropic_filtering: descriptor.extensions.anisotropicFiltering, - }, + extensions: wgt::Extensions::empty(), limits: wgt::Limits { max_bind_groups: descriptor.limits.maxBindGroups, }, diff --git a/components/script/dom/gpubindgroup.rs b/components/script/dom/gpubindgroup.rs index b7b8cadeacf..4767d28d0f1 100644 --- a/components/script/dom/gpubindgroup.rs +++ b/components/script/dom/gpubindgroup.rs @@ -21,7 +21,7 @@ pub struct GPUBindGroup { } impl GPUBindGroup { - fn new_inherited(bind_group: WebGPUBindGroup, valid: bool) -> GPUBindGroup { + fn new_inherited(bind_group: WebGPUBindGroup, valid: bool) -> Self { Self { reflector_: Reflector::new(), label: DomRefCell::new(None), @@ -30,11 +30,7 @@ impl GPUBindGroup { } } - pub fn new( - global: &GlobalScope, - bind_group: WebGPUBindGroup, - valid: bool, - ) -> DomRoot { + pub fn new(global: &GlobalScope, bind_group: WebGPUBindGroup, valid: bool) -> DomRoot { reflect_dom_object( Box::new(GPUBindGroup::new_inherited(bind_group, valid)), global, diff --git a/components/script/dom/gpubindgrouplayout.rs b/components/script/dom/gpubindgrouplayout.rs index c57fc272328..8c141256261 100644 --- a/components/script/dom/gpubindgrouplayout.rs +++ b/components/script/dom/gpubindgrouplayout.rs @@ -32,7 +32,7 @@ impl GPUBindGroupLayout { bind_group_layout: WebGPUBindGroupLayout, bindings: Vec, valid: bool, - ) -> GPUBindGroupLayout { + ) -> Self { Self { reflector_: Reflector::new(), channel, @@ -49,7 +49,7 @@ impl GPUBindGroupLayout { bind_group_layout: WebGPUBindGroupLayout, bindings: Vec, valid: bool, - ) -> DomRoot { + ) -> DomRoot { reflect_dom_object( Box::new(GPUBindGroupLayout::new_inherited( channel, diff --git a/components/script/dom/gpubuffer.rs b/components/script/dom/gpubuffer.rs index 643fbfc98c7..1c756dae15f 100644 --- a/components/script/dom/gpubuffer.rs +++ b/components/script/dom/gpubuffer.rs @@ -57,7 +57,7 @@ impl GPUBuffer { usage: u32, valid: bool, mapping: RootedTraceableBox>, - ) -> GPUBuffer { + ) -> Self { Self { reflector_: Reflector::new(), channel, @@ -83,7 +83,7 @@ impl GPUBuffer { usage: u32, valid: bool, mapping: RootedTraceableBox>, - ) -> DomRoot { + ) -> DomRoot { reflect_dom_object( Box::new(GPUBuffer::new_inherited( channel, buffer, device, state, size, usage, valid, mapping, diff --git a/components/script/dom/gpucommandbuffer.rs b/components/script/dom/gpucommandbuffer.rs index b1871051e52..4b23a622ca3 100644 --- a/components/script/dom/gpucommandbuffer.rs +++ b/components/script/dom/gpucommandbuffer.rs @@ -37,8 +37,8 @@ impl GPUCommandBuffer { channel: WebGPU, command_buffer: WebGPUCommandBuffer, buffers: HashSet>, - ) -> GPUCommandBuffer { - GPUCommandBuffer { + ) -> Self { + Self { channel, reflector_: Reflector::new(), label: DomRefCell::new(None), @@ -52,7 +52,7 @@ impl GPUCommandBuffer { channel: WebGPU, command_buffer: WebGPUCommandBuffer, buffers: HashSet>, - ) -> DomRoot { + ) -> DomRoot { reflect_dom_object( Box::new(GPUCommandBuffer::new_inherited( channel, diff --git a/components/script/dom/gpucommandencoder.rs b/components/script/dom/gpucommandencoder.rs index 6fcd1bc23b6..d0ba2dc8624 100644 --- a/components/script/dom/gpucommandencoder.rs +++ b/components/script/dom/gpucommandencoder.rs @@ -192,12 +192,14 @@ impl GPUCommandEncoderMethods for GPUCommandEncoder { GPUStoreOp::Clear => wgt::StoreOp::Clear, }, clear_depth, + depth_read_only: depth.depthReadOnly, stencil_load_op, stencil_store_op: match depth.stencilStoreOp { GPUStoreOp::Store => wgt::StoreOp::Store, GPUStoreOp::Clear => wgt::StoreOp::Clear, }, clear_stencil, + stencil_read_only: depth.stencilReadOnly, } }); diff --git a/components/script/dom/gpucomputepipeline.rs b/components/script/dom/gpucomputepipeline.rs index a4700db4505..e96697c95a2 100644 --- a/components/script/dom/gpucomputepipeline.rs +++ b/components/script/dom/gpucomputepipeline.rs @@ -20,7 +20,7 @@ pub struct GPUComputePipeline { } impl GPUComputePipeline { - fn new_inherited(compute_pipeline: WebGPUComputePipeline) -> GPUComputePipeline { + fn new_inherited(compute_pipeline: WebGPUComputePipeline) -> Self { Self { reflector_: Reflector::new(), label: DomRefCell::new(None), @@ -28,10 +28,7 @@ impl GPUComputePipeline { } } - pub fn new( - global: &GlobalScope, - compute_pipeline: WebGPUComputePipeline, - ) -> DomRoot { + pub fn new(global: &GlobalScope, compute_pipeline: WebGPUComputePipeline) -> DomRoot { reflect_dom_object( Box::new(GPUComputePipeline::new_inherited(compute_pipeline)), global, diff --git a/components/script/dom/gpudevice.rs b/components/script/dom/gpudevice.rs index 6a4301124b9..e8720bf2189 100644 --- a/components/script/dom/gpudevice.rs +++ b/components/script/dom/gpudevice.rs @@ -85,7 +85,7 @@ impl GPUDevice { limits: Heap<*mut JSObject>, device: webgpu::WebGPUDevice, queue: &GPUQueue, - ) -> GPUDevice { + ) -> Self { Self { eventtarget: EventTarget::new_inherited(), channel, @@ -106,7 +106,7 @@ impl GPUDevice { limits: Heap<*mut JSObject>, device: webgpu::WebGPUDevice, queue: webgpu::WebGPUQueue, - ) -> DomRoot { + ) -> DomRoot { let queue = GPUQueue::new(global, channel.clone(), queue); reflect_dom_object( Box::new(GPUDevice::new_inherited( @@ -121,6 +121,7 @@ impl GPUDevice { fn validate_buffer_descriptor( &self, descriptor: &GPUBufferDescriptor, + mapped_at_creation: bool, ) -> (bool, wgt::BufferDescriptor) { // TODO: Record a validation error in the current scope if the descriptor is invalid. let wgpu_usage = wgt::BufferUsage::from_bits(descriptor.usage); @@ -132,6 +133,7 @@ impl GPUDevice { wgt::BufferDescriptor { size: descriptor.size, usage: wgpu_usage.unwrap(), + mapped_at_creation, label: Default::default(), }, ) @@ -141,6 +143,7 @@ impl GPUDevice { wgt::BufferDescriptor { size: 0, usage: wgt::BufferUsage::empty(), + mapped_at_creation, label: Default::default(), }, ) @@ -181,7 +184,7 @@ impl GPUDeviceMethods for GPUDevice { /// https://gpuweb.github.io/gpuweb/#dom-gpudevice-createbuffer fn CreateBuffer(&self, descriptor: &GPUBufferDescriptor) -> DomRoot { - let (valid, wgpu_descriptor) = self.validate_buffer_descriptor(descriptor); + let (valid, wgpu_descriptor) = self.validate_buffer_descriptor(descriptor, false); let id = self .global() .wgpu_id_hub() @@ -217,7 +220,7 @@ impl GPUDeviceMethods for GPUDevice { cx: SafeJSContext, descriptor: &GPUBufferDescriptor, ) -> Vec { - let (valid, wgpu_descriptor) = self.validate_buffer_descriptor(descriptor); + let (valid, wgpu_descriptor) = self.validate_buffer_descriptor(descriptor, true); let buffer_id = self .global() .wgpu_id_hub() @@ -225,7 +228,7 @@ impl GPUDeviceMethods for GPUDevice { .create_buffer_id(self.device.0.backend()); self.channel .0 - .send(WebGPURequest::CreateBufferMapped { + .send(WebGPURequest::CreateBuffer { device_id: self.device.0, buffer_id, descriptor: wgpu_descriptor.clone(), @@ -546,7 +549,9 @@ impl GPUDeviceMethods for GPUDevice { resource: BindingResource::Buffer(BufferBinding { buffer: bind.resource.buffer.id().0, offset: bind.resource.offset, - size: bind.resource.size.unwrap_or(bind.resource.buffer.size()), + size: wgt::BufferSize( + bind.resource.size.unwrap_or(bind.resource.buffer.size()), + ), }), }) .collect::>(); @@ -729,11 +734,8 @@ impl GPUDeviceMethods for GPUDevice { mipmap_filter: convert_filter_mode(descriptor.mipmapFilter), lod_min_clamp: *descriptor.lodMinClamp, lod_max_clamp: *descriptor.lodMaxClamp, - compare: if let Some(c) = descriptor.compare { - convert_compare_function(c) - } else { - wgt::CompareFunction::Undefined - }, + compare: descriptor.compare.map(|c| convert_compare_function(c)), + anisotropy_clamp: None, }; self.channel .0 diff --git a/components/script/dom/gpupipelinelayout.rs b/components/script/dom/gpupipelinelayout.rs index d1c3d0d2bef..af665ba8c41 100644 --- a/components/script/dom/gpupipelinelayout.rs +++ b/components/script/dom/gpupipelinelayout.rs @@ -26,7 +26,7 @@ impl GPUPipelineLayout { bind_group_layouts: Vec, pipeline_layout: WebGPUPipelineLayout, valid: bool, - ) -> GPUPipelineLayout { + ) -> Self { Self { reflector_: Reflector::new(), bind_group_layouts, @@ -41,7 +41,7 @@ impl GPUPipelineLayout { bind_group_layouts: Vec, pipeline_layout: WebGPUPipelineLayout, valid: bool, - ) -> DomRoot { + ) -> DomRoot { reflect_dom_object( Box::new(GPUPipelineLayout::new_inherited( bind_group_layouts, diff --git a/components/script/dom/gpuqueue.rs b/components/script/dom/gpuqueue.rs index 1b4ffa590f3..5b533a8d32c 100644 --- a/components/script/dom/gpuqueue.rs +++ b/components/script/dom/gpuqueue.rs @@ -23,7 +23,7 @@ pub struct GPUQueue { } impl GPUQueue { - fn new_inherited(channel: WebGPU, queue: WebGPUQueue) -> GPUQueue { + fn new_inherited(channel: WebGPU, queue: WebGPUQueue) -> Self { GPUQueue { channel, reflector_: Reflector::new(), @@ -32,7 +32,7 @@ impl GPUQueue { } } - pub fn new(global: &GlobalScope, channel: WebGPU, queue: WebGPUQueue) -> DomRoot { + pub fn new(global: &GlobalScope, channel: WebGPU, queue: WebGPUQueue) -> DomRoot { reflect_dom_object(Box::new(GPUQueue::new_inherited(channel, queue)), global) } } diff --git a/components/script/dom/gpurenderpassencoder.rs b/components/script/dom/gpurenderpassencoder.rs index 47ac8c6db22..a74d1f86c8e 100644 --- a/components/script/dom/gpurenderpassencoder.rs +++ b/components/script/dom/gpurenderpassencoder.rs @@ -173,12 +173,11 @@ impl GPURenderPassEncoderMethods for GPURenderPassEncoder { /// https://gpuweb.github.io/gpuweb/#dom-gpurenderencoderbase-setindexbuffer fn SetIndexBuffer(&self, buffer: &GPUBuffer, offset: u64, size: u64) { - let s; - if size == 0 { - s = buffer.size() - offset; + let s = if size == 0 { + wgt::BufferSize::WHOLE } else { - s = size; - } + wgt::BufferSize(size) + }; if let Some(raw_pass) = self.raw_pass.borrow_mut().as_mut() { unsafe { @@ -189,12 +188,11 @@ impl GPURenderPassEncoderMethods for GPURenderPassEncoder { /// https://gpuweb.github.io/gpuweb/#dom-gpurenderencoderbase-setvertexbuffer fn SetVertexBuffer(&self, slot: u32, buffer: &GPUBuffer, offset: u64, size: u64) { - let s; - if size == 0 { - s = buffer.size() - offset; + let s = if size == 0 { + wgt::BufferSize::WHOLE } else { - s = size; - } + wgt::BufferSize(size) + }; if let Some(raw_pass) = self.raw_pass.borrow_mut().as_mut() { unsafe { diff --git a/components/script/dom/gpurenderpipeline.rs b/components/script/dom/gpurenderpipeline.rs index 68d07820103..3a9bebba945 100644 --- a/components/script/dom/gpurenderpipeline.rs +++ b/components/script/dom/gpurenderpipeline.rs @@ -27,7 +27,7 @@ impl GPURenderPipeline { render_pipeline: WebGPURenderPipeline, device: WebGPUDevice, valid: bool, - ) -> GPURenderPipeline { + ) -> Self { Self { reflector_: Reflector::new(), label: DomRefCell::new(None), @@ -42,7 +42,7 @@ impl GPURenderPipeline { render_pipeline: WebGPURenderPipeline, device: WebGPUDevice, valid: bool, - ) -> DomRoot { + ) -> DomRoot { reflect_dom_object( Box::new(GPURenderPipeline::new_inherited( render_pipeline, diff --git a/components/script/dom/gpusampler.rs b/components/script/dom/gpusampler.rs index eab237a4c8f..db85f60e9b6 100644 --- a/components/script/dom/gpusampler.rs +++ b/components/script/dom/gpusampler.rs @@ -31,7 +31,7 @@ impl GPUSampler { compare_enable: bool, sampler: WebGPUSampler, valid: bool, - ) -> GPUSampler { + ) -> Self { Self { reflector_: Reflector::new(), channel, @@ -50,7 +50,7 @@ impl GPUSampler { compare_enable: bool, sampler: WebGPUSampler, valid: bool, - ) -> DomRoot { + ) -> DomRoot { reflect_dom_object( Box::new(GPUSampler::new_inherited( channel, diff --git a/components/script/dom/gpushadermodule.rs b/components/script/dom/gpushadermodule.rs index 07aef69cbcc..24a96bdaac4 100644 --- a/components/script/dom/gpushadermodule.rs +++ b/components/script/dom/gpushadermodule.rs @@ -19,7 +19,7 @@ pub struct GPUShaderModule { } impl GPUShaderModule { - fn new_inherited(shader_module: WebGPUShaderModule) -> GPUShaderModule { + fn new_inherited(shader_module: WebGPUShaderModule) -> Self { Self { reflector_: Reflector::new(), label: DomRefCell::new(None), @@ -27,10 +27,7 @@ impl GPUShaderModule { } } - pub fn new( - global: &GlobalScope, - shader_module: WebGPUShaderModule, - ) -> DomRoot { + pub fn new(global: &GlobalScope, shader_module: WebGPUShaderModule) -> DomRoot { reflect_dom_object( Box::new(GPUShaderModule::new_inherited(shader_module)), global, diff --git a/components/script/dom/gputexture.rs b/components/script/dom/gputexture.rs index 036c1a57307..be2d11bfc50 100644 --- a/components/script/dom/gputexture.rs +++ b/components/script/dom/gputexture.rs @@ -49,7 +49,7 @@ impl GPUTexture { format: GPUTextureFormat, texture_usage: u32, valid: bool, - ) -> GPUTexture { + ) -> Self { Self { reflector_: Reflector::new(), texture, @@ -78,7 +78,7 @@ impl GPUTexture { format: GPUTextureFormat, texture_usage: u32, valid: bool, - ) -> DomRoot { + ) -> DomRoot { reflect_dom_object( Box::new(GPUTexture::new_inherited( texture, diff --git a/components/script/dom/webidls/GPUAdapter.webidl b/components/script/dom/webidls/GPUAdapter.webidl index cc664fabffa..8d2e34f4a57 100644 --- a/components/script/dom/webidls/GPUAdapter.webidl +++ b/components/script/dom/webidls/GPUAdapter.webidl @@ -14,12 +14,13 @@ interface GPUAdapter { }; dictionary GPUDeviceDescriptor : GPUObjectDescriptorBase { - GPUExtensions extensions = {}; + sequence extensions = []; GPULimits limits = {}; }; -dictionary GPUExtensions { - boolean anisotropicFiltering = false; +enum GPUExtensionName { + "texture-compression-bc", + "pipeline-statistics-query" }; dictionary GPULimits { diff --git a/components/webgpu/lib.rs b/components/webgpu/lib.rs index 442e2201e18..1248940e079 100644 --- a/components/webgpu/lib.rs +++ b/components/webgpu/lib.rs @@ -74,11 +74,6 @@ pub enum WebGPURequest { buffer_id: id::BufferId, descriptor: wgt::BufferDescriptor, }, - CreateBufferMapped { - device_id: id::DeviceId, - buffer_id: id::BufferId, - descriptor: wgt::BufferDescriptor, - }, CreateCommandEncoder { device_id: id::DeviceId, // TODO(zakorgy): Serialize CommandEncoderDescriptor in wgpu-core @@ -315,26 +310,9 @@ impl WGPU { descriptor, } => { let global = &self.global; - let desc = wgt::BufferDescriptor { - size: descriptor.size, - usage: descriptor.usage, - label: ptr::null(), - }; - let _ = gfx_select!(buffer_id => global.device_create_buffer(device_id, &desc, buffer_id)); - }, - WebGPURequest::CreateBufferMapped { - device_id, - buffer_id, - descriptor, - } => { - let global = &self.global; - let desc = wgt::BufferDescriptor { - size: descriptor.size, - usage: descriptor.usage, - label: ptr::null(), - }; + let st = CString::new(descriptor.label.as_bytes()).unwrap(); let _ = gfx_select!(buffer_id => - global.device_create_buffer_mapped(device_id, &desc, buffer_id)); + global.device_create_buffer(device_id, &descriptor.map_label(|_| st.as_ptr()), buffer_id)); }, WebGPURequest::CreateCommandEncoder { device_id,