diff --git a/Cargo.lock b/Cargo.lock index fc1c351d2e15..396adc979c72 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 8420a0058fc8..7947a0693352 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 b7b8cadeacfd..4767d28d0f16 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 c57fc2723287..8c1412562617 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 643fbfc98c7c..1c756dae15f5 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 b1871051e523..4b23a622ca34 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 6fcd1bc23b62..d0ba2dc8624b 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 a4700db4505e..e96697c95a29 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 6a4301124b9b..e8720bf2189f 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 d1c3d0d2beff..af665ba8c417 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 1b4ffa590f36..5b533a8d32c4 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 47ac8c6db222..a74d1f86c8e6 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 68d07820103b..3a9bebba9457 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 eab237a4c8f4..db85f60e9b6d 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 07aef69cbcc6..24a96bdaac49 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 036c1a57307d..be2d11bfc501 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 cc664fabffa5..8d2e34f4a572 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 442e2201e188..1248940e0795 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,