Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running Playground Chapters from MetalKit in MacOS #9

Open
pudepiedj opened this issue Nov 14, 2020 · 2 comments
Open

Running Playground Chapters from MetalKit in MacOS #9

pudepiedj opened this issue Nov 14, 2020 · 2 comments

Comments

@pudepiedj
Copy link

pudepiedj commented Nov 14, 2020

Marius, I've very much enjoyed your MetalKit sequence and learned much from it, so thank you.

From the Chapter 8 code accompanying the blogs onwards where you use playgrounds rather than projects I find that the path search in Metal.swift using guard let path = never manages to find the Shaders.metal file inside Resources, so the code won't build. Replacing the whole line with an absolute path fixes it, but I am not sure whether this is my setup or something that has changed in Swift 5.3, XCode 12.0 or somewhere else both of which I am using.

All the fixes for this error on SO seem to relate to XCode projects rather than playgrounds, and I haven't found any suggestions about how to fix the problem directly in the playground files and avoid introducing an absolute path.

Thanks.

@Eric-Sunny-Fish
Copy link

The reason to add the .metal extension to the file is so that Xcode can recognize the file is a Metal file, and display the file with syntax highlighting. Nothing in the process of running the file requires the extension. An alternative way to mark this as a Metal file is to set the type to Metal Shader Source in the File Inspector.
Bundle.main.path(forResource:, ofType:) appears to be broken. It will not find a file of type "metal" it will find a file of type "meta" or "mmmmm" or no type. It appears to do something wrong with .metal files.
So a work around for this issue is to manually set the type of Shaders.metal to Metal Shader Source, remove the .metal extension, and change the type to nil in Bundle.main.path(forResource:, ofType:).

@songhuaixu
Copy link

In Xcode 14, device.makeDefaultLibrary() can function normally

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants