aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/webgpu
diff options
context:
space:
mode:
Diffstat (limited to 'components/script/dom/webgpu')
-rw-r--r--components/script/dom/webgpu/gpubindgroup.rs5
-rw-r--r--components/script/dom/webgpu/gpubindgrouplayout.rs3
-rw-r--r--components/script/dom/webgpu/gpubuffer.rs3
-rw-r--r--components/script/dom/webgpu/gpucanvascontext.rs3
-rw-r--r--components/script/dom/webgpu/gpucommandencoder.rs29
-rw-r--r--components/script/dom/webgpu/gpucomputepipeline.rs5
-rw-r--r--components/script/dom/webgpu/gpuconvert.rs182
-rw-r--r--components/script/dom/webgpu/gpudevice.rs35
-rw-r--r--components/script/dom/webgpu/gpuerror.rs7
-rw-r--r--components/script/dom/webgpu/gpupipelinelayout.rs3
-rw-r--r--components/script/dom/webgpu/gpuqueue.rs7
-rw-r--r--components/script/dom/webgpu/gpurenderbundleencoder.rs5
-rw-r--r--components/script/dom/webgpu/gpurenderpassencoder.rs3
-rw-r--r--components/script/dom/webgpu/gpusampler.rs17
-rw-r--r--components/script/dom/webgpu/gputexture.rs5
15 files changed, 163 insertions, 149 deletions
diff --git a/components/script/dom/webgpu/gpubindgroup.rs b/components/script/dom/webgpu/gpubindgroup.rs
index b734684b92d..bb698210c93 100644
--- a/components/script/dom/webgpu/gpubindgroup.rs
+++ b/components/script/dom/webgpu/gpubindgroup.rs
@@ -8,6 +8,7 @@ use dom_struct::dom_struct;
use webgpu::wgc::binding_model::BindGroupDescriptor;
use webgpu::{WebGPU, WebGPUBindGroup, WebGPUDevice, WebGPURequest};
+use crate::conversions::Convert;
use crate::dom::bindings::cell::DomRefCell;
use crate::dom::bindings::codegen::Bindings::WebGPUBinding::{
GPUBindGroupDescriptor, GPUBindGroupMethods,
@@ -81,11 +82,11 @@ impl GPUBindGroup {
let entries = descriptor
.entries
.iter()
- .map(|bind| bind.into())
+ .map(|bind| bind.convert())
.collect::<Vec<_>>();
let desc = BindGroupDescriptor {
- label: (&descriptor.parent).into(),
+ label: (&descriptor.parent).convert(),
layout: descriptor.layout.id().0,
entries: Cow::Owned(entries),
};
diff --git a/components/script/dom/webgpu/gpubindgrouplayout.rs b/components/script/dom/webgpu/gpubindgrouplayout.rs
index bdfdcab1e9e..470b24c3192 100644
--- a/components/script/dom/webgpu/gpubindgrouplayout.rs
+++ b/components/script/dom/webgpu/gpubindgrouplayout.rs
@@ -8,6 +8,7 @@ use dom_struct::dom_struct;
use webgpu::wgc::binding_model::BindGroupLayoutDescriptor;
use webgpu::{WebGPU, WebGPUBindGroupLayout, WebGPURequest};
+use crate::conversions::Convert;
use crate::dom::bindings::cell::DomRefCell;
use crate::dom::bindings::codegen::Bindings::WebGPUBinding::{
GPUBindGroupLayoutDescriptor, GPUBindGroupLayoutMethods,
@@ -80,7 +81,7 @@ impl GPUBindGroupLayout {
let desc = match entries {
Ok(entries) => Some(BindGroupLayoutDescriptor {
- label: (&descriptor.parent).into(),
+ label: (&descriptor.parent).convert(),
entries: Cow::Owned(entries),
}),
Err(error) => {
diff --git a/components/script/dom/webgpu/gpubuffer.rs b/components/script/dom/webgpu/gpubuffer.rs
index 6a47b14331f..2a546a5e849 100644
--- a/components/script/dom/webgpu/gpubuffer.rs
+++ b/components/script/dom/webgpu/gpubuffer.rs
@@ -12,6 +12,7 @@ use js::typedarray::ArrayBuffer;
use webgpu::wgc::device::HostMap;
use webgpu::{wgt, Mapping, WebGPU, WebGPUBuffer, WebGPURequest, WebGPUResponse};
+use crate::conversions::Convert;
use crate::dom::bindings::buffer_source::DataBlock;
use crate::dom::bindings::cell::DomRefCell;
use crate::dom::bindings::codegen::Bindings::WebGPUBinding::{
@@ -136,7 +137,7 @@ impl GPUBuffer {
descriptor: &GPUBufferDescriptor,
) -> Fallible<DomRoot<GPUBuffer>> {
let desc = wgt::BufferDescriptor {
- label: (&descriptor.parent).into(),
+ label: (&descriptor.parent).convert(),
size: descriptor.size as wgt::BufferAddress,
usage: wgt::BufferUsages::from_bits_retain(descriptor.usage),
mapped_at_creation: descriptor.mappedAtCreation,
diff --git a/components/script/dom/webgpu/gpucanvascontext.rs b/components/script/dom/webgpu/gpucanvascontext.rs
index 06c69190a09..3fb906e2581 100644
--- a/components/script/dom/webgpu/gpucanvascontext.rs
+++ b/components/script/dom/webgpu/gpucanvascontext.rs
@@ -20,6 +20,7 @@ use webrender_api::ImageKey;
use super::gpuconvert::convert_texture_descriptor;
use super::gputexture::GPUTexture;
+use crate::conversions::Convert;
use crate::dom::bindings::codegen::Bindings::GPUCanvasContextBinding::GPUCanvasContextMethods;
use crate::dom::bindings::codegen::Bindings::WebGPUBinding::GPUTexture_Binding::GPUTextureMethods;
use crate::dom::bindings::codegen::Bindings::WebGPUBinding::{
@@ -196,7 +197,7 @@ impl GPUCanvasContext {
drawing_buffer.config = Some(ContextConfiguration {
device_id: configuration.device.id().0,
queue_id: configuration.device.queue_id().0,
- format: configuration.format.into(),
+ format: configuration.format.convert(),
is_opaque: matches!(configuration.alphaMode, GPUCanvasAlphaMode::Opaque),
});
} else {
diff --git a/components/script/dom/webgpu/gpucommandencoder.rs b/components/script/dom/webgpu/gpucommandencoder.rs
index 8c72b12f6b7..db92794eaf2 100644
--- a/components/script/dom/webgpu/gpucommandencoder.rs
+++ b/components/script/dom/webgpu/gpucommandencoder.rs
@@ -9,6 +9,7 @@ use webgpu::{
WebGPURenderPass, WebGPURequest,
};
+use crate::conversions::{Convert, TryConvert};
use crate::dom::bindings::cell::DomRefCell;
use crate::dom::bindings::codegen::Bindings::WebGPUBinding::{
GPUCommandBufferDescriptor, GPUCommandEncoderDescriptor, GPUCommandEncoderMethods,
@@ -93,7 +94,7 @@ impl GPUCommandEncoder {
device_id: device.id().0,
command_encoder_id,
desc: wgt::CommandEncoderDescriptor {
- label: (&descriptor.parent).into(),
+ label: (&descriptor.parent).convert(),
},
})
.expect("Failed to create WebGPU command encoder");
@@ -131,7 +132,7 @@ impl GPUCommandEncoderMethods<crate::DomTypeHolder> for GPUCommandEncoder {
if let Err(e) = self.channel.0.send(WebGPURequest::BeginComputePass {
command_encoder_id: self.id().0,
compute_pass_id,
- label: (&descriptor.parent).into(),
+ label: (&descriptor.parent).convert(),
device_id: self.device.id().0,
}) {
warn!("Failed to send WebGPURequest::BeginComputePass {e:?}");
@@ -179,7 +180,7 @@ impl GPUCommandEncoderMethods<crate::DomTypeHolder> for GPUCommandEncoder {
clear_value: color
.clearValue
.as_ref()
- .map(|color| (color).try_into())
+ .map(|color| (color).try_convert())
.transpose()?
.unwrap_or_default(),
read_only: false,
@@ -196,7 +197,7 @@ impl GPUCommandEncoderMethods<crate::DomTypeHolder> for GPUCommandEncoder {
if let Err(e) = self.channel.0.send(WebGPURequest::BeginRenderPass {
command_encoder_id: self.id().0,
render_pass_id,
- label: (&descriptor.parent).into(),
+ label: (&descriptor.parent).convert(),
depth_stencil_attachment,
color_attachments,
device_id: self.device.id().0,
@@ -246,9 +247,9 @@ impl GPUCommandEncoderMethods<crate::DomTypeHolder> for GPUCommandEncoder {
.0
.send(WebGPURequest::CopyBufferToTexture {
command_encoder_id: self.encoder.0,
- source: source.into(),
- destination: destination.try_into()?,
- copy_size: (&copy_size).try_into()?,
+ source: source.convert(),
+ destination: destination.try_convert()?,
+ copy_size: (&copy_size).try_convert()?,
})
.expect("Failed to send CopyBufferToTexture");
@@ -266,9 +267,9 @@ impl GPUCommandEncoderMethods<crate::DomTypeHolder> for GPUCommandEncoder {
.0
.send(WebGPURequest::CopyTextureToBuffer {
command_encoder_id: self.encoder.0,
- source: source.try_into()?,
- destination: destination.into(),
- copy_size: (&copy_size).try_into()?,
+ source: source.try_convert()?,
+ destination: destination.convert(),
+ copy_size: (&copy_size).try_convert()?,
})
.expect("Failed to send CopyTextureToBuffer");
@@ -286,9 +287,9 @@ impl GPUCommandEncoderMethods<crate::DomTypeHolder> for GPUCommandEncoder {
.0
.send(WebGPURequest::CopyTextureToTexture {
command_encoder_id: self.encoder.0,
- source: source.try_into()?,
- destination: destination.try_into()?,
- copy_size: (&copy_size).try_into()?,
+ source: source.try_convert()?,
+ destination: destination.try_convert()?,
+ copy_size: (&copy_size).try_convert()?,
})
.expect("Failed to send CopyTextureToTexture");
@@ -303,7 +304,7 @@ impl GPUCommandEncoderMethods<crate::DomTypeHolder> for GPUCommandEncoder {
command_encoder_id: self.encoder.0,
device_id: self.device.id().0,
desc: wgt::CommandBufferDescriptor {
- label: (&descriptor.parent).into(),
+ label: (&descriptor.parent).convert(),
},
})
.expect("Failed to send Finish");
diff --git a/components/script/dom/webgpu/gpucomputepipeline.rs b/components/script/dom/webgpu/gpucomputepipeline.rs
index ace43db11b4..a5d0997e3a3 100644
--- a/components/script/dom/webgpu/gpucomputepipeline.rs
+++ b/components/script/dom/webgpu/gpucomputepipeline.rs
@@ -7,6 +7,7 @@ use ipc_channel::ipc::IpcSender;
use webgpu::wgc::pipeline::ComputePipelineDescriptor;
use webgpu::{WebGPU, WebGPUBindGroupLayout, WebGPUComputePipeline, WebGPURequest, WebGPUResponse};
+use crate::conversions::Convert;
use crate::dom::bindings::cell::DomRefCell;
use crate::dom::bindings::codegen::Bindings::WebGPUBinding::{
GPUComputePipelineDescriptor, GPUComputePipelineMethods,
@@ -79,9 +80,9 @@ impl GPUComputePipeline {
let pipeline_layout = device.get_pipeline_layout_data(&descriptor.parent.layout);
let desc = ComputePipelineDescriptor {
- label: (&descriptor.parent.parent).into(),
+ label: (&descriptor.parent.parent).convert(),
layout: pipeline_layout.explicit(),
- stage: (&descriptor.compute).into(),
+ stage: (&descriptor.compute).convert(),
cache: None,
};
diff --git a/components/script/dom/webgpu/gpuconvert.rs b/components/script/dom/webgpu/gpuconvert.rs
index db2390a03b0..bcb83ee80b5 100644
--- a/components/script/dom/webgpu/gpuconvert.rs
+++ b/components/script/dom/webgpu/gpuconvert.rs
@@ -11,6 +11,7 @@ use webgpu::wgc::pipeline::ProgrammableStageDescriptor;
use webgpu::wgc::resource::TextureDescriptor;
use webgpu::wgt::{self, AstcBlock, AstcChannel};
+use crate::conversions::{Convert, TryConvert};
use crate::dom::bindings::codegen::Bindings::WebGPUBinding::{
GPUAddressMode, GPUBindGroupEntry, GPUBindGroupLayoutEntry, GPUBindingResource,
GPUBlendComponent, GPUBlendFactor, GPUBlendOperation, GPUBufferBindingType, GPUColor,
@@ -24,9 +25,9 @@ use crate::dom::bindings::codegen::Bindings::WebGPUBinding::{
use crate::dom::bindings::error::{Error, Fallible};
use crate::dom::types::GPUDevice;
-impl From<GPUTextureFormat> for wgt::TextureFormat {
- fn from(format: GPUTextureFormat) -> Self {
- match format {
+impl Convert<wgt::TextureFormat> for GPUTextureFormat {
+ fn convert(self) -> wgt::TextureFormat {
+ match self {
GPUTextureFormat::R8unorm => wgt::TextureFormat::R8Unorm,
GPUTextureFormat::R8snorm => wgt::TextureFormat::R8Snorm,
GPUTextureFormat::R8uint => wgt::TextureFormat::R8Uint,
@@ -210,11 +211,11 @@ impl From<GPUTextureFormat> for wgt::TextureFormat {
}
}
-impl TryFrom<&GPUExtent3D> for wgt::Extent3d {
+impl TryConvert<wgt::Extent3d> for &GPUExtent3D {
type Error = Error;
- fn try_from(size: &GPUExtent3D) -> Result<Self, Self::Error> {
- match *size {
+ fn try_convert(self) -> Result<wgt::Extent3d, Self::Error> {
+ match *self {
GPUExtent3D::GPUExtent3DDict(ref dict) => Ok(wgt::Extent3d {
width: dict.width,
height: dict.height,
@@ -238,19 +239,19 @@ impl TryFrom<&GPUExtent3D> for wgt::Extent3d {
}
}
-impl From<&GPUImageDataLayout> for wgt::ImageDataLayout {
- fn from(data_layout: &GPUImageDataLayout) -> Self {
+impl Convert<wgt::ImageDataLayout> for &GPUImageDataLayout {
+ fn convert(self) -> wgt::ImageDataLayout {
wgt::ImageDataLayout {
- offset: data_layout.offset as wgt::BufferAddress,
- bytes_per_row: data_layout.bytesPerRow,
- rows_per_image: data_layout.rowsPerImage,
+ offset: self.offset as wgt::BufferAddress,
+ bytes_per_row: self.bytesPerRow,
+ rows_per_image: self.rowsPerImage,
}
}
}
-impl From<GPUVertexFormat> for wgt::VertexFormat {
- fn from(format: GPUVertexFormat) -> Self {
- match format {
+impl Convert<wgt::VertexFormat> for GPUVertexFormat {
+ fn convert(self) -> wgt::VertexFormat {
+ match self {
GPUVertexFormat::Uint8x2 => wgt::VertexFormat::Uint8x2,
GPUVertexFormat::Uint8x4 => wgt::VertexFormat::Uint8x4,
GPUVertexFormat::Sint8x2 => wgt::VertexFormat::Sint8x2,
@@ -285,34 +286,34 @@ impl From<GPUVertexFormat> for wgt::VertexFormat {
}
}
-impl From<&GPUPrimitiveState> for wgt::PrimitiveState {
- fn from(primitive_state: &GPUPrimitiveState) -> Self {
+impl Convert<wgt::PrimitiveState> for &GPUPrimitiveState {
+ fn convert(self) -> wgt::PrimitiveState {
wgt::PrimitiveState {
- topology: wgt::PrimitiveTopology::from(&primitive_state.topology),
- strip_index_format: primitive_state.stripIndexFormat.map(|index_format| {
- match index_format {
+ topology: self.topology.convert(),
+ strip_index_format: self
+ .stripIndexFormat
+ .map(|index_format| match index_format {
GPUIndexFormat::Uint16 => wgt::IndexFormat::Uint16,
GPUIndexFormat::Uint32 => wgt::IndexFormat::Uint32,
- }
- }),
- front_face: match primitive_state.frontFace {
+ }),
+ front_face: match self.frontFace {
GPUFrontFace::Ccw => wgt::FrontFace::Ccw,
GPUFrontFace::Cw => wgt::FrontFace::Cw,
},
- cull_mode: match primitive_state.cullMode {
+ cull_mode: match self.cullMode {
GPUCullMode::None => None,
GPUCullMode::Front => Some(wgt::Face::Front),
GPUCullMode::Back => Some(wgt::Face::Back),
},
- unclipped_depth: primitive_state.clampDepth,
+ unclipped_depth: self.clampDepth,
..Default::default()
}
}
}
-impl From<&GPUPrimitiveTopology> for wgt::PrimitiveTopology {
- fn from(primitive_topology: &GPUPrimitiveTopology) -> Self {
- match primitive_topology {
+impl Convert<wgt::PrimitiveTopology> for &GPUPrimitiveTopology {
+ fn convert(self) -> wgt::PrimitiveTopology {
+ match self {
GPUPrimitiveTopology::Point_list => wgt::PrimitiveTopology::PointList,
GPUPrimitiveTopology::Line_list => wgt::PrimitiveTopology::LineList,
GPUPrimitiveTopology::Line_strip => wgt::PrimitiveTopology::LineStrip,
@@ -322,9 +323,9 @@ impl From<&GPUPrimitiveTopology> for wgt::PrimitiveTopology {
}
}
-impl From<GPUAddressMode> for wgt::AddressMode {
- fn from(address_mode: GPUAddressMode) -> Self {
- match address_mode {
+impl Convert<wgt::AddressMode> for GPUAddressMode {
+ fn convert(self) -> wgt::AddressMode {
+ match self {
GPUAddressMode::Clamp_to_edge => wgt::AddressMode::ClampToEdge,
GPUAddressMode::Repeat => wgt::AddressMode::Repeat,
GPUAddressMode::Mirror_repeat => wgt::AddressMode::MirrorRepeat,
@@ -332,18 +333,18 @@ impl From<GPUAddressMode> for wgt::AddressMode {
}
}
-impl From<GPUFilterMode> for wgt::FilterMode {
- fn from(filter_mode: GPUFilterMode) -> Self {
- match filter_mode {
+impl Convert<wgt::FilterMode> for GPUFilterMode {
+ fn convert(self) -> wgt::FilterMode {
+ match self {
GPUFilterMode::Nearest => wgt::FilterMode::Nearest,
GPUFilterMode::Linear => wgt::FilterMode::Linear,
}
}
}
-impl From<GPUTextureViewDimension> for wgt::TextureViewDimension {
- fn from(view_dimension: GPUTextureViewDimension) -> Self {
- match view_dimension {
+impl Convert<wgt::TextureViewDimension> for GPUTextureViewDimension {
+ fn convert(self) -> wgt::TextureViewDimension {
+ match self {
GPUTextureViewDimension::_1d => wgt::TextureViewDimension::D1,
GPUTextureViewDimension::_2d => wgt::TextureViewDimension::D2,
GPUTextureViewDimension::_2d_array => wgt::TextureViewDimension::D2Array,
@@ -354,9 +355,9 @@ impl From<GPUTextureViewDimension> for wgt::TextureViewDimension {
}
}
-impl From<GPUCompareFunction> for wgt::CompareFunction {
- fn from(compare: GPUCompareFunction) -> Self {
- match compare {
+impl Convert<wgt::CompareFunction> for GPUCompareFunction {
+ fn convert(self) -> wgt::CompareFunction {
+ match self {
GPUCompareFunction::Never => wgt::CompareFunction::Never,
GPUCompareFunction::Less => wgt::CompareFunction::Less,
GPUCompareFunction::Equal => wgt::CompareFunction::Equal,
@@ -369,9 +370,9 @@ impl From<GPUCompareFunction> for wgt::CompareFunction {
}
}
-impl From<&GPUBlendFactor> for wgt::BlendFactor {
- fn from(factor: &GPUBlendFactor) -> Self {
- match factor {
+impl Convert<wgt::BlendFactor> for &GPUBlendFactor {
+ fn convert(self) -> wgt::BlendFactor {
+ match self {
GPUBlendFactor::Zero => wgt::BlendFactor::Zero,
GPUBlendFactor::One => wgt::BlendFactor::One,
GPUBlendFactor::Src => wgt::BlendFactor::Src,
@@ -389,12 +390,12 @@ impl From<&GPUBlendFactor> for wgt::BlendFactor {
}
}
-impl From<&GPUBlendComponent> for wgt::BlendComponent {
- fn from(blend_component: &GPUBlendComponent) -> Self {
+impl Convert<wgt::BlendComponent> for &GPUBlendComponent {
+ fn convert(self) -> wgt::BlendComponent {
wgt::BlendComponent {
- src_factor: wgt::BlendFactor::from(&blend_component.srcFactor),
- dst_factor: wgt::BlendFactor::from(&blend_component.dstFactor),
- operation: match blend_component.operation {
+ src_factor: self.srcFactor.convert(),
+ dst_factor: self.dstFactor.convert(),
+ operation: match self.operation {
GPUBlendOperation::Add => wgt::BlendOperation::Add,
GPUBlendOperation::Subtract => wgt::BlendOperation::Subtract,
GPUBlendOperation::Reverse_subtract => wgt::BlendOperation::ReverseSubtract,
@@ -421,9 +422,9 @@ pub fn convert_store_op(op: Option<GPUStoreOp>) -> wgpu_com::StoreOp {
}
}
-impl From<GPUStencilOperation> for wgt::StencilOperation {
- fn from(operation: GPUStencilOperation) -> Self {
- match operation {
+impl Convert<wgt::StencilOperation> for GPUStencilOperation {
+ fn convert(self) -> wgt::StencilOperation {
+ match self {
GPUStencilOperation::Keep => wgt::StencilOperation::Keep,
GPUStencilOperation::Zero => wgt::StencilOperation::Zero,
GPUStencilOperation::Replace => wgt::StencilOperation::Replace,
@@ -436,20 +437,20 @@ impl From<GPUStencilOperation> for wgt::StencilOperation {
}
}
-impl From<&GPUImageCopyBuffer> for wgpu_com::ImageCopyBuffer {
- fn from(ic_buffer: &GPUImageCopyBuffer) -> Self {
+impl Convert<wgpu_com::ImageCopyBuffer> for &GPUImageCopyBuffer {
+ fn convert(self) -> wgpu_com::ImageCopyBuffer {
wgpu_com::ImageCopyBuffer {
- buffer: ic_buffer.buffer.id().0,
- layout: wgt::ImageDataLayout::from(&ic_buffer.parent),
+ buffer: self.buffer.id().0,
+ layout: self.parent.convert(),
}
}
}
-impl TryFrom<&GPUOrigin3D> for wgt::Origin3d {
+impl TryConvert<wgt::Origin3d> for &GPUOrigin3D {
type Error = Error;
- fn try_from(origin: &GPUOrigin3D) -> Result<Self, Self::Error> {
- match origin {
+ fn try_convert(self) -> Result<wgt::Origin3d, Self::Error> {
+ match self {
GPUOrigin3D::RangeEnforcedUnsignedLongSequence(v) => {
// https://gpuweb.github.io/gpuweb/#abstract-opdef-validate-gpuorigin3d-shape
if v.len() > 3 {
@@ -473,20 +474,20 @@ impl TryFrom<&GPUOrigin3D> for wgt::Origin3d {
}
}
-impl TryFrom<&GPUImageCopyTexture> for wgpu_com::ImageCopyTexture {
+impl TryConvert<wgpu_com::ImageCopyTexture> for &GPUImageCopyTexture {
type Error = Error;
- fn try_from(ic_texture: &GPUImageCopyTexture) -> Result<Self, Self::Error> {
+ fn try_convert(self) -> Result<wgpu_com::ImageCopyTexture, Self::Error> {
Ok(wgpu_com::ImageCopyTexture {
- texture: ic_texture.texture.id().0,
- mip_level: ic_texture.mipLevel,
- origin: ic_texture
+ texture: self.texture.id().0,
+ mip_level: self.mipLevel,
+ origin: self
.origin
.as_ref()
- .map(wgt::Origin3d::try_from)
+ .map(TryConvert::<wgt::Origin3d>::try_convert)
.transpose()?
.unwrap_or_default(),
- aspect: match ic_texture.aspect {
+ aspect: match self.aspect {
GPUTextureAspect::All => wgt::TextureAspect::All,
GPUTextureAspect::Stencil_only => wgt::TextureAspect::StencilOnly,
GPUTextureAspect::Depth_only => wgt::TextureAspect::DepthOnly,
@@ -495,12 +496,12 @@ impl TryFrom<&GPUImageCopyTexture> for wgpu_com::ImageCopyTexture {
}
}
-impl<'a> From<&GPUObjectDescriptorBase> for Option<Cow<'a, str>> {
- fn from(val: &GPUObjectDescriptorBase) -> Self {
- if val.label.is_empty() {
+impl<'a> Convert<Option<Cow<'a, str>>> for &GPUObjectDescriptorBase {
+ fn convert(self) -> Option<Cow<'a, str>> {
+ if self.label.is_empty() {
None
} else {
- Some(Cow::Owned(val.label.to_string()))
+ Some(Cow::Owned(self.label.to_string()))
}
}
}
@@ -541,7 +542,7 @@ pub fn convert_bind_group_layout_entry(
GPUStorageTextureAccess::Read_write => wgt::StorageTextureAccess::ReadWrite,
},
format: device.validate_texture_format_required_features(&storage.format)?,
- view_dimension: storage.viewDimension.into(),
+ view_dimension: storage.viewDimension.convert(),
})
} else if let Some(texture) = &bgle.texture {
Some(wgt::BindingType::Texture {
@@ -554,7 +555,7 @@ pub fn convert_bind_group_layout_entry(
GPUTextureSampleType::Sint => wgt::TextureSampleType::Sint,
GPUTextureSampleType::Uint => wgt::TextureSampleType::Uint,
},
- view_dimension: texture.viewDimension.into(),
+ view_dimension: texture.viewDimension.convert(),
multisampled: texture.multisampled,
})
} else {
@@ -584,13 +585,13 @@ pub fn convert_texture_descriptor(
descriptor: &GPUTextureDescriptor,
device: &GPUDevice,
) -> Fallible<(TextureDescriptor<'static>, wgt::Extent3d)> {
- let size = (&descriptor.size).try_into()?;
+ let size = (&descriptor.size).try_convert()?;
let desc = TextureDescriptor {
- label: (&descriptor.parent).into(),
+ label: (&descriptor.parent).convert(),
size,
mip_level_count: descriptor.mipLevelCount,
sample_count: descriptor.sampleCount,
- dimension: descriptor.dimension.into(),
+ dimension: descriptor.dimension.convert(),
format: device.validate_texture_format_required_features(&descriptor.format)?,
usage: wgt::TextureUsages::from_bits_retain(descriptor.usage),
view_formats: descriptor
@@ -602,11 +603,11 @@ pub fn convert_texture_descriptor(
Ok((desc, size))
}
-impl TryFrom<&GPUColor> for wgt::Color {
+impl TryConvert<wgt::Color> for &GPUColor {
type Error = Error;
- fn try_from(color: &GPUColor) -> Result<Self, Self::Error> {
- match color {
+ fn try_convert(self) -> Result<wgt::Color, Self::Error> {
+ match self {
GPUColor::DoubleSequence(s) => {
// https://gpuweb.github.io/gpuweb/#abstract-opdef-validate-gpucolor-shape
if s.len() != 4 {
@@ -630,17 +631,16 @@ impl TryFrom<&GPUColor> for wgt::Color {
}
}
-impl<'a> From<&GPUProgrammableStage> for ProgrammableStageDescriptor<'a> {
- fn from(stage: &GPUProgrammableStage) -> Self {
- Self {
- module: stage.module.id().0,
- entry_point: stage
+impl<'a> Convert<ProgrammableStageDescriptor<'a>> for &GPUProgrammableStage {
+ fn convert(self) -> ProgrammableStageDescriptor<'a> {
+ ProgrammableStageDescriptor {
+ module: self.module.id().0,
+ entry_point: self
.entryPoint
.as_ref()
.map(|ep| Cow::Owned(ep.to_string())),
constants: Cow::Owned(
- stage
- .constants
+ self.constants
.as_ref()
.map(|records| records.iter().map(|(k, v)| (k.0.clone(), **v)).collect())
.unwrap_or_default(),
@@ -650,11 +650,11 @@ impl<'a> From<&GPUProgrammableStage> for ProgrammableStageDescriptor<'a> {
}
}
-impl From<&GPUBindGroupEntry> for BindGroupEntry<'_> {
- fn from(entry: &GPUBindGroupEntry) -> Self {
- Self {
- binding: entry.binding,
- resource: match entry.resource {
+impl<'a> Convert<BindGroupEntry<'a>> for &GPUBindGroupEntry {
+ fn convert(self) -> BindGroupEntry<'a> {
+ BindGroupEntry {
+ binding: self.binding,
+ resource: match self.resource {
GPUBindingResource::GPUSampler(ref s) => BindingResource::Sampler(s.id().0),
GPUBindingResource::GPUTextureView(ref t) => BindingResource::TextureView(t.id().0),
GPUBindingResource::GPUBufferBinding(ref b) => {
@@ -669,9 +669,9 @@ impl From<&GPUBindGroupEntry> for BindGroupEntry<'_> {
}
}
-impl From<GPUTextureDimension> for wgt::TextureDimension {
- fn from(dimension: GPUTextureDimension) -> Self {
- match dimension {
+impl Convert<wgt::TextureDimension> for GPUTextureDimension {
+ fn convert(self) -> wgt::TextureDimension {
+ match self {
GPUTextureDimension::_1d => wgt::TextureDimension::D1,
GPUTextureDimension::_2d => wgt::TextureDimension::D2,
GPUTextureDimension::_3d => wgt::TextureDimension::D3,
diff --git a/components/script/dom/webgpu/gpudevice.rs b/components/script/dom/webgpu/gpudevice.rs
index 62b47bc7661..589395b0a2b 100644
--- a/components/script/dom/webgpu/gpudevice.rs
+++ b/components/script/dom/webgpu/gpudevice.rs
@@ -23,6 +23,7 @@ use super::gpu::AsyncWGPUListener;
use super::gpudevicelostinfo::GPUDeviceLostInfo;
use super::gpupipelineerror::GPUPipelineError;
use super::gpusupportedlimits::GPUSupportedLimits;
+use crate::conversions::Convert;
use crate::dom::bindings::cell::DomRefCell;
use crate::dom::bindings::codegen::Bindings::EventBinding::EventInit;
use crate::dom::bindings::codegen::Bindings::EventTargetBinding::EventTargetMethods;
@@ -215,7 +216,7 @@ impl GPUDevice {
&self,
format: &GPUTextureFormat,
) -> Fallible<TextureFormat> {
- let texture_format: TextureFormat = (*format).into();
+ let texture_format: TextureFormat = (*format).convert();
if self
.features
.wgpu_features()
@@ -258,11 +259,11 @@ impl GPUDevice {
let pipeline_layout = self.get_pipeline_layout_data(&descriptor.parent.layout);
let desc = wgpu_pipe::RenderPipelineDescriptor {
- label: (&descriptor.parent.parent).into(),
+ label: (&descriptor.parent.parent).convert(),
layout: pipeline_layout.explicit(),
cache: None,
vertex: wgpu_pipe::VertexState {
- stage: (&descriptor.vertex.parent).into(),
+ stage: (&descriptor.vertex.parent).convert(),
buffers: Cow::Owned(
descriptor
.vertex
@@ -279,7 +280,7 @@ impl GPUDevice {
.attributes
.iter()
.map(|att| wgt::VertexAttribute {
- format: att.format.into(),
+ format: att.format.convert(),
offset: att.offset,
shader_location: att.shaderLocation,
})
@@ -294,7 +295,7 @@ impl GPUDevice {
.as_ref()
.map(|stage| -> Fallible<wgpu_pipe::FragmentState> {
Ok(wgpu_pipe::FragmentState {
- stage: (&stage.parent).into(),
+ stage: (&stage.parent).convert(),
targets: Cow::Owned(
stage
.targets
@@ -309,8 +310,8 @@ impl GPUDevice {
),
blend: state.blend.as_ref().map(|blend| {
wgt::BlendState {
- color: (&blend.color).into(),
- alpha: (&blend.alpha).into(),
+ color: (&blend.color).convert(),
+ alpha: (&blend.alpha).convert(),
}
}),
})
@@ -321,7 +322,7 @@ impl GPUDevice {
})
})
.transpose()?,
- primitive: (&descriptor.primitive).into(),
+ primitive: (&descriptor.primitive).convert(),
depth_stencil: descriptor
.depthStencil
.as_ref()
@@ -330,20 +331,20 @@ impl GPUDevice {
.map(|format| wgt::DepthStencilState {
format,
depth_write_enabled: dss_desc.depthWriteEnabled,
- depth_compare: dss_desc.depthCompare.into(),
+ depth_compare: dss_desc.depthCompare.convert(),
stencil: wgt::StencilState {
front: wgt::StencilFaceState {
- compare: dss_desc.stencilFront.compare.into(),
+ compare: dss_desc.stencilFront.compare.convert(),
- fail_op: dss_desc.stencilFront.failOp.into(),
- depth_fail_op: dss_desc.stencilFront.depthFailOp.into(),
- pass_op: dss_desc.stencilFront.passOp.into(),
+ fail_op: dss_desc.stencilFront.failOp.convert(),
+ depth_fail_op: dss_desc.stencilFront.depthFailOp.convert(),
+ pass_op: dss_desc.stencilFront.passOp.convert(),
},
back: wgt::StencilFaceState {
- compare: dss_desc.stencilBack.compare.into(),
- fail_op: dss_desc.stencilBack.failOp.into(),
- depth_fail_op: dss_desc.stencilBack.depthFailOp.into(),
- pass_op: dss_desc.stencilBack.passOp.into(),
+ compare: dss_desc.stencilBack.compare.convert(),
+ fail_op: dss_desc.stencilBack.failOp.convert(),
+ depth_fail_op: dss_desc.stencilBack.depthFailOp.convert(),
+ pass_op: dss_desc.stencilBack.passOp.convert(),
},
read_mask: dss_desc.stencilReadMask,
write_mask: dss_desc.stencilWriteMask,
diff --git a/components/script/dom/webgpu/gpuerror.rs b/components/script/dom/webgpu/gpuerror.rs
index a4de08cc18b..bc349ed4377 100644
--- a/components/script/dom/webgpu/gpuerror.rs
+++ b/components/script/dom/webgpu/gpuerror.rs
@@ -6,6 +6,7 @@ use dom_struct::dom_struct;
use js::rust::HandleObject;
use webgpu::{Error, ErrorFilter};
+use crate::conversions::Convert;
use crate::dom::bindings::codegen::Bindings::WebGPUBinding::{GPUErrorFilter, GPUErrorMethods};
use crate::dom::bindings::reflector::{reflect_dom_object_with_proto, Reflector};
use crate::dom::bindings::root::DomRoot;
@@ -79,9 +80,9 @@ impl GPUErrorMethods<crate::DomTypeHolder> for GPUError {
}
}
-impl From<ErrorFilter> for GPUErrorFilter {
- fn from(filter: ErrorFilter) -> Self {
- match filter {
+impl Convert<GPUErrorFilter> for ErrorFilter {
+ fn convert(self) -> GPUErrorFilter {
+ match self {
ErrorFilter::Validation => GPUErrorFilter::Validation,
ErrorFilter::OutOfMemory => GPUErrorFilter::Out_of_memory,
ErrorFilter::Internal => GPUErrorFilter::Internal,
diff --git a/components/script/dom/webgpu/gpupipelinelayout.rs b/components/script/dom/webgpu/gpupipelinelayout.rs
index 5a5768388c4..10bbc53f690 100644
--- a/components/script/dom/webgpu/gpupipelinelayout.rs
+++ b/components/script/dom/webgpu/gpupipelinelayout.rs
@@ -8,6 +8,7 @@ use dom_struct::dom_struct;
use webgpu::wgc::binding_model::PipelineLayoutDescriptor;
use webgpu::{WebGPU, WebGPUBindGroupLayout, WebGPUPipelineLayout, WebGPURequest};
+use crate::conversions::Convert;
use crate::dom::bindings::cell::DomRefCell;
use crate::dom::bindings::codegen::Bindings::WebGPUBinding::{
GPUPipelineLayoutDescriptor, GPUPipelineLayoutMethods,
@@ -87,7 +88,7 @@ impl GPUPipelineLayout {
.collect::<Vec<_>>();
let desc = PipelineLayoutDescriptor {
- label: (&descriptor.parent).into(),
+ label: (&descriptor.parent).convert(),
bind_group_layouts: Cow::Owned(bgls.iter().map(|l| l.0).collect::<Vec<_>>()),
push_constant_ranges: Cow::Owned(vec![]),
};
diff --git a/components/script/dom/webgpu/gpuqueue.rs b/components/script/dom/webgpu/gpuqueue.rs
index 9eea0bffa69..72e74ba66d3 100644
--- a/components/script/dom/webgpu/gpuqueue.rs
+++ b/components/script/dom/webgpu/gpuqueue.rs
@@ -9,6 +9,7 @@ use ipc_channel::ipc::IpcSharedMemory;
use webgpu::{wgt, WebGPU, WebGPUQueue, WebGPURequest, WebGPUResponse};
use super::gpu::{response_async, AsyncWGPUListener};
+use crate::conversions::{Convert, TryConvert};
use crate::dom::bindings::cell::DomRefCell;
use crate::dom::bindings::codegen::Bindings::WebGPUBinding::{
GPUExtent3D, GPUImageCopyTexture, GPUImageDataLayout, GPUQueueMethods, GPUSize64,
@@ -162,9 +163,9 @@ impl GPUQueueMethods<crate::DomTypeHolder> for GPUQueue {
return Err(Error::Operation);
}
- let texture_cv = destination.try_into()?;
- let texture_layout = data_layout.into();
- let write_size = (&size).try_into()?;
+ let texture_cv = destination.try_convert()?;
+ let texture_layout = data_layout.convert();
+ let write_size = (&size).try_convert()?;
let final_data = IpcSharedMemory::from_bytes(&bytes);
if let Err(e) = self.channel.0.send(WebGPURequest::WriteTexture {
diff --git a/components/script/dom/webgpu/gpurenderbundleencoder.rs b/components/script/dom/webgpu/gpurenderbundleencoder.rs
index 2a76bfe0336..11483bc3eac 100644
--- a/components/script/dom/webgpu/gpurenderbundleencoder.rs
+++ b/components/script/dom/webgpu/gpurenderbundleencoder.rs
@@ -10,6 +10,7 @@ use webgpu::wgc::command::{
};
use webgpu::{wgt, WebGPU, WebGPURenderBundle, WebGPURequest};
+use crate::conversions::Convert;
use crate::dom::bindings::cell::DomRefCell;
use crate::dom::bindings::codegen::Bindings::WebGPUBinding::{
GPUIndexFormat, GPURenderBundleDescriptor, GPURenderBundleEncoderDescriptor,
@@ -81,7 +82,7 @@ impl GPURenderBundleEncoder {
descriptor: &GPURenderBundleEncoderDescriptor,
) -> Fallible<DomRoot<GPURenderBundleEncoder>> {
let desc = RenderBundleEncoderDescriptor {
- label: (&descriptor.parent.parent).into(),
+ label: (&descriptor.parent.parent).convert(),
color_formats: Cow::Owned(
descriptor
.parent
@@ -252,7 +253,7 @@ impl GPURenderBundleEncoderMethods<crate::DomTypeHolder> for GPURenderBundleEnco
/// <https://gpuweb.github.io/gpuweb/#dom-gpurenderbundleencoder-finish>
fn Finish(&self, descriptor: &GPURenderBundleDescriptor) -> DomRoot<GPURenderBundle> {
let desc = wgt::RenderBundleDescriptor {
- label: (&descriptor.parent).into(),
+ label: (&descriptor.parent).convert(),
};
let encoder = self.render_bundle_encoder.borrow_mut().take().unwrap();
let render_bundle_id = self.global().wgpu_id_hub().create_render_bundle_id();
diff --git a/components/script/dom/webgpu/gpurenderpassencoder.rs b/components/script/dom/webgpu/gpurenderpassencoder.rs
index 765e220f32e..e52cb4dec45 100644
--- a/components/script/dom/webgpu/gpurenderpassencoder.rs
+++ b/components/script/dom/webgpu/gpurenderpassencoder.rs
@@ -5,6 +5,7 @@
use dom_struct::dom_struct;
use webgpu::{wgt, RenderCommand, WebGPU, WebGPURenderPass, WebGPURequest};
+use crate::conversions::TryConvert;
use crate::dom::bindings::cell::DomRefCell;
use crate::dom::bindings::codegen::Bindings::WebGPUBinding::{
GPUColor, GPUIndexFormat, GPURenderPassEncoderMethods,
@@ -130,7 +131,7 @@ impl GPURenderPassEncoderMethods<crate::DomTypeHolder> for GPURenderPassEncoder
/// <https://gpuweb.github.io/gpuweb/#dom-gpurenderpassencoder-setblendcolor>
fn SetBlendConstant(&self, color: GPUColor) -> Fallible<()> {
- self.send_render_command(RenderCommand::SetBlendConstant((&color).try_into()?));
+ self.send_render_command(RenderCommand::SetBlendConstant((&color).try_convert()?));
Ok(())
}
diff --git a/components/script/dom/webgpu/gpusampler.rs b/components/script/dom/webgpu/gpusampler.rs
index 25fa90a2410..98ec5a873ff 100644
--- a/components/script/dom/webgpu/gpusampler.rs
+++ b/components/script/dom/webgpu/gpusampler.rs
@@ -6,6 +6,7 @@ use dom_struct::dom_struct;
use webgpu::wgc::resource::SamplerDescriptor;
use webgpu::{WebGPU, WebGPUDevice, WebGPURequest, WebGPUSampler};
+use crate::conversions::Convert;
use crate::dom::bindings::cell::DomRefCell;
use crate::dom::bindings::codegen::Bindings::WebGPUBinding::{
GPUSamplerDescriptor, GPUSamplerMethods,
@@ -79,18 +80,18 @@ impl GPUSampler {
let sampler_id = device.global().wgpu_id_hub().create_sampler_id();
let compare_enable = descriptor.compare.is_some();
let desc = SamplerDescriptor {
- label: (&descriptor.parent).into(),
+ label: (&descriptor.parent).convert(),
address_modes: [
- descriptor.addressModeU.into(),
- descriptor.addressModeV.into(),
- descriptor.addressModeW.into(),
+ descriptor.addressModeU.convert(),
+ descriptor.addressModeV.convert(),
+ descriptor.addressModeW.convert(),
],
- mag_filter: descriptor.magFilter.into(),
- min_filter: descriptor.minFilter.into(),
- mipmap_filter: descriptor.mipmapFilter.into(),
+ mag_filter: descriptor.magFilter.convert(),
+ min_filter: descriptor.minFilter.convert(),
+ mipmap_filter: descriptor.mipmapFilter.convert(),
lod_min_clamp: *descriptor.lodMinClamp,
lod_max_clamp: *descriptor.lodMaxClamp,
- compare: descriptor.compare.map(Into::into),
+ compare: descriptor.compare.map(Convert::convert),
anisotropy_clamp: 1,
border_color: None,
};
diff --git a/components/script/dom/webgpu/gputexture.rs b/components/script/dom/webgpu/gputexture.rs
index 02cb4c94f74..9a136165dff 100644
--- a/components/script/dom/webgpu/gputexture.rs
+++ b/components/script/dom/webgpu/gputexture.rs
@@ -9,6 +9,7 @@ use webgpu::wgc::resource;
use webgpu::{wgt, WebGPU, WebGPURequest, WebGPUTexture, WebGPUTextureView};
use super::gpuconvert::convert_texture_descriptor;
+use crate::conversions::Convert;
use crate::dom::bindings::cell::DomRefCell;
use crate::dom::bindings::codegen::Bindings::WebGPUBinding::{
GPUTextureAspect, GPUTextureDescriptor, GPUTextureDimension, GPUTextureFormat,
@@ -180,12 +181,12 @@ impl GPUTextureMethods<crate::DomTypeHolder> for GPUTexture {
!matches!(descriptor.arrayLayerCount, Some(0))
{
Some(resource::TextureViewDescriptor {
- label: (&descriptor.parent).into(),
+ label: (&descriptor.parent).convert(),
format: descriptor
.format
.map(|f| self.device.validate_texture_format_required_features(&f))
.transpose()?,
- dimension: descriptor.dimension.map(|dimension| dimension.into()),
+ dimension: descriptor.dimension.map(|dimension| dimension.convert()),
range: wgt::ImageSubresourceRange {
aspect: match descriptor.aspect {
GPUTextureAspect::All => wgt::TextureAspect::All,