MacOS and IOS

Now that Apple have decided to deprecate OpenGL in favour of Metal, where do we stand with MonoGame?

I have just had to convert a couple of hundred DX9 shaders to metal and it was a bitch of a job.

They also are refusing to supply C++ bindings to Metal, so everything has to be done with Objective C bridges, I cannot tell you how much of a pain that is.

Just wondering what the plan is.

OpenGL is deprecated, but still supported for now. Interop can be done with C#, without getting into Objective C. Check out for example Veldrid’s bindings: https://github.com/mellinoe/veldrid/blob/master/src/Veldrid.MetalBindings/ObjectiveCRuntime.cs.

So we can bind c# to metal, but what about shaders?

HLSL can be cross-compiled to MSL with DirectXShaderCompiler + SPIRV-Cross.

Have you tried it?

I have.

The Microsoft shader compiler only accepts DX11, and MonoGame is based on DX9.

HLSL shader parser only supports a tiny subset of HLSL, for example it does not support pre-processors, does not support using subscripts such as .xyz

I cannot find a way of going from DX9 to metal , in fact I have just had to hand convert 166 shaders because of these issues.

Since Apple, in their infinite wisdom have deprecated OpenGL , it is something we should be thinking about.

  • We’ll use a custom preprocessor.
  • We’ll still support the Effect syntax. We’re already using our own parser to read and remove Effect syntax before feeding the shader to the DX compiler.
  • We’ll either drop support for legacy dx9 shader syntax or we’ll use our parser to rewrite DX9 code to DX10+ syntax. IMO we should drop dx9 support, but we have to discuss this. You can already write DX11 shaders, but we compile shaders with legacy flag so users don’t have to migrate shaders they used with XNA.

We’ll use HlslTools as the preprocessor, parser and syntax rewriter.

What parser do you mean?

Thanks for pointing me at HLSLTools, not seen that before and it is pretty cool.

Please don’t underestimate the task of going from DX9 to DX11.

One of the massive problems I had to deal with is #includes. The DX9 shader compiler is very good at dead code optomisation, so if you have a whole bunch of uniforms and samplers in an included file, no problem. I found the metal shader compiler does dead code optomisation very late , which caused me all sorts of problems.

Also the online metal compiler is sandboxed, it has no access to the file system, so you cannot have #includes in metal shaders that are compiled online. You can if you pre-compile them, just not in game.

IIRC the HLSL Tools preprocessor handles #includes :slight_smile:

I know this will be a hassle and I’d like to not keep legacy stuff around forever, which is why I prefer dropping DX9 syntax support.

I have done a couple of posts on things I have come across that might be useful in the future.

When you do start on it, send me a message and I will see if I have time to help.

1 Like

We may as well wait around for DX13 to drop… oh wait… going by the past timelines, it is due anytime now…

So, from this, my guess is making anything major for Apple platforms is, put it on ice?