[Mesa-dev] [PATCH] ac/nir: mark some texture intrinsics as convergent

Rhys Perry pendingchaos02 at gmail.com
Fri May 31 18:24:11 UTC 2019


The first and last hunks are needed to pass on the shader_info to the
middle hunk, which needs it so that it can test if the compute shader
has a derivative group.

On Fri, 31 May 2019 at 18:38, Marek Olšák <maraeo at gmail.com> wrote:
>
> The first and last hunks look like they shouldn't be there. Other than that:
>
> Reviewed-by: Marek Olšák <marek.olsak at amd.com>
>
> Marek
>
> On Fri, May 31, 2019 at 11:53 AM Rhys Perry <pendingchaos02 at gmail.com> wrote:
>>
>> Otherwise LLVM can sink them and their texture coordinate calculations
>> into divergent branches.
>>
>> v2: simplify the conditions on which the intrinsic is marked as convergent
>> v3: only mark as convergent in FS and CS with derivative groups
>>
>> Cc: <mesa-stable at lists.freedesktop.org>
>> Signed-off-by: Rhys Perry <pendingchaos02 at gmail.com>
>> ---
>>  src/amd/common/ac_nir_to_llvm.c | 18 ++++++++++++++++++
>>  1 file changed, 18 insertions(+)
>>
>> diff --git a/src/amd/common/ac_nir_to_llvm.c b/src/amd/common/ac_nir_to_llvm.c
>> index 265e3b636c4..9e9fade7227 100644
>> --- a/src/amd/common/ac_nir_to_llvm.c
>> +++ b/src/amd/common/ac_nir_to_llvm.c
>> @@ -38,6 +38,7 @@ struct ac_nir_context {
>>         struct ac_shader_abi *abi;
>>
>>         gl_shader_stage stage;
>> +       shader_info *info;
>>
>>         LLVMValueRef *ssa_defs;
>>
>> @@ -1394,6 +1395,22 @@ static LLVMValueRef build_tex_intrinsic(struct ac_nir_context *ctx,
>>         }
>>
>>         args->attributes = AC_FUNC_ATTR_READNONE;
>> +       bool cs_derivs = ctx->stage == MESA_SHADER_COMPUTE &&
>> +                        ctx->info->cs.derivative_group != DERIVATIVE_GROUP_NONE;
>> +       if (ctx->stage == MESA_SHADER_FRAGMENT || cs_derivs) {
>> +               /* Prevent texture instructions with implicit derivatives from being
>> +                * sinked into branches. */
>> +               switch (instr->op) {
>> +               case nir_texop_tex:
>> +               case nir_texop_txb:
>> +               case nir_texop_lod:
>> +                       args->attributes |= AC_FUNC_ATTR_CONVERGENT;
>> +                       break;
>> +               default:
>> +                       break;
>> +               }
>> +       }
>> +
>>         return ac_build_image_opcode(&ctx->ac, args);
>>  }
>>
>> @@ -4350,6 +4367,7 @@ void ac_nir_translate(struct ac_llvm_context *ac, struct ac_shader_abi *abi,
>>         ctx.abi = abi;
>>
>>         ctx.stage = nir->info.stage;
>> +       ctx.info = &nir->info;
>>
>>         ctx.main_function = LLVMGetBasicBlockParent(LLVMGetInsertBlock(ctx.ac.builder));
>>
>> --
>> 2.21.0
>>


More information about the mesa-dev mailing list