[Mesa-dev] [PATCH 2/2] radeonsi: fix a regression in integer cube map handling

Marek Olšák maraeo at gmail.com
Fri Sep 29 14:53:58 UTC 2017


For the series:

Reviewed-by: Marek Olšák <marek.olsak at amd.com>

Marek

On Fri, Sep 29, 2017 at 12:12 PM, Nicolai Hähnle <nhaehnle at gmail.com> wrote:
> From: Nicolai Hähnle <nicolai.haehnle at amd.com>
>
> A recent commit fixed the case of 8888 integer cube maps, which need the
> workaround of replacing the data format with USCALED/SSCALED. However,
> this broke the case of non-8888 integer cube maps; those still need the
> fix of shifting the texture coordinates.
>
> Fixes KHR-GL45.texture_gather.plain-gather-int-cube-array and similar.
>
> Fixes: 6fb0c1013b35 ("radeonsi: workaround for gather4 on integer cube maps")
> ---
>  src/gallium/drivers/radeonsi/si_shader_tgsi_mem.c | 34 +++++++++++++++++------
>  1 file changed, 26 insertions(+), 8 deletions(-)
>
> diff --git a/src/gallium/drivers/radeonsi/si_shader_tgsi_mem.c b/src/gallium/drivers/radeonsi/si_shader_tgsi_mem.c
> index be92044750c..0863876ed89 100644
> --- a/src/gallium/drivers/radeonsi/si_shader_tgsi_mem.c
> +++ b/src/gallium/drivers/radeonsi/si_shader_tgsi_mem.c
> @@ -1715,72 +1715,78 @@ static void tex_fetch_args(
>   * runtime. In this case, return an i1 value that indicates whether the
>   * descriptor was overridden (and hence a fixup of the sampler result is needed).
>   */
>  static LLVMValueRef
>  si_lower_gather4_integer(struct si_shader_context *ctx,
>                          struct ac_image_args *args,
>                          unsigned target,
>                          enum tgsi_return_type return_type)
>  {
>         LLVMBuilderRef builder = ctx->gallivm.builder;
> +       LLVMValueRef wa_8888 = NULL;
>         LLVMValueRef coord = args->addr;
>         LLVMValueRef half_texel[2];
>         /* Texture coordinates start after:
>          *   {offset, bias, z-compare, derivatives}
>          * Only the offset and z-compare can occur here.
>          */
>         unsigned coord_vgpr_index = (int)args->offset + (int)args->compare;
>         int c;
>
>         assert(return_type == TGSI_RETURN_TYPE_SINT ||
>                return_type == TGSI_RETURN_TYPE_UINT);
>
>         if (target == TGSI_TEXTURE_CUBE ||
>             target == TGSI_TEXTURE_CUBE_ARRAY) {
>                 LLVMValueRef formats;
>                 LLVMValueRef data_format;
>                 LLVMValueRef wa_formats;
> -               LLVMValueRef wa;
>
>                 formats = LLVMBuildExtractElement(builder, args->resource, ctx->i32_1, "");
>
>                 data_format = LLVMBuildLShr(builder, formats,
>                                             LLVMConstInt(ctx->i32, 20, false), "");
>                 data_format = LLVMBuildAnd(builder, data_format,
>                                            LLVMConstInt(ctx->i32, (1u << 6) - 1, false), "");
> -               wa = LLVMBuildICmp(builder, LLVMIntEQ, data_format,
> -                                  LLVMConstInt(ctx->i32, V_008F14_IMG_DATA_FORMAT_8_8_8_8, false),
> -                                  "");
> +               wa_8888 = LLVMBuildICmp(
> +                       builder, LLVMIntEQ, data_format,
> +                       LLVMConstInt(ctx->i32, V_008F14_IMG_DATA_FORMAT_8_8_8_8, false),
> +                       "");
>
>                 uint32_t wa_num_format =
>                         return_type == TGSI_RETURN_TYPE_UINT ?
>                         S_008F14_NUM_FORMAT_GFX6(V_008F14_IMG_NUM_FORMAT_USCALED) :
>                         S_008F14_NUM_FORMAT_GFX6(V_008F14_IMG_NUM_FORMAT_SSCALED);
>                 wa_formats = LLVMBuildAnd(builder, formats,
>                                           LLVMConstInt(ctx->i32, C_008F14_NUM_FORMAT_GFX6, false),
>                                           "");
>                 wa_formats = LLVMBuildOr(builder, wa_formats,
>                                         LLVMConstInt(ctx->i32, wa_num_format, false), "");
>
> -               formats = LLVMBuildSelect(builder, wa, wa_formats, formats, "");
> +               formats = LLVMBuildSelect(builder, wa_8888, wa_formats, formats, "");
>                 args->resource = LLVMBuildInsertElement(
>                         builder, args->resource, formats, ctx->i32_1, "");
> -
> -               return wa;
>         }
>
>         if (target == TGSI_TEXTURE_RECT ||
>             target == TGSI_TEXTURE_SHADOWRECT) {
> +               assert(!wa_8888);
>                 half_texel[0] = half_texel[1] = LLVMConstReal(ctx->f32, -0.5);
>         } else {
>                 struct tgsi_full_instruction txq_inst = {};
>                 struct lp_build_emit_data txq_emit_data = {};
> +               struct lp_build_if_state if_ctx;
> +
> +               if (wa_8888) {
> +                       /* Skip the texture size query entirely if we don't need it. */
> +                       lp_build_if(&if_ctx, &ctx->gallivm, LLVMBuildNot(builder, wa_8888, ""));
> +               }
>
>                 /* Query the texture size. */
>                 txq_inst.Texture.Texture = target;
>                 txq_emit_data.inst = &txq_inst;
>                 txq_emit_data.dst_type = ctx->v4i32;
>                 set_tex_fetch_args(ctx, &txq_emit_data, target,
>                                    args->resource, NULL, &ctx->i32_0,
>                                    1, 0xf);
>                 txq_emit(NULL, &ctx->bld_base, &txq_emit_data);
>
> @@ -1789,36 +1795,48 @@ si_lower_gather4_integer(struct si_shader_context *ctx,
>                         half_texel[c] =
>                                 LLVMBuildExtractElement(builder, txq_emit_data.output[0],
>                                                         LLVMConstInt(ctx->i32, c, 0), "");
>                         half_texel[c] = LLVMBuildUIToFP(builder, half_texel[c], ctx->f32, "");
>                         half_texel[c] =
>                                 lp_build_emit_llvm_unary(&ctx->bld_base,
>                                                          TGSI_OPCODE_RCP, half_texel[c]);
>                         half_texel[c] = LLVMBuildFMul(builder, half_texel[c],
>                                                       LLVMConstReal(ctx->f32, -0.5), "");
>                 }
> +
> +               if (wa_8888) {
> +                       lp_build_endif(&if_ctx);
> +
> +                       LLVMBasicBlockRef bb[2] = { if_ctx.true_block, if_ctx.entry_block };
> +
> +                       for (c = 0; c < 2; c++) {
> +                               LLVMValueRef values[2] = { half_texel[c], ctx->ac.f32_0 };
> +                               half_texel[c] = ac_build_phi(&ctx->ac, ctx->f32, 2,
> +                                                            values, bb);
> +                       }
> +               }
>         }
>
>         for (c = 0; c < 2; c++) {
>                 LLVMValueRef tmp;
>                 LLVMValueRef index = LLVMConstInt(ctx->i32, coord_vgpr_index + c, 0);
>
>                 tmp = LLVMBuildExtractElement(builder, coord, index, "");
>                 tmp = LLVMBuildBitCast(builder, tmp, ctx->f32, "");
>                 tmp = LLVMBuildFAdd(builder, tmp, half_texel[c], "");
>                 tmp = LLVMBuildBitCast(builder, tmp, ctx->i32, "");
>                 coord = LLVMBuildInsertElement(builder, coord, tmp, index, "");
>         }
>
>         args->addr = coord;
>
> -       return NULL;
> +       return wa_8888;
>  }
>
>  /* The second half of the cube texture 8_8_8_8 integer workaround: adjust the
>   * result after the gather operation.
>   */
>  static LLVMValueRef
>  si_fix_gather4_integer_result(struct si_shader_context *ctx,
>                            LLVMValueRef result,
>                            enum tgsi_return_type return_type,
>                            LLVMValueRef wa)
> --
> 2.11.0
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev


More information about the mesa-dev mailing list