mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
Upgrade whole webgpu stack (#29795)
* Allow noidl files in script/dom/webidls * Upgrade wgpu to 0.16 and refresh whole webgpu implementation * Update WebGPU test expectations * misc * MutNullableDom -> DomRefCell<Option<Dom for GPUTexture * Direct use of GPUTextureDescriptor * Remove config from GPUCanvasContext * misc * finally blue color * gpubuffer "handle" error * GPU object have non-null label * gpu limits and info * use buffer_size * fix warnings * Cleanup * device destroy * fallback adapter * mach update-webgpu write webgpu commit hash in file * Mising deps in CI for webgpu tests * Updated expectations * Fixups * early reject * DomRefCell<Option<Dom -> MutNullableDom for GPUTexture
This commit is contained in:
parent
fed3491f23
commit
71e0372ac1
96 changed files with 15612 additions and 4023 deletions
|
@ -5,14 +5,10 @@
|
|||
use crate::dom::bindings::cell::DomRefCell;
|
||||
use crate::dom::bindings::codegen::Bindings::GPUBufferBinding::GPUSize64;
|
||||
use crate::dom::bindings::codegen::Bindings::GPUCommandEncoderBinding::{
|
||||
GPUBufferCopyView, GPUCommandBufferDescriptor, GPUCommandEncoderMethods,
|
||||
GPUComputePassDescriptor, GPUOrigin3D, GPURenderPassDescriptor, GPUStencilLoadValue,
|
||||
GPUStoreOp, GPUTextureCopyView, GPUTextureDataLayout,
|
||||
GPUCommandEncoderMethods, GPUComputePassDescriptor, GPUOrigin3D, GPURenderPassDescriptor,
|
||||
GPUStoreOp,
|
||||
};
|
||||
use crate::dom::bindings::codegen::Bindings::GPUTextureBinding::GPUExtent3D;
|
||||
use crate::dom::bindings::codegen::UnionTypes::{
|
||||
GPULoadOpOrDoubleSequenceOrGPUColorDict as GPUColorLoad, GPULoadOpOrFloat,
|
||||
};
|
||||
use crate::dom::bindings::num::Finite;
|
||||
use crate::dom::bindings::reflector::DomObject;
|
||||
use crate::dom::bindings::reflector::{reflect_dom_object, Reflector};
|
||||
|
@ -31,6 +27,14 @@ use std::collections::HashSet;
|
|||
use webgpu::wgpu::command as wgpu_com;
|
||||
use webgpu::{self, wgt, WebGPU, WebGPURequest};
|
||||
|
||||
use super::bindings::codegen::Bindings::GPUCommandBufferBinding::GPUCommandBufferDescriptor;
|
||||
use super::bindings::codegen::Bindings::GPUCommandEncoderBinding::{
|
||||
GPUImageCopyBuffer, GPUImageCopyTexture, GPUImageDataLayout, GPULoadOp,
|
||||
};
|
||||
use super::bindings::codegen::Bindings::GPUTextureViewBinding::GPUTextureAspect;
|
||||
use super::bindings::codegen::UnionTypes::DoubleSequenceOrGPUColorDict;
|
||||
|
||||
// TODO(sagudev): this is different now
|
||||
// https://gpuweb.github.io/gpuweb/#enumdef-encoder-state
|
||||
#[derive(MallocSizeOf, PartialEq)]
|
||||
pub enum GPUCommandEncoderState {
|
||||
|
@ -46,7 +50,7 @@ pub struct GPUCommandEncoder {
|
|||
#[ignore_malloc_size_of = "defined in webgpu"]
|
||||
#[no_trace]
|
||||
channel: WebGPU,
|
||||
label: DomRefCell<Option<USVString>>,
|
||||
label: DomRefCell<USVString>,
|
||||
#[no_trace]
|
||||
encoder: webgpu::WebGPUCommandEncoder,
|
||||
buffers: DomRefCell<HashSet<DomRoot<GPUBuffer>>>,
|
||||
|
@ -60,7 +64,7 @@ impl GPUCommandEncoder {
|
|||
channel: WebGPU,
|
||||
device: &GPUDevice,
|
||||
encoder: webgpu::WebGPUCommandEncoder,
|
||||
label: Option<USVString>,
|
||||
label: USVString,
|
||||
) -> Self {
|
||||
Self {
|
||||
channel,
|
||||
|
@ -79,7 +83,7 @@ impl GPUCommandEncoder {
|
|||
channel: WebGPU,
|
||||
device: &GPUDevice,
|
||||
encoder: webgpu::WebGPUCommandEncoder,
|
||||
label: Option<USVString>,
|
||||
label: USVString,
|
||||
) -> DomRoot<Self> {
|
||||
reflect_dom_object(
|
||||
Box::new(GPUCommandEncoder::new_inherited(
|
||||
|
@ -107,12 +111,12 @@ impl GPUCommandEncoder {
|
|||
|
||||
impl GPUCommandEncoderMethods for GPUCommandEncoder {
|
||||
/// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label
|
||||
fn GetLabel(&self) -> Option<USVString> {
|
||||
fn Label(&self) -> USVString {
|
||||
self.label.borrow().clone()
|
||||
}
|
||||
|
||||
/// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label
|
||||
fn SetLabel(&self, value: Option<USVString>) {
|
||||
fn SetLabel(&self, value: USVString) {
|
||||
*self.label.borrow_mut() = value;
|
||||
}
|
||||
|
||||
|
@ -129,7 +133,16 @@ impl GPUCommandEncoderMethods for GPUCommandEncoder {
|
|||
let compute_pass = if !self.valid.get() {
|
||||
None
|
||||
} else {
|
||||
Some(wgpu_com::ComputePass::new(self.encoder.0))
|
||||
Some(wgpu_com::ComputePass::new(
|
||||
self.encoder.0,
|
||||
&wgpu_com::ComputePassDescriptor {
|
||||
label: descriptor
|
||||
.parent
|
||||
.label
|
||||
.as_ref()
|
||||
.map(|l| Cow::Borrowed(&**l)),
|
||||
},
|
||||
))
|
||||
};
|
||||
|
||||
GPUComputePassEncoder::new(
|
||||
|
@ -137,7 +150,7 @@ impl GPUCommandEncoderMethods for GPUCommandEncoder {
|
|||
self.channel.clone(),
|
||||
&self,
|
||||
compute_pass,
|
||||
descriptor.parent.label.as_ref().cloned(),
|
||||
descriptor.parent.label.clone().unwrap_or_default(),
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -155,38 +168,20 @@ impl GPUCommandEncoderMethods for GPUCommandEncoder {
|
|||
None
|
||||
} else {
|
||||
let depth_stencil = descriptor.depthStencilAttachment.as_ref().map(|depth| {
|
||||
let (depth_load_op, clear_depth) = match depth.depthLoadValue {
|
||||
GPULoadOpOrFloat::GPULoadOp(_) => (wgpu_com::LoadOp::Load, 0.0f32),
|
||||
GPULoadOpOrFloat::Float(f) => (wgpu_com::LoadOp::Clear, *f),
|
||||
};
|
||||
let (stencil_load_op, clear_stencil) = match depth.stencilLoadValue {
|
||||
GPUStencilLoadValue::GPULoadOp(_) => (wgpu_com::LoadOp::Load, 0u32),
|
||||
GPUStencilLoadValue::RangeEnforcedUnsignedLong(l) => {
|
||||
(wgpu_com::LoadOp::Clear, l)
|
||||
wgpu_com::RenderPassDepthStencilAttachment {
|
||||
depth: wgpu_com::PassChannel {
|
||||
load_op: convert_load_op(depth.depthLoadOp),
|
||||
store_op: convert_store_op(depth.depthStoreOp),
|
||||
clear_value: *depth.depthClearValue.unwrap_or_default(),
|
||||
read_only: depth.depthReadOnly,
|
||||
},
|
||||
};
|
||||
let depth_channel = wgpu_com::PassChannel {
|
||||
load_op: depth_load_op,
|
||||
store_op: match depth.depthStoreOp {
|
||||
GPUStoreOp::Store => wgpu_com::StoreOp::Store,
|
||||
GPUStoreOp::Clear => wgpu_com::StoreOp::Clear,
|
||||
stencil: wgpu_com::PassChannel {
|
||||
load_op: convert_load_op(depth.stencilLoadOp),
|
||||
store_op: convert_store_op(depth.stencilStoreOp),
|
||||
clear_value: depth.stencilClearValue,
|
||||
read_only: depth.stencilReadOnly,
|
||||
},
|
||||
clear_value: clear_depth,
|
||||
read_only: depth.depthReadOnly,
|
||||
};
|
||||
let stencil_channel = wgpu_com::PassChannel {
|
||||
load_op: stencil_load_op,
|
||||
store_op: match depth.stencilStoreOp {
|
||||
GPUStoreOp::Store => wgpu_com::StoreOp::Store,
|
||||
GPUStoreOp::Clear => wgpu_com::StoreOp::Clear,
|
||||
},
|
||||
clear_value: clear_stencil,
|
||||
read_only: depth.stencilReadOnly,
|
||||
};
|
||||
wgpu_com::DepthStencilAttachmentDescriptor {
|
||||
attachment: depth.attachment.id().0,
|
||||
depth: depth_channel,
|
||||
stencil: stencil_channel,
|
||||
view: depth.view.id().0,
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -196,56 +191,54 @@ impl GPUCommandEncoderMethods for GPUCommandEncoder {
|
|||
.colorAttachments
|
||||
.iter()
|
||||
.map(|color| {
|
||||
let (load_op, clear_value) = match color.loadValue {
|
||||
GPUColorLoad::GPULoadOp(_) => {
|
||||
(wgpu_com::LoadOp::Load, wgt::Color::TRANSPARENT)
|
||||
},
|
||||
GPUColorLoad::DoubleSequence(ref s) => {
|
||||
let mut w = s.clone();
|
||||
if w.len() < 3 {
|
||||
w.resize(3, Finite::wrap(0.0f64));
|
||||
}
|
||||
w.resize(4, Finite::wrap(1.0f64));
|
||||
(
|
||||
wgpu_com::LoadOp::Clear,
|
||||
wgt::Color {
|
||||
r: *w[0],
|
||||
g: *w[1],
|
||||
b: *w[2],
|
||||
a: *w[3],
|
||||
},
|
||||
)
|
||||
},
|
||||
GPUColorLoad::GPUColorDict(ref d) => (
|
||||
wgpu_com::LoadOp::Clear,
|
||||
wgt::Color {
|
||||
r: *d.r,
|
||||
g: *d.g,
|
||||
b: *d.b,
|
||||
a: *d.a,
|
||||
},
|
||||
),
|
||||
};
|
||||
let channel = wgpu_com::PassChannel {
|
||||
load_op,
|
||||
store_op: match color.storeOp {
|
||||
GPUStoreOp::Store => wgpu_com::StoreOp::Store,
|
||||
GPUStoreOp::Clear => wgpu_com::StoreOp::Clear,
|
||||
load_op: convert_load_op(Some(color.loadOp)),
|
||||
store_op: convert_store_op(Some(color.storeOp)),
|
||||
clear_value: if let Some(clear_val) = &color.clearValue {
|
||||
match clear_val {
|
||||
DoubleSequenceOrGPUColorDict::DoubleSequence(s) => {
|
||||
let mut w = s.clone();
|
||||
if w.len() < 3 {
|
||||
w.resize(3, Finite::wrap(0.0f64));
|
||||
}
|
||||
w.resize(4, Finite::wrap(1.0f64));
|
||||
wgt::Color {
|
||||
r: *w[0],
|
||||
g: *w[1],
|
||||
b: *w[2],
|
||||
a: *w[3],
|
||||
}
|
||||
},
|
||||
DoubleSequenceOrGPUColorDict::GPUColorDict(d) => {
|
||||
wgt::Color {
|
||||
r: *d.r,
|
||||
g: *d.g,
|
||||
b: *d.b,
|
||||
a: *d.a,
|
||||
}
|
||||
},
|
||||
}
|
||||
} else {
|
||||
wgt::Color::TRANSPARENT
|
||||
},
|
||||
clear_value,
|
||||
read_only: false,
|
||||
};
|
||||
wgpu_com::ColorAttachmentDescriptor {
|
||||
attachment: color.attachment.id().0,
|
||||
Some(wgpu_com::RenderPassColorAttachment {
|
||||
resolve_target: color.resolveTarget.as_ref().map(|t| t.id().0),
|
||||
channel,
|
||||
}
|
||||
view: color.view.id().0,
|
||||
})
|
||||
})
|
||||
.collect::<Vec<_>>(),
|
||||
),
|
||||
depth_stencil_attachment: depth_stencil.as_ref(),
|
||||
label: descriptor
|
||||
.parent
|
||||
.label
|
||||
.as_ref()
|
||||
.map(|l| Cow::Borrowed(&**l)),
|
||||
};
|
||||
Some(wgpu_com::RenderPass::new(self.encoder.0, desc))
|
||||
Some(wgpu_com::RenderPass::new(self.encoder.0, &desc))
|
||||
};
|
||||
|
||||
GPURenderPassEncoder::new(
|
||||
|
@ -253,7 +246,7 @@ impl GPUCommandEncoderMethods for GPUCommandEncoder {
|
|||
self.channel.clone(),
|
||||
render_pass,
|
||||
&self,
|
||||
descriptor.parent.label.as_ref().cloned(),
|
||||
descriptor.parent.label.clone().unwrap_or_default(),
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -294,8 +287,8 @@ impl GPUCommandEncoderMethods for GPUCommandEncoder {
|
|||
/// https://gpuweb.github.io/gpuweb/#dom-gpucommandencoder-copybuffertotexture
|
||||
fn CopyBufferToTexture(
|
||||
&self,
|
||||
source: &GPUBufferCopyView,
|
||||
destination: &GPUTextureCopyView,
|
||||
source: &GPUImageCopyBuffer,
|
||||
destination: &GPUImageCopyTexture,
|
||||
copy_size: GPUExtent3D,
|
||||
) {
|
||||
if !(*self.state.borrow() == GPUCommandEncoderState::Open) {
|
||||
|
@ -313,8 +306,8 @@ impl GPUCommandEncoderMethods for GPUCommandEncoder {
|
|||
None,
|
||||
WebGPURequest::CopyBufferToTexture {
|
||||
command_encoder_id: self.encoder.0,
|
||||
source: convert_buffer_cv(source),
|
||||
destination: convert_texture_cv(destination),
|
||||
source: convert_ic_buffer(source),
|
||||
destination: convert_ic_texture(destination),
|
||||
copy_size: convert_texture_size_to_wgt(&convert_texture_size_to_dict(
|
||||
©_size,
|
||||
)),
|
||||
|
@ -323,11 +316,11 @@ impl GPUCommandEncoderMethods for GPUCommandEncoder {
|
|||
.expect("Failed to send CopyBufferToTexture");
|
||||
}
|
||||
|
||||
/// https://gpuweb.github.io/gpuweb/#GPUCommandEncoder-copyTextureToBuffer
|
||||
/// https://gpuweb.github.io/gpuweb/#dom-gpucommandencoder-copybuffertotexture
|
||||
fn CopyTextureToBuffer(
|
||||
&self,
|
||||
source: &GPUTextureCopyView,
|
||||
destination: &GPUBufferCopyView,
|
||||
source: &GPUImageCopyTexture,
|
||||
destination: &GPUImageCopyBuffer,
|
||||
copy_size: GPUExtent3D,
|
||||
) {
|
||||
if !(*self.state.borrow() == GPUCommandEncoderState::Open) {
|
||||
|
@ -345,8 +338,8 @@ impl GPUCommandEncoderMethods for GPUCommandEncoder {
|
|||
None,
|
||||
WebGPURequest::CopyTextureToBuffer {
|
||||
command_encoder_id: self.encoder.0,
|
||||
source: convert_texture_cv(source),
|
||||
destination: convert_buffer_cv(destination),
|
||||
source: convert_ic_texture(source),
|
||||
destination: convert_ic_buffer(destination),
|
||||
copy_size: convert_texture_size_to_wgt(&convert_texture_size_to_dict(
|
||||
©_size,
|
||||
)),
|
||||
|
@ -358,8 +351,8 @@ impl GPUCommandEncoderMethods for GPUCommandEncoder {
|
|||
/// https://gpuweb.github.io/gpuweb/#GPUCommandEncoder-copyTextureToTexture
|
||||
fn CopyTextureToTexture(
|
||||
&self,
|
||||
source: &GPUTextureCopyView,
|
||||
destination: &GPUTextureCopyView,
|
||||
source: &GPUImageCopyTexture,
|
||||
destination: &GPUImageCopyTexture,
|
||||
copy_size: GPUExtent3D,
|
||||
) {
|
||||
if !(*self.state.borrow() == GPUCommandEncoderState::Open) {
|
||||
|
@ -373,8 +366,8 @@ impl GPUCommandEncoderMethods for GPUCommandEncoder {
|
|||
None,
|
||||
WebGPURequest::CopyTextureToTexture {
|
||||
command_encoder_id: self.encoder.0,
|
||||
source: convert_texture_cv(source),
|
||||
destination: convert_texture_cv(destination),
|
||||
source: convert_ic_texture(source),
|
||||
destination: convert_ic_texture(destination),
|
||||
copy_size: convert_texture_size_to_wgt(&convert_texture_size_to_dict(
|
||||
©_size,
|
||||
)),
|
||||
|
@ -406,24 +399,40 @@ impl GPUCommandEncoderMethods for GPUCommandEncoder {
|
|||
self.channel.clone(),
|
||||
buffer,
|
||||
self.buffers.borrow_mut().drain().collect(),
|
||||
descriptor.parent.label.as_ref().cloned(),
|
||||
descriptor.parent.label.clone().unwrap_or_default(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fn convert_buffer_cv(buffer_cv: &GPUBufferCopyView) -> wgpu_com::BufferCopyView {
|
||||
wgpu_com::BufferCopyView {
|
||||
buffer: buffer_cv.buffer.id().0,
|
||||
layout: convert_texture_data_layout(&buffer_cv.parent),
|
||||
fn convert_load_op(op: Option<GPULoadOp>) -> wgpu_com::LoadOp {
|
||||
match op {
|
||||
Some(GPULoadOp::Load) => wgpu_com::LoadOp::Load,
|
||||
Some(GPULoadOp::Clear) => wgpu_com::LoadOp::Clear,
|
||||
None => wgpu_com::LoadOp::Clear,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn convert_texture_cv(texture_cv: &GPUTextureCopyView) -> wgpu_com::TextureCopyView {
|
||||
wgpu_com::TextureCopyView {
|
||||
texture: texture_cv.texture.id().0,
|
||||
mip_level: texture_cv.mipLevel,
|
||||
origin: match texture_cv.origin {
|
||||
GPUOrigin3D::RangeEnforcedUnsignedLongSequence(ref v) => {
|
||||
fn convert_store_op(op: Option<GPUStoreOp>) -> wgpu_com::StoreOp {
|
||||
match op {
|
||||
Some(GPUStoreOp::Store) => wgpu_com::StoreOp::Store,
|
||||
Some(GPUStoreOp::Discard) => wgpu_com::StoreOp::Discard,
|
||||
None => wgpu_com::StoreOp::Discard,
|
||||
}
|
||||
}
|
||||
|
||||
fn convert_ic_buffer(ic_buffer: &GPUImageCopyBuffer) -> wgpu_com::ImageCopyBuffer {
|
||||
wgpu_com::ImageCopyBuffer {
|
||||
buffer: ic_buffer.buffer.id().0,
|
||||
layout: convert_image_data_layout(&ic_buffer.parent),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn convert_ic_texture(ic_texture: &GPUImageCopyTexture) -> wgpu_com::ImageCopyTexture {
|
||||
wgpu_com::ImageCopyTexture {
|
||||
texture: ic_texture.texture.id().0,
|
||||
mip_level: ic_texture.mipLevel,
|
||||
origin: match ic_texture.origin {
|
||||
Some(GPUOrigin3D::RangeEnforcedUnsignedLongSequence(ref v)) => {
|
||||
let mut w = v.clone();
|
||||
w.resize(3, 0);
|
||||
wgt::Origin3d {
|
||||
|
@ -432,17 +441,23 @@ pub fn convert_texture_cv(texture_cv: &GPUTextureCopyView) -> wgpu_com::TextureC
|
|||
z: w[2],
|
||||
}
|
||||
},
|
||||
GPUOrigin3D::GPUOrigin3DDict(ref d) => wgt::Origin3d {
|
||||
Some(GPUOrigin3D::GPUOrigin3DDict(ref d)) => wgt::Origin3d {
|
||||
x: d.x,
|
||||
y: d.y,
|
||||
z: d.z,
|
||||
},
|
||||
None => wgt::Origin3d::default(),
|
||||
},
|
||||
aspect: match ic_texture.aspect {
|
||||
GPUTextureAspect::All => wgt::TextureAspect::All,
|
||||
GPUTextureAspect::Stencil_only => wgt::TextureAspect::StencilOnly,
|
||||
GPUTextureAspect::Depth_only => wgt::TextureAspect::DepthOnly,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
pub fn convert_texture_data_layout(data_layout: &GPUTextureDataLayout) -> wgt::TextureDataLayout {
|
||||
wgt::TextureDataLayout {
|
||||
pub fn convert_image_data_layout(data_layout: &GPUImageDataLayout) -> wgt::ImageDataLayout {
|
||||
wgt::ImageDataLayout {
|
||||
offset: data_layout.offset as wgt::BufferAddress,
|
||||
bytes_per_row: data_layout.bytesPerRow,
|
||||
rows_per_image: data_layout.rowsPerImage,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue