Iris Shaders

Iris Shaders

36M Downloads

Move all initializers to main() to avoid issues with patching NV, Chronos, and Magnificient, and to fix crashes with some shader packs on M1

IMS212 opened this issue ยท 3 comments

commented

To avoid dealing with direct compatibility profile, NV and Chronos (and Magnificent) do roughly the following on top of each shader:

vec3 inPos = gl_Vertex.xyz;
vec2 inUV = gl_MultiTexCoord0.xy;
vec2 inLight = gl_MultiTexCoord2.xy;

Iris can't patch these, because they're global initializations before the _vert_init(); function loads.

commented

I think we can probably consider moving non-const initializers into main(). This is needed anyways for full compatibility with M1 for older shaderpacks as well, isn't it?

commented

Moving all initializations into the main function is planned, but there were some difficulties with it. I started prototyping initializer moving here in TransformTest in glsl-transformer.

  • Nested array initializers { ... } are only possible in initializers and not expressions so they can't simply be moved to the main function without creating a temporary declaration and then taking the value from there. (Edit: according to Builderb0y array initializers can have side effects, even if it'd be unlikely to happen in practice)
  • Const declarations need to be detected and not moved into main. It is assumed that since they have to be side-effect free that they can't call functions or otherwise modify state in their initializers.
commented

Related: #1082 (fixed on the side of Complementary, but the underlying issue still exists)