mirror of
https://github.com/servo/servo.git
synced 2025-08-04 13:10:20 +01:00
Transform convert_* functions in gpuconvert.rs to From/TryFrom implementations (#33302)
Signed-off-by: Taym <haddadi.taym@gmail.com>
This commit is contained in:
parent
c0ced7a524
commit
00389cf007
6 changed files with 493 additions and 483 deletions
|
@ -4,10 +4,11 @@
|
||||||
|
|
||||||
use dom_struct::dom_struct;
|
use dom_struct::dom_struct;
|
||||||
use webgpu::wgc::command as wgpu_com;
|
use webgpu::wgc::command as wgpu_com;
|
||||||
|
use webgpu::wgt::Color;
|
||||||
use webgpu::{self, wgt, WebGPU, WebGPUComputePass, WebGPURenderPass, WebGPURequest};
|
use webgpu::{self, wgt, WebGPU, WebGPUComputePass, WebGPURenderPass, WebGPURequest};
|
||||||
|
|
||||||
use super::bindings::error::Fallible;
|
use super::bindings::error::Fallible;
|
||||||
use super::gpuconvert::{convert_color, convert_label};
|
use super::gpuconvert::convert_label;
|
||||||
use crate::dom::bindings::cell::DomRefCell;
|
use crate::dom::bindings::cell::DomRefCell;
|
||||||
use crate::dom::bindings::codegen::Bindings::WebGPUBinding::{
|
use crate::dom::bindings::codegen::Bindings::WebGPUBinding::{
|
||||||
GPUCommandBufferDescriptor, GPUCommandEncoderMethods, GPUComputePassDescriptor, GPUExtent3D,
|
GPUCommandBufferDescriptor, GPUCommandEncoderMethods, GPUComputePassDescriptor, GPUExtent3D,
|
||||||
|
@ -20,9 +21,7 @@ use crate::dom::globalscope::GlobalScope;
|
||||||
use crate::dom::gpubuffer::GPUBuffer;
|
use crate::dom::gpubuffer::GPUBuffer;
|
||||||
use crate::dom::gpucommandbuffer::GPUCommandBuffer;
|
use crate::dom::gpucommandbuffer::GPUCommandBuffer;
|
||||||
use crate::dom::gpucomputepassencoder::GPUComputePassEncoder;
|
use crate::dom::gpucomputepassencoder::GPUComputePassEncoder;
|
||||||
use crate::dom::gpuconvert::{
|
use crate::dom::gpuconvert::{convert_load_op, convert_store_op};
|
||||||
convert_ic_buffer, convert_ic_texture, convert_load_op, convert_store_op, convert_texture_size,
|
|
||||||
};
|
|
||||||
use crate::dom::gpudevice::GPUDevice;
|
use crate::dom::gpudevice::GPUDevice;
|
||||||
use crate::dom::gpurenderpassencoder::GPURenderPassEncoder;
|
use crate::dom::gpurenderpassencoder::GPURenderPassEncoder;
|
||||||
|
|
||||||
|
@ -152,7 +151,7 @@ impl GPUCommandEncoderMethods for GPUCommandEncoder {
|
||||||
clear_value: color
|
clear_value: color
|
||||||
.clearValue
|
.clearValue
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|color| convert_color(color))
|
.map(|color| (color).try_into())
|
||||||
.transpose()?
|
.transpose()?
|
||||||
.unwrap_or_default(),
|
.unwrap_or_default(),
|
||||||
read_only: false,
|
read_only: false,
|
||||||
|
@ -222,9 +221,9 @@ impl GPUCommandEncoderMethods for GPUCommandEncoder {
|
||||||
.0
|
.0
|
||||||
.send(WebGPURequest::CopyBufferToTexture {
|
.send(WebGPURequest::CopyBufferToTexture {
|
||||||
command_encoder_id: self.encoder.0,
|
command_encoder_id: self.encoder.0,
|
||||||
source: convert_ic_buffer(source),
|
source: source.into(),
|
||||||
destination: convert_ic_texture(destination)?,
|
destination: destination.try_into()?,
|
||||||
copy_size: convert_texture_size(©_size)?,
|
copy_size: (©_size).try_into()?,
|
||||||
})
|
})
|
||||||
.expect("Failed to send CopyBufferToTexture");
|
.expect("Failed to send CopyBufferToTexture");
|
||||||
|
|
||||||
|
@ -242,9 +241,9 @@ impl GPUCommandEncoderMethods for GPUCommandEncoder {
|
||||||
.0
|
.0
|
||||||
.send(WebGPURequest::CopyTextureToBuffer {
|
.send(WebGPURequest::CopyTextureToBuffer {
|
||||||
command_encoder_id: self.encoder.0,
|
command_encoder_id: self.encoder.0,
|
||||||
source: convert_ic_texture(source)?,
|
source: source.try_into()?,
|
||||||
destination: convert_ic_buffer(destination),
|
destination: destination.into(),
|
||||||
copy_size: convert_texture_size(©_size)?,
|
copy_size: (©_size).try_into()?,
|
||||||
})
|
})
|
||||||
.expect("Failed to send CopyTextureToBuffer");
|
.expect("Failed to send CopyTextureToBuffer");
|
||||||
|
|
||||||
|
@ -262,9 +261,9 @@ impl GPUCommandEncoderMethods for GPUCommandEncoder {
|
||||||
.0
|
.0
|
||||||
.send(WebGPURequest::CopyTextureToTexture {
|
.send(WebGPURequest::CopyTextureToTexture {
|
||||||
command_encoder_id: self.encoder.0,
|
command_encoder_id: self.encoder.0,
|
||||||
source: convert_ic_texture(source)?,
|
source: source.try_into()?,
|
||||||
destination: convert_ic_texture(destination)?,
|
destination: destination.try_into()?,
|
||||||
copy_size: convert_texture_size(©_size)?,
|
copy_size: (©_size).try_into()?,
|
||||||
})
|
})
|
||||||
.expect("Failed to send CopyTextureToTexture");
|
.expect("Failed to send CopyTextureToTexture");
|
||||||
|
|
||||||
|
|
|
@ -23,375 +23,384 @@ use crate::dom::bindings::codegen::Bindings::WebGPUBinding::{
|
||||||
use crate::dom::bindings::error::Fallible;
|
use crate::dom::bindings::error::Fallible;
|
||||||
use crate::dom::types::GPUDevice;
|
use crate::dom::types::GPUDevice;
|
||||||
|
|
||||||
pub fn convert_texture_format(format: GPUTextureFormat) -> wgt::TextureFormat {
|
impl From<GPUTextureFormat> for wgt::TextureFormat {
|
||||||
match format {
|
fn from(format: GPUTextureFormat) -> Self {
|
||||||
GPUTextureFormat::R8unorm => wgt::TextureFormat::R8Unorm,
|
match format {
|
||||||
GPUTextureFormat::R8snorm => wgt::TextureFormat::R8Snorm,
|
GPUTextureFormat::R8unorm => wgt::TextureFormat::R8Unorm,
|
||||||
GPUTextureFormat::R8uint => wgt::TextureFormat::R8Uint,
|
GPUTextureFormat::R8snorm => wgt::TextureFormat::R8Snorm,
|
||||||
GPUTextureFormat::R8sint => wgt::TextureFormat::R8Sint,
|
GPUTextureFormat::R8uint => wgt::TextureFormat::R8Uint,
|
||||||
GPUTextureFormat::R16uint => wgt::TextureFormat::R16Uint,
|
GPUTextureFormat::R8sint => wgt::TextureFormat::R8Sint,
|
||||||
GPUTextureFormat::R16sint => wgt::TextureFormat::R16Sint,
|
GPUTextureFormat::R16uint => wgt::TextureFormat::R16Uint,
|
||||||
GPUTextureFormat::R16float => wgt::TextureFormat::R16Float,
|
GPUTextureFormat::R16sint => wgt::TextureFormat::R16Sint,
|
||||||
GPUTextureFormat::Rg8unorm => wgt::TextureFormat::Rg8Unorm,
|
GPUTextureFormat::R16float => wgt::TextureFormat::R16Float,
|
||||||
GPUTextureFormat::Rg8snorm => wgt::TextureFormat::Rg8Snorm,
|
GPUTextureFormat::Rg8unorm => wgt::TextureFormat::Rg8Unorm,
|
||||||
GPUTextureFormat::Rg8uint => wgt::TextureFormat::Rg8Uint,
|
GPUTextureFormat::Rg8snorm => wgt::TextureFormat::Rg8Snorm,
|
||||||
GPUTextureFormat::Rg8sint => wgt::TextureFormat::Rg8Sint,
|
GPUTextureFormat::Rg8uint => wgt::TextureFormat::Rg8Uint,
|
||||||
GPUTextureFormat::R32uint => wgt::TextureFormat::R32Uint,
|
GPUTextureFormat::Rg8sint => wgt::TextureFormat::Rg8Sint,
|
||||||
GPUTextureFormat::R32sint => wgt::TextureFormat::R32Sint,
|
GPUTextureFormat::R32uint => wgt::TextureFormat::R32Uint,
|
||||||
GPUTextureFormat::R32float => wgt::TextureFormat::R32Float,
|
GPUTextureFormat::R32sint => wgt::TextureFormat::R32Sint,
|
||||||
GPUTextureFormat::Rg16uint => wgt::TextureFormat::Rg16Uint,
|
GPUTextureFormat::R32float => wgt::TextureFormat::R32Float,
|
||||||
GPUTextureFormat::Rg16sint => wgt::TextureFormat::Rg16Sint,
|
GPUTextureFormat::Rg16uint => wgt::TextureFormat::Rg16Uint,
|
||||||
GPUTextureFormat::Rg16float => wgt::TextureFormat::Rg16Float,
|
GPUTextureFormat::Rg16sint => wgt::TextureFormat::Rg16Sint,
|
||||||
GPUTextureFormat::Rgba8unorm => wgt::TextureFormat::Rgba8Unorm,
|
GPUTextureFormat::Rg16float => wgt::TextureFormat::Rg16Float,
|
||||||
GPUTextureFormat::Rgba8unorm_srgb => wgt::TextureFormat::Rgba8UnormSrgb,
|
GPUTextureFormat::Rgba8unorm => wgt::TextureFormat::Rgba8Unorm,
|
||||||
GPUTextureFormat::Rgba8snorm => wgt::TextureFormat::Rgba8Snorm,
|
GPUTextureFormat::Rgba8unorm_srgb => wgt::TextureFormat::Rgba8UnormSrgb,
|
||||||
GPUTextureFormat::Rgba8uint => wgt::TextureFormat::Rgba8Uint,
|
GPUTextureFormat::Rgba8snorm => wgt::TextureFormat::Rgba8Snorm,
|
||||||
GPUTextureFormat::Rgba8sint => wgt::TextureFormat::Rgba8Sint,
|
GPUTextureFormat::Rgba8uint => wgt::TextureFormat::Rgba8Uint,
|
||||||
GPUTextureFormat::Bgra8unorm => wgt::TextureFormat::Bgra8Unorm,
|
GPUTextureFormat::Rgba8sint => wgt::TextureFormat::Rgba8Sint,
|
||||||
GPUTextureFormat::Bgra8unorm_srgb => wgt::TextureFormat::Bgra8UnormSrgb,
|
GPUTextureFormat::Bgra8unorm => wgt::TextureFormat::Bgra8Unorm,
|
||||||
GPUTextureFormat::Rgb10a2unorm => wgt::TextureFormat::Rgb10a2Unorm,
|
GPUTextureFormat::Bgra8unorm_srgb => wgt::TextureFormat::Bgra8UnormSrgb,
|
||||||
GPUTextureFormat::Rg32uint => wgt::TextureFormat::Rg32Uint,
|
GPUTextureFormat::Rgb10a2unorm => wgt::TextureFormat::Rgb10a2Unorm,
|
||||||
GPUTextureFormat::Rg32sint => wgt::TextureFormat::Rg32Sint,
|
GPUTextureFormat::Rg32uint => wgt::TextureFormat::Rg32Uint,
|
||||||
GPUTextureFormat::Rg32float => wgt::TextureFormat::Rg32Float,
|
GPUTextureFormat::Rg32sint => wgt::TextureFormat::Rg32Sint,
|
||||||
GPUTextureFormat::Rgba16uint => wgt::TextureFormat::Rgba16Uint,
|
GPUTextureFormat::Rg32float => wgt::TextureFormat::Rg32Float,
|
||||||
GPUTextureFormat::Rgba16sint => wgt::TextureFormat::Rgba16Sint,
|
GPUTextureFormat::Rgba16uint => wgt::TextureFormat::Rgba16Uint,
|
||||||
GPUTextureFormat::Rgba16float => wgt::TextureFormat::Rgba16Float,
|
GPUTextureFormat::Rgba16sint => wgt::TextureFormat::Rgba16Sint,
|
||||||
GPUTextureFormat::Rgba32uint => wgt::TextureFormat::Rgba32Uint,
|
GPUTextureFormat::Rgba16float => wgt::TextureFormat::Rgba16Float,
|
||||||
GPUTextureFormat::Rgba32sint => wgt::TextureFormat::Rgba32Sint,
|
GPUTextureFormat::Rgba32uint => wgt::TextureFormat::Rgba32Uint,
|
||||||
GPUTextureFormat::Rgba32float => wgt::TextureFormat::Rgba32Float,
|
GPUTextureFormat::Rgba32sint => wgt::TextureFormat::Rgba32Sint,
|
||||||
GPUTextureFormat::Depth32float => wgt::TextureFormat::Depth32Float,
|
GPUTextureFormat::Rgba32float => wgt::TextureFormat::Rgba32Float,
|
||||||
GPUTextureFormat::Depth24plus => wgt::TextureFormat::Depth24Plus,
|
GPUTextureFormat::Depth32float => wgt::TextureFormat::Depth32Float,
|
||||||
GPUTextureFormat::Depth24plus_stencil8 => wgt::TextureFormat::Depth24PlusStencil8,
|
GPUTextureFormat::Depth24plus => wgt::TextureFormat::Depth24Plus,
|
||||||
GPUTextureFormat::Bc1_rgba_unorm => wgt::TextureFormat::Bc1RgbaUnorm,
|
GPUTextureFormat::Depth24plus_stencil8 => wgt::TextureFormat::Depth24PlusStencil8,
|
||||||
GPUTextureFormat::Bc1_rgba_unorm_srgb => wgt::TextureFormat::Bc1RgbaUnormSrgb,
|
GPUTextureFormat::Bc1_rgba_unorm => wgt::TextureFormat::Bc1RgbaUnorm,
|
||||||
GPUTextureFormat::Bc2_rgba_unorm => wgt::TextureFormat::Bc2RgbaUnorm,
|
GPUTextureFormat::Bc1_rgba_unorm_srgb => wgt::TextureFormat::Bc1RgbaUnormSrgb,
|
||||||
GPUTextureFormat::Bc2_rgba_unorm_srgb => wgt::TextureFormat::Bc2RgbaUnormSrgb,
|
GPUTextureFormat::Bc2_rgba_unorm => wgt::TextureFormat::Bc2RgbaUnorm,
|
||||||
GPUTextureFormat::Bc3_rgba_unorm => wgt::TextureFormat::Bc3RgbaUnorm,
|
GPUTextureFormat::Bc2_rgba_unorm_srgb => wgt::TextureFormat::Bc2RgbaUnormSrgb,
|
||||||
GPUTextureFormat::Bc3_rgba_unorm_srgb => wgt::TextureFormat::Bc3RgbaUnormSrgb,
|
GPUTextureFormat::Bc3_rgba_unorm => wgt::TextureFormat::Bc3RgbaUnorm,
|
||||||
GPUTextureFormat::Bc4_r_unorm => wgt::TextureFormat::Bc4RUnorm,
|
GPUTextureFormat::Bc3_rgba_unorm_srgb => wgt::TextureFormat::Bc3RgbaUnormSrgb,
|
||||||
GPUTextureFormat::Bc4_r_snorm => wgt::TextureFormat::Bc4RSnorm,
|
GPUTextureFormat::Bc4_r_unorm => wgt::TextureFormat::Bc4RUnorm,
|
||||||
GPUTextureFormat::Bc5_rg_unorm => wgt::TextureFormat::Bc5RgUnorm,
|
GPUTextureFormat::Bc4_r_snorm => wgt::TextureFormat::Bc4RSnorm,
|
||||||
GPUTextureFormat::Bc5_rg_snorm => wgt::TextureFormat::Bc5RgSnorm,
|
GPUTextureFormat::Bc5_rg_unorm => wgt::TextureFormat::Bc5RgUnorm,
|
||||||
GPUTextureFormat::Bc6h_rgb_ufloat => wgt::TextureFormat::Bc6hRgbUfloat,
|
GPUTextureFormat::Bc5_rg_snorm => wgt::TextureFormat::Bc5RgSnorm,
|
||||||
GPUTextureFormat::Bc7_rgba_unorm => wgt::TextureFormat::Bc7RgbaUnorm,
|
GPUTextureFormat::Bc6h_rgb_ufloat => wgt::TextureFormat::Bc6hRgbUfloat,
|
||||||
GPUTextureFormat::Bc7_rgba_unorm_srgb => wgt::TextureFormat::Bc7RgbaUnormSrgb,
|
GPUTextureFormat::Bc7_rgba_unorm => wgt::TextureFormat::Bc7RgbaUnorm,
|
||||||
GPUTextureFormat::Bc6h_rgb_float => wgt::TextureFormat::Bc6hRgbFloat,
|
GPUTextureFormat::Bc7_rgba_unorm_srgb => wgt::TextureFormat::Bc7RgbaUnormSrgb,
|
||||||
GPUTextureFormat::Rgb9e5ufloat => wgt::TextureFormat::Rgb9e5Ufloat,
|
GPUTextureFormat::Bc6h_rgb_float => wgt::TextureFormat::Bc6hRgbFloat,
|
||||||
GPUTextureFormat::Rgb10a2uint => wgt::TextureFormat::Rgb10a2Uint,
|
GPUTextureFormat::Rgb9e5ufloat => wgt::TextureFormat::Rgb9e5Ufloat,
|
||||||
GPUTextureFormat::Rg11b10ufloat => wgt::TextureFormat::Rg11b10UFloat,
|
GPUTextureFormat::Rgb10a2uint => wgt::TextureFormat::Rgb10a2Uint,
|
||||||
GPUTextureFormat::Stencil8 => wgt::TextureFormat::Stencil8,
|
GPUTextureFormat::Rg11b10ufloat => wgt::TextureFormat::Rg11b10UFloat,
|
||||||
GPUTextureFormat::Depth16unorm => wgt::TextureFormat::Depth16Unorm,
|
GPUTextureFormat::Stencil8 => wgt::TextureFormat::Stencil8,
|
||||||
GPUTextureFormat::Depth32float_stencil8 => wgt::TextureFormat::Depth32FloatStencil8,
|
GPUTextureFormat::Depth16unorm => wgt::TextureFormat::Depth16Unorm,
|
||||||
GPUTextureFormat::Etc2_rgb8unorm => wgt::TextureFormat::Etc2Rgb8Unorm,
|
GPUTextureFormat::Depth32float_stencil8 => wgt::TextureFormat::Depth32FloatStencil8,
|
||||||
GPUTextureFormat::Etc2_rgb8unorm_srgb => wgt::TextureFormat::Etc2Rgb8UnormSrgb,
|
GPUTextureFormat::Etc2_rgb8unorm => wgt::TextureFormat::Etc2Rgb8Unorm,
|
||||||
GPUTextureFormat::Etc2_rgb8a1unorm => wgt::TextureFormat::Etc2Rgb8A1Unorm,
|
GPUTextureFormat::Etc2_rgb8unorm_srgb => wgt::TextureFormat::Etc2Rgb8UnormSrgb,
|
||||||
GPUTextureFormat::Etc2_rgb8a1unorm_srgb => wgt::TextureFormat::Etc2Rgb8A1UnormSrgb,
|
GPUTextureFormat::Etc2_rgb8a1unorm => wgt::TextureFormat::Etc2Rgb8A1Unorm,
|
||||||
GPUTextureFormat::Etc2_rgba8unorm => wgt::TextureFormat::Etc2Rgba8Unorm,
|
GPUTextureFormat::Etc2_rgb8a1unorm_srgb => wgt::TextureFormat::Etc2Rgb8A1UnormSrgb,
|
||||||
GPUTextureFormat::Etc2_rgba8unorm_srgb => wgt::TextureFormat::Etc2Rgba8UnormSrgb,
|
GPUTextureFormat::Etc2_rgba8unorm => wgt::TextureFormat::Etc2Rgba8Unorm,
|
||||||
GPUTextureFormat::Eac_r11unorm => wgt::TextureFormat::EacR11Unorm,
|
GPUTextureFormat::Etc2_rgba8unorm_srgb => wgt::TextureFormat::Etc2Rgba8UnormSrgb,
|
||||||
GPUTextureFormat::Eac_r11snorm => wgt::TextureFormat::EacR11Snorm,
|
GPUTextureFormat::Eac_r11unorm => wgt::TextureFormat::EacR11Unorm,
|
||||||
GPUTextureFormat::Eac_rg11unorm => wgt::TextureFormat::EacRg11Unorm,
|
GPUTextureFormat::Eac_r11snorm => wgt::TextureFormat::EacR11Snorm,
|
||||||
GPUTextureFormat::Eac_rg11snorm => wgt::TextureFormat::EacRg11Snorm,
|
GPUTextureFormat::Eac_rg11unorm => wgt::TextureFormat::EacRg11Unorm,
|
||||||
GPUTextureFormat::Astc_4x4_unorm => wgt::TextureFormat::Astc {
|
GPUTextureFormat::Eac_rg11snorm => wgt::TextureFormat::EacRg11Snorm,
|
||||||
block: AstcBlock::B4x4,
|
GPUTextureFormat::Astc_4x4_unorm => wgt::TextureFormat::Astc {
|
||||||
channel: AstcChannel::Unorm,
|
block: AstcBlock::B4x4,
|
||||||
},
|
channel: AstcChannel::Unorm,
|
||||||
GPUTextureFormat::Astc_4x4_unorm_srgb => wgt::TextureFormat::Astc {
|
|
||||||
block: AstcBlock::B4x4,
|
|
||||||
channel: AstcChannel::UnormSrgb,
|
|
||||||
},
|
|
||||||
GPUTextureFormat::Astc_5x4_unorm => wgt::TextureFormat::Astc {
|
|
||||||
block: AstcBlock::B5x4,
|
|
||||||
channel: AstcChannel::Unorm,
|
|
||||||
},
|
|
||||||
GPUTextureFormat::Astc_5x4_unorm_srgb => wgt::TextureFormat::Astc {
|
|
||||||
block: AstcBlock::B5x4,
|
|
||||||
channel: AstcChannel::UnormSrgb,
|
|
||||||
},
|
|
||||||
GPUTextureFormat::Astc_5x5_unorm => wgt::TextureFormat::Astc {
|
|
||||||
block: AstcBlock::B5x5,
|
|
||||||
channel: AstcChannel::Unorm,
|
|
||||||
},
|
|
||||||
GPUTextureFormat::Astc_5x5_unorm_srgb => wgt::TextureFormat::Astc {
|
|
||||||
block: AstcBlock::B5x5,
|
|
||||||
channel: AstcChannel::UnormSrgb,
|
|
||||||
},
|
|
||||||
GPUTextureFormat::Astc_6x5_unorm => wgt::TextureFormat::Astc {
|
|
||||||
block: AstcBlock::B6x5,
|
|
||||||
channel: AstcChannel::Unorm,
|
|
||||||
},
|
|
||||||
GPUTextureFormat::Astc_6x5_unorm_srgb => wgt::TextureFormat::Astc {
|
|
||||||
block: AstcBlock::B6x5,
|
|
||||||
channel: AstcChannel::UnormSrgb,
|
|
||||||
},
|
|
||||||
GPUTextureFormat::Astc_6x6_unorm => wgt::TextureFormat::Astc {
|
|
||||||
block: AstcBlock::B6x6,
|
|
||||||
channel: AstcChannel::Unorm,
|
|
||||||
},
|
|
||||||
GPUTextureFormat::Astc_6x6_unorm_srgb => wgt::TextureFormat::Astc {
|
|
||||||
block: AstcBlock::B6x6,
|
|
||||||
channel: AstcChannel::UnormSrgb,
|
|
||||||
},
|
|
||||||
GPUTextureFormat::Astc_8x5_unorm => wgt::TextureFormat::Astc {
|
|
||||||
block: AstcBlock::B8x5,
|
|
||||||
channel: AstcChannel::Unorm,
|
|
||||||
},
|
|
||||||
GPUTextureFormat::Astc_8x5_unorm_srgb => wgt::TextureFormat::Astc {
|
|
||||||
block: AstcBlock::B8x5,
|
|
||||||
channel: AstcChannel::UnormSrgb,
|
|
||||||
},
|
|
||||||
GPUTextureFormat::Astc_8x6_unorm => wgt::TextureFormat::Astc {
|
|
||||||
block: AstcBlock::B8x6,
|
|
||||||
channel: AstcChannel::Unorm,
|
|
||||||
},
|
|
||||||
GPUTextureFormat::Astc_8x6_unorm_srgb => wgt::TextureFormat::Astc {
|
|
||||||
block: AstcBlock::B8x6,
|
|
||||||
channel: AstcChannel::UnormSrgb,
|
|
||||||
},
|
|
||||||
GPUTextureFormat::Astc_8x8_unorm => wgt::TextureFormat::Astc {
|
|
||||||
block: AstcBlock::B8x8,
|
|
||||||
channel: AstcChannel::Unorm,
|
|
||||||
},
|
|
||||||
GPUTextureFormat::Astc_8x8_unorm_srgb => wgt::TextureFormat::Astc {
|
|
||||||
block: AstcBlock::B8x8,
|
|
||||||
channel: AstcChannel::UnormSrgb,
|
|
||||||
},
|
|
||||||
GPUTextureFormat::Astc_10x5_unorm => wgt::TextureFormat::Astc {
|
|
||||||
block: AstcBlock::B10x5,
|
|
||||||
channel: AstcChannel::Unorm,
|
|
||||||
},
|
|
||||||
GPUTextureFormat::Astc_10x5_unorm_srgb => wgt::TextureFormat::Astc {
|
|
||||||
block: AstcBlock::B10x5,
|
|
||||||
channel: AstcChannel::UnormSrgb,
|
|
||||||
},
|
|
||||||
GPUTextureFormat::Astc_10x6_unorm => wgt::TextureFormat::Astc {
|
|
||||||
block: AstcBlock::B10x6,
|
|
||||||
channel: AstcChannel::Unorm,
|
|
||||||
},
|
|
||||||
GPUTextureFormat::Astc_10x6_unorm_srgb => wgt::TextureFormat::Astc {
|
|
||||||
block: AstcBlock::B10x6,
|
|
||||||
channel: AstcChannel::UnormSrgb,
|
|
||||||
},
|
|
||||||
GPUTextureFormat::Astc_10x8_unorm => wgt::TextureFormat::Astc {
|
|
||||||
block: AstcBlock::B10x8,
|
|
||||||
channel: AstcChannel::Unorm,
|
|
||||||
},
|
|
||||||
GPUTextureFormat::Astc_10x8_unorm_srgb => wgt::TextureFormat::Astc {
|
|
||||||
block: AstcBlock::B10x8,
|
|
||||||
channel: AstcChannel::UnormSrgb,
|
|
||||||
},
|
|
||||||
GPUTextureFormat::Astc_10x10_unorm => wgt::TextureFormat::Astc {
|
|
||||||
block: AstcBlock::B10x10,
|
|
||||||
channel: AstcChannel::Unorm,
|
|
||||||
},
|
|
||||||
GPUTextureFormat::Astc_10x10_unorm_srgb => wgt::TextureFormat::Astc {
|
|
||||||
block: AstcBlock::B10x10,
|
|
||||||
channel: AstcChannel::UnormSrgb,
|
|
||||||
},
|
|
||||||
GPUTextureFormat::Astc_12x10_unorm => wgt::TextureFormat::Astc {
|
|
||||||
block: AstcBlock::B12x10,
|
|
||||||
channel: AstcChannel::Unorm,
|
|
||||||
},
|
|
||||||
GPUTextureFormat::Astc_12x10_unorm_srgb => wgt::TextureFormat::Astc {
|
|
||||||
block: AstcBlock::B12x10,
|
|
||||||
channel: AstcChannel::UnormSrgb,
|
|
||||||
},
|
|
||||||
GPUTextureFormat::Astc_12x12_unorm => wgt::TextureFormat::Astc {
|
|
||||||
block: AstcBlock::B12x12,
|
|
||||||
channel: AstcChannel::Unorm,
|
|
||||||
},
|
|
||||||
GPUTextureFormat::Astc_12x12_unorm_srgb => wgt::TextureFormat::Astc {
|
|
||||||
block: AstcBlock::B12x12,
|
|
||||||
channel: AstcChannel::UnormSrgb,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn convert_texture_view_dimension(
|
|
||||||
dimension: GPUTextureViewDimension,
|
|
||||||
) -> wgt::TextureViewDimension {
|
|
||||||
match dimension {
|
|
||||||
GPUTextureViewDimension::_1d => wgt::TextureViewDimension::D1,
|
|
||||||
GPUTextureViewDimension::_2d => wgt::TextureViewDimension::D2,
|
|
||||||
GPUTextureViewDimension::_2d_array => wgt::TextureViewDimension::D2Array,
|
|
||||||
GPUTextureViewDimension::Cube => wgt::TextureViewDimension::Cube,
|
|
||||||
GPUTextureViewDimension::Cube_array => wgt::TextureViewDimension::CubeArray,
|
|
||||||
GPUTextureViewDimension::_3d => wgt::TextureViewDimension::D3,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn convert_texture_size(size: &GPUExtent3D) -> Fallible<wgt::Extent3d> {
|
|
||||||
match *size {
|
|
||||||
GPUExtent3D::GPUExtent3DDict(ref dict) => Ok(wgt::Extent3d {
|
|
||||||
width: dict.width,
|
|
||||||
height: dict.height,
|
|
||||||
depth_or_array_layers: dict.depthOrArrayLayers,
|
|
||||||
}),
|
|
||||||
GPUExtent3D::RangeEnforcedUnsignedLongSequence(ref v) => {
|
|
||||||
// https://gpuweb.github.io/gpuweb/#abstract-opdef-validate-gpuextent3d-shape
|
|
||||||
if v.len() < 1 || v.len() > 3 {
|
|
||||||
Err(Error::Type(
|
|
||||||
"GPUExtent3D size must be between 1 and 3 (inclusive)".to_string(),
|
|
||||||
))
|
|
||||||
} else {
|
|
||||||
Ok(wgt::Extent3d {
|
|
||||||
width: v[0],
|
|
||||||
height: v.get(1).copied().unwrap_or(1),
|
|
||||||
depth_or_array_layers: v.get(2).copied().unwrap_or(1),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn convert_vertex_format(format: GPUVertexFormat) -> wgt::VertexFormat {
|
|
||||||
match format {
|
|
||||||
GPUVertexFormat::Uint8x2 => wgt::VertexFormat::Uint8x2,
|
|
||||||
GPUVertexFormat::Uint8x4 => wgt::VertexFormat::Uint8x4,
|
|
||||||
GPUVertexFormat::Sint8x2 => wgt::VertexFormat::Sint8x2,
|
|
||||||
GPUVertexFormat::Sint8x4 => wgt::VertexFormat::Sint8x4,
|
|
||||||
GPUVertexFormat::Unorm8x2 => wgt::VertexFormat::Unorm8x2,
|
|
||||||
GPUVertexFormat::Unorm8x4 => wgt::VertexFormat::Unorm8x4,
|
|
||||||
GPUVertexFormat::Snorm8x2 => wgt::VertexFormat::Unorm8x2,
|
|
||||||
GPUVertexFormat::Snorm8x4 => wgt::VertexFormat::Unorm8x4,
|
|
||||||
GPUVertexFormat::Uint16x2 => wgt::VertexFormat::Uint16x2,
|
|
||||||
GPUVertexFormat::Uint16x4 => wgt::VertexFormat::Uint16x4,
|
|
||||||
GPUVertexFormat::Sint16x2 => wgt::VertexFormat::Sint16x2,
|
|
||||||
GPUVertexFormat::Sint16x4 => wgt::VertexFormat::Sint16x4,
|
|
||||||
GPUVertexFormat::Unorm16x2 => wgt::VertexFormat::Unorm16x2,
|
|
||||||
GPUVertexFormat::Unorm16x4 => wgt::VertexFormat::Unorm16x4,
|
|
||||||
GPUVertexFormat::Snorm16x2 => wgt::VertexFormat::Snorm16x2,
|
|
||||||
GPUVertexFormat::Snorm16x4 => wgt::VertexFormat::Snorm16x4,
|
|
||||||
GPUVertexFormat::Float16x2 => wgt::VertexFormat::Float16x2,
|
|
||||||
GPUVertexFormat::Float16x4 => wgt::VertexFormat::Float16x4,
|
|
||||||
GPUVertexFormat::Float32 => wgt::VertexFormat::Float32,
|
|
||||||
GPUVertexFormat::Float32x2 => wgt::VertexFormat::Float32x2,
|
|
||||||
GPUVertexFormat::Float32x3 => wgt::VertexFormat::Float32x3,
|
|
||||||
GPUVertexFormat::Float32x4 => wgt::VertexFormat::Float32x4,
|
|
||||||
GPUVertexFormat::Uint32 => wgt::VertexFormat::Uint32,
|
|
||||||
GPUVertexFormat::Uint32x2 => wgt::VertexFormat::Uint32x2,
|
|
||||||
GPUVertexFormat::Uint32x3 => wgt::VertexFormat::Uint32x3,
|
|
||||||
GPUVertexFormat::Uint32x4 => wgt::VertexFormat::Uint32x4,
|
|
||||||
GPUVertexFormat::Sint32 => wgt::VertexFormat::Sint32,
|
|
||||||
GPUVertexFormat::Sint32x2 => wgt::VertexFormat::Sint32x2,
|
|
||||||
GPUVertexFormat::Sint32x3 => wgt::VertexFormat::Sint32x3,
|
|
||||||
GPUVertexFormat::Sint32x4 => wgt::VertexFormat::Sint32x4,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn convert_primitive_state(primitive_state: &GPUPrimitiveState) -> wgt::PrimitiveState {
|
|
||||||
wgt::PrimitiveState {
|
|
||||||
topology: convert_primitive_topology(&primitive_state.topology),
|
|
||||||
strip_index_format: primitive_state.stripIndexFormat.map(
|
|
||||||
|index_format| match index_format {
|
|
||||||
GPUIndexFormat::Uint16 => wgt::IndexFormat::Uint16,
|
|
||||||
GPUIndexFormat::Uint32 => wgt::IndexFormat::Uint32,
|
|
||||||
},
|
},
|
||||||
),
|
GPUTextureFormat::Astc_4x4_unorm_srgb => wgt::TextureFormat::Astc {
|
||||||
front_face: match primitive_state.frontFace {
|
block: AstcBlock::B4x4,
|
||||||
GPUFrontFace::Ccw => wgt::FrontFace::Ccw,
|
channel: AstcChannel::UnormSrgb,
|
||||||
GPUFrontFace::Cw => wgt::FrontFace::Cw,
|
},
|
||||||
},
|
GPUTextureFormat::Astc_5x4_unorm => wgt::TextureFormat::Astc {
|
||||||
cull_mode: match primitive_state.cullMode {
|
block: AstcBlock::B5x4,
|
||||||
GPUCullMode::None => None,
|
channel: AstcChannel::Unorm,
|
||||||
GPUCullMode::Front => Some(wgt::Face::Front),
|
},
|
||||||
GPUCullMode::Back => Some(wgt::Face::Back),
|
GPUTextureFormat::Astc_5x4_unorm_srgb => wgt::TextureFormat::Astc {
|
||||||
},
|
block: AstcBlock::B5x4,
|
||||||
unclipped_depth: primitive_state.clampDepth,
|
channel: AstcChannel::UnormSrgb,
|
||||||
..Default::default()
|
},
|
||||||
|
GPUTextureFormat::Astc_5x5_unorm => wgt::TextureFormat::Astc {
|
||||||
|
block: AstcBlock::B5x5,
|
||||||
|
channel: AstcChannel::Unorm,
|
||||||
|
},
|
||||||
|
GPUTextureFormat::Astc_5x5_unorm_srgb => wgt::TextureFormat::Astc {
|
||||||
|
block: AstcBlock::B5x5,
|
||||||
|
channel: AstcChannel::UnormSrgb,
|
||||||
|
},
|
||||||
|
GPUTextureFormat::Astc_6x5_unorm => wgt::TextureFormat::Astc {
|
||||||
|
block: AstcBlock::B6x5,
|
||||||
|
channel: AstcChannel::Unorm,
|
||||||
|
},
|
||||||
|
GPUTextureFormat::Astc_6x5_unorm_srgb => wgt::TextureFormat::Astc {
|
||||||
|
block: AstcBlock::B6x5,
|
||||||
|
channel: AstcChannel::UnormSrgb,
|
||||||
|
},
|
||||||
|
GPUTextureFormat::Astc_6x6_unorm => wgt::TextureFormat::Astc {
|
||||||
|
block: AstcBlock::B6x6,
|
||||||
|
channel: AstcChannel::Unorm,
|
||||||
|
},
|
||||||
|
GPUTextureFormat::Astc_6x6_unorm_srgb => wgt::TextureFormat::Astc {
|
||||||
|
block: AstcBlock::B6x6,
|
||||||
|
channel: AstcChannel::UnormSrgb,
|
||||||
|
},
|
||||||
|
GPUTextureFormat::Astc_8x5_unorm => wgt::TextureFormat::Astc {
|
||||||
|
block: AstcBlock::B8x5,
|
||||||
|
channel: AstcChannel::Unorm,
|
||||||
|
},
|
||||||
|
GPUTextureFormat::Astc_8x5_unorm_srgb => wgt::TextureFormat::Astc {
|
||||||
|
block: AstcBlock::B8x5,
|
||||||
|
channel: AstcChannel::UnormSrgb,
|
||||||
|
},
|
||||||
|
GPUTextureFormat::Astc_8x6_unorm => wgt::TextureFormat::Astc {
|
||||||
|
block: AstcBlock::B8x6,
|
||||||
|
channel: AstcChannel::Unorm,
|
||||||
|
},
|
||||||
|
GPUTextureFormat::Astc_8x6_unorm_srgb => wgt::TextureFormat::Astc {
|
||||||
|
block: AstcBlock::B8x6,
|
||||||
|
channel: AstcChannel::UnormSrgb,
|
||||||
|
},
|
||||||
|
GPUTextureFormat::Astc_8x8_unorm => wgt::TextureFormat::Astc {
|
||||||
|
block: AstcBlock::B8x8,
|
||||||
|
channel: AstcChannel::Unorm,
|
||||||
|
},
|
||||||
|
GPUTextureFormat::Astc_8x8_unorm_srgb => wgt::TextureFormat::Astc {
|
||||||
|
block: AstcBlock::B8x8,
|
||||||
|
channel: AstcChannel::UnormSrgb,
|
||||||
|
},
|
||||||
|
GPUTextureFormat::Astc_10x5_unorm => wgt::TextureFormat::Astc {
|
||||||
|
block: AstcBlock::B10x5,
|
||||||
|
channel: AstcChannel::Unorm,
|
||||||
|
},
|
||||||
|
GPUTextureFormat::Astc_10x5_unorm_srgb => wgt::TextureFormat::Astc {
|
||||||
|
block: AstcBlock::B10x5,
|
||||||
|
channel: AstcChannel::UnormSrgb,
|
||||||
|
},
|
||||||
|
GPUTextureFormat::Astc_10x6_unorm => wgt::TextureFormat::Astc {
|
||||||
|
block: AstcBlock::B10x6,
|
||||||
|
channel: AstcChannel::Unorm,
|
||||||
|
},
|
||||||
|
GPUTextureFormat::Astc_10x6_unorm_srgb => wgt::TextureFormat::Astc {
|
||||||
|
block: AstcBlock::B10x6,
|
||||||
|
channel: AstcChannel::UnormSrgb,
|
||||||
|
},
|
||||||
|
GPUTextureFormat::Astc_10x8_unorm => wgt::TextureFormat::Astc {
|
||||||
|
block: AstcBlock::B10x8,
|
||||||
|
channel: AstcChannel::Unorm,
|
||||||
|
},
|
||||||
|
GPUTextureFormat::Astc_10x8_unorm_srgb => wgt::TextureFormat::Astc {
|
||||||
|
block: AstcBlock::B10x8,
|
||||||
|
channel: AstcChannel::UnormSrgb,
|
||||||
|
},
|
||||||
|
GPUTextureFormat::Astc_10x10_unorm => wgt::TextureFormat::Astc {
|
||||||
|
block: AstcBlock::B10x10,
|
||||||
|
channel: AstcChannel::Unorm,
|
||||||
|
},
|
||||||
|
GPUTextureFormat::Astc_10x10_unorm_srgb => wgt::TextureFormat::Astc {
|
||||||
|
block: AstcBlock::B10x10,
|
||||||
|
channel: AstcChannel::UnormSrgb,
|
||||||
|
},
|
||||||
|
GPUTextureFormat::Astc_12x10_unorm => wgt::TextureFormat::Astc {
|
||||||
|
block: AstcBlock::B12x10,
|
||||||
|
channel: AstcChannel::Unorm,
|
||||||
|
},
|
||||||
|
GPUTextureFormat::Astc_12x10_unorm_srgb => wgt::TextureFormat::Astc {
|
||||||
|
block: AstcBlock::B12x10,
|
||||||
|
channel: AstcChannel::UnormSrgb,
|
||||||
|
},
|
||||||
|
GPUTextureFormat::Astc_12x12_unorm => wgt::TextureFormat::Astc {
|
||||||
|
block: AstcBlock::B12x12,
|
||||||
|
channel: AstcChannel::Unorm,
|
||||||
|
},
|
||||||
|
GPUTextureFormat::Astc_12x12_unorm_srgb => wgt::TextureFormat::Astc {
|
||||||
|
block: AstcBlock::B12x12,
|
||||||
|
channel: AstcChannel::UnormSrgb,
|
||||||
|
},
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn convert_primitive_topology(
|
impl TryFrom<&GPUExtent3D> for wgt::Extent3d {
|
||||||
primitive_topology: &GPUPrimitiveTopology,
|
type Error = Error;
|
||||||
) -> wgt::PrimitiveTopology {
|
|
||||||
match primitive_topology {
|
fn try_from(size: &GPUExtent3D) -> Result<Self, Self::Error> {
|
||||||
GPUPrimitiveTopology::Point_list => wgt::PrimitiveTopology::PointList,
|
match *size {
|
||||||
GPUPrimitiveTopology::Line_list => wgt::PrimitiveTopology::LineList,
|
GPUExtent3D::GPUExtent3DDict(ref dict) => Ok(wgt::Extent3d {
|
||||||
GPUPrimitiveTopology::Line_strip => wgt::PrimitiveTopology::LineStrip,
|
width: dict.width,
|
||||||
GPUPrimitiveTopology::Triangle_list => wgt::PrimitiveTopology::TriangleList,
|
height: dict.height,
|
||||||
GPUPrimitiveTopology::Triangle_strip => wgt::PrimitiveTopology::TriangleStrip,
|
depth_or_array_layers: dict.depthOrArrayLayers,
|
||||||
|
}),
|
||||||
|
GPUExtent3D::RangeEnforcedUnsignedLongSequence(ref v) => {
|
||||||
|
// https://gpuweb.github.io/gpuweb/#abstract-opdef-validate-gpuextent3d-shape
|
||||||
|
if v.len() < 1 || v.len() > 3 {
|
||||||
|
Err(Error::Type(
|
||||||
|
"GPUExtent3D size must be between 1 and 3 (inclusive)".to_string(),
|
||||||
|
))
|
||||||
|
} else {
|
||||||
|
Ok(wgt::Extent3d {
|
||||||
|
width: v[0],
|
||||||
|
height: v.get(1).copied().unwrap_or(1),
|
||||||
|
depth_or_array_layers: v.get(2).copied().unwrap_or(1),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn convert_address_mode(address_mode: GPUAddressMode) -> wgt::AddressMode {
|
impl From<&GPUImageDataLayout> for wgt::ImageDataLayout {
|
||||||
match address_mode {
|
fn from(data_layout: &GPUImageDataLayout) -> Self {
|
||||||
GPUAddressMode::Clamp_to_edge => wgt::AddressMode::ClampToEdge,
|
wgt::ImageDataLayout {
|
||||||
GPUAddressMode::Repeat => wgt::AddressMode::Repeat,
|
offset: data_layout.offset as wgt::BufferAddress,
|
||||||
GPUAddressMode::Mirror_repeat => wgt::AddressMode::MirrorRepeat,
|
bytes_per_row: data_layout.bytesPerRow,
|
||||||
|
rows_per_image: data_layout.rowsPerImage,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn convert_filter_mode(filter_mode: GPUFilterMode) -> wgt::FilterMode {
|
impl From<GPUVertexFormat> for wgt::VertexFormat {
|
||||||
match filter_mode {
|
fn from(format: GPUVertexFormat) -> Self {
|
||||||
GPUFilterMode::Nearest => wgt::FilterMode::Nearest,
|
match format {
|
||||||
GPUFilterMode::Linear => wgt::FilterMode::Linear,
|
GPUVertexFormat::Uint8x2 => wgt::VertexFormat::Uint8x2,
|
||||||
|
GPUVertexFormat::Uint8x4 => wgt::VertexFormat::Uint8x4,
|
||||||
|
GPUVertexFormat::Sint8x2 => wgt::VertexFormat::Sint8x2,
|
||||||
|
GPUVertexFormat::Sint8x4 => wgt::VertexFormat::Sint8x4,
|
||||||
|
GPUVertexFormat::Unorm8x2 => wgt::VertexFormat::Unorm8x2,
|
||||||
|
GPUVertexFormat::Unorm8x4 => wgt::VertexFormat::Unorm8x4,
|
||||||
|
GPUVertexFormat::Snorm8x2 => wgt::VertexFormat::Unorm8x2,
|
||||||
|
GPUVertexFormat::Snorm8x4 => wgt::VertexFormat::Unorm8x4,
|
||||||
|
GPUVertexFormat::Uint16x2 => wgt::VertexFormat::Uint16x2,
|
||||||
|
GPUVertexFormat::Uint16x4 => wgt::VertexFormat::Uint16x4,
|
||||||
|
GPUVertexFormat::Sint16x2 => wgt::VertexFormat::Sint16x2,
|
||||||
|
GPUVertexFormat::Sint16x4 => wgt::VertexFormat::Sint16x4,
|
||||||
|
GPUVertexFormat::Unorm16x2 => wgt::VertexFormat::Unorm16x2,
|
||||||
|
GPUVertexFormat::Unorm16x4 => wgt::VertexFormat::Unorm16x4,
|
||||||
|
GPUVertexFormat::Snorm16x2 => wgt::VertexFormat::Snorm16x2,
|
||||||
|
GPUVertexFormat::Snorm16x4 => wgt::VertexFormat::Snorm16x4,
|
||||||
|
GPUVertexFormat::Float16x2 => wgt::VertexFormat::Float16x2,
|
||||||
|
GPUVertexFormat::Float16x4 => wgt::VertexFormat::Float16x4,
|
||||||
|
GPUVertexFormat::Float32 => wgt::VertexFormat::Float32,
|
||||||
|
GPUVertexFormat::Float32x2 => wgt::VertexFormat::Float32x2,
|
||||||
|
GPUVertexFormat::Float32x3 => wgt::VertexFormat::Float32x3,
|
||||||
|
GPUVertexFormat::Float32x4 => wgt::VertexFormat::Float32x4,
|
||||||
|
GPUVertexFormat::Uint32 => wgt::VertexFormat::Uint32,
|
||||||
|
GPUVertexFormat::Uint32x2 => wgt::VertexFormat::Uint32x2,
|
||||||
|
GPUVertexFormat::Uint32x3 => wgt::VertexFormat::Uint32x3,
|
||||||
|
GPUVertexFormat::Uint32x4 => wgt::VertexFormat::Uint32x4,
|
||||||
|
GPUVertexFormat::Sint32 => wgt::VertexFormat::Sint32,
|
||||||
|
GPUVertexFormat::Sint32x2 => wgt::VertexFormat::Sint32x2,
|
||||||
|
GPUVertexFormat::Sint32x3 => wgt::VertexFormat::Sint32x3,
|
||||||
|
GPUVertexFormat::Sint32x4 => wgt::VertexFormat::Sint32x4,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn convert_view_dimension(
|
impl From<&GPUPrimitiveState> for wgt::PrimitiveState {
|
||||||
view_dimension: GPUTextureViewDimension,
|
fn from(primitive_state: &GPUPrimitiveState) -> Self {
|
||||||
) -> wgt::TextureViewDimension {
|
wgt::PrimitiveState {
|
||||||
match view_dimension {
|
topology: wgt::PrimitiveTopology::from(&primitive_state.topology),
|
||||||
GPUTextureViewDimension::_1d => wgt::TextureViewDimension::D1,
|
strip_index_format: primitive_state.stripIndexFormat.map(|index_format| {
|
||||||
GPUTextureViewDimension::_2d => wgt::TextureViewDimension::D2,
|
match index_format {
|
||||||
GPUTextureViewDimension::_2d_array => wgt::TextureViewDimension::D2Array,
|
GPUIndexFormat::Uint16 => wgt::IndexFormat::Uint16,
|
||||||
GPUTextureViewDimension::Cube => wgt::TextureViewDimension::Cube,
|
GPUIndexFormat::Uint32 => wgt::IndexFormat::Uint32,
|
||||||
GPUTextureViewDimension::Cube_array => wgt::TextureViewDimension::CubeArray,
|
}
|
||||||
GPUTextureViewDimension::_3d => wgt::TextureViewDimension::D3,
|
}),
|
||||||
|
front_face: match primitive_state.frontFace {
|
||||||
|
GPUFrontFace::Ccw => wgt::FrontFace::Ccw,
|
||||||
|
GPUFrontFace::Cw => wgt::FrontFace::Cw,
|
||||||
|
},
|
||||||
|
cull_mode: match primitive_state.cullMode {
|
||||||
|
GPUCullMode::None => None,
|
||||||
|
GPUCullMode::Front => Some(wgt::Face::Front),
|
||||||
|
GPUCullMode::Back => Some(wgt::Face::Back),
|
||||||
|
},
|
||||||
|
unclipped_depth: primitive_state.clampDepth,
|
||||||
|
..Default::default()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn convert_compare_function(compare: GPUCompareFunction) -> wgt::CompareFunction {
|
impl From<&GPUPrimitiveTopology> for wgt::PrimitiveTopology {
|
||||||
match compare {
|
fn from(primitive_topology: &GPUPrimitiveTopology) -> Self {
|
||||||
GPUCompareFunction::Never => wgt::CompareFunction::Never,
|
match primitive_topology {
|
||||||
GPUCompareFunction::Less => wgt::CompareFunction::Less,
|
GPUPrimitiveTopology::Point_list => wgt::PrimitiveTopology::PointList,
|
||||||
GPUCompareFunction::Equal => wgt::CompareFunction::Equal,
|
GPUPrimitiveTopology::Line_list => wgt::PrimitiveTopology::LineList,
|
||||||
GPUCompareFunction::Less_equal => wgt::CompareFunction::LessEqual,
|
GPUPrimitiveTopology::Line_strip => wgt::PrimitiveTopology::LineStrip,
|
||||||
GPUCompareFunction::Greater => wgt::CompareFunction::Greater,
|
GPUPrimitiveTopology::Triangle_list => wgt::PrimitiveTopology::TriangleList,
|
||||||
GPUCompareFunction::Not_equal => wgt::CompareFunction::NotEqual,
|
GPUPrimitiveTopology::Triangle_strip => wgt::PrimitiveTopology::TriangleStrip,
|
||||||
GPUCompareFunction::Greater_equal => wgt::CompareFunction::GreaterEqual,
|
}
|
||||||
GPUCompareFunction::Always => wgt::CompareFunction::Always,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn convert_blend_factor(factor: &GPUBlendFactor) -> wgt::BlendFactor {
|
impl From<GPUAddressMode> for wgt::AddressMode {
|
||||||
match factor {
|
fn from(address_mode: GPUAddressMode) -> Self {
|
||||||
GPUBlendFactor::Zero => wgt::BlendFactor::Zero,
|
match address_mode {
|
||||||
GPUBlendFactor::One => wgt::BlendFactor::One,
|
GPUAddressMode::Clamp_to_edge => wgt::AddressMode::ClampToEdge,
|
||||||
GPUBlendFactor::Src => wgt::BlendFactor::Src,
|
GPUAddressMode::Repeat => wgt::AddressMode::Repeat,
|
||||||
GPUBlendFactor::One_minus_src => wgt::BlendFactor::OneMinusSrc,
|
GPUAddressMode::Mirror_repeat => wgt::AddressMode::MirrorRepeat,
|
||||||
GPUBlendFactor::Src_alpha => wgt::BlendFactor::SrcAlpha,
|
}
|
||||||
GPUBlendFactor::One_minus_src_alpha => wgt::BlendFactor::OneMinusSrcAlpha,
|
|
||||||
GPUBlendFactor::Dst => wgt::BlendFactor::Dst,
|
|
||||||
GPUBlendFactor::One_minus_dst => wgt::BlendFactor::OneMinusDst,
|
|
||||||
GPUBlendFactor::Dst_alpha => wgt::BlendFactor::DstAlpha,
|
|
||||||
GPUBlendFactor::One_minus_dst_alpha => wgt::BlendFactor::OneMinusDstAlpha,
|
|
||||||
GPUBlendFactor::Src_alpha_saturated => wgt::BlendFactor::SrcAlphaSaturated,
|
|
||||||
GPUBlendFactor::Constant => wgt::BlendFactor::Constant,
|
|
||||||
GPUBlendFactor::One_minus_constant => wgt::BlendFactor::OneMinusConstant,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn convert_blend_component(blend_component: &GPUBlendComponent) -> wgt::BlendComponent {
|
impl From<GPUFilterMode> for wgt::FilterMode {
|
||||||
wgt::BlendComponent {
|
fn from(filter_mode: GPUFilterMode) -> Self {
|
||||||
src_factor: convert_blend_factor(&blend_component.srcFactor),
|
match filter_mode {
|
||||||
dst_factor: convert_blend_factor(&blend_component.dstFactor),
|
GPUFilterMode::Nearest => wgt::FilterMode::Nearest,
|
||||||
operation: match blend_component.operation {
|
GPUFilterMode::Linear => wgt::FilterMode::Linear,
|
||||||
GPUBlendOperation::Add => wgt::BlendOperation::Add,
|
}
|
||||||
GPUBlendOperation::Subtract => wgt::BlendOperation::Subtract,
|
}
|
||||||
GPUBlendOperation::Reverse_subtract => wgt::BlendOperation::ReverseSubtract,
|
}
|
||||||
GPUBlendOperation::Min => wgt::BlendOperation::Min,
|
|
||||||
GPUBlendOperation::Max => wgt::BlendOperation::Max,
|
impl From<GPUTextureViewDimension> for wgt::TextureViewDimension {
|
||||||
},
|
fn from(view_dimension: GPUTextureViewDimension) -> Self {
|
||||||
|
match view_dimension {
|
||||||
|
GPUTextureViewDimension::_1d => wgt::TextureViewDimension::D1,
|
||||||
|
GPUTextureViewDimension::_2d => wgt::TextureViewDimension::D2,
|
||||||
|
GPUTextureViewDimension::_2d_array => wgt::TextureViewDimension::D2Array,
|
||||||
|
GPUTextureViewDimension::Cube => wgt::TextureViewDimension::Cube,
|
||||||
|
GPUTextureViewDimension::Cube_array => wgt::TextureViewDimension::CubeArray,
|
||||||
|
GPUTextureViewDimension::_3d => wgt::TextureViewDimension::D3,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<GPUCompareFunction> for wgt::CompareFunction {
|
||||||
|
fn from(compare: GPUCompareFunction) -> Self {
|
||||||
|
match compare {
|
||||||
|
GPUCompareFunction::Never => wgt::CompareFunction::Never,
|
||||||
|
GPUCompareFunction::Less => wgt::CompareFunction::Less,
|
||||||
|
GPUCompareFunction::Equal => wgt::CompareFunction::Equal,
|
||||||
|
GPUCompareFunction::Less_equal => wgt::CompareFunction::LessEqual,
|
||||||
|
GPUCompareFunction::Greater => wgt::CompareFunction::Greater,
|
||||||
|
GPUCompareFunction::Not_equal => wgt::CompareFunction::NotEqual,
|
||||||
|
GPUCompareFunction::Greater_equal => wgt::CompareFunction::GreaterEqual,
|
||||||
|
GPUCompareFunction::Always => wgt::CompareFunction::Always,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<&GPUBlendFactor> for wgt::BlendFactor {
|
||||||
|
fn from(factor: &GPUBlendFactor) -> Self {
|
||||||
|
match factor {
|
||||||
|
GPUBlendFactor::Zero => wgt::BlendFactor::Zero,
|
||||||
|
GPUBlendFactor::One => wgt::BlendFactor::One,
|
||||||
|
GPUBlendFactor::Src => wgt::BlendFactor::Src,
|
||||||
|
GPUBlendFactor::One_minus_src => wgt::BlendFactor::OneMinusSrc,
|
||||||
|
GPUBlendFactor::Src_alpha => wgt::BlendFactor::SrcAlpha,
|
||||||
|
GPUBlendFactor::One_minus_src_alpha => wgt::BlendFactor::OneMinusSrcAlpha,
|
||||||
|
GPUBlendFactor::Dst => wgt::BlendFactor::Dst,
|
||||||
|
GPUBlendFactor::One_minus_dst => wgt::BlendFactor::OneMinusDst,
|
||||||
|
GPUBlendFactor::Dst_alpha => wgt::BlendFactor::DstAlpha,
|
||||||
|
GPUBlendFactor::One_minus_dst_alpha => wgt::BlendFactor::OneMinusDstAlpha,
|
||||||
|
GPUBlendFactor::Src_alpha_saturated => wgt::BlendFactor::SrcAlphaSaturated,
|
||||||
|
GPUBlendFactor::Constant => wgt::BlendFactor::Constant,
|
||||||
|
GPUBlendFactor::One_minus_constant => wgt::BlendFactor::OneMinusConstant,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<&GPUBlendComponent> for wgt::BlendComponent {
|
||||||
|
fn from(blend_component: &GPUBlendComponent) -> Self {
|
||||||
|
wgt::BlendComponent {
|
||||||
|
src_factor: wgt::BlendFactor::from(&blend_component.srcFactor),
|
||||||
|
dst_factor: wgt::BlendFactor::from(&blend_component.dstFactor),
|
||||||
|
operation: match blend_component.operation {
|
||||||
|
GPUBlendOperation::Add => wgt::BlendOperation::Add,
|
||||||
|
GPUBlendOperation::Subtract => wgt::BlendOperation::Subtract,
|
||||||
|
GPUBlendOperation::Reverse_subtract => wgt::BlendOperation::ReverseSubtract,
|
||||||
|
GPUBlendOperation::Min => wgt::BlendOperation::Min,
|
||||||
|
GPUBlendOperation::Max => wgt::BlendOperation::Max,
|
||||||
|
},
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -411,68 +420,78 @@ pub fn convert_store_op(op: Option<GPUStoreOp>) -> wgpu_com::StoreOp {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn convert_stencil_op(operation: GPUStencilOperation) -> wgt::StencilOperation {
|
impl From<GPUStencilOperation> for wgt::StencilOperation {
|
||||||
match operation {
|
fn from(operation: GPUStencilOperation) -> Self {
|
||||||
GPUStencilOperation::Keep => wgt::StencilOperation::Keep,
|
match operation {
|
||||||
GPUStencilOperation::Zero => wgt::StencilOperation::Zero,
|
GPUStencilOperation::Keep => wgt::StencilOperation::Keep,
|
||||||
GPUStencilOperation::Replace => wgt::StencilOperation::Replace,
|
GPUStencilOperation::Zero => wgt::StencilOperation::Zero,
|
||||||
GPUStencilOperation::Invert => wgt::StencilOperation::Invert,
|
GPUStencilOperation::Replace => wgt::StencilOperation::Replace,
|
||||||
GPUStencilOperation::Increment_clamp => wgt::StencilOperation::IncrementClamp,
|
GPUStencilOperation::Invert => wgt::StencilOperation::Invert,
|
||||||
GPUStencilOperation::Decrement_clamp => wgt::StencilOperation::DecrementClamp,
|
GPUStencilOperation::Increment_clamp => wgt::StencilOperation::IncrementClamp,
|
||||||
GPUStencilOperation::Increment_wrap => wgt::StencilOperation::IncrementWrap,
|
GPUStencilOperation::Decrement_clamp => wgt::StencilOperation::DecrementClamp,
|
||||||
GPUStencilOperation::Decrement_wrap => wgt::StencilOperation::DecrementWrap,
|
GPUStencilOperation::Increment_wrap => wgt::StencilOperation::IncrementWrap,
|
||||||
|
GPUStencilOperation::Decrement_wrap => wgt::StencilOperation::DecrementWrap,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn convert_ic_buffer(ic_buffer: &GPUImageCopyBuffer) -> wgpu_com::ImageCopyBuffer {
|
impl From<&GPUImageCopyBuffer> for wgpu_com::ImageCopyBuffer {
|
||||||
wgpu_com::ImageCopyBuffer {
|
fn from(ic_buffer: &GPUImageCopyBuffer) -> Self {
|
||||||
buffer: ic_buffer.buffer.id().0,
|
wgpu_com::ImageCopyBuffer {
|
||||||
layout: convert_image_data_layout(&ic_buffer.parent),
|
buffer: ic_buffer.buffer.id().0,
|
||||||
|
layout: wgt::ImageDataLayout::from(&ic_buffer.parent),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn convert_origin3d(origin: &GPUOrigin3D) -> Fallible<wgt::Origin3d> {
|
impl TryFrom<&GPUOrigin3D> for wgt::Origin3d {
|
||||||
match origin {
|
type Error = Error;
|
||||||
GPUOrigin3D::RangeEnforcedUnsignedLongSequence(v) => {
|
|
||||||
// https://gpuweb.github.io/gpuweb/#abstract-opdef-validate-gpuorigin3d-shape
|
fn try_from(origin: &GPUOrigin3D) -> Result<Self, Self::Error> {
|
||||||
if v.len() > 3 {
|
match origin {
|
||||||
Err(Error::Type(
|
GPUOrigin3D::RangeEnforcedUnsignedLongSequence(v) => {
|
||||||
"sequence is too long for GPUOrigin3D".to_string(),
|
// https://gpuweb.github.io/gpuweb/#abstract-opdef-validate-gpuorigin3d-shape
|
||||||
))
|
if v.len() > 3 {
|
||||||
} else {
|
Err(Error::Type(
|
||||||
Ok(wgt::Origin3d {
|
"sequence is too long for GPUOrigin3D".to_string(),
|
||||||
x: v.get(0).copied().unwrap_or(0),
|
))
|
||||||
y: v.get(1).copied().unwrap_or(0),
|
} else {
|
||||||
z: v.get(2).copied().unwrap_or(0),
|
Ok(wgt::Origin3d {
|
||||||
})
|
x: v.get(0).copied().unwrap_or(0),
|
||||||
}
|
y: v.get(1).copied().unwrap_or(0),
|
||||||
},
|
z: v.get(2).copied().unwrap_or(0),
|
||||||
GPUOrigin3D::GPUOrigin3DDict(d) => Ok(wgt::Origin3d {
|
})
|
||||||
x: d.x,
|
}
|
||||||
y: d.y,
|
},
|
||||||
z: d.z,
|
GPUOrigin3D::GPUOrigin3DDict(d) => Ok(wgt::Origin3d {
|
||||||
}),
|
x: d.x,
|
||||||
|
y: d.y,
|
||||||
|
z: d.z,
|
||||||
|
}),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn convert_ic_texture(
|
impl TryFrom<&GPUImageCopyTexture> for wgpu_com::ImageCopyTexture {
|
||||||
ic_texture: &GPUImageCopyTexture,
|
type Error = Error;
|
||||||
) -> Fallible<wgpu_com::ImageCopyTexture> {
|
|
||||||
Ok(wgpu_com::ImageCopyTexture {
|
fn try_from(ic_texture: &GPUImageCopyTexture) -> Result<Self, Self::Error> {
|
||||||
texture: ic_texture.texture.id().0,
|
Ok(wgpu_com::ImageCopyTexture {
|
||||||
mip_level: ic_texture.mipLevel,
|
texture: ic_texture.texture.id().0,
|
||||||
origin: ic_texture
|
mip_level: ic_texture.mipLevel,
|
||||||
.origin
|
origin: ic_texture
|
||||||
.as_ref()
|
.origin
|
||||||
.map(|origin| convert_origin3d(origin))
|
.as_ref()
|
||||||
.transpose()?
|
.map(|origin| wgt::Origin3d::try_from(origin))
|
||||||
.unwrap_or_default(),
|
.transpose()?
|
||||||
aspect: match ic_texture.aspect {
|
.unwrap_or_default(),
|
||||||
GPUTextureAspect::All => wgt::TextureAspect::All,
|
aspect: match ic_texture.aspect {
|
||||||
GPUTextureAspect::Stencil_only => wgt::TextureAspect::StencilOnly,
|
GPUTextureAspect::All => wgt::TextureAspect::All,
|
||||||
GPUTextureAspect::Depth_only => wgt::TextureAspect::DepthOnly,
|
GPUTextureAspect::Stencil_only => wgt::TextureAspect::StencilOnly,
|
||||||
},
|
GPUTextureAspect::Depth_only => wgt::TextureAspect::DepthOnly,
|
||||||
})
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn convert_label<'a>(parent: &GPUObjectDescriptorBase) -> Option<Cow<'a, str>> {
|
pub fn convert_label<'a>(parent: &GPUObjectDescriptorBase) -> Option<Cow<'a, str>> {
|
||||||
|
@ -519,7 +538,7 @@ pub fn convert_bind_group_layout_entry(
|
||||||
GPUStorageTextureAccess::Read_write => wgt::StorageTextureAccess::ReadWrite,
|
GPUStorageTextureAccess::Read_write => wgt::StorageTextureAccess::ReadWrite,
|
||||||
},
|
},
|
||||||
format: device.validate_texture_format_required_features(&storage.format)?,
|
format: device.validate_texture_format_required_features(&storage.format)?,
|
||||||
view_dimension: convert_view_dimension(storage.viewDimension),
|
view_dimension: storage.viewDimension.into(),
|
||||||
})
|
})
|
||||||
} else if let Some(texture) = &bgle.texture {
|
} else if let Some(texture) = &bgle.texture {
|
||||||
Some(wgt::BindingType::Texture {
|
Some(wgt::BindingType::Texture {
|
||||||
|
@ -532,7 +551,7 @@ pub fn convert_bind_group_layout_entry(
|
||||||
GPUTextureSampleType::Sint => wgt::TextureSampleType::Sint,
|
GPUTextureSampleType::Sint => wgt::TextureSampleType::Sint,
|
||||||
GPUTextureSampleType::Uint => wgt::TextureSampleType::Uint,
|
GPUTextureSampleType::Uint => wgt::TextureSampleType::Uint,
|
||||||
},
|
},
|
||||||
view_dimension: convert_view_dimension(texture.viewDimension),
|
view_dimension: texture.viewDimension.into(),
|
||||||
multisampled: texture.multisampled,
|
multisampled: texture.multisampled,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
|
@ -558,27 +577,31 @@ pub fn convert_bind_group_layout_entry(
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn convert_color(color: &GPUColor) -> Fallible<wgt::Color> {
|
impl TryFrom<&GPUColor> for wgt::Color {
|
||||||
match color {
|
type Error = Error;
|
||||||
GPUColor::DoubleSequence(s) => {
|
|
||||||
// https://gpuweb.github.io/gpuweb/#abstract-opdef-validate-gpucolor-shape
|
fn try_from(color: &GPUColor) -> Result<Self, Self::Error> {
|
||||||
if s.len() != 4 {
|
match color {
|
||||||
Err(Error::Type("GPUColor sequence must be len 4".to_string()))
|
GPUColor::DoubleSequence(s) => {
|
||||||
} else {
|
// https://gpuweb.github.io/gpuweb/#abstract-opdef-validate-gpucolor-shape
|
||||||
Ok(wgt::Color {
|
if s.len() != 4 {
|
||||||
r: *s[0],
|
Err(Error::Type("GPUColor sequence must be len 4".to_string()))
|
||||||
g: *s[1],
|
} else {
|
||||||
b: *s[2],
|
Ok(wgt::Color {
|
||||||
a: *s[3],
|
r: *s[0],
|
||||||
})
|
g: *s[1],
|
||||||
}
|
b: *s[2],
|
||||||
},
|
a: *s[3],
|
||||||
GPUColor::GPUColorDict(d) => Ok(wgt::Color {
|
})
|
||||||
r: *d.r,
|
}
|
||||||
g: *d.g,
|
},
|
||||||
b: *d.b,
|
GPUColor::GPUColorDict(d) => Ok(wgt::Color {
|
||||||
a: *d.a,
|
r: *d.r,
|
||||||
}),
|
g: *d.g,
|
||||||
|
b: *d.b,
|
||||||
|
a: *d.a,
|
||||||
|
}),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@ use webgpu::wgc::pipeline::RenderPipelineDescriptor;
|
||||||
use webgpu::wgc::{
|
use webgpu::wgc::{
|
||||||
binding_model as wgpu_bind, command as wgpu_com, pipeline as wgpu_pipe, resource as wgpu_res,
|
binding_model as wgpu_bind, command as wgpu_com, pipeline as wgpu_pipe, resource as wgpu_res,
|
||||||
};
|
};
|
||||||
use webgpu::wgt::TextureFormat;
|
use webgpu::wgt::{BlendComponent, TextureFormat};
|
||||||
use webgpu::{
|
use webgpu::{
|
||||||
self, wgt, PopError, WebGPU, WebGPUComputePipeline, WebGPURenderPipeline, WebGPURequest,
|
self, wgt, PopError, WebGPU, WebGPUComputePipeline, WebGPURenderPipeline, WebGPURequest,
|
||||||
WebGPUResponse,
|
WebGPUResponse,
|
||||||
|
@ -57,11 +57,7 @@ use crate::dom::gpubindgrouplayout::GPUBindGroupLayout;
|
||||||
use crate::dom::gpubuffer::{ActiveBufferMapping, GPUBuffer};
|
use crate::dom::gpubuffer::{ActiveBufferMapping, GPUBuffer};
|
||||||
use crate::dom::gpucommandencoder::GPUCommandEncoder;
|
use crate::dom::gpucommandencoder::GPUCommandEncoder;
|
||||||
use crate::dom::gpucomputepipeline::GPUComputePipeline;
|
use crate::dom::gpucomputepipeline::GPUComputePipeline;
|
||||||
use crate::dom::gpuconvert::{
|
use crate::dom::gpuconvert::convert_label;
|
||||||
convert_address_mode, convert_blend_component, convert_compare_function, convert_filter_mode,
|
|
||||||
convert_label, convert_primitive_state, convert_stencil_op, convert_texture_format,
|
|
||||||
convert_texture_size, convert_vertex_format,
|
|
||||||
};
|
|
||||||
use crate::dom::gpupipelinelayout::GPUPipelineLayout;
|
use crate::dom::gpupipelinelayout::GPUPipelineLayout;
|
||||||
use crate::dom::gpuqueue::GPUQueue;
|
use crate::dom::gpuqueue::GPUQueue;
|
||||||
use crate::dom::gpurenderbundleencoder::GPURenderBundleEncoder;
|
use crate::dom::gpurenderbundleencoder::GPURenderBundleEncoder;
|
||||||
|
@ -197,7 +193,7 @@ impl GPUDevice {
|
||||||
&self,
|
&self,
|
||||||
format: &GPUTextureFormat,
|
format: &GPUTextureFormat,
|
||||||
) -> Fallible<TextureFormat> {
|
) -> Fallible<TextureFormat> {
|
||||||
let texture_format = convert_texture_format(*format);
|
let texture_format: TextureFormat = (*format).into();
|
||||||
if self
|
if self
|
||||||
.features
|
.features
|
||||||
.wgpu_features()
|
.wgpu_features()
|
||||||
|
@ -276,7 +272,7 @@ impl GPUDevice {
|
||||||
.attributes
|
.attributes
|
||||||
.iter()
|
.iter()
|
||||||
.map(|att| wgt::VertexAttribute {
|
.map(|att| wgt::VertexAttribute {
|
||||||
format: convert_vertex_format(att.format),
|
format: att.format.into(),
|
||||||
offset: att.offset,
|
offset: att.offset,
|
||||||
shader_location: att.shaderLocation,
|
shader_location: att.shaderLocation,
|
||||||
})
|
})
|
||||||
|
@ -306,12 +302,8 @@ impl GPUDevice {
|
||||||
),
|
),
|
||||||
blend: state.blend.as_ref().map(|blend| {
|
blend: state.blend.as_ref().map(|blend| {
|
||||||
wgt::BlendState {
|
wgt::BlendState {
|
||||||
color: convert_blend_component(
|
color: (&blend.color).into(),
|
||||||
&blend.color,
|
alpha: (&blend.alpha).into(),
|
||||||
),
|
|
||||||
alpha: convert_blend_component(
|
|
||||||
&blend.alpha,
|
|
||||||
),
|
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
|
@ -322,7 +314,7 @@ impl GPUDevice {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.transpose()?,
|
.transpose()?,
|
||||||
primitive: convert_primitive_state(&descriptor.primitive),
|
primitive: (&descriptor.primitive).into(),
|
||||||
depth_stencil: descriptor
|
depth_stencil: descriptor
|
||||||
.depthStencil
|
.depthStencil
|
||||||
.as_ref()
|
.as_ref()
|
||||||
|
@ -331,25 +323,20 @@ impl GPUDevice {
|
||||||
.map(|format| wgt::DepthStencilState {
|
.map(|format| wgt::DepthStencilState {
|
||||||
format,
|
format,
|
||||||
depth_write_enabled: dss_desc.depthWriteEnabled,
|
depth_write_enabled: dss_desc.depthWriteEnabled,
|
||||||
depth_compare: convert_compare_function(dss_desc.depthCompare),
|
depth_compare: dss_desc.depthCompare.into(),
|
||||||
stencil: wgt::StencilState {
|
stencil: wgt::StencilState {
|
||||||
front: wgt::StencilFaceState {
|
front: wgt::StencilFaceState {
|
||||||
compare: convert_compare_function(
|
compare: dss_desc.stencilFront.compare.into(),
|
||||||
dss_desc.stencilFront.compare,
|
|
||||||
),
|
fail_op: dss_desc.stencilFront.failOp.into(),
|
||||||
fail_op: convert_stencil_op(dss_desc.stencilFront.failOp),
|
depth_fail_op: dss_desc.stencilFront.depthFailOp.into(),
|
||||||
depth_fail_op: convert_stencil_op(
|
pass_op: dss_desc.stencilFront.passOp.into(),
|
||||||
dss_desc.stencilFront.depthFailOp,
|
|
||||||
),
|
|
||||||
pass_op: convert_stencil_op(dss_desc.stencilFront.passOp),
|
|
||||||
},
|
},
|
||||||
back: wgt::StencilFaceState {
|
back: wgt::StencilFaceState {
|
||||||
compare: convert_compare_function(dss_desc.stencilBack.compare),
|
compare: dss_desc.stencilBack.compare.into(),
|
||||||
fail_op: convert_stencil_op(dss_desc.stencilBack.failOp),
|
fail_op: dss_desc.stencilBack.failOp.into(),
|
||||||
depth_fail_op: convert_stencil_op(
|
depth_fail_op: dss_desc.stencilBack.depthFailOp.into(),
|
||||||
dss_desc.stencilBack.depthFailOp,
|
pass_op: dss_desc.stencilBack.passOp.into(),
|
||||||
),
|
|
||||||
pass_op: convert_stencil_op(dss_desc.stencilBack.passOp),
|
|
||||||
},
|
},
|
||||||
read_mask: dss_desc.stencilReadMask,
|
read_mask: dss_desc.stencilReadMask,
|
||||||
write_mask: dss_desc.stencilWriteMask,
|
write_mask: dss_desc.stencilWriteMask,
|
||||||
|
@ -742,7 +729,7 @@ impl GPUDeviceMethods for GPUDevice {
|
||||||
|
|
||||||
/// <https://gpuweb.github.io/gpuweb/#dom-gpudevice-createtexture>
|
/// <https://gpuweb.github.io/gpuweb/#dom-gpudevice-createtexture>
|
||||||
fn CreateTexture(&self, descriptor: &GPUTextureDescriptor) -> Fallible<DomRoot<GPUTexture>> {
|
fn CreateTexture(&self, descriptor: &GPUTextureDescriptor) -> Fallible<DomRoot<GPUTexture>> {
|
||||||
let size = convert_texture_size(&descriptor.size)?;
|
let size = (&descriptor.size).try_into()?;
|
||||||
let desc = wgpu_res::TextureDescriptor {
|
let desc = wgpu_res::TextureDescriptor {
|
||||||
label: convert_label(&descriptor.parent),
|
label: convert_label(&descriptor.parent),
|
||||||
size,
|
size,
|
||||||
|
@ -803,16 +790,18 @@ impl GPUDeviceMethods for GPUDevice {
|
||||||
let desc = wgpu_res::SamplerDescriptor {
|
let desc = wgpu_res::SamplerDescriptor {
|
||||||
label: convert_label(&descriptor.parent),
|
label: convert_label(&descriptor.parent),
|
||||||
address_modes: [
|
address_modes: [
|
||||||
convert_address_mode(descriptor.addressModeU),
|
descriptor.addressModeU.into(),
|
||||||
convert_address_mode(descriptor.addressModeV),
|
descriptor.addressModeV.into(),
|
||||||
convert_address_mode(descriptor.addressModeW),
|
descriptor.addressModeW.into(),
|
||||||
],
|
],
|
||||||
mag_filter: convert_filter_mode(descriptor.magFilter),
|
mag_filter: descriptor.magFilter.into(),
|
||||||
min_filter: convert_filter_mode(descriptor.minFilter),
|
min_filter: descriptor.minFilter.into(),
|
||||||
mipmap_filter: convert_filter_mode(descriptor.mipmapFilter),
|
mipmap_filter: descriptor.mipmapFilter.into(),
|
||||||
lod_min_clamp: *descriptor.lodMinClamp,
|
lod_min_clamp: *descriptor.lodMinClamp,
|
||||||
lod_max_clamp: *descriptor.lodMaxClamp,
|
lod_max_clamp: *descriptor.lodMaxClamp,
|
||||||
compare: descriptor.compare.map(convert_compare_function),
|
compare: descriptor
|
||||||
|
.compare
|
||||||
|
.map(|gpu_compare_function| gpu_compare_function.into()),
|
||||||
anisotropy_clamp: 1,
|
anisotropy_clamp: 1,
|
||||||
border_color: None,
|
border_color: None,
|
||||||
};
|
};
|
||||||
|
|
|
@ -6,6 +6,7 @@ use std::rc::Rc;
|
||||||
|
|
||||||
use dom_struct::dom_struct;
|
use dom_struct::dom_struct;
|
||||||
use ipc_channel::ipc::IpcSharedMemory;
|
use ipc_channel::ipc::IpcSharedMemory;
|
||||||
|
use webgpu::wgt::Extent3d;
|
||||||
use webgpu::{wgt, WebGPU, WebGPUQueue, WebGPURequest, WebGPUResponse};
|
use webgpu::{wgt, WebGPU, WebGPUQueue, WebGPURequest, WebGPUResponse};
|
||||||
|
|
||||||
use super::bindings::codegen::Bindings::WebGPUBinding::{GPUImageCopyTexture, GPUImageDataLayout};
|
use super::bindings::codegen::Bindings::WebGPUBinding::{GPUImageCopyTexture, GPUImageDataLayout};
|
||||||
|
@ -22,7 +23,6 @@ use crate::dom::bindings::str::USVString;
|
||||||
use crate::dom::globalscope::GlobalScope;
|
use crate::dom::globalscope::GlobalScope;
|
||||||
use crate::dom::gpubuffer::GPUBuffer;
|
use crate::dom::gpubuffer::GPUBuffer;
|
||||||
use crate::dom::gpucommandbuffer::GPUCommandBuffer;
|
use crate::dom::gpucommandbuffer::GPUCommandBuffer;
|
||||||
use crate::dom::gpuconvert::{convert_ic_texture, convert_image_data_layout, convert_texture_size};
|
|
||||||
use crate::dom::gpudevice::GPUDevice;
|
use crate::dom::gpudevice::GPUDevice;
|
||||||
use crate::dom::promise::Promise;
|
use crate::dom::promise::Promise;
|
||||||
|
|
||||||
|
@ -163,9 +163,9 @@ impl GPUQueueMethods for GPUQueue {
|
||||||
return Err(Error::Operation);
|
return Err(Error::Operation);
|
||||||
}
|
}
|
||||||
|
|
||||||
let texture_cv = convert_ic_texture(destination)?;
|
let texture_cv = destination.try_into()?;
|
||||||
let texture_layout = convert_image_data_layout(data_layout);
|
let texture_layout = data_layout.into();
|
||||||
let write_size = convert_texture_size(&size)?;
|
let write_size = (&size).try_into()?;
|
||||||
let final_data = IpcSharedMemory::from_bytes(&bytes);
|
let final_data = IpcSharedMemory::from_bytes(&bytes);
|
||||||
|
|
||||||
if let Err(e) = self.channel.0.send(WebGPURequest::WriteTexture {
|
if let Err(e) = self.channel.0.send(WebGPURequest::WriteTexture {
|
||||||
|
|
|
@ -19,7 +19,6 @@ use crate::dom::globalscope::GlobalScope;
|
||||||
use crate::dom::gpubindgroup::GPUBindGroup;
|
use crate::dom::gpubindgroup::GPUBindGroup;
|
||||||
use crate::dom::gpubuffer::GPUBuffer;
|
use crate::dom::gpubuffer::GPUBuffer;
|
||||||
use crate::dom::gpucommandencoder::GPUCommandEncoder;
|
use crate::dom::gpucommandencoder::GPUCommandEncoder;
|
||||||
use crate::dom::gpuconvert::convert_color;
|
|
||||||
use crate::dom::gpurenderbundle::GPURenderBundle;
|
use crate::dom::gpurenderbundle::GPURenderBundle;
|
||||||
use crate::dom::gpurenderpipeline::GPURenderPipeline;
|
use crate::dom::gpurenderpipeline::GPURenderPipeline;
|
||||||
|
|
||||||
|
@ -132,7 +131,7 @@ impl GPURenderPassEncoderMethods for GPURenderPassEncoder {
|
||||||
|
|
||||||
/// <https://gpuweb.github.io/gpuweb/#dom-gpurenderpassencoder-setblendcolor>
|
/// <https://gpuweb.github.io/gpuweb/#dom-gpurenderpassencoder-setblendcolor>
|
||||||
fn SetBlendConstant(&self, color: GPUColor) -> Fallible<()> {
|
fn SetBlendConstant(&self, color: GPUColor) -> Fallible<()> {
|
||||||
self.send_render_command(RenderCommand::SetBlendConstant(convert_color(&color)?));
|
self.send_render_command(RenderCommand::SetBlendConstant((&color).try_into()?));
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector};
|
||||||
use crate::dom::bindings::root::{Dom, DomRoot};
|
use crate::dom::bindings::root::{Dom, DomRoot};
|
||||||
use crate::dom::bindings::str::USVString;
|
use crate::dom::bindings::str::USVString;
|
||||||
use crate::dom::globalscope::GlobalScope;
|
use crate::dom::globalscope::GlobalScope;
|
||||||
use crate::dom::gpuconvert::{convert_label, convert_texture_view_dimension};
|
use crate::dom::gpuconvert::convert_label;
|
||||||
use crate::dom::gpudevice::GPUDevice;
|
use crate::dom::gpudevice::GPUDevice;
|
||||||
use crate::dom::gputextureview::GPUTextureView;
|
use crate::dom::gputextureview::GPUTextureView;
|
||||||
|
|
||||||
|
@ -155,7 +155,7 @@ impl GPUTextureMethods for GPUTexture {
|
||||||
.format
|
.format
|
||||||
.map(|f| self.device.validate_texture_format_required_features(&f))
|
.map(|f| self.device.validate_texture_format_required_features(&f))
|
||||||
.transpose()?,
|
.transpose()?,
|
||||||
dimension: descriptor.dimension.map(convert_texture_view_dimension),
|
dimension: descriptor.dimension.map(|dimension| dimension.into()),
|
||||||
range: wgt::ImageSubresourceRange {
|
range: wgt::ImageSubresourceRange {
|
||||||
aspect: match descriptor.aspect {
|
aspect: match descriptor.aspect {
|
||||||
GPUTextureAspect::All => wgt::TextureAspect::All,
|
GPUTextureAspect::All => wgt::TextureAspect::All,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue