Skip to content

Commit

Permalink
Auto merge of #27389 - kunalmohan:update-wgpu, r=kvark
Browse files Browse the repository at this point in the history
Implement GPURenderBundles

<!-- Please describe your changes on the following line: -->
1. Implement `GPURenderBundleEncoder` and `GPURenderBundle`.
2. Update wgpu to use serializable descriptors.
3. Set user-defined labels on object creation.

r?@kvark

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors

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

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
  • Loading branch information
bors-servo committed Jul 24, 2020
2 parents 49870f9 + aff22db commit ebec798
Show file tree
Hide file tree
Showing 31 changed files with 897 additions and 441 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

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

8 changes: 5 additions & 3 deletions components/script/dom/bindings/trace.rs
Expand Up @@ -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};
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions components/script/dom/gpuadapter.rs
Expand Up @@ -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()
{
Expand All @@ -119,6 +120,7 @@ impl AsyncWGPUListener for GPUAdapter {
device_id,
queue_id,
_descriptor,
label,
} => {
let device = GPUDevice::new(
&self.global(),
Expand All @@ -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);
Expand Down
8 changes: 6 additions & 2 deletions components/script/dom/gpubindgroup.rs
Expand Up @@ -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),
Expand All @@ -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,
)
}
Expand Down
12 changes: 8 additions & 4 deletions components/script/dom/gpubindgrouplayout.rs
Expand Up @@ -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,
)
}
Expand Down
6 changes: 4 additions & 2 deletions components/script/dom/gpubuffer.rs
Expand Up @@ -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,
Expand All @@ -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,
)
Expand Down
8 changes: 7 additions & 1 deletion components/script/dom/gpucanvascontext.rs
Expand Up @@ -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
}
Expand Down
5 changes: 4 additions & 1 deletion components/script/dom/gpucommandbuffer.rs
Expand Up @@ -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()),
}
Expand All @@ -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,
)
Expand Down

0 comments on commit ebec798

Please sign in to comment.