metal

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

≯℡__Kan透↙ 提交于 2020-01-23 07:52:59
问题 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?

Confused about thread_position_in_grid

淺唱寂寞╮ 提交于 2020-01-21 14:00:08
问题 I'm working on a compute shader in Metal on macOS. I'm trying to do some very basic things to learn how they work. I'm seeing some output I don't understand. I thought I would start by trying to generate a simple 2D gradient. The red channel would increase from 0 to 1 along the width and the green channel would increase from 0 to 1 along the height. So I wrote this kernel: kernel void myKernel(texture2d<half, access::write> outTexture [[ texture(MBKT_OutputTexture) ]], uint2 gid [[thread

What is the coordinate system used in metal?

孤者浪人 提交于 2020-01-16 08:40:13
问题 In metal what coordinate system to use inside shader (in and out)? and when we render to texture is it the same? with the z buffer also? Are there any inconsistencies? finally what are the difference between metal, opengl and directX ? 回答1: Metal Coordinate Systems Metal defines several standard coordinate systems to represent transformed graphics data at different stages along the rendering pipeline. 1) NDC (Normalized Device Coordinate): this coordinates is used by developers to construct

How to specify Metal Shader Language version?

被刻印的时光 ゝ 提交于 2020-01-16 05:12:07
问题 My app got Binary Rejected for the third time. The crashlogs are no help (I've symbolized them, but they do not contain any print logs...). Runs fine on iPhone 6s , iPhone X and iPad Pro 12.9 I'm testing on iOS 12 with app target iOS 11 As Metal for iOS can not be run in the simulator, I have not tested on iOS 11 So I got Crashlytics and got some info for the crash_info_entry_0 key: ...Error Domain=AGXMetalA8X Code=3 "Function ... is using language version 2.1 which is incompatible with this

iOS 8.3 - Metal, found nil while unwrapping an Optional Value

荒凉一梦 提交于 2020-01-15 03:21:07
问题 Before Apple released iOS 8.3 my code worked, however since the updating XCode complains that a nil value is found, even though none of my values are nil (I validated this when debugging). For sanity, I re-wrote my program to render a simple triangle to the screen with Metal, but the same error is thrown. I have an array of 3 vertices, I then multiply that by the array size to get the size of the buffer and pass in OptionCPUCacheModeDefault as I thought passing a nil parameter may have been

How can I make screen shot image from MTKView in iOS?

微笑、不失礼 提交于 2020-01-14 13:51:08
问题 I refer to MetalKitEssentials, and make model viewer application by MetalKit in iOS 9.1 . I want to make screen shot image(RGBA Format) from MTKView . But, I get only black image. What should I do? Thank you for reading! Code: @implemtntation MetalViewController { MTKView *metalView; } - (void)viewDidLoad { [super viewDidload]; [self setup]; } - (void)setup { metalDevice = MTLCreateSystemDefaultDevice(); commandQueue = [metalDevice newCommandQueue]; defaultLibrary = [metalDevice

Xcode GPU shader profiler

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-14 10:40:06
问题 The Xcode->GPU Capture frame->GPU shader profiler can't work, I run the Capture frame, and open the Metal compute shader source code by GPU shader profiler. But I can't see the shader code performance profile like thatGPU shader profiler 回答1: Set your project's "iOS Deployment Target" to a higher version. I had this issue and in my case it was set to 9.x. When I set it to 11.4 I could see the percentage on source lines. 来源: https://stackoverflow.com/questions/50802533/xcode-gpu-shader

Trouble Getting Depth Testing To Work With Apple's Metal Graphics API

流过昼夜 提交于 2020-01-13 02:13:40
问题 I'm spending some time in the evenings trying to learn Apple's Metal graphics API. I've run into a frustrating problem and so must be missing something pretty fundamental: I can only get rendered objects to appear on screen when depth testing is disabled, or when the depth function is changed to "Greater". What could possibly be going wrong? Also, what kinds of things can I check in order to debug this problem? Here's what I'm doing: 1) I'm using SDL to create my window. When setting up Metal

Difference between packed vs normal data type

↘锁芯ラ 提交于 2020-01-12 07:33:14
问题 In Metal what is the difference between a packed_float4 and a float4 ? 回答1: This information is from here float4 has an alignment of 16 bytes. This means that the memory address of such a type (e.g. 0x12345670 ) will be divisible by 16 (aka the last hexadecimal digit is 0 ). packed_float4 on the other hand has an alignment of 4 bytes . Last digit of the address will be 0 , 4 , 8 or c This does matter when you create custom structs. Say you want a struct with 2 normal float s and 1 float4 /

why is metal shader gradient lighter as a SCNProgram applied to a SceneKit Node than it is as a MTKView?

喜欢而已 提交于 2020-01-10 02:04:10
问题 I have a gradient, generated by a Metal fragment shader that I've applied to a SCNNode defined by a plane geometry. It looks like this: When I use the same shader applied to a MTKView rendered in an Xcode playground, the colors are darker. What is causing the colors to be lighter in the Scenekit version? Here is the Metal shader and the GameViewController. Shader: #include <metal_stdlib> using namespace metal; #include <SceneKit/scn_metal> struct myPlaneNodeBuffer { float4x4 modelTransform;