Questions tagged [metalkit]

Use this tag for questions MetalKit, a framework that provides functions and classes intended to reduce the effort required to create a Metal application. Consider using a more specific tag such as [mtkview] or [mtktextureloader].

MetalKit is a framework that first appeared in iOS 9 and OS X El Capitan. It provides functions and classes intended to reduce the effort required to create a Metal application.

The following functions are the three key areas MetalKit provides:

  • Texture Loading enables your application to load textures from various sources easily. Loading of textures can be achieved in an asynchronous way with only a few lines of code. For more information, please see the MTKTextureLoader Class Reference.
  • Model Handling enables Metal-specific functionality to easily interface with Model I/O assets; these highly-optimized functions and objects make up of a collection that enables efficient data transfer between Metal buffers and Model I/O.
  • View Management provides a standard implementation of a Metal view and an optional drawing delegate, which reduce greatly the amount of code needed to generate graphics rendering in Metal app. For more information, please see the MTKView Class Reference and MTKViewDelegate Protocol Reference.

This tag is appropriate for general questions about MetalKit. Specific questions about any of the aformentioned functions should use a more specific tag instead, such as or .

400 questions
4
votes
1 answer

Metal RGB to YUV conversion compute shader

I am trying to write a Metal compute shader for converting from RGB to YUV, but am getting build errors. typedef struct { float3x3 matrix; float3 offset; } ColorConversion; // Compute kernel kernel void kernelRGBtoYUV(texture2d
Deepak Sharma
  • 5,577
  • 7
  • 55
  • 131
4
votes
2 answers

MTKView - Resizing Texture To Fill View

I am very new to Metal, but diligently working to follow Apple's AVCamFilter sample project. The project demonstrates using a MTKView as a preview for an AVCaptureSession. I have been unsuccessful in figuring out how to have my MTKView render "full…
ZbadhabitZ
  • 2,753
  • 1
  • 25
  • 45
4
votes
0 answers

Is a large MTLTexture more performant than using multiple smaller MTLTextures?

I'm using Metal to display an image into a 2D plane. The image is being rendered as tiles to an IOSurface using Core Image. After each tile is rendered, the IOSurface is sent via XPC to the app, wrapped in an MTLTexture and its contents are copied…
kennyc
  • 5,490
  • 5
  • 34
  • 57
4
votes
1 answer

Distorting a view in iOS using Metal

Question: How can I capture a view to be modified in Metal? My (probably incomplete) understanding is that I need to capture the view as a texture, move it into device memory, do work on it with shaders, and then render it back into the view. I'm…
Erik
  • 2,299
  • 4
  • 18
  • 23
4
votes
1 answer

How do I use MetalKit texture loader with Metal heaps?

I have a set of Metal textures that are stored in an Xcode Assets Catalog as Texture Sets. I'm loading these using MTKTextureLoader.newTexture(name:scaleFactor:bundle:options). I then use a MTLArgumentEncoder to encode all of the textures into a…
OliverD
  • 1,074
  • 13
  • 19
4
votes
1 answer

Metal Best Practice: Triple-buffering – Textures too?

In the Metal Best Practices Guide, it states that for best performance one should "implement a triple buffering model to update dynamic buffer data," and that "dynamic buffer data refers to frequently updated data stored in a buffer." Does an…
Tricky
  • 7,025
  • 5
  • 33
  • 43
4
votes
1 answer

How to convert a MTLTexture to CVpixelBuffer to write into an AVAssetWriter?

I have a requirement to apply filters on the live video and I'm trying to do it in Metal. But I have encountered problem with converting the MTLTexture into CVPixelBuffer after encoding the filter into destination filter. Reference…
4
votes
1 answer

ModelIO Framework Not Working

I'm trying to import 3D model files and render them with Metal using ModelIO and MetalKit (on OS X 10.11), but the behavior I'm seeing from these frameworks (specifically ModelIO) is not as expected. I can import .obj files and convert them to…
lcmylin
  • 2,552
  • 2
  • 19
  • 31
3
votes
1 answer

Apple Metal iOS why does GLKMatrix4MakeLookAt rock back and forth

I am developing a 3D scene on iOS 16.1 with Xcode 14.3. I have a rectangular plane orbiting the origin at an incline and I want to use GLKMatrix4MakeLookAt to cause the plane to always face the origin. I am using the code below. The plane does…
PhilBot
  • 748
  • 18
  • 85
  • 173
3
votes
0 answers

Adding UV Map to Model IO MDLMesh

I'm trying to generate UV map for a mesh using Model/IO. The code runs on the simulator and generates a UV map for the input mesh but when I run it on a device it crashes on mdlMesh.addUnwrappedTextureCoordinates(forAttributeNamed:…
3
votes
1 answer

Specify sampling method in Metal Core Image Kernel

In Metal we can create samplers like this constexpr sampler s(coord::normalized, address::clamp_to_edge, filter::linear); Then we can sample any texture using this sampler. I am wondering if something similar is available in Metal Core Image…
Deepak Sharma
  • 5,577
  • 7
  • 55
  • 131
3
votes
1 answer

How do I convert an OpenGL GLKView to a MTLKit Metal based View?

A few years ago, Apple started warning anyone using GLKit in their app that OpenGL was going away: warning: OpenGLES is deprecated. Consider migrating to Metal instead warning: GLKit is deprecated. Consider migrating to MetalKit instead My app…
David H
  • 40,852
  • 12
  • 92
  • 138
3
votes
0 answers

Making use of Metal's volatile MTLPurgeableState while triple buffering

I have a number of cached MTLTexture's which I would like to set to purgeable using MTLTexture's setPurgeableState API. In order to do this I follow the process outlined in Apple's 2019 WWDC video which suggests: Setting cached MTLTexture instances…
ndg
  • 2,585
  • 2
  • 33
  • 58
3
votes
2 answers

My custom metal image filter is slow. How can I make it faster?

I've seen a lot of other's online tutorial that are able to achieve 0.0X seconds mark on filtering an image. Meanwhile my code here took 1.09 seconds to filter an image.(Just to reduce brightness by half). edit after first comment time measured with…
3
votes
1 answer

How to bind a variable number of textures to Metal shader?

On the CPU I'm gathering an array of MTLTexture objects that I want to send to the fragment shader. There can be any number of these textures at any given moment. How can I send a variable-length array of MTLTextures to a fragment…
iosdev55
  • 129
  • 1
  • 6