Auto merge of #27329 - kunalmohan:gpu-label, r=kvark

Update GPUObjectBase webidl and cleanup valid flags

<!-- Please describe your changes on the following line: -->
Update labels to be `USVString`
Remove `valid` flags in WebGPU resources. The only place where we still have that is `GPUCommandEncoder` (Only to validate the GPUCommandEncoder state. Not sure how errors would be handled/reported by server for copy commands).

r?@kvark

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [ ] These changes fix #___ (GitHub issue number if applicable)

<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because ___

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
This commit is contained in:
bors-servo 2020-07-20 20:43:56 -04:00 committed by GitHub
commit 59841377c2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
20 changed files with 229 additions and 251 deletions

View file

@ -6,28 +6,25 @@ use crate::dom::bindings::cell::DomRefCell;
use crate::dom::bindings::codegen::Bindings::GPUBindGroupBinding::GPUBindGroupMethods;
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::bindings::str::USVString;
use crate::dom::globalscope::GlobalScope;
use crate::dom::gpubindgrouplayout::GPUBindGroupLayout;
use dom_struct::dom_struct;
use std::cell::Cell;
use webgpu::{WebGPUBindGroup, WebGPUDevice};
#[dom_struct]
pub struct GPUBindGroup {
reflector_: Reflector,
label: DomRefCell<Option<DOMString>>,
label: DomRefCell<Option<USVString>>,
bind_group: WebGPUBindGroup,
device: WebGPUDevice,
layout: Dom<GPUBindGroupLayout>,
valid: Cell<bool>,
}
impl GPUBindGroup {
fn new_inherited(
bind_group: WebGPUBindGroup,
device: WebGPUDevice,
valid: bool,
layout: &GPUBindGroupLayout,
) -> Self {
Self {
@ -35,7 +32,6 @@ impl GPUBindGroup {
label: DomRefCell::new(None),
bind_group,
device,
valid: Cell::new(valid),
layout: Dom::from_ref(layout),
}
}
@ -44,13 +40,10 @@ impl GPUBindGroup {
global: &GlobalScope,
bind_group: WebGPUBindGroup,
device: WebGPUDevice,
valid: bool,
layout: &GPUBindGroupLayout,
) -> DomRoot<Self> {
reflect_dom_object(
Box::new(GPUBindGroup::new_inherited(
bind_group, device, valid, layout,
)),
Box::new(GPUBindGroup::new_inherited(bind_group, device, layout)),
global,
)
}
@ -64,12 +57,12 @@ impl GPUBindGroup {
impl GPUBindGroupMethods for GPUBindGroup {
/// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label
fn GetLabel(&self) -> Option<DOMString> {
fn GetLabel(&self) -> Option<USVString> {
self.label.borrow().clone()
}
/// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label
fn SetLabel(&self, value: Option<DOMString>) {
fn SetLabel(&self, value: Option<USVString>) {
*self.label.borrow_mut() = value;
}
}

View file

@ -6,47 +6,36 @@ use crate::dom::bindings::cell::DomRefCell;
use crate::dom::bindings::codegen::Bindings::GPUBindGroupLayoutBinding::GPUBindGroupLayoutMethods;
use crate::dom::bindings::reflector::{reflect_dom_object, Reflector};
use crate::dom::bindings::root::DomRoot;
use crate::dom::bindings::str::DOMString;
use crate::dom::bindings::str::USVString;
use crate::dom::globalscope::GlobalScope;
use dom_struct::dom_struct;
use std::cell::Cell;
use webgpu::WebGPUBindGroupLayout;
#[dom_struct]
pub struct GPUBindGroupLayout {
reflector_: Reflector,
label: DomRefCell<Option<DOMString>>,
label: DomRefCell<Option<USVString>>,
bind_group_layout: WebGPUBindGroupLayout,
valid: Cell<bool>,
}
impl GPUBindGroupLayout {
fn new_inherited(bind_group_layout: WebGPUBindGroupLayout, valid: bool) -> Self {
fn new_inherited(bind_group_layout: WebGPUBindGroupLayout) -> Self {
Self {
reflector_: Reflector::new(),
label: DomRefCell::new(None),
bind_group_layout,
valid: Cell::new(valid),
}
}
pub fn new(
global: &GlobalScope,
bind_group_layout: WebGPUBindGroupLayout,
valid: bool,
) -> DomRoot<Self> {
pub fn new(global: &GlobalScope, bind_group_layout: WebGPUBindGroupLayout) -> DomRoot<Self> {
reflect_dom_object(
Box::new(GPUBindGroupLayout::new_inherited(bind_group_layout, valid)),
Box::new(GPUBindGroupLayout::new_inherited(bind_group_layout)),
global,
)
}
}
impl GPUBindGroupLayout {
pub fn is_valid(&self) -> bool {
self.valid.get()
}
pub fn id(&self) -> WebGPUBindGroupLayout {
self.bind_group_layout
}
@ -54,12 +43,12 @@ impl GPUBindGroupLayout {
impl GPUBindGroupLayoutMethods for GPUBindGroupLayout {
/// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label
fn GetLabel(&self) -> Option<DOMString> {
fn GetLabel(&self) -> Option<USVString> {
self.label.borrow().clone()
}
/// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label
fn SetLabel(&self, value: Option<DOMString>) {
fn SetLabel(&self, value: Option<USVString>) {
*self.label.borrow_mut() = value;
}
}

View file

@ -9,7 +9,7 @@ use crate::dom::bindings::error::{Error, Fallible};
use crate::dom::bindings::reflector::DomObject;
use crate::dom::bindings::reflector::{reflect_dom_object, Reflector};
use crate::dom::bindings::root::DomRoot;
use crate::dom::bindings::str::DOMString;
use crate::dom::bindings::str::USVString;
use crate::dom::globalscope::GlobalScope;
use crate::dom::gpu::{response_async, AsyncWGPUListener};
use crate::dom::promise::Promise;
@ -58,11 +58,10 @@ pub struct GPUBuffer {
reflector_: Reflector,
#[ignore_malloc_size_of = "defined in webgpu"]
channel: WebGPU,
label: DomRefCell<Option<DOMString>>,
label: DomRefCell<Option<USVString>>,
state: Cell<GPUBufferState>,
buffer: WebGPUBuffer,
device: WebGPUDevice,
valid: Cell<bool>,
size: GPUSize64,
#[ignore_malloc_size_of = "promises are hard"]
map_promise: DomRefCell<Option<Rc<Promise>>>,
@ -76,7 +75,6 @@ impl GPUBuffer {
device: WebGPUDevice,
state: GPUBufferState,
size: GPUSize64,
valid: bool,
map_info: DomRefCell<Option<GPUBufferMapInfo>>,
) -> Self {
Self {
@ -84,7 +82,6 @@ impl GPUBuffer {
channel,
label: DomRefCell::new(None),
state: Cell::new(state),
valid: Cell::new(valid),
device,
buffer,
map_promise: DomRefCell::new(None),
@ -101,12 +98,11 @@ impl GPUBuffer {
device: WebGPUDevice,
state: GPUBufferState,
size: GPUSize64,
valid: bool,
map_info: DomRefCell<Option<GPUBufferMapInfo>>,
) -> DomRoot<Self> {
reflect_dom_object(
Box::new(GPUBuffer::new_inherited(
channel, buffer, device, state, size, valid, map_info,
channel, buffer, device, state, size, map_info,
)),
global,
)
@ -121,10 +117,6 @@ impl GPUBuffer {
pub fn state(&self) -> GPUBufferState {
self.state.get()
}
pub fn is_valid(&self) -> bool {
self.valid.get()
}
}
impl Drop for GPUBuffer {
@ -305,12 +297,12 @@ impl GPUBufferMethods for GPUBuffer {
}
/// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label
fn GetLabel(&self) -> Option<DOMString> {
fn GetLabel(&self) -> Option<USVString> {
self.label.borrow().clone()
}
/// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label
fn SetLabel(&self, value: Option<DOMString>) {
fn SetLabel(&self, value: Option<USVString>) {
*self.label.borrow_mut() = value;
}
}

View file

@ -7,7 +7,7 @@ use crate::dom::bindings::codegen::Bindings::GPUCommandBufferBinding::GPUCommand
use crate::dom::bindings::reflector::{reflect_dom_object, Reflector};
use crate::dom::bindings::root::Dom;
use crate::dom::bindings::root::DomRoot;
use crate::dom::bindings::str::DOMString;
use crate::dom::bindings::str::USVString;
use crate::dom::globalscope::GlobalScope;
use crate::dom::gpubuffer::GPUBuffer;
use dom_struct::dom_struct;
@ -27,7 +27,7 @@ pub struct GPUCommandBuffer {
reflector_: Reflector,
#[ignore_malloc_size_of = "defined in webgpu"]
channel: WebGPU,
label: DomRefCell<Option<DOMString>>,
label: DomRefCell<Option<USVString>>,
command_buffer: WebGPUCommandBuffer,
buffers: DomRefCell<HashSet<Dom<GPUBuffer>>>,
}
@ -76,12 +76,12 @@ impl GPUCommandBuffer {
impl GPUCommandBufferMethods for GPUCommandBuffer {
/// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label
fn GetLabel(&self) -> Option<DOMString> {
fn GetLabel(&self) -> Option<USVString> {
self.label.borrow().clone()
}
/// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label
fn SetLabel(&self, value: Option<DOMString>) {
fn SetLabel(&self, value: Option<USVString>) {
*self.label.borrow_mut() = value;
}
}

View file

@ -14,7 +14,7 @@ use crate::dom::bindings::codegen::UnionTypes::{
use crate::dom::bindings::reflector::DomObject;
use crate::dom::bindings::reflector::{reflect_dom_object, Reflector};
use crate::dom::bindings::root::DomRoot;
use crate::dom::bindings::str::DOMString;
use crate::dom::bindings::str::USVString;
use crate::dom::globalscope::GlobalScope;
use crate::dom::gpubuffer::GPUBuffer;
use crate::dom::gpucommandbuffer::GPUCommandBuffer;
@ -43,7 +43,7 @@ pub struct GPUCommandEncoder {
reflector_: Reflector,
#[ignore_malloc_size_of = "defined in webgpu"]
channel: WebGPU,
label: DomRefCell<Option<DOMString>>,
label: DomRefCell<Option<USVString>>,
encoder: webgpu::WebGPUCommandEncoder,
buffers: DomRefCell<HashSet<DomRoot<GPUBuffer>>>,
state: DomRefCell<GPUCommandEncoderState>,
@ -103,12 +103,12 @@ impl GPUCommandEncoder {
impl GPUCommandEncoderMethods for GPUCommandEncoder {
/// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label
fn GetLabel(&self) -> Option<DOMString> {
fn GetLabel(&self) -> Option<USVString> {
self.label.borrow().clone()
}
/// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label
fn SetLabel(&self, value: Option<DOMString>) {
fn SetLabel(&self, value: Option<USVString>) {
*self.label.borrow_mut() = value;
}
@ -229,9 +229,7 @@ impl GPUCommandEncoderMethods for GPUCommandEncoder {
destination_offset: GPUSize64,
size: GPUSize64,
) {
let valid = source.is_valid() &&
destination.is_valid() &&
*self.state.borrow() == GPUCommandEncoderState::Open;
let valid = *self.state.borrow() == GPUCommandEncoderState::Open;
if !valid {
// TODO: Record an error in the current scope.

View file

@ -6,7 +6,7 @@ use crate::dom::bindings::cell::DomRefCell;
use crate::dom::bindings::codegen::Bindings::GPUComputePassEncoderBinding::GPUComputePassEncoderMethods;
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::bindings::str::USVString;
use crate::dom::globalscope::GlobalScope;
use crate::dom::gpubindgroup::GPUBindGroup;
use crate::dom::gpubuffer::GPUBuffer;
@ -23,7 +23,7 @@ pub struct GPUComputePassEncoder {
reflector_: Reflector,
#[ignore_malloc_size_of = "defined in webgpu"]
channel: WebGPU,
label: DomRefCell<Option<DOMString>>,
label: DomRefCell<Option<USVString>>,
#[ignore_malloc_size_of = "defined in wgpu-core"]
compute_pass: DomRefCell<Option<ComputePass>>,
command_encoder: Dom<GPUCommandEncoder>,
@ -50,12 +50,12 @@ impl GPUComputePassEncoder {
impl GPUComputePassEncoderMethods for GPUComputePassEncoder {
/// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label
fn GetLabel(&self) -> Option<DOMString> {
fn GetLabel(&self) -> Option<USVString> {
self.label.borrow().clone()
}
/// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label
fn SetLabel(&self, value: Option<DOMString>) {
fn SetLabel(&self, value: Option<USVString>) {
*self.label.borrow_mut() = value;
}

View file

@ -7,37 +7,30 @@ use crate::dom::bindings::codegen::Bindings::GPUComputePipelineBinding::GPUCompu
use crate::dom::bindings::reflector::reflect_dom_object;
use crate::dom::bindings::reflector::Reflector;
use crate::dom::bindings::root::DomRoot;
use crate::dom::bindings::str::DOMString;
use crate::dom::bindings::str::USVString;
use crate::dom::globalscope::GlobalScope;
use dom_struct::dom_struct;
use std::cell::Cell;
use webgpu::WebGPUComputePipeline;
#[dom_struct]
pub struct GPUComputePipeline {
reflector_: Reflector,
label: DomRefCell<Option<DOMString>>,
label: DomRefCell<Option<USVString>>,
compute_pipeline: WebGPUComputePipeline,
valid: Cell<bool>,
}
impl GPUComputePipeline {
fn new_inherited(compute_pipeline: WebGPUComputePipeline, valid: bool) -> Self {
fn new_inherited(compute_pipeline: WebGPUComputePipeline) -> Self {
Self {
reflector_: Reflector::new(),
label: DomRefCell::new(None),
compute_pipeline,
valid: Cell::new(valid),
}
}
pub fn new(
global: &GlobalScope,
compute_pipeline: WebGPUComputePipeline,
valid: bool,
) -> DomRoot<Self> {
pub fn new(global: &GlobalScope, compute_pipeline: WebGPUComputePipeline) -> DomRoot<Self> {
reflect_dom_object(
Box::new(GPUComputePipeline::new_inherited(compute_pipeline, valid)),
Box::new(GPUComputePipeline::new_inherited(compute_pipeline)),
global,
)
}
@ -51,12 +44,12 @@ impl GPUComputePipeline {
impl GPUComputePipelineMethods for GPUComputePipeline {
/// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label
fn GetLabel(&self) -> Option<DOMString> {
fn GetLabel(&self) -> Option<USVString> {
self.label.borrow().clone()
}
/// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label
fn SetLabel(&self, value: Option<DOMString>) {
fn SetLabel(&self, value: Option<USVString>) {
*self.label.borrow_mut() = value;
}
}

View file

@ -34,11 +34,11 @@ use crate::dom::bindings::codegen::Bindings::GPUTextureViewBinding::GPUTextureVi
use crate::dom::bindings::codegen::Bindings::GPUValidationErrorBinding::{
GPUError, GPUErrorFilter,
};
use crate::dom::bindings::codegen::UnionTypes::Uint32ArrayOrString::{String, Uint32Array};
use crate::dom::bindings::codegen::UnionTypes::Uint32ArrayOrString;
use crate::dom::bindings::error::Error;
use crate::dom::bindings::reflector::{reflect_dom_object, DomObject};
use crate::dom::bindings::root::{Dom, DomRoot};
use crate::dom::bindings::str::DOMString;
use crate::dom::bindings::str::USVString;
use crate::dom::bindings::trace::RootedTraceableBox;
use crate::dom::eventtarget::EventTarget;
use crate::dom::globalscope::GlobalScope;
@ -64,6 +64,7 @@ use std::cell::RefCell;
use std::collections::HashMap;
use std::ptr::NonNull;
use std::rc::Rc;
use std::string::String;
use webgpu::wgpu::binding_model::BufferBinding;
use webgpu::{self, wgt, WebGPU, WebGPUBindings, WebGPURequest};
@ -96,7 +97,7 @@ pub struct GPUDevice {
extensions: Heap<*mut JSObject>,
#[ignore_malloc_size_of = "mozjs"]
limits: Heap<*mut JSObject>,
label: DomRefCell<Option<DOMString>>,
label: DomRefCell<Option<USVString>>,
device: webgpu::WebGPUDevice,
default_queue: Dom<GPUQueue>,
scope_context: DomRefCell<ScopeContext>,
@ -227,12 +228,12 @@ impl GPUDeviceMethods for GPUDevice {
}
/// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label
fn GetLabel(&self) -> Option<DOMString> {
fn GetLabel(&self) -> Option<USVString> {
self.label.borrow().clone()
}
/// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label
fn SetLabel(&self, value: Option<DOMString>) {
fn SetLabel(&self, value: Option<USVString>) {
*self.label.borrow_mut() = value;
}
@ -246,7 +247,11 @@ impl GPUDeviceMethods for GPUDevice {
/// https://gpuweb.github.io/gpuweb/#dom-gpudevice-createbuffer
fn CreateBuffer(&self, descriptor: &GPUBufferDescriptor) -> DomRoot<GPUBuffer> {
let wgpu_descriptor = wgt::BufferDescriptor {
label: Default::default(),
label: descriptor
.parent
.label
.as_ref()
.map(|s| String::from(s.as_ref())),
size: descriptor.size,
usage: match wgt::BufferUsage::from_bits(descriptor.usage) {
Some(u) => u,
@ -293,7 +298,6 @@ impl GPUDeviceMethods for GPUDevice {
self.device,
state,
descriptor.size,
true,
map_info,
)
}
@ -409,12 +413,17 @@ impl GPUDeviceMethods for GPUDevice {
bind_group_layout_id,
entries: entries.clone(),
scope_id,
label: descriptor
.parent
.label
.as_ref()
.map(|s| String::from(s.as_ref())),
})
.expect("Failed to create WebGPU BindGroupLayout");
let bgl = webgpu::WebGPUBindGroupLayout(bind_group_layout_id);
let layout = GPUBindGroupLayout::new(&self.global(), bgl, true);
let layout = GPUBindGroupLayout::new(&self.global(), bgl);
self.bind_group_layouts
.borrow_mut()
@ -429,11 +438,10 @@ impl GPUDeviceMethods for GPUDevice {
descriptor: &GPUPipelineLayoutDescriptor,
) -> DomRoot<GPUPipelineLayout> {
let mut bgl_ids = Vec::new();
descriptor.bindGroupLayouts.iter().for_each(|each| {
if each.is_valid() {
bgl_ids.push(each.id().0);
}
});
descriptor
.bindGroupLayouts
.iter()
.for_each(|each| bgl_ids.push(each.id().0));
let scope_id = self.use_current_scope();
@ -453,12 +461,11 @@ impl GPUDeviceMethods for GPUDevice {
.expect("Failed to create WebGPU PipelineLayout");
let pipeline_layout = webgpu::WebGPUPipelineLayout(pipeline_layout_id);
GPUPipelineLayout::new(&self.global(), pipeline_layout, true)
GPUPipelineLayout::new(&self.global(), pipeline_layout)
}
/// https://gpuweb.github.io/gpuweb/#dom-gpudevice-createbindgroup
fn CreateBindGroup(&self, descriptor: &GPUBindGroupDescriptor) -> DomRoot<GPUBindGroup> {
let mut valid = descriptor.layout.is_valid();
let entries = descriptor
.entries
.iter()
@ -466,16 +473,11 @@ impl GPUDeviceMethods for GPUDevice {
(
bind.binding,
match bind.resource {
GPUBindingResource::GPUSampler(ref s) => {
valid &= s.is_valid();
WebGPUBindings::Sampler(s.id().0)
},
GPUBindingResource::GPUSampler(ref s) => WebGPUBindings::Sampler(s.id().0),
GPUBindingResource::GPUTextureView(ref t) => {
valid &= t.is_valid();
WebGPUBindings::TextureView(t.id().0)
},
GPUBindingResource::GPUBufferBindings(ref b) => {
valid &= b.buffer.is_valid();
WebGPUBindings::Buffer(BufferBinding {
buffer_id: b.buffer.id().0,
offset: b.offset,
@ -502,18 +504,17 @@ impl GPUDeviceMethods for GPUDevice {
bind_group_layout_id: descriptor.layout.id().0,
entries,
scope_id,
label: descriptor
.parent
.label
.as_ref()
.map(|s| String::from(s.as_ref())),
})
.expect("Failed to create WebGPU BindGroup");
let bind_group = webgpu::WebGPUBindGroup(bind_group_id);
GPUBindGroup::new(
&self.global(),
bind_group,
self.device,
valid,
&*descriptor.layout,
)
GPUBindGroup::new(&self.global(), bind_group, self.device, &*descriptor.layout)
}
/// https://gpuweb.github.io/gpuweb/#dom-gpudevice-createshadermodule
@ -522,8 +523,10 @@ impl GPUDeviceMethods for GPUDevice {
descriptor: RootedTraceableBox<GPUShaderModuleDescriptor>,
) -> DomRoot<GPUShaderModule> {
let program: Vec<u32> = match &descriptor.code {
Uint32Array(program) => program.to_vec(),
String(program) => program.chars().map(|c| c as u32).collect::<Vec<u32>>(),
Uint32ArrayOrString::Uint32Array(program) => program.to_vec(),
Uint32ArrayOrString::String(program) => {
program.chars().map(|c| c as u32).collect::<Vec<u32>>()
},
};
let program_id = self
.global()
@ -548,7 +551,6 @@ impl GPUDeviceMethods for GPUDevice {
&self,
descriptor: &GPUComputePipelineDescriptor,
) -> DomRoot<GPUComputePipeline> {
let valid = descriptor.parent.layout.is_valid();
let pipeline = descriptor.parent.layout.id();
let program = descriptor.computeStage.module.id();
let entry_point = descriptor.computeStage.entryPoint.to_string();
@ -573,13 +575,13 @@ impl GPUDeviceMethods for GPUDevice {
.expect("Failed to create WebGPU ComputePipeline");
let compute_pipeline = webgpu::WebGPUComputePipeline(compute_pipeline_id);
GPUComputePipeline::new(&self.global(), compute_pipeline, valid)
GPUComputePipeline::new(&self.global(), compute_pipeline)
}
/// https://gpuweb.github.io/gpuweb/#dom-gpudevice-createcommandencoder
fn CreateCommandEncoder(
&self,
_descriptor: &GPUCommandEncoderDescriptor,
descriptor: &GPUCommandEncoderDescriptor,
) -> DomRoot<GPUCommandEncoder> {
let command_encoder_id = self
.global()
@ -591,6 +593,11 @@ impl GPUDeviceMethods for GPUDevice {
.send(WebGPURequest::CreateCommandEncoder {
device_id: self.device.0,
command_encoder_id,
label: descriptor
.parent
.label
.as_ref()
.map(|s| String::from(s.as_ref())),
})
.expect("Failed to create WebGPU command encoder");
@ -607,10 +614,13 @@ impl GPUDeviceMethods for GPUDevice {
/// https://gpuweb.github.io/gpuweb/#dom-gpudevice-createtexture
fn CreateTexture(&self, descriptor: &GPUTextureDescriptor) -> DomRoot<GPUTexture> {
let mut valid = true;
let size = convert_texture_size_to_dict(&descriptor.size);
let desc = wgt::TextureDescriptor {
label: Default::default(),
label: descriptor
.parent
.label
.as_ref()
.map(|s| String::from(s.as_ref())),
size: convert_texture_size_to_wgt(&size),
mip_level_count: descriptor.mipLevelCount,
sample_count: descriptor.sampleCount,
@ -622,10 +632,7 @@ impl GPUDeviceMethods for GPUDevice {
format: convert_texture_format(descriptor.format),
usage: match wgt::TextureUsage::from_bits(descriptor.usage) {
Some(t) => t,
None => {
valid = false;
wgt::TextureUsage::empty()
},
None => wgt::TextureUsage::empty(),
},
};
@ -657,7 +664,6 @@ impl GPUDeviceMethods for GPUDevice {
descriptor.dimension,
descriptor.format,
descriptor.usage,
valid,
)
}
@ -670,7 +676,11 @@ impl GPUDeviceMethods for GPUDevice {
.create_sampler_id(self.device.0.backend());
let compare_enable = descriptor.compare.is_some();
let desc = wgt::SamplerDescriptor {
label: Default::default(),
label: descriptor
.parent
.label
.as_ref()
.map(|s| String::from(s.as_ref())),
address_mode_u: convert_address_mode(descriptor.addressModeU),
address_mode_v: convert_address_mode(descriptor.addressModeV),
address_mode_w: convert_address_mode(descriptor.addressModeW),
@ -694,7 +704,7 @@ impl GPUDeviceMethods for GPUDevice {
let sampler = webgpu::WebGPUSampler(sampler_id);
GPUSampler::new(&self.global(), self.device, compare_enable, sampler, true)
GPUSampler::new(&self.global(), self.device, compare_enable, sampler)
}
/// https://gpuweb.github.io/gpuweb/#dom-gpudevice-createrenderpipeline
@ -702,7 +712,6 @@ impl GPUDeviceMethods for GPUDevice {
&self,
descriptor: &GPURenderPipelineDescriptor,
) -> DomRoot<GPURenderPipeline> {
let valid = descriptor.parent.layout.is_valid();
let vertex_module = descriptor.vertexStage.module.id().0;
let vertex_entry_point = descriptor.vertexStage.entryPoint.to_string();
let (fragment_module, fragment_entry_point) = match descriptor.fragmentStage {
@ -834,7 +843,7 @@ impl GPUDeviceMethods for GPUDevice {
let render_pipeline = webgpu::WebGPURenderPipeline(render_pipeline_id);
GPURenderPipeline::new(&self.global(), render_pipeline, self.device, valid)
GPURenderPipeline::new(&self.global(), render_pipeline, self.device)
}
/// https://gpuweb.github.io/gpuweb/#dom-gpudevice-pusherrorscope

View file

@ -6,37 +6,30 @@ use crate::dom::bindings::cell::DomRefCell;
use crate::dom::bindings::codegen::Bindings::GPUPipelineLayoutBinding::GPUPipelineLayoutMethods;
use crate::dom::bindings::reflector::{reflect_dom_object, Reflector};
use crate::dom::bindings::root::DomRoot;
use crate::dom::bindings::str::DOMString;
use crate::dom::bindings::str::USVString;
use crate::dom::globalscope::GlobalScope;
use dom_struct::dom_struct;
use std::cell::Cell;
use webgpu::WebGPUPipelineLayout;
#[dom_struct]
pub struct GPUPipelineLayout {
reflector_: Reflector,
label: DomRefCell<Option<DOMString>>,
label: DomRefCell<Option<USVString>>,
pipeline_layout: WebGPUPipelineLayout,
valid: Cell<bool>,
}
impl GPUPipelineLayout {
fn new_inherited(pipeline_layout: WebGPUPipelineLayout, valid: bool) -> Self {
fn new_inherited(pipeline_layout: WebGPUPipelineLayout) -> Self {
Self {
reflector_: Reflector::new(),
label: DomRefCell::new(None),
pipeline_layout,
valid: Cell::new(valid),
}
}
pub fn new(
global: &GlobalScope,
pipeline_layout: WebGPUPipelineLayout,
valid: bool,
) -> DomRoot<Self> {
pub fn new(global: &GlobalScope, pipeline_layout: WebGPUPipelineLayout) -> DomRoot<Self> {
reflect_dom_object(
Box::new(GPUPipelineLayout::new_inherited(pipeline_layout, valid)),
Box::new(GPUPipelineLayout::new_inherited(pipeline_layout)),
global,
)
}
@ -46,20 +39,16 @@ impl GPUPipelineLayout {
pub fn id(&self) -> WebGPUPipelineLayout {
self.pipeline_layout
}
pub fn is_valid(&self) -> bool {
self.valid.get()
}
}
impl GPUPipelineLayoutMethods for GPUPipelineLayout {
/// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label
fn GetLabel(&self) -> Option<DOMString> {
fn GetLabel(&self) -> Option<USVString> {
self.label.borrow().clone()
}
/// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label
fn SetLabel(&self, value: Option<DOMString>) {
fn SetLabel(&self, value: Option<USVString>) {
*self.label.borrow_mut() = value;
}
}

View file

@ -11,7 +11,7 @@ use crate::dom::bindings::codegen::Bindings::GPUTextureBinding::{
use crate::dom::bindings::error::{Error, Fallible};
use crate::dom::bindings::reflector::{reflect_dom_object, Reflector};
use crate::dom::bindings::root::DomRoot;
use crate::dom::bindings::str::DOMString;
use crate::dom::bindings::str::USVString;
use crate::dom::globalscope::GlobalScope;
use crate::dom::gpubuffer::{GPUBuffer, GPUBufferState};
use crate::dom::gpucommandbuffer::GPUCommandBuffer;
@ -27,7 +27,7 @@ pub struct GPUQueue {
reflector_: Reflector,
#[ignore_malloc_size_of = "defined in webgpu"]
channel: WebGPU,
label: DomRefCell<Option<DOMString>>,
label: DomRefCell<Option<USVString>>,
queue: WebGPUQueue,
}
@ -48,12 +48,12 @@ impl GPUQueue {
impl GPUQueueMethods for GPUQueue {
/// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label
fn GetLabel(&self) -> Option<DOMString> {
fn GetLabel(&self) -> Option<USVString> {
self.label.borrow().clone()
}
/// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label
fn SetLabel(&self, value: Option<DOMString>) {
fn SetLabel(&self, value: Option<USVString>) {
*self.label.borrow_mut() = value;
}
@ -98,8 +98,7 @@ impl GPUQueueMethods for GPUQueue {
let valid = data_offset + content_size <= bytes.len() as u64 &&
buffer.state() == GPUBufferState::Unmapped &&
content_size % wgt::COPY_BUFFER_ALIGNMENT == 0 &&
buffer_offset % wgt::COPY_BUFFER_ALIGNMENT == 0 &&
buffer.is_valid();
buffer_offset % wgt::COPY_BUFFER_ALIGNMENT == 0;
if !valid {
return Err(Error::Operation);
@ -130,7 +129,7 @@ impl GPUQueueMethods for GPUQueue {
size: GPUExtent3D,
) -> Fallible<()> {
let bytes = data.to_vec();
let valid = data_layout.offset <= data.len() as u64 && destination.texture.is_valid();
let valid = data_layout.offset <= data.len() as u64;
if !valid {
return Err(Error::Operation);

View file

@ -8,7 +8,7 @@ use crate::dom::bindings::codegen::Bindings::GPURenderPassEncoderBinding::GPURen
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::bindings::str::USVString;
use crate::dom::globalscope::GlobalScope;
use crate::dom::gpubindgroup::GPUBindGroup;
use crate::dom::gpubuffer::GPUBuffer;
@ -25,7 +25,7 @@ pub struct GPURenderPassEncoder {
reflector_: Reflector,
#[ignore_malloc_size_of = "defined in webgpu"]
channel: WebGPU,
label: DomRefCell<Option<DOMString>>,
label: DomRefCell<Option<USVString>>,
#[ignore_malloc_size_of = "defined in wgpu-core"]
render_pass: DomRefCell<Option<RenderPass>>,
command_encoder: Dom<GPUCommandEncoder>,
@ -61,12 +61,12 @@ impl GPURenderPassEncoder {
impl GPURenderPassEncoderMethods for GPURenderPassEncoder {
/// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label
fn GetLabel(&self) -> Option<DOMString> {
fn GetLabel(&self) -> Option<USVString> {
self.label.borrow().clone()
}
/// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label
fn SetLabel(&self, value: Option<DOMString>) {
fn SetLabel(&self, value: Option<USVString>) {
*self.label.borrow_mut() = value;
}

View file

@ -7,32 +7,25 @@ use crate::dom::bindings::codegen::Bindings::GPURenderPipelineBinding::GPURender
use crate::dom::bindings::reflector::reflect_dom_object;
use crate::dom::bindings::reflector::Reflector;
use crate::dom::bindings::root::DomRoot;
use crate::dom::bindings::str::DOMString;
use crate::dom::bindings::str::USVString;
use crate::dom::globalscope::GlobalScope;
use dom_struct::dom_struct;
use std::cell::Cell;
use webgpu::{WebGPUDevice, WebGPURenderPipeline};
#[dom_struct]
pub struct GPURenderPipeline {
reflector_: Reflector,
label: DomRefCell<Option<DOMString>>,
label: DomRefCell<Option<USVString>>,
render_pipeline: WebGPURenderPipeline,
device: WebGPUDevice,
valid: Cell<bool>,
}
impl GPURenderPipeline {
fn new_inherited(
render_pipeline: WebGPURenderPipeline,
device: WebGPUDevice,
valid: bool,
) -> Self {
fn new_inherited(render_pipeline: WebGPURenderPipeline, device: WebGPUDevice) -> Self {
Self {
reflector_: Reflector::new(),
label: DomRefCell::new(None),
render_pipeline,
valid: Cell::new(valid),
device,
}
}
@ -41,14 +34,9 @@ impl GPURenderPipeline {
global: &GlobalScope,
render_pipeline: WebGPURenderPipeline,
device: WebGPUDevice,
valid: bool,
) -> DomRoot<Self> {
reflect_dom_object(
Box::new(GPURenderPipeline::new_inherited(
render_pipeline,
device,
valid,
)),
Box::new(GPURenderPipeline::new_inherited(render_pipeline, device)),
global,
)
}
@ -62,12 +50,12 @@ impl GPURenderPipeline {
impl GPURenderPipelineMethods for GPURenderPipeline {
/// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label
fn GetLabel(&self) -> Option<DOMString> {
fn GetLabel(&self) -> Option<USVString> {
self.label.borrow().clone()
}
/// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label
fn SetLabel(&self, value: Option<DOMString>) {
fn SetLabel(&self, value: Option<USVString>) {
*self.label.borrow_mut() = value;
}
}

View file

@ -6,33 +6,25 @@ use crate::dom::bindings::cell::DomRefCell;
use crate::dom::bindings::codegen::Bindings::GPUSamplerBinding::GPUSamplerMethods;
use crate::dom::bindings::reflector::{reflect_dom_object, Reflector};
use crate::dom::bindings::root::DomRoot;
use crate::dom::bindings::str::DOMString;
use crate::dom::bindings::str::USVString;
use crate::dom::globalscope::GlobalScope;
use dom_struct::dom_struct;
use std::cell::Cell;
use webgpu::{WebGPUDevice, WebGPUSampler};
#[dom_struct]
pub struct GPUSampler {
reflector_: Reflector,
label: DomRefCell<Option<DOMString>>,
label: DomRefCell<Option<USVString>>,
device: WebGPUDevice,
compare_enable: bool,
sampler: WebGPUSampler,
valid: Cell<bool>,
}
impl GPUSampler {
fn new_inherited(
device: WebGPUDevice,
compare_enable: bool,
sampler: WebGPUSampler,
valid: bool,
) -> Self {
fn new_inherited(device: WebGPUDevice, compare_enable: bool, sampler: WebGPUSampler) -> Self {
Self {
reflector_: Reflector::new(),
label: DomRefCell::new(None),
valid: Cell::new(valid),
device,
sampler,
compare_enable,
@ -44,15 +36,9 @@ impl GPUSampler {
device: WebGPUDevice,
compare_enable: bool,
sampler: WebGPUSampler,
valid: bool,
) -> DomRoot<Self> {
reflect_dom_object(
Box::new(GPUSampler::new_inherited(
device,
compare_enable,
sampler,
valid,
)),
Box::new(GPUSampler::new_inherited(device, compare_enable, sampler)),
global,
)
}
@ -62,20 +48,16 @@ impl GPUSampler {
pub fn id(&self) -> WebGPUSampler {
self.sampler
}
pub fn is_valid(&self) -> bool {
self.valid.get()
}
}
impl GPUSamplerMethods for GPUSampler {
/// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label
fn GetLabel(&self) -> Option<DOMString> {
fn GetLabel(&self) -> Option<USVString> {
self.label.borrow().clone()
}
/// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label
fn SetLabel(&self, value: Option<DOMString>) {
fn SetLabel(&self, value: Option<USVString>) {
*self.label.borrow_mut() = value;
}
}

View file

@ -6,7 +6,7 @@ use crate::dom::bindings::cell::DomRefCell;
use crate::dom::bindings::codegen::Bindings::GPUShaderModuleBinding::GPUShaderModuleMethods;
use crate::dom::bindings::reflector::{reflect_dom_object, Reflector};
use crate::dom::bindings::root::DomRoot;
use crate::dom::bindings::str::DOMString;
use crate::dom::bindings::str::USVString;
use crate::dom::globalscope::GlobalScope;
use dom_struct::dom_struct;
use webgpu::WebGPUShaderModule;
@ -14,7 +14,7 @@ use webgpu::WebGPUShaderModule;
#[dom_struct]
pub struct GPUShaderModule {
reflector_: Reflector,
label: DomRefCell<Option<DOMString>>,
label: DomRefCell<Option<USVString>>,
shader_module: WebGPUShaderModule,
}
@ -43,12 +43,12 @@ impl GPUShaderModule {
impl GPUShaderModuleMethods for GPUShaderModule {
/// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label
fn GetLabel(&self) -> Option<DOMString> {
fn GetLabel(&self) -> Option<USVString> {
self.label.borrow().clone()
}
/// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label
fn SetLabel(&self, value: Option<DOMString>) {
fn SetLabel(&self, value: Option<USVString>) {
*self.label.borrow_mut() = value;
}
}

View file

@ -6,7 +6,7 @@ use crate::dom::bindings::cell::DomRefCell;
use crate::dom::bindings::codegen::Bindings::GPUSwapChainBinding::GPUSwapChainMethods;
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::bindings::str::USVString;
use crate::dom::globalscope::GlobalScope;
use crate::dom::gpucanvascontext::GPUCanvasContext;
use crate::dom::gputexture::GPUTexture;
@ -18,7 +18,7 @@ pub struct GPUSwapChain {
reflector_: Reflector,
#[ignore_malloc_size_of = "channels are hard"]
channel: WebGPU,
label: DomRefCell<Option<DOMString>>,
label: DomRefCell<Option<USVString>>,
context: Dom<GPUCanvasContext>,
texture: Dom<GPUTexture>,
}
@ -67,12 +67,12 @@ impl GPUSwapChain {
impl GPUSwapChainMethods for GPUSwapChain {
/// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label
fn GetLabel(&self) -> Option<DOMString> {
fn GetLabel(&self) -> Option<USVString> {
self.label.borrow().clone()
}
/// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label
fn SetLabel(&self, value: Option<DOMString>) {
fn SetLabel(&self, value: Option<USVString>) {
*self.label.borrow_mut() = value;
}

View file

@ -11,19 +11,19 @@ use crate::dom::bindings::codegen::Bindings::GPUTextureViewBinding::{
};
use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector};
use crate::dom::bindings::root::DomRoot;
use crate::dom::bindings::str::DOMString;
use crate::dom::bindings::str::USVString;
use crate::dom::globalscope::GlobalScope;
use crate::dom::gpudevice::{convert_texture_format, convert_texture_view_dimension};
use crate::dom::gputextureview::GPUTextureView;
use dom_struct::dom_struct;
use std::cell::Cell;
use std::string::String;
use webgpu::{wgt, WebGPU, WebGPUDevice, WebGPURequest, WebGPUTexture, WebGPUTextureView};
#[dom_struct]
pub struct GPUTexture {
reflector_: Reflector,
texture: WebGPUTexture,
label: DomRefCell<Option<DOMString>>,
label: DomRefCell<Option<USVString>>,
device: WebGPUDevice,
#[ignore_malloc_size_of = "channels are hard"]
channel: WebGPU,
@ -34,7 +34,6 @@ pub struct GPUTexture {
dimension: GPUTextureDimension,
format: GPUTextureFormat,
texture_usage: u32,
valid: Cell<bool>,
}
impl GPUTexture {
@ -48,7 +47,6 @@ impl GPUTexture {
dimension: GPUTextureDimension,
format: GPUTextureFormat,
texture_usage: u32,
valid: bool,
) -> Self {
Self {
reflector_: Reflector::new(),
@ -62,7 +60,6 @@ impl GPUTexture {
dimension,
format,
texture_usage,
valid: Cell::new(valid),
}
}
@ -77,7 +74,6 @@ impl GPUTexture {
dimension: GPUTextureDimension,
format: GPUTextureFormat,
texture_usage: u32,
valid: bool,
) -> DomRoot<Self> {
reflect_dom_object(
Box::new(GPUTexture::new_inherited(
@ -90,7 +86,6 @@ impl GPUTexture {
dimension,
format,
texture_usage,
valid,
)),
global,
)
@ -107,20 +102,16 @@ impl GPUTexture {
pub fn id(&self) -> WebGPUTexture {
self.texture
}
pub fn is_valid(&self) -> bool {
self.valid.get()
}
}
impl GPUTextureMethods for GPUTexture {
/// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label
fn GetLabel(&self) -> Option<DOMString> {
fn GetLabel(&self) -> Option<USVString> {
self.label.borrow().clone()
}
/// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label
fn SetLabel(&self, value: Option<DOMString>) {
fn SetLabel(&self, value: Option<USVString>) {
*self.label.borrow_mut() = value;
}
@ -145,7 +136,11 @@ impl GPUTextureMethods for GPUTexture {
let format = descriptor.format.unwrap_or(self.format);
let desc = wgt::TextureViewDescriptor {
label: Default::default(),
label: descriptor
.parent
.label
.as_ref()
.map(|s| String::from(s.as_ref())),
format: convert_texture_format(format),
dimension: convert_texture_view_dimension(dimension),
aspect: match descriptor.aspect {
@ -184,7 +179,7 @@ impl GPUTextureMethods for GPUTexture {
let texture_view = WebGPUTextureView(texture_view_id);
GPUTextureView::new(&self.global(), texture_view, &self, self.valid.get())
GPUTextureView::new(&self.global(), texture_view, &self)
}
/// https://gpuweb.github.io/gpuweb/#dom-gputexture-destroy

View file

@ -6,34 +6,27 @@ use crate::dom::bindings::cell::DomRefCell;
use crate::dom::bindings::codegen::Bindings::GPUTextureViewBinding::GPUTextureViewMethods;
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::bindings::str::USVString;
use crate::dom::globalscope::GlobalScope;
use crate::dom::gputexture::GPUTexture;
use dom_struct::dom_struct;
use std::cell::Cell;
use webgpu::WebGPUTextureView;
#[dom_struct]
pub struct GPUTextureView {
reflector_: Reflector,
label: DomRefCell<Option<DOMString>>,
label: DomRefCell<Option<USVString>>,
texture_view: WebGPUTextureView,
texture: Dom<GPUTexture>,
valid: Cell<bool>,
}
impl GPUTextureView {
fn new_inherited(
texture_view: WebGPUTextureView,
texture: &GPUTexture,
valid: bool,
) -> GPUTextureView {
fn new_inherited(texture_view: WebGPUTextureView, texture: &GPUTexture) -> GPUTextureView {
Self {
reflector_: Reflector::new(),
texture: Dom::from_ref(texture),
label: DomRefCell::new(None),
texture_view,
valid: Cell::new(valid),
}
}
@ -41,10 +34,9 @@ impl GPUTextureView {
global: &GlobalScope,
texture_view: WebGPUTextureView,
texture: &GPUTexture,
valid: bool,
) -> DomRoot<GPUTextureView> {
reflect_dom_object(
Box::new(GPUTextureView::new_inherited(texture_view, texture, valid)),
Box::new(GPUTextureView::new_inherited(texture_view, texture)),
global,
)
}
@ -54,20 +46,16 @@ impl GPUTextureView {
pub fn id(&self) -> WebGPUTextureView {
self.texture_view
}
pub fn is_valid(&self) -> bool {
self.valid.get()
}
}
impl GPUTextureViewMethods for GPUTextureView {
/// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label
fn GetLabel(&self) -> Option<DOMString> {
fn GetLabel(&self) -> Option<USVString> {
self.label.borrow().clone()
}
/// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label
fn SetLabel(&self, value: Option<DOMString>) {
fn SetLabel(&self, value: Option<USVString>) {
*self.label.borrow_mut() = value;
}
}

View file

@ -5,9 +5,9 @@
// https://gpuweb.github.io/gpuweb/#gpuobjectbase
[Exposed=(Window)]
interface mixin GPUObjectBase {
attribute DOMString? label;
attribute USVString? label;
};
dictionary GPUObjectDescriptorBase {
DOMString? label;
USVString label;
};