Metal iOS gives compile error

import UIKit
import Metal
import QuartzCore

class ViewController: UIViewController {

var device: MTLDevice! = nil
var metalLayer: CAMetalLayer! = nil

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
    device = MTLCreateSystemDefaultDevice()
    metalLayer = CAMetalLayer()          // 1
    metalLayer.device = device           // 2
    metalLayer.pixelFormat = .BGRA8Unorm // 3
    metalLayer.framebufferOnly = true    // 4
    metalLayer.frame = view.layer.frame  // 5
    view.layer.addSublayer(metalLayer)   // 6
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}


}

When I have this in my ViewController.swift, I get the error "Use of undeclared type CAMetalLayer" even though I've imported Metal and QuartzCore. How can I get this code to work?

UPDATE: Simulator support is coming this year (2019)

Pre Xcode 11/iOS 13: Metal code doesn't compile on the Simulator. Try compiling for a device.

Metal runtime compile error (iOS 1…, Hi. It seems "MTLDevice newLibraryWithData:error:" would cause runtime error while running on iOS 13 simulator with Xcode 11. I tried to create a new project� Any idea why compiling a Metal shader at runtime from source on the iOS 13 Simulator fails with the following error: Error: PCH file built from a different branch ((metalfe-902.9.49)) than the compiler ((metalfe-902.9.52))

If your app has a fallback or mode that doesn't depend on Metal, and you want to compile your app for the simulator, you can do something like this:

#if targetEnvironment(simulator)
// dummy, do-nothing view controller for simulator
class ViewController: UIViewController {

}
#else
class ViewController: UIViewController {

    var device: MTLDevice! = nil
    var metalLayer: CAMetalLayer! = nil

    override func viewDidLoad() {
        super.viewDidLoad()
        device = MTLCreateSystemDefaultDevice()
        metalLayer = CAMetalLayer()
        ...
    }

}
#endif

Then your code will at least compile for both device and simulator, which can ease your non-Metal development.

Chapter 4 compile error/program crash, playground. This statement causes compiler errors in Xcode 9.4.1 an… My hope is that Apple fix it before the final release of Xcode 10. While this should work, I'm giving it a quick test through the chapter now. Edit: I'm� To compile shader source into a library without using Xcode: Use the metal tool to compile each .metal file into a single .air file, which stores an intermediate representation (IR) of shader language code. Optionally, use the metal-ar tool to archive several .air files together into a single .metalar file. (metal-ar is similar to the Unix ar.)

The same problem may appear if you name your XCode project "Metal".

In that case compiler will be confused and you'll receive the same error message.

Unknown shader compiler error using Unity 2019.2.8f1 when , Hi I encountered shader compiler error using Unity 2019.2.8f1 when building iOS app in be enough for me to keep working while Unity provides an official fix. My game is 60fps on Metal, but about 15fps on OpenGLES3. :/. Most metal-organic frameworks (MOFs) contain just one type of metal in the nodes connecting the organic linkers. Multivariate MOFs containing multiple metals can offer greater selectivity in sorption and catalytic properties, but determining the arrangement of metals in these materials is challenging. Ji et al. found that atom-probe tomography can reveal sequences of metals for MOF-74 single

Metal - Unity, To enable Metal API validation in Xcode: In Unity, build your Project for iOS. This generates an Xcode project. Open the generated Xcode project in Xcode and� Metal ions are critical for catalysis by many RNA and protein enzymes. To understand how these enzymes use metal ions for catalysis, it is crucial to determine how many metal ions are positioned at the active site. We report here an approach, combining atomic mutagenesis with quantitative determination of metal ion affinities, that allows individual metal ions to be distinguished. Using this

Shader compile error on iOS : 'data' declared as a pointer to 'metal , I got error when compile following shader. It's ok on MacOS. To be precise, error occurred when compiling this line. imageStore(OutMip[3]� Now the code compiles for Metal (If I go to "Compile and show code -> Metal") I noticed I can set the Target Version to 8.1 in xcode. But the shader doesn't run on my IPad (IOS8.1.1, Xcode 6.1), they all fall back to vertex lit. With the error: Pass '' shader state not supported All passes removed Setting to default shader.

How to Make Your First Circle Using Metal Shaders, Introduction to Apple's Metal When the code gets compiled into assembly, that “ one” instruction gets broken down into a series of multiple� To properly compile a bare metal program, we need to set the appropriate compiler and linker options to ensure the program is configured to run standalone. Compiler option -ffreestanding This gcc option directs the compiler to limit this program to only those features available in the freestanding environment.

Comments
  • Try selecting a device instead of the simulator in Xcode
  • This response doesn't answer the question, because there was no question, however it is a solution to the stated problem: the Simulator can't compile metal code. If you select a Device, the compile errors go away.
  • There is the implicit "How to fix it" question if you make a little effort.
  • Is there any option to silent this error while i am building in simulator?
  • @souvickcse , with Metal, there is no simulator. You must tether a device, end of story ! That's the deal! I guess they really mean it with "Metal" :)
  • I doubt you get the same error as the OP has stated?
  • @trojanfoe you can easily recheck it. Error is exactly the same