rt(mtl): move icrate definitions to objc2-metal
This commit is contained in:
parent
5e9ce1207c
commit
b5d523e9f3
130
Cargo.lock
generated
130
Cargo.lock
generated
|
@ -125,7 +125,7 @@ checksum = "0ae92a5119aa49cdbcf6b9f893fe4e1d98b04ccbf82ee0584ad948a44a734dea"
|
|||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.66",
|
||||
"syn 2.0.67",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -186,7 +186,7 @@ checksum = "c6fa2087f2753a7da8cc1c0dbfcf89579dd57458e36769de5ac750b4671737ca"
|
|||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.66",
|
||||
"syn 2.0.67",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -301,9 +301,9 @@ checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1"
|
|||
|
||||
[[package]]
|
||||
name = "bitstream-io"
|
||||
version = "2.4.0"
|
||||
version = "2.4.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1bdba4ac537b9346c50122b6e9f9b0d2bd721e04c6032e1d15f53ce0747b054c"
|
||||
checksum = "415f8399438eb5e4b2f73ed3152a3448b98149dda642a957ee704e1daa5cf1d8"
|
||||
|
||||
[[package]]
|
||||
name = "bitvec"
|
||||
|
@ -366,12 +366,11 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "block2"
|
||||
version = "0.4.0"
|
||||
version = "0.5.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e58aa60e59d8dbfcc36138f5f18be5f24394d33b38b24f7fd0b1caa33095f22f"
|
||||
checksum = "2c132eebf10f5cad5289222520a4a058514204aed6d791f1cf4fe8088b82d15f"
|
||||
dependencies = [
|
||||
"block-sys",
|
||||
"objc2 0.5.1",
|
||||
"objc2 0.5.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -400,9 +399,9 @@ checksum = "5ce89b21cab1437276d2650d57e971f9d548a2d9037cc231abdc0562b97498ce"
|
|||
|
||||
[[package]]
|
||||
name = "bytemuck"
|
||||
version = "1.16.0"
|
||||
version = "1.16.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "78834c15cb5d5efe3452d58b1e8ba890dd62d21907f867f383358198e56ebca5"
|
||||
checksum = "b236fc92302c97ed75b38da1f4917b5cdda4984745740f153a5d3059e48d725e"
|
||||
dependencies = [
|
||||
"bytemuck_derive",
|
||||
]
|
||||
|
@ -415,7 +414,7 @@ checksum = "1ee891b04274a59bd38b412188e24b849617b2e45a0fd8d057deb63e7403761b"
|
|||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.66",
|
||||
"syn 2.0.67",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1039,7 +1038,7 @@ checksum = "1a5c6c585bc94aaf2c7b51dd4c2ba22680844aba4c687be581871a6f518c5742"
|
|||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.66",
|
||||
"syn 2.0.67",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1351,6 +1350,12 @@ version = "0.3.9"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024"
|
||||
|
||||
[[package]]
|
||||
name = "hermit-abi"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fbf6a919d6cf397374f7dfeeea91d974c7c0a7221d0d0f4f20d859d329e53fcc"
|
||||
|
||||
[[package]]
|
||||
name = "hexf-parse"
|
||||
version = "0.2.1"
|
||||
|
@ -1374,16 +1379,6 @@ dependencies = [
|
|||
"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]]
|
||||
name = "image"
|
||||
version = "0.25.1"
|
||||
|
@ -1451,7 +1446,7 @@ checksum = "c34819042dc3d3971c46c2190835914dfbe0c3c13f61449b2997f4e9722dfa60"
|
|||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.66",
|
||||
"syn 2.0.67",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1556,9 +1551,9 @@ checksum = "e2db585e1d738fc771bf08a151420d3ed193d9d895a36df7f6f8a9456b911ddc"
|
|||
|
||||
[[package]]
|
||||
name = "lazy_static"
|
||||
version = "1.4.0"
|
||||
version = "1.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
|
||||
checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
|
||||
|
||||
[[package]]
|
||||
name = "lebe"
|
||||
|
@ -1610,7 +1605,6 @@ dependencies = [
|
|||
"ash",
|
||||
"glob",
|
||||
"halfbrown",
|
||||
"icrate 0.1.2",
|
||||
"librashader-cache",
|
||||
"librashader-common",
|
||||
"librashader-preprocess",
|
||||
|
@ -1624,7 +1618,8 @@ dependencies = [
|
|||
"librashader-runtime-mtl",
|
||||
"librashader-runtime-vk",
|
||||
"librashader-runtime-wgpu",
|
||||
"objc2 0.5.1",
|
||||
"objc2 0.5.2",
|
||||
"objc2-metal",
|
||||
"once_cell",
|
||||
"rayon",
|
||||
"wgpu",
|
||||
|
@ -1662,10 +1657,10 @@ version = "0.2.7"
|
|||
dependencies = [
|
||||
"ash",
|
||||
"gl",
|
||||
"icrate 0.1.2",
|
||||
"librashader",
|
||||
"librashader-spirv-cross",
|
||||
"objc2 0.5.1",
|
||||
"objc2 0.5.2",
|
||||
"objc2-metal",
|
||||
"paste",
|
||||
"rustc-hash",
|
||||
"sptr",
|
||||
|
@ -1680,8 +1675,8 @@ dependencies = [
|
|||
"ash",
|
||||
"gl",
|
||||
"halfbrown",
|
||||
"icrate 0.1.2",
|
||||
"num-traits",
|
||||
"objc2-metal",
|
||||
"rustc-hash",
|
||||
"wgpu-types",
|
||||
"windows",
|
||||
|
@ -1835,13 +1830,14 @@ version = "0.2.7"
|
|||
dependencies = [
|
||||
"array-concat",
|
||||
"bytemuck",
|
||||
"icrate 0.1.2",
|
||||
"librashader-common",
|
||||
"librashader-preprocess",
|
||||
"librashader-presets",
|
||||
"librashader-reflect",
|
||||
"librashader-runtime",
|
||||
"objc2 0.5.1",
|
||||
"objc2 0.5.2",
|
||||
"objc2-foundation",
|
||||
"objc2-metal",
|
||||
"rayon",
|
||||
"thiserror",
|
||||
]
|
||||
|
@ -2041,9 +2037,9 @@ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
|
|||
|
||||
[[package]]
|
||||
name = "miniz_oxide"
|
||||
version = "0.7.3"
|
||||
version = "0.7.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "87dfd01fe195c66b572b37921ad8803d010623c0aca821bea2302239d155cdae"
|
||||
checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08"
|
||||
dependencies = [
|
||||
"adler",
|
||||
"simd-adler32",
|
||||
|
@ -2176,7 +2172,7 @@ checksum = "ed3955f1a9c7c0c15e092f9c887db08b1fc683305fdf6eb6684f22555355e202"
|
|||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.66",
|
||||
"syn 2.0.67",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -2237,7 +2233,7 @@ dependencies = [
|
|||
"proc-macro-crate",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.66",
|
||||
"syn 2.0.67",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -2267,9 +2263,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "objc2"
|
||||
version = "0.5.1"
|
||||
version = "0.5.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b4b25e1034d0e636cd84707ccdaa9f81243d399196b8a773946dcffec0401659"
|
||||
checksum = "46a785d4eeff09c14c487497c162e92766fbb3e4059a71840cecc03d9a50b804"
|
||||
dependencies = [
|
||||
"objc-sys",
|
||||
"objc2-encode 4.0.3",
|
||||
|
@ -2287,6 +2283,30 @@ version = "4.0.3"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
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]]
|
||||
name = "once_cell"
|
||||
version = "1.19.0"
|
||||
|
@ -2418,7 +2438,7 @@ dependencies = [
|
|||
"pest_meta",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.66",
|
||||
"syn 2.0.67",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -2478,13 +2498,13 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "polling"
|
||||
version = "3.7.1"
|
||||
version = "3.7.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5e6a007746f34ed64099e88783b0ae369eaa3da6392868ba262e2af9b8fbaea1"
|
||||
checksum = "a3ed00ed3fbf728b5816498ecd316d1716eecaced9c0c8d2c5a6740ca214985b"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"concurrent-queue",
|
||||
"hermit-abi 0.3.9",
|
||||
"hermit-abi 0.4.0",
|
||||
"pin-project-lite",
|
||||
"rustix",
|
||||
"tracing",
|
||||
|
@ -2544,9 +2564,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.85"
|
||||
version = "1.0.86"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23"
|
||||
checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
@ -2567,7 +2587,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "8021cf59c8ec9c432cfc2526ac6b8aa508ecaf29cd415f271b8406c1b851c3fd"
|
||||
dependencies = [
|
||||
"quote",
|
||||
"syn 2.0.66",
|
||||
"syn 2.0.67",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -2682,9 +2702,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "ravif"
|
||||
version = "0.11.5"
|
||||
version = "0.11.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bc13288f5ab39e6d7c9d501759712e6969fcc9734220846fc9ed26cae2cc4234"
|
||||
checksum = "67376f469e7e7840d0040bbf4b9b3334005bb167f814621326e4c7ab8cd6e944"
|
||||
dependencies = [
|
||||
"avif-serialize",
|
||||
"imgref",
|
||||
|
@ -2943,7 +2963,7 @@ checksum = "500cbc0ebeb6f46627f50f3f5811ccf6bf00643be300b4c3eabc0ef55dc5b5ba"
|
|||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.66",
|
||||
"syn 2.0.67",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -3128,9 +3148,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.66"
|
||||
version = "2.0.67"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5"
|
||||
checksum = "ff8655ed1d86f3af4ee3fd3263786bc14245ad17c4c7e85ba7187fb3ae028c90"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
|
@ -3206,7 +3226,7 @@ checksum = "46c3384250002a6d5af4d114f2845d37b57521033f30d5c3f46c4d70e1197533"
|
|||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.66",
|
||||
"syn 2.0.67",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -3444,7 +3464,7 @@ dependencies = [
|
|||
"once_cell",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.66",
|
||||
"syn 2.0.67",
|
||||
"wasm-bindgen-shared",
|
||||
]
|
||||
|
||||
|
@ -3478,7 +3498,7 @@ checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7"
|
|||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.66",
|
||||
"syn 2.0.67",
|
||||
"wasm-bindgen-backend",
|
||||
"wasm-bindgen-shared",
|
||||
]
|
||||
|
@ -4010,7 +4030,7 @@ dependencies = [
|
|||
"core-foundation",
|
||||
"core-graphics",
|
||||
"cursor-icon",
|
||||
"icrate 0.0.4",
|
||||
"icrate",
|
||||
"js-sys",
|
||||
"libc",
|
||||
"log",
|
||||
|
@ -4159,7 +4179,7 @@ checksum = "15e934569e47891f7d9411f1a451d947a60e000ab3bd24fbb970f000387d1b3b"
|
|||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.66",
|
||||
"syn 2.0.67",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
|
@ -29,7 +29,7 @@ __cbindgen_internal = ["runtime-all"]
|
|||
|
||||
# make runtime-metal depend on this, so its automatically implied.
|
||||
# this will make cbindgen generate __OBJC__ ifdefs for metal functions.
|
||||
__cbindgen_internal_objc = ["icrate", "objc2"]
|
||||
__cbindgen_internal_objc = ["objc2-metal", "objc2"]
|
||||
|
||||
[dependencies]
|
||||
thiserror = "1.0.37"
|
||||
|
@ -51,7 +51,7 @@ workspace = true
|
|||
optional = true
|
||||
|
||||
[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 }
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
|
|
|
@ -13,8 +13,8 @@ use std::slice;
|
|||
use librashader::runtime::FilterChainParameters;
|
||||
use librashader::runtime::{Size, Viewport};
|
||||
|
||||
use icrate::Metal::{MTLCommandBuffer, MTLCommandQueue, MTLTexture};
|
||||
use objc2::runtime::ProtocolObject;
|
||||
use objc2_metal::{MTLCommandBuffer, MTLCommandQueue, MTLTexture};
|
||||
|
||||
use crate::LIBRASHADER_API_VERSION;
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ d3d12 = ["windows", "dxgi"]
|
|||
dxgi = ["windows"]
|
||||
vulkan = ["ash"]
|
||||
wgpu = ["wgpu-types"]
|
||||
metal = ["icrate"]
|
||||
metal = ["objc2-metal"]
|
||||
|
||||
[dependencies]
|
||||
gl = { version = "0.14.0", optional = true }
|
||||
|
@ -42,7 +42,7 @@ features = [
|
|||
"Win32_Graphics_Direct3D12",
|
||||
]
|
||||
|
||||
[target.'cfg(target_vendor="apple")'.dependencies.icrate]
|
||||
[target.'cfg(target_vendor="apple")'.dependencies.objc2-metal]
|
||||
optional = true
|
||||
version = "0.1.0"
|
||||
features = ["Metal", "Metal_all"]
|
||||
version = "0.2.0"
|
||||
features = ["MTLPixelFormat", "MTLRenderCommandEncoder", "MTLSampler"]
|
||||
|
|
|
@ -1,46 +1,48 @@
|
|||
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 {
|
||||
match format {
|
||||
ImageFormat::Unknown => 0 as Metal::MTLPixelFormat,
|
||||
ImageFormat::R8Unorm => Metal::MTLPixelFormatR8Unorm,
|
||||
ImageFormat::R8Uint => Metal::MTLPixelFormatR8Uint,
|
||||
ImageFormat::R8Sint => Metal::MTLPixelFormatR8Sint,
|
||||
ImageFormat::R8G8Unorm => Metal::MTLPixelFormatRG8Unorm,
|
||||
ImageFormat::R8G8Uint => Metal::MTLPixelFormatRG8Uint,
|
||||
ImageFormat::R8G8Sint => Metal::MTLPixelFormatRG8Sint,
|
||||
ImageFormat::R8G8B8A8Unorm => Metal::MTLPixelFormatRGBA8Unorm,
|
||||
ImageFormat::R8G8B8A8Uint => Metal::MTLPixelFormatRGBA8Uint,
|
||||
ImageFormat::R8G8B8A8Sint => Metal::MTLPixelFormatRGBA8Sint,
|
||||
ImageFormat::R8G8B8A8Srgb => Metal::MTLPixelFormatRGBA8Unorm_sRGB,
|
||||
ImageFormat::A2B10G10R10UnormPack32 => Metal::MTLPixelFormatRGB10A2Unorm,
|
||||
ImageFormat::A2B10G10R10UintPack32 => Metal::MTLPixelFormatRGB10A2Uint,
|
||||
ImageFormat::R16Uint => Metal::MTLPixelFormatR16Uint,
|
||||
ImageFormat::R16Sint => Metal::MTLPixelFormatR16Sint,
|
||||
ImageFormat::R16Sfloat => Metal::MTLPixelFormatR16Float,
|
||||
ImageFormat::R16G16Uint => Metal::MTLPixelFormatRG16Uint,
|
||||
ImageFormat::R16G16Sint => Metal::MTLPixelFormatRG16Sint,
|
||||
ImageFormat::R16G16Sfloat => Metal::MTLPixelFormatRG16Float,
|
||||
ImageFormat::R16G16B16A16Uint => Metal::MTLPixelFormatRGBA16Uint,
|
||||
ImageFormat::R16G16B16A16Sint => Metal::MTLPixelFormatRGBA16Sint,
|
||||
ImageFormat::R16G16B16A16Sfloat => Metal::MTLPixelFormatRGBA16Float,
|
||||
ImageFormat::R32Uint => Metal::MTLPixelFormatR32Uint,
|
||||
ImageFormat::R32Sint => Metal::MTLPixelFormatR32Sint,
|
||||
ImageFormat::R32Sfloat => Metal::MTLPixelFormatR32Float,
|
||||
ImageFormat::R32G32Uint => Metal::MTLPixelFormatRG32Uint,
|
||||
ImageFormat::R32G32Sint => Metal::MTLPixelFormatRG32Sint,
|
||||
ImageFormat::R32G32Sfloat => Metal::MTLPixelFormatRG32Float,
|
||||
ImageFormat::R32G32B32A32Uint => Metal::MTLPixelFormatRGBA32Uint,
|
||||
ImageFormat::R32G32B32A32Sint => Metal::MTLPixelFormatRGBA32Sint,
|
||||
ImageFormat::R32G32B32A32Sfloat => Metal::MTLPixelFormatRGBA32Float,
|
||||
ImageFormat::Unknown => MTLPixelFormat(0),
|
||||
ImageFormat::R8Unorm => MTLPixelFormat::R8Unorm,
|
||||
ImageFormat::R8Uint => MTLPixelFormat::R8Uint,
|
||||
ImageFormat::R8Sint => MTLPixelFormat::R8Sint,
|
||||
ImageFormat::R8G8Unorm => MTLPixelFormat::RG8Unorm,
|
||||
ImageFormat::R8G8Uint => MTLPixelFormat::RG8Uint,
|
||||
ImageFormat::R8G8Sint => MTLPixelFormat::RG8Sint,
|
||||
ImageFormat::R8G8B8A8Unorm => MTLPixelFormat::RGBA8Unorm,
|
||||
ImageFormat::R8G8B8A8Uint => MTLPixelFormat::RGBA8Uint,
|
||||
ImageFormat::R8G8B8A8Sint => MTLPixelFormat::RGBA8Sint,
|
||||
ImageFormat::R8G8B8A8Srgb => MTLPixelFormat::RGBA8Unorm_sRGB,
|
||||
ImageFormat::A2B10G10R10UnormPack32 => MTLPixelFormat::RGB10A2Unorm,
|
||||
ImageFormat::A2B10G10R10UintPack32 => MTLPixelFormat::RGB10A2Uint,
|
||||
ImageFormat::R16Uint => MTLPixelFormat::R16Uint,
|
||||
ImageFormat::R16Sint => MTLPixelFormat::R16Sint,
|
||||
ImageFormat::R16Sfloat => MTLPixelFormat::R16Float,
|
||||
ImageFormat::R16G16Uint => MTLPixelFormat::RG16Uint,
|
||||
ImageFormat::R16G16Sint => MTLPixelFormat::RG16Sint,
|
||||
ImageFormat::R16G16Sfloat => MTLPixelFormat::RG16Float,
|
||||
ImageFormat::R16G16B16A16Uint => MTLPixelFormat::RGBA16Uint,
|
||||
ImageFormat::R16G16B16A16Sint => MTLPixelFormat::RGBA16Sint,
|
||||
ImageFormat::R16G16B16A16Sfloat => MTLPixelFormat::RGBA16Float,
|
||||
ImageFormat::R32Uint => MTLPixelFormat::R32Uint,
|
||||
ImageFormat::R32Sint => MTLPixelFormat::R32Sint,
|
||||
ImageFormat::R32Sfloat => MTLPixelFormat::R32Float,
|
||||
ImageFormat::R32G32Uint => MTLPixelFormat::RG32Uint,
|
||||
ImageFormat::R32G32Sint => MTLPixelFormat::RG32Sint,
|
||||
ImageFormat::R32G32Sfloat => MTLPixelFormat::RG32Float,
|
||||
ImageFormat::R32G32B32A32Uint => MTLPixelFormat::RGBA32Uint,
|
||||
ImageFormat::R32G32B32A32Sint => MTLPixelFormat::RGBA32Sint,
|
||||
ImageFormat::R32G32B32A32Sfloat => MTLPixelFormat::RGBA32Float,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Metal::MTLViewport> for Size<u32> {
|
||||
fn from(value: Metal::MTLViewport) -> Self {
|
||||
impl From<MTLViewport> for Size<u32> {
|
||||
fn from(value: MTLViewport) -> Self {
|
||||
Size {
|
||||
width: value.width 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 {
|
||||
Metal::MTLViewport {
|
||||
MTLViewport {
|
||||
originX: 0.0,
|
||||
originY: 0.0,
|
||||
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 {
|
||||
match value {
|
||||
WrapMode::ClampToBorder => Metal::MTLSamplerAddressModeClampToBorderColor,
|
||||
WrapMode::ClampToEdge => Metal::MTLSamplerAddressModeClampToEdge,
|
||||
WrapMode::Repeat => Metal::MTLSamplerAddressModeRepeat,
|
||||
WrapMode::MirroredRepeat => Metal::MTLSamplerAddressModeMirrorRepeat,
|
||||
WrapMode::ClampToBorder => MTLSamplerAddressMode::ClampToBorderColor,
|
||||
WrapMode::ClampToEdge => MTLSamplerAddressMode::ClampToEdge,
|
||||
WrapMode::Repeat => MTLSamplerAddressMode::Repeat,
|
||||
WrapMode::MirroredRepeat => MTLSamplerAddressMode::MirrorRepeat,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<FilterMode> for Metal::MTLSamplerMinMagFilter {
|
||||
impl From<FilterMode> for MTLSamplerMinMagFilter {
|
||||
fn from(value: FilterMode) -> Self {
|
||||
match value {
|
||||
FilterMode::Linear => Metal::MTLSamplerMinMagFilterLinear,
|
||||
_ => Metal::MTLSamplerMipFilterNearest,
|
||||
FilterMode::Linear => MTLSamplerMinMagFilter::Linear,
|
||||
_ => MTLSamplerMinMagFilter::Nearest,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl FilterMode {
|
||||
/// 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 {
|
||||
FilterMode::Linear => Metal::MTLSamplerMipFilterLinear,
|
||||
FilterMode::Nearest => Metal::MTLSamplerMipFilterNearest,
|
||||
FilterMode::Linear => MTLSamplerMipFilter::Linear,
|
||||
FilterMode::Nearest => MTLSamplerMipFilter::Nearest,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,12 +34,14 @@ harness = false
|
|||
targets = ["x86_64-apple-darwin", "aarch64-apple-darwin", "aarch64-apple-ios"]
|
||||
|
||||
[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"] }
|
||||
|
||||
[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]
|
||||
#crate-type = ["lib", "staticlib"]
|
|
@ -1,16 +1,13 @@
|
|||
use crate::error;
|
||||
use crate::error::FilterChainError;
|
||||
use icrate::Foundation::{NSRange, NSString};
|
||||
use icrate::Metal::{
|
||||
MTLBuffer, MTLDevice, MTLResource, MTLResourceOptions, MTLResourceStorageModeManaged,
|
||||
MTLResourceStorageModeShared,
|
||||
};
|
||||
use objc2::rc::Id;
|
||||
use objc2::rc::Retained;
|
||||
use objc2::runtime::ProtocolObject;
|
||||
use objc2_foundation::{NSRange, NSString};
|
||||
use objc2_metal::{MTLBuffer, MTLDevice, MTLResource, MTLResourceOptions};
|
||||
use std::ops::{Deref, DerefMut};
|
||||
|
||||
pub struct MetalBuffer {
|
||||
buffer: Id<ProtocolObject<dyn MTLBuffer>>,
|
||||
buffer: Retained<ProtocolObject<dyn MTLBuffer>>,
|
||||
size: usize,
|
||||
storage_mode: MTLResourceOptions,
|
||||
}
|
||||
|
@ -28,9 +25,9 @@ impl MetalBuffer {
|
|||
label: &str,
|
||||
) -> error::Result<Self> {
|
||||
let storage_mode = if cfg!(all(target_arch = "aarch64", target_vendor = "apple")) {
|
||||
MTLResourceStorageModeShared
|
||||
MTLResourceOptions::MTLResourceStorageModeShared
|
||||
} else {
|
||||
MTLResourceStorageModeManaged
|
||||
MTLResourceOptions::MTLResourceStorageModeManaged
|
||||
};
|
||||
|
||||
// Can't create buffer of size 0.
|
||||
|
@ -53,7 +50,7 @@ impl MetalBuffer {
|
|||
|
||||
pub fn flush(&self) {
|
||||
// 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 {
|
||||
location: 0,
|
||||
length: self.size,
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
use array_concat::concat_arrays;
|
||||
use icrate::Metal::{
|
||||
MTLBuffer, MTLDevice, MTLPrimitiveTypeTriangleStrip, MTLRenderCommandEncoder,
|
||||
MTLResourceStorageModeManaged, MTLResourceStorageModeShared,
|
||||
};
|
||||
use librashader_runtime::quad::{QuadType, VertexInput};
|
||||
use objc2::rc::Id;
|
||||
use objc2::rc::Retained;
|
||||
use objc2::runtime::ProtocolObject;
|
||||
use objc2_metal::{
|
||||
MTLBuffer, MTLDevice, MTLPrimitiveType, MTLRenderCommandEncoder, MTLResourceOptions,
|
||||
};
|
||||
use std::ffi::c_void;
|
||||
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);
|
||||
|
||||
pub struct DrawQuad {
|
||||
buffer: Id<ProtocolObject<dyn MTLBuffer>>,
|
||||
buffer: Retained<ProtocolObject<dyn MTLBuffer>>,
|
||||
}
|
||||
|
||||
impl DrawQuad {
|
||||
|
@ -83,9 +82,9 @@ impl DrawQuad {
|
|||
NonNull::new_unchecked(vbo_data.as_ptr() as *mut c_void),
|
||||
vbo_data.len(),
|
||||
if cfg!(target_os = "ios") {
|
||||
MTLResourceStorageModeShared
|
||||
MTLResourceOptions::MTLResourceStorageModeShared
|
||||
} else {
|
||||
MTLResourceStorageModeManaged
|
||||
MTLResourceOptions::MTLResourceStorageModeManaged
|
||||
},
|
||||
)
|
||||
.ok_or(FilterChainError::BufferError)?
|
||||
|
@ -103,7 +102,7 @@ impl DrawQuad {
|
|||
|
||||
unsafe {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
//! Metal shader runtime errors.
|
||||
use icrate::Foundation::NSError;
|
||||
use librashader_common::{FilterMode, WrapMode};
|
||||
use librashader_preprocess::PreprocessError;
|
||||
use librashader_presets::ParsePresetError;
|
||||
use librashader_reflect::error::{ShaderCompileError, ShaderReflectError};
|
||||
use librashader_runtime::image::ImageError;
|
||||
use objc2::rc::Id;
|
||||
use objc2::rc::Retained;
|
||||
use objc2_foundation::NSError;
|
||||
use thiserror::Error;
|
||||
|
||||
/// Cumulative error type for Metal filter chains.
|
||||
|
@ -26,7 +26,7 @@ pub enum FilterChainError {
|
|||
#[error("buffer creation error")]
|
||||
BufferError,
|
||||
#[error("metal error")]
|
||||
MetalError(#[from] Id<NSError>),
|
||||
MetalError(#[from] Retained<NSError>),
|
||||
#[error("couldn't find entry for shader")]
|
||||
ShaderWrongEntryName,
|
||||
#[error("couldn't create render pass")]
|
||||
|
|
|
@ -8,12 +8,6 @@ use crate::luts::LutTexture;
|
|||
use crate::options::{FilterChainOptionsMetal, FrameOptionsMetal};
|
||||
use crate::samplers::SamplerSet;
|
||||
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::{ImageFormat, Size, Viewport};
|
||||
use librashader_presets::context::VideoDriver;
|
||||
|
@ -35,6 +29,11 @@ use librashader_runtime::scaling::ScaleFramebuffer;
|
|||
use librashader_runtime::uniforms::UniformStorage;
|
||||
use objc2::rc::Id;
|
||||
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 std::collections::VecDeque;
|
||||
use std::fmt::{Debug, Formatter};
|
||||
|
@ -184,8 +183,8 @@ impl FilterChainMetal {
|
|||
let graphics_pipeline = MetalGraphicsPipeline::new(
|
||||
&device,
|
||||
&msl,
|
||||
if render_pass_format == 0 {
|
||||
MTLPixelFormatRGBA8Unorm
|
||||
if render_pass_format == MTLPixelFormat(0) {
|
||||
MTLPixelFormat::RGBA8Unorm
|
||||
} else {
|
||||
render_pass_format
|
||||
},
|
||||
|
@ -344,11 +343,11 @@ impl FilterChainMetal {
|
|||
let desc = MTLRenderPassDescriptor::new();
|
||||
desc.colorAttachments()
|
||||
.objectAtIndexedSubscript(0)
|
||||
.setLoadAction(MTLLoadActionClear);
|
||||
.setLoadAction(MTLLoadAction::Clear);
|
||||
|
||||
desc.colorAttachments()
|
||||
.objectAtIndexedSubscript(0)
|
||||
.setStoreAction(MTLStoreActionDontCare);
|
||||
.setStoreAction(MTLStoreAction::DontCare);
|
||||
desc
|
||||
};
|
||||
|
||||
|
@ -360,8 +359,8 @@ impl FilterChainMetal {
|
|||
.colorAttachments()
|
||||
.objectAtIndexedSubscript(index);
|
||||
ca.setTexture(Some(&history.texture));
|
||||
ca.setLoadAction(MTLLoadActionClear);
|
||||
ca.setStoreAction(MTLStoreActionStore);
|
||||
ca.setLoadAction(MTLLoadAction::Clear);
|
||||
ca.setStoreAction(MTLStoreAction::Store);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@ use crate::graphics_pipeline::MetalGraphicsPipeline;
|
|||
use crate::options::FrameOptionsMetal;
|
||||
use crate::samplers::SamplerSet;
|
||||
use crate::texture::{get_texture_size, InputTexture};
|
||||
use icrate::Metal::{MTLCommandBuffer, MTLCommandEncoder, MTLRenderCommandEncoder, MTLTexture};
|
||||
use librashader_common::map::FastHashMap;
|
||||
use librashader_common::{ImageFormat, Size, Viewport};
|
||||
use librashader_preprocess::ShaderSource;
|
||||
|
@ -18,6 +17,7 @@ use librashader_runtime::quad::QuadType;
|
|||
use librashader_runtime::render_target::RenderTarget;
|
||||
use librashader_runtime::uniforms::{NoUniformBinder, UniformStorage};
|
||||
use objc2::runtime::ProtocolObject;
|
||||
use objc2_metal::{MTLCommandBuffer, MTLCommandEncoder, MTLRenderCommandEncoder, MTLTexture};
|
||||
|
||||
impl TextureInput for InputTexture {
|
||||
fn size(&self) -> Size<u32> {
|
||||
|
|
|
@ -1,22 +1,21 @@
|
|||
use crate::error::{FilterChainError, Result};
|
||||
use crate::select_optimal_pixel_format;
|
||||
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::ShaderCompilerOutput;
|
||||
use librashader_runtime::quad::VertexInput;
|
||||
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;
|
||||
|
||||
/// 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 layout: PipelineLayoutObjects,
|
||||
render_pipeline: Id<ProtocolObject<dyn MTLRenderPipelineState>>,
|
||||
render_pipeline: Retained<ProtocolObject<dyn MTLRenderPipelineState>>,
|
||||
pub render_pass_format: MTLPixelFormat,
|
||||
}
|
||||
|
||||
pub struct PipelineLayoutObjects {
|
||||
_vertex_lib: Id<ProtocolObject<dyn MTLLibrary>>,
|
||||
_fragment_lib: Id<ProtocolObject<dyn MTLLibrary>>,
|
||||
vertex_entry: Id<ProtocolObject<dyn MTLFunction>>,
|
||||
fragment_entry: Id<ProtocolObject<dyn MTLFunction>>,
|
||||
_vertex_lib: Retained<ProtocolObject<dyn MTLLibrary>>,
|
||||
_fragment_lib: Retained<ProtocolObject<dyn MTLLibrary>>,
|
||||
vertex_entry: Retained<ProtocolObject<dyn MTLFunction>>,
|
||||
fragment_entry: Retained<ProtocolObject<dyn MTLFunction>>,
|
||||
}
|
||||
|
||||
pub(crate) trait MslEntryPoint {
|
||||
fn entry_point() -> Id<NSString>;
|
||||
fn entry_point() -> Retained<NSString>;
|
||||
}
|
||||
|
||||
impl MslEntryPoint for CrossMslContext {
|
||||
fn entry_point() -> Id<NSString> {
|
||||
fn entry_point() -> Retained<NSString> {
|
||||
NSString::from_str("main0")
|
||||
}
|
||||
}
|
||||
|
||||
impl MslEntryPoint for NagaMslContext {
|
||||
fn entry_point() -> Id<NSString> {
|
||||
fn entry_point() -> Retained<NSString> {
|
||||
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 attributes = descriptor.attributes();
|
||||
let layouts = descriptor.layouts();
|
||||
|
@ -89,11 +88,11 @@ impl PipelineLayoutObjects {
|
|||
let texcoord = MTLVertexAttributeDescriptor::new();
|
||||
|
||||
// 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.setOffset(offset_of!(VertexInput, position));
|
||||
|
||||
texcoord.setFormat(MTLVertexFormatFloat2);
|
||||
texcoord.setFormat(MTLVertexFormat::Float2);
|
||||
texcoord.setBufferIndex(VERTEX_BUFFER_INDEX);
|
||||
texcoord.setOffset(offset_of!(VertexInput, texcoord));
|
||||
|
||||
|
@ -101,7 +100,7 @@ impl PipelineLayoutObjects {
|
|||
|
||||
attributes.setObject_atIndexedSubscript(Some(&texcoord), 1);
|
||||
|
||||
binding.setStepFunction(MTLVertexStepFunctionPerVertex);
|
||||
binding.setStepFunction(MTLVertexStepFunction::PerVertex);
|
||||
binding.setStride(std::mem::size_of::<VertexInput>());
|
||||
layouts.setObject_atIndexedSubscript(Some(&binding), VERTEX_BUFFER_INDEX);
|
||||
|
||||
|
@ -109,15 +108,15 @@ impl PipelineLayoutObjects {
|
|||
}
|
||||
|
||||
unsafe fn create_color_attachments(
|
||||
ca: Id<MTLRenderPipelineColorAttachmentDescriptor>,
|
||||
ca: Retained<MTLRenderPipelineColorAttachmentDescriptor>,
|
||||
format: MTLPixelFormat,
|
||||
) -> Id<MTLRenderPipelineColorAttachmentDescriptor> {
|
||||
) -> Retained<MTLRenderPipelineColorAttachmentDescriptor> {
|
||||
ca.setPixelFormat(select_optimal_pixel_format(format));
|
||||
ca.setBlendingEnabled(false);
|
||||
ca.setSourceAlphaBlendFactor(MTLBlendFactorSourceAlpha);
|
||||
ca.setSourceRGBBlendFactor(MTLBlendFactorSourceAlpha);
|
||||
ca.setDestinationAlphaBlendFactor(MTLBlendFactorOneMinusSourceAlpha);
|
||||
ca.setDestinationRGBBlendFactor(MTLBlendFactorOneMinusSourceAlpha);
|
||||
ca.setSourceAlphaBlendFactor(MTLBlendFactor::SourceAlpha);
|
||||
ca.setSourceRGBBlendFactor(MTLBlendFactor::SourceAlpha);
|
||||
ca.setDestinationAlphaBlendFactor(MTLBlendFactor::OneMinusSourceAlpha);
|
||||
ca.setDestinationRGBBlendFactor(MTLBlendFactor::OneMinusSourceAlpha);
|
||||
|
||||
ca
|
||||
}
|
||||
|
@ -126,12 +125,12 @@ impl PipelineLayoutObjects {
|
|||
&self,
|
||||
device: &ProtocolObject<dyn MTLDevice>,
|
||||
format: MTLPixelFormat,
|
||||
) -> Result<Id<ProtocolObject<dyn MTLRenderPipelineState>>> {
|
||||
) -> Result<Retained<ProtocolObject<dyn MTLRenderPipelineState>>> {
|
||||
let descriptor = MTLRenderPipelineDescriptor::new();
|
||||
|
||||
unsafe {
|
||||
let vertex = Self::create_vertex_descriptor();
|
||||
descriptor.setInputPrimitiveTopology(MTLPrimitiveTopologyClassTriangle);
|
||||
descriptor.setInputPrimitiveTopology(MTLPrimitiveTopologyClass::Triangle);
|
||||
descriptor.setVertexDescriptor(Some(&vertex));
|
||||
|
||||
let ca = descriptor.colorAttachments().objectAtIndexedSubscript(0);
|
||||
|
@ -176,12 +175,12 @@ impl MetalGraphicsPipeline {
|
|||
&self,
|
||||
output: &RenderTarget<ProtocolObject<dyn MTLTexture>>,
|
||||
buffer: &ProtocolObject<dyn MTLCommandBuffer>,
|
||||
) -> Result<Id<ProtocolObject<dyn MTLRenderCommandEncoder>>> {
|
||||
) -> Result<Retained<ProtocolObject<dyn MTLRenderCommandEncoder>>> {
|
||||
unsafe {
|
||||
let descriptor = MTLRenderPassDescriptor::new();
|
||||
let ca = descriptor.colorAttachments().objectAtIndexedSubscript(0);
|
||||
ca.setLoadAction(MTLLoadActionDontCare);
|
||||
ca.setStoreAction(MTLStoreActionStore);
|
||||
ca.setLoadAction(MTLLoadAction::DontCare);
|
||||
ca.setStoreAction(MTLStoreAction::Store);
|
||||
ca.setTexture(Some(output.output));
|
||||
|
||||
let rpass = buffer
|
||||
|
|
|
@ -11,10 +11,7 @@ mod samplers;
|
|||
mod texture;
|
||||
|
||||
pub use filter_chain::FilterChainMetal;
|
||||
use icrate::Metal::{
|
||||
MTLPixelFormat, MTLPixelFormatBGRA8Unorm, MTLPixelFormatBGRA8Unorm_sRGB,
|
||||
MTLPixelFormatRGBA8Unorm, MTLPixelFormatRGBA8Unorm_sRGB,
|
||||
};
|
||||
use objc2_metal::MTLPixelFormat;
|
||||
|
||||
pub mod error;
|
||||
pub mod options;
|
||||
|
@ -24,12 +21,12 @@ impl_filter_chain_parameters!(FilterChainMetal);
|
|||
pub use texture::MetalTextureRef;
|
||||
|
||||
fn select_optimal_pixel_format(format: MTLPixelFormat) -> MTLPixelFormat {
|
||||
if format == MTLPixelFormatRGBA8Unorm {
|
||||
return MTLPixelFormatBGRA8Unorm;
|
||||
if format == MTLPixelFormat::RGBA8Unorm {
|
||||
return MTLPixelFormat::BGRA8Unorm;
|
||||
}
|
||||
|
||||
if format == MTLPixelFormatRGBA8Unorm_sRGB {
|
||||
return MTLPixelFormatBGRA8Unorm_sRGB;
|
||||
if format == MTLPixelFormat::RGBA8Unorm_sRGB {
|
||||
return MTLPixelFormat::BGRA8Unorm_sRGB;
|
||||
}
|
||||
return format;
|
||||
}
|
||||
|
|
|
@ -1,14 +1,13 @@
|
|||
use crate::error::{FilterChainError, Result};
|
||||
use crate::texture::InputTexture;
|
||||
use icrate::Metal::{
|
||||
MTLBlitCommandEncoder, MTLDevice, MTLOrigin, MTLPixelFormatBGRA8Unorm, MTLRegion,
|
||||
MTLResourceStorageModeManaged, MTLResourceStorageModeShared, MTLSize, MTLTexture,
|
||||
MTLTextureDescriptor, MTLTextureUsageShaderRead,
|
||||
};
|
||||
use librashader_presets::TextureConfig;
|
||||
use librashader_runtime::image::{Image, BGRA8};
|
||||
use librashader_runtime::scaling::MipmapSize;
|
||||
use objc2::runtime::ProtocolObject;
|
||||
use objc2_metal::{
|
||||
MTLBlitCommandEncoder, MTLDevice, MTLOrigin, MTLPixelFormat, MTLRegion, MTLSize,
|
||||
MTLStorageMode, MTLTexture, MTLTextureDescriptor, MTLTextureUsage,
|
||||
};
|
||||
use std::ffi::c_void;
|
||||
use std::ptr::NonNull;
|
||||
|
||||
|
@ -30,7 +29,7 @@ impl LutTexture {
|
|||
let descriptor = unsafe {
|
||||
let descriptor =
|
||||
MTLTextureDescriptor::texture2DDescriptorWithPixelFormat_width_height_mipmapped(
|
||||
MTLPixelFormatBGRA8Unorm,
|
||||
MTLPixelFormat::BGRA8Unorm,
|
||||
image.size.width as usize,
|
||||
image.size.height as usize,
|
||||
config.mipmap,
|
||||
|
@ -45,13 +44,13 @@ impl LutTexture {
|
|||
|
||||
descriptor.setStorageMode(
|
||||
if cfg!(all(target_arch = "aarch64", target_vendor = "apple")) {
|
||||
MTLResourceStorageModeShared
|
||||
MTLStorageMode::Shared
|
||||
} else {
|
||||
MTLResourceStorageModeManaged
|
||||
MTLStorageMode::Managed
|
||||
},
|
||||
);
|
||||
|
||||
descriptor.setUsage(MTLTextureUsageShaderRead);
|
||||
descriptor.setUsage(MTLTextureUsage::ShaderRead);
|
||||
|
||||
descriptor
|
||||
};
|
||||
|
|
|
@ -1,19 +1,20 @@
|
|||
use icrate::Metal::{
|
||||
MTLCompareFunctionNever, MTLDevice, MTLSamplerAddressMode,
|
||||
MTLSamplerBorderColorTransparentBlack, MTLSamplerDescriptor, MTLSamplerMinMagFilter,
|
||||
MTLSamplerState,
|
||||
};
|
||||
use librashader_common::map::FastHashMap;
|
||||
use librashader_common::{FilterMode, WrapMode};
|
||||
use objc2::rc::Id;
|
||||
use objc2::rc::Retained;
|
||||
use objc2::runtime::ProtocolObject;
|
||||
use objc2_metal::{
|
||||
MTLCompareFunction, MTLDevice, MTLSamplerAddressMode, MTLSamplerBorderColor,
|
||||
MTLSamplerDescriptor, MTLSamplerMinMagFilter, MTLSamplerState,
|
||||
};
|
||||
|
||||
use crate::error::{FilterChainError, Result};
|
||||
|
||||
pub struct SamplerSet {
|
||||
// todo: may need to deal with differences in mip filter.
|
||||
samplers:
|
||||
FastHashMap<(WrapMode, FilterMode, FilterMode), Id<ProtocolObject<dyn MTLSamplerState>>>,
|
||||
samplers: FastHashMap<
|
||||
(WrapMode, FilterMode, FilterMode),
|
||||
Retained<ProtocolObject<dyn MTLSamplerState>>,
|
||||
>,
|
||||
}
|
||||
|
||||
impl SamplerSet {
|
||||
|
@ -27,7 +28,7 @@ impl SamplerSet {
|
|||
// eprintln!("{wrap}, {filter}, {mip}");
|
||||
// SAFETY: the sampler set is complete for the matrix
|
||||
// wrap x filter x mipmap
|
||||
let id: &Id<ProtocolObject<dyn MTLSamplerState>> = unsafe {
|
||||
let id: &Retained<ProtocolObject<dyn MTLSamplerState>> = unsafe {
|
||||
self.samplers
|
||||
.get(&(wrap, filter, mipmap))
|
||||
.unwrap_unchecked()
|
||||
|
@ -58,9 +59,9 @@ impl SamplerSet {
|
|||
descriptor.setMipFilter(filter_mode.mtl_mip(*mipmap_filter));
|
||||
descriptor.setLodMinClamp(0.0);
|
||||
descriptor.setLodMaxClamp(1000.0);
|
||||
descriptor.setCompareFunction(MTLCompareFunctionNever);
|
||||
descriptor.setCompareFunction(MTLCompareFunction::Never);
|
||||
descriptor.setMaxAnisotropy(1);
|
||||
descriptor.setBorderColor(MTLSamplerBorderColorTransparentBlack);
|
||||
descriptor.setBorderColor(MTLSamplerBorderColor::TransparentBlack);
|
||||
descriptor.setNormalizedCoordinates(true);
|
||||
|
||||
let Some(sampler_state) = device.newSamplerStateWithDescriptor(&descriptor)
|
||||
|
|
|
@ -1,17 +1,16 @@
|
|||
use crate::error::{FilterChainError, Result};
|
||||
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_presets::Scale2D;
|
||||
use librashader_runtime::scaling::{MipmapSize, ScaleFramebuffer, ViewportSize};
|
||||
use objc2::rc::Id;
|
||||
use objc2::rc::Retained;
|
||||
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>`.
|
||||
pub type MetalTextureRef<'a> = &'a ProtocolObject<dyn MTLTexture>;
|
||||
|
@ -71,11 +70,11 @@ impl OwnedTexture {
|
|||
1
|
||||
});
|
||||
|
||||
descriptor.setStorageMode(MTLStorageModePrivate);
|
||||
descriptor.setStorageMode(MTLStorageMode::Private);
|
||||
descriptor.setUsage(
|
||||
MTLTextureUsageShaderRead
|
||||
| MTLTextureUsageShaderWrite
|
||||
| MTLTextureUsageRenderTarget,
|
||||
MTLTextureUsage::ShaderRead
|
||||
| MTLTextureUsage::ShaderWrite
|
||||
| MTLTextureUsage::RenderTarget,
|
||||
);
|
||||
|
||||
descriptor
|
||||
|
|
|
@ -39,7 +39,7 @@ workspace = true
|
|||
optional = true
|
||||
|
||||
[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 }
|
||||
|
||||
[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-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
|
||||
reflect-cross = ["reflect", "librashader-reflect/cross"]
|
||||
|
@ -75,7 +75,7 @@ internal = []
|
|||
full = ["runtime-all", "reflect-all", "preprocess", "presets"]
|
||||
|
||||
# cache hack
|
||||
docsrs = ["librashader-cache/docsrs", "objc2/unstable-docsrs"]
|
||||
docsrs = ["librashader-cache/docsrs"]
|
||||
|
||||
# emits warning messages in tests
|
||||
github-ci = []
|
||||
|
|
Loading…
Reference in a new issue