icculus / mojoshader

Use Direct3D shaders with other 3D rendering APIs.
https://icculus.org/mojoshader/
zlib License
150 stars 37 forks source link

Use MSL directly for SDL_GPU #74

Closed TheSpydog closed 1 week ago

TheSpydog commented 2 weeks ago

This is a quickly-slapped-together proof of concept for using MojoShader's MSL emitter for the SDLGPU driver rather than going through SPIRV -> ShaderCross. The code organization and OS detection logic (particularly that it only checks for Mac and not iOS/tvOS) could be massively improved, so marking this as a draft for now.

I also removed ShaderCross references entirely from mojoshader_sdlgpu but that's definitely overkill. We'll need it for at least D3D12, but we could dynamically load it instead via SDL_LoadObject.

The only change on the emitter side was changing the hardcoded uniform buffer index 16 to 0 to match SDL's binding order requirements.

flibitijibibo commented 2 weeks ago

Honestly I wouldn't say this is overkill necessarily; we were planning on skipping D3D12 until the memory manager is in, and since we're strapped for resources we might actually get Shader Model 7 first anyway... precompiled blobs won't be affected either, so unless someone does all that extra D3D work we won't be missing out on anything.

TheSpydog commented 2 weeks ago

Fair points, and in the event that we do set up D3D12's memory manager in the near-ish future, we'll still need to rework shadercross integration anyway since this was still using the old single-header version. (Which is now deleted by this PR!)

I think this is ready for review now. Wasn't totally sure how to select the shader format so I went with preprocessor checks, since it's only Apple platforms that need special handling.