Questions tagged [metal]
Metal is a proprietary framework for GPU-accelerated advanced 3D graphics rendering and data-parallel computation workloads. Made by Apple.
2,076
questions
2
votes
1
answer
39
views
Integrating a metal depth buffer with scenekit rendering
I'm using Metal to render a scene with a z buffer and now need to integrate this z-buffer into SceneKit's rendering. However I can't figure out how to get SceneKit to use this depth better correctly ...
1
vote
0
answers
27
views
Triangle mesh in Metal
I'm trying to create triangle 2D mesh using SwiftUI & Metal. I have lists of vertices[929 items] and indices[1750 items] to draw a mesh. I have used method .drawIndexedPrimitives, but it isn't ...
1
vote
0
answers
24
views
Can MetalFX scalers support textures with alpha?
I'm trying to upscale a texture using MetalFX's MTLFXSpatialScaler. The input texture has transparency (it's rgba8Unorm) but in the scaled texture, the transparency has been removed so that previous ...
0
votes
0
answers
21
views
Metal assertion `A command encoder is already encoding to this command buffer`
I am using Metal in my project and I have encapsulated some of the kernels as functions kind of the same way as MetalPerformanceShaders suggests.
So each my Metal kernel has Objective-C class with the ...
0
votes
0
answers
18
views
Metal fragment shader receives incorrect interpolated vertex z values
I have a simple vertex shader that outputs position and color and a fragment shader that outputs color. There is also depth testing enabled with a texture that I created.
struct VertexOut {
float4 ...
1
vote
1
answer
28
views
How to import Metal Shaders and Headers from SPM to use inside other local shaders
I'm trying to link a Swift Package with some helper shaders (.metal) and types (in header .h).
I'd like to be able to import those shader functions in the local project's metal shaders to use them. ...
-2
votes
0
answers
20
views
Convert a .3dl file to Metal Texture?
I am trying to convert .3dl to Metal Texture on iOS device in Swift language, then a 3D color lookup table can read from a Metal texture for photo filters. But I don't know how to parse .3dl file. Any ...
-1
votes
1
answer
52
views
Metal API, GetBytes Validation rowBytes(1600) must be >= (4680)
Metal experts!
I'm struggling with the following error:
failed assertion `GetBytes Validation rowBytes(1600) must be >= (4680)
at
texture.getBytes(pixelBufferBytes, bytesPerRow: bytesPerRow, from: ...
-1
votes
0
answers
23
views
Metal CubeMaps reversed +Y and -Y
I am loading a cubemap using assets and MTKTextureLoader but the +Y and -Y images are always reversed. What I mean is I need to put the +Y image in the -Y and vice versa for the cubemap to sample ...
0
votes
0
answers
23
views
Citrix Workspace - Disable MacOS Metal on Client side
Maybe people are running MacOS on unsupported Mac computers. Everything works except the METAL Graphics (more or less - it depends on the GPU). That causes the Citrix Workspace client to show a grey ...
0
votes
0
answers
31
views
Using MPSGraph.reductionSum on a specific axis
I have the following function:
let mtlDevice = MTLCreateSystemDefaultDevice()!
let device = MPSGraphDevice(mtlDevice: mtlDevice)
let inputData: [UInt32] = [0, 45, 0, 0, 45, 81, 0, 54, 0, 0, 54, 81, 1,...
0
votes
0
answers
18
views
Metal: Instance a Fragment Function?
I’m a beginner to MSL, I’ve written a pair of vertex and fragment shaders. The fragment shader takes a material argument to implement phong lighting. I then learned about instancing and modified my ...
1
vote
0
answers
44
views
How do you take advantage of Metal 3's argument buffers in swift?
In Metal 3, argument buffer's are able to be accesed (from my understanding) by passing a memory address in the form of a uint64_t, with the gpuAddress of a buffer.
obj c
struct Scene
{
// The ...
0
votes
0
answers
54
views
Crash when set CAMetalLayer.presentsWithTransaction=true in background thread
When set metalLayer.presentsWithTransaction = true, and when I call nextDrawable.present() in bg thread (our rendering thread is not main thread), the app sometimes will crash with:
*** Terminating ...
-1
votes
1
answer
27
views
Convert fragment shader (in GLSL) to Metal Shader code [closed]
The following code needs to be converted to Metal for Xcode:
uniform sampler2D emissionTexture;
vec3 light = _lightingContribution.diffuse;
float lum = max(0.0, 1 - (0.2126*light.r + 0.7152*light.g + ...
2
votes
1
answer
96
views
How to make a frosted glass effect on SceneKit
On my SceneKit node, I want to apply a frosted glass effect like this:
https://www.shadertoy.com/view/WdSGz1
This shader takes a texture as input and outputs a "blurry" version of the ...
0
votes
0
answers
39
views
iOS MetalKit: Loop through array in MSL
This seems to be a silly question, but I can't find a good way to loop through an array and currently, I have to pass a buffer that contains the element count to my kernel function.
kernel void ...
0
votes
0
answers
26
views
Problems when capturing video using AVCaptureVideoDataOutput and AVCaptureAudioDataOutput
fellow developers!
I am working on an application for photo and video shooting with the ability to apply filters of the Core Image to frames right during shooting. Rendering and displaying frames ...
0
votes
0
answers
38
views
Error installing tensor flow-metal plugin
I followed the instruction to install the tensorflow-metal plugin, but when I ran the verification example found on the website I am getting these errors
2023-01-07 16:51:14.262420: I tensorflow/core/...
0
votes
0
answers
31
views
Negating `function_constant()` call for conditionally omitting struct fields in Metal shading language
so it appears that Apple Metal got away with preprocessor directives, opting to use function constants for optionally enabling / disabling parts of shader code.
I can conditionally enable certain ...
-1
votes
1
answer
81
views
Metal Sampler ::linear doesn't work as expected
My source image is a 512x512 pixels checkerboard (see source image). When I render it to 1/3 of its size (170,6.. x 170,6..) the result looks like it is downsized with the ::nearest filter. I expect ...
1
vote
0
answers
28
views
MDLMesh strange buffer layout
I was curious to see the vertex positions of an MDLMesh for a boxWithExtent and I have notices a strange behaviour. When I print out the positions and normals for the first 3 vertices you get the ...
0
votes
1
answer
61
views
CAMetalLayer.nextDrawable takes much time, even more than 8ms
CAMetalLayer.nextDrawable() should not be a very time-comsuming method.But sometimes it often takes much time, even more than 8ms
Copy the code below
Follow the comment guide in viewDidLoad
See the ...
0
votes
0
answers
33
views
Recommended way to merge layers of textures in Metal?
Say I have a tree of graphics objects, and each one renders itself into a 'layer' – a Metal texture. Then as a final step I want to merge all these layers into one final output image, to display to ...
0
votes
1
answer
550
views
Tensorflow Error on Macbook M1 Pro - NotFoundError: Graph execution error
I've installed Tensorflow on a Macbook Pro M1 Max Pro by first using Anaconda to install the dependencies:
conda install -c apple tensorflow-deps
Then after, I install the Tensorflow distribution ...
1
vote
0
answers
26
views
Something like vertex_id for Metal fragment shader, to identify fragment?
Vertex shaders in Metal can use a [[vertex_id]] attribute on an integer argument, and that argument will get values between 0 and the number of vertexes. Is there a similar thing for fragment shaders?...
0
votes
1
answer
33
views
PyTorch memory leak reference cycle in for loop
I am facing a memory leak when iteratively updating tensors in PyTorch on my Mac M1 GPU using the PyTorch mps interface. The following is a minimal reproducible example that replicates the behavior:
...
0
votes
1
answer
56
views
How can I write a using a struct to a MTLBuffer?
I have an array of 3 MTLBuffers. They are created and then reused. They are managed with semaphores to avoid conflicts. I need to write to them using a struct I created. I'm having trouble binding to ...
0
votes
1
answer
74
views
Trouble getting started with Metal shader compilation
I'm having trouble getting started with Metal's shader compilation.
How to make a MTLLibrary that can link to a MTLDynamicLibrary (or MTLLinkedFunctions), in particular a library that declares extern ...
2
votes
1
answer
64
views
Checking if a Metal vertexBuffer is null in MTKMesh
I'm trying to draw an MTKMesh. To do this, I will need to set bind vertex buffers before executing the draw call. The documentation for MTKMesh.vertexBuffers is as follows:
/**
@property ...
2
votes
0
answers
57
views
Create UnsafeMutableRawPointer from NSData
I'm converting a ObjC tutorial (Apple's Selecting Device Objects for Compute Processing tutorial, in particular) to Swift.
I am doing it in increments, so I have to interface to some code still ...
0
votes
0
answers
38
views
Transparency issue with Scenekit renderer on arkit
I have an odd behaviour in certain conditions when I have two geometries one above the other and the first one at least has alpha value != 0.
I am using a program for the SCNMaterial, program is in ...
1
vote
1
answer
41
views
MTLRenderCommandEncoder for compute processing?
Trying to put together a puzzle:
Is it OK to use MTLRenderCommandEncoder not for rendering but for computing tasks?
If not, does it possible to do vertex shader job using MTLComputeCommandEncoder?
...
2
votes
2
answers
1k
views
Can't get Tensorflow working on macOS M1 Pro Chip
I've been trying to get into ML and I wanted to follow a course on it but it requires Tensorflow and I've been trying to get that working on my system. I have the 2021 14" 16GB Macbook Pro with ...
0
votes
1
answer
46
views
How to Handle Apple Metal Texture RGB instead of RGBA
I'm working on an Apple Metal project in C++, and I was trying to implement things from learnopengl.com like the model loader. One part that I'm having trouble on is loading the textures correctly. In ...
0
votes
0
answers
26
views
Is it possible to declare and initialize a texture inside a .metal file?
I was just wondering, instead of creating a texture, initializing data to it via blit command encoder if it is private or by using MTLTexture replace if it not private, and passing it to GPU using ...
0
votes
1
answer
45
views
iOS - Metal not rendering color with low saturation and alpha
I'm using MTKView to render some triangles. Everything works fine until I decrease the color's saturation and opacity value which makes the triangle completely transparent. Creating SwiftUI's Color ...
0
votes
0
answers
62
views
Triple (ring) buffering doesn't increase the FPS
I'm creating a drawing app with Metal. Unlike other drawing app, my app stores all strokes as data model rather than just saving the bitmap result after drawing, the goal of this approach is allowing ...
0
votes
0
answers
83
views
Draw `MTLTexture` to `CAMetalLayer`
I am drawing stuff onto an off-screen MTLTexture. (using Skia Canvas)
At a later point, I want to render this MTLTexture into a CAMetalLayer to display it on the screen.
Since I was using Skia for the ...
0
votes
1
answer
137
views
Poor performance in Metal drawing app when render more than 4000 strokes
I'm creating a drawing app with Metal. Unlike other drawing app, my app stores all strokes as data model rather than just saving the bitmap result after drawing, the goal of this approach is allowing ...
0
votes
0
answers
70
views
how to render CIImage to offscreen MTLTexture?
I don't want to draw the CIImage to the currentDrawable.texture of the MTKView, I want to get the texture, and then pass it to the fragment shader to do other things. But why the obtained texture is ...
0
votes
0
answers
36
views
Metal Alpha Blending to create smooth line
I am trying to implement the method of drawing a smooth line through a large number of 3D points shown here --> https://ahmetkermen.com/simple-smooth-line-drawing-with-opengl.
I have a small quad ...
0
votes
1
answer
34
views
objective-c working in xcode but not on command line
I have a program that compiles in Xcode and behaves as expected, but when compiled on the command line doesn't behave as expected.
This is on MacOS 13.0.1 (not sure what other version information is ...
0
votes
1
answer
53
views
MTKView is blurry - samplingNearest() does not appear to work
I'm using a MTKView to display some pixel art, but it shows up blurry.
Here is the really weird part: I took a screenshot to show you all what it looks like, but the screenshot is perfectly sharp! Yet,...
1
vote
1
answer
50
views
How do I tell a CIKernel to only process specific regions of an image?
I have a simple CIKernel that tints pixel red:
extern "C" float4 BasicFilter (coreimage::sampler input, coreimage::destination dest) {
float4 inputPixel = input.sample(input.transform(...
1
vote
1
answer
29
views
Determine the element's type of a buffer in the Metal Shader Language
I use a codegen for generating declarations of Metal shaders and sometimes I do not know the exact types of objects that are passed to shaders.
E.g. I would have this declaration generated ...
1
vote
2
answers
62
views
Metal defaultLibrary does not load .metal functions
My metal default library does not contain the vertex and shader functions from the .metal file of the same directory.
Then the library.makeFunction(name: ..) returns nil for both the vertex and ...
1
vote
0
answers
28
views
GLU_TESS_WINDING_NONZERO for apple Metal
Does anyone know a property like GLU_TESS_WINDING_NONZERO for MetalKit?
I want to add this effect in my drawing app, however in MetalKit there is no property like glu_tess_winding.
0
votes
0
answers
52
views
mmap() and newBufferWithBytesNoCopy causing IOAF code -536870211 error if the file is too small
I noticed that, while generating a texture from an MTLBuffer created from mmap() via newBufferWithBytesNoCopy, if the size requested by the len argument to mmap, page aligned, is larger than the ...
0
votes
0
answers
30
views
Is there a way to get higher quality depth map through ARSession?
I am developing an application which ties an ARSession camera stream to an MTKView. Right now, I am able to access the depth map through currentFrame.sceneDepth.depthMap (or smoothedSceneDepth if I ...