{"id":19141079,"url":"https://github.com/computer-graphics-tools/metal-tools","last_synced_at":"2025-12-11T22:59:26.732Z","repository":{"id":63909553,"uuid":"402696053","full_name":"computer-graphics-tools/metal-tools","owner":"computer-graphics-tools","description":"A Swift framework that simplifies working with Apple's Metal API.","archived":false,"fork":false,"pushed_at":"2025-02-07T16:55:45.000Z","size":3606,"stargazers_count":64,"open_issues_count":1,"forks_count":5,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-05-06T23:18:16.357Z","etag":null,"topics":["computer-graphics","metal","swift"],"latest_commit_sha":null,"homepage":"https://swiftpackageindex.com/computer-graphics-tools/metal-tools","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/computer-graphics-tools.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-09-03T08:14:11.000Z","updated_at":"2025-04-12T04:51:33.000Z","dependencies_parsed_at":"2024-03-24T15:23:20.256Z","dependency_job_id":"60ac2845-7648-48b6-bf76-9a04e34cddfe","html_url":"https://github.com/computer-graphics-tools/metal-tools","commit_stats":{"total_commits":22,"total_committers":1,"mean_commits":22.0,"dds":0.0,"last_synced_commit":"be1014109e096ea0f716623714a8be837d2a003b"},"previous_names":["computer-graphics-tools/metal-tools","eugenebokhan/metal-tools"],"tags_count":24,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/computer-graphics-tools%2Fmetal-tools","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/computer-graphics-tools%2Fmetal-tools/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/computer-graphics-tools%2Fmetal-tools/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/computer-graphics-tools%2Fmetal-tools/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/computer-graphics-tools","download_url":"https://codeload.github.com/computer-graphics-tools/metal-tools/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252782835,"owners_count":21803410,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["computer-graphics","metal","swift"],"created_at":"2024-11-09T07:20:18.676Z","updated_at":"2025-12-11T22:59:26.693Z","avatar_url":"https://github.com/computer-graphics-tools.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MetalTools\n\n[![Platform Compatibility](https://img.shields.io/badge/Platforms-iOS%20|%20macOS-brightgreen)](https://swift.org/platforms/)\n[![Swift Version](https://img.shields.io/badge/Swift-5.9-orange)](https://swift.org)\n\n\u003cp align=\"left\"\u003e\n    \u003cimg src=\"Sources/MetalTools/MetalTools.docc/Resources/table-of-contents-art/metal-tools@2x.png\", width=\"120\"\u003e\n\u003c/p\u003e\n\n## Description\n\nMetalTools provides a convenient, Swifty way of working with Metal. This library is heavily used in computer vision startups [ZERO10](https://zero10.ar) and [Prisma](https://prisma-ai.com).\n\n## Usage\n\nPlease see [the package's documentation](https://swiftpackageindex.com/computer-graphics-tools/metal-tools/documentation/metaltools)\nfor the detailed usage instructions.\n\n### MTLContext\n\n`MTLContext` is a central component of the MetalTools framework, designed to streamline Metal-based operations. It encapsulates an `MTLDevice` and an `MTLCommandQueue`, providing a unified interface for common Metal tasks.\n\n```swift\nimport MetalTools\n\ndo {\n    let context = try MTLContext()\n    // Use the context for further operations\n} catch {\n    print(\"Failed to create MTLContext: \\(error)\")\n}\n```\n\n### Dispatch command buffers in both sync/async manner\n\nSee how you can group encodings with Swift closures.\n\n```swift\nself.context.scheduleAndWait { buffer in\n    buffer.compute { encoder in\n      // compute command encoding logic\n    }\n\n    buffer.blit { encoder in\n      // blit command encoding logic\n    }\n}\n```\n\n### Set resources to Command Encoder\n\n```swift\nencoder.setTextures(source, destination)\nencoder.setValue(affineTransform, at: 0)\n```\n\n### Easily create textures from CGImage\n\n```swift\nlet texture = try context.texture(\n    from: cgImage,\n    usage: [.shaderRead, .shaderWrite]\n)\n```\n\n### Serialize and deserialize MTLTexture\n\n```swift\nlet encoder = JSONEncoder()\nlet data = try encoder.encode(texture.codable())\n\nlet decoder = JSONDecoder()\nlet decodableTexture = try decoder.decode(MTLTextureCodableBox.self, from: data)\nlet decodedTexture = try decodableTexture.texture(device: self.context.device)\n```\n\n### Load a compute pipeline state for a function that sits in a framework\n\n```swift\nlet library = context.library(for: Foo.self)\nlet computePipelineState = try lib.computePipelineState(function: \"brightness\")\n```\n\n### Allocate buffer by value type\n\n```swift\nlet buffer = context.buffer(\n    for: InstanceUniforms.self,\n    count: 99,\n    options: .storageModeShared\n)\n```\n\n### Setup blending mode in render passes\n\n```swift\nlet renderPipelineDescriptor = MTLRenderPipelineDescriptor()\nrenderPipelineDescriptor.colorAttachments[0].setup(blending: .alpha)\n```\n\n### Other things\n\n- [Ready-to-use compute kernels](Sources/MetalComputeTools/Kernels)\n- [Simple geometry renderers](Sources/MetalRenderingTools/Renderers)\n- Create multi-sample render target pairs\n- Create depth buffers\n- Create depth / stencil states\n- and more!\n\n## License\n\nMetalTools is licensed under [MIT license](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcomputer-graphics-tools%2Fmetal-tools","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcomputer-graphics-tools%2Fmetal-tools","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcomputer-graphics-tools%2Fmetal-tools/lists"}