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
3
votes
4 answers

Recording of metal view is slow due to texture.getbytes function - Swift

I am using this post for recording a custom metal view, but I am experiencing some issues. When I start recording I go from 60fps to ~20fps on a iPhone 12 Pro Max. After Profiling, the function that is slowing everything is texture.getBytes, as it…
jmrueda
  • 1,362
  • 19
  • 30
3
votes
2 answers

How to draw on MTLTexture in bgra8Unorm pixel format

My code works when I draw on MTLTexture with rgba32Float pixel format, I can take then CVPixelBuffer out of it. But FlutterTexture requires bgra8Unorm format. I do not want to convert CVPixelBuffer due to performance overhead. So I'm trying to…
Dmytro Rostopira
  • 10,588
  • 4
  • 64
  • 86
3
votes
1 answer

SwiftUI macOS view starts lagging when displaying multiple charts

I am displaying multiple charts in a view. The charts are just paths in a frame and data comes from an csv file (not bigger than 400mb). Those charts are displayed inside of a LazyVGrid and the whole view is inside a scroll view. Loading the view…
DoTryCatch
  • 1,052
  • 6
  • 17
3
votes
1 answer

Antialiasing a SceneKit rendering with Metal

I'm new to Metal. I'm rendering a SceneKit scene with Metal using this Apple sample code. TLDR; it calls the SCNRenderer's render function and passes in a command buffer. I'm compiling for Big Sur. It works, but it is not anti-aliased. I've tried a…
Morten J
  • 814
  • 10
  • 21
3
votes
2 answers

Resulting MTLTexture lighter than CGImage

I have kernel func which must convert Y and CbCr textures created from pixelBuffer(ARFrame.capturedImage) to RGB texture like in apple guide https://developer.apple.com/documentation/arkit/displaying_an_ar_experience_with_metal But I get over…
3
votes
1 answer

MTKView always render the background color to red

I want to use MTKView on Mac app. After init the MTKView, it appears red instead of the expected clear color on My laptop is MacBook Pro of macOS Catalina 10.15.2, and it render black background on a iMac of macOS Mojave 10.14.6 I try to exchange…
guojing
  • 129
  • 14
3
votes
0 answers

How to replace MTLTexture getBytes:bytesPerRow:fromRegion:mipmapLevel: with MTLBlitCommandEncoder?

the apple doc of MTLTexture getBytes:bytesPerRow:fromRegion:mipmapLevel: say Don't use this for textures with a private storage mode. To copy data from a private texture, use a MTLBlitCommandEncoder to copy the data from the private texture to…
zeus
  • 12,173
  • 9
  • 63
  • 184
3
votes
0 answers

How to use Metal to draw shapes on a rendered image without redrawing the whole texture?

I'm trying to understand GPU image processing with Metal and have successfully manipulated and rendered images onto a screen. I currently render my manipulated image by using a custom vertex and fragment shader that takes in the size of the texture…
Christina
  • 51
  • 2
3
votes
1 answer

When to use setVertexBytes/setVertexBuffer when dealing with small data in Metal?

The documentation for setVertexBytes says: Use this method for single-use data smaller than 4 KB. Create a MTLBuffer object if your data exceeds 4 KB in length or persists for multiple uses. What exactly does single-use mean? For example, if I…
3
votes
1 answer

MTLCreateSystemDefaultDevice returning nil on iOS 13 Simulator

I am using Xcode 11 GM Seed (11A419c). When I run Metal code on iOS 13 simulator and try to access metal device created using MTLCreateSystemDefaultDevice(), it returns nil. How is Metal supposed to run on simulator without this device? Is there any…
Deepak Sharma
  • 5,577
  • 7
  • 55
  • 131
3
votes
1 answer

Convert a CGImage to MTLTexture without premultiplication

I have a UIImage which I've previously created from a png file: let strokeUIImage = UIImage(data: pngData) I want to convert strokeImage (which has opacity) to an MTLTexture for display in an MTKView, but doing the conversion seems to perform an…
Plutovman
  • 677
  • 5
  • 22
3
votes
1 answer

Rendering small CIImage centered in MTKView

I'm rendering a CIImage to MTKView and the image is smaller than the drawable. let centered = image.transformed(by: CGAffineTransform(translationX: (view.drawableSize.width - image.extent.width) / 2, y: (view.drawableSize.height -…
Dannie P
  • 4,464
  • 3
  • 29
  • 48
3
votes
1 answer

MTKTextureLoader causing banding in grayscale image

I'm trying to implement a simple LUT color grade in a metal shader. It works with a color LUT, but when the LUT is grayscale, problems crop up. First, loading the grayscale image causes an "image decoding failed" error, which is fixed with this bug…
Ian
  • 2,078
  • 1
  • 17
  • 27
3
votes
0 answers

Writing Textures using Kernel

In single pass (In a single draw cycle) to the shader How many maximum Textures we can draw at once in metal using Kernel ? I have tried to draw six squared textures in a draw cycle.When the textures points overlap actual texture is not presented as…
Ruban4Axis
  • 821
  • 6
  • 27
3
votes
1 answer

When is an MTLFence or MTLEvent required for synchronization between command encoders?

Note: In many ways, this is a follow-up to How do you synchronize a Metal Performance Shader with an MTLBlitCommandEncoder? I'm still a bit confused when explicit synchronization is required between sequential command encoders and when…
kennyc
  • 5,490
  • 5
  • 34
  • 57