metal

How do you synchronize a Metal Performance Shader with an MTLBlitCommandEncoder?

两盒软妹~` 提交于 2019-12-06 02:47:24
问题 I'm trying to better understand the synchronization requirements when working with Metal Performance Shaders and an MTLBlitCommandEncoder . I have an MTLCommandBuffer that is set up as follows: Use MTLBlitCommandEncoder to copy a region of Texture A into Texture B. Texture A is larger than Texture B. I'm extracting a "tile" from Texture A and copying it into Texture B. Use an MPSImageBilinearScale metal performance shader with Texture B as the source texture and a third texture, Texture C, as

Render horizon silhouette using Metal in SceneKit

邮差的信 提交于 2019-12-05 22:19:27
I'm working on simple side project and small part of it is rendering a terrain. I'm rendering the terrain using height map information. But here is my problem: I would like to render just a silhouette/outline of the terrain/horizon. Here is screenshot from my app rendering height map: And here is screenshot similar to desired result from peakfinder.org: I would like to draw just lines representing silhouette of terrain with the rest transparent or solid colour. How can I solve it? Calculate local maximum somehow? I created sample project here , in case you want to help me. Thanks! 来源: https:/

Metal shader in SceneKit to outline an object

≯℡__Kan透↙ 提交于 2019-12-05 21:17:38
I'm playing around and trying to implement Metal shader in SceneKit that will outline an object. The idea is to draw an outline (or silhouette) similar to this image found in this blogpost (the blogpost doesn't contain any code): I'm new to SceneKit and Metal shaders so I'm able just to draw some geometry and write simple vertex or fragment shader. I'm curious how can I achieve this kind of effect? Is it done in multiple passes? Cheers! The basic idea here is to clone the "selected" node and its geometry, then use a custom vertex and fragment shader to "push" the geometry out along the vertex

Explaining the different types in Metal and SIMD

僤鯓⒐⒋嵵緔 提交于 2019-12-05 18:06:04
When working with Metal, I find there's a bewildering number of types and it's not always clear to me which type I should be using in which context. In Apple's Metal Shading Language Specification, there's a pretty clear table of which types are supported within a Metal shader file. However, there's plenty of sample code available that seems to use additional types that are part of SIMD. On the macOS (Objective-C) side of things, the Metal types are not available but the SIMD ones are and I'm not sure which ones I'm supposed to be used. For example: In the Metal Spec, there's float2 that is

How to implement/use atomic counter in Metal fragment shader?

核能气质少年 提交于 2019-12-05 17:18:56
I want to implement an A-Buffer algorithm for order-independent-transparency in my Metal application. The description of the technique mentions using an atomic counter. I've never used one of these or even heard of them. I just read about atomic variables in the Metal Shading Language Specification, but I can't figure out how to actually implement or use one. Does anyone have experience with these in Metal? Can you point me to an example of how to set up and use a simple integer counter? Basically each render pass I need to be able to increment an integer from within the fragment shader,

Metal emulate geometry shaders using compute shaders

扶醉桌前 提交于 2019-12-05 11:45:46
I'm trying to implement voxel cone tracing in Metal. One of the steps in the algorithm is to voxelize the geometry using a geometry shader. Metal does not have geometry shaders so I was looking into emulating them using a compute shader. I pass in my vertex buffer into the compute shader, do what a geometry shader would normally do, and write the result to an output buffer. I also add a draw command to an indirect buffer. I use the output buffer as the vertex buffer for my vertex shader. This works fine, but I need twice as much memory for my vertices, one for the vertex buffer and one for the

Metal kernels not behaving properly on the new MacBook Pro (late 2016) GPUs

强颜欢笑 提交于 2019-12-05 09:21:41
I'm working on macOS project that uses Swift and Metal for image processing on the GPU. Last week, I received my new 15-inch MacBook Pro (late 2016) and noticed something strange with my code: kernels that were supposed to write to a texture did not seem to do so... After a lot of digging, I found that the problem is related to which GPU is used by Metal (AMD Radeon Pro 455 or Intel(R) HD Graphics 530) to do the computation. Initializing the MTLDevice using MTLCopyAllDevices() returns an array of devices representing the Radeon and the Intel GPUs (while MTLCreateSystemDefaultDevice() returns

iOS Metal line width

浪尽此生 提交于 2019-12-05 08:17:55
I would like to set the width of a line that I'm drawing in Metal. I can set the size of a point with point_size as explained here: https://developer.apple.com/library/prerelease/ios/documentation/Metal/Reference/MTLRenderCommandEncoder_Ref/index.html But, I'm not sure how it works with lines. codingminion Short answer would be there is no way to control line width in the same way as a point size in Metal. Even in OpenGL graphics API, the function to do this (which used to exist as gllinewidth function) is now deprecated. An option would be to draw the line as a quad (a box), with two

iOS10 - can't render Sprite Kit scene within SceneKit with openGL

白昼怎懂夜的黑 提交于 2019-12-05 03:32:05
Since I've updated to iOS 10, I'm not able anymore to render a Sprite Kit scene to a Scene Node while using openGL for rendering. Things work fine with Metal. The error logs: "Failed to create IOSurface image (texture)" I used to be able to do something like: class ViewController: UIViewController { @IBOutlet weak var scnView: SCNView! override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. scnView.showsStatistics = true scnView.allowsCameraControl = true let scnScene = SCNScene() scnView.scene = scnScene print("scnView

Compiling and running the metal examples

寵の児 提交于 2019-12-05 00:08:58
It has been a while since I have used XCode, but since Apple revieled XCode 6 and the new Metal API I had to check it out. They have released examples, e.g. a converted version of their Basic3D example. I am having problems making them compile and run, though. I had to add paths the Quatz and Metal frameworks for compilation and linking to work - thought that should have worked out of the box with build-in libraries? Also the metal shader compilation step fails, it can not find the metal compiler. Where in XCode is that path setup? If I ignore the shader compilation step I get an error that