From ea1d6ad8ace75f25a77605a9dc6437ba1512cdb1 Mon Sep 17 00:00:00 2001 From: Christian Guinard <28689358+christiangnrd@users.noreply.github.com> Date: Fri, 20 Dec 2024 10:01:23 -0400 Subject: [PATCH] Generate MTL and MPS structs and enums with Clang.jl (#492) * Add Docs and wrapping readme Co-authored-by: Tim Besard --------- Co-authored-by: Tim Besard --- docs/src/faq/contributing.md | 6 +- lib/mps/MPS.jl | 3 + lib/mps/copy.jl | 7 - lib/mps/decomposition.jl | 8 - lib/mps/images.jl | 8 - lib/mps/kernel.jl | 10 - lib/mps/libmps.jl | 623 ++++++++++++++ lib/mps/matrix.jl | 38 +- lib/mps/matrixrandom.jl | 6 - lib/mps/size.jl | 31 +- lib/mtl/MTL.jl | 2 +- lib/mtl/argument.jl | 214 ----- lib/mtl/capture.jl | 24 +- lib/mtl/command_buf.jl | 19 - lib/mtl/command_enc/compute.jl | 5 - lib/mtl/compile-opts.jl | 16 +- lib/mtl/device.jl | 30 - lib/mtl/function.jl | 11 - lib/mtl/heap.jl | 10 - lib/mtl/libmtl.jl | 1397 ++++++++++++++++++++++++++++++++ lib/mtl/resource.jl | 41 +- lib/mtl/size.jl | 30 +- lib/mtl/texture.jl | 202 ----- res/.gitignore | 3 - res/wrap/.gitignore | 1 + res/wrap/Project.toml | 9 + res/wrap/README.md | 50 ++ res/wrap/libmps.toml | 36 + res/wrap/libmps_prologue.jl | 1 + res/wrap/libmtl.toml | 31 + res/wrap/wrap.jl | 180 ++++ 31 files changed, 2347 insertions(+), 705 deletions(-) create mode 100644 lib/mps/libmps.jl delete mode 100644 lib/mtl/argument.jl create mode 100644 lib/mtl/libmtl.jl delete mode 100644 res/.gitignore create mode 100644 res/wrap/.gitignore create mode 100644 res/wrap/Project.toml create mode 100644 res/wrap/README.md create mode 100644 res/wrap/libmps.toml create mode 100644 res/wrap/libmps_prologue.jl create mode 100644 res/wrap/libmtl.toml create mode 100644 res/wrap/wrap.jl diff --git a/docs/src/faq/contributing.md b/docs/src/faq/contributing.md index 2f17b21a9..480b4b6f2 100644 --- a/docs/src/faq/contributing.md +++ b/docs/src/faq/contributing.md @@ -38,6 +38,10 @@ skip the first two steps. 2. Create high-level Julia structures and functionality 3. Create tests for added functionality +`struct`s and `enums` for Objective-C interfaces are automatically generated (see res/wrap/), +so you should not have to define them. If using a struct for the first time in a higher-level +interface, remember to add tests! You may need to define more functions around the structs. + ## Mapping to Metal Intrinsics Some Metal functions map directly to Apple intermediate representation intrinsics. In this @@ -134,4 +138,4 @@ their free time helping out. Most anything you're able to do is helpful, but if stuck, seek guidance from Slack or Discourse. Don't feel like your contribution has to be perfect. If you put in effort and make progress, there will likely be some senior developer willing to polish your code before merging. Open-source software is a team effort...welcome -to the team! \ No newline at end of file +to the team! diff --git a/lib/mps/MPS.jl b/lib/mps/MPS.jl index 0d7ec52b4..eb4312863 100644 --- a/lib/mps/MPS.jl +++ b/lib/mps/MPS.jl @@ -23,6 +23,9 @@ Base.convert(::Type{MPSShape}, tuple::Union{Vector{N},NTuple{N, <:Integer}}) whe is_supported(dev::MTLDevice) = ccall(:MPSSupportsMTLDevice, Bool, (id{MTLDevice},), dev) +# Load in generated enums and structs +include("libmps.jl") + include("size.jl") # high-level wrappers diff --git a/lib/mps/copy.jl b/lib/mps/copy.jl index 2aa4a9053..dd5e9fce3 100644 --- a/lib/mps/copy.jl +++ b/lib/mps/copy.jl @@ -2,13 +2,6 @@ export MPSMatrixCopyDescriptor -struct MPSMatrixCopyOffsets - sourceRowOffset::Cuint - sourceColumnOffset::Cuint - destinationRowOffset::Cuint - destinationColumnOffset::Cuint -end - @objcwrapper MPSMatrixCopyDescriptor <: NSObject function MPSMatrixCopyDescriptor(sourceMatrix, destinationMatrix, offsets = MPSMatrixCopyOffsets(Cuint(0), Cuint(0), Cuint(0), Cuint(0))) diff --git a/lib/mps/decomposition.jl b/lib/mps/decomposition.jl index ce241cf27..5946849fe 100644 --- a/lib/mps/decomposition.jl +++ b/lib/mps/decomposition.jl @@ -1,11 +1,3 @@ -@cenum MPSMatrixDecompositionStatus::Cint begin - MPSMatrixDecompositionStatusSuccess = 0 - MPSMatrixDecompositionStatusFailure = -1 - MPSMatrixDecompositionStatusSingular = -2 - MPSMatrixDecompositionStatusNonPositiveDefinite = -3 -end - - ## lu export MPSMatrixDecompositionLU, encode! diff --git a/lib/mps/images.jl b/lib/mps/images.jl index 1b1727801..d2a68562b 100644 --- a/lib/mps/images.jl +++ b/lib/mps/images.jl @@ -1,13 +1,5 @@ ## kernels -@cenum MPSImageEdgeMode::NSUInteger begin - MPSImageEdgeModeZero = 0 - MPSImageEdgeModeClamp = 1 - MPSImageEdgeModeMirror = 2 - MPSImageEdgeModeMirrorWithEdge = 3 - MPSImageEdgeModeConstant = 4 -end - @objcwrapper immutable=false MPSUnaryImageKernel <: MPSKernel @objcproperties MPSUnaryImageKernel begin diff --git a/lib/mps/kernel.jl b/lib/mps/kernel.jl index cf1e609f0..33752551f 100644 --- a/lib/mps/kernel.jl +++ b/lib/mps/kernel.jl @@ -2,16 +2,6 @@ # kernels # -@cenum MPSKernelOptions::NSUInteger begin - MPSKernelOptionsNone = 0 - MPSKernelOptionsSkipAPIValidation = 1 << 0 - MPSKernelOptionsAllowReducedPrecision = 1 << 1 - MPSKernelOptionsDisableInternalTiling = 1 << 2 - MPSKernelOptionsInsertDebugGroups = 1 << 3 - MPSKernelOptionsVerbose = 1 << 4 -end - - @objcwrapper MPSKernel <: NSObject @objcproperties MPSKernel begin diff --git a/lib/mps/libmps.jl b/lib/mps/libmps.jl new file mode 100644 index 000000000..34e92367b --- /dev/null +++ b/lib/mps/libmps.jl @@ -0,0 +1,623 @@ +# This file is automatically generated. Do not edit! +# To re-generate, execute res/wrap/wrap.jl + +using CEnum: CEnum, @cenum + +using .MTL: MTLPixelFormat, MTLTextureType, MTLTextureUsage + +@cenum MPSKernelOptions::UInt64 begin + MPSKernelOptionsNone = 0x0000000000000000 + MPSKernelOptionsSkipAPIValidation = 0x0000000000000001 + MPSKernelOptionsAllowReducedPrecision = 0x0000000000000002 + MPSKernelOptionsDisableInternalTiling = 0x0000000000000004 + MPSKernelOptionsInsertDebugGroups = 0x0000000000000008 + MPSKernelOptionsVerbose = 0x0000000000000010 +end + +@cenum MPSImageEdgeMode::UInt64 begin + MPSImageEdgeModeZero = 0x0000000000000000 + MPSImageEdgeModeClamp = 0x0000000000000001 + MPSImageEdgeModeMirror = 0x0000000000000002 + MPSImageEdgeModeMirrorWithEdge = 0x0000000000000003 + MPSImageEdgeModeConstant = 0x0000000000000004 +end + +@cenum MPSImageFeatureChannelFormat::UInt64 begin + MPSImageFeatureChannelFormatNone = 0x0000000000000000 + MPSImageFeatureChannelFormatUnorm8 = 0x0000000000000001 + MPSImageFeatureChannelFormatUnorm16 = 0x0000000000000002 + MPSImageFeatureChannelFormatFloat16 = 0x0000000000000003 + MPSImageFeatureChannelFormatFloat32 = 0x0000000000000004 + MPSImageFeatureChannelFormat_reserved0 = 0x0000000000000005 + MPSImageFeatureChannelFormatCount = 0x0000000000000006 +end + +@cenum MPSFloatDataTypeBit::UInt32 begin + MPSFloatDataTypeSignBit = 0x0000000000800000 + MPSFloatDataTypeExponentBit = 0x00000000007c0000 + MPSFloatDataTypeMantissaBit = 0x000000000003fc00 +end + +@cenum MPSFloatDataTypeShift::UInt32 begin + MPSFloatDataTypeSignShift = 0x0000000000000017 + MPSFloatDataTypeExponentShift = 0x0000000000000012 + MPSFloatDataTypeMantissaShift = 0x000000000000000a +end + +@cenum MPSDataType::UInt32 begin + MPSDataTypeInvalid = 0x0000000000000000 + MPSDataTypeFloatBit = 0x0000000010000000 + MPSDataTypeFloat32 = 0x0000000010000020 + MPSDataTypeFloat16 = 0x0000000010000010 + MPSDataTypeComplexBit = 0x0000000001000000 + MPSDataTypeComplexFloat32 = 0x0000000011000040 + MPSDataTypeComplexFloat16 = 0x0000000011000020 + MPSDataTypeSignedBit = 0x0000000020000000 + MPSDataTypeIntBit = 0x0000000020000000 + MPSDataTypeInt4 = 0x0000000020000004 + MPSDataTypeInt8 = 0x0000000020000008 + MPSDataTypeInt16 = 0x0000000020000010 + MPSDataTypeInt32 = 0x0000000020000020 + MPSDataTypeInt64 = 0x0000000020000040 + MPSDataTypeUInt4 = 0x0000000000000004 + MPSDataTypeUInt8 = 0x0000000000000008 + MPSDataTypeUInt16 = 0x0000000000000010 + MPSDataTypeUInt32 = 0x0000000000000020 + MPSDataTypeUInt64 = 0x0000000000000040 + MPSDataTypeAlternateEncodingBit = 0x0000000080000000 + MPSDataTypeBool = 0x0000000080000008 + MPSDataTypeBFloat16 = 0x0000000090000010 + MPSDataTypeNormalizedBit = 0x0000000040000000 + MPSDataTypeUnorm1 = 0x0000000040000001 + MPSDataTypeUnorm8 = 0x0000000040000008 +end + +@cenum MPSAliasingStrategy::UInt64 begin + MPSAliasingStrategyDefault = 0x0000000000000000 + MPSAliasingStrategyDontCare = 0x0000000000000000 + MPSAliasingStrategyShallAlias = 0x0000000000000001 + MPSAliasingStrategyShallNotAlias = 0x0000000000000002 + MPSAliasingStrategyAliasingReserved = 0x0000000000000003 + MPSAliasingStrategyPreferTemporaryMemory = 0x0000000000000004 + MPSAliasingStrategyPreferNonTemporaryMemory = 0x0000000000000008 +end + +struct MPSOffset + x::NSInteger + y::NSInteger + z::NSInteger + MPSOffset(x=0, y=0, z=0) = new(x, y, z) +end + +struct MPSOrigin + x::Cdouble + y::Cdouble + z::Cdouble + MPSOrigin(x=0.0, y=0.0, z=0.0) = new(x, y, z) +end + +struct MPSSize + width::Cdouble + height::Cdouble + depth::Cdouble + MPSSize(w=1.0, h=1.0, d=1.0) = new(w, h, d) +end + +struct MPSDimensionSlice + start::NSUInteger + length::NSUInteger +end + +struct MPSRegion + origin::MPSOrigin + size::MPSSize + MPSRegion(origin=MPSOrigin(), size=MPSSize()) = new(origin, size) +end + +struct MPSScaleTransform + scaleX::Cdouble + scaleY::Cdouble + translateX::Cdouble + translateY::Cdouble +end + +struct MPSImageCoordinate + x::NSUInteger + y::NSUInteger + channel::NSUInteger +end + +struct MPSImageRegion + offset::MPSImageCoordinate + size::MPSImageCoordinate +end + +@cenum MPSPurgeableState::UInt64 begin + MPSPurgeableStateAllocationDeferred = 0x0000000000000000 + MPSPurgeableStateKeepCurrent = 0x0000000000000001 + MPSPurgeableStateNonVolatile = 0x0000000000000002 + MPSPurgeableStateVolatile = 0x0000000000000003 + MPSPurgeableStateEmpty = 0x0000000000000004 +end + +@cenum MPSDataLayout::UInt64 begin + MPSDataLayoutHeightxWidthxFeatureChannels = 0x0000000000000000 + MPSDataLayoutFeatureChannelsxHeightxWidth = 0x0000000000000001 +end + +struct MPSImageReadWriteParams + featureChannelOffset::NSUInteger + numberOfFeatureChannelsToReadWrite::NSUInteger +end + +struct MPSStateTextureInfo + width::NSUInteger + height::NSUInteger + depth::NSUInteger + arrayLength::NSUInteger + pixelFormat::MTLPixelFormat + textureType::MTLTextureType + usage::MTLTextureUsage + _reserved::NTuple{4,NSUInteger} +end + +@cenum MPSStateResourceType::UInt64 begin + MPSStateResourceTypeNone = 0x0000000000000000 + MPSStateResourceTypeBuffer = 0x0000000000000001 + MPSStateResourceTypeTexture = 0x0000000000000002 +end + +@cenum MPSDeviceCapsValues::UInt32 begin + MPSDeviceCapsNull = 0x0000000000000000 + MPSDeviceSupportsReadableArrayOfTextures = 0x0000000000000001 + MPSDeviceSupportsWritableArrayOfTextures = 0x0000000000000002 + MPSDeviceSupportsReadWriteTextures = 0x0000000000000004 + MPSDeviceSupportsSimdgroupBarrier = 0x0000000000000008 + MPSDeviceSupportsQuadShuffle = 0x0000000000000010 + MPSDeviceSupportsSimdShuffle = 0x0000000000000020 + MPSDeviceSupportsSimdReduction = 0x0000000000000040 + MPSDeviceSupportsFloat32Filtering = 0x0000000000000080 + MPSDeviceSupportsNorm16BicubicFiltering = 0x0000000000000100 + MPSDeviceSupportsFloat16BicubicFiltering = 0x0000000000000200 + MPSDeviceIsAppleDevice = 0x0000000000000400 + MPSDeviceSupportsSimdShuffleAndFill = 0x0000000000000800 + MPSDeviceSupportsBFloat16Arithmetic = 0x0000000000001000 + MPSDeviceCapsLast = 0x0000000000002000 +end + +const MPSDeviceCaps = UInt32 + +@cenum MPSCustomKernelIndex::UInt32 begin + MPSCustomKernelIndexDestIndex = 0 + MPSCustomKernelIndexSrc0Index = 0 + MPSCustomKernelIndexSrc1Index = 1 + MPSCustomKernelIndexSrc2Index = 2 + MPSCustomKernelIndexSrc3Index = 3 + MPSCustomKernelIndexSrc4Index = 4 + MPSCustomKernelIndexUserDataIndex = 30 +end + +struct MPSMatrixOffset + rowOffset::UInt32 + columnOffset::UInt32 +end + +struct MPSIntegerDivisionParams + divisor::UInt16 + recip::UInt16 + addend::UInt16 + shift::UInt16 +end + +@cenum MPSImageType::UInt32 begin + MPSImageType2d = 0x0000000000000000 + MPSImageType2d_array = 0x0000000000000001 + MPSImageTypeArray2d = 0x0000000000000002 + MPSImageTypeArray2d_array = 0x0000000000000003 + MPSImageType_ArrayMask = 0x0000000000000001 + MPSImageType_BatchMask = 0x0000000000000002 + MPSImageType_typeMask = 0x0000000000000003 + MPSImageType_noAlpha = 0x0000000000000004 + MPSImageType_texelFormatMask = 0x0000000000000038 + MPSImageType_texelFormatShift = 0x0000000000000003 + MPSImageType_texelFormatStandard = 0x0000000000000000 + MPSImageType_texelFormatUnorm8 = 0x0000000000000008 + MPSImageType_texelFormatFloat16 = 0x0000000000000010 + MPSImageType_texelFormatBFloat16 = 0x0000000000000018 + MPSImageType_bitCount = 0x0000000000000006 + MPSImageType_mask = 0x000000000000003f + MPSImageType2d_noAlpha = 0x0000000000000004 + MPSImageType2d_array_noAlpha = 0x0000000000000005 + MPSImageTypeArray2d_noAlpha = 0x0000000000000006 + MPSImageTypeArray2d_array_noAlpha = 0x0000000000000007 +end + +const MPSFunctionConstant = Int64 + +const MPSFunctionConstantInMetal = UInt32 + +struct MPSCustomKernelArgumentCount + destinationTextureCount::Culong + sourceTextureCount::Culong + broadcastTextureCount::Culong +end + +@cenum MPSAlphaType::UInt64 begin + MPSAlphaTypeNonPremultiplied = 0x0000000000000000 + MPSAlphaTypeAlphaIsOne = 0x0000000000000001 + MPSAlphaTypePremultiplied = 0x0000000000000002 +end + +@cenum MPSMatrixDecompositionStatus::Int32 begin + MPSMatrixDecompositionStatusSuccess = 0 + MPSMatrixDecompositionStatusFailure = -1 + MPSMatrixDecompositionStatusSingular = -2 + MPSMatrixDecompositionStatusNonPositiveDefinite = -3 +end + +struct MPSMatrixCopyOffsets + sourceRowOffset::UInt32 + sourceColumnOffset::UInt32 + destinationRowOffset::UInt32 + destinationColumnOffset::UInt32 +end + +@cenum MPSMatrixRandomDistribution::UInt64 begin + MPSMatrixRandomDistributionDefault = 0x0000000000000001 + MPSMatrixRandomDistributionUniform = 0x0000000000000002 + MPSMatrixRandomDistributionNormal = 0x0000000000000003 +end + +struct MPSImageKeypointRangeInfo + maximumKeypoints::NSUInteger + minimumThresholdValue::Cfloat +end + +@cenum MPSCNNConvolutionFlags::UInt64 begin + MPSCNNConvolutionFlagsNone = 0x0000000000000000 +end + +@cenum MPSCNNBinaryConvolutionFlags::UInt64 begin + MPSCNNBinaryConvolutionFlagsNone = 0x0000000000000000 + MPSCNNBinaryConvolutionFlagsUseBetaScaling = 0x0000000000000001 +end + +@cenum MPSCNNBinaryConvolutionType::UInt64 begin + MPSCNNBinaryConvolutionTypeBinaryWeights = 0x0000000000000000 + MPSCNNBinaryConvolutionTypeXNOR = 0x0000000000000001 + MPSCNNBinaryConvolutionTypeAND = 0x0000000000000002 +end + +@cenum MPSNNConvolutionAccumulatorPrecisionOption::UInt64 begin + MPSNNConvolutionAccumulatorPrecisionOptionHalf = 0x0000000000000000 + MPSNNConvolutionAccumulatorPrecisionOptionFloat = 0x0000000000000001 +end + +@cenum MPSNNTrainingStyle::UInt64 begin + MPSNNTrainingStyleUpdateDeviceNone = 0x0000000000000000 + MPSNNTrainingStyleUpdateDeviceCPU = 0x0000000000000001 + MPSNNTrainingStyleUpdateDeviceGPU = 0x0000000000000002 +end + +@cenum MPSCNNBatchNormalizationFlags::UInt64 begin + MPSCNNBatchNormalizationFlagsDefault = 0x0000000000000000 + MPSCNNBatchNormalizationFlagsCalculateStatisticsAutomatic = 0x0000000000000000 + MPSCNNBatchNormalizationFlagsCalculateStatisticsAlways = 0x0000000000000001 + MPSCNNBatchNormalizationFlagsCalculateStatisticsNever = 0x0000000000000002 + MPSCNNBatchNormalizationFlagsCalculateStatisticsMask = 0x0000000000000003 +end + +@cenum MPSNNPaddingMethod::UInt64 begin + MPSNNPaddingMethodAlignCentered = 0x0000000000000000 + MPSNNPaddingMethodAlignTopLeft = 0x0000000000000001 + MPSNNPaddingMethodAlignBottomRight = 0x0000000000000002 + MPSNNPaddingMethodAlign_reserved = 0x0000000000000003 + MPSNNPaddingMethodAlignMask = 0x0000000000000003 + MPSNNPaddingMethodAddRemainderToTopLeft = 0x0000000000000000 + MPSNNPaddingMethodAddRemainderToTopRight = 0x0000000000000004 + MPSNNPaddingMethodAddRemainderToBottomLeft = 0x0000000000000008 + MPSNNPaddingMethodAddRemainderToBottomRight = 0x000000000000000c + MPSNNPaddingMethodAddRemainderToMask = 0x000000000000000c + MPSNNPaddingMethodSizeValidOnly = 0x0000000000000000 + MPSNNPaddingMethodSizeSame = 0x0000000000000010 + MPSNNPaddingMethodSizeFull = 0x0000000000000020 + MPSNNPaddingMethodSize_reserved = 0x0000000000000030 + MPSNNPaddingMethodCustomWhitelistForNodeFusion = 0x0000000000002000 + MPSNNPaddingMethodCustomAllowForNodeFusion = 0x0000000000002000 + MPSNNPaddingMethodCustom = 0x0000000000004000 + MPSNNPaddingMethodSizeMask = 0x00000000000007f0 + MPSNNPaddingMethodExcludeEdges = 0x0000000000008000 +end + +@cenum MPSCNNNeuronType::Int32 begin + MPSCNNNeuronTypeNone = 0 + MPSCNNNeuronTypeReLU = 1 + MPSCNNNeuronTypeLinear = 2 + MPSCNNNeuronTypeSigmoid = 3 + MPSCNNNeuronTypeHardSigmoid = 4 + MPSCNNNeuronTypeTanH = 5 + MPSCNNNeuronTypeAbsolute = 6 + MPSCNNNeuronTypeSoftPlus = 7 + MPSCNNNeuronTypeSoftSign = 8 + MPSCNNNeuronTypeELU = 9 + MPSCNNNeuronTypePReLU = 10 + MPSCNNNeuronTypeReLUN = 11 + MPSCNNNeuronTypePower = 12 + MPSCNNNeuronTypeExponential = 13 + MPSCNNNeuronTypeLogarithm = 14 + MPSCNNNeuronTypeGeLU = 15 + MPSCNNNeuronTypeCount = 16 +end + +@cenum MPSCNNConvolutionWeightsLayout::UInt32 begin + MPSCNNConvolutionWeightsLayoutOHWI = 0x0000000000000000 +end + +@cenum MPSCNNWeightsQuantizationType::UInt32 begin + MPSCNNWeightsQuantizationTypeNone = 0x0000000000000000 + MPSCNNWeightsQuantizationTypeLinear = 0x0000000000000001 + MPSCNNWeightsQuantizationTypeLookupTable = 0x0000000000000002 +end + +@cenum MPSCNNConvolutionGradientOption::UInt64 begin + MPSCNNConvolutionGradientOptionGradientWithData = 0x0000000000000001 + MPSCNNConvolutionGradientOptionGradientWithWeightsAndBias = 0x0000000000000002 + MPSCNNConvolutionGradientOptionAll = 0x0000000000000003 +end + +@cenum MPSCNNLossType::UInt32 begin + MPSCNNLossTypeMeanAbsoluteError = 0x0000000000000000 + MPSCNNLossTypeMeanSquaredError = 0x0000000000000001 + MPSCNNLossTypeSoftMaxCrossEntropy = 0x0000000000000002 + MPSCNNLossTypeSigmoidCrossEntropy = 0x0000000000000003 + MPSCNNLossTypeCategoricalCrossEntropy = 0x0000000000000004 + MPSCNNLossTypeHinge = 0x0000000000000005 + MPSCNNLossTypeHuber = 0x0000000000000006 + MPSCNNLossTypeCosineDistance = 0x0000000000000007 + MPSCNNLossTypeLog = 0x0000000000000008 + MPSCNNLossTypeKullbackLeiblerDivergence = 0x0000000000000009 + MPSCNNLossTypeCount = 0x000000000000000a +end + +@cenum MPSCNNReductionType::Int32 begin + MPSCNNReductionTypeNone = 0 + MPSCNNReductionTypeSum = 1 + MPSCNNReductionTypeMean = 2 + MPSCNNReductionTypeSumByNonZeroWeights = 3 + MPSCNNReductionTypeCount = 4 +end + +@cenum MPSNNComparisonType::UInt64 begin + MPSNNComparisonTypeEqual = 0x0000000000000000 + MPSNNComparisonTypeNotEqual = 0x0000000000000001 + MPSNNComparisonTypeLess = 0x0000000000000002 + MPSNNComparisonTypeLessOrEqual = 0x0000000000000003 + MPSNNComparisonTypeGreater = 0x0000000000000004 + MPSNNComparisonTypeGreaterOrEqual = 0x0000000000000005 +end + +@cenum MPSRNNSequenceDirection::UInt64 begin + MPSRNNSequenceDirectionForward = 0x0000000000000000 + MPSRNNSequenceDirectionBackward = 0x0000000000000001 +end + +@cenum MPSRNNBidirectionalCombineMode::UInt64 begin + MPSRNNBidirectionalCombineModeNone = 0x0000000000000000 + MPSRNNBidirectionalCombineModeAdd = 0x0000000000000001 + MPSRNNBidirectionalCombineModeConcatenate = 0x0000000000000002 +end + +@cenum MPSRNNMatrixId::UInt64 begin + MPSRNNMatrixIdSingleGateInputWeights = 0x0000000000000000 + MPSRNNMatrixIdSingleGateRecurrentWeights = 0x0000000000000001 + MPSRNNMatrixIdSingleGateBiasTerms = 0x0000000000000002 + MPSRNNMatrixIdLSTMInputGateInputWeights = 0x0000000000000003 + MPSRNNMatrixIdLSTMInputGateRecurrentWeights = 0x0000000000000004 + MPSRNNMatrixIdLSTMInputGateMemoryWeights = 0x0000000000000005 + MPSRNNMatrixIdLSTMInputGateBiasTerms = 0x0000000000000006 + MPSRNNMatrixIdLSTMForgetGateInputWeights = 0x0000000000000007 + MPSRNNMatrixIdLSTMForgetGateRecurrentWeights = 0x0000000000000008 + MPSRNNMatrixIdLSTMForgetGateMemoryWeights = 0x0000000000000009 + MPSRNNMatrixIdLSTMForgetGateBiasTerms = 0x000000000000000a + MPSRNNMatrixIdLSTMMemoryGateInputWeights = 0x000000000000000b + MPSRNNMatrixIdLSTMMemoryGateRecurrentWeights = 0x000000000000000c + MPSRNNMatrixIdLSTMMemoryGateMemoryWeights = 0x000000000000000d + MPSRNNMatrixIdLSTMMemoryGateBiasTerms = 0x000000000000000e + MPSRNNMatrixIdLSTMOutputGateInputWeights = 0x000000000000000f + MPSRNNMatrixIdLSTMOutputGateRecurrentWeights = 0x0000000000000010 + MPSRNNMatrixIdLSTMOutputGateMemoryWeights = 0x0000000000000011 + MPSRNNMatrixIdLSTMOutputGateBiasTerms = 0x0000000000000012 + MPSRNNMatrixIdGRUInputGateInputWeights = 0x0000000000000013 + MPSRNNMatrixIdGRUInputGateRecurrentWeights = 0x0000000000000014 + MPSRNNMatrixIdGRUInputGateBiasTerms = 0x0000000000000015 + MPSRNNMatrixIdGRURecurrentGateInputWeights = 0x0000000000000016 + MPSRNNMatrixIdGRURecurrentGateRecurrentWeights = 0x0000000000000017 + MPSRNNMatrixIdGRURecurrentGateBiasTerms = 0x0000000000000018 + MPSRNNMatrixIdGRUOutputGateInputWeights = 0x0000000000000019 + MPSRNNMatrixIdGRUOutputGateRecurrentWeights = 0x000000000000001a + MPSRNNMatrixIdGRUOutputGateInputGateWeights = 0x000000000000001b + MPSRNNMatrixIdGRUOutputGateBiasTerms = 0x000000000000001c + MPSRNNMatrixId_count = 0x000000000000001d +end + +@cenum MPSNNRegularizationType::UInt64 begin + MPSNNRegularizationTypeNone = 0x0000000000000000 + MPSNNRegularizationTypeL1 = 0x0000000000000001 + MPSNNRegularizationTypeL2 = 0x0000000000000002 +end + +struct MPSNDArrayOffsets + dimensions::NTuple{16,NSInteger} +end + +struct MPSNDArraySizes + dimensions::NTuple{16,NSUInteger} +end + +@cenum MPSNDArrayQuantizationScheme::UInt64 begin + MPSNDArrayQuantizationTypeNone = 0x0000000000000000 + MPSNDArrayQuantizationTypeAffine = 0x0000000000000001 + MPSNDArrayQuantizationTypeLUT = 0x0000000000000002 +end + +struct _MPSPackedFloat3 + data::NTuple{12,UInt8} +end + +function Base.getproperty(x::Ptr{_MPSPackedFloat3}, f::Symbol) + f === :x && return Ptr{Cfloat}(x + 0) + f === :y && return Ptr{Cfloat}(x + 4) + f === :z && return Ptr{Cfloat}(x + 8) + f === :elements && return Ptr{NTuple{3,Cfloat}}(x + 0) + return getfield(x, f) +end + +function Base.getproperty(x::_MPSPackedFloat3, f::Symbol) + r = Ref{_MPSPackedFloat3}(x) + ptr = Base.unsafe_convert(Ptr{_MPSPackedFloat3}, r) + fptr = getproperty(ptr, f) + GC.@preserve r unsafe_load(fptr) +end + +function Base.setproperty!(x::Ptr{_MPSPackedFloat3}, f::Symbol, v) + return unsafe_store!(getproperty(x, f), v) +end + +const MPSPackedFloat3 = _MPSPackedFloat3 + +struct MPSRayPackedOriginDirection + origin::MPSPackedFloat3 + direction::MPSPackedFloat3 +end + +struct MPSRayOriginMinDistanceDirectionMaxDistance + origin::MPSPackedFloat3 + minDistance::Cfloat + direction::MPSPackedFloat3 + maxDistance::Cfloat +end + +struct MPSRayOriginMaskDirectionMaxDistance + origin::MPSPackedFloat3 + mask::Cuint + direction::MPSPackedFloat3 + maxDistance::Cfloat +end + +struct MPSIntersectionDistance + distance::Cfloat +end + +struct MPSIntersectionDistancePrimitiveIndex + distance::Cfloat + primitiveIndex::Cuint +end + +struct MPSIntersectionDistancePrimitiveIndexBufferIndex + distance::Cfloat + primitiveIndex::Cuint + bufferIndex::Cuint +end + +struct MPSIntersectionDistancePrimitiveIndexInstanceIndex + distance::Cfloat + primitiveIndex::Cuint + instanceIndex::Cuint +end + +struct MPSIntersectionDistancePrimitiveIndexBufferIndexInstanceIndex + distance::Cfloat + primitiveIndex::Cuint + bufferIndex::Cuint + instanceIndex::Cuint +end + +@cenum MPSAccelerationStructureUsage::UInt64 begin + MPSAccelerationStructureUsageNone = 0x0000000000000000 + MPSAccelerationStructureUsageRefit = 0x0000000000000001 + MPSAccelerationStructureUsageFrequentRebuild = 0x0000000000000002 + MPSAccelerationStructureUsagePreferGPUBuild = 0x0000000000000004 + MPSAccelerationStructureUsagePreferCPUBuild = 0x0000000000000008 +end + +@cenum MPSAccelerationStructureStatus::UInt64 begin + MPSAccelerationStructureStatusUnbuilt = 0x0000000000000000 + MPSAccelerationStructureStatusBuilt = 0x0000000000000001 +end + +@cenum MPSPolygonType::UInt64 begin + MPSPolygonTypeTriangle = 0x0000000000000000 + MPSPolygonTypeQuadrilateral = 0x0000000000000001 +end + +@cenum MPSTransformType::UInt64 begin + MPSTransformTypeFloat4x4 = 0x0000000000000000 + MPSTransformTypeIdentity = 0x0000000000000001 +end + +@cenum MPSTemporalWeighting::UInt64 begin + MPSTemporalWeightingAverage = 0x0000000000000000 + MPSTemporalWeightingExponentialMovingAverage = 0x0000000000000001 +end + +@cenum MPSDeviceOptions::UInt64 begin + MPSDeviceOptionsDefault = 0x0000000000000000 + MPSDeviceOptionsLowPower = 0x0000000000000001 + MPSDeviceOptionsSkipRemovable = 0x0000000000000002 +end + +@cenum MPSIntersectionType::UInt64 begin + MPSIntersectionTypeNearest = 0x0000000000000000 + MPSIntersectionTypeAny = 0x0000000000000001 +end + +@cenum MPSTriangleIntersectionTestType::UInt64 begin + MPSTriangleIntersectionTestTypeDefault = 0x0000000000000000 + MPSTriangleIntersectionTestTypeWatertight = 0x0000000000000001 +end + +@cenum MPSBoundingBoxIntersectionTestType::UInt64 begin + MPSBoundingBoxIntersectionTestTypeDefault = 0x0000000000000000 + MPSBoundingBoxIntersectionTestTypeAxisAligned = 0x0000000000000001 + MPSBoundingBoxIntersectionTestTypeFast = 0x0000000000000002 +end + +@cenum MPSRayMaskOptions::UInt64 begin + MPSRayMaskOptionNone = 0x0000000000000000 + MPSRayMaskOptionPrimitive = 0x0000000000000001 + MPSRayMaskOptionInstance = 0x0000000000000002 +end + +@cenum MPSRayDataType::UInt64 begin + MPSRayDataTypeOriginDirection = 0x0000000000000000 + MPSRayDataTypeOriginMinDistanceDirectionMaxDistance = 0x0000000000000001 + MPSRayDataTypeOriginMaskDirectionMaxDistance = 0x0000000000000002 + MPSRayDataTypePackedOriginDirection = 0x0000000000000003 +end + +@cenum MPSIntersectionDataType::UInt64 begin + MPSIntersectionDataTypeDistance = 0x0000000000000000 + MPSIntersectionDataTypeDistancePrimitiveIndex = 0x0000000000000001 + MPSIntersectionDataTypeDistancePrimitiveIndexCoordinates = 0x0000000000000002 + MPSIntersectionDataTypeDistancePrimitiveIndexInstanceIndex = 0x0000000000000003 + MPSIntersectionDataTypeDistancePrimitiveIndexInstanceIndexCoordinates = 0x0000000000000004 + MPSIntersectionDataTypeDistancePrimitiveIndexBufferIndex = 0x0000000000000005 + MPSIntersectionDataTypeDistancePrimitiveIndexBufferIndexCoordinates = 0x0000000000000006 + MPSIntersectionDataTypeDistancePrimitiveIndexBufferIndexInstanceIndex = 0x0000000000000007 + MPSIntersectionDataTypeDistancePrimitiveIndexBufferIndexInstanceIndexCoordinates = 0x0000000000000008 +end + +@cenum MPSRayMaskOperator::UInt64 begin + MPSRayMaskOperatorAnd = 0x0000000000000000 + MPSRayMaskOperatorNotAnd = 0x0000000000000001 + MPSRayMaskOperatorOr = 0x0000000000000002 + MPSRayMaskOperatorNotOr = 0x0000000000000003 + MPSRayMaskOperatorXor = 0x0000000000000004 + MPSRayMaskOperatorNotXor = 0x0000000000000005 + MPSRayMaskOperatorLessThan = 0x0000000000000006 + MPSRayMaskOperatorLessThanOrEqualTo = 0x0000000000000007 + MPSRayMaskOperatorGreaterThan = 0x0000000000000008 + MPSRayMaskOperatorGreaterThanOrEqualTo = 0x0000000000000009 + MPSRayMaskOperatorEqual = 0x000000000000000a + MPSRayMaskOperatorNotEqual = 0x000000000000000b +end diff --git a/lib/mps/matrix.jl b/lib/mps/matrix.jl index 5a94e9164..de6023eb7 100644 --- a/lib/mps/matrix.jl +++ b/lib/mps/matrix.jl @@ -1,41 +1,5 @@ -## enums - -@cenum MPSDataTypeBits::UInt32 begin - MPSDataTypeFloatBit = UInt32(0x10000000) - MPSDataTypeComplexBit = UInt32(0x01000000) - MPSDataTypeSignedBit = UInt32(0x20000000) - MPSDataTypeIntBit = UInt32(0x20000000) - MPSDataTypeAlternateEncodingBit = UInt32(0x80000000) - MPSDataTypeNormalizedBit = UInt32(0x40000000) -end - -@cenum MPSDataType::UInt32 begin - MPSDataTypeInvalid = UInt32(0) - - MPSDataTypeFloat32 = MPSDataTypeFloatBit | UInt32(32) - MPSDataTypeFloat16 = MPSDataTypeFloatBit | UInt32(16) - - MPSDataTypeComplexFloat32 = MPSDataTypeFloatBit | MPSDataTypeComplexBit | UInt32(64) - MPSDataTypeComplexFloat16 = MPSDataTypeFloatBit | MPSDataTypeComplexBit | UInt32(32) +## Some extra definitions for MPSDataType defined in libmps.jl - MPSDataTypeInt4 = MPSDataTypeSignedBit | UInt32(4) - MPSDataTypeInt8 = MPSDataTypeSignedBit | UInt32(8) - MPSDataTypeInt16 = MPSDataTypeSignedBit | UInt32(16) - MPSDataTypeInt32 = MPSDataTypeSignedBit | UInt32(32) - MPSDataTypeInt64 = MPSDataTypeSignedBit | UInt32(64) - - MPSDataTypeUInt4 = UInt32(4) - MPSDataTypeUInt8 = UInt32(8) - MPSDataTypeUInt16 = UInt32(16) - MPSDataTypeUInt32 = UInt32(32) - MPSDataTypeUInt64 = UInt32(64) - - MPSDataTypeBool = MPSDataTypeAlternateEncodingBit | UInt32(8) - MPSDataTypeBFloat16 = MPSDataTypeAlternateEncodingBit | MPSDataTypeFloatBit | UInt32(16) - - MPSDataTypeUnorm1 = MPSDataTypeNormalizedBit | UInt32(1) - MPSDataTypeUnorm8 = MPSDataTypeNormalizedBit | UInt32(8) -end ## bitwise operations lose type information, so allow conversions Base.convert(::Type{MPSDataType}, x::Integer) = MPSDataType(x) diff --git a/lib/mps/matrixrandom.jl b/lib/mps/matrixrandom.jl index cca50a95a..b0e2da41f 100644 --- a/lib/mps/matrixrandom.jl +++ b/lib/mps/matrixrandom.jl @@ -1,9 +1,3 @@ -@cenum MPSMatrixRandomDistribution::UInt begin - MPSMatrixRandomDistributionDefault = 1 - MPSMatrixRandomDistributionUniform = 2 - MPSMatrixRandomDistributionNormal = 3 -end - # # matrix random descriptor # diff --git a/lib/mps/size.jl b/lib/mps/size.jl index 3df266bfc..016ac627b 100644 --- a/lib/mps/size.jl +++ b/lib/mps/size.jl @@ -1,14 +1,7 @@ -## size - -export MPSSize -struct MPSSize - width::Float64 - height::Float64 - depth::Float64 +## size - MPSSize(w=1.0, h=1.0, d=1.0) = new(w, h, d) -end +export MPSSize # (defined in libmps.jl) # convenience constructors from tuple inputs MPSSize(dims::NTuple{1,<:Real}) = MPSSize(dims[1], 1.0, 1.0) @@ -18,22 +11,4 @@ MPSSize(dims::NTuple{3,<:Real}) = MPSSize(dims[1], dims[2], dims[3]) ## origin -export MPSOrigin - -struct MPSOrigin - x::Float64 - y::Float64 - z::Float64 - - MPSOrigin(x=0, y=0, z=0) = new(x, y, z) -end - -## Offset - -struct MPSOffset - x::NSInteger - y::NSInteger - z::NSInteger - - MPSOffset(x=0, y=0, z=0) = new(x, y, z) -end +export MPSOrigin # (defined in libmps.jl) diff --git a/lib/mtl/MTL.jl b/lib/mtl/MTL.jl index e8d77898c..74a6f0921 100644 --- a/lib/mtl/MTL.jl +++ b/lib/mtl/MTL.jl @@ -22,6 +22,7 @@ release(obj) = @autoreleasepool unsafe=true Foundation.release(obj) ## source code includes +include("libmtl.jl") include("size.jl") include("device.jl") include("resource.jl") @@ -29,7 +30,6 @@ include("storage_type.jl") include("compile-opts.jl") include("library.jl") include("function.jl") -include("argument.jl") include("events.jl") include("fences.jl") include("heap.jl") diff --git a/lib/mtl/argument.jl b/lib/mtl/argument.jl deleted file mode 100644 index 31a8c36f8..000000000 --- a/lib/mtl/argument.jl +++ /dev/null @@ -1,214 +0,0 @@ -@cenum MTLDataType::NSUInteger begin - MTLDataTypeNone = 0 - - MTLDataTypeStruct = 1 - MTLDataTypeArray = 2 - - MTLDataTypeFloat = 3 - MTLDataTypeFloat2 = 4 - MTLDataTypeFloat3 = 5 - MTLDataTypeFloat4 = 6 - - MTLDataTypeFloat2x2 = 7 - MTLDataTypeFloat2x3 = 8 - MTLDataTypeFloat2x4 = 9 - - MTLDataTypeFloat3x2 = 10 - MTLDataTypeFloat3x3 = 11 - MTLDataTypeFloat3x4 = 12 - - MTLDataTypeFloat4x2 = 13 - MTLDataTypeFloat4x3 = 14 - MTLDataTypeFloat4x4 = 15 - - MTLDataTypeHalf = 16 - MTLDataTypeHalf2 = 17 - MTLDataTypeHalf3 = 18 - MTLDataTypeHalf4 = 19 - - MTLDataTypeHalf2x2 = 20 - MTLDataTypeHalf2x3 = 21 - MTLDataTypeHalf2x4 = 22 - - MTLDataTypeHalf3x2 = 23 - MTLDataTypeHalf3x3 = 24 - MTLDataTypeHalf3x4 = 25 - - MTLDataTypeHalf4x2 = 26 - MTLDataTypeHalf4x3 = 27 - MTLDataTypeHalf4x4 = 28 - - MTLDataTypeInt = 29 - MTLDataTypeInt2 = 30 - MTLDataTypeInt3 = 31 - MTLDataTypeInt4 = 32 - - MTLDataTypeUInt = 33 - MTLDataTypeUInt2 = 34 - MTLDataTypeUInt3 = 35 - MTLDataTypeUInt4 = 36 - - MTLDataTypeShort = 37 - MTLDataTypeShort2 = 38 - MTLDataTypeShort3 = 39 - MTLDataTypeShort4 = 40 - - MTLDataTypeUShort = 41 - MTLDataTypeUShort2 = 42 - MTLDataTypeUShort3 = 43 - MTLDataTypeUShort4 = 44 - - MTLDataTypeChar = 45 - MTLDataTypeChar2 = 46 - MTLDataTypeChar3 = 47 - MTLDataTypeChar4 = 48 - - MTLDataTypeUChar = 49 - MTLDataTypeUChar2 = 50 - MTLDataTypeUChar3 = 51 - MTLDataTypeUChar4 = 52 - - MTLDataTypeBool = 53 - MTLDataTypeBool2 = 54 - MTLDataTypeBool3 = 55 - MTLDataTypeBool4 = 56 - - MTLDataTypeTexture = 58 - MTLDataTypeSampler = 59 - MTLDataTypePointer = 60 - - MTLDataTypeR8Unorm = 62 - MTLDataTypeR8Snorm = 63 - MTLDataTypeR16Unorm = 64 - MTLDataTypeR16Snorm = 65 - MTLDataTypeRG8Unorm = 66 - MTLDataTypeRG8Snorm = 67 - MTLDataTypeRG16Unorm = 68 - MTLDataTypeRG16Snorm = 69 - MTLDataTypeRGBA8Unorm = 70 - MTLDataTypeRGBA8Unorm_sRGB = 71 - MTLDataTypeRGBA8Snorm = 72 - MTLDataTypeRGBA16Unorm = 73 - MTLDataTypeRGBA16Snorm = 74 - MTLDataTypeRGB10A2Unorm = 75 - MTLDataTypeRG11B10Float = 76 - MTLDataTypeRGB9E5Float = 77 - - MTLDataTypeRenderPipeline = 78 - MTLDataTypeComputePipeline = 79 - MTLDataTypeIndirectCommandBuffer = 80 - - MTLDataTypeLong = 81 - MTLDataTypeLong2 = 82 - MTLDataTypeLong3 = 83 - MTLDataTypeLong4 = 84 - - MTLDataTypeULong = 85 - MTLDataTypeULong2 = 86 - MTLDataTypeULong3 = 87 - MTLDataTypeULong4 = 88 - - MTLDataTypeDouble = 89 - MTLDataTypeDouble2 = 90 - MTLDataTypeDouble3 = 91 - MTLDataTypeDouble4 = 92 - - MTLDataTypeFloat8 = 93 - MTLDataTypeFloat16 = 94 - - MTLDataTypeHalf8 = 95 - MTLDataTypeHalf16 = 96 - - MTLDataTypeInt8 = 97 - MTLDataTypeInt16 = 98 - - MTLDataTypeUInt8 = 99 - MTLDataTypeUInt16 = 100 - - MTLDataTypeShort8 = 101 - MTLDataTypeShort16 = 102 - - MTLDataTypeUShort8 = 103 - MTLDataTypeUShort16 = 104 - - MTLDataTypeChar8 = 105 - MTLDataTypeChar16 = 106 - - MTLDataTypeUChar8 = 107 - MTLDataTypeUChar16 = 108 - - MTLDataTypeLong8 = 109 - MTLDataTypeLong16 = 110 - - MTLDataTypeULong8 = 111 - MTLDataTypeULong16 = 112 - - MTLDataTypeDouble8 = 113 - MTLDataTypeDouble16 = 114 - - MTLDataTypeVisibleFunctionTable = 115 - MTLDataTypeIntersectionFunctionTable = 116 - MTLDataTypePrimitiveAccelerationStructure = 117 - MTLDataTypeInstanceAccelerationStructure = 118 - - MTLDataTypeBool8 = 119 - MTLDataTypeBool16 = 120 - - MTLDataTypeBFloat = 121 - MTLDataTypeBFloat2 = 122 - MTLDataTypeBFloat3 = 123 - MTLDataTypeBFloat4 = 124 - MTLDataTypeBFloat8 = 125 - MTLDataTypeBFloat16 = 126 - - MTLDataTypeBFloat2x2 = 127 - MTLDataTypeBFloat2x3 = 128 - MTLDataTypeBFloat2x4 = 129 - - MTLDataTypeBFloat3x2 = 130 - MTLDataTypeBFloat3x3 = 131 - MTLDataTypeBFloat3x4 = 132 - - MTLDataTypeBFloat4x2 = 133 - MTLDataTypeBFloat4x3 = 134 - MTLDataTypeBFloat4x4 = 135 -end - -#= - -Possible (undocumented) values for this enum can be iterated using the MTLTypeInternal type: - -```julia -load_framework("Metal") - -@objcwrapper immutable=false MTLType <: NSObject - -@objcwrapper immutable=false MTLTypeInternal <: MTLType - -@objcproperties MTLTypeInternal begin - @autoproperty dataType::UInt64 - @autoproperty description::id{NSString} -end - -function MTLTypeInternal(dataType::Integer) - obj = MTLTypeInternal(@objc [MTLTypeInternal alloc]::id{MTLTypeInternal}) - finalizer(dealloc, obj) - @objc [obj::id{MTLTypeInternal} initWithDataType:dataType::UInt64]::id{MTLTypeInternal} - return obj -end - -dealloc(obj::MTLTypeInternal) = @objc [obj::id{MTLTypeInternal} dealloc]::Cvoid - -for i in 1:200 - typ = MTLTypeInternal(i) - name = string(typ.description) - if name != "Unknown" - println(" $name = $i") - end -end -``` - -=# - - -# the actual MTLArgument class is deprecated, so we don't wrap it diff --git a/lib/mtl/capture.jl b/lib/mtl/capture.jl index 4ca2a3c4f..adc3843c0 100644 --- a/lib/mtl/capture.jl +++ b/lib/mtl/capture.jl @@ -1,25 +1,3 @@ -# -# capture enums -# - -@cenum MTLCaptureError::NSUInteger begin - MTLCaptureErrorNotSupported = 1 - MTLCaptureErrorAlreadyCapturing = 2 - MTLCaptureErrorInvalidDescriptor = 3 -end - -@cenum MTLCaptureDestination::NSUInteger begin - MTLCaptureDestinationDeveloperTools = 1 - MTLCaptureDestinationGPUTraceDocument = 2 -end - -@cenum MTLCaptureDescriptorCaptureObjectType::NSUInteger begin - MTLCaptureDescriptorCaptureObjectTypeNull = 0 - MTLCaptureDescriptorCaptureObjectTypeDevice = 1 - MTLCaptureDescriptorCaptureObjectTypeQueue = 2 - MTLCaptureDescriptorCaptureObjectTypeScope = 3 -end - # # capture scope # @@ -116,7 +94,7 @@ end export MTLCaptureManager, startCapture, stopCapture, supports_destination """ - struct MTLCaptureManager + MTLCaptureManager <: NSObject Metal-managed object that handles GPU frame capture support and usage. Note: There is only one (shared) capture manager per process. diff --git a/lib/mtl/command_buf.jl b/lib/mtl/command_buf.jl index 51401cea8..b15815a87 100644 --- a/lib/mtl/command_buf.jl +++ b/lib/mtl/command_buf.jl @@ -1,22 +1,3 @@ -# -# commannd buffer enums -# - -@cenum MTLCommandBufferErrorOption::NSUInteger begin - MTLCommandBufferErrorOptionNone = 0 - MTLCommandBufferErrorOptionEncoderExecutionStatus = 1 -end - -@cenum MTLCommandBufferStatus::NSUInteger begin - MTLCommandBufferStatusNotEnqueued = 0 - MTLCommandBufferStatusEnqueued = 1 - MTLCommandBufferStatusCommitted = 2 - MTLCommandBufferStatusScheduled = 3 - MTLCommandBufferStatusCompleted = 4 - MTLCommandBufferStatusError = 5 -end - - # # command buffer descriptor # diff --git a/lib/mtl/command_enc/compute.jl b/lib/mtl/command_enc/compute.jl index ee91c97d4..439d68526 100644 --- a/lib/mtl/command_enc/compute.jl +++ b/lib/mtl/command_enc/compute.jl @@ -2,11 +2,6 @@ export MTLComputeCommandEncoder export set_function!, set_buffer!, dispatchThreadgroups!, endEncoding! export append_current_function! -@cenum MTLDispatchType::NSUInteger begin - MTLDispatchTypeSerial = 0 - MTLDispatchTypeConcurrent = 1 -end - @objcwrapper immutable=false MTLComputeCommandEncoder <: MTLCommandEncoder function MTLComputeCommandEncoder(cmdbuf::MTLCommandBuffer; diff --git a/lib/mtl/compile-opts.jl b/lib/mtl/compile-opts.jl index 5eb9c3c2b..f4cddfd36 100644 --- a/lib/mtl/compile-opts.jl +++ b/lib/mtl/compile-opts.jl @@ -1,21 +1,7 @@ # -# enums +# Extra definitions to go with MTLLanguageVersion defined in libmtl.jl # -@cenum MTLLanguageVersion::NSUInteger begin - MTLLanguageVersion1_0 = (1 << 16) - MTLLanguageVersion1_1 = (1 << 16) + 1 - MTLLanguageVersion1_2 = (1 << 16) + 2 - MTLLanguageVersion2_0 = (2 << 16) - MTLLanguageVersion2_1 = (2 << 16) + 1 - MTLLanguageVersion2_2 = (2 << 16) + 2 - MTLLanguageVersion2_3 = (2 << 16) + 3 - MTLLanguageVersion2_4 = (2 << 16) + 4 - MTLLanguageVersion3_0 = (3 << 16) + 0 - MTLLanguageVersion3_1 = (3 << 16) + 1 - MTLLanguageVersion3_2 = (3 << 16) + 2 -end - const language_versions = Dict( MTLLanguageVersion1_0 => v"1.0", MTLLanguageVersion1_1 => v"1.1", diff --git a/lib/mtl/device.jl b/lib/mtl/device.jl index 0747006e4..fccbebc1e 100644 --- a/lib/mtl/device.jl +++ b/lib/mtl/device.jl @@ -1,13 +1,3 @@ -# -# device enums -# - -@enum MTLArgumentBuffersTier::NSUInteger begin - MTLArgumentBuffersTier1 = 0 - MTLArgumentBuffersTier2 = 1 -end - - # # device # @@ -93,26 +83,6 @@ MTLDevice(i::Integer) = devices()[i] export supports_family, is_m4, is_m3, is_m2, is_m1 -@cenum MTLGPUFamily::NSInteger begin - MTLGPUFamilyMetal3 = 5001 # Metal 3 support - - MTLGPUFamilyApple9 = 1009 # M3, M4 & A17 - MTLGPUFamilyApple8 = 1008 # M2 & A15, A16 - MTLGPUFamilyApple7 = 1007 # M1 & A14 - MTLGPUFamilyApple6 = 1006 # A13 - MTLGPUFamilyApple5 = 1005 # A12 - MTLGPUFamilyApple4 = 1004 # A11 - MTLGPUFamilyApple3 = 1003 # A9, A10 - MTLGPUFamilyApple2 = 1002 # A8 - MTLGPUFamilyApple1 = 1001 # A7 - - MTLGPUFamilyCommon3 = 3003 - MTLGPUFamilyCommon2 = 3002 - MTLGPUFamilyCommon1 = 3001 - - MTLGPUFamilyMac2 = 2002 # Mac family 2 GPU features -end - function supports_family(dev::MTLDevice, gpufamily::MTLGPUFamily) @objc [dev::MTLDevice supportsFamily:gpufamily::MTLGPUFamily]::Bool end diff --git a/lib/mtl/function.jl b/lib/mtl/function.jl index 4142d7020..cc0843b46 100644 --- a/lib/mtl/function.jl +++ b/lib/mtl/function.jl @@ -1,14 +1,3 @@ -# -# function enums -# - -@cenum MTLFunctionType::NSUInteger begin - MTLFunctionTypeVertex = 1 - MTLFunctionTypeFragment = 2 - MTLFunctionTypeKernel = 3 -end - - # # function descriptor # diff --git a/lib/mtl/heap.jl b/lib/mtl/heap.jl index b59606745..bfec65b7d 100644 --- a/lib/mtl/heap.jl +++ b/lib/mtl/heap.jl @@ -1,13 +1,3 @@ -# -# heap enums -# - -@cenum MTLHeapType::NSInteger begin - MTLHeapTypeAutomatic = 0 - MTLHeapTypePlacement = 1 -end - - # # heap descriptor # diff --git a/lib/mtl/libmtl.jl b/lib/mtl/libmtl.jl new file mode 100644 index 000000000..87e89adcf --- /dev/null +++ b/lib/mtl/libmtl.jl @@ -0,0 +1,1397 @@ +# This file is automatically generated. Do not edit! +# To re-generate, execute res/wrap/wrap.jl + +using CEnum: CEnum, @cenum + +@cenum MTLTextureSwizzle::UInt8 begin + MTLTextureSwizzleZero = 0x0000000000000000 + MTLTextureSwizzleOne = 0x0000000000000001 + MTLTextureSwizzleRed = 0x0000000000000002 + MTLTextureSwizzleGreen = 0x0000000000000003 + MTLTextureSwizzleBlue = 0x0000000000000004 + MTLTextureSwizzleAlpha = 0x0000000000000005 +end + +struct MTLTextureSwizzleChannels + red::MTLTextureSwizzle + green::MTLTextureSwizzle + blue::MTLTextureSwizzle + alpha::MTLTextureSwizzle +end + +struct MTLOrigin + x::NSUInteger + y::NSUInteger + z::NSUInteger + MTLOrigin(x=0, y=0, z=0) = new(x, y, z) +end + +struct MTLSize + width::NSUInteger + height::NSUInteger + depth::NSUInteger + MTLSize(w=1, h=1, d=1) = new(w, h, d) +end + +struct MTLRegion + origin::MTLOrigin + size::MTLSize + MTLRegion(origin=MTLOrigin(), size=MTLSize()) = new(origin, size) +end + +struct MTLSamplePosition + x::Cfloat + y::Cfloat +end + +const MTLCoordinate2D = MTLSamplePosition + +struct MTLResourceID + _impl::UInt64 +end + +@cenum MTLResourceUsage::UInt64 begin + MTLResourceUsageRead = 0x0000000000000001 + MTLResourceUsageWrite = 0x0000000000000002 + MTLResourceUsageSample = 0x0000000000000004 +end + +@cenum MTLBarrierScope::UInt64 begin + MTLBarrierScopeBuffers = 0x0000000000000001 + MTLBarrierScopeTextures = 0x0000000000000002 + MTLBarrierScopeRenderTargets = 0x0000000000000004 +end + +@cenum MTLPurgeableState::UInt64 begin + MTLPurgeableStateKeepCurrent = 0x0000000000000001 + MTLPurgeableStateNonVolatile = 0x0000000000000002 + MTLPurgeableStateVolatile = 0x0000000000000003 + MTLPurgeableStateEmpty = 0x0000000000000004 +end + +@cenum MTLCPUCacheMode::UInt64 begin + MTLCPUCacheModeDefaultCache = 0x0000000000000000 + MTLCPUCacheModeWriteCombined = 0x0000000000000001 +end + +@cenum MTLStorageMode::UInt64 begin + MTLStorageModeShared = 0x0000000000000000 + MTLStorageModeManaged = 0x0000000000000001 + MTLStorageModePrivate = 0x0000000000000002 + MTLStorageModeMemoryless = 0x0000000000000003 +end + +@cenum MTLHazardTrackingMode::UInt64 begin + MTLHazardTrackingModeDefault = 0x0000000000000000 + MTLHazardTrackingModeUntracked = 0x0000000000000001 + MTLHazardTrackingModeTracked = 0x0000000000000002 +end + +@cenum MTLResourceOptions::UInt64 begin + MTLResourceCPUCacheModeDefaultCache = 0x0000000000000000 + MTLResourceCPUCacheModeWriteCombined = 0x0000000000000001 + MTLResourceStorageModeShared = 0x0000000000000000 + MTLResourceStorageModeManaged = 0x0000000000000010 + MTLResourceStorageModePrivate = 0x0000000000000020 + MTLResourceStorageModeMemoryless = 0x0000000000000030 + MTLResourceHazardTrackingModeDefault = 0x0000000000000000 + MTLResourceHazardTrackingModeUntracked = 0x0000000000000100 + MTLResourceHazardTrackingModeTracked = 0x0000000000000200 + MTLResourceOptionCPUCacheModeDefault = 0x0000000000000000 + MTLResourceOptionCPUCacheModeWriteCombined = 0x0000000000000001 +end + +@cenum MTLPixelFormat::UInt64 begin + MTLPixelFormatInvalid = 0x0000000000000000 + MTLPixelFormatA8Unorm = 0x0000000000000001 + MTLPixelFormatR8Unorm = 0x000000000000000a + MTLPixelFormatR8Unorm_sRGB = 0x000000000000000b + MTLPixelFormatR8Snorm = 0x000000000000000c + MTLPixelFormatR8Uint = 0x000000000000000d + MTLPixelFormatR8Sint = 0x000000000000000e + MTLPixelFormatR16Unorm = 0x0000000000000014 + MTLPixelFormatR16Snorm = 0x0000000000000016 + MTLPixelFormatR16Uint = 0x0000000000000017 + MTLPixelFormatR16Sint = 0x0000000000000018 + MTLPixelFormatR16Float = 0x0000000000000019 + MTLPixelFormatRG8Unorm = 0x000000000000001e + MTLPixelFormatRG8Unorm_sRGB = 0x000000000000001f + MTLPixelFormatRG8Snorm = 0x0000000000000020 + MTLPixelFormatRG8Uint = 0x0000000000000021 + MTLPixelFormatRG8Sint = 0x0000000000000022 + MTLPixelFormatB5G6R5Unorm = 0x0000000000000028 + MTLPixelFormatA1BGR5Unorm = 0x0000000000000029 + MTLPixelFormatABGR4Unorm = 0x000000000000002a + MTLPixelFormatBGR5A1Unorm = 0x000000000000002b + MTLPixelFormatR32Uint = 0x0000000000000035 + MTLPixelFormatR32Sint = 0x0000000000000036 + MTLPixelFormatR32Float = 0x0000000000000037 + MTLPixelFormatRG16Unorm = 0x000000000000003c + MTLPixelFormatRG16Snorm = 0x000000000000003e + MTLPixelFormatRG16Uint = 0x000000000000003f + MTLPixelFormatRG16Sint = 0x0000000000000040 + MTLPixelFormatRG16Float = 0x0000000000000041 + MTLPixelFormatRGBA8Unorm = 0x0000000000000046 + MTLPixelFormatRGBA8Unorm_sRGB = 0x0000000000000047 + MTLPixelFormatRGBA8Snorm = 0x0000000000000048 + MTLPixelFormatRGBA8Uint = 0x0000000000000049 + MTLPixelFormatRGBA8Sint = 0x000000000000004a + MTLPixelFormatBGRA8Unorm = 0x0000000000000050 + MTLPixelFormatBGRA8Unorm_sRGB = 0x0000000000000051 + MTLPixelFormatRGB10A2Unorm = 0x000000000000005a + MTLPixelFormatRGB10A2Uint = 0x000000000000005b + MTLPixelFormatRG11B10Float = 0x000000000000005c + MTLPixelFormatRGB9E5Float = 0x000000000000005d + MTLPixelFormatBGR10A2Unorm = 0x000000000000005e + MTLPixelFormatBGR10_XR = 0x000000000000022a + MTLPixelFormatBGR10_XR_sRGB = 0x000000000000022b + MTLPixelFormatRG32Uint = 0x0000000000000067 + MTLPixelFormatRG32Sint = 0x0000000000000068 + MTLPixelFormatRG32Float = 0x0000000000000069 + MTLPixelFormatRGBA16Unorm = 0x000000000000006e + MTLPixelFormatRGBA16Snorm = 0x0000000000000070 + MTLPixelFormatRGBA16Uint = 0x0000000000000071 + MTLPixelFormatRGBA16Sint = 0x0000000000000072 + MTLPixelFormatRGBA16Float = 0x0000000000000073 + MTLPixelFormatBGRA10_XR = 0x0000000000000228 + MTLPixelFormatBGRA10_XR_sRGB = 0x0000000000000229 + MTLPixelFormatRGBA32Uint = 0x000000000000007b + MTLPixelFormatRGBA32Sint = 0x000000000000007c + MTLPixelFormatRGBA32Float = 0x000000000000007d + MTLPixelFormatBC1_RGBA = 0x0000000000000082 + MTLPixelFormatBC1_RGBA_sRGB = 0x0000000000000083 + MTLPixelFormatBC2_RGBA = 0x0000000000000084 + MTLPixelFormatBC2_RGBA_sRGB = 0x0000000000000085 + MTLPixelFormatBC3_RGBA = 0x0000000000000086 + MTLPixelFormatBC3_RGBA_sRGB = 0x0000000000000087 + MTLPixelFormatBC4_RUnorm = 0x000000000000008c + MTLPixelFormatBC4_RSnorm = 0x000000000000008d + MTLPixelFormatBC5_RGUnorm = 0x000000000000008e + MTLPixelFormatBC5_RGSnorm = 0x000000000000008f + MTLPixelFormatBC6H_RGBFloat = 0x0000000000000096 + MTLPixelFormatBC6H_RGBUfloat = 0x0000000000000097 + MTLPixelFormatBC7_RGBAUnorm = 0x0000000000000098 + MTLPixelFormatBC7_RGBAUnorm_sRGB = 0x0000000000000099 + MTLPixelFormatPVRTC_RGB_2BPP = 0x00000000000000a0 + MTLPixelFormatPVRTC_RGB_2BPP_sRGB = 0x00000000000000a1 + MTLPixelFormatPVRTC_RGB_4BPP = 0x00000000000000a2 + MTLPixelFormatPVRTC_RGB_4BPP_sRGB = 0x00000000000000a3 + MTLPixelFormatPVRTC_RGBA_2BPP = 0x00000000000000a4 + MTLPixelFormatPVRTC_RGBA_2BPP_sRGB = 0x00000000000000a5 + MTLPixelFormatPVRTC_RGBA_4BPP = 0x00000000000000a6 + MTLPixelFormatPVRTC_RGBA_4BPP_sRGB = 0x00000000000000a7 + MTLPixelFormatEAC_R11Unorm = 0x00000000000000aa + MTLPixelFormatEAC_R11Snorm = 0x00000000000000ac + MTLPixelFormatEAC_RG11Unorm = 0x00000000000000ae + MTLPixelFormatEAC_RG11Snorm = 0x00000000000000b0 + MTLPixelFormatEAC_RGBA8 = 0x00000000000000b2 + MTLPixelFormatEAC_RGBA8_sRGB = 0x00000000000000b3 + MTLPixelFormatETC2_RGB8 = 0x00000000000000b4 + MTLPixelFormatETC2_RGB8_sRGB = 0x00000000000000b5 + MTLPixelFormatETC2_RGB8A1 = 0x00000000000000b6 + MTLPixelFormatETC2_RGB8A1_sRGB = 0x00000000000000b7 + MTLPixelFormatASTC_4x4_sRGB = 0x00000000000000ba + MTLPixelFormatASTC_5x4_sRGB = 0x00000000000000bb + MTLPixelFormatASTC_5x5_sRGB = 0x00000000000000bc + MTLPixelFormatASTC_6x5_sRGB = 0x00000000000000bd + MTLPixelFormatASTC_6x6_sRGB = 0x00000000000000be + MTLPixelFormatASTC_8x5_sRGB = 0x00000000000000c0 + MTLPixelFormatASTC_8x6_sRGB = 0x00000000000000c1 + MTLPixelFormatASTC_8x8_sRGB = 0x00000000000000c2 + MTLPixelFormatASTC_10x5_sRGB = 0x00000000000000c3 + MTLPixelFormatASTC_10x6_sRGB = 0x00000000000000c4 + MTLPixelFormatASTC_10x8_sRGB = 0x00000000000000c5 + MTLPixelFormatASTC_10x10_sRGB = 0x00000000000000c6 + MTLPixelFormatASTC_12x10_sRGB = 0x00000000000000c7 + MTLPixelFormatASTC_12x12_sRGB = 0x00000000000000c8 + MTLPixelFormatASTC_4x4_LDR = 0x00000000000000cc + MTLPixelFormatASTC_5x4_LDR = 0x00000000000000cd + MTLPixelFormatASTC_5x5_LDR = 0x00000000000000ce + MTLPixelFormatASTC_6x5_LDR = 0x00000000000000cf + MTLPixelFormatASTC_6x6_LDR = 0x00000000000000d0 + MTLPixelFormatASTC_8x5_LDR = 0x00000000000000d2 + MTLPixelFormatASTC_8x6_LDR = 0x00000000000000d3 + MTLPixelFormatASTC_8x8_LDR = 0x00000000000000d4 + MTLPixelFormatASTC_10x5_LDR = 0x00000000000000d5 + MTLPixelFormatASTC_10x6_LDR = 0x00000000000000d6 + MTLPixelFormatASTC_10x8_LDR = 0x00000000000000d7 + MTLPixelFormatASTC_10x10_LDR = 0x00000000000000d8 + MTLPixelFormatASTC_12x10_LDR = 0x00000000000000d9 + MTLPixelFormatASTC_12x12_LDR = 0x00000000000000da + MTLPixelFormatASTC_4x4_HDR = 0x00000000000000de + MTLPixelFormatASTC_5x4_HDR = 0x00000000000000df + MTLPixelFormatASTC_5x5_HDR = 0x00000000000000e0 + MTLPixelFormatASTC_6x5_HDR = 0x00000000000000e1 + MTLPixelFormatASTC_6x6_HDR = 0x00000000000000e2 + MTLPixelFormatASTC_8x5_HDR = 0x00000000000000e4 + MTLPixelFormatASTC_8x6_HDR = 0x00000000000000e5 + MTLPixelFormatASTC_8x8_HDR = 0x00000000000000e6 + MTLPixelFormatASTC_10x5_HDR = 0x00000000000000e7 + MTLPixelFormatASTC_10x6_HDR = 0x00000000000000e8 + MTLPixelFormatASTC_10x8_HDR = 0x00000000000000e9 + MTLPixelFormatASTC_10x10_HDR = 0x00000000000000ea + MTLPixelFormatASTC_12x10_HDR = 0x00000000000000eb + MTLPixelFormatASTC_12x12_HDR = 0x00000000000000ec + MTLPixelFormatGBGR422 = 0x00000000000000f0 + MTLPixelFormatBGRG422 = 0x00000000000000f1 + MTLPixelFormatDepth16Unorm = 0x00000000000000fa + MTLPixelFormatDepth32Float = 0x00000000000000fc + MTLPixelFormatStencil8 = 0x00000000000000fd + MTLPixelFormatDepth24Unorm_Stencil8 = 0x00000000000000ff + MTLPixelFormatDepth32Float_Stencil8 = 0x0000000000000104 + MTLPixelFormatX32_Stencil8 = 0x0000000000000105 + MTLPixelFormatX24_Stencil8 = 0x0000000000000106 +end + +@cenum MTLTextureType::UInt64 begin + MTLTextureType1D = 0x0000000000000000 + MTLTextureType1DArray = 0x0000000000000001 + MTLTextureType2D = 0x0000000000000002 + MTLTextureType2DArray = 0x0000000000000003 + MTLTextureType2DMultisample = 0x0000000000000004 + MTLTextureTypeCube = 0x0000000000000005 + MTLTextureTypeCubeArray = 0x0000000000000006 + MTLTextureType3D = 0x0000000000000007 + MTLTextureType2DMultisampleArray = 0x0000000000000008 + MTLTextureTypeTextureBuffer = 0x0000000000000009 +end + +@cenum MTLTextureUsage::UInt64 begin + MTLTextureUsageUnknown = 0x0000000000000000 + MTLTextureUsageShaderRead = 0x0000000000000001 + MTLTextureUsageShaderWrite = 0x0000000000000002 + MTLTextureUsageRenderTarget = 0x0000000000000004 + MTLTextureUsagePixelFormatView = 0x0000000000000010 + MTLTextureUsageShaderAtomic = 0x0000000000000020 +end + +@cenum MTLTextureCompressionType::Int64 begin + MTLTextureCompressionTypeLossless = 0 + MTLTextureCompressionTypeLossy = 1 +end + +@cenum MTLDataType::UInt64 begin + MTLDataTypeNone = 0x0000000000000000 + MTLDataTypeStruct = 0x0000000000000001 + MTLDataTypeArray = 0x0000000000000002 + MTLDataTypeFloat = 0x0000000000000003 + MTLDataTypeFloat2 = 0x0000000000000004 + MTLDataTypeFloat3 = 0x0000000000000005 + MTLDataTypeFloat4 = 0x0000000000000006 + MTLDataTypeFloat2x2 = 0x0000000000000007 + MTLDataTypeFloat2x3 = 0x0000000000000008 + MTLDataTypeFloat2x4 = 0x0000000000000009 + MTLDataTypeFloat3x2 = 0x000000000000000a + MTLDataTypeFloat3x3 = 0x000000000000000b + MTLDataTypeFloat3x4 = 0x000000000000000c + MTLDataTypeFloat4x2 = 0x000000000000000d + MTLDataTypeFloat4x3 = 0x000000000000000e + MTLDataTypeFloat4x4 = 0x000000000000000f + MTLDataTypeHalf = 0x0000000000000010 + MTLDataTypeHalf2 = 0x0000000000000011 + MTLDataTypeHalf3 = 0x0000000000000012 + MTLDataTypeHalf4 = 0x0000000000000013 + MTLDataTypeHalf2x2 = 0x0000000000000014 + MTLDataTypeHalf2x3 = 0x0000000000000015 + MTLDataTypeHalf2x4 = 0x0000000000000016 + MTLDataTypeHalf3x2 = 0x0000000000000017 + MTLDataTypeHalf3x3 = 0x0000000000000018 + MTLDataTypeHalf3x4 = 0x0000000000000019 + MTLDataTypeHalf4x2 = 0x000000000000001a + MTLDataTypeHalf4x3 = 0x000000000000001b + MTLDataTypeHalf4x4 = 0x000000000000001c + MTLDataTypeInt = 0x000000000000001d + MTLDataTypeInt2 = 0x000000000000001e + MTLDataTypeInt3 = 0x000000000000001f + MTLDataTypeInt4 = 0x0000000000000020 + MTLDataTypeUInt = 0x0000000000000021 + MTLDataTypeUInt2 = 0x0000000000000022 + MTLDataTypeUInt3 = 0x0000000000000023 + MTLDataTypeUInt4 = 0x0000000000000024 + MTLDataTypeShort = 0x0000000000000025 + MTLDataTypeShort2 = 0x0000000000000026 + MTLDataTypeShort3 = 0x0000000000000027 + MTLDataTypeShort4 = 0x0000000000000028 + MTLDataTypeUShort = 0x0000000000000029 + MTLDataTypeUShort2 = 0x000000000000002a + MTLDataTypeUShort3 = 0x000000000000002b + MTLDataTypeUShort4 = 0x000000000000002c + MTLDataTypeChar = 0x000000000000002d + MTLDataTypeChar2 = 0x000000000000002e + MTLDataTypeChar3 = 0x000000000000002f + MTLDataTypeChar4 = 0x0000000000000030 + MTLDataTypeUChar = 0x0000000000000031 + MTLDataTypeUChar2 = 0x0000000000000032 + MTLDataTypeUChar3 = 0x0000000000000033 + MTLDataTypeUChar4 = 0x0000000000000034 + MTLDataTypeBool = 0x0000000000000035 + MTLDataTypeBool2 = 0x0000000000000036 + MTLDataTypeBool3 = 0x0000000000000037 + MTLDataTypeBool4 = 0x0000000000000038 + MTLDataTypeTexture = 0x000000000000003a + MTLDataTypeSampler = 0x000000000000003b + MTLDataTypePointer = 0x000000000000003c + MTLDataTypeR8Unorm = 0x000000000000003e + MTLDataTypeR8Snorm = 0x000000000000003f + MTLDataTypeR16Unorm = 0x0000000000000040 + MTLDataTypeR16Snorm = 0x0000000000000041 + MTLDataTypeRG8Unorm = 0x0000000000000042 + MTLDataTypeRG8Snorm = 0x0000000000000043 + MTLDataTypeRG16Unorm = 0x0000000000000044 + MTLDataTypeRG16Snorm = 0x0000000000000045 + MTLDataTypeRGBA8Unorm = 0x0000000000000046 + MTLDataTypeRGBA8Unorm_sRGB = 0x0000000000000047 + MTLDataTypeRGBA8Snorm = 0x0000000000000048 + MTLDataTypeRGBA16Unorm = 0x0000000000000049 + MTLDataTypeRGBA16Snorm = 0x000000000000004a + MTLDataTypeRGB10A2Unorm = 0x000000000000004b + MTLDataTypeRG11B10Float = 0x000000000000004c + MTLDataTypeRGB9E5Float = 0x000000000000004d + MTLDataTypeRenderPipeline = 0x000000000000004e + MTLDataTypeComputePipeline = 0x000000000000004f + MTLDataTypeIndirectCommandBuffer = 0x0000000000000050 + MTLDataTypeLong = 0x0000000000000051 + MTLDataTypeLong2 = 0x0000000000000052 + MTLDataTypeLong3 = 0x0000000000000053 + MTLDataTypeLong4 = 0x0000000000000054 + MTLDataTypeULong = 0x0000000000000055 + MTLDataTypeULong2 = 0x0000000000000056 + MTLDataTypeULong3 = 0x0000000000000057 + MTLDataTypeULong4 = 0x0000000000000058 + MTLDataTypeVisibleFunctionTable = 0x0000000000000073 + MTLDataTypeIntersectionFunctionTable = 0x0000000000000074 + MTLDataTypePrimitiveAccelerationStructure = 0x0000000000000075 + MTLDataTypeInstanceAccelerationStructure = 0x0000000000000076 + MTLDataTypeBFloat = 0x0000000000000079 + MTLDataTypeBFloat2 = 0x000000000000007a + MTLDataTypeBFloat3 = 0x000000000000007b + MTLDataTypeBFloat4 = 0x000000000000007c +end + +@cenum MTLBindingType::Int64 begin + MTLBindingTypeBuffer = 0 + MTLBindingTypeThreadgroupMemory = 1 + MTLBindingTypeTexture = 2 + MTLBindingTypeSampler = 3 + MTLBindingTypeImageblockData = 16 + MTLBindingTypeImageblock = 17 + MTLBindingTypeVisibleFunctionTable = 24 + MTLBindingTypePrimitiveAccelerationStructure = 25 + MTLBindingTypeInstanceAccelerationStructure = 26 + MTLBindingTypeIntersectionFunctionTable = 27 + MTLBindingTypeObjectPayload = 34 +end + +@cenum MTLArgumentType::UInt64 begin + MTLArgumentTypeBuffer = 0x0000000000000000 + MTLArgumentTypeThreadgroupMemory = 0x0000000000000001 + MTLArgumentTypeTexture = 0x0000000000000002 + MTLArgumentTypeSampler = 0x0000000000000003 + MTLArgumentTypeImageblockData = 0x0000000000000010 + MTLArgumentTypeImageblock = 0x0000000000000011 + MTLArgumentTypeVisibleFunctionTable = 0x0000000000000018 + MTLArgumentTypePrimitiveAccelerationStructure = 0x0000000000000019 + MTLArgumentTypeInstanceAccelerationStructure = 0x000000000000001a + MTLArgumentTypeIntersectionFunctionTable = 0x000000000000001b +end + +@cenum MTLBindingAccess::UInt64 begin + MTLBindingAccessReadOnly = 0x0000000000000000 + MTLBindingAccessReadWrite = 0x0000000000000001 + MTLBindingAccessWriteOnly = 0x0000000000000002 + MTLArgumentAccessReadOnly = 0x0000000000000000 + MTLArgumentAccessReadWrite = 0x0000000000000001 + MTLArgumentAccessWriteOnly = 0x0000000000000002 +end + +const MTLArgumentAccess = MTLBindingAccess + +@cenum MTLFunctionOptions::UInt64 begin + MTLFunctionOptionNone = 0x0000000000000000 + MTLFunctionOptionCompileToBinary = 0x0000000000000001 + MTLFunctionOptionStoreFunctionInMetalPipelinesScript = 0x0000000000000002 + MTLFunctionOptionStoreFunctionInMetalScript = 0x0000000000000002 + MTLFunctionOptionFailOnBinaryArchiveMiss = 0x0000000000000004 +end + +@cenum MTLPatchType::UInt64 begin + MTLPatchTypeNone = 0x0000000000000000 + MTLPatchTypeTriangle = 0x0000000000000001 + MTLPatchTypeQuad = 0x0000000000000002 +end + +@cenum MTLFunctionType::UInt64 begin + MTLFunctionTypeVertex = 0x0000000000000001 + MTLFunctionTypeFragment = 0x0000000000000002 + MTLFunctionTypeKernel = 0x0000000000000003 + MTLFunctionTypeVisible = 0x0000000000000005 + MTLFunctionTypeIntersection = 0x0000000000000006 + MTLFunctionTypeMesh = 0x0000000000000007 + MTLFunctionTypeObject = 0x0000000000000008 +end + +@cenum MTLLanguageVersion::UInt64 begin + MTLLanguageVersion1_0 = 0x0000000000010000 + MTLLanguageVersion1_1 = 0x0000000000010001 + MTLLanguageVersion1_2 = 0x0000000000010002 + MTLLanguageVersion2_0 = 0x0000000000020000 + MTLLanguageVersion2_1 = 0x0000000000020001 + MTLLanguageVersion2_2 = 0x0000000000020002 + MTLLanguageVersion2_3 = 0x0000000000020003 + MTLLanguageVersion2_4 = 0x0000000000020004 + MTLLanguageVersion3_0 = 0x0000000000030000 + MTLLanguageVersion3_1 = 0x0000000000030001 + MTLLanguageVersion3_2 = 0x0000000000030002 +end + +@cenum MTLLibraryType::Int64 begin + MTLLibraryTypeExecutable = 0 + MTLLibraryTypeDynamic = 1 +end + +@cenum MTLLibraryOptimizationLevel::Int64 begin + MTLLibraryOptimizationLevelDefault = 0 + MTLLibraryOptimizationLevelSize = 1 +end + +@cenum MTLCompileSymbolVisibility::Int64 begin + MTLCompileSymbolVisibilityDefault = 0 + MTLCompileSymbolVisibilityHidden = 1 +end + +@cenum MTLMathMode::Int64 begin + MTLMathModeSafe = 0 + MTLMathModeRelaxed = 1 + MTLMathModeFast = 2 +end + +@cenum MTLMathFloatingPointFunctions::Int64 begin + MTLMathFloatingPointFunctionsFast = 0 + MTLMathFloatingPointFunctionsPrecise = 1 +end + +@cenum MTLLibraryError::UInt64 begin + MTLLibraryErrorUnsupported = 0x0000000000000001 + MTLLibraryErrorInternal = 0x0000000000000002 + MTLLibraryErrorCompileFailure = 0x0000000000000003 + MTLLibraryErrorCompileWarning = 0x0000000000000004 + MTLLibraryErrorFunctionNotFound = 0x0000000000000005 + MTLLibraryErrorFileNotFound = 0x0000000000000006 +end + +struct MTLCounterResultTimestamp + timestamp::UInt64 +end + +struct MTLCounterResultStageUtilization + totalCycles::UInt64 + vertexCycles::UInt64 + tessellationCycles::UInt64 + postTessellationVertexCycles::UInt64 + fragmentCycles::UInt64 + renderTargetCycles::UInt64 +end + +struct MTLCounterResultStatistic + tessellationInputPatches::UInt64 + vertexInvocations::UInt64 + postTessellationVertexInvocations::UInt64 + clipperInvocations::UInt64 + clipperPrimitivesOut::UInt64 + fragmentInvocations::UInt64 + fragmentsPassed::UInt64 + computeKernelInvocations::UInt64 +end + +@cenum MTLCounterSampleBufferError::Int64 begin + MTLCounterSampleBufferErrorOutOfMemory = 0 + MTLCounterSampleBufferErrorInvalid = 1 + MTLCounterSampleBufferErrorInternal = 2 +end + +@cenum MTLIOCompressionMethod::Int64 begin + MTLIOCompressionMethodZlib = 0 + MTLIOCompressionMethodLZFSE = 1 + MTLIOCompressionMethodLZ4 = 2 + MTLIOCompressionMethodLZMA = 3 + MTLIOCompressionMethodLZBitmap = 4 +end + +@cenum MTLFeatureSet::UInt64 begin + MTLFeatureSet_iOS_GPUFamily1_v1 = 0x0000000000000000 + MTLFeatureSet_iOS_GPUFamily2_v1 = 0x0000000000000001 + MTLFeatureSet_iOS_GPUFamily1_v2 = 0x0000000000000002 + MTLFeatureSet_iOS_GPUFamily2_v2 = 0x0000000000000003 + MTLFeatureSet_iOS_GPUFamily3_v1 = 0x0000000000000004 + MTLFeatureSet_iOS_GPUFamily1_v3 = 0x0000000000000005 + MTLFeatureSet_iOS_GPUFamily2_v3 = 0x0000000000000006 + MTLFeatureSet_iOS_GPUFamily3_v2 = 0x0000000000000007 + MTLFeatureSet_iOS_GPUFamily1_v4 = 0x0000000000000008 + MTLFeatureSet_iOS_GPUFamily2_v4 = 0x0000000000000009 + MTLFeatureSet_iOS_GPUFamily3_v3 = 0x000000000000000a + MTLFeatureSet_iOS_GPUFamily4_v1 = 0x000000000000000b + MTLFeatureSet_iOS_GPUFamily1_v5 = 0x000000000000000c + MTLFeatureSet_iOS_GPUFamily2_v5 = 0x000000000000000d + MTLFeatureSet_iOS_GPUFamily3_v4 = 0x000000000000000e + MTLFeatureSet_iOS_GPUFamily4_v2 = 0x000000000000000f + MTLFeatureSet_iOS_GPUFamily5_v1 = 0x0000000000000010 + MTLFeatureSet_macOS_GPUFamily1_v1 = 0x0000000000002710 + MTLFeatureSet_OSX_GPUFamily1_v1 = 0x0000000000002710 + MTLFeatureSet_macOS_GPUFamily1_v2 = 0x0000000000002711 + MTLFeatureSet_OSX_GPUFamily1_v2 = 0x0000000000002711 + MTLFeatureSet_macOS_ReadWriteTextureTier2 = 0x0000000000002712 + MTLFeatureSet_OSX_ReadWriteTextureTier2 = 0x0000000000002712 + MTLFeatureSet_macOS_GPUFamily1_v3 = 0x0000000000002713 + MTLFeatureSet_macOS_GPUFamily1_v4 = 0x0000000000002714 + MTLFeatureSet_macOS_GPUFamily2_v1 = 0x0000000000002715 + MTLFeatureSet_tvOS_GPUFamily1_v1 = 0x0000000000007530 + MTLFeatureSet_TVOS_GPUFamily1_v1 = 0x0000000000007530 + MTLFeatureSet_tvOS_GPUFamily1_v2 = 0x0000000000007531 + MTLFeatureSet_tvOS_GPUFamily1_v3 = 0x0000000000007532 + MTLFeatureSet_tvOS_GPUFamily2_v1 = 0x0000000000007533 + MTLFeatureSet_tvOS_GPUFamily1_v4 = 0x0000000000007534 + MTLFeatureSet_tvOS_GPUFamily2_v2 = 0x0000000000007535 +end + +@cenum MTLGPUFamily::Int64 begin + MTLGPUFamilyApple1 = 1001 + MTLGPUFamilyApple2 = 1002 + MTLGPUFamilyApple3 = 1003 + MTLGPUFamilyApple4 = 1004 + MTLGPUFamilyApple5 = 1005 + MTLGPUFamilyApple6 = 1006 + MTLGPUFamilyApple7 = 1007 + MTLGPUFamilyApple8 = 1008 + MTLGPUFamilyApple9 = 1009 + MTLGPUFamilyMac1 = 2001 + MTLGPUFamilyMac2 = 2002 + MTLGPUFamilyCommon1 = 3001 + MTLGPUFamilyCommon2 = 3002 + MTLGPUFamilyCommon3 = 3003 + MTLGPUFamilyMacCatalyst1 = 4001 + MTLGPUFamilyMacCatalyst2 = 4002 + MTLGPUFamilyMetal3 = 5001 +end + +@cenum MTLDeviceLocation::UInt64 begin + MTLDeviceLocationBuiltIn = 0x0000000000000000 + MTLDeviceLocationSlot = 0x0000000000000001 + MTLDeviceLocationExternal = 0x0000000000000002 + MTLDeviceLocationUnspecified = 0xffffffffffffffff +end + +@cenum MTLPipelineOption::UInt64 begin + MTLPipelineOptionNone = 0x0000000000000000 + MTLPipelineOptionArgumentInfo = 0x0000000000000001 + MTLPipelineOptionBindingInfo = 0x0000000000000001 + MTLPipelineOptionBufferTypeInfo = 0x0000000000000002 + MTLPipelineOptionFailOnBinaryArchiveMiss = 0x0000000000000004 +end + +@cenum MTLReadWriteTextureTier::UInt64 begin + MTLReadWriteTextureTierNone = 0x0000000000000000 + MTLReadWriteTextureTier1 = 0x0000000000000001 + MTLReadWriteTextureTier2 = 0x0000000000000002 +end + +@cenum MTLArgumentBuffersTier::UInt64 begin + MTLArgumentBuffersTier1 = 0x0000000000000000 + MTLArgumentBuffersTier2 = 0x0000000000000001 +end + +@cenum MTLSparseTextureRegionAlignmentMode::UInt64 begin + MTLSparseTextureRegionAlignmentModeOutward = 0x0000000000000000 + MTLSparseTextureRegionAlignmentModeInward = 0x0000000000000001 +end + +@cenum MTLSparsePageSize::Int64 begin + MTLSparsePageSize16 = 101 + MTLSparsePageSize64 = 102 + MTLSparsePageSize256 = 103 +end + +struct MTLAccelerationStructureSizes + accelerationStructureSize::NSUInteger + buildScratchBufferSize::NSUInteger + refitScratchBufferSize::NSUInteger +end + +@cenum MTLCounterSamplingPoint::UInt64 begin + MTLCounterSamplingPointAtStageBoundary = 0x0000000000000000 + MTLCounterSamplingPointAtDrawBoundary = 0x0000000000000001 + MTLCounterSamplingPointAtDispatchBoundary = 0x0000000000000002 + MTLCounterSamplingPointAtTileDispatchBoundary = 0x0000000000000003 + MTLCounterSamplingPointAtBlitBoundary = 0x0000000000000004 +end + +struct MTLSizeAndAlign + size::NSUInteger + align::NSUInteger +end + +const MTLTimestamp = UInt64 + +@cenum MTLSparseTextureMappingMode::UInt64 begin + MTLSparseTextureMappingModeMap = 0x0000000000000000 + MTLSparseTextureMappingModeUnmap = 0x0000000000000001 +end + +struct MTLMapIndirectArguments + regionOriginX::UInt32 + regionOriginY::UInt32 + regionOriginZ::UInt32 + regionSizeWidth::UInt32 + regionSizeHeight::UInt32 + regionSizeDepth::UInt32 + mipMapLevel::UInt32 + sliceId::UInt32 +end + +struct MTLClearColor + red::Cdouble + green::Cdouble + blue::Cdouble + alpha::Cdouble +end + +@cenum MTLLoadAction::UInt64 begin + MTLLoadActionDontCare = 0x0000000000000000 + MTLLoadActionLoad = 0x0000000000000001 + MTLLoadActionClear = 0x0000000000000002 +end + +@cenum MTLStoreAction::UInt64 begin + MTLStoreActionDontCare = 0x0000000000000000 + MTLStoreActionStore = 0x0000000000000001 + MTLStoreActionMultisampleResolve = 0x0000000000000002 + MTLStoreActionStoreAndMultisampleResolve = 0x0000000000000003 + MTLStoreActionUnknown = 0x0000000000000004 + MTLStoreActionCustomSampleDepthStore = 0x0000000000000005 +end + +@cenum MTLStoreActionOptions::UInt64 begin + MTLStoreActionOptionNone = 0x0000000000000000 + MTLStoreActionOptionCustomSamplePositions = 0x0000000000000001 +end + +@cenum MTLMultisampleDepthResolveFilter::UInt64 begin + MTLMultisampleDepthResolveFilterSample0 = 0x0000000000000000 + MTLMultisampleDepthResolveFilterMin = 0x0000000000000001 + MTLMultisampleDepthResolveFilterMax = 0x0000000000000002 +end + +@cenum MTLMultisampleStencilResolveFilter::UInt64 begin + MTLMultisampleStencilResolveFilterSample0 = 0x0000000000000000 + MTLMultisampleStencilResolveFilterDepthResolvedSample = 0x0000000000000001 +end + +@cenum MTLBlitOption::UInt64 begin + MTLBlitOptionNone = 0x0000000000000000 + MTLBlitOptionDepthFromDepthStencil = 0x0000000000000001 + MTLBlitOptionStencilFromDepthStencil = 0x0000000000000002 + MTLBlitOptionRowLinearPVRTC = 0x0000000000000004 +end + +@cenum MTLCommandBufferStatus::UInt64 begin + MTLCommandBufferStatusNotEnqueued = 0x0000000000000000 + MTLCommandBufferStatusEnqueued = 0x0000000000000001 + MTLCommandBufferStatusCommitted = 0x0000000000000002 + MTLCommandBufferStatusScheduled = 0x0000000000000003 + MTLCommandBufferStatusCompleted = 0x0000000000000004 + MTLCommandBufferStatusError = 0x0000000000000005 +end + +@cenum MTLCommandBufferError::UInt64 begin + MTLCommandBufferErrorNone = 0x0000000000000000 + MTLCommandBufferErrorInternal = 0x0000000000000001 + MTLCommandBufferErrorTimeout = 0x0000000000000002 + MTLCommandBufferErrorPageFault = 0x0000000000000003 + MTLCommandBufferErrorBlacklisted = 0x0000000000000004 + MTLCommandBufferErrorAccessRevoked = 0x0000000000000004 + MTLCommandBufferErrorNotPermitted = 0x0000000000000007 + MTLCommandBufferErrorOutOfMemory = 0x0000000000000008 + MTLCommandBufferErrorInvalidResource = 0x0000000000000009 + MTLCommandBufferErrorMemoryless = 0x000000000000000a + MTLCommandBufferErrorDeviceRemoved = 0x000000000000000b + MTLCommandBufferErrorStackOverflow = 0x000000000000000c +end + +@cenum MTLCommandBufferErrorOption::UInt64 begin + MTLCommandBufferErrorOptionNone = 0x0000000000000000 + MTLCommandBufferErrorOptionEncoderExecutionStatus = 0x0000000000000001 +end + +@cenum MTLCommandEncoderErrorState::Int64 begin + MTLCommandEncoderErrorStateUnknown = 0 + MTLCommandEncoderErrorStateCompleted = 1 + MTLCommandEncoderErrorStateAffected = 2 + MTLCommandEncoderErrorStatePending = 3 + MTLCommandEncoderErrorStateFaulted = 4 +end + +@cenum MTLDispatchType::UInt64 begin + MTLDispatchTypeSerial = 0x0000000000000000 + MTLDispatchTypeConcurrent = 0x0000000000000001 +end + +struct MTLDispatchThreadgroupsIndirectArguments + threadgroupsPerGrid::NTuple{3,UInt32} +end + +struct MTLStageInRegionIndirectArguments + stageInOrigin::NTuple{3,UInt32} + stageInSize::NTuple{3,UInt32} +end + +const NSDeviceCertification = NSInteger + +const NSProcessPerformanceProfile = NSInteger + +@cenum MTLCompareFunction::UInt64 begin + MTLCompareFunctionNever = 0x0000000000000000 + MTLCompareFunctionLess = 0x0000000000000001 + MTLCompareFunctionEqual = 0x0000000000000002 + MTLCompareFunctionLessEqual = 0x0000000000000003 + MTLCompareFunctionGreater = 0x0000000000000004 + MTLCompareFunctionNotEqual = 0x0000000000000005 + MTLCompareFunctionGreaterEqual = 0x0000000000000006 + MTLCompareFunctionAlways = 0x0000000000000007 +end + +@cenum MTLStencilOperation::UInt64 begin + MTLStencilOperationKeep = 0x0000000000000000 + MTLStencilOperationZero = 0x0000000000000001 + MTLStencilOperationReplace = 0x0000000000000002 + MTLStencilOperationIncrementClamp = 0x0000000000000003 + MTLStencilOperationDecrementClamp = 0x0000000000000004 + MTLStencilOperationInvert = 0x0000000000000005 + MTLStencilOperationIncrementWrap = 0x0000000000000006 + MTLStencilOperationDecrementWrap = 0x0000000000000007 +end + +@cenum MTLVertexFormat::UInt64 begin + MTLVertexFormatInvalid = 0x0000000000000000 + MTLVertexFormatUChar2 = 0x0000000000000001 + MTLVertexFormatUChar3 = 0x0000000000000002 + MTLVertexFormatUChar4 = 0x0000000000000003 + MTLVertexFormatChar2 = 0x0000000000000004 + MTLVertexFormatChar3 = 0x0000000000000005 + MTLVertexFormatChar4 = 0x0000000000000006 + MTLVertexFormatUChar2Normalized = 0x0000000000000007 + MTLVertexFormatUChar3Normalized = 0x0000000000000008 + MTLVertexFormatUChar4Normalized = 0x0000000000000009 + MTLVertexFormatChar2Normalized = 0x000000000000000a + MTLVertexFormatChar3Normalized = 0x000000000000000b + MTLVertexFormatChar4Normalized = 0x000000000000000c + MTLVertexFormatUShort2 = 0x000000000000000d + MTLVertexFormatUShort3 = 0x000000000000000e + MTLVertexFormatUShort4 = 0x000000000000000f + MTLVertexFormatShort2 = 0x0000000000000010 + MTLVertexFormatShort3 = 0x0000000000000011 + MTLVertexFormatShort4 = 0x0000000000000012 + MTLVertexFormatUShort2Normalized = 0x0000000000000013 + MTLVertexFormatUShort3Normalized = 0x0000000000000014 + MTLVertexFormatUShort4Normalized = 0x0000000000000015 + MTLVertexFormatShort2Normalized = 0x0000000000000016 + MTLVertexFormatShort3Normalized = 0x0000000000000017 + MTLVertexFormatShort4Normalized = 0x0000000000000018 + MTLVertexFormatHalf2 = 0x0000000000000019 + MTLVertexFormatHalf3 = 0x000000000000001a + MTLVertexFormatHalf4 = 0x000000000000001b + MTLVertexFormatFloat = 0x000000000000001c + MTLVertexFormatFloat2 = 0x000000000000001d + MTLVertexFormatFloat3 = 0x000000000000001e + MTLVertexFormatFloat4 = 0x000000000000001f + MTLVertexFormatInt = 0x0000000000000020 + MTLVertexFormatInt2 = 0x0000000000000021 + MTLVertexFormatInt3 = 0x0000000000000022 + MTLVertexFormatInt4 = 0x0000000000000023 + MTLVertexFormatUInt = 0x0000000000000024 + MTLVertexFormatUInt2 = 0x0000000000000025 + MTLVertexFormatUInt3 = 0x0000000000000026 + MTLVertexFormatUInt4 = 0x0000000000000027 + MTLVertexFormatInt1010102Normalized = 0x0000000000000028 + MTLVertexFormatUInt1010102Normalized = 0x0000000000000029 + MTLVertexFormatUChar4Normalized_BGRA = 0x000000000000002a + MTLVertexFormatUChar = 0x000000000000002d + MTLVertexFormatChar = 0x000000000000002e + MTLVertexFormatUCharNormalized = 0x000000000000002f + MTLVertexFormatCharNormalized = 0x0000000000000030 + MTLVertexFormatUShort = 0x0000000000000031 + MTLVertexFormatShort = 0x0000000000000032 + MTLVertexFormatUShortNormalized = 0x0000000000000033 + MTLVertexFormatShortNormalized = 0x0000000000000034 + MTLVertexFormatHalf = 0x0000000000000035 + MTLVertexFormatFloatRG11B10 = 0x0000000000000036 + MTLVertexFormatFloatRGB9E5 = 0x0000000000000037 +end + +@cenum MTLVertexStepFunction::UInt64 begin + MTLVertexStepFunctionConstant = 0x0000000000000000 + MTLVertexStepFunctionPerVertex = 0x0000000000000001 + MTLVertexStepFunctionPerInstance = 0x0000000000000002 + MTLVertexStepFunctionPerPatch = 0x0000000000000003 + MTLVertexStepFunctionPerPatchControlPoint = 0x0000000000000004 +end + +@cenum MTLAttributeFormat::UInt64 begin + MTLAttributeFormatInvalid = 0x0000000000000000 + MTLAttributeFormatUChar2 = 0x0000000000000001 + MTLAttributeFormatUChar3 = 0x0000000000000002 + MTLAttributeFormatUChar4 = 0x0000000000000003 + MTLAttributeFormatChar2 = 0x0000000000000004 + MTLAttributeFormatChar3 = 0x0000000000000005 + MTLAttributeFormatChar4 = 0x0000000000000006 + MTLAttributeFormatUChar2Normalized = 0x0000000000000007 + MTLAttributeFormatUChar3Normalized = 0x0000000000000008 + MTLAttributeFormatUChar4Normalized = 0x0000000000000009 + MTLAttributeFormatChar2Normalized = 0x000000000000000a + MTLAttributeFormatChar3Normalized = 0x000000000000000b + MTLAttributeFormatChar4Normalized = 0x000000000000000c + MTLAttributeFormatUShort2 = 0x000000000000000d + MTLAttributeFormatUShort3 = 0x000000000000000e + MTLAttributeFormatUShort4 = 0x000000000000000f + MTLAttributeFormatShort2 = 0x0000000000000010 + MTLAttributeFormatShort3 = 0x0000000000000011 + MTLAttributeFormatShort4 = 0x0000000000000012 + MTLAttributeFormatUShort2Normalized = 0x0000000000000013 + MTLAttributeFormatUShort3Normalized = 0x0000000000000014 + MTLAttributeFormatUShort4Normalized = 0x0000000000000015 + MTLAttributeFormatShort2Normalized = 0x0000000000000016 + MTLAttributeFormatShort3Normalized = 0x0000000000000017 + MTLAttributeFormatShort4Normalized = 0x0000000000000018 + MTLAttributeFormatHalf2 = 0x0000000000000019 + MTLAttributeFormatHalf3 = 0x000000000000001a + MTLAttributeFormatHalf4 = 0x000000000000001b + MTLAttributeFormatFloat = 0x000000000000001c + MTLAttributeFormatFloat2 = 0x000000000000001d + MTLAttributeFormatFloat3 = 0x000000000000001e + MTLAttributeFormatFloat4 = 0x000000000000001f + MTLAttributeFormatInt = 0x0000000000000020 + MTLAttributeFormatInt2 = 0x0000000000000021 + MTLAttributeFormatInt3 = 0x0000000000000022 + MTLAttributeFormatInt4 = 0x0000000000000023 + MTLAttributeFormatUInt = 0x0000000000000024 + MTLAttributeFormatUInt2 = 0x0000000000000025 + MTLAttributeFormatUInt3 = 0x0000000000000026 + MTLAttributeFormatUInt4 = 0x0000000000000027 + MTLAttributeFormatInt1010102Normalized = 0x0000000000000028 + MTLAttributeFormatUInt1010102Normalized = 0x0000000000000029 + MTLAttributeFormatUChar4Normalized_BGRA = 0x000000000000002a + MTLAttributeFormatUChar = 0x000000000000002d + MTLAttributeFormatChar = 0x000000000000002e + MTLAttributeFormatUCharNormalized = 0x000000000000002f + MTLAttributeFormatCharNormalized = 0x0000000000000030 + MTLAttributeFormatUShort = 0x0000000000000031 + MTLAttributeFormatShort = 0x0000000000000032 + MTLAttributeFormatUShortNormalized = 0x0000000000000033 + MTLAttributeFormatShortNormalized = 0x0000000000000034 + MTLAttributeFormatHalf = 0x0000000000000035 + MTLAttributeFormatFloatRG11B10 = 0x0000000000000036 + MTLAttributeFormatFloatRGB9E5 = 0x0000000000000037 +end + +@cenum MTLIndexType::UInt64 begin + MTLIndexTypeUInt16 = 0x0000000000000000 + MTLIndexTypeUInt32 = 0x0000000000000001 +end + +@cenum MTLStepFunction::UInt64 begin + MTLStepFunctionConstant = 0x0000000000000000 + MTLStepFunctionPerVertex = 0x0000000000000001 + MTLStepFunctionPerInstance = 0x0000000000000002 + MTLStepFunctionPerPatch = 0x0000000000000003 + MTLStepFunctionPerPatchControlPoint = 0x0000000000000004 + MTLStepFunctionThreadPositionInGridX = 0x0000000000000005 + MTLStepFunctionThreadPositionInGridY = 0x0000000000000006 + MTLStepFunctionThreadPositionInGridXIndexed = 0x0000000000000007 + MTLStepFunctionThreadPositionInGridYIndexed = 0x0000000000000008 +end + +@cenum MTLMutability::UInt64 begin + MTLMutabilityDefault = 0x0000000000000000 + MTLMutabilityMutable = 0x0000000000000001 + MTLMutabilityImmutable = 0x0000000000000002 +end + +@cenum MTLShaderValidation::Int64 begin + MTLShaderValidationDefault = 0 + MTLShaderValidationEnabled = 1 + MTLShaderValidationDisabled = 2 +end + +@cenum MTLPrimitiveType::UInt64 begin + MTLPrimitiveTypePoint = 0x0000000000000000 + MTLPrimitiveTypeLine = 0x0000000000000001 + MTLPrimitiveTypeLineStrip = 0x0000000000000002 + MTLPrimitiveTypeTriangle = 0x0000000000000003 + MTLPrimitiveTypeTriangleStrip = 0x0000000000000004 +end + +@cenum MTLVisibilityResultMode::UInt64 begin + MTLVisibilityResultModeDisabled = 0x0000000000000000 + MTLVisibilityResultModeBoolean = 0x0000000000000001 + MTLVisibilityResultModeCounting = 0x0000000000000002 +end + +struct MTLScissorRect + x::NSUInteger + y::NSUInteger + width::NSUInteger + height::NSUInteger +end + +struct MTLViewport + originX::Cdouble + originY::Cdouble + width::Cdouble + height::Cdouble + znear::Cdouble + zfar::Cdouble +end + +@cenum MTLCullMode::UInt64 begin + MTLCullModeNone = 0x0000000000000000 + MTLCullModeFront = 0x0000000000000001 + MTLCullModeBack = 0x0000000000000002 +end + +@cenum MTLWinding::UInt64 begin + MTLWindingClockwise = 0x0000000000000000 + MTLWindingCounterClockwise = 0x0000000000000001 +end + +@cenum MTLDepthClipMode::UInt64 begin + MTLDepthClipModeClip = 0x0000000000000000 + MTLDepthClipModeClamp = 0x0000000000000001 +end + +@cenum MTLTriangleFillMode::UInt64 begin + MTLTriangleFillModeFill = 0x0000000000000000 + MTLTriangleFillModeLines = 0x0000000000000001 +end + +struct MTLDrawPrimitivesIndirectArguments + vertexCount::UInt32 + instanceCount::UInt32 + vertexStart::UInt32 + baseInstance::UInt32 +end + +struct MTLDrawIndexedPrimitivesIndirectArguments + indexCount::UInt32 + instanceCount::UInt32 + indexStart::UInt32 + baseVertex::Int32 + baseInstance::UInt32 +end + +struct MTLVertexAmplificationViewMapping + viewportArrayIndexOffset::UInt32 + renderTargetArrayIndexOffset::UInt32 +end + +struct MTLDrawPatchIndirectArguments + patchCount::UInt32 + instanceCount::UInt32 + patchStart::UInt32 + baseInstance::UInt32 +end + +struct MTLQuadTessellationFactorsHalf + edgeTessellationFactor::NTuple{4,UInt16} + insideTessellationFactor::NTuple{2,UInt16} +end + +struct MTLTriangleTessellationFactorsHalf + edgeTessellationFactor::NTuple{3,UInt16} + insideTessellationFactor::UInt16 +end + +@cenum MTLRenderStages::UInt64 begin + MTLRenderStageVertex = 0x0000000000000001 + MTLRenderStageFragment = 0x0000000000000002 + MTLRenderStageTile = 0x0000000000000004 + MTLRenderStageObject = 0x0000000000000008 + MTLRenderStageMesh = 0x0000000000000010 +end + +@cenum MTLBlendFactor::UInt64 begin + MTLBlendFactorZero = 0x0000000000000000 + MTLBlendFactorOne = 0x0000000000000001 + MTLBlendFactorSourceColor = 0x0000000000000002 + MTLBlendFactorOneMinusSourceColor = 0x0000000000000003 + MTLBlendFactorSourceAlpha = 0x0000000000000004 + MTLBlendFactorOneMinusSourceAlpha = 0x0000000000000005 + MTLBlendFactorDestinationColor = 0x0000000000000006 + MTLBlendFactorOneMinusDestinationColor = 0x0000000000000007 + MTLBlendFactorDestinationAlpha = 0x0000000000000008 + MTLBlendFactorOneMinusDestinationAlpha = 0x0000000000000009 + MTLBlendFactorSourceAlphaSaturated = 0x000000000000000a + MTLBlendFactorBlendColor = 0x000000000000000b + MTLBlendFactorOneMinusBlendColor = 0x000000000000000c + MTLBlendFactorBlendAlpha = 0x000000000000000d + MTLBlendFactorOneMinusBlendAlpha = 0x000000000000000e + MTLBlendFactorSource1Color = 0x000000000000000f + MTLBlendFactorOneMinusSource1Color = 0x0000000000000010 + MTLBlendFactorSource1Alpha = 0x0000000000000011 + MTLBlendFactorOneMinusSource1Alpha = 0x0000000000000012 +end + +@cenum MTLBlendOperation::UInt64 begin + MTLBlendOperationAdd = 0x0000000000000000 + MTLBlendOperationSubtract = 0x0000000000000001 + MTLBlendOperationReverseSubtract = 0x0000000000000002 + MTLBlendOperationMin = 0x0000000000000003 + MTLBlendOperationMax = 0x0000000000000004 +end + +@cenum MTLColorWriteMask::UInt64 begin + MTLColorWriteMaskNone = 0x0000000000000000 + MTLColorWriteMaskRed = 0x0000000000000008 + MTLColorWriteMaskGreen = 0x0000000000000004 + MTLColorWriteMaskBlue = 0x0000000000000002 + MTLColorWriteMaskAlpha = 0x0000000000000001 + MTLColorWriteMaskAll = 0x000000000000000f +end + +@cenum MTLPrimitiveTopologyClass::UInt64 begin + MTLPrimitiveTopologyClassUnspecified = 0x0000000000000000 + MTLPrimitiveTopologyClassPoint = 0x0000000000000001 + MTLPrimitiveTopologyClassLine = 0x0000000000000002 + MTLPrimitiveTopologyClassTriangle = 0x0000000000000003 +end + +@cenum MTLTessellationPartitionMode::UInt64 begin + MTLTessellationPartitionModePow2 = 0x0000000000000000 + MTLTessellationPartitionModeInteger = 0x0000000000000001 + MTLTessellationPartitionModeFractionalOdd = 0x0000000000000002 + MTLTessellationPartitionModeFractionalEven = 0x0000000000000003 +end + +@cenum MTLTessellationFactorStepFunction::UInt64 begin + MTLTessellationFactorStepFunctionConstant = 0x0000000000000000 + MTLTessellationFactorStepFunctionPerPatch = 0x0000000000000001 + MTLTessellationFactorStepFunctionPerInstance = 0x0000000000000002 + MTLTessellationFactorStepFunctionPerPatchAndPerInstance = 0x0000000000000003 +end + +@cenum MTLTessellationFactorFormat::UInt64 begin + MTLTessellationFactorFormatHalf = 0x0000000000000000 +end + +@cenum MTLTessellationControlPointIndexType::UInt64 begin + MTLTessellationControlPointIndexTypeNone = 0x0000000000000000 + MTLTessellationControlPointIndexTypeUInt16 = 0x0000000000000001 + MTLTessellationControlPointIndexTypeUInt32 = 0x0000000000000002 +end + +@cenum MTLSamplerMinMagFilter::UInt64 begin + MTLSamplerMinMagFilterNearest = 0x0000000000000000 + MTLSamplerMinMagFilterLinear = 0x0000000000000001 +end + +@cenum MTLSamplerMipFilter::UInt64 begin + MTLSamplerMipFilterNotMipmapped = 0x0000000000000000 + MTLSamplerMipFilterNearest = 0x0000000000000001 + MTLSamplerMipFilterLinear = 0x0000000000000002 +end + +@cenum MTLSamplerAddressMode::UInt64 begin + MTLSamplerAddressModeClampToEdge = 0x0000000000000000 + MTLSamplerAddressModeMirrorClampToEdge = 0x0000000000000001 + MTLSamplerAddressModeRepeat = 0x0000000000000002 + MTLSamplerAddressModeMirrorRepeat = 0x0000000000000003 + MTLSamplerAddressModeClampToZero = 0x0000000000000004 + MTLSamplerAddressModeClampToBorderColor = 0x0000000000000005 +end + +@cenum MTLSamplerBorderColor::UInt64 begin + MTLSamplerBorderColorTransparentBlack = 0x0000000000000000 + MTLSamplerBorderColorOpaqueBlack = 0x0000000000000001 + MTLSamplerBorderColorOpaqueWhite = 0x0000000000000002 +end + +struct _MTLPackedFloat3 + data::NTuple{12,UInt8} +end + +function Base.getproperty(x::Ptr{_MTLPackedFloat3}, f::Symbol) + f === :x && return Ptr{Cfloat}(x + 0) + f === :y && return Ptr{Cfloat}(x + 4) + f === :z && return Ptr{Cfloat}(x + 8) + f === :elements && return Ptr{NTuple{3,Cfloat}}(x + 0) + return getfield(x, f) +end + +function Base.getproperty(x::_MTLPackedFloat3, f::Symbol) + r = Ref{_MTLPackedFloat3}(x) + ptr = Base.unsafe_convert(Ptr{_MTLPackedFloat3}, r) + fptr = getproperty(ptr, f) + GC.@preserve r unsafe_load(fptr) +end + +function Base.setproperty!(x::Ptr{_MTLPackedFloat3}, f::Symbol, v) + return unsafe_store!(getproperty(x, f), v) +end + +const MTLPackedFloat3 = _MTLPackedFloat3 + +struct MTLPackedFloatQuaternion + x::Cfloat + y::Cfloat + z::Cfloat + w::Cfloat +end + +struct _MTLPackedFloat4x3 + columns::NTuple{4,MTLPackedFloat3} +end + +const MTLPackedFloat4x3 = _MTLPackedFloat4x3 + +struct _MTLAxisAlignedBoundingBox + min::MTLPackedFloat3 + max::MTLPackedFloat3 +end + +const MTLAxisAlignedBoundingBox = _MTLAxisAlignedBoundingBox + +struct MTLComponentTransform + scale::MTLPackedFloat3 + shear::MTLPackedFloat3 + pivot::MTLPackedFloat3 + rotation::MTLPackedFloatQuaternion + translation::MTLPackedFloat3 +end + +@cenum MTLAccelerationStructureUsage::UInt64 begin + MTLAccelerationStructureUsageNone = 0x0000000000000000 + MTLAccelerationStructureUsageRefit = 0x0000000000000001 + MTLAccelerationStructureUsagePreferFastBuild = 0x0000000000000002 + MTLAccelerationStructureUsageExtendedLimits = 0x0000000000000004 +end + +@cenum MTLAccelerationStructureInstanceOptions::UInt32 begin + MTLAccelerationStructureInstanceOptionNone = 0x0000000000000000 + MTLAccelerationStructureInstanceOptionDisableTriangleCulling = 0x0000000000000001 + MTLAccelerationStructureInstanceOptionTriangleFrontFacingWindingCounterClockwise = 0x0000000000000002 + MTLAccelerationStructureInstanceOptionOpaque = 0x0000000000000004 + MTLAccelerationStructureInstanceOptionNonOpaque = 0x0000000000000008 +end + +@cenum MTLMatrixLayout::Int64 begin + MTLMatrixLayoutColumnMajor = 0 + MTLMatrixLayoutRowMajor = 1 +end + +@cenum MTLMotionBorderMode::UInt32 begin + MTLMotionBorderModeClamp = 0x0000000000000000 + MTLMotionBorderModeVanish = 0x0000000000000001 +end + +@cenum MTLCurveType::Int64 begin + MTLCurveTypeRound = 0 + MTLCurveTypeFlat = 1 +end + +@cenum MTLCurveBasis::Int64 begin + MTLCurveBasisBSpline = 0 + MTLCurveBasisCatmullRom = 1 + MTLCurveBasisLinear = 2 + MTLCurveBasisBezier = 3 +end + +@cenum MTLCurveEndCaps::Int64 begin + MTLCurveEndCapsNone = 0 + MTLCurveEndCapsDisk = 1 + MTLCurveEndCapsSphere = 2 +end + +struct MTLAccelerationStructureInstanceDescriptor + transformationMatrix::MTLPackedFloat4x3 + options::MTLAccelerationStructureInstanceOptions + mask::UInt32 + intersectionFunctionTableOffset::UInt32 + accelerationStructureIndex::UInt32 +end + +struct MTLAccelerationStructureUserIDInstanceDescriptor + transformationMatrix::MTLPackedFloat4x3 + options::MTLAccelerationStructureInstanceOptions + mask::UInt32 + intersectionFunctionTableOffset::UInt32 + accelerationStructureIndex::UInt32 + userID::UInt32 +end + +@cenum MTLAccelerationStructureInstanceDescriptorType::UInt64 begin + MTLAccelerationStructureInstanceDescriptorTypeDefault = 0x0000000000000000 + MTLAccelerationStructureInstanceDescriptorTypeUserID = 0x0000000000000001 + MTLAccelerationStructureInstanceDescriptorTypeMotion = 0x0000000000000002 + MTLAccelerationStructureInstanceDescriptorTypeIndirect = 0x0000000000000003 + MTLAccelerationStructureInstanceDescriptorTypeIndirectMotion = 0x0000000000000004 +end + +struct MTLAccelerationStructureMotionInstanceDescriptor + options::MTLAccelerationStructureInstanceOptions + mask::UInt32 + intersectionFunctionTableOffset::UInt32 + accelerationStructureIndex::UInt32 + userID::UInt32 + motionTransformsStartIndex::UInt32 + motionTransformsCount::UInt32 + motionStartBorderMode::MTLMotionBorderMode + motionEndBorderMode::MTLMotionBorderMode + motionStartTime::Cfloat + motionEndTime::Cfloat +end + +struct MTLIndirectAccelerationStructureInstanceDescriptor + transformationMatrix::MTLPackedFloat4x3 + options::MTLAccelerationStructureInstanceOptions + mask::UInt32 + intersectionFunctionTableOffset::UInt32 + userID::UInt32 + accelerationStructureID::MTLResourceID +end + +struct MTLIndirectAccelerationStructureMotionInstanceDescriptor + options::MTLAccelerationStructureInstanceOptions + mask::UInt32 + intersectionFunctionTableOffset::UInt32 + userID::UInt32 + accelerationStructureID::MTLResourceID + motionTransformsStartIndex::UInt32 + motionTransformsCount::UInt32 + motionStartBorderMode::MTLMotionBorderMode + motionEndBorderMode::MTLMotionBorderMode + motionStartTime::Cfloat + motionEndTime::Cfloat +end + +@cenum MTLTransformType::Int64 begin + MTLTransformTypePackedFloat4x3 = 0 + MTLTransformTypeComponent = 1 +end + +@cenum MTLHeapType::Int64 begin + MTLHeapTypeAutomatic = 0 + MTLHeapTypePlacement = 1 + MTLHeapTypeSparse = 2 +end + +@cenum MTLCaptureError::Int64 begin + MTLCaptureErrorNotSupported = 1 + MTLCaptureErrorAlreadyCapturing = 2 + MTLCaptureErrorInvalidDescriptor = 3 +end + +@cenum MTLCaptureDestination::Int64 begin + MTLCaptureDestinationDeveloperTools = 1 + MTLCaptureDestinationGPUTraceDocument = 2 +end + +@cenum MTLIndirectCommandType::UInt64 begin + MTLIndirectCommandTypeDraw = 0x0000000000000001 + MTLIndirectCommandTypeDrawIndexed = 0x0000000000000002 + MTLIndirectCommandTypeDrawPatches = 0x0000000000000004 + MTLIndirectCommandTypeDrawIndexedPatches = 0x0000000000000008 + MTLIndirectCommandTypeConcurrentDispatch = 0x0000000000000020 + MTLIndirectCommandTypeConcurrentDispatchThreads = 0x0000000000000040 + MTLIndirectCommandTypeDrawMeshThreadgroups = 0x0000000000000080 + MTLIndirectCommandTypeDrawMeshThreads = 0x0000000000000100 +end + +struct MTLIndirectCommandBufferExecutionRange + location::UInt32 + length::UInt32 +end + +@cenum MTLFunctionLogType::UInt64 begin + MTLFunctionLogTypeValidation = 0x0000000000000000 +end + +@cenum MTLAccelerationStructureRefitOptions::UInt64 begin + MTLAccelerationStructureRefitOptionVertexData = 0x0000000000000001 + MTLAccelerationStructureRefitOptionPerPrimitiveData = 0x0000000000000002 +end + +@cenum MTLDynamicLibraryError::UInt64 begin + MTLDynamicLibraryErrorNone = 0x0000000000000000 + MTLDynamicLibraryErrorInvalidFile = 0x0000000000000001 + MTLDynamicLibraryErrorCompilationFailure = 0x0000000000000002 + MTLDynamicLibraryErrorUnresolvedInstallName = 0x0000000000000003 + MTLDynamicLibraryErrorDependencyLoadFailure = 0x0000000000000004 + MTLDynamicLibraryErrorUnsupported = 0x0000000000000005 +end + +@cenum MTLLogLevel::Int64 begin + MTLLogLevelUndefined = 0 + MTLLogLevelDebug = 1 + MTLLogLevelInfo = 2 + MTLLogLevelNotice = 3 + MTLLogLevelError = 4 + MTLLogLevelFault = 5 +end + +@cenum MTLLogStateError::UInt64 begin + MTLLogStateErrorInvalidSize = 0x0000000000000001 + MTLLogStateErrorInvalid = 0x0000000000000002 +end + +@cenum MTLBinaryArchiveError::UInt64 begin + MTLBinaryArchiveErrorNone = 0x0000000000000000 + MTLBinaryArchiveErrorInvalidFile = 0x0000000000000001 + MTLBinaryArchiveErrorUnexpectedElement = 0x0000000000000002 + MTLBinaryArchiveErrorCompilationFailure = 0x0000000000000003 + MTLBinaryArchiveErrorInternalError = 0x0000000000000004 +end + +@cenum MTLIntersectionFunctionSignature::UInt64 begin + MTLIntersectionFunctionSignatureNone = 0x0000000000000000 + MTLIntersectionFunctionSignatureInstancing = 0x0000000000000001 + MTLIntersectionFunctionSignatureTriangleData = 0x0000000000000002 + MTLIntersectionFunctionSignatureWorldSpaceData = 0x0000000000000004 + MTLIntersectionFunctionSignatureInstanceMotion = 0x0000000000000008 + MTLIntersectionFunctionSignaturePrimitiveMotion = 0x0000000000000010 + MTLIntersectionFunctionSignatureExtendedLimits = 0x0000000000000020 + MTLIntersectionFunctionSignatureMaxLevels = 0x0000000000000040 + MTLIntersectionFunctionSignatureCurveData = 0x0000000000000080 +end + +@cenum MTLStitchedLibraryOptions::UInt64 begin + MTLStitchedLibraryOptionNone = 0x0000000000000000 + MTLStitchedLibraryOptionFailOnBinaryArchiveMiss = 0x0000000000000001 + MTLStitchedLibraryOptionStoreLibraryInMetalPipelinesScript = 0x0000000000000002 +end + +@cenum MTLIOPriority::Int64 begin + MTLIOPriorityHigh = 0 + MTLIOPriorityNormal = 1 + MTLIOPriorityLow = 2 +end + +@cenum MTLIOCommandQueueType::Int64 begin + MTLIOCommandQueueTypeConcurrent = 0 + MTLIOCommandQueueTypeSerial = 1 +end + +@cenum MTLIOError::Int64 begin + MTLIOErrorURLInvalid = 1 + MTLIOErrorInternal = 2 +end + +@cenum MTLIOStatus::Int64 begin + MTLIOStatusPending = 0 + MTLIOStatusCancelled = 1 + MTLIOStatusError = 2 + MTLIOStatusComplete = 3 +end + +@cenum MTLIOCompressionStatus::Int64 begin + MTLIOCompressionStatusComplete = 0 + MTLIOCompressionStatusError = 1 +end + +const MTLIOCompressionContext = Ptr{Cvoid} diff --git a/lib/mtl/resource.jl b/lib/mtl/resource.jl index 84555914d..2a120ceb0 100644 --- a/lib/mtl/resource.jl +++ b/lib/mtl/resource.jl @@ -1,46 +1,7 @@ -# -# resource enums -# - -@cenum MTLCPUCacheMode::NSUInteger begin - MTLCPUCacheModeDefaultCache = 0 - MTLCPUCacheModeWriteCombined = 1 -end - -@cenum MTLHazardTrackingMode::NSUInteger begin - MTLHazardTrackingModeDefault = 0 - MTLHazardTrackingModeUntracked = 1 - MTLHazardTrackingModeTracked = 2 -end - -@cenum MTLStorageMode::NSUInteger begin - MTLStorageModeShared = 0 - MTLStorageModeManaged = 1 - MTLStorageModePrivate = 2 - MTLStorageModeMemoryless = 3 -end - -@cenum MTLResourceOptions::NSUInteger begin - MTLResourceStorageModeShared = 0 - MTLResourceStorageModeManaged = 16 - MTLResourceStorageModePrivate = 32 - MTLResourceStorageModeMemoryless = 48 - MTLResourceCPUCacheModeDefaultCache = 0 - MTLResourceCPUCacheModeWriteCombined = 1 - MTLResourceHazardTrackingModeDefault = 0 - MTLResourceHazardTrackingModeUntracked = 256 - MTLResourceHazardTrackingModeTracked = 512 -end +# Extra definition for MTLResourceOptions defined in libmtl.jl ## bitwise operations lose type information, so allow conversions Base.convert(::Type{MTLResourceOptions}, x::Integer) = MTLResourceOptions(x) -@cenum MTLResourceUsage::NSUInteger begin - MTLResourceUsageRead = 1 - MTLResourceUsageWrite = 2 - MTLResourceUsageSample = 4 -end - - # # resourcs # diff --git a/lib/mtl/size.jl b/lib/mtl/size.jl index ea5c51979..25ee5a444 100644 --- a/lib/mtl/size.jl +++ b/lib/mtl/size.jl @@ -1,14 +1,6 @@ ## size -export MTLSize - -struct MTLSize - width::NSUInteger - height::NSUInteger - depth::NSUInteger - - MTLSize(w=1, h=1, d=1) = new(w, h, d) -end +export MTLSize # (defined in libmtl.jl) # convenience constructors from tuple inputs MTLSize(dims::NTuple{1,Integer}) = MTLSize(dims[1], 1, 1) @@ -18,24 +10,8 @@ MTLSize(dims::NTuple{3,Integer}) = MTLSize(dims[1], dims[2], dims[3]) ## origin -export MTLOrigin - -struct MTLOrigin - x::NSUInteger - y::NSUInteger - z::NSUInteger - - MTLOrigin(x=0, y=0, z=0) = new(x, y, z) -end - +export MTLOrigin # (defined in libmtl.jl) ## region -export MTLRegion - -struct MTLRegion - origin::MTLOrigin # The top-left corner of the region - size::MTLSize # The size of the region - - MTLRegion(origin=MTLOrigin(), size=MTLSize()) = new(origin, size) -end +export MTLRegion # (defined in libmtl.jl) diff --git a/lib/mtl/texture.jl b/lib/mtl/texture.jl index de2e35726..88db1c6aa 100644 --- a/lib/mtl/texture.jl +++ b/lib/mtl/texture.jl @@ -1,199 +1,5 @@ export MTLTextureDescriptor, MTLTexture -# See https://developer.apple.com/documentation/metal/mtlpixelformat?language=objc -# for details on each format -@cenum MTLPixelFormat::NSUInteger begin - MTLPixelFormatInvalid = 0 - - # Normal 8 bit formats - MTLPixelFormatA8Unorm = 1 - MTLPixelFormatR8Unorm = 10 - MTLPixelFormatR8Unorm_sRGB = 11 - MTLPixelFormatR8Snorm = 12 - MTLPixelFormatR8Uint = 13 - MTLPixelFormatR8Sint = 14 - - # Normal 16 bit formats - MTLPixelFormatR16Unorm = 20 - MTLPixelFormatR16Snorm = 22 - MTLPixelFormatR16Uint = 23 - MTLPixelFormatR16Sint = 24 - MTLPixelFormatR16Float = 25 - - MTLPixelFormatRG8Unorm = 30 - MTLPixelFormatRG8Unorm_sRGB = 31 - MTLPixelFormatRG8Snorm = 32 - MTLPixelFormatRG8Uint = 33 - MTLPixelFormatRG8Sint = 34 - - # Packed 16 bit formats - MTLPixelFormatB5G6R5Unorm = 40 - MTLPixelFormatA1BGR5Unorm = 41 - MTLPixelFormatABGR4Unorm = 42 - MTLPixelFormatBGR5A1Unorm = 43 - - # Normal 32 bit formats - MTLPixelFormatR32Uint = 53 - MTLPixelFormatR32Sint = 54 - MTLPixelFormatR32Float = 55 - - MTLPixelFormatRG16Unorm = 60 - MTLPixelFormatRG16Snorm = 62 - MTLPixelFormatRG16Uint = 63 - MTLPixelFormatRG16Sint = 64 - MTLPixelFormatRG16Float = 65 - - MTLPixelFormatRGBA8Unorm = 70 - MTLPixelFormatRGBA8Unorm_sRGB = 71 - MTLPixelFormatRGBA8Snorm = 72 - MTLPixelFormatRGBA8Uint = 73 - MTLPixelFormatRGBA8Sint = 74 - - MTLPixelFormatBGRA8Unorm = 80 - MTLPixelFormatBGRA8Unorm_sRGB = 81 - - # Packed 32 bit formats - MTLPixelFormatRGB10A2Unorm = 90 - MTLPixelFormatRGB10A2Uint = 91 - - MTLPixelFormatRG11B10Float = 92 - MTLPixelFormatRGB9E5Float = 93 - - MTLPixelFormatBGR10A2Unorm = 94 - - MTLPixelFormatBGR10_XR = 554 - MTLPixelFormatBGR10_XR_sRGB = 555 - - # Normal 64 bit formats - MTLPixelFormatRG32Uint = 103 - MTLPixelFormatRG32Sint = 104 - MTLPixelFormatRG32Float = 105 - - MTLPixelFormatRGBA16Unorm = 110 - MTLPixelFormatRGBA16Snorm = 112 - MTLPixelFormatRGBA16Uint = 113 - MTLPixelFormatRGBA16Sint = 114 - MTLPixelFormatRGBA16Float = 115 - - MTLPixelFormatBGRA10_XR = 552 - MTLPixelFormatBGRA10_XR_sRGB = 553 - - # Normal 128 bit formats - MTLPixelFormatRGBA32Uint = 123 - MTLPixelFormatRGBA32Sint = 124 - MTLPixelFormatRGBA32Float = 125 - - ## Compressed formats - - # S3TC/DXT - MTLPixelFormatBC1_RGBA = 130 - MTLPixelFormatBC1_RGBA_sRGB = 131 - MTLPixelFormatBC2_RGBA = 132 - MTLPixelFormatBC2_RGBA_sRGB = 133 - MTLPixelFormatBC3_RGBA = 134 - MTLPixelFormatBC3_RGBA_sRGB = 135 - - # RGTC - MTLPixelFormatBC4_RUnorm = 140 - MTLPixelFormatBC4_RSnorm = 141 - MTLPixelFormatBC5_RGUnorm = 142 - MTLPixelFormatBC5_RGSnorm = 143 - - # BPTC - MTLPixelFormatBC6H_RGBFloat = 150 - MTLPixelFormatBC6H_RGBUfloat = 151 - MTLPixelFormatBC7_RGBAUnorm = 152 - MTLPixelFormatBC7_RGBAUnorm_sRGB = 153 - - # PVRTC - MTLPixelFormatPVRTC_RGB_2BPP = 160 - MTLPixelFormatPVRTC_RGB_2BPP_sRGB = 161 - MTLPixelFormatPVRTC_RGB_4BPP = 162 - MTLPixelFormatPVRTC_RGB_4BPP_sRGB = 163 - MTLPixelFormatPVRTC_RGBA_2BPP = 164 - MTLPixelFormatPVRTC_RGBA_2BPP_sRGB = 165 - MTLPixelFormatPVRTC_RGBA_4BPP = 166 - MTLPixelFormatPVRTC_RGBA_4BPP_sRGB = 167 - - # ETC2 - MTLPixelFormatEAC_R11Unorm = 170 - MTLPixelFormatEAC_R11Snorm = 172 - MTLPixelFormatEAC_RG11Unorm = 174 - MTLPixelFormatEAC_RG11Snorm = 176 - MTLPixelFormatEAC_RGBA8 = 178 - MTLPixelFormatEAC_RGBA8_sRGB = 179 - - MTLPixelFormatETC2_RGB8 = 180 - MTLPixelFormatETC2_RGB8_sRGB = 181 - MTLPixelFormatETC2_RGB8A1 = 182 - MTLPixelFormatETC2_RGB8A1_sRGB = 183 - - # ASTC - MTLPixelFormatASTC_4x4_sRGB = 186 - MTLPixelFormatASTC_5x4_sRGB = 187 - MTLPixelFormatASTC_5x5_sRGB = 188 - MTLPixelFormatASTC_6x5_sRGB = 189 - MTLPixelFormatASTC_6x6_sRGB = 190 - MTLPixelFormatASTC_8x5_sRGB = 192 - MTLPixelFormatASTC_8x6_sRGB = 193 - MTLPixelFormatASTC_8x8_sRGB = 194 - MTLPixelFormatASTC_10x5_sRGB = 195 - MTLPixelFormatASTC_10x6_sRGB = 196 - MTLPixelFormatASTC_10x8_sRGB = 197 - MTLPixelFormatASTC_10x10_sRGB = 198 - MTLPixelFormatASTC_12x10_sRGB = 199 - MTLPixelFormatASTC_12x12_sRGB = 200 - - MTLPixelFormatASTC_4x4_LDR = 204 - MTLPixelFormatASTC_5x4_LDR = 205 - MTLPixelFormatASTC_5x5_LDR = 206 - MTLPixelFormatASTC_6x5_LDR = 207 - MTLPixelFormatASTC_6x6_LDR = 208 - MTLPixelFormatASTC_8x5_LDR = 210 - MTLPixelFormatASTC_8x6_LDR = 211 - MTLPixelFormatASTC_8x8_LDR = 212 - MTLPixelFormatASTC_10x5_LDR = 213 - MTLPixelFormatASTC_10x6_LDR = 214 - MTLPixelFormatASTC_10x8_LDR = 215 - MTLPixelFormatASTC_10x10_LDR = 216 - MTLPixelFormatASTC_12x10_LDR = 217 - MTLPixelFormatASTC_12x12_LDR = 218 - - - # ASTC HDR (High Dynamic Range) Formats - MTLPixelFormatASTC_4x4_HDR = 222 - MTLPixelFormatASTC_5x4_HDR = 223 - MTLPixelFormatASTC_5x5_HDR = 224 - MTLPixelFormatASTC_6x5_HDR = 225 - MTLPixelFormatASTC_6x6_HDR = 226 - MTLPixelFormatASTC_8x5_HDR = 228 - MTLPixelFormatASTC_8x6_HDR = 229 - MTLPixelFormatASTC_8x8_HDR = 230 - MTLPixelFormatASTC_10x5_HDR = 231 - MTLPixelFormatASTC_10x6_HDR = 232 - MTLPixelFormatASTC_10x8_HDR = 233 - MTLPixelFormatASTC_10x10_HDR = 234 - MTLPixelFormatASTC_12x10_HDR = 235 - MTLPixelFormatASTC_12x12_HDR = 236 - - # YUV - MTLPixelFormatGBGR422 = 240 - MTLPixelFormatBGRG422 = 241 - - # Depth - MTLPixelFormatDepth16Unorm = 250 - MTLPixelFormatDepth32Float = 252 - - # Stencil - MTLPixelFormatStencil8 = 253 - - # Depth Stencil - MTLPixelFormatDepth24Unorm_Stencil8 = 255 - MTLPixelFormatDepth32Float_Stencil8 = 260 - - MTLPixelFormatX32_Stencil8 = 261 - MTLPixelFormatX24_Stencil8 = 262 -end ## bitwise operations lose type information, so allow conversions Base.convert(::Type{MTLPixelFormat}, x::Integer) = MTLPixelFormat(x) @@ -201,14 +7,6 @@ function minimumLinearTextureAlignmentForPixelFormat(dev, format) return @objc [dev::MTLDevice minimumLinearTextureAlignmentForPixelFormat:format::MTLPixelFormat]::NSUInteger end -@cenum MTLTextureUsage::NSUInteger begin - MTLTextureUsageUnknown = 0x0000 - MTLTextureUsageShaderRead = 0x0001 - MTLTextureUsageShaderWrite = 0x0002 - MTLTextureUsageRenderTarget = 0x0004 - MTLTextureUsagePixelFormatView = 0x0010 - MTLTextureUsageShaderAtomic = 0x0020 -end ## bitwise operations lose type information, so allow conversions Base.convert(::Type{MTLTextureUsage}, x::Integer) = MTLTextureUsage(x) diff --git a/res/.gitignore b/res/.gitignore deleted file mode 100644 index 5083895b4..000000000 --- a/res/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -LibTemplate.jl -ctypes.jl -lib*.jl diff --git a/res/wrap/.gitignore b/res/wrap/.gitignore new file mode 100644 index 000000000..d33fed702 --- /dev/null +++ b/res/wrap/.gitignore @@ -0,0 +1 @@ +*.JLD2 diff --git a/res/wrap/Project.toml b/res/wrap/Project.toml new file mode 100644 index 000000000..2daf101b3 --- /dev/null +++ b/res/wrap/Project.toml @@ -0,0 +1,9 @@ +[deps] +Clang = "40e3b903-d033-50b4-a0cc-940c62c95e31" +Clang_jll = "0ee61d77-7f21-5576-8119-9fcc46b10100" +Glob = "c27321d9-0574-5035-807b-f59d2c89b15c" +JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819" +JuliaFormatter = "98e50ef6-434e-11e9-1051-2b60c6c9e899" +Logging = "56ddb016-857b-54e1-b83d-db4d58db5568" +Revise = "295af30f-e4ad-537b-8983-00126c2a3abe" +Tokenize = "0796e94c-ce3b-5d07-9a54-7f471281c624" diff --git a/res/wrap/README.md b/res/wrap/README.md new file mode 100644 index 000000000..f7c466bf7 --- /dev/null +++ b/res/wrap/README.md @@ -0,0 +1,50 @@ +# Automated wrapper generation + +This directory contains scripts to generate Julia wrappers for Metal and MetalPerformanceShaders. + +Currently, only `enums` and `structs` are able to be generated. Don't forget to update the wrappers section in the contributing docs if this changes! + +The scripts are meant to be run from this directory, and at the moment, [this Clang.jl branch](https://github.com/christiangnrd/Clang.jl/tree/objectiveC) must be used. + +-------- + +Comment from removed file on `MTLDataType`. Parsing the headers does not reveal these hidden values. + +~~~ +#= + +Possible (undocumented) values for this enum can be iterated using the MTLTypeInternal type: + +```julia +load_framework("Metal") + +@objcwrapper immutable=false MTLType <: NSObject + +@objcwrapper immutable=false MTLTypeInternal <: MTLType + +@objcproperties MTLTypeInternal begin + @autoproperty dataType::UInt64 + @autoproperty description::id{NSString} +end + +function MTLTypeInternal(dataType::Integer) + obj = MTLTypeInternal(@objc [MTLTypeInternal alloc]::id{MTLTypeInternal}) + finalizer(dealloc, obj) + @objc [obj::id{MTLTypeInternal} initWithDataType:dataType::UInt64]::id{MTLTypeInternal} + return obj +end + +dealloc(obj::MTLTypeInternal) = @objc [obj::id{MTLTypeInternal} dealloc]::Cvoid + +for i in 1:200 + typ = MTLTypeInternal(i) + name = string(typ.description) + if name != "Unknown" + println(" $name = $i") + end +end +``` + +=# + +~~~ diff --git a/res/wrap/libmps.toml b/res/wrap/libmps.toml new file mode 100644 index 000000000..92ff458ae --- /dev/null +++ b/res/wrap/libmps.toml @@ -0,0 +1,36 @@ +[general] +library_name = "libmps" +output_file_path = "../../lib/mps/libmps.jl" +prologue_file_path = "libmps_prologue.jl" + +printer_blacklist = [ + "mt_macCatalyst", + "mt_ios", + "mt_macos", + "CF.*", + "MTL.*", + "NS.*", + "BOOL" +] + +[codegen] +use_ccall_macro = true +always_NUL_terminated_string = true + +[codegen.macro] +# it's highly recommended to set this entry to "basic". +# if you'd like to skip all of the macros, please set this entry to "disable". +# if you'd like to translate function-like macros to Julia, please set this entry to "aggressive". +macro_mode = "disable" + +[api.MPSSize] +constructor = "MPSSize(w=1.0, h=1.0, d=1.0) = new(w, h, d)" + +[api.MPSRegion] +constructor = "MPSRegion(origin=MPSOrigin(), size=MPSSize()) = new(origin, size)" + +[api.MPSOrigin] +constructor = "MPSOrigin(x=0.0, y=0.0, z=0.0) = new(x, y, z)" + +[api.MPSOffset] +constructor = "MPSOffset(x=0, y=0, z=0) = new(x, y, z)" diff --git a/res/wrap/libmps_prologue.jl b/res/wrap/libmps_prologue.jl new file mode 100644 index 000000000..b6b6deb28 --- /dev/null +++ b/res/wrap/libmps_prologue.jl @@ -0,0 +1 @@ +using .MTL: MTLPixelFormat, MTLTextureType, MTLTextureUsage \ No newline at end of file diff --git a/res/wrap/libmtl.toml b/res/wrap/libmtl.toml new file mode 100644 index 000000000..db53adb5d --- /dev/null +++ b/res/wrap/libmtl.toml @@ -0,0 +1,31 @@ +[general] +library_name = "libmtl" +output_file_path = "../../lib/mtl/libmtl.jl" + +generate_isystem_symbols = false + +printer_blacklist = [ + "mt_macCatalyst", + "mt_ios", + "mt_macos", + "CF*" +] + +[codegen] +use_ccall_macro = true +always_NUL_terminated_string = true + +[codegen.macro] +# it's highly recommended to set this entry to "basic". +# if you'd like to skip all of the macros, please set this entry to "disable". +# if you'd like to translate function-like macros to Julia, please set this entry to "aggressive". +macro_mode = "disable" + +[api.MTLSize] +constructor = "MTLSize(w=1, h=1, d=1) = new(w, h, d)" + +[api.MTLRegion] +constructor = "MTLRegion(origin=MTLOrigin(), size=MTLSize()) = new(origin, size)" + +[api.MTLOrigin] +constructor = "MTLOrigin(x=0, y=0, z=0) = new(x, y, z)" diff --git a/res/wrap/wrap.jl b/res/wrap/wrap.jl new file mode 100644 index 000000000..e86588bd8 --- /dev/null +++ b/res/wrap/wrap.jl @@ -0,0 +1,180 @@ +# Not necessary, but removes some errors that don't seem to affect the output +using Clang_jll +Clang_jll.libclang = "/Applications/Xcode.app/Contents/Frameworks/libclang.dylib" + +using Clang.Generators +using Clang.Generators: LinkEnumAlias +using Clang +using Glob +using JLD2 +using JuliaFormatter +using Logging + +# Use system SDK +SDK_PATH = `xcrun --show-sdk-path` |> open |> readchomp |> String + +# Hack to prevent printing of functions for now +Generators.skip_check(dag::Generators.ExprDAG, node::Generators.ExprNode{Generators.FunctionProto}) = true + +main(name::AbstractString; kwargs...) = main([name]; kwargs...) +function main(names=["all"]; sdk_path=SDK_PATH) + path_to_framework(framework) = joinpath(sdk_path, "System/Library/Frameworks/",framework*".framework","Headers") + path_to_mps_framework(framework) = joinpath(sdk_path, "System/Library/Frameworks/","MetalPerformanceShaders.framework","Frameworks",framework*".framework","Headers") + + defines = [] + + ctxs = [] + + if "all" in names || "libmtl" in names || "mtl" in names + fwpath = path_to_framework("Metal") + tctx = wrap("libmtl", joinpath(fwpath, "Metal.h"); defines) + push!(ctxs, tctx) + end + + if "all" in names || "libmps" in names || "mps" in names + mpsframeworks = ["MPSCore", "MPSImage", "MPSMatrix", "MPSNDArray", "MPSNeuralNetwork", "MPSRayIntersector"] + fwpaths = [path_to_framework("MetalPerformanceShaders")] + fwpaths = append!(fwpaths, path_to_mps_framework.(mpsframeworks)) + + getheaderfname(path) = Sys.splitext(Sys.splitpath(path)[end-1])[1] * ".h" + headers = joinpath.(fwpaths, getheaderfname.(fwpaths)) + + tctx = wrap("libmps", headers; defines) + push!(ctxs, tctx) + end + + # if "all" in names || "libfoundation" in names || "foundation" in names + # fwpath = path_to_framework("Foundation") + # tctx = wrap("libfoundation", joinpath(foundation, "Foundation.h");, defines=["__builtin_va_list"]) + # push!(ctxs, tctx) + # end + # if "all" in names || "libcf" in names || "cf" in names + # fwpath = path_to_framework("CoreFoundation") + # tctx = wrap("libfoundation", joinpath(fwpath, "CoreFoundation.h");, defines=["__builtin_va_list"]) + # push!(ctxs, tctx) + # end + return ctxs +end + +function wrap(name, headers; defines=[]) + @info "Wrapping $name" + + options = load_options(joinpath(@__DIR__, "$(name).toml")) + + args = [ + "-x","objective-c", + "-isysroot", SDK_PATH, + "-fblocks", + "-fregister-global-dtors-with-atexit", + "-fgnuc-version=4.2.1", + "-fobjc-runtime=macosx-15.0.0", + "-fobjc-exceptions", + "-fexceptions", + "-fmax-type-align=16", + "-fcommon", + "-DNS_FORMAT_ARGUMENT(A)=", + "-D__GCC_HAVE_DWARF2_CFI_ASM=1", + ] + + for define in defines + if isa(define, Pair) + append!(args, ["-D", "$(first(define))=$(last(define))"]) + else + append!(args, ["-D", "$define"]) + end + end + + @info "Creating context" + ctx = create_objc_context(headers, args, options) + + @info "Building no printing" + build!(ctx, BUILDSTAGE_NO_PRINTING) + + rewriter!(ctx, options) + + @info "Building only printing" + build!(ctx, BUILDSTAGE_PRINTING_ONLY) + + output_file = options["general"]["output_file_path"] + + # prepend "autogenerated, do not edit!" comment + output_data = read(output_file, String) + open(output_file, "w") do io + println(io, """# This file is automatically generated. Do not edit! + # To re-generate, execute res/wrap/wrap.jl""") + println(io) + print(io, output_data) + end + + format_file(output_file, YASStyle()) + + return ctx +end + +# Uses the same passes as with C, but with some other changes +create_objc_context(header::AbstractString, args=String[], ops=Dict()) = create_objc_context([header], args, ops) +function create_objc_context(headers::Vector, args::Vector=String[], options::Dict=Dict()) + system_dirs = [ + SDK_PATH, + "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain" + ] + + # Since the framework we're wrapping is a system header, + # find all dependent headers, then remove all but the relevant ones + # also temporarily disable logging + dep_headers_fname = if haskey(options, "general") && haskey(options["general"], "library_name") + options["general"]["library_name"]*".JLD2" + else + nothing + end + Base.CoreLogging._min_enabled_level[] = Logging.Info+1 + dependent_headers = if !isnothing(dep_headers_fname) && isfile(dep_headers_fname) + JLD2.load(dep_headers_fname, "dep_headers") + else + all_headers = find_dependent_headers(headers,args,[]) + dep_headers = Vector{eltype(all_headers)}(undef, 0) + for header in headers + target_framework = "/"*joinpath(Sys.splitpath(header)[end-2:end-1]) + dep_headers = append!(dep_headers, filter(s -> occursin(target_framework, s), all_headers)) + end + JLD2.@save dep_headers_fname dep_headers + dep_headers + end + Base.CoreLogging._min_enabled_level[] = Logging.Debug + + ctx = Context(; options) + + @info "Parsing headers..." + parse_headers!(ctx, headers, args) + + Generators.add_default_passes!(ctx, options, system_dirs, dependent_headers) +end + +function rewriter!(ctx, options) + if haskey(options, "api") + for node in get_nodes(ctx.dag) + if typeof(node) <: Generators.ExprNode{<:Generators.AbstractStructNodeType} + expr = node.exprs[1] + structName = String(expr.args[2]) + + if haskey(options["api"], structName) + # Add default constructer to some structs + if haskey(options["api"][structName], "constructor") + expr = node.exprs[1] + con = options["api"][structName]["constructor"] |> Meta.parse + + if con.head == :(=) && con.args[2] isa Expr && con.args[2].head == :block && + con.args[2].args[1] isa LineNumberNode && con.args[2].args[2].head == :call + con.args[2] = con.args[2].args[2] + end + push!(expr.args[3].args, con) + end + end + end + end + end +end + +if abspath(PROGRAM_FILE) == @__FILE__ + main() +end