Skip to content

glsl,nir: Allow NIR to inline some functions instead of doing all inlining in ir

I created new MR for instead of updating old one (!5252 (closed)) to avoid confusion with reviews.


Due to the typo in a condition, when compiling glsl shader, all functions were inlined before getting to NIR.

Unfortunately, fixing the condition is not enough, since deref_cast generated in glsl_to_nir (nir_visitor::visit(ir_dereference_variable *ir)) for out function parameters cannot be optimized, causing errors down the line.

The following code is generated:

decl_var  INTERP_MODE_NONE float webgl_7f75b23f84f0e51a
impl main {
...
vec1 32 ssa_570 = deref_var &webgl_7f75b23f84f0e51a (shader_temp float) <---- Could have other modes than shader_temp
...
vec1 32 ssa_719 = deref_cast (float *)ssa_570 (function_temp float)  /* ptr_stride=0 */

Such deref chain isn't considered trivial in opt_deref_cast which I tried to correct.


Example with shader temp
[require]
GLSL >= 4.50

[vertex shader]
#version 450
void webgl_f473b6d23ddb8775();
vec3 webgl_7f75b23f84f0e51a;

void webgl_ca3f90b3af1344d8(out vec3 webgl_79a0bb06e8e1fac2)
{
 if(1.0 < webgl_79a0bb06e8e1fac2.x)
  {
   webgl_79a0bb06e8e1fac2 = vec3(1.0);
  }
}
void webgl_69a266870c8b8057()
{
 webgl_ca3f90b3af1344d8(webgl_7f75b23f84f0e51a);
}
void webgl_f473b6d23ddb8775()
{
 webgl_69a266870c8b8057();
}
void main()
{
 webgl_f473b6d23ddb8775();
}
[test]

Example with ssbo
[require]
GLSL >= 4.50

[vertex shader]
#version 450
void webgl_f473b6d23ddb8775();
float webgl_7f75b23f84f0e51a;
layout(binding = 0) buffer layoutName
{
    float data_SSBO;
};

void webgl_ca3f90b3af1344d8(out float webgl_79a0bb06e8e1fac2)
{
 if(1.0 < webgl_79a0bb06e8e1fac2)
  {
   webgl_79a0bb06e8e1fac2 = 2.0;
  }
}
void webgl_69a266870c8b8057()
{
 webgl_ca3f90b3af1344d8(data_SSBO);
}
void webgl_f473b6d23ddb8775()
{
 webgl_69a266870c8b8057();
}
void main()
{
 webgl_f473b6d23ddb8775();
}

[test]

draw rect -1 -1 2 2
---

Or maybe there is a better way to handle out parameters?

Edited by Danylo Piliaiev

Merge request reports