[metal] Do not glob-import enum variants

The `metal` crate is currently unsound regarding unknown/future enum
variants, see https://github.com/gfx-rs/metal-rs/issues/209 and
https://github.com/rust-lang/rfcs/pull/3803.

`objc2-metal` fixes this by emitting C enums as a newtype + constants
for each variant, but that prevents us from importing the
variants/constants. So this commit converts to a pattern that works with
that in preparation for the migration.
This commit is contained in:
Mads Marquart 2025-04-25 09:57:39 +02:00 committed by Connor Fitzgerald
parent 78a5b22458
commit 949c5af934
2 changed files with 232 additions and 232 deletions

View File

@ -1082,144 +1082,144 @@ impl super::PrivateCapabilities {
pub fn map_format(&self, format: wgt::TextureFormat) -> MTLPixelFormat { pub fn map_format(&self, format: wgt::TextureFormat) -> MTLPixelFormat {
use wgt::TextureFormat as Tf; use wgt::TextureFormat as Tf;
use MTLPixelFormat::*; use MTLPixelFormat as MTL;
match format { match format {
Tf::R8Unorm => R8Unorm, Tf::R8Unorm => MTL::R8Unorm,
Tf::R8Snorm => R8Snorm, Tf::R8Snorm => MTL::R8Snorm,
Tf::R8Uint => R8Uint, Tf::R8Uint => MTL::R8Uint,
Tf::R8Sint => R8Sint, Tf::R8Sint => MTL::R8Sint,
Tf::R16Uint => R16Uint, Tf::R16Uint => MTL::R16Uint,
Tf::R16Sint => R16Sint, Tf::R16Sint => MTL::R16Sint,
Tf::R16Unorm => R16Unorm, Tf::R16Unorm => MTL::R16Unorm,
Tf::R16Snorm => R16Snorm, Tf::R16Snorm => MTL::R16Snorm,
Tf::R16Float => R16Float, Tf::R16Float => MTL::R16Float,
Tf::Rg8Unorm => RG8Unorm, Tf::Rg8Unorm => MTL::RG8Unorm,
Tf::Rg8Snorm => RG8Snorm, Tf::Rg8Snorm => MTL::RG8Snorm,
Tf::Rg8Uint => RG8Uint, Tf::Rg8Uint => MTL::RG8Uint,
Tf::Rg8Sint => RG8Sint, Tf::Rg8Sint => MTL::RG8Sint,
Tf::Rg16Unorm => RG16Unorm, Tf::Rg16Unorm => MTL::RG16Unorm,
Tf::Rg16Snorm => RG16Snorm, Tf::Rg16Snorm => MTL::RG16Snorm,
Tf::R32Uint => R32Uint, Tf::R32Uint => MTL::R32Uint,
Tf::R32Sint => R32Sint, Tf::R32Sint => MTL::R32Sint,
Tf::R32Float => R32Float, Tf::R32Float => MTL::R32Float,
Tf::Rg16Uint => RG16Uint, Tf::Rg16Uint => MTL::RG16Uint,
Tf::Rg16Sint => RG16Sint, Tf::Rg16Sint => MTL::RG16Sint,
Tf::Rg16Float => RG16Float, Tf::Rg16Float => MTL::RG16Float,
Tf::Rgba8Unorm => RGBA8Unorm, Tf::Rgba8Unorm => MTL::RGBA8Unorm,
Tf::Rgba8UnormSrgb => RGBA8Unorm_sRGB, Tf::Rgba8UnormSrgb => MTL::RGBA8Unorm_sRGB,
Tf::Bgra8UnormSrgb => BGRA8Unorm_sRGB, Tf::Bgra8UnormSrgb => MTL::BGRA8Unorm_sRGB,
Tf::Rgba8Snorm => RGBA8Snorm, Tf::Rgba8Snorm => MTL::RGBA8Snorm,
Tf::Bgra8Unorm => BGRA8Unorm, Tf::Bgra8Unorm => MTL::BGRA8Unorm,
Tf::Rgba8Uint => RGBA8Uint, Tf::Rgba8Uint => MTL::RGBA8Uint,
Tf::Rgba8Sint => RGBA8Sint, Tf::Rgba8Sint => MTL::RGBA8Sint,
Tf::Rgb10a2Uint => RGB10A2Uint, Tf::Rgb10a2Uint => MTL::RGB10A2Uint,
Tf::Rgb10a2Unorm => RGB10A2Unorm, Tf::Rgb10a2Unorm => MTL::RGB10A2Unorm,
Tf::Rg11b10Ufloat => RG11B10Float, Tf::Rg11b10Ufloat => MTL::RG11B10Float,
// Ruint64 textures are emulated on metal // Ruint64 textures are emulated on metal
Tf::R64Uint => RG32Uint, Tf::R64Uint => MTL::RG32Uint,
Tf::Rg32Uint => RG32Uint, Tf::Rg32Uint => MTL::RG32Uint,
Tf::Rg32Sint => RG32Sint, Tf::Rg32Sint => MTL::RG32Sint,
Tf::Rg32Float => RG32Float, Tf::Rg32Float => MTL::RG32Float,
Tf::Rgba16Uint => RGBA16Uint, Tf::Rgba16Uint => MTL::RGBA16Uint,
Tf::Rgba16Sint => RGBA16Sint, Tf::Rgba16Sint => MTL::RGBA16Sint,
Tf::Rgba16Unorm => RGBA16Unorm, Tf::Rgba16Unorm => MTL::RGBA16Unorm,
Tf::Rgba16Snorm => RGBA16Snorm, Tf::Rgba16Snorm => MTL::RGBA16Snorm,
Tf::Rgba16Float => RGBA16Float, Tf::Rgba16Float => MTL::RGBA16Float,
Tf::Rgba32Uint => RGBA32Uint, Tf::Rgba32Uint => MTL::RGBA32Uint,
Tf::Rgba32Sint => RGBA32Sint, Tf::Rgba32Sint => MTL::RGBA32Sint,
Tf::Rgba32Float => RGBA32Float, Tf::Rgba32Float => MTL::RGBA32Float,
Tf::Stencil8 => Stencil8, Tf::Stencil8 => MTL::Stencil8,
Tf::Depth16Unorm => Depth16Unorm, Tf::Depth16Unorm => MTL::Depth16Unorm,
Tf::Depth32Float => Depth32Float, Tf::Depth32Float => MTL::Depth32Float,
Tf::Depth32FloatStencil8 => Depth32Float_Stencil8, Tf::Depth32FloatStencil8 => MTL::Depth32Float_Stencil8,
Tf::Depth24Plus => { Tf::Depth24Plus => {
if self.format_depth24_stencil8 { if self.format_depth24_stencil8 {
Depth24Unorm_Stencil8 MTL::Depth24Unorm_Stencil8
} else { } else {
Depth32Float MTL::Depth32Float
} }
} }
Tf::Depth24PlusStencil8 => { Tf::Depth24PlusStencil8 => {
if self.format_depth24_stencil8 { if self.format_depth24_stencil8 {
Depth24Unorm_Stencil8 MTL::Depth24Unorm_Stencil8
} else { } else {
Depth32Float_Stencil8 MTL::Depth32Float_Stencil8
} }
} }
Tf::NV12 => unreachable!(), Tf::NV12 => unreachable!(),
Tf::Rgb9e5Ufloat => RGB9E5Float, Tf::Rgb9e5Ufloat => MTL::RGB9E5Float,
Tf::Bc1RgbaUnorm => BC1_RGBA, Tf::Bc1RgbaUnorm => MTL::BC1_RGBA,
Tf::Bc1RgbaUnormSrgb => BC1_RGBA_sRGB, Tf::Bc1RgbaUnormSrgb => MTL::BC1_RGBA_sRGB,
Tf::Bc2RgbaUnorm => BC2_RGBA, Tf::Bc2RgbaUnorm => MTL::BC2_RGBA,
Tf::Bc2RgbaUnormSrgb => BC2_RGBA_sRGB, Tf::Bc2RgbaUnormSrgb => MTL::BC2_RGBA_sRGB,
Tf::Bc3RgbaUnorm => BC3_RGBA, Tf::Bc3RgbaUnorm => MTL::BC3_RGBA,
Tf::Bc3RgbaUnormSrgb => BC3_RGBA_sRGB, Tf::Bc3RgbaUnormSrgb => MTL::BC3_RGBA_sRGB,
Tf::Bc4RUnorm => BC4_RUnorm, Tf::Bc4RUnorm => MTL::BC4_RUnorm,
Tf::Bc4RSnorm => BC4_RSnorm, Tf::Bc4RSnorm => MTL::BC4_RSnorm,
Tf::Bc5RgUnorm => BC5_RGUnorm, Tf::Bc5RgUnorm => MTL::BC5_RGUnorm,
Tf::Bc5RgSnorm => BC5_RGSnorm, Tf::Bc5RgSnorm => MTL::BC5_RGSnorm,
Tf::Bc6hRgbFloat => BC6H_RGBFloat, Tf::Bc6hRgbFloat => MTL::BC6H_RGBFloat,
Tf::Bc6hRgbUfloat => BC6H_RGBUfloat, Tf::Bc6hRgbUfloat => MTL::BC6H_RGBUfloat,
Tf::Bc7RgbaUnorm => BC7_RGBAUnorm, Tf::Bc7RgbaUnorm => MTL::BC7_RGBAUnorm,
Tf::Bc7RgbaUnormSrgb => BC7_RGBAUnorm_sRGB, Tf::Bc7RgbaUnormSrgb => MTL::BC7_RGBAUnorm_sRGB,
Tf::Etc2Rgb8Unorm => ETC2_RGB8, Tf::Etc2Rgb8Unorm => MTL::ETC2_RGB8,
Tf::Etc2Rgb8UnormSrgb => ETC2_RGB8_sRGB, Tf::Etc2Rgb8UnormSrgb => MTL::ETC2_RGB8_sRGB,
Tf::Etc2Rgb8A1Unorm => ETC2_RGB8A1, Tf::Etc2Rgb8A1Unorm => MTL::ETC2_RGB8A1,
Tf::Etc2Rgb8A1UnormSrgb => ETC2_RGB8A1_sRGB, Tf::Etc2Rgb8A1UnormSrgb => MTL::ETC2_RGB8A1_sRGB,
Tf::Etc2Rgba8Unorm => EAC_RGBA8, Tf::Etc2Rgba8Unorm => MTL::EAC_RGBA8,
Tf::Etc2Rgba8UnormSrgb => EAC_RGBA8_sRGB, Tf::Etc2Rgba8UnormSrgb => MTL::EAC_RGBA8_sRGB,
Tf::EacR11Unorm => EAC_R11Unorm, Tf::EacR11Unorm => MTL::EAC_R11Unorm,
Tf::EacR11Snorm => EAC_R11Snorm, Tf::EacR11Snorm => MTL::EAC_R11Snorm,
Tf::EacRg11Unorm => EAC_RG11Unorm, Tf::EacRg11Unorm => MTL::EAC_RG11Unorm,
Tf::EacRg11Snorm => EAC_RG11Snorm, Tf::EacRg11Snorm => MTL::EAC_RG11Snorm,
Tf::Astc { block, channel } => match channel { Tf::Astc { block, channel } => match channel {
AstcChannel::Unorm => match block { AstcChannel::Unorm => match block {
AstcBlock::B4x4 => ASTC_4x4_LDR, AstcBlock::B4x4 => MTL::ASTC_4x4_LDR,
AstcBlock::B5x4 => ASTC_5x4_LDR, AstcBlock::B5x4 => MTL::ASTC_5x4_LDR,
AstcBlock::B5x5 => ASTC_5x5_LDR, AstcBlock::B5x5 => MTL::ASTC_5x5_LDR,
AstcBlock::B6x5 => ASTC_6x5_LDR, AstcBlock::B6x5 => MTL::ASTC_6x5_LDR,
AstcBlock::B6x6 => ASTC_6x6_LDR, AstcBlock::B6x6 => MTL::ASTC_6x6_LDR,
AstcBlock::B8x5 => ASTC_8x5_LDR, AstcBlock::B8x5 => MTL::ASTC_8x5_LDR,
AstcBlock::B8x6 => ASTC_8x6_LDR, AstcBlock::B8x6 => MTL::ASTC_8x6_LDR,
AstcBlock::B8x8 => ASTC_8x8_LDR, AstcBlock::B8x8 => MTL::ASTC_8x8_LDR,
AstcBlock::B10x5 => ASTC_10x5_LDR, AstcBlock::B10x5 => MTL::ASTC_10x5_LDR,
AstcBlock::B10x6 => ASTC_10x6_LDR, AstcBlock::B10x6 => MTL::ASTC_10x6_LDR,
AstcBlock::B10x8 => ASTC_10x8_LDR, AstcBlock::B10x8 => MTL::ASTC_10x8_LDR,
AstcBlock::B10x10 => ASTC_10x10_LDR, AstcBlock::B10x10 => MTL::ASTC_10x10_LDR,
AstcBlock::B12x10 => ASTC_12x10_LDR, AstcBlock::B12x10 => MTL::ASTC_12x10_LDR,
AstcBlock::B12x12 => ASTC_12x12_LDR, AstcBlock::B12x12 => MTL::ASTC_12x12_LDR,
}, },
AstcChannel::UnormSrgb => match block { AstcChannel::UnormSrgb => match block {
AstcBlock::B4x4 => ASTC_4x4_sRGB, AstcBlock::B4x4 => MTL::ASTC_4x4_sRGB,
AstcBlock::B5x4 => ASTC_5x4_sRGB, AstcBlock::B5x4 => MTL::ASTC_5x4_sRGB,
AstcBlock::B5x5 => ASTC_5x5_sRGB, AstcBlock::B5x5 => MTL::ASTC_5x5_sRGB,
AstcBlock::B6x5 => ASTC_6x5_sRGB, AstcBlock::B6x5 => MTL::ASTC_6x5_sRGB,
AstcBlock::B6x6 => ASTC_6x6_sRGB, AstcBlock::B6x6 => MTL::ASTC_6x6_sRGB,
AstcBlock::B8x5 => ASTC_8x5_sRGB, AstcBlock::B8x5 => MTL::ASTC_8x5_sRGB,
AstcBlock::B8x6 => ASTC_8x6_sRGB, AstcBlock::B8x6 => MTL::ASTC_8x6_sRGB,
AstcBlock::B8x8 => ASTC_8x8_sRGB, AstcBlock::B8x8 => MTL::ASTC_8x8_sRGB,
AstcBlock::B10x5 => ASTC_10x5_sRGB, AstcBlock::B10x5 => MTL::ASTC_10x5_sRGB,
AstcBlock::B10x6 => ASTC_10x6_sRGB, AstcBlock::B10x6 => MTL::ASTC_10x6_sRGB,
AstcBlock::B10x8 => ASTC_10x8_sRGB, AstcBlock::B10x8 => MTL::ASTC_10x8_sRGB,
AstcBlock::B10x10 => ASTC_10x10_sRGB, AstcBlock::B10x10 => MTL::ASTC_10x10_sRGB,
AstcBlock::B12x10 => ASTC_12x10_sRGB, AstcBlock::B12x10 => MTL::ASTC_12x10_sRGB,
AstcBlock::B12x12 => ASTC_12x12_sRGB, AstcBlock::B12x12 => MTL::ASTC_12x12_sRGB,
}, },
AstcChannel::Hdr => match block { AstcChannel::Hdr => match block {
AstcBlock::B4x4 => ASTC_4x4_HDR, AstcBlock::B4x4 => MTL::ASTC_4x4_HDR,
AstcBlock::B5x4 => ASTC_5x4_HDR, AstcBlock::B5x4 => MTL::ASTC_5x4_HDR,
AstcBlock::B5x5 => ASTC_5x5_HDR, AstcBlock::B5x5 => MTL::ASTC_5x5_HDR,
AstcBlock::B6x5 => ASTC_6x5_HDR, AstcBlock::B6x5 => MTL::ASTC_6x5_HDR,
AstcBlock::B6x6 => ASTC_6x6_HDR, AstcBlock::B6x6 => MTL::ASTC_6x6_HDR,
AstcBlock::B8x5 => ASTC_8x5_HDR, AstcBlock::B8x5 => MTL::ASTC_8x5_HDR,
AstcBlock::B8x6 => ASTC_8x6_HDR, AstcBlock::B8x6 => MTL::ASTC_8x6_HDR,
AstcBlock::B8x8 => ASTC_8x8_HDR, AstcBlock::B8x8 => MTL::ASTC_8x8_HDR,
AstcBlock::B10x5 => ASTC_10x5_HDR, AstcBlock::B10x5 => MTL::ASTC_10x5_HDR,
AstcBlock::B10x6 => ASTC_10x6_HDR, AstcBlock::B10x6 => MTL::ASTC_10x6_HDR,
AstcBlock::B10x8 => ASTC_10x8_HDR, AstcBlock::B10x8 => MTL::ASTC_10x8_HDR,
AstcBlock::B10x10 => ASTC_10x10_HDR, AstcBlock::B10x10 => MTL::ASTC_10x10_HDR,
AstcBlock::B12x10 => ASTC_12x10_HDR, AstcBlock::B12x10 => MTL::ASTC_12x10_HDR,
AstcBlock::B12x12 => ASTC_12x12_HDR, AstcBlock::B12x12 => MTL::ASTC_12x12_HDR,
}, },
}, },
} }
@ -1232,18 +1232,18 @@ impl super::PrivateCapabilities {
) -> MTLPixelFormat { ) -> MTLPixelFormat {
use crate::FormatAspects as Fa; use crate::FormatAspects as Fa;
use wgt::TextureFormat as Tf; use wgt::TextureFormat as Tf;
use MTLPixelFormat::*; use MTLPixelFormat as MTL;
match (format, aspects) { match (format, aspects) {
// map combined depth-stencil format to their stencil-only format // map combined depth-stencil format to their stencil-only format
// see https://developer.apple.com/library/archive/documentation/Miscellaneous/Conceptual/MetalProgrammingGuide/WhatsNewiniOS10tvOS10andOSX1012/WhatsNewiniOS10tvOS10andOSX1012.html#//apple_ref/doc/uid/TP40014221-CH14-DontLinkElementID_77 // see https://developer.apple.com/library/archive/documentation/Miscellaneous/Conceptual/MetalProgrammingGuide/WhatsNewiniOS10tvOS10andOSX1012/WhatsNewiniOS10tvOS10andOSX1012.html#//apple_ref/doc/uid/TP40014221-CH14-DontLinkElementID_77
(Tf::Depth24PlusStencil8, Fa::STENCIL) => { (Tf::Depth24PlusStencil8, Fa::STENCIL) => {
if self.format_depth24_stencil8 { if self.format_depth24_stencil8 {
X24_Stencil8 MTL::X24_Stencil8
} else { } else {
X32_Stencil8 MTL::X32_Stencil8
} }
} }
(Tf::Depth32FloatStencil8, Fa::STENCIL) => X32_Stencil8, (Tf::Depth32FloatStencil8, Fa::STENCIL) => MTL::X32_Stencil8,
_ => self.map_format(format), _ => self.map_format(format),
} }

View File

@ -42,58 +42,58 @@ pub fn map_texture_usage(format: wgt::TextureFormat, usage: wgt::TextureUses) ->
pub fn map_texture_view_dimension(dim: wgt::TextureViewDimension) -> MTLTextureType { pub fn map_texture_view_dimension(dim: wgt::TextureViewDimension) -> MTLTextureType {
use wgt::TextureViewDimension as Tvd; use wgt::TextureViewDimension as Tvd;
use MTLTextureType::*; use MTLTextureType as MTL;
match dim { match dim {
Tvd::D1 => D1, Tvd::D1 => MTL::D1,
Tvd::D2 => D2, Tvd::D2 => MTL::D2,
Tvd::D2Array => D2Array, Tvd::D2Array => MTL::D2Array,
Tvd::D3 => D3, Tvd::D3 => MTL::D3,
Tvd::Cube => Cube, Tvd::Cube => MTL::Cube,
Tvd::CubeArray => CubeArray, Tvd::CubeArray => MTL::CubeArray,
} }
} }
pub fn map_compare_function(fun: wgt::CompareFunction) -> MTLCompareFunction { pub fn map_compare_function(fun: wgt::CompareFunction) -> MTLCompareFunction {
use wgt::CompareFunction as Cf; use wgt::CompareFunction as Cf;
use MTLCompareFunction::*; use MTLCompareFunction as MTL;
match fun { match fun {
Cf::Never => Never, Cf::Never => MTL::Never,
Cf::Less => Less, Cf::Less => MTL::Less,
Cf::LessEqual => LessEqual, Cf::LessEqual => MTL::LessEqual,
Cf::Equal => Equal, Cf::Equal => MTL::Equal,
Cf::GreaterEqual => GreaterEqual, Cf::GreaterEqual => MTL::GreaterEqual,
Cf::Greater => Greater, Cf::Greater => MTL::Greater,
Cf::NotEqual => NotEqual, Cf::NotEqual => MTL::NotEqual,
Cf::Always => Always, Cf::Always => MTL::Always,
} }
} }
pub fn map_filter_mode(filter: wgt::FilterMode) -> MTLSamplerMinMagFilter { pub fn map_filter_mode(filter: wgt::FilterMode) -> MTLSamplerMinMagFilter {
use MTLSamplerMinMagFilter::*; use MTLSamplerMinMagFilter as MTL;
match filter { match filter {
wgt::FilterMode::Nearest => Nearest, wgt::FilterMode::Nearest => MTL::Nearest,
wgt::FilterMode::Linear => Linear, wgt::FilterMode::Linear => MTL::Linear,
} }
} }
pub fn map_address_mode(address: wgt::AddressMode) -> MTLSamplerAddressMode { pub fn map_address_mode(address: wgt::AddressMode) -> MTLSamplerAddressMode {
use wgt::AddressMode as Fm; use wgt::AddressMode as Fm;
use MTLSamplerAddressMode::*; use MTLSamplerAddressMode as MTL;
match address { match address {
Fm::Repeat => Repeat, Fm::Repeat => MTL::Repeat,
Fm::MirrorRepeat => MirrorRepeat, Fm::MirrorRepeat => MTL::MirrorRepeat,
Fm::ClampToEdge => ClampToEdge, Fm::ClampToEdge => MTL::ClampToEdge,
Fm::ClampToBorder => ClampToBorderColor, Fm::ClampToBorder => MTL::ClampToBorderColor,
//Fm::MirrorClamp => MirrorClampToEdge, //Fm::MirrorClamp => MTL::MirrorClampToEdge,
} }
} }
pub fn map_border_color(border_color: wgt::SamplerBorderColor) -> MTLSamplerBorderColor { pub fn map_border_color(border_color: wgt::SamplerBorderColor) -> MTLSamplerBorderColor {
use MTLSamplerBorderColor::*; use MTLSamplerBorderColor as MTL;
match border_color { match border_color {
wgt::SamplerBorderColor::TransparentBlack => TransparentBlack, wgt::SamplerBorderColor::TransparentBlack => MTL::TransparentBlack,
wgt::SamplerBorderColor::OpaqueBlack => OpaqueBlack, wgt::SamplerBorderColor::OpaqueBlack => MTL::OpaqueBlack,
wgt::SamplerBorderColor::OpaqueWhite => OpaqueWhite, wgt::SamplerBorderColor::OpaqueWhite => MTL::OpaqueWhite,
wgt::SamplerBorderColor::Zero => unreachable!(), wgt::SamplerBorderColor::Zero => unreachable!(),
} }
} }
@ -138,39 +138,39 @@ pub fn map_color_write(mask: wgt::ColorWrites) -> MTLColorWriteMask {
pub fn map_blend_factor(factor: wgt::BlendFactor) -> MTLBlendFactor { pub fn map_blend_factor(factor: wgt::BlendFactor) -> MTLBlendFactor {
use wgt::BlendFactor as Bf; use wgt::BlendFactor as Bf;
use MTLBlendFactor::*; use MTLBlendFactor as MTL;
match factor { match factor {
Bf::Zero => Zero, Bf::Zero => MTL::Zero,
Bf::One => One, Bf::One => MTL::One,
Bf::Src => SourceColor, Bf::Src => MTL::SourceColor,
Bf::OneMinusSrc => OneMinusSourceColor, Bf::OneMinusSrc => MTL::OneMinusSourceColor,
Bf::Dst => DestinationColor, Bf::Dst => MTL::DestinationColor,
Bf::OneMinusDst => OneMinusDestinationColor, Bf::OneMinusDst => MTL::OneMinusDestinationColor,
Bf::SrcAlpha => SourceAlpha, Bf::SrcAlpha => MTL::SourceAlpha,
Bf::OneMinusSrcAlpha => OneMinusSourceAlpha, Bf::OneMinusSrcAlpha => MTL::OneMinusSourceAlpha,
Bf::DstAlpha => DestinationAlpha, Bf::DstAlpha => MTL::DestinationAlpha,
Bf::OneMinusDstAlpha => OneMinusDestinationAlpha, Bf::OneMinusDstAlpha => MTL::OneMinusDestinationAlpha,
Bf::Constant => BlendColor, Bf::Constant => MTL::BlendColor,
Bf::OneMinusConstant => OneMinusBlendColor, Bf::OneMinusConstant => MTL::OneMinusBlendColor,
Bf::SrcAlphaSaturated => SourceAlphaSaturated, Bf::SrcAlphaSaturated => MTL::SourceAlphaSaturated,
Bf::Src1 => Source1Color, Bf::Src1 => MTL::Source1Color,
Bf::OneMinusSrc1 => OneMinusSource1Color, Bf::OneMinusSrc1 => MTL::OneMinusSource1Color,
Bf::Src1Alpha => Source1Alpha, Bf::Src1Alpha => MTL::Source1Alpha,
Bf::OneMinusSrc1Alpha => OneMinusSource1Alpha, Bf::OneMinusSrc1Alpha => MTL::OneMinusSource1Alpha,
} }
} }
pub fn map_blend_op(operation: wgt::BlendOperation) -> MTLBlendOperation { pub fn map_blend_op(operation: wgt::BlendOperation) -> MTLBlendOperation {
use wgt::BlendOperation as Bo; use wgt::BlendOperation as Bo;
use MTLBlendOperation::*; use MTLBlendOperation as MTL;
match operation { match operation {
Bo::Add => Add, Bo::Add => MTL::Add,
Bo::Subtract => Subtract, Bo::Subtract => MTL::Subtract,
Bo::ReverseSubtract => ReverseSubtract, Bo::ReverseSubtract => MTL::ReverseSubtract,
Bo::Min => Min, Bo::Min => MTL::Min,
Bo::Max => Max, Bo::Max => MTL::Max,
} }
} }
@ -186,50 +186,50 @@ pub fn map_blend_component(
pub fn map_vertex_format(format: wgt::VertexFormat) -> MTLVertexFormat { pub fn map_vertex_format(format: wgt::VertexFormat) -> MTLVertexFormat {
use wgt::VertexFormat as Vf; use wgt::VertexFormat as Vf;
use MTLVertexFormat::*; use MTLVertexFormat as MTL;
match format { match format {
Vf::Unorm8 => UCharNormalized, Vf::Unorm8 => MTL::UCharNormalized,
Vf::Snorm8 => CharNormalized, Vf::Snorm8 => MTL::CharNormalized,
Vf::Uint8 => UChar, Vf::Uint8 => MTL::UChar,
Vf::Sint8 => Char, Vf::Sint8 => MTL::Char,
Vf::Unorm8x2 => UChar2Normalized, Vf::Unorm8x2 => MTL::UChar2Normalized,
Vf::Snorm8x2 => Char2Normalized, Vf::Snorm8x2 => MTL::Char2Normalized,
Vf::Uint8x2 => UChar2, Vf::Uint8x2 => MTL::UChar2,
Vf::Sint8x2 => Char2, Vf::Sint8x2 => MTL::Char2,
Vf::Unorm8x4 => UChar4Normalized, Vf::Unorm8x4 => MTL::UChar4Normalized,
Vf::Snorm8x4 => Char4Normalized, Vf::Snorm8x4 => MTL::Char4Normalized,
Vf::Uint8x4 => UChar4, Vf::Uint8x4 => MTL::UChar4,
Vf::Sint8x4 => Char4, Vf::Sint8x4 => MTL::Char4,
Vf::Unorm16 => UShortNormalized, Vf::Unorm16 => MTL::UShortNormalized,
Vf::Snorm16 => ShortNormalized, Vf::Snorm16 => MTL::ShortNormalized,
Vf::Uint16 => UShort, Vf::Uint16 => MTL::UShort,
Vf::Sint16 => Short, Vf::Sint16 => MTL::Short,
Vf::Float16 => Half, Vf::Float16 => MTL::Half,
Vf::Unorm16x2 => UShort2Normalized, Vf::Unorm16x2 => MTL::UShort2Normalized,
Vf::Snorm16x2 => Short2Normalized, Vf::Snorm16x2 => MTL::Short2Normalized,
Vf::Uint16x2 => UShort2, Vf::Uint16x2 => MTL::UShort2,
Vf::Sint16x2 => Short2, Vf::Sint16x2 => MTL::Short2,
Vf::Float16x2 => Half2, Vf::Float16x2 => MTL::Half2,
Vf::Unorm16x4 => UShort4Normalized, Vf::Unorm16x4 => MTL::UShort4Normalized,
Vf::Snorm16x4 => Short4Normalized, Vf::Snorm16x4 => MTL::Short4Normalized,
Vf::Uint16x4 => UShort4, Vf::Uint16x4 => MTL::UShort4,
Vf::Sint16x4 => Short4, Vf::Sint16x4 => MTL::Short4,
Vf::Float16x4 => Half4, Vf::Float16x4 => MTL::Half4,
Vf::Uint32 => UInt, Vf::Uint32 => MTL::UInt,
Vf::Sint32 => Int, Vf::Sint32 => MTL::Int,
Vf::Float32 => Float, Vf::Float32 => MTL::Float,
Vf::Uint32x2 => UInt2, Vf::Uint32x2 => MTL::UInt2,
Vf::Sint32x2 => Int2, Vf::Sint32x2 => MTL::Int2,
Vf::Float32x2 => Float2, Vf::Float32x2 => MTL::Float2,
Vf::Uint32x3 => UInt3, Vf::Uint32x3 => MTL::UInt3,
Vf::Sint32x3 => Int3, Vf::Sint32x3 => MTL::Int3,
Vf::Float32x3 => Float3, Vf::Float32x3 => MTL::Float3,
Vf::Uint32x4 => UInt4, Vf::Uint32x4 => MTL::UInt4,
Vf::Sint32x4 => Int4, Vf::Sint32x4 => MTL::Int4,
Vf::Float32x4 => Float4, Vf::Float32x4 => MTL::Float4,
Vf::Unorm10_10_10_2 => UInt1010102Normalized, Vf::Unorm10_10_10_2 => MTL::UInt1010102Normalized,
Vf::Unorm8x4Bgra => UChar4Normalized_BGRA, Vf::Unorm8x4Bgra => MTL::UChar4Normalized_BGRA,
Vf::Float64 | Vf::Float64x2 | Vf::Float64x3 | Vf::Float64x4 => unimplemented!(), Vf::Float64 | Vf::Float64x2 | Vf::Float64x3 | Vf::Float64x4 => unimplemented!(),
} }
} }
@ -243,17 +243,17 @@ pub fn map_step_mode(mode: wgt::VertexStepMode) -> MTLVertexStepFunction {
pub fn map_stencil_op(op: wgt::StencilOperation) -> MTLStencilOperation { pub fn map_stencil_op(op: wgt::StencilOperation) -> MTLStencilOperation {
use wgt::StencilOperation as So; use wgt::StencilOperation as So;
use MTLStencilOperation::*; use MTLStencilOperation as MTL;
match op { match op {
So::Keep => Keep, So::Keep => MTL::Keep,
So::Zero => Zero, So::Zero => MTL::Zero,
So::Replace => Replace, So::Replace => MTL::Replace,
So::IncrementClamp => IncrementClamp, So::IncrementClamp => MTL::IncrementClamp,
So::IncrementWrap => IncrementWrap, So::IncrementWrap => MTL::IncrementWrap,
So::DecrementClamp => DecrementClamp, So::DecrementClamp => MTL::DecrementClamp,
So::DecrementWrap => DecrementWrap, So::DecrementWrap => MTL::DecrementWrap,
So::Invert => Invert, So::Invert => MTL::Invert,
} }
} }
@ -296,12 +296,12 @@ pub fn map_origin(origin: &wgt::Origin3d) -> MTLOrigin {
} }
pub fn map_store_action(store: bool, resolve: bool) -> MTLStoreAction { pub fn map_store_action(store: bool, resolve: bool) -> MTLStoreAction {
use MTLStoreAction::*; use MTLStoreAction as MTL;
match (store, resolve) { match (store, resolve) {
(true, true) => StoreAndMultisampleResolve, (true, true) => MTL::StoreAndMultisampleResolve,
(false, true) => MultisampleResolve, (false, true) => MTL::MultisampleResolve,
(true, false) => Store, (true, false) => MTL::Store,
(false, false) => DontCare, (false, false) => MTL::DontCare,
} }
} }