thatcosmonaut / SDL

Simple Directmedia Layer
https://libsdl.org
zlib License
1 stars 1 forks source link

Disallow (or mangle?) the "main" shader entry point name #25

Closed TheSpydog closed 1 month ago

TheSpydog commented 1 month ago

Metal Shading Language doesn't allow you to name functions "main". When transpiling a function named "main", SPIRV-Cross will rename it to "main0". This means if you have some logic like:

SDL_GpuShaderCreateInfo createInfo;
createInfo.entryPointName = "main";

This will work everywhere except Metal, meaning you'll need to rewrite your shaders accordingly.

For the sake of portability we should either (1) outright disallow the use of main in all shaders to ensure consistency, or (2) detect if the shader format is MSL, in which case we internally replace the entry point with "main0". The latter is a bit nicer but it's reliant on SPIRV-Cross keeping its MSL name-mangling behavior. (IMO it's unlikely to change, and we could always do a runtime version check for SPIRV-Cross to change the mangling logic if needed...)

flibitijibibo commented 1 month ago

I'd be up for disallowing main, it's not hard to use something like vs_main instead, and even MojoShader allows specifying the entry point name now so FNA3D would handle that restriction just fine.

TheSpydog commented 1 month ago

Turns out GLSL requires you to have "main" as your entry point, so let's go with the mangling route. But we don't have to hardcode it to "main0"; instead we can use a spirv-cross API to get the renamed entry point name instead.