From c19b9401813bdc4fac82dc8b64da9f3d5bdb7c8e Mon Sep 17 00:00:00 2001 From: Tim Besard Date: Wed, 8 Mar 2023 16:41:30 +0100 Subject: [PATCH] Remove libcmt, use native ObjectiveC FFI (#117) --- .buildkite/pipeline.yml | 8 - Manifest.toml | 14 +- Project.toml | 10 +- README.md | 61 +- deps/build_ci.jl | 54 - deps/build_cmt.jl | 58 - deps/cmt/CMakeLists.txt | 88 - deps/cmt/LICENSE | 21 - deps/cmt/README.md | 42 - deps/cmt/include/cmt/argument_buffer.h | 25 - deps/cmt/include/cmt/argument_descriptor.h | 85 - deps/cmt/include/cmt/argument_encoder.h | 111 - .../include/cmt/capture/capture_descriptor.h | 60 - .../cmt/include/cmt/capture/capture_manager.h | 50 - deps/cmt/include/cmt/capture/capture_scope.h | 50 - deps/cmt/include/cmt/cmt.h | 78 - deps/cmt/include/cmt/command_buf.h | 203 -- deps/cmt/include/cmt/command_buf_indirect.h | 48 - deps/cmt/include/cmt/command_enc.h | 47 - deps/cmt/include/cmt/command_enc_blit.h | 129 - deps/cmt/include/cmt/command_enc_compute.h | 166 -- deps/cmt/include/cmt/command_enc_render.h | 91 - deps/cmt/include/cmt/command_queue.h | 42 - deps/cmt/include/cmt/common.h | 38 - deps/cmt/include/cmt/common_internal.h | 18 - .../include/cmt/compute/compute-pipeline.h | 142 - deps/cmt/include/cmt/device.h | 161 -- deps/cmt/include/cmt/enums.h | 518 ---- deps/cmt/include/cmt/error.h | 47 - deps/cmt/include/cmt/event.h | 72 - deps/cmt/include/cmt/kernels/attribute.h | 49 - .../include/cmt/kernels/attribute_vertex.h | 49 - deps/cmt/include/cmt/kernels/binary_archive.h | 70 - deps/cmt/include/cmt/kernels/compile-opts.h | 44 - .../cmt/include/cmt/kernels/constant_values.h | 41 - deps/cmt/include/cmt/kernels/function.h | 84 - deps/cmt/include/cmt/kernels/library.h | 65 - deps/cmt/include/cmt/macros.h | 10 - deps/cmt/include/cmt/memory/buffer.h | 65 - deps/cmt/include/cmt/memory/heap-descriptor.h | 85 - deps/cmt/include/cmt/memory/heap.h | 112 - deps/cmt/include/cmt/memory/vertex.h | 144 - .../include/cmt/performance_shaders/device.h | 24 - .../include/cmt/performance_shaders/matrix.h | 43 - deps/cmt/include/cmt/pixelformat.h | 179 -- deps/cmt/include/cmt/reflection/argument.h | 87 - deps/cmt/include/cmt/reflection/descriptor.h | 29 - .../cmt/include/cmt/reflection/pointer_type.h | 54 - deps/cmt/include/cmt/rendering/depthstencil.h | 46 - deps/cmt/include/cmt/rendering/pass.h | 37 - deps/cmt/include/cmt/rendering/pipeline.h | 70 - deps/cmt/include/cmt/resource.h | 85 - deps/cmt/include/cmt/types.h | 15 - deps/cmt/include/cmt/types_foundation.h | 35 - deps/cmt/include/cmt/types_metal.h | 127 - deps/cmt/include/cmt/types_mps.h | 15 - deps/cmt/include/impl/common.h | 14 - deps/cmt/include/impl/conversion.h | 140 - deps/cmt/src/argument_buffer.m | 7 - deps/cmt/src/argument_descriptor.m | 99 - deps/cmt/src/argument_encoder.m | 157 -- deps/cmt/src/capture/capture_descriptor.m | 66 - deps/cmt/src/capture/capture_manager.m | 51 - deps/cmt/src/capture/capture_scope.m | 52 - deps/cmt/src/cmt.m | 19 - deps/cmt/src/command_buf.m | 268 -- deps/cmt/src/command_buf_indirect.m | 49 - deps/cmt/src/command_enc.m | 53 - deps/cmt/src/command_enc_blit.m | 182 -- deps/cmt/src/command_enc_compute.m | 228 -- deps/cmt/src/command_enc_render.m | 133 - deps/cmt/src/command_queue.m | 42 - deps/cmt/src/compute/compute-pipeline.m | 187 -- deps/cmt/src/device.m | 250 -- deps/cmt/src/error.m | 61 - deps/cmt/src/event.m | 82 - deps/cmt/src/kernels/attribute.m | 49 - deps/cmt/src/kernels/attribute_vertex.m | 49 - deps/cmt/src/kernels/binary_archive.m | 80 - deps/cmt/src/kernels/compile-opts.m | 44 - deps/cmt/src/kernels/constant_values.m | 43 - deps/cmt/src/kernels/function.m | 113 - deps/cmt/src/kernels/library.m | 92 - deps/cmt/src/memory/buffer.m | 64 - deps/cmt/src/memory/heap-descriptor.m | 100 - deps/cmt/src/memory/heap.m | 138 - deps/cmt/src/memory/vertex.m | 68 - deps/cmt/src/performance_shaders/device.m | 16 - deps/cmt/src/performance_shaders/matrix.m | 59 - deps/cmt/src/reflection/argument.m | 94 - deps/cmt/src/reflection/descriptor.m | 31 - deps/cmt/src/reflection/pointer_type.m | 56 - deps/cmt/src/rendering/depthstencil.m | 20 - deps/cmt/src/rendering/rpass.m | 41 - deps/cmt/src/rendering/rpip.m | 94 - deps/cmt/src/resource.m | 56 - deps/cmt/src/utils/conversion.m | 6 - lib/cmt/cmt.jl | 24 - lib/cmt/libcmt.jl | 2476 ----------------- lib/mps/MPS.jl | 5 +- lib/mps/matrix.jl | 134 +- lib/mtl/MTL.jl | 24 +- lib/mtl/binary_archive.jl | 151 +- lib/mtl/buffer.jl | 117 +- lib/mtl/capture.jl | 199 ++ lib/mtl/command_buf.jl | 288 +- lib/mtl/command_enc.jl | 41 +- lib/mtl/command_enc/blit.jl | 50 +- lib/mtl/command_enc/compute.jl | 85 +- lib/mtl/command_queue.jl | 70 +- lib/mtl/compile-opts.jl | 113 +- lib/mtl/compute_pipeline.jl | 160 +- lib/mtl/compute_pipeline/reflection.jl | 29 - lib/mtl/device.jl | 159 +- lib/mtl/error.jl | 87 - lib/mtl/events.jl | 91 +- lib/mtl/fences.jl | 26 +- lib/mtl/function.jl | 151 +- lib/mtl/heap.jl | 181 +- lib/mtl/helpers.jl | 73 - lib/mtl/library.jl | 108 +- lib/mtl/memory.jl | 38 - lib/mtl/profile.jl | 320 --- lib/mtl/resource.jl | 81 +- lib/mtl/size.jl | 53 +- lib/mtl/storage_type.jl | 52 +- src/Metal.jl | 4 +- src/array.jl | 25 +- src/compiler/execution.jl | 44 +- src/gpuarrays.jl | 6 +- src/initialization.jl | 2 +- src/mapreduce.jl | 2 +- src/memory.jl | 40 +- src/state.jl | 32 +- src/utilities.jl | 12 +- test/Project.toml | 1 + test/array.jl | 8 +- test/execution.jl | 2 +- test/metal.jl | 170 +- test/profiling.jl | 26 +- test/runtests.jl | 1 - test/setup.jl | 2 +- 142 files changed, 1206 insertions(+), 12211 deletions(-) delete mode 100644 deps/build_ci.jl delete mode 100644 deps/build_cmt.jl delete mode 100644 deps/cmt/CMakeLists.txt delete mode 100644 deps/cmt/LICENSE delete mode 100644 deps/cmt/README.md delete mode 100644 deps/cmt/include/cmt/argument_buffer.h delete mode 100644 deps/cmt/include/cmt/argument_descriptor.h delete mode 100644 deps/cmt/include/cmt/argument_encoder.h delete mode 100644 deps/cmt/include/cmt/capture/capture_descriptor.h delete mode 100644 deps/cmt/include/cmt/capture/capture_manager.h delete mode 100644 deps/cmt/include/cmt/capture/capture_scope.h delete mode 100644 deps/cmt/include/cmt/cmt.h delete mode 100644 deps/cmt/include/cmt/command_buf.h delete mode 100644 deps/cmt/include/cmt/command_buf_indirect.h delete mode 100644 deps/cmt/include/cmt/command_enc.h delete mode 100644 deps/cmt/include/cmt/command_enc_blit.h delete mode 100644 deps/cmt/include/cmt/command_enc_compute.h delete mode 100644 deps/cmt/include/cmt/command_enc_render.h delete mode 100644 deps/cmt/include/cmt/command_queue.h delete mode 100644 deps/cmt/include/cmt/common.h delete mode 100644 deps/cmt/include/cmt/common_internal.h delete mode 100644 deps/cmt/include/cmt/compute/compute-pipeline.h delete mode 100644 deps/cmt/include/cmt/device.h delete mode 100644 deps/cmt/include/cmt/enums.h delete mode 100644 deps/cmt/include/cmt/error.h delete mode 100644 deps/cmt/include/cmt/event.h delete mode 100644 deps/cmt/include/cmt/kernels/attribute.h delete mode 100644 deps/cmt/include/cmt/kernels/attribute_vertex.h delete mode 100644 deps/cmt/include/cmt/kernels/binary_archive.h delete mode 100644 deps/cmt/include/cmt/kernels/compile-opts.h delete mode 100644 deps/cmt/include/cmt/kernels/constant_values.h delete mode 100644 deps/cmt/include/cmt/kernels/function.h delete mode 100644 deps/cmt/include/cmt/kernels/library.h delete mode 100644 deps/cmt/include/cmt/macros.h delete mode 100644 deps/cmt/include/cmt/memory/buffer.h delete mode 100644 deps/cmt/include/cmt/memory/heap-descriptor.h delete mode 100644 deps/cmt/include/cmt/memory/heap.h delete mode 100644 deps/cmt/include/cmt/memory/vertex.h delete mode 100644 deps/cmt/include/cmt/performance_shaders/device.h delete mode 100644 deps/cmt/include/cmt/performance_shaders/matrix.h delete mode 100644 deps/cmt/include/cmt/pixelformat.h delete mode 100644 deps/cmt/include/cmt/reflection/argument.h delete mode 100644 deps/cmt/include/cmt/reflection/descriptor.h delete mode 100644 deps/cmt/include/cmt/reflection/pointer_type.h delete mode 100644 deps/cmt/include/cmt/rendering/depthstencil.h delete mode 100644 deps/cmt/include/cmt/rendering/pass.h delete mode 100644 deps/cmt/include/cmt/rendering/pipeline.h delete mode 100644 deps/cmt/include/cmt/resource.h delete mode 100644 deps/cmt/include/cmt/types.h delete mode 100644 deps/cmt/include/cmt/types_foundation.h delete mode 100644 deps/cmt/include/cmt/types_metal.h delete mode 100644 deps/cmt/include/cmt/types_mps.h delete mode 100644 deps/cmt/include/impl/common.h delete mode 100644 deps/cmt/include/impl/conversion.h delete mode 100644 deps/cmt/src/argument_buffer.m delete mode 100644 deps/cmt/src/argument_descriptor.m delete mode 100644 deps/cmt/src/argument_encoder.m delete mode 100644 deps/cmt/src/capture/capture_descriptor.m delete mode 100644 deps/cmt/src/capture/capture_manager.m delete mode 100644 deps/cmt/src/capture/capture_scope.m delete mode 100644 deps/cmt/src/cmt.m delete mode 100644 deps/cmt/src/command_buf.m delete mode 100644 deps/cmt/src/command_buf_indirect.m delete mode 100644 deps/cmt/src/command_enc.m delete mode 100644 deps/cmt/src/command_enc_blit.m delete mode 100644 deps/cmt/src/command_enc_compute.m delete mode 100644 deps/cmt/src/command_enc_render.m delete mode 100644 deps/cmt/src/command_queue.m delete mode 100644 deps/cmt/src/compute/compute-pipeline.m delete mode 100644 deps/cmt/src/device.m delete mode 100644 deps/cmt/src/error.m delete mode 100644 deps/cmt/src/event.m delete mode 100644 deps/cmt/src/kernels/attribute.m delete mode 100644 deps/cmt/src/kernels/attribute_vertex.m delete mode 100644 deps/cmt/src/kernels/binary_archive.m delete mode 100644 deps/cmt/src/kernels/compile-opts.m delete mode 100644 deps/cmt/src/kernels/constant_values.m delete mode 100644 deps/cmt/src/kernels/function.m delete mode 100644 deps/cmt/src/kernels/library.m delete mode 100644 deps/cmt/src/memory/buffer.m delete mode 100644 deps/cmt/src/memory/heap-descriptor.m delete mode 100644 deps/cmt/src/memory/heap.m delete mode 100644 deps/cmt/src/memory/vertex.m delete mode 100644 deps/cmt/src/performance_shaders/device.m delete mode 100644 deps/cmt/src/performance_shaders/matrix.m delete mode 100644 deps/cmt/src/reflection/argument.m delete mode 100644 deps/cmt/src/reflection/descriptor.m delete mode 100644 deps/cmt/src/reflection/pointer_type.m delete mode 100644 deps/cmt/src/rendering/depthstencil.m delete mode 100644 deps/cmt/src/rendering/rpass.m delete mode 100644 deps/cmt/src/rendering/rpip.m delete mode 100644 deps/cmt/src/resource.m delete mode 100644 deps/cmt/src/utils/conversion.m delete mode 100644 lib/cmt/cmt.jl delete mode 100644 lib/cmt/libcmt.jl create mode 100644 lib/mtl/capture.jl delete mode 100644 lib/mtl/compute_pipeline/reflection.jl delete mode 100644 lib/mtl/error.jl delete mode 100644 lib/mtl/helpers.jl delete mode 100644 lib/mtl/memory.jl delete mode 100644 lib/mtl/profile.jl diff --git a/.buildkite/pipeline.yml b/.buildkite/pipeline.yml index 417da1f3..431ca53e 100644 --- a/.buildkite/pipeline.yml +++ b/.buildkite/pipeline.yml @@ -15,8 +15,6 @@ steps: - src - lib - examples - command: | - julia --project=deps deps/build_ci.jl agents: queue: "juliaecosystem" os: "macos" @@ -37,8 +35,6 @@ steps: # - src # - lib # - examples - # command: | - # julia --project=deps deps/build_ci.jl # agents: # queue: "juliaecosystem" # os: "macos" @@ -58,8 +54,6 @@ steps: # - src # - lib # - examples - # command: | - # julia --project=deps deps/build_ci.jl # agents: # queue: "juliaecosystem" # os: "macos" @@ -86,8 +80,6 @@ steps: - src - lib - examples - command: | - julia --project=deps deps/build_ci.jl env: MTL_DEBUG_LAYER: '1' MTL_SHADER_VALIDATION: '1' diff --git a/Manifest.toml b/Manifest.toml index 53679e43..342b0369 100644 --- a/Manifest.toml +++ b/Manifest.toml @@ -2,7 +2,7 @@ julia_version = "1.8.5" manifest_format = "2.0" -project_hash = "97c97a79809f4555c5aae0f6b4c9553a7330505e" +project_hash = "f5746c1a98e06b2349e32c5d2131234120f2cc34" [[deps.Adapt]] deps = ["LinearAlgebra", "Requires"] @@ -143,6 +143,12 @@ version = "2022.2.1" uuid = "ca575930-c2e3-43a9-ace4-1e988b2c1908" version = "1.2.0" +[[deps.ObjectiveC]] +deps = ["CEnum"] +git-tree-sha1 = "5b3c98aacd5429e9c367e551134d9466e40ed6d5" +uuid = "e86c9b32-1129-44ac-8ea0-90d5bb39ded9" +version = "0.1.0" + [[deps.OpenBLAS_jll]] deps = ["Artifacts", "CompilerSupportLibraries_jll", "Libdl"] uuid = "4536629a-c528-5b80-bd46-f80d51c5b363" @@ -228,12 +234,6 @@ deps = ["Libdl"] uuid = "83775a58-1f1d-513f-b197-d71354ab007a" version = "1.2.12+3" -[[deps.cmt_jll]] -deps = ["Artifacts", "JLLWrappers", "Libdl"] -git-tree-sha1 = "049e4965e08ffb1fe62f731c385b92cf62d34817" -uuid = "65323cdd-17ec-5719-9643-72016a7f97e3" -version = "0.2.0+0" - [[deps.libblastrampoline_jll]] deps = ["Artifacts", "Libdl", "OpenBLAS_jll"] uuid = "8e850b90-86db-534c-a0d3-1478176c7d93" diff --git a/Project.toml b/Project.toml index bdeb1280..cb6b133b 100644 --- a/Project.toml +++ b/Project.toml @@ -1,8 +1,6 @@ name = "Metal" uuid = "dde4c033-4e86-420c-a63e-0dd931031962" -authors = ["Filippo Vicentini ", - "Tim Besard ", - "Max Hawkins "] +authors = ["Filippo Vicentini ", "Tim Besard ", "Max Hawkins "] version = "0.2.0" [deps] @@ -14,9 +12,9 @@ GPUCompiler = "61eb1bfa-7361-4325-ad38-22787b887f55" LLVM = "929cbde3-209d-540e-8aea-75f648917ca0" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" Metal_LLVM_Tools_jll = "0418c028-ff8c-56b8-a53e-0f9676ed36fc" +ObjectiveC = "e86c9b32-1129-44ac-8ea0-90d5bb39ded9" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" Reexport = "189a3867-3050-52da-a836-e630ba90ab69" -cmt_jll = "65323cdd-17ec-5719-9643-72016a7f97e3" [compat] Adapt = "3" @@ -24,8 +22,8 @@ CEnum = "0.4" ExprTools = "0.1" GPUArrays = "8.4" GPUCompiler = "0.16, 0.17" -Reexport = "1.0" LLVM = "4.15" Metal_LLVM_Tools_jll = "~0.3" -cmt_jll = "~0.2" +ObjectiveC = "0.1" +Reexport = "1.0" julia = "1.8" diff --git a/README.md b/README.md index f1452d5e..1601795d 100644 --- a/README.md +++ b/README.md @@ -154,61 +154,30 @@ may fail to start. ## Metal API wrapper -Finally, all of the above functionality is made possible by interfacing with -the Metal libraries through a [small C library](https://github.com/JuliaGPU/cmt) -that wraps the ObjectiveC APIs. - -These low-level wrappers, along with some slightly higher-level Julia wrappers, -are available in the `MTL` submodule exported by Metal.jl. All wrapped C -functions and types start with the `mt` prefix, whereas the Julia wrappers are -prefixed with `Mtl`: +Finally, all of the above functionality is made possible by interfacing with the Metal +libraries through [ObjectiveC.jl](https://github.com/JuliaInterop/ObjectiveC.jl). We provide low-level objects and functions that map These +low-level API wrappers, along with some slightly higher-level Julia wrappers, are available +in the `MTL` submodule exported by Metal.jl: ```julia -julia> dev = MtlDevice(1) -MtlDevice: - name: Apple M1 Pro - lowpower: false - headless: false - removable: false - unified memory: true - registry id: 4294969448 - transfer rate: 0 +julia> dev = MTLDevice(1) + + name = Apple M1 Pro julia> dev.name -"Apple M1 Pro" +NSString("Apple M1 Pro") ``` ## Hacking -Metal.jl relies on two binary dependencies (provided as JLLs): - -- [cmt](https://github.com/JuliaGPU/Metal.jl/tree/main/deps/cmt) -- [LLVM with an AIR back-end](https://github.com/JuliaGPU/llvm-metal) - -Normally, these dependencies are built on -[Yggdrasil](https://github.com/JuliaPackaging/Yggdrasil/). -If you need to make changes to these dependencies, have a look at the -`build_cmt.jl` and `build_llvm.jl` scripts in the `deps/` folder. These -scripts build a local version of the dependency, and configure a local -preference such that any environment depending on the corresponding JLLs will -pick-up the modified version (i.e., do `julia --project` in a clone -of `Metal.jl`): - -``` -$ julia --project -e 'using Metal; @show MTL.cmt.libcmt' -MTL.libcmt = "/Users/tim/Julia/depot/artifacts/6adc0ed9a8370ff1e3bb8fbaf36e8519ee11fd96/lib/libcmt.dylib" - -$ julia --project=deps deps/build_cmt.jl -... -[100%] Built target cmt - -$ julia --project -e 'using Metal; @show MTL.cmt.libcmt' -MTL.libcmt = "/Users/tim/Julia/depot/scratchspaces/dde4c033-4e86-420c-a63e-0dd931031962/cmt/lib/libcmt.dylib" -``` - -These scripts are integrated with our CI, and will be triggered if -the `ci.build_cmt` or `ci.build_llvm` labels are set on a pull request. +Metal.jl relies on a custom [LLVM with an AIR +back-end](https://github.com/JuliaGPU/llvm-metal), provided as a JLL. Normally, this JLLis +built on [Yggdrasil](https://github.com/JuliaPackaging/Yggdrasil/). If you need to make +changes to the LLVM back-end, have a look at the `build_llvm.jl` in the `deps/` folder. This +scripts builds a local version of the LLVM back-end, and configures a local preference such +that any environment depending on the corresponding JLLs will pick-up the modified version +(i.e., do `julia --project` in a clone of `Metal.jl`). ## Acknowledgements diff --git a/deps/build_ci.jl b/deps/build_ci.jl deleted file mode 100644 index a9f77f55..00000000 --- a/deps/build_ci.jl +++ /dev/null @@ -1,54 +0,0 @@ -using Pkg -Pkg.activate(@__DIR__) -Pkg.instantiate() - -using Git, Scratch, Dates - -Metal = Base.UUID("dde4c033-4e86-420c-a63e-0dd931031962") - -# get scratch directories -support_dir = get_scratch!(Metal, "support") - -# is this a full-fledged check-out? -if isdir(joinpath(@__DIR__), "..", ".git") - # determine latest change to the wrappers - deps_timestamp = parse(Int, read(`$(git()) -C $(@__DIR__) log -1 --format=%ct cmt`, String)) - @info "Latest change to the wrappers: $(unix2datetime(deps_timestamp))" - - # find out which version of cmt_jll we are using - Pkg.activate(joinpath(@__DIR__, "..")) - deps = collect(values(Pkg.dependencies())) - filter!(deps) do dep - dep.name == "cmt_jll" - end - library_version = only(deps).version - @info "cmt_jll version: $(library_version)" - - # compare to the JLL's tags - jll_tags = mktempdir() do dir - if !isdir(joinpath(support_dir, ".git")) - run(`$(git()) clone -q https://github.com/JuliaBinaryWrappers/cmt_jll.jl $dir`) - else - run(`$(git()) -C $dir fetch -q`) - end - tags = Dict{String,Int}() - for line in eachline(`$(git()) -C $dir tag --format "%(refname:short) %(creatordate:unix)"`) - tag, timestamp = split(line) - tags[tag] = parse(Int, timestamp) - end - tags - end - jll_timestamp = jll_tags["cmt-v$(library_version)"] - @info "cmt_jll timestamp: $(unix2datetime(jll_timestamp))" - - if deps_timestamp > jll_timestamp - @info "Wrappers have changed since the last JLL build. Building the support library locally." - include(joinpath(@__DIR__, "build_cmt.jl")) - else - @info "Wrappers have not changed since the last JLL build. Using the JLL's support library." - end -else - @warn """Metal.jl source code is not checked-out from Git. - This means we cannot check for changes, and need to unconditionally build the support library.""" - include(joinpath(@__DIR__, "build_cmt.jl")) -end diff --git a/deps/build_cmt.jl b/deps/build_cmt.jl deleted file mode 100644 index 0b10e54c..00000000 --- a/deps/build_cmt.jl +++ /dev/null @@ -1,58 +0,0 @@ -# build cmt locally - -using Pkg -Pkg.activate(@__DIR__) -Pkg.instantiate() - -if haskey(ENV, "BUILDKITE") - run(`buildkite-agent annotate 'Using a locally-built cmt library; A bump of cmt_jll will be required before releasing Metal.jl.' --style 'warning' --context 'ctx-deps'`) -end - -using Scratch, CMake_jll, Ninja_jll, Libdl, Preferences - -Metal = Base.UUID("dde4c033-4e86-420c-a63e-0dd931031962") - -# get a scratch directory -scratch_dir = get_scratch!(Metal, "cmt") -isdir(scratch_dir) && rm(scratch_dir; recursive=true) -source_dir = joinpath(@__DIR__, "cmt") - -# get build directory -build_dir = if isempty(ARGS) - mktempdir() -else - ARGS[1] -end -mkpath(build_dir) - -# build and install -cmake() do cmake_path -ninja() do ninja_path - run(```$cmake_path -GNinja - -DCMAKE_BUILD_TYPE=Debug - -DCMAKE_INSTALL_PREFIX=$(scratch_dir) - -DCMAKE_COLOR_DIAGNOSTICS=$(get(stdout, :color, false) ? "On" : "Off") - -B$(build_dir) -S$(source_dir)```) - run(`$cmake --build $(build_dir) --parallel $(Sys.CPU_THREADS)`) - run(`$ninja_path -C $(build_dir) install`) -end -end - -# Discover built libraries -built_libs = filter(readdir(joinpath(scratch_dir, "lib"))) do file - endswith(file, ".$(Libdl.dlext)") -end -lib_path = joinpath(scratch_dir, "lib", only(built_libs)) -isfile(lib_path) || error("Could not find library $lib_path in build directory") - -# Tell cmt_jll to load our library instead of the default artifact one -set_preferences!( - joinpath(dirname(@__DIR__), "LocalPreferences.toml"), - "cmt_jll", - "libcmt_path" => lib_path; - force=true, -) - -# Copy the preferences to `test/` as well to work around Pkg.jl#2500 -cp(joinpath(dirname(@__DIR__), "LocalPreferences.toml"), - joinpath(dirname(@__DIR__), "test", "LocalPreferences.toml"); force=true) diff --git a/deps/cmt/CMakeLists.txt b/deps/cmt/CMakeLists.txt deleted file mode 100644 index c3c700be..00000000 --- a/deps/cmt/CMakeLists.txt +++ /dev/null @@ -1,88 +0,0 @@ -cmake_minimum_required(VERSION 3.9) - -project(cmt VERSION 1.0.1 DESCRIPTION "C Metal Wrapper" - LANGUAGES C OBJC) - -find_library(FOUNDATION_LIBRARY Foundation) -find_library(METAL_LIBRARY Metal) -find_library(MPS_LIBRARY MetalPerformanceShaders) - -# with debug builds, invoke dsymutil to generate separate debug info. -# this needs to be done when object files are available -# to extract the debug info from. -if ((CMAKE_BUILD_TYPE MATCHES Debug) OR (CMAKE_BUILD_TYPE MATCHES RelWithDebInfo)) - find_program(DSYMUTIL_PROGRAM dsymutil) - if (DSYMUTIL_PROGRAM) - foreach(lang C CXX OBJC) - foreach(var LINK_EXECUTABLE CREATE_SHARED_LIBRARY) - set(CMAKE_${lang}_${var} "${CMAKE_${lang}_${var}}" "${DSYMUTIL_PROGRAM} ") - endforeach() - endforeach() - endif() -endif() - -set(SOURCES - src/reflection/argument.m - src/reflection/pointer_type.m - src/reflection/descriptor.m - src/compute/compute-pipeline.m - src/kernels/attribute.m - src/kernels/attribute_vertex.m - src/kernels/constant_values.m - src/kernels/compile-opts.m - src/kernels/function.m - src/kernels/library.m - src/kernels/binary_archive.m - src/memory/buffer.m - src/memory/heap-descriptor.m - src/memory/heap.m - src/memory/vertex.m - src/rendering/depthstencil.m - src/rendering/rpass.m - src/rendering/rpip.m - src/utils/conversion.m - src/argument_descriptor.m - src/argument_encoder.m - src/cmt.m - src/command_buf.m - src/command_buf_indirect.m - src/command_queue.m - src/command_enc.m - src/command_enc_render.m - src/command_enc_compute.m - src/command_enc_blit.m - src/device.m - src/error.m - src/event.m - src/resource.m - src/capture/capture_descriptor.m - src/capture/capture_manager.m - src/capture/capture_scope.m - src/performance_shaders/device.m - src/performance_shaders/matrix.m) - -add_library(cmt SHARED ${SOURCES}) - -target_include_directories(cmt PRIVATE .) -target_include_directories(cmt PRIVATE include/) -target_include_directories(cmt INTERFACE include/) - -set_target_properties(cmt PROPERTIES - VERSION ${PROJECT_VERSION} - SOVERSION 1 - PUBLIC_HEADER include/cmt/cmt.h) - -target_link_libraries(cmt ${FOUNDATION_LIBRARY} ${METAL_LIBRARY} ${MPS_LIBRARY}) - -# libcmt uses Manual-Retain-Release and not ARC -target_compile_options(cmt PRIVATE -fno-objc-arc) - -install(TARGETS cmt - LIBRARY DESTINATION lib - PUBLIC_HEADER DESTINATION include) - -# XXX: can we add the dSYM to the target instead of copying it to the prefix ourselve? -if ((CMAKE_BUILD_TYPE MATCHES Debug) OR (CMAKE_BUILD_TYPE MATCHES RelWithDebInfo)) - install(DIRECTORY ${CMAKE_BINARY_DIR}/libcmt.dylib.dSYM - DESTINATION ${CMAKE_INSTALL_PREFIX}/lib) -endif() diff --git a/deps/cmt/LICENSE b/deps/cmt/LICENSE deleted file mode 100644 index f042fb1d..00000000 --- a/deps/cmt/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2018 Recep Aslantas - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/deps/cmt/README.md b/deps/cmt/README.md deleted file mode 100644 index 54a0abff..00000000 --- a/deps/cmt/README.md +++ /dev/null @@ -1,42 +0,0 @@ -# Apple's Metal for `C` - -C Wrapper for Apple's METAL framework. This library is C bindings of Metal API (MetalGL). - -This started as a fork of [rcp/cmt](https://github.com/recp/cmt), with the aim of wrapping Metal in Julia, but at the time of writing is more complete. - -The graphics-related part of the API are not very developed. At the moment mostly functionality related to computing is wrapped. - -Currently this library does not alloc memory for its types. It retains ObjC objects and work on them. This also makes the library very very thin layer on ObjC. - -## Building and linking - -A CMake project is included that builds a shared library. The headers for that library are contained in `include/cmt`, and are bare-C. - - -```C - -MtDevice *device; -MtCommandQueue *cmdQueue; -MtRenderPipelineDescriptor *pipDesc; -MtLibrary *lib; -MtFunction *vertFunc, *fragFunc; -MtRenderPipelineState *pip; - -device = mtCreateDevice(); -lib = mtDefaultLibrary(device); -cmdQueue = mtCommandQueueCreate(device); -pipDesc = mtRenderDescCreate(MtPixelFormatBGRA8Unorm); - -vertFunc = mtCreateFunc(lib, "vertexShader"); -fragFunc = mtCreateFunc(lib, "fragmentShader"); - -mtSetFunc(pipDesc, vertFunc, MT_FUNC_VERT); -mtSetFunc(pipDesc, fragFunc, MT_FUNC_FRAG); - -pip = mtRenderStateCreate(device, pipDesc); - -``` - -### Trademarks - -Apple name/logo and Metal are trademarks of Apple Inc. This software only provides C bindings for Metal, it is not alternative to Metal. diff --git a/deps/cmt/include/cmt/argument_buffer.h b/deps/cmt/include/cmt/argument_buffer.h deleted file mode 100644 index ac5ea3c9..00000000 --- a/deps/cmt/include/cmt/argument_buffer.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c), Recep Aslantas. - * MIT License (MIT), http://opensource.org/licenses/MIT - */ - -#ifndef cmt_argument_buffer_h -#define cmt_argument_buffer_h -#ifdef __cplusplus -extern "C" { -#endif - -#include "cmt/common.h" -#include "cmt/types.h" -#include "cmt/enums.h" -#include "cmt/resource.h" - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -MtArgumentDescriptor* -mtNewArgumentDescriptor(void); - -#ifdef __cplusplus -} -#endif -#endif /* cmt_argument_buffer_h */ diff --git a/deps/cmt/include/cmt/argument_descriptor.h b/deps/cmt/include/cmt/argument_descriptor.h deleted file mode 100644 index 4fa74348..00000000 --- a/deps/cmt/include/cmt/argument_descriptor.h +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright (c), Recep Aslantas. - * MIT License (MIT), http://opensource.org/licenses/MIT - */ - -#ifndef cmt_argument_descriptor_h -#define cmt_argument_descriptor_h -#ifdef __cplusplus -extern "C" { -#endif - -#include "cmt/common.h" -#include "cmt/types.h" -#include "cmt/enums.h" -#include "cmt/resource.h" - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -MtArgumentDescriptor* -mtNewArgumentDescriptor(void); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -MtDataType -mtArgumentDescriptorDataType(MtArgumentDescriptor *desc); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -void -mtArgumentDescriptorDataTypeSet(MtArgumentDescriptor *desc, MtDataType dataType); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -NsUInteger -mtArgumentDescriptorIndex(MtArgumentDescriptor *desc); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -void -mtArgumentDescriptorIndexSet(MtArgumentDescriptor *desc, NsUInteger index); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -MtArgumentAccess -mtArgumentDescriptorAccess(MtArgumentDescriptor *desc); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -void -mtArgumentDescriptorAccessSet(MtArgumentDescriptor *desc, MtArgumentAccess access); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -NsUInteger -mtArgumentDescriptorArrayLength(MtArgumentDescriptor *desc); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -void -mtArgumentDescriptorArrayLengthSet(MtArgumentDescriptor *desc, NsUInteger length); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -NsUInteger -mtArgumentDescriptorConstantBlockAlignment(MtArgumentDescriptor *desc); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -void -mtArgumentDescriptorConstantBlockAlignmentSet(MtArgumentDescriptor *desc, NsUInteger alignment); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -MtTextureType -mtArgumentDescriptorTextureType(MtArgumentDescriptor *desc); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -void -mtArgumentDescriptorTextureTypeSet(MtArgumentDescriptor *desc, MtTextureType textype); - -#ifdef __cplusplus -} -#endif -#endif /* cmt_argument_descriptor_h */ diff --git a/deps/cmt/include/cmt/argument_encoder.h b/deps/cmt/include/cmt/argument_encoder.h deleted file mode 100644 index a8ac69b2..00000000 --- a/deps/cmt/include/cmt/argument_encoder.h +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright (c), Recep Aslantas. - * MIT License (MIT), http://opensource.org/licenses/MIT - */ - -#ifndef cmt_argument_encoder_h -#define cmt_argument_encoder_h -#ifdef __cplusplus -extern "C" { -#endif - -#include "cmt/common.h" -#include "cmt/types.h" -#include "cmt/enums.h" -#include "cmt/resource.h" - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -MtArgumentEncoder* -mtNewArgumentEncoderWithBufferIndexFromFunction(MtFunction *function, NsUInteger bufferIndex); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -MtArgumentEncoder* -mtNewArgumentEncoderWithBufferIndexReflectionFromFunction(MtFunction *function, NsUInteger bufferIndex, MtAutoreleasedArgument *reflection); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -MtArgumentEncoder* -mtNewArgumentEncoderWithBufferIndexFromArgumentBuffer(MtArgumentEncoder *ae, NsUInteger bufferIndex); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -MtArgumentEncoder* -mtNewArgumentEncoder(MtDevice *device, MtArgumentDescriptor **arguments, uint64_t count); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -NsUInteger -mtArgumentEncoderLength(MtArgumentEncoder *encoder); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -void -mtArgumentEncoderSetArgumentBufferWithOffset(MtArgumentEncoder *cce, MtBuffer *buf, NsUInteger offset); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -void -mtArgumentEncoderSetArgumentBufferWithOffsetForElement(MtArgumentEncoder *cce, MtBuffer *buf, NsUInteger startOffset, NsUInteger arrayElement); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -void -mtArgumentEncoderSetBufferOffsetAtIndex(MtArgumentEncoder *cce, MtBuffer *buf, NsUInteger offset, NsUInteger indx); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -void -mtArgumentEncoderSetBuffersOffsetsWithRange(MtArgumentEncoder *cce, MtBuffer **bufs, const NsUInteger *offsets, NsRange range); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -void -mtArgumentEncoderSetTextureAtIndex(MtArgumentEncoder *cce, MtTexture *tex, NsUInteger indx); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -void -mtArgumentEncoderSetTexturesWithRange(MtArgumentEncoder *cce, MtTexture **textures, NsRange range); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -void -mtArgumentEncoderSetSamplerStateAtIndex(MtArgumentEncoder *cce, MtSamplerState *sampler, NsUInteger indx); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -void -mtArgumentEncoderSetSamplerStatesWithRange(MtArgumentEncoder *cce, MtSamplerState **samplers, NsRange range); - -/*MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -void -mtArgumentEncoderSetComputePipelineState(MtArgumentEncoder *cce, MtComputePipelineState *state, NsUInteger index); -IOS */ - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -void* -mtArgumentEncoderConstantDataAtIndex(MtArgumentEncoder *cce, NsUInteger index); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.14), mt_ios(12.0)) -void -mtArgumentEncoderSetIndirectCommandBuffer(MtArgumentEncoder *cce, MtIndirectCommandBuffer *cbuf, NsUInteger index); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.14), mt_ios(12.0)) -void -mtArgumentEncoderSetIndirectCommandBuffers(MtArgumentEncoder *cce, MtIndirectCommandBuffer **cbufs, NsRange range); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -NsUInteger -mtArgumentEncoderAlignment(MtArgumentEncoder *cce); - -#ifdef __cplusplus -} -#endif -#endif /* cmt_argument_encoder_h */ diff --git a/deps/cmt/include/cmt/capture/capture_descriptor.h b/deps/cmt/include/cmt/capture/capture_descriptor.h deleted file mode 100644 index 9f446cc0..00000000 --- a/deps/cmt/include/cmt/capture/capture_descriptor.h +++ /dev/null @@ -1,60 +0,0 @@ -#ifndef cmt_capture_descriptor_h -#define cmt_capture_descriptor_h -#ifdef __cplusplus -extern "C" { -#endif - -#include "cmt/common.h" -#include "cmt/types.h" -#include "cmt/enums.h" -#include "cmt/resource.h" - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.15), mt_ios(13.0)) -MtCaptureDescriptor* -mtNewCaptureDescriptor(void); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.15), mt_ios(13.0)) -void* -mtCaptureDescriptorCaptureObject(MtCaptureDescriptor *desc); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.15), mt_ios(13.0)) -void -mtCaptureDescriptorCaptureObjectSetQueue(MtCaptureDescriptor *desc, MtCommandQueue *cmdq); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.15), mt_ios(13.0)) -void -mtCaptureDescriptorCaptureObjectSetDevice(MtCaptureDescriptor *desc, MtDevice *dev); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.15), mt_ios(13.0)) -void -mtCaptureDescriptorCaptureObjectSetScope(MtCaptureDescriptor *desc, MtCaptureScope *scope); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.15), mt_ios(13.0)) -MtCaptureDestination -mtCaptureDescriptorDestination(MtCaptureDescriptor *desc); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.15), mt_ios(13.0)) -void -mtCaptureDescriptorDestinationSet(MtCaptureDescriptor *desc, MtCaptureDestination dest); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.15), mt_ios(13.0)) -void -mtCaptureDescriptorOutputURLSet(MtCaptureDescriptor *desc, const char *path); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.15), mt_ios(13.0)) -const char* -mtCaptureDescriptorOutputURL(MtCaptureDescriptor *desc); - -#ifdef __cplusplus -} -#endif -#endif \ No newline at end of file diff --git a/deps/cmt/include/cmt/capture/capture_manager.h b/deps/cmt/include/cmt/capture/capture_manager.h deleted file mode 100644 index 4dc4bf47..00000000 --- a/deps/cmt/include/cmt/capture/capture_manager.h +++ /dev/null @@ -1,50 +0,0 @@ -#ifndef cmt_capture_manager_h -#define cmt_capture_manager_h -#ifdef __cplusplus -extern "C" { -#endif - -#include "cmt/common.h" -#include "cmt/types.h" -#include "cmt/enums.h" -#include "cmt/resource.h" - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -MtCaptureManager* -mtSharedCaptureManager(void); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -bool -mtSupportsDestination(MtCaptureManager *manager, MtCaptureDestination destination); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -bool -mtStartCaptureWithDescriptor(MtCaptureManager *manager, MtCaptureDescriptor *descriptor, NsError **error); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -void -mtStopCapture(MtCaptureManager *manager); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -bool -mtIsCapturing(MtCaptureManager *manager); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -MtCaptureScope* -mtDefaultCaptureScope(MtCaptureManager *manager); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -void -mtDefaultCaptureScopeSet(MtCaptureManager *manager, MtCaptureScope *scope); - -#ifdef __cplusplus -} -#endif -#endif \ No newline at end of file diff --git a/deps/cmt/include/cmt/capture/capture_scope.h b/deps/cmt/include/cmt/capture/capture_scope.h deleted file mode 100644 index e75ded6a..00000000 --- a/deps/cmt/include/cmt/capture/capture_scope.h +++ /dev/null @@ -1,50 +0,0 @@ -#ifndef cmt_capture_scope_h -#define cmt_capture_scope_h -#ifdef __cplusplus -extern "C" { -#endif - -#include "cmt/common.h" -#include "cmt/types.h" -#include "cmt/enums.h" -#include "cmt/resource.h" - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -MtCaptureScope* -mtNewCaptureScopeWithCommandQueue(MtCaptureManager *manager, MtCommandQueue *queue); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -void -mtBeginScope(MtCaptureScope *scope); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -void -mtEndScope(MtCaptureScope *scope); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -const char* -mtCaptureScopeLabel(MtCaptureScope *scope); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -void -mtCaptureScopeLabelSet(MtCaptureScope *scope, const char* label); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -MtDevice* -mtCaptureScopeDevice(MtCaptureScope *scope); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -MtCommandQueue* -mtCaptureScopeCommandQueue(MtCaptureScope *scope); - -#ifdef __cplusplus -} -#endif -#endif \ No newline at end of file diff --git a/deps/cmt/include/cmt/cmt.h b/deps/cmt/include/cmt/cmt.h deleted file mode 100644 index d3bf6658..00000000 --- a/deps/cmt/include/cmt/cmt.h +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (c), Recep Aslantas. - * MIT License (MIT), http://opensource.org/licenses/MIT - */ - -#ifndef cmt_h -#define cmt_h -#ifdef __cplusplus -extern "C" { -#endif - -#include "macros.h" -#include "common.h" - -#include "types.h" -#include "enums.h" -#include "error.h" -#include "pixelformat.h" - -#include "event.h" -#include "resource.h" -#include "device.h" - -#include "compute/compute-pipeline.h" - -#include "kernels/attribute.h" -#include "kernels/attribute_vertex.h" -#include "kernels/compile-opts.h" -#include "kernels/constant_values.h" -#include "kernels/function.h" -#include "kernels/library.h" -#include "kernels/binary_archive.h" - -#include "memory/buffer.h" -#include "memory/heap-descriptor.h" -#include "memory/heap.h" -#include "memory/vertex.h" - -#include "rendering/depthstencil.h" -#include "rendering/pass.h" -#include "rendering/pipeline.h" - -#include "reflection/argument.h" -#include "reflection/descriptor.h" -#include "reflection/pointer_type.h" - -#include "command_buf.h" -#include "command_buf_indirect.h" - -#include "command_enc.h" -#include "command_enc_blit.h" -#include "command_enc_compute.h" -#include "command_enc_render.h" - -#include "command_queue.h" - -#include "argument_descriptor.h" -#include "argument_encoder.h" - -#include "capture/capture_descriptor.h" -#include "capture/capture_manager.h" -#include "capture/capture_scope.h" - -#include "performance_shaders/device.h" -#include "performance_shaders/matrix.h" - -MT_EXPORT -void* -mtRetain(void *obj); - -MT_EXPORT -void -mtRelease(void *obj); - -#ifdef __cplusplus -} -#endif -#endif /* cmt_h */ diff --git a/deps/cmt/include/cmt/command_buf.h b/deps/cmt/include/cmt/command_buf.h deleted file mode 100644 index dc2600e7..00000000 --- a/deps/cmt/include/cmt/command_buf.h +++ /dev/null @@ -1,203 +0,0 @@ -/* - * Copyright (c), Recep Aslantas. - * MIT License (MIT), http://opensource.org/licenses/MIT - */ - -#ifndef cmt_commandbuff_h -#define cmt_commandbuff_h -#ifdef __cplusplus -extern "C" { -#endif - -#include "common.h" -#include "types.h" -#include "enums.h" - -typedef void (*MtCommandBufferOnCompletedFn)(void * __restrict data); - -typedef void (*MtCommandBufferOnScheduledFn)(void * __restrict data); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -MtCommandBufferDescriptor* -mtNewCommandBufferDescriptor(void); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -bool -mtCommandBufferDescriptorRetainedReferences(MtCommandBufferDescriptor *desc); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtCommandBufferDescriptorRetainedReferencesSet(MtCommandBufferDescriptor *desc, bool retain); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -NsUInteger -mtCommandBufferDescriptorErrorOptions(MtCommandBufferDescriptor *desc); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtCommandBufferDescriptorErrorOptionsSet(MtCommandBufferDescriptor *desc, NsUInteger errorOption); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -MtCommandBuffer* -mtNewCommandBuffer(MtCommandQueue *cmdq); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -MtCommandBuffer* -mtNewCommandBufferWithDescriptor(MtCommandQueue *cmdq, MtCommandBufferDescriptor *desc); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -MtCommandBuffer* -mtNewCommandBufferWithUnretainedReferences(MtCommandQueue *cmdq); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtCommandBufferOnCompleted(MtCommandBuffer * __restrict cmdb, - void * __restrict data, - MtCommandBufferOnCompletedFn fn); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtCommandBufferOnScheduled(MtCommandBuffer * __restrict cmdb, - void * __restrict data, - MtCommandBufferOnScheduledFn fn); - -MT_EXPORT -void -mtCommandBufferPresentDrawable(MtCommandBuffer *cmdb, - MtDrawable *drawable); - -/*MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -MtResourceStateCommandEncoder* -mtNewResourceStateCommandEncoder(MtCommandBuffer *cmdb); IOS 13*/ - -// Scheduling and Executing Commands - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtCommandBufferEnqueue(MtCommandBuffer *cmdb); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtCommandBufferCommit(MtCommandBuffer *cmdb); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtCommandBufferAddScheduledHandler(MtCommandBuffer *cmdb, MtCommandBufferHandlerFun handler); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtCommandBufferAddCompletedHandler(MtCommandBuffer *cmdb, MtCommandBufferHandlerFun handler); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtCommandBufferWaitUntilScheduled(MtCommandBuffer *cmdb); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtCommandBufferWaitUntilCompleted(MtCommandBuffer *cmdb); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -MtCommandBufferStatus -mtCommandBufferStatus(MtCommandBuffer *cmdb); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -MtCommandBufferErrorOption -mtCommandBufferErrorOptions(MtCommandBuffer *cmdb); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -NsError* -mtCommandBufferError(MtCommandBuffer *cmdb); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.15), mt_ios(13.0)) -CfTimeInterval -mtCommandBufferKernelStartTime(MtCommandBuffer *cmdb); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.15), mt_ios(13.0)) -CfTimeInterval -mtCommandBufferKernelEndTime(MtCommandBuffer *cmdb); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.15), mt_ios(13.0)) -CfTimeInterval -mtCommandBufferGPUStartTime(MtCommandBuffer *cmdb); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.15), mt_ios(13.0)) -CfTimeInterval -mtCommandBufferGPUEndTime(MtCommandBuffer *cmdb); - -// Events -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.15), mt_ios(13.0)) -void -mtCommandBufferEncodeSignalEvent(MtCommandBuffer *cmdb, MtEvent *event, uint64_t val); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.15), mt_ios(13.0)) -void -mtCommandBufferEncodeWaitForEvent(MtCommandBuffer *cmdb, MtEvent *event, uint64_t val); - -// retained references ? -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -bool -mtCommandBufferRetainedReferences(MtCommandBuffer *cmdb); - -// identifying -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -MtDevice* -mtCommandBufferDevice(MtCommandBuffer *cmdb); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -MtCommandQueue* -mtCommandBufferCommandQueue(MtCommandBuffer *cmdb); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -const char* -mtCommandBufferLabel(MtCommandBuffer *cmdb); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtCommandBufferLabelSet(MtCommandBuffer *cmdb, const char* label); - -// debug -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -void -mtCommandBufferPushDebugGroup(MtCommandBuffer *cmdb, char* str); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -void -mtCommandBufferPopDebugGroup(MtCommandBuffer *cmdb); - -#ifdef __cplusplus -} -#endif -#endif /* cmt_commandbuff_h */ diff --git a/deps/cmt/include/cmt/command_buf_indirect.h b/deps/cmt/include/cmt/command_buf_indirect.h deleted file mode 100644 index 232f3a34..00000000 --- a/deps/cmt/include/cmt/command_buf_indirect.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c), Recep Aslantas. - * MIT License (MIT), http://opensource.org/licenses/MIT - */ - -#ifndef cmt_indirect_comm_buff_h -#define cmt_indirect_comm_buff_h -#ifdef __cplusplus -extern "C" { -#endif - -#include "cmt/common.h" -#include "cmt/types.h" -#include "cmt/enums.h" -#include "cmt/resource.h" - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.14), mt_ios(12.0)) -MtIndirectCommandBuffer* -mtNewIndirectCommandBuffer(MtDevice *device, MtIndirectCommandBufferDescriptor *desc, - NsUInteger maxCount, MtResourceOptions options); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -NsUInteger -mtIndirectCommandBufferSize(MtIndirectCommandBuffer *icb); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -MtIndirectComputeCommand* -mtIndirectCommandBufferComputeCommandAtIndex(MtIndirectCommandBuffer *icb, - NsUInteger index); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -MtIndirectRenderCommand* -mtIndirectCommandBufferRenderCommandAtIndex(MtIndirectCommandBuffer *icb, - NsUInteger index); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtIndirectCommandBufferResetWithRange(MtIndirectCommandBuffer *icb, NsRange range); - -#ifdef __cplusplus -} -#endif -#endif /* cmt_indirect_comm_buff_h */ diff --git a/deps/cmt/include/cmt/command_enc.h b/deps/cmt/include/cmt/command_enc.h deleted file mode 100644 index 227b5899..00000000 --- a/deps/cmt/include/cmt/command_enc.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c), Recep Aslantas. - * MIT License (MIT), http://opensource.org/licenses/MIT - */ - -#ifndef cmt_commandenc_h -#define cmt_commandenc_h -#ifdef __cplusplus -extern "C" { -#endif - -#include "cmt/common.h" -#include "cmt/types.h" -#include "cmt/enums.h" - -MT_EXPORT -void -mtCommandEncoderEndEncoding(MtCommandEncoder *ce); - -MT_EXPORT -MtDevice* -mtCommandEncoderDevice(MtCommandEncoder *ce); - -MT_EXPORT -const char* -mtCommandEncoderLabel(MtCommandEncoder *ce); - -MT_EXPORT -void -mtCommandEncoderLabelSet(MtCommandEncoder *ce, const char* label); - -MT_EXPORT -void -mtCommandEncoderInsertDebugSignpost(MtCommandEncoder *ce, char* string); - -MT_EXPORT -void -mtCommandEncoderPushDebugGroup(MtCommandEncoder *ce, char* string); - -MT_EXPORT -void -mtCommandEncoderPopDebugGroup(MtCommandEncoder *ce); - -#ifdef __cplusplus -} -#endif -#endif /* cmt_commandenc_h */ diff --git a/deps/cmt/include/cmt/command_enc_blit.h b/deps/cmt/include/cmt/command_enc_blit.h deleted file mode 100644 index b165f9f0..00000000 --- a/deps/cmt/include/cmt/command_enc_blit.h +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Copyright (c), Recep Aslantas. - * MIT License (MIT), http://opensource.org/licenses/MIT - */ - -#ifndef cmt_command_enc_blit_h -#define cmt_command_enc_blit_h -#ifdef __cplusplus -extern "C" { -#endif - -#include "cmt/common.h" -#include "cmt/types.h" -#include "cmt/enums.h" - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -MtBlitCommandEncoder* -mtNewBlitCommandEncoder(MtCommandBuffer *cmdb); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtBlitCommandEncoderCopyFromBufferToBuffer(MtBlitCommandEncoder *bce, - MtBuffer *src, NsUInteger src_offset, - MtBuffer *dst, NsUInteger dst_offset, - NsUInteger size); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtBlitCommandEncoderFillBuffer(MtBlitCommandEncoder *bce, - MtBuffer *src, NsRange range, uint8_t val); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtBlitCommandEncoderGenerateMipmaps(MtBlitCommandEncoder *bce, - MtTexture *texture); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.14), mt_ios(12.0)) -void -mtBlitCommandEncoderCopyIndirectCommandBuffer(MtBlitCommandEncoder *bce, - MtIndirectCommandBuffer *src, NsRange range, - MtIndirectCommandBuffer *dst, NsUInteger dst_index); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.14), mt_ios(12.0)) -void -mtBlitCommandEncoderOptimizeIndirectCommandBuffer(MtBlitCommandEncoder *bce, - MtIndirectCommandBuffer *buffer, NsRange range); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.14), mt_ios(12.0)) -void -mtBlitCommandEncoderResetCommandsInBuffer(MtBlitCommandEncoder *bce, - MtIndirectCommandBuffer *buffer, NsRange range); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtBlitCommandEncoderSynchronizeResource(MtBlitCommandEncoder *bce, - MtResource *resource); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtBlitCommandEncoderSynchronizeTexture(MtBlitCommandEncoder *bce, - MtTexture *texture, NsUInteger slice, NsUInteger level); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(10.0)) -void -mtBlitCommandEncoderUpdateFence(MtIndirectCommandBuffer *icb, MtFence *fence); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(10.0)) -void -mtBlitCommandEncoderWaitForFence(MtIndirectCommandBuffer *icb, MtFence *fence); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.14), mt_ios(12.0)) -void -mtBlitCommandEncoderOptimizeContentsForGPUAccess(MtIndirectCommandBuffer *icb, - MtTexture *tex); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.14), mt_ios(12.0)) -void -mtBlitCommandEncoderOptimizeContentsForGPUAccessSliceLevel(MtIndirectCommandBuffer *icb, - MtTexture *tex, NsUInteger slice, NsUInteger level); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.14), mt_ios(12.0)) -void -mtBlitCommandEncoderOptimizeContentsForCPUAccess(MtIndirectCommandBuffer *icb, - MtTexture *tex); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.14), mt_ios(12.0)) -void -mtBlitCommandEncoderOptimizeContentsForCPUAccessSliceLevel(MtIndirectCommandBuffer *icb, - MtTexture *tex, NsUInteger slice, NsUInteger level); - -// GPU Execution data -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.15)) -MT_API_UNAVAILABLE(mt_ios) -void -mtBlitCommandEncoderSampleCountersInBuffer(MtIndirectCommandBuffer *icb, - MtCounterSampleBuffer *sbuf, - NsUInteger sampleindex, - bool barrier); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.15)) -MT_API_UNAVAILABLE(mt_ios) -void -mtBlitCommandEncoderResolveCounters(MtIndirectCommandBuffer *icb, - MtCounterSampleBuffer *sbuf, - NsRange range, - MtBuffer *dst, - NsUInteger dst_offset); - -#ifdef __cplusplus -} -#endif -#endif /* cmt_command_enc_blit_h */ diff --git a/deps/cmt/include/cmt/command_enc_compute.h b/deps/cmt/include/cmt/command_enc_compute.h deleted file mode 100644 index 1e7f502b..00000000 --- a/deps/cmt/include/cmt/command_enc_compute.h +++ /dev/null @@ -1,166 +0,0 @@ -/* - * Copyright (c), Recep Aslantas. - * MIT License (MIT), http://opensource.org/licenses/MIT - */ - -#ifndef cmt_command_enc_compute_h -#define cmt_command_enc_compute_h -#ifdef __cplusplus -extern "C" { -#endif - -#include "cmt/common.h" -#include "cmt/types.h" -#include "cmt/enums.h" - -// Creating Command Encoders -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -MtComputeCommandEncoder* -mtNewComputeCommandEncoder(MtCommandBuffer *cmdb); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.14), mt_ios(12.0)) -MtComputeCommandEncoder* -mtNewComputeCommandEncoderWithDispatchType(MtCommandBuffer *cmdb, MtDispatchType dtype); - -// Could be removed because in base class -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtComputeCommandEncoderEndEncoding(MtComputeCommandEncoder *cce); - -// Specifying the Compute Pipeline State - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtComputeCommandEncoderSetComputePipelineState(MtComputeCommandEncoder *cce, MtComputePipelineState *state); - -// Specifying Arguments for a Compute Function - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtComputeCommandEncoderSetBufferOffsetAtIndex(MtComputeCommandEncoder *cce, MtBuffer *buf, NsUInteger offset, NsUInteger indx); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtComputeCommandEncoderSetBuffersOffsetsWithRange(MtComputeCommandEncoder *cce, MtBuffer **bufs, const NsUInteger *offsets, NsRange range); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtComputeCommandEncoderBufferSetOffsetAtIndex(MtComputeCommandEncoder *cce, NsUInteger offset, NsUInteger indx); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtComputeCommandEncoderSetBytesLengthAtIndex(MtComputeCommandEncoder *cce, const void* ptr, NsUInteger length, NsUInteger indx); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtComputeCommandEncoderSetSamplerStateAtIndex(MtComputeCommandEncoder *cce, MtSamplerState *sampler, NsUInteger indx); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtComputeCommandEncoderSetSamplerStatesWithRange(MtComputeCommandEncoder *cce, MtSamplerState **samplers, NsRange range); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtComputeCommandEncoderSetSamplerStateLodMinClampLodMaxClampAtIndex(MtComputeCommandEncoder *cce, MtSamplerState *sampler, float lodMinClamp, float lodMaxClamp, NsUInteger indx); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtComputeCommandEncoderSetTextureAtIndex(MtComputeCommandEncoder *cce, MtTexture *tex, NsUInteger indx); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtComputeCommandEncoderSetTexturesWithRange(MtComputeCommandEncoder *cce, MtTexture **textures, NsRange range); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtComputeCommandEncoderSetThreadgroupMemoryLengthAtIndex(MtComputeCommandEncoder *cce, NsUInteger length, NsUInteger indx); - -// Executing a Compute Function Directly - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtComputeCommandEncoderDispatchThreadgroups_threadsPerThreadgroup(MtComputeCommandEncoder *cce, MtSize threadgroupsPerGrid, MtSize threadsPerThreadgroup); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -void -mtComputeCommandEncoderDispatchThread_threadsPerThreadgroup(MtComputeCommandEncoder *cce, MtSize threadsPerGrid, MtSize threadsPerThreadgroup); - -// Executing a Compute Function Indirectly -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtComputeCommandEncoderDispatchThreadgroupsWithIndirectBuffer_IndirectBufferOffset_threadsPerThreadgroup(MtComputeCommandEncoder *cce, MtBuffer *indirectBuffer, NsUInteger indirectBufferOffset, MtSize threadsPerThreadgroup); - -// Specifying Resource Usage for Argument Buffers -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -void -mtComputeCommandEncoderUseResourceUsage(MtComputeCommandEncoder *cce, MtResource *res, MtResourceUsage usage); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtComputeCommandEncoderUseResourcesCountUsage(MtComputeCommandEncoder *cce, MtResource **res, NsUInteger count, MtResourceUsage usage); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -void -mtComputeCommandEncoderUseHeap(MtComputeCommandEncoder *cce, MtHeap *heap); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -void -mtComputeCommandEncoderUseHeaps(MtComputeCommandEncoder *cce, MtHeap **heaps, NsUInteger count); - -//Specifying the Stage-In Region -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.12), mt_ios(10.0)) -void -mtComputeCommandEncoderSetStageInRegion(MtComputeCommandEncoder *cce, MtRegion region); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.14), mt_ios(12.0)) -void -mtComputeCommandEncoderSetStageInRegionWithIndirectBuffer(MtComputeCommandEncoder *cce, MtBuffer *buf, NsUInteger offset); - -// Executing Commands Concurrently or Serially -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.14), mt_ios(12.0)) -MtDispatchType -mtComputeCommandEncoderDispatchType(MtComputeCommandEncoder *cce); - -// Executing Commands Concurrently or Serially -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.14), mt_ios(12.0)) -void -mtComputeCommandEncoderMemoryBarrierWithScope(MtComputeCommandEncoder *cce, MtBarrierScope scope); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.14), mt_ios(12.0)) -void -mtComputeCommandEncoderMemoryBarrierWithResource(MtComputeCommandEncoder *cce, MtResource **resources, NsUInteger count); - -MT_EXPORT -void -mtComputeCommandEncoderExecuteCommandInBuffer(MtComputeCommandEncoder *cce, MtResource **resources, NsUInteger count); - -#ifdef __cplusplus -} -#endif -#endif /* cmt_command_enc_compute_h */ diff --git a/deps/cmt/include/cmt/command_enc_render.h b/deps/cmt/include/cmt/command_enc_render.h deleted file mode 100644 index 201a5ee6..00000000 --- a/deps/cmt/include/cmt/command_enc_render.h +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (c), Recep Aslantas. - * MIT License (MIT), http://opensource.org/licenses/MIT - */ - -#ifndef cmt_command_enc_render_h -#define cmt_command_enc_render_h -#ifdef __cplusplus -extern "C" { -#endif - -#include "cmt/common.h" -#include "cmt/types.h" -#include "cmt/enums.h" - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -MtRenderCommandEncoder* -mtNewRenderCommandEncoder(MtCommandBuffer *cmdb, MtRenderPassDesc *pass); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtFrontFace(MtRenderCommandEncoder *rce, MtWinding winding); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtCullMode(MtRenderCommandEncoder *rce, MtCullMode mode); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtViewport(MtRenderCommandEncoder *rce, MtViewport *viewport); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtSetRenderState(MtRenderCommandEncoder *rce, MtRenderPipeline *pipline); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtSetDepthStencil(MtRenderCommandEncoder *rce, MtDepthStencil *ds); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtVertexBytes(MtRenderCommandEncoder *rce, - void *bytes, - size_t legth, - uint32_t atIndex); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtVertexBuffer(MtRenderCommandEncoder *rce, - MtBuffer *buf, - size_t off, - uint32_t index); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtFragmentBuffer(MtRenderCommandEncoder *rce, - MtBuffer *buf, - size_t off, - uint32_t index); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtDrawPrims(MtRenderCommandEncoder *rce, - MtPrimitiveType type, - size_t start, - size_t count); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtDrawIndexedPrims(MtRenderCommandEncoder *rce, - MtPrimitiveType type, - uint32_t indexCount, - MtIndexType indexType, - MtBuffer *indexBuffer, - uint32_t indexBufferOffset); - -#ifdef __cplusplus -} -#endif -#endif /* cmt_command_enc_render_h */ diff --git a/deps/cmt/include/cmt/command_queue.h b/deps/cmt/include/cmt/command_queue.h deleted file mode 100644 index 90294607..00000000 --- a/deps/cmt/include/cmt/command_queue.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c), Recep Aslantas. - * MIT License (MIT), http://opensource.org/licenses/MIT - */ - -#ifndef cmt_commandqueue_h -#define cmt_commandqueue_h -#ifdef __cplusplus -extern "C" { -#endif - -#include "common.h" -#include "types.h" -#include "enums.h" - -MT_EXPORT -MtCommandQueue* -mtNewCommandQueue(MtDevice *device); - -MT_EXPORT -MtCommandQueue* -mtNewCommandQueueWithMaxCommandBufferCount(MtDevice *device, NsUInteger count); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -MtDevice* -mtCommandQueueDevice(MtCommandQueue *cmdq); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -const char* -mtCommandQueueLabel(MtCommandQueue *cmdq); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtCommandQueueLabelSet(MtCommandQueue *cmdq, const char* label); - -#ifdef __cplusplus -} -#endif -#endif /* cmt_commandqueue_h */ diff --git a/deps/cmt/include/cmt/common.h b/deps/cmt/include/cmt/common.h deleted file mode 100644 index 70461132..00000000 --- a/deps/cmt/include/cmt/common.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c), Recep Aslantas. - * MIT License (MIT), http://opensource.org/licenses/MIT - */ - -#ifndef cmt_common_h -#define cmt_common_h - -#define MT_EXPORT __attribute__((visibility("default"))) -#define MT_HIDE __attribute__((visibility("hidden"))) -#define MT_INLINE inline __attribute((always_inline)) -#define MT_ALIGN(X) __attribute((aligned(X))) - -#include -#include -#include - -/* - MT_API_AVAILABLE usage: - MT_API_AVAILABLE(minimum_macos_version, minimum_ios_version) - */ - -#ifdef __APPLE__ -# include -# define mt_macCatalyst macCatalyst -# define mt_ios ios -# define mt_macos macos -//# define MT_API_AVAILABLE(M, I) API_AVAILABLE(macos(M), ios(I)) -# define MT_API_AVAILABLE(...) API_AVAILABLE(__VA_ARGS__) -# define MT_API_UNAVAILABLE(X) API_UNAVAILABLE(X) -#else -# define mt_macCatalyst -# define mt_ios -# define mt_macos -# define mt_API_AVAILABLE(M, I) -#endif - -#endif /* cmt_common_h */ diff --git a/deps/cmt/include/cmt/common_internal.h b/deps/cmt/include/cmt/common_internal.h deleted file mode 100644 index ead316f2..00000000 --- a/deps/cmt/include/cmt/common_internal.h +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Copyright (c), Recep Aslantas. - * MIT License (MIT), http://opensource.org/licenses/MIT - */ - -#ifndef cmt__core_h -#define cmt__core_h - -#define MT_EXPORT __attribute__((visibility("default"))) -#define MT_HIDE __attribute__((visibility("hidden"))) -#define MT_INLINE inline __attribute((always_inline)) -#define MT_ALIGN(X) __attribute((aligned(X))) - -#include -#include -#include - -#endif /* cmt__core_h */ diff --git a/deps/cmt/include/cmt/compute/compute-pipeline.h b/deps/cmt/include/cmt/compute/compute-pipeline.h deleted file mode 100644 index c7acd1a2..00000000 --- a/deps/cmt/include/cmt/compute/compute-pipeline.h +++ /dev/null @@ -1,142 +0,0 @@ - /* - * Copyright (c), Recep Aslantas. - * MIT License (MIT), http://opensource.org/licenses/MIT - */ - -#ifndef cmt_compute_pipeline_h -#define cmt_compute_pipeline_h -#ifdef __cplusplus -extern "C" { -#endif - -#include "cmt/common.h" -#include "cmt/types.h" -#include "cmt/enums.h" - -// Compute Pipeline Descriptor -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(9.0)) -MtComputePipelineDescriptor* -mtNewComputePipelineDescriptor(void); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(9.0)) -const char* -mtComputePipelineDescriptorLabel(MtComputePipelineDescriptor *desc); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(9.0)) -void -mtComputePipelineDescriptorLabelSet(MtComputePipelineDescriptor *desc, const char *label); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(9.0)) -MtFunction* -mtComputePipelineDescriptorComputeFunction(MtComputePipelineDescriptor *desc); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(9.0)) -void -mtComputePipelineDescriptorComputeFunctionSet(MtComputePipelineDescriptor *desc, MtFunction *fun); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(9.0)) -bool -mtComputePipelineDescriptorThreadGroupSizeIsMultipleOfThreadExecutionWidth(MtComputePipelineDescriptor *desc); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(9.0)) -void -mtComputePipelineDescriptorThreadGroupSizeIsMultipleOfThreadExecutionWidthSet(MtComputePipelineDescriptor *desc, bool val); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.14), mt_ios(12.0)) -uint32_t -mtComputePipelineDescriptorMaxTotalThreadsPerThreadgroup(MtComputePipelineDescriptor *desc); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.14), mt_ios(12.0)) -void -mtComputePipelineDescriptorMaxTotalThreadsPerThreadgroupSet(MtComputePipelineDescriptor *desc, uint32_t val); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(11.00), mt_ios(14.0)) -uint32_t -mtComputePipelineDescriptorMaxCallStackDepth(MtComputePipelineDescriptor *desc); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(11.00), mt_ios(14.0)) -void -mtComputePipelineDescriptorMaxCallStackDepthSet(MtComputePipelineDescriptor *desc, uint32_t val); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(11.0), mt_ios(13.0)) -bool -mtComputePipelineDescriptorSupportIndirectCommandBuffers(MtComputePipelineDescriptor *desc); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(9.0)) -void -mtComputePipelineDescriptorReset(MtComputePipelineDescriptor *desc); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(11.00), mt_ios(14.0)) -bool -mtComputePipelineDescriptorSupportAddingBinaryFunctions(MtComputePipelineDescriptor *desc); - -// Create Pipeline -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -MtComputePipelineState* -mtNewComputePipelineStateWithFunction(MtDevice *device, MtFunction* fun, NsError **error); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -MtComputePipelineState* -mtNewComputePipelineStateWithFunctionReflection(MtDevice *device, MtFunction* fun,MtPipelineOption opt, - MtComputePipelineReflection **reflection, NsError **error); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -MtComputePipelineState* -mtNewComputePipelineStateWithDescriptor(MtDevice *device, MtComputePipelineDescriptor* desc, - MtPipelineOption opt, - MtComputePipelineReflection **reflection, - NsError **error); - -// properties -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -MtDevice* -mtComputePipelineDevice(MtComputePipelineState *pip); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -const char* -mtComputePipelineLabel(MtComputePipelineState *pip); - -// attributes -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -NsUInteger -mtComputePipelineMaxTotalThreadsPerThreadgroup(MtComputePipelineState *pip); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -NsUInteger -mtComputePipelineThreadExecutionWidth(MtComputePipelineState *pip); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -NsUInteger -mtComputePipelineStaticThreadgroupMemoryLength(MtComputePipelineState *pip); - -// imageblock attri -/*MT_EXPORT -NsUInteger -mtComputePipelineImageblockMemoryLengthForDimensions(MtComputePipelineState *pip, MtSize imageblockDimensions); IOS 11*/ - -#ifdef __cplusplus -} -#endif -#endif /* cmt_compute_pipeline_h */ diff --git a/deps/cmt/include/cmt/device.h b/deps/cmt/include/cmt/device.h deleted file mode 100644 index a876cbb7..00000000 --- a/deps/cmt/include/cmt/device.h +++ /dev/null @@ -1,161 +0,0 @@ -/* - * Copyright (c), Recep Aslantas. - * MIT License (MIT), http://opensource.org/licenses/MIT - */ - -#ifndef cmt_device_h -#define cmt_device_h -#ifdef __cplusplus -extern "C" { -#endif - -#include "common.h" -#include "types.h" -#include "enums.h" -#include "error.h" -#include "resource.h" - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -MtDevice* -mtCreateSystemDefaultDevice(void); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtCopyAllDevices(size_t *count, MtDevice** devices); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -const char* -mtDeviceName(MtDevice*); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -bool -mtDeviceHeadless(MtDevice*); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -bool -mtDeviceLowPower(MtDevice*); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_macCatalyst(13.0)) -MT_API_UNAVAILABLE(mt_ios) -bool -mtDeviceRemovable(MtDevice*); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -uint64_t -mtDeviceRegistryID(MtDevice*); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -MtDeviceLocation -mtDeviceLocation(MtDevice*); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.15)) -API_UNAVAILABLE(mt_ios) -uint64_t -mtDeviceLocationNumber(MtDevice*); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.15)) -API_UNAVAILABLE(mt_ios) -uint64_t -mtDeviceMaxTransferRate(MtDevice*); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.15), mt_ios(13.0)) -bool -mtDeviceHasUnifiedMemory(MtDevice*); - -// peers -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.15)) -MT_API_UNAVAILABLE(mt_ios) -uint64_t -mtDevicePeerGroupID(MtDevice*); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.15)) -MT_API_UNAVAILABLE(mt_ios) -uint32_t -mtDevicePeerCount(MtDevice*); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.15)) -MT_API_UNAVAILABLE(mt_ios) -uint32_t -mtDevicePeerIndex(MtDevice*); - -// level -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.15), mt_ios(13.0)) -bool -mtDeviceSupportsFamily(MtDevice *device, MtGPUFamily family); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -bool -mtDeviceSupportsFeatureSet(MtDevice *device, MtFeatureSet set); - -// -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.12), mt_macCatalyst(13.0)) -MT_API_UNAVAILABLE(mt_ios) -uint64_t -mtDeviceRecommendedMaxWorkingSetSize(MtDevice* device); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -NsUInteger -mtDeviceCurrentAllocatedSize(MtDevice* device); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -NsUInteger -mtDeviceMaxThreadgroupMemoryLength(MtDevice* device); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -MtSize -mtMaxThreadsPerThreadgroup(MtDevice* device); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -MtArgumentBuffersTier -mtDeviceArgumentBuffersSupport(MtDevice *device); - -// Buffers -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.14), mt_ios(12.0)) -NsUInteger -mtDeviceMaxBufferLength(MtDevice *device); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -MtBuffer* -mtDeviceNewBufferWithLength(MtDevice *device, NsUInteger length, MtResourceOptions opts); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -MtBuffer* -mtDeviceNewBufferWithBytes(MtDevice *device, const void* ptr, NsUInteger length, MtResourceOptions opts); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -MtBuffer* -mtDeviceNewBufferWithBytesNoCopy(MtDevice *device, void* ptr, NsUInteger length, MtResourceOptions opts); - -//MT_EXPORT -//MtBuffer* -//mtDeviceNewBufferWithBytesNoCopyDeallocator(MtDevice *device, void* ptr, NsUInteger length, MtResourceOptions opts); - -#ifdef __cplusplus -} -#endif -#endif /* cmt_device_h */ diff --git a/deps/cmt/include/cmt/enums.h b/deps/cmt/include/cmt/enums.h deleted file mode 100644 index df7c6961..00000000 --- a/deps/cmt/include/cmt/enums.h +++ /dev/null @@ -1,518 +0,0 @@ -/* - * Copyright (c), Recep Aslantas. - * MIT License (MIT), http://opensource.org/licenses/MIT - */ - -#ifndef cmt_enums_h -#define cmt_enums_h - -#include "common.h" - -typedef enum MtPrimitiveType { - MtPrimitiveTypePoint = 0, - MtPrimitiveTypeLine = 1, - MtPrimitiveTypeLineStrip = 2, - MtPrimitiveTypeTriangle = 3, - MtPrimitiveTypeTriangleStrip = 4 -} MtPrimitiveType; - -typedef enum MtVisibilityResultMode { - MtVisibilityResultModeDisabled = 0, - MtVisibilityResultModeBoolean = 1, - MtVisibilityResultModeCounting = 2 -} MtVisibilityResultMode; - -typedef struct MtScissorRect { - uint32_t x, y, width, height; -} MtScissorRect; - -typedef struct MtViewport { - double originX, originY, width, height, znear, zfar; -} MtViewport; - -typedef enum MtCullMode { - MtCullModeNone = 0, - MtCullModeFront = 1, - MtCullModeBack = 2 -} MtCullMode; - -typedef enum MtWinding { - MtWindingClockwise = 0, - MtWindingCounterClockwise = 1 -} MtWinding; - -typedef enum MtDepthClipMode { - MtDepthClipModeClip = 0, - MtDepthClipModeClamp = 1 -} MtDepthClipMode; - -typedef enum MtTriangleFillMode { - MtTriangleFillModeFill = 0, - MtTriangleFillModeLines = 1 -} MtTriangleFillMode; - -typedef struct MtDrawPrimitivesIndirectArguments { - uint32_t vertexCount; - uint32_t instanceCount; - uint32_t vertexStart; - uint32_t baseInstance; -} MtDrawPrimitivesIndirectArguments; - -typedef struct MtDrawIndexedPrimitivesIndirectArguments { - uint32_t indexCount; - uint32_t instanceCount; - uint32_t indexStart; - int32_t baseVertex; - uint32_t baseInstance; -} MtDrawIndexedPrimitivesIndirectArguments; - -typedef struct MtDrawPatchIndirectArguments { - uint32_t patchCount; - uint32_t instanceCount; - uint32_t patchStart; - uint32_t baseInstance; -} MtDrawPatchIndirectArguments; - -typedef struct MtQuadTessellationFactorsHalf { - uint16_t edgeTessellationFactor[4]; - uint16_t insideTessellationFactor[2]; -} MtQuadTessellationFactorsHalf; - -typedef struct MtTriangleTessellationFactorsHalf { - uint16_t edgeTessellationFactor[3]; - uint16_t insideTessellationFactor; -} MtTriangleTessellationFactorsHalf; - -typedef enum MtRenderStages { - MtRenderStageVertex = (1UL << 0), - MtRenderStageFragment = (1UL << 1) -} MtRenderStages; - -typedef enum MtLoadAction { - MtLoadActionDontCare = 0, - MtLoadActionLoad = 1, - MtLoadActionClear = 2, -} MtLoadAction; - -typedef enum MtIndexType { - MtIndexTypeUInt16 = 0, - MtIndexTypeUInt32 = 1, -} MtIndexType; - -typedef enum MtStoreAction { - MtStoreActionDontCare = 0, - MtStoreActionStore = 1, - MtStoreActionMultisampleResolve = 2, - MtStoreActionStoreAndMultisampleResolve = 3, - MtStoreActionUnknown = 4, - MtStoreActionCustomSampleDepthStore = 5, -} MtStoreAction; - -typedef enum MtDeviceLocation { - MtDeviceLocationBuiltIn = 0, - MtDeviceLocationSlot = 1, - MtDeviceLocationExternal = 2, - MtDeviceLocationUnspecified = 100, -} MtDeviceLocation; - -typedef enum MtLanguageVersion { - MtLanguageVersion1_0 = (1 << 16), - MtLanguageVersion1_1 = (1 << 16) + 1, - MtLanguageVersion1_2 = (1 << 16) + 2, - MtLanguageVersion2_0 = (2 << 16), - MtLanguageVersion2_1 = (2 << 16) + 1, - MtLanguageVersion2_2 = (2 << 16) + 2, - MtLanguageVersion2_3 = (2 << 16) + 3, - MtLanguageVersion2_4 = (2 << 16) + 4, -} MtLanguageVersion; - -typedef enum MtFunctionType { - MtFunctionTypeVertex = 1, - MtFunctionTypeFragment = 2, - MtFunctionTypeKernel = 3, -} MtFunctionType; - -typedef enum MtDispatchType { - MtDispatchTypeSerial, - MtDispatchTypeConcurrent, -} MtDispatchType; - -typedef enum MtCommandBufferStatus { - MtCommandBufferStatusNotEnqueued = 0, - MtCommandBufferStatusEnqueued = 1, - MtCommandBufferStatusCommitted = 2, - MtCommandBufferStatusScheduled = 3, - MtCommandBufferStatusCompleted = 4, - MtCommandBufferStatusError = 5, -} MtCommandBufferStatus; - -typedef enum MtResourceUsage { - MtResourceUsageRead = 1 << 0, - MtResourceUsageWrite = 1 << 1, - MtResourceUsageSample = 1 << 2 -} MtResourceUsage; - -typedef enum MtGPUFamily { - MtGPUFamilyApple1 = 1001, - MtGPUFamilyApple2 = 1002, - MtGPUFamilyApple3 = 1003, - MtGPUFamilyApple4 = 1004, - MtGPUFamilyApple5 = 1005, - - MtGPUFamilyMac1 = 2001, - MtGPUFamilyMac2 = 2002, - - MtGPUFamilyCommon1 = 3001, - MtGPUFamilyCommon2 = 3002, - MtGPUFamilyCommon3 = 3003, - - MtGPUFamilyMacCatalyst1 = 4001, - MtGPUFamilyMacCatalyst2 = 4002, -} MtGPUFamily; - -typedef enum MtFeatureSet { - MtFeatureSet_macOS_GPUFamily1_v1 = 10000, - MtFeatureSet_OSX_GPUFamily1_v1 = MtFeatureSet_macOS_GPUFamily1_v1, // deprecated - - MtFeatureSet_macOS_GPUFamily1_v2 = 10001, - MtFeatureSet_OSX_GPUFamily1_v2 = MtFeatureSet_macOS_GPUFamily1_v2, // deprecated - MtFeatureSet_macOS_ReadWriteTextureTier2 = 10002, - MtFeatureSet_OSX_ReadWriteTextureTier2 = MtFeatureSet_macOS_ReadWriteTextureTier2, // deprecated - - MtFeatureSet_macOS_GPUFamily1_v3 = 10003, - - MtFeatureSet_macOS_GPUFamily1_v4 = 10004, - MtFeatureSet_macOS_GPUFamily2_v1 = 10005, -} MtFeatureSet; - -typedef enum MtPurgeableState { - MtPurgeableStateKeepCurrent = 1, - - MtPurgeableStateNonVolatile = 2, - MtPurgeableStateVolatile = 3, - MtPurgeableStateEmpty = 4, -} MtPurgeableState; - -typedef enum MtCommandBufferError { - MtCommandBufferErrorNone = 0, - MtCommandBufferErrorInternal = 1, - MtCommandBufferErrorTimeout = 2, - MtCommandBufferErrorPageFault = 3, - MtCommandBufferErrorBlacklisted = 4, - MtCommandBufferErrorNotPermitted = 7, - MtCommandBufferErrorOutOfMemory = 8, - MtCommandBufferErrorInvalidResource = 9, - MtCommandBufferErrorMemoryless = 10, - MtCommandBufferErrorDeviceRemoved = 11, -} MtCommandBufferError; - -typedef enum MtCommandBufferErrorOption { - MtCommandBufferErrorOptionNone = 0, - MtCommandBufferErrorOptionEncoderExecutionStatus = 1, -} MtCommandBufferErrorOption; - -typedef enum MtCommandEncoderErrorState { - MtCommandEncodererrorStateUnknown = 0, - MtCommandEncodererrorStateCompleted = 1, - MtCommandEncodererrorStateAffected = 2, - MtCommandEncodererrorStatePending = 3, - MtCommandEncodererrorStateFaulted = 4, -} MtCommandencoderErrorState; - -/*! - @enum MTLHeapType - @abstract Describes the mode of operation for an MTLHeap. - @constant MTLHeapTypeAutomatic - In this mode, resources are placed in the heap automatically. - Automatically placed resources have optimal GPU-specific layout, and may perform better than MTLHeapTypePlacement. - This heap type is recommended when the heap primarily contains temporary write-often resources. - @constant MTLHeapTypePlacement - In this mode, the app places resources in the heap. - Manually placed resources allow the app to control memory usage and heap fragmentation directly. - This heap type is recommended when the heap primarily contains persistent write-rarely resources. - */ -typedef enum MtHeapType { - MtHeapTypeAutomatic = 0, - MtHeapTypePlacement = 1, -} MtHeapType; - - -typedef enum MtBlitOption { - MtBlitOptionNone = 0, - MtBlitOptionDepthFromDepthStencil = 1 << 0, - MtBlitOptionStencilFromDepthStencil = 1 << 1, - } MtBlitOption; - - -typedef enum { - MtLibraryErrorUnsupported = 1, - MtLibraryErrorInternal = 2, - MtLibraryErrorCompileFailure = 3, - MtLibraryErrorCompileWarning = 4, - MtLibraryErrorFunctionNotFound = 5, - MtLibraryErrorFileNotFound = 6, -} MtLibraryError; - -typedef enum MtBarrierScope -{ - MtBarrierScopeBuffers = 1 << 0, - MtBarrierScopeTextures = 1 << 1, - MtBarrierScopeRenderTargets = 1 << 2, -} MtBarrierScope; - -typedef enum MtIndirectCommandType { - MIndirectCommandTypeDraw = (1 << 0), - MIndirectCommandTypeDrawIndexed = (1 << 1), - MIndirectCommandTypeDrawPatches = (1 << 2), - MIndirectCommandTypeDrawIndexedPatches = (1 << 3) , -} MtIndirectCommandType; - -typedef enum MtDataType { - - MtDataTypeNone = 0, - - MtDataTypeStruct = 1, - MtDataTypeArray = 2, - - MtDataTypeFloat = 3, - MtDataTypeFloat2 = 4, - MtDataTypeFloat3 = 5, - MtDataTypeFloat4 = 6, - - MtDataTypeFloat2x2 = 7, - MtDataTypeFloat2x3 = 8, - MtDataTypeFloat2x4 = 9, - - MtDataTypeFloat3x2 = 10, - MtDataTypeFloat3x3 = 11, - MtDataTypeFloat3x4 = 12, - - MtDataTypeFloat4x2 = 13, - MtDataTypeFloat4x3 = 14, - MtDataTypeFloat4x4 = 15, - - MtDataTypeHalf = 16, - MtDataTypeHalf2 = 17, - MtDataTypeHalf3 = 18, - MtDataTypeHalf4 = 19, - - MtDataTypeHalf2x2 = 20, - MtDataTypeHalf2x3 = 21, - MtDataTypeHalf2x4 = 22, - - MtDataTypeHalf3x2 = 23, - MtDataTypeHalf3x3 = 24, - MtDataTypeHalf3x4 = 25, - - MtDataTypeHalf4x2 = 26, - MtDataTypeHalf4x3 = 27, - MtDataTypeHalf4x4 = 28, - - MtDataTypeInt = 29, - MtDataTypeInt2 = 30, - MtDataTypeInt3 = 31, - MtDataTypeInt4 = 32, - - MtDataTypeUInt = 33, - MtDataTypeUInt2 = 34, - MtDataTypeUInt3 = 35, - MtDataTypeUInt4 = 36, - - MtDataTypeShort = 37, - MtDataTypeShort2 = 38, - MtDataTypeShort3 = 39, - MtDataTypeShort4 = 40, - - MtDataTypeUShort = 41, - MtDataTypeUShort2 = 42, - MtDataTypeUShort3 = 43, - MtDataTypeUShort4 = 44, - - MtDataTypeChar = 45, - MtDataTypeChar2 = 46, - MtDataTypeChar3 = 47, - MtDataTypeChar4 = 48, - - MtDataTypeUChar = 49, - MtDataTypeUChar2 = 50, - MtDataTypeUChar3 = 51, - MtDataTypeUChar4 = 52, - - MtDataTypeBool = 53, - MtDataTypeBool2 = 54, - MtDataTypeBool3 = 55, - MtDataTypeBool4 = 56, - - MtDataTypeTexture = 58, - MtDataTypeSampler = 59, - MtDataTypePointer = 60, - - MtDataTypeRenderPipeline = 78, - MtDataTypeIndirectCommandBuffer = 80, -} MtDataType; - -typedef enum MtArgumentAccess { - MtArgumentAccessReadOnly = 0, - MtArgumentAccessReadWrite = 1, - MtArgumentAccessWriteOnly = 2, -} MtArgumentAccess; - -typedef enum MtArgumentBuffersTier -{ - MtArgumentBuffersTier1 = 0, - MtArgumentBuffersTier2 = 1, -} MtArgumentBuffersTier; - -typedef enum MtTextureType { - MtTextureType1D = 0, - MtTextureType1DArray = 1, - MtTextureType2D = 2, - MtTextureType2DArray = 3, - MtTextureType2DMultisample = 4, - MtTextureTypeCube = 5, - MtTextureTypeCubeArray = 6, - MtTextureType3D = 7, - MtTextureType2DMultisampleArray = 8, - MtTextureTypeTextureBuffer = 9 -} MtTextureType; - -typedef enum MtTextureSwizzle { - MtTextureSwizzleZero = 0, - MtTextureSwizzleOne = 1, - MtTextureSwizzleRed = 2, - MtTextureSwizzleGreen = 3, - MtTextureSwizzleBlue = 4, - MtTextureSwizzleAlpha = 5, -} MtTextureSwizzle; - -typedef enum MtAttributeFormat -{ - MtAttributeFormatInvalid = 0, - - MtAttributeFormatUChar2 = 1, - MtAttributeFormatUChar3 = 2, - MtAttributeFormatUChar4 = 3, - - MtAttributeFormatChar2 = 4, - MtAttributeFormatChar3 = 5, - MtAttributeFormatChar4 = 6, - - MtAttributeFormatUChar2Normalized = 7, - MtAttributeFormatUChar3Normalized = 8, - MtAttributeFormatUChar4Normalized = 9, - - MtAttributeFormatChar2Normalized = 10, - MtAttributeFormatChar3Normalized = 11, - MtAttributeFormatChar4Normalized = 12, - - MtAttributeFormatUShort2 = 13, - MtAttributeFormatUShort3 = 14, - MtAttributeFormatUShort4 = 15, - - MtAttributeFormatShort2 = 16, - MtAttributeFormatShort3 = 17, - MtAttributeFormatShort4 = 18, - - MtAttributeFormatUShort2Normalized = 19, - MtAttributeFormatUShort3Normalized = 20, - MtAttributeFormatUShort4Normalized = 21, - - MtAttributeFormatShort2Normalized = 22, - MtAttributeFormatShort3Normalized = 23, - MtAttributeFormatShort4Normalized = 24, - - MtAttributeFormatHalf2 = 25, - MtAttributeFormatHalf3 = 26, - MtAttributeFormatHalf4 = 27, - - MtAttributeFormatFloat = 28, - MtAttributeFormatFloat2 = 29, - MtAttributeFormatFloat3 = 30, - MtAttributeFormatFloat4 = 31, - - MtAttributeFormatInt = 32, - MtAttributeFormatInt2 = 33, - MtAttributeFormatInt3 = 34, - MtAttributeFormatInt4 = 35, - - MtAttributeFormatUInt = 36, - MtAttributeFormatUInt2 = 37, - MtAttributeFormatUInt3 = 38, - MtAttributeFormatUInt4 = 39, - - MtAttributeFormatInt1010102Normalized = 40, - MtAttributeFormatUInt1010102Normalized = 41, - - MtAttributeFormatUChar4Normalized_BGRA = 42, - - MtAttributeFormatUChar = 45, - MtAttributeFormatChar = 46, - MtAttributeFormatUCharNormalized = 47, - MtAttributeFormatCharNormalized = 48, - - MtAttributeFormatUShort = 49, - MtAttributeFormatShort = 50, - MtAttributeFormatUShortNormalized = 51, - MtAttributeFormatShortNormalized = 52, - - MtAttributeFormatHalf = 53, - -} MtAttributeFormat; - - -typedef enum MtStepFunction -{ - MtStepFunctionConstant = 0, - - // vertex functions only - MtStepFunctionPerVertex = 1, - MtStepFunctionPerInstance = 2, - MtStepFunctionPerPatch = 3, - MtStepFunctionPerPatchControlPoint = 4, - - // compute functions only - MtStepFunctionThreadPositionInGridX = 5, - MtStepFunctionThreadPositionInGridY = 6, - MtStepFunctionThreadPositionInGridXIndexed = 7, - MtStepFunctionThreadPositionInGridYIndexed = 8, -} MtStepFunction; - -typedef enum MtPipelineOption -{ - MtPipelineOptionNone = 0, - MtPipelineOptionArgumentInfo = 1 << 0, - MtPipelineOptionBufferTypeInfo = 1 << 1, -} MtPipelineOption; - -typedef enum MtArgumentType { - MtArgumentTypeBuffer = 0, - MtArgumentTypeThreadgroupMemory= 1, - MtArgumentTypeTexture = 2, - MtArgumentTypeSampler = 3, -} MtArgumentType; - -typedef enum MtCaptureError { - /// Capturing is not supported, maybe the destination is not supported. - MtCaptureErrorNotSupported = 1, - /// A capture is already in progress. - MtCaptureErrorAlreadyCapturing, - /// The MTLCaptureDescriptor contains an invalid parameters. - MtCaptureErrorInvalidDescriptor, -} MtCaptureError; - -/// The destination where you want the GPU trace to be captured to. -typedef enum MtCaptureDestination { - /// Capture to Developer Tools (Xcode) and stop the execution after capturing. - MtCaptureDestinationDeveloperTools = 1, - /// Capture to a GPU Trace document and continue execution after capturing. - MtCaptureDestinationGPUTraceDocument, -} MtCaptureDestination; - -typedef enum MtCaptureDescriptorCaptureObjectType { - MtCaptureDescriptorCaptureObjectTypeNull = 0, - MtCaptureDescriptorCaptureObjectTypeDevice = 1, - MtCaptureDescriptorCaptureObjectTypeQueue = 2, - MtCaptureDescriptorCaptureObjectTypeScope = 3 -} MtCaptureDescriptorCaptureObjectType; - -#endif /* cmt_enums_h */ diff --git a/deps/cmt/include/cmt/error.h b/deps/cmt/include/cmt/error.h deleted file mode 100644 index 54218c30..00000000 --- a/deps/cmt/include/cmt/error.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c), Recep Aslantas. - * MIT License (MIT), http://opensource.org/licenses/MIT - */ - -#ifndef cmt_error_h -#define cmt_error_h -#ifdef __cplusplus -extern "C" { -#endif - -#include "common_internal.h" -#include "types_foundation.h" - -MT_EXPORT -NsInteger -mtErrorCode(NsError *err); - -MT_EXPORT -const char* -mtErrorDomain(NsError *err); - -MT_EXPORT -const char* -mtErrorUserInfo(NsError *err); - -MT_EXPORT -const char* -mtErrorLocalizedDescription(NsError *err); - -MT_EXPORT -const char** -mtErrorLocalizedRecoveryOptions(NsError *err, size_t* count, const char** options); - -MT_EXPORT -const char* -mtErrorLocalizedRecoverySuggestion(NsError *err); - -MT_EXPORT -const char* -mtErrorLocalizedFailureReason(NsError *err); - - -#ifdef __cplusplus -} -#endif -#endif /* cmt_error_h */ diff --git a/deps/cmt/include/cmt/event.h b/deps/cmt/include/cmt/event.h deleted file mode 100644 index 897665a5..00000000 --- a/deps/cmt/include/cmt/event.h +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (c), Recep Aslantas. - * MIT License (MIT), http://opensource.org/licenses/MIT - */ - -#ifndef cmt_event_h -#define cmt_event_h -#ifdef __cplusplus -extern "C" { -#endif - -#include "common.h" - -#include "types_foundation.h" - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.14), mt_ios(12.0)) -MtEvent* -mtDeviceNewEvent(MtDevice *dev); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.14), mt_ios(12.0)) -MtSharedEvent* -mtDeviceNewSharedEvent(MtDevice *dev); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.14), mt_ios(12.0)) -MtSharedEvent* -mtDeviceNewSharedEventWithHandle(MtDevice *dev, MtSharedEventHandle *handle); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(10.0)) -MtFence* -mtDeviceNewFence(MtDevice *dev); - -// -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.14), mt_ios(12.0)) -MtDevice* -mtEventDevice(MtEvent *event); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.14), mt_ios(12.0)) -const char* -mtEventLabel(MtEvent *event); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.14), mt_ios(12.0)) -void -mtEventLabelSet(MtEvent *event, const char* label); - -// shared -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.14), mt_ios(12.0)) -uint64_t -mtSharedEventSignaledValue(MtSharedEvent *event); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.14), mt_ios(12.0)) -MtSharedEventHandle* -mtSharedEventNewHandle(MtSharedEvent *event); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.14), mt_ios(12.0)) -void -mtSharedEventNotifyListener(MtSharedEvent *event, MtSharedEventListener *listener, uint64_t val, MtSharedEventNotificationBlock block); - - -#ifdef __cplusplus -} -#endif -#endif /* cmt_event_h */ diff --git a/deps/cmt/include/cmt/kernels/attribute.h b/deps/cmt/include/cmt/kernels/attribute.h deleted file mode 100644 index ca39dc44..00000000 --- a/deps/cmt/include/cmt/kernels/attribute.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c), Recep Aslantas. - * MIT License (MIT), http://opensource.org/licenses/MIT - */ - -#ifndef attribute_h -#define attribute_h -#ifdef __cplusplus -extern "C" { -#endif - -#include "cmt/common.h" -#include "cmt/types.h" -#include "cmt/enums.h" - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.12), mt_ios(10.0)) -const char* -mtAttributeName(MtAttribute *attr); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.12), mt_ios(10.0)) -NsUInteger -mtAttributeIndex(MtAttribute *attr); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.12), mt_ios(10.0)) -MtDataType -mtAttributeDataType(MtAttribute *attr); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.12), mt_ios(10.0)) -bool -mtAttributeActive(MtAttribute *attr); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.12), mt_ios(10.0)) -bool -mtAttributeIsPatchControlPointData(MtAttribute *attr); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.12), mt_ios(10.0)) -bool -mtAttributeIsPatchData(MtAttribute *attr); - -#ifdef __cplusplus -} -#endif -#endif /* attribute_h */ diff --git a/deps/cmt/include/cmt/kernels/attribute_vertex.h b/deps/cmt/include/cmt/kernels/attribute_vertex.h deleted file mode 100644 index 76a97ebe..00000000 --- a/deps/cmt/include/cmt/kernels/attribute_vertex.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c), Recep Aslantas. - * MIT License (MIT), http://opensource.org/licenses/MIT - */ - -#ifndef attribute_vertex_h -#define attribute_vertex_h -#ifdef __cplusplus -extern "C" { -#endif - -#include "cmt/common.h" -#include "cmt/types.h" -#include "cmt/enums.h" - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -const char* -mtVertexAttributeName(MtVertexAttribute *attr); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -NsUInteger -mtVertexAttributeIndex(MtVertexAttribute *attr); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -MtDataType -mtVertexAttributeDataType(MtVertexAttribute *attr); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -bool -mtVertexAttributeActive(MtVertexAttribute *attr); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.12), mt_ios(10.0)) -bool -mtVertexAttributeIsPatchControlPointData(MtVertexAttribute *attr); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.12), mt_ios(10.0)) -bool -mtVertexAttributeIsPatchData(MtVertexAttribute *attr); - -#ifdef __cplusplus -} -#endif -#endif /* attribute_vertex_h */ diff --git a/deps/cmt/include/cmt/kernels/binary_archive.h b/deps/cmt/include/cmt/kernels/binary_archive.h deleted file mode 100644 index c0b1c5a0..00000000 --- a/deps/cmt/include/cmt/kernels/binary_archive.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (c), Recep Aslantas. - * MIT License (MIT), http://opensource.org/licenses/MIT - */ - -#ifndef cmt_binary_archive_h -#define cmt_binary_archive_h -#ifdef __cplusplus -extern "C" { -#endif - -#include "cmt/common.h" -#include "cmt/types.h" -#include "cmt/enums.h" -#include "cmt/error.h" - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(11.0), mt_ios(14.0)) -MtBinaryArchiveDescriptor* -mtNewBinaryArchiveDescriptor(void); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(11.0), mt_ios(14.0)) -const char* -mtBinaryArchiveDescriptorURL(MtBinaryArchiveDescriptor *desc); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(11.0), mt_ios(14.0)) -void -mtBinaryArchiveDescriptorURLSet(MtBinaryArchiveDescriptor *desc, const char *path); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(11.0), mt_ios(14.0)) -MtBinaryArchive* -mtNewBinaryArchiveWithDescriptor(MtDevice *device, MtBinaryArchiveDescriptor *desc, NsError **error); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(11.0), mt_ios(14.0)) -MtDevice* -mtBinaryArchiveDevice(MtBinaryArchive *bin); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(11.0), mt_ios(14.0)) -const char* -mtBinaryArchiveLabel(MtBinaryArchive *bin); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(11.0), mt_ios(14.0)) -void -mtBinaryArchiveLabelSet(MtBinaryArchive *bin, const char *label); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(11.0), mt_ios(14.0)) -void -mtBinaryArchiveAddComputePipelineFunctions(MtBinaryArchive *bin, MtComputePipelineDescriptor *desc, NsError **error); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(11.0), mt_ios(14.0)) -void -mtBinaryArchiveAddFunction(MtBinaryArchive *bin, MtFunctionDescriptor *desc, MtLibrary *lib, NsError **error); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(11.0), mt_ios(14.0)) -void -mtBinaryArchiveSerialize(MtBinaryArchive *bin, const char *path, NsError **error); - -#ifdef __cplusplus -} -#endif -#endif /* cmt_binary_archive_h */ diff --git a/deps/cmt/include/cmt/kernels/compile-opts.h b/deps/cmt/include/cmt/kernels/compile-opts.h deleted file mode 100644 index 4642d52f..00000000 --- a/deps/cmt/include/cmt/kernels/compile-opts.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c), Recep Aslantas. - * MIT License (MIT), http://opensource.org/licenses/MIT - */ - -#ifndef cmt_compile_opts_h -#define cmt_compile_opts_h -#ifdef __cplusplus -extern "C" { -#endif - -#include "cmt/common.h" -#include "cmt/types.h" -#include "cmt/enums.h" - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -MtCompileOptions* -mtNewCompileOpts(void); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -bool -mtCompileOptsFastMath(MtCompileOptions *opts); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtCompileOptsFastMathSet(MtCompileOptions *opts, bool val); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -MtLanguageVersion -mtCompileOptsLanguageVersion(MtCompileOptions *opts); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtCompileOptsLanguageVersionSet(MtCompileOptions *opts, MtLanguageVersion val); - -#ifdef __cplusplus -} -#endif -#endif /* cmt_compile_opts_h */ diff --git a/deps/cmt/include/cmt/kernels/constant_values.h b/deps/cmt/include/cmt/kernels/constant_values.h deleted file mode 100644 index 380e119f..00000000 --- a/deps/cmt/include/cmt/kernels/constant_values.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c), Recep Aslantas. - * MIT License (MIT), http://opensource.org/licenses/MIT - */ - -/* https://developer.apple.com/documentation/metal/mtlfunctionconstantvalues?language=objc */ - -#ifndef cmt_constant_values_h -#define cmt_constant_values_h -#ifdef __cplusplus -extern "C" { -#endif - -#include "cmt/common.h" -#include "cmt/types.h" -#include "cmt/enums.h" - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.12), mt_ios(10.0)) -void -mtFunctionConstantValuesSetWithIndex(MtFunctionConstantValues *funval, const void *value, MtDataType typ, NsUInteger idx); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.12), mt_ios(10.0)) -void -mtFunctionConstantValuesSetWithName(MtFunctionConstantValues *funval, const void *value, MtDataType typ, const char* name); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.12), mt_ios(10.0)) -void -mtFunctionConstantValuesSetWithRange(MtFunctionConstantValues *funval, const void *value, MtDataType typ, NsRange range); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.12), mt_ios(10.0)) -void -mtFunctionConstantValuesReset(MtFunctionConstantValues *funval); - -#ifdef __cplusplus -} -#endif -#endif /* cmt_constant_values_h */ diff --git a/deps/cmt/include/cmt/kernels/function.h b/deps/cmt/include/cmt/kernels/function.h deleted file mode 100644 index 550bb0ef..00000000 --- a/deps/cmt/include/cmt/kernels/function.h +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright (c), Recep Aslantas. - * MIT License (MIT), http://opensource.org/licenses/MIT - */ - -#ifndef cmt_function_h -#define cmt_function_h -#ifdef __cplusplus -extern "C" { -#endif - -#include "cmt/common.h" -#include "cmt/types.h" -#include "cmt/enums.h" - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -MtFunction* -mtNewFunctionWithName(MtLibrary *lib, const char *name); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.12), mt_ios(10.0)) -MtFunction* -mtNewFunctionWithNameConstantValues(MtLibrary *lib, const char *name, MtFunctionConstantValues *constantValues, NsError **error); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -MtDevice* -mtFunctionDevice(MtFunction* fun); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.12), mt_ios(10.0)) -const char* -mtFunctionLabel(MtFunction* fun); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.12), mt_ios(10.0)) -void -mtFunctionLabelSet(MtFunction *fun, const char* label); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -MtFunctionType -mtFunctionType(MtFunction* fun); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -const char* -mtFunctionName(MtFunction* fun); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.12), mt_ios(10.0)) -MtAttribute** -mtFunctionStageInputAttributes(MtFunction* fun); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(11.0), mt_ios(14.0)) -MtFunctionDescriptor* -mtNewFunctionDescriptor(void); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(11.0), mt_ios(14.0)) -const char* -mtFunctionDescriptorName(MtFunctionDescriptor *desc); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(11.0), mt_ios(14.0)) -void -mtFunctionDescriptorNameSet(MtFunctionDescriptor *desc, const char *name); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(11.0), mt_ios(14.0)) -const char* -mtFunctionDescriptorSpecializedName(MtFunctionDescriptor *desc); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(11.0), mt_ios(14.0)) -void -mtFunctionDescriptorSpecializedNameSet(MtFunctionDescriptor *desc, const char *specializedName); - -#ifdef __cplusplus -} -#endif -#endif /* cmt_function_h */ diff --git a/deps/cmt/include/cmt/kernels/library.h b/deps/cmt/include/cmt/kernels/library.h deleted file mode 100644 index d358a0a8..00000000 --- a/deps/cmt/include/cmt/kernels/library.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (c), Recep Aslantas. - * MIT License (MIT), http://opensource.org/licenses/MIT - */ - -#ifndef cmt_library_h -#define cmt_library_h -#ifdef __cplusplus -extern "C" { -#endif - -#include "cmt/common.h" -#include "cmt/types.h" -#include "cmt/enums.h" -#include "cmt/error.h" - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -MtLibrary* -mtNewDefaultLibrary(MtDevice *device); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -MtLibrary* -mtNewLibraryWithFile(MtDevice *device, const char *filepath, NsError **error); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -MtLibrary* -mtNewLibraryWithURL(MtDevice *device, const char *url, NsError **error); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -MtLibrary* -mtNewLibraryWithSource(MtDevice *device, const char *source, MtCompileOptions *Opts, NsError **error); - -MT_EXPORT -MtLibrary* -mtNewLibraryWithData(MtDevice *device, const void* buffer, size_t size, NsError **error); - -MT_EXPORT -MtDevice* -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -mtLibraryDevice(MtLibrary *lib); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -const char* -mtLibraryLabel(MtLibrary *lib); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtLibraryLabelSet(MtLibrary *lib, const char *label); - -MT_EXPORT -void -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -mtLibraryFunctionNames(MtLibrary *lib, size_t* count, const char **names); - - -#ifdef __cplusplus -} -#endif -#endif /* cmt_library_h */ diff --git a/deps/cmt/include/cmt/macros.h b/deps/cmt/include/cmt/macros.h deleted file mode 100644 index 7c40147f..00000000 --- a/deps/cmt/include/cmt/macros.h +++ /dev/null @@ -1,10 +0,0 @@ -/* - * Copyright (c), Recep Aslantas. - * MIT License (MIT), http://opensource.org/licenses/MIT - */ - -#define mtIdPropertyDef(fName, objT, propertyT, propertyN) \ -MT_EXPORT Mt ## propertyT fName(Mt ## objT *obj); - -#define mtIdPropertyImpl(fName, objT, propertyT, propertyN) \ -MT_EXPORT Mt ## propertyT fName(Mt ## objT *obj) { return [(id)obj propertyN]; } diff --git a/deps/cmt/include/cmt/memory/buffer.h b/deps/cmt/include/cmt/memory/buffer.h deleted file mode 100644 index 353b17fe..00000000 --- a/deps/cmt/include/cmt/memory/buffer.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (c), Recep Aslantas. - * MIT License (MIT), http://opensource.org/licenses/MIT - */ - -#ifndef cmt_buffer_h -#define cmt_buffer_h -#ifdef __cplusplus -extern "C" { -#endif - -#include "cmt/common.h" -#include "cmt/types.h" -#include "cmt/enums.h" -#include "cmt/resource.h" - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void* -mtBufferContents(MtBuffer* buf); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -NsUInteger -mtBufferLength(MtBuffer* buf); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtBufferDidModifyRange(MtBuffer* buf, NsRange ran); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.12), mt_ios(10.0)) -void -mtBufferAddDebugMarkerRange(MtBuffer* buf, char* string, NsRange range); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.12), mt_ios(10.0)) -void -mtBufferRemoveAllDebugMarkers(MtBuffer* buf); - -// Those exist only on osx 10.15 -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.15)) -MT_API_UNAVAILABLE(mt_ios) -MtBuffer* -mtBufferNewRemoteBufferViewForDevice(MtBuffer *buf, MtDevice *device); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.15)) -MT_API_UNAVAILABLE(mt_ios) -MtBuffer* -mtBufferRemoteStorageBuffer(MtBuffer *buf); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(13.0), mt_ios(16.0)) -uint64_t -mtBufferGPUAddress(MtBuffer* buf); - -#ifdef __cplusplus -} -#endif - -// end 10.15 -#endif /* cmt_buffer_h */ diff --git a/deps/cmt/include/cmt/memory/heap-descriptor.h b/deps/cmt/include/cmt/memory/heap-descriptor.h deleted file mode 100644 index fcc6bb01..00000000 --- a/deps/cmt/include/cmt/memory/heap-descriptor.h +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright (c), Recep Aslantas. - * MIT License (MIT), http://opensource.org/licenses/MIT - */ - -#ifndef cmt_heap_descriptor_h -#define cmt_heap_descriptor_h -#ifdef __cplusplus -extern "C" { -#endif - -#include "cmt/common.h" -#include "cmt/types.h" -#include "cmt/enums.h" -#include "cmt/resource.h" - - -MT_EXPORT -MtHeapDescriptor* -mtNewHeapDescriptor(void); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.15), mt_ios(13.0)) -MtHeapType -mtHeapDescriptorType(MtHeapDescriptor *heap); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.15), mt_ios(13.0)) -void -mtHeapDescriptorTypeSet(MtHeapDescriptor *heap, MtHeapType type); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(10.0)) -MtStorageMode -mtHeapDescriptorStorageMode(MtHeapDescriptor *heap); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(10.0)) -void -mtHeapDescriptorStorageModeSet(MtHeapDescriptor *heap, MtStorageMode mode); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(10.0)) -MtCPUCacheMode -mtHeapDescriptorCPUCacheMode(MtHeapDescriptor *heap); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(10.0)) -void -mtHeapDescriptorCpuCacheModeSet(MtHeapDescriptor *heap, MtCPUCacheMode mode); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.15), mt_ios(13.0)) -MtHazardTrackingMode -mtHeapDescriptorHazardTrackingMode(MtHeapDescriptor *heap); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.15), mt_ios(13.0)) -void -mtHeapDescriptorHazardTrackingModeSet(MtHeapDescriptor *heap, MtHazardTrackingMode mode); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.15), mt_ios(13.0)) -MtResourceOptions -mtHeapDescriptorResourceOptions(MtHeapDescriptor *heap); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.15), mt_ios(13.0)) -void -mtHeapDescriptorResourceOptionsSet(MtHeapDescriptor *heap, MtResourceOptions mode); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(10.0)) -NsUInteger -mtHeapDescriptorSize(MtHeapDescriptor *heap); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(10.0)) -void -mtHeapDescriptorSizeSet(MtHeapDescriptor *heap, NsUInteger size); - -#ifdef __cplusplus -} -#endif -#endif /* cmt_heap_descriptor_h */ diff --git a/deps/cmt/include/cmt/memory/heap.h b/deps/cmt/include/cmt/memory/heap.h deleted file mode 100644 index 92710875..00000000 --- a/deps/cmt/include/cmt/memory/heap.h +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright (c), Recep Aslantas. - * MIT License (MIT), http://opensource.org/licenses/MIT - */ - -#ifndef cmt_heap_h -#define cmt_heap_h -#ifdef __cplusplus -extern "C" { -#endif - -#include "cmt/common.h" -#include "cmt/types.h" -#include "cmt/enums.h" -#include "cmt/resource.h" - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(10.0)) -MtHeap* -mtDeviceNewHeapWithDescriptor(MtDevice *dev, MtHeapDescriptor *descriptor); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(10.0)) -MtDevice* -mtHeapDevice(MtHeap *heap); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(10.0)) -const char* -mtHeapLabel(MtHeap *heap); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(10.0)) -void -mtHeapLabelSet(MtHeap *heap, const char* label); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.15), mt_ios(13.0)) -MtHeapType -mtHeapType(MtHeap *heap); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(10.0)) -MtStorageMode -mtHeapStorageMode(MtHeap *heap); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(10.0)) -MtCPUCacheMode -mtHeapCPUCacheMode(MtHeap *heap); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.15), mt_ios(13.0)) -MtHazardTrackingMode -mtHeapHazardTrackingMode(MtHeap *heap); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.15), mt_ios(13.0)) -MtResourceOptions -mtHeapResourceOptions(MtHeap *heap); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(10.0)) -NsUInteger -mtHeapSize(MtHeap *heap); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(10.0)) -NsUInteger -mtHeapUsedSize(MtHeap *heap); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(10.0)) -NsUInteger -mtHeapCurrentAllocatedSize(MtHeap *heap); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(10.0)) -NsUInteger -mtHeapMaxAvailableSizeWithAlignment(MtHeap *heap, NsUInteger alignment); - -// -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(10.0)) -MtPurgeableState -mtHeapSetPurgeableState(MtHeap *heap, MtPurgeableState state); - -// Creating Resources on the Heap -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(10.0)) -MtBuffer* -mtHeapNewBufferWithLength(MtHeap *heap, NsUInteger len, MtResourceOptions opt); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.15), mt_ios(13.0)) -MtBuffer* -mtHeapNewBufferWithLengthOffset(MtHeap *heap, NsUInteger len, MtResourceOptions opt, NsUInteger offset); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(10.0)) -MtTexture* -mtHeapNewTextureWithDescriptor(MtHeap *heap, MtTextureDescriptor *desc); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.15), mt_ios(13.0)) -MtTexture* -mtHeapNewTextureWithDescriptorOffset(MtHeap *heap, MtTextureDescriptor *desc, NsUInteger offset); - -#ifdef __cplusplus -} -#endif -#endif /* cmt_heap_h */ diff --git a/deps/cmt/include/cmt/memory/vertex.h b/deps/cmt/include/cmt/memory/vertex.h deleted file mode 100644 index 4d91cf4b..00000000 --- a/deps/cmt/include/cmt/memory/vertex.h +++ /dev/null @@ -1,144 +0,0 @@ -/* - * Copyright (c), Recep Aslantas. - * MIT License (MIT), http://opensource.org/licenses/MIT - */ - -#ifndef cmt_vertex_h -#define cmt_vertex_h -#ifdef __cplusplus -extern "C" { -#endif - -#include "cmt/common.h" -#include "cmt/types.h" -#include "cmt/enums.h" -#include "cmt/resource.h" - -typedef enum MtVertexFormat { - MtVertexFormatInvalid = 0, - - MtVertexFormatUChar2 = 1, - MtVertexFormatUChar3 = 2, - MtVertexFormatUChar4 = 3, - - MtVertexFormatChar2 = 4, - MtVertexFormatChar3 = 5, - MtVertexFormatChar4 = 6, - - MtVertexFormatUChar2Normalized = 7, - MtVertexFormatUChar3Normalized = 8, - MtVertexFormatUChar4Normalized = 9, - - MtVertexFormatChar2Normalized = 10, - MtVertexFormatChar3Normalized = 11, - MtVertexFormatChar4Normalized = 12, - - MtVertexFormatUShort2 = 13, - MtVertexFormatUShort3 = 14, - MtVertexFormatUShort4 = 15, - - MtVertexFormatShort2 = 16, - MtVertexFormatShort3 = 17, - MtVertexFormatShort4 = 18, - - MtVertexFormatUShort2Normalized = 19, - MtVertexFormatUShort3Normalized = 20, - MtVertexFormatUShort4Normalized = 21, - - MtVertexFormatShort2Normalized = 22, - MtVertexFormatShort3Normalized = 23, - MtVertexFormatShort4Normalized = 24, - - MtVertexFormatHalf2 = 25, - MtVertexFormatHalf3 = 26, - MtVertexFormatHalf4 = 27, - - MtVertexFormatFloat = 28, - MtVertexFormatFloat2 = 29, - MtVertexFormatFloat3 = 30, - MtVertexFormatFloat4 = 31, - - MtVertexFormatInt = 32, - MtVertexFormatInt2 = 33, - MtVertexFormatInt3 = 34, - MtVertexFormatInt4 = 35, - - MtVertexFormatUInt = 36, - MtVertexFormatUInt2 = 37, - MtVertexFormatUInt3 = 38, - MtVertexFormatUInt4 = 39, - - MtVertexFormatInt1010102Normalized = 40, - MtVertexFormatUInt1010102Normalized = 41, - - MtVertexFormatUChar4Normalized_BGRA = 42, - - MtVertexFormatUChar = 45, - MtVertexFormatChar = 46, - MtVertexFormatUCharNormalized = 47, - MtVertexFormatCharNormalized = 48, - - MtVertexFormatUShort = 49, - MtVertexFormatShort = 50, - MtVertexFormatUShortNormalized = 51, - MtVertexFormatShortNormalized = 52, - - MtVertexFormatHalf = 53 -} MtVertexFormat MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)); - -typedef enum MtVertexStepFunction { - MtVertexStepFunctionConstant = 0, - MtVertexStepFunctionPerVertex = 1, - MtVertexStepFunctionPerInstance = 2, - MtVertexStepFunctionPerPatch = 3, - MtVertexStepFunctionPerPatchControlPoint = 4 -} MtVertexStepFunction MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)); - -/* -typedef struct MtVertexAttribDesc { - MtVertexFormat format; - uint32_t offset; - uint32_t bufferIndex; -} MtVertexAttribDesc; - -typedef struct MtVertexBufferLayoutDesc { - MtVertexStepFunction stepFunction; - uint32_t stepRate; - uint32_t stride; -} MtVertexBufferLayoutDesc; -*/ - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -MtVertexDescriptor* -mtVertexDescNew(void); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtVertexAttrib(MtVertexDescriptor * __restrict vertex, - uint32_t attribIndex, - MtVertexFormat format, - uint32_t offset, - uint32_t bufferIndex); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtVertexLayout(MtVertexDescriptor * __restrict vertex, - uint32_t layoutIndex, - uint32_t stride, - uint32_t stepRate, - MtVertexStepFunction stepFunction); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtSetVertexDesc(MtRenderPipeline * __restrict pipeline, - MtVertexDescriptor * __restrict vert); - -#ifdef __cplusplus -} -#endif - -#endif /* cmt_vertex_h */ diff --git a/deps/cmt/include/cmt/performance_shaders/device.h b/deps/cmt/include/cmt/performance_shaders/device.h deleted file mode 100644 index fa7b8a2d..00000000 --- a/deps/cmt/include/cmt/performance_shaders/device.h +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (c), Recep Aslantas. - * MIT License (MIT), http://opensource.org/licenses/MIT - */ - -#ifndef cmt_mps_device_h -#define cmt_mps_device_h - -#ifdef __cplusplus -extern "C" { -#endif - -#include "cmt/common.h" -#include "cmt/types.h" - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(9.0)) -bool -mtMPSSupportsMTLDevice(MtDevice* device); - -#ifdef __cplusplus -} -#endif -#endif /* cmt_mps_device_h */ diff --git a/deps/cmt/include/cmt/performance_shaders/matrix.h b/deps/cmt/include/cmt/performance_shaders/matrix.h deleted file mode 100644 index 7b669644..00000000 --- a/deps/cmt/include/cmt/performance_shaders/matrix.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c), Recep Aslantas. - * MIT License (MIT), http://opensource.org/licenses/MIT - */ - -#ifndef cmt_mps_matrix_h -#define cmt_mps_matrix_h - -#ifdef __cplusplus -extern "C" { -#endif - -#include "cmt/common.h" -#include "cmt/types.h" - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -MtMPSMatrixDescriptor* -mtNewMatrixDescriptorWithRows(NsUInteger rows, NsUInteger columns, NsUInteger rowBytes, - uint32_t dataType); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(10.0)) -MtMPSMatrix* -mtNewMPSMatrixInitWithBuffer(MtBuffer *buffer, MtMPSMatrixDescriptor *descriptor); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(10.0)) -MtMPSMatrixMultiplication* -mtNewMPSMatrixMultiplication(MtDevice *device, bool transposeLeft, bool transposeRight, - NsUInteger resultRows, NsUInteger resultColumns, - NsUInteger interiorColumns, double alpha, double beta); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(10.0)) -void -mtMPSMatMulEncodeToCommandBuffer(MtMPSMatrixMultiplication *matMul, MtCommandBuffer *commandBuffer, MtMPSMatrix * leftMatrix, - MtMPSMatrix *rightMatrix, MtMPSMatrix *resultMatrix); - -#ifdef __cplusplus -} -#endif -#endif /* cmt_mps_matrix_h */ diff --git a/deps/cmt/include/cmt/pixelformat.h b/deps/cmt/include/cmt/pixelformat.h deleted file mode 100644 index 401e4496..00000000 --- a/deps/cmt/include/cmt/pixelformat.h +++ /dev/null @@ -1,179 +0,0 @@ -/* - * Copyright (c), Recep Aslantas. - * MIT License (MIT), http://opensource.org/licenses/MIT - */ - -#ifndef cmt_pixelformat_h -#define cmt_pixelformat_h - -#include "common.h" - -typedef enum MtPixelFormat { - MtPixelFormatInvalid = 0, - - /* Normal 8 bit formats */ - MtPixelFormatA8Unorm = 1, - MtPixelFormatR8Unorm = 10, - MtPixelFormatR8Unorm_sRGB = 11, - MtPixelFormatR8Snorm = 12, - MtPixelFormatR8Uint = 13, - MtPixelFormatR8Sint = 14, - - /* Normal 16 bit formats */ - MtPixelFormatR16Unorm = 20, - MtPixelFormatR16Snorm = 22, - MtPixelFormatR16Uint = 23, - MtPixelFormatR16Sint = 24, - MtPixelFormatR16Float = 25, - - MtPixelFormatRG8Unorm = 30, - MtPixelFormatRG8Unorm_sRGB = 31, - MtPixelFormatRG8Snorm = 32, - MtPixelFormatRG8Uint = 33, - MtPixelFormatRG8Sint = 34, - - /* Packed 16 bit formats */ - MtPixelFormatB5G6R5Unorm = 40, - MtPixelFormatA1BGR5Unorm = 41, - MtPixelFormatABGR4Unorm = 42, - MtPixelFormatBGR5A1Unorm = 43, - - /* Normal 32 bit formats */ - MtPixelFormatR32Uint = 53, - MtPixelFormatR32Sint = 54, - MtPixelFormatR32Float = 55, - MtPixelFormatRG16Unorm = 60, - MtPixelFormatRG16Snorm = 62, - MtPixelFormatRG16Uint = 63, - MtPixelFormatRG16Sint = 64, - MtPixelFormatRG16Float = 65, - MtPixelFormatRGBA8Unorm = 70, - MtPixelFormatRGBA8Unorm_sRGB = 71, - MtPixelFormatRGBA8Snorm = 72, - MtPixelFormatRGBA8Uint = 73, - MtPixelFormatRGBA8Sint = 74, - MtPixelFormatBGRX8Unorm = 75, - MtPixelFormatBGRA8Unorm = 80, - MtPixelFormatBGRA8Unorm_sRGB = 81, - - /* Packed 32 bit formats */ - MtPixelFormatRGB10A2Unorm = 90, - MtPixelFormatRGB10A2Uint = 91, - MtPixelFormatRG11B10Float = 92, - MtPixelFormatRGB9E5Float = 93, - MtPixelFormatBGR10A2Unorm = 94, - MtPixelFormatBGR10_XR = 554, - MtPixelFormatBGR10_XR_sRGB = 555, - - /* Normal 64 bit formats */ - - MtPixelFormatRG32Uint = 103, - MtPixelFormatRG32Sint = 104, - MtPixelFormatRG32Float = 105, - MtPixelFormatRGBA16Unorm = 110, - MtPixelFormatRGBA16Snorm = 112, - MtPixelFormatRGBA16Uint = 113, - MtPixelFormatRGBA16Sint = 114, - MtPixelFormatRGBA16Float = 115, - MtPixelFormatBGRA10_XR = 552, - MtPixelFormatBGRA10_XR_sRGB = 553, - - /* Normal 128 bit formats */ - - MtPixelFormatRGBA32Uint = 123, - MtPixelFormatRGBA32Sint = 124, - MtPixelFormatRGBA32Float = 125, - - /* Compressed formats. */ - - /* S3TC/DXT */ - MtPixelFormatBC1_RGBA = 130, - MtPixelFormatBC1_RGBA_sRGB = 131, - MtPixelFormatBC2_RGBA = 132, - MtPixelFormatBC2_RGBA_sRGB = 133, - MtPixelFormatBC3_RGBA = 134, - MtPixelFormatBC3_RGBA_sRGB = 135, - - /* RGTC */ - MtPixelFormatBC4_RUnorm = 140, - MtPixelFormatBC4_RSnorm = 141, - MtPixelFormatBC5_RGUnorm = 142, - MtPixelFormatBC5_RGSnorm = 143, - - /* BPTC */ - MtPixelFormatBC6H_RGBFloat = 150, - MtPixelFormatBC6H_RGBUfloat = 151, - MtPixelFormatBC7_RGBAUnorm = 152, - MtPixelFormatBC7_RGBAUnorm_sRGB = 153, - - /* PVRTC */ - MtPixelFormatPVRTC_RGB_2BPP = 160, - MtPixelFormatPVRTC_RGB_2BPP_sRGB = 161, - MtPixelFormatPVRTC_RGB_4BPP = 162, - MtPixelFormatPVRTC_RGB_4BPP_sRGB = 163, - MtPixelFormatPVRTC_RGBA_2BPP = 164, - MtPixelFormatPVRTC_RGBA_2BPP_sRGB = 165, - MtPixelFormatPVRTC_RGBA_4BPP = 166, - MtPixelFormatPVRTC_RGBA_4BPP_sRGB = 167, - - /* ETC2 */ - MtPixelFormatEAC_R11Unorm = 170, - MtPixelFormatEAC_R11Snorm = 172, - MtPixelFormatEAC_RG11Unorm = 174, - MtPixelFormatEAC_RG11Snorm = 176, - MtPixelFormatEAC_RGBA8 = 178, - MtPixelFormatEAC_RGBA8_sRGB = 179, - - MtPixelFormatETC2_RGB8 = 180, - MtPixelFormatETC2_RGB8_sRGB = 181, - MtPixelFormatETC2_RGB8A1 = 182, - MtPixelFormatETC2_RGB8A1_sRGB = 183, - - /* ASTC */ - MtPixelFormatASTC_4x4_sRGB = 186, - MtPixelFormatASTC_5x4_sRGB = 187, - MtPixelFormatASTC_5x5_sRGB = 188, - MtPixelFormatASTC_6x5_sRGB = 189, - MtPixelFormatASTC_6x6_sRGB = 190, - MtPixelFormatASTC_8x5_sRGB = 192, - MtPixelFormatASTC_8x6_sRGB = 193, - MtPixelFormatASTC_8x8_sRGB = 194, - MtPixelFormatASTC_10x5_sRGB = 195, - MtPixelFormatASTC_10x6_sRGB = 196, - MtPixelFormatASTC_10x8_sRGB = 197, - MtPixelFormatASTC_10x10_sRGB = 198, - MtPixelFormatASTC_12x10_sRGB = 199, - MtPixelFormatASTC_12x12_sRGB = 200, - - MtPixelFormatASTC_4x4_LDR = 204, - MtPixelFormatASTC_5x4_LDR = 205, - MtPixelFormatASTC_5x5_LDR = 206, - MtPixelFormatASTC_6x5_LDR = 207, - MtPixelFormatASTC_6x6_LDR = 208, - MtPixelFormatASTC_8x5_LDR = 210, - MtPixelFormatASTC_8x6_LDR = 211, - MtPixelFormatASTC_8x8_LDR = 212, - MtPixelFormatASTC_10x5_LDR = 213, - MtPixelFormatASTC_10x6_LDR = 214, - MtPixelFormatASTC_10x8_LDR = 215, - MtPixelFormatASTC_10x10_LDR = 216, - MtPixelFormatASTC_12x10_LDR = 217, - MtPixelFormatASTC_12x12_LDR = 218, - MtPixelFormatGBGR422 = 240, - MtPixelFormatBGRG422 = 241, - - /* Depth */ - MtPixelFormatDepth16Unorm = 250, - MtPixelFormatDepth32Float = 252, - - /* Stencil */ - MtPixelFormatStencil8 = 253, - - /* Depth Stencil */ - MtPixelFormatDepth24Unorm_Stencil8 = 255, - MtPixelFormatDepth32Float_Stencil8 = 260, - MtPixelFormatX32_Stencil8 = 261, - MtPixelFormatX24_Stencil8 = 262 -} MtPixelFormat; - -#endif /* cmt_pixelformat_h */ diff --git a/deps/cmt/include/cmt/reflection/argument.h b/deps/cmt/include/cmt/reflection/argument.h deleted file mode 100644 index 3d792003..00000000 --- a/deps/cmt/include/cmt/reflection/argument.h +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright (c), Recep Aslantas. - * MIT License (MIT), http://opensource.org/licenses/MIT - */ - -#ifndef cmt_argument_ -#define cmt_argument_ -#ifdef __cplusplus -extern "C" { -#endif - -#include "cmt/common.h" -#include "cmt/types.h" -#include "cmt/enums.h" - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -const char* -mtArgumentName(MtArgument *arg); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -bool -mtArgumentActive(MtArgument *arg); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -NsUInteger -mtArgumentIndex(MtArgument *arg); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -MtArgumentType -mtArgumentType(MtArgument *arg); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -MtArgumentAccess -mtArgumentAccess(MtArgument *arg); - -// Buffer -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -NsUInteger -mtArgumentBufferAlignment(MtArgument *arg); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -NsUInteger -mtArgumentBufferDataSize(MtArgument *arg); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -MtDataType -mtArgumentBufferDataType(MtArgument *arg); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -MtStructType* -mtArgumentBufferStructType(MtArgument *arg); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -MtPointerType* -mtArgumentBufferPointerType(MtArgument *arg); - -// Array -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(10.0)) -NsUInteger -mtArgumentArrayLength(MtArgument *arg); - -// Array -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -NsUInteger -mtArgumentThreadgroupMemoryAlignment(MtArgument *arg); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -NsUInteger -mtArgumentThreadgroupMemoryDataSize(MtArgument *arg); - -#ifdef __cplusplus -} -#endif -#endif /* cmt_argument_ */ diff --git a/deps/cmt/include/cmt/reflection/descriptor.h b/deps/cmt/include/cmt/reflection/descriptor.h deleted file mode 100644 index cddb76c6..00000000 --- a/deps/cmt/include/cmt/reflection/descriptor.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (c), Recep Aslantas. - * MIT License (MIT), http://opensource.org/licenses/MIT - */ - -#ifndef cmt_descriptor_h -#define cmt_descriptor_h -#ifdef __cplusplus -extern "C" { -#endif - -#include "cmt/common.h" -#include "cmt/types.h" -#include "cmt/enums.h" - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -MtComputePipelineReflection* -mtNewComputePipelineReflection(void); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -const MtArgument * -mtComputePipelinereflectionArguments(MtComputePipelineReflection *refl); - -#ifdef __cplusplus -} -#endif -#endif /* cmt_descriptor_h */ diff --git a/deps/cmt/include/cmt/reflection/pointer_type.h b/deps/cmt/include/cmt/reflection/pointer_type.h deleted file mode 100644 index a695a9ce..00000000 --- a/deps/cmt/include/cmt/reflection/pointer_type.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c), Recep Aslantas. - * MIT License (MIT), http://opensource.org/licenses/MIT - */ - -#ifndef cmt_pointer_type_h -#define cmt_pointer_type_h -#ifdef __cplusplus -extern "C" { -#endif - -#include "cmt/common.h" -#include "cmt/types.h" -#include "cmt/enums.h" - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -MtDataType -mtPointerTypeElementType(MtPointerType *ptr); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -MtArgumentAccess -mtPointerTypeAccess(MtPointerType *ptr); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -NsUInteger -mtPointerTypeAlignment(MtPointerType *ptr); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -NsUInteger -mtPointerTypeDataSize(MtPointerType *ptr); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -bool -mtPointerTypeElementIsArgumentBuffer(MtPointerType *ptr); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -MtStructType* -mtPointerTypeElementStructType(MtPointerType *ptr); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -MtArrayType* -mtPointerTypeElementArrayType(MtPointerType *ptr); - -#ifdef __cplusplus -} -#endif -#endif /* cmt_compute_pipeline_h */ diff --git a/deps/cmt/include/cmt/rendering/depthstencil.h b/deps/cmt/include/cmt/rendering/depthstencil.h deleted file mode 100644 index a50bce8e..00000000 --- a/deps/cmt/include/cmt/rendering/depthstencil.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c), Recep Aslantas. - * MIT License (MIT), http://opensource.org/licenses/MIT - */ - -#ifndef cmt_depthstencil_h -#define cmt_depthstencil_h -#ifdef __cplusplus -extern "C" { -#endif - -#include "cmt/common.h" -#include "cmt/types.h" -#include "cmt/enums.h" - -typedef enum MtCompareFunction { - MtCompareFunctionNever = 0, - MtCompareFunctionLess = 1, - MtCompareFunctionEqual = 2, - MtCompareFunctionLessEqual = 3, - MtCompareFunctionGreater = 4, - MtCompareFunctionNotEqual = 5, - MtCompareFunctionGreaterEqual = 6, - MtCompareFunctionAlways = 7, -} MtCompareFunction; - -typedef enum MtStencilOperation { - MtStencilOperationKeep = 0, - MtStencilOperationZero = 1, - MtStencilOperationReplace = 2, - MtStencilOperationIncrementClamp = 3, - MtStencilOperationDecrementClamp = 4, - MtStencilOperationInvert = 5, - MtStencilOperationIncrementWrap = 6, - MtStencilOperationDecrementWrap = 7, -} MtStencilOperation; - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -MtDepthStencil* -mtDepthStencil(MtCompareFunction depthCompareFunc, bool depthWriteEnabled); - -#ifdef __cplusplus -} -#endif -#endif /* cmt_depthstencil_h */ diff --git a/deps/cmt/include/cmt/rendering/pass.h b/deps/cmt/include/cmt/rendering/pass.h deleted file mode 100644 index 221b3104..00000000 --- a/deps/cmt/include/cmt/rendering/pass.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c), Recep Aslantas. - * MIT License (MIT), http://opensource.org/licenses/MIT - */ - -#ifndef cmt_pass_h -#define cmt_pass_h -#ifdef __cplusplus -extern "C" { -#endif - -#include "cmt/common.h" -#include "cmt/types.h" -#include "cmt/enums.h" - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -MtRenderPassDesc* -mtNewPass(void); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtPassTexture(MtRenderPassDesc *pass, - int colorAttch, - MtTexture *tex); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtPassLoadAction(MtRenderPassDesc *pass, - int colorAttch, - MtLoadAction action); -#ifdef __cplusplus -} -#endif -#endif /* cmt_pass_h */ diff --git a/deps/cmt/include/cmt/rendering/pipeline.h b/deps/cmt/include/cmt/rendering/pipeline.h deleted file mode 100644 index ed6fbfa3..00000000 --- a/deps/cmt/include/cmt/rendering/pipeline.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (c), Recep Aslantas. - * MIT License (MIT), http://opensource.org/licenses/MIT - */ - -#ifndef cmt_pipeline_h -#define cmt_pipeline_h -#ifdef __cplusplus -extern "C" { -#endif - -#include "cmt/common.h" -#include "cmt/types.h" -#include "cmt/enums.h" -#include "cmt/error.h" -#include "cmt/pixelformat.h" - -typedef enum MtFuncType { - MT_FUNC_VERT = 1, - MT_FUNC_FRAG = 2 -} MtFuncType; - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -MtRenderDesc* -mtNewRenderPipeline(MtPixelFormat pixelFormat); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtSetFunc(MtRenderDesc *pipDesc, - MtFunction *func, - MtFuncType functype); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -MtRenderPipeline* -mtNewRenderState(MtDevice *device, - MtRenderDesc *pipDesc, - NsError **error); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtColorPixelFormat(MtRenderDesc * __restrict renderdesc, - uint32_t index, - MtPixelFormat pixelFormat); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtDepthPixelFormat(MtRenderDesc * __restrict renderdesc, - MtPixelFormat pixelFormat); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtStencilPixelFormat(MtRenderDesc * __restrict renderdesc, - MtPixelFormat pixelFormat); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtSampleCount(MtRenderDesc * __restrict renderdesc, - uint32_t sampleCount); - -#ifdef __cplusplus -} -#endif -#endif /* cmt_pipeline_h */ diff --git a/deps/cmt/include/cmt/resource.h b/deps/cmt/include/cmt/resource.h deleted file mode 100644 index 1555bb2b..00000000 --- a/deps/cmt/include/cmt/resource.h +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright (c), Recep Aslantas. - * MIT License (MIT), http://opensource.org/licenses/MIT - */ - -#ifndef cmt_resource_h -#define cmt_resource_h -#ifdef __cplusplus -extern "C" { -#endif - -#include "common.h" - -typedef enum MtCPUCacheMode { - MtCPUCacheModeDefaultCache = 0, - MtCPUCacheModeWriteCombined = 1 -} MtCPUCacheMode; - -typedef enum MtHazardTrackingMode { - MtHazardTrackingModeDefault = 0, - MtHazardTrackingModeUntracked = 1, - MtHazardTrackingModeTracked = 2 -} MtHazardTrackingMode; - -typedef enum MtStorageMode { - MtStorageModeShared = 0, - MtStorageModeManaged = 1, - MtStorageModePrivate = 2, - MtStorageModeMemoryless = 3 -} MtStorageMode; - -typedef enum MtResourceOptions { - MtResourceCPUCacheModeDefaultCache = MtCPUCacheModeDefaultCache, - MtResourceCPUCacheModeWriteCombined = MtCPUCacheModeWriteCombined, - - MtResourceStorageModeShared = MtStorageModeShared << 4, - MtResourceStorageModeManaged = MtStorageModeManaged << 4, - MtResourceStorageModePrivate = MtStorageModePrivate << 4, - MtResourceStorageModeMemoryless = MtStorageModeMemoryless << 4, - - MtResourceHazardTrackingModeDefault = MtHazardTrackingModeDefault << 8, - MtResourceHazardTrackingModeUntracked = MtHazardTrackingModeUntracked << 8, - MtResourceHazardTrackingModeTracked = MtHazardTrackingModeTracked << 8 -} MtResourceOptions; - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -MtDevice* -mtResourceDevice(MtResource *res); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -const char* -mtResourceLabel(MtResource *res); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtResourceLabelSet(MtResource *res, const char* label); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -MtCPUCacheMode -mtResourceCPUCacheMode(MtResource *res); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -MtStorageMode -mtResourceStorageMode(MtResource *res); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.15), mt_ios(13.0)) -MtHazardTrackingMode -mtResourceHazardTrackingMode(MtResource *res); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.15), mt_ios(13.0)) -MtResourceOptions -mtResourceOptions(MtResource *res); - -#ifdef __cplusplus -} -#endif - -#endif /* cmt_resource_h */ diff --git a/deps/cmt/include/cmt/types.h b/deps/cmt/include/cmt/types.h deleted file mode 100644 index b86fd4bf..00000000 --- a/deps/cmt/include/cmt/types.h +++ /dev/null @@ -1,15 +0,0 @@ -/* - * Copyright (c), Recep Aslantas. - * MIT License (MIT), http://opensource.org/licenses/MIT - */ - -#ifndef cmt_types_h -#define cmt_types_h - -#include "common.h" - -#include "types_foundation.h" -#include "types_metal.h" -#include "types_mps.h" - -#endif /* cmt_types_h */ diff --git a/deps/cmt/include/cmt/types_foundation.h b/deps/cmt/include/cmt/types_foundation.h deleted file mode 100644 index 4e7230dc..00000000 --- a/deps/cmt/include/cmt/types_foundation.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c), Recep Aslantas. - * MIT License (MIT), http://opensource.org/licenses/MIT - */ - -#ifndef cmt_types_foundation_h -#define cmt_types_foundation_h - -#include "common.h" - -#if INTPTR_MAX == INT64_MAX -// 64-bit -typedef unsigned long NsUInteger; -typedef long NsInteger; -#elif INTPTR_MAX == INT32_MAX -// 32-bit -typedef unsigned int NsUInteger; -typedef int NsInteger; -#endif - -typedef double CfTimeInterval; - -typedef struct NsRange { - NsUInteger location; - NsUInteger length; -} NsRange; - -typedef void NsError; - -typedef struct { - char ** keys; - char ** values; -} NsDictionaryStringString; - -#endif /* cmt_types_foundation_h */ diff --git a/deps/cmt/include/cmt/types_metal.h b/deps/cmt/include/cmt/types_metal.h deleted file mode 100644 index d5ab1290..00000000 --- a/deps/cmt/include/cmt/types_metal.h +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright (c), Recep Aslantas. - * MIT License (MIT), http://opensource.org/licenses/MIT - */ - -#ifndef cmt_types_metal_h -#define cmt_types_metal_h - -#include "cmt/common.h" -#include "cmt/types_foundation.h" -#include "cmt/enums.h" - -typedef struct { - NsUInteger width, height, depth; -} MtSize; - -typedef struct { - NsUInteger x, y, z; -} MtOrigin; - -typedef struct { - NsUInteger size; - NsUInteger align; -} MtSizeAndAlign; - -typedef void MtDevice; -typedef void MtRenderDesc; -typedef void MtRenderPipeline; -typedef void MtCommandQueue; -typedef void MtCommandEncoder; -typedef void MtBlitCommandEncoder; -typedef void MtLibrary; -typedef void MtBinaryArchive; -typedef void MtBinaryArchiveDescriptor; -typedef void MtRenderPassDesc; -typedef void MtTexture; -typedef void MtCommandBuffer; -typedef void MtCommandBufferDescriptor; -typedef void MtCommandBufferEncoderInfo; -typedef void MtDrawable; -typedef void MtVertexDescriptor; -typedef void MtTextureDescriptor; -typedef void MtIndirectCommandBufferDescriptor; -typedef void MtIndirectCommandBuffer; -typedef void MtIndirectComputeCommand; -typedef void MtIndirectRenderCommand; -typedef void MtDepthStencil; -typedef void MtBuffer; -typedef void MtCompileOptions; - -typedef void MtFunction; -typedef void MtFunctionDescriptor; -typedef void MtFunctionConstant; -typedef void MtFunctionConstantValues; - -typedef void MtEvent; -typedef void MtSharedEvent; -typedef void MtSharedEventHandle; -typedef void MtFence; -typedef void (^MtSharedEventNotificationBlock)(MtSharedEvent *ev, uint64_t value); -typedef void (*MtCommandBufferHandlerFun)(MtCommandBuffer * buf); -typedef void MtSharedEventListener; - -typedef void MtResource; -typedef void MtHeap; -typedef void MtHeapDescriptor; - -typedef void MtAttribute; -typedef void MtVertexAttribute; - -typedef void MtComputePipelineState; -typedef void MtSamplerState; - -typedef void MtRenderCommandEncoder; -typedef void MtComputeCommandEncoder; -typedef void MtBlitCommandEncoder; -typedef void MtResourceStateCommandEncoder; - -typedef void MtCounterSampleBuffer; - -typedef void MtArgumentEncoder; -typedef void MtAutoreleasedArgument; -typedef void MtArgument; -typedef void MtArgumentDescriptor; - -typedef void MtComputePipelineDescriptor; -typedef void MtPointerType; -typedef void MtArrayType; -typedef void MtStructType; - -typedef void MtComputePipelineReflection; -typedef void MtRenderPipelineReflection; - -typedef void MtCaptureManager; -typedef void MtCaptureScope; -typedef void MtCaptureDescriptor; - -typedef struct { - uint32_t threadgroupsPerGrid[3]; -} MtDispatchThreadgroupsIndirectArguments; - -typedef struct { - uint32_t stageInOrigin[3]; - uint32_t stageInSize[3]; -} MtStageInRegionIndirectArguments; - -typedef struct -{ - MtOrigin origin; - MtSize size; -} MtRegion; - -typedef struct -{ - uint32_t location; - uint32_t length; -} MtIndirectCommandBufferExecutionRange; - -typedef struct -{ - MtTextureSwizzle red; - MtTextureSwizzle green; - MtTextureSwizzle blue; - MtTextureSwizzle alpha; -} MtTextureSwizzleChannels; - -#endif /* cmt_types_metal_h */ diff --git a/deps/cmt/include/cmt/types_mps.h b/deps/cmt/include/cmt/types_mps.h deleted file mode 100644 index 99de5dc7..00000000 --- a/deps/cmt/include/cmt/types_mps.h +++ /dev/null @@ -1,15 +0,0 @@ -/* - * Copyright (c), Recep Aslantas. - * MIT License (MIT), http://opensource.org/licenses/MIT - */ - -#ifndef cmt_types_mps_h -#define cmt_types_mps_h - -typedef void MtMPSVectorDescriptor; -typedef void MtMPSVector; -typedef void MtMPSMatrixDescriptor; -typedef void MtMPSMatrix; -typedef void MtMPSMatrixMultiplication; - -#endif /* cmt_types_mps_h */ diff --git a/deps/cmt/include/impl/common.h b/deps/cmt/include/impl/common.h deleted file mode 100644 index 92e98bc0..00000000 --- a/deps/cmt/include/impl/common.h +++ /dev/null @@ -1,14 +0,0 @@ -/* - * Copyright (c), Recep Aslantas. - * MIT License (MIT), http://opensource.org/licenses/MIT - */ - -#ifndef src_common_h -#define src_common_h - -#import -#import - -#import "conversion.h" - -#endif /* src_common_h */ diff --git a/deps/cmt/include/impl/conversion.h b/deps/cmt/include/impl/conversion.h deleted file mode 100644 index 4f5cbbbe..00000000 --- a/deps/cmt/include/impl/conversion.h +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Copyright (c), Recep Aslantas. - * MIT License (MIT), http://opensource.org/licenses/MIT - */ - -#import -#import -#import "cmt/types.h" - -MT_HIDE -MT_INLINE -const char* -mtNSURLFileSystemRepresentation(NSURL *url) { - return (const char*)[(NSURL*)url fileSystemRepresentation]; -} - -MT_HIDE -MT_INLINE -NSString* -mtNSString(const char *str) { - return [NSString stringWithCString: str - encoding: NSUTF8StringEncoding]; -} - -MT_HIDE -MT_INLINE -NSURL* -mtNSURL(const char *str){ - return [NSURL fileURLWithPath: mtNSString(str)]; -} - -MT_HIDE -MT_INLINE -const char* -Cstring(NSString* str) { - return [str cStringUsingEncoding:NSUTF8StringEncoding]; -} - -MT_HIDE -MT_INLINE -MTLSize -mtMTLSize(MtSize size) { - return MTLSizeMake(size.width, size.height, size.depth); -} - -MT_HIDE -MT_INLINE -MtSize -mtSize(MTLSize size) { - MtSize sz = {size.width, size.height, size.depth}; - return sz; -} - -MT_HIDE -MT_INLINE -MTLOrigin -mtMTLOrigin(MtOrigin orig) { - return MTLOriginMake(orig.x, orig.y, orig.z); -} - -MT_HIDE -MT_INLINE -MtOrigin -mtOrigin(MTLOrigin orig) { - MtOrigin o = {orig.x, orig.y, orig.z}; - return o; -} - -MT_HIDE -MT_INLINE -MTLSizeAndAlign -mtMTLSizeAndAlign(MtSizeAndAlign s) { - MTLSizeAndAlign o = {s.size, s.align}; - return o; -} - -MT_HIDE -MT_INLINE -MtSizeAndAlign -mtSizeAndAlign(MTLSizeAndAlign s) { - MtSizeAndAlign o = {s.size, s.align}; - return o; -} - - -MT_HIDE -MT_INLINE -NSRange -mtNSRange(NsRange range) { - return NSMakeRange(range.location, range.length); -} - -MT_HIDE -MT_INLINE -NsRange -mtRange(NSRange range) { - NsRange r = {range.location, range.length}; - return r; -} - -MT_HIDE -MT_INLINE -const char* -CstringFromDict(NSDictionary *dict) { - return Cstring([NSString stringWithFormat:@"Dictionary: %@", dict]); -} - -MT_HIDE -MT_INLINE -MTLRegion -mtMTLRegion(MtRegion region) { - MTLRegion reg = {mtMTLOrigin(region.origin), mtMTLSize(region.size)}; - return reg; -} - -MT_HIDE -MT_INLINE -MtRegion -mtRegion(MtRegion region) { - MtRegion reg = {region.origin, region.size}; - return reg; -} - -MT_HIDE -MT_INLINE -MtIndirectCommandBufferExecutionRange -mtIndirectCommandBufferExecutionRange(MTLIndirectCommandBufferExecutionRange range) { - MtIndirectCommandBufferExecutionRange icbRange = {range.location, range.length}; - return icbRange; -} - -MT_HIDE -MT_INLINE -MTLIndirectCommandBufferExecutionRange -mtMTLIndirectCommandBufferExecutionRange(MtIndirectCommandBufferExecutionRange range) { - MTLIndirectCommandBufferExecutionRange icbRange = {range.location, range.length}; - return icbRange; -} - - diff --git a/deps/cmt/src/argument_buffer.m b/deps/cmt/src/argument_buffer.m deleted file mode 100644 index a3c3d108..00000000 --- a/deps/cmt/src/argument_buffer.m +++ /dev/null @@ -1,7 +0,0 @@ -/* - * Copyright (c), Recep Aslantas. - * MIT License (MIT), http://opensource.org/licenses/MIT - */ - -#include "cmt/argument_buffer.h" -#include "impl/common.h" \ No newline at end of file diff --git a/deps/cmt/src/argument_descriptor.m b/deps/cmt/src/argument_descriptor.m deleted file mode 100644 index 4963d569..00000000 --- a/deps/cmt/src/argument_descriptor.m +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright (c), Recep Aslantas. - * MIT License (MIT), http://opensource.org/licenses/MIT - */ - -#include "cmt/argument_descriptor.h" -#include "impl/common.h" - -CF_RETURNS_RETAINED -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -MtArgumentDescriptor* -mtNewArgumentDescriptor() { - return [MTLArgumentDescriptor new]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -MtDataType -mtArgumentDescriptorDataType(MtArgumentDescriptor *desc) { - return (MtDataType)[(MTLArgumentDescriptor*)desc dataType]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -void -mtArgumentDescriptorDataTypeSet(MtArgumentDescriptor *desc, MtDataType dataType) { - [(MTLArgumentDescriptor*)desc setDataType:(MTLDataType)dataType]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -NsUInteger -mtArgumentDescriptorIndex(MtArgumentDescriptor *desc) { - return [(MTLArgumentDescriptor*)desc index]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -void -mtArgumentDescriptorIndexSet(MtArgumentDescriptor *desc, NsUInteger index) { - [(MTLArgumentDescriptor*)desc setIndex: index]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -MtArgumentAccess -mtArgumentDescriptorAccess(MtArgumentDescriptor *desc) { - return (MtArgumentAccess)[(MTLArgumentDescriptor*)desc access]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -void -mtArgumentDescriptorAccessSet(MtArgumentDescriptor *desc, MtArgumentAccess access) { - [(MTLArgumentDescriptor*)desc setIndex: (MTLArgumentAccess)access]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -NsUInteger -mtArgumentDescriptorArrayLength(MtArgumentDescriptor *desc) { - return [(MTLArgumentDescriptor*)desc arrayLength]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -void -mtArgumentDescriptorArrayLengthSet(MtArgumentDescriptor *desc, NsUInteger index) { - [(MTLArgumentDescriptor*)desc setArrayLength: index]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -NsUInteger -mtArgumentDescriptorConstantBlockAlignment(MtArgumentDescriptor *desc) { - return [(MTLArgumentDescriptor*)desc constantBlockAlignment]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -void -mtArgumentDescriptorConstantBlockAlignmentSet(MtArgumentDescriptor *desc, NsUInteger alignment) { - [(MTLArgumentDescriptor*)desc setConstantBlockAlignment: alignment]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -MtTextureType -mtArgumentDescriptorTextureType(MtArgumentDescriptor *desc) { - return (MtTextureType)[(MTLArgumentDescriptor*)desc textureType]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -void -mtArgumentDescriptorTextureTypeSet(MtArgumentDescriptor *desc, MtTextureType textype) { - [(MTLArgumentDescriptor*)desc setTextureType: (MTLTextureType)textype]; -} diff --git a/deps/cmt/src/argument_encoder.m b/deps/cmt/src/argument_encoder.m deleted file mode 100644 index 6ab84f11..00000000 --- a/deps/cmt/src/argument_encoder.m +++ /dev/null @@ -1,157 +0,0 @@ -/* - * Copyright (c), Recep Aslantas. - * MIT License (MIT), http://opensource.org/licenses/MIT - */ - -#include "cmt/argument_encoder.h" -#include "impl/common.h" - -CF_RETURNS_RETAINED -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -MtArgumentEncoder* -mtNewArgumentEncoderWithBufferIndexFromFunction(MtFunction *function, NsUInteger bufferIndex) { - return [(id)function newArgumentEncoderWithBufferIndex: bufferIndex]; -} - -// TODO : the reflection info is an autoreleased pointer that will be populated with -// info on reflection information. Should probably look at retaining it. -CF_RETURNS_RETAINED -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -MtArgumentEncoder* -mtNewArgumentEncoderWithBufferIndexReflectionFromFunction(MtFunction *function, NsUInteger bufferIndex, MtAutoreleasedArgument *reflection) { - return [(id)function newArgumentEncoderWithBufferIndex: bufferIndex - reflection: (MTLAutoreleasedArgument *)reflection]; -} - -CF_RETURNS_RETAINED -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -MtArgumentEncoder* -mtNewArgumentEncoderWithBufferIndexFromArgumentBuffer(MtArgumentEncoder *ae, NsUInteger idx) { - return [(id)ae newArgumentEncoderForBufferAtIndex: idx]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -MtArgumentEncoder* -mtNewArgumentEncoder(MtDevice *device, MtArgumentDescriptor **arguments, uint64_t count) { - NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity: count]; - for (uint64_t i=0; i < count; i++) { - [array addObject: (MTLArgumentDescriptor*)arguments[i]]; - } - return [(id)device newArgumentEncoderWithArguments:array]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -NsUInteger -mtArgumentEncoderLength(MtArgumentEncoder *encoder) { - return [(id)encoder encodedLength]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -void -mtArgumentEncoderSetArgumentBufferWithOffset(MtArgumentEncoder *cce, MtBuffer *buf, NsUInteger offset) { - [(id)cce setArgumentBuffer: (id)buf - offset: offset]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -void -mtArgumentEncoderSetArgumentBufferWithOffsetForElement(MtArgumentEncoder *cce, MtBuffer *buf, NsUInteger startOffset, NsUInteger arrayElement) { - [(id)cce setArgumentBuffer: (id)buf - startOffset: startOffset - arrayElement: arrayElement]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -void -mtArgumentEncoderSetBufferOffsetAtIndex(MtArgumentEncoder *cce, MtBuffer *buf, NsUInteger offset, NsUInteger indx) { - [(id)cce setBuffer: (id)buf - offset: offset - atIndex: indx]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -void -mtArgumentSetBuffersOffsetsWithRange(MtArgumentEncoder *cce, MtBuffer **bufs, const NsUInteger *offsets, NsRange range) { - [(id)cce setBuffers: (id*)bufs - offsets: offsets - withRange: mtNSRange(range)]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -void -mtArgumentEncoderSetTextureAtIndex(MtArgumentEncoder *cce, MtTexture *tex, NsUInteger indx) { - [(id)cce setTexture: (id)tex - atIndex: indx]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -void -mtArgumentEncoderSetTexturesWithRange(MtArgumentEncoder *cce, MtTexture **textures, NsRange range) { - [(id)cce setTextures: (id*)textures - withRange: mtNSRange(range)]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -void -mtArgumentEncoderSetSamplerStateAtIndex(MtArgumentEncoder *cce, MtSamplerState *sampler, NsUInteger indx) { - [(id)cce setSamplerState: (id)sampler - atIndex: indx]; -} - - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -void -mtArgumentEncoderSetSamplerStatesWithRange(MtArgumentEncoder *cce, MtSamplerState **samplers, NsRange range) { - [(id)cce setSamplerStates: (id*)samplers - withRange: mtNSRange(range)]; -} - -/*MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -void -mtArgumentEncoderSetComputePipelineState(MtArgumentEncoder *cce, MtComputePipelineState *state, NsUInteger index) { - [(id)cce setComputePipelineState: (id)state - atIndex: index]; -} */ - -MT_EXPORT -void* -mtArgumentEncoderConstantDataAtIndex(MtArgumentEncoder *cce, NsUInteger index) { - return [(id)cce constantDataAtIndex: index]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.14), mt_ios(12.0)) -void -mtArgumentEncoderSetIndirectCommandBuffer(MtArgumentEncoder *cce, MtIndirectCommandBuffer *cbuf, NsUInteger index) { - [(id)cce setIndirectCommandBuffer: (id)cbuf - atIndex: index]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.14), mt_ios(12.0)) -void -mtArgumentEncoderSetIndirectCommandBuffers(MtArgumentEncoder *cce, MtIndirectCommandBuffer **cbufs, NsRange range) { - [(id)cce setIndirectCommandBuffers: (id*)cbufs - withRange: mtNSRange(range)]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -NsUInteger -mtArgumentEncoderAlignment(MtArgumentEncoder *cce) { - return [(id)cce alignment]; -} diff --git a/deps/cmt/src/capture/capture_descriptor.m b/deps/cmt/src/capture/capture_descriptor.m deleted file mode 100644 index c3df415e..00000000 --- a/deps/cmt/src/capture/capture_descriptor.m +++ /dev/null @@ -1,66 +0,0 @@ -#include "cmt/capture/capture_descriptor.h" -#include "impl/common.h" - -CF_RETURNS_RETAINED -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.15), mt_ios(13.0)) -MtCaptureDescriptor* -mtNewCaptureDescriptor() { - return [MTLCaptureDescriptor new]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.15), mt_ios(13.0)) -void* -mtCaptureDescriptorCaptureObject(MtCaptureDescriptor *desc) { - return (void*)[(MTLCaptureDescriptor*)desc captureObject]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.15), mt_ios(13.0)) -void -mtCaptureDescriptorCaptureObjectSetQueue(MtCaptureDescriptor *desc, MtCommandQueue *cmdq) { - [(MTLCaptureDescriptor*)desc setCaptureObject:(id)cmdq]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.15), mt_ios(13.0)) -void -mtCaptureDescriptorCaptureObjectSetDevice(MtCaptureDescriptor *desc, MtDevice *dev) { - [(MTLCaptureDescriptor*)desc setCaptureObject:(id)dev]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.15), mt_ios(13.0)) -void -mtCaptureDescriptorCaptureObjectSetScope(MtCaptureDescriptor *desc, MtCaptureScope *scope) { - [(MTLCaptureDescriptor*)desc setCaptureObject:(id)scope]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.15), mt_ios(13.0)) -MtCaptureDestination -mtCaptureDescriptorDestination(MtCaptureDescriptor *desc) { - return (MtCaptureDestination)[(MTLCaptureDescriptor*)desc destination]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.15), mt_ios(13.0)) -void -mtCaptureDescriptorDestinationSet(MtCaptureDescriptor *desc, MtCaptureDestination dest) { - [(MTLCaptureDescriptor*)desc setDestination:(MTLCaptureDestination)dest]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.15), mt_ios(13.0)) -const char* -mtCaptureDescriptorOutputURL(MtCaptureDescriptor *desc) { - return (const char*)mtNSURLFileSystemRepresentation((NSURL*)[(MTLCaptureDescriptor*)desc outputURL]); -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.15), mt_ios(13.0)) -void -mtCaptureDescriptorOutputURLSet(MtCaptureDescriptor *desc, const char *path) { - [(MTLCaptureDescriptor*)desc setOutputURL:mtNSURL(path)]; -} \ No newline at end of file diff --git a/deps/cmt/src/capture/capture_manager.m b/deps/cmt/src/capture/capture_manager.m deleted file mode 100644 index 01194197..00000000 --- a/deps/cmt/src/capture/capture_manager.m +++ /dev/null @@ -1,51 +0,0 @@ -#include "cmt/capture/capture_manager.h" -#include "impl/common.h" - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -MtCaptureManager* -mtSharedCaptureManager(void){ - return [MTLCaptureManager sharedCaptureManager]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -bool -mtSupportsDestination(MtCaptureManager *manager, MtCaptureDestination destination){ - return (bool)[(MTLCaptureManager*)manager supportsDestination:(MTLCaptureDestination)destination]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -bool -mtStartCaptureWithDescriptor(MtCaptureManager *manager, MtCaptureDescriptor *descriptor, NsError **error){ - return (bool)[(MTLCaptureManager*)manager startCaptureWithDescriptor:descriptor error:(NSError **)error]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -void -mtStopCapture(MtCaptureManager *manager){ - [(MTLCaptureManager*)manager stopCapture]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -bool -mtIsCapturing(MtCaptureManager *manager){ - return (bool)[(MTLCaptureManager*)manager isCapturing]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -MtCaptureScope* -mtDefaultCaptureScope(MtCaptureManager *manager){ - return [(MTLCaptureManager*) manager defaultCaptureScope]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -void -mtDefaultCaptureScopeSet(MtCaptureManager *manager, MtCaptureScope *scope){ - [(MTLCaptureManager*) manager setDefaultCaptureScope: scope]; -} diff --git a/deps/cmt/src/capture/capture_scope.m b/deps/cmt/src/capture/capture_scope.m deleted file mode 100644 index d0d5156d..00000000 --- a/deps/cmt/src/capture/capture_scope.m +++ /dev/null @@ -1,52 +0,0 @@ -#include "impl/common.h" -#include "cmt/command_queue.h" -#include "cmt/capture/capture_scope.h" - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -MtCaptureScope* -mtNewCaptureScopeWithCommandQueue(MtCaptureManager *manager, MtCommandQueue *queue){ - return (MtCaptureScope*)[(MTLCaptureManager*)manager newCaptureScopeWithCommandQueue: queue]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -void -mtBeginScope(MtCaptureScope *scope){ -[(id)scope beginScope]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -void -mtEndScope(MtCaptureScope *scope){ - [(id)scope endScope]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -const char* -mtCaptureScopeLabel(MtCaptureScope *scope) { - return Cstring([(id)scope label]); -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -void -mtCaptureScopeLabelSet(MtCaptureScope *scope, const char* label) { - [(id)scope setLabel: mtNSString(label)]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -MtDevice* -mtCaptureScopeDevice(MtCaptureScope *scope) { - return [(id)scope device]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -MtCommandQueue* -mtCaptureScopeCommandQueue(MtCaptureScope *scope) { - return [(id)scope commandQueue]; -} diff --git a/deps/cmt/src/cmt.m b/deps/cmt/src/cmt.m deleted file mode 100644 index 829fedcd..00000000 --- a/deps/cmt/src/cmt.m +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright (c), Recep Aslantas. - * MIT License (MIT), http://opensource.org/licenses/MIT - */ - -#import "impl/common.h" - -CF_RETURNS_RETAINED -MT_EXPORT -void* -mtRetain(void *obj) { - return [(id)obj retain]; -} - -MT_EXPORT -void -mtRelease(void * CF_RELEASES_ARGUMENT obj) { - [(id)obj release]; -} diff --git a/deps/cmt/src/command_buf.m b/deps/cmt/src/command_buf.m deleted file mode 100644 index a3b2c220..00000000 --- a/deps/cmt/src/command_buf.m +++ /dev/null @@ -1,268 +0,0 @@ -#include "cmt/common.h" -#include "impl/common.h" -#include "cmt/command_buf.h" - -CF_RETURNS_RETAINED -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -MtCommandBufferDescriptor* -mtNewCommandBufferDescriptor() { - return [MTLCommandBufferDescriptor new]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -bool -mtCommandBufferDescriptorRetainedReferences(MtCommandBufferDescriptor *desc) { - return (bool)[(MTLCommandBufferDescriptor*)desc retainedReferences]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtCommandBufferDescriptorRetainedReferencesSet(MtCommandBufferDescriptor *desc, bool retain) { - [(MTLCommandBufferDescriptor*)desc setRetainedReferences: retain]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -NsUInteger -mtCommandBufferDescriptorErrorOptions(MtCommandBufferDescriptor *desc) { - return (NsUInteger)[(MTLCommandBufferDescriptor*)desc errorOptions]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtCommandBufferDescriptorErrorOptionsSet(MtCommandBufferDescriptor *desc, NsUInteger errorOption) { - [(MTLCommandBufferDescriptor*)desc setErrorOptions: errorOption]; -} - -CF_RETURNS_RETAINED -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -MtCommandBuffer* -mtNewCommandBuffer(MtCommandQueue *cmdq) { - id commandBuffer = [(id ) cmdq commandBuffer]; - // Per Apple's "Basic Memory Management Rules" the above invocation does not imply ownership. - // To be consistent the name of the function and CF_RETURNS_RETAINED, we explicitly claim - // ownership with an explicit `retain` - [commandBuffer retain]; - return commandBuffer; -} - -CF_RETURNS_RETAINED -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -MtCommandBuffer* -mtNewCommandBufferWithDescriptor(MtCommandQueue *cmdq, MtCommandBufferDescriptor *desc) { - id commandBuffer = [(id)cmdq commandBufferWithDescriptor:(MtCommandBufferDescriptor *)desc]; - // Per Apple's "Basic Memory Management Rules" the above invocation does not imply ownership. - // To be consistent the name of the function and CF_RETURNS_RETAINED, we explicitly claim - // ownership with an explicit `retain` - [commandBuffer retain]; - return commandBuffer; -} - -CF_RETURNS_RETAINED -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -MtCommandBuffer* -mtNewCommandBufferWithUnretainedReferences(MtCommandQueue *cmdq) { - return [(id)cmdq commandBufferWithUnretainedReferences]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtCommandBufferOnCompleted(MtCommandBuffer * __restrict cmdb, - void * __restrict data, - MtCommandBufferOnCompletedFn fn) { - [(id)cmdb addCompletedHandler:^(id buffer) { - // we don't care about the buffer; the user can capture it if they want - fn(data); - }]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtCommandBufferOnScheduled(MtCommandBuffer * __restrict cmdb, - void * __restrict data, - MtCommandBufferOnScheduledFn fn) { - [(id)cmdb addScheduledHandler:^(id buffer) { - // we don't care about the buffer; the user can capture it if they want - fn(data); - }]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtCommandBufferPresentDrawable(MtCommandBuffer *cmdb, MtDrawable *drawable) { - [(id)cmdb presentDrawable: drawable]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtCommandBufferEnqueue(MtCommandBuffer *cmdb) { - [(id)cmdb enqueue]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtCommandBufferCommit(MtCommandBuffer *cmdb) { - [(id)cmdb commit]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtCommandBufferAddScheduledHandler(MtCommandBuffer *cmdb, MtCommandBufferHandlerFun handler) { - [(id)cmdb addScheduledHandler:(MTLCommandBufferHandler)handler]; -} - -typedef void (^MtCommandBufferHandlerBlock)(id); - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtCommandBufferAddCompletedHandler(MtCommandBuffer *cmdb, MtCommandBufferHandlerFun handler) { - MTLCommandBufferHandler block = ^(id buf){ - MtCommandBuffer *_cmdb = buf; - (*handler)(_cmdb); - }; - - [(id)cmdb addCompletedHandler:block]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtCommandBufferWaitUntilScheduled(MtCommandBuffer *cmdb) { - [(id)cmdb waitUntilScheduled]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtCommandBufferWaitUntilCompleted(MtCommandBuffer *cmdb) { - [(id)cmdb waitUntilCompleted]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -MtCommandBufferStatus -mtCommandBufferStatus(MtCommandBuffer *cmdb) { - return (MtCommandBufferStatus)[(id)cmdb status]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -NsError* -mtCommandBufferError(MtCommandBuffer *cmdb) { - return [(id)cmdb error]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -MtCommandBufferErrorOption -mtCommandBufferErrorOptions(MtCommandBuffer *cmdb) { - return (MtCommandBufferErrorOption)[(id)cmdb errorOptions]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.15), mt_ios(13.0)) -CfTimeInterval -mtCommandBufferKernelStartTime(MtCommandBuffer *cmdb) { - return [(id)cmdb kernelStartTime]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.15), mt_ios(13.0)) -CfTimeInterval -mtCommandBufferKernelEndTime(MtCommandBuffer *cmdb) { - return [(id)cmdb kernelEndTime]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.15), mt_ios(13.0)) -CfTimeInterval -mtCommandBufferGPUStartTime(MtCommandBuffer *cmdb){ - return [(id)cmdb GPUStartTime]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.15), mt_ios(13.0)) -CfTimeInterval -mtCommandBufferGPUEndTime(MtCommandBuffer *cmdb) { - return [(id)cmdb GPUEndTime]; -} - -// Events -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.15), mt_ios(13.0)) -void -mtCommandBufferEncodeSignalEvent(MtCommandBuffer *cmdb, MtEvent *event, uint64_t val) { - [(id)cmdb encodeSignalEvent:(id)event value: val]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.15), mt_ios(13.0)) -void -mtCommandBufferEncodeWaitForEvent(MtCommandBuffer *cmdb, MtEvent *event, uint64_t val) { - [(id)cmdb encodeWaitForEvent:(id)event value: val]; -} - -// retained references ? -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -bool -mtCommandBufferRetainedReferences(MtCommandBuffer *cmdb) { - return [(id)cmdb retainedReferences]; -} - -// identifying -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -MtDevice* -mtCommandBufferDevice(MtCommandBuffer *cmdb) { - return [(id)cmdb device]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -MtCommandQueue* -mtCommandBufferCommandQueue(MtCommandBuffer *cmdb) { - return [(id)cmdb commandQueue]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -const char* -mtCommandBufferLabel(MtCommandBuffer *cmdb) { - return Cstring([(id)cmdb label]); -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtCommandBufferLabelSet(MtCommandBuffer *cmdb, const char* label) { - ((id)cmdb).label = mtNSString(label); -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -void -mtCommandBufferPushDebugGroup(MtCommandBuffer *cmdb, char* str) { - return [(id)cmdb pushDebugGroup: mtNSString(str)]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -void -mtCommandBufferPopDebugGroup(MtCommandBuffer *cmdb) { - [(id)cmdb popDebugGroup]; -} diff --git a/deps/cmt/src/command_buf_indirect.m b/deps/cmt/src/command_buf_indirect.m deleted file mode 100644 index 28271ced..00000000 --- a/deps/cmt/src/command_buf_indirect.m +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c), Recep Aslantas. - * MIT License (MIT), http://opensource.org/licenses/MIT - */ - -#import "impl/common.h" -#import "cmt/command_buf_indirect.h" - -CF_RETURNS_RETAINED -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.14), mt_ios(12.0)) -MtIndirectCommandBuffer* -mtNewIndirectCommandBuffer(MtDevice *device, MtIndirectCommandBufferDescriptor *desc, - NsUInteger maxCount, MtResourceOptions options) { - return [(id)device - newIndirectCommandBufferWithDescriptor: (MTLIndirectCommandBufferDescriptor *)desc - maxCommandCount: maxCount - options: (MTLResourceOptions)options]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -NsUInteger -mtIndirectCommandBufferSize(MtIndirectCommandBuffer *icb) { - return [(id)icb size]; -} - -/* IOS Only atm -MT_EXPORT -MtIndirectComputeCommand* -mtIndirectCommandBufferComputeCommandAtIndex(MtIndirectCommandBuffer *icb, - NsUInteger index) { - return [(id)icb indirectComputeCommandAtIndex:index]; -}*/ - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -MtIndirectRenderCommand* -mtIndirectCommandBufferRenderCommandAtIndex(MtIndirectCommandBuffer *icb, - NsUInteger index) { - return [(id)icb indirectRenderCommandAtIndex:index]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtIndirectCommandBufferResetWithRange(MtIndirectCommandBuffer *icb, NsRange range) { - return [(id)icb resetWithRange:mtNSRange(range)]; -} \ No newline at end of file diff --git a/deps/cmt/src/command_enc.m b/deps/cmt/src/command_enc.m deleted file mode 100644 index f02613bc..00000000 --- a/deps/cmt/src/command_enc.m +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c), Recep Aslantas. - * MIT License (MIT), http://opensource.org/licenses/MIT - */ - -#include "cmt/common.h" -#include "impl/common.h" -#include "cmt/command_enc.h" - -MT_EXPORT -void -mtCommandEncoderEndEncoding(MtCommandEncoder *cce) { - [(id)cce endEncoding]; -} - -MT_EXPORT -MtDevice* -mtCommandEncoderDevice(MtCommandEncoder *ce) { - return [(id)ce device]; -} - -MT_EXPORT -const char* -mtCommandEncoderLabel(MtCommandEncoder *ce) { - return Cstring([(id)ce label]); -} - -MT_EXPORT -void -mtCommandEncoderLabelSet(MtCommandEncoder *ce, const char* label) { - ((id)ce).label = mtNSString(label); -} - -MT_EXPORT -void -mtCommandEncoderInsertDebugSignpost(MtCommandEncoder *ce, char* string) { - [(id)ce insertDebugSignpost: mtNSString(string)]; -} - -MT_EXPORT -void -mtCommandEncoderPushDebugGroup(MtCommandEncoder *ce, char* string) { - [(id)ce pushDebugGroup: mtNSString(string)]; -} - -MT_EXPORT -void -mtCommandEncoderPopDebugGroup(MtCommandEncoder *ce) { - [(id)ce popDebugGroup]; -} - - - diff --git a/deps/cmt/src/command_enc_blit.m b/deps/cmt/src/command_enc_blit.m deleted file mode 100644 index 90d4899b..00000000 --- a/deps/cmt/src/command_enc_blit.m +++ /dev/null @@ -1,182 +0,0 @@ -/* - * Copyright (c), Recep Aslantas. - * MIT License (MIT), http://opensource.org/licenses/MIT - */ - -#import "impl/common.h" -#import "cmt/command_enc_blit.h" - -CF_RETURNS_RETAINED -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -MtBlitCommandEncoder* -mtNewBlitCommandEncoder(MtCommandBuffer *cmdb) { - id encoder = [(id)cmdb blitCommandEncoder]; - // Per Apple's "Basic Memory Management Rules" the above invocation does not imply ownership. - // To be consistent the name of the function and CF_RETURNS_RETAINED, we explicitly claim - // ownership with an explicit `retain` - [encoder retain]; - return encoder; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtBlitCommandEncoderCopyFromBufferToBuffer(MtBlitCommandEncoder *bce, - MtBuffer *src, NsUInteger src_offset, - MtBuffer *dst, NsUInteger dst_offset, - NsUInteger size) { - [(id)bce copyFromBuffer: (id)src - sourceOffset: src_offset - toBuffer: (id)dst - destinationOffset: dst_offset - size: size ]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtBlitCommandEncoderFillBuffer(MtBlitCommandEncoder *bce, - MtBuffer *buf, NsRange range, uint8_t val) { - [(id)bce fillBuffer: (id)buf - range: mtNSRange(range) - value: val]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtBlitCommandEncoderGenerateMipmaps(MtBlitCommandEncoder *bce, - MtTexture *texture) { - [(id)bce generateMipmapsForTexture:(id)texture]; -} - - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.14), mt_ios(12.0)) -void -mtBlitCommandEncoderCopyIndirectCommandBuffer(MtBlitCommandEncoder *bce, - MtIndirectCommandBuffer *src, NsRange range, - MtIndirectCommandBuffer *dst, NsUInteger dst_index) { - [(id)bce copyIndirectCommandBuffer: (id)src - sourceRange: mtNSRange(range) - destination:(id)dst - destinationIndex: dst_index ]; - -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.14), mt_ios(12.0)) -void -mtBlitCommandEncoderOptimizeIndirectCommandBuffer(MtBlitCommandEncoder *bce, - MtIndirectCommandBuffer *buffer, NsRange range) { - [(id)bce - optimizeIndirectCommandBuffer: (id)buffer - withRange: mtNSRange(range)]; - -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.14), mt_ios(12.0)) -void -mtBlitCommandEncoderResetCommandsInBuffer(MtBlitCommandEncoder *bce, - MtIndirectCommandBuffer *buffer, NsRange range) { - [(id)bce - resetCommandsInBuffer: (id)buffer - withRange: mtNSRange(range)]; - -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtBlitCommandEncoderSynchronizeResource(MtBlitCommandEncoder *bce, - MtResource *resource) { - [(id)bce synchronizeResource: (id)resource]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtBlitCommandEncoderSynchronizeTexture(MtBlitCommandEncoder *bce, - MtTexture *texture, NsUInteger slice, NsUInteger level){ - [(id)bce synchronizeTexture: (id)texture - slice: slice level:level]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(10.0)) -void -mtBlitCommandEncoderUpdateFence(MtBlitCommandEncoder *icb, MtFence *fence) { - [(id)icb updateFence: (id)fence]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(10.0)) -void -mtBlitCommandEncoderWaitForFence(MtBlitCommandEncoder *icb, MtFence *fence) { - [(id)icb waitForFence: (id)fence]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.14), mt_ios(12.0)) -void -mtBlitCommandEncoderOptimizeContentsForGPUAccess(MtIndirectCommandBuffer *icb, - MtTexture *tex) { - [(id)icb optimizeContentsForGPUAccess: (id)tex]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.14), mt_ios(12.0)) -void -mtBlitCommandEncoderOptimizeContentsForGPUAccessSliceLevel(MtIndirectCommandBuffer *icb, - MtTexture *tex, NsUInteger slice, NsUInteger level) { - [(id)icb optimizeContentsForGPUAccess: (id)tex - slice:slice level:level]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.14), mt_ios(12.0)) -void -mtBlitCommandEncoderOptimizeContentsForCPUAccess(MtIndirectCommandBuffer *icb, - MtTexture *tex) { - [(id)icb optimizeContentsForCPUAccess: (id)tex]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.14), mt_ios(12.0)) -void -mtBlitCommandEncoderOptimizeContentsForCPUAccessSliceLevel(MtIndirectCommandBuffer *icb, - MtTexture *tex, NsUInteger slice, NsUInteger level) { - [(id)icb optimizeContentsForCPUAccess: (id)tex - slice:slice level:level]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.15)) -MT_API_UNAVAILABLE(mt_ios) -void -mtBlitCommandEncoderSampleCountersInBuffer(MtIndirectCommandBuffer *icb, - MtCounterSampleBuffer *sbuf, - NsUInteger sampleindex, - bool barrier){ - [(id)icb sampleCountersInBuffer: (id) sbuf - atSampleIndex: sampleindex - withBarrier: barrier]; -} - - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.15)) -MT_API_UNAVAILABLE(mt_ios) -void -mtBlitCommandEncoderResolveCounters(MtIndirectCommandBuffer *icb, - MtCounterSampleBuffer *sbuf, - NsRange range, - MtBuffer *dst, - NsUInteger dst_offset) { - [(id)icb resolveCounters: (id)sbuf - inRange: mtNSRange(range) - destinationBuffer: (id)dst - destinationOffset: dst_offset]; -} diff --git a/deps/cmt/src/command_enc_compute.m b/deps/cmt/src/command_enc_compute.m deleted file mode 100644 index d2b2996e..00000000 --- a/deps/cmt/src/command_enc_compute.m +++ /dev/null @@ -1,228 +0,0 @@ -/* - * Copyright (c), Recep Aslantas. - * MIT License (MIT), http://opensource.org/licenses/MIT - */ - -#include "cmt/common.h" -#include "impl/common.h" -#include "impl/conversion.h" -#include "cmt/command_enc_compute.h" - -CF_RETURNS_RETAINED -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -MtComputeCommandEncoder* -mtNewComputeCommandEncoder(MtCommandBuffer *cmdb) { - id encoder = [(id)cmdb computeCommandEncoder]; - // Per Apple's "Basic Memory Management Rules" the above invocation does not imply ownership. - // To be consistent the name of the function and CF_RETURNS_RETAINED, we explicitly claim - // ownership with an explicit `retain` - [encoder retain]; - return encoder; -} - -CF_RETURNS_RETAINED -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.14), mt_ios(12.0)) -MtComputeCommandEncoder* -mtNewComputeCommandEncoderWithDispatchType(MtCommandBuffer *cmdb, MtDispatchType dtype) { - id encoder = [(id ) cmdb - computeCommandEncoderWithDispatchType:(MTLDispatchType) dtype]; - // Per Apple's "Basic Memory Management Rules" the above invocation does not imply ownership. - // To be consistent the name of the function and CF_RETURNS_RETAINED, we explicitly claim - // ownership with an explicit `retain` - [encoder retain]; - return encoder; - -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtComputeCommandEncoderEndEncoding(MtComputeCommandEncoder *cce) { - [(id)cce endEncoding]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtComputeCommandEncoderSetComputePipelineState(MtComputeCommandEncoder *cce, MtComputePipelineState *state) { - [(id)cce setComputePipelineState:(id)state]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtComputeCommandEncoderSetBufferOffsetAtIndex(MtComputeCommandEncoder *cce, MtBuffer *buf, NsUInteger offset, NsUInteger indx) { - [(id)cce setBuffer:(id)buf - offset:offset - atIndex:indx]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtComputeCommandEncoderSetBuffersOffsetsWithRange(MtComputeCommandEncoder *cce, MtBuffer **bufs, const NsUInteger *offsets, NsRange range) { - [(id)cce setBuffers:(id*)bufs - offsets: offsets - withRange:mtNSRange(range)]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtComputeCommandEncoderBufferSetOffsetAtIndex(MtComputeCommandEncoder *cce, NsUInteger offset, NsUInteger indx) { - [(id)cce setBufferOffset:offset atIndex:indx]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtComputeCommandEncoderSetBytesLengthAtIndex(MtComputeCommandEncoder *cce, const void* ptr, NsUInteger length, NsUInteger indx) { - [(id)cce setBytes:ptr length:length atIndex:indx]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtComputeCommandEncoderSetSamplerStateAtIndex(MtComputeCommandEncoder *cce, MtSamplerState *sampler, NsUInteger indx) { - [(id)cce setSamplerState:(id)sampler atIndex:indx]; -} - - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtComputeCommandEncoderSetSamplerStatesWithRange(MtComputeCommandEncoder *cce, MtSamplerState **samplers, NsRange range) { - [(id)cce setSamplerStates:(id*)samplers - withRange:mtNSRange(range)]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtComputeCommandEncoderSetSamplerStateLodMinClampLodMaxClampAtIndex(MtComputeCommandEncoder *cce, MtSamplerState *sampler, float lodMinClamp, float lodMaxClamp, NsUInteger indx) { - [(id)cce setSamplerState:(id)sampler - lodMinClamp:lodMinClamp - lodMaxClamp:lodMaxClamp - atIndex:indx]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtComputeCommandEncoderSetTextureAtIndex(MtComputeCommandEncoder *cce, MtTexture *tex, NsUInteger indx) { - [(id)cce setTexture:(id)tex - atIndex:indx]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtComputeCommandEncoderSetTexturesWithRange(MtComputeCommandEncoder *cce, MtTexture **textures, NsRange range) { - [(id)cce setTextures:(id*)textures - withRange:mtNSRange(range)]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtComputeCommandEncoderSetThreadgroupMemoryLengthAtIndex(MtComputeCommandEncoder *cce, NsUInteger length, NsUInteger indx) { - [(id)cce setThreadgroupMemoryLength: length - atIndex:indx]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtComputeCommandEncoderDispatchThreadgroups_threadsPerThreadgroup(MtComputeCommandEncoder *cce, MtSize threadgroupsPerGrid, MtSize threadsPerThreadgroup) { - [(id)cce dispatchThreadgroups: mtMTLSize(threadgroupsPerGrid) - threadsPerThreadgroup: mtMTLSize(threadsPerThreadgroup)]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -void -mtComputeCommandEncoderDispatchThread_threadsPerThreadgroup(MtComputeCommandEncoder *cce, MtSize threadsPerGrid, MtSize threadsPerThreadgroup) { - [(id)cce dispatchThreads: mtMTLSize(threadsPerGrid) - threadsPerThreadgroup:mtMTLSize(threadsPerThreadgroup)]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtComputeCommandEncoderDispatchThreadgroupsWithIndirectBuffer_IndirectBufferOffset_threadsPerThreadgroup(MtComputeCommandEncoder *cce, MtBuffer *indirectBuffer, NsUInteger indirectBufferOffset, MtSize threadsPerThreadgroup) { - [(id)cce dispatchThreadgroupsWithIndirectBuffer: (id)indirectBuffer - indirectBufferOffset: indirectBufferOffset - threadsPerThreadgroup: mtMTLSize(threadsPerThreadgroup)]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -void -mtComputeCommandEncoderUseResourceUsage(MtComputeCommandEncoder *cce, MtResource *res, MtResourceUsage usage) { - [(id)cce useResource: (id)res - usage: (MTLResourceUsage)usage]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -void -mtComputeCommandEncoderUseResourceCountUsage(MtComputeCommandEncoder *cce, MtResource **res, NsUInteger count, MtResourceUsage usage) { - [(id)cce useResources: (id*)res - count: count - usage: (MTLResourceUsage)usage]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -void -mtComputeCommandEncoderUseHeap(MtComputeCommandEncoder *cce, MtHeap *heap) { - [(id)cce useHeap: (id)heap]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -void -mtComputeCommandEncoderUseHeaps(MtComputeCommandEncoder *cce, MtHeap **heaps, NsUInteger count) { - [(id)cce useHeaps:(id*)heaps count: count]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.12), mt_ios(10.0)) -void -mtComputeCommandEncoderSetStageInRegion(MtComputeCommandEncoder *cce, MtRegion region) { - [(id)cce setStageInRegion:mtMTLRegion(region)]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.14), mt_ios(12.0)) -void -mtComputeCommandEncoderSetStageInRegionWithIndirectBuffer(MtComputeCommandEncoder *cce, MtBuffer *buf, NsUInteger offset) { - [(id)cce setStageInRegionWithIndirectBuffer: (id)buf - indirectBufferOffset: offset]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.14), mt_ios(12.0)) -MtDispatchType -mtComputeCommandEncoderDispatchType(MtComputeCommandEncoder *cce) { - return (MtDispatchType)[(id)cce dispatchType]; -} - -// Executing Commands Concurrently or Serially -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.14), mt_ios(12.0)) -void -mtComputeCommandEncoderMemoryBarrierWithScope(MtComputeCommandEncoder *cce, MtBarrierScope scope) { - return [(id)cce memoryBarrierWithScope: (MTLBarrierScope)scope]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.14), mt_ios(12.0)) -void -mtComputeCommandEncoderMemoryBarrierWithResource(MtComputeCommandEncoder *cce, MtResource **resources, NsUInteger count) { - return [(id)cce memoryBarrierWithResources: (id*)resources - count: count]; - -} diff --git a/deps/cmt/src/command_enc_render.m b/deps/cmt/src/command_enc_render.m deleted file mode 100644 index 50b19f5a..00000000 --- a/deps/cmt/src/command_enc_render.m +++ /dev/null @@ -1,133 +0,0 @@ -/* - * Copyright (c), Recep Aslantas. - * MIT License (MIT), http://opensource.org/licenses/MIT - */ - -#include "cmt/common.h" -#include "impl/common.h" -#include "cmt/command_enc_render.h" - -/*MT_EXPORT -MtResourceStateCommandEncoder* -mtNewResourceStateCommandEncoder(MtCommandBuffer *cmdb) { - return [(id)cmdb resourceStateCommandEncoder]; -}*/ //IOS 13 - -CF_RETURNS_RETAINED -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -MT_EXPORT -MtRenderCommandEncoder* -mtNewRenderCommandEncoder(MtCommandBuffer *cmdb, MtRenderPassDesc *pass) { - id encoder = [(id)cmdb renderCommandEncoderWithDescriptor: pass]; - // Per Apple's "Basic Memory Management Rules" the above invocation does not imply ownership. - // To be consistent the name of the function and CF_RETURNS_RETAINED, we explicitly claim - // ownership with an explicit `retain` - [encoder retain]; - return encoder; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtFrontFace(MtRenderCommandEncoder *rce, MtWinding winding) { - [(id)rce setFrontFacingWinding:(MTLWinding)winding]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtCullMode(MtRenderCommandEncoder *rce, MtCullMode mode) { - [(id)rce setCullMode:(MTLCullMode)mode]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtViewport(MtRenderCommandEncoder *rce, MtViewport *viewport) { - [(id)rce setViewport: *(MTLViewport *)viewport]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtSetRenderState(MtRenderCommandEncoder *rce, MtRenderPipeline *pipline) { - [(id)rce setRenderPipelineState: pipline]; -} - -MT_EXPORT -void -mtSetDepthStencil(MtRenderCommandEncoder *rce, MtDepthStencil *ds) { - [(id)rce setDepthStencilState: ds]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtVertexBytes(MtRenderCommandEncoder *enc, - void *bytes, - size_t legth, - uint32_t atIndex) { - [(id)enc setVertexBytes: bytes - length: legth - atIndex: atIndex]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtVertexBuffer(MtRenderCommandEncoder *rce, - MtBuffer *buf, - size_t off, - uint32_t index) { - [(id)rce setVertexBuffer: buf - offset: off - atIndex: index]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtFragmentBuffer(MtRenderCommandEncoder *rce, - MtBuffer *buf, - size_t off, - uint32_t index) { - [(id)rce setFragmentBuffer: buf - offset: off - atIndex: index]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtDrawPrims(MtRenderCommandEncoder *rce, - MtPrimitiveType type, - size_t start, - size_t count) { - [(id)rce drawPrimitives: (MTLPrimitiveType)type - vertexStart: start - vertexCount: count]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtDrawIndexedPrims(MtRenderCommandEncoder *rce, - MtPrimitiveType type, - uint32_t indexCount, - MtIndexType indexType, - MtBuffer *indexBuffer, - uint32_t indexBufferOffset) { - [(id)rce - drawIndexedPrimitives: (MTLPrimitiveType)type - indexCount: indexCount - indexType: (MTLIndexType)indexType - indexBuffer: indexBuffer - indexBufferOffset: indexBufferOffset]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtEndEncoding(MtRenderCommandEncoder *rce) { - [(id)rce endEncoding]; -} diff --git a/deps/cmt/src/command_queue.m b/deps/cmt/src/command_queue.m deleted file mode 100644 index 00fd216e..00000000 --- a/deps/cmt/src/command_queue.m +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c), Recep Aslantas. - * MIT License (MIT), http://opensource.org/licenses/MIT - */ - -#include "impl/common.h" -#include "cmt/command_queue.h" - -CF_RETURNS_RETAINED -MT_EXPORT -MtCommandQueue* -mtNewCommandQueue(MtDevice *device) { - return [(id)device newCommandQueue]; -} - -CF_RETURNS_RETAINED -MT_EXPORT -MtCommandQueue* -mtNewCommandQueueWithMaxCommandBufferCount(MtDevice *device, NsUInteger count) { - return [(id)device newCommandQueueWithMaxCommandBufferCount: count]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -MtDevice* -mtCommandQueueDevice(MtCommandQueue *cmdq) { - return [(id)cmdq device]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -const char* -mtCommandQueueLabel(MtCommandQueue *cmdq) { - return Cstring([(id)cmdq label]); -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtCommandQueueLabelSet(MtCommandQueue *cmdq, const char* label) { - ((id)cmdq).label = mtNSString(label); -} diff --git a/deps/cmt/src/compute/compute-pipeline.m b/deps/cmt/src/compute/compute-pipeline.m deleted file mode 100644 index 259e8b60..00000000 --- a/deps/cmt/src/compute/compute-pipeline.m +++ /dev/null @@ -1,187 +0,0 @@ -/* - * Copyright (c), Recep Aslantas. - * MIT License (MIT), http://opensource.org/licenses/MIT - */ - -#import "impl/common.h" -#import "cmt/compute/compute-pipeline.h" -#import "cmt/error.h" - -CF_RETURNS_RETAINED -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(9.0)) -MtComputePipelineDescriptor* -mtNewComputePipelineDescriptor(void) { - return [MTLComputePipelineDescriptor new]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(9.0)) -const char* -mtComputePipelineDescriptorLabel(MtComputePipelineDescriptor *desc) { - return (const char*)Cstring([(MTLComputePipelineDescriptor*)desc label]); -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(9.0)) -void -mtComputePipelineDescriptorLabelSet(MtComputePipelineDescriptor *desc, const char *label) { - [(MTLComputePipelineDescriptor*)desc setLabel: mtNSString(label)]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(9.0)) -MtFunction* -mtComputePipelineDescriptorComputeFunction(MtComputePipelineDescriptor *desc) { - return [(MTLComputePipelineDescriptor*)desc computeFunction]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(9.0)) -void -mtComputePipelineDescriptorComputeFunctionSet(MtComputePipelineDescriptor *desc, MtFunction *fun) { - [(MTLComputePipelineDescriptor*)desc setComputeFunction: fun]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(9.0)) -bool -mtComputePipelineDescriptorThreadGroupSizeIsMultipleOfThreadExecutionWidth(MtComputePipelineDescriptor *desc) { - return [(MTLComputePipelineDescriptor*)desc threadGroupSizeIsMultipleOfThreadExecutionWidth]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(9.0)) -void -mtComputePipelineDescriptorThreadGroupSizeIsMultipleOfThreadExecutionWidthSet(MtComputePipelineDescriptor *desc, bool val) { - [(MTLComputePipelineDescriptor*)desc setThreadGroupSizeIsMultipleOfThreadExecutionWidth: val]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.14), mt_ios(12.0)) -uint32_t -mtComputePipelineDescriptorMaxTotalThreadsPerThreadgroup(MtComputePipelineDescriptor *desc) { - return [(MTLComputePipelineDescriptor*)desc maxTotalThreadsPerThreadgroup]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.14), mt_ios(12.0)) -void -mtComputePipelineDescriptorMaxTotalThreadsPerThreadgroupSet(MtComputePipelineDescriptor *desc, uint32_t val) { - [(MTLComputePipelineDescriptor*)desc setMaxTotalThreadsPerThreadgroup: val]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(11.00), mt_ios(14.0)) -uint32_t -mtComputePipelineDescriptorMaxCallStackDepth(MtComputePipelineDescriptor *desc) { - return [(MTLComputePipelineDescriptor*)desc maxCallStackDepth]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(11.00), mt_ios(14.0)) -void -mtComputePipelineDescriptorMaxCallStackDepthSet(MtComputePipelineDescriptor *desc, uint32_t val) { - [(MTLComputePipelineDescriptor*)desc setMaxCallStackDepth: val]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(11.0), mt_ios(13.0)) -bool -mtComputePipelineDescriptorSupportIndirectCommandBuffers(MtComputePipelineDescriptor *desc) { - return [(MTLComputePipelineDescriptor*)desc supportIndirectCommandBuffers]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(9.0)) -void -mtComputePipelineDescriptorReset(MtComputePipelineDescriptor *desc) { - [(MTLComputePipelineDescriptor*)desc reset]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(11.00), mt_ios(14.0)) -bool -mtComputePipelineDescriptorSupportAddingBinaryFunctions(MtComputePipelineDescriptor *desc) { - return [(MTLComputePipelineDescriptor*)desc supportAddingBinaryFunctions]; -} - -CF_RETURNS_RETAINED -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -MtComputePipelineState* -mtNewComputePipelineStateWithFunction(MtDevice *device, MtFunction* fun, NsError **error) { - return[(id)device newComputePipelineStateWithFunction: fun error: (NSError **)error]; -} - -CF_RETURNS_RETAINED -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -MT_EXPORT -MtComputePipelineState* -mtNewComputePipelineStateWithFunctionReflection(MtDevice *device, MtFunction* fun,MtPipelineOption opt, - MtComputePipelineReflection **reflection, NsError **error) { - return [(id)device - newComputePipelineStateWithFunction: fun - options: (MTLPipelineOption)opt - reflection: (MTLAutoreleasedComputePipelineReflection*) reflection - error: (NSError **)error]; -} - -CF_RETURNS_RETAINED -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -MtComputePipelineState* -mtNewComputePipelineStateWithDescriptor(MtDevice *device, MtComputePipelineDescriptor* desc, - MtPipelineOption opt, - MtComputePipelineReflection **reflection, - NsError **error) { - return [(id)device - newComputePipelineStateWithDescriptor: (MTLComputePipelineDescriptor*)desc - options: (MTLPipelineOption)opt - reflection: (MTLAutoreleasedComputePipelineReflection*) reflection - error: (NSError **)error]; - -} - -CF_RETURNS_RETAINED -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -MtDevice* -mtComputePipelineDevice(MtComputePipelineState *pip) { - return [(id)pip device]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -const char* -mtComputePipelineLabel(MtComputePipelineState *pip) { - return Cstring([(id)pip label]); -} - -// Properties -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -NsUInteger -mtComputePipelineMaxTotalThreadsPerThreadgroup(MtComputePipelineState *pip) { - return [(id)pip maxTotalThreadsPerThreadgroup]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -NsUInteger -mtComputePipelineThreadExecutionWidth(MtComputePipelineState *pip) { - return [(id)pip threadExecutionWidth]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -NsUInteger -mtComputePipelineStaticThreadgroupMemoryLength(MtComputePipelineState *pip) { - return [(id)pip staticThreadgroupMemoryLength]; -} - -/*MT_EXPORT -NsUInteger -mtComputePipelineImageblockMemoryLengthForDimensions(MtComputePipelineState *pip, MtSize imageblockDimensions) { - return [(id)pip imageblockMemoryLengthForDimensions: mtMTLSize(imageblockDimensions)]; -} IOS 11*/ diff --git a/deps/cmt/src/device.m b/deps/cmt/src/device.m deleted file mode 100644 index 7fa19e54..00000000 --- a/deps/cmt/src/device.m +++ /dev/null @@ -1,250 +0,0 @@ -/* - * Copyright (c), Recep Aslantas. - * MIT License (MIT), http://opensource.org/licenses/MIT - */ - -#import "impl/common.h" -#import "cmt/device.h" - - -// Acquiring Device Objects - -CF_RETURNS_RETAINED -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -MtDevice* -mtCreateSystemDefaultDevice() { - return MTLCreateSystemDefaultDevice(); -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtCopyAllDevices(size_t* count, MtDevice** devices) { - NSArray> * _devices = MTLCopyAllDevices(); - NSInteger n = [_devices count]; - - if (*count == 0) { - *count = n; - } else { - assert(*count <= n); - for (int i=0; i < *count; i++) - devices[i] = [_devices objectAtIndex:i]; - } - - return; -} - - -// Querying GPU Properties - -CF_RETURNS_RETAINED -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -const char* -mtDeviceName(MtDevice* device) { - return [[(id)device name] cStringUsingEncoding:NSUTF8StringEncoding]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -bool -mtDeviceHeadless(MtDevice* device) { - return [(id)device isHeadless]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -bool -mtDeviceLowPower(MtDevice* device) { - return [(id)device isLowPower]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_macCatalyst(13.0)) -MT_API_UNAVAILABLE(mt_ios) -bool -mtDeviceRemovable(MtDevice* device) { - return [(id)device isRemovable]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -uint64_t -mtDeviceRegistryID(MtDevice* device) { - return [(id)device registryID]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -MtDeviceLocation -mtDeviceLocation(MtDevice* device) { - return MtDeviceLocationExternal;//[(id)device location]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.15)) -API_UNAVAILABLE(mt_ios) -uint64_t -mtDeviceLocationNumber(MtDevice* device) { - return [(id)device locationNumber]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.15)) -API_UNAVAILABLE(mt_ios) -uint64_t -mtDeviceMaxTransferRate(MtDevice* device) { - return [(id)device maxTransferRate]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.15), mt_ios(13.0)) -bool -mtDeviceHasUnifiedMemory(MtDevice* device) { - return [(id)device hasUnifiedMemory]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.12), mt_macCatalyst(13.0)) -MT_API_UNAVAILABLE(mt_ios) -uint64_t -mtDeviceRecommendedMaxWorkingSetSize(MtDevice* device) { - return [(id)device recommendedMaxWorkingSetSize]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -NsUInteger -mtDeviceCurrentAllocatedSize(MtDevice* device) { - return [(id)device currentAllocatedSize]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -NsUInteger -mtDeviceMaxThreadgroupMemoryLength(MtDevice* device) { - return [(id)device maxThreadgroupMemoryLength]; -} - - -// Determining Threadgroup Limits - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -MtSize -mtMaxThreadsPerThreadgroup(MtDevice* device) { - return mtSize([(id)device maxThreadsPerThreadgroup]); -} - - -// Finding Groups of Connected GPUs - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.15)) -MT_API_UNAVAILABLE(mt_ios) -uint64_t -mtDevicePeerGroupID(MtDevice *device) { - return [(id)device peerGroupID]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.15)) -MT_API_UNAVAILABLE(mt_ios) -uint32_t -mtDevicePeerCount(MtDevice *device) { - return[(id)device peerCount]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.15)) -MT_API_UNAVAILABLE(mt_ios) -uint32_t -mtDevicePeerIndex(MtDevice *device) { - return [(id)device peerIndex]; -} - - -// Querying Feature Sets and GPU Families - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.15), mt_ios(13.0)) -bool -mtDeviceSupportsFamily(MtDevice *device, MtGPUFamily family) { - return [(id)device supportsFamily: (MTLGPUFamily)family]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -bool -mtDeviceSupportsFeatureSet(MtDevice *device, MtFeatureSet set) { - return [(id)device supportsFeatureSet: (MTLFeatureSet)set]; -} - - -// Querying Argument Buffer Support - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -MtArgumentBuffersTier -mtDeviceArgumentBuffersSupport(MtDevice *device) { - return [(id)device argumentBuffersSupport]; -} - - -// Creating Buffers - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.14), mt_ios(12.0)) -NsUInteger -mtDeviceMaxBufferLength(MtDevice *device) { - return [(id)device maxBufferLength]; -} - -CF_RETURNS_RETAINED -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -MtBuffer* -mtDeviceNewBufferWithLength(MtDevice *device, NsUInteger length, MtResourceOptions opts) { - return [(id)device - newBufferWithLength: length - options: (MTLResourceOptions)opts]; -} - -CF_RETURNS_RETAINED -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -MtCommandBuffer* -mtDeviceNewBufferWithBytes(MtDevice * __restrict device, - const void * __restrict ptr, - NsUInteger len, - MtResourceOptions options) { - return [(id)device - newBufferWithBytes: ptr - length: len - options: (MTLResourceOptions)options]; -} - - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -MtBuffer* -mtDeviceNewBufferWithBytesNoCopy(MtDevice * __restrict device, - void * ptr, - NsUInteger length, - MtResourceOptions opts) { - return [(id)device newBufferWithBytesNoCopy: ptr - length: length - options: (MTLResourceOptions)opts - deallocator: nil]; -} - -/* -MT_EXPORT -MtBuffer* -mtDeviceNewBufferWithBytesNoCopyDeallocator(MtDevice *device, const void* ptr, NsUInteger length, MtResourceOptions opts) { - return [(id)device newBufferWithBytesNoCopy: ptr - length: length - options: (MTLResourceOptions)opts - deallocator: nil]; -}*/ diff --git a/deps/cmt/src/error.m b/deps/cmt/src/error.m deleted file mode 100644 index 5bccf32a..00000000 --- a/deps/cmt/src/error.m +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (c), Recep Aslantas. - * MIT License (MIT), http://opensource.org/licenses/MIT - */ - -#include "impl/common.h" -#include "cmt/common.h" - -MT_EXPORT -NsInteger -mtErrorCode(NsError *err) { return [(NSError *)err code]; } - -MT_EXPORT -const char* -mtErrorDomain(NsError *err) { - return Cstring([(NSError *)err domain]); -} - -MT_EXPORT -const char* -mtErrorUserInfo(NsError *err) { - return CstringFromDict([(NSError*)err userInfo]); -} - -MT_EXPORT -const char* -mtErrorLocalizedDescription(NsError *err) { - return Cstring([(NSError*)err localizedDescription]); -} - -MT_EXPORT -void -mtErrorLocalizedRecoveryOptions(NsError *err, size_t* count, const char** options) { - NSArray *_strings = [(NSError*)err localizedRecoveryOptions]; - NSInteger n = [_strings count]; - - if (*count == 0) { - *count = n; - } else { - assert(*count <= n); - for (int i=0; i < *count; i++) - options[i] = Cstring([_strings objectAtIndex:i]); - } - - return; -} - -MT_EXPORT -const char* -mtErrorLocalizedRecoverySuggestion(NsError *err) { - return Cstring([(NSError*)err localizedRecoverySuggestion]); -} - -MT_EXPORT -const char* -mtErrorLocalizedFailureReason(NsError *err) { - return Cstring([(NSError*)err localizedFailureReason]); -} - - - diff --git a/deps/cmt/src/event.m b/deps/cmt/src/event.m deleted file mode 100644 index 1e8000cf..00000000 --- a/deps/cmt/src/event.m +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (c), Recep Aslantas. - * MIT License (MIT), http://opensource.org/licenses/MIT - */ - -#include "impl/common.h" -#include "cmt/common.h" - -CF_RETURNS_RETAINED -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.14), mt_ios(12.0)) -MtEvent* -mtDeviceNewEvent(MtDevice *dev) { - return [(id)dev newEvent]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.14), mt_ios(12.0)) -MtSharedEvent* -mtDeviceNewSharedEvent(MtDevice *dev) { - return [(id)dev newSharedEvent]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.14), mt_ios(12.0)) -MtSharedEvent* -mtDeviceNewSharedEventWithHandle(MtDevice *dev, MtSharedEventHandle *handle) { - return [(id)dev newSharedEventWithHandle: (MTLSharedEventHandle*)handle]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(10.0)) -MtFence* -mtDeviceNewFence(MtDevice *dev) { - return [(id)dev newFence]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.14), mt_ios(12.0)) -MtDevice* -mtEventDevice(MtEvent *event) { - return [(id)event device]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.14), mt_ios(12.0)) -const char* -mtEventLabel(MtEvent *event) { - return Cstring([(id)event label]); -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.14), mt_ios(12.0)) -void -mtEventLabelSet(MtEvent *event, const char* label) { - ((id)event).label = mtNSString(label); -} - -// shared -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.14), mt_ios(12.0)) -uint64_t -mtSharedEventSignaledValue(MtSharedEvent *event) { - return [(id)event signaledValue]; -} - -// shared -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.14), mt_ios(12.0)) -MtSharedEventHandle* -mtSharedEventNewHandle(MtSharedEvent *event) { - return [(id)event newSharedEventHandle]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.14), mt_ios(12.0)) -void -mtSharedEventNotifyListener(MtSharedEvent *event, MtSharedEventListener *listener, uint64_t val, MtSharedEventNotificationBlock block) { - [(id)event notifyListener: (MTLSharedEventListener*)listener - atValue:val - block: (MTLSharedEventNotificationBlock) block]; -} diff --git a/deps/cmt/src/kernels/attribute.m b/deps/cmt/src/kernels/attribute.m deleted file mode 100644 index 1551e800..00000000 --- a/deps/cmt/src/kernels/attribute.m +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c), Recep Aslantas. - * MIT License (MIT), http://opensource.org/licenses/MIT - */ - -#include "impl/common.h" -#include "cmt/kernels/attribute.h" - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.12), mt_ios(10.0)) -const char* -mtAttributeName(MtAttribute *attr) { - return Cstring([(MTLAttribute*)attr name]); -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.12), mt_ios(10.0)) -NsUInteger -mtAttributeIndex(MtAttribute *attr) { - return [(MTLAttribute*)attr attributeIndex]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.12), mt_ios(10.0)) -MtDataType -mtAttributeDataType(MtAttribute *attr) { - return (MtDataType)[(MTLAttribute*)attr attributeType]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.12), mt_ios(10.0)) -bool -mtAttributeActive(MtAttribute *attr) { - return [(MTLAttribute*)attr isActive]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.12), mt_ios(10.0)) -bool -mtAttributeIsPatchControlPointData(MtAttribute *attr) { - return [(MTLAttribute*)attr isPatchControlPointData]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.12), mt_ios(10.0)) -bool -mtAttributeIsPatchData(MtAttribute *attr) { - return [(MTLAttribute*)attr isPatchData]; -} diff --git a/deps/cmt/src/kernels/attribute_vertex.m b/deps/cmt/src/kernels/attribute_vertex.m deleted file mode 100644 index 88e28f23..00000000 --- a/deps/cmt/src/kernels/attribute_vertex.m +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c), Recep Aslantas. - * MIT License (MIT), http://opensource.org/licenses/MIT - */ - -#include "impl/common.h" -#include "cmt/kernels/attribute.h" - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -const char* -mtVertexAttributeName(MtVertexAttribute *attr) { - return Cstring([(MTLVertexAttribute*)attr name]); -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -NsUInteger -mtVertexAttributeIndex(MtVertexAttribute *attr) { - return [(MTLVertexAttribute*)attr attributeIndex]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -MtDataType -mtVertexAttributeDataType(MtVertexAttribute *attr) { - return (MtDataType)[(MTLVertexAttribute*)attr attributeType]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -bool -mtVertexAttributeActive(MtVertexAttribute *attr) { - return [(MTLVertexAttribute*)attr isActive]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.12), mt_ios(10.0)) -bool -mtVertexAttributeIsPatchControlPointData(MtVertexAttribute *attr) { - return [(MTLVertexAttribute*)attr isPatchControlPointData]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.12), mt_ios(10.0)) -bool -mtVertexAttributeIsPatchData(MtVertexAttribute *attr) { - return [(MTLVertexAttribute*)attr isPatchData]; -} diff --git a/deps/cmt/src/kernels/binary_archive.m b/deps/cmt/src/kernels/binary_archive.m deleted file mode 100644 index e1708c49..00000000 --- a/deps/cmt/src/kernels/binary_archive.m +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (c), Recep Aslantas. - * MIT License (MIT), http://opensource.org/licenses/MIT - */ - -#import "impl/common.h" -#import "cmt/common.h" -#import "cmt/kernels/binary_archive.h" - -CF_RETURNS_RETAINED -MT_EXPORT -MT_API_AVAILABLE(mt_macos(11.0), mt_ios(14.0)) -MtBinaryArchiveDescriptor* -mtNewBinaryArchiveDescriptor(void) { - return [MTLBinaryArchiveDescriptor new]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(11.0), mt_ios(14.0)) -const char* -mtBinaryArchiveDescriptorURL(MtBinaryArchiveDescriptor *desc) { - return (const char*)mtNSURLFileSystemRepresentation((NSURL*)[(MTLBinaryArchiveDescriptor*)desc url]); -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(11.0), mt_ios(14.0)) -void -mtBinaryArchiveDescriptorURLSet(MtBinaryArchiveDescriptor *desc, const char *path) { - [(MTLBinaryArchiveDescriptor*)desc setUrl: mtNSURL(path)]; -} - -CF_RETURNS_RETAINED -MT_EXPORT -MT_API_AVAILABLE(mt_macos(11.0), mt_ios(14.0)) -MtBinaryArchive* -mtNewBinaryArchiveWithDescriptor(MtDevice *device, MtBinaryArchiveDescriptor *desc, NsError **error) { - return [(id)device newBinaryArchiveWithDescriptor: (MtBinaryArchiveDescriptor *)desc error: (NSError**)error]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(11.0), mt_ios(14.0)) -MtDevice* -mtBinaryArchiveDevice(MtBinaryArchive *bin) { - return [(id)bin device]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(11.0), mt_ios(14.0)) -const char* -mtBinaryArchiveLabel(MtBinaryArchive *bin) { - return Cstring([(id)bin label]); -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(11.0), mt_ios(14.0)) -void -mtBinaryArchiveLabelSet(MtBinaryArchive *bin, const char* label) { - ((id)bin).label = mtNSString(label); -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(11.0), mt_ios(14.0)) -void -mtBinaryArchiveAddComputePipelineFunctions(MtBinaryArchive *bin, MtComputePipelineDescriptor *desc, NsError **error) { - [(id)bin addComputePipelineFunctionsWithDescriptor: (MTLComputePipelineDescriptor*)desc error: (NSError**)error]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(11.0), mt_ios(14.0)) -void -mtBinaryArchiveAddFunction(MtBinaryArchive *bin, MtFunctionDescriptor *desc, MtLibrary *lib, NsError **error) { - [(id)bin addFunctionWithDescriptor: (MTLFunctionDescriptor*)desc library: (id)lib error: (NSError**)error]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(11.0), mt_ios(14.0)) -void -mtBinaryArchiveSerialize(MtBinaryArchive *bin, const char *path, NsError **error) { - [(id)bin serializeToURL: mtNSURL(path) error: (NSError**)error]; -} diff --git a/deps/cmt/src/kernels/compile-opts.m b/deps/cmt/src/kernels/compile-opts.m deleted file mode 100644 index 353ec80a..00000000 --- a/deps/cmt/src/kernels/compile-opts.m +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c), Recep Aslantas. - * MIT License (MIT), http://opensource.org/licenses/MIT - */ - -#include "impl/common.h" -#include "cmt/common.h" -#include "cmt/kernels/compile-opts.h" - -CF_RETURNS_RETAINED -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -MT_EXPORT -MtCompileOptions* -mtNewCompileOpts() { - return [MTLCompileOptions new]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -bool -mtCompileOptsFastMath(MtCompileOptions *opts) { - return [(MTLCompileOptions *)(opts) fastMathEnabled]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtCompileOptsFastMathSet(MtCompileOptions *opts, bool val) { - [(MTLCompileOptions *)(opts) setFastMathEnabled:val]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -MtLanguageVersion -mtCompileOptsLanguageVersion(MtCompileOptions *opts) { - return (MtLanguageVersion)[(MTLCompileOptions *)(opts) languageVersion]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtCompileOptsLanguageVersionSet(MtCompileOptions *opts, MtLanguageVersion val) { - return [(MTLCompileOptions *)(opts) setLanguageVersion:(MTLLanguageVersion)val]; -} \ No newline at end of file diff --git a/deps/cmt/src/kernels/constant_values.m b/deps/cmt/src/kernels/constant_values.m deleted file mode 100644 index d8562fb4..00000000 --- a/deps/cmt/src/kernels/constant_values.m +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c), Recep Aslantas. - * MIT License (MIT), http://opensource.org/licenses/MIT - */ - -/* https://developer.apple.com/documentation/metal/mtlfunctionconstantvalues?language=objc */ - -#include "cmt/kernels/constant_values.h" -#include "impl/common.h" - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.12), mt_ios(10.0)) -void -mtFunctionConstantValuesSetWithIndex(MtFunctionConstantValues *funval, const void *value, MtDataType typ, NsUInteger idx) { - [(MTLFunctionConstantValues*)funval setConstantValue: value - type: (MTLDataType)typ - atIndex: idx]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.12), mt_ios(10.0)) -void -mtFunctionConstantValuesSetWithName(MtFunctionConstantValues *funval, const void *value, MtDataType typ, const char* name) { - [(MTLFunctionConstantValues*)funval setConstantValue: value - type: (MTLDataType)typ - withName: mtNSString(name)]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.12), mt_ios(10.0)) -void -mtFunctionConstantValuesSetWithRange(MtFunctionConstantValues *funval, const void *value, MtDataType typ, NsRange range) { - [(MTLFunctionConstantValues*)funval setConstantValues: value - type: (MTLDataType)typ - withRange: mtNSRange(range)]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.12), mt_ios(10.0)) -void -mtFunctionConstantValuesReset(MtFunctionConstantValues *funval){ - [(MTLFunctionConstantValues*)funval reset]; -} diff --git a/deps/cmt/src/kernels/function.m b/deps/cmt/src/kernels/function.m deleted file mode 100644 index cdd7c303..00000000 --- a/deps/cmt/src/kernels/function.m +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Copyright (c), Recep Aslantas. - * MIT License (MIT), http://opensource.org/licenses/MIT - */ - -#import "impl/common.h" -#include "cmt/kernels/function.h" -#import "cmt/error.h" - -CF_RETURNS_RETAINED -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -MtFunction* -mtNewFunctionWithName(MtLibrary *lib, const char *name) { - return [(id)lib newFunctionWithName: mtNSString(name)]; -} - -CF_RETURNS_RETAINED -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.12), mt_ios(10.0)) -MtFunction* -mtNewFunctionWithNameConstantValues(MtLibrary *lib, const char *name, MtFunctionConstantValues *constantValues, NsError **error) { - return [(id)lib newFunctionWithName: mtNSString(name) - constantValues: (MtFunctionConstantValues *)constantValues - error: (NSError**)&error]; -} - -CF_RETURNS_RETAINED -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -MtDevice* -mtFunctionDevice(MtFunction* fun) { - return [(id)fun device]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.12), mt_ios(10.0)) -const char* -mtFunctionLabel(MtFunction* fun) { - return Cstring([(id)fun label]); -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.12), mt_ios(10.0)) -void -mtFunctionLabelSet(MtFunction *fun, const char* label) { - ((id)fun).label = mtNSString(label); -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -MtFunctionType -mtFunctionType(MtFunction* fun) { - return (MtFunctionType)[(id)fun functionType]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -const char* -mtFunctionName(MtFunction* fun) { - return Cstring([(id)fun name]); -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.12), mt_ios(10.0)) -MtAttribute** -mtFunctionStageInputAttributes(MtFunction* fun) { - NSArray *_attributes = [(id)fun stageInputAttributes]; - NSInteger n = [_attributes count]; - MtAttribute* *attributes = malloc(sizeof(MtAttribute*) * (n+1)); - for (int i=0; i < n; i++) { - attributes[i] = [_attributes objectAtIndex:i]; - } - attributes[n] = NULL; - - return attributes; -} - -CF_RETURNS_RETAINED -MT_EXPORT -MT_API_AVAILABLE(mt_macos(11.0), mt_ios(14.0)) -MtFunctionDescriptor* -mtNewFunctionDescriptor(void) { - return [MTLFunctionDescriptor new]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(11.0), mt_ios(14.0)) -const char* -mtFunctionDescriptorName(MtFunctionDescriptor *desc) { - return (const char*)Cstring([(MTLFunctionDescriptor*)desc name]); -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(11.0), mt_ios(14.0)) -void -mtFunctionDescriptorNameSet(MtFunctionDescriptor *desc, const char *name) { - [(MTLFunctionDescriptor*)desc setName: mtNSString(name)]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(11.0), mt_ios(14.0)) -const char* -mtFunctionDescriptorSpecializedName(MtFunctionDescriptor *desc) { - return (const char*)Cstring([(MTLFunctionDescriptor*)desc specializedName]); -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(11.0), mt_ios(14.0)) -void -mtFunctionDescriptorSpecializedNameSet(MtFunctionDescriptor *desc, const char *specializedName) { - [(MTLFunctionDescriptor*)desc setSpecializedName: mtNSString(specializedName)]; -} diff --git a/deps/cmt/src/kernels/library.m b/deps/cmt/src/kernels/library.m deleted file mode 100644 index eaa4e830..00000000 --- a/deps/cmt/src/kernels/library.m +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright (c), Recep Aslantas. - * MIT License (MIT), http://opensource.org/licenses/MIT - */ - -#import "impl/common.h" -#import "cmt/common.h" -#import "cmt/kernels/library.h" - -CF_RETURNS_RETAINED -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -MtLibrary* -mtNewDefaultLibrary(MtDevice *device) { - return [(id)device newDefaultLibrary]; -} - -CF_RETURNS_RETAINED -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -MtLibrary* -mtNewLibraryWithFile(MtDevice *device, const char *filepath, NsError **error) { - return [(id)device newLibraryWithFile: mtNSString(filepath) error: (NSError**)error]; -} - -CF_RETURNS_RETAINED -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -MtLibrary* -mtNewLibraryWithURL(MtDevice *device, const char *path, NsError **error) { - return [(id)device newLibraryWithURL: mtNSURL(path) error: (NSError**)error]; -} - -CF_RETURNS_RETAINED -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -MtLibrary* -mtNewLibraryWithSource(MtDevice *device, const char *source, MtCompileOptions *Opts, NsError **error) { - return [(id)device newLibraryWithSource: mtNSString(source) - options: (MTLCompileOptions*)Opts - error: (NSError**) error]; -} - -CF_RETURNS_RETAINED -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -MtLibrary* -mtNewLibraryWithData(MtDevice *device, const void* buffer, size_t size, NsError **error) { - dispatch_data_t dispatch_data = - dispatch_data_create(buffer, size, dispatch_get_main_queue(), - DISPATCH_DATA_DESTRUCTOR_DEFAULT); - return [(id)device newLibraryWithData: dispatch_data error:(NSError**)error]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -MtDevice* -mtLibraryDevice(MtLibrary *lib) { - return [(id)lib device]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -const char* -mtLibraryLabel(MtLibrary *lib) { - return Cstring([(id)lib label]); -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtLibraryLabelSet(MtLibrary *lib, const char* label) { - ((id)lib).label = mtNSString(label); -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtLibraryFunctionNames(MtLibrary *lib, size_t* count, const char** names) { - NSArray *_names = [(id)lib functionNames]; - NSInteger n = [_names count]; - - if (*count == 0) { - *count = n; - } else { - assert(*count <= n); - for (int i=0; i < *count; i++) - names[i] = Cstring([_names objectAtIndex:i]); - } - return; -} - diff --git a/deps/cmt/src/memory/buffer.m b/deps/cmt/src/memory/buffer.m deleted file mode 100644 index 440e3d71..00000000 --- a/deps/cmt/src/memory/buffer.m +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (c), Recep Aslantas. - * MIT License (MIT), http://opensource.org/licenses/MIT - */ - -#import "impl/common.h" - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void* -mtBufferContents(MtBuffer* buf) { - return [(id)buf contents]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -NsUInteger -mtBufferLength(MtBuffer* buf) { - return [(id)buf length]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtBufferDidModifyRange(MtBuffer* buf, NsRange ran) { - [(id)buf didModifyRange: mtNSRange(ran)]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.12), mt_ios(10.0)) -void -mtBufferAddDebugMarkerRange(MtBuffer* buf, char* string, NsRange range) { - [(id)buf addDebugMarker: mtNSString(string) range:mtNSRange(range)]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.12), mt_ios(10.0)) -void -mtBufferRemoveAllDebugMarkers(MtBuffer* buf) { - [(id)buf removeAllDebugMarkers]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.15)) -MT_API_UNAVAILABLE(mt_ios) -MtBuffer* -mtBufferNewRemoteBufferViewForDevice(MtBuffer *buf, MtDevice *device) { - return [(id)buf newRemoteBufferViewForDevice: (id)device]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.15)) -MT_API_UNAVAILABLE(mt_ios) -MtBuffer* -mtBufferRemoteStorageBuffer(MtBuffer *buf) { - return [(id)buf remoteStorageBuffer]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(13.0), mt_ios(16.0)) -uint64_t -mtBufferGPUAddress(MtBuffer* buf) { - return [(id)buf gpuAddress]; -} diff --git a/deps/cmt/src/memory/heap-descriptor.m b/deps/cmt/src/memory/heap-descriptor.m deleted file mode 100644 index 3dbceeab..00000000 --- a/deps/cmt/src/memory/heap-descriptor.m +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright (c), Recep Aslantas. - * MIT License (MIT), http://opensource.org/licenses/MIT - */ - -#import "impl/common.h" -#import "cmt/common.h" -#import "cmt/memory/heap-descriptor.h" - -CF_RETURNS_RETAINED -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(10.0)) -MtHeapDescriptor* -mtNewHeapDescriptor(void) { - return [MTLHeapDescriptor new]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.15), mt_ios(13.0)) -MtHeapType -mtHeapDescriptorType(MtHeapDescriptor *heap) { - return (MtHeapType)[(MTLHeapDescriptor*)heap type]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.15), mt_ios(13.0)) -void -mtHeapDescriptorTypeSet(MtHeapDescriptor *heap, MtHeapType type) { - [(MTLHeapDescriptor*)heap setType:(MTLHeapType)type]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(10.0)) -MtStorageMode -mtHeapDescriptorStorageMode(MtHeapDescriptor *heap) { - return (MtStorageMode)[(MTLHeapDescriptor*)heap storageMode]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(10.0)) -void -mtHeapDescriptorStorageModeSet(MtHeapDescriptor *heap, MtStorageMode mode) { - [(MTLHeapDescriptor*)heap setStorageMode: (MTLStorageMode)mode]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(10.0)) -MtCPUCacheMode -mtHeapDescriptorCPUCacheMode(MtHeapDescriptor *heap) { - return (MtCPUCacheMode)[(MTLHeapDescriptor*)heap cpuCacheMode]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(10.0)) -void -mtHeapDescriptorCpuCacheModeSet(MtHeapDescriptor *heap, MtCPUCacheMode mode) { - [(MTLHeapDescriptor*)heap setCpuCacheMode:(MTLCPUCacheMode)mode]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.15), mt_ios(13.0)) -MtHazardTrackingMode -mtHeapDescriptorHazardTrackingMode(MtHeapDescriptor *heap) { - return (MtHazardTrackingMode)[(MTLHeapDescriptor*)heap hazardTrackingMode]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.15), mt_ios(13.0)) -void -mtHeapDescriptorHazardTrackingModeSet(MtHeapDescriptor *heap, MtHazardTrackingMode mode) { - [(MTLHeapDescriptor*)heap setHazardTrackingMode: (MTLHazardTrackingMode)mode]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.15), mt_ios(13.0)) -MtResourceOptions -mtHeapDescriptorResourceOptions(MtHeapDescriptor *heap) { - return (MtResourceOptions)[(MTLHeapDescriptor*)heap resourceOptions]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.15), mt_ios(13.0)) -void -mtHeapDescriptorResourceOptionsSet(MtHeapDescriptor *heap, MtResourceOptions opts) { - [(MTLHeapDescriptor*)heap setResourceOptions:(MTLResourceOptions)opts]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(10.0)) -NsUInteger -mtHeapDescriptorSize(MtHeapDescriptor *heap) { - return [(MTLHeapDescriptor*)heap size]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(10.0)) -void -mtHeapDescriptorSizeSet(MtHeapDescriptor *heap, NsUInteger size) { - [(MTLHeapDescriptor*)heap setSize:size]; -} diff --git a/deps/cmt/src/memory/heap.m b/deps/cmt/src/memory/heap.m deleted file mode 100644 index 5e9b46c0..00000000 --- a/deps/cmt/src/memory/heap.m +++ /dev/null @@ -1,138 +0,0 @@ -/* - * Copyright (c), Recep Aslantas. - * MIT License (MIT), http://opensource.org/licenses/MIT - */ - -#include "impl/common.h" -#include "cmt/common.h" -#include "cmt/memory/heap.h" - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(10.0)) -MtHeap* -mtDeviceNewHeapWithDescriptor(MtDevice *dev, MtHeapDescriptor *descriptor) { - return [(id)dev newHeapWithDescriptor:(MTLHeapDescriptor*)descriptor]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(10.0)) -MtDevice* -mtHeapDevice(MtHeap *heap) { - return [(id)heap device]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(10.0)) -const char* -mtHeapLabel(MtHeap *heap) { - return Cstring([(id)heap label]); -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(10.0)) -void -mtHeapLabelSet(MtHeap *heap, const char* label) { - ((id)heap).label = mtNSString(label); -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.15), mt_ios(13.0)) -MtHeapType -mtHeapType(MtHeap *heap) { - return (MtHeapType)[(id)heap type]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(10.0)) -MtStorageMode -mtHeapStorageMode(MtHeap *heap) { - return (MtStorageMode)[(id)heap storageMode]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(10.0)) -MtCPUCacheMode -mtHeapCPUCacheMode(MtHeap *heap) { - return (MtCPUCacheMode)[(id)heap cpuCacheMode]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.15), mt_ios(13.0)) -MtHazardTrackingMode -mtHeapHazardTrackingMode(MtHeap *heap) { - return (MtHazardTrackingMode)[(id)heap hazardTrackingMode]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.15), mt_ios(13.0)) -MtResourceOptions -mtHeapResourceOptions(MtHeap *heap) { - return (MtResourceOptions)[(id)heap resourceOptions]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(10.0)) -NsUInteger -mtHeapSize(MtHeap *heap) { - return [(id)heap size]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(10.0)) -NsUInteger -mtHeapUsedSize(MtHeap *heap) { - return [(id)heap usedSize]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(10.0)) -NsUInteger -mtHeapCurrentAllocatedSize(MtHeap *heap) { - return [(id)heap currentAllocatedSize]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(10.0)) -NsUInteger -mtHeapMaxAvailableSizeWithAlignment(MtHeap *heap, NsUInteger alignment) { - return [(id)heap maxAvailableSizeWithAlignment: alignment]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(10.0)) -MtPurgeableState -mtHeapSetPurgeableState(MtHeap *heap, MtPurgeableState state) { - return (MtPurgeableState)[(id)heap setPurgeableState: (MTLPurgeableState)state]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(10.0)) -MtBuffer* -mtHeapNewBufferWithLength(MtHeap *heap, NsUInteger len, MtResourceOptions opt) { - return [(id)heap newBufferWithLength:len - options:(MTLResourceOptions)opt]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.15), mt_ios(13.0)) -MtBuffer* -mtHeapNewBufferWithLengthOffset(MtHeap *heap, NsUInteger len, MtResourceOptions opt, NsUInteger offset) { - return [(id)heap newBufferWithLength: len - options: (MTLResourceOptions)opt - offset: offset]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(10.0)) -MtTexture* -mtHeapNewTextureWithDescriptor(MtHeap *heap, MtTextureDescriptor *desc) { - return [(id)heap newTextureWithDescriptor: (MTLTextureDescriptor*)desc]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.15), mt_ios(13.0)) -MtTexture* -mtHeapNewTextureWithDescriptorOffset(MtHeap *heap, MtTextureDescriptor *desc, NsUInteger offset) { - return [(id)heap newTextureWithDescriptor: (MTLTextureDescriptor*)desc - offset: offset]; -} diff --git a/deps/cmt/src/memory/vertex.m b/deps/cmt/src/memory/vertex.m deleted file mode 100644 index 2a8e5ed5..00000000 --- a/deps/cmt/src/memory/vertex.m +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (c), Recep Aslantas. - * MIT License (MIT), http://opensource.org/licenses/MIT - */ - -#import "impl/common.h" -#import "cmt/common.h" -#import "impl/common.h" -#import "cmt/memory/vertex.h" - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -MtVertexDescriptor* -mtVertexDescNew() { - MTLVertexDescriptor *mvertDesc; - mvertDesc = [MTLVertexDescriptor vertexDescriptor]; - return mvertDesc; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtVertexAttrib(MtVertexDescriptor * __restrict vertex, - uint32_t attribIndex, - MtVertexFormat format, - uint32_t offset, - uint32_t bufferIndex) { - MTLVertexDescriptor *mvert; - MTLVertexAttributeDescriptor *mattrib; - - mvert = vertex; - mattrib = mvert.attributes[attribIndex]; - - mattrib.format = (MTLVertexFormat)format; - mattrib.offset = offset; - mattrib.bufferIndex = bufferIndex; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtVertexLayout(MtVertexDescriptor * __restrict vertex, - uint32_t layoutIndex, - uint32_t stride, - uint32_t stepRate, - MtVertexStepFunction stepFunction) { - MTLVertexDescriptor *mvert; - MTLVertexBufferLayoutDescriptor *mlay; - - mvert = vertex; - mlay = mvert.layouts[layoutIndex]; - - mlay.stride = stride; - mlay.stepRate = stepRate; - mlay.stepFunction = (MTLVertexStepFunction)stepFunction; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtSetVertexDesc(MtRenderPipeline * __restrict pipeline, - MtVertexDescriptor * __restrict vert) { - MTLRenderPipelineDescriptor *mpip; - - mpip = pipeline; - - mpip.vertexDescriptor = vert; -} diff --git a/deps/cmt/src/performance_shaders/device.m b/deps/cmt/src/performance_shaders/device.m deleted file mode 100644 index 08ed6ff9..00000000 --- a/deps/cmt/src/performance_shaders/device.m +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright (c), Recep Aslantas. - * MIT License (MIT), http://opensource.org/licenses/MIT - */ - -#import "impl/common.h" -#import "cmt/performance_shaders/device.h" - -#include - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(9.0)) -bool -mtMPSSupportsMTLDevice(MtDevice* device) { - return (bool)MPSSupportsMTLDevice(device); -} diff --git a/deps/cmt/src/performance_shaders/matrix.m b/deps/cmt/src/performance_shaders/matrix.m deleted file mode 100644 index eb5a6bf9..00000000 --- a/deps/cmt/src/performance_shaders/matrix.m +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (c), Recep Aslantas. - * MIT License (MIT), http://opensource.org/licenses/MIT - */ - -#import "impl/common.h" -#import "cmt/performance_shaders/matrix.h" - -#include - -CF_RETURNS_RETAINED -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -MtMPSMatrixDescriptor* -mtNewMatrixDescriptorWithRows(NSUInteger rows, NSUInteger columns, NSUInteger rowBytes, - uint32_t dataType){ - return [MPSMatrixDescriptor matrixDescriptorWithRows: (NSUInteger)rows - columns: (NSUInteger)columns - rowBytes: (NSUInteger)rowBytes - dataType: (uint32_t)dataType]; -} - -CF_RETURNS_RETAINED -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(10.0)) -MtMPSMatrix* -mtNewMPSMatrixInitWithBuffer(MtBuffer *buffer, MtMPSMatrixDescriptor *descriptor){ - return (MtMPSMatrix*)[[MPSMatrix alloc] initWithBuffer: (id)buffer - descriptor: (MPSMatrixDescriptor*)descriptor]; -} - -CF_RETURNS_RETAINED -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(10.0)) -MtMPSMatrixMultiplication* -mtNewMPSMatrixMultiplication(MtDevice *device, bool transposeLeft, bool transposeRight, - NsUInteger resultRows, NsUInteger resultColumns, - NsUInteger interiorColumns, double alpha, double beta){ - -return (MtMPSMatrix *)[[MPSMatrixMultiplication alloc] initWithDevice:(id)device - transposeLeft:(BOOL)transposeLeft - transposeRight:(BOOL)transposeRight - resultRows:(NSUInteger)resultRows - resultColumns:(NSUInteger)resultColumns - interiorColumns:(NSUInteger)interiorColumns - alpha:(double)alpha - beta:(double)beta]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(10.0)) -void -mtMPSMatMulEncodeToCommandBuffer(MtMPSMatrixMultiplication *matMul, MtCommandBuffer *commandBuffer, MtMPSMatrix * leftMatrix, - MtMPSMatrix *rightMatrix, MtMPSMatrix *resultMatrix){ - [(MPSMatrixMultiplication *)matMul encodeToCommandBuffer:(id)commandBuffer - leftMatrix:(MPSMatrix *)leftMatrix - rightMatrix:(MPSMatrix *)rightMatrix - resultMatrix:(MPSMatrix *)resultMatrix]; -} diff --git a/deps/cmt/src/reflection/argument.m b/deps/cmt/src/reflection/argument.m deleted file mode 100644 index 9f7461f7..00000000 --- a/deps/cmt/src/reflection/argument.m +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (c), Recep Aslantas. - * MIT License (MIT), http://opensource.org/licenses/MIT - */ - -#include "impl/common.h" -#include "cmt/reflection/argument.h" - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -const char* -mtArgumentName(MtArgument *arg) { - return Cstring([(MTLArgument*)arg name]); -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -bool -mtArgumentActive(MtArgument *arg) { - return [(MTLArgument*)arg isActive]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -NsUInteger -mtArgumentIndex(MtArgument *arg) { - return [(MTLArgument*)arg index]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -MtArgumentType -mtArgumentType(MtArgument *arg) { - return (MtArgumentType)[(MTLArgument *)arg type]; -} - -// Buffer -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -NsUInteger -mtArgumentBufferAlignment(MtArgument *arg) { - return [(MTLArgument*)arg bufferAlignment]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -NsUInteger -mtArgumentBufferDataSize(MtArgument *arg) { - return [(MTLArgument*)arg bufferDataSize]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -MtDataType -mtArgumentBufferDataType(MtArgument *arg) { - return (MtDataType)[(MTLArgument *)arg bufferDataType]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -MtStructType* -mtArgumentBufferStructType(MtArgument *arg) { - return [(MTLArgument*)arg bufferStructType]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -MtPointerType* -mtArgumentBufferPointerType(MtArgument *arg) { - return [(MTLArgument*)arg bufferPointerType]; -} - -// Array -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(10.0)) -NsUInteger -mtArgumentArrayLength(MtArgument *arg) { - return [(MTLArgument*)arg arrayLength]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -NsUInteger -mtArgumentThreadgroupMemoryAlignment(MtArgument *arg) { - return [(MTLArgument*)arg threadgroupMemoryAlignment]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -NsUInteger -mtArgumentThreadgroupMemoryDataSize(MtArgument *arg) { - return [(MTLArgument*)arg threadgroupMemoryDataSize]; -} - diff --git a/deps/cmt/src/reflection/descriptor.m b/deps/cmt/src/reflection/descriptor.m deleted file mode 100644 index 05e6641f..00000000 --- a/deps/cmt/src/reflection/descriptor.m +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c), Recep Aslantas. - * MIT License (MIT), http://opensource.org/licenses/MIT - */ - -#include "impl/common.h" -#include "cmt/reflection/descriptor.h" - -CF_RETURNS_RETAINED -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -MtComputePipelineReflection* -mtNewComputePipelineReflection() { - return [MTLComputePipelineReflection new]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -const MtArgument * -mtComputePipelinereflectionArguments(MtComputePipelineReflection *refl) { - NSArray *_args = [(MTLComputePipelineReflection*) refl arguments]; - - NSInteger n = [_args count]; - MtArgument* *args = malloc(sizeof(MtArgument*) * (n+1)); - for (int i=0; i < n; i++) { - args[i] = [_args objectAtIndex:i]; - } - args[n] = NULL; - - return args; -} diff --git a/deps/cmt/src/reflection/pointer_type.m b/deps/cmt/src/reflection/pointer_type.m deleted file mode 100644 index 349854c0..00000000 --- a/deps/cmt/src/reflection/pointer_type.m +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (c), Recep Aslantas. - * MIT License (MIT), http://opensource.org/licenses/MIT - */ - -#include "impl/common.h" -#include "cmt/reflection/pointer_type.h" - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -MtDataType -mtPointerTypeElementType(MtPointerType *ptr) { - return (MtDataType)[(MTLPointerType *)ptr elementType]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -MtArgumentAccess -mtPointerTypeAccess(MtPointerType *ptr) { - return (MtArgumentAccess)[(MTLPointerType*)ptr access]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -NsUInteger -mtPointerTypeAlignment(MtPointerType *ptr) { - return [(MTLPointerType*)ptr alignment]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -NsUInteger -mtPointerTypeDataSize(MtPointerType *ptr) { - return [(MTLPointerType*)ptr dataSize]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -bool -mtPointerTypeElementIsArgumentBuffer(MtPointerType *ptr) { - return [(MTLPointerType*)ptr elementIsArgumentBuffer]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -MtStructType* -mtPointerTypeElementStructType(MtPointerType *ptr) { - return [(MTLPointerType*)ptr elementStructType]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.13), mt_ios(11.0)) -MtArrayType* -mtPointerTypeElementArrayType(MtPointerType *ptr) { - return [(MTLPointerType*)ptr elementArrayType]; -} diff --git a/deps/cmt/src/rendering/depthstencil.m b/deps/cmt/src/rendering/depthstencil.m deleted file mode 100644 index 559b6e27..00000000 --- a/deps/cmt/src/rendering/depthstencil.m +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright (c), Recep Aslantas. - * MIT License (MIT), http://opensource.org/licenses/MIT - */ - -#import "impl/common.h" -#import "cmt/rendering/depthstencil.h" - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -MtDepthStencil* -mtDepthStencil(MtCompareFunction depthCompareFunc, bool depthWriteEnabled) { - MTLDepthStencilDescriptor *depthStateDesc; - - depthStateDesc = [MTLDepthStencilDescriptor new]; - depthStateDesc.depthCompareFunction = (MTLCompareFunction)depthCompareFunc; - depthStateDesc.depthWriteEnabled = depthWriteEnabled; - - return depthStateDesc; -} diff --git a/deps/cmt/src/rendering/rpass.m b/deps/cmt/src/rendering/rpass.m deleted file mode 100644 index 300a07f6..00000000 --- a/deps/cmt/src/rendering/rpass.m +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c), Recep Aslantas. - * MIT License (MIT), http://opensource.org/licenses/MIT - */ - -#import "impl/common.h" -#import "cmt/rendering/pass.h" - -CF_RETURNS_RETAINED -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -MtRenderPassDesc* -mtNewPass() { - return [MTLRenderPassDescriptor new]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtPassTexture(MtRenderPassDesc *pass, - int colorAttch, - MtTexture *tex) { - MTLRenderPassDescriptor *mpass; - - mpass = pass; - - mpass.colorAttachments[colorAttch].texture = tex; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtPassLoadAction(MtRenderPassDesc *pass, - int colorAttch, - MtLoadAction action) { - MTLRenderPassDescriptor *mpass; - - mpass = pass; - - mpass.colorAttachments[colorAttch].loadAction = (MTLLoadAction)action; -} diff --git a/deps/cmt/src/rendering/rpip.m b/deps/cmt/src/rendering/rpip.m deleted file mode 100644 index 61b5d7a3..00000000 --- a/deps/cmt/src/rendering/rpip.m +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (c), Recep Aslantas. - * MIT License (MIT), http://opensource.org/licenses/MIT - */ - -#import "impl/common.h" -#import "cmt/common.h" -#import "cmt/pixelformat.h" - -#import "cmt/rendering/pass.h" -#import "cmt/rendering/pipeline.h" - -CF_RETURNS_RETAINED -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -MtRenderDesc* -mtNewRenderPipeline(MtPixelFormat pixelFormat) { - MTLRenderPipelineDescriptor *mpipDesc; - mpipDesc = [MTLRenderPipelineDescriptor new]; - mpipDesc.colorAttachments[0].pixelFormat = (MTLPixelFormat)pixelFormat; - return mpipDesc; -} - -CF_RETURNS_RETAINED -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -MtRenderPipeline* -mtNewRenderState(MtDevice *device, MtRenderDesc *pipDesc, NsError **error) { - return [(id)device - newRenderPipelineStateWithDescriptor: (MTLRenderPipelineDescriptor *)pipDesc - error: (NSError**)&error]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtSetFunc(MtRenderDesc *pipDesc, - MtFunction *func, - MtFuncType functype) { - MTLRenderPipelineDescriptor *mpip; - - mpip = pipDesc; - - switch (functype) { - case MT_FUNC_VERT: - mpip.vertexFunction = func; - break; - case MT_FUNC_FRAG: - mpip.fragmentFunction = func; - break; - default: break; - } -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtColorPixelFormat(MtRenderDesc * __restrict renderdesc, - uint32_t index, - MtPixelFormat pixelFormat) { - MTLRenderPipelineDescriptor *mpipDesc; - mpipDesc = renderdesc; - mpipDesc.colorAttachments[index].pixelFormat = (MTLPixelFormat)pixelFormat; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtDepthPixelFormat(MtRenderDesc * __restrict renderdesc, - MtPixelFormat pixelFormat) { - MTLRenderPipelineDescriptor *mpipDesc; - mpipDesc = renderdesc; - mpipDesc.depthAttachmentPixelFormat = (MTLPixelFormat)pixelFormat; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtStencilPixelFormat(MtRenderDesc * __restrict renderdesc, - MtPixelFormat pixelFormat) { - MTLRenderPipelineDescriptor *mpipDesc; - mpipDesc = renderdesc; - mpipDesc.stencilAttachmentPixelFormat = (MTLPixelFormat)pixelFormat; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtSampleCount(MtRenderDesc * __restrict renderdesc, - uint32_t sampleCount) { - MTLRenderPipelineDescriptor *mpipDesc; - mpipDesc = renderdesc; - mpipDesc.sampleCount = sampleCount; -} diff --git a/deps/cmt/src/resource.m b/deps/cmt/src/resource.m deleted file mode 100644 index 03c36e33..00000000 --- a/deps/cmt/src/resource.m +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (c), Recep Aslantas. - * MIT License (MIT), http://opensource.org/licenses/MIT - */ - -#include "impl/common.h" -#include "cmt/resource.h" - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -MtDevice* -mtResourceDevice(MtResource *res) { - return [(id)res device]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -const char* -mtResourceLabel(MtResource *res) { - return Cstring([(id)res label]); -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -void -mtResourceLabelSet(MtResource *res, const char* label) { - ((id)res).label = mtNSString(label); -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -MtCPUCacheMode -mtResourceCPUCacheMode(MtResource *res) { - return (MtCPUCacheMode)[(id)res cpuCacheMode]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.11), mt_ios(8.0)) -MtStorageMode -mtResourceStorageMode(MtResource *res) { - return (MtStorageMode)[(id)res storageMode]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.15), mt_ios(13.0)) -MtHazardTrackingMode -mtResourceHazardTrackingMode(MtResource *res) { - return (MtHazardTrackingMode)[(id)res hazardTrackingMode]; -} - -MT_EXPORT -MT_API_AVAILABLE(mt_macos(10.15), mt_ios(13.0)) -MtResourceOptions -mtResourceOptions(MtResource *res) { - return (MtResourceOptions)[(id)res resourceOptions]; -} diff --git a/deps/cmt/src/utils/conversion.m b/deps/cmt/src/utils/conversion.m deleted file mode 100644 index d5cbed35..00000000 --- a/deps/cmt/src/utils/conversion.m +++ /dev/null @@ -1,6 +0,0 @@ -/* - * Copyright (c), Recep Aslantas. - * MIT License (MIT), http://opensource.org/licenses/MIT - */ - -#include "impl/conversion.h" diff --git a/lib/cmt/cmt.jl b/lib/cmt/cmt.jl deleted file mode 100644 index 4fd3abc5..00000000 --- a/lib/cmt/cmt.jl +++ /dev/null @@ -1,24 +0,0 @@ -module cmt - -using cmt_jll - -include("libcmt.jl") - -# export everything -for n in names(@__MODULE__; all=true) - if Base.isidentifier(n) && n ∉ (Symbol(@__MODULE__), :eval, :include) - @eval export $n - end -end - -function __init__() - precompiling = ccall(:jl_generating_output, Cint, ()) != 0 - precompiling && return - - if !cmt_jll.is_available() - @error """Metal library wrapper not available for your platform.""" - return - end -end - -end diff --git a/lib/cmt/libcmt.jl b/lib/cmt/libcmt.jl deleted file mode 100644 index 1ad4b483..00000000 --- a/lib/cmt/libcmt.jl +++ /dev/null @@ -1,2476 +0,0 @@ -using CEnum - -const NsUInteger = Culong - -const NsInteger = Clong - -const CfTimeInterval = Cdouble - -struct NsRange - location::NsUInteger - length::NsUInteger -end - -struct NsError - #= /Users/tim/Julia/pkg/Metal/res/wrap.jl:39 =# -end - -struct NsDictionaryStringString - keys::Ptr{Cstring} - values::Ptr{Cstring} -end - -@cenum MtPrimitiveType::UInt32 begin - MtPrimitiveTypePoint = 0 - MtPrimitiveTypeLine = 1 - MtPrimitiveTypeLineStrip = 2 - MtPrimitiveTypeTriangle = 3 - MtPrimitiveTypeTriangleStrip = 4 -end - -@cenum MtVisibilityResultMode::UInt32 begin - MtVisibilityResultModeDisabled = 0 - MtVisibilityResultModeBoolean = 1 - MtVisibilityResultModeCounting = 2 -end - -struct MtScissorRect - x::UInt32 - y::UInt32 - width::UInt32 - height::UInt32 -end - -struct MtViewport - originX::Cdouble - originY::Cdouble - width::Cdouble - height::Cdouble - znear::Cdouble - zfar::Cdouble -end - -@cenum MtCullMode::UInt32 begin - MtCullModeNone = 0 - MtCullModeFront = 1 - MtCullModeBack = 2 -end - -@cenum MtWinding::UInt32 begin - MtWindingClockwise = 0 - MtWindingCounterClockwise = 1 -end - -@cenum MtDepthClipMode::UInt32 begin - MtDepthClipModeClip = 0 - MtDepthClipModeClamp = 1 -end - -@cenum MtTriangleFillMode::UInt32 begin - MtTriangleFillModeFill = 0 - MtTriangleFillModeLines = 1 -end - -struct MtDrawPrimitivesIndirectArguments - vertexCount::UInt32 - instanceCount::UInt32 - vertexStart::UInt32 - baseInstance::UInt32 -end - -struct MtDrawIndexedPrimitivesIndirectArguments - indexCount::UInt32 - instanceCount::UInt32 - indexStart::UInt32 - baseVertex::Int32 - baseInstance::UInt32 -end - -struct MtDrawPatchIndirectArguments - patchCount::UInt32 - instanceCount::UInt32 - patchStart::UInt32 - baseInstance::UInt32 -end - -struct MtQuadTessellationFactorsHalf - edgeTessellationFactor::NTuple{4, UInt16} - insideTessellationFactor::NTuple{2, UInt16} -end - -struct MtTriangleTessellationFactorsHalf - edgeTessellationFactor::NTuple{3, UInt16} - insideTessellationFactor::UInt16 -end - -@cenum MtRenderStages::UInt32 begin - MtRenderStageVertex = 1 - MtRenderStageFragment = 2 -end - -@cenum MtLoadAction::UInt32 begin - MtLoadActionDontCare = 0 - MtLoadActionLoad = 1 - MtLoadActionClear = 2 -end - -@cenum MtIndexType::UInt32 begin - MtIndexTypeUInt16 = 0 - MtIndexTypeUInt32 = 1 -end - -@cenum MtStoreAction::UInt32 begin - MtStoreActionDontCare = 0 - MtStoreActionStore = 1 - MtStoreActionMultisampleResolve = 2 - MtStoreActionStoreAndMultisampleResolve = 3 - MtStoreActionUnknown = 4 - MtStoreActionCustomSampleDepthStore = 5 -end - -@cenum MtDeviceLocation::UInt32 begin - MtDeviceLocationBuiltIn = 0 - MtDeviceLocationSlot = 1 - MtDeviceLocationExternal = 2 - MtDeviceLocationUnspecified = 100 -end - -@cenum MtLanguageVersion::UInt32 begin - MtLanguageVersion1_0 = 65536 - MtLanguageVersion1_1 = 65537 - MtLanguageVersion1_2 = 65538 - MtLanguageVersion2_0 = 131072 - MtLanguageVersion2_1 = 131073 - MtLanguageVersion2_2 = 131074 - MtLanguageVersion2_3 = 131075 - MtLanguageVersion2_4 = 131076 -end - -@cenum MtFunctionType::UInt32 begin - MtFunctionTypeVertex = 1 - MtFunctionTypeFragment = 2 - MtFunctionTypeKernel = 3 -end - -@cenum MtDispatchType::UInt32 begin - MtDispatchTypeSerial = 0 - MtDispatchTypeConcurrent = 1 -end - -@cenum MtCommandBufferStatus::UInt32 begin - MtCommandBufferStatusNotEnqueued = 0 - MtCommandBufferStatusEnqueued = 1 - MtCommandBufferStatusCommitted = 2 - MtCommandBufferStatusScheduled = 3 - MtCommandBufferStatusCompleted = 4 - MtCommandBufferStatusError = 5 -end - -@cenum MtResourceUsage::UInt32 begin - MtResourceUsageRead = 1 - MtResourceUsageWrite = 2 - MtResourceUsageSample = 4 -end - -@cenum MtGPUFamily::UInt32 begin - MtGPUFamilyApple1 = 1001 - MtGPUFamilyApple2 = 1002 - MtGPUFamilyApple3 = 1003 - MtGPUFamilyApple4 = 1004 - MtGPUFamilyApple5 = 1005 - MtGPUFamilyMac1 = 2001 - MtGPUFamilyMac2 = 2002 - MtGPUFamilyCommon1 = 3001 - MtGPUFamilyCommon2 = 3002 - MtGPUFamilyCommon3 = 3003 - MtGPUFamilyMacCatalyst1 = 4001 - MtGPUFamilyMacCatalyst2 = 4002 -end - -@cenum MtFeatureSet::UInt32 begin - MtFeatureSet_macOS_GPUFamily1_v1 = 10000 - MtFeatureSet_OSX_GPUFamily1_v1 = 10000 - MtFeatureSet_macOS_GPUFamily1_v2 = 10001 - MtFeatureSet_OSX_GPUFamily1_v2 = 10001 - MtFeatureSet_macOS_ReadWriteTextureTier2 = 10002 - MtFeatureSet_OSX_ReadWriteTextureTier2 = 10002 - MtFeatureSet_macOS_GPUFamily1_v3 = 10003 - MtFeatureSet_macOS_GPUFamily1_v4 = 10004 - MtFeatureSet_macOS_GPUFamily2_v1 = 10005 -end - -@cenum MtPurgeableState::UInt32 begin - MtPurgeableStateKeepCurrent = 1 - MtPurgeableStateNonVolatile = 2 - MtPurgeableStateVolatile = 3 - MtPurgeableStateEmpty = 4 -end - -@cenum MtCommandBufferError::UInt32 begin - MtCommandBufferErrorNone = 0 - MtCommandBufferErrorInternal = 1 - MtCommandBufferErrorTimeout = 2 - MtCommandBufferErrorPageFault = 3 - MtCommandBufferErrorBlacklisted = 4 - MtCommandBufferErrorNotPermitted = 7 - MtCommandBufferErrorOutOfMemory = 8 - MtCommandBufferErrorInvalidResource = 9 - MtCommandBufferErrorMemoryless = 10 - MtCommandBufferErrorDeviceRemoved = 11 -end - -@cenum MtCommandBufferErrorOption::UInt32 begin - MtCommandBufferErrorOptionNone = 0 - MtCommandBufferErrorOptionEncoderExecutionStatus = 1 -end - -@cenum MtCommandEncoderErrorState::UInt32 begin - MtCommandEncodererrorStateUnknown = 0 - MtCommandEncodererrorStateCompleted = 1 - MtCommandEncodererrorStateAffected = 2 - MtCommandEncodererrorStatePending = 3 - MtCommandEncodererrorStateFaulted = 4 -end - -const MtCommandencoderErrorState = MtCommandEncoderErrorState - -@cenum MtHeapType::UInt32 begin - MtHeapTypeAutomatic = 0 - MtHeapTypePlacement = 1 -end - -@cenum MtBlitOption::UInt32 begin - MtBlitOptionNone = 0 - MtBlitOptionDepthFromDepthStencil = 1 - MtBlitOptionStencilFromDepthStencil = 2 -end - -@cenum MtLibraryError::UInt32 begin - MtLibraryErrorUnsupported = 1 - MtLibraryErrorInternal = 2 - MtLibraryErrorCompileFailure = 3 - MtLibraryErrorCompileWarning = 4 - MtLibraryErrorFunctionNotFound = 5 - MtLibraryErrorFileNotFound = 6 -end - -@cenum MtBarrierScope::UInt32 begin - MtBarrierScopeBuffers = 1 - MtBarrierScopeTextures = 2 - MtBarrierScopeRenderTargets = 4 -end - -@cenum MtIndirectCommandType::UInt32 begin - MIndirectCommandTypeDraw = 1 - MIndirectCommandTypeDrawIndexed = 2 - MIndirectCommandTypeDrawPatches = 4 - MIndirectCommandTypeDrawIndexedPatches = 8 -end - -@cenum MtDataType::UInt32 begin - MtDataTypeNone = 0 - MtDataTypeStruct = 1 - MtDataTypeArray = 2 - MtDataTypeFloat = 3 - MtDataTypeFloat2 = 4 - MtDataTypeFloat3 = 5 - MtDataTypeFloat4 = 6 - MtDataTypeFloat2x2 = 7 - MtDataTypeFloat2x3 = 8 - MtDataTypeFloat2x4 = 9 - MtDataTypeFloat3x2 = 10 - MtDataTypeFloat3x3 = 11 - MtDataTypeFloat3x4 = 12 - MtDataTypeFloat4x2 = 13 - MtDataTypeFloat4x3 = 14 - MtDataTypeFloat4x4 = 15 - MtDataTypeHalf = 16 - MtDataTypeHalf2 = 17 - MtDataTypeHalf3 = 18 - MtDataTypeHalf4 = 19 - MtDataTypeHalf2x2 = 20 - MtDataTypeHalf2x3 = 21 - MtDataTypeHalf2x4 = 22 - MtDataTypeHalf3x2 = 23 - MtDataTypeHalf3x3 = 24 - MtDataTypeHalf3x4 = 25 - MtDataTypeHalf4x2 = 26 - MtDataTypeHalf4x3 = 27 - MtDataTypeHalf4x4 = 28 - MtDataTypeInt = 29 - MtDataTypeInt2 = 30 - MtDataTypeInt3 = 31 - MtDataTypeInt4 = 32 - MtDataTypeUInt = 33 - MtDataTypeUInt2 = 34 - MtDataTypeUInt3 = 35 - MtDataTypeUInt4 = 36 - MtDataTypeShort = 37 - MtDataTypeShort2 = 38 - MtDataTypeShort3 = 39 - MtDataTypeShort4 = 40 - MtDataTypeUShort = 41 - MtDataTypeUShort2 = 42 - MtDataTypeUShort3 = 43 - MtDataTypeUShort4 = 44 - MtDataTypeChar = 45 - MtDataTypeChar2 = 46 - MtDataTypeChar3 = 47 - MtDataTypeChar4 = 48 - MtDataTypeUChar = 49 - MtDataTypeUChar2 = 50 - MtDataTypeUChar3 = 51 - MtDataTypeUChar4 = 52 - MtDataTypeBool = 53 - MtDataTypeBool2 = 54 - MtDataTypeBool3 = 55 - MtDataTypeBool4 = 56 - MtDataTypeTexture = 58 - MtDataTypeSampler = 59 - MtDataTypePointer = 60 - MtDataTypeRenderPipeline = 78 - MtDataTypeIndirectCommandBuffer = 80 -end - -@cenum MtArgumentAccess::UInt32 begin - MtArgumentAccessReadOnly = 0 - MtArgumentAccessReadWrite = 1 - MtArgumentAccessWriteOnly = 2 -end - -@cenum MtArgumentBuffersTier::UInt32 begin - MtArgumentBuffersTier1 = 0 - MtArgumentBuffersTier2 = 1 -end - -@cenum MtTextureType::UInt32 begin - MtTextureType1D = 0 - MtTextureType1DArray = 1 - MtTextureType2D = 2 - MtTextureType2DArray = 3 - MtTextureType2DMultisample = 4 - MtTextureTypeCube = 5 - MtTextureTypeCubeArray = 6 - MtTextureType3D = 7 - MtTextureType2DMultisampleArray = 8 - MtTextureTypeTextureBuffer = 9 -end - -@cenum MtTextureSwizzle::UInt32 begin - MtTextureSwizzleZero = 0 - MtTextureSwizzleOne = 1 - MtTextureSwizzleRed = 2 - MtTextureSwizzleGreen = 3 - MtTextureSwizzleBlue = 4 - MtTextureSwizzleAlpha = 5 -end - -@cenum MtAttributeFormat::UInt32 begin - MtAttributeFormatInvalid = 0 - MtAttributeFormatUChar2 = 1 - MtAttributeFormatUChar3 = 2 - MtAttributeFormatUChar4 = 3 - MtAttributeFormatChar2 = 4 - MtAttributeFormatChar3 = 5 - MtAttributeFormatChar4 = 6 - MtAttributeFormatUChar2Normalized = 7 - MtAttributeFormatUChar3Normalized = 8 - MtAttributeFormatUChar4Normalized = 9 - MtAttributeFormatChar2Normalized = 10 - MtAttributeFormatChar3Normalized = 11 - MtAttributeFormatChar4Normalized = 12 - MtAttributeFormatUShort2 = 13 - MtAttributeFormatUShort3 = 14 - MtAttributeFormatUShort4 = 15 - MtAttributeFormatShort2 = 16 - MtAttributeFormatShort3 = 17 - MtAttributeFormatShort4 = 18 - MtAttributeFormatUShort2Normalized = 19 - MtAttributeFormatUShort3Normalized = 20 - MtAttributeFormatUShort4Normalized = 21 - MtAttributeFormatShort2Normalized = 22 - MtAttributeFormatShort3Normalized = 23 - MtAttributeFormatShort4Normalized = 24 - MtAttributeFormatHalf2 = 25 - MtAttributeFormatHalf3 = 26 - MtAttributeFormatHalf4 = 27 - MtAttributeFormatFloat = 28 - MtAttributeFormatFloat2 = 29 - MtAttributeFormatFloat3 = 30 - MtAttributeFormatFloat4 = 31 - MtAttributeFormatInt = 32 - MtAttributeFormatInt2 = 33 - MtAttributeFormatInt3 = 34 - MtAttributeFormatInt4 = 35 - MtAttributeFormatUInt = 36 - MtAttributeFormatUInt2 = 37 - MtAttributeFormatUInt3 = 38 - MtAttributeFormatUInt4 = 39 - MtAttributeFormatInt1010102Normalized = 40 - MtAttributeFormatUInt1010102Normalized = 41 - MtAttributeFormatUChar4Normalized_BGRA = 42 - MtAttributeFormatUChar = 45 - MtAttributeFormatChar = 46 - MtAttributeFormatUCharNormalized = 47 - MtAttributeFormatCharNormalized = 48 - MtAttributeFormatUShort = 49 - MtAttributeFormatShort = 50 - MtAttributeFormatUShortNormalized = 51 - MtAttributeFormatShortNormalized = 52 - MtAttributeFormatHalf = 53 -end - -@cenum MtStepFunction::UInt32 begin - MtStepFunctionConstant = 0 - MtStepFunctionPerVertex = 1 - MtStepFunctionPerInstance = 2 - MtStepFunctionPerPatch = 3 - MtStepFunctionPerPatchControlPoint = 4 - MtStepFunctionThreadPositionInGridX = 5 - MtStepFunctionThreadPositionInGridY = 6 - MtStepFunctionThreadPositionInGridXIndexed = 7 - MtStepFunctionThreadPositionInGridYIndexed = 8 -end - -@cenum MtPipelineOption::UInt32 begin - MtPipelineOptionNone = 0 - MtPipelineOptionArgumentInfo = 1 - MtPipelineOptionBufferTypeInfo = 2 -end - -@cenum MtArgumentType::UInt32 begin - MtArgumentTypeBuffer = 0 - MtArgumentTypeThreadgroupMemory = 1 - MtArgumentTypeTexture = 2 - MtArgumentTypeSampler = 3 -end - -@cenum MtCaptureError::UInt32 begin - MtCaptureErrorNotSupported = 1 - MtCaptureErrorAlreadyCapturing = 2 - MtCaptureErrorInvalidDescriptor = 3 -end - -@cenum MtCaptureDestination::UInt32 begin - MtCaptureDestinationDeveloperTools = 1 - MtCaptureDestinationGPUTraceDocument = 2 -end - -@cenum MtCaptureDescriptorCaptureObjectType::UInt32 begin - MtCaptureDescriptorCaptureObjectTypeNull = 0 - MtCaptureDescriptorCaptureObjectTypeDevice = 1 - MtCaptureDescriptorCaptureObjectTypeQueue = 2 - MtCaptureDescriptorCaptureObjectTypeScope = 3 -end - -struct MtSize - width::NsUInteger - height::NsUInteger - depth::NsUInteger -end - -struct MtOrigin - x::NsUInteger - y::NsUInteger - z::NsUInteger -end - -struct MtSizeAndAlign - size::NsUInteger - align::NsUInteger -end - -struct MtDevice - #= /Users/tim/Julia/pkg/Metal/res/wrap.jl:39 =# -end - -struct MtRenderDesc - #= /Users/tim/Julia/pkg/Metal/res/wrap.jl:39 =# -end - -struct MtRenderPipeline - #= /Users/tim/Julia/pkg/Metal/res/wrap.jl:39 =# -end - -struct MtCommandQueue - #= /Users/tim/Julia/pkg/Metal/res/wrap.jl:39 =# -end - -struct MtCommandEncoder - #= /Users/tim/Julia/pkg/Metal/res/wrap.jl:39 =# -end - -struct MtBlitCommandEncoder - #= /Users/tim/Julia/pkg/Metal/res/wrap.jl:39 =# -end - -struct MtLibrary - #= /Users/tim/Julia/pkg/Metal/res/wrap.jl:39 =# -end - -struct MtBinaryArchive - #= /Users/tim/Julia/pkg/Metal/res/wrap.jl:39 =# -end - -struct MtBinaryArchiveDescriptor - #= /Users/tim/Julia/pkg/Metal/res/wrap.jl:39 =# -end - -struct MtRenderPassDesc - #= /Users/tim/Julia/pkg/Metal/res/wrap.jl:39 =# -end - -struct MtTexture - #= /Users/tim/Julia/pkg/Metal/res/wrap.jl:39 =# -end - -struct MtCommandBuffer - #= /Users/tim/Julia/pkg/Metal/res/wrap.jl:39 =# -end - -struct MtCommandBufferDescriptor - #= /Users/tim/Julia/pkg/Metal/res/wrap.jl:39 =# -end - -struct MtCommandBufferEncoderInfo - #= /Users/tim/Julia/pkg/Metal/res/wrap.jl:39 =# -end - -struct MtDrawable - #= /Users/tim/Julia/pkg/Metal/res/wrap.jl:39 =# -end - -struct MtVertexDescriptor - #= /Users/tim/Julia/pkg/Metal/res/wrap.jl:39 =# -end - -struct MtTextureDescriptor - #= /Users/tim/Julia/pkg/Metal/res/wrap.jl:39 =# -end - -struct MtIndirectCommandBufferDescriptor - #= /Users/tim/Julia/pkg/Metal/res/wrap.jl:39 =# -end - -struct MtIndirectCommandBuffer - #= /Users/tim/Julia/pkg/Metal/res/wrap.jl:39 =# -end - -struct MtIndirectComputeCommand - #= /Users/tim/Julia/pkg/Metal/res/wrap.jl:39 =# -end - -struct MtIndirectRenderCommand - #= /Users/tim/Julia/pkg/Metal/res/wrap.jl:39 =# -end - -struct MtDepthStencil - #= /Users/tim/Julia/pkg/Metal/res/wrap.jl:39 =# -end - -struct MtBuffer - #= /Users/tim/Julia/pkg/Metal/res/wrap.jl:39 =# -end - -struct MtCompileOptions - #= /Users/tim/Julia/pkg/Metal/res/wrap.jl:39 =# -end - -struct MtFunction - #= /Users/tim/Julia/pkg/Metal/res/wrap.jl:39 =# -end - -struct MtFunctionDescriptor - #= /Users/tim/Julia/pkg/Metal/res/wrap.jl:39 =# -end - -struct MtFunctionConstant - #= /Users/tim/Julia/pkg/Metal/res/wrap.jl:39 =# -end - -struct MtFunctionConstantValues - #= /Users/tim/Julia/pkg/Metal/res/wrap.jl:39 =# -end - -struct MtEvent - #= /Users/tim/Julia/pkg/Metal/res/wrap.jl:39 =# -end - -struct MtSharedEvent - #= /Users/tim/Julia/pkg/Metal/res/wrap.jl:39 =# -end - -struct MtSharedEventHandle - #= /Users/tim/Julia/pkg/Metal/res/wrap.jl:39 =# -end - -struct MtFence - #= /Users/tim/Julia/pkg/Metal/res/wrap.jl:39 =# -end - -# typedef void ( * MtCommandBufferHandlerFun ) ( MtCommandBuffer * buf ) -const MtCommandBufferHandlerFun = Ptr{Cvoid} - -struct MtSharedEventListener - #= /Users/tim/Julia/pkg/Metal/res/wrap.jl:39 =# -end - -struct MtResource - #= /Users/tim/Julia/pkg/Metal/res/wrap.jl:39 =# -end - -struct MtHeap - #= /Users/tim/Julia/pkg/Metal/res/wrap.jl:39 =# -end - -struct MtHeapDescriptor - #= /Users/tim/Julia/pkg/Metal/res/wrap.jl:39 =# -end - -struct MtAttribute - #= /Users/tim/Julia/pkg/Metal/res/wrap.jl:39 =# -end - -struct MtVertexAttribute - #= /Users/tim/Julia/pkg/Metal/res/wrap.jl:39 =# -end - -struct MtComputePipelineState - #= /Users/tim/Julia/pkg/Metal/res/wrap.jl:39 =# -end - -struct MtSamplerState - #= /Users/tim/Julia/pkg/Metal/res/wrap.jl:39 =# -end - -struct MtRenderCommandEncoder - #= /Users/tim/Julia/pkg/Metal/res/wrap.jl:39 =# -end - -struct MtComputeCommandEncoder - #= /Users/tim/Julia/pkg/Metal/res/wrap.jl:39 =# -end - -struct MtResourceStateCommandEncoder - #= /Users/tim/Julia/pkg/Metal/res/wrap.jl:39 =# -end - -struct MtCounterSampleBuffer - #= /Users/tim/Julia/pkg/Metal/res/wrap.jl:39 =# -end - -struct MtArgumentEncoder - #= /Users/tim/Julia/pkg/Metal/res/wrap.jl:39 =# -end - -struct MtAutoreleasedArgument - #= /Users/tim/Julia/pkg/Metal/res/wrap.jl:39 =# -end - -struct MtArgument - #= /Users/tim/Julia/pkg/Metal/res/wrap.jl:39 =# -end - -struct MtArgumentDescriptor - #= /Users/tim/Julia/pkg/Metal/res/wrap.jl:39 =# -end - -struct MtComputePipelineDescriptor - #= /Users/tim/Julia/pkg/Metal/res/wrap.jl:39 =# -end - -struct MtPointerType - #= /Users/tim/Julia/pkg/Metal/res/wrap.jl:39 =# -end - -struct MtArrayType - #= /Users/tim/Julia/pkg/Metal/res/wrap.jl:39 =# -end - -struct MtStructType - #= /Users/tim/Julia/pkg/Metal/res/wrap.jl:39 =# -end - -struct MtComputePipelineReflection - #= /Users/tim/Julia/pkg/Metal/res/wrap.jl:39 =# -end - -struct MtRenderPipelineReflection - #= /Users/tim/Julia/pkg/Metal/res/wrap.jl:39 =# -end - -struct MtCaptureManager - #= /Users/tim/Julia/pkg/Metal/res/wrap.jl:39 =# -end - -struct MtCaptureScope - #= /Users/tim/Julia/pkg/Metal/res/wrap.jl:39 =# -end - -struct MtCaptureDescriptor - #= /Users/tim/Julia/pkg/Metal/res/wrap.jl:39 =# -end - -struct MtDispatchThreadgroupsIndirectArguments - threadgroupsPerGrid::NTuple{3, UInt32} -end - -struct MtStageInRegionIndirectArguments - stageInOrigin::NTuple{3, UInt32} - stageInSize::NTuple{3, UInt32} -end - -struct MtRegion - origin::MtOrigin - size::MtSize -end - -struct MtIndirectCommandBufferExecutionRange - location::UInt32 - length::UInt32 -end - -struct MtTextureSwizzleChannels - red::MtTextureSwizzle - green::MtTextureSwizzle - blue::MtTextureSwizzle - alpha::MtTextureSwizzle -end - -struct MtMPSVectorDescriptor - #= /Users/tim/Julia/pkg/Metal/res/wrap.jl:39 =# -end - -struct MtMPSVector - #= /Users/tim/Julia/pkg/Metal/res/wrap.jl:39 =# -end - -struct MtMPSMatrixDescriptor - #= /Users/tim/Julia/pkg/Metal/res/wrap.jl:39 =# -end - -struct MtMPSMatrix - #= /Users/tim/Julia/pkg/Metal/res/wrap.jl:39 =# -end - -struct MtMPSMatrixMultiplication - #= /Users/tim/Julia/pkg/Metal/res/wrap.jl:39 =# -end - -function mtErrorCode(err) - ccall((:mtErrorCode, libcmt), NsInteger, (Ptr{NsError},), err) -end - -function mtErrorDomain(err) - ccall((:mtErrorDomain, libcmt), Cstring, (Ptr{NsError},), err) -end - -function mtErrorUserInfo(err) - ccall((:mtErrorUserInfo, libcmt), Cstring, (Ptr{NsError},), err) -end - -function mtErrorLocalizedDescription(err) - ccall((:mtErrorLocalizedDescription, libcmt), Cstring, (Ptr{NsError},), err) -end - -function mtErrorLocalizedRecoveryOptions(err, count, options) - ccall((:mtErrorLocalizedRecoveryOptions, libcmt), Ptr{Cstring}, (Ptr{NsError}, Ptr{Csize_t}, Ptr{Cstring}), err, count, options) -end - -function mtErrorLocalizedRecoverySuggestion(err) - ccall((:mtErrorLocalizedRecoverySuggestion, libcmt), Cstring, (Ptr{NsError},), err) -end - -function mtErrorLocalizedFailureReason(err) - ccall((:mtErrorLocalizedFailureReason, libcmt), Cstring, (Ptr{NsError},), err) -end - -@cenum MtPixelFormat::UInt32 begin - MtPixelFormatInvalid = 0 - MtPixelFormatA8Unorm = 1 - MtPixelFormatR8Unorm = 10 - MtPixelFormatR8Unorm_sRGB = 11 - MtPixelFormatR8Snorm = 12 - MtPixelFormatR8Uint = 13 - MtPixelFormatR8Sint = 14 - MtPixelFormatR16Unorm = 20 - MtPixelFormatR16Snorm = 22 - MtPixelFormatR16Uint = 23 - MtPixelFormatR16Sint = 24 - MtPixelFormatR16Float = 25 - MtPixelFormatRG8Unorm = 30 - MtPixelFormatRG8Unorm_sRGB = 31 - MtPixelFormatRG8Snorm = 32 - MtPixelFormatRG8Uint = 33 - MtPixelFormatRG8Sint = 34 - MtPixelFormatB5G6R5Unorm = 40 - MtPixelFormatA1BGR5Unorm = 41 - MtPixelFormatABGR4Unorm = 42 - MtPixelFormatBGR5A1Unorm = 43 - MtPixelFormatR32Uint = 53 - MtPixelFormatR32Sint = 54 - MtPixelFormatR32Float = 55 - MtPixelFormatRG16Unorm = 60 - MtPixelFormatRG16Snorm = 62 - MtPixelFormatRG16Uint = 63 - MtPixelFormatRG16Sint = 64 - MtPixelFormatRG16Float = 65 - MtPixelFormatRGBA8Unorm = 70 - MtPixelFormatRGBA8Unorm_sRGB = 71 - MtPixelFormatRGBA8Snorm = 72 - MtPixelFormatRGBA8Uint = 73 - MtPixelFormatRGBA8Sint = 74 - MtPixelFormatBGRX8Unorm = 75 - MtPixelFormatBGRA8Unorm = 80 - MtPixelFormatBGRA8Unorm_sRGB = 81 - MtPixelFormatRGB10A2Unorm = 90 - MtPixelFormatRGB10A2Uint = 91 - MtPixelFormatRG11B10Float = 92 - MtPixelFormatRGB9E5Float = 93 - MtPixelFormatBGR10A2Unorm = 94 - MtPixelFormatBGR10_XR = 554 - MtPixelFormatBGR10_XR_sRGB = 555 - MtPixelFormatRG32Uint = 103 - MtPixelFormatRG32Sint = 104 - MtPixelFormatRG32Float = 105 - MtPixelFormatRGBA16Unorm = 110 - MtPixelFormatRGBA16Snorm = 112 - MtPixelFormatRGBA16Uint = 113 - MtPixelFormatRGBA16Sint = 114 - MtPixelFormatRGBA16Float = 115 - MtPixelFormatBGRA10_XR = 552 - MtPixelFormatBGRA10_XR_sRGB = 553 - MtPixelFormatRGBA32Uint = 123 - MtPixelFormatRGBA32Sint = 124 - MtPixelFormatRGBA32Float = 125 - MtPixelFormatBC1_RGBA = 130 - MtPixelFormatBC1_RGBA_sRGB = 131 - MtPixelFormatBC2_RGBA = 132 - MtPixelFormatBC2_RGBA_sRGB = 133 - MtPixelFormatBC3_RGBA = 134 - MtPixelFormatBC3_RGBA_sRGB = 135 - MtPixelFormatBC4_RUnorm = 140 - MtPixelFormatBC4_RSnorm = 141 - MtPixelFormatBC5_RGUnorm = 142 - MtPixelFormatBC5_RGSnorm = 143 - MtPixelFormatBC6H_RGBFloat = 150 - MtPixelFormatBC6H_RGBUfloat = 151 - MtPixelFormatBC7_RGBAUnorm = 152 - MtPixelFormatBC7_RGBAUnorm_sRGB = 153 - MtPixelFormatPVRTC_RGB_2BPP = 160 - MtPixelFormatPVRTC_RGB_2BPP_sRGB = 161 - MtPixelFormatPVRTC_RGB_4BPP = 162 - MtPixelFormatPVRTC_RGB_4BPP_sRGB = 163 - MtPixelFormatPVRTC_RGBA_2BPP = 164 - MtPixelFormatPVRTC_RGBA_2BPP_sRGB = 165 - MtPixelFormatPVRTC_RGBA_4BPP = 166 - MtPixelFormatPVRTC_RGBA_4BPP_sRGB = 167 - MtPixelFormatEAC_R11Unorm = 170 - MtPixelFormatEAC_R11Snorm = 172 - MtPixelFormatEAC_RG11Unorm = 174 - MtPixelFormatEAC_RG11Snorm = 176 - MtPixelFormatEAC_RGBA8 = 178 - MtPixelFormatEAC_RGBA8_sRGB = 179 - MtPixelFormatETC2_RGB8 = 180 - MtPixelFormatETC2_RGB8_sRGB = 181 - MtPixelFormatETC2_RGB8A1 = 182 - MtPixelFormatETC2_RGB8A1_sRGB = 183 - MtPixelFormatASTC_4x4_sRGB = 186 - MtPixelFormatASTC_5x4_sRGB = 187 - MtPixelFormatASTC_5x5_sRGB = 188 - MtPixelFormatASTC_6x5_sRGB = 189 - MtPixelFormatASTC_6x6_sRGB = 190 - MtPixelFormatASTC_8x5_sRGB = 192 - MtPixelFormatASTC_8x6_sRGB = 193 - MtPixelFormatASTC_8x8_sRGB = 194 - MtPixelFormatASTC_10x5_sRGB = 195 - MtPixelFormatASTC_10x6_sRGB = 196 - MtPixelFormatASTC_10x8_sRGB = 197 - MtPixelFormatASTC_10x10_sRGB = 198 - MtPixelFormatASTC_12x10_sRGB = 199 - MtPixelFormatASTC_12x12_sRGB = 200 - MtPixelFormatASTC_4x4_LDR = 204 - MtPixelFormatASTC_5x4_LDR = 205 - MtPixelFormatASTC_5x5_LDR = 206 - MtPixelFormatASTC_6x5_LDR = 207 - MtPixelFormatASTC_6x6_LDR = 208 - MtPixelFormatASTC_8x5_LDR = 210 - MtPixelFormatASTC_8x6_LDR = 211 - MtPixelFormatASTC_8x8_LDR = 212 - MtPixelFormatASTC_10x5_LDR = 213 - MtPixelFormatASTC_10x6_LDR = 214 - MtPixelFormatASTC_10x8_LDR = 215 - MtPixelFormatASTC_10x10_LDR = 216 - MtPixelFormatASTC_12x10_LDR = 217 - MtPixelFormatASTC_12x12_LDR = 218 - MtPixelFormatGBGR422 = 240 - MtPixelFormatBGRG422 = 241 - MtPixelFormatDepth16Unorm = 250 - MtPixelFormatDepth32Float = 252 - MtPixelFormatStencil8 = 253 - MtPixelFormatDepth24Unorm_Stencil8 = 255 - MtPixelFormatDepth32Float_Stencil8 = 260 - MtPixelFormatX32_Stencil8 = 261 - MtPixelFormatX24_Stencil8 = 262 -end - -function mtDeviceNewEvent(dev) - ccall((:mtDeviceNewEvent, libcmt), Ptr{MtEvent}, (Ptr{MtDevice},), dev) -end - -function mtDeviceNewSharedEvent(dev) - ccall((:mtDeviceNewSharedEvent, libcmt), Ptr{MtSharedEvent}, (Ptr{MtDevice},), dev) -end - -function mtDeviceNewSharedEventWithHandle(dev, handle) - ccall((:mtDeviceNewSharedEventWithHandle, libcmt), Ptr{MtSharedEvent}, (Ptr{MtDevice}, Ptr{MtSharedEventHandle}), dev, handle) -end - -function mtDeviceNewFence(dev) - ccall((:mtDeviceNewFence, libcmt), Ptr{MtFence}, (Ptr{MtDevice},), dev) -end - -function mtEventDevice(event) - ccall((:mtEventDevice, libcmt), Ptr{MtDevice}, (Ptr{MtEvent},), event) -end - -function mtEventLabel(event) - ccall((:mtEventLabel, libcmt), Cstring, (Ptr{MtEvent},), event) -end - -function mtEventLabelSet(event, label) - ccall((:mtEventLabelSet, libcmt), Cvoid, (Ptr{MtEvent}, Cstring), event, label) -end - -function mtSharedEventSignaledValue(event) - ccall((:mtSharedEventSignaledValue, libcmt), UInt64, (Ptr{MtSharedEvent},), event) -end - -function mtSharedEventNewHandle(event) - ccall((:mtSharedEventNewHandle, libcmt), Ptr{MtSharedEventHandle}, (Ptr{MtSharedEvent},), event) -end - -@cenum MtCPUCacheMode::UInt32 begin - MtCPUCacheModeDefaultCache = 0 - MtCPUCacheModeWriteCombined = 1 -end - -@cenum MtHazardTrackingMode::UInt32 begin - MtHazardTrackingModeDefault = 0 - MtHazardTrackingModeUntracked = 1 - MtHazardTrackingModeTracked = 2 -end - -@cenum MtStorageMode::UInt32 begin - MtStorageModeShared = 0 - MtStorageModeManaged = 1 - MtStorageModePrivate = 2 - MtStorageModeMemoryless = 3 -end - -@cenum MtResourceOptions::UInt32 begin - MtResourceCPUCacheModeDefaultCache = 0 - MtResourceCPUCacheModeWriteCombined = 1 - MtResourceStorageModeShared = 0 - MtResourceStorageModeManaged = 16 - MtResourceStorageModePrivate = 32 - MtResourceStorageModeMemoryless = 48 - MtResourceHazardTrackingModeDefault = 0 - MtResourceHazardTrackingModeUntracked = 256 - MtResourceHazardTrackingModeTracked = 512 -end - -function mtResourceDevice(res) - ccall((:mtResourceDevice, libcmt), Ptr{MtDevice}, (Ptr{MtResource},), res) -end - -function mtResourceLabel(res) - ccall((:mtResourceLabel, libcmt), Cstring, (Ptr{MtResource},), res) -end - -function mtResourceLabelSet(res, label) - ccall((:mtResourceLabelSet, libcmt), Cvoid, (Ptr{MtResource}, Cstring), res, label) -end - -function mtResourceCPUCacheMode(res) - ccall((:mtResourceCPUCacheMode, libcmt), MtCPUCacheMode, (Ptr{MtResource},), res) -end - -function mtResourceStorageMode(res) - ccall((:mtResourceStorageMode, libcmt), MtStorageMode, (Ptr{MtResource},), res) -end - -function mtResourceHazardTrackingMode(res) - ccall((:mtResourceHazardTrackingMode, libcmt), MtHazardTrackingMode, (Ptr{MtResource},), res) -end - -function mtResourceOptions(res) - ccall((:mtResourceOptions, libcmt), MtResourceOptions, (Ptr{MtResource},), res) -end - -function mtCreateSystemDefaultDevice() - ccall((:mtCreateSystemDefaultDevice, libcmt), Ptr{MtDevice}, ()) -end - -function mtCopyAllDevices(count, devices) - ccall((:mtCopyAllDevices, libcmt), Cvoid, (Ptr{Csize_t}, Ptr{Ptr{MtDevice}}), count, devices) -end - -function mtDeviceName(arg1) - ccall((:mtDeviceName, libcmt), Cstring, (Ptr{MtDevice},), arg1) -end - -function mtDeviceHeadless(arg1) - ccall((:mtDeviceHeadless, libcmt), Bool, (Ptr{MtDevice},), arg1) -end - -function mtDeviceLowPower(arg1) - ccall((:mtDeviceLowPower, libcmt), Bool, (Ptr{MtDevice},), arg1) -end - -function mtDeviceRemovable(arg1) - ccall((:mtDeviceRemovable, libcmt), Bool, (Ptr{MtDevice},), arg1) -end - -function mtDeviceRegistryID(arg1) - ccall((:mtDeviceRegistryID, libcmt), UInt64, (Ptr{MtDevice},), arg1) -end - -function mtDeviceLocation(arg1) - ccall((:mtDeviceLocation, libcmt), MtDeviceLocation, (Ptr{MtDevice},), arg1) -end - -function mtDeviceLocationNumber(arg1) - ccall((:mtDeviceLocationNumber, libcmt), UInt64, (Ptr{MtDevice},), arg1) -end - -function mtDeviceMaxTransferRate(arg1) - ccall((:mtDeviceMaxTransferRate, libcmt), UInt64, (Ptr{MtDevice},), arg1) -end - -function mtDeviceHasUnifiedMemory(arg1) - ccall((:mtDeviceHasUnifiedMemory, libcmt), Bool, (Ptr{MtDevice},), arg1) -end - -function mtDevicePeerGroupID(arg1) - ccall((:mtDevicePeerGroupID, libcmt), UInt64, (Ptr{MtDevice},), arg1) -end - -function mtDevicePeerCount(arg1) - ccall((:mtDevicePeerCount, libcmt), UInt32, (Ptr{MtDevice},), arg1) -end - -function mtDevicePeerIndex(arg1) - ccall((:mtDevicePeerIndex, libcmt), UInt32, (Ptr{MtDevice},), arg1) -end - -function mtDeviceSupportsFamily(device, family) - ccall((:mtDeviceSupportsFamily, libcmt), Bool, (Ptr{MtDevice}, MtGPUFamily), device, family) -end - -function mtDeviceSupportsFeatureSet(device, set) - ccall((:mtDeviceSupportsFeatureSet, libcmt), Bool, (Ptr{MtDevice}, MtFeatureSet), device, set) -end - -function mtDeviceRecommendedMaxWorkingSetSize(device) - ccall((:mtDeviceRecommendedMaxWorkingSetSize, libcmt), UInt64, (Ptr{MtDevice},), device) -end - -function mtDeviceCurrentAllocatedSize(device) - ccall((:mtDeviceCurrentAllocatedSize, libcmt), NsUInteger, (Ptr{MtDevice},), device) -end - -function mtDeviceMaxThreadgroupMemoryLength(device) - ccall((:mtDeviceMaxThreadgroupMemoryLength, libcmt), NsUInteger, (Ptr{MtDevice},), device) -end - -function mtMaxThreadsPerThreadgroup(device) - ccall((:mtMaxThreadsPerThreadgroup, libcmt), MtSize, (Ptr{MtDevice},), device) -end - -function mtDeviceArgumentBuffersSupport(device) - ccall((:mtDeviceArgumentBuffersSupport, libcmt), MtArgumentBuffersTier, (Ptr{MtDevice},), device) -end - -function mtDeviceMaxBufferLength(device) - ccall((:mtDeviceMaxBufferLength, libcmt), NsUInteger, (Ptr{MtDevice},), device) -end - -function mtDeviceNewBufferWithLength(device, length, opts) - ccall((:mtDeviceNewBufferWithLength, libcmt), Ptr{MtBuffer}, (Ptr{MtDevice}, NsUInteger, MtResourceOptions), device, length, opts) -end - -function mtDeviceNewBufferWithBytes(device, ptr, length, opts) - ccall((:mtDeviceNewBufferWithBytes, libcmt), Ptr{MtBuffer}, (Ptr{MtDevice}, Ptr{Cvoid}, NsUInteger, MtResourceOptions), device, ptr, length, opts) -end - -function mtDeviceNewBufferWithBytesNoCopy(device, ptr, length, opts) - ccall((:mtDeviceNewBufferWithBytesNoCopy, libcmt), Ptr{MtBuffer}, (Ptr{MtDevice}, Ptr{Cvoid}, NsUInteger, MtResourceOptions), device, ptr, length, opts) -end - -function mtNewComputePipelineDescriptor() - ccall((:mtNewComputePipelineDescriptor, libcmt), Ptr{MtComputePipelineDescriptor}, ()) -end - -function mtComputePipelineDescriptorLabel(desc) - ccall((:mtComputePipelineDescriptorLabel, libcmt), Cstring, (Ptr{MtComputePipelineDescriptor},), desc) -end - -function mtComputePipelineDescriptorLabelSet(desc, label) - ccall((:mtComputePipelineDescriptorLabelSet, libcmt), Cvoid, (Ptr{MtComputePipelineDescriptor}, Cstring), desc, label) -end - -function mtComputePipelineDescriptorComputeFunction(desc) - ccall((:mtComputePipelineDescriptorComputeFunction, libcmt), Ptr{MtFunction}, (Ptr{MtComputePipelineDescriptor},), desc) -end - -function mtComputePipelineDescriptorComputeFunctionSet(desc, fun) - ccall((:mtComputePipelineDescriptorComputeFunctionSet, libcmt), Cvoid, (Ptr{MtComputePipelineDescriptor}, Ptr{MtFunction}), desc, fun) -end - -function mtComputePipelineDescriptorThreadGroupSizeIsMultipleOfThreadExecutionWidth(desc) - ccall((:mtComputePipelineDescriptorThreadGroupSizeIsMultipleOfThreadExecutionWidth, libcmt), Bool, (Ptr{MtComputePipelineDescriptor},), desc) -end - -function mtComputePipelineDescriptorThreadGroupSizeIsMultipleOfThreadExecutionWidthSet(desc, val) - ccall((:mtComputePipelineDescriptorThreadGroupSizeIsMultipleOfThreadExecutionWidthSet, libcmt), Cvoid, (Ptr{MtComputePipelineDescriptor}, Bool), desc, val) -end - -function mtComputePipelineDescriptorMaxTotalThreadsPerThreadgroup(desc) - ccall((:mtComputePipelineDescriptorMaxTotalThreadsPerThreadgroup, libcmt), UInt32, (Ptr{MtComputePipelineDescriptor},), desc) -end - -function mtComputePipelineDescriptorMaxTotalThreadsPerThreadgroupSet(desc, val) - ccall((:mtComputePipelineDescriptorMaxTotalThreadsPerThreadgroupSet, libcmt), Cvoid, (Ptr{MtComputePipelineDescriptor}, UInt32), desc, val) -end - -function mtComputePipelineDescriptorMaxCallStackDepth(desc) - ccall((:mtComputePipelineDescriptorMaxCallStackDepth, libcmt), UInt32, (Ptr{MtComputePipelineDescriptor},), desc) -end - -function mtComputePipelineDescriptorMaxCallStackDepthSet(desc, val) - ccall((:mtComputePipelineDescriptorMaxCallStackDepthSet, libcmt), Cvoid, (Ptr{MtComputePipelineDescriptor}, UInt32), desc, val) -end - -function mtComputePipelineDescriptorSupportIndirectCommandBuffers(desc) - ccall((:mtComputePipelineDescriptorSupportIndirectCommandBuffers, libcmt), Bool, (Ptr{MtComputePipelineDescriptor},), desc) -end - -function mtComputePipelineDescriptorReset(desc) - ccall((:mtComputePipelineDescriptorReset, libcmt), Cvoid, (Ptr{MtComputePipelineDescriptor},), desc) -end - -function mtComputePipelineDescriptorSupportAddingBinaryFunctions(desc) - ccall((:mtComputePipelineDescriptorSupportAddingBinaryFunctions, libcmt), Bool, (Ptr{MtComputePipelineDescriptor},), desc) -end - -function mtNewComputePipelineStateWithFunction(device, fun, error) - ccall((:mtNewComputePipelineStateWithFunction, libcmt), Ptr{MtComputePipelineState}, (Ptr{MtDevice}, Ptr{MtFunction}, Ptr{Ptr{NsError}}), device, fun, error) -end - -function mtNewComputePipelineStateWithFunctionReflection(device, fun, opt, reflection, error) - ccall((:mtNewComputePipelineStateWithFunctionReflection, libcmt), Ptr{MtComputePipelineState}, (Ptr{MtDevice}, Ptr{MtFunction}, MtPipelineOption, Ptr{Ptr{MtComputePipelineReflection}}, Ptr{Ptr{NsError}}), device, fun, opt, reflection, error) -end - -function mtNewComputePipelineStateWithDescriptor(device, desc, opt, reflection, error) - ccall((:mtNewComputePipelineStateWithDescriptor, libcmt), Ptr{MtComputePipelineState}, (Ptr{MtDevice}, Ptr{MtComputePipelineDescriptor}, MtPipelineOption, Ptr{Ptr{MtComputePipelineReflection}}, Ptr{Ptr{NsError}}), device, desc, opt, reflection, error) -end - -function mtComputePipelineDevice(pip) - ccall((:mtComputePipelineDevice, libcmt), Ptr{MtDevice}, (Ptr{MtComputePipelineState},), pip) -end - -function mtComputePipelineLabel(pip) - ccall((:mtComputePipelineLabel, libcmt), Cstring, (Ptr{MtComputePipelineState},), pip) -end - -function mtComputePipelineMaxTotalThreadsPerThreadgroup(pip) - ccall((:mtComputePipelineMaxTotalThreadsPerThreadgroup, libcmt), NsUInteger, (Ptr{MtComputePipelineState},), pip) -end - -function mtComputePipelineThreadExecutionWidth(pip) - ccall((:mtComputePipelineThreadExecutionWidth, libcmt), NsUInteger, (Ptr{MtComputePipelineState},), pip) -end - -function mtComputePipelineStaticThreadgroupMemoryLength(pip) - ccall((:mtComputePipelineStaticThreadgroupMemoryLength, libcmt), NsUInteger, (Ptr{MtComputePipelineState},), pip) -end - -function mtAttributeName(attr) - ccall((:mtAttributeName, libcmt), Cstring, (Ptr{MtAttribute},), attr) -end - -function mtAttributeIndex(attr) - ccall((:mtAttributeIndex, libcmt), NsUInteger, (Ptr{MtAttribute},), attr) -end - -function mtAttributeDataType(attr) - ccall((:mtAttributeDataType, libcmt), MtDataType, (Ptr{MtAttribute},), attr) -end - -function mtAttributeActive(attr) - ccall((:mtAttributeActive, libcmt), Bool, (Ptr{MtAttribute},), attr) -end - -function mtAttributeIsPatchControlPointData(attr) - ccall((:mtAttributeIsPatchControlPointData, libcmt), Bool, (Ptr{MtAttribute},), attr) -end - -function mtAttributeIsPatchData(attr) - ccall((:mtAttributeIsPatchData, libcmt), Bool, (Ptr{MtAttribute},), attr) -end - -function mtVertexAttributeName(attr) - ccall((:mtVertexAttributeName, libcmt), Cstring, (Ptr{MtVertexAttribute},), attr) -end - -function mtVertexAttributeIndex(attr) - ccall((:mtVertexAttributeIndex, libcmt), NsUInteger, (Ptr{MtVertexAttribute},), attr) -end - -function mtVertexAttributeDataType(attr) - ccall((:mtVertexAttributeDataType, libcmt), MtDataType, (Ptr{MtVertexAttribute},), attr) -end - -function mtVertexAttributeActive(attr) - ccall((:mtVertexAttributeActive, libcmt), Bool, (Ptr{MtVertexAttribute},), attr) -end - -function mtVertexAttributeIsPatchControlPointData(attr) - ccall((:mtVertexAttributeIsPatchControlPointData, libcmt), Bool, (Ptr{MtVertexAttribute},), attr) -end - -function mtVertexAttributeIsPatchData(attr) - ccall((:mtVertexAttributeIsPatchData, libcmt), Bool, (Ptr{MtVertexAttribute},), attr) -end - -function mtNewCompileOpts() - ccall((:mtNewCompileOpts, libcmt), Ptr{MtCompileOptions}, ()) -end - -function mtCompileOptsFastMath(opts) - ccall((:mtCompileOptsFastMath, libcmt), Bool, (Ptr{MtCompileOptions},), opts) -end - -function mtCompileOptsFastMathSet(opts, val) - ccall((:mtCompileOptsFastMathSet, libcmt), Cvoid, (Ptr{MtCompileOptions}, Bool), opts, val) -end - -function mtCompileOptsLanguageVersion(opts) - ccall((:mtCompileOptsLanguageVersion, libcmt), MtLanguageVersion, (Ptr{MtCompileOptions},), opts) -end - -function mtCompileOptsLanguageVersionSet(opts, val) - ccall((:mtCompileOptsLanguageVersionSet, libcmt), Cvoid, (Ptr{MtCompileOptions}, MtLanguageVersion), opts, val) -end - -function mtFunctionConstantValuesSetWithIndex(funval, value, typ, idx) - ccall((:mtFunctionConstantValuesSetWithIndex, libcmt), Cvoid, (Ptr{MtFunctionConstantValues}, Ptr{Cvoid}, MtDataType, NsUInteger), funval, value, typ, idx) -end - -function mtFunctionConstantValuesSetWithName(funval, value, typ, name) - ccall((:mtFunctionConstantValuesSetWithName, libcmt), Cvoid, (Ptr{MtFunctionConstantValues}, Ptr{Cvoid}, MtDataType, Cstring), funval, value, typ, name) -end - -function mtFunctionConstantValuesSetWithRange(funval, value, typ, range) - ccall((:mtFunctionConstantValuesSetWithRange, libcmt), Cvoid, (Ptr{MtFunctionConstantValues}, Ptr{Cvoid}, MtDataType, NsRange), funval, value, typ, range) -end - -function mtFunctionConstantValuesReset(funval) - ccall((:mtFunctionConstantValuesReset, libcmt), Cvoid, (Ptr{MtFunctionConstantValues},), funval) -end - -function mtNewFunctionWithName(lib, name) - ccall((:mtNewFunctionWithName, libcmt), Ptr{MtFunction}, (Ptr{MtLibrary}, Cstring), lib, name) -end - -function mtNewFunctionWithNameConstantValues(lib, name, constantValues, error) - ccall((:mtNewFunctionWithNameConstantValues, libcmt), Ptr{MtFunction}, (Ptr{MtLibrary}, Cstring, Ptr{MtFunctionConstantValues}, Ptr{Ptr{NsError}}), lib, name, constantValues, error) -end - -function mtFunctionDevice(fun) - ccall((:mtFunctionDevice, libcmt), Ptr{MtDevice}, (Ptr{MtFunction},), fun) -end - -function mtFunctionLabel(fun) - ccall((:mtFunctionLabel, libcmt), Cstring, (Ptr{MtFunction},), fun) -end - -function mtFunctionLabelSet(fun, label) - ccall((:mtFunctionLabelSet, libcmt), Cvoid, (Ptr{MtFunction}, Cstring), fun, label) -end - -function mtFunctionType(fun) - ccall((:mtFunctionType, libcmt), MtFunctionType, (Ptr{MtFunction},), fun) -end - -function mtFunctionName(fun) - ccall((:mtFunctionName, libcmt), Cstring, (Ptr{MtFunction},), fun) -end - -function mtFunctionStageInputAttributes(fun) - ccall((:mtFunctionStageInputAttributes, libcmt), Ptr{Ptr{MtAttribute}}, (Ptr{MtFunction},), fun) -end - -function mtNewFunctionDescriptor() - ccall((:mtNewFunctionDescriptor, libcmt), Ptr{MtFunctionDescriptor}, ()) -end - -function mtFunctionDescriptorName(desc) - ccall((:mtFunctionDescriptorName, libcmt), Cstring, (Ptr{MtFunctionDescriptor},), desc) -end - -function mtFunctionDescriptorNameSet(desc, name) - ccall((:mtFunctionDescriptorNameSet, libcmt), Cvoid, (Ptr{MtFunctionDescriptor}, Cstring), desc, name) -end - -function mtFunctionDescriptorSpecializedName(desc) - ccall((:mtFunctionDescriptorSpecializedName, libcmt), Cstring, (Ptr{MtFunctionDescriptor},), desc) -end - -function mtFunctionDescriptorSpecializedNameSet(desc, specializedName) - ccall((:mtFunctionDescriptorSpecializedNameSet, libcmt), Cvoid, (Ptr{MtFunctionDescriptor}, Cstring), desc, specializedName) -end - -function mtNewDefaultLibrary(device) - ccall((:mtNewDefaultLibrary, libcmt), Ptr{MtLibrary}, (Ptr{MtDevice},), device) -end - -function mtNewLibraryWithFile(device, filepath, error) - ccall((:mtNewLibraryWithFile, libcmt), Ptr{MtLibrary}, (Ptr{MtDevice}, Cstring, Ptr{Ptr{NsError}}), device, filepath, error) -end - -function mtNewLibraryWithURL(device, url, error) - ccall((:mtNewLibraryWithURL, libcmt), Ptr{MtLibrary}, (Ptr{MtDevice}, Cstring, Ptr{Ptr{NsError}}), device, url, error) -end - -function mtNewLibraryWithSource(device, source, Opts, error) - ccall((:mtNewLibraryWithSource, libcmt), Ptr{MtLibrary}, (Ptr{MtDevice}, Cstring, Ptr{MtCompileOptions}, Ptr{Ptr{NsError}}), device, source, Opts, error) -end - -function mtNewLibraryWithData(device, buffer, size, error) - ccall((:mtNewLibraryWithData, libcmt), Ptr{MtLibrary}, (Ptr{MtDevice}, Ptr{Cvoid}, Csize_t, Ptr{Ptr{NsError}}), device, buffer, size, error) -end - -function mtLibraryDevice(lib) - ccall((:mtLibraryDevice, libcmt), Ptr{MtDevice}, (Ptr{MtLibrary},), lib) -end - -function mtLibraryLabel(lib) - ccall((:mtLibraryLabel, libcmt), Cstring, (Ptr{MtLibrary},), lib) -end - -function mtLibraryLabelSet(lib, label) - ccall((:mtLibraryLabelSet, libcmt), Cvoid, (Ptr{MtLibrary}, Cstring), lib, label) -end - -function mtLibraryFunctionNames(lib, count, names) - ccall((:mtLibraryFunctionNames, libcmt), Cvoid, (Ptr{MtLibrary}, Ptr{Csize_t}, Ptr{Cstring}), lib, count, names) -end - -function mtNewBinaryArchiveDescriptor() - ccall((:mtNewBinaryArchiveDescriptor, libcmt), Ptr{MtBinaryArchiveDescriptor}, ()) -end - -function mtBinaryArchiveDescriptorURL(desc) - ccall((:mtBinaryArchiveDescriptorURL, libcmt), Cstring, (Ptr{MtBinaryArchiveDescriptor},), desc) -end - -function mtBinaryArchiveDescriptorURLSet(desc, path) - ccall((:mtBinaryArchiveDescriptorURLSet, libcmt), Cvoid, (Ptr{MtBinaryArchiveDescriptor}, Cstring), desc, path) -end - -function mtNewBinaryArchiveWithDescriptor(device, desc, error) - ccall((:mtNewBinaryArchiveWithDescriptor, libcmt), Ptr{MtBinaryArchive}, (Ptr{MtDevice}, Ptr{MtBinaryArchiveDescriptor}, Ptr{Ptr{NsError}}), device, desc, error) -end - -function mtBinaryArchiveDevice(bin) - ccall((:mtBinaryArchiveDevice, libcmt), Ptr{MtDevice}, (Ptr{MtBinaryArchive},), bin) -end - -function mtBinaryArchiveLabel(bin) - ccall((:mtBinaryArchiveLabel, libcmt), Cstring, (Ptr{MtBinaryArchive},), bin) -end - -function mtBinaryArchiveLabelSet(bin, label) - ccall((:mtBinaryArchiveLabelSet, libcmt), Cvoid, (Ptr{MtBinaryArchive}, Cstring), bin, label) -end - -function mtBinaryArchiveAddComputePipelineFunctions(bin, desc, error) - ccall((:mtBinaryArchiveAddComputePipelineFunctions, libcmt), Cvoid, (Ptr{MtBinaryArchive}, Ptr{MtComputePipelineDescriptor}, Ptr{Ptr{NsError}}), bin, desc, error) -end - -function mtBinaryArchiveAddFunction(bin, desc, lib, error) - ccall((:mtBinaryArchiveAddFunction, libcmt), Cvoid, (Ptr{MtBinaryArchive}, Ptr{MtFunctionDescriptor}, Ptr{MtLibrary}, Ptr{Ptr{NsError}}), bin, desc, lib, error) -end - -function mtBinaryArchiveSerialize(bin, path, error) - ccall((:mtBinaryArchiveSerialize, libcmt), Cvoid, (Ptr{MtBinaryArchive}, Cstring, Ptr{Ptr{NsError}}), bin, path, error) -end - -function mtBufferContents(buf) - ccall((:mtBufferContents, libcmt), Ptr{Cvoid}, (Ptr{MtBuffer},), buf) -end - -function mtBufferLength(buf) - ccall((:mtBufferLength, libcmt), NsUInteger, (Ptr{MtBuffer},), buf) -end - -function mtBufferDidModifyRange(buf, ran) - ccall((:mtBufferDidModifyRange, libcmt), Cvoid, (Ptr{MtBuffer}, NsRange), buf, ran) -end - -function mtBufferAddDebugMarkerRange(buf, string, range) - ccall((:mtBufferAddDebugMarkerRange, libcmt), Cvoid, (Ptr{MtBuffer}, Cstring, NsRange), buf, string, range) -end - -function mtBufferRemoveAllDebugMarkers(buf) - ccall((:mtBufferRemoveAllDebugMarkers, libcmt), Cvoid, (Ptr{MtBuffer},), buf) -end - -function mtBufferNewRemoteBufferViewForDevice(buf, device) - ccall((:mtBufferNewRemoteBufferViewForDevice, libcmt), Ptr{MtBuffer}, (Ptr{MtBuffer}, Ptr{MtDevice}), buf, device) -end - -function mtBufferRemoteStorageBuffer(buf) - ccall((:mtBufferRemoteStorageBuffer, libcmt), Ptr{MtBuffer}, (Ptr{MtBuffer},), buf) -end - -function mtBufferGPUAddress(buf) - ccall((:mtBufferGPUAddress, libcmt), UInt64, (Ptr{MtBuffer},), buf) -end - -function mtNewHeapDescriptor() - ccall((:mtNewHeapDescriptor, libcmt), Ptr{MtHeapDescriptor}, ()) -end - -function mtHeapDescriptorType(heap) - ccall((:mtHeapDescriptorType, libcmt), MtHeapType, (Ptr{MtHeapDescriptor},), heap) -end - -function mtHeapDescriptorTypeSet(heap, type) - ccall((:mtHeapDescriptorTypeSet, libcmt), Cvoid, (Ptr{MtHeapDescriptor}, MtHeapType), heap, type) -end - -function mtHeapDescriptorStorageMode(heap) - ccall((:mtHeapDescriptorStorageMode, libcmt), MtStorageMode, (Ptr{MtHeapDescriptor},), heap) -end - -function mtHeapDescriptorStorageModeSet(heap, mode) - ccall((:mtHeapDescriptorStorageModeSet, libcmt), Cvoid, (Ptr{MtHeapDescriptor}, MtStorageMode), heap, mode) -end - -function mtHeapDescriptorCPUCacheMode(heap) - ccall((:mtHeapDescriptorCPUCacheMode, libcmt), MtCPUCacheMode, (Ptr{MtHeapDescriptor},), heap) -end - -function mtHeapDescriptorCpuCacheModeSet(heap, mode) - ccall((:mtHeapDescriptorCpuCacheModeSet, libcmt), Cvoid, (Ptr{MtHeapDescriptor}, MtCPUCacheMode), heap, mode) -end - -function mtHeapDescriptorHazardTrackingMode(heap) - ccall((:mtHeapDescriptorHazardTrackingMode, libcmt), MtHazardTrackingMode, (Ptr{MtHeapDescriptor},), heap) -end - -function mtHeapDescriptorHazardTrackingModeSet(heap, mode) - ccall((:mtHeapDescriptorHazardTrackingModeSet, libcmt), Cvoid, (Ptr{MtHeapDescriptor}, MtHazardTrackingMode), heap, mode) -end - -function mtHeapDescriptorResourceOptions(heap) - ccall((:mtHeapDescriptorResourceOptions, libcmt), MtResourceOptions, (Ptr{MtHeapDescriptor},), heap) -end - -function mtHeapDescriptorResourceOptionsSet(heap, mode) - ccall((:mtHeapDescriptorResourceOptionsSet, libcmt), Cvoid, (Ptr{MtHeapDescriptor}, MtResourceOptions), heap, mode) -end - -function mtHeapDescriptorSize(heap) - ccall((:mtHeapDescriptorSize, libcmt), NsUInteger, (Ptr{MtHeapDescriptor},), heap) -end - -function mtHeapDescriptorSizeSet(heap, size) - ccall((:mtHeapDescriptorSizeSet, libcmt), Cvoid, (Ptr{MtHeapDescriptor}, NsUInteger), heap, size) -end - -function mtDeviceNewHeapWithDescriptor(dev, descriptor) - ccall((:mtDeviceNewHeapWithDescriptor, libcmt), Ptr{MtHeap}, (Ptr{MtDevice}, Ptr{MtHeapDescriptor}), dev, descriptor) -end - -function mtHeapDevice(heap) - ccall((:mtHeapDevice, libcmt), Ptr{MtDevice}, (Ptr{MtHeap},), heap) -end - -function mtHeapLabel(heap) - ccall((:mtHeapLabel, libcmt), Cstring, (Ptr{MtHeap},), heap) -end - -function mtHeapLabelSet(heap, label) - ccall((:mtHeapLabelSet, libcmt), Cvoid, (Ptr{MtHeap}, Cstring), heap, label) -end - -function mtHeapType(heap) - ccall((:mtHeapType, libcmt), MtHeapType, (Ptr{MtHeap},), heap) -end - -function mtHeapStorageMode(heap) - ccall((:mtHeapStorageMode, libcmt), MtStorageMode, (Ptr{MtHeap},), heap) -end - -function mtHeapCPUCacheMode(heap) - ccall((:mtHeapCPUCacheMode, libcmt), MtCPUCacheMode, (Ptr{MtHeap},), heap) -end - -function mtHeapHazardTrackingMode(heap) - ccall((:mtHeapHazardTrackingMode, libcmt), MtHazardTrackingMode, (Ptr{MtHeap},), heap) -end - -function mtHeapResourceOptions(heap) - ccall((:mtHeapResourceOptions, libcmt), MtResourceOptions, (Ptr{MtHeap},), heap) -end - -function mtHeapSize(heap) - ccall((:mtHeapSize, libcmt), NsUInteger, (Ptr{MtHeap},), heap) -end - -function mtHeapUsedSize(heap) - ccall((:mtHeapUsedSize, libcmt), NsUInteger, (Ptr{MtHeap},), heap) -end - -function mtHeapCurrentAllocatedSize(heap) - ccall((:mtHeapCurrentAllocatedSize, libcmt), NsUInteger, (Ptr{MtHeap},), heap) -end - -function mtHeapMaxAvailableSizeWithAlignment(heap, alignment) - ccall((:mtHeapMaxAvailableSizeWithAlignment, libcmt), NsUInteger, (Ptr{MtHeap}, NsUInteger), heap, alignment) -end - -function mtHeapSetPurgeableState(heap, state) - ccall((:mtHeapSetPurgeableState, libcmt), MtPurgeableState, (Ptr{MtHeap}, MtPurgeableState), heap, state) -end - -function mtHeapNewBufferWithLength(heap, len, opt) - ccall((:mtHeapNewBufferWithLength, libcmt), Ptr{MtBuffer}, (Ptr{MtHeap}, NsUInteger, MtResourceOptions), heap, len, opt) -end - -function mtHeapNewBufferWithLengthOffset(heap, len, opt, offset) - ccall((:mtHeapNewBufferWithLengthOffset, libcmt), Ptr{MtBuffer}, (Ptr{MtHeap}, NsUInteger, MtResourceOptions, NsUInteger), heap, len, opt, offset) -end - -function mtHeapNewTextureWithDescriptor(heap, desc) - ccall((:mtHeapNewTextureWithDescriptor, libcmt), Ptr{MtTexture}, (Ptr{MtHeap}, Ptr{MtTextureDescriptor}), heap, desc) -end - -function mtHeapNewTextureWithDescriptorOffset(heap, desc, offset) - ccall((:mtHeapNewTextureWithDescriptorOffset, libcmt), Ptr{MtTexture}, (Ptr{MtHeap}, Ptr{MtTextureDescriptor}, NsUInteger), heap, desc, offset) -end - -@cenum MtVertexFormat::UInt32 begin - MtVertexFormatInvalid = 0 - MtVertexFormatUChar2 = 1 - MtVertexFormatUChar3 = 2 - MtVertexFormatUChar4 = 3 - MtVertexFormatChar2 = 4 - MtVertexFormatChar3 = 5 - MtVertexFormatChar4 = 6 - MtVertexFormatUChar2Normalized = 7 - MtVertexFormatUChar3Normalized = 8 - MtVertexFormatUChar4Normalized = 9 - MtVertexFormatChar2Normalized = 10 - MtVertexFormatChar3Normalized = 11 - MtVertexFormatChar4Normalized = 12 - MtVertexFormatUShort2 = 13 - MtVertexFormatUShort3 = 14 - MtVertexFormatUShort4 = 15 - MtVertexFormatShort2 = 16 - MtVertexFormatShort3 = 17 - MtVertexFormatShort4 = 18 - MtVertexFormatUShort2Normalized = 19 - MtVertexFormatUShort3Normalized = 20 - MtVertexFormatUShort4Normalized = 21 - MtVertexFormatShort2Normalized = 22 - MtVertexFormatShort3Normalized = 23 - MtVertexFormatShort4Normalized = 24 - MtVertexFormatHalf2 = 25 - MtVertexFormatHalf3 = 26 - MtVertexFormatHalf4 = 27 - MtVertexFormatFloat = 28 - MtVertexFormatFloat2 = 29 - MtVertexFormatFloat3 = 30 - MtVertexFormatFloat4 = 31 - MtVertexFormatInt = 32 - MtVertexFormatInt2 = 33 - MtVertexFormatInt3 = 34 - MtVertexFormatInt4 = 35 - MtVertexFormatUInt = 36 - MtVertexFormatUInt2 = 37 - MtVertexFormatUInt3 = 38 - MtVertexFormatUInt4 = 39 - MtVertexFormatInt1010102Normalized = 40 - MtVertexFormatUInt1010102Normalized = 41 - MtVertexFormatUChar4Normalized_BGRA = 42 - MtVertexFormatUChar = 45 - MtVertexFormatChar = 46 - MtVertexFormatUCharNormalized = 47 - MtVertexFormatCharNormalized = 48 - MtVertexFormatUShort = 49 - MtVertexFormatShort = 50 - MtVertexFormatUShortNormalized = 51 - MtVertexFormatShortNormalized = 52 - MtVertexFormatHalf = 53 -end - -@cenum MtVertexStepFunction::UInt32 begin - MtVertexStepFunctionConstant = 0 - MtVertexStepFunctionPerVertex = 1 - MtVertexStepFunctionPerInstance = 2 - MtVertexStepFunctionPerPatch = 3 - MtVertexStepFunctionPerPatchControlPoint = 4 -end - -function mtVertexDescNew() - ccall((:mtVertexDescNew, libcmt), Ptr{MtVertexDescriptor}, ()) -end - -function mtVertexAttrib(vertex, attribIndex, format, offset, bufferIndex) - ccall((:mtVertexAttrib, libcmt), Cvoid, (Ptr{MtVertexDescriptor}, UInt32, MtVertexFormat, UInt32, UInt32), vertex, attribIndex, format, offset, bufferIndex) -end - -function mtVertexLayout(vertex, layoutIndex, stride, stepRate, stepFunction) - ccall((:mtVertexLayout, libcmt), Cvoid, (Ptr{MtVertexDescriptor}, UInt32, UInt32, UInt32, MtVertexStepFunction), vertex, layoutIndex, stride, stepRate, stepFunction) -end - -function mtSetVertexDesc(pipeline, vert) - ccall((:mtSetVertexDesc, libcmt), Cvoid, (Ptr{MtRenderPipeline}, Ptr{MtVertexDescriptor}), pipeline, vert) -end - -@cenum MtCompareFunction::UInt32 begin - MtCompareFunctionNever = 0 - MtCompareFunctionLess = 1 - MtCompareFunctionEqual = 2 - MtCompareFunctionLessEqual = 3 - MtCompareFunctionGreater = 4 - MtCompareFunctionNotEqual = 5 - MtCompareFunctionGreaterEqual = 6 - MtCompareFunctionAlways = 7 -end - -@cenum MtStencilOperation::UInt32 begin - MtStencilOperationKeep = 0 - MtStencilOperationZero = 1 - MtStencilOperationReplace = 2 - MtStencilOperationIncrementClamp = 3 - MtStencilOperationDecrementClamp = 4 - MtStencilOperationInvert = 5 - MtStencilOperationIncrementWrap = 6 - MtStencilOperationDecrementWrap = 7 -end - -function mtDepthStencil(depthCompareFunc, depthWriteEnabled) - ccall((:mtDepthStencil, libcmt), Ptr{MtDepthStencil}, (MtCompareFunction, Bool), depthCompareFunc, depthWriteEnabled) -end - -function mtNewPass() - ccall((:mtNewPass, libcmt), Ptr{MtRenderPassDesc}, ()) -end - -function mtPassTexture(pass, colorAttch, tex) - ccall((:mtPassTexture, libcmt), Cvoid, (Ptr{MtRenderPassDesc}, Cint, Ptr{MtTexture}), pass, colorAttch, tex) -end - -function mtPassLoadAction(pass, colorAttch, action) - ccall((:mtPassLoadAction, libcmt), Cvoid, (Ptr{MtRenderPassDesc}, Cint, MtLoadAction), pass, colorAttch, action) -end - -@cenum MtFuncType::UInt32 begin - MT_FUNC_VERT = 1 - MT_FUNC_FRAG = 2 -end - -function mtNewRenderPipeline(pixelFormat) - ccall((:mtNewRenderPipeline, libcmt), Ptr{MtRenderDesc}, (MtPixelFormat,), pixelFormat) -end - -function mtSetFunc(pipDesc, func, functype) - ccall((:mtSetFunc, libcmt), Cvoid, (Ptr{MtRenderDesc}, Ptr{MtFunction}, MtFuncType), pipDesc, func, functype) -end - -function mtNewRenderState(device, pipDesc, error) - ccall((:mtNewRenderState, libcmt), Ptr{MtRenderPipeline}, (Ptr{MtDevice}, Ptr{MtRenderDesc}, Ptr{Ptr{NsError}}), device, pipDesc, error) -end - -function mtColorPixelFormat(renderdesc, index, pixelFormat) - ccall((:mtColorPixelFormat, libcmt), Cvoid, (Ptr{MtRenderDesc}, UInt32, MtPixelFormat), renderdesc, index, pixelFormat) -end - -function mtDepthPixelFormat(renderdesc, pixelFormat) - ccall((:mtDepthPixelFormat, libcmt), Cvoid, (Ptr{MtRenderDesc}, MtPixelFormat), renderdesc, pixelFormat) -end - -function mtStencilPixelFormat(renderdesc, pixelFormat) - ccall((:mtStencilPixelFormat, libcmt), Cvoid, (Ptr{MtRenderDesc}, MtPixelFormat), renderdesc, pixelFormat) -end - -function mtSampleCount(renderdesc, sampleCount) - ccall((:mtSampleCount, libcmt), Cvoid, (Ptr{MtRenderDesc}, UInt32), renderdesc, sampleCount) -end - -function mtArgumentName(arg) - ccall((:mtArgumentName, libcmt), Cstring, (Ptr{MtArgument},), arg) -end - -function mtArgumentActive(arg) - ccall((:mtArgumentActive, libcmt), Bool, (Ptr{MtArgument},), arg) -end - -function mtArgumentIndex(arg) - ccall((:mtArgumentIndex, libcmt), NsUInteger, (Ptr{MtArgument},), arg) -end - -function mtArgumentType(arg) - ccall((:mtArgumentType, libcmt), MtArgumentType, (Ptr{MtArgument},), arg) -end - -function mtArgumentAccess(arg) - ccall((:mtArgumentAccess, libcmt), MtArgumentAccess, (Ptr{MtArgument},), arg) -end - -function mtArgumentBufferAlignment(arg) - ccall((:mtArgumentBufferAlignment, libcmt), NsUInteger, (Ptr{MtArgument},), arg) -end - -function mtArgumentBufferDataSize(arg) - ccall((:mtArgumentBufferDataSize, libcmt), NsUInteger, (Ptr{MtArgument},), arg) -end - -function mtArgumentBufferDataType(arg) - ccall((:mtArgumentBufferDataType, libcmt), MtDataType, (Ptr{MtArgument},), arg) -end - -function mtArgumentBufferStructType(arg) - ccall((:mtArgumentBufferStructType, libcmt), Ptr{MtStructType}, (Ptr{MtArgument},), arg) -end - -function mtArgumentBufferPointerType(arg) - ccall((:mtArgumentBufferPointerType, libcmt), Ptr{MtPointerType}, (Ptr{MtArgument},), arg) -end - -function mtArgumentArrayLength(arg) - ccall((:mtArgumentArrayLength, libcmt), NsUInteger, (Ptr{MtArgument},), arg) -end - -function mtArgumentThreadgroupMemoryAlignment(arg) - ccall((:mtArgumentThreadgroupMemoryAlignment, libcmt), NsUInteger, (Ptr{MtArgument},), arg) -end - -function mtArgumentThreadgroupMemoryDataSize(arg) - ccall((:mtArgumentThreadgroupMemoryDataSize, libcmt), NsUInteger, (Ptr{MtArgument},), arg) -end - -function mtNewComputePipelineReflection() - ccall((:mtNewComputePipelineReflection, libcmt), Ptr{MtComputePipelineReflection}, ()) -end - -function mtComputePipelinereflectionArguments(refl) - ccall((:mtComputePipelinereflectionArguments, libcmt), Ptr{MtArgument}, (Ptr{MtComputePipelineReflection},), refl) -end - -function mtPointerTypeElementType(ptr) - ccall((:mtPointerTypeElementType, libcmt), MtDataType, (Ptr{MtPointerType},), ptr) -end - -function mtPointerTypeAccess(ptr) - ccall((:mtPointerTypeAccess, libcmt), MtArgumentAccess, (Ptr{MtPointerType},), ptr) -end - -function mtPointerTypeAlignment(ptr) - ccall((:mtPointerTypeAlignment, libcmt), NsUInteger, (Ptr{MtPointerType},), ptr) -end - -function mtPointerTypeDataSize(ptr) - ccall((:mtPointerTypeDataSize, libcmt), NsUInteger, (Ptr{MtPointerType},), ptr) -end - -function mtPointerTypeElementIsArgumentBuffer(ptr) - ccall((:mtPointerTypeElementIsArgumentBuffer, libcmt), Bool, (Ptr{MtPointerType},), ptr) -end - -function mtPointerTypeElementStructType(ptr) - ccall((:mtPointerTypeElementStructType, libcmt), Ptr{MtStructType}, (Ptr{MtPointerType},), ptr) -end - -function mtPointerTypeElementArrayType(ptr) - ccall((:mtPointerTypeElementArrayType, libcmt), Ptr{MtArrayType}, (Ptr{MtPointerType},), ptr) -end - -# typedef void ( * MtCommandBufferOnCompletedFn ) ( void * __restrict data ) -const MtCommandBufferOnCompletedFn = Ptr{Cvoid} - -# typedef void ( * MtCommandBufferOnScheduledFn ) ( void * __restrict data ) -const MtCommandBufferOnScheduledFn = Ptr{Cvoid} - -function mtNewCommandBufferDescriptor() - ccall((:mtNewCommandBufferDescriptor, libcmt), Ptr{MtCommandBufferDescriptor}, ()) -end - -function mtCommandBufferDescriptorRetainedReferences(desc) - ccall((:mtCommandBufferDescriptorRetainedReferences, libcmt), Bool, (Ptr{MtCommandBufferDescriptor},), desc) -end - -function mtCommandBufferDescriptorRetainedReferencesSet(desc, retain) - ccall((:mtCommandBufferDescriptorRetainedReferencesSet, libcmt), Cvoid, (Ptr{MtCommandBufferDescriptor}, Bool), desc, retain) -end - -function mtCommandBufferDescriptorErrorOptions(desc) - ccall((:mtCommandBufferDescriptorErrorOptions, libcmt), NsUInteger, (Ptr{MtCommandBufferDescriptor},), desc) -end - -function mtCommandBufferDescriptorErrorOptionsSet(desc, errorOption) - ccall((:mtCommandBufferDescriptorErrorOptionsSet, libcmt), Cvoid, (Ptr{MtCommandBufferDescriptor}, NsUInteger), desc, errorOption) -end - -function mtNewCommandBuffer(cmdq) - ccall((:mtNewCommandBuffer, libcmt), Ptr{MtCommandBuffer}, (Ptr{MtCommandQueue},), cmdq) -end - -function mtNewCommandBufferWithDescriptor(cmdq, desc) - ccall((:mtNewCommandBufferWithDescriptor, libcmt), Ptr{MtCommandBuffer}, (Ptr{MtCommandQueue}, Ptr{MtCommandBufferDescriptor}), cmdq, desc) -end - -function mtNewCommandBufferWithUnretainedReferences(cmdq) - ccall((:mtNewCommandBufferWithUnretainedReferences, libcmt), Ptr{MtCommandBuffer}, (Ptr{MtCommandQueue},), cmdq) -end - -function mtCommandBufferOnCompleted(cmdb, data, fn) - ccall((:mtCommandBufferOnCompleted, libcmt), Cvoid, (Ptr{MtCommandBuffer}, Ptr{Cvoid}, MtCommandBufferOnCompletedFn), cmdb, data, fn) -end - -function mtCommandBufferOnScheduled(cmdb, data, fn) - ccall((:mtCommandBufferOnScheduled, libcmt), Cvoid, (Ptr{MtCommandBuffer}, Ptr{Cvoid}, MtCommandBufferOnScheduledFn), cmdb, data, fn) -end - -function mtCommandBufferPresentDrawable(cmdb, drawable) - ccall((:mtCommandBufferPresentDrawable, libcmt), Cvoid, (Ptr{MtCommandBuffer}, Ptr{MtDrawable}), cmdb, drawable) -end - -function mtCommandBufferEnqueue(cmdb) - ccall((:mtCommandBufferEnqueue, libcmt), Cvoid, (Ptr{MtCommandBuffer},), cmdb) -end - -function mtCommandBufferCommit(cmdb) - ccall((:mtCommandBufferCommit, libcmt), Cvoid, (Ptr{MtCommandBuffer},), cmdb) -end - -function mtCommandBufferAddScheduledHandler(cmdb, handler) - ccall((:mtCommandBufferAddScheduledHandler, libcmt), Cvoid, (Ptr{MtCommandBuffer}, MtCommandBufferHandlerFun), cmdb, handler) -end - -function mtCommandBufferAddCompletedHandler(cmdb, handler) - ccall((:mtCommandBufferAddCompletedHandler, libcmt), Cvoid, (Ptr{MtCommandBuffer}, MtCommandBufferHandlerFun), cmdb, handler) -end - -function mtCommandBufferWaitUntilScheduled(cmdb) - ccall((:mtCommandBufferWaitUntilScheduled, libcmt), Cvoid, (Ptr{MtCommandBuffer},), cmdb) -end - -function mtCommandBufferWaitUntilCompleted(cmdb) - ccall((:mtCommandBufferWaitUntilCompleted, libcmt), Cvoid, (Ptr{MtCommandBuffer},), cmdb) -end - -function mtCommandBufferStatus(cmdb) - ccall((:mtCommandBufferStatus, libcmt), MtCommandBufferStatus, (Ptr{MtCommandBuffer},), cmdb) -end - -function mtCommandBufferErrorOptions(cmdb) - ccall((:mtCommandBufferErrorOptions, libcmt), MtCommandBufferErrorOption, (Ptr{MtCommandBuffer},), cmdb) -end - -function mtCommandBufferError(cmdb) - ccall((:mtCommandBufferError, libcmt), Ptr{NsError}, (Ptr{MtCommandBuffer},), cmdb) -end - -function mtCommandBufferKernelStartTime(cmdb) - ccall((:mtCommandBufferKernelStartTime, libcmt), CfTimeInterval, (Ptr{MtCommandBuffer},), cmdb) -end - -function mtCommandBufferKernelEndTime(cmdb) - ccall((:mtCommandBufferKernelEndTime, libcmt), CfTimeInterval, (Ptr{MtCommandBuffer},), cmdb) -end - -function mtCommandBufferGPUStartTime(cmdb) - ccall((:mtCommandBufferGPUStartTime, libcmt), CfTimeInterval, (Ptr{MtCommandBuffer},), cmdb) -end - -function mtCommandBufferGPUEndTime(cmdb) - ccall((:mtCommandBufferGPUEndTime, libcmt), CfTimeInterval, (Ptr{MtCommandBuffer},), cmdb) -end - -function mtCommandBufferEncodeSignalEvent(cmdb, event, val) - ccall((:mtCommandBufferEncodeSignalEvent, libcmt), Cvoid, (Ptr{MtCommandBuffer}, Ptr{MtEvent}, UInt64), cmdb, event, val) -end - -function mtCommandBufferEncodeWaitForEvent(cmdb, event, val) - ccall((:mtCommandBufferEncodeWaitForEvent, libcmt), Cvoid, (Ptr{MtCommandBuffer}, Ptr{MtEvent}, UInt64), cmdb, event, val) -end - -function mtCommandBufferRetainedReferences(cmdb) - ccall((:mtCommandBufferRetainedReferences, libcmt), Bool, (Ptr{MtCommandBuffer},), cmdb) -end - -function mtCommandBufferDevice(cmdb) - ccall((:mtCommandBufferDevice, libcmt), Ptr{MtDevice}, (Ptr{MtCommandBuffer},), cmdb) -end - -function mtCommandBufferCommandQueue(cmdb) - ccall((:mtCommandBufferCommandQueue, libcmt), Ptr{MtCommandQueue}, (Ptr{MtCommandBuffer},), cmdb) -end - -function mtCommandBufferLabel(cmdb) - ccall((:mtCommandBufferLabel, libcmt), Cstring, (Ptr{MtCommandBuffer},), cmdb) -end - -function mtCommandBufferLabelSet(cmdb, label) - ccall((:mtCommandBufferLabelSet, libcmt), Cvoid, (Ptr{MtCommandBuffer}, Cstring), cmdb, label) -end - -function mtCommandBufferPushDebugGroup(cmdb, str) - ccall((:mtCommandBufferPushDebugGroup, libcmt), Cvoid, (Ptr{MtCommandBuffer}, Cstring), cmdb, str) -end - -function mtCommandBufferPopDebugGroup(cmdb) - ccall((:mtCommandBufferPopDebugGroup, libcmt), Cvoid, (Ptr{MtCommandBuffer},), cmdb) -end - -function mtNewIndirectCommandBuffer(device, desc, maxCount, options) - ccall((:mtNewIndirectCommandBuffer, libcmt), Ptr{MtIndirectCommandBuffer}, (Ptr{MtDevice}, Ptr{MtIndirectCommandBufferDescriptor}, NsUInteger, MtResourceOptions), device, desc, maxCount, options) -end - -function mtIndirectCommandBufferSize(icb) - ccall((:mtIndirectCommandBufferSize, libcmt), NsUInteger, (Ptr{MtIndirectCommandBuffer},), icb) -end - -function mtIndirectCommandBufferComputeCommandAtIndex(icb, index) - ccall((:mtIndirectCommandBufferComputeCommandAtIndex, libcmt), Ptr{MtIndirectComputeCommand}, (Ptr{MtIndirectCommandBuffer}, NsUInteger), icb, index) -end - -function mtIndirectCommandBufferRenderCommandAtIndex(icb, index) - ccall((:mtIndirectCommandBufferRenderCommandAtIndex, libcmt), Ptr{MtIndirectRenderCommand}, (Ptr{MtIndirectCommandBuffer}, NsUInteger), icb, index) -end - -function mtIndirectCommandBufferResetWithRange(icb, range) - ccall((:mtIndirectCommandBufferResetWithRange, libcmt), Cvoid, (Ptr{MtIndirectCommandBuffer}, NsRange), icb, range) -end - -function mtCommandEncoderEndEncoding(ce) - ccall((:mtCommandEncoderEndEncoding, libcmt), Cvoid, (Ptr{MtCommandEncoder},), ce) -end - -function mtCommandEncoderDevice(ce) - ccall((:mtCommandEncoderDevice, libcmt), Ptr{MtDevice}, (Ptr{MtCommandEncoder},), ce) -end - -function mtCommandEncoderLabel(ce) - ccall((:mtCommandEncoderLabel, libcmt), Cstring, (Ptr{MtCommandEncoder},), ce) -end - -function mtCommandEncoderLabelSet(ce, label) - ccall((:mtCommandEncoderLabelSet, libcmt), Cvoid, (Ptr{MtCommandEncoder}, Cstring), ce, label) -end - -function mtCommandEncoderInsertDebugSignpost(ce, string) - ccall((:mtCommandEncoderInsertDebugSignpost, libcmt), Cvoid, (Ptr{MtCommandEncoder}, Cstring), ce, string) -end - -function mtCommandEncoderPushDebugGroup(ce, string) - ccall((:mtCommandEncoderPushDebugGroup, libcmt), Cvoid, (Ptr{MtCommandEncoder}, Cstring), ce, string) -end - -function mtCommandEncoderPopDebugGroup(ce) - ccall((:mtCommandEncoderPopDebugGroup, libcmt), Cvoid, (Ptr{MtCommandEncoder},), ce) -end - -function mtNewBlitCommandEncoder(cmdb) - ccall((:mtNewBlitCommandEncoder, libcmt), Ptr{MtBlitCommandEncoder}, (Ptr{MtCommandBuffer},), cmdb) -end - -function mtBlitCommandEncoderCopyFromBufferToBuffer(bce, src, src_offset, dst, dst_offset, size) - ccall((:mtBlitCommandEncoderCopyFromBufferToBuffer, libcmt), Cvoid, (Ptr{MtBlitCommandEncoder}, Ptr{MtBuffer}, NsUInteger, Ptr{MtBuffer}, NsUInteger, NsUInteger), bce, src, src_offset, dst, dst_offset, size) -end - -function mtBlitCommandEncoderFillBuffer(bce, src, range, val) - ccall((:mtBlitCommandEncoderFillBuffer, libcmt), Cvoid, (Ptr{MtBlitCommandEncoder}, Ptr{MtBuffer}, NsRange, UInt8), bce, src, range, val) -end - -function mtBlitCommandEncoderGenerateMipmaps(bce, texture) - ccall((:mtBlitCommandEncoderGenerateMipmaps, libcmt), Cvoid, (Ptr{MtBlitCommandEncoder}, Ptr{MtTexture}), bce, texture) -end - -function mtBlitCommandEncoderCopyIndirectCommandBuffer(bce, src, range, dst, dst_index) - ccall((:mtBlitCommandEncoderCopyIndirectCommandBuffer, libcmt), Cvoid, (Ptr{MtBlitCommandEncoder}, Ptr{MtIndirectCommandBuffer}, NsRange, Ptr{MtIndirectCommandBuffer}, NsUInteger), bce, src, range, dst, dst_index) -end - -function mtBlitCommandEncoderOptimizeIndirectCommandBuffer(bce, buffer, range) - ccall((:mtBlitCommandEncoderOptimizeIndirectCommandBuffer, libcmt), Cvoid, (Ptr{MtBlitCommandEncoder}, Ptr{MtIndirectCommandBuffer}, NsRange), bce, buffer, range) -end - -function mtBlitCommandEncoderResetCommandsInBuffer(bce, buffer, range) - ccall((:mtBlitCommandEncoderResetCommandsInBuffer, libcmt), Cvoid, (Ptr{MtBlitCommandEncoder}, Ptr{MtIndirectCommandBuffer}, NsRange), bce, buffer, range) -end - -function mtBlitCommandEncoderSynchronizeResource(bce, resource) - ccall((:mtBlitCommandEncoderSynchronizeResource, libcmt), Cvoid, (Ptr{MtBlitCommandEncoder}, Ptr{MtResource}), bce, resource) -end - -function mtBlitCommandEncoderSynchronizeTexture(bce, texture, slice, level) - ccall((:mtBlitCommandEncoderSynchronizeTexture, libcmt), Cvoid, (Ptr{MtBlitCommandEncoder}, Ptr{MtTexture}, NsUInteger, NsUInteger), bce, texture, slice, level) -end - -function mtBlitCommandEncoderUpdateFence(icb, fence) - ccall((:mtBlitCommandEncoderUpdateFence, libcmt), Cvoid, (Ptr{MtIndirectCommandBuffer}, Ptr{MtFence}), icb, fence) -end - -function mtBlitCommandEncoderWaitForFence(icb, fence) - ccall((:mtBlitCommandEncoderWaitForFence, libcmt), Cvoid, (Ptr{MtIndirectCommandBuffer}, Ptr{MtFence}), icb, fence) -end - -function mtBlitCommandEncoderOptimizeContentsForGPUAccess(icb, tex) - ccall((:mtBlitCommandEncoderOptimizeContentsForGPUAccess, libcmt), Cvoid, (Ptr{MtIndirectCommandBuffer}, Ptr{MtTexture}), icb, tex) -end - -function mtBlitCommandEncoderOptimizeContentsForGPUAccessSliceLevel(icb, tex, slice, level) - ccall((:mtBlitCommandEncoderOptimizeContentsForGPUAccessSliceLevel, libcmt), Cvoid, (Ptr{MtIndirectCommandBuffer}, Ptr{MtTexture}, NsUInteger, NsUInteger), icb, tex, slice, level) -end - -function mtBlitCommandEncoderOptimizeContentsForCPUAccess(icb, tex) - ccall((:mtBlitCommandEncoderOptimizeContentsForCPUAccess, libcmt), Cvoid, (Ptr{MtIndirectCommandBuffer}, Ptr{MtTexture}), icb, tex) -end - -function mtBlitCommandEncoderOptimizeContentsForCPUAccessSliceLevel(icb, tex, slice, level) - ccall((:mtBlitCommandEncoderOptimizeContentsForCPUAccessSliceLevel, libcmt), Cvoid, (Ptr{MtIndirectCommandBuffer}, Ptr{MtTexture}, NsUInteger, NsUInteger), icb, tex, slice, level) -end - -function mtBlitCommandEncoderSampleCountersInBuffer(icb, sbuf, sampleindex, barrier) - ccall((:mtBlitCommandEncoderSampleCountersInBuffer, libcmt), Cvoid, (Ptr{MtIndirectCommandBuffer}, Ptr{MtCounterSampleBuffer}, NsUInteger, Bool), icb, sbuf, sampleindex, barrier) -end - -function mtBlitCommandEncoderResolveCounters(icb, sbuf, range, dst, dst_offset) - ccall((:mtBlitCommandEncoderResolveCounters, libcmt), Cvoid, (Ptr{MtIndirectCommandBuffer}, Ptr{MtCounterSampleBuffer}, NsRange, Ptr{MtBuffer}, NsUInteger), icb, sbuf, range, dst, dst_offset) -end - -function mtNewComputeCommandEncoder(cmdb) - ccall((:mtNewComputeCommandEncoder, libcmt), Ptr{MtComputeCommandEncoder}, (Ptr{MtCommandBuffer},), cmdb) -end - -function mtNewComputeCommandEncoderWithDispatchType(cmdb, dtype) - ccall((:mtNewComputeCommandEncoderWithDispatchType, libcmt), Ptr{MtComputeCommandEncoder}, (Ptr{MtCommandBuffer}, MtDispatchType), cmdb, dtype) -end - -function mtComputeCommandEncoderEndEncoding(cce) - ccall((:mtComputeCommandEncoderEndEncoding, libcmt), Cvoid, (Ptr{MtComputeCommandEncoder},), cce) -end - -function mtComputeCommandEncoderSetComputePipelineState(cce, state) - ccall((:mtComputeCommandEncoderSetComputePipelineState, libcmt), Cvoid, (Ptr{MtComputeCommandEncoder}, Ptr{MtComputePipelineState}), cce, state) -end - -function mtComputeCommandEncoderSetBufferOffsetAtIndex(cce, buf, offset, indx) - ccall((:mtComputeCommandEncoderSetBufferOffsetAtIndex, libcmt), Cvoid, (Ptr{MtComputeCommandEncoder}, Ptr{MtBuffer}, NsUInteger, NsUInteger), cce, buf, offset, indx) -end - -function mtComputeCommandEncoderSetBuffersOffsetsWithRange(cce, bufs, offsets, range) - ccall((:mtComputeCommandEncoderSetBuffersOffsetsWithRange, libcmt), Cvoid, (Ptr{MtComputeCommandEncoder}, Ptr{Ptr{MtBuffer}}, Ptr{NsUInteger}, NsRange), cce, bufs, offsets, range) -end - -function mtComputeCommandEncoderBufferSetOffsetAtIndex(cce, offset, indx) - ccall((:mtComputeCommandEncoderBufferSetOffsetAtIndex, libcmt), Cvoid, (Ptr{MtComputeCommandEncoder}, NsUInteger, NsUInteger), cce, offset, indx) -end - -function mtComputeCommandEncoderSetBytesLengthAtIndex(cce, ptr, length, indx) - ccall((:mtComputeCommandEncoderSetBytesLengthAtIndex, libcmt), Cvoid, (Ptr{MtComputeCommandEncoder}, Ptr{Cvoid}, NsUInteger, NsUInteger), cce, ptr, length, indx) -end - -function mtComputeCommandEncoderSetSamplerStateAtIndex(cce, sampler, indx) - ccall((:mtComputeCommandEncoderSetSamplerStateAtIndex, libcmt), Cvoid, (Ptr{MtComputeCommandEncoder}, Ptr{MtSamplerState}, NsUInteger), cce, sampler, indx) -end - -function mtComputeCommandEncoderSetSamplerStatesWithRange(cce, samplers, range) - ccall((:mtComputeCommandEncoderSetSamplerStatesWithRange, libcmt), Cvoid, (Ptr{MtComputeCommandEncoder}, Ptr{Ptr{MtSamplerState}}, NsRange), cce, samplers, range) -end - -function mtComputeCommandEncoderSetSamplerStateLodMinClampLodMaxClampAtIndex(cce, sampler, lodMinClamp, lodMaxClamp, indx) - ccall((:mtComputeCommandEncoderSetSamplerStateLodMinClampLodMaxClampAtIndex, libcmt), Cvoid, (Ptr{MtComputeCommandEncoder}, Ptr{MtSamplerState}, Cfloat, Cfloat, NsUInteger), cce, sampler, lodMinClamp, lodMaxClamp, indx) -end - -function mtComputeCommandEncoderSetTextureAtIndex(cce, tex, indx) - ccall((:mtComputeCommandEncoderSetTextureAtIndex, libcmt), Cvoid, (Ptr{MtComputeCommandEncoder}, Ptr{MtTexture}, NsUInteger), cce, tex, indx) -end - -function mtComputeCommandEncoderSetTexturesWithRange(cce, textures, range) - ccall((:mtComputeCommandEncoderSetTexturesWithRange, libcmt), Cvoid, (Ptr{MtComputeCommandEncoder}, Ptr{Ptr{MtTexture}}, NsRange), cce, textures, range) -end - -function mtComputeCommandEncoderSetThreadgroupMemoryLengthAtIndex(cce, length, indx) - ccall((:mtComputeCommandEncoderSetThreadgroupMemoryLengthAtIndex, libcmt), Cvoid, (Ptr{MtComputeCommandEncoder}, NsUInteger, NsUInteger), cce, length, indx) -end - -function mtComputeCommandEncoderDispatchThreadgroups_threadsPerThreadgroup(cce, threadgroupsPerGrid, threadsPerThreadgroup) - ccall((:mtComputeCommandEncoderDispatchThreadgroups_threadsPerThreadgroup, libcmt), Cvoid, (Ptr{MtComputeCommandEncoder}, MtSize, MtSize), cce, threadgroupsPerGrid, threadsPerThreadgroup) -end - -function mtComputeCommandEncoderDispatchThread_threadsPerThreadgroup(cce, threadsPerGrid, threadsPerThreadgroup) - ccall((:mtComputeCommandEncoderDispatchThread_threadsPerThreadgroup, libcmt), Cvoid, (Ptr{MtComputeCommandEncoder}, MtSize, MtSize), cce, threadsPerGrid, threadsPerThreadgroup) -end - -function mtComputeCommandEncoderDispatchThreadgroupsWithIndirectBuffer_IndirectBufferOffset_threadsPerThreadgroup(cce, indirectBuffer, indirectBufferOffset, threadsPerThreadgroup) - ccall((:mtComputeCommandEncoderDispatchThreadgroupsWithIndirectBuffer_IndirectBufferOffset_threadsPerThreadgroup, libcmt), Cvoid, (Ptr{MtComputeCommandEncoder}, Ptr{MtBuffer}, NsUInteger, MtSize), cce, indirectBuffer, indirectBufferOffset, threadsPerThreadgroup) -end - -function mtComputeCommandEncoderUseResourceUsage(cce, res, usage) - ccall((:mtComputeCommandEncoderUseResourceUsage, libcmt), Cvoid, (Ptr{MtComputeCommandEncoder}, Ptr{MtResource}, MtResourceUsage), cce, res, usage) -end - -function mtComputeCommandEncoderUseResourcesCountUsage(cce, res, count, usage) - ccall((:mtComputeCommandEncoderUseResourcesCountUsage, libcmt), Cvoid, (Ptr{MtComputeCommandEncoder}, Ptr{Ptr{MtResource}}, NsUInteger, MtResourceUsage), cce, res, count, usage) -end - -function mtComputeCommandEncoderUseHeap(cce, heap) - ccall((:mtComputeCommandEncoderUseHeap, libcmt), Cvoid, (Ptr{MtComputeCommandEncoder}, Ptr{MtHeap}), cce, heap) -end - -function mtComputeCommandEncoderUseHeaps(cce, heaps, count) - ccall((:mtComputeCommandEncoderUseHeaps, libcmt), Cvoid, (Ptr{MtComputeCommandEncoder}, Ptr{Ptr{MtHeap}}, NsUInteger), cce, heaps, count) -end - -function mtComputeCommandEncoderSetStageInRegion(cce, region) - ccall((:mtComputeCommandEncoderSetStageInRegion, libcmt), Cvoid, (Ptr{MtComputeCommandEncoder}, MtRegion), cce, region) -end - -function mtComputeCommandEncoderSetStageInRegionWithIndirectBuffer(cce, buf, offset) - ccall((:mtComputeCommandEncoderSetStageInRegionWithIndirectBuffer, libcmt), Cvoid, (Ptr{MtComputeCommandEncoder}, Ptr{MtBuffer}, NsUInteger), cce, buf, offset) -end - -function mtComputeCommandEncoderDispatchType(cce) - ccall((:mtComputeCommandEncoderDispatchType, libcmt), MtDispatchType, (Ptr{MtComputeCommandEncoder},), cce) -end - -function mtComputeCommandEncoderMemoryBarrierWithScope(cce, scope) - ccall((:mtComputeCommandEncoderMemoryBarrierWithScope, libcmt), Cvoid, (Ptr{MtComputeCommandEncoder}, MtBarrierScope), cce, scope) -end - -function mtComputeCommandEncoderMemoryBarrierWithResource(cce, resources, count) - ccall((:mtComputeCommandEncoderMemoryBarrierWithResource, libcmt), Cvoid, (Ptr{MtComputeCommandEncoder}, Ptr{Ptr{MtResource}}, NsUInteger), cce, resources, count) -end - -function mtComputeCommandEncoderExecuteCommandInBuffer(cce, resources, count) - ccall((:mtComputeCommandEncoderExecuteCommandInBuffer, libcmt), Cvoid, (Ptr{MtComputeCommandEncoder}, Ptr{Ptr{MtResource}}, NsUInteger), cce, resources, count) -end - -function mtNewRenderCommandEncoder(cmdb, pass) - ccall((:mtNewRenderCommandEncoder, libcmt), Ptr{MtRenderCommandEncoder}, (Ptr{MtCommandBuffer}, Ptr{MtRenderPassDesc}), cmdb, pass) -end - -function mtFrontFace(rce, winding) - ccall((:mtFrontFace, libcmt), Cvoid, (Ptr{MtRenderCommandEncoder}, MtWinding), rce, winding) -end - -function mtCullMode(rce, mode) - ccall((:mtCullMode, libcmt), Cvoid, (Ptr{MtRenderCommandEncoder}, MtCullMode), rce, mode) -end - -function mtViewport(rce, viewport) - ccall((:mtViewport, libcmt), Cvoid, (Ptr{MtRenderCommandEncoder}, Ptr{MtViewport}), rce, viewport) -end - -function mtSetRenderState(rce, pipline) - ccall((:mtSetRenderState, libcmt), Cvoid, (Ptr{MtRenderCommandEncoder}, Ptr{MtRenderPipeline}), rce, pipline) -end - -function mtSetDepthStencil(rce, ds) - ccall((:mtSetDepthStencil, libcmt), Cvoid, (Ptr{MtRenderCommandEncoder}, Ptr{MtDepthStencil}), rce, ds) -end - -function mtVertexBytes(rce, bytes, legth, atIndex) - ccall((:mtVertexBytes, libcmt), Cvoid, (Ptr{MtRenderCommandEncoder}, Ptr{Cvoid}, Csize_t, UInt32), rce, bytes, legth, atIndex) -end - -function mtVertexBuffer(rce, buf, off, index) - ccall((:mtVertexBuffer, libcmt), Cvoid, (Ptr{MtRenderCommandEncoder}, Ptr{MtBuffer}, Csize_t, UInt32), rce, buf, off, index) -end - -function mtFragmentBuffer(rce, buf, off, index) - ccall((:mtFragmentBuffer, libcmt), Cvoid, (Ptr{MtRenderCommandEncoder}, Ptr{MtBuffer}, Csize_t, UInt32), rce, buf, off, index) -end - -function mtDrawPrims(rce, type, start, count) - ccall((:mtDrawPrims, libcmt), Cvoid, (Ptr{MtRenderCommandEncoder}, MtPrimitiveType, Csize_t, Csize_t), rce, type, start, count) -end - -function mtDrawIndexedPrims(rce, type, indexCount, indexType, indexBuffer, indexBufferOffset) - ccall((:mtDrawIndexedPrims, libcmt), Cvoid, (Ptr{MtRenderCommandEncoder}, MtPrimitiveType, UInt32, MtIndexType, Ptr{MtBuffer}, UInt32), rce, type, indexCount, indexType, indexBuffer, indexBufferOffset) -end - -function mtNewCommandQueue(device) - ccall((:mtNewCommandQueue, libcmt), Ptr{MtCommandQueue}, (Ptr{MtDevice},), device) -end - -function mtNewCommandQueueWithMaxCommandBufferCount(device, count) - ccall((:mtNewCommandQueueWithMaxCommandBufferCount, libcmt), Ptr{MtCommandQueue}, (Ptr{MtDevice}, NsUInteger), device, count) -end - -function mtCommandQueueDevice(cmdq) - ccall((:mtCommandQueueDevice, libcmt), Ptr{MtDevice}, (Ptr{MtCommandQueue},), cmdq) -end - -function mtCommandQueueLabel(cmdq) - ccall((:mtCommandQueueLabel, libcmt), Cstring, (Ptr{MtCommandQueue},), cmdq) -end - -function mtCommandQueueLabelSet(cmdq, label) - ccall((:mtCommandQueueLabelSet, libcmt), Cvoid, (Ptr{MtCommandQueue}, Cstring), cmdq, label) -end - -function mtNewArgumentDescriptor() - ccall((:mtNewArgumentDescriptor, libcmt), Ptr{MtArgumentDescriptor}, ()) -end - -function mtArgumentDescriptorDataType(desc) - ccall((:mtArgumentDescriptorDataType, libcmt), MtDataType, (Ptr{MtArgumentDescriptor},), desc) -end - -function mtArgumentDescriptorDataTypeSet(desc, dataType) - ccall((:mtArgumentDescriptorDataTypeSet, libcmt), Cvoid, (Ptr{MtArgumentDescriptor}, MtDataType), desc, dataType) -end - -function mtArgumentDescriptorIndex(desc) - ccall((:mtArgumentDescriptorIndex, libcmt), NsUInteger, (Ptr{MtArgumentDescriptor},), desc) -end - -function mtArgumentDescriptorIndexSet(desc, index) - ccall((:mtArgumentDescriptorIndexSet, libcmt), Cvoid, (Ptr{MtArgumentDescriptor}, NsUInteger), desc, index) -end - -function mtArgumentDescriptorAccess(desc) - ccall((:mtArgumentDescriptorAccess, libcmt), MtArgumentAccess, (Ptr{MtArgumentDescriptor},), desc) -end - -function mtArgumentDescriptorAccessSet(desc, access) - ccall((:mtArgumentDescriptorAccessSet, libcmt), Cvoid, (Ptr{MtArgumentDescriptor}, MtArgumentAccess), desc, access) -end - -function mtArgumentDescriptorArrayLength(desc) - ccall((:mtArgumentDescriptorArrayLength, libcmt), NsUInteger, (Ptr{MtArgumentDescriptor},), desc) -end - -function mtArgumentDescriptorArrayLengthSet(desc, length) - ccall((:mtArgumentDescriptorArrayLengthSet, libcmt), Cvoid, (Ptr{MtArgumentDescriptor}, NsUInteger), desc, length) -end - -function mtArgumentDescriptorConstantBlockAlignment(desc) - ccall((:mtArgumentDescriptorConstantBlockAlignment, libcmt), NsUInteger, (Ptr{MtArgumentDescriptor},), desc) -end - -function mtArgumentDescriptorConstantBlockAlignmentSet(desc, alignment) - ccall((:mtArgumentDescriptorConstantBlockAlignmentSet, libcmt), Cvoid, (Ptr{MtArgumentDescriptor}, NsUInteger), desc, alignment) -end - -function mtArgumentDescriptorTextureType(desc) - ccall((:mtArgumentDescriptorTextureType, libcmt), MtTextureType, (Ptr{MtArgumentDescriptor},), desc) -end - -function mtArgumentDescriptorTextureTypeSet(desc, textype) - ccall((:mtArgumentDescriptorTextureTypeSet, libcmt), Cvoid, (Ptr{MtArgumentDescriptor}, MtTextureType), desc, textype) -end - -function mtNewArgumentEncoderWithBufferIndexFromFunction(_function, bufferIndex) - ccall((:mtNewArgumentEncoderWithBufferIndexFromFunction, libcmt), Ptr{MtArgumentEncoder}, (Ptr{MtFunction}, NsUInteger), _function, bufferIndex) -end - -function mtNewArgumentEncoderWithBufferIndexReflectionFromFunction(_function, bufferIndex, reflection) - ccall((:mtNewArgumentEncoderWithBufferIndexReflectionFromFunction, libcmt), Ptr{MtArgumentEncoder}, (Ptr{MtFunction}, NsUInteger, Ptr{MtAutoreleasedArgument}), _function, bufferIndex, reflection) -end - -function mtNewArgumentEncoderWithBufferIndexFromArgumentBuffer(ae, bufferIndex) - ccall((:mtNewArgumentEncoderWithBufferIndexFromArgumentBuffer, libcmt), Ptr{MtArgumentEncoder}, (Ptr{MtArgumentEncoder}, NsUInteger), ae, bufferIndex) -end - -function mtNewArgumentEncoder(device, arguments, count) - ccall((:mtNewArgumentEncoder, libcmt), Ptr{MtArgumentEncoder}, (Ptr{MtDevice}, Ptr{Ptr{MtArgumentDescriptor}}, UInt64), device, arguments, count) -end - -function mtArgumentEncoderLength(encoder) - ccall((:mtArgumentEncoderLength, libcmt), NsUInteger, (Ptr{MtArgumentEncoder},), encoder) -end - -function mtArgumentEncoderSetArgumentBufferWithOffset(cce, buf, offset) - ccall((:mtArgumentEncoderSetArgumentBufferWithOffset, libcmt), Cvoid, (Ptr{MtArgumentEncoder}, Ptr{MtBuffer}, NsUInteger), cce, buf, offset) -end - -function mtArgumentEncoderSetArgumentBufferWithOffsetForElement(cce, buf, startOffset, arrayElement) - ccall((:mtArgumentEncoderSetArgumentBufferWithOffsetForElement, libcmt), Cvoid, (Ptr{MtArgumentEncoder}, Ptr{MtBuffer}, NsUInteger, NsUInteger), cce, buf, startOffset, arrayElement) -end - -function mtArgumentEncoderSetBufferOffsetAtIndex(cce, buf, offset, indx) - ccall((:mtArgumentEncoderSetBufferOffsetAtIndex, libcmt), Cvoid, (Ptr{MtArgumentEncoder}, Ptr{MtBuffer}, NsUInteger, NsUInteger), cce, buf, offset, indx) -end - -function mtArgumentEncoderSetBuffersOffsetsWithRange(cce, bufs, offsets, range) - ccall((:mtArgumentEncoderSetBuffersOffsetsWithRange, libcmt), Cvoid, (Ptr{MtArgumentEncoder}, Ptr{Ptr{MtBuffer}}, Ptr{NsUInteger}, NsRange), cce, bufs, offsets, range) -end - -function mtArgumentEncoderSetTextureAtIndex(cce, tex, indx) - ccall((:mtArgumentEncoderSetTextureAtIndex, libcmt), Cvoid, (Ptr{MtArgumentEncoder}, Ptr{MtTexture}, NsUInteger), cce, tex, indx) -end - -function mtArgumentEncoderSetTexturesWithRange(cce, textures, range) - ccall((:mtArgumentEncoderSetTexturesWithRange, libcmt), Cvoid, (Ptr{MtArgumentEncoder}, Ptr{Ptr{MtTexture}}, NsRange), cce, textures, range) -end - -function mtArgumentEncoderSetSamplerStateAtIndex(cce, sampler, indx) - ccall((:mtArgumentEncoderSetSamplerStateAtIndex, libcmt), Cvoid, (Ptr{MtArgumentEncoder}, Ptr{MtSamplerState}, NsUInteger), cce, sampler, indx) -end - -function mtArgumentEncoderSetSamplerStatesWithRange(cce, samplers, range) - ccall((:mtArgumentEncoderSetSamplerStatesWithRange, libcmt), Cvoid, (Ptr{MtArgumentEncoder}, Ptr{Ptr{MtSamplerState}}, NsRange), cce, samplers, range) -end - -function mtArgumentEncoderConstantDataAtIndex(cce, index) - ccall((:mtArgumentEncoderConstantDataAtIndex, libcmt), Ptr{Cvoid}, (Ptr{MtArgumentEncoder}, NsUInteger), cce, index) -end - -function mtArgumentEncoderSetIndirectCommandBuffer(cce, cbuf, index) - ccall((:mtArgumentEncoderSetIndirectCommandBuffer, libcmt), Cvoid, (Ptr{MtArgumentEncoder}, Ptr{MtIndirectCommandBuffer}, NsUInteger), cce, cbuf, index) -end - -function mtArgumentEncoderSetIndirectCommandBuffers(cce, cbufs, range) - ccall((:mtArgumentEncoderSetIndirectCommandBuffers, libcmt), Cvoid, (Ptr{MtArgumentEncoder}, Ptr{Ptr{MtIndirectCommandBuffer}}, NsRange), cce, cbufs, range) -end - -function mtArgumentEncoderAlignment(cce) - ccall((:mtArgumentEncoderAlignment, libcmt), NsUInteger, (Ptr{MtArgumentEncoder},), cce) -end - -function mtNewCaptureDescriptor() - ccall((:mtNewCaptureDescriptor, libcmt), Ptr{MtCaptureDescriptor}, ()) -end - -function mtCaptureDescriptorCaptureObject(desc) - ccall((:mtCaptureDescriptorCaptureObject, libcmt), Ptr{Cvoid}, (Ptr{MtCaptureDescriptor},), desc) -end - -function mtCaptureDescriptorCaptureObjectSetQueue(desc, cmdq) - ccall((:mtCaptureDescriptorCaptureObjectSetQueue, libcmt), Cvoid, (Ptr{MtCaptureDescriptor}, Ptr{MtCommandQueue}), desc, cmdq) -end - -function mtCaptureDescriptorCaptureObjectSetDevice(desc, dev) - ccall((:mtCaptureDescriptorCaptureObjectSetDevice, libcmt), Cvoid, (Ptr{MtCaptureDescriptor}, Ptr{MtDevice}), desc, dev) -end - -function mtCaptureDescriptorCaptureObjectSetScope(desc, scope) - ccall((:mtCaptureDescriptorCaptureObjectSetScope, libcmt), Cvoid, (Ptr{MtCaptureDescriptor}, Ptr{MtCaptureScope}), desc, scope) -end - -function mtCaptureDescriptorDestination(desc) - ccall((:mtCaptureDescriptorDestination, libcmt), MtCaptureDestination, (Ptr{MtCaptureDescriptor},), desc) -end - -function mtCaptureDescriptorDestinationSet(desc, dest) - ccall((:mtCaptureDescriptorDestinationSet, libcmt), Cvoid, (Ptr{MtCaptureDescriptor}, MtCaptureDestination), desc, dest) -end - -function mtCaptureDescriptorOutputURLSet(desc, path) - ccall((:mtCaptureDescriptorOutputURLSet, libcmt), Cvoid, (Ptr{MtCaptureDescriptor}, Cstring), desc, path) -end - -function mtCaptureDescriptorOutputURL(desc) - ccall((:mtCaptureDescriptorOutputURL, libcmt), Cstring, (Ptr{MtCaptureDescriptor},), desc) -end - -function mtSharedCaptureManager() - ccall((:mtSharedCaptureManager, libcmt), Ptr{MtCaptureManager}, ()) -end - -function mtSupportsDestination(manager, destination) - ccall((:mtSupportsDestination, libcmt), Bool, (Ptr{MtCaptureManager}, MtCaptureDestination), manager, destination) -end - -function mtStartCaptureWithDescriptor(manager, descriptor, error) - ccall((:mtStartCaptureWithDescriptor, libcmt), Bool, (Ptr{MtCaptureManager}, Ptr{MtCaptureDescriptor}, Ptr{Ptr{NsError}}), manager, descriptor, error) -end - -function mtStopCapture(manager) - ccall((:mtStopCapture, libcmt), Cvoid, (Ptr{MtCaptureManager},), manager) -end - -function mtIsCapturing(manager) - ccall((:mtIsCapturing, libcmt), Bool, (Ptr{MtCaptureManager},), manager) -end - -function mtDefaultCaptureScope(manager) - ccall((:mtDefaultCaptureScope, libcmt), Ptr{MtCaptureScope}, (Ptr{MtCaptureManager},), manager) -end - -function mtDefaultCaptureScopeSet(manager, scope) - ccall((:mtDefaultCaptureScopeSet, libcmt), Cvoid, (Ptr{MtCaptureManager}, Ptr{MtCaptureScope}), manager, scope) -end - -function mtNewCaptureScopeWithCommandQueue(manager, queue) - ccall((:mtNewCaptureScopeWithCommandQueue, libcmt), Ptr{MtCaptureScope}, (Ptr{MtCaptureManager}, Ptr{MtCommandQueue}), manager, queue) -end - -function mtBeginScope(scope) - ccall((:mtBeginScope, libcmt), Cvoid, (Ptr{MtCaptureScope},), scope) -end - -function mtEndScope(scope) - ccall((:mtEndScope, libcmt), Cvoid, (Ptr{MtCaptureScope},), scope) -end - -function mtCaptureScopeLabel(scope) - ccall((:mtCaptureScopeLabel, libcmt), Cstring, (Ptr{MtCaptureScope},), scope) -end - -function mtCaptureScopeLabelSet(scope, label) - ccall((:mtCaptureScopeLabelSet, libcmt), Cvoid, (Ptr{MtCaptureScope}, Cstring), scope, label) -end - -function mtCaptureScopeDevice(scope) - ccall((:mtCaptureScopeDevice, libcmt), Ptr{MtDevice}, (Ptr{MtCaptureScope},), scope) -end - -function mtCaptureScopeCommandQueue(scope) - ccall((:mtCaptureScopeCommandQueue, libcmt), Ptr{MtCommandQueue}, (Ptr{MtCaptureScope},), scope) -end - -function mtMPSSupportsMTLDevice(device) - ccall((:mtMPSSupportsMTLDevice, libcmt), Bool, (Ptr{MtDevice},), device) -end - -function mtNewMatrixDescriptorWithRows(rows, columns, rowBytes, dataType) - ccall((:mtNewMatrixDescriptorWithRows, libcmt), Ptr{MtMPSMatrixDescriptor}, (NsUInteger, NsUInteger, NsUInteger, UInt32), rows, columns, rowBytes, dataType) -end - -function mtNewMPSMatrixInitWithBuffer(buffer, descriptor) - ccall((:mtNewMPSMatrixInitWithBuffer, libcmt), Ptr{MtMPSMatrix}, (Ptr{MtBuffer}, Ptr{MtMPSMatrixDescriptor}), buffer, descriptor) -end - -function mtNewMPSMatrixMultiplication(device, transposeLeft, transposeRight, resultRows, resultColumns, interiorColumns, alpha, beta) - ccall((:mtNewMPSMatrixMultiplication, libcmt), Ptr{MtMPSMatrixMultiplication}, (Ptr{MtDevice}, Bool, Bool, NsUInteger, NsUInteger, NsUInteger, Cdouble, Cdouble), device, transposeLeft, transposeRight, resultRows, resultColumns, interiorColumns, alpha, beta) -end - -function mtMPSMatMulEncodeToCommandBuffer(matMul, commandBuffer, leftMatrix, rightMatrix, resultMatrix) - ccall((:mtMPSMatMulEncodeToCommandBuffer, libcmt), Cvoid, (Ptr{MtMPSMatrixMultiplication}, Ptr{MtCommandBuffer}, Ptr{MtMPSMatrix}, Ptr{MtMPSMatrix}, Ptr{MtMPSMatrix}), matMul, commandBuffer, leftMatrix, rightMatrix, resultMatrix) -end - -function mtRetain(obj) - ccall((:mtRetain, libcmt), Ptr{Cvoid}, (Ptr{Cvoid},), obj) -end - -function mtRelease(obj) - ccall((:mtRelease, libcmt), Cvoid, (Ptr{Cvoid},), obj) -end - -# Skipping MacroDefinition: MT_EXPORT __attribute__ ( ( visibility ( "default" ) ) ) - -# Skipping MacroDefinition: MT_HIDE __attribute__ ( ( visibility ( "hidden" ) ) ) - -# Skipping MacroDefinition: MT_INLINE inline __attribute ( ( always_inline ) ) - diff --git a/lib/mps/MPS.jl b/lib/mps/MPS.jl index d250c6b9..731eb82b 100644 --- a/lib/mps/MPS.jl +++ b/lib/mps/MPS.jl @@ -2,11 +2,12 @@ module MPS using ..Metal -using ..cmt +using CEnum +using ObjectiveC, .Foundation import GPUArrays -is_supported(dev::MtlDevice) = mtMPSSupportsMTLDevice(dev) +is_supported(dev::MTLDevice) = ccall(:MPSSupportsMTLDevice, Bool, (id{MTLDevice},), dev) # high-level wrappers include("matrix.jl") diff --git a/lib/mps/matrix.jl b/lib/mps/matrix.jl index 5c37a29a..6997cac0 100644 --- a/lib/mps/matrix.jl +++ b/lib/mps/matrix.jl @@ -1,13 +1,37 @@ +# +# matrix enums +# + +@cenum MPSDataType::UInt32 begin + MPSDataTypeComplexBit = UInt32(0x01000000) + MPSDataTypeFloatBit = UInt32(0x10000000) + MPSDataTypeSignedBit = UInt32(0x20000000) + MPSDataTypeNormalizedBit = UInt32(0x40000000) + MPSDataTypeAlternateEncodingBit = UInt32(0x80000000) +end +## bitwise operations lose type information, so allow conversions +Base.convert(::Type{MPSDataType}, x::Integer) = MPSDataType(x) + +@cenum MPSKernelOptions::NSUInteger begin + MPSKernelOptionsNone = 0 + MPSKernelOptionsSkipAPIValidation = 1 << 0 + MPSKernelOptionsAllowReducedPrecision = 1 << 1 + MPSKernelOptionsDisableInternalTiling = 1 << 2 + MPSKernelOptionsInsertDebugGroups = 1 << 3 + MPSKernelOptionsVerbose = 1 << 4 +end + + +# +# matrix descriptor +# -# MPS Data Type Bitfields -const MPSDataTypeComplexBit = UInt32(0x01000000) -const MPSDataTypeFloatBit = UInt32(0x10000000) -const MPSDataTypeSignedBit = UInt32(0x20000000) -const MPSDataTypeNormalizedBit = UInt32(0x40000000) -const MPSDataTypeAlternateEncodingBit = UInt32(0x80000000) +export MPSMatrixDescriptor + +@objcwrapper MPSMatrixDescriptor <: NSObject # Mapping from Julia types to the Performance Shader bitfields -const jl_typ_to_mps = Dict{DataType,UInt32}( +const jl_typ_to_mps = Dict{DataType,MPSDataType}( UInt8 => UInt32(8), UInt16 => UInt32(16), UInt32 => UInt32(32), @@ -25,12 +49,25 @@ const jl_typ_to_mps = Dict{DataType,UInt32}( ComplexF32 => MPSDataTypeFloatBit | MPSDataTypeComplexBit | UInt32(32) ) -const MPTMatrix = Ptr{cmt.MtMPSMatrix} - -mutable struct MpsMatrix - handle::MPTMatrix +function MPSMatrixDescriptor(rows, columns, rowBytes, dataType) + desc = @objc [MPSMatrixDescriptor matrixDescriptorWithRows:rows::NSUInteger + columns:columns::NSUInteger + rowBytes:rowBytes::NSUInteger + dataType:jl_typ_to_mps[dataType]::MPSDataType]::id{MPSMatrixDescriptor} + obj = MPSMatrixDescriptor(desc) + # TODO: release? + return obj end + +# +# matrix object +# + +export MPSMatrix + +@objcwrapper MPSMatrix <: NSObject + """ MPSMatrix(arr::MtlMatrix) @@ -41,9 +78,64 @@ as Metal stores matrices row-major instead of column-major. """ function MPSMatrix(arr::MtlMatrix{T}) where T n_cols, n_rows = size(arr) - desc = cmt.mtNewMatrixDescriptorWithRows(n_rows, n_cols, sizeof(T)*n_cols, - jl_typ_to_mps[T]) - return cmt.mtNewMPSMatrixInitWithBuffer(arr.buffer, desc) + desc = MPSMatrixDescriptor(n_rows, n_cols, sizeof(T)*n_cols, T) + mat = @objc [MPSMatrix alloc]::id{MPSMatrix} + obj = MPSMatrix(mat) + # TODO: release? + @objc [obj::id{MPSMatrix} initWithBuffer:arr.buffer::id{MTLBuffer} + descriptor:desc::id{MPSMatrixDescriptor}]::id{MPSMatrix} + return obj +end + + +# +# kernels +# + +@objcwrapper MPSKernel <: NSObject + +@objcproperties MPSKernel begin + @autoproperty device::id{MTLDevice} + @autoproperty label::id{NSString} setter=setLabel + @autoproperty options::MPSKernelOptions setter=setOptions +end + + +# +# matrix multiplication +# + +@objcwrapper MPSMatrixMultiplication <: MPSKernel + +@objcproperties MPSMatrixMultiplication begin + @autoproperty leftMatrixOrigin::MTLOrigin setter=setLeftMatrixOrigin + @autoproperty rightMatrixOrigin::MTLOrigin setter=setRightMatrixOrigin + @autoproperty resultMatrixOrigin::MTLOrigin setter=setResultMatrixOrigin + @autoproperty batchSize::NSUInteger setter=setBatchSize + @autoproperty batchStart::NSUInteger setter=setBatchStart +end + +function MPSMatrixMultiplication(device, transposeLeft, transposeRight, resultRows, + resultColumns, interiorColumns, alpha, beta) + kernel = @objc [MPSMatrixMultiplication alloc]::id{MPSMatrixMultiplication} + obj = MPSMatrixMultiplication(kernel) + # TODO: release? + @objc [obj::id{MPSMatrixMultiplication} initWithDevice:device::id{MTLDevice} + transposeLeft:transposeLeft::Bool + transposeRight:transposeRight::Bool + resultRows:resultRows::NSUInteger + resultColumns:resultColumns::NSUInteger + interiorColumns:interiorColumns::NSUInteger + alpha:alpha::Cdouble + beta:beta::Cdouble]::id{MPSMatrixMultiplication} + return obj +end + +function encode!(cmdbuf::MTLCommandBuffer, matmul::MPSMatrixMultiplication, left, right, result) + @objc [matmul::id{MPSMatrixMultiplication} encodeToCommandBuffer:cmdbuf::id{MTLCommandBuffer} + leftMatrix:left::id{MPSMatrix} + rightMatrix:right::id{MPSMatrix} + resultMatrix:result::id{MPSMatrix}]::Nothing end """ @@ -66,15 +158,15 @@ function matmul!(c::MtlMatrix, a::MtlMatrix, b::MtlMatrix, mps_b = MPSMatrix(b) mps_c = MPSMatrix(c) - mat_mul_kernel = - cmt.mtNewMPSMatrixMultiplication(current_device(), - transpose_b, transpose_a, - rows_c, cols_c, cols_a, - alpha, beta) + mat_mul_kernel = MPSMatrixMultiplication(current_device(), + transpose_b, transpose_a, + rows_c, cols_c, cols_a, + alpha, beta) + # Encode and commit matmul kernel - cmdbuf = MtlCommandBuffer(global_queue(current_device())) - cmt.mtMPSMatMulEncodeToCommandBuffer(mat_mul_kernel, cmdbuf, mps_b, mps_a, mps_c) + cmdbuf = MTLCommandBuffer(global_queue(current_device())) + encode!(cmdbuf, mat_mul_kernel, mps_b, mps_a, mps_c) commit!(cmdbuf) c diff --git a/lib/mtl/MTL.jl b/lib/mtl/MTL.jl index 1510cbde..00bce0b2 100644 --- a/lib/mtl/MTL.jl +++ b/lib/mtl/MTL.jl @@ -1,6 +1,7 @@ module MTL -using ..cmt +using CEnum +using ObjectiveC, .Foundation, .Dispatch ## version information @@ -25,15 +26,10 @@ end ## source code includes -# low-level wrappers -include("error.jl") -include("helpers.jl") - -# high-level wrappers include("size.jl") -include("storage_type.jl") -include("resource.jl") include("device.jl") +include("resource.jl") +include("storage_type.jl") include("compile-opts.jl") include("library.jl") include("function.jl") @@ -44,11 +40,19 @@ include("buffer.jl") include("command_queue.jl") include("command_buf.jl") include("compute_pipeline.jl") -include("compute_pipeline/reflection.jl") include("command_enc.jl") include("command_enc/blit.jl") include("command_enc/compute.jl") include("binary_archive.jl") -include("profile.jl") +include("capture.jl") + +function __init__() + precompiling = ccall(:jl_generating_output, Cint, ()) != 0 + precompiling && return + + Sys.isapple() || return + + load_framework("CoreGraphics") +end end # module diff --git a/lib/mtl/binary_archive.jl b/lib/mtl/binary_archive.jl index 0d386f05..796ae5e4 100644 --- a/lib/mtl/binary_archive.jl +++ b/lib/mtl/binary_archive.jl @@ -2,144 +2,59 @@ # binary archive descriptor # -export MtlBinaryArchiveDescriptor +export MTLBinaryArchiveDescriptor -const MTLBinaryArchiveDescriptor = Ptr{MTL.MtBinaryArchiveDescriptor} +@objcwrapper immutable=false MTLBinaryArchiveDescriptor <: NSObject -mutable struct MtlBinaryArchiveDescriptor - handle::MTLBinaryArchiveDescriptor +@objcproperties MTLBinaryArchiveDescriptor begin + # Choosing an Archive File + @autoproperty url::id{NSURL} setter=setUrl end -Base.unsafe_convert(::Type{MTLBinaryArchiveDescriptor}, q::MtlBinaryArchiveDescriptor) = q.handle - -Base.:(==)(a::MtlBinaryArchiveDescriptor, b::MtlBinaryArchiveDescriptor) = a.handle == b.handle -Base.hash(lib::MtlBinaryArchiveDescriptor, h::UInt) = hash(lib.handle, h) - -function MtlBinaryArchiveDescriptor() - handle = mtNewBinaryArchiveDescriptor() - obj = MtlBinaryArchiveDescriptor(handle) - finalizer(unsafe_destroy!, obj) +function MTLBinaryArchiveDescriptor() + handle = @objc [MTLBinaryArchiveDescriptor new]::id{MTLBinaryArchiveDescriptor} + obj = MTLBinaryArchiveDescriptor(handle) + finalizer(release, obj) return obj end -function unsafe_destroy!(desc::MtlBinaryArchiveDescriptor) - mtRelease(desc.handle) -end - - -## properties - -Base.propertynames(::MtlBinaryArchiveDescriptor) = (:url,) - -function Base.getproperty(opts::MtlBinaryArchiveDescriptor, f::Symbol) - if f === :url - ptr = mtBinaryArchiveDescriptorURL(opts) - ptr == C_NULL ? nothing : unsafe_string(ptr) - else - getfield(opts, f) - end -end - -function Base.setproperty!(opts::MtlBinaryArchiveDescriptor, f::Symbol, val) - if f === :url - mtBinaryArchiveDescriptorURLSet(opts, val) - else - setfield!(opts, f, val) - end -end - - -## display - -function Base.show(io::IO, opts::MtlBinaryArchiveDescriptor) - print(io, "MtlBinaryArchiveDescriptor(…)") -end - -function Base.show(io::IO, ::MIME"text/plain", opts::MtlBinaryArchiveDescriptor) - println(io, "MtlBinaryArchiveDescriptor:") - println(io, " url: ", opts.url) -end - - # # binary archive # -export MtlBinaryArchive, add_functions! +export MTLBinaryArchive, add_functions! -const MTLBinaryArchive = Ptr{MTL.MtBinaryArchive} +@objcwrapper immutable=false MTLBinaryArchive <: NSObject -mutable struct MtlBinaryArchive - handle::MTLBinaryArchive - device::MtlDevice - desc::MtlBinaryArchiveDescriptor +@objcproperties MTLBinaryArchive begin + # Identifying the Archive + @autoproperty label::id{NSString} setter=setLabel + @autoproperty device::id{MTLDevice} end -Base.unsafe_convert(::Type{MTLBinaryArchive}, q::MtlBinaryArchive) = q.handle - -Base.:(==)(a::MtlBinaryArchive, b::MtlBinaryArchive) = a.handle == b.handle -Base.hash(lib::MtlBinaryArchive, h::UInt) = hash(lib.handle, h) +function MTLBinaryArchive(dev::MTLDevice, desc::MTLBinaryArchiveDescriptor) + err = Ref{id{NSError}}(nil) + handle = @objc [dev::id{MTLDevice} newBinaryArchiveWithDescriptor:desc::id{MTLBinaryArchiveDescriptor} + error:err::Ptr{id{NSError}}]::id{MTLBinaryArchive} + err[] == nil || throw(NSError(err[])) -function MtlBinaryArchive(device::MtlDevice, desc::MtlBinaryArchiveDescriptor) - handle = @mtlthrows _errptr mtNewBinaryArchiveWithDescriptor(device, desc, _errptr) - - obj = MtlBinaryArchive(handle, device, desc) - finalizer(unsafe_destroy!, obj) + obj = MTLBinaryArchive(handle) + finalizer(release, obj) return obj end -function unsafe_destroy!(archive::MtlBinaryArchive) - mtRelease(archive.handle) -end - - -## properties - -Base.propertynames(o::MtlBinaryArchive) = ( - # identification - :device, :label -) - -function Base.getproperty(o::MtlBinaryArchive, f::Symbol) - if f === :device - return MtlDevice(mtBinaryArchiveDevice(o)) - elseif f === :label - ptr = mtBinaryArchiveLabel(o) - ptr == C_NULL ? nothing : unsafe_string(ptr) - else - getfield(o, f) - end -end - -function Base.setproperty!(o::MtlBinaryArchive, f::Symbol, val) - if f === :label - mtBinaryArchiveLabelSet(o, val) - else - setfield!(opts, f, val) - end -end - - -## display - -function Base.show(io::IO, bin::MtlBinaryArchive) - print(io, "MtlBinaryArchive(…)") -end - -function Base.show(io::IO, ::MIME"text/plain", bin::MtlBinaryArchive) - println(io, "MtlBinaryArchive:") - println(io, " label: ", bin.label) - println(io, " device: ", bin.device) -end - - -## operations - -function add_functions!(bin::MtlBinaryArchive, desc::MtlComputePipelineDescriptor) - @mtlthrows _errptr mtBinaryArchiveAddComputePipelineFunctions(bin, desc, _errptr) +function add_functions!(bin::MTLBinaryArchive, desc::MTLComputePipelineDescriptor) + err = Ref{id{NSError}}(nil) + @objc [bin::id{MTLBinaryArchive} addComputePipelineFunctionsWithDescriptor:desc::id{MTLComputePipelineDescriptor} + error:err::Ptr{id{NSError}}]::Nothing + err[] == nil || throw(NSError(err[])) end -function Base.write(filename::String, bin::MtlBinaryArchive) - @mtlthrows _errptr mtBinaryArchiveSerialize(bin, filename, _errptr) +function Base.write(filename::String, bin::MTLBinaryArchive) + url = NSFileURL(filename) + err = Ref{id{NSError}}(nil) + @objc [bin::id{MTLBinaryArchive} serializeToURL:url::id{NSURL} + error:err::Ptr{id{NSError}}]::Nothing + err[] == nil || throw(NSError(err[])) end diff --git a/lib/mtl/buffer.jl b/lib/mtl/buffer.jl index 72ff3198..fba4e525 100644 --- a/lib/mtl/buffer.jl +++ b/lib/mtl/buffer.jl @@ -1,44 +1,21 @@ -export MtlBuffer, device, contents, alloc, free, handle - -const MTLBuffer = Ptr{MtBuffer} +export MTLBuffer, device, contents, alloc, free, handle # From docs: "MSL implements a buffer as a pointer to a built-in or user defined data type described in the # device, constant, or threadgroup address space. -struct MtlBuffer <: MtlResource - handle::MTLBuffer +@objcwrapper MTLBuffer <: MTLResource + +@objcproperties MTLBuffer begin + @autoproperty length::NSUInteger + @autoproperty device::id{MTLDevice} + @autoproperty contents::Ptr{Cvoid} + @autoproperty remoteStorageBuffer::id{MTLBuffer} + @autoproperty gpuAddress::UInt64 type=Ptr{Cvoid} end -Base.unsafe_convert(::Type{MTLBuffer}, buf::MtlBuffer) = buf.handle - -Base.:(==)(a::MtlBuffer, b::MtlBuffer) = a.handle == b.handle -Base.hash(buf::MtlBuffer, h::UInt) = hash(buf.handle, h) - +Base.sizeof(buf::MTLBuffer) = Int(buf.length) -## properties - -Base.propertynames(o::MtlBuffer) = ( - :length, - invoke(propertynames, Tuple{MtlResource}, o)... -) - -function Base.getproperty(o::MtlBuffer, f::Symbol) - if f === :length - mtBufferLength(o) - elseif f === :gpuAddress - # XXX: even though the gpuAddress property is only documented in Metal 3, - # it seems to be present in earlier versions of the API as well. - # can we rely on this? - Base.bitcast(Ptr{Nothing}, mtBufferGPUAddress(o)) - else - invoke(getproperty, Tuple{MtlResource, Symbol}, o, f) - end -end - -Base.sizeof(buf::MtlBuffer) = Int(buf.length) - -function contents(buf::MtlBuffer) - buf.handle == C_NULL && return C_NULL - ptr = Base.bitcast(Ptr{Cvoid}, mtBufferContents(buf)) +function contents(buf::MTLBuffer) + ptr = @objc [buf::id{MTLBuffer} contents]::Ptr{Cvoid} ptr == C_NULL && error("Cannot access the contents of a private buffer") return ptr end @@ -46,34 +23,43 @@ end ## allocation -alloc_buffer(dev::MtlDevice, bytesize, opts::MtlResourceOptions) = - mtDeviceNewBufferWithLength(dev, bytesize, opts) -alloc_buffer(dev::MtlHeap, bytesize, opts::MtlResourceOptions) = - mtHeapNewBufferWithLength(heap, bytesize, opts) -alloc_buffer(dev::MtlDevice, bytesize, opts::MtlResourceOptions, ptr::Ptr) = - mtDeviceNewBufferWithBytes(dev, ptr, bytesize, opts) -alloc_buffer(dev::MtlHeap, bytesize, opts::MtlResourceOptions, ptr::Ptr) = - mtHeapNewBufferWithBytes(heap, ptr, bytesize, opts) +# from device +alloc_buffer(dev::MTLDevice, bytesize, opts::MTLResourceOptions) = + @objc [dev::id{MTLDevice} newBufferWithLength:bytesize::NSUInteger + options:opts::MTLResourceOptions]::id{MTLBuffer} +alloc_buffer(dev::MTLDevice, bytesize, opts::MTLResourceOptions, ptr::Ptr) = + @objc [dev::id{MTLDevice} newBufferWithBytes:ptr::Ptr{Cvoid} + length:bytesize::NSUInteger + options:opts::MTLResourceOptions]::id{MTLBuffer} + +# from heap +alloc_buffer(dev::MTLHeap, bytesize, opts::MTLResourceOptions) = + @objc [dev::id{MTLHeap} newBufferWithLength:bytesize::NSUInteger + options:opts::MTLResourceOptions]::id{MTLBuffer} +alloc_buffer(dev::MTLHeap, bytesize, opts::MTLResourceOptions, ptr::Ptr) = + @objc [dev::id{MTLHeap} newBufferWithBytes:ptr::Ptr{Cvoid} + length:bytesize::NSUInteger + options:opts::MTLResourceOptions]::id{MTLBuffer} alloc_buffer(dev, bytesize, opts::Integer) = - alloc_buffer(dev, bytesize, Base.bitcast(MtlResourceOptions, UInt32(opts))) + alloc_buffer(dev, bytesize, MTLResourceOptions(opts)) alloc_buffer(dev, bytesize, opts::Integer, ptr) = - alloc_buffer(dev, bytesize, Base.bitcast(MtlResourceOptions, UInt32(opts)), ptr) + alloc_buffer(dev, bytesize, MTLResourceOptions(opts), ptr) -function MtlBuffer(dev::Union{MtlDevice,MtlHeap}, +function MTLBuffer(dev::Union{MTLDevice,MTLHeap}, bytesize::Integer; storage = Private, hazard_tracking = DefaultTracking, cache_mode = DefaultCPUCache) opts = storage | hazard_tracking | cache_mode - @assert 0 < bytesize <= dev.maxBufferLength # XXX: not supported by MtlHeap + @assert 0 < bytesize <= dev.maxBufferLength # XXX: not supported by MTLHeap ptr = alloc_buffer(dev, bytesize, opts) - return MtlBuffer(ptr) + return MTLBuffer(ptr) end -function MtlBuffer(dev::Union{MtlDevice,MtlHeap}, +function MTLBuffer(dev::Union{MTLDevice,MTLHeap}, bytesize::Integer, ptr::Ptr; storage = Managed, @@ -82,15 +68,15 @@ function MtlBuffer(dev::Union{MtlDevice,MtlHeap}, storage == Private && error("Can't create a Private copy-allocated buffer.") opts = storage | hazard_tracking | cache_mode - @assert 0 < bytesize <= dev.maxBufferLength # XXX: not supported by MtlHeap + @assert 0 < bytesize <= dev.maxBufferLength # XXX: not supported by MTLHeap ptr = alloc_buffer(dev, bytesize, opts, ptr) - return MtlBuffer(ptr) + return MTLBuffer(ptr) end """ alloc(device, bytesize, [ptr=nothing]; storage=Default, hazard_tracking=Default, chache_mode=Default) - MtlBuffer(device, bytesize...) + MTLBuffer(device, bytesize...) Allocates a Metal buffer on `device` of`bytesize` bytes. If a CPU-pointer is passed as last argument, then the buffer is initialized with the content of the memory starting at `ptr`, @@ -108,39 +94,24 @@ The storage kwarg controls where the buffer is stored. Possible values are: Note that `Private` buffers can't be directly accessed from the CPU, therefore you cannot use this option if you pass a ptr to initialize the memory. """ -alloc(args...; kwargs...) = MtlBuffer(args...; kwargs...) +alloc(args...; kwargs...) = MTLBuffer(args...; kwargs...) """ - free(buffer::MtlBuffer) + free(buffer::MTLBuffer) Frees the buffer if the handle is valid. This does not protect against double-freeing of the same buffer! """ -free(buf::MtlBuffer) = mtRelease(buf.handle) +free(buf::MTLBuffer) = @objc [buf::id{MTLBuffer} release]::Nothing """ - DidModifyRange!(buf::MtlBuffer, range::UnitRange) + DidModifyRange!(buf::MTLBuffer, range::UnitRange) Notifies the GPU that the range of bytes specified by `range` have been modified on the CPU, and that they should be transferred to the device before executing any following command. Only valid for `Managed` buffers. """ -function DidModifyRange!(buf::MtlBuffer, range::UnitRange) - mtBufferDidModifyRange(buf, range) +function DidModifyRange!(buf::MTLBuffer, range) + @objc [buf::id{MTLBuffer} didModifyRange:range::NSRange]::Nothing end - -# Views on different device -NewBuffer(buf::MtlBuffer, d::MtlDevice) = - mtBufferNewRemoteBufferViewForDevice(buf, d); - -function ParentBuffer(buf::MtlBuffer) - orig = mtBufferRemoteStorageBuffer(buf); - if orig == C_NULL - return nothing - else - return MtlBuffer(orig) - end -end - -handle_array(vec::Vector{<:MtlBuffer}) = [buf.handle for buf in vec] diff --git a/lib/mtl/capture.jl b/lib/mtl/capture.jl new file mode 100644 index 00000000..50eec880 --- /dev/null +++ b/lib/mtl/capture.jl @@ -0,0 +1,199 @@ +# +# 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 +# + +export MTLCaptureScope, beginScope, endScope + +""" + MTLCaptureScope(handle::MTLCaptureScope) +An object that defines custom boundaries for a GPU frame capture. + +Use [`beginScope()`](@ref) and [`endScope()`](@ref) to set the boundaries for a capture scope. +""" +MTLCaptureScope + +@objcwrapper MTLCaptureScope <: NSObject + +@objcproperties MTLCaptureScope begin + # Identifying the Capture Scope + @autoproperty label::id{NSString} setter=setLabel + @autoproperty device::id{MTLDevice} + @autoproperty commandQueue::id{MTLCommandQueue} +end + +""" + beginScope(scope::MTLCaptureScope) + +Begin recording GPU command information. +""" +function beginScope(scope::MTLCaptureScope) + @objc [scope::id{MTLCaptureScope} beginScope]::Nothing +end + +""" + endScope(scope::MTLCaptureScope) + +Stop recording GPU command information. +""" +function endScope(scope::MTLCaptureScope) + @objc [scope::id{MTLCaptureScope} endScope]::Nothing +end + + +# +# capture descriptor +# + +export MTLCaptureDescriptor + +""" + MTLCaptureDescriptor() + MTLCaptureDescriptor(obj::Union{MTLDevice,MTLCommandQueue}, + destination::MTLCaptureDestination; + folder::String=nothing) + +Create a GPU frame capture descriptor to alter the parameters of a profiling session. +""" +MTLCaptureDescriptor + +@objcwrapper immutable=false MTLCaptureDescriptor <: NSObject + +@objcproperties MTLCaptureDescriptor begin + # Identifying the Capture Scope + @autoproperty captureObject::id{NSObject} setter=setCaptureObject + @autoproperty destination::MTLCaptureDestination setter=setDestination + @autoproperty outputURL::id{NSURL} setter=setOutputURL +end + +function MTLCaptureDescriptor() + handle = @objc [MTLCaptureDescriptor new]::id{MTLCaptureDescriptor} + obj = MTLCaptureDescriptor(handle) + finalizer(release, obj) + return obj +end + +# TODO: Add capture state +function MTLCaptureDescriptor(obj::Union{MTLDevice,MTLCommandQueue, MTLCaptureScope}, + destination::MTLCaptureDestination; + folder::String=nothing) + desc = MTLCaptureDescriptor() + desc.destination = destination + desc.captureObject = obj + if folder != nothing + desc.outputURL = NSFileURL(folder) + end + return desc +end + + + +# +# capture manager +# + +export MTLCaptureManager, startCapture, stopCapture, supports_destination + +""" + struct MTLCaptureManager + +Metal-managed object that handles GPU frame capture support and usage. +Note: There is only one (shared) capture manager per process. +""" +MTLCaptureManager + +@objcwrapper MTLCaptureManager <: NSObject + +@objcproperties MTLCaptureManager begin + # Creating a Capture Scope + @autoproperty defaultCaptureScope::id{MTLCaptureScope} setter=setDefaultCaptureScope + + # Monitoring Capture + @autoproperty isCapturing::Bool +end + +""" + MTLCaptureManager() + +Return the unique shared GPU frame capture manager for this process. +""" +function MTLCaptureManager() + # Inexpensive dummy metal command to trigger GPU frame capture enable on Metal's end + # Without this, two separate capture managers are potentially handled + # One with capture enabled and one without + MTLDevice(1) + handle = @objc [MTLCaptureManager sharedCaptureManager]::id{MTLCaptureManager} + MTLCaptureManager(handle) +end + +""" + startCapture(obj::Union{MTLDevice,MTLCommandQueue}, + destination::MTLCaptureDestination=MTLCaptureDestinationGPUTraceDocument; + folder::String=nothing) + +Start GPU frame capture using the default capture object and specifying capture descriptor parameters directly. +""" +function startCapture(obj::Union{MTLDevice,MTLCommandQueue, MTLCaptureScope}, + destination::MTLCaptureDestination=MTLCaptureDestinationGPUTraceDocument; + folder::String=nothing) + if destination == MTLCaptureDestinationGPUTraceDocument && folder == nothing + throw(ArgumentError("Must specify output folder if destination is GPUTraceDocument")) + end + startCapture(MTLCaptureManager(), MTLCaptureDescriptor(obj, destination; folder=folder)) +end + +""" + startCapture(manager::MTLCaptureManager, desc::MTLCaptureDescriptor) + +Start a GPU frame capture session with the given capture manager and descriptor. +""" +function startCapture(manager::MTLCaptureManager, desc::MTLCaptureDescriptor) + # Check not already capturing + manager.isCapturing && throw(error("Capture manager is already capturing.")) + # Warn users if environment variable isn't set (required in most cases) + haskey(ENV, "METAL_CAPTURE_ENABLED") || + @warn """Environment variable 'METAL_CAPTURE_ENABLED' is not set. In most cases, this + will need to be set to 1 before launching Julia to enable GPU frame capture.""" + # Error if explicitly disallowed + haskey(ENV, "METAL_CAPTURE_ENABLED") && ENV["METAL_CAPTURE_ENABLED"] == 0 && + throw(error("Metal GPU frame capture explicitly disallowed via environment vairable.")) + + err = Ref{id{NSError}}(nil) + success = @objc [manager::id{MTLCaptureManager} startCaptureWithDescriptor:desc::id{MTLCaptureDescriptor} + error:err::Ptr{id{NSError}}]::Bool + success || throw(NSError(err[])) + return +end + +""" + stopCapture(manager::MTLCaptureManager=MTLCaptureManager()) +Stop GPU frame capture. +""" +function stopCapture(manager::MTLCaptureManager=MTLCaptureManager()) + @objc [manager::id{MTLCaptureManager} stopCapture]::Nothing +end + +function supports_destination(manager::MTLCaptureManager, destination::MTLCaptureDestination) + @objc [manager::id{MTLCaptureManager} supportsDestination:destination::MTLCaptureDestination]::Bool +end diff --git a/lib/mtl/command_buf.jl b/lib/mtl/command_buf.jl index 46a7752b..e15a9688 100644 --- a/lib/mtl/command_buf.jl +++ b/lib/mtl/command_buf.jl @@ -1,176 +1,95 @@ # -# command buffer descriptor +# commannd buffer enums # -export MtlCommandBufferDescriptor - -const MTLCommandBufferDescriptor = Ptr{MTL.MtCommandBufferDescriptor} - -mutable struct MtlCommandBufferDescriptor - handle::MTLCommandBufferDescriptor +@cenum MTLCommandBufferErrorOption::NSUInteger begin + MTLCommandBufferErrorOptionNone = 0 + MTLCommandBufferErrorOptionEncoderExecutionStatus = 1 end -Base.unsafe_convert(::Type{MTLCommandBufferDescriptor}, q::MtlCommandBufferDescriptor) = - q.handle - -function MtlCommandBufferDescriptor() - handle = mtNewCommandBufferDescriptor() - obj = MtlCommandBufferDescriptor(handle) - finalizer(unsafe_destroy!, obj) - return obj +@cenum MTLCommandBufferStatus::NSUInteger begin + MTLCommandBufferStatusNotEnqueued = 0 + MTLCommandBufferStatusEnqueued = 1 + MTLCommandBufferStatusCommitted = 2 + MTLCommandBufferStatusScheduled = 3 + MTLCommandBufferStatusCompleted = 4 + MTLCommandBufferStatusError = 5 end -function unsafe_destroy!(desc::MtlCommandBufferDescriptor) - mtRelease(desc.handle) -end +# +# command buffer descriptor +# -## properties - -Base.propertynames(::MtlCommandBufferDescriptor) = ( - :retainedReferences, :errorOptions -) +export MTLCommandBufferDescriptor -function Base.getproperty(o::MtlCommandBufferDescriptor, f::Symbol) - if f === :errorOptions - mtCommandBufferDescriptorErrorOptions(o) - elseif f === :retainedReferences - mtCommandBufferDescriptorRetainedReferences(o) - else - getfield(o, f) - end -end +@objcwrapper immutable=false MTLCommandBufferDescriptor <: NSObject -function Base.setproperty!(o::MtlCommandBufferDescriptor, f::Symbol, val) - if f === :errorOptions - mtCommandBufferDescriptorErrorOptionsSet(o, val) - elseif f === :retainedReferences - mtCommandBufferDescriptorRetainedReferencesSet(o, val) - else - setfield!(o, f, val) - end +@objcproperties MTLCommandBufferDescriptor begin + @autoproperty retainedReferences::Bool setter=setRetainedReferences + @autoproperty errorOptions::MTLCommandBufferErrorOption setter=setErrorOptions end - -## display - -function Base.show(io::IO, desc::MtlCommandBufferDescriptor) - print(io, "MtlCommandBufferDescriptor(...)") +function MTLCommandBufferDescriptor() + handle = @objc [MTLCommandBufferDescriptor new]::id{MTLCommandBufferDescriptor} + obj = MTLCommandBufferDescriptor(handle) + finalizer(release, obj) + return obj end -function show(io::IO, ::MIME"text/plain", q::MtlCommandBufferDescriptor) - println(io, "MtlCommandBufferDescriptor:") - println(io, " retainReferences: ", q.retainReferences) - print(io, " errorOption: ", q.errorOption) -end # # command buffer # -export MtlCommandBuffer, enqueue!, wait_scheduled, wait_completed, encode_signal!, +export MTLCommandBuffer, enqueue!, wait_scheduled, wait_completed, encode_signal!, encode_wait!, commit!, on_scheduled, on_completed -const MTLCommandBuffer = Ptr{MtCommandBuffer} +@objcwrapper immutable=false MTLCommandBuffer <: NSObject -""" - MtlCommandBuffer(queue::MtlCommandQueue, [desc::MtlCommandBufferDescriptor]) +@objcproperties MTLCommandBuffer begin + # Identifying the Command Buffer + @autoproperty commandQueue::id{MTLCommandQueue} + @autoproperty label::id{NSString} setter=setLabel + @autoproperty device::id{MTLDevice} + @autoproperty status::MTLCommandBufferStatus -A container that stores encoded commands for the GPU to execute. -""" -mutable struct MtlCommandBuffer - handle::MTLCommandBuffer - queue::MtlCommandQueue - desc::Union{Nothing, MtlCommandBufferDescriptor} -end + # Getting Error Details + @autoproperty error::id{NSError} + @autoproperty errorOptions::MTLCommandBufferErrorOption -Base.unsafe_convert(::Type{MTLCommandBuffer}, q::MtlCommandBuffer) = q.handle + # Reading the Runtime Message Logs + #@autoproperty logs::id{NSArray} type=Vector{MTLCommandBufferLogEntry} -Base.:(==)(a::MtlCommandBuffer, b::MtlCommandBuffer) = a.handle == b.handle -Base.hash(q::MtlCommandBuffer, h::UInt) = hash(q.handle, h) + # Checking Scheduling Times on the CPU + @autoproperty kernelStartTime::Cdouble + @autoproperty kernelEndTime::Cdouble -function MtlCommandBuffer(queue::MtlCommandQueue, - desc::MtlCommandBufferDescriptor=MtlCommandBufferDescriptor()) - handle = mtNewCommandBufferWithDescriptor(queue, desc) - obj = MtlCommandBuffer(handle, queue, desc) - finalizer(unsafe_destroy!, obj) - return obj -end + # Checking Execution Times on the GPU + @autoproperty GPUStartTime::Cdouble + @autoproperty GPUEndTime::Cdouble -function unsafe_destroy!(cmdbuf::MtlCommandBuffer) - mtRelease(cmdbuf.handle) + # Determining Whether to Maintain Strong References + @autoproperty retainedReferences::Bool end +function MTLCommandBuffer(queue::MTLCommandQueue, + desc::MTLCommandBufferDescriptor=MTLCommandBufferDescriptor()) + handle = @objc [queue::id{MTLCommandQueue} commandBufferWithDescriptor:desc::id{MTLCommandBufferDescriptor}]::id{MTLCommandBuffer} + obj = MTLCommandBuffer(handle) + finalizer(release, obj) -## properties - -Base.propertynames(::MtlCommandBuffer) = ( - :device, :commandQueue, :label, - :status, :errorOptions, :error, - #=:logs,=# - :kernelStartTime, :kernelEndTime, :gpuStartTime, :gpuEndTime, - :retainedReferences, :encoderInfo -) - -function Base.getproperty(o::MtlCommandBuffer, f::Symbol) - if f === :device - MtlDevice(mtCommandBufferDevice(o)) - elseif f === :commandQueue - MtlCommandQueue(mtCommandBufferCommandQueue(o), o.device) - elseif f === :label - ptr = mtCommandBufferLabel(o) - ptr == C_NULL ? nothing : unsafe_string(ptr) - elseif f === :status - mtCommandBufferStatus(o) - elseif f === :error - ptr = mtCommandBufferError(o) - ptr == C_NULL ? nothing : MtlError(ptr) - elseif f === :errorOptions - mtCommandBufferErrorOptions(o) - elseif f === :kernelStartTime - mtCommandBufferKernelStartTime(o) - elseif f === :kernelEndTime - mtCommandBufferKernelEndTime(o) - elseif f === :gpuStartTime - mtCommandBufferGPUStartTime(o) - elseif f === :gpuEndTime - mtCommandBufferGPUEndTime(o) - elseif f === :retainedReferences - mtCommandBufferRetainedReferences(o) - elseif f === :encoderInfo - mtCommandBufferEncoderInfo(o) - else - getfield(o, f) - end -end - -function Base.setproperty!(o::MtlCommandBuffer, f::Symbol, val) - if f === :label - mtCommandBufferLabelSet(o, val) - else - setfield!(o, f, val) - end -end - + # Per Apple's "Basic Memory Management Rules" the above invocation does not imply + # ownership. To be consistent the name of the function and CF_RETURNS_RETAINED, we + # explicitly claim ownership with an explicit `retain` + retain(obj) -## display - -function Base.show(io::IO, q::MtlCommandBuffer) - print(io, "MtlCommandBuffer(...)") -end - -function show(io::IO, ::MIME"text/plain", q::MtlCommandBuffer) - println(io, "MtlCommandBuffer:") - println(io, " queue: ", q.commandQueue) - print(io, " status: ", q.status) + return obj end - -## operations - """ - enqueue!(q::MtlCommandBuffer) + enqueue!(q::MTLCommandBuffer) Enqueueing a command buffer reserves a place for the command buffer on the command queue without committing the command buffer for execution. When this command buffer @@ -181,14 +100,16 @@ into the command buffers and those threads can complete in any order. [enqueue](https://developer.apple.com/documentation/metal/mtlcommandbuffer/1443019-enqueue?language=objc) """ -function enqueue!(q::MtlCommandBuffer) - q.status in [MtCommandBufferStatusCompleted, MtCommandBufferStatusEnqueued] && error("Cannot enqueue an already enqueued command buffer") - mtCommandBufferEnqueue(q) +function enqueue!(q::MTLCommandBuffer) + q.status in [MTLCommandBufferStatusCompleted, MTLCommandBufferStatusEnqueued] && + error("Cannot enqueue an already enqueued command buffer") + @objc [q::id{MTLCommandBuffer} enqueue]::Nothing end -function commit!(q::MtlCommandBuffer) - q.status in [MtCommandBufferStatusCompleted, MtCommandBufferStatusCommitted] && error("Cannot commit an already committed/completed command buffer") - mtCommandBufferCommit(q) +function commit!(q::MTLCommandBuffer) + q.status in [MTLCommandBufferStatusCompleted, MTLCommandBufferStatusCommitted] && + error("Cannot commit an already committed/completed command buffer") + @objc [q::id{MTLCommandBuffer} commit]::Nothing end """ @@ -200,20 +121,24 @@ blocks registered by addScheduledHandler: have been invoked. A command buffer is considered scheduled after all its dependencies are resolved, and it is sent to the GPU for execution. """ -wait_scheduled(q::MtlCommandBuffer) = mtCommandBufferWaitUntilScheduled(q) +function wait_scheduled(q::MTLCommandBuffer) + @objc [q::id{MTLCommandBuffer} waitUntilScheduled]::Nothing +end """ - wait_completed(cmdbuf::MtlCommandBuffer) + wait_completed(cmdbuf::MTLCommandBuffer) Blocks execution of the current thread until execution of the command buffer is completed. This method returns after the command buffer is completed and all code blocks registered by addCompletedHandler: are invoked. """ -wait_completed(q::MtlCommandBuffer) = mtCommandBufferWaitUntilCompleted(q) +function wait_completed(q::MTLCommandBuffer) + @objc [q::id{MTLCommandBuffer} waitUntilCompleted]::Nothing +end """ - encode_signal!(buf::MtlCommandBuffer, ev::MtlEvent, val::UInt) + encode_signal!(buf::MTLCommandBuffer, ev::MTLEvent, val::UInt) Encodes a command that signals the given event, updating it to a new value. @@ -225,11 +150,13 @@ waiting on the event are allowed to run if the new value is equal to or greater than the value for which they are waiting. For shared events, this update similarly triggers notification handlers waiting on the event. """ -encode_signal!(buf::MtlCommandBuffer, ev::MtlAbstractEvent, val::Integer) = - mtCommandBufferEncodeSignalEvent(buf, ev, val) +function encode_signal!(buf::MTLCommandBuffer, ev::MTLEvent, val::Integer) + @objc [buf::id{MTLCommandBuffer} encodeSignalEvent:ev::id{MTLEvent} + value:val::UInt64]::Nothing +end """ - encode_wait!(buf::MtlCommandBuffer, ev::MtlEvent, val::UInt) + encode_wait!(buf::MTLCommandBuffer, ev::MTLEvent, val::UInt) Encodes a command that blocks the execution of the command buffer until the given event reaches the given value. @@ -242,56 +169,63 @@ GPU executes commands that appear earlier than the wait command, but doesn't start any commands that appear after it. Execution continues immediately if the event already has an equal or larger value. """ -encode_wait!(buf::MtlCommandBuffer, ev::MtlAbstractEvent, val::Integer) = - mtCommandBufferEncodeWaitForEvent(buf, ev, val) +function encode_wait!(buf::MTLCommandBuffer, ev::MTLEvent, val::Integer) + @objc [buf::id{MTLCommandBuffer} encodeWaitForEvent:ev::id{MTLEvent} + value:val::UInt64]::Nothing +end -async_send(data::Ptr{Cvoid}) = ccall(:uv_async_send, Cint, (Ptr{Cvoid},), data) +if VERSION >= v"1.9-" -function _command_buffer_async_callback(handle, data) - # we don't care about the buffer (handle), the user can capture it if needed - ccall(:uv_async_send, Cint, (Ptr{Cvoid},), data) - return +# on 1.9, we can just have Metal call back into Julia regardless of the thread it's on. +# this means we can have Metal pass us the buffer, and don't need any additional capture. +function _command_buffer_callback(f, _) + # convert the incoming pointer, and discard any return value + function g(_buf) + f(_buf == nil ? nothing : MTLCommandBuffer(_buf)) + return + end + @objcblock(g, Nothing, (id{MTLCommandBuffer},)) end -function _command_buffer_callback(f::Base.Callable, buf::MtlCommandBuffer) +else + +# on 1.8 and earlier, we cannot have Metal call into Julia because it may happen from an +# unmanaged thread. instead, we use uv_async_send to notify the libuv event loop, but +# that doesn't take any arguments so we have to capture the buffer in the callback. +# we also cannot return any values, but that isn't needed for these handlers. +function _command_buffer_callback(f, buf) cond = Base.AsyncCondition() do async_cond - f() + f(buf) close(async_cond) end + @objcasyncblock(cond) +end - # the condition object is embedded in a task, so the Julia scheduler keeps it alive - - # callback = @cfunction(async_send, Cint, (Ptr{Cvoid},)) - # See https://github.com/JuliaGPU/CUDA.jl/issues/1314. - # and https://github.com/JuliaLang/julia/issues/43748 - # TL;DR We are not allowed to cache `async_send` in the sysimage - # so instead let's just pull out the function pointer and pass it instead. - callback = cglobal(:uv_async_send) - - return callback, cond end """ - on_scheduled(buf::MtlCommandBuffer) do buf + on_scheduled(buf::MTLCommandBuffer) do buf ... + return end Execute a block of code when execution of the command buffer is scheduled. """ -function on_scheduled(f::Base.Callable, buf::MtlCommandBuffer) - handler, data = _command_buffer_callback(f, buf) - MTL.mtCommandBufferOnScheduled(buf, data, handler) +function on_scheduled(f::Base.Callable, buf::MTLCommandBuffer) + block = _command_buffer_callback(f, buf) + @objc [buf::id{MTLCommandBuffer} addScheduledHandler:block::id{NSBlock}]::Nothing end """ - on_completed(buf::MtlCommandBuffer) do buf + on_completed(buf::MTLCommandBuffer) do buf ... + return end Execute a block of code when execution of the command buffer is completed. """ -function on_completed(f::Base.Callable, buf::MtlCommandBuffer) - handler, data = _command_buffer_callback(f, buf) - MTL.mtCommandBufferOnCompleted(buf, data, handler) +function on_completed(f::Base.Callable, buf::MTLCommandBuffer) + block = _command_buffer_callback(f, buf) + @objc [buf::id{MTLCommandBuffer} addCompletedHandler:block::id{NSBlock}]::Nothing end diff --git a/lib/mtl/command_enc.jl b/lib/mtl/command_enc.jl index e199899a..d117c89f 100644 --- a/lib/mtl/command_enc.jl +++ b/lib/mtl/command_enc.jl @@ -1,40 +1,11 @@ export endEncoding! -abstract type MtlCommandEncoder end +@objcwrapper MTLCommandEncoder <: NSObject -Base.:(==)(a::T, b::T) where {T <: MtlCommandEncoder} = a.handle == b.handle -Base.hash(q::MtlCommandEncoder, h::UInt) = hash(q.handle, h) - -function unsafe_destroy!(cce::MtlCommandEncoder) - mtRelease(cce.handle) -end - - -## properties - -Base.propertynames(::MtlCommandEncoder) = (:device, :label) - -function Base.getproperty(o::MtlCommandEncoder, f::Symbol) - if f === :device - MtlDevice(mtCommandEncoderDevice(o)) - elseif f === :label - ptr = mtCommandEncoderLabel(o) - ptr == C_NULL ? nothing : unsafe_string(ptr) - else - getfield(o, f) - end -end - -function Base.setproperty!(o::MtlCommandEncoder, f::Symbol, val) - if f === :label - mtCommandEncoderLabelSet(o, val) - else - setfield!(o, f, val) - end +@objcproperties MTLCommandEncoder begin + @autoproperty device::id{MTLDevice} + @autoproperty label::id{NSString} setter=setLabel end - -## encoding - -endEncoding!(ce::MtlCommandEncoder) = mtCommandEncoderEndEncoding(ce.handle) -Base.close(ce::MtlCommandEncoder) = endEncoding!(ce) +endEncoding!(ce::MTLCommandEncoder) = @objc [ce::id{MTLCommandEncoder} endEncoding]::Nothing +Base.close(ce::MTLCommandEncoder) = endEncoding!(ce) diff --git a/lib/mtl/command_enc/blit.jl b/lib/mtl/command_enc/blit.jl index cd5c1780..91a84ffe 100644 --- a/lib/mtl/command_enc/blit.jl +++ b/lib/mtl/command_enc/blit.jl @@ -1,24 +1,23 @@ -export MtlBlitCommandEncoder, append_copy!, append_fillbuffer!, append_sync! +export MTLBlitCommandEncoder, append_copy!, append_fillbuffer!, append_sync! -const MTLBlitCommandEncoder = Ptr{MtBlitCommandEncoder} +@objcwrapper immutable=false MTLBlitCommandEncoder <: MTLCommandEncoder -mutable struct MtlBlitCommandEncoder <: MtlCommandEncoder - handle::MTLBlitCommandEncoder - cmdbuf::MtlCommandBuffer -end +function MTLBlitCommandEncoder(cmdbuf::MTLCommandBuffer) + handle = @objc [cmdbuf::id{MTLCommandBuffer} blitCommandEncoder]::id{MTLBlitCommandEncoder} + obj = MTLBlitCommandEncoder(handle) + finalizer(release, obj) -Base.unsafe_convert(::Type{MTLBlitCommandEncoder}, e::MtlBlitCommandEncoder) = e.handle + # Per Apple's "Basic Memory Management Rules" the above invocation does not imply + # ownership. To be consistent the name of the function and CF_RETURNS_RETAINED, we + # explicitly claim ownership with an explicit `retain` + retain(obj) -function MtlBlitCommandEncoder(cmdbuf::MtlCommandBuffer) - handle = mtNewBlitCommandEncoder(cmdbuf) - obj = MtlBlitCommandEncoder(handle, cmdbuf) - finalizer(unsafe_destroy!, obj) return obj end ## encode in the Command Encoder -function MtlBlitCommandEncoder(f::Base.Callable, cmdbuf::MtlCommandBuffer) - encoder = MtlBlitCommandEncoder(cmdbuf) +function MTLBlitCommandEncoder(f::Base.Callable, cmdbuf::MTLCommandBuffer) + encoder = MTLBlitCommandEncoder(cmdbuf) f(encoder) close(encoder) return encoder @@ -26,13 +25,24 @@ end ## # Copy from device to device -append_copy!(enc::MtlBlitCommandEncoder, dst::MtlBuffer, doff, src::MtlBuffer, soff, len) = - mtBlitCommandEncoderCopyFromBufferToBuffer(enc, src, soff, dst, doff, len) +function append_copy!(enc::MTLBlitCommandEncoder, dst::MTLBuffer, doff, + src::MTLBuffer, soff, len) + @objc [enc::id{MTLBlitCommandEncoder} copyFromBuffer:src::id{MTLBuffer} + sourceOffset:soff::Csize_t + toBuffer:dst::id{MTLBuffer} + destinationOffset:doff::Csize_t + size:len::Csize_t]::Nothing +end -append_fillbuffer!(enc::MtlBlitCommandEncoder, src::MtlBuffer, - val::Union{Int8, UInt8}, bytesize, offset=0) = - mtBlitCommandEncoderFillBuffer(enc, src, UnitRange(offset:bytesize-1), val) +function append_fillbuffer!(enc::MTLBlitCommandEncoder, src::MTLBuffer, + val::Union{Int8, UInt8}, bytesize, offset=0) + range = NSRange(offset, bytesize) + @objc [enc::id{MTLBlitCommandEncoder} fillBuffer:src::id{MTLBuffer} + range:range::NSRange + value:val::UInt8]::Nothing +end # only for managed resources -append_sync!(enc::MtlBlitCommandEncoder, src::MtlBuffer) = - mtBlitCommandencoderSynchronizeResource!(enc, src) +function append_sync!(enc::MTLBlitCommandEncoder, src::MTLBuffer) + @objc [enc::id{MTLBlitCommandEncoder} synchronizeResource:src::id{MTLBuffer}]::Nothing +end diff --git a/lib/mtl/command_enc/compute.jl b/lib/mtl/command_enc/compute.jl index 1712c2b1..5487aa2b 100644 --- a/lib/mtl/command_enc/compute.jl +++ b/lib/mtl/command_enc/compute.jl @@ -1,53 +1,53 @@ -export MtlComputeCommandEncoder +export MTLComputeCommandEncoder export set_function!, set_buffer!, set_bytes!, dispatchThreads!, endEncoding! export set_buffers!, append_current_function! -const MTLComputeCommandEncoder = Ptr{MtComputeCommandEncoder} - -mutable struct MtlComputeCommandEncoder <: MtlCommandEncoder - handle::MTLComputeCommandEncoder - cmdbuf::MtlCommandBuffer +@cenum MTLDispatchType::NSUInteger begin + MTLDispatchTypeSerial = 0 + MTLDispatchTypeConcurrent = 1 end -Base.unsafe_convert(::Type{MTLComputeCommandEncoder}, q::MtlComputeCommandEncoder) = q.handle +@objcwrapper immutable=false MTLComputeCommandEncoder <: MTLCommandEncoder -function MtlComputeCommandEncoder(cmdbuf::MtlCommandBuffer; dispatch_type::Union{Nothing,MtDispatchType} = nothing) - if isnothing(dispatch_type) - handle = mtNewComputeCommandEncoder(cmdbuf) +function MTLComputeCommandEncoder(cmdbuf::MTLCommandBuffer; + dispatch_type::Union{Nothing,MTLDispatchType} = nothing) + handle = if isnothing(dispatch_type) + @objc [cmdbuf::id{MTLCommandBuffer} computeCommandEncoder]::id{MTLComputeCommandEncoder} else - handle = mtNewComputeCommandEncoderWithDispatchtype(cmdbuf, dispatchtype) + @objc [cmdbuf::id{MTLCommandBuffer} computeCommandEncoderWithDispatchType:dispatch_type::MTLDispatchType]::id{MTLComputeCommandEncoder} end - obj = MtlComputeCommandEncoder(handle, cmdbuf) - finalizer(unsafe_destroy!, obj) - return obj -end -device(cce::MtlComputeCommandEncoder) = cce.cmdbuf.device + obj = MTLComputeCommandEncoder(handle) + finalizer(release, obj) -set_function!(cce::MtlComputeCommandEncoder, pip::MtlComputePipelineState) = - mtComputeCommandEncoderSetComputePipelineState(cce, pip) + # Per Apple's "Basic Memory Management Rules" the above invocation does not imply + # ownership. To be consistent the name of the function and CF_RETURNS_RETAINED, we + # explicitly claim ownership with an explicit `retain` + retain(obj) -set_buffer!(cce::MtlComputeCommandEncoder, buf::MtlBuffer, offset::Integer, index::Integer) = - mtComputeCommandEncoderSetBufferOffsetAtIndex(cce, buf, offset, index - 1) -#set_bufferoffset!(cce::MtlComputeCommandEncoder, offset::Integer, index::Integer) = -# mtComputeCommandEncoderBufferSetOffsetAtIndex(cce, offset, index) -set_buffers!(cce::MtlComputeCommandEncoder, bufs::Vector{T}, - offsets::Vector{Int}, indices::UnitRange{Int}) where {T<:MtlBuffer} = - mtComputeCommandEncoderSetBuffersOffsetsWithRange(cce, handle_array(bufs), offsets, indices .- 1) -#=set_buffers!(cce::MtlComputeCommandEncoder, bufs::Vector{MtlPtr{T}}, - offsets::Vector{Int}, indices::UnitRange{Int}) where {T} = - mtComputeCommandEncoderSetBuffersOffsetsWithRange(cce, bufs, offsets, indices .- 1)=# + return obj +end + +function set_function!(cce::MTLComputeCommandEncoder, pip::MTLComputePipelineState) + @objc [cce::id{MTLComputeCommandEncoder} setComputePipelineState:pip::id{MTLComputePipelineState}]::Nothing +end -set_bytes!(cce::MtlComputeCommandEncoder, ptr, length::Integer, index::Integer) = - mtComputeCommandEncoderSetBytesLengthAtIndex(cce, ptr, length, index - 1) +function set_buffer!(cce::MTLComputeCommandEncoder, buf::MTLBuffer, offset, index) + @objc [cce::id{MTLComputeCommandEncoder} setBuffer:buf::id{MTLBuffer} + offset:offset::NSUInteger + atIndex:(index-1)::NSUInteger]::Nothing +end -dispatchThreadgroups!(cce::MtlComputeCommandEncoder, gridSize::MtSize, threadGroupSize::MtSize) = - mtComputeCommandEncoderDispatchThreadgroups_threadsPerThreadgroup(cce, gridSize, threadGroupSize) +function dispatchThreadgroups!(cce::MTLComputeCommandEncoder, gridSize, threadGroupSize) + @objc [cce::id{MTLComputeCommandEncoder} dispatchThreadgroups:gridSize::MTLSize + threadsPerThreadgroup:threadGroupSize::MTLSize]::Nothing +end ##### # encode in the Command Encoder -function MtlComputeCommandEncoder(f::Base.Callable, cmdbuf::MtlCommandBuffer; kwargs...) - encoder = MtlComputeCommandEncoder(cmdbuf; kwargs...) + +function MTLComputeCommandEncoder(f::Base.Callable, cmdbuf::MTLCommandBuffer; kwargs...) + encoder = MTLComputeCommandEncoder(cmdbuf; kwargs...) try f(encoder) finally @@ -55,12 +55,19 @@ function MtlComputeCommandEncoder(f::Base.Callable, cmdbuf::MtlCommandBuffer; kw end end -append_current_function!(cce::MtlComputeCommandEncoder, gridSize::MtSize, threadGroupSize::MtSize) = +function append_current_function!(cce::MTLComputeCommandEncoder, gridSize, threadGroupSize) dispatchThreadgroups!(cce, gridSize, threadGroupSize) +end #### use -use!(cce::MtlComputeCommandEncoder, buf::MtlBuffer, mode::MtResourceUsage=ReadWriteUsage) = - mtComputeCommandEncoderUseResourceUsage(cce, buf, mode) -use!(cce::MtlComputeCommandEncoder, buf::Vector{MtlBuffer}, mode::MtResourceUsage=ReadWriteUsage) = - mtComputeCommandEncoderUseResourceCountUsage(cce, handle_array(buf), length(buf), mode) +function use!(cce::MTLComputeCommandEncoder, buf::MTLBuffer, mode::MTLResourceUsage=ReadWriteUsage) + @objc [cce::id{MTLComputeCommandEncoder} useResource:buf::id{MTLBuffer} + usage:mode::MTLResourceUsage]::Nothing +end + +function use!(cce::MTLComputeCommandEncoder, buf::Vector{MTLBuffer}, mode::MTLResourceUsage=ReadWriteUsage) + @objc [cce::id{MTLComputeCommandEncoder} useResources:buf::id{MTLBuffer} + count:length(buf)::Csize_t + usage:mode::MTLResourceUsage]::Nothing +end diff --git a/lib/mtl/command_queue.jl b/lib/mtl/command_queue.jl index 958036ba..ed41bd85 100644 --- a/lib/mtl/command_queue.jl +++ b/lib/mtl/command_queue.jl @@ -1,67 +1,15 @@ -export MtlCommandQueue +export MTLCommandQueue -const MTLCommandQueue = Ptr{MtCommandQueue} +@objcwrapper immutable=false MTLCommandQueue <: NSObject -""" - MtlCommandQueue(dev::MtlDevice) - -A queue that organizes command buffers to be executed by the GPU `MtlDevice`. - -A MTLCommandQueue object is used to queue an ordered list of command buffers for a -MTLDevice to execute. Command queues are thread-safe and allow multiple outstanding -command buffers to be encoded simultaneously. - -[Metal Docs](https://developer.apple.com/documentation/metal/mtlcommandqueue?language=objc) -""" -mutable struct MtlCommandQueue - handle::MTLCommandQueue - device::MtlDevice +@objcproperties MTLCommandQueue begin + @autoproperty device::id{MTLDevice} + @autoproperty label::id{NSString} setter=setLabel end -Base.unsafe_convert(::Type{MTLCommandQueue}, q::MtlCommandQueue) = q.handle - -Base.:(==)(a::MtlCommandQueue, b::MtlCommandQueue) = a.handle == b.handle -Base.hash(q::MtlCommandQueue, h::UInt) = hash(q.handle, h) - -function MtlCommandQueue(dev::MtlDevice) - queue = mtNewCommandQueue(dev) - obj = MtlCommandQueue(queue, dev) - finalizer(unsafe_destroy!, obj) +function MTLCommandQueue(dev::MTLDevice) + handle = @objc [dev::id{MTLDevice} newCommandQueue]::id{MTLCommandQueue} + obj = MTLCommandQueue(handle) + finalizer(release, obj) return obj end - -function unsafe_destroy!(queue::MtlCommandQueue) - mtRelease(queue.handle) -end - - -## properties - -Base.propertynames(::MtlCommandQueue) = (:device, :label) - -function Base.getproperty(o::MtlCommandQueue, f::Symbol) - if f === :device - MtlDevice(mtCommandQueueDevice(o)) - elseif f === :label - ptr = mtCommandQueueLabel(o) - ptr == C_NULL ? nothing : unsafe_string(ptr) - else - getfield(o, f) - end -end - -function Base.setproperty!(o::MtlCommandQueue, f::Symbol, val) - if f === :label - mtCommandQueueLabelSet(o, val) - else - setfield!(o, f, val) - end -end - - -## display - -function show(io::IO, ::MIME"text/plain", q::MtlCommandQueue) - println(io, "MtlCommandQueue:") - print(io, " device: ", q.device) -end diff --git a/lib/mtl/compile-opts.jl b/lib/mtl/compile-opts.jl index 237935ae..43e278b5 100644 --- a/lib/mtl/compile-opts.jl +++ b/lib/mtl/compile-opts.jl @@ -1,82 +1,61 @@ -export MtlCompileOptions - -const MTLCompileOptions = Ptr{MtCompileOptions} - -mutable struct MtlCompileOptions - handle::MTLCompileOptions -end - -Base.unsafe_convert(::Type{MTLCompileOptions}, opts::MtlCompileOptions) = opts.handle - -Base.:(==)(a::MtlCompileOptions, b::MtlCompileOptions) = a.handle == b.handle -Base.hash(opts::MtlCompileOptions, h::UInt) = hash(opts.handle, h) - -function MtlCompileOptions() - handle = mtNewCompileOpts() - obj = MtlCompileOptions(handle) - finalizer(unsafe_destroy!, obj) - return obj -end - -function unsafe_destroy!(opts::MtlCompileOptions) - mtRelease(opts.handle) +# +# enums +# + +@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 end - -## properties - -Base.propertynames(::MtlCompileOptions) = (:fastMathEnabled, :languageVersion) - const language_versions = Dict( - MtLanguageVersion1_0 => v"1.0", - MtLanguageVersion1_1 => v"1.1", - MtLanguageVersion1_2 => v"1.2", - MtLanguageVersion2_0 => v"2.0", - MtLanguageVersion2_1 => v"2.1", - MtLanguageVersion2_2 => v"2.2", - MtLanguageVersion2_3 => v"2.3", - MtLanguageVersion2_4 => v"2.4", + MTLLanguageVersion1_0 => v"1.0", + MTLLanguageVersion1_1 => v"1.1", + MTLLanguageVersion1_2 => v"1.2", + MTLLanguageVersion2_0 => v"2.0", + MTLLanguageVersion2_1 => v"2.1", + MTLLanguageVersion2_2 => v"2.2", + MTLLanguageVersion2_3 => v"2.3", + MTLLanguageVersion2_4 => v"2.4", + MTLLanguageVersion3_0 => v"3.0", ) -function Base.getproperty(opts::MtlCompileOptions, f::Symbol) - if f === :fastMathEnabled - mtCompileOptsFastMath(opts) - elseif f === :languageVersion - ver = mtCompileOptsLanguageVersion(opts) - haskey(language_versions, ver) || error("Unknown language version $ver; please file an issue.") - language_versions[ver] - else - getfield(opts, f) - end +function Base.convert(::Type{VersionNumber}, ver::MTLLanguageVersion) + haskey(language_versions, ver) || error("Unknown language version $ver; please file an issue.") + language_versions[ver] end -function Base.setproperty!(opts::MtlCompileOptions, f::Symbol, val) - if f === :fastMathEnabled - mtCompileOptsFastMathSet(opts, val) - elseif f === :languageVersion - isa(val, VersionNumber) || - throw(ArgumentError("languageVersion property should be a version number")) - for (enum,ver) in language_versions - if ver === val - mtCompileOptsLanguageVersionSet(opts, enum) - return - end - end - error("Unknown language version $val") - else - setfield!(opts, f, val) +function Base.convert(::Type{MTLLanguageVersion}, ver::VersionNumber) + for (k, v) in language_versions + v == ver && return k end + error("Unknown language version $ver; please file an issue.") end -## display +# +# compile options +# + +export MTLCompileOptions -function Base.show(io::IO, opts::MtlCompileOptions) - print(io, "CompileOptions(…)") +@objcwrapper immutable=false MTLCompileOptions <: NSObject + +@objcproperties MTLCompileOptions begin + @autoproperty fastMathEnabled::Bool setter=setFastMathEnabled + @autoproperty preserveInvariance::Bool setter=setPreserveInvariance + @autoproperty languageVersion::MTLLanguageVersion type=VersionNumber setter=setLanguageVersion end -function Base.show(io::IO, ::MIME"text/plain", opts::MtlCompileOptions) - println(io, "CompileOptions:") - println(io, " fast math: ", opts.fastMathEnabled) - print(io, " language version: ", opts.languageVersion) +function MTLCompileOptions() + handle = @objc [MTLCompileOptions new]::id{MTLCompileOptions} + obj = MTLCompileOptions(handle) + finalizer(release, obj) + return obj end diff --git a/lib/mtl/compute_pipeline.jl b/lib/mtl/compute_pipeline.jl index cfdd5e2f..737227a4 100644 --- a/lib/mtl/compute_pipeline.jl +++ b/lib/mtl/compute_pipeline.jl @@ -2,89 +2,32 @@ # compute pipeline descriptor # -export MtlComputePipelineDescriptor +export MTLComputePipelineDescriptor -const MTLComputePipelineDescriptor = Ptr{MtComputePipelineDescriptor} +@objcwrapper immutable=false MTLComputePipelineDescriptor <: NSObject -mutable struct MtlComputePipelineDescriptor - handle::MTLComputePipelineDescriptor -end - -Base.unsafe_convert(::Type{MTLComputePipelineDescriptor}, q::MtlComputePipelineDescriptor) = q.handle - -Base.:(==)(a::MtlComputePipelineDescriptor, b::MtlComputePipelineDescriptor) = a.handle == b.handle -Base.hash(lib::MtlComputePipelineDescriptor, h::UInt) = hash(lib.handle, h) - -function MtlComputePipelineDescriptor() - handle = mtNewComputePipelineDescriptor() - obj = MtlComputePipelineDescriptor(handle) - finalizer(unsafe_destroy!, obj) +function MTLComputePipelineDescriptor() + handle = @objc [MTLComputePipelineDescriptor new]::id{MTLComputePipelineDescriptor} + obj = MTLComputePipelineDescriptor(handle) + finalizer(release, obj) return obj end -function unsafe_destroy!(desc::MtlComputePipelineDescriptor) - mtRelease(desc.handle) -end - ## properties -Base.propertynames(::MtlComputePipelineDescriptor) = ( - :label, :computeFunction, :threadGroupSizeIsMultipleOfExecutionWidth, - :maxTotalThreads, :maxCallStackDepth, :supportIndirectCommandBuffers -) - -function Base.getproperty(o::MtlComputePipelineDescriptor, f::Symbol) - if f === :label - ptr = mtComputePipelineDescriptorLabel(o) - ptr == C_NULL ? nothing : unsafe_string(ptr) - elseif f === :computeFunction - ptr = mtComputePipelineDescriptorComputeFunction(o) - ptr == C_NULL ? nothing : MtlFunction(ptr) - elseif f === :threadGroupSizeIsMultipleOfThreadExecutionWidth - mtComputePipelineDescriptorThreadGroupSizeIsMultipleOfThreadExecutionWidth(o) - elseif f === :maxTotalThreadsPerThreadgroup - mtComputePipelineDescriptorMaxTotalThreadsPerThreadgroup(o) - elseif f === :maxCallStackDepth - mtComputePipelineDescriptorMaxCallStackDepth(o) - elseif f === :supportIndirectCommandBuffers - mtComputePipelineDescriptorSupportIndirectCommandBuffers(o) - else - getfield(o, f) - end -end - -function Base.setproperty!(o::MtlComputePipelineDescriptor, f::Symbol, val) - if f === :label - mtComputePipelineDescriptorLabelSet(o, val) - elseif f === :computeFunction - mtComputePipelineDescriptorComputeFunctionSet(o, val) - elseif f === :threadGroupSizeIsMultipleOfThreadExecutionWidth - mtComputePipelineDescriptorThreadGroupSizeIsMultipleOfThreadExecutionWidthSet(o, val) - elseif f === :maxTotalThreadsPerThreadgroup - mtComputePipelineDescriptorMaxTotalThreadsPerThreadgroupSet(o, val) - elseif f === :maxCallStackDepth - mtComputePipelineDescriptorMaxCallStackDepthSet(o, val) - else - setfield!(opts, f, val) - end -end - +@objcproperties MTLComputePipelineDescriptor begin + # Specifying the Compute Function and Associated Data + @autoproperty computeFunction::id{MTLFunction} setter=setComputeFunction + @autoproperty threadGroupSizeIsMultipleOfThreadExecutionWidth::Bool setter=setThreadGroupSizeIsMultipleOfThreadExecutionWidth + @autoproperty maxTotalThreadsPerThreadgroup::NSUInteger setter=setMaxTotalThreadsPerThreadgroup + @autoproperty maxCallStackDepth::NSUInteger setter=setMaxCallStackDepth -## display + # Identifying the Pipeline State Object + @autoproperty label::id{NSString} setter=setLabel -function Base.show(io::IO, bin::MtlComputePipelineDescriptor) - print(io, "MtlComputePipelineDescriptor(…)") -end - -function Base.show(io::IO, ::MIME"text/plain", q::MtlComputePipelineDescriptor) - println(io, "MtlComputePipelineDescriptor:") - println(io, " label: ", q.label) - println(io, " computeFunction: ", q.computeFunction) - println(io, " threadGroupSizeIsMultipleOfThreadExecutionWidth: ", q.threadGroupSizeIsMultipleOfThreadExecutionWidth) - println(io, " maxTotalThreadsPerThreadgroup: ", q.maxTotalThreadsPerThreadgroup) - println(io, " maxCallStackDepth: ", q.maxCallStackDepth) - println(io, " supportIndirectCommandBuffers: ", q.supportIndirectCommandBuffers) + # Setting Indirect Command Buffer Support + @autoproperty supportIndirectCommandBuffers::Bool end @@ -92,64 +35,33 @@ end # compute pipeline state # -export MtlComputePipelineState - -const MTLComputePipelineState = Ptr{MtComputePipelineState} +export MTLComputePipelineState -""" - MtlComputePipelineState(d::MtlDevice, f::MtlFunction) - -Create an object that stores information about the execution parameters of a MtlFunction. -""" -mutable struct MtlComputePipelineState - handle::MTLComputePipelineState - device::MtlDevice -end +@objcwrapper immutable=false MTLComputePipelineState <: NSObject -Base.unsafe_convert(::Type{MTLComputePipelineState}, q::MtlComputePipelineState) = q.handle +@objcproperties MTLComputePipelineState begin + # Identifying Properties + @autoproperty device::id{MTLDevice} + @autoproperty label::id{NSString} setter=setLabel -Base.:(==)(a::MtlComputePipelineState, b::MtlComputePipelineState) = a.handle == b.handle -Base.hash(q::MtlComputePipelineState, h::UInt) = hash(q.handle, h) + # Querying Threadgroup Attributes + @autoproperty maxTotalThreadsPerThreadgroup::NSUInteger + @autoproperty threadExecutionWidth::NSUInteger + @autoproperty staticThreadgroupMemoryLength::NSUInteger -function unsafe_destroy!(cce::MtlComputePipelineState) - mtRelease(cce.handle) + # Querying Indirect Command Buffer Support + @autoproperty supportIndirectCommandBuffers::Bool end -function MtlComputePipelineState(d::MtlDevice, f::MtlFunction) - handle = @mtlthrows _errptr mtNewComputePipelineStateWithFunction(d, f, _errptr) +function MTLComputePipelineState(dev::MTLDevice, fun::MTLFunction) + err = Ref{id{NSError}}(nil) + handle = @objc [dev::id{MTLDevice} newComputePipelineStateWithFunction:fun::id{MTLFunction} + error:err::Ptr{id{NSError}}]::id{MTLComputePipelineState} + err[] == nil || throw(NSError(err[])) - obj = MtlComputePipelineState(handle, d) - finalizer(unsafe_destroy!, obj) + obj = MTLComputePipelineState(handle) + finalizer(release, obj) return obj end -# TODO: MtlComputePipelineState(d::MtlDevice, desc::MtlComputePipelineDescriptor, ...) - - -## properties - -Base.propertynames(o::MtlComputePipelineState) = ( - # identification - :device, :label, - # threadgroup attributes - :maxTotalThreadsPerThreadgroup, :threadExecutionWidth, :staticThreadgroupMemoryLength, - #other - #=supportIndirectCommandBuffers=# -) - -function Base.getproperty(o::MtlComputePipelineState, f::Symbol) - if f === :device - return MtlDevice(mtComputePipelineDevice(o)) - elseif f === :label - ptr = mtComputePipelineLabel(o) - ptr == C_NULL ? nothing : unsafe_string(ptr) - elseif f === :maxTotalThreadsPerThreadgroup - return Int(mtComputePipelineMaxTotalThreadsPerThreadgroup(o)) - elseif f === :threadExecutionWidth - return Int(mtComputePipelineThreadExecutionWidth(o)) - elseif f === :staticThreadgroupMemoryLength - return Int(mtComputePipelineStaticThreadgroupMemoryLength(o)) - else - getfield(o, f) - end -end +# TODO: MTLComputePipelineState(d::MTLDevice, desc::MTLComputePipelineDescriptor, ...) diff --git a/lib/mtl/compute_pipeline/reflection.jl b/lib/mtl/compute_pipeline/reflection.jl deleted file mode 100644 index 68e70cc6..00000000 --- a/lib/mtl/compute_pipeline/reflection.jl +++ /dev/null @@ -1,29 +0,0 @@ -export MtlComputePipelineReflection - -const MTLComputePipelineReflection = Ptr{MtComputePipelineReflection} - -mutable struct MtlComputePipelineReflection - handle::MTLComputePipelineReflection - - "Get a handle to a kernel function in a Metal Library." - function MtlComputePipelineReflection(handle) - obj = new(handle) - finalizer(unsafe_destroy!, obj) - return obj - end -end - -function unsafe_destroy!(fun::MtlComputePipelineReflection) - mtRelease(fun.handle) -end - -Base.unsafe_convert(::Type{MTLComputePipelineReflection}, fun::MtlComputePipelineReflection) = fun.handle - -Base.:(==)(a::MtlComputePipelineReflection, b::MtlComputePipelineReflection) = a.handle == b.handle -Base.hash(fun::MtlComputePipelineReflection, h::UInt) = hash(mod.handle, h) - -function arguments(refl::MtlComputePipelineReflection) - args = mtComputePipelinereflectionArguments(refl) - - -end diff --git a/lib/mtl/device.jl b/lib/mtl/device.jl index 05d92f4d..8c6bc87e 100644 --- a/lib/mtl/device.jl +++ b/lib/mtl/device.jl @@ -1,15 +1,73 @@ -export MtlDevice, devices +# +# device enums +# -const MTLDevice = Ptr{MtDevice} - -struct MtlDevice - handle::MTLDevice +@enum MTLArgumentBuffersTier::NSUInteger begin + MTLArgumentBuffersTier1 = 0 + MTLArgumentBuffersTier2 = 1 end -Base.unsafe_convert(::Type{MTLDevice}, dev::MtlDevice) = dev.handle -Base.:(==)(a::MtlDevice, b::MtlDevice) = a.handle == b.handle -Base.hash(dev::MtlDevice, h::UInt) = hash(dev.handle, h) +# +# device +# + +export MTLDevice, devices + +@objcwrapper MTLDevice <: NSObject + +@objcproperties MTLDevice begin + ## device inspection + # compute support + @autoproperty maxThreadgroupMemoryLength::NSUInteger + @autoproperty maxThreadsPerThreadgroup::MTLSize + # render support + @autoproperty supportsRaytracing::Bool + @autoproperty supportsPrimitiveMotionBlur::Bool + @autoproperty supportsRaytracingFromRender::Bool + @autoproperty supports32BitMSAA::Bool + @autoproperty supportsPullModelInterpolation::Bool + @autoproperty supportsShaderBarycentricCoordinates::Bool + @autoproperty programmableSamplePositionsSupported::Bool + @autoproperty rasterOrderGroupsSupported::Bool + # texture and sampler support + @autoproperty supports32BitFloatFiltering::Bool + @autoproperty supportsBCTextureCompression::Bool + @autoproperty depth24Stencil8PixelFormatSupported::Bool + @autoproperty supportsQueryTextureLOD::Bool + #@autoproperty readWriteTextureSupport::MTLReadWriteTextureTier + # function pointer support + @autoproperty supportsFunctionPointers::Bool + @autoproperty supportsFunctionPointersFromRender::Bool + # memory + @autoproperty currentAllocatedSize::UInt64 + @autoproperty recommendedMaxWorkingSetSize::NSUInteger + @autoproperty hasUnifiedMemory::Bool + @autoproperty maxTransferRate::NSUInteger + # counters + #@autoproperty counterSets::MTLCounterSet + # identifying + @autoproperty name::id{NSString} + @autoproperty registryID::UInt64 + #@autoproperty location::MTLDeviceLocation + @autoproperty locationNumber::UInt64 + @autoproperty isLowPower::Bool + @autoproperty isRemovable::Bool + @autoproperty isHeadless::Bool + @autoproperty peerGroupID::UInt64 + @autoproperty peerCount::UInt64 + @autoproperty peerIndex::UInt64 + + ## resource creation + # creating buffers + @autoproperty maxBufferLength::NSUInteger + # creating argument buffer encoders + @autoproperty argumentBuffersSupport::MTLArgumentBuffersTier + @autoproperty maxArgumentBufferSamplerCount::NSUInteger +end + +MTLCreateSystemDefaultDevice() = + MTLDevice(ccall(:MTLCreateSystemDefaultDevice, id{MTLDevice}, ())) """ devices() @@ -17,90 +75,13 @@ Base.hash(dev::MtlDevice, h::UInt) = hash(dev.handle, h) Get an iterator for the compute devices. """ function devices() - count = Ref{Csize_t}(0) - mtCopyAllDevices(count, C_NULL) - handles = Vector{Ptr{MtDevice}}(undef, count[]) - mtCopyAllDevices(count, handles) - MtlDevice.(handles) + list = NSArray(ccall(:MTLCopyAllDevices, id{NSArray}, ())) + [reinterpret(MTLDevice, dev) for dev in list] end """ - MtlDevice(i::Integer) + MTLDevice(i::Integer) Get a handle to a compute device. """ -MtlDevice(i::Integer) = devices()[i] - - -## properties - -Base.propertynames(::MtlDevice) = ( - # GPU properties - :recommendedMaxWorkingSetSize, - :hasUnifiedMemory, - :maxTransferRate, - :name, - :isHeadless, - :isLowPower, - :isRemovable, - :registryID, - # threadgroup limits - :maxThreadgroupMemoryLength, - :maxThreadsPerThreadgroup, - # argument buffers - :argumentBuffersSupport, - # buffers - :maxBufferLength, - # gpu memory - :currentAllocatedSize, -) - -function Base.getproperty(dev::MtlDevice, f::Symbol) - if f === :recommendedMaxWorkingSetSize - mtDeviceRecommendedMaxWorkingSetSize(dev) - elseif f === :hasUnifiedMemory - mtDeviceHasUnifiedMemory(dev) - elseif f === :maxTransferRate - mtDeviceMaxTransferRate(dev) - elseif f === :name - unsafe_string(mtDeviceName(dev)) - elseif f === :isHeadless - mtDeviceLowPower(dev) - elseif f === :isLowPower - mtDeviceHeadless(dev) - elseif f === :isRemovable - mtDeviceRemovable(dev) - elseif f === :registryID - mtDeviceRegistryID(dev) - elseif f === :maxThreadgroupMemoryLength - mtDeviceMaxThreadgroupMemoryLength(dev) - elseif f === :maxThreadsPerThreadgroup - mtMaxThreadsPerThreadgroup(dev) - elseif f === :argumentBuffersSupport - mtDeviceArgumentBuffersSupport(dev) - elseif f === :maxBufferLength - mtDeviceMaxBufferLength(dev) - elseif f === :currentAllocatedSize - mtDeviceCurrentAllocatedSize(dev) - else - getfield(dev, f) - end -end - - -## display - -function Base.show(io::IO, dev::MtlDevice) - print(io, "MtlDevice($(dev.name))") -end - -function Base.show(io::IO, ::MIME"text/plain", dev::MtlDevice) - println(io, "MtlDevice:") - println(io, " name: ", dev.name) - println(io, " lowpower: ", dev.isLowPower) - println(io, " headless: ", dev.isHeadless) - println(io, " removable: ", dev.isRemovable) - println(io, " unified memory: ", dev.hasUnifiedMemory) - println(io, " registry id: ", dev.registryID) - print(io, " transfer rate: ", dev.maxTransferRate) -end +MTLDevice(i::Integer) = devices()[i] diff --git a/lib/mtl/error.jl b/lib/mtl/error.jl deleted file mode 100644 index 48c03dc8..00000000 --- a/lib/mtl/error.jl +++ /dev/null @@ -1,87 +0,0 @@ -export MtlError - -const MTLError = Ptr{NsError} - -mutable struct MtlError <: Exception - code::NsInteger - domain::String - userinfo::String - - ptr::MTLError -end - -Base.unsafe_convert(::Type{MTLError}, err::MtlError) = err.ptr - -function MtlError(err::MTLError) - code = mtErrorCode(err) - domain = mtErrorDomain(err) |> unsafe_string - userinfo = mtErrorUserInfo(err) |> unsafe_string - - obj = MtlError(code, domain, userinfo, err) - finalizer(unsafe_destroy!, obj) - return obj -end - -function unsafe_destroy!(err::MtlError) - mtRelease(err.ptr) -end - - -## properties - -Base.propertynames(::MtlError) = ( - # error properties - :code, :domain, :userInfo, - # localized error descriptions - :localizedDescription, :localizedRecoveryOptions, - :localizedRecoverySuggestion, :localizedFailureReason) - -function Base.getproperty(o::MtlError, f::Symbol) - if f === :code - mtErrorCode(o) - elseif f === :domain - unsafe_string(mtErrorDomain(o)) - elseif f === :userinfo - ptr = mtErrorUserInfo(o) - if ptr == C_NULL - Dict{String,Any}() - else - unsafe_string(ptr) - end - elseif f === :localizedDescription - unsafe_string(mtErrorLocalizedDescription(o)) - elseif f === :localizedRecoveryOptions - count = Ref{Csize_t}(0) - mtErrorLocalizedRecoveryOptions(o, count, C_NULL) - options = Vector{String}(undef, count[]) - mtErrorLocalizedRecoveryOptions(o, count, options) - unsafe_string.(options) - elseif f === :localizedRecoverySuggestion - ptr = mtErrorLocalizedRecoverySuggestion(o) - ptr == C_NULL ? nothing : unsafe_string(ptr) - elseif f === :localizedFailureReason - ptr = mtErrorLocalizedFailureReason(o) - ptr == C_NULL ? nothing : unsafe_string(ptr) - else - getfield(o, f) - end -end - - -## display - -function Base.showerror(io::IO, err::MtlError) - print(io, "MtlError: $(err.localizedDescription) (code $(err.code), $(err.domain))") - - if err.localizedFailureReason !== nothing - print(io, "\nFailure reason: $(err.localizedFailureReason)") - end - - recovery_options = err.localizedRecoveryOptions - if !isempty(recovery_options) - print(io, "\nRecovery Options:") - for option in recovery_options - print(io, "\n - $(option)") - end - end -end diff --git a/lib/mtl/events.jl b/lib/mtl/events.jl index fd7617cf..7be5e03c 100644 --- a/lib/mtl/events.jl +++ b/lib/mtl/events.jl @@ -1,89 +1,42 @@ -export MtlEvent, MtlSharedEvent, MtlSharedEventHandle +# +# event +# -abstract type MtlAbstractEvent end +export MTLEvent -const MTLEvent = Ptr{MtEvent} -const MTLSharedEvent = Ptr{MtSharedEvent} -const MTLSharedEventHandle = Ptr{MtSharedEventHandle} +@objcwrapper MTLEvent <: NSObject -mutable struct MtlEvent <: MtlAbstractEvent - handle::MTLEvent - device::MtlDevice +@objcproperties MTLEvent begin + @autoproperty device::id{MTLDevice} + @autoproperty label::id{NSString} setter=setLabel end -mutable struct MtlSharedEvent <: MtlAbstractEvent - handle::MTLSharedEvent - device::MtlDevice +function MTLEvent(dev::MTLDevice) + MTLEvent(@objc [dev::id{MTLDevice} newEvent]::id{MTLEvent}) end -Base.unsafe_convert(::Type{MTLEvent}, ev::MtlAbstractEvent) = convert(MTLEvent, ev.handle) -Base.unsafe_convert(::Type{MTLSharedEvent}, ev::MtlSharedEvent) = ev.handle -Base.:(==)(a::MtlAbstractEvent, b::MtlAbstractEvent) = a.handle == b.handle -Base.hash(ev::MtlAbstractEvent, h::UInt) = hash(ev.handle, h) - -function unsafe_destroy!(fun::MtlAbstractEvent) - mtRelease(fun.handle) -end - -function MtlEvent(dev::MtlDevice) - handle = mtDeviceNewEvent(dev) - obj = MtlEvent(handle, dev) - finalizer(unsafe_destroy!, obj) - return obj -end - -function MtlSharedEvent(dev::MtlDevice) - handle = mtDeviceNewSharedEvent(dev) - obj = MtlSharedEvent(handle, dev) - finalizer(unsafe_destroy!, obj) - return obj -end +# +# shared event +# +export MTLSharedEvent, MTLSharedEventHandle -## properties +@objcwrapper MTLSharedEvent <: MTLEvent -Base.propertynames(::MtlAbstractEvent) = (:device, :label, :signaledValue) - -function Base.getproperty(ev::MtlAbstractEvent, f::Symbol) - if f === :label - ptr = mtEventLabel(ev) - ptr == C_NULL ? nothing : unsafe_string(ptr) - elseif ev isa MtlSharedEvent && f === :signaledValue - mtSharedEventSignaledValue(ev) - else - getfield(ev, f) - end +@objcproperties MTLSharedEvent begin + @autoproperty signaledValue::UInt64 end -function Base.setproperty!(ev::MtlAbstractEvent, f::Symbol, val) - if f === :label - mtEventLabelSet(ev, val) - else - setfield!(ev, f, val) - end +function MTLSharedEvent(dev::MTLDevice) + MTLSharedEvent(@objc [dev::id{MTLDevice} newSharedEvent]::id{MTLSharedEvent}) end ## shared event handle -mutable struct MtlSharedEventHandle - handle::MTLSharedEventHandle - event::MtlSharedEvent -end - -function MtlSharedEventHandle(ev::MtlSharedEvent) - handle = mtSharedEventNewHandle(ev) - obj = MtlSharedEventHandle(handle, ev) - finalizer(unsafe_destroy!, obj) - return obj -end +@objcwrapper MTLSharedEventHandle <: NSObject -function unsafe_destroy!(evh::MtlSharedEventHandle) - mtRelease(evh.handle) +function MTLSharedEventHandle(ev::MTLSharedEvent) + MTLSharedEventHandle(@objc [ev::id{MTLSharedEvent} newSharedEventHandle]::id{MTLSharedEventHandle}) end - -Base.unsafe_convert(::Type{MTLSharedEventHandle}, evh::MtlSharedEventHandle) = evh.handle - -Base.:(==)(a::MtlSharedEventHandle, b::MtlSharedEventHandle) = a.handle == b.handle -Base.hash(evh::MtlSharedEventHandle, h::UInt) = hash(evh.handle, h) diff --git a/lib/mtl/fences.jl b/lib/mtl/fences.jl index 9f4d5e22..9466abf9 100644 --- a/lib/mtl/fences.jl +++ b/lib/mtl/fences.jl @@ -1,24 +1,12 @@ -export MtlFence +export MTLFence -const MTLFence = Ptr{MtFence} +@objcwrapper MTLFence <: NSObject -mutable struct MtlFence - handle::MTLFence - device::MtlDevice +@objcproperties MTLFence begin + @autoproperty device::id{MTLDevice} + @autoproperty label::id{NSString} end -Base.unsafe_convert(::Type{MTLFence}, fen::MtlFence) = fen.handle - -Base.:(==)(a::MtlFence, b::MtlFence) = a.handle == b.handle -Base.hash(ev::MtlFence, h::UInt) = hash(ev.handle, h) - -function MtlFence(dev::MtlDevice) - handle = mtDeviceNewFence(dev) - obj = MtlFence(handle, dev) - finalizer(unsafe_destroy!, obj) - return obj -end - -function unsafe_destroy!(fen::MtlFence) - mtRelease(fen.handle) +function MTLFence(dev::MTLDevice) + MTLFence(@objc [dev::id{MTLDevice} newFence]::id{MTLFence}) end diff --git a/lib/mtl/function.jl b/lib/mtl/function.jl index 211899a9..c6c657bb 100644 --- a/lib/mtl/function.jl +++ b/lib/mtl/function.jl @@ -1,69 +1,32 @@ # -# function descriptor +# function enums # -export MtlFunctionDescriptor - -const MTLFunctionDescriptor = Ptr{MtFunctionDescriptor} - -mutable struct MtlFunctionDescriptor - handle::MTLFunctionDescriptor -end - -Base.unsafe_convert(::Type{MTLFunctionDescriptor}, q::MtlFunctionDescriptor) = q.handle - -Base.:(==)(a::MtlFunctionDescriptor, b::MtlFunctionDescriptor) = a.handle == b.handle -Base.hash(lib::MtlFunctionDescriptor, h::UInt) = hash(lib.handle, h) - -function MtlFunctionDescriptor() - handle = mtNewFunctionDescriptor() - obj = MtlFunctionDescriptor(handle) - finalizer(unsafe_destroy!, obj) - return obj -end - -function unsafe_destroy!(desc::MtlFunctionDescriptor) - mtRelease(desc.handle) +@cenum MTLFunctionType::NSUInteger begin + MTLFunctionTypeVertex = 1 + MTLFunctionTypeFragment = 2 + MTLFunctionTypeKernel = 3 end -## properties - -Base.propertynames(::MtlFunctionDescriptor) = (:name, :specializedName) - -function Base.getproperty(desc::MtlFunctionDescriptor, f::Symbol) - if f === :name - ptr = mtFunctionDescriptorName(desc) - ptr == C_NULL ? nothing : unsafe_string(ptr) - elseif f === :specializedName - ptr = mtFunctionDescriptorSpecializedName(desc) - ptr == C_NULL ? nothing : unsafe_string(ptr) - else - getfield(desc, f) - end -end - -function Base.setproperty!(desc::MtlFunctionDescriptor, f::Symbol, val) - if f === :name - mtFunctionDescriptorNameSet(desc, val) - elseif f === :specializedName - mtFunctionDescriptorSpecializedNameSet(desc, val) - else - setfield!(desc, f, val) - end -end +# +# function descriptor +# +export MTLFunctionDescriptor -## display +@objcwrapper immutable=false MTLFunctionDescriptor <: NSObject -function Base.show(io::IO, ::MIME"text/plain", desc::MtlFunctionDescriptor) - println(io, "MtlFunctionDescriptor:") - println(io, " name: ", desc.name) - println(io, " specializedName: ", desc.specializedName) +@objcproperties MTLFunctionDescriptor begin + @autoproperty name::id{NSString} setter=setName + @autoproperty specializedName::id{NSString} setter=setSpecializedName end -function Base.show(io::IO, desc::MtlFunctionDescriptor) - print(io, "MtlFunctionDescriptor(...)") +function MTLFunctionDescriptor() + handle = @objc [MTLFunctionDescriptor new]::id{MTLFunctionDescriptor} + obj = MTLFunctionDescriptor(handle) + finalizer(release, obj) + return obj end @@ -72,76 +35,22 @@ end # function # -export MtlFunction +export MTLFunction -const MTLFunction = Ptr{MtFunction} +@objcwrapper immutable=false MTLFunction <: NSObject -mutable struct MtlFunction - handle::MTLFunction - - # roots (can be nothing if the function was created directly from a handle) - lib::Union{Nothing,MtlLibrary} - - MtlFunction(handle::MTLFunction, lib=nothing) = new(handle, lib) +@objcproperties MTLFunction begin + @autoproperty device::id{MTLDevice} + @autoproperty label::id{NSString} setter=setLabel + @autoproperty name::id{NSString} + @autoproperty functionType::MTLFunctionType end -function unsafe_destroy!(fun::MtlFunction) - mtRelease(fun.handle) -end - -Base.unsafe_convert(::Type{MTLFunction}, fun::MtlFunction) = fun.handle - -Base.:(==)(a::MtlFunction, b::MtlFunction) = a.handle == b.handle -Base.hash(fun::MtlFunction, h::UInt) = hash(mod.handle, h) - # Get a handle to a kernel function in a Metal Library. -function MtlFunction(lib::MtlLibrary, name::String) - handle = mtNewFunctionWithName(lib, name) - handle == C_NULL && throw(KeyError(name)) - obj = MtlFunction(handle, lib) - finalizer(unsafe_destroy!, obj) +function MTLFunction(lib::MTLLibrary, name::String) + handle = @objc [lib::id{MTLLibrary} newFunctionWithName:name::id{NSString}]::id{MTLFunction} + handle == nil && throw(KeyError(name)) + obj = MTLFunction(handle) + finalizer(release, obj) return obj end - - -## properties - -Base.propertynames(::MtlFunction) = (:device, :label, :name, :functionType) - -function Base.getproperty(fun::MtlFunction, f::Symbol) - if f === :device - MtlDevice(mtFunctionDevice(fun)) - elseif f === :label - ptr = mtFunctionLabel(fun) - ptr == C_NULL ? nothing : unsafe_string(ptr) - elseif f === :name - unsafe_string(mtFunctionName(fun)) - elseif f === :functionType - mtFunctionType(fun) - else - getfield(fun, f) - end -end - -function Base.setproperty!(fun::MtlFunction, f::Symbol, val) - if f === :label - mtFunctionLabelSet(fun, val) - else - setfield!(fun, f, val) - end -end - - -## display - -function Base.show(io::IO, ::MIME"text/plain", fun::MtlFunction) - println(io, "MtlFunction:") - println(io, " name: ", fun.name) - println(io, " type: ", fun.functionType) - println(io, " device: ", fun.device) - print(io, " label: ", fun.label) -end - -function Base.show(io::IO, fun::MtlFunction) - print(io, "MtlFunction($(fun.name))") -end diff --git a/lib/mtl/heap.jl b/lib/mtl/heap.jl index 2bcb6889..a6e39181 100644 --- a/lib/mtl/heap.jl +++ b/lib/mtl/heap.jl @@ -1,156 +1,67 @@ -export MtlHeapDescriptor, MtlHeap +# +# heap enums +# -const MTLHeapDescriptor = Ptr{MtHeapDescriptor} - -mutable struct MtlHeapDescriptor - handle::MTLHeapDescriptor -end - -function MtlHeapDescriptor() - handle = mtNewHeapDescriptor() - obj = MtlHeapDescriptor(handle) - finalizer(unsafe_destroy!, obj) - return obj +@cenum MTLHeapType::NSUInteger begin + MTLHeapTypeAutomatic = 0 + MTLHeapTypePlacement = 1 end -function unsafe_destroy!(desc::MtlHeapDescriptor) - mtRelease(desc.handle) -end - -Base.unsafe_convert(::Type{MTLHeapDescriptor}, d::MtlHeapDescriptor) = d.handle - -Base.:(==)(a::MtlHeapDescriptor, b::MtlHeapDescriptor) = a.handle == b.handle -Base.hash(dev::MtlHeapDescriptor, h::UInt) = hash(dev.handle, h) +# +# heap descriptor +# -## properties +export MTLHeapDescriptor -Base.propertynames(::MtlHeapDescriptor) = - (:type, :storageMode, :cpuCacheMode, :hazardTrackingMode, :resourceOptions, :size) +@objcwrapper immutable=false MTLHeapDescriptor <: NSObject -function Base.getproperty(o::MtlHeapDescriptor, f::Symbol) - if f === :type - mtHeapDescriptorType(o) - elseif f === :storageMode - mtHeapDescriptorStorageMode(o) - elseif f === :cpuCacheMode - mtHeapDescriptorCPUCacheMode(o) - elseif f === :hazardTrackingMode - mtHeapDescriptorHazardTrackingMode(o) - elseif f === :resourceOptions - mtHeapDescriptorResourceOptions(o) - elseif f === :size - mtHeapDescriptorSize(o) - else - getfield(o, f) - end +@objcproperties MTLHeapDescriptor begin + # Configuring a Heap + @autoproperty type::MTLHeapType setter=setType + @autoproperty storageMode::MTLStorageMode setter=setStorageMode + @autoproperty cpuCacheMode::MTLCPUCacheMode setter=setCpuCacheMode + @autoproperty hazardTrackingMode::MTLHazardTrackingMode setter=setHazardTrackingMode + @autoproperty resourceOptions::MTLResourceOptions setter=setResourceOptions + @autoproperty size::NSUInteger setter=setSize end -function Base.setproperty!(o::MtlHeapDescriptor, f::Symbol, val) - if f === :type - mtHeapDescriptorTypeSet(o, val) - elseif f === :storageMode - mtHeapDescriptorStorageModeSet(o, val) - elseif f === :cpuCacheMode - mtHeapDescriptorCpuCacheModeSet(o, val) - elseif f === :hazardTrackingMode - mtHeapDescriptorHazardTrackingModeSet(o, val) - elseif f === :resourceOptions - mtHeapDescriptorResourceOptionsSet(o, val) - elseif f === :size - mtHeapDescriptorSizeSet(o, val) - else - setfield!(o, f, val) - end +function MTLHeapDescriptor() + handle = @objc [MTLHeapDescriptor new]::id{MTLHeapDescriptor} + obj = MTLHeapDescriptor(handle) + finalizer(release, obj) + return obj end -## display - -function Base.show(io::IO, ::MIME"text/plain", o::MtlHeapDescriptor) - print(io, "MtlHeapDescriptor: ") - for f = propertynames(o) - print(io, "\n $f : $(getproperty(o, f))") - end -end +# +# heap +# +export MTLHeap -############################################################################### +@objcwrapper immutable=false MTLHeap <: NSObject -const MTLHeap = Ptr{MtHeap} +@objcproperties MTLHeap begin + # Identifying the Heap + @autoproperty device::id{MTLDevice} + @autoproperty label::id{NSString} setter=setLabel -mutable struct MtlHeap - handle::MTLHeap - device::MtlDevice + # Querying Heap Properties + @autoproperty type::MTLHeapType + @autoproperty storageMode::MTLStorageMode + @autoproperty cpuCacheMode::MTLCPUCacheMode + @autoproperty hazardTrackingMode::MTLHazardTrackingMode + @autoproperty resourceOptions::MTLResourceOptions + @autoproperty size::NSUInteger + @autoproperty usedSize::NSUInteger + @autoproperty currentAllocatedSize::NSUInteger end -Base.unsafe_convert(::Type{MTLHeap}, d::MtlHeap) = d.handle - -Base.:(==)(a::MtlHeap, b::MtlHeap) = a.handle == b.handle -Base.hash(dev::MtlHeap, h::UInt) = hash(dev.handle, h) - -function MtlHeap(device::MtlDevice, desc::MtlHeapDescriptor) - handle = mtDeviceNewHeapWithDescriptor(device, desc) - obj = MtlHeap(handle, device) - finalizer(unsafe_destroy!, obj) +function MTLHeap(dev::MTLDevice, desc::MTLHeapDescriptor) + handle = @objc [dev::id{MTLDevice} newHeapWithDescriptor:desc::id{MTLHeapDescriptor}]::id{MTLHeap} + obj = MTLHeap(handle) + finalizer(release, obj) return obj end - -function unsafe_destroy!(desc::MtlHeap) - mtRelease(desc.handle) -end - - -## properties - -Base.propertynames(::MtlHeap) = - (:device, :label, :type, :storageMode, :cpuCacheMode, :hazardTrackingMode, - :resourceOptions, :size, :usedSize, :currentAllocatedSize, :maxAvailableSizeWithAlignment) - -function Base.getproperty(o::MtlHeap, f::Symbol) - if f === :device - mtHeapDevice(heap) - elseif f === :label - ptr = mtHeapLabel(o) - ptr == C_NULL ? nothing : unsafe_string(ptr) - elseif f === :type - mtHeapType(o) - elseif f === :storageMode - mtHeapStorageMode(o) - elseif f === :cpuCacheMode - mtHeapCPUCacheMode(o) - elseif f === :hazardTrackingMode - mtHeapHazardTrackingMode(o) - elseif f === :resourceOptions - mtHeapResourceOptions(o) - elseif f === :size - mtHeapSize(o) - elseif f === :usedSize - mtHeapUsedSize(o) - elseif f === :currentAllocatedSize - mtHeapCurrentAllocatedSize(o) - elseif f === :maxAvailableSizeWithAlignment - maxAvailableSizeWithAlignment(o) - else - getfield(o, f) - end -end - -function Base.setproperty!(o::MtlHeap, f::Symbol, val) - if f === :label - mtHeapLabelSet(o, val) - else - setfield!(o, f, val) - end -end - - -## display - -function Base.show(io::IO, ::MIME"text/plain", o::MtlHeap) - print(io, "MtlHeap: ") - for f = propertynames(o) - print(io, "\n $f : $(getproperty(o, f))") - end -end diff --git a/lib/mtl/helpers.jl b/lib/mtl/helpers.jl deleted file mode 100644 index 117b71ce..00000000 --- a/lib/mtl/helpers.jl +++ /dev/null @@ -1,73 +0,0 @@ -function unsafe_string_maybe(ptr::Cstring) - if ptr == C_NULL - return "" - else - return unsafe_string(ptr) - end -end - -function NsError_maybe(ptr::MtlError) - if ptr === C_NULL - return nothing - else - return MtlError(ptr) - end -end - - -## redeclare enum values without a prefix - -# this is useful when enum values from an underlying C library, typically prefixed for the -# lack of namespacing in C, are to be used in Julia where we do have module namespacing. -macro enum_without_prefix(enum, prefix) - if isa(enum, Symbol) - mod = __module__ - elseif Meta.isexpr(enum, :(.)) - mod = getfield(__module__, enum.args[1]) - enum = enum.args[2].value - else - error("Do not know how to refer to $enum") - end - enum = getfield(mod, enum) - prefix = String(prefix) - - ex = quote end - for instance in instances(enum) - name = String(Symbol(instance)) - @assert startswith(name, prefix) - push!(ex.args, :(const $(Symbol(name[length(prefix) + 1:end])) = $(mod).$(Symbol(name)))) - end - - return esc(ex) -end - -## -Base.convert(::Type{MtResourceOptions}, val::UInt32) = - MtResourceOptions(val) - -## -""" - @mtlthrows error_var function(..., error_var) - -Marks that this Metal function has an argument error_var which -must be passed by reference in the underlying ccall, and when -the function returns checks that no error has been set. - -Expands roughly to -```julia -error_var = Ref{MTLError}() -result = function(..., error_var) -error[] != C_NULL && throw(MtlError(error[])) -``` -""" -macro mtlthrows(error, fun) - expr = quote - $error = Ref{MTLError}(C_NULL) - result = $fun - if $error[] != C_NULL - throw(MtlError($(error)[])) - end - result - end - return esc(expr) -end diff --git a/lib/mtl/library.jl b/lib/mtl/library.jl index 00681f91..be065264 100644 --- a/lib/mtl/library.jl +++ b/lib/mtl/library.jl @@ -1,96 +1,56 @@ -export MtlLibrary, MtlLibraryFromFile, MtlLibraryFromData +export MTLLibrary, MTLLibraryFromFile, MTLLibraryFromData -const MTLLibrary = Ptr{MtLibrary} +@objcwrapper immutable=false MTLLibrary <: NSObject -""" - MtlDevice(i::Integer) - -Get a handle to a compute device. -""" -mutable struct MtlLibrary - handle::MTLLibrary - device::MtlDevice +@objcproperties MTLLibrary begin + @autoproperty device::id{MTLDevice} + @autoproperty label::id{NSString} setter=setLabel + @autoproperty functionNames::id{NSArray} type=Vector{NSString} end -Base.unsafe_convert(::Type{MTLLibrary}, lib::MtlLibrary) = lib.handle - -Base.:(==)(a::MtlLibrary, b::MtlLibrary) = a.handle == b.handle -Base.hash(lib::MtlLibrary, h::UInt) = hash(lib.handle, h) - -function MtlLibrary(device::MtlDevice, src::String, opts::MtlCompileOptions=MtlCompileOptions()) - handle = @mtlthrows _errptr mtNewLibraryWithSource(device, src, opts, _errptr) +function MTLLibrary(device::MTLDevice, src::String, + opts::MTLCompileOptions=MTLCompileOptions()) + err = Ref{id{NSError}}(nil) + handle = @objc [device::id{MTLDevice} newLibraryWithSource:src::id{NSString} + options:opts::id{MTLCompileOptions} + error:err::Ptr{id{NSError}}]::id{MTLLibrary} + err[] == nil || throw(NSError(err[])) - obj = MtlLibrary(handle, device) - finalizer(unsafe_destroy!, obj) + obj = MTLLibrary(handle) + finalizer(release, obj) return obj end -function MtlLibraryFromFile(device::MtlDevice, path::String) +function MTLLibraryFromFile(device::MTLDevice, path::String) + err = Ref{id{NSError}}(nil) handle = if macos_version() >= v"13" - @mtlthrows _errptr mtNewLibraryWithURL(device, path, _errptr) + url = NSFileURL(path) + @objc [device::id{MTLDevice} newLibraryWithURL:url::id{NSURL} + error:err::Ptr{id{NSError}}]::id{MTLLibrary} else - @mtlthrows _errptr mtNewLibraryWithFile(device, path, _errptr) + @objc [device::id{MTLDevice} newLibraryWithFile:path::id{NSString} + error:err::Ptr{id{NSError}}]::id{MTLLibrary} end + err[] == nil || throw(NSError(err[])) - obj = MtlLibrary(handle, device) - finalizer(unsafe_destroy!, obj) + obj = MTLLibrary(handle) + finalizer(release, obj) return obj end -function MtlLibraryFromData(device::MtlDevice, data) - GC.@preserve data begin - handle = @mtlthrows _errptr mtNewLibraryWithData(device, pointer(data), sizeof(data), _errptr) +function MTLLibraryFromData(device::MTLDevice, input_data) + err = Ref{id{NSError}}(nil) + GC.@preserve input_data begin + data = dispatch_data(pointer(input_data), sizeof(input_data)) + handle = @objc [device::id{MTLDevice} newLibraryWithData:data::dispatch_data_t + error:err::Ptr{id{NSError}}]::id{MTLLibrary} end + err[] == nil || throw(NSError(err[])) - obj = MtlLibrary(handle, device) - finalizer(unsafe_destroy!, obj) + obj = MTLLibrary(handle) + finalizer(release, obj) return obj end - -function unsafe_destroy!(lib::MtlLibrary) - mtRelease(lib.handle) -end - - -## properties - -Base.propertynames(::MtlLibrary) = (:device, :label, :functionNames) - -function Base.getproperty(lib::MtlLibrary, f::Symbol) - if f === :label - ptr = mtLibraryLabel(lib) - ptr == C_NULL ? nothing : unsafe_string(ptr) - elseif f === :functionNames - count = Ref{Csize_t}(0) - mtLibraryFunctionNames(lib, count, C_NULL) - names = Vector{Cstring}(undef, count[]) - mtLibraryFunctionNames(lib, count, names) - unsafe_string.(names) - else - getfield(lib, f) - end -end - -function Base.setproperty!(lib::MtlLibrary, f::Symbol, val) - if f === :label - mtLibraryLabelSet(lib, val) - else - setfield!(lib, f, val) - end -end - - -## display - -function Base.show(io::IO, lib::MtlLibrary) - print(io, "MtlLibrary($(lib.device))") -end - -function Base.show(io::IO, ::MIME"text/plain", lib::MtlLibrary) - println(io, "MtlLibrary:") - println(io, " device: ", lib.device) - print(io, " label: ", lib.label) -end diff --git a/lib/mtl/memory.jl b/lib/mtl/memory.jl deleted file mode 100644 index 8ba8afd4..00000000 --- a/lib/mtl/memory.jl +++ /dev/null @@ -1,38 +0,0 @@ - -mutable struct MetalBufferRC{T} - buf::MetalBuffer{T} - - freed::Bool - refcount::Int -end - -function alloc_refcount(args...; kwargs...) - buf = alloc(args...; kwargs...) - self = MetalBufferRC(buf, false, 0) -end - -@inline function retain(a::MetalBufferRC) - a.refcount += 1 - return -end - -@inline function release(a::MetalBufferRC) - a.refcount -= 1 - return a.refcount == 0 -end - -function unsafe_free!(xs::MetalBufferRC) - # this call should only have an effect once, becuase both the user and the GC can call it - xs.freed && return - _unsafe_free!(xs) - xs.freed = true - return -end - -function _unsafe_free!(xs::CuArray) - @assert xs.refcount >= 0 - if release(xs) - free(xs.buf) - end - return -end diff --git a/lib/mtl/profile.jl b/lib/mtl/profile.jl deleted file mode 100644 index 6117e9bb..00000000 --- a/lib/mtl/profile.jl +++ /dev/null @@ -1,320 +0,0 @@ -export MtlCaptureDescriptor, MtlCaptureManager, MtlCaptureScope, startCapture, stopCapture, - beginScope, endScope - -### Capture Scope -const MTLCaptureScope = Ptr{MtCaptureScope} - -""" - MtlCaptureScope(handle::MTLCaptureScope) -An object that defines custom boundaries for a GPU frame capture. - -Use [`beginScope()`](@ref) and [`endScope()`](@ref) to set the boundaries for a capture scope. -""" -mutable struct MtlCaptureScope - handle::MTLCaptureScope - - function MtlCaptureScope(handle::MTLCaptureScope) - obj = new(handle) - # No finalizer because handled by Metal - return obj - end -end - -Base.unsafe_convert(::Type{MTLCaptureScope}, scope::MtlCaptureScope) = scope.handle - -Base.:(==)(a::MtlCaptureScope, b::MtlCaptureScope) = a.handle == b.handle -Base.hash(scope::MtlCaptureScope, h::UInt) = hash(scope.handle, h) - -""" - beginScope(scope::MtlCaptureScope) -Begin recording GPU command information. -""" -function beginScope(scope::MtlCaptureScope) - mtBeginScope(scope) -end - -""" - endScope(scope::MtlCaptureScope) -Stop recording GPU command information. -""" -function endScope(scope::MtlCaptureScope) - mtEndScope(scope) -end - -## properties - -Base.propertynames(::MtlCaptureScope) = ( - :device, :commandQueue, :label, -) - -function Base.getproperty(o::MtlCaptureScope, f::Symbol) - if f === :device - MtlDevice(mtCaptureScopeDevice(o)) - elseif f === :commandQueue - MtlCommandQueue(mtCaptureScopeCommandQueue(o), o.device) - elseif f === :label - ptr = mtCaptureScopeLabel(o) - ptr == C_NULL ? nothing : unsafe_string(ptr) - else - getfield(o, f) - end -end - -function Base.setproperty!(o::MtlCaptureScope, f::Symbol, val) - if f === :label - mtCaptureScopeLabelSet(o, val) - else - setfield!(o, f, val) - end -end - -## display - -function show(io::IO, ::MIME"text/plain", scope::MtlCaptureScope) - println(io, "MtlCaptureScope:") - println(io, " label: ", scope.label) - print(io, " device: ", scope.device) - print(io, " command queue: ", scope.commandQueue) -end - -### Capture Descriptor - -const MTLCaptureDescriptor = Ptr{MtCaptureDescriptor} - -""" - MtlCaptureDescriptor() - MtlCaptureDescriptor(obj::Union{MtlDevice,MtlCommandQueue}, - destination::MtCaptureDestination; - folder::String=nothing) -Create a GPU frame capture descriptor to alter the parameters of a profiling session. -""" -mutable struct MtlCaptureDescriptor - handle::MTLCaptureDescriptor - cap_obj_type::MtCaptureDescriptorCaptureObjectType - - function MtlCaptureDescriptor() - handle = mtNewCaptureDescriptor() - obj = new(handle, MtCaptureDescriptorCaptureObjectTypeNull) - finalizer(unsafe_destroy!, obj) - return obj - end - - # TODO: Add capture state - function MtlCaptureDescriptor(obj::Union{MtlDevice,MtlCommandQueue, MtlCaptureScope}, - destination::MtCaptureDestination; - folder::String=nothing) - desc = MtlCaptureDescriptor() - desc.destination = destination - desc.captureObject = obj - if folder != nothing - desc.outputFolder = folder - end - return desc - end -end - -Base.unsafe_convert(::Type{MTLCaptureDescriptor}, desc::MtlCaptureDescriptor) = desc.handle - -Base.:(==)(a::MtlCaptureDescriptor, b::MtlCaptureDescriptor) = a.handle == b.handle -Base.hash(desc::MtlCaptureDescriptor, h::UInt) = hash(desc.handle, h) - -function unsafe_destroy!(desc::MtlCaptureDescriptor) - mtRelease(desc.handle) -end - -## properties - -# Mapping between capture object types and Julia types -const obj_enum_to_jl_typ = Dict(MtCaptureDescriptorCaptureObjectTypeDevice => MTLDevice, - MtCaptureDescriptorCaptureObjectTypeQueue => MTLCommandQueue, - MtCaptureDescriptorCaptureObjectTypeScope => MTLCaptureScope) - -Base.propertynames(::MtlCaptureDescriptor) = (:captureObject, :destination, :outputFolder) - -function Base.getproperty(desc::MtlCaptureDescriptor, f::Symbol) - if f === :captureObject - ptr = mtCaptureDescriptorCaptureObject(desc) - ptr == C_NULL ? nothing : obj_enum_to_jl_typ[desc.cap_obj_type](ptr) - elseif f === :destination - mtCaptureDescriptorDestination(desc) - elseif f === :outputFolder - # TODO: Redo this if users want full NSURL capabilities - ptr = mtCaptureDescriptorOutputURL(desc) - ptr == C_NULL ? nothing : unsafe_string(ptr) - else - getfield(desc, f) - end -end - -function Base.setproperty!(desc::MtlCaptureDescriptor, f::Symbol, val) - if f === :captureObject - if isa(val, MtlCommandQueue) - mtCaptureDescriptorCaptureObjectSetQueue(desc.handle, val.handle) - desc.cap_obj_type = MtCaptureDescriptorCaptureObjectTypeQueue - elseif isa(val, MtlDevice) - mtCaptureDescriptorCaptureObjectSetDevice(desc.handle, val.handle) - desc.cap_obj_type = MtCaptureDescriptorCaptureObjectTypeDevice - elseif isa(val, MtlCaptureScope) - mtCaptureDescriptorCaptureObjectSetScope(desc.handle, val.handle) - desc.cap_obj_type = MtCaptureDescriptorCaptureObjectTypeScope - else - throw(ArgumentError("captureObject property should be a MtlCommandQueue, MtlDevice, or MtlCaptureScope.")) - end - elseif f === :destination - isa(val, MtCaptureDestination) || - throw(ArgumentError("destination property must be a MtlCaptureDestination")) - mtCaptureDescriptorDestinationSet(desc.handle, val) - elseif f === :outputFolder - # TODO: Check that it doesn't already exist and allow for path or other compatible objects - isa(val, String) || - throw(ArgumentError("outputFolder property must be a String")) - mtCaptureDescriptorOutputURLSet(desc.handle, val) - else - setfield!(desc, f, val) - end -end - -## display - -function Base.show(io::IO, desc::MtlCaptureDescriptor) - print(io, "MtlCaptureDescriptor(...)") -end - -function Base.show(io::IO, ::MIME"text/plain", desc::MtlCaptureDescriptor) - println(io, "MtlCaptureDescriptor:") - println(io, " capture object: ", desc.captureObject) - println(io, " destination: ", desc.destination) - print(io, " output folder: ", desc.outputFolder) -end - -### Capture Manager - -const MTLCaptureManager = Ptr{MtCaptureManager} - -""" - struct MtlCaptureManager -Metal-managed object that handles GPU frame capture support and usage. -Note: There is only one (shared) capture manager per process. -""" -struct MtlCaptureManager - handle::MTLCaptureManager - - """ - MtlCaptureManager() - Return the unique shared GPU frame capture manager for this process. - """ - function MtlCaptureManager() - # Inexpensive dummy metal command to trigger GPU framce capture enable on Metal's end - # Without this, two separate capture managers are potentially handled - # One with capture enabled and one without - MtlDevice(1) - handle = mtSharedCaptureManager() - obj = new(handle) - # No finalizer needed since the manager is handled by Metal - return obj - end -end - -Base.unsafe_convert(::Type{MTLCaptureManager}, capman::MtlCaptureManager) = capman.handle - -Base.:(==)(a::MtlCaptureManager, b::MtlCaptureManager) = a.handle == b.handle -Base.hash(capman::MtlCaptureManager, h::UInt) = hash(capman.handle, h) - - -""" - startCapture(obj::Union{MtlDevice,MtlCommandQueue}, - destination::MtCaptureDestination=MtCaptureDestinationGPUTraceDocument; - folder::String=nothing) -Start GPU frame capture using the default capture object and specifying capture descriptor parameters directly. -""" -function startCapture(obj::Union{MtlDevice,MtlCommandQueue, MtlCaptureScope}, - destination::MtCaptureDestination=MtCaptureDestinationGPUTraceDocument; - folder::String=nothing) - destination == MtCaptureDestinationGPUTraceDocument && folder == nothing && - throw(ArgumentError("Must specify output folder if destination is GPUTraceDocument")) - startCapture(MtlCaptureManager(), MtlCaptureDescriptor(obj, destination; folder=folder)) -end - -""" - startCapture(manager::MtlCaptureManager, desc::MtlCaptureDescriptor) -Start a GPU frame capture session with the given capture manager and descriptor. -""" -function startCapture(manager::MtlCaptureManager, desc::MtlCaptureDescriptor) - # Check not already capturing - manager.isCapturing && throw(error("Capture manager is already capturing.")) - # Warn users if environment variable isn't set (required in most cases) - haskey(ENV, "METAL_CAPTURE_ENABLED") || - @warn """Environment variable 'METAL_CAPTURE_ENABLED' is not set. In most cases, this - will need to be set to 1 before launching Julia to enable GPU frame capture.""" - # Error if explicitly disallowed - haskey(ENV, "METAL_CAPTURE_ENABLED") && ENV["METAL_CAPTURE_ENABLED"] == 0 && - throw(error("Metal GPU frame capture explicitly disallowed via environment vairable.")) - - # Validate outputFolder - if desc.destination == MtCaptureDestinationGPUTraceDocument - dir = desc.outputFolder - # Append required suffix if not already there - if !(endswith(dir, ".gputrace")) - desc.outputFolder = dir * ".gputrace" - end - isdir(dir) && - throw(ArgumentError("`dir` keyword argument to @profile should not be an existing directory")) - end - - _errptr = Ref{MTLError}() - success = mtStartCaptureWithDescriptor(manager.handle, desc.handle, _errptr) - success || throw(MtlError(_errptr[])) - return -end - -""" - stopCapture(manager::MtlCaptureManager=MtlCaptureManager()) -Stop GPU frame capture. -""" -function stopCapture(manager::MtlCaptureManager=MtlCaptureManager()) - mtStopCapture(manager) -end - -## properties - -Base.propertynames(::MtlCaptureManager) = (:supportsTraceXcode, - :supportsTraceFile, - :isCapturing, - :defaultCaptureScope) - -function Base.getproperty(manager::MtlCaptureManager, f::Symbol) - if f === :supportsTraceXcode - mtSupportsDestination(manager, MTL.MtCaptureDestinationDeveloperTools) - elseif f === :supportsTraceFile - mtSupportsDestination(manager, MTL.MtCaptureDestinationGPUTraceDocument) - elseif f === :isCapturing - mtIsCapturing(manager) - elseif f === :defaultCaptureScope - ptr = mtDefaultCaptureScope(manager) - ptr == C_NULL ? nothing : MtlCaptureScope(ptr) - else - getfield(manager, f) - end -end - -function Base.setproperty!(o::MtlCaptureManager, f::Symbol, val) - if f === :defaultCaptureScope - mtDefaultCaptureScopeSet(o, val) - else - setfield!(o, f, val) - end -end - -## display - -function Base.show(io::IO, capman::MtlCaptureManager) - print(io, "MtlCaptureManager(...)") -end - -function Base.show(io::IO, ::MIME"text/plain", capman::MtlCaptureManager) - println(io, "MtlCaptureManager:") - println(io, " is capturing: ", capman.isCapturing) - println(io, " default capture scope: ", capman.defaultCaptureScope) - println(io, " supports Xcode trace: ", capman.supportsTraceXcode) - print(io, " supports file trace: ", capman.supportsTraceFile) -end \ No newline at end of file diff --git a/lib/mtl/resource.jl b/lib/mtl/resource.jl index 271c4905..f91d941e 100644 --- a/lib/mtl/resource.jl +++ b/lib/mtl/resource.jl @@ -1,40 +1,59 @@ -export MtlResource +# +# resource enums +# -const MTLResource = Ptr{MtResource} +@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 -abstract type MtlResource end +@cenum MTLResourceOptions::NSUInteger begin + MTLResourceCPUCacheModeDefaultCache = 0 + MTLResourceCPUCacheModeWriteCombined = 1 + MTLResourceStorageModeShared = 0 + MTLResourceStorageModeManaged = 16 + MTLResourceStorageModePrivate = 32 + MTLResourceStorageModeMemoryless = 48 + MTLResourceHazardTrackingModeDefault = 0 + MTLResourceHazardTrackingModeUntracked = 256 + MTLResourceHazardTrackingModeTracked = 512 +end +## bitwise operations lose type information, so allow conversions +Base.convert(::Type{MTLResourceOptions}, x::Integer) = MTLResourceOptions(x) -Base.unsafe_convert(::Type{MTLResource}, res::MtlResource) = Base.bitcast(MTLResource, res.handle) +@cenum MTLResourceUsage::NSUInteger begin + MTLResourceUsageRead = 1 + MTLResourceUsageWrite = 2 + MTLResourceUsageSample = 4 +end -## properties +# +# resourcs +# -Base.propertynames(::MtlResource) = - (:device, :label, :cpuCacheMode, :storageMode, :hazardTrackingMode, :resourceOptions) +export MTLResource -function Base.getproperty(res::MtlResource, f::Symbol) - if f === :device - MtlDevice(mtResourceDevice(res)) - elseif f === :label - ptr = mtResourceLabel(res) - ptr == C_NULL ? nothing : unsafe_string(ptr) - elseif f === :cpuCacheMode - mtResourceCPUCacheMode(res) - elseif f === :storageMode - mtResourceStorageMode(res) - elseif f === :hazardTrackingMode - mtResourceHazardTrackingMode(res) - elseif f === :resourceOptions - mtResourceOptions(res) - else - getfield(res, f) - end -end +@objcwrapper MTLResource <: NSObject -function Base.setproperty!(res::MtlResource, f::Symbol, val) - if f === :label - mtResourceLabelSet(res, val) - else - setfield!(res, f, val) - end +@objcproperties MTLResource begin + @autoproperty device::id{MTLDevice} + @autoproperty label::id{NSString} setter=setLabel + @autoproperty cpuCacheMode::MTLCPUCacheMode + @autoproperty storageMode::MTLStorageMode + @autoproperty hazardTrackingMode::MTLHazardTrackingMode + @autoproperty resourceOptions::MTLResourceOptions end diff --git a/lib/mtl/size.jl b/lib/mtl/size.jl index 5719da2e..1e386cde 100644 --- a/lib/mtl/size.jl +++ b/lib/mtl/size.jl @@ -1,42 +1,29 @@ -## sizes +## size -export MtSize, MtlDim, MtlDim3 +export MTLSize -const MTLDim = MtSize -""" - MtlDim3(x) +struct MTLSize + width::NSUInteger + height::NSUInteger + depth::NSUInteger - MtlDim3((x,)) - MtlDim3((x, y)) - MtlDim3((x, y, x)) + MTLSize(w=1, h=1, d=1) = new(w, h, d) +end -A type used to specify dimensions, consisting of 3 integers for respectively the `x`, `y` -and `z` dimension. Unspecified dimensions default to `1`. +# convenience constructors from tuple inputs +MTLSize(dims::NTuple{1,<:Integer}) = MTLSize(dims[1], 1, 1) +MTLSize(dims::NTuple{2,<:Integer}) = MTLSize(dims[1], dims[2], 1) +MTLSize(dims::NTuple{3,<:Integer}) = MTLSize(dims[1], dims[2], dims[3]) -Often accepted as argument through the `MtlDim` type alias, eg. in the case of -[`mtlcall`](@ref) or [`launch`](@ref), allowing to pass dimensions as a plain integer or a -tuple without having to construct an explicit `MtlDim3` object. -""" -const MtlDim3 = MTLDim -MtlDim3(dims::Integer) = MtlDim3(dims, NsUInteger(1), NsUInteger(1)) -MtlDim3(dims::NTuple{1,<:Integer}) = MtlDim3(dims[1], NsUInteger(1), NsUInteger(1)) -MtlDim3(dims::NTuple{2,<:Integer}) = MtlDim3(dims[1], dims[2], NsUInteger(1)) -MtlDim3(dims::NTuple{3,<:Integer}) = MtlDim3(dims[1], dims[2], dims[3]) +## origin -# Type alias for conveniently specifying the dimensions -# (e.g. `(len, 2)` instead of `MtlDim3((len, 2))`) -const MtlDim = Union{Integer, - Tuple{Integer}, - Tuple{Integer, Integer}, - Tuple{Integer, Integer, Integer}} +export MTLOrigin +struct MTLOrigin + x::NSUInteger + y::NSUInteger + z::NSUInteger -## ranges - -# convert from 1 based indexing to 0 based indexing -Base.convert(::Type{NsRange}, range::UnitRange{T}) where T <: Integer = - NsRange(first(range), length(range)) -# used for byte ranges. -Base.convert(::Type{NsRange}, range::StepRange{T}) where T <: Integer = - NsRange(first(range)-step(range), length(range)*step(range)) + MTLOrigin(x=0, y=0, z=0) = new(x, y, z) +end diff --git a/lib/mtl/storage_type.jl b/lib/mtl/storage_type.jl index 569db613..ed5fa519 100644 --- a/lib/mtl/storage_type.jl +++ b/lib/mtl/storage_type.jl @@ -1,5 +1,5 @@ abstract type StorageMode end -export MtStorageMode, Shared, Managed, Private +export Shared, Managed, Private export ReadUsage, WriteUsage, ReadWriteUsage # Metal Has 4 storage types @@ -17,43 +17,39 @@ struct Memoryless <: StorageMode end end const CPUStorage = Union{AS.Shared,AS.Managed} -Base.convert(::Type{MtStorageMode}, ::Type{AS.Shared}) = MtStorageModeShared -Base.convert(::Type{MtStorageMode}, ::Type{AS.Managed}) = MtStorageModeManaged -Base.convert(::Type{MtStorageMode}, ::Type{AS.Private}) = MtStorageModePrivate -Base.convert(::Type{MtStorageMode}, ::Type{AS.Memoryless}) = MtStorageModeMemoryless +Base.convert(::Type{MTLStorageMode}, ::Type{AS.Shared}) = MTLStorageModeShared +Base.convert(::Type{MTLStorageMode}, ::Type{AS.Managed}) = MTLStorageModeManaged +Base.convert(::Type{MTLStorageMode}, ::Type{AS.Private}) = MTLStorageModePrivate +Base.convert(::Type{MTLStorageMode}, ::Type{AS.Memoryless}) = MTLStorageModeMemoryless -Base.convert(::Type{MtResourceOptions}, ::Type{AS.Shared}) = MtResourceStorageModeShared -Base.convert(::Type{MtResourceOptions}, ::Type{AS.Managed}) = MtResourceStorageModeManaged -Base.convert(::Type{MtResourceOptions}, ::Type{AS.Private}) = MtResourceStorageModePrivate -Base.convert(::Type{MtResourceOptions}, ::Type{AS.Memoryless}) = MtResourceStorageModeMemoryless +Base.convert(::Type{MTLResourceOptions}, ::Type{AS.Shared}) = MTLResourceStorageModeShared +Base.convert(::Type{MTLResourceOptions}, ::Type{AS.Managed}) = MTLResourceStorageModeManaged +Base.convert(::Type{MTLResourceOptions}, ::Type{AS.Private}) = MTLResourceStorageModePrivate +Base.convert(::Type{MTLResourceOptions}, ::Type{AS.Memoryless}) = MTLResourceStorageModeMemoryless -# Broken because multiple zeros -#@enum_without_prefix MtResourceOptions MtResource -const MtlResourceOptions = MtResourceOptions +const Shared = MTLResourceStorageModeShared +const Managed = MTLResourceStorageModeManaged +const Private = MTLResourceStorageModePrivate +const Memoryless = MTLResourceStorageModeMemoryless -const Shared = MtResourceStorageModeShared -const Managed = MtResourceStorageModeManaged -const Private = MtResourceStorageModePrivate -const Memoryless = MtResourceStorageModeMemoryless +const DefaultCPUCache = MTLResourceCPUCacheModeDefaultCache +const CombinedWriteCPUCache = MTLResourceCPUCacheModeWriteCombined -const DefaultCPUCache = MtResourceCPUCacheModeDefaultCache -const CombinedWriteCPUCache = MtResourceCPUCacheModeWriteCombined - -const DefaultTracking = MtResourceHazardTrackingModeDefault -const Untracked = MtResourceHazardTrackingModeUntracked -const Tracked = MtResourceHazardTrackingModeTracked +const DefaultTracking = MTLResourceHazardTrackingModeDefault +const Untracked = MTLResourceHazardTrackingModeUntracked +const Tracked = MTLResourceHazardTrackingModeTracked const Default = DefaultCPUCache -Base.:(==)(a::MtlResourceOptions, b::MtStorageMode) = +Base.:(==)(a::MTLResourceOptions, b::MTLStorageMode) = (UInt(a) >> 4) == UInt(b) -Base.:(==)(a::MtStorageMode, b::MtlResourceOptions) = +Base.:(==)(a::MTLStorageMode, b::MTLResourceOptions) = b == a ################## -Base.convert(::Type{MtResourceUsage}, val::Integer) = MtResourceUsage(val) +Base.convert(::Type{MTLResourceUsage}, val::Integer) = MTLResourceUsage(val) -const ReadUsage = MtResourceUsageRead -const WriteUsage = MtResourceUsageWrite -const ReadWriteUsage = convert(MtResourceUsage, MtResourceUsageRead | MtResourceUsageWrite) +const ReadUsage = MTLResourceUsageRead +const WriteUsage = MTLResourceUsageWrite +const ReadWriteUsage = convert(MTLResourceUsage, MTLResourceUsageRead | MTLResourceUsageWrite) diff --git a/src/Metal.jl b/src/Metal.jl index a1d3a1f4..34a56258 100644 --- a/src/Metal.jl +++ b/src/Metal.jl @@ -8,9 +8,7 @@ using LLVM using LLVM.Interop using Metal_LLVM_Tools_jll using ExprTools: splitdef, combinedef - -# C wrappers -include("../lib/cmt/cmt.jl") +using ObjectiveC, .Foundation, .Dispatch # core library include("../lib/mtl/MTL.jl") diff --git a/src/array.jl b/src/array.jl index 5936860c..831c5593 100644 --- a/src/array.jl +++ b/src/array.jl @@ -27,7 +27,7 @@ function contains_double(T) end mutable struct MtlArray{T,N} <: AbstractGPUArray{T,N} - buffer::MtlBuffer + buffer::MTLBuffer maxsize::Int # maximum data size; excluding any selector bytes offset::Int # offset of the data in the buffer, in number of elements @@ -45,12 +45,13 @@ mutable struct MtlArray{T,N} <: AbstractGPUArray{T,N} end dev = current_device() - if bufsize > 0 - buf = alloc(dev, bufsize; storage=storage) - buf.label = "MtlArray{$(T),$(N)}(dims=$dims)" - else - buf = MtlBuffer(C_NULL) + if bufsize == 0 + # Metal doesn't support empty allocations. for simplicity (i.e., the ability to get + # a pointer, query the buffer's properties, etc), we use a 1-byte buffer instead. + bufsize = 1 end + buf = alloc(dev, bufsize; storage=storage) + buf.label = "MtlArray{$(T),$(N)}(dims=$dims)" obj = new(buf, maxsize, 0, dims) finalizer(obj) do arr @@ -59,10 +60,10 @@ mutable struct MtlArray{T,N} <: AbstractGPUArray{T,N} return obj end - function MtlArray{T,N}(buffer::MtlBuffer, dims::Dims{N}; + function MtlArray{T,N}(buffer::MTLBuffer, dims::Dims{N}; maxsize::Int=prod(dims) * sizeof(T), offset::Int=0) where {T,N} Base.allocatedinline(T) || error("MtlArray only supports element types that are stored inline") - MTL.mtRetain(buffer.handle) + retain(buffer) obj = new{T,N}(buffer, maxsize, offset, dims) finalizer(obj) do arr free(arr.buffer) @@ -220,7 +221,7 @@ end Base.copyto!(dest::MtlArray{T}, src::MtlArray{T}) where {T} = copyto!(dest, 1, src, 1, length(src)) -function Base.unsafe_copyto!(dev::MtlDevice, dest::MtlArray{T}, doffs, src::Array{T}, soffs, n) where T +function Base.unsafe_copyto!(dev::MTLDevice, dest::MtlArray{T}, doffs, src::Array{T}, soffs, n) where T # these copies are implemented using pure memcpy's, not API calls, so aren't ordered. synchronize() @@ -232,7 +233,7 @@ function Base.unsafe_copyto!(dev::MtlDevice, dest::MtlArray{T}, doffs, src::Arra return dest end -function Base.unsafe_copyto!(dev::MtlDevice, dest::Array{T}, doffs, src::MtlArray{T}, soffs, n) where T +function Base.unsafe_copyto!(dev::MTLDevice, dest::Array{T}, doffs, src::MtlArray{T}, soffs, n) where T # these copies are implemented using pure memcpy's, not API calls, so aren't ordered. synchronize() @@ -244,7 +245,7 @@ function Base.unsafe_copyto!(dev::MtlDevice, dest::Array{T}, doffs, src::MtlArra return dest end -function Base.unsafe_copyto!(dev::MtlDevice, dest::MtlArray{T}, doffs, src::MtlArray{T}, soffs, n) where T +function Base.unsafe_copyto!(dev::MTLDevice, dest::MtlArray{T}, doffs, src::MtlArray{T}, soffs, n) where T # these copies are implemented using pure memcpy's, not API calls, so aren't ordered. synchronize() @@ -508,7 +509,7 @@ end ## unsafe_wrap -function Base.unsafe_wrap(t::Type{<:Array{T}}, buf::MtlBuffer, dims; own=false) where T +function Base.unsafe_wrap(t::Type{<:Array{T}}, buf::MTLBuffer, dims; own=false) where T ptr = convert(Ptr{T}, contents(buf)) return unsafe_wrap(t, ptr, dims; own) end diff --git a/src/compiler/execution.jl b/src/compiler/execution.jl index 4d1d0baf..1417b3e8 100644 --- a/src/compiler/execution.jl +++ b/src/compiler/execution.jl @@ -80,12 +80,12 @@ end ## argument conversion struct Adaptor - cce::Union{Nothing,MtlComputeCommandEncoder} + cce::Union{Nothing,MTLComputeCommandEncoder} end # convert Metal buffers to their GPU address -function Adapt.adapt_storage(to::Adaptor, buf::MtlBuffer) - if to.cce !== nothing && buf.handle != C_NULL +function Adapt.adapt_storage(to::Adaptor, buf::MTLBuffer) + if to.cce !== nothing MTL.use!(to.cce, buf, MTL.ReadWriteUsage) end reinterpret(Core.LLVMPtr{Nothing,AS.Device}, buf.gpuAddress) @@ -124,8 +124,8 @@ mtlconvert(arg, cce=nothing) = adapt(Adaptor(cce), arg) struct HostKernel{F,TT} f::F - fun::MtlFunction - pipeline_state::MtlComputePipelineState + fun::MTLFunction + pipeline_state::MTLComputePipelineState end """ @@ -139,7 +139,7 @@ in a hot path without degrading performance. New code will be generated automati the function changes, or when different types or keyword arguments are provided. """ function mtlfunction(f::F, tt::TT=Tuple{}; name=nothing, kwargs...) where {F,TT} - dev = MtlDevice(1) + dev = MTLDevice(1) cache = get!(()->Dict{UInt,Any}(), mtlfunction_cache, dev) source = FunctionSpec(f, tt, true, name) target = MetalCompilerTarget(macos=macos_version(); kwargs...) @@ -171,10 +171,10 @@ end function mtlfunction_link(@nospecialize(job::CompilerJob), compiled) dev = current_device() - lib = MtlLibraryFromData(dev, compiled.image) - fun = MtlFunction(lib, compiled.entry) + lib = MTLLibraryFromData(dev, compiled.image) + fun = MTLFunction(lib, compiled.entry) pipeline_state = try - MtlComputePipelineState(dev, fun) + MTLComputePipelineState(dev, fun) catch # the back-end compiler likely failed # XXX: check more accurately? the error domain doesn't help much here @@ -190,9 +190,9 @@ end ## kernel launching and argument encoding -function (kernel::HostKernel)(args...; grid::MtlDim=1, threads::MtlDim=1, queue=global_queue(current_device())) - grid = MtlDim3(grid) - threads = MtlDim3(threads) +function (kernel::HostKernel)(args...; grid=1, threads=1, queue=global_queue(current_device())) + grid = MTLSize(grid) + threads = MTLSize(threads) (grid.width>0 && grid.height>0 && grid.depth>0) || throw(ArgumentError("Grid dimensions should be non-null")) (threads.width>0 && threads.height>0 && threads.depth>0) || @@ -201,16 +201,16 @@ function (kernel::HostKernel)(args...; grid::MtlDim=1, threads::MtlDim=1, queue= (threads.width * threads.height * threads.depth) > kernel.pipeline_state.maxTotalThreadsPerThreadgroup && throw(ArgumentError("Max total threadgroup size should not exceed $(kernel.pipeline_state.maxTotalThreadsPerThreadgroup)")) - cmdbuf = MtlCommandBuffer(queue) - cmdbuf.label = "MtlCommandBuffer($(nameof(kernel.f)))" - argument_buffers = MtlBuffer[] - MtlComputeCommandEncoder(cmdbuf) do cce + cmdbuf = MTLCommandBuffer(queue) + cmdbuf.label = "MTLCommandBuffer($(nameof(kernel.f)))" + argument_buffers = MTLBuffer[] + MTLComputeCommandEncoder(cmdbuf) do cce MTL.set_function!(cce, kernel.pipeline_state) # encode arguments idx = 1 for arg in (kernel.f, args...) - if arg isa MtlBuffer + if arg isa MTLBuffer # top-level buffers are passed as a pointer-valued argument set_buffer!(cce, arg, 0, idx) elseif arg isa MtlPointer @@ -224,9 +224,9 @@ function (kernel::HostKernel)(args...; grid::MtlDim=1, threads::MtlDim=1, queue= continue end @assert isbits(arg) - argument_buffer = alloc(kernel.fun.lib.device, sizeof(argtyp), + argument_buffer = alloc(kernel.fun.device, sizeof(argtyp), storage=Shared) - argument_buffer.label = "MtlBuffer for kernel argument" + argument_buffer.label = "MTLBuffer for kernel argument" unsafe_store!(convert(Ptr{argtyp}, contents(argument_buffer)), arg) set_buffer!(cce, argument_buffer, 0, idx) push!(argument_buffers, argument_buffer) @@ -246,7 +246,7 @@ function (kernel::HostKernel)(args...; grid::MtlDim=1, threads::MtlDim=1, queue= # # TODO: is there a way to bind additional resources to the command buffer? roots = [kernel.f, args] - MTL.on_completed(cmdbuf) do + MTL.on_completed(cmdbuf) do buf empty!(roots) foreach(free, argument_buffers) @@ -266,12 +266,12 @@ end Returns the next or previous nearest number of threads that is a multiple of the warp size of a device `dev`. This is a common requirement when using intra-warp communication. """ -function nextwarp(pipe::MtlComputePipelineState, threads::Integer) +function nextwarp(pipe::MTLComputePipelineState, threads::Integer) ws = pipe.threadExecutionWidth return threads + (ws - threads % ws) % ws end -@doc (@doc nextwarp) function prevwarp(pipe::MtlComputePipelineState, threads::Integer) +@doc (@doc nextwarp) function prevwarp(pipe::MTLComputePipelineState, threads::Integer) ws = pipe.threadExecutionWidth return threads - Base.rem(threads, ws) end diff --git a/src/gpuarrays.jl b/src/gpuarrays.jl index 6e0a8c07..674fb632 100644 --- a/src/gpuarrays.jl +++ b/src/gpuarrays.jl @@ -17,7 +17,7 @@ struct mtlKernelContext <: AbstractKernelContext end threads = min(elements, kernel.pipeline_state.maxTotalThreadsPerThreadgroup) blocks = cld(elements, threads) - return (; threads, blocks) + return (; threads=Int(threads), blocks=Int(blocks)) end function GPUArrays.gpu_call(::mtlArrayBackend, f, args, threads::Int, blocks::Int; @@ -63,9 +63,9 @@ end GPUArrays.backend(::Type{<:MtlArray}) = mtlArrayBackend() -const GLOBAL_RNGs = Dict{MtlDevice,GPUArrays.RNG}() +const GLOBAL_RNGs = Dict{MTLDevice,GPUArrays.RNG}() function GPUArrays.default_rng(::Type{<:MtlArray}) - dev = MtlDevice(1) + dev = MTLDevice(1) get!(GLOBAL_RNGs, dev) do N = 128 # Size of default oneAPI working group with barrier, so should be good for Metal state = MtlArray{NTuple{4, UInt32}}(undef, N) diff --git a/src/initialization.jl b/src/initialization.jl index b3259e3b..ab04b314 100644 --- a/src/initialization.jl +++ b/src/initialization.jl @@ -32,7 +32,7 @@ function synchronize_metal_tasks(ex) try $(ex) finally - if haskey($task_local_storage(), :MtlDevice) + if haskey($task_local_storage(), :MTLDevice) $device_synchronize() end end diff --git a/src/mapreduce.jl b/src/mapreduce.jl index e8788511..40c8c596 100644 --- a/src/mapreduce.jl +++ b/src/mapreduce.jl @@ -174,7 +174,7 @@ function GPUArrays.mapreducedim!(f::F, op::OP, R::WrappedMtlArray{T}, # XXX: can we query the 1024? kernel = @metal launch=false partial_mapreduce_device(f, op, init, Val(1024), Val(Rreduce), Val(Rother), Val(UInt64(length(Rother))), Val(shuffle), R′, A) - pipeline = MtlComputePipelineState(kernel.fun.lib.device, kernel.fun) + pipeline = MTLComputePipelineState(kernel.fun.device, kernel.fun) # how many threads do we want? # diff --git a/src/memory.jl b/src/memory.jl index 499fd4da..7cf34be6 100644 --- a/src/memory.jl +++ b/src/memory.jl @@ -4,14 +4,14 @@ ## pointer type -# we cannot take a MtlBuffer's handle and work with that as it were a pointer to memory. +# we cannot take a MTLBuffer's handle and work with that as it were a pointer to memory. # instead, the Metal APIs always take the original handle and an offset parameter. struct MtlPointer{T} - buffer::MtlBuffer + buffer::MTLBuffer offset::UInt # in bytes - function MtlPointer{T}(buffer::MtlBuffer, offset=0) where {T} + function MtlPointer{T}(buffer::MTLBuffer, offset=0) where {T} new(buffer, offset) end end @@ -30,10 +30,10 @@ MTL.contents(ptr::MtlPointer{T}) where {T} = convert(Ptr{T}, contents(ptr.buffer ## operations # GPU -> GPU -function Base.unsafe_copyto!(dev::MtlDevice, dst::MtlPointer{T}, src::MtlPointer{T}, N::Integer; - queue::MtlCommandQueue=global_queue(dev), async::Bool=false) where T - cmdbuf = MtlCommandBuffer(queue) - MtlBlitCommandEncoder(cmdbuf) do enc +function Base.unsafe_copyto!(dev::MTLDevice, dst::MtlPointer{T}, src::MtlPointer{T}, N::Integer; + queue::MTLCommandQueue=global_queue(dev), async::Bool=false) where T + cmdbuf = MTLCommandBuffer(queue) + MTLBlitCommandEncoder(cmdbuf) do enc MTL.append_copy!(enc, dst.buffer, dst.offset, src.buffer, src.offset, N * sizeof(T)) end commit!(cmdbuf) @@ -41,43 +41,43 @@ function Base.unsafe_copyto!(dev::MtlDevice, dst::MtlPointer{T}, src::MtlPointer end # GPU -> CPU -function Base.unsafe_copyto!(dev::MtlDevice, dst::Ptr{T}, src::MtlPointer{T}, N::Integer; - queue::MtlCommandQueue=global_queue(dev), async::Bool=false) where T +function Base.unsafe_copyto!(dev::MTLDevice, dst::Ptr{T}, src::MtlPointer{T}, N::Integer; + queue::MTLCommandQueue=global_queue(dev), async::Bool=false) where T storage_type = src.buffer.storageMode - if storage_type == MTL.MtStorageModePrivate + if storage_type == MTL.MTLStorageModePrivate tmp_buf = alloc(T, dev, N, storage=Shared) unsafe_copyto!(dev, tmp_buf, 1, src.buffer, src.offset, N; queue, async) unsafe_copyto!(dst, contents(tmp_buf), N) free(tmp_buf) - elseif storage_type == MTL.MtStorageModeShared + elseif storage_type == MTL.MTLStorageModeShared unsafe_copyto!(dst, contents(src), N) - elseif storage_type == MTL.MtStorageModeManaged + elseif storage_type == MTL.MTLStorageModeManaged unsafe_copyto!(dst, contents(src), N) end return dst end # CPU -> GPU -function Base.unsafe_copyto!(dev::MtlDevice, dst::MtlPointer{T}, src::Ptr{T}, N::Integer; - queue::MtlCommandQueue=global_queue(dev), async::Bool=false) where T +function Base.unsafe_copyto!(dev::MTLDevice, dst::MtlPointer{T}, src::Ptr{T}, N::Integer; + queue::MTLCommandQueue=global_queue(dev), async::Bool=false) where T storage_type = dst.buffer.storageMode - if storage_type == MTL.MtStorageModePrivate + if storage_type == MTL.MTLStorageModePrivate tmp_buf = alloc(T, dev, N, src, storage=Shared) unsafe_copyto!(dev, tmp_buf, src, N; queue, async) unsafe_copyto!(dev, dst.buffer, dst.offset, tmp_buf, 1, N; queue, async) free(tmp_buf) - elseif storage_type == MTL.MtStorageModeShared + elseif storage_type == MTL.MTLStorageModeShared unsafe_copyto!(contents(dst), src, N) - elseif storage_type == MTL.MtStorageModeManaged + elseif storage_type == MTL.MTLStorageModeManaged unsafe_copyto!(contents(dst), src, N) MTL.DidModifyRange!(dst, 1:N) end return dst end -function unsafe_fill!(dev::MtlDevice, ptr::MtlPointer{T}, value::Union{UInt8,Int8}, N::Integer) where T - cmdbuf = MtlCommandBuffer(global_queue(dev)) - MtlBlitCommandEncoder(cmdbuf) do enc +function unsafe_fill!(dev::MTLDevice, ptr::MtlPointer{T}, value::Union{UInt8,Int8}, N::Integer) where T + cmdbuf = MTLCommandBuffer(global_queue(dev)) + MTLBlitCommandEncoder(cmdbuf) do enc MTL.append_fillbuffer!(enc, ptr.buffer, value, N * sizeof(T), ptr.offset) end commit!(cmdbuf) diff --git a/src/state.jl b/src/state.jl index 9dcff56b..c6b72d82 100644 --- a/src/state.jl +++ b/src/state.jl @@ -1,7 +1,7 @@ export current_device, device!, global_queue, synchronize, device_synchronize """ - current_device()::MtlDevice + current_device()::MTLDevice Return the Metal GPU device associated with the current Julia task. @@ -9,35 +9,35 @@ Since all M-series systems currently only externally show a single GPU, this fun effectively returns the only system GPU. """ function current_device() - get!(task_local_storage(), :MtlDevice) do - dev = MtlDevice(1) - startswith(dev.name, "Apple M") || @warn """Metal.jl is only supported on M-series Macs, you may run into issues. + get!(task_local_storage(), :MTLDevice) do + dev = MTLDevice(1) + startswith(String(dev.name), "Apple M") || @warn """Metal.jl is only supported on M-series Macs, you may run into issues. See https://github.com/JuliaGPU/Metal.jl/issues/22 for more details.""" maxlog=1 return dev - end::MtlDevice + end::MTLDevice end """ - device!(dev::MtlDevice) + device!(dev::MTLDevice) Sets the Metal GPU device associated with the current Julia task. """ -device!(dev::MtlDevice) = task_local_storage(:MtlDevice, dev) +device!(dev::MTLDevice) = task_local_storage(:MTLDevice, dev) -const global_queues = WeakKeyDict{MtlCommandQueue,Nothing}() +const global_queues = WeakKeyDict{MTLCommandQueue,Nothing}() """ - global_queue(dev::MtlDevice)::MtlCommandQueue + global_queue(dev::MTLDevice)::MTLCommandQueue Return the Metal command queue associated with the current Julia thread. """ -function global_queue(dev::MtlDevice) - get!(task_local_storage(), (:MtlCommandQueue, dev)) do - queue = MtlCommandQueue(dev) +function global_queue(dev::MTLDevice) + get!(task_local_storage(), (:MTLCommandQueue, dev)) do + queue = MTLCommandQueue(dev) queue.label = "global_queue($(current_task()))" global_queues[queue] = nothing queue - end::MtlCommandQueue + end::MTLCommandQueue end # TODO: Increase performance (currently ~15us) @@ -46,12 +46,12 @@ end Wait for currently committed GPU work on this queue to finish. -Create a new MtlCommandBuffer from the global command queue, commit it to the queue, +Create a new MTLCommandBuffer from the global command queue, commit it to the queue, and simply wait for it to be completed. Since command buffers *should* execute in a First-In-First-Out manner, this synchronizes the GPU. """ -function synchronize(queue::MtlCommandQueue=global_queue(current_device())) - cmdbuf = MtlCommandBuffer(queue) +function synchronize(queue::MTLCommandQueue=global_queue(current_device())) + cmdbuf = MTLCommandBuffer(queue) commit!(cmdbuf) wait_completed(cmdbuf) end diff --git a/src/utilities.jl b/src/utilities.jl index a9a2af79..e1dffe27 100644 --- a/src/utilities.jl +++ b/src/utilities.jl @@ -68,13 +68,13 @@ Profile Metal/GPU work using XCode's GPU frame capture capabilities. Several keyword arguments are supported that influence the behavior of `Metal.@profile`: -- `capture`: the object to capture GPU work on. Can be a MtlDevice, MtlCommandQueue, or - MtlCaptureScope. This defaults to the global command queue, and selecting a different +- `capture`: the object to capture GPU work on. Can be a MTLDevice, MTLCommandQueue, or + MTLCaptureScope. This defaults to the global command queue, and selecting a different capture object may result in no GPU commands detected when viewed from Xcode. - `dest`: the type of GPU frame capture output. Potential values: - - `MTL.MtCaptureDestinationGPUTraceDocument` for folder output for later + - `MTL.MTLCaptureDestinationGPUTraceDocument` for folder output for later viewing/sharing. (default) - - `MTL.MtCaptureDestinationDeveloperTools` for direct XCode viewing. + - `MTL.MTLCaptureDestinationDeveloperTools` for direct XCode viewing. When profiling the resulting gputrace folder in Xcode, do so one at a time to avoid "no profiling data found" errors. @@ -82,8 +82,8 @@ profiling data found" errors. macro profile(ex...) work = ex[end] kwargs = ex[1:end-1] - dest = MTL.MtCaptureDestinationGPUTraceDocument # default: folder output - capture = global_queue(current_device()) # default: capture global command queue + dest = MTL.MTLCaptureDestinationGPUTraceDocument # default: folder output + capture = global_queue(current_device()) # default: capture global command queue if !isempty(kwargs) for kwarg in kwargs key,val = kwarg.args diff --git a/test/Project.toml b/test/Project.toml index 23a329aa..75fbf189 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -6,6 +6,7 @@ Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b" GPUArrays = "0c68f7d7-f131-5f86-a1c3-88cf8149b2d7" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" Metal_LLVM_Tools_jll = "0418c028-ff8c-56b8-a53e-0f9676ed36fc" +ObjectiveC = "e86c9b32-1129-44ac-8ea0-90d5bb39ded9" Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7" REPL = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" diff --git a/test/array.jl b/test/array.jl index f35b65fa..43a81168 100644 --- a/test/array.jl +++ b/test/array.jl @@ -1,15 +1,13 @@ @testset "arrays" begin -let mtl_arr = MtlArray{Int}(undef, 1) - arr = Array(mtl_arr) - +let arr = MtlArray{Int}(undef, 1) @test sizeof(arr) == 8 @test length(arr) == 1 @test eltype(arr) == Int end -let mtl_arr = MtlArray{Int}(undef, 0) - @test pointer(mtl_arr).buffer.handle == C_NULL +let arr = MtlArray{Int}(undef, 0) + @test sizeof(arr) == 0 end @testset "mtl" begin diff --git a/test/execution.jl b/test/execution.jl index 95a9ed86..c58df36d 100644 --- a/test/execution.jl +++ b/test/execution.jl @@ -38,7 +38,7 @@ end vecA .= 0 dev = current_device() - queue = MtlCommandQueue(dev) + queue = MTLCommandQueue(dev) @metal threads=(3) queue=queue tester(bufferA) synchronize(queue) @test all(vecA == Int.([5, 5, 5, 0, 0, 0, 0, 0])) diff --git a/test/metal.jl b/test/metal.jl index 44947c57..aff291e3 100644 --- a/test/metal.jl +++ b/test/metal.jl @@ -15,7 +15,7 @@ end compact_str = sprint(io->show(io, dev)) full_str = sprint(io->show(io, MIME"text/plain"(), dev)) -@test dev.name isa String +@test dev.name isa NSString @test dev.isLowPower isa Bool @test dev.isRemovable isa Bool @test dev.hasUnifiedMemory isa Bool @@ -24,8 +24,8 @@ full_str = sprint(io->show(io, MIME"text/plain"(), dev)) @test dev.recommendedMaxWorkingSetSize isa Integer @test dev.maxThreadgroupMemoryLength isa Integer -@test dev.maxThreadsPerThreadgroup isa MTL.MtSize -@test dev.argumentBuffersSupport isa MTL.MtArgumentBuffersTier +@test dev.maxThreadsPerThreadgroup isa MTL.MTLSize +@test dev.argumentBuffersSupport isa MTL.MTLArgumentBuffersTier @test dev.maxBufferLength isa Integer @test dev.currentAllocatedSize isa Integer @@ -34,7 +34,7 @@ end @testset "compile options" begin -opts = MtlCompileOptions() +opts = MTLCompileOptions() compact_str = sprint(io->show(io, opts)) full_str = sprint(io->show(io, MIME"text/plain"(), opts)) @@ -53,9 +53,9 @@ end @testset "libraries" begin dev = first(devices()) -opts = MtlCompileOptions() +opts = MTLCompileOptions() -let lib = MtlLibrary(dev, "", opts) +let lib = MTLLibrary(dev, "", opts) @test lib.device == dev @test lib.label === nothing lib.label = "MyLibrary" @@ -64,7 +64,7 @@ let lib = MtlLibrary(dev, "", opts) end metal_code = read(joinpath(@__DIR__, "dummy.metal"), String) -let lib = MtlLibrary(dev, metal_code, opts) +let lib = MTLLibrary(dev, metal_code, opts) @test lib.device == dev @test lib.label === nothing fns = lib.functionNames @@ -74,7 +74,7 @@ let lib = MtlLibrary(dev, metal_code, opts) end binary_path = joinpath(@__DIR__, "dummy.metallib") -let lib = MtlLibraryFromFile(dev, binary_path) +let lib = MTLLibraryFromFile(dev, binary_path) @test lib.device == dev @test lib.label === nothing fns = lib.functionNames @@ -84,7 +84,7 @@ let lib = MtlLibraryFromFile(dev, binary_path) end binary_code = read(binary_path) -let lib = MtlLibraryFromData(dev, binary_code) +let lib = MTLLibraryFromData(dev, binary_code) @test lib.device == dev @test lib.label === nothing fns = lib.functionNames @@ -100,7 +100,7 @@ end @testset "functions" begin -desc = MtlFunctionDescriptor() +desc = MTLFunctionDescriptor() compact_str = sprint(io->show(io, desc)) full_str = sprint(io->show(io, MIME"text/plain"(), desc)) @@ -115,8 +115,8 @@ desc.specializedName = "MySpecializedKernel" dev = first(devices()) -lib = MtlLibraryFromFile(dev, joinpath(@__DIR__, "dummy.metallib")) -fun = MtlFunction(lib, "kernel_1") +lib = MTLLibraryFromFile(dev, joinpath(@__DIR__, "dummy.metallib")) +fun = MTLFunction(lib, "kernel_1") compact_str = sprint(io->show(io, fun)) full_str = sprint(io->show(io, MIME"text/plain"(), fun)) @@ -126,7 +126,7 @@ full_str = sprint(io->show(io, MIME"text/plain"(), fun)) fun.label = "MyKernel" @test fun.label == "MyKernel" @test fun.name == "kernel_1" -@test fun.functionType == MTL.MtFunctionTypeKernel +@test fun.functionType == MTL.MTLFunctionTypeKernel end @@ -134,15 +134,17 @@ end dev = first(devices()) -let ev = MtlEvent(dev) +let ev = MTLEvent(dev) @test ev.device == dev @test ev.label === nothing ev.label = "MyEvent" @test ev.label == "MyEvent" end -let ev = MtlSharedEvent(dev) - @test ev.device == dev +let ev = MTLSharedEvent(dev) + # XXX: this returns nothing, which seems like a Metal bug, + # especially because it does return a device under validation. + #@test ev.device == dev @test ev.label === nothing ev.label = "MyEvent" @test ev.label == "MyEvent" @@ -155,7 +157,7 @@ end dev = first(devices()) -let fen = MtlFence(dev) +let fen = MTLFence(dev) @test fen.device == dev end @@ -165,46 +167,46 @@ end dev = first(devices()) -let desc = MtlHeapDescriptor() - @test desc.type == MTL.MtHeapTypeAutomatic - desc.type = MTL.MtHeapTypePlacement - @test desc.type == MTL.MtHeapTypePlacement +let desc = MTLHeapDescriptor() + @test desc.type == MTL.MTLHeapTypeAutomatic + desc.type = MTL.MTLHeapTypePlacement + @test desc.type == MTL.MTLHeapTypePlacement @test desc.size == 0 desc.size = 1024 @test desc.size == 1024 - @test desc.storageMode == MTL.MtStorageModePrivate - desc.storageMode = MTL.MtStorageModeShared - @test desc.storageMode == MTL.MtStorageModeShared + @test desc.storageMode == MTL.MTLStorageModePrivate + desc.storageMode = MTL.MTLStorageModeShared + @test desc.storageMode == MTL.MTLStorageModeShared - @test desc.cpuCacheMode == MTL.MtCPUCacheModeDefaultCache - desc.cpuCacheMode = MTL.MtCPUCacheModeWriteCombined - @test desc.cpuCacheMode == MTL.MtCPUCacheModeWriteCombined + @test desc.cpuCacheMode == MTL.MTLCPUCacheModeDefaultCache + desc.cpuCacheMode = MTL.MTLCPUCacheModeWriteCombined + @test desc.cpuCacheMode == MTL.MTLCPUCacheModeWriteCombined - @test desc.hazardTrackingMode == MTL.MtHazardTrackingModeDefault - desc.hazardTrackingMode = MTL.MtHazardTrackingModeUntracked - @test desc.hazardTrackingMode == MTL.MtHazardTrackingModeUntracked + @test desc.hazardTrackingMode == MTL.MTLHazardTrackingModeDefault + desc.hazardTrackingMode = MTL.MTLHazardTrackingModeUntracked + @test desc.hazardTrackingMode == MTL.MTLHazardTrackingModeUntracked - @test desc.resourceOptions == MTL.MtResourceStorageModeShared | - MTL.MtResourceCPUCacheModeWriteCombined | - MTL.MtResourceHazardTrackingModeUntracked - desc.resourceOptions = MTL.MtResourceStorageModePrivate | - MTL.MtResourceCPUCacheModeDefaultCache | - MTL.MtResourceHazardTrackingModeDefault - @test desc.resourceOptions == MTL.MtResourceStorageModePrivate | - MTL.MtResourceCPUCacheModeDefaultCache | - MTL.MtResourceHazardTrackingModeDefault + @test desc.resourceOptions == MTL.MTLResourceStorageModeShared | + MTL.MTLResourceCPUCacheModeWriteCombined | + MTL.MTLResourceHazardTrackingModeUntracked + desc.resourceOptions = MTL.MTLResourceStorageModePrivate | + MTL.MTLResourceCPUCacheModeDefaultCache | + MTL.MTLResourceHazardTrackingModeDefault + @test desc.resourceOptions == MTL.MTLResourceStorageModePrivate | + MTL.MTLResourceCPUCacheModeDefaultCache | + MTL.MTLResourceHazardTrackingModeDefault # setting resource options should be reflected in individual fields - @test desc.storageMode == MTL.MtStorageModePrivate - @test desc.cpuCacheMode == MTL.MtCPUCacheModeDefaultCache - @test desc.hazardTrackingMode == MTL.MtHazardTrackingModeDefault + @test desc.storageMode == MTL.MTLStorageModePrivate + @test desc.cpuCacheMode == MTL.MTLCPUCacheModeDefaultCache + @test desc.hazardTrackingMode == MTL.MTLHazardTrackingModeDefault end -desc = MtlHeapDescriptor() +desc = MTLHeapDescriptor() desc.size = 0x4000 # TODO: use heapBufferSizeAndAlign -let heap = MtlHeap(dev, desc) +let heap = MTLHeap(dev, desc) @test heap.label === nothing heap.label = "MyHeap" @test heap.label == "MyHeap" @@ -230,12 +232,12 @@ end dev = first(devices()) -buf = MtlBuffer(dev, 8; storage=Shared) +buf = MTLBuffer(dev, 8; storage=Shared) @test buf.length == 8 @test sizeof(buf) == 8 -# MtlResource properties +# MTLResource properties @test buf.device == dev @test buf.label === nothing buf.label = "MyBuffer" @@ -252,7 +254,7 @@ end dev = first(devices()) -cmdq = MtlCommandQueue(dev) +cmdq = MTLCommandQueue(dev) @test cmdq.device == dev @test cmdq.label === nothing @@ -264,10 +266,10 @@ end @testset "command buffer" begin dev = first(devices()) -cmdq = MtlCommandQueue(dev) +cmdq = MTLCommandQueue(dev) -cmdbuf = MtlCommandBuffer(cmdq) +cmdbuf = MTLCommandBuffer(cmdq) @test cmdbuf.device == dev @test cmdbuf.commandQueue == cmdq @@ -275,13 +277,13 @@ cmdbuf = MtlCommandBuffer(cmdq) cmdbuf.label = "MyCommandBuffer" @test cmdbuf.label == "MyCommandBuffer" @test cmdbuf.error === nothing -@test cmdbuf.status == MTL.MtCommandBufferStatusNotEnqueued +@test cmdbuf.status == MTL.MTLCommandBufferStatusNotEnqueued @test cmdbuf.kernelStartTime == 0 @test cmdbuf.kernelEndTime == 0 -@test cmdbuf.gpuStartTime == 0 -@test cmdbuf.gpuEndTime == 0 +@test cmdbuf.GPUStartTime == 0 +@test cmdbuf.GPUEndTime == 0 -let ev = MtlSharedEvent(dev) +let ev = MTLSharedEvent(dev) @test ev.signaledValue == 0 encode_signal!(cmdbuf, ev, 42) encode_wait!(cmdbuf, ev, 21) @@ -290,25 +292,25 @@ let ev = MtlSharedEvent(dev) @test ev.signaledValue == 42 end -cmdbuf = MtlCommandBuffer(cmdq) +cmdbuf = MTLCommandBuffer(cmdq) scheduled = Ref(false) completed = Ref(false) -on_scheduled(cmdbuf) do +on_scheduled(cmdbuf) do buf scheduled[] = true end -on_completed(cmdbuf) do +on_completed(cmdbuf) do buf completed[] = true end @test scheduled[] == false @test completed[] == false -@test cmdbuf.status == MTL.MtCommandBufferStatusNotEnqueued +@test cmdbuf.status == MTL.MTLCommandBufferStatusNotEnqueued enqueue!(cmdbuf) -@test cmdbuf.status == MTL.MtCommandBufferStatusEnqueued +@test cmdbuf.status == MTL.MTLCommandBufferStatusEnqueued commit!(cmdbuf) # XXX: happens too quickly to test for committed status -#@test cmdbuf.status == MTL.MtCommandBufferStatusCommitted -wait_completed(cmdbuf) == MTL.MtCommandBufferStatusCompleted -@test cmdbuf.status == MTL.MtCommandBufferStatusCompleted +#@test cmdbuf.status == MTL.MTLCommandBufferStatusCommitted +wait_completed(cmdbuf) == MTL.MTLCommandBufferStatusCompleted +@test cmdbuf.status == MTL.MTLCommandBufferStatusCompleted retry(; delays=[0, 0.1, 1]) do scheduled[] || error("scheduled callback not called") completed[] || error("completed callback not called") @@ -317,33 +319,33 @@ end() @test completed[] == true -desc = MtlCommandBufferDescriptor() +desc = MTLCommandBufferDescriptor() @test desc.retainedReferences == true desc.retainedReferences = false @test desc.retainedReferences == false -@test desc.errorOptions == MTL.MtCommandBufferErrorOptionNone -desc.errorOptions = MTL.MtCommandBufferErrorOptionEncoderExecutionStatus -@test desc.errorOptions == MTL.MtCommandBufferErrorOptionEncoderExecutionStatus +@test desc.errorOptions == MTL.MTLCommandBufferErrorOptionNone +desc.errorOptions = MTL.MTLCommandBufferErrorOptionEncoderExecutionStatus +@test desc.errorOptions == MTL.MTLCommandBufferErrorOptionEncoderExecutionStatus -cmq = MtlCommandQueue(current_device()) -cmdbuf = MtlCommandBuffer(cmq, desc) +cmq = MTLCommandQueue(current_device()) +cmdbuf = MTLCommandBuffer(cmq, desc) if !runtime_validation # when the debug layer is activated, Metal seems to retain all resources? @test cmdbuf.retainedReferences == false end -@test cmdbuf.errorOptions == MTL.MtCommandBufferErrorOptionEncoderExecutionStatus +@test cmdbuf.errorOptions == MTL.MTLCommandBufferErrorOptionEncoderExecutionStatus end @testset "compute pipeline" begin dev = first(devices()) -lib = MtlLibraryFromFile(dev, joinpath(@__DIR__, "dummy.metallib")) -fun = MtlFunction(lib, "kernel_1") +lib = MTLLibraryFromFile(dev, joinpath(@__DIR__, "dummy.metallib")) +fun = MTLFunction(lib, "kernel_1") -pipeline = MtlComputePipelineState(dev, fun) +pipeline = MTLComputePipelineState(dev, fun) @test pipeline.device == dev @test pipeline.label === nothing @@ -353,7 +355,7 @@ pipeline = MtlComputePipelineState(dev, fun) @test pipeline.staticThreadgroupMemoryLength == 0 -desc = MtlComputePipelineDescriptor() +desc = MTLComputePipelineDescriptor() compact_str = sprint(io->show(io, desc)) full_str = sprint(io->show(io, MIME"text/plain"(), desc)) @@ -383,20 +385,20 @@ end @testset "binary archive" begin dev = first(devices()) -lib = MtlLibraryFromFile(dev, joinpath(@__DIR__, "dummy.metallib")) -fun = MtlFunction(lib, "kernel_1") +lib = MTLLibraryFromFile(dev, joinpath(@__DIR__, "dummy.metallib")) +fun = MTLFunction(lib, "kernel_1") -desc = MtlBinaryArchiveDescriptor() -bin = MtlBinaryArchive(dev, desc) +desc = MTLBinaryArchiveDescriptor() +bin = MTLBinaryArchive(dev, desc) compact_str = sprint(io->show(io, desc)) full_str = sprint(io->show(io, MIME"text/plain"(), desc)) @test desc.url === nothing -desc.url = "/tmp/foo" -@test desc.url == "/tmp/foo" +desc.url = NSFileURL("/tmp/foo") +@test desc.url == NSFileURL("/tmp/foo") -pipeline_desc = MtlComputePipelineDescriptor() +pipeline_desc = MTLComputePipelineDescriptor() pipeline_desc.computeFunction = fun if !runtime_validation # XXX: for some reason, this crashes under the validator @@ -421,11 +423,11 @@ end B = MtlArray(rand(Float32, N)) a = Array{Float32}(undef, N) - queue1 = Metal.MtlCommandQueue(dev) - queue2 = Metal.MtlCommandQueue(dev) - buf1 = Metal.MtlCommandBuffer(queue1) - buf2 = Metal.MtlCommandBuffer(queue2) - event = Metal.MtlEvent(dev) + queue1 = Metal.MTLCommandQueue(dev) + queue2 = Metal.MTLCommandQueue(dev) + buf1 = Metal.MTLCommandBuffer(queue1) + buf2 = Metal.MTLCommandBuffer(queue2) + event = Metal.MTLEvent(dev) Metal.encode_wait!(buf2, event, signal_value) diff --git a/test/profiling.jl b/test/profiling.jl index 02081387..74960f61 100644 --- a/test/profiling.jl +++ b/test/profiling.jl @@ -12,38 +12,36 @@ function tester(A) end # Capture Manager -manager = MtlCaptureManager() -@test manager.supportsTraceXcode isa Bool -@test manager.supportsTraceFile isa Bool +manager = MTLCaptureManager() @test manager.isCapturing isa Bool # Capture Descriptor -desc = MtlCaptureDescriptor() +desc = MTLCaptureDescriptor() # Capture Object @test desc.captureObject == nothing cmdq = global_queue(current_device()) desc.captureObject = cmdq -@test desc.captureObject == cmdq.handle +@test desc.captureObject == cmdq dev = current_device() desc.captureObject = dev -@test desc.captureObject == dev.handle +@test desc.captureObject == dev # Capture Destination -@test desc.destination == MTL.MtCaptureDestinationDeveloperTools -desc.destination = MTL.MtCaptureDestinationGPUTraceDocument -@test desc.destination == MTL.MtCaptureDestinationGPUTraceDocument +@test desc.destination == MTL.MTLCaptureDestinationDeveloperTools +desc.destination = MTL.MTLCaptureDestinationGPUTraceDocument +@test desc.destination == MTL.MTLCaptureDestinationGPUTraceDocument # Output URL -@test desc.outputFolder == nothing +@test desc.outputURL == nothing path = joinpath(tmpdir, "test.gputrace") -desc.outputFolder = path -@test desc.outputFolder == path +desc.outputURL = NSFileURL(path) +@test desc.outputURL == NSFileURL(path) # Capture Scope -queue = MtlCommandQueue(current_device()) +queue = MTLCommandQueue(current_device()) default_scope = manager.defaultCaptureScope @test default_scope == nothing -new_scope = MtlCaptureScope(Metal.MTL.mtNewCaptureScopeWithCommandQueue(manager, queue)) +new_scope = MTLCaptureScope(@objc [manager::id{MTLCaptureManager} newCaptureScopeWithCommandQueue:queue::id{MTLCommandQueue}]::id{MTLCaptureScope}) @test new_scope.commandQueue == queue @test new_scope.device == current_device() @test new_scope.label == nothing diff --git a/test/runtests.jl b/test/runtests.jl index 0f6f535e..c8ca46c8 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -42,7 +42,6 @@ do_quickfail, _ = extract_flag!(ARGS, "--quickfail") include("setup.jl") # make sure everything is precompiled @info "System information:\n" * sprint(io->Metal.versioninfo(io)) -@info "Using cmt library from $(dirname(MTL.cmt.libcmt))" metallib_as_version = Metal.Metal_LLVM_Tools_jll.Metal_LLVM_Tools_jll.metallib_as() do metallib_as read(`$metallib_as --version`, String) end diff --git a/test/setup.jl b/test/setup.jl index 265fb5d8..982cf496 100644 --- a/test/setup.jl +++ b/test/setup.jl @@ -1,4 +1,4 @@ -using Distributed, Test, Metal, Adapt +using Distributed, Test, Metal, Adapt, ObjectiveC, ObjectiveC.Foundation # GPUArrays has a testsuite that isn't part of the main package. # Include it directly.