[Mesa-dev] [PATCH 3/3] glsl: Mark gl_GlobalInvocationID dependencies as used

Ilia Mirkin imirkin at alum.mit.edu
Thu Aug 6 11:21:34 PDT 2015


By the way, there are a number of these derived system values...
instead of creating lowering for all of them, have you considered just
starting out *every* CS with the instructions to compute them and then
not having any lowering at all? The dead code elim should take care of
removing any that aren't used.

  -ilia

On Thu, Aug 6, 2015 at 2:13 PM, Ilia Mirkin <imirkin at alum.mit.edu> wrote:
> Why doesn't the lowering pass do that? Do you need to call it earlier?
> Or does it rely on some information that only becomes available later?
>
> On Thu, Aug 6, 2015 at 2:01 PM, Jordan Justen <jordan.l.justen at intel.com> wrote:
>> gl_GlobalInvocationID =
>>   gl_WorkGroupID * gl_WorkGroupSize + gl_LocalInvocationID
>>
>> Therefore, if gl_GlobalInvocationID is used, then we mark these other
>> variables as being used. This prevents them from being considered dead
>> variables and being removed.
>>
>> Signed-off-by: Jordan Justen <jordan.l.justen at intel.com>
>> ---
>>  src/glsl/glsl_parser_extras.cpp | 33 +++++++++++++++++++++++++++++++++
>>  1 file changed, 33 insertions(+)
>>
>> diff --git a/src/glsl/glsl_parser_extras.cpp b/src/glsl/glsl_parser_extras.cpp
>> index 46896d7..49fc12d 100644
>> --- a/src/glsl/glsl_parser_extras.cpp
>> +++ b/src/glsl/glsl_parser_extras.cpp
>> @@ -1568,6 +1568,36 @@ set_shader_inout_layout(struct gl_shader *shader,
>>     }
>>  }
>>
>> +static void
>> +set_cs_variable_deps_as_used(struct gl_shader *shader,
>> +                             struct _mesa_glsl_parse_state *state)
>> +{
>> +   /* gl_GlobalInvocationID only exists in the compute shader.
>> +    */
>> +   if (shader->Stage != MESA_SHADER_COMPUTE)
>> +      return;
>> +
>> +   ir_variable *gl_GlobalInvocationID =
>> +      state->symbols->get_variable("gl_GlobalInvocationID");
>> +   assert(gl_GlobalInvocationID);
>> +
>> +   if (!gl_GlobalInvocationID->data.used)
>> +      return;
>> +
>> +   static const char *dep_var_names[] = {
>> +      "gl_WorkGroupSize",
>> +      "gl_WorkGroupID",
>> +      "gl_LocalInvocationID"
>> +   };
>> +
>> +   for (unsigned i = 0; i < ARRAY_SIZE(dep_var_names); i++) {
>> +      ir_variable *var =
>> +         state->symbols->get_variable(dep_var_names[i]);
>> +      assert(var);
>> +      var->data.used = true;
>> +   }
>> +}
>> +
>>  extern "C" {
>>
>>  void
>> @@ -1618,6 +1648,9 @@ _mesa_glsl_compile_shader(struct gl_context *ctx, struct gl_shader *shader,
>>           &ctx->Const.ShaderCompilerOptions[shader->Stage];
>>
>>        lower_subroutine(shader->ir, state);
>> +
>> +      set_cs_variable_deps_as_used(shader, state);
>> +
>>        /* Do some optimization at compile time to reduce shader IR size
>>         * and reduce later work if the same shader is linked multiple times
>>         */
>> --
>> 2.1.4
>>
>> _______________________________________________
>> mesa-dev mailing list
>> mesa-dev at lists.freedesktop.org
>> http://lists.freedesktop.org/mailman/listinfo/mesa-dev


More information about the mesa-dev mailing list