Skip to content

Commit

Permalink
Auto merge of #27329 - kunalmohan:gpu-label, r=kvark
Browse files Browse the repository at this point in the history
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. -->
  • Loading branch information
bors-servo committed Jul 21, 2020
2 parents 1ded1ba + cdc0a75 commit 5984137
Show file tree
Hide file tree
Showing 20 changed files with 229 additions and 251 deletions.
25 changes: 23 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 5 additions & 12 deletions components/script/dom/gpubindgroup.rs
Expand Up @@ -6,36 +6,32 @@ 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 {
reflector_: Reflector::new(),
label: DomRefCell::new(None),
bind_group,
device,
valid: Cell::new(valid),
layout: Dom::from_ref(layout),
}
}
Expand All @@ -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,
)
}
Expand All @@ -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;
}
}
25 changes: 7 additions & 18 deletions components/script/dom/gpubindgrouplayout.rs
Expand Up @@ -6,60 +6,49 @@ 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
}
}

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;
}
}
18 changes: 5 additions & 13 deletions components/script/dom/gpubuffer.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -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>>>,
Expand All @@ -76,15 +75,13 @@ impl GPUBuffer {
device: WebGPUDevice,
state: GPUBufferState,
size: GPUSize64,
valid: bool,
map_info: DomRefCell<Option<GPUBufferMapInfo>>,
) -> Self {
Self {
reflector_: Reflector::new(),
channel,
label: DomRefCell::new(None),
state: Cell::new(state),
valid: Cell::new(valid),
device,
buffer,
map_promise: DomRefCell::new(None),
Expand All @@ -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,
)
Expand All @@ -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 {
Expand Down Expand Up @@ -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;
}
}
Expand Down
8 changes: 4 additions & 4 deletions components/script/dom/gpucommandbuffer.rs
Expand Up @@ -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;
Expand All @@ -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>>>,
}
Expand Down Expand Up @@ -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;
}
}
12 changes: 5 additions & 7 deletions components/script/dom/gpucommandencoder.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -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>,
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions components/script/dom/gpucomputepassencoder.rs
Expand Up @@ -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;
Expand All @@ -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>,
Expand All @@ -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;
}

Expand Down

0 comments on commit 5984137

Please sign in to comment.