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"
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]]
name = "thread_local"
version = "1.0.1"
@ -6815,7 +6835,7 @@ dependencies = [
[[package]]
name = "wgpu-core"
version = "0.5.0"
source = "git+https://github.com/gfx-rs/wgpu#71e853d6ce289cb529ce39c03263e7f101dd4db5"
source = "git+https://github.com/gfx-rs/wgpu#73b230871ea4428ed3fb1e6e8bff81a7364fcdb2"
dependencies = [
"arrayvec 0.5.1",
"bitflags",
@ -6836,6 +6856,7 @@ dependencies = [
"serde",
"smallvec 1.4.1",
"spirv_headers",
"thiserror",
"tracing",
"wgpu-types",
]
@ -6843,7 +6864,7 @@ dependencies = [
[[package]]
name = "wgpu-types"
version = "0.5.0"
source = "git+https://github.com/gfx-rs/wgpu#71e853d6ce289cb529ce39c03263e7f101dd4db5"
source = "git+https://github.com/gfx-rs/wgpu#73b230871ea4428ed3fb1e6e8bff81a7364fcdb2"
dependencies = [
"bitflags",
"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::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;
};

View file

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