rt(mtl): move icrate definitions to objc2-metal

This commit is contained in:
chyyran 2024-06-21 20:50:35 -04:00 committed by Ronny Chan
parent 5e9ce1207c
commit b5d523e9f3
17 changed files with 237 additions and 223 deletions

130
Cargo.lock generated
View file

@ -125,7 +125,7 @@ checksum = "0ae92a5119aa49cdbcf6b9f893fe4e1d98b04ccbf82ee0584ad948a44a734dea"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.66", "syn 2.0.67",
] ]
[[package]] [[package]]
@ -186,7 +186,7 @@ checksum = "c6fa2087f2753a7da8cc1c0dbfcf89579dd57458e36769de5ac750b4671737ca"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.66", "syn 2.0.67",
] ]
[[package]] [[package]]
@ -301,9 +301,9 @@ checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1"
[[package]] [[package]]
name = "bitstream-io" name = "bitstream-io"
version = "2.4.0" version = "2.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1bdba4ac537b9346c50122b6e9f9b0d2bd721e04c6032e1d15f53ce0747b054c" checksum = "415f8399438eb5e4b2f73ed3152a3448b98149dda642a957ee704e1daa5cf1d8"
[[package]] [[package]]
name = "bitvec" name = "bitvec"
@ -366,12 +366,11 @@ dependencies = [
[[package]] [[package]]
name = "block2" name = "block2"
version = "0.4.0" version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e58aa60e59d8dbfcc36138f5f18be5f24394d33b38b24f7fd0b1caa33095f22f" checksum = "2c132eebf10f5cad5289222520a4a058514204aed6d791f1cf4fe8088b82d15f"
dependencies = [ dependencies = [
"block-sys", "objc2 0.5.2",
"objc2 0.5.1",
] ]
[[package]] [[package]]
@ -400,9 +399,9 @@ checksum = "5ce89b21cab1437276d2650d57e971f9d548a2d9037cc231abdc0562b97498ce"
[[package]] [[package]]
name = "bytemuck" name = "bytemuck"
version = "1.16.0" version = "1.16.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "78834c15cb5d5efe3452d58b1e8ba890dd62d21907f867f383358198e56ebca5" checksum = "b236fc92302c97ed75b38da1f4917b5cdda4984745740f153a5d3059e48d725e"
dependencies = [ dependencies = [
"bytemuck_derive", "bytemuck_derive",
] ]
@ -415,7 +414,7 @@ checksum = "1ee891b04274a59bd38b412188e24b849617b2e45a0fd8d057deb63e7403761b"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.66", "syn 2.0.67",
] ]
[[package]] [[package]]
@ -1039,7 +1038,7 @@ checksum = "1a5c6c585bc94aaf2c7b51dd4c2ba22680844aba4c687be581871a6f518c5742"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.66", "syn 2.0.67",
] ]
[[package]] [[package]]
@ -1351,6 +1350,12 @@ version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024"
[[package]]
name = "hermit-abi"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fbf6a919d6cf397374f7dfeeea91d974c7c0a7221d0d0f4f20d859d329e53fcc"
[[package]] [[package]]
name = "hexf-parse" name = "hexf-parse"
version = "0.2.1" version = "0.2.1"
@ -1374,16 +1379,6 @@ dependencies = [
"objc2 0.4.1", "objc2 0.4.1",
] ]
[[package]]
name = "icrate"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3fb69199826926eb864697bddd27f73d9fddcffc004f5733131e15b465e30642"
dependencies = [
"block2 0.4.0",
"objc2 0.5.1",
]
[[package]] [[package]]
name = "image" name = "image"
version = "0.25.1" version = "0.25.1"
@ -1451,7 +1446,7 @@ checksum = "c34819042dc3d3971c46c2190835914dfbe0c3c13f61449b2997f4e9722dfa60"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.66", "syn 2.0.67",
] ]
[[package]] [[package]]
@ -1556,9 +1551,9 @@ checksum = "e2db585e1d738fc771bf08a151420d3ed193d9d895a36df7f6f8a9456b911ddc"
[[package]] [[package]]
name = "lazy_static" name = "lazy_static"
version = "1.4.0" version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
[[package]] [[package]]
name = "lebe" name = "lebe"
@ -1610,7 +1605,6 @@ dependencies = [
"ash", "ash",
"glob", "glob",
"halfbrown", "halfbrown",
"icrate 0.1.2",
"librashader-cache", "librashader-cache",
"librashader-common", "librashader-common",
"librashader-preprocess", "librashader-preprocess",
@ -1624,7 +1618,8 @@ dependencies = [
"librashader-runtime-mtl", "librashader-runtime-mtl",
"librashader-runtime-vk", "librashader-runtime-vk",
"librashader-runtime-wgpu", "librashader-runtime-wgpu",
"objc2 0.5.1", "objc2 0.5.2",
"objc2-metal",
"once_cell", "once_cell",
"rayon", "rayon",
"wgpu", "wgpu",
@ -1662,10 +1657,10 @@ version = "0.2.7"
dependencies = [ dependencies = [
"ash", "ash",
"gl", "gl",
"icrate 0.1.2",
"librashader", "librashader",
"librashader-spirv-cross", "librashader-spirv-cross",
"objc2 0.5.1", "objc2 0.5.2",
"objc2-metal",
"paste", "paste",
"rustc-hash", "rustc-hash",
"sptr", "sptr",
@ -1680,8 +1675,8 @@ dependencies = [
"ash", "ash",
"gl", "gl",
"halfbrown", "halfbrown",
"icrate 0.1.2",
"num-traits", "num-traits",
"objc2-metal",
"rustc-hash", "rustc-hash",
"wgpu-types", "wgpu-types",
"windows", "windows",
@ -1835,13 +1830,14 @@ version = "0.2.7"
dependencies = [ dependencies = [
"array-concat", "array-concat",
"bytemuck", "bytemuck",
"icrate 0.1.2",
"librashader-common", "librashader-common",
"librashader-preprocess", "librashader-preprocess",
"librashader-presets", "librashader-presets",
"librashader-reflect", "librashader-reflect",
"librashader-runtime", "librashader-runtime",
"objc2 0.5.1", "objc2 0.5.2",
"objc2-foundation",
"objc2-metal",
"rayon", "rayon",
"thiserror", "thiserror",
] ]
@ -2041,9 +2037,9 @@ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
[[package]] [[package]]
name = "miniz_oxide" name = "miniz_oxide"
version = "0.7.3" version = "0.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "87dfd01fe195c66b572b37921ad8803d010623c0aca821bea2302239d155cdae" checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08"
dependencies = [ dependencies = [
"adler", "adler",
"simd-adler32", "simd-adler32",
@ -2176,7 +2172,7 @@ checksum = "ed3955f1a9c7c0c15e092f9c887db08b1fc683305fdf6eb6684f22555355e202"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.66", "syn 2.0.67",
] ]
[[package]] [[package]]
@ -2237,7 +2233,7 @@ dependencies = [
"proc-macro-crate", "proc-macro-crate",
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.66", "syn 2.0.67",
] ]
[[package]] [[package]]
@ -2267,9 +2263,9 @@ dependencies = [
[[package]] [[package]]
name = "objc2" name = "objc2"
version = "0.5.1" version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b4b25e1034d0e636cd84707ccdaa9f81243d399196b8a773946dcffec0401659" checksum = "46a785d4eeff09c14c487497c162e92766fbb3e4059a71840cecc03d9a50b804"
dependencies = [ dependencies = [
"objc-sys", "objc-sys",
"objc2-encode 4.0.3", "objc2-encode 4.0.3",
@ -2287,6 +2283,30 @@ version = "4.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7891e71393cd1f227313c9379a26a584ff3d7e6e7159e988851f0934c993f0f8" checksum = "7891e71393cd1f227313c9379a26a584ff3d7e6e7159e988851f0934c993f0f8"
[[package]]
name = "objc2-foundation"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0ee638a5da3799329310ad4cfa62fbf045d5f56e3ef5ba4149e7452dcf89d5a8"
dependencies = [
"bitflags 2.5.0",
"block2 0.5.1",
"libc",
"objc2 0.5.2",
]
[[package]]
name = "objc2-metal"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dd0cba1276f6023976a406a14ffa85e1fdd19df6b0f737b063b95f6c8c7aadd6"
dependencies = [
"bitflags 2.5.0",
"block2 0.5.1",
"objc2 0.5.2",
"objc2-foundation",
]
[[package]] [[package]]
name = "once_cell" name = "once_cell"
version = "1.19.0" version = "1.19.0"
@ -2418,7 +2438,7 @@ dependencies = [
"pest_meta", "pest_meta",
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.66", "syn 2.0.67",
] ]
[[package]] [[package]]
@ -2478,13 +2498,13 @@ dependencies = [
[[package]] [[package]]
name = "polling" name = "polling"
version = "3.7.1" version = "3.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5e6a007746f34ed64099e88783b0ae369eaa3da6392868ba262e2af9b8fbaea1" checksum = "a3ed00ed3fbf728b5816498ecd316d1716eecaced9c0c8d2c5a6740ca214985b"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"concurrent-queue", "concurrent-queue",
"hermit-abi 0.3.9", "hermit-abi 0.4.0",
"pin-project-lite", "pin-project-lite",
"rustix", "rustix",
"tracing", "tracing",
@ -2544,9 +2564,9 @@ dependencies = [
[[package]] [[package]]
name = "proc-macro2" name = "proc-macro2"
version = "1.0.85" version = "1.0.86"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23" checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77"
dependencies = [ dependencies = [
"unicode-ident", "unicode-ident",
] ]
@ -2567,7 +2587,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8021cf59c8ec9c432cfc2526ac6b8aa508ecaf29cd415f271b8406c1b851c3fd" checksum = "8021cf59c8ec9c432cfc2526ac6b8aa508ecaf29cd415f271b8406c1b851c3fd"
dependencies = [ dependencies = [
"quote", "quote",
"syn 2.0.66", "syn 2.0.67",
] ]
[[package]] [[package]]
@ -2682,9 +2702,9 @@ dependencies = [
[[package]] [[package]]
name = "ravif" name = "ravif"
version = "0.11.5" version = "0.11.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bc13288f5ab39e6d7c9d501759712e6969fcc9734220846fc9ed26cae2cc4234" checksum = "67376f469e7e7840d0040bbf4b9b3334005bb167f814621326e4c7ab8cd6e944"
dependencies = [ dependencies = [
"avif-serialize", "avif-serialize",
"imgref", "imgref",
@ -2943,7 +2963,7 @@ checksum = "500cbc0ebeb6f46627f50f3f5811ccf6bf00643be300b4c3eabc0ef55dc5b5ba"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.66", "syn 2.0.67",
] ]
[[package]] [[package]]
@ -3128,9 +3148,9 @@ dependencies = [
[[package]] [[package]]
name = "syn" name = "syn"
version = "2.0.66" version = "2.0.67"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" checksum = "ff8655ed1d86f3af4ee3fd3263786bc14245ad17c4c7e85ba7187fb3ae028c90"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -3206,7 +3226,7 @@ checksum = "46c3384250002a6d5af4d114f2845d37b57521033f30d5c3f46c4d70e1197533"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.66", "syn 2.0.67",
] ]
[[package]] [[package]]
@ -3444,7 +3464,7 @@ dependencies = [
"once_cell", "once_cell",
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.66", "syn 2.0.67",
"wasm-bindgen-shared", "wasm-bindgen-shared",
] ]
@ -3478,7 +3498,7 @@ checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.66", "syn 2.0.67",
"wasm-bindgen-backend", "wasm-bindgen-backend",
"wasm-bindgen-shared", "wasm-bindgen-shared",
] ]
@ -4010,7 +4030,7 @@ dependencies = [
"core-foundation", "core-foundation",
"core-graphics", "core-graphics",
"cursor-icon", "cursor-icon",
"icrate 0.0.4", "icrate",
"js-sys", "js-sys",
"libc", "libc",
"log", "log",
@ -4159,7 +4179,7 @@ checksum = "15e934569e47891f7d9411f1a451d947a60e000ab3bd24fbb970f000387d1b3b"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.66", "syn 2.0.67",
] ]
[[package]] [[package]]

View file

@ -29,7 +29,7 @@ __cbindgen_internal = ["runtime-all"]
# make runtime-metal depend on this, so its automatically implied. # make runtime-metal depend on this, so its automatically implied.
# this will make cbindgen generate __OBJC__ ifdefs for metal functions. # this will make cbindgen generate __OBJC__ ifdefs for metal functions.
__cbindgen_internal_objc = ["icrate", "objc2"] __cbindgen_internal_objc = ["objc2-metal", "objc2"]
[dependencies] [dependencies]
thiserror = "1.0.37" thiserror = "1.0.37"
@ -51,7 +51,7 @@ workspace = true
optional = true optional = true
[target.'cfg(target_vendor="apple")'.dependencies] [target.'cfg(target_vendor="apple")'.dependencies]
icrate = { version = "0.1.0" , features = [ "Metal", "Metal_all" ], optional = true } objc2-metal = { version = "0.2.0" , features = [ "all" ], optional = true }
objc2 = { version = "0.5.0", features = ["apple"] , optional = true } objc2 = { version = "0.5.0", features = ["apple"] , optional = true }
[package.metadata.docs.rs] [package.metadata.docs.rs]

View file

@ -13,8 +13,8 @@ use std::slice;
use librashader::runtime::FilterChainParameters; use librashader::runtime::FilterChainParameters;
use librashader::runtime::{Size, Viewport}; use librashader::runtime::{Size, Viewport};
use icrate::Metal::{MTLCommandBuffer, MTLCommandQueue, MTLTexture};
use objc2::runtime::ProtocolObject; use objc2::runtime::ProtocolObject;
use objc2_metal::{MTLCommandBuffer, MTLCommandQueue, MTLTexture};
use crate::LIBRASHADER_API_VERSION; use crate::LIBRASHADER_API_VERSION;

View file

@ -20,7 +20,7 @@ d3d12 = ["windows", "dxgi"]
dxgi = ["windows"] dxgi = ["windows"]
vulkan = ["ash"] vulkan = ["ash"]
wgpu = ["wgpu-types"] wgpu = ["wgpu-types"]
metal = ["icrate"] metal = ["objc2-metal"]
[dependencies] [dependencies]
gl = { version = "0.14.0", optional = true } gl = { version = "0.14.0", optional = true }
@ -42,7 +42,7 @@ features = [
"Win32_Graphics_Direct3D12", "Win32_Graphics_Direct3D12",
] ]
[target.'cfg(target_vendor="apple")'.dependencies.icrate] [target.'cfg(target_vendor="apple")'.dependencies.objc2-metal]
optional = true optional = true
version = "0.1.0" version = "0.2.0"
features = ["Metal", "Metal_all"] features = ["MTLPixelFormat", "MTLRenderCommandEncoder", "MTLSampler"]

View file

@ -1,46 +1,48 @@
use crate::{FilterMode, ImageFormat, Size, WrapMode}; use crate::{FilterMode, ImageFormat, Size, WrapMode};
use icrate::Metal; use objc2_metal::{
MTLPixelFormat, MTLSamplerAddressMode, MTLSamplerMinMagFilter, MTLSamplerMipFilter, MTLViewport,
};
impl From<ImageFormat> for Metal::MTLPixelFormat { impl From<ImageFormat> for MTLPixelFormat {
fn from(format: ImageFormat) -> Self { fn from(format: ImageFormat) -> Self {
match format { match format {
ImageFormat::Unknown => 0 as Metal::MTLPixelFormat, ImageFormat::Unknown => MTLPixelFormat(0),
ImageFormat::R8Unorm => Metal::MTLPixelFormatR8Unorm, ImageFormat::R8Unorm => MTLPixelFormat::R8Unorm,
ImageFormat::R8Uint => Metal::MTLPixelFormatR8Uint, ImageFormat::R8Uint => MTLPixelFormat::R8Uint,
ImageFormat::R8Sint => Metal::MTLPixelFormatR8Sint, ImageFormat::R8Sint => MTLPixelFormat::R8Sint,
ImageFormat::R8G8Unorm => Metal::MTLPixelFormatRG8Unorm, ImageFormat::R8G8Unorm => MTLPixelFormat::RG8Unorm,
ImageFormat::R8G8Uint => Metal::MTLPixelFormatRG8Uint, ImageFormat::R8G8Uint => MTLPixelFormat::RG8Uint,
ImageFormat::R8G8Sint => Metal::MTLPixelFormatRG8Sint, ImageFormat::R8G8Sint => MTLPixelFormat::RG8Sint,
ImageFormat::R8G8B8A8Unorm => Metal::MTLPixelFormatRGBA8Unorm, ImageFormat::R8G8B8A8Unorm => MTLPixelFormat::RGBA8Unorm,
ImageFormat::R8G8B8A8Uint => Metal::MTLPixelFormatRGBA8Uint, ImageFormat::R8G8B8A8Uint => MTLPixelFormat::RGBA8Uint,
ImageFormat::R8G8B8A8Sint => Metal::MTLPixelFormatRGBA8Sint, ImageFormat::R8G8B8A8Sint => MTLPixelFormat::RGBA8Sint,
ImageFormat::R8G8B8A8Srgb => Metal::MTLPixelFormatRGBA8Unorm_sRGB, ImageFormat::R8G8B8A8Srgb => MTLPixelFormat::RGBA8Unorm_sRGB,
ImageFormat::A2B10G10R10UnormPack32 => Metal::MTLPixelFormatRGB10A2Unorm, ImageFormat::A2B10G10R10UnormPack32 => MTLPixelFormat::RGB10A2Unorm,
ImageFormat::A2B10G10R10UintPack32 => Metal::MTLPixelFormatRGB10A2Uint, ImageFormat::A2B10G10R10UintPack32 => MTLPixelFormat::RGB10A2Uint,
ImageFormat::R16Uint => Metal::MTLPixelFormatR16Uint, ImageFormat::R16Uint => MTLPixelFormat::R16Uint,
ImageFormat::R16Sint => Metal::MTLPixelFormatR16Sint, ImageFormat::R16Sint => MTLPixelFormat::R16Sint,
ImageFormat::R16Sfloat => Metal::MTLPixelFormatR16Float, ImageFormat::R16Sfloat => MTLPixelFormat::R16Float,
ImageFormat::R16G16Uint => Metal::MTLPixelFormatRG16Uint, ImageFormat::R16G16Uint => MTLPixelFormat::RG16Uint,
ImageFormat::R16G16Sint => Metal::MTLPixelFormatRG16Sint, ImageFormat::R16G16Sint => MTLPixelFormat::RG16Sint,
ImageFormat::R16G16Sfloat => Metal::MTLPixelFormatRG16Float, ImageFormat::R16G16Sfloat => MTLPixelFormat::RG16Float,
ImageFormat::R16G16B16A16Uint => Metal::MTLPixelFormatRGBA16Uint, ImageFormat::R16G16B16A16Uint => MTLPixelFormat::RGBA16Uint,
ImageFormat::R16G16B16A16Sint => Metal::MTLPixelFormatRGBA16Sint, ImageFormat::R16G16B16A16Sint => MTLPixelFormat::RGBA16Sint,
ImageFormat::R16G16B16A16Sfloat => Metal::MTLPixelFormatRGBA16Float, ImageFormat::R16G16B16A16Sfloat => MTLPixelFormat::RGBA16Float,
ImageFormat::R32Uint => Metal::MTLPixelFormatR32Uint, ImageFormat::R32Uint => MTLPixelFormat::R32Uint,
ImageFormat::R32Sint => Metal::MTLPixelFormatR32Sint, ImageFormat::R32Sint => MTLPixelFormat::R32Sint,
ImageFormat::R32Sfloat => Metal::MTLPixelFormatR32Float, ImageFormat::R32Sfloat => MTLPixelFormat::R32Float,
ImageFormat::R32G32Uint => Metal::MTLPixelFormatRG32Uint, ImageFormat::R32G32Uint => MTLPixelFormat::RG32Uint,
ImageFormat::R32G32Sint => Metal::MTLPixelFormatRG32Sint, ImageFormat::R32G32Sint => MTLPixelFormat::RG32Sint,
ImageFormat::R32G32Sfloat => Metal::MTLPixelFormatRG32Float, ImageFormat::R32G32Sfloat => MTLPixelFormat::RG32Float,
ImageFormat::R32G32B32A32Uint => Metal::MTLPixelFormatRGBA32Uint, ImageFormat::R32G32B32A32Uint => MTLPixelFormat::RGBA32Uint,
ImageFormat::R32G32B32A32Sint => Metal::MTLPixelFormatRGBA32Sint, ImageFormat::R32G32B32A32Sint => MTLPixelFormat::RGBA32Sint,
ImageFormat::R32G32B32A32Sfloat => Metal::MTLPixelFormatRGBA32Float, ImageFormat::R32G32B32A32Sfloat => MTLPixelFormat::RGBA32Float,
} }
} }
} }
impl From<Metal::MTLViewport> for Size<u32> { impl From<MTLViewport> for Size<u32> {
fn from(value: Metal::MTLViewport) -> Self { fn from(value: MTLViewport) -> Self {
Size { Size {
width: value.width as u32, width: value.width as u32,
height: value.height as u32, height: value.height as u32,
@ -48,9 +50,9 @@ impl From<Metal::MTLViewport> for Size<u32> {
} }
} }
impl From<Size<u32>> for Metal::MTLViewport { impl From<Size<u32>> for MTLViewport {
fn from(value: Size<u32>) -> Self { fn from(value: Size<u32>) -> Self {
Metal::MTLViewport { MTLViewport {
originX: 0.0, originX: 0.0,
originY: 0.0, originY: 0.0,
width: value.width as f64, width: value.width as f64,
@ -61,32 +63,32 @@ impl From<Size<u32>> for Metal::MTLViewport {
} }
} }
impl From<WrapMode> for Metal::MTLSamplerAddressMode { impl From<WrapMode> for MTLSamplerAddressMode {
fn from(value: WrapMode) -> Self { fn from(value: WrapMode) -> Self {
match value { match value {
WrapMode::ClampToBorder => Metal::MTLSamplerAddressModeClampToBorderColor, WrapMode::ClampToBorder => MTLSamplerAddressMode::ClampToBorderColor,
WrapMode::ClampToEdge => Metal::MTLSamplerAddressModeClampToEdge, WrapMode::ClampToEdge => MTLSamplerAddressMode::ClampToEdge,
WrapMode::Repeat => Metal::MTLSamplerAddressModeRepeat, WrapMode::Repeat => MTLSamplerAddressMode::Repeat,
WrapMode::MirroredRepeat => Metal::MTLSamplerAddressModeMirrorRepeat, WrapMode::MirroredRepeat => MTLSamplerAddressMode::MirrorRepeat,
} }
} }
} }
impl From<FilterMode> for Metal::MTLSamplerMinMagFilter { impl From<FilterMode> for MTLSamplerMinMagFilter {
fn from(value: FilterMode) -> Self { fn from(value: FilterMode) -> Self {
match value { match value {
FilterMode::Linear => Metal::MTLSamplerMinMagFilterLinear, FilterMode::Linear => MTLSamplerMinMagFilter::Linear,
_ => Metal::MTLSamplerMipFilterNearest, _ => MTLSamplerMinMagFilter::Nearest,
} }
} }
} }
impl FilterMode { impl FilterMode {
/// Get the mipmap filtering mode for the given combination. /// Get the mipmap filtering mode for the given combination.
pub fn mtl_mip(&self, mip: FilterMode) -> Metal::MTLSamplerMipFilter { pub fn mtl_mip(&self, _mip: FilterMode) -> MTLSamplerMipFilter {
match self { match self {
FilterMode::Linear => Metal::MTLSamplerMipFilterLinear, FilterMode::Linear => MTLSamplerMipFilter::Linear,
FilterMode::Nearest => Metal::MTLSamplerMipFilterNearest, FilterMode::Nearest => MTLSamplerMipFilter::Nearest,
} }
} }
} }

View file

@ -34,12 +34,14 @@ harness = false
targets = ["x86_64-apple-darwin", "aarch64-apple-darwin", "aarch64-apple-ios"] targets = ["x86_64-apple-darwin", "aarch64-apple-darwin", "aarch64-apple-ios"]
[target.'cfg(target_vendor="apple")'.dependencies] [target.'cfg(target_vendor="apple")'.dependencies]
icrate = { version = "0.1.0" , features = [ "Metal", "Metal_all" ] } objc2-metal = { version = "0.2", features = ["all"] }
objc2-foundation = { version = "0.2", features = ["NSError"] }
objc2 = { version = "0.5.0", features = ["apple"] } objc2 = { version = "0.5.0", features = ["apple"] }
[features] [features]
run_test = ["icrate/AppKit", "icrate/AppKit_all", "icrate/Foundation", "icrate/Foundation_all", "icrate/MetalKit", "icrate/MetalKit_all"] # run_test = ["icrate/AppKit", "i "icrate/Foundation_all", "icrate/MetalKit", "icrate/MetalKit_all"]
#[lib] #[lib]
#crate-type = ["lib", "staticlib"] #crate-type = ["lib", "staticlib"]

View file

@ -1,16 +1,13 @@
use crate::error; use crate::error;
use crate::error::FilterChainError; use crate::error::FilterChainError;
use icrate::Foundation::{NSRange, NSString}; use objc2::rc::Retained;
use icrate::Metal::{
MTLBuffer, MTLDevice, MTLResource, MTLResourceOptions, MTLResourceStorageModeManaged,
MTLResourceStorageModeShared,
};
use objc2::rc::Id;
use objc2::runtime::ProtocolObject; use objc2::runtime::ProtocolObject;
use objc2_foundation::{NSRange, NSString};
use objc2_metal::{MTLBuffer, MTLDevice, MTLResource, MTLResourceOptions};
use std::ops::{Deref, DerefMut}; use std::ops::{Deref, DerefMut};
pub struct MetalBuffer { pub struct MetalBuffer {
buffer: Id<ProtocolObject<dyn MTLBuffer>>, buffer: Retained<ProtocolObject<dyn MTLBuffer>>,
size: usize, size: usize,
storage_mode: MTLResourceOptions, storage_mode: MTLResourceOptions,
} }
@ -28,9 +25,9 @@ impl MetalBuffer {
label: &str, label: &str,
) -> error::Result<Self> { ) -> error::Result<Self> {
let storage_mode = if cfg!(all(target_arch = "aarch64", target_vendor = "apple")) { let storage_mode = if cfg!(all(target_arch = "aarch64", target_vendor = "apple")) {
MTLResourceStorageModeShared MTLResourceOptions::MTLResourceStorageModeShared
} else { } else {
MTLResourceStorageModeManaged MTLResourceOptions::MTLResourceStorageModeManaged
}; };
// Can't create buffer of size 0. // Can't create buffer of size 0.
@ -53,7 +50,7 @@ impl MetalBuffer {
pub fn flush(&self) { pub fn flush(&self) {
// We don't know what was actually written to so... // We don't know what was actually written to so...
if self.storage_mode == MTLResourceStorageModeManaged { if self.storage_mode == MTLResourceOptions::MTLResourceStorageModeManaged {
self.buffer.didModifyRange(NSRange { self.buffer.didModifyRange(NSRange {
location: 0, location: 0,
length: self.size, length: self.size,

View file

@ -1,11 +1,10 @@
use array_concat::concat_arrays; use array_concat::concat_arrays;
use icrate::Metal::{
MTLBuffer, MTLDevice, MTLPrimitiveTypeTriangleStrip, MTLRenderCommandEncoder,
MTLResourceStorageModeManaged, MTLResourceStorageModeShared,
};
use librashader_runtime::quad::{QuadType, VertexInput}; use librashader_runtime::quad::{QuadType, VertexInput};
use objc2::rc::Id; use objc2::rc::Retained;
use objc2::runtime::ProtocolObject; use objc2::runtime::ProtocolObject;
use objc2_metal::{
MTLBuffer, MTLDevice, MTLPrimitiveType, MTLRenderCommandEncoder, MTLResourceOptions,
};
use std::ffi::c_void; use std::ffi::c_void;
use std::ptr::NonNull; use std::ptr::NonNull;
@ -53,7 +52,7 @@ const FINAL_VBO_DATA: [VertexInput; 4] = [
const VBO_DATA: [VertexInput; 8] = concat_arrays!(OFFSCREEN_VBO_DATA, FINAL_VBO_DATA); const VBO_DATA: [VertexInput; 8] = concat_arrays!(OFFSCREEN_VBO_DATA, FINAL_VBO_DATA);
pub struct DrawQuad { pub struct DrawQuad {
buffer: Id<ProtocolObject<dyn MTLBuffer>>, buffer: Retained<ProtocolObject<dyn MTLBuffer>>,
} }
impl DrawQuad { impl DrawQuad {
@ -83,9 +82,9 @@ impl DrawQuad {
NonNull::new_unchecked(vbo_data.as_ptr() as *mut c_void), NonNull::new_unchecked(vbo_data.as_ptr() as *mut c_void),
vbo_data.len(), vbo_data.len(),
if cfg!(target_os = "ios") { if cfg!(target_os = "ios") {
MTLResourceStorageModeShared MTLResourceOptions::MTLResourceStorageModeShared
} else { } else {
MTLResourceStorageModeManaged MTLResourceOptions::MTLResourceStorageModeManaged
}, },
) )
.ok_or(FilterChainError::BufferError)? .ok_or(FilterChainError::BufferError)?
@ -103,7 +102,7 @@ impl DrawQuad {
unsafe { unsafe {
cmd.setVertexBuffer_offset_atIndex(Some(&self.buffer), 0, VERTEX_BUFFER_INDEX); cmd.setVertexBuffer_offset_atIndex(Some(&self.buffer), 0, VERTEX_BUFFER_INDEX);
cmd.drawPrimitives_vertexStart_vertexCount(MTLPrimitiveTypeTriangleStrip, offset, 4); cmd.drawPrimitives_vertexStart_vertexCount(MTLPrimitiveType::TriangleStrip, offset, 4);
} }
} }
} }

View file

@ -1,11 +1,11 @@
//! Metal shader runtime errors. //! Metal shader runtime errors.
use icrate::Foundation::NSError;
use librashader_common::{FilterMode, WrapMode}; use librashader_common::{FilterMode, WrapMode};
use librashader_preprocess::PreprocessError; use librashader_preprocess::PreprocessError;
use librashader_presets::ParsePresetError; use librashader_presets::ParsePresetError;
use librashader_reflect::error::{ShaderCompileError, ShaderReflectError}; use librashader_reflect::error::{ShaderCompileError, ShaderReflectError};
use librashader_runtime::image::ImageError; use librashader_runtime::image::ImageError;
use objc2::rc::Id; use objc2::rc::Retained;
use objc2_foundation::NSError;
use thiserror::Error; use thiserror::Error;
/// Cumulative error type for Metal filter chains. /// Cumulative error type for Metal filter chains.
@ -26,7 +26,7 @@ pub enum FilterChainError {
#[error("buffer creation error")] #[error("buffer creation error")]
BufferError, BufferError,
#[error("metal error")] #[error("metal error")]
MetalError(#[from] Id<NSError>), MetalError(#[from] Retained<NSError>),
#[error("couldn't find entry for shader")] #[error("couldn't find entry for shader")]
ShaderWrongEntryName, ShaderWrongEntryName,
#[error("couldn't create render pass")] #[error("couldn't create render pass")]

View file

@ -8,12 +8,6 @@ use crate::luts::LutTexture;
use crate::options::{FilterChainOptionsMetal, FrameOptionsMetal}; use crate::options::{FilterChainOptionsMetal, FrameOptionsMetal};
use crate::samplers::SamplerSet; use crate::samplers::SamplerSet;
use crate::texture::{get_texture_size, InputTexture, MetalTextureRef, OwnedTexture}; use crate::texture::{get_texture_size, InputTexture, MetalTextureRef, OwnedTexture};
use icrate::Foundation::NSString;
use icrate::Metal::{
MTLCommandBuffer, MTLCommandEncoder, MTLCommandQueue, MTLDevice, MTLLoadActionClear,
MTLPixelFormat, MTLPixelFormatRGBA8Unorm, MTLRenderPassDescriptor, MTLResource,
MTLStoreActionDontCare, MTLStoreActionStore, MTLTexture,
};
use librashader_common::map::FastHashMap; use librashader_common::map::FastHashMap;
use librashader_common::{ImageFormat, Size, Viewport}; use librashader_common::{ImageFormat, Size, Viewport};
use librashader_presets::context::VideoDriver; use librashader_presets::context::VideoDriver;
@ -35,6 +29,11 @@ use librashader_runtime::scaling::ScaleFramebuffer;
use librashader_runtime::uniforms::UniformStorage; use librashader_runtime::uniforms::UniformStorage;
use objc2::rc::Id; use objc2::rc::Id;
use objc2::runtime::ProtocolObject; use objc2::runtime::ProtocolObject;
use objc2_foundation::NSString;
use objc2_metal::{
MTLCommandBuffer, MTLCommandEncoder, MTLCommandQueue, MTLDevice, MTLLoadAction, MTLPixelFormat,
MTLRenderPassDescriptor, MTLResource, MTLStoreAction, MTLTexture,
};
use rayon::prelude::*; use rayon::prelude::*;
use std::collections::VecDeque; use std::collections::VecDeque;
use std::fmt::{Debug, Formatter}; use std::fmt::{Debug, Formatter};
@ -184,8 +183,8 @@ impl FilterChainMetal {
let graphics_pipeline = MetalGraphicsPipeline::new( let graphics_pipeline = MetalGraphicsPipeline::new(
&device, &device,
&msl, &msl,
if render_pass_format == 0 { if render_pass_format == MTLPixelFormat(0) {
MTLPixelFormatRGBA8Unorm MTLPixelFormat::RGBA8Unorm
} else { } else {
render_pass_format render_pass_format
}, },
@ -344,11 +343,11 @@ impl FilterChainMetal {
let desc = MTLRenderPassDescriptor::new(); let desc = MTLRenderPassDescriptor::new();
desc.colorAttachments() desc.colorAttachments()
.objectAtIndexedSubscript(0) .objectAtIndexedSubscript(0)
.setLoadAction(MTLLoadActionClear); .setLoadAction(MTLLoadAction::Clear);
desc.colorAttachments() desc.colorAttachments()
.objectAtIndexedSubscript(0) .objectAtIndexedSubscript(0)
.setStoreAction(MTLStoreActionDontCare); .setStoreAction(MTLStoreAction::DontCare);
desc desc
}; };
@ -360,8 +359,8 @@ impl FilterChainMetal {
.colorAttachments() .colorAttachments()
.objectAtIndexedSubscript(index); .objectAtIndexedSubscript(index);
ca.setTexture(Some(&history.texture)); ca.setTexture(Some(&history.texture));
ca.setLoadAction(MTLLoadActionClear); ca.setLoadAction(MTLLoadAction::Clear);
ca.setStoreAction(MTLStoreActionStore); ca.setStoreAction(MTLStoreAction::Store);
} }
} }
} }

View file

@ -5,7 +5,6 @@ use crate::graphics_pipeline::MetalGraphicsPipeline;
use crate::options::FrameOptionsMetal; use crate::options::FrameOptionsMetal;
use crate::samplers::SamplerSet; use crate::samplers::SamplerSet;
use crate::texture::{get_texture_size, InputTexture}; use crate::texture::{get_texture_size, InputTexture};
use icrate::Metal::{MTLCommandBuffer, MTLCommandEncoder, MTLRenderCommandEncoder, MTLTexture};
use librashader_common::map::FastHashMap; use librashader_common::map::FastHashMap;
use librashader_common::{ImageFormat, Size, Viewport}; use librashader_common::{ImageFormat, Size, Viewport};
use librashader_preprocess::ShaderSource; use librashader_preprocess::ShaderSource;
@ -18,6 +17,7 @@ use librashader_runtime::quad::QuadType;
use librashader_runtime::render_target::RenderTarget; use librashader_runtime::render_target::RenderTarget;
use librashader_runtime::uniforms::{NoUniformBinder, UniformStorage}; use librashader_runtime::uniforms::{NoUniformBinder, UniformStorage};
use objc2::runtime::ProtocolObject; use objc2::runtime::ProtocolObject;
use objc2_metal::{MTLCommandBuffer, MTLCommandEncoder, MTLRenderCommandEncoder, MTLTexture};
impl TextureInput for InputTexture { impl TextureInput for InputTexture {
fn size(&self) -> Size<u32> { fn size(&self) -> Size<u32> {

View file

@ -1,22 +1,21 @@
use crate::error::{FilterChainError, Result}; use crate::error::{FilterChainError, Result};
use crate::select_optimal_pixel_format; use crate::select_optimal_pixel_format;
use bytemuck::offset_of; use bytemuck::offset_of;
use icrate::Foundation::NSString;
use icrate::Metal::{
MTLBlendFactorOneMinusSourceAlpha, MTLBlendFactorSourceAlpha, MTLCommandBuffer,
MTLCommandEncoder, MTLDevice, MTLFunction, MTLLibrary, MTLLoadActionDontCare, MTLPixelFormat,
MTLPrimitiveTopologyClassTriangle, MTLRenderCommandEncoder, MTLRenderPassDescriptor,
MTLRenderPipelineColorAttachmentDescriptor, MTLRenderPipelineDescriptor,
MTLRenderPipelineState, MTLScissorRect, MTLStoreActionStore, MTLTexture,
MTLVertexAttributeDescriptor, MTLVertexBufferLayoutDescriptor, MTLVertexDescriptor,
MTLVertexFormatFloat2, MTLVertexFormatFloat4, MTLVertexStepFunctionPerVertex, MTLViewport,
};
use librashader_reflect::back::msl::{CrossMslContext, NagaMslContext}; use librashader_reflect::back::msl::{CrossMslContext, NagaMslContext};
use librashader_reflect::back::ShaderCompilerOutput; use librashader_reflect::back::ShaderCompilerOutput;
use librashader_runtime::quad::VertexInput; use librashader_runtime::quad::VertexInput;
use librashader_runtime::render_target::RenderTarget; use librashader_runtime::render_target::RenderTarget;
use objc2_foundation::NSString;
use objc2_metal::{
MTLBlendFactor, MTLCommandBuffer, MTLCommandEncoder, MTLDevice, MTLFunction, MTLLibrary,
MTLLoadAction, MTLPixelFormat, MTLPrimitiveTopologyClass, MTLRenderCommandEncoder,
MTLRenderPassDescriptor, MTLRenderPipelineColorAttachmentDescriptor,
MTLRenderPipelineDescriptor, MTLRenderPipelineState, MTLScissorRect, MTLStoreAction,
MTLTexture, MTLVertexAttributeDescriptor, MTLVertexBufferLayoutDescriptor, MTLVertexDescriptor,
MTLVertexFormat, MTLVertexStepFunction, MTLViewport,
};
use objc2::rc::Id; use objc2::rc::Retained;
use objc2::runtime::ProtocolObject; use objc2::runtime::ProtocolObject;
/// This is only really plausible for SPIRV-Cross, for Naga we need to supply the next plausible binding. /// This is only really plausible for SPIRV-Cross, for Naga we need to supply the next plausible binding.
@ -24,29 +23,29 @@ pub const VERTEX_BUFFER_INDEX: usize = 4;
pub struct MetalGraphicsPipeline { pub struct MetalGraphicsPipeline {
pub layout: PipelineLayoutObjects, pub layout: PipelineLayoutObjects,
render_pipeline: Id<ProtocolObject<dyn MTLRenderPipelineState>>, render_pipeline: Retained<ProtocolObject<dyn MTLRenderPipelineState>>,
pub render_pass_format: MTLPixelFormat, pub render_pass_format: MTLPixelFormat,
} }
pub struct PipelineLayoutObjects { pub struct PipelineLayoutObjects {
_vertex_lib: Id<ProtocolObject<dyn MTLLibrary>>, _vertex_lib: Retained<ProtocolObject<dyn MTLLibrary>>,
_fragment_lib: Id<ProtocolObject<dyn MTLLibrary>>, _fragment_lib: Retained<ProtocolObject<dyn MTLLibrary>>,
vertex_entry: Id<ProtocolObject<dyn MTLFunction>>, vertex_entry: Retained<ProtocolObject<dyn MTLFunction>>,
fragment_entry: Id<ProtocolObject<dyn MTLFunction>>, fragment_entry: Retained<ProtocolObject<dyn MTLFunction>>,
} }
pub(crate) trait MslEntryPoint { pub(crate) trait MslEntryPoint {
fn entry_point() -> Id<NSString>; fn entry_point() -> Retained<NSString>;
} }
impl MslEntryPoint for CrossMslContext { impl MslEntryPoint for CrossMslContext {
fn entry_point() -> Id<NSString> { fn entry_point() -> Retained<NSString> {
NSString::from_str("main0") NSString::from_str("main0")
} }
} }
impl MslEntryPoint for NagaMslContext { impl MslEntryPoint for NagaMslContext {
fn entry_point() -> Id<NSString> { fn entry_point() -> Retained<NSString> {
NSString::from_str("main_") NSString::from_str("main_")
} }
} }
@ -78,7 +77,7 @@ impl PipelineLayoutObjects {
}) })
} }
unsafe fn create_vertex_descriptor() -> Id<MTLVertexDescriptor> { unsafe fn create_vertex_descriptor() -> Retained<MTLVertexDescriptor> {
let descriptor = MTLVertexDescriptor::new(); let descriptor = MTLVertexDescriptor::new();
let attributes = descriptor.attributes(); let attributes = descriptor.attributes();
let layouts = descriptor.layouts(); let layouts = descriptor.layouts();
@ -89,11 +88,11 @@ impl PipelineLayoutObjects {
let texcoord = MTLVertexAttributeDescriptor::new(); let texcoord = MTLVertexAttributeDescriptor::new();
// hopefully metal fills in vertices otherwise we'll need to use the vec4 stuff. // hopefully metal fills in vertices otherwise we'll need to use the vec4 stuff.
position.setFormat(MTLVertexFormatFloat4); position.setFormat(MTLVertexFormat::Float4);
position.setBufferIndex(VERTEX_BUFFER_INDEX); position.setBufferIndex(VERTEX_BUFFER_INDEX);
position.setOffset(offset_of!(VertexInput, position)); position.setOffset(offset_of!(VertexInput, position));
texcoord.setFormat(MTLVertexFormatFloat2); texcoord.setFormat(MTLVertexFormat::Float2);
texcoord.setBufferIndex(VERTEX_BUFFER_INDEX); texcoord.setBufferIndex(VERTEX_BUFFER_INDEX);
texcoord.setOffset(offset_of!(VertexInput, texcoord)); texcoord.setOffset(offset_of!(VertexInput, texcoord));
@ -101,7 +100,7 @@ impl PipelineLayoutObjects {
attributes.setObject_atIndexedSubscript(Some(&texcoord), 1); attributes.setObject_atIndexedSubscript(Some(&texcoord), 1);
binding.setStepFunction(MTLVertexStepFunctionPerVertex); binding.setStepFunction(MTLVertexStepFunction::PerVertex);
binding.setStride(std::mem::size_of::<VertexInput>()); binding.setStride(std::mem::size_of::<VertexInput>());
layouts.setObject_atIndexedSubscript(Some(&binding), VERTEX_BUFFER_INDEX); layouts.setObject_atIndexedSubscript(Some(&binding), VERTEX_BUFFER_INDEX);
@ -109,15 +108,15 @@ impl PipelineLayoutObjects {
} }
unsafe fn create_color_attachments( unsafe fn create_color_attachments(
ca: Id<MTLRenderPipelineColorAttachmentDescriptor>, ca: Retained<MTLRenderPipelineColorAttachmentDescriptor>,
format: MTLPixelFormat, format: MTLPixelFormat,
) -> Id<MTLRenderPipelineColorAttachmentDescriptor> { ) -> Retained<MTLRenderPipelineColorAttachmentDescriptor> {
ca.setPixelFormat(select_optimal_pixel_format(format)); ca.setPixelFormat(select_optimal_pixel_format(format));
ca.setBlendingEnabled(false); ca.setBlendingEnabled(false);
ca.setSourceAlphaBlendFactor(MTLBlendFactorSourceAlpha); ca.setSourceAlphaBlendFactor(MTLBlendFactor::SourceAlpha);
ca.setSourceRGBBlendFactor(MTLBlendFactorSourceAlpha); ca.setSourceRGBBlendFactor(MTLBlendFactor::SourceAlpha);
ca.setDestinationAlphaBlendFactor(MTLBlendFactorOneMinusSourceAlpha); ca.setDestinationAlphaBlendFactor(MTLBlendFactor::OneMinusSourceAlpha);
ca.setDestinationRGBBlendFactor(MTLBlendFactorOneMinusSourceAlpha); ca.setDestinationRGBBlendFactor(MTLBlendFactor::OneMinusSourceAlpha);
ca ca
} }
@ -126,12 +125,12 @@ impl PipelineLayoutObjects {
&self, &self,
device: &ProtocolObject<dyn MTLDevice>, device: &ProtocolObject<dyn MTLDevice>,
format: MTLPixelFormat, format: MTLPixelFormat,
) -> Result<Id<ProtocolObject<dyn MTLRenderPipelineState>>> { ) -> Result<Retained<ProtocolObject<dyn MTLRenderPipelineState>>> {
let descriptor = MTLRenderPipelineDescriptor::new(); let descriptor = MTLRenderPipelineDescriptor::new();
unsafe { unsafe {
let vertex = Self::create_vertex_descriptor(); let vertex = Self::create_vertex_descriptor();
descriptor.setInputPrimitiveTopology(MTLPrimitiveTopologyClassTriangle); descriptor.setInputPrimitiveTopology(MTLPrimitiveTopologyClass::Triangle);
descriptor.setVertexDescriptor(Some(&vertex)); descriptor.setVertexDescriptor(Some(&vertex));
let ca = descriptor.colorAttachments().objectAtIndexedSubscript(0); let ca = descriptor.colorAttachments().objectAtIndexedSubscript(0);
@ -176,12 +175,12 @@ impl MetalGraphicsPipeline {
&self, &self,
output: &RenderTarget<ProtocolObject<dyn MTLTexture>>, output: &RenderTarget<ProtocolObject<dyn MTLTexture>>,
buffer: &ProtocolObject<dyn MTLCommandBuffer>, buffer: &ProtocolObject<dyn MTLCommandBuffer>,
) -> Result<Id<ProtocolObject<dyn MTLRenderCommandEncoder>>> { ) -> Result<Retained<ProtocolObject<dyn MTLRenderCommandEncoder>>> {
unsafe { unsafe {
let descriptor = MTLRenderPassDescriptor::new(); let descriptor = MTLRenderPassDescriptor::new();
let ca = descriptor.colorAttachments().objectAtIndexedSubscript(0); let ca = descriptor.colorAttachments().objectAtIndexedSubscript(0);
ca.setLoadAction(MTLLoadActionDontCare); ca.setLoadAction(MTLLoadAction::DontCare);
ca.setStoreAction(MTLStoreActionStore); ca.setStoreAction(MTLStoreAction::Store);
ca.setTexture(Some(output.output)); ca.setTexture(Some(output.output));
let rpass = buffer let rpass = buffer

View file

@ -11,10 +11,7 @@ mod samplers;
mod texture; mod texture;
pub use filter_chain::FilterChainMetal; pub use filter_chain::FilterChainMetal;
use icrate::Metal::{ use objc2_metal::MTLPixelFormat;
MTLPixelFormat, MTLPixelFormatBGRA8Unorm, MTLPixelFormatBGRA8Unorm_sRGB,
MTLPixelFormatRGBA8Unorm, MTLPixelFormatRGBA8Unorm_sRGB,
};
pub mod error; pub mod error;
pub mod options; pub mod options;
@ -24,12 +21,12 @@ impl_filter_chain_parameters!(FilterChainMetal);
pub use texture::MetalTextureRef; pub use texture::MetalTextureRef;
fn select_optimal_pixel_format(format: MTLPixelFormat) -> MTLPixelFormat { fn select_optimal_pixel_format(format: MTLPixelFormat) -> MTLPixelFormat {
if format == MTLPixelFormatRGBA8Unorm { if format == MTLPixelFormat::RGBA8Unorm {
return MTLPixelFormatBGRA8Unorm; return MTLPixelFormat::BGRA8Unorm;
} }
if format == MTLPixelFormatRGBA8Unorm_sRGB { if format == MTLPixelFormat::RGBA8Unorm_sRGB {
return MTLPixelFormatBGRA8Unorm_sRGB; return MTLPixelFormat::BGRA8Unorm_sRGB;
} }
return format; return format;
} }

View file

@ -1,14 +1,13 @@
use crate::error::{FilterChainError, Result}; use crate::error::{FilterChainError, Result};
use crate::texture::InputTexture; use crate::texture::InputTexture;
use icrate::Metal::{
MTLBlitCommandEncoder, MTLDevice, MTLOrigin, MTLPixelFormatBGRA8Unorm, MTLRegion,
MTLResourceStorageModeManaged, MTLResourceStorageModeShared, MTLSize, MTLTexture,
MTLTextureDescriptor, MTLTextureUsageShaderRead,
};
use librashader_presets::TextureConfig; use librashader_presets::TextureConfig;
use librashader_runtime::image::{Image, BGRA8}; use librashader_runtime::image::{Image, BGRA8};
use librashader_runtime::scaling::MipmapSize; use librashader_runtime::scaling::MipmapSize;
use objc2::runtime::ProtocolObject; use objc2::runtime::ProtocolObject;
use objc2_metal::{
MTLBlitCommandEncoder, MTLDevice, MTLOrigin, MTLPixelFormat, MTLRegion, MTLSize,
MTLStorageMode, MTLTexture, MTLTextureDescriptor, MTLTextureUsage,
};
use std::ffi::c_void; use std::ffi::c_void;
use std::ptr::NonNull; use std::ptr::NonNull;
@ -30,7 +29,7 @@ impl LutTexture {
let descriptor = unsafe { let descriptor = unsafe {
let descriptor = let descriptor =
MTLTextureDescriptor::texture2DDescriptorWithPixelFormat_width_height_mipmapped( MTLTextureDescriptor::texture2DDescriptorWithPixelFormat_width_height_mipmapped(
MTLPixelFormatBGRA8Unorm, MTLPixelFormat::BGRA8Unorm,
image.size.width as usize, image.size.width as usize,
image.size.height as usize, image.size.height as usize,
config.mipmap, config.mipmap,
@ -45,13 +44,13 @@ impl LutTexture {
descriptor.setStorageMode( descriptor.setStorageMode(
if cfg!(all(target_arch = "aarch64", target_vendor = "apple")) { if cfg!(all(target_arch = "aarch64", target_vendor = "apple")) {
MTLResourceStorageModeShared MTLStorageMode::Shared
} else { } else {
MTLResourceStorageModeManaged MTLStorageMode::Managed
}, },
); );
descriptor.setUsage(MTLTextureUsageShaderRead); descriptor.setUsage(MTLTextureUsage::ShaderRead);
descriptor descriptor
}; };

View file

@ -1,19 +1,20 @@
use icrate::Metal::{
MTLCompareFunctionNever, MTLDevice, MTLSamplerAddressMode,
MTLSamplerBorderColorTransparentBlack, MTLSamplerDescriptor, MTLSamplerMinMagFilter,
MTLSamplerState,
};
use librashader_common::map::FastHashMap; use librashader_common::map::FastHashMap;
use librashader_common::{FilterMode, WrapMode}; use librashader_common::{FilterMode, WrapMode};
use objc2::rc::Id; use objc2::rc::Retained;
use objc2::runtime::ProtocolObject; use objc2::runtime::ProtocolObject;
use objc2_metal::{
MTLCompareFunction, MTLDevice, MTLSamplerAddressMode, MTLSamplerBorderColor,
MTLSamplerDescriptor, MTLSamplerMinMagFilter, MTLSamplerState,
};
use crate::error::{FilterChainError, Result}; use crate::error::{FilterChainError, Result};
pub struct SamplerSet { pub struct SamplerSet {
// todo: may need to deal with differences in mip filter. // todo: may need to deal with differences in mip filter.
samplers: samplers: FastHashMap<
FastHashMap<(WrapMode, FilterMode, FilterMode), Id<ProtocolObject<dyn MTLSamplerState>>>, (WrapMode, FilterMode, FilterMode),
Retained<ProtocolObject<dyn MTLSamplerState>>,
>,
} }
impl SamplerSet { impl SamplerSet {
@ -27,7 +28,7 @@ impl SamplerSet {
// eprintln!("{wrap}, {filter}, {mip}"); // eprintln!("{wrap}, {filter}, {mip}");
// SAFETY: the sampler set is complete for the matrix // SAFETY: the sampler set is complete for the matrix
// wrap x filter x mipmap // wrap x filter x mipmap
let id: &Id<ProtocolObject<dyn MTLSamplerState>> = unsafe { let id: &Retained<ProtocolObject<dyn MTLSamplerState>> = unsafe {
self.samplers self.samplers
.get(&(wrap, filter, mipmap)) .get(&(wrap, filter, mipmap))
.unwrap_unchecked() .unwrap_unchecked()
@ -58,9 +59,9 @@ impl SamplerSet {
descriptor.setMipFilter(filter_mode.mtl_mip(*mipmap_filter)); descriptor.setMipFilter(filter_mode.mtl_mip(*mipmap_filter));
descriptor.setLodMinClamp(0.0); descriptor.setLodMinClamp(0.0);
descriptor.setLodMaxClamp(1000.0); descriptor.setLodMaxClamp(1000.0);
descriptor.setCompareFunction(MTLCompareFunctionNever); descriptor.setCompareFunction(MTLCompareFunction::Never);
descriptor.setMaxAnisotropy(1); descriptor.setMaxAnisotropy(1);
descriptor.setBorderColor(MTLSamplerBorderColorTransparentBlack); descriptor.setBorderColor(MTLSamplerBorderColor::TransparentBlack);
descriptor.setNormalizedCoordinates(true); descriptor.setNormalizedCoordinates(true);
let Some(sampler_state) = device.newSamplerStateWithDescriptor(&descriptor) let Some(sampler_state) = device.newSamplerStateWithDescriptor(&descriptor)

View file

@ -1,17 +1,16 @@
use crate::error::{FilterChainError, Result}; use crate::error::{FilterChainError, Result};
use crate::select_optimal_pixel_format; use crate::select_optimal_pixel_format;
use icrate::Metal::{
MTLBlitCommandEncoder, MTLCommandBuffer, MTLCommandEncoder, MTLDevice, MTLPixelFormat,
MTLStorageModePrivate, MTLTexture, MTLTextureDescriptor, MTLTextureUsageRenderTarget,
MTLTextureUsageShaderRead, MTLTextureUsageShaderWrite,
};
use librashader_common::{FilterMode, ImageFormat, Size, WrapMode}; use librashader_common::{FilterMode, ImageFormat, Size, WrapMode};
use librashader_presets::Scale2D; use librashader_presets::Scale2D;
use librashader_runtime::scaling::{MipmapSize, ScaleFramebuffer, ViewportSize}; use librashader_runtime::scaling::{MipmapSize, ScaleFramebuffer, ViewportSize};
use objc2::rc::Id; use objc2::rc::Retained;
use objc2::runtime::ProtocolObject; use objc2::runtime::ProtocolObject;
use objc2_metal::{
MTLBlitCommandEncoder, MTLCommandBuffer, MTLCommandEncoder, MTLDevice, MTLPixelFormat,
MTLStorageMode, MTLTexture, MTLTextureDescriptor, MTLTextureUsage,
};
pub type MetalTexture = Id<ProtocolObject<dyn MTLTexture>>; pub type MetalTexture = Retained<ProtocolObject<dyn MTLTexture>>;
/// Alias to an `id<MTLTexture>`. /// Alias to an `id<MTLTexture>`.
pub type MetalTextureRef<'a> = &'a ProtocolObject<dyn MTLTexture>; pub type MetalTextureRef<'a> = &'a ProtocolObject<dyn MTLTexture>;
@ -71,11 +70,11 @@ impl OwnedTexture {
1 1
}); });
descriptor.setStorageMode(MTLStorageModePrivate); descriptor.setStorageMode(MTLStorageMode::Private);
descriptor.setUsage( descriptor.setUsage(
MTLTextureUsageShaderRead MTLTextureUsage::ShaderRead
| MTLTextureUsageShaderWrite | MTLTextureUsage::ShaderWrite
| MTLTextureUsageRenderTarget, | MTLTextureUsage::RenderTarget,
); );
descriptor descriptor

View file

@ -39,7 +39,7 @@ workspace = true
optional = true optional = true
[target.'cfg(target_vendor="apple")'.dependencies] [target.'cfg(target_vendor="apple")'.dependencies]
icrate = { version = "0.1.0" , features = [ "Metal", "Metal_all" ], optional = true} objc2-metal = { version = "0.2.0" , features = [ "all" ], optional = true}
objc2 = { version = "0.5.0", features = ["apple"] , optional = true } objc2 = { version = "0.5.0", features = ["apple"] , optional = true }
[features] [features]
@ -58,7 +58,7 @@ runtime-d3d9 = [ "runtime", "reflect-cross", "librashader-common/d3d9", "librash
runtime-vk = ["runtime", "reflect-cross", "librashader-common/vulkan", "librashader-runtime-vk", "ash" ] runtime-vk = ["runtime", "reflect-cross", "librashader-common/vulkan", "librashader-runtime-vk", "ash" ]
runtime-wgpu = [ "runtime", "reflect-naga", "librashader-common/wgpu", "librashader-runtime-wgpu", "wgpu", "wgpu-types" ] runtime-wgpu = [ "runtime", "reflect-naga", "librashader-common/wgpu", "librashader-runtime-wgpu", "wgpu", "wgpu-types" ]
runtime-metal = [ "runtime", "reflect-naga", "reflect-cross", "librashader-common/metal", "librashader-runtime-mtl", "icrate", "objc2" ] runtime-metal = [ "runtime", "reflect-naga", "reflect-cross", "librashader-common/metal", "librashader-runtime-mtl", "objc2-metal", "objc2" ]
# reflection # reflection
reflect-cross = ["reflect", "librashader-reflect/cross"] reflect-cross = ["reflect", "librashader-reflect/cross"]
@ -75,7 +75,7 @@ internal = []
full = ["runtime-all", "reflect-all", "preprocess", "presets"] full = ["runtime-all", "reflect-all", "preprocess", "presets"]
# cache hack # cache hack
docsrs = ["librashader-cache/docsrs", "objc2/unstable-docsrs"] docsrs = ["librashader-cache/docsrs"]
# emits warning messages in tests # emits warning messages in tests
github-ci = [] github-ci = []