Update GPUObjectBase webidl and cleanup valid flags

This commit is contained in:
Kunal Mohan 2020-07-20 20:10:41 +05:30
parent 3216209506
commit cdc0a75fe4
20 changed files with 229 additions and 251 deletions

25
Cargo.lock generated
View file

@ -5901,6 +5901,26 @@ version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8eaa81235c7058867fa8c0e7314f33dcce9c215f535d1913822a2b3f5e289f3c" checksum = "8eaa81235c7058867fa8c0e7314f33dcce9c215f535d1913822a2b3f5e289f3c"
[[package]]
name = "thiserror"
version = "1.0.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7dfdd070ccd8ccb78f4ad66bf1982dc37f620ef696c6b5028fe2ed83dd3d0d08"
dependencies = [
"thiserror-impl",
]
[[package]]
name = "thiserror-impl"
version = "1.0.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bd80fc12f73063ac132ac92aceea36734f04a1d93c1240c6944e23a3b8841793"
dependencies = [
"proc-macro2 1.0.17",
"quote 1.0.2",
"syn",
]
[[package]] [[package]]
name = "thread_local" name = "thread_local"
version = "1.0.1" version = "1.0.1"
@ -6815,7 +6835,7 @@ dependencies = [
[[package]] [[package]]
name = "wgpu-core" name = "wgpu-core"
version = "0.5.0" version = "0.5.0"
source = "git+https://github.com/gfx-rs/wgpu#71e853d6ce289cb529ce39c03263e7f101dd4db5" source = "git+https://github.com/gfx-rs/wgpu#73b230871ea4428ed3fb1e6e8bff81a7364fcdb2"
dependencies = [ dependencies = [
"arrayvec 0.5.1", "arrayvec 0.5.1",
"bitflags", "bitflags",
@ -6836,6 +6856,7 @@ dependencies = [
"serde", "serde",
"smallvec 1.4.1", "smallvec 1.4.1",
"spirv_headers", "spirv_headers",
"thiserror",
"tracing", "tracing",
"wgpu-types", "wgpu-types",
] ]
@ -6843,7 +6864,7 @@ dependencies = [
[[package]] [[package]]
name = "wgpu-types" name = "wgpu-types"
version = "0.5.0" version = "0.5.0"
source = "git+https://github.com/gfx-rs/wgpu#71e853d6ce289cb529ce39c03263e7f101dd4db5" source = "git+https://github.com/gfx-rs/wgpu#73b230871ea4428ed3fb1e6e8bff81a7364fcdb2"
dependencies = [ dependencies = [
"bitflags", "bitflags",
"serde", "serde",

View file

@ -6,28 +6,25 @@ use crate::dom::bindings::cell::DomRefCell;
use crate::dom::bindings::codegen::Bindings::GPUBindGroupBinding::GPUBindGroupMethods; use crate::dom::bindings::codegen::Bindings::GPUBindGroupBinding::GPUBindGroupMethods;
use crate::dom::bindings::reflector::{reflect_dom_object, Reflector}; use crate::dom::bindings::reflector::{reflect_dom_object, Reflector};
use crate::dom::bindings::root::{Dom, DomRoot}; 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::globalscope::GlobalScope;
use crate::dom::gpubindgrouplayout::GPUBindGroupLayout; use crate::dom::gpubindgrouplayout::GPUBindGroupLayout;
use dom_struct::dom_struct; use dom_struct::dom_struct;
use std::cell::Cell;
use webgpu::{WebGPUBindGroup, WebGPUDevice}; use webgpu::{WebGPUBindGroup, WebGPUDevice};
#[dom_struct] #[dom_struct]
pub struct GPUBindGroup { pub struct GPUBindGroup {
reflector_: Reflector, reflector_: Reflector,
label: DomRefCell<Option<DOMString>>, label: DomRefCell<Option<USVString>>,
bind_group: WebGPUBindGroup, bind_group: WebGPUBindGroup,
device: WebGPUDevice, device: WebGPUDevice,
layout: Dom<GPUBindGroupLayout>, layout: Dom<GPUBindGroupLayout>,
valid: Cell<bool>,
} }
impl GPUBindGroup { impl GPUBindGroup {
fn new_inherited( fn new_inherited(
bind_group: WebGPUBindGroup, bind_group: WebGPUBindGroup,
device: WebGPUDevice, device: WebGPUDevice,
valid: bool,
layout: &GPUBindGroupLayout, layout: &GPUBindGroupLayout,
) -> Self { ) -> Self {
Self { Self {
@ -35,7 +32,6 @@ impl GPUBindGroup {
label: DomRefCell::new(None), label: DomRefCell::new(None),
bind_group, bind_group,
device, device,
valid: Cell::new(valid),
layout: Dom::from_ref(layout), layout: Dom::from_ref(layout),
} }
} }
@ -44,13 +40,10 @@ impl GPUBindGroup {
global: &GlobalScope, global: &GlobalScope,
bind_group: WebGPUBindGroup, bind_group: WebGPUBindGroup,
device: WebGPUDevice, device: WebGPUDevice,
valid: bool,
layout: &GPUBindGroupLayout, layout: &GPUBindGroupLayout,
) -> DomRoot<Self> { ) -> DomRoot<Self> {
reflect_dom_object( reflect_dom_object(
Box::new(GPUBindGroup::new_inherited( Box::new(GPUBindGroup::new_inherited(bind_group, device, layout)),
bind_group, device, valid, layout,
)),
global, global,
) )
} }
@ -64,12 +57,12 @@ impl GPUBindGroup {
impl GPUBindGroupMethods for GPUBindGroup { impl GPUBindGroupMethods for GPUBindGroup {
/// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label /// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label
fn GetLabel(&self) -> Option<DOMString> { fn GetLabel(&self) -> Option<USVString> {
self.label.borrow().clone() self.label.borrow().clone()
} }
/// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label /// 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; *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::codegen::Bindings::GPUBindGroupLayoutBinding::GPUBindGroupLayoutMethods;
use crate::dom::bindings::reflector::{reflect_dom_object, Reflector}; use crate::dom::bindings::reflector::{reflect_dom_object, Reflector};
use crate::dom::bindings::root::DomRoot; 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::globalscope::GlobalScope;
use dom_struct::dom_struct; use dom_struct::dom_struct;
use std::cell::Cell;
use webgpu::WebGPUBindGroupLayout; use webgpu::WebGPUBindGroupLayout;
#[dom_struct] #[dom_struct]
pub struct GPUBindGroupLayout { pub struct GPUBindGroupLayout {
reflector_: Reflector, reflector_: Reflector,
label: DomRefCell<Option<DOMString>>, label: DomRefCell<Option<USVString>>,
bind_group_layout: WebGPUBindGroupLayout, bind_group_layout: WebGPUBindGroupLayout,
valid: Cell<bool>,
} }
impl GPUBindGroupLayout { impl GPUBindGroupLayout {
fn new_inherited(bind_group_layout: WebGPUBindGroupLayout, valid: bool) -> Self { fn new_inherited(bind_group_layout: WebGPUBindGroupLayout) -> Self {
Self { Self {
reflector_: Reflector::new(), reflector_: Reflector::new(),
label: DomRefCell::new(None), label: DomRefCell::new(None),
bind_group_layout, bind_group_layout,
valid: Cell::new(valid),
} }
} }
pub fn new( pub fn new(global: &GlobalScope, bind_group_layout: WebGPUBindGroupLayout) -> DomRoot<Self> {
global: &GlobalScope,
bind_group_layout: WebGPUBindGroupLayout,
valid: bool,
) -> DomRoot<Self> {
reflect_dom_object( reflect_dom_object(
Box::new(GPUBindGroupLayout::new_inherited(bind_group_layout, valid)), Box::new(GPUBindGroupLayout::new_inherited(bind_group_layout)),
global, global,
) )
} }
} }
impl GPUBindGroupLayout { impl GPUBindGroupLayout {
pub fn is_valid(&self) -> bool {
self.valid.get()
}
pub fn id(&self) -> WebGPUBindGroupLayout { pub fn id(&self) -> WebGPUBindGroupLayout {
self.bind_group_layout self.bind_group_layout
} }
@ -54,12 +43,12 @@ impl GPUBindGroupLayout {
impl GPUBindGroupLayoutMethods for GPUBindGroupLayout { impl GPUBindGroupLayoutMethods for GPUBindGroupLayout {
/// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label /// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label
fn GetLabel(&self) -> Option<DOMString> { fn GetLabel(&self) -> Option<USVString> {
self.label.borrow().clone() self.label.borrow().clone()
} }
/// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label /// 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; *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::DomObject;
use crate::dom::bindings::reflector::{reflect_dom_object, Reflector}; use crate::dom::bindings::reflector::{reflect_dom_object, Reflector};
use crate::dom::bindings::root::DomRoot; 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::globalscope::GlobalScope;
use crate::dom::gpu::{response_async, AsyncWGPUListener}; use crate::dom::gpu::{response_async, AsyncWGPUListener};
use crate::dom::promise::Promise; use crate::dom::promise::Promise;
@ -58,11 +58,10 @@ pub struct GPUBuffer {
reflector_: Reflector, reflector_: Reflector,
#[ignore_malloc_size_of = "defined in webgpu"] #[ignore_malloc_size_of = "defined in webgpu"]
channel: WebGPU, channel: WebGPU,
label: DomRefCell<Option<DOMString>>, label: DomRefCell<Option<USVString>>,
state: Cell<GPUBufferState>, state: Cell<GPUBufferState>,
buffer: WebGPUBuffer, buffer: WebGPUBuffer,
device: WebGPUDevice, device: WebGPUDevice,
valid: Cell<bool>,
size: GPUSize64, size: GPUSize64,
#[ignore_malloc_size_of = "promises are hard"] #[ignore_malloc_size_of = "promises are hard"]
map_promise: DomRefCell<Option<Rc<Promise>>>, map_promise: DomRefCell<Option<Rc<Promise>>>,
@ -76,7 +75,6 @@ impl GPUBuffer {
device: WebGPUDevice, device: WebGPUDevice,
state: GPUBufferState, state: GPUBufferState,
size: GPUSize64, size: GPUSize64,
valid: bool,
map_info: DomRefCell<Option<GPUBufferMapInfo>>, map_info: DomRefCell<Option<GPUBufferMapInfo>>,
) -> Self { ) -> Self {
Self { Self {
@ -84,7 +82,6 @@ impl GPUBuffer {
channel, channel,
label: DomRefCell::new(None), label: DomRefCell::new(None),
state: Cell::new(state), state: Cell::new(state),
valid: Cell::new(valid),
device, device,
buffer, buffer,
map_promise: DomRefCell::new(None), map_promise: DomRefCell::new(None),
@ -101,12 +98,11 @@ impl GPUBuffer {
device: WebGPUDevice, device: WebGPUDevice,
state: GPUBufferState, state: GPUBufferState,
size: GPUSize64, size: GPUSize64,
valid: bool,
map_info: DomRefCell<Option<GPUBufferMapInfo>>, map_info: DomRefCell<Option<GPUBufferMapInfo>>,
) -> DomRoot<Self> { ) -> DomRoot<Self> {
reflect_dom_object( reflect_dom_object(
Box::new(GPUBuffer::new_inherited( Box::new(GPUBuffer::new_inherited(
channel, buffer, device, state, size, valid, map_info, channel, buffer, device, state, size, map_info,
)), )),
global, global,
) )
@ -121,10 +117,6 @@ impl GPUBuffer {
pub fn state(&self) -> GPUBufferState { pub fn state(&self) -> GPUBufferState {
self.state.get() self.state.get()
} }
pub fn is_valid(&self) -> bool {
self.valid.get()
}
} }
impl Drop for GPUBuffer { impl Drop for GPUBuffer {
@ -305,12 +297,12 @@ impl GPUBufferMethods for GPUBuffer {
} }
/// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label /// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label
fn GetLabel(&self) -> Option<DOMString> { fn GetLabel(&self) -> Option<USVString> {
self.label.borrow().clone() self.label.borrow().clone()
} }
/// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label /// 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; *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::reflector::{reflect_dom_object, Reflector};
use crate::dom::bindings::root::Dom; use crate::dom::bindings::root::Dom;
use crate::dom::bindings::root::DomRoot; 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::globalscope::GlobalScope;
use crate::dom::gpubuffer::GPUBuffer; use crate::dom::gpubuffer::GPUBuffer;
use dom_struct::dom_struct; use dom_struct::dom_struct;
@ -27,7 +27,7 @@ pub struct GPUCommandBuffer {
reflector_: Reflector, reflector_: Reflector,
#[ignore_malloc_size_of = "defined in webgpu"] #[ignore_malloc_size_of = "defined in webgpu"]
channel: WebGPU, channel: WebGPU,
label: DomRefCell<Option<DOMString>>, label: DomRefCell<Option<USVString>>,
command_buffer: WebGPUCommandBuffer, command_buffer: WebGPUCommandBuffer,
buffers: DomRefCell<HashSet<Dom<GPUBuffer>>>, buffers: DomRefCell<HashSet<Dom<GPUBuffer>>>,
} }
@ -76,12 +76,12 @@ impl GPUCommandBuffer {
impl GPUCommandBufferMethods for GPUCommandBuffer { impl GPUCommandBufferMethods for GPUCommandBuffer {
/// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label /// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label
fn GetLabel(&self) -> Option<DOMString> { fn GetLabel(&self) -> Option<USVString> {
self.label.borrow().clone() self.label.borrow().clone()
} }
/// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label /// 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; *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::DomObject;
use crate::dom::bindings::reflector::{reflect_dom_object, Reflector}; use crate::dom::bindings::reflector::{reflect_dom_object, Reflector};
use crate::dom::bindings::root::DomRoot; 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::globalscope::GlobalScope;
use crate::dom::gpubuffer::GPUBuffer; use crate::dom::gpubuffer::GPUBuffer;
use crate::dom::gpucommandbuffer::GPUCommandBuffer; use crate::dom::gpucommandbuffer::GPUCommandBuffer;
@ -43,7 +43,7 @@ pub struct GPUCommandEncoder {
reflector_: Reflector, reflector_: Reflector,
#[ignore_malloc_size_of = "defined in webgpu"] #[ignore_malloc_size_of = "defined in webgpu"]
channel: WebGPU, channel: WebGPU,
label: DomRefCell<Option<DOMString>>, label: DomRefCell<Option<USVString>>,
encoder: webgpu::WebGPUCommandEncoder, encoder: webgpu::WebGPUCommandEncoder,
buffers: DomRefCell<HashSet<DomRoot<GPUBuffer>>>, buffers: DomRefCell<HashSet<DomRoot<GPUBuffer>>>,
state: DomRefCell<GPUCommandEncoderState>, state: DomRefCell<GPUCommandEncoderState>,
@ -103,12 +103,12 @@ impl GPUCommandEncoder {
impl GPUCommandEncoderMethods for GPUCommandEncoder { impl GPUCommandEncoderMethods for GPUCommandEncoder {
/// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label /// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label
fn GetLabel(&self) -> Option<DOMString> { fn GetLabel(&self) -> Option<USVString> {
self.label.borrow().clone() self.label.borrow().clone()
} }
/// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label /// 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; *self.label.borrow_mut() = value;
} }
@ -229,9 +229,7 @@ impl GPUCommandEncoderMethods for GPUCommandEncoder {
destination_offset: GPUSize64, destination_offset: GPUSize64,
size: GPUSize64, size: GPUSize64,
) { ) {
let valid = source.is_valid() && let valid = *self.state.borrow() == GPUCommandEncoderState::Open;
destination.is_valid() &&
*self.state.borrow() == GPUCommandEncoderState::Open;
if !valid { if !valid {
// TODO: Record an error in the current scope. // 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::codegen::Bindings::GPUComputePassEncoderBinding::GPUComputePassEncoderMethods;
use crate::dom::bindings::reflector::{reflect_dom_object, Reflector}; use crate::dom::bindings::reflector::{reflect_dom_object, Reflector};
use crate::dom::bindings::root::{Dom, DomRoot}; 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::globalscope::GlobalScope;
use crate::dom::gpubindgroup::GPUBindGroup; use crate::dom::gpubindgroup::GPUBindGroup;
use crate::dom::gpubuffer::GPUBuffer; use crate::dom::gpubuffer::GPUBuffer;
@ -23,7 +23,7 @@ pub struct GPUComputePassEncoder {
reflector_: Reflector, reflector_: Reflector,
#[ignore_malloc_size_of = "defined in webgpu"] #[ignore_malloc_size_of = "defined in webgpu"]
channel: WebGPU, channel: WebGPU,
label: DomRefCell<Option<DOMString>>, label: DomRefCell<Option<USVString>>,
#[ignore_malloc_size_of = "defined in wgpu-core"] #[ignore_malloc_size_of = "defined in wgpu-core"]
compute_pass: DomRefCell<Option<ComputePass>>, compute_pass: DomRefCell<Option<ComputePass>>,
command_encoder: Dom<GPUCommandEncoder>, command_encoder: Dom<GPUCommandEncoder>,
@ -50,12 +50,12 @@ impl GPUComputePassEncoder {
impl GPUComputePassEncoderMethods for GPUComputePassEncoder { impl GPUComputePassEncoderMethods for GPUComputePassEncoder {
/// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label /// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label
fn GetLabel(&self) -> Option<DOMString> { fn GetLabel(&self) -> Option<USVString> {
self.label.borrow().clone() self.label.borrow().clone()
} }
/// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label /// 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; *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::reflect_dom_object;
use crate::dom::bindings::reflector::Reflector; use crate::dom::bindings::reflector::Reflector;
use crate::dom::bindings::root::DomRoot; 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::globalscope::GlobalScope;
use dom_struct::dom_struct; use dom_struct::dom_struct;
use std::cell::Cell;
use webgpu::WebGPUComputePipeline; use webgpu::WebGPUComputePipeline;
#[dom_struct] #[dom_struct]
pub struct GPUComputePipeline { pub struct GPUComputePipeline {
reflector_: Reflector, reflector_: Reflector,
label: DomRefCell<Option<DOMString>>, label: DomRefCell<Option<USVString>>,
compute_pipeline: WebGPUComputePipeline, compute_pipeline: WebGPUComputePipeline,
valid: Cell<bool>,
} }
impl GPUComputePipeline { impl GPUComputePipeline {
fn new_inherited(compute_pipeline: WebGPUComputePipeline, valid: bool) -> Self { fn new_inherited(compute_pipeline: WebGPUComputePipeline) -> Self {
Self { Self {
reflector_: Reflector::new(), reflector_: Reflector::new(),
label: DomRefCell::new(None), label: DomRefCell::new(None),
compute_pipeline, compute_pipeline,
valid: Cell::new(valid),
} }
} }
pub fn new( pub fn new(global: &GlobalScope, compute_pipeline: WebGPUComputePipeline) -> DomRoot<Self> {
global: &GlobalScope,
compute_pipeline: WebGPUComputePipeline,
valid: bool,
) -> DomRoot<Self> {
reflect_dom_object( reflect_dom_object(
Box::new(GPUComputePipeline::new_inherited(compute_pipeline, valid)), Box::new(GPUComputePipeline::new_inherited(compute_pipeline)),
global, global,
) )
} }
@ -51,12 +44,12 @@ impl GPUComputePipeline {
impl GPUComputePipelineMethods for GPUComputePipeline { impl GPUComputePipelineMethods for GPUComputePipeline {
/// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label /// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label
fn GetLabel(&self) -> Option<DOMString> { fn GetLabel(&self) -> Option<USVString> {
self.label.borrow().clone() self.label.borrow().clone()
} }
/// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label /// 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; *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::{ use crate::dom::bindings::codegen::Bindings::GPUValidationErrorBinding::{
GPUError, GPUErrorFilter, 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::error::Error;
use crate::dom::bindings::reflector::{reflect_dom_object, DomObject}; use crate::dom::bindings::reflector::{reflect_dom_object, DomObject};
use crate::dom::bindings::root::{Dom, DomRoot}; 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::bindings::trace::RootedTraceableBox;
use crate::dom::eventtarget::EventTarget; use crate::dom::eventtarget::EventTarget;
use crate::dom::globalscope::GlobalScope; use crate::dom::globalscope::GlobalScope;
@ -64,6 +64,7 @@ use std::cell::RefCell;
use std::collections::HashMap; use std::collections::HashMap;
use std::ptr::NonNull; use std::ptr::NonNull;
use std::rc::Rc; use std::rc::Rc;
use std::string::String;
use webgpu::wgpu::binding_model::BufferBinding; use webgpu::wgpu::binding_model::BufferBinding;
use webgpu::{self, wgt, WebGPU, WebGPUBindings, WebGPURequest}; use webgpu::{self, wgt, WebGPU, WebGPUBindings, WebGPURequest};
@ -96,7 +97,7 @@ pub struct GPUDevice {
extensions: Heap<*mut JSObject>, extensions: Heap<*mut JSObject>,
#[ignore_malloc_size_of = "mozjs"] #[ignore_malloc_size_of = "mozjs"]
limits: Heap<*mut JSObject>, limits: Heap<*mut JSObject>,
label: DomRefCell<Option<DOMString>>, label: DomRefCell<Option<USVString>>,
device: webgpu::WebGPUDevice, device: webgpu::WebGPUDevice,
default_queue: Dom<GPUQueue>, default_queue: Dom<GPUQueue>,
scope_context: DomRefCell<ScopeContext>, scope_context: DomRefCell<ScopeContext>,
@ -227,12 +228,12 @@ impl GPUDeviceMethods for GPUDevice {
} }
/// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label /// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label
fn GetLabel(&self) -> Option<DOMString> { fn GetLabel(&self) -> Option<USVString> {
self.label.borrow().clone() self.label.borrow().clone()
} }
/// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label /// 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; *self.label.borrow_mut() = value;
} }
@ -246,7 +247,11 @@ impl GPUDeviceMethods for GPUDevice {
/// https://gpuweb.github.io/gpuweb/#dom-gpudevice-createbuffer /// https://gpuweb.github.io/gpuweb/#dom-gpudevice-createbuffer
fn CreateBuffer(&self, descriptor: &GPUBufferDescriptor) -> DomRoot<GPUBuffer> { fn CreateBuffer(&self, descriptor: &GPUBufferDescriptor) -> DomRoot<GPUBuffer> {
let wgpu_descriptor = wgt::BufferDescriptor { let wgpu_descriptor = wgt::BufferDescriptor {
label: Default::default(), label: descriptor
.parent
.label
.as_ref()
.map(|s| String::from(s.as_ref())),
size: descriptor.size, size: descriptor.size,
usage: match wgt::BufferUsage::from_bits(descriptor.usage) { usage: match wgt::BufferUsage::from_bits(descriptor.usage) {
Some(u) => u, Some(u) => u,
@ -293,7 +298,6 @@ impl GPUDeviceMethods for GPUDevice {
self.device, self.device,
state, state,
descriptor.size, descriptor.size,
true,
map_info, map_info,
) )
} }
@ -409,12 +413,17 @@ impl GPUDeviceMethods for GPUDevice {
bind_group_layout_id, bind_group_layout_id,
entries: entries.clone(), entries: entries.clone(),
scope_id, scope_id,
label: descriptor
.parent
.label
.as_ref()
.map(|s| String::from(s.as_ref())),
}) })
.expect("Failed to create WebGPU BindGroupLayout"); .expect("Failed to create WebGPU BindGroupLayout");
let bgl = webgpu::WebGPUBindGroupLayout(bind_group_layout_id); 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 self.bind_group_layouts
.borrow_mut() .borrow_mut()
@ -429,11 +438,10 @@ impl GPUDeviceMethods for GPUDevice {
descriptor: &GPUPipelineLayoutDescriptor, descriptor: &GPUPipelineLayoutDescriptor,
) -> DomRoot<GPUPipelineLayout> { ) -> DomRoot<GPUPipelineLayout> {
let mut bgl_ids = Vec::new(); let mut bgl_ids = Vec::new();
descriptor.bindGroupLayouts.iter().for_each(|each| { descriptor
if each.is_valid() { .bindGroupLayouts
bgl_ids.push(each.id().0); .iter()
} .for_each(|each| bgl_ids.push(each.id().0));
});
let scope_id = self.use_current_scope(); let scope_id = self.use_current_scope();
@ -453,12 +461,11 @@ impl GPUDeviceMethods for GPUDevice {
.expect("Failed to create WebGPU PipelineLayout"); .expect("Failed to create WebGPU PipelineLayout");
let pipeline_layout = webgpu::WebGPUPipelineLayout(pipeline_layout_id); 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 /// https://gpuweb.github.io/gpuweb/#dom-gpudevice-createbindgroup
fn CreateBindGroup(&self, descriptor: &GPUBindGroupDescriptor) -> DomRoot<GPUBindGroup> { fn CreateBindGroup(&self, descriptor: &GPUBindGroupDescriptor) -> DomRoot<GPUBindGroup> {
let mut valid = descriptor.layout.is_valid();
let entries = descriptor let entries = descriptor
.entries .entries
.iter() .iter()
@ -466,16 +473,11 @@ impl GPUDeviceMethods for GPUDevice {
( (
bind.binding, bind.binding,
match bind.resource { match bind.resource {
GPUBindingResource::GPUSampler(ref s) => { GPUBindingResource::GPUSampler(ref s) => WebGPUBindings::Sampler(s.id().0),
valid &= s.is_valid();
WebGPUBindings::Sampler(s.id().0)
},
GPUBindingResource::GPUTextureView(ref t) => { GPUBindingResource::GPUTextureView(ref t) => {
valid &= t.is_valid();
WebGPUBindings::TextureView(t.id().0) WebGPUBindings::TextureView(t.id().0)
}, },
GPUBindingResource::GPUBufferBindings(ref b) => { GPUBindingResource::GPUBufferBindings(ref b) => {
valid &= b.buffer.is_valid();
WebGPUBindings::Buffer(BufferBinding { WebGPUBindings::Buffer(BufferBinding {
buffer_id: b.buffer.id().0, buffer_id: b.buffer.id().0,
offset: b.offset, offset: b.offset,
@ -502,18 +504,17 @@ impl GPUDeviceMethods for GPUDevice {
bind_group_layout_id: descriptor.layout.id().0, bind_group_layout_id: descriptor.layout.id().0,
entries, entries,
scope_id, scope_id,
label: descriptor
.parent
.label
.as_ref()
.map(|s| String::from(s.as_ref())),
}) })
.expect("Failed to create WebGPU BindGroup"); .expect("Failed to create WebGPU BindGroup");
let bind_group = webgpu::WebGPUBindGroup(bind_group_id); let bind_group = webgpu::WebGPUBindGroup(bind_group_id);
GPUBindGroup::new( GPUBindGroup::new(&self.global(), bind_group, self.device, &*descriptor.layout)
&self.global(),
bind_group,
self.device,
valid,
&*descriptor.layout,
)
} }
/// https://gpuweb.github.io/gpuweb/#dom-gpudevice-createshadermodule /// https://gpuweb.github.io/gpuweb/#dom-gpudevice-createshadermodule
@ -522,8 +523,10 @@ impl GPUDeviceMethods for GPUDevice {
descriptor: RootedTraceableBox<GPUShaderModuleDescriptor>, descriptor: RootedTraceableBox<GPUShaderModuleDescriptor>,
) -> DomRoot<GPUShaderModule> { ) -> DomRoot<GPUShaderModule> {
let program: Vec<u32> = match &descriptor.code { let program: Vec<u32> = match &descriptor.code {
Uint32Array(program) => program.to_vec(), Uint32ArrayOrString::Uint32Array(program) => program.to_vec(),
String(program) => program.chars().map(|c| c as u32).collect::<Vec<u32>>(), Uint32ArrayOrString::String(program) => {
program.chars().map(|c| c as u32).collect::<Vec<u32>>()
},
}; };
let program_id = self let program_id = self
.global() .global()
@ -548,7 +551,6 @@ impl GPUDeviceMethods for GPUDevice {
&self, &self,
descriptor: &GPUComputePipelineDescriptor, descriptor: &GPUComputePipelineDescriptor,
) -> DomRoot<GPUComputePipeline> { ) -> DomRoot<GPUComputePipeline> {
let valid = descriptor.parent.layout.is_valid();
let pipeline = descriptor.parent.layout.id(); let pipeline = descriptor.parent.layout.id();
let program = descriptor.computeStage.module.id(); let program = descriptor.computeStage.module.id();
let entry_point = descriptor.computeStage.entryPoint.to_string(); let entry_point = descriptor.computeStage.entryPoint.to_string();
@ -573,13 +575,13 @@ impl GPUDeviceMethods for GPUDevice {
.expect("Failed to create WebGPU ComputePipeline"); .expect("Failed to create WebGPU ComputePipeline");
let compute_pipeline = webgpu::WebGPUComputePipeline(compute_pipeline_id); 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 /// https://gpuweb.github.io/gpuweb/#dom-gpudevice-createcommandencoder
fn CreateCommandEncoder( fn CreateCommandEncoder(
&self, &self,
_descriptor: &GPUCommandEncoderDescriptor, descriptor: &GPUCommandEncoderDescriptor,
) -> DomRoot<GPUCommandEncoder> { ) -> DomRoot<GPUCommandEncoder> {
let command_encoder_id = self let command_encoder_id = self
.global() .global()
@ -591,6 +593,11 @@ impl GPUDeviceMethods for GPUDevice {
.send(WebGPURequest::CreateCommandEncoder { .send(WebGPURequest::CreateCommandEncoder {
device_id: self.device.0, device_id: self.device.0,
command_encoder_id, command_encoder_id,
label: descriptor
.parent
.label
.as_ref()
.map(|s| String::from(s.as_ref())),
}) })
.expect("Failed to create WebGPU command encoder"); .expect("Failed to create WebGPU command encoder");
@ -607,10 +614,13 @@ impl GPUDeviceMethods for GPUDevice {
/// https://gpuweb.github.io/gpuweb/#dom-gpudevice-createtexture /// https://gpuweb.github.io/gpuweb/#dom-gpudevice-createtexture
fn CreateTexture(&self, descriptor: &GPUTextureDescriptor) -> DomRoot<GPUTexture> { fn CreateTexture(&self, descriptor: &GPUTextureDescriptor) -> DomRoot<GPUTexture> {
let mut valid = true;
let size = convert_texture_size_to_dict(&descriptor.size); let size = convert_texture_size_to_dict(&descriptor.size);
let desc = wgt::TextureDescriptor { 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), size: convert_texture_size_to_wgt(&size),
mip_level_count: descriptor.mipLevelCount, mip_level_count: descriptor.mipLevelCount,
sample_count: descriptor.sampleCount, sample_count: descriptor.sampleCount,
@ -622,10 +632,7 @@ impl GPUDeviceMethods for GPUDevice {
format: convert_texture_format(descriptor.format), format: convert_texture_format(descriptor.format),
usage: match wgt::TextureUsage::from_bits(descriptor.usage) { usage: match wgt::TextureUsage::from_bits(descriptor.usage) {
Some(t) => t, Some(t) => t,
None => { None => wgt::TextureUsage::empty(),
valid = false;
wgt::TextureUsage::empty()
},
}, },
}; };
@ -657,7 +664,6 @@ impl GPUDeviceMethods for GPUDevice {
descriptor.dimension, descriptor.dimension,
descriptor.format, descriptor.format,
descriptor.usage, descriptor.usage,
valid,
) )
} }
@ -670,7 +676,11 @@ impl GPUDeviceMethods for GPUDevice {
.create_sampler_id(self.device.0.backend()); .create_sampler_id(self.device.0.backend());
let compare_enable = descriptor.compare.is_some(); let compare_enable = descriptor.compare.is_some();
let desc = wgt::SamplerDescriptor { 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_u: convert_address_mode(descriptor.addressModeU),
address_mode_v: convert_address_mode(descriptor.addressModeV), address_mode_v: convert_address_mode(descriptor.addressModeV),
address_mode_w: convert_address_mode(descriptor.addressModeW), address_mode_w: convert_address_mode(descriptor.addressModeW),
@ -694,7 +704,7 @@ impl GPUDeviceMethods for GPUDevice {
let sampler = webgpu::WebGPUSampler(sampler_id); 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 /// https://gpuweb.github.io/gpuweb/#dom-gpudevice-createrenderpipeline
@ -702,7 +712,6 @@ impl GPUDeviceMethods for GPUDevice {
&self, &self,
descriptor: &GPURenderPipelineDescriptor, descriptor: &GPURenderPipelineDescriptor,
) -> DomRoot<GPURenderPipeline> { ) -> DomRoot<GPURenderPipeline> {
let valid = descriptor.parent.layout.is_valid();
let vertex_module = descriptor.vertexStage.module.id().0; let vertex_module = descriptor.vertexStage.module.id().0;
let vertex_entry_point = descriptor.vertexStage.entryPoint.to_string(); let vertex_entry_point = descriptor.vertexStage.entryPoint.to_string();
let (fragment_module, fragment_entry_point) = match descriptor.fragmentStage { 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); 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 /// 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::codegen::Bindings::GPUPipelineLayoutBinding::GPUPipelineLayoutMethods;
use crate::dom::bindings::reflector::{reflect_dom_object, Reflector}; use crate::dom::bindings::reflector::{reflect_dom_object, Reflector};
use crate::dom::bindings::root::DomRoot; 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::globalscope::GlobalScope;
use dom_struct::dom_struct; use dom_struct::dom_struct;
use std::cell::Cell;
use webgpu::WebGPUPipelineLayout; use webgpu::WebGPUPipelineLayout;
#[dom_struct] #[dom_struct]
pub struct GPUPipelineLayout { pub struct GPUPipelineLayout {
reflector_: Reflector, reflector_: Reflector,
label: DomRefCell<Option<DOMString>>, label: DomRefCell<Option<USVString>>,
pipeline_layout: WebGPUPipelineLayout, pipeline_layout: WebGPUPipelineLayout,
valid: Cell<bool>,
} }
impl GPUPipelineLayout { impl GPUPipelineLayout {
fn new_inherited(pipeline_layout: WebGPUPipelineLayout, valid: bool) -> Self { fn new_inherited(pipeline_layout: WebGPUPipelineLayout) -> Self {
Self { Self {
reflector_: Reflector::new(), reflector_: Reflector::new(),
label: DomRefCell::new(None), label: DomRefCell::new(None),
pipeline_layout, pipeline_layout,
valid: Cell::new(valid),
} }
} }
pub fn new( pub fn new(global: &GlobalScope, pipeline_layout: WebGPUPipelineLayout) -> DomRoot<Self> {
global: &GlobalScope,
pipeline_layout: WebGPUPipelineLayout,
valid: bool,
) -> DomRoot<Self> {
reflect_dom_object( reflect_dom_object(
Box::new(GPUPipelineLayout::new_inherited(pipeline_layout, valid)), Box::new(GPUPipelineLayout::new_inherited(pipeline_layout)),
global, global,
) )
} }
@ -46,20 +39,16 @@ impl GPUPipelineLayout {
pub fn id(&self) -> WebGPUPipelineLayout { pub fn id(&self) -> WebGPUPipelineLayout {
self.pipeline_layout self.pipeline_layout
} }
pub fn is_valid(&self) -> bool {
self.valid.get()
}
} }
impl GPUPipelineLayoutMethods for GPUPipelineLayout { impl GPUPipelineLayoutMethods for GPUPipelineLayout {
/// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label /// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label
fn GetLabel(&self) -> Option<DOMString> { fn GetLabel(&self) -> Option<USVString> {
self.label.borrow().clone() self.label.borrow().clone()
} }
/// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label /// 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; *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::error::{Error, Fallible};
use crate::dom::bindings::reflector::{reflect_dom_object, Reflector}; use crate::dom::bindings::reflector::{reflect_dom_object, Reflector};
use crate::dom::bindings::root::DomRoot; 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::globalscope::GlobalScope;
use crate::dom::gpubuffer::{GPUBuffer, GPUBufferState}; use crate::dom::gpubuffer::{GPUBuffer, GPUBufferState};
use crate::dom::gpucommandbuffer::GPUCommandBuffer; use crate::dom::gpucommandbuffer::GPUCommandBuffer;
@ -27,7 +27,7 @@ pub struct GPUQueue {
reflector_: Reflector, reflector_: Reflector,
#[ignore_malloc_size_of = "defined in webgpu"] #[ignore_malloc_size_of = "defined in webgpu"]
channel: WebGPU, channel: WebGPU,
label: DomRefCell<Option<DOMString>>, label: DomRefCell<Option<USVString>>,
queue: WebGPUQueue, queue: WebGPUQueue,
} }
@ -48,12 +48,12 @@ impl GPUQueue {
impl GPUQueueMethods for GPUQueue { impl GPUQueueMethods for GPUQueue {
/// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label /// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label
fn GetLabel(&self) -> Option<DOMString> { fn GetLabel(&self) -> Option<USVString> {
self.label.borrow().clone() self.label.borrow().clone()
} }
/// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label /// 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; *self.label.borrow_mut() = value;
} }
@ -98,8 +98,7 @@ impl GPUQueueMethods for GPUQueue {
let valid = data_offset + content_size <= bytes.len() as u64 && let valid = data_offset + content_size <= bytes.len() as u64 &&
buffer.state() == GPUBufferState::Unmapped && buffer.state() == GPUBufferState::Unmapped &&
content_size % wgt::COPY_BUFFER_ALIGNMENT == 0 && content_size % wgt::COPY_BUFFER_ALIGNMENT == 0 &&
buffer_offset % wgt::COPY_BUFFER_ALIGNMENT == 0 && buffer_offset % wgt::COPY_BUFFER_ALIGNMENT == 0;
buffer.is_valid();
if !valid { if !valid {
return Err(Error::Operation); return Err(Error::Operation);
@ -130,7 +129,7 @@ impl GPUQueueMethods for GPUQueue {
size: GPUExtent3D, size: GPUExtent3D,
) -> Fallible<()> { ) -> Fallible<()> {
let bytes = data.to_vec(); 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 { if !valid {
return Err(Error::Operation); 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::num::Finite;
use crate::dom::bindings::reflector::{reflect_dom_object, Reflector}; use crate::dom::bindings::reflector::{reflect_dom_object, Reflector};
use crate::dom::bindings::root::{Dom, DomRoot}; 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::globalscope::GlobalScope;
use crate::dom::gpubindgroup::GPUBindGroup; use crate::dom::gpubindgroup::GPUBindGroup;
use crate::dom::gpubuffer::GPUBuffer; use crate::dom::gpubuffer::GPUBuffer;
@ -25,7 +25,7 @@ pub struct GPURenderPassEncoder {
reflector_: Reflector, reflector_: Reflector,
#[ignore_malloc_size_of = "defined in webgpu"] #[ignore_malloc_size_of = "defined in webgpu"]
channel: WebGPU, channel: WebGPU,
label: DomRefCell<Option<DOMString>>, label: DomRefCell<Option<USVString>>,
#[ignore_malloc_size_of = "defined in wgpu-core"] #[ignore_malloc_size_of = "defined in wgpu-core"]
render_pass: DomRefCell<Option<RenderPass>>, render_pass: DomRefCell<Option<RenderPass>>,
command_encoder: Dom<GPUCommandEncoder>, command_encoder: Dom<GPUCommandEncoder>,
@ -61,12 +61,12 @@ impl GPURenderPassEncoder {
impl GPURenderPassEncoderMethods for GPURenderPassEncoder { impl GPURenderPassEncoderMethods for GPURenderPassEncoder {
/// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label /// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label
fn GetLabel(&self) -> Option<DOMString> { fn GetLabel(&self) -> Option<USVString> {
self.label.borrow().clone() self.label.borrow().clone()
} }
/// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label /// 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; *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::reflect_dom_object;
use crate::dom::bindings::reflector::Reflector; use crate::dom::bindings::reflector::Reflector;
use crate::dom::bindings::root::DomRoot; 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::globalscope::GlobalScope;
use dom_struct::dom_struct; use dom_struct::dom_struct;
use std::cell::Cell;
use webgpu::{WebGPUDevice, WebGPURenderPipeline}; use webgpu::{WebGPUDevice, WebGPURenderPipeline};
#[dom_struct] #[dom_struct]
pub struct GPURenderPipeline { pub struct GPURenderPipeline {
reflector_: Reflector, reflector_: Reflector,
label: DomRefCell<Option<DOMString>>, label: DomRefCell<Option<USVString>>,
render_pipeline: WebGPURenderPipeline, render_pipeline: WebGPURenderPipeline,
device: WebGPUDevice, device: WebGPUDevice,
valid: Cell<bool>,
} }
impl GPURenderPipeline { impl GPURenderPipeline {
fn new_inherited( fn new_inherited(render_pipeline: WebGPURenderPipeline, device: WebGPUDevice) -> Self {
render_pipeline: WebGPURenderPipeline,
device: WebGPUDevice,
valid: bool,
) -> Self {
Self { Self {
reflector_: Reflector::new(), reflector_: Reflector::new(),
label: DomRefCell::new(None), label: DomRefCell::new(None),
render_pipeline, render_pipeline,
valid: Cell::new(valid),
device, device,
} }
} }
@ -41,14 +34,9 @@ impl GPURenderPipeline {
global: &GlobalScope, global: &GlobalScope,
render_pipeline: WebGPURenderPipeline, render_pipeline: WebGPURenderPipeline,
device: WebGPUDevice, device: WebGPUDevice,
valid: bool,
) -> DomRoot<Self> { ) -> DomRoot<Self> {
reflect_dom_object( reflect_dom_object(
Box::new(GPURenderPipeline::new_inherited( Box::new(GPURenderPipeline::new_inherited(render_pipeline, device)),
render_pipeline,
device,
valid,
)),
global, global,
) )
} }
@ -62,12 +50,12 @@ impl GPURenderPipeline {
impl GPURenderPipelineMethods for GPURenderPipeline { impl GPURenderPipelineMethods for GPURenderPipeline {
/// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label /// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label
fn GetLabel(&self) -> Option<DOMString> { fn GetLabel(&self) -> Option<USVString> {
self.label.borrow().clone() self.label.borrow().clone()
} }
/// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label /// 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; *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::codegen::Bindings::GPUSamplerBinding::GPUSamplerMethods;
use crate::dom::bindings::reflector::{reflect_dom_object, Reflector}; use crate::dom::bindings::reflector::{reflect_dom_object, Reflector};
use crate::dom::bindings::root::DomRoot; 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::globalscope::GlobalScope;
use dom_struct::dom_struct; use dom_struct::dom_struct;
use std::cell::Cell;
use webgpu::{WebGPUDevice, WebGPUSampler}; use webgpu::{WebGPUDevice, WebGPUSampler};
#[dom_struct] #[dom_struct]
pub struct GPUSampler { pub struct GPUSampler {
reflector_: Reflector, reflector_: Reflector,
label: DomRefCell<Option<DOMString>>, label: DomRefCell<Option<USVString>>,
device: WebGPUDevice, device: WebGPUDevice,
compare_enable: bool, compare_enable: bool,
sampler: WebGPUSampler, sampler: WebGPUSampler,
valid: Cell<bool>,
} }
impl GPUSampler { impl GPUSampler {
fn new_inherited( fn new_inherited(device: WebGPUDevice, compare_enable: bool, sampler: WebGPUSampler) -> Self {
device: WebGPUDevice,
compare_enable: bool,
sampler: WebGPUSampler,
valid: bool,
) -> Self {
Self { Self {
reflector_: Reflector::new(), reflector_: Reflector::new(),
label: DomRefCell::new(None), label: DomRefCell::new(None),
valid: Cell::new(valid),
device, device,
sampler, sampler,
compare_enable, compare_enable,
@ -44,15 +36,9 @@ impl GPUSampler {
device: WebGPUDevice, device: WebGPUDevice,
compare_enable: bool, compare_enable: bool,
sampler: WebGPUSampler, sampler: WebGPUSampler,
valid: bool,
) -> DomRoot<Self> { ) -> DomRoot<Self> {
reflect_dom_object( reflect_dom_object(
Box::new(GPUSampler::new_inherited( Box::new(GPUSampler::new_inherited(device, compare_enable, sampler)),
device,
compare_enable,
sampler,
valid,
)),
global, global,
) )
} }
@ -62,20 +48,16 @@ impl GPUSampler {
pub fn id(&self) -> WebGPUSampler { pub fn id(&self) -> WebGPUSampler {
self.sampler self.sampler
} }
pub fn is_valid(&self) -> bool {
self.valid.get()
}
} }
impl GPUSamplerMethods for GPUSampler { impl GPUSamplerMethods for GPUSampler {
/// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label /// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label
fn GetLabel(&self) -> Option<DOMString> { fn GetLabel(&self) -> Option<USVString> {
self.label.borrow().clone() self.label.borrow().clone()
} }
/// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label /// 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; *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::codegen::Bindings::GPUShaderModuleBinding::GPUShaderModuleMethods;
use crate::dom::bindings::reflector::{reflect_dom_object, Reflector}; use crate::dom::bindings::reflector::{reflect_dom_object, Reflector};
use crate::dom::bindings::root::DomRoot; 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::globalscope::GlobalScope;
use dom_struct::dom_struct; use dom_struct::dom_struct;
use webgpu::WebGPUShaderModule; use webgpu::WebGPUShaderModule;
@ -14,7 +14,7 @@ use webgpu::WebGPUShaderModule;
#[dom_struct] #[dom_struct]
pub struct GPUShaderModule { pub struct GPUShaderModule {
reflector_: Reflector, reflector_: Reflector,
label: DomRefCell<Option<DOMString>>, label: DomRefCell<Option<USVString>>,
shader_module: WebGPUShaderModule, shader_module: WebGPUShaderModule,
} }
@ -43,12 +43,12 @@ impl GPUShaderModule {
impl GPUShaderModuleMethods for GPUShaderModule { impl GPUShaderModuleMethods for GPUShaderModule {
/// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label /// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label
fn GetLabel(&self) -> Option<DOMString> { fn GetLabel(&self) -> Option<USVString> {
self.label.borrow().clone() self.label.borrow().clone()
} }
/// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label /// 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; *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::codegen::Bindings::GPUSwapChainBinding::GPUSwapChainMethods;
use crate::dom::bindings::reflector::{reflect_dom_object, Reflector}; use crate::dom::bindings::reflector::{reflect_dom_object, Reflector};
use crate::dom::bindings::root::{Dom, DomRoot}; 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::globalscope::GlobalScope;
use crate::dom::gpucanvascontext::GPUCanvasContext; use crate::dom::gpucanvascontext::GPUCanvasContext;
use crate::dom::gputexture::GPUTexture; use crate::dom::gputexture::GPUTexture;
@ -18,7 +18,7 @@ pub struct GPUSwapChain {
reflector_: Reflector, reflector_: Reflector,
#[ignore_malloc_size_of = "channels are hard"] #[ignore_malloc_size_of = "channels are hard"]
channel: WebGPU, channel: WebGPU,
label: DomRefCell<Option<DOMString>>, label: DomRefCell<Option<USVString>>,
context: Dom<GPUCanvasContext>, context: Dom<GPUCanvasContext>,
texture: Dom<GPUTexture>, texture: Dom<GPUTexture>,
} }
@ -67,12 +67,12 @@ impl GPUSwapChain {
impl GPUSwapChainMethods for GPUSwapChain { impl GPUSwapChainMethods for GPUSwapChain {
/// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label /// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label
fn GetLabel(&self) -> Option<DOMString> { fn GetLabel(&self) -> Option<USVString> {
self.label.borrow().clone() self.label.borrow().clone()
} }
/// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label /// 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; *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::reflector::{reflect_dom_object, DomObject, Reflector};
use crate::dom::bindings::root::DomRoot; 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::globalscope::GlobalScope;
use crate::dom::gpudevice::{convert_texture_format, convert_texture_view_dimension}; use crate::dom::gpudevice::{convert_texture_format, convert_texture_view_dimension};
use crate::dom::gputextureview::GPUTextureView; use crate::dom::gputextureview::GPUTextureView;
use dom_struct::dom_struct; use dom_struct::dom_struct;
use std::cell::Cell; use std::string::String;
use webgpu::{wgt, WebGPU, WebGPUDevice, WebGPURequest, WebGPUTexture, WebGPUTextureView}; use webgpu::{wgt, WebGPU, WebGPUDevice, WebGPURequest, WebGPUTexture, WebGPUTextureView};
#[dom_struct] #[dom_struct]
pub struct GPUTexture { pub struct GPUTexture {
reflector_: Reflector, reflector_: Reflector,
texture: WebGPUTexture, texture: WebGPUTexture,
label: DomRefCell<Option<DOMString>>, label: DomRefCell<Option<USVString>>,
device: WebGPUDevice, device: WebGPUDevice,
#[ignore_malloc_size_of = "channels are hard"] #[ignore_malloc_size_of = "channels are hard"]
channel: WebGPU, channel: WebGPU,
@ -34,7 +34,6 @@ pub struct GPUTexture {
dimension: GPUTextureDimension, dimension: GPUTextureDimension,
format: GPUTextureFormat, format: GPUTextureFormat,
texture_usage: u32, texture_usage: u32,
valid: Cell<bool>,
} }
impl GPUTexture { impl GPUTexture {
@ -48,7 +47,6 @@ impl GPUTexture {
dimension: GPUTextureDimension, dimension: GPUTextureDimension,
format: GPUTextureFormat, format: GPUTextureFormat,
texture_usage: u32, texture_usage: u32,
valid: bool,
) -> Self { ) -> Self {
Self { Self {
reflector_: Reflector::new(), reflector_: Reflector::new(),
@ -62,7 +60,6 @@ impl GPUTexture {
dimension, dimension,
format, format,
texture_usage, texture_usage,
valid: Cell::new(valid),
} }
} }
@ -77,7 +74,6 @@ impl GPUTexture {
dimension: GPUTextureDimension, dimension: GPUTextureDimension,
format: GPUTextureFormat, format: GPUTextureFormat,
texture_usage: u32, texture_usage: u32,
valid: bool,
) -> DomRoot<Self> { ) -> DomRoot<Self> {
reflect_dom_object( reflect_dom_object(
Box::new(GPUTexture::new_inherited( Box::new(GPUTexture::new_inherited(
@ -90,7 +86,6 @@ impl GPUTexture {
dimension, dimension,
format, format,
texture_usage, texture_usage,
valid,
)), )),
global, global,
) )
@ -107,20 +102,16 @@ impl GPUTexture {
pub fn id(&self) -> WebGPUTexture { pub fn id(&self) -> WebGPUTexture {
self.texture self.texture
} }
pub fn is_valid(&self) -> bool {
self.valid.get()
}
} }
impl GPUTextureMethods for GPUTexture { impl GPUTextureMethods for GPUTexture {
/// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label /// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label
fn GetLabel(&self) -> Option<DOMString> { fn GetLabel(&self) -> Option<USVString> {
self.label.borrow().clone() self.label.borrow().clone()
} }
/// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label /// 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; *self.label.borrow_mut() = value;
} }
@ -145,7 +136,11 @@ impl GPUTextureMethods for GPUTexture {
let format = descriptor.format.unwrap_or(self.format); let format = descriptor.format.unwrap_or(self.format);
let desc = wgt::TextureViewDescriptor { 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), format: convert_texture_format(format),
dimension: convert_texture_view_dimension(dimension), dimension: convert_texture_view_dimension(dimension),
aspect: match descriptor.aspect { aspect: match descriptor.aspect {
@ -184,7 +179,7 @@ impl GPUTextureMethods for GPUTexture {
let texture_view = WebGPUTextureView(texture_view_id); 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 /// 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::codegen::Bindings::GPUTextureViewBinding::GPUTextureViewMethods;
use crate::dom::bindings::reflector::{reflect_dom_object, Reflector}; use crate::dom::bindings::reflector::{reflect_dom_object, Reflector};
use crate::dom::bindings::root::{Dom, DomRoot}; 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::globalscope::GlobalScope;
use crate::dom::gputexture::GPUTexture; use crate::dom::gputexture::GPUTexture;
use dom_struct::dom_struct; use dom_struct::dom_struct;
use std::cell::Cell;
use webgpu::WebGPUTextureView; use webgpu::WebGPUTextureView;
#[dom_struct] #[dom_struct]
pub struct GPUTextureView { pub struct GPUTextureView {
reflector_: Reflector, reflector_: Reflector,
label: DomRefCell<Option<DOMString>>, label: DomRefCell<Option<USVString>>,
texture_view: WebGPUTextureView, texture_view: WebGPUTextureView,
texture: Dom<GPUTexture>, texture: Dom<GPUTexture>,
valid: Cell<bool>,
} }
impl GPUTextureView { impl GPUTextureView {
fn new_inherited( fn new_inherited(texture_view: WebGPUTextureView, texture: &GPUTexture) -> GPUTextureView {
texture_view: WebGPUTextureView,
texture: &GPUTexture,
valid: bool,
) -> GPUTextureView {
Self { Self {
reflector_: Reflector::new(), reflector_: Reflector::new(),
texture: Dom::from_ref(texture), texture: Dom::from_ref(texture),
label: DomRefCell::new(None), label: DomRefCell::new(None),
texture_view, texture_view,
valid: Cell::new(valid),
} }
} }
@ -41,10 +34,9 @@ impl GPUTextureView {
global: &GlobalScope, global: &GlobalScope,
texture_view: WebGPUTextureView, texture_view: WebGPUTextureView,
texture: &GPUTexture, texture: &GPUTexture,
valid: bool,
) -> DomRoot<GPUTextureView> { ) -> DomRoot<GPUTextureView> {
reflect_dom_object( reflect_dom_object(
Box::new(GPUTextureView::new_inherited(texture_view, texture, valid)), Box::new(GPUTextureView::new_inherited(texture_view, texture)),
global, global,
) )
} }
@ -54,20 +46,16 @@ impl GPUTextureView {
pub fn id(&self) -> WebGPUTextureView { pub fn id(&self) -> WebGPUTextureView {
self.texture_view self.texture_view
} }
pub fn is_valid(&self) -> bool {
self.valid.get()
}
} }
impl GPUTextureViewMethods for GPUTextureView { impl GPUTextureViewMethods for GPUTextureView {
/// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label /// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label
fn GetLabel(&self) -> Option<DOMString> { fn GetLabel(&self) -> Option<USVString> {
self.label.borrow().clone() self.label.borrow().clone()
} }
/// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label /// 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; *self.label.borrow_mut() = value;
} }
} }

View file

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

View file

@ -88,23 +88,26 @@ pub enum WebGPURequest {
bind_group_id: id::BindGroupId, bind_group_id: id::BindGroupId,
bind_group_layout_id: id::BindGroupLayoutId, bind_group_layout_id: id::BindGroupLayoutId,
entries: Vec<(u32, WebGPUBindings)>, entries: Vec<(u32, WebGPUBindings)>,
label: Option<String>,
}, },
CreateBindGroupLayout { CreateBindGroupLayout {
device_id: id::DeviceId, device_id: id::DeviceId,
scope_id: Option<u64>, scope_id: Option<u64>,
bind_group_layout_id: id::BindGroupLayoutId, bind_group_layout_id: id::BindGroupLayoutId,
entries: Vec<wgt::BindGroupLayoutEntry>, entries: Vec<wgt::BindGroupLayoutEntry>,
label: Option<String>,
}, },
CreateBuffer { CreateBuffer {
device_id: id::DeviceId, device_id: id::DeviceId,
buffer_id: id::BufferId, buffer_id: id::BufferId,
descriptor: wgt::BufferDescriptor<String>, descriptor: wgt::BufferDescriptor<Option<String>>,
}, },
CreateCommandEncoder { CreateCommandEncoder {
device_id: id::DeviceId, device_id: id::DeviceId,
// TODO(zakorgy): Serialize CommandEncoderDescriptor in wgpu-core // TODO(zakorgy): Serialize CommandEncoderDescriptor in wgpu-core
// wgpu::command::CommandEncoderDescriptor, // wgpu::command::CommandEncoderDescriptor,
command_encoder_id: id::CommandEncoderId, command_encoder_id: id::CommandEncoderId,
label: Option<String>,
}, },
CreateComputePipeline { CreateComputePipeline {
device_id: id::DeviceId, device_id: id::DeviceId,
@ -145,7 +148,7 @@ pub enum WebGPURequest {
CreateSampler { CreateSampler {
device_id: id::DeviceId, device_id: id::DeviceId,
sampler_id: id::SamplerId, sampler_id: id::SamplerId,
descriptor: wgt::SamplerDescriptor<String>, descriptor: wgt::SamplerDescriptor<Option<String>>,
}, },
CreateShaderModule { CreateShaderModule {
device_id: id::DeviceId, device_id: id::DeviceId,
@ -163,12 +166,12 @@ pub enum WebGPURequest {
CreateTexture { CreateTexture {
device_id: id::DeviceId, device_id: id::DeviceId,
texture_id: id::TextureId, texture_id: id::TextureId,
descriptor: wgt::TextureDescriptor<String>, descriptor: wgt::TextureDescriptor<Option<String>>,
}, },
CreateTextureView { CreateTextureView {
texture_id: id::TextureId, texture_id: id::TextureId,
texture_view_id: id::TextureViewId, texture_view_id: id::TextureViewId,
descriptor: wgt::TextureViewDescriptor<String>, descriptor: wgt::TextureViewDescriptor<Option<String>>,
}, },
DestroyBuffer(id::BufferId), DestroyBuffer(id::BufferId),
DestroySwapChain { DestroySwapChain {
@ -368,7 +371,7 @@ impl<'a> WGPU<'a> {
fn run(&'a mut self) { fn run(&'a mut self) {
loop { loop {
if self.last_poll.elapsed() >= Duration::from_millis(DEVICE_POLL_INTERVAL) { if self.last_poll.elapsed() >= Duration::from_millis(DEVICE_POLL_INTERVAL) {
self.global.poll_all_devices(false); let _ = self.global.poll_all_devices(false);
self.last_poll = Instant::now(); self.last_poll = Instant::now();
} }
if let Ok(msg) = self.receiver.try_recv() { if let Ok(msg) = self.receiver.try_recv() {
@ -457,6 +460,7 @@ impl<'a> WGPU<'a> {
bind_group_id, bind_group_id,
bind_group_layout_id, bind_group_layout_id,
mut entries, mut entries,
label,
} => { } => {
let global = &self.global; let global = &self.global;
let bindings = entries let bindings = entries
@ -476,7 +480,7 @@ impl<'a> WGPU<'a> {
}) })
.collect::<Vec<_>>(); .collect::<Vec<_>>();
let descriptor = BindGroupDescriptor { let descriptor = BindGroupDescriptor {
label: None, label: label.as_deref(),
layout: bind_group_layout_id, layout: bind_group_layout_id,
entries: bindings.as_slice(), entries: bindings.as_slice(),
}; };
@ -491,11 +495,12 @@ impl<'a> WGPU<'a> {
scope_id, scope_id,
bind_group_layout_id, bind_group_layout_id,
entries, entries,
label,
} => { } => {
let global = &self.global; let global = &self.global;
let descriptor = wgt::BindGroupLayoutDescriptor { let descriptor = wgt::BindGroupLayoutDescriptor {
entries: entries.as_slice(), entries: entries.as_slice(),
label: None, label: label.as_deref(),
}; };
let result = gfx_select!(bind_group_layout_id => let result = gfx_select!(bind_group_layout_id =>
global.device_create_bind_group_layout(device_id, &descriptor, bind_group_layout_id)); global.device_create_bind_group_layout(device_id, &descriptor, bind_group_layout_id));
@ -509,16 +514,32 @@ impl<'a> WGPU<'a> {
descriptor, descriptor,
} => { } => {
let global = &self.global; let global = &self.global;
let st = CString::new(descriptor.label.as_bytes()).unwrap(); let st;
let label = match descriptor.label {
Some(ref s) => {
st = CString::new(s.as_bytes()).unwrap();
st.as_ptr()
},
None => ptr::null(),
};
let _ = gfx_select!(buffer_id => let _ = gfx_select!(buffer_id =>
global.device_create_buffer(device_id, &descriptor.map_label(|_| st.as_ptr()), buffer_id)); global.device_create_buffer(device_id, &descriptor.map_label(|_| label), buffer_id));
}, },
WebGPURequest::CreateCommandEncoder { WebGPURequest::CreateCommandEncoder {
device_id, device_id,
command_encoder_id, command_encoder_id,
label,
} => { } => {
let global = &self.global; let global = &self.global;
let desc = wgt::CommandEncoderDescriptor { label: ptr::null() }; let st;
let label = match label {
Some(ref s) => {
st = CString::new(s.as_bytes()).unwrap();
st.as_ptr()
},
None => ptr::null(),
};
let desc = wgt::CommandEncoderDescriptor { label };
let _ = gfx_select!(command_encoder_id => let _ = gfx_select!(command_encoder_id =>
global.device_create_command_encoder(device_id, &desc, command_encoder_id)); global.device_create_command_encoder(device_id, &desc, command_encoder_id));
}, },
@ -647,10 +668,17 @@ impl<'a> WGPU<'a> {
descriptor, descriptor,
} => { } => {
let global = &self.global; let global = &self.global;
let st = CString::new(descriptor.label.as_bytes()).unwrap(); let st;
let label = match descriptor.label {
Some(ref s) => {
st = CString::new(s.as_bytes()).unwrap();
st.as_ptr()
},
None => ptr::null(),
};
let _ = gfx_select!(sampler_id => global.device_create_sampler( let _ = gfx_select!(sampler_id => global.device_create_sampler(
device_id, device_id,
&descriptor.map_label(|_| st.as_ptr()), &descriptor.map_label(|_| label),
sampler_id sampler_id
)); ));
}, },
@ -712,10 +740,17 @@ impl<'a> WGPU<'a> {
descriptor, descriptor,
} => { } => {
let global = &self.global; let global = &self.global;
let st = CString::new(descriptor.label.as_bytes()).unwrap(); let st;
let label = match descriptor.label {
Some(ref s) => {
st = CString::new(s.as_bytes()).unwrap();
st.as_ptr()
},
None => ptr::null(),
};
let _ = gfx_select!(texture_id => global.device_create_texture( let _ = gfx_select!(texture_id => global.device_create_texture(
device_id, device_id,
&descriptor.map_label(|_| st.as_ptr()), &descriptor.map_label(|_| label),
texture_id texture_id
)); ));
}, },
@ -725,10 +760,17 @@ impl<'a> WGPU<'a> {
descriptor, descriptor,
} => { } => {
let global = &self.global; let global = &self.global;
let st = CString::new(descriptor.label.as_bytes()).unwrap(); let st;
let label = match descriptor.label {
Some(ref s) => {
st = CString::new(s.as_bytes()).unwrap();
st.as_ptr()
},
None => ptr::null(),
};
let _ = gfx_select!(texture_view_id => global.texture_create_view( let _ = gfx_select!(texture_view_id => global.texture_create_view(
texture_id, texture_id,
Some(&descriptor.map_label(|_| st.as_ptr())), Some(&descriptor.map_label(|_| label)),
texture_view_id texture_view_id
)); ));
}, },
@ -880,7 +922,7 @@ impl<'a> WGPU<'a> {
command_buffers, command_buffers,
} => { } => {
let global = &self.global; let global = &self.global;
gfx_select!(queue_id => global.queue_submit(queue_id, &command_buffers)); let _ = gfx_select!(queue_id => global.queue_submit(queue_id, &command_buffers));
}, },
WebGPURequest::SwapChainPresent { WebGPURequest::SwapChainPresent {
external_id, external_id,
@ -973,7 +1015,7 @@ impl<'a> WGPU<'a> {
encoder_id, encoder_id,
&wgt::CommandBufferDescriptor::default() &wgt::CommandBufferDescriptor::default()
)); ));
gfx_select!(queue_id => global.queue_submit( let _ = gfx_select!(queue_id => global.queue_submit(
queue_id, queue_id,
&[encoder_id] &[encoder_id]
)); ));