[Mesa-dev] [PATCH v2 6/9] radeonsi: remove unused si_prepare_cube_coords

Marek Olšák maraeo at gmail.com
Thu Jan 12 20:42:55 UTC 2017


I commented on patches 1 & 2. Other than that, patches 1-6 are:

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

Marek

On Thu, Jan 12, 2017 at 4:39 PM, Nicolai Hähnle <nhaehnle at gmail.com> wrote:
> From: Nicolai Hähnle <nicolai.haehnle at amd.com>
>
> Reviewed-by: Bas Nieuwenhuizen <bas at basnieuwenhuizen.nl>
> ---
>  src/gallium/drivers/radeonsi/si_shader_internal.h |   4 -
>  src/gallium/drivers/radeonsi/si_shader_tgsi_alu.c | 196 ----------------------
>  2 files changed, 200 deletions(-)
>
> diff --git a/src/gallium/drivers/radeonsi/si_shader_internal.h b/src/gallium/drivers/radeonsi/si_shader_internal.h
> index 6b3ac17..51d491e 100644
> --- a/src/gallium/drivers/radeonsi/si_shader_internal.h
> +++ b/src/gallium/drivers/radeonsi/si_shader_internal.h
> @@ -208,16 +208,12 @@ LLVMValueRef si_llvm_emit_fetch(struct lp_build_tgsi_context *bld_base,
>                                 const struct tgsi_full_src_register *reg,
>                                 enum tgsi_opcode_type type,
>                                 unsigned swizzle);
>
>  void si_llvm_emit_store(struct lp_build_tgsi_context *bld_base,
>                         const struct tgsi_full_instruction *inst,
>                         const struct tgsi_opcode_info *info,
>                         LLVMValueRef dst[4]);
>
>  void si_shader_context_init_alu(struct lp_build_tgsi_context *bld_base);
> -void si_prepare_cube_coords(struct lp_build_tgsi_context *bld_base,
> -                           struct lp_build_emit_data *emit_data,
> -                           LLVMValueRef *coords_arg,
> -                           LLVMValueRef *derivs_arg);
>
>  #endif
> diff --git a/src/gallium/drivers/radeonsi/si_shader_tgsi_alu.c b/src/gallium/drivers/radeonsi/si_shader_tgsi_alu.c
> index 11bd45d..085fd5b 100644
> --- a/src/gallium/drivers/radeonsi/si_shader_tgsi_alu.c
> +++ b/src/gallium/drivers/radeonsi/si_shader_tgsi_alu.c
> @@ -899,206 +899,10 @@ void si_shader_context_init_alu(struct lp_build_tgsi_context *bld_base)
>         bld_base->op_actions[TGSI_OPCODE_U64ADD].emit = emit_uadd;
>         bld_base->op_actions[TGSI_OPCODE_U64SHL].emit = emit_shl;
>         bld_base->op_actions[TGSI_OPCODE_U64SHR].emit = emit_ushr;
>         bld_base->op_actions[TGSI_OPCODE_I64SHR].emit = emit_ishr;
>
>         bld_base->op_actions[TGSI_OPCODE_U64MOD].emit = emit_umod;
>         bld_base->op_actions[TGSI_OPCODE_I64MOD].emit = emit_mod;
>         bld_base->op_actions[TGSI_OPCODE_U64DIV].emit = emit_udiv;
>         bld_base->op_actions[TGSI_OPCODE_I64DIV].emit = emit_idiv;
>  }
> -
> -/* Coordinates for cube map selection. sc, tc, and ma are as in Table 8.27
> - * of the OpenGL 4.5 (Compatibility Profile) specification, except ma is
> - * already multiplied by two. id is the cube face number.
> - */
> -struct cube_selection_coords {
> -       LLVMValueRef stc[2];
> -       LLVMValueRef ma;
> -       LLVMValueRef id;
> -};
> -
> -static void build_cube_intrinsic(struct gallivm_state *gallivm,
> -                                LLVMValueRef in[3],
> -                                struct cube_selection_coords *out)
> -{
> -       LLVMBuilderRef builder = gallivm->builder;
> -
> -       if (HAVE_LLVM >= 0x0309) {
> -               LLVMTypeRef f32 = LLVMTypeOf(in[0]);
> -
> -               out->stc[1] = lp_build_intrinsic(builder, "llvm.amdgcn.cubetc",
> -                                           f32, in, 3, LP_FUNC_ATTR_READNONE);
> -               out->stc[0] = lp_build_intrinsic(builder, "llvm.amdgcn.cubesc",
> -                                           f32, in, 3, LP_FUNC_ATTR_READNONE);
> -               out->ma = lp_build_intrinsic(builder, "llvm.amdgcn.cubema",
> -                                           f32, in, 3, LP_FUNC_ATTR_READNONE);
> -               out->id = lp_build_intrinsic(builder, "llvm.amdgcn.cubeid",
> -                                           f32, in, 3, LP_FUNC_ATTR_READNONE);
> -       } else {
> -               LLVMValueRef c[4] = {
> -                       in[0],
> -                       in[1],
> -                       in[2],
> -                       LLVMGetUndef(LLVMTypeOf(in[0]))
> -               };
> -               LLVMValueRef vec = lp_build_gather_values(gallivm, c, 4);
> -
> -               LLVMValueRef tmp =
> -                       lp_build_intrinsic(builder, "llvm.AMDGPU.cube",
> -                                         LLVMTypeOf(vec), &vec, 1,
> -                                         LP_FUNC_ATTR_READNONE);
> -
> -               out->stc[1] = LLVMBuildExtractElement(builder, tmp,
> -                               lp_build_const_int32(gallivm, 0), "");
> -               out->stc[0] = LLVMBuildExtractElement(builder, tmp,
> -                               lp_build_const_int32(gallivm, 1), "");
> -               out->ma = LLVMBuildExtractElement(builder, tmp,
> -                               lp_build_const_int32(gallivm, 2), "");
> -               out->id = LLVMBuildExtractElement(builder, tmp,
> -                               lp_build_const_int32(gallivm, 3), "");
> -       }
> -}
> -
> -/**
> - * Build a manual selection sequence for cube face sc/tc coordinates and
> - * major axis vector (multiplied by 2 for consistency) for the given
> - * vec3 \p coords, for the face implied by \p selcoords.
> - *
> - * For the major axis, we always adjust the sign to be in the direction of
> - * selcoords.ma; i.e., a positive out_ma means that coords is pointed towards
> - * the selcoords major axis.
> - */
> -static void build_cube_select(LLVMBuilderRef builder,
> -                             const struct cube_selection_coords *selcoords,
> -                             const LLVMValueRef *coords,
> -                             LLVMValueRef *out_st,
> -                             LLVMValueRef *out_ma)
> -{
> -       LLVMTypeRef f32 = LLVMTypeOf(coords[0]);
> -       LLVMValueRef is_ma_positive;
> -       LLVMValueRef sgn_ma;
> -       LLVMValueRef is_ma_z, is_not_ma_z;
> -       LLVMValueRef is_ma_y;
> -       LLVMValueRef is_ma_x;
> -       LLVMValueRef sgn;
> -       LLVMValueRef tmp;
> -
> -       is_ma_positive = LLVMBuildFCmp(builder, LLVMRealUGE,
> -               selcoords->ma, LLVMConstReal(f32, 0.0), "");
> -       sgn_ma = LLVMBuildSelect(builder, is_ma_positive,
> -               LLVMConstReal(f32, 1.0), LLVMConstReal(f32, -1.0), "");
> -
> -       is_ma_z = LLVMBuildFCmp(builder, LLVMRealUGE, selcoords->id, LLVMConstReal(f32, 4.0), "");
> -       is_not_ma_z = LLVMBuildNot(builder, is_ma_z, "");
> -       is_ma_y = LLVMBuildAnd(builder, is_not_ma_z,
> -               LLVMBuildFCmp(builder, LLVMRealUGE, selcoords->id, LLVMConstReal(f32, 2.0), ""), "");
> -       is_ma_x = LLVMBuildAnd(builder, is_not_ma_z, LLVMBuildNot(builder, is_ma_y, ""), "");
> -
> -       /* Select sc */
> -       tmp = LLVMBuildSelect(builder, is_ma_z, coords[2], coords[0], "");
> -       sgn = LLVMBuildSelect(builder, is_ma_y, LLVMConstReal(f32, 1.0),
> -               LLVMBuildSelect(builder, is_ma_x, sgn_ma,
> -                       LLVMBuildFNeg(builder, sgn_ma, ""), ""), "");
> -       out_st[0] = LLVMBuildFMul(builder, tmp, sgn, "");
> -
> -       /* Select tc */
> -       tmp = LLVMBuildSelect(builder, is_ma_y, coords[2], coords[1], "");
> -       sgn = LLVMBuildSelect(builder, is_ma_y, LLVMBuildFNeg(builder, sgn_ma, ""),
> -               LLVMConstReal(f32, -1.0), "");
> -       out_st[1] = LLVMBuildFMul(builder, tmp, sgn, "");
> -
> -       /* Select ma */
> -       tmp = LLVMBuildSelect(builder, is_ma_z, coords[2],
> -               LLVMBuildSelect(builder, is_ma_y, coords[1], coords[0], ""), "");
> -       sgn = LLVMBuildSelect(builder, is_ma_positive,
> -               LLVMConstReal(f32, 2.0), LLVMConstReal(f32, -2.0), "");
> -       *out_ma = LLVMBuildFMul(builder, tmp, sgn, "");
> -}
> -
> -void si_prepare_cube_coords(struct lp_build_tgsi_context *bld_base,
> -                           struct lp_build_emit_data *emit_data,
> -                           LLVMValueRef *coords_arg,
> -                           LLVMValueRef *derivs_arg)
> -{
> -
> -       unsigned target = emit_data->inst->Texture.Texture;
> -       unsigned opcode = emit_data->inst->Instruction.Opcode;
> -       struct gallivm_state *gallivm = bld_base->base.gallivm;
> -       LLVMBuilderRef builder = gallivm->builder;
> -       LLVMTypeRef type = bld_base->base.elem_type;
> -       struct cube_selection_coords selcoords;
> -       LLVMValueRef coords[3];
> -       LLVMValueRef invma;
> -
> -       build_cube_intrinsic(gallivm, coords_arg, &selcoords);
> -
> -       invma = lp_build_intrinsic(builder, "llvm.fabs.f32",
> -                       type, &selcoords.ma, 1, LP_FUNC_ATTR_READNONE);
> -       invma = lp_build_emit_llvm_unary(bld_base, TGSI_OPCODE_RCP, invma);
> -
> -       for (int i = 0; i < 2; ++i)
> -               coords[i] = LLVMBuildFMul(builder, selcoords.stc[i], invma, "");
> -
> -       coords[2] = selcoords.id;
> -
> -       if (opcode == TGSI_OPCODE_TXD && derivs_arg) {
> -               LLVMValueRef derivs[4];
> -               int axis;
> -
> -               /* Convert cube derivatives to 2D derivatives. */
> -               for (axis = 0; axis < 2; axis++) {
> -                       LLVMValueRef deriv_st[2];
> -                       LLVMValueRef deriv_ma;
> -
> -                       /* Transform the derivative alongside the texture
> -                        * coordinate. Mathematically, the correct formula is
> -                        * as follows. Assume we're projecting onto the +Z face
> -                        * and denote by dx/dh the derivative of the (original)
> -                        * X texture coordinate with respect to horizontal
> -                        * window coordinates. The projection onto the +Z face
> -                        * plane is:
> -                        *
> -                        *   f(x,z) = x/z
> -                        *
> -                        * Then df/dh = df/dx * dx/dh + df/dz * dz/dh
> -                        *            = 1/z * dx/dh - x/z * 1/z * dz/dh.
> -                        *
> -                        * This motivatives the implementation below.
> -                        *
> -                        * Whether this actually gives the expected results for
> -                        * apps that might feed in derivatives obtained via
> -                        * finite differences is anyone's guess. The OpenGL spec
> -                        * seems awfully quiet about how textureGrad for cube
> -                        * maps should be handled.
> -                        */
> -                       build_cube_select(builder, &selcoords, &derivs_arg[axis * 3],
> -                                         deriv_st, &deriv_ma);
> -
> -                       deriv_ma = LLVMBuildFMul(builder, deriv_ma, invma, "");
> -
> -                       for (int i = 0; i < 2; ++i)
> -                               derivs[axis * 2 + i] =
> -                                       LLVMBuildFSub(builder,
> -                                               LLVMBuildFMul(builder, deriv_st[i], invma, ""),
> -                                               LLVMBuildFMul(builder, deriv_ma, coords[i], ""), "");
> -               }
> -
> -               memcpy(derivs_arg, derivs, sizeof(derivs));
> -       }
> -
> -       /* Shift the texture coordinate. This must be applied after the
> -        * derivative calculation.
> -        */
> -       for (int i = 0; i < 2; ++i)
> -               coords[i] = LLVMBuildFAdd(builder, coords[i], LLVMConstReal(type, 1.5), "");
> -
> -       if (target == TGSI_TEXTURE_CUBE_ARRAY ||
> -           target == TGSI_TEXTURE_SHADOWCUBE_ARRAY) {
> -               /* for cube arrays coord.z = coord.w(array_index) * 8 + face */
> -               /* coords_arg.w component - array_index for cube arrays */
> -               coords[2] = lp_build_emit_llvm_ternary(bld_base, TGSI_OPCODE_MAD,
> -                                                      coords_arg[3], lp_build_const_float(gallivm, 8.0), coords[2]);
> -       }
> -
> -       memcpy(coords_arg, coords, sizeof(coords));
> -}
> --
> 2.7.4
>
> _______________________________________________
> 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