aboutsummaryrefslogtreecommitdiffstats
path: root/components/script
diff options
context:
space:
mode:
Diffstat (limited to 'components/script')
-rw-r--r--components/script/dom/bindings/trace.rs8
-rw-r--r--components/script/dom/gpuadapter.rs3
-rw-r--r--components/script/dom/gpubindgroup.rs8
-rw-r--r--components/script/dom/gpubindgrouplayout.rs12
-rw-r--r--components/script/dom/gpubuffer.rs6
-rw-r--r--components/script/dom/gpucanvascontext.rs8
-rw-r--r--components/script/dom/gpucommandbuffer.rs5
-rw-r--r--components/script/dom/gpucommandencoder.rs26
-rw-r--r--components/script/dom/gpucomputepassencoder.rs19
-rw-r--r--components/script/dom/gpucomputepipeline.rs12
-rw-r--r--components/script/dom/gpudevice.rs124
-rw-r--r--components/script/dom/gpupipelinelayout.rs12
-rw-r--r--components/script/dom/gpurenderbundle.rs75
-rw-r--r--components/script/dom/gpurenderbundleencoder.rs213
-rw-r--r--components/script/dom/gpurenderpassencoder.rs45
-rw-r--r--components/script/dom/gpurenderpipeline.rs15
-rw-r--r--components/script/dom/gpusampler.rs17
-rw-r--r--components/script/dom/gpushadermodule.rs12
-rw-r--r--components/script/dom/gpuswapchain.rs14
-rw-r--r--components/script/dom/gputexture.rs12
-rw-r--r--components/script/dom/gputextureview.rs11
-rw-r--r--components/script/dom/identityhub.rs14
-rw-r--r--components/script/dom/mod.rs2
-rw-r--r--components/script/dom/webidls/GPUDevice.webidl4
-rw-r--r--components/script/dom/webidls/GPURenderBundle.webidl12
-rw-r--r--components/script/dom/webidls/GPURenderBundleEncoder.webidl18
-rw-r--r--components/script/dom/webidls/GPURenderPassEncoder.webidl9
-rw-r--r--components/script/dom/webidls/GPURenderPipeline.webidl2
-rw-r--r--components/script/script_thread.rs1
29 files changed, 624 insertions, 95 deletions
diff --git a/components/script/dom/bindings/trace.rs b/components/script/dom/bindings/trace.rs
index a752b129a12..a5496a7cc17 100644
--- a/components/script/dom/bindings/trace.rs
+++ b/components/script/dom/bindings/trace.rs
@@ -168,12 +168,12 @@ use tendril::{StrTendril, TendrilSink};
use time::{Duration, Timespec, Tm};
use uuid::Uuid;
use webgpu::{
- wgpu::command::{ComputePass, RenderPass},
+ wgpu::command::{ComputePass, RenderBundleEncoder, RenderPass},
wgt::BindGroupLayoutEntry,
WebGPU, WebGPUAdapter, WebGPUBindGroup, WebGPUBindGroupLayout, WebGPUBuffer,
WebGPUCommandBuffer, WebGPUCommandEncoder, WebGPUComputePipeline, WebGPUDevice,
- WebGPUPipelineLayout, WebGPUQueue, WebGPURenderPipeline, WebGPUSampler, WebGPUShaderModule,
- WebGPUTexture, WebGPUTextureView,
+ WebGPUPipelineLayout, WebGPUQueue, WebGPURenderBundle, WebGPURenderPipeline, WebGPUSampler,
+ WebGPUShaderModule, WebGPUTexture, WebGPUTextureView,
};
use webrender_api::{DocumentId, ExternalImageId, ImageKey};
use webxr_api::{Finger, Hand, Ray, View};
@@ -618,6 +618,7 @@ unsafe_no_jsmanaged_fields!(WebGPUBindGroup);
unsafe_no_jsmanaged_fields!(WebGPUBindGroupLayout);
unsafe_no_jsmanaged_fields!(WebGPUComputePipeline);
unsafe_no_jsmanaged_fields!(WebGPURenderPipeline);
+unsafe_no_jsmanaged_fields!(WebGPURenderBundle);
unsafe_no_jsmanaged_fields!(WebGPUPipelineLayout);
unsafe_no_jsmanaged_fields!(WebGPUQueue);
unsafe_no_jsmanaged_fields!(WebGPUShaderModule);
@@ -630,6 +631,7 @@ unsafe_no_jsmanaged_fields!(WebGPUCommandEncoder);
unsafe_no_jsmanaged_fields!(WebGPUDevice);
unsafe_no_jsmanaged_fields!(BindGroupLayoutEntry);
unsafe_no_jsmanaged_fields!(Option<RenderPass>);
+unsafe_no_jsmanaged_fields!(Option<RenderBundleEncoder>);
unsafe_no_jsmanaged_fields!(Option<ComputePass>);
unsafe_no_jsmanaged_fields!(GPUBufferState);
unsafe_no_jsmanaged_fields!(GPUCommandEncoderState);
diff --git a/components/script/dom/gpuadapter.rs b/components/script/dom/gpuadapter.rs
index afab6b89d09..9392f1414fa 100644
--- a/components/script/dom/gpuadapter.rs
+++ b/components/script/dom/gpuadapter.rs
@@ -103,6 +103,7 @@ impl GPUAdapterMethods for GPUAdapter {
descriptor: desc,
device_id: id,
pipeline_id,
+ label: descriptor.parent.label.as_ref().map(|s| s.to_string()),
})
.is_err()
{
@@ -119,6 +120,7 @@ impl AsyncWGPUListener for GPUAdapter {
device_id,
queue_id,
_descriptor,
+ label,
} => {
let device = GPUDevice::new(
&self.global(),
@@ -128,6 +130,7 @@ impl AsyncWGPUListener for GPUAdapter {
Heap::default(),
device_id,
queue_id,
+ label,
);
self.global().add_gpu_device(&device);
promise.resolve_native(&device);
diff --git a/components/script/dom/gpubindgroup.rs b/components/script/dom/gpubindgroup.rs
index 458a437eed4..394cf41e915 100644
--- a/components/script/dom/gpubindgroup.rs
+++ b/components/script/dom/gpubindgroup.rs
@@ -26,10 +26,11 @@ impl GPUBindGroup {
bind_group: WebGPUBindGroup,
device: WebGPUDevice,
layout: &GPUBindGroupLayout,
+ label: Option<USVString>,
) -> Self {
Self {
reflector_: Reflector::new(),
- label: DomRefCell::new(None),
+ label: DomRefCell::new(label),
bind_group,
device,
layout: Dom::from_ref(layout),
@@ -41,9 +42,12 @@ impl GPUBindGroup {
bind_group: WebGPUBindGroup,
device: WebGPUDevice,
layout: &GPUBindGroupLayout,
+ label: Option<USVString>,
) -> DomRoot<Self> {
reflect_dom_object(
- Box::new(GPUBindGroup::new_inherited(bind_group, device, layout)),
+ Box::new(GPUBindGroup::new_inherited(
+ bind_group, device, layout, label,
+ )),
global,
)
}
diff --git a/components/script/dom/gpubindgrouplayout.rs b/components/script/dom/gpubindgrouplayout.rs
index 622981ebb4d..ce794269359 100644
--- a/components/script/dom/gpubindgrouplayout.rs
+++ b/components/script/dom/gpubindgrouplayout.rs
@@ -19,17 +19,21 @@ pub struct GPUBindGroupLayout {
}
impl GPUBindGroupLayout {
- fn new_inherited(bind_group_layout: WebGPUBindGroupLayout) -> Self {
+ fn new_inherited(bind_group_layout: WebGPUBindGroupLayout, label: Option<USVString>) -> Self {
Self {
reflector_: Reflector::new(),
- label: DomRefCell::new(None),
+ label: DomRefCell::new(label),
bind_group_layout,
}
}
- pub fn new(global: &GlobalScope, bind_group_layout: WebGPUBindGroupLayout) -> DomRoot<Self> {
+ pub fn new(
+ global: &GlobalScope,
+ bind_group_layout: WebGPUBindGroupLayout,
+ label: Option<USVString>,
+ ) -> DomRoot<Self> {
reflect_dom_object(
- Box::new(GPUBindGroupLayout::new_inherited(bind_group_layout)),
+ Box::new(GPUBindGroupLayout::new_inherited(bind_group_layout, label)),
global,
)
}
diff --git a/components/script/dom/gpubuffer.rs b/components/script/dom/gpubuffer.rs
index c7629852d92..1a9c9d14f2f 100644
--- a/components/script/dom/gpubuffer.rs
+++ b/components/script/dom/gpubuffer.rs
@@ -76,11 +76,12 @@ impl GPUBuffer {
state: GPUBufferState,
size: GPUSize64,
map_info: DomRefCell<Option<GPUBufferMapInfo>>,
+ label: Option<USVString>,
) -> Self {
Self {
reflector_: Reflector::new(),
channel,
- label: DomRefCell::new(None),
+ label: DomRefCell::new(label),
state: Cell::new(state),
device,
buffer,
@@ -99,10 +100,11 @@ impl GPUBuffer {
state: GPUBufferState,
size: GPUSize64,
map_info: DomRefCell<Option<GPUBufferMapInfo>>,
+ label: Option<USVString>,
) -> DomRoot<Self> {
reflect_dom_object(
Box::new(GPUBuffer::new_inherited(
- channel, buffer, device, state, size, map_info,
+ channel, buffer, device, state, size, map_info, label,
)),
global,
)
diff --git a/components/script/dom/gpucanvascontext.rs b/components/script/dom/gpucanvascontext.rs
index ca059fdec97..511f78634ef 100644
--- a/components/script/dom/gpucanvascontext.rs
+++ b/components/script/dom/gpucanvascontext.rs
@@ -201,7 +201,13 @@ impl GPUCanvasContextMethods for GPUCanvasContext {
self.webrender_image.set(Some(receiver.recv().unwrap()));
- let swap_chain = GPUSwapChain::new(&self.global(), self.channel.clone(), &self, &*texture);
+ let swap_chain = GPUSwapChain::new(
+ &self.global(),
+ self.channel.clone(),
+ &self,
+ &*texture,
+ descriptor.parent.label.as_ref().cloned(),
+ );
*self.swap_chain.borrow_mut() = Some(Dom::from_ref(&*swap_chain));
swap_chain
}
diff --git a/components/script/dom/gpucommandbuffer.rs b/components/script/dom/gpucommandbuffer.rs
index 7c7f03629d9..6e1eb8446f0 100644
--- a/components/script/dom/gpucommandbuffer.rs
+++ b/components/script/dom/gpucommandbuffer.rs
@@ -37,11 +37,12 @@ impl GPUCommandBuffer {
channel: WebGPU,
command_buffer: WebGPUCommandBuffer,
buffers: HashSet<DomRoot<GPUBuffer>>,
+ label: Option<USVString>,
) -> Self {
Self {
channel,
reflector_: Reflector::new(),
- label: DomRefCell::new(None),
+ label: DomRefCell::new(label),
command_buffer,
buffers: DomRefCell::new(buffers.into_iter().map(|b| Dom::from_ref(&*b)).collect()),
}
@@ -52,12 +53,14 @@ impl GPUCommandBuffer {
channel: WebGPU,
command_buffer: WebGPUCommandBuffer,
buffers: HashSet<DomRoot<GPUBuffer>>,
+ label: Option<USVString>,
) -> DomRoot<Self> {
reflect_dom_object(
Box::new(GPUCommandBuffer::new_inherited(
channel,
command_buffer,
buffers,
+ label,
)),
global,
)
diff --git a/components/script/dom/gpucommandencoder.rs b/components/script/dom/gpucommandencoder.rs
index 4f297fadb1b..8d8311eeae1 100644
--- a/components/script/dom/gpucommandencoder.rs
+++ b/components/script/dom/gpucommandencoder.rs
@@ -59,11 +59,12 @@ impl GPUCommandEncoder {
device: WebGPUDevice,
encoder: webgpu::WebGPUCommandEncoder,
valid: bool,
+ label: Option<USVString>,
) -> Self {
Self {
channel,
reflector_: Reflector::new(),
- label: DomRefCell::new(None),
+ label: DomRefCell::new(label),
device,
encoder,
buffers: DomRefCell::new(HashSet::new()),
@@ -78,10 +79,11 @@ impl GPUCommandEncoder {
device: WebGPUDevice,
encoder: webgpu::WebGPUCommandEncoder,
valid: bool,
+ label: Option<USVString>,
) -> DomRoot<Self> {
reflect_dom_object(
Box::new(GPUCommandEncoder::new_inherited(
- channel, device, encoder, valid,
+ channel, device, encoder, valid, label,
)),
global,
)
@@ -117,13 +119,18 @@ impl GPUCommandEncoderMethods for GPUCommandEncoder {
/// https://gpuweb.github.io/gpuweb/#dom-gpucommandencoder-begincomputepass
fn BeginComputePass(
&self,
- _descriptor: &GPUComputePassDescriptor,
+ descriptor: &GPUComputePassDescriptor,
) -> DomRoot<GPUComputePassEncoder> {
self.set_state(
GPUCommandEncoderState::EncodingComputePass,
GPUCommandEncoderState::Open,
);
- GPUComputePassEncoder::new(&self.global(), self.channel.clone(), &self)
+ GPUComputePassEncoder::new(
+ &self.global(),
+ self.channel.clone(),
+ &self,
+ descriptor.parent.label.as_ref().cloned(),
+ )
}
/// https://gpuweb.github.io/gpuweb/#dom-gpucommandencoder-beginrenderpass
@@ -228,7 +235,13 @@ impl GPUCommandEncoderMethods for GPUCommandEncoder {
let render_pass = wgpu_com::RenderPass::new(self.encoder.0, desc);
- GPURenderPassEncoder::new(&self.global(), self.channel.clone(), render_pass, &self)
+ GPURenderPassEncoder::new(
+ &self.global(),
+ self.channel.clone(),
+ render_pass,
+ &self,
+ descriptor.parent.label.as_ref().cloned(),
+ )
}
/// https://gpuweb.github.io/gpuweb/#dom-gpucommandencoder-copybuffertobuffer
@@ -352,7 +365,7 @@ impl GPUCommandEncoderMethods for GPUCommandEncoder {
}
/// https://gpuweb.github.io/gpuweb/#dom-gpucommandencoder-finish
- fn Finish(&self, _descriptor: &GPUCommandBufferDescriptor) -> DomRoot<GPUCommandBuffer> {
+ fn Finish(&self, descriptor: &GPUCommandBufferDescriptor) -> DomRoot<GPUCommandBuffer> {
self.channel
.0
.send(WebGPURequest::CommandEncoderFinish {
@@ -369,6 +382,7 @@ impl GPUCommandEncoderMethods for GPUCommandEncoder {
self.channel.clone(),
buffer,
self.buffers.borrow_mut().drain().collect(),
+ descriptor.parent.label.as_ref().cloned(),
)
}
}
diff --git a/components/script/dom/gpucomputepassencoder.rs b/components/script/dom/gpucomputepassencoder.rs
index 2f4535d835e..1cfcdf7a25c 100644
--- a/components/script/dom/gpucomputepassencoder.rs
+++ b/components/script/dom/gpucomputepassencoder.rs
@@ -30,19 +30,28 @@ pub struct GPUComputePassEncoder {
}
impl GPUComputePassEncoder {
- fn new_inherited(channel: WebGPU, parent: &GPUCommandEncoder) -> Self {
+ fn new_inherited(
+ channel: WebGPU,
+ parent: &GPUCommandEncoder,
+ label: Option<USVString>,
+ ) -> Self {
Self {
channel,
reflector_: Reflector::new(),
- label: DomRefCell::new(None),
+ label: DomRefCell::new(label),
compute_pass: DomRefCell::new(Some(ComputePass::new(parent.id().0))),
command_encoder: Dom::from_ref(parent),
}
}
- pub fn new(global: &GlobalScope, channel: WebGPU, parent: &GPUCommandEncoder) -> DomRoot<Self> {
+ pub fn new(
+ global: &GlobalScope,
+ channel: WebGPU,
+ parent: &GPUCommandEncoder,
+ label: Option<USVString>,
+ ) -> DomRoot<Self> {
reflect_dom_object(
- Box::new(GPUComputePassEncoder::new_inherited(channel, parent)),
+ Box::new(GPUComputePassEncoder::new_inherited(channel, parent, label)),
global,
)
}
@@ -86,7 +95,7 @@ impl GPUComputePassEncoderMethods for GPUComputePassEncoder {
command_encoder_id: self.command_encoder.id().0,
compute_pass,
})
- .unwrap();
+ .expect("Failed to send RunComputePass");
self.command_encoder.set_state(
GPUCommandEncoderState::Open,
diff --git a/components/script/dom/gpucomputepipeline.rs b/components/script/dom/gpucomputepipeline.rs
index a5b7fbc495d..598c6a7caee 100644
--- a/components/script/dom/gpucomputepipeline.rs
+++ b/components/script/dom/gpucomputepipeline.rs
@@ -20,17 +20,21 @@ pub struct GPUComputePipeline {
}
impl GPUComputePipeline {
- fn new_inherited(compute_pipeline: WebGPUComputePipeline) -> Self {
+ fn new_inherited(compute_pipeline: WebGPUComputePipeline, label: Option<USVString>) -> Self {
Self {
reflector_: Reflector::new(),
- label: DomRefCell::new(None),
+ label: DomRefCell::new(label),
compute_pipeline,
}
}
- pub fn new(global: &GlobalScope, compute_pipeline: WebGPUComputePipeline) -> DomRoot<Self> {
+ pub fn new(
+ global: &GlobalScope,
+ compute_pipeline: WebGPUComputePipeline,
+ label: Option<USVString>,
+ ) -> DomRoot<Self> {
reflect_dom_object(
- Box::new(GPUComputePipeline::new_inherited(compute_pipeline)),
+ Box::new(GPUComputePipeline::new_inherited(compute_pipeline, label)),
global,
)
}
diff --git a/components/script/dom/gpudevice.rs b/components/script/dom/gpudevice.rs
index a1d2c19c58c..1cd9c7653ed 100644
--- a/components/script/dom/gpudevice.rs
+++ b/components/script/dom/gpudevice.rs
@@ -17,6 +17,7 @@ use crate::dom::bindings::codegen::Bindings::GPUDeviceBinding::{
GPUCommandEncoderDescriptor, GPUDeviceMethods,
};
use crate::dom::bindings::codegen::Bindings::GPUPipelineLayoutBinding::GPUPipelineLayoutDescriptor;
+use crate::dom::bindings::codegen::Bindings::GPURenderBundleEncoderBinding::GPURenderBundleEncoderDescriptor;
use crate::dom::bindings::codegen::Bindings::GPURenderPipelineBinding::{
GPUBlendDescriptor, GPUBlendFactor, GPUBlendOperation, GPUCullMode, GPUFrontFace,
GPUIndexFormat, GPUInputStepMode, GPUPrimitiveTopology, GPURenderPipelineDescriptor,
@@ -50,6 +51,7 @@ use crate::dom::gpucommandencoder::GPUCommandEncoder;
use crate::dom::gpucomputepipeline::GPUComputePipeline;
use crate::dom::gpupipelinelayout::GPUPipelineLayout;
use crate::dom::gpuqueue::GPUQueue;
+use crate::dom::gpurenderbundleencoder::GPURenderBundleEncoder;
use crate::dom::gpurenderpipeline::GPURenderPipeline;
use crate::dom::gpusampler::GPUSampler;
use crate::dom::gpushadermodule::GPUShaderModule;
@@ -64,8 +66,9 @@ 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 as wgpu_bind, pipeline as wgpu_pipe};
+use webgpu::wgpu::{
+ binding_model as wgpu_bind, command::RenderBundleEncoder, pipeline as wgpu_pipe,
+};
use webgpu::{self, wgt, WebGPU, WebGPURequest};
type ErrorScopeId = u64;
@@ -116,6 +119,7 @@ impl GPUDevice {
limits: Heap<*mut JSObject>,
device: webgpu::WebGPUDevice,
queue: &GPUQueue,
+ label: Option<String>,
) -> Self {
Self {
eventtarget: EventTarget::new_inherited(),
@@ -123,7 +127,7 @@ impl GPUDevice {
adapter: Dom::from_ref(adapter),
extensions,
limits,
- label: DomRefCell::new(None),
+ label: DomRefCell::new(label.map(|l| USVString::from(l))),
device,
default_queue: Dom::from_ref(queue),
scope_context: DomRefCell::new(ScopeContext {
@@ -144,11 +148,12 @@ impl GPUDevice {
limits: Heap<*mut JSObject>,
device: webgpu::WebGPUDevice,
queue: webgpu::WebGPUQueue,
+ label: Option<String>,
) -> DomRoot<Self> {
let queue = GPUQueue::new(global, channel.clone(), queue);
reflect_dom_object(
Box::new(GPUDevice::new_inherited(
- channel, adapter, extensions, limits, device, &queue,
+ channel, adapter, extensions, limits, device, &queue, label,
)),
global,
)
@@ -247,11 +252,7 @@ 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: descriptor
- .parent
- .label
- .as_ref()
- .map(|s| String::from(s.as_ref())),
+ label: descriptor.parent.label.as_ref().map(|s| s.to_string()),
size: descriptor.size,
usage: match wgt::BufferUsage::from_bits(descriptor.usage) {
Some(u) => u,
@@ -299,6 +300,7 @@ impl GPUDeviceMethods for GPUDevice {
state,
descriptor.size,
map_info,
+ descriptor.parent.label.as_ref().cloned(),
)
}
@@ -427,7 +429,11 @@ impl GPUDeviceMethods for GPUDevice {
let bgl = webgpu::WebGPUBindGroupLayout(bind_group_layout_id);
- let layout = GPUBindGroupLayout::new(&self.global(), bgl);
+ let layout = GPUBindGroupLayout::new(
+ &self.global(),
+ bgl,
+ descriptor.parent.label.as_ref().cloned(),
+ );
self.bind_group_layouts
.borrow_mut()
@@ -470,7 +476,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)
+ GPUPipelineLayout::new(
+ &self.global(),
+ pipeline_layout,
+ descriptor.parent.label.as_ref().cloned(),
+ )
}
/// https://gpuweb.github.io/gpuweb/#dom-gpudevice-createbindgroup
@@ -527,7 +537,13 @@ impl GPUDeviceMethods for GPUDevice {
let bind_group = webgpu::WebGPUBindGroup(bind_group_id);
- GPUBindGroup::new(&self.global(), bind_group, self.device, &*descriptor.layout)
+ GPUBindGroup::new(
+ &self.global(),
+ bind_group,
+ self.device,
+ &*descriptor.layout,
+ descriptor.parent.label.as_ref().cloned(),
+ )
}
/// https://gpuweb.github.io/gpuweb/#dom-gpudevice-createshadermodule
@@ -556,7 +572,11 @@ impl GPUDeviceMethods for GPUDevice {
.expect("Failed to create WebGPU ShaderModule");
let shader_module = webgpu::WebGPUShaderModule(program_id);
- GPUShaderModule::new(&self.global(), shader_module)
+ GPUShaderModule::new(
+ &self.global(),
+ shader_module,
+ descriptor.parent.label.as_ref().cloned(),
+ )
}
/// https://gpuweb.github.io/gpuweb/#dom-gpudevice-createcomputepipeline
@@ -591,7 +611,11 @@ impl GPUDeviceMethods for GPUDevice {
.expect("Failed to create WebGPU ComputePipeline");
let compute_pipeline = webgpu::WebGPUComputePipeline(compute_pipeline_id);
- GPUComputePipeline::new(&self.global(), compute_pipeline)
+ GPUComputePipeline::new(
+ &self.global(),
+ compute_pipeline,
+ descriptor.parent.parent.label.as_ref().cloned(),
+ )
}
/// https://gpuweb.github.io/gpuweb/#dom-gpudevice-createcommandencoder
@@ -609,11 +633,7 @@ 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())),
+ label: descriptor.parent.label.as_ref().map(|s| s.to_string()),
})
.expect("Failed to create WebGPU command encoder");
@@ -625,6 +645,7 @@ impl GPUDeviceMethods for GPUDevice {
self.device,
encoder,
true,
+ descriptor.parent.label.as_ref().cloned(),
)
}
@@ -632,11 +653,7 @@ impl GPUDeviceMethods for GPUDevice {
fn CreateTexture(&self, descriptor: &GPUTextureDescriptor) -> DomRoot<GPUTexture> {
let size = convert_texture_size_to_dict(&descriptor.size);
let desc = wgt::TextureDescriptor {
- label: descriptor
- .parent
- .label
- .as_ref()
- .map(|s| String::from(s.as_ref())),
+ label: descriptor.parent.label.as_ref().map(|s| s.to_string()),
size: convert_texture_size_to_wgt(&size),
mip_level_count: descriptor.mipLevelCount,
sample_count: descriptor.sampleCount,
@@ -680,6 +697,7 @@ impl GPUDeviceMethods for GPUDevice {
descriptor.dimension,
descriptor.format,
descriptor.usage,
+ descriptor.parent.label.as_ref().cloned(),
)
}
@@ -692,11 +710,7 @@ impl GPUDeviceMethods for GPUDevice {
.create_sampler_id(self.device.0.backend());
let compare_enable = descriptor.compare.is_some();
let desc = wgt::SamplerDescriptor {
- label: descriptor
- .parent
- .label
- .as_ref()
- .map(|s| String::from(s.as_ref())),
+ label: descriptor.parent.label.as_ref().map(|s| s.to_string()),
address_mode_u: convert_address_mode(descriptor.addressModeU),
address_mode_v: convert_address_mode(descriptor.addressModeV),
address_mode_w: convert_address_mode(descriptor.addressModeW),
@@ -720,7 +734,13 @@ impl GPUDeviceMethods for GPUDevice {
let sampler = webgpu::WebGPUSampler(sampler_id);
- GPUSampler::new(&self.global(), self.device, compare_enable, sampler)
+ GPUSampler::new(
+ &self.global(),
+ self.device,
+ compare_enable,
+ sampler,
+ descriptor.parent.label.as_ref().cloned(),
+ )
}
/// https://gpuweb.github.io/gpuweb/#dom-gpudevice-createrenderpipeline
@@ -753,6 +773,7 @@ impl GPUDeviceMethods for GPUDevice {
GPUCullMode::Front => wgt::CullMode::Front,
GPUCullMode::Back => wgt::CullMode::Back,
},
+ clamp_depth: rs_desc.clampDepth,
depth_bias: rs_desc.depthBias,
depth_bias_slope_scale: *rs_desc.depthBiasSlopeScale,
depth_bias_clamp: *rs_desc.depthBiasClamp,
@@ -855,7 +876,48 @@ impl GPUDeviceMethods for GPUDevice {
let render_pipeline = webgpu::WebGPURenderPipeline(render_pipeline_id);
- GPURenderPipeline::new(&self.global(), render_pipeline, self.device)
+ GPURenderPipeline::new(
+ &self.global(),
+ render_pipeline,
+ self.device,
+ descriptor.parent.parent.label.as_ref().cloned(),
+ )
+ }
+
+ /// https://gpuweb.github.io/gpuweb/#dom-gpudevice-createrenderbundleencoder
+ fn CreateRenderBundleEncoder(
+ &self,
+ descriptor: &GPURenderBundleEncoderDescriptor,
+ ) -> DomRoot<GPURenderBundleEncoder> {
+ let desc = wgt::RenderBundleEncoderDescriptor {
+ label: descriptor
+ .parent
+ .label
+ .as_ref()
+ .map(|s| Cow::Owned(s.to_string())),
+ color_formats: Cow::Owned(
+ descriptor
+ .colorFormats
+ .iter()
+ .map(|f| convert_texture_format(*f))
+ .collect::<Vec<_>>(),
+ ),
+ depth_stencil_format: descriptor
+ .depthStencilFormat
+ .map(|f| convert_texture_format(f)),
+ sample_count: descriptor.sampleCount,
+ };
+
+ // Handle error gracefully
+ let render_bundle_encoder = RenderBundleEncoder::new(&desc, self.device.0, None).unwrap();
+
+ GPURenderBundleEncoder::new(
+ &self.global(),
+ render_bundle_encoder,
+ self.device,
+ self.channel.clone(),
+ descriptor.parent.label.as_ref().cloned(),
+ )
}
/// https://gpuweb.github.io/gpuweb/#dom-gpudevice-pusherrorscope
diff --git a/components/script/dom/gpupipelinelayout.rs b/components/script/dom/gpupipelinelayout.rs
index d0809819600..7547adce843 100644
--- a/components/script/dom/gpupipelinelayout.rs
+++ b/components/script/dom/gpupipelinelayout.rs
@@ -19,17 +19,21 @@ pub struct GPUPipelineLayout {
}
impl GPUPipelineLayout {
- fn new_inherited(pipeline_layout: WebGPUPipelineLayout) -> Self {
+ fn new_inherited(pipeline_layout: WebGPUPipelineLayout, label: Option<USVString>) -> Self {
Self {
reflector_: Reflector::new(),
- label: DomRefCell::new(None),
+ label: DomRefCell::new(label),
pipeline_layout,
}
}
- pub fn new(global: &GlobalScope, pipeline_layout: WebGPUPipelineLayout) -> DomRoot<Self> {
+ pub fn new(
+ global: &GlobalScope,
+ pipeline_layout: WebGPUPipelineLayout,
+ label: Option<USVString>,
+ ) -> DomRoot<Self> {
reflect_dom_object(
- Box::new(GPUPipelineLayout::new_inherited(pipeline_layout)),
+ Box::new(GPUPipelineLayout::new_inherited(pipeline_layout, label)),
global,
)
}
diff --git a/components/script/dom/gpurenderbundle.rs b/components/script/dom/gpurenderbundle.rs
new file mode 100644
index 00000000000..5c020f8f697
--- /dev/null
+++ b/components/script/dom/gpurenderbundle.rs
@@ -0,0 +1,75 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
+
+use crate::dom::bindings::cell::DomRefCell;
+use crate::dom::bindings::codegen::Bindings::GPURenderBundleBinding::GPURenderBundleMethods;
+use crate::dom::bindings::reflector::{reflect_dom_object, Reflector};
+use crate::dom::bindings::root::DomRoot;
+use crate::dom::bindings::str::USVString;
+use crate::dom::globalscope::GlobalScope;
+use dom_struct::dom_struct;
+use webgpu::{WebGPU, WebGPUDevice, WebGPURenderBundle};
+
+#[dom_struct]
+pub struct GPURenderBundle {
+ reflector_: Reflector,
+ #[ignore_malloc_size_of = "channels are hard"]
+ channel: WebGPU,
+ device: WebGPUDevice,
+ render_bundle: WebGPURenderBundle,
+ label: DomRefCell<Option<USVString>>,
+}
+
+impl GPURenderBundle {
+ fn new_inherited(
+ render_bundle: WebGPURenderBundle,
+ device: WebGPUDevice,
+ channel: WebGPU,
+ label: Option<USVString>,
+ ) -> Self {
+ Self {
+ reflector_: Reflector::new(),
+ render_bundle,
+ device,
+ channel,
+ label: DomRefCell::new(label),
+ }
+ }
+
+ pub fn new(
+ global: &GlobalScope,
+ render_bundle: WebGPURenderBundle,
+ device: WebGPUDevice,
+ channel: WebGPU,
+ label: Option<USVString>,
+ ) -> DomRoot<Self> {
+ reflect_dom_object(
+ Box::new(GPURenderBundle::new_inherited(
+ render_bundle,
+ device,
+ channel,
+ label,
+ )),
+ global,
+ )
+ }
+}
+
+impl GPURenderBundle {
+ pub fn id(&self) -> WebGPURenderBundle {
+ self.render_bundle
+ }
+}
+
+impl GPURenderBundleMethods for GPURenderBundle {
+ /// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label
+ fn GetLabel(&self) -> Option<USVString> {
+ self.label.borrow().clone()
+ }
+
+ /// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label
+ fn SetLabel(&self, value: Option<USVString>) {
+ *self.label.borrow_mut() = value;
+ }
+}
diff --git a/components/script/dom/gpurenderbundleencoder.rs b/components/script/dom/gpurenderbundleencoder.rs
new file mode 100644
index 00000000000..5759b09b299
--- /dev/null
+++ b/components/script/dom/gpurenderbundleencoder.rs
@@ -0,0 +1,213 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
+
+use crate::dom::bindings::cell::DomRefCell;
+use crate::dom::bindings::codegen::Bindings::GPURenderBundleBinding::GPURenderBundleDescriptor;
+use crate::dom::bindings::codegen::Bindings::GPURenderBundleEncoderBinding::GPURenderBundleEncoderMethods;
+use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector};
+use crate::dom::bindings::root::DomRoot;
+use crate::dom::bindings::str::USVString;
+use crate::dom::globalscope::GlobalScope;
+use crate::dom::gpubindgroup::GPUBindGroup;
+use crate::dom::gpubuffer::GPUBuffer;
+use crate::dom::gpurenderbundle::GPURenderBundle;
+use crate::dom::gpurenderpipeline::GPURenderPipeline;
+use dom_struct::dom_struct;
+use webgpu::{
+ wgpu::command::{bundle_ffi as wgpu_bundle, RenderBundleEncoder},
+ wgt, WebGPU, WebGPUDevice, WebGPURenderBundle, WebGPURequest,
+};
+
+#[dom_struct]
+pub struct GPURenderBundleEncoder {
+ reflector_: Reflector,
+ #[ignore_malloc_size_of = "channels are hard"]
+ channel: WebGPU,
+ device: WebGPUDevice,
+ #[ignore_malloc_size_of = "defined in wgpu-core"]
+ render_bundle_encoder: DomRefCell<Option<RenderBundleEncoder>>,
+ label: DomRefCell<Option<USVString>>,
+}
+
+impl GPURenderBundleEncoder {
+ fn new_inherited(
+ render_bundle_encoder: RenderBundleEncoder,
+ device: WebGPUDevice,
+ channel: WebGPU,
+ label: Option<USVString>,
+ ) -> Self {
+ Self {
+ reflector_: Reflector::new(),
+ render_bundle_encoder: DomRefCell::new(Some(render_bundle_encoder)),
+ device,
+ channel,
+ label: DomRefCell::new(label),
+ }
+ }
+
+ pub fn new(
+ global: &GlobalScope,
+ render_bundle_encoder: RenderBundleEncoder,
+ device: WebGPUDevice,
+ channel: WebGPU,
+ label: Option<USVString>,
+ ) -> DomRoot<Self> {
+ reflect_dom_object(
+ Box::new(GPURenderBundleEncoder::new_inherited(
+ render_bundle_encoder,
+ device,
+ channel,
+ label,
+ )),
+ global,
+ )
+ }
+}
+
+impl GPURenderBundleEncoderMethods for GPURenderBundleEncoder {
+ /// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label
+ fn GetLabel(&self) -> Option<USVString> {
+ self.label.borrow().clone()
+ }
+
+ /// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label
+ fn SetLabel(&self, value: Option<USVString>) {
+ *self.label.borrow_mut() = value;
+ }
+
+ /// https://gpuweb.github.io/gpuweb/#dom-gpuprogrammablepassencoder-setbindgroup
+ #[allow(unsafe_code)]
+ fn SetBindGroup(&self, index: u32, bind_group: &GPUBindGroup, dynamic_offsets: Vec<u32>) {
+ if let Some(encoder) = self.render_bundle_encoder.borrow_mut().as_mut() {
+ unsafe {
+ wgpu_bundle::wgpu_render_bundle_set_bind_group(
+ encoder,
+ index,
+ bind_group.id().0,
+ dynamic_offsets.as_ptr(),
+ dynamic_offsets.len(),
+ )
+ };
+ }
+ }
+
+ /// https://gpuweb.github.io/gpuweb/#dom-gpurenderencoderbase-setpipeline
+ fn SetPipeline(&self, pipeline: &GPURenderPipeline) {
+ if let Some(encoder) = self.render_bundle_encoder.borrow_mut().as_mut() {
+ wgpu_bundle::wgpu_render_bundle_set_pipeline(encoder, pipeline.id().0);
+ }
+ }
+
+ /// https://gpuweb.github.io/gpuweb/#dom-gpurenderencoderbase-setindexbuffer
+ fn SetIndexBuffer(&self, buffer: &GPUBuffer, offset: u64, size: u64) {
+ if let Some(encoder) = self.render_bundle_encoder.borrow_mut().as_mut() {
+ wgpu_bundle::wgpu_render_bundle_set_index_buffer(
+ encoder,
+ buffer.id().0,
+ offset,
+ wgt::BufferSize::new(size),
+ );
+ }
+ }
+
+ /// https://gpuweb.github.io/gpuweb/#dom-gpurenderencoderbase-setvertexbuffer
+ fn SetVertexBuffer(&self, slot: u32, buffer: &GPUBuffer, offset: u64, size: u64) {
+ if let Some(encoder) = self.render_bundle_encoder.borrow_mut().as_mut() {
+ wgpu_bundle::wgpu_render_bundle_set_vertex_buffer(
+ encoder,
+ slot,
+ buffer.id().0,
+ offset,
+ wgt::BufferSize::new(size),
+ );
+ }
+ }
+
+ /// https://gpuweb.github.io/gpuweb/#dom-gpurenderencoderbase-draw
+ fn Draw(&self, vertex_count: u32, instance_count: u32, first_vertex: u32, first_instance: u32) {
+ if let Some(encoder) = self.render_bundle_encoder.borrow_mut().as_mut() {
+ wgpu_bundle::wgpu_render_bundle_draw(
+ encoder,
+ vertex_count,
+ instance_count,
+ first_vertex,
+ first_instance,
+ );
+ }
+ }
+
+ /// https://gpuweb.github.io/gpuweb/#dom-gpurenderencoderbase-drawindexed
+ fn DrawIndexed(
+ &self,
+ index_count: u32,
+ instance_count: u32,
+ first_index: u32,
+ base_vertex: i32,
+ first_instance: u32,
+ ) {
+ if let Some(encoder) = self.render_bundle_encoder.borrow_mut().as_mut() {
+ wgpu_bundle::wgpu_render_bundle_draw_indexed(
+ encoder,
+ index_count,
+ instance_count,
+ first_index,
+ base_vertex,
+ first_instance,
+ );
+ }
+ }
+
+ /// https://gpuweb.github.io/gpuweb/#dom-gpurenderencoderbase-drawindirect
+ fn DrawIndirect(&self, indirect_buffer: &GPUBuffer, indirect_offset: u64) {
+ if let Some(encoder) = self.render_bundle_encoder.borrow_mut().as_mut() {
+ wgpu_bundle::wgpu_render_bundle_draw_indirect(
+ encoder,
+ indirect_buffer.id().0,
+ indirect_offset,
+ );
+ }
+ }
+
+ /// https://gpuweb.github.io/gpuweb/#dom-gpurenderencoderbase-drawindexedindirect
+ fn DrawIndexedIndirect(&self, indirect_buffer: &GPUBuffer, indirect_offset: u64) {
+ if let Some(encoder) = self.render_bundle_encoder.borrow_mut().as_mut() {
+ wgpu_bundle::wgpu_render_pass_bundle_indexed_indirect(
+ encoder,
+ indirect_buffer.id().0,
+ indirect_offset,
+ );
+ }
+ }
+
+ /// https://gpuweb.github.io/gpuweb/#dom-gpurenderbundleencoder-finish
+ fn Finish(&self, descriptor: &GPURenderBundleDescriptor) -> DomRoot<GPURenderBundle> {
+ let desc = wgt::RenderBundleDescriptor {
+ label: descriptor.parent.label.as_ref().map(|s| s.to_string()),
+ };
+ let encoder = self.render_bundle_encoder.borrow_mut().take().unwrap();
+ let render_bundle_id = self
+ .global()
+ .wgpu_id_hub()
+ .lock()
+ .create_render_bundle_id(self.device.0.backend());
+
+ self.channel
+ .0
+ .send(WebGPURequest::RenderBundleEncoderFinish {
+ render_bundle_encoder: encoder,
+ descriptor: desc,
+ render_bundle_id,
+ })
+ .expect("Failed to send RenderBundleEncoderFinish");
+
+ let render_bundle = WebGPURenderBundle(render_bundle_id);
+ GPURenderBundle::new(
+ &self.global(),
+ render_bundle,
+ self.device,
+ self.channel.clone(),
+ descriptor.parent.label.as_ref().cloned(),
+ )
+ }
+}
diff --git a/components/script/dom/gpurenderpassencoder.rs b/components/script/dom/gpurenderpassencoder.rs
index ba8cf0a65d2..a3c620e7ee2 100644
--- a/components/script/dom/gpurenderpassencoder.rs
+++ b/components/script/dom/gpurenderpassencoder.rs
@@ -13,6 +13,7 @@ use crate::dom::globalscope::GlobalScope;
use crate::dom::gpubindgroup::GPUBindGroup;
use crate::dom::gpubuffer::GPUBuffer;
use crate::dom::gpucommandencoder::{GPUCommandEncoder, GPUCommandEncoderState};
+use crate::dom::gpurenderbundle::GPURenderBundle;
use crate::dom::gpurenderpipeline::GPURenderPipeline;
use dom_struct::dom_struct;
use webgpu::{
@@ -32,11 +33,16 @@ pub struct GPURenderPassEncoder {
}
impl GPURenderPassEncoder {
- fn new_inherited(channel: WebGPU, render_pass: RenderPass, parent: &GPUCommandEncoder) -> Self {
+ fn new_inherited(
+ channel: WebGPU,
+ render_pass: RenderPass,
+ parent: &GPUCommandEncoder,
+ label: Option<USVString>,
+ ) -> Self {
Self {
channel,
reflector_: Reflector::new(),
- label: DomRefCell::new(None),
+ label: DomRefCell::new(label),
render_pass: DomRefCell::new(Some(render_pass)),
command_encoder: Dom::from_ref(parent),
}
@@ -47,12 +53,14 @@ impl GPURenderPassEncoder {
channel: WebGPU,
render_pass: RenderPass,
parent: &GPUCommandEncoder,
+ label: Option<USVString>,
) -> DomRoot<Self> {
reflect_dom_object(
Box::new(GPURenderPassEncoder::new_inherited(
channel,
render_pass,
parent,
+ label,
)),
global,
)
@@ -125,11 +133,17 @@ impl GPURenderPassEncoderMethods for GPURenderPassEncoder {
b: *d.b,
a: *d.a,
},
- GPUColor::DoubleSequence(s) => wgt::Color {
- r: *s[0],
- g: *s[1],
- b: *s[2],
- a: *s[3],
+ GPUColor::DoubleSequence(mut s) => {
+ if s.len() < 3 {
+ s.resize(3, Finite::wrap(0.0f64));
+ }
+ s.resize(4, Finite::wrap(1.0f64));
+ wgt::Color {
+ r: *s[0],
+ g: *s[1],
+ b: *s[2],
+ a: *s[3],
+ }
},
};
if let Some(render_pass) = self.render_pass.borrow_mut().as_mut() {
@@ -153,7 +167,7 @@ impl GPURenderPassEncoderMethods for GPURenderPassEncoder {
command_encoder_id: self.command_encoder.id().0,
render_pass,
})
- .unwrap();
+ .expect("Failed to send RunRenderPass");
self.command_encoder.set_state(
GPUCommandEncoderState::Open,
@@ -249,4 +263,19 @@ impl GPURenderPassEncoderMethods for GPURenderPassEncoder {
);
}
}
+
+ /// https://gpuweb.github.io/gpuweb/#dom-gpurenderpassencoder-executebundles
+ #[allow(unsafe_code)]
+ fn ExecuteBundles(&self, bundles: Vec<DomRoot<GPURenderBundle>>) {
+ let bundle_ids = bundles.iter().map(|b| b.id().0).collect::<Vec<_>>();
+ if let Some(render_pass) = self.render_pass.borrow_mut().as_mut() {
+ unsafe {
+ wgpu_render::wgpu_render_pass_execute_bundles(
+ render_pass,
+ bundle_ids.as_ptr(),
+ bundle_ids.len(),
+ )
+ };
+ }
+ }
}
diff --git a/components/script/dom/gpurenderpipeline.rs b/components/script/dom/gpurenderpipeline.rs
index 88e55848b91..bb618a248a9 100644
--- a/components/script/dom/gpurenderpipeline.rs
+++ b/components/script/dom/gpurenderpipeline.rs
@@ -21,10 +21,14 @@ pub struct GPURenderPipeline {
}
impl GPURenderPipeline {
- fn new_inherited(render_pipeline: WebGPURenderPipeline, device: WebGPUDevice) -> Self {
+ fn new_inherited(
+ render_pipeline: WebGPURenderPipeline,
+ device: WebGPUDevice,
+ label: Option<USVString>,
+ ) -> Self {
Self {
reflector_: Reflector::new(),
- label: DomRefCell::new(None),
+ label: DomRefCell::new(label),
render_pipeline,
device,
}
@@ -34,9 +38,14 @@ impl GPURenderPipeline {
global: &GlobalScope,
render_pipeline: WebGPURenderPipeline,
device: WebGPUDevice,
+ label: Option<USVString>,
) -> DomRoot<Self> {
reflect_dom_object(
- Box::new(GPURenderPipeline::new_inherited(render_pipeline, device)),
+ Box::new(GPURenderPipeline::new_inherited(
+ render_pipeline,
+ device,
+ label,
+ )),
global,
)
}
diff --git a/components/script/dom/gpusampler.rs b/components/script/dom/gpusampler.rs
index cba3ec3b018..23395ee058c 100644
--- a/components/script/dom/gpusampler.rs
+++ b/components/script/dom/gpusampler.rs
@@ -21,10 +21,15 @@ pub struct GPUSampler {
}
impl GPUSampler {
- fn new_inherited(device: WebGPUDevice, compare_enable: bool, sampler: WebGPUSampler) -> Self {
+ fn new_inherited(
+ device: WebGPUDevice,
+ compare_enable: bool,
+ sampler: WebGPUSampler,
+ label: Option<USVString>,
+ ) -> Self {
Self {
reflector_: Reflector::new(),
- label: DomRefCell::new(None),
+ label: DomRefCell::new(label),
device,
sampler,
compare_enable,
@@ -36,9 +41,15 @@ impl GPUSampler {
device: WebGPUDevice,
compare_enable: bool,
sampler: WebGPUSampler,
+ label: Option<USVString>,
) -> DomRoot<Self> {
reflect_dom_object(
- Box::new(GPUSampler::new_inherited(device, compare_enable, sampler)),
+ Box::new(GPUSampler::new_inherited(
+ device,
+ compare_enable,
+ sampler,
+ label,
+ )),
global,
)
}
diff --git a/components/script/dom/gpushadermodule.rs b/components/script/dom/gpushadermodule.rs
index 3c752e7fe4a..c4f20124ea8 100644
--- a/components/script/dom/gpushadermodule.rs
+++ b/components/script/dom/gpushadermodule.rs
@@ -19,17 +19,21 @@ pub struct GPUShaderModule {
}
impl GPUShaderModule {
- fn new_inherited(shader_module: WebGPUShaderModule) -> Self {
+ fn new_inherited(shader_module: WebGPUShaderModule, label: Option<USVString>) -> Self {
Self {
reflector_: Reflector::new(),
- label: DomRefCell::new(None),
+ label: DomRefCell::new(label),
shader_module,
}
}
- pub fn new(global: &GlobalScope, shader_module: WebGPUShaderModule) -> DomRoot<Self> {
+ pub fn new(
+ global: &GlobalScope,
+ shader_module: WebGPUShaderModule,
+ label: Option<USVString>,
+ ) -> DomRoot<Self> {
reflect_dom_object(
- Box::new(GPUShaderModule::new_inherited(shader_module)),
+ Box::new(GPUShaderModule::new_inherited(shader_module, label)),
global,
)
}
diff --git a/components/script/dom/gpuswapchain.rs b/components/script/dom/gpuswapchain.rs
index 5e50e7e57ab..1d50a00f40a 100644
--- a/components/script/dom/gpuswapchain.rs
+++ b/components/script/dom/gpuswapchain.rs
@@ -24,13 +24,18 @@ pub struct GPUSwapChain {
}
impl GPUSwapChain {
- fn new_inherited(channel: WebGPU, context: &GPUCanvasContext, texture: &GPUTexture) -> Self {
+ fn new_inherited(
+ channel: WebGPU,
+ context: &GPUCanvasContext,
+ texture: &GPUTexture,
+ label: Option<USVString>,
+ ) -> Self {
Self {
reflector_: Reflector::new(),
channel,
context: Dom::from_ref(context),
texture: Dom::from_ref(texture),
- label: DomRefCell::new(None),
+ label: DomRefCell::new(label),
}
}
@@ -39,9 +44,12 @@ impl GPUSwapChain {
channel: WebGPU,
context: &GPUCanvasContext,
texture: &GPUTexture,
+ label: Option<USVString>,
) -> DomRoot<Self> {
reflect_dom_object(
- Box::new(GPUSwapChain::new_inherited(channel, context, texture)),
+ Box::new(GPUSwapChain::new_inherited(
+ channel, context, texture, label,
+ )),
global,
)
}
diff --git a/components/script/dom/gputexture.rs b/components/script/dom/gputexture.rs
index 4977207942e..4a6256ee369 100644
--- a/components/script/dom/gputexture.rs
+++ b/components/script/dom/gputexture.rs
@@ -47,11 +47,12 @@ impl GPUTexture {
dimension: GPUTextureDimension,
format: GPUTextureFormat,
texture_usage: u32,
+ label: Option<USVString>,
) -> Self {
Self {
reflector_: Reflector::new(),
texture,
- label: DomRefCell::new(None),
+ label: DomRefCell::new(label),
device,
channel,
texture_size,
@@ -74,6 +75,7 @@ impl GPUTexture {
dimension: GPUTextureDimension,
format: GPUTextureFormat,
texture_usage: u32,
+ label: Option<USVString>,
) -> DomRoot<Self> {
reflect_dom_object(
Box::new(GPUTexture::new_inherited(
@@ -86,6 +88,7 @@ impl GPUTexture {
dimension,
format,
texture_usage,
+ label,
)),
global,
)
@@ -179,7 +182,12 @@ impl GPUTextureMethods for GPUTexture {
let texture_view = WebGPUTextureView(texture_view_id);
- GPUTextureView::new(&self.global(), texture_view, &self)
+ GPUTextureView::new(
+ &self.global(),
+ texture_view,
+ &self,
+ descriptor.parent.label.as_ref().cloned(),
+ )
}
/// https://gpuweb.github.io/gpuweb/#dom-gputexture-destroy
diff --git a/components/script/dom/gputextureview.rs b/components/script/dom/gputextureview.rs
index 208352f3ff7..af346d92250 100644
--- a/components/script/dom/gputextureview.rs
+++ b/components/script/dom/gputextureview.rs
@@ -21,11 +21,15 @@ pub struct GPUTextureView {
}
impl GPUTextureView {
- fn new_inherited(texture_view: WebGPUTextureView, texture: &GPUTexture) -> GPUTextureView {
+ fn new_inherited(
+ texture_view: WebGPUTextureView,
+ texture: &GPUTexture,
+ label: Option<USVString>,
+ ) -> GPUTextureView {
Self {
reflector_: Reflector::new(),
texture: Dom::from_ref(texture),
- label: DomRefCell::new(None),
+ label: DomRefCell::new(label),
texture_view,
}
}
@@ -34,9 +38,10 @@ impl GPUTextureView {
global: &GlobalScope,
texture_view: WebGPUTextureView,
texture: &GPUTexture,
+ label: Option<USVString>,
) -> DomRoot<GPUTextureView> {
reflect_dom_object(
- Box::new(GPUTextureView::new_inherited(texture_view, texture)),
+ Box::new(GPUTextureView::new_inherited(texture_view, texture, label)),
global,
)
}
diff --git a/components/script/dom/identityhub.rs b/components/script/dom/identityhub.rs
index 3862702561e..515e9f7e1b1 100644
--- a/components/script/dom/identityhub.rs
+++ b/components/script/dom/identityhub.rs
@@ -7,8 +7,8 @@ use webgpu::wgpu::{
hub::IdentityManager,
id::{
AdapterId, BindGroupId, BindGroupLayoutId, BufferId, CommandEncoderId, ComputePipelineId,
- DeviceId, PipelineLayoutId, RenderPipelineId, SamplerId, ShaderModuleId, TextureId,
- TextureViewId,
+ DeviceId, PipelineLayoutId, RenderBundleId, RenderPipelineId, SamplerId, ShaderModuleId,
+ TextureId, TextureViewId,
},
};
use webgpu::wgt::Backend;
@@ -28,6 +28,7 @@ pub struct IdentityHub {
texture_views: IdentityManager,
samplers: IdentityManager,
render_pipelines: IdentityManager,
+ render_bundles: IdentityManager,
}
impl IdentityHub {
@@ -46,6 +47,7 @@ impl IdentityHub {
texture_views: IdentityManager::default(),
samplers: IdentityManager::default(),
render_pipelines: IdentityManager::default(),
+ render_bundles: IdentityManager::default(),
}
}
}
@@ -215,4 +217,12 @@ impl Identities {
pub fn kill_texture_view_id(&mut self, id: TextureViewId) {
self.select(id.backend()).texture_views.free(id);
}
+
+ pub fn create_render_bundle_id(&mut self, backend: Backend) -> RenderBundleId {
+ self.select(backend).render_bundles.alloc(backend)
+ }
+
+ pub fn kill_render_bundle_id(&mut self, id: RenderBundleId) {
+ self.select(id.backend()).render_bundles.free(id);
+ }
}
diff --git a/components/script/dom/mod.rs b/components/script/dom/mod.rs
index 698cff979c9..30681be0ff2 100644
--- a/components/script/dom/mod.rs
+++ b/components/script/dom/mod.rs
@@ -338,6 +338,8 @@ pub mod gpumapmode;
pub mod gpuoutofmemoryerror;
pub mod gpupipelinelayout;
pub mod gpuqueue;
+pub mod gpurenderbundle;
+pub mod gpurenderbundleencoder;
pub mod gpurenderpassencoder;
pub mod gpurenderpipeline;
pub mod gpusampler;
diff --git a/components/script/dom/webidls/GPUDevice.webidl b/components/script/dom/webidls/GPUDevice.webidl
index 24ee59b54a9..4303b262201 100644
--- a/components/script/dom/webidls/GPUDevice.webidl
+++ b/components/script/dom/webidls/GPUDevice.webidl
@@ -3,7 +3,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
// https://gpuweb.github.io/gpuweb/#gpudevice
-[Exposed=(Window, DedicatedWorker)/*, Serializable */, Pref="dom.webgpu.enabled"]
+[Exposed=(Window, DedicatedWorker), /*Serializable,*/ Pref="dom.webgpu.enabled"]
interface GPUDevice : EventTarget {
[SameObject] readonly attribute GPUAdapter adapter;
readonly attribute object extensions;
@@ -24,7 +24,7 @@ interface GPUDevice : EventTarget {
GPURenderPipeline createRenderPipeline(GPURenderPipelineDescriptor descriptor);
GPUCommandEncoder createCommandEncoder(optional GPUCommandEncoderDescriptor descriptor = {});
- // GPURenderBundleEncoder createRenderBundleEncoder(GPURenderBundleEncoderDescriptor descriptor);
+ GPURenderBundleEncoder createRenderBundleEncoder(GPURenderBundleEncoderDescriptor descriptor);
};
GPUDevice includes GPUObjectBase;
diff --git a/components/script/dom/webidls/GPURenderBundle.webidl b/components/script/dom/webidls/GPURenderBundle.webidl
new file mode 100644
index 00000000000..52a8e5b0bc8
--- /dev/null
+++ b/components/script/dom/webidls/GPURenderBundle.webidl
@@ -0,0 +1,12 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
+
+// https://gpuweb.github.io/gpuweb/#gpurenderbundle
+[Exposed=(Window, DedicatedWorker), Pref="dom.webgpu.enabled"]
+interface GPURenderBundle {
+};
+GPURenderBundle includes GPUObjectBase;
+
+dictionary GPURenderBundleDescriptor : GPUObjectDescriptorBase {
+};
diff --git a/components/script/dom/webidls/GPURenderBundleEncoder.webidl b/components/script/dom/webidls/GPURenderBundleEncoder.webidl
new file mode 100644
index 00000000000..50676b431b9
--- /dev/null
+++ b/components/script/dom/webidls/GPURenderBundleEncoder.webidl
@@ -0,0 +1,18 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
+
+// https://gpuweb.github.io/gpuweb/#gpurenderbundleencoder
+[Exposed=(Window, DedicatedWorker), Pref="dom.webgpu.enabled"]
+interface GPURenderBundleEncoder {
+ GPURenderBundle finish(optional GPURenderBundleDescriptor descriptor = {});
+};
+GPURenderBundleEncoder includes GPUObjectBase;
+GPURenderBundleEncoder includes GPUProgrammablePassEncoder;
+GPURenderBundleEncoder includes GPURenderEncoderBase;
+
+dictionary GPURenderBundleEncoderDescriptor : GPUObjectDescriptorBase {
+ required sequence<GPUTextureFormat> colorFormats;
+ GPUTextureFormat depthStencilFormat;
+ GPUSize32 sampleCount = 1;
+};
diff --git a/components/script/dom/webidls/GPURenderPassEncoder.webidl b/components/script/dom/webidls/GPURenderPassEncoder.webidl
index 2aa6e7c5581..6261cf89453 100644
--- a/components/script/dom/webidls/GPURenderPassEncoder.webidl
+++ b/components/script/dom/webidls/GPURenderPassEncoder.webidl
@@ -16,9 +16,14 @@ interface GPURenderPassEncoder {
void setStencilReference(GPUStencilValue reference);
//void beginOcclusionQuery(GPUSize32 queryIndex);
- //void endOcclusionQuery(GPUSize32 queryIndex);
+ //void endOcclusionQuery();
- //void executeBundles(sequence<GPURenderBundle> bundles);
+ //void beginPipelineStatisticsQuery(GPUQuerySet querySet, GPUSize32 queryIndex);
+ //void endPipelineStatisticsQuery();
+
+ //void writeTimestamp(GPUQuerySet querySet, GPUSize32 queryIndex);
+
+ void executeBundles(sequence<GPURenderBundle> bundles);
void endPass();
};
GPURenderPassEncoder includes GPUObjectBase;
diff --git a/components/script/dom/webidls/GPURenderPipeline.webidl b/components/script/dom/webidls/GPURenderPipeline.webidl
index 951a480601a..a25890112fc 100644
--- a/components/script/dom/webidls/GPURenderPipeline.webidl
+++ b/components/script/dom/webidls/GPURenderPipeline.webidl
@@ -38,6 +38,8 @@ typedef [EnforceRange] long GPUDepthBias;
dictionary GPURasterizationStateDescriptor {
GPUFrontFace frontFace = "ccw";
GPUCullMode cullMode = "none";
+ // Enable depth clamping (requires "depth-clamping" extension)
+ boolean clampDepth = false;
GPUDepthBias depthBias = 0;
float depthBiasSlopeScale = 0;
diff --git a/components/script/script_thread.rs b/components/script/script_thread.rs
index b5ea3f619a6..1b7c137e9a2 100644
--- a/components/script/script_thread.rs
+++ b/components/script/script_thread.rs
@@ -2057,6 +2057,7 @@ impl ScriptThread {
WebGPUMsg::FreeCommandBuffer(id) => self.gpu_id_hub.lock().kill_command_buffer_id(id),
WebGPUMsg::FreeSampler(id) => self.gpu_id_hub.lock().kill_sampler_id(id),
WebGPUMsg::FreeShaderModule(id) => self.gpu_id_hub.lock().kill_shader_module_id(id),
+ WebGPUMsg::FreeRenderBundle(id) => self.gpu_id_hub.lock().kill_render_bundle_id(id),
WebGPUMsg::FreeRenderPipeline(id) => self.gpu_id_hub.lock().kill_render_pipeline_id(id),
WebGPUMsg::FreeTexture(id) => self.gpu_id_hub.lock().kill_texture_id(id),
WebGPUMsg::FreeTextureView(id) => self.gpu_id_hub.lock().kill_texture_view_id(id),