[Mesa-dev] [PATCH 5/5] radeonsi: add a workaround for a compute VGPR-usage LLVM bug

Marek Olšák maraeo at gmail.com
Wed Jul 13 10:28:00 UTC 2016


On Wed, Jul 13, 2016 at 11:32 AM, Grazvydas Ignotas <notasas at gmail.com> wrote:
> On Tue, Jul 12, 2016 at 11:52 PM, Marek Olšák <maraeo at gmail.com> wrote:
>> From: Marek Olšák <marek.olsak at amd.com>
>>
>> This patch may be dropped depending on feedback.
>>
>> Cc: 12.0 <mesa-stable at lists.freedesktop.org>
>> ---
>>  src/gallium/drivers/radeonsi/si_shader.c | 33 ++++++++++++++++++++++++++++++++
>>  1 file changed, 33 insertions(+)
>>
>> diff --git a/src/gallium/drivers/radeonsi/si_shader.c b/src/gallium/drivers/radeonsi/si_shader.c
>> index 79c3496..81d071e 100644
>> --- a/src/gallium/drivers/radeonsi/si_shader.c
>> +++ b/src/gallium/drivers/radeonsi/si_shader.c
>> @@ -6705,6 +6705,39 @@ int si_compile_tgsi_shader(struct si_screen *sscreen,
>>
>>         radeon_llvm_dispose(&ctx.radeon_bld);
>>
>> +       /* Validate SGPR and VGPR usage for compute to detect compiler bugs. */
>> +       if (sel->type == PIPE_SHADER_COMPUTE) {
>> +               unsigned *props = sel->info.properties;
>> +               unsigned wave_size = 64;
>> +               unsigned max_vgprs = 256;
>> +               unsigned max_sgprs = sscreen->b.chip_class >= VI ? 800 : 512;
>> +               unsigned max_sgprs_per_wave = 128;
>> +               unsigned min_waves_per_cu =
>> +                       DIV_ROUND_UP(props[TGSI_PROPERTY_CS_FIXED_BLOCK_WIDTH] *
>> +                                    props[TGSI_PROPERTY_CS_FIXED_BLOCK_HEIGHT] *
>> +                                    props[TGSI_PROPERTY_CS_FIXED_BLOCK_DEPTH],
>> +                                    wave_size);
>> +               unsigned min_waves_per_simd = DIV_ROUND_UP(min_waves_per_cu, 4);
>> +
>> +               max_vgprs = max_vgprs / min_waves_per_simd;
>> +               max_sgprs = MIN2(max_sgprs / min_waves_per_simd, max_sgprs_per_wave);
>> +
>> +               if (shader->config.num_sgprs > max_sgprs ||
>> +                   shader->config.num_vgprs > max_vgprs) {
>> +                       fprintf(stderr, "LLVM failed to compile a shader correctly: "
>> +                               "SGPR:VGPR usage is %u:%u, but the hw limit is %u:%u\n",
>> +                               shader->config.num_sgprs, shader->config.num_vgprs,
>> +                               max_sgprs, max_vgprs);
>> +
>> +                       /* Just terminate the process, because dependent
>> +                        * shaders can hang due to bad input data, but use
>> +                        * the env var to allow shader-db to work.
>> +                        */
>> +                       if (!debug_get_bool_option("SI_PASS_BAD_SHADERS", false))
>> +                               exit(0);
>
> Hmm exit(0) usually means "the program finished successfully" and not
> everyone might notice the error message. I think exit(1) or even
> abort() would be better.

OK, I'll use abort().

Marek


More information about the mesa-dev mailing list