libsdl-org / SDL

Simple Directmedia Layer
https://libsdl.org
zlib License
9.87k stars 1.83k forks source link

Metal shader compilation issues with the SDL_Renderer GPU backend #10669

Closed coffeechriph closed 2 months ago

coffeechriph commented 2 months ago

Hello! I've been playing around with the new GPU backend for the SDL_Renderer, thanks for all the hard work on this!

I was unable to load the MSL shaders as they were.

Error output when trying to load the shaders ERROR: Creating MTLLibrary failed: Error Domain=MTLLibraryErrorDomain Code=3 "program_source:33:1: error: expected unqualified-id <U+0014><U+0002> ^ " UserInfo={NSLocalizedDescription=program_source:33:1: error: expected unqualified-id <U+0014><U+0002> ^ }

Now the error seems to point out unexpected characters at the end of the file. Opening the .metal files that are generated from spirv-cross there were 2 seemingly blank lines. Removing them manually and re-creating the header file without recompiling using spirv-cross fixed the issue..

Another solution to the problem was to compile the metal source to metallib and changing the shader format to SDL_GPU_SHADERFORMAT_METALLIB.

I'll post my fork and the changes that I made to compile the shaders to metallib instead https://github.com/coffeechriph/SDL/compare/main...coffeechriph:SDL:patch-1

Thanks

maia-s commented 2 months ago

This sounds like it may have been fixed by #10674

coffeechriph commented 2 months ago

Yes I verified and it works now! Closing