gallivm: remove dead cube map lod calculation code
authorRoland Scheidegger <sroland@vmware.com>
Thu, 29 Sep 2022 18:59:03 +0000 (20:59 +0200)
committerMarge Bot <emma+marge@anholt.net>
Sat, 1 Oct 2022 00:27:19 +0000 (00:27 +0000)
Since commit d413fd02190d ("gallivm: Always take the per-pixel LOD path
for cubemaps.") the special cube rho code was not used anymore.

Reviewed-by: Brian Paul <brianp@vmware.com>
Reviewed-By: Mike Blumenkrantz <michael.blumenkrantz@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18892>

src/gallium/auxiliary/gallivm/lp_bld_sample.c
src/gallium/auxiliary/gallivm/lp_bld_sample.h
src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c

index 50353d7..bb7b422 100644 (file)
@@ -342,7 +342,6 @@ lp_build_rho(struct lp_build_sample_context *bld,
              LLVMValueRef s,
              LLVMValueRef t,
              LLVMValueRef r,
-             LLVMValueRef cube_rho,
              const struct lp_derivatives *derivs)
 {
    struct gallivm_state *gallivm = bld->gallivm;
@@ -383,29 +382,7 @@ lp_build_rho(struct lp_build_sample_context *bld,
    int_size = lp_build_minify(int_size_bld, bld->int_size, first_level_vec, TRUE);
    float_size = lp_build_int_to_float(float_size_bld, int_size);
 
-   if (cube_rho) {
-      LLVMValueRef cubesize;
-      LLVMValueRef index0 = lp_build_const_int32(gallivm, 0);
-
-      /*
-       * Cube map code did already everything except size mul and per-quad extraction.
-       * Luckily cube maps are always quadratic!
-       */
-      if (rho_per_quad) {
-         rho = lp_build_pack_aos_scalars(bld->gallivm, coord_bld->type,
-                                         rho_bld->type, cube_rho, 0);
-      }
-      else {
-         rho = lp_build_swizzle_scalar_aos(coord_bld, cube_rho, 0, 4);
-      }
-      /* Could optimize this for single quad just skip the broadcast */
-      cubesize = lp_build_extract_broadcast(gallivm, bld->float_size_in_type,
-                                            rho_bld->type, float_size, index0);
-      /* skipping sqrt hence returning rho squared */
-      cubesize = lp_build_mul(rho_bld, cubesize, cubesize);
-      rho = lp_build_mul(rho_bld, cubesize, rho);
-   }
-   else if (derivs) {
+   if (derivs) {
       LLVMValueRef ddmax[3] = { NULL }, ddx[3] = { NULL }, ddy[3] = { NULL };
       for (i = 0; i < dims; i++) {
          LLVMValueRef floatdim;
@@ -820,7 +797,6 @@ lp_build_ilog2_sqrt(struct lp_build_context *bld,
  * \param derivs  partial derivatives of (s, t, r, q) with respect to X and Y
  * \param lod_bias  optional float vector with the shader lod bias
  * \param explicit_lod  optional float vector with the explicit lod
- * \param cube_rho  rho calculated by cube coord mapping (optional)
  * \param out_lod_ipart  integer part of lod
  * \param out_lod_fpart  float part of lod (never larger than 1 but may be negative)
  * \param out_lod_positive  (mask) if lod is positive (i.e. texture is minified)
@@ -835,7 +811,6 @@ lp_build_lod_selector(struct lp_build_sample_context *bld,
                       LLVMValueRef s,
                       LLVMValueRef t,
                       LLVMValueRef r,
-                      LLVMValueRef cube_rho,
                       const struct lp_derivatives *derivs,
                       LLVMValueRef lod_bias, /* optional */
                       LLVMValueRef explicit_lod, /* optional */
@@ -894,15 +869,14 @@ lp_build_lod_selector(struct lp_build_sample_context *bld,
       }
       else {
          LLVMValueRef rho;
-         boolean rho_squared = (bld->no_rho_approx &&
-                                (bld->dims > 1)) || cube_rho;
+         boolean rho_squared = bld->no_rho_approx && (bld->dims > 1);
 
          if (bld->static_sampler_state->aniso &&
              !explicit_lod) {
             rho = lp_build_pmin(bld, texture_unit, s, t, max_aniso);
             rho_squared = true;
          } else
-            rho = lp_build_rho(bld, texture_unit, s, t, r, cube_rho, derivs);
+            rho = lp_build_rho(bld, texture_unit, s, t, r, derivs);
 
          /*
           * Compute lod = log2(rho)
@@ -1840,7 +1814,6 @@ void
 lp_build_cube_lookup(struct lp_build_sample_context *bld,
                      LLVMValueRef *coords,
                      const struct lp_derivatives *derivs_in, /* optional */
-                     LLVMValueRef *rho,
                      struct lp_derivatives *derivs_out, /* optional */
                      boolean need_derivs)
 {
@@ -1853,16 +1826,7 @@ lp_build_cube_lookup(struct lp_build_sample_context *bld,
     * Do per-pixel face selection. We cannot however (as we used to do)
     * simply calculate the derivs afterwards (which is very bogus for
     * explicit derivs btw) because the values would be "random" when
-    * not all pixels lie on the same face. So what we do here is just
-    * calculate the derivatives after scaling the coords by the absolute
-    * value of the inverse major axis, and essentially do rho calculation
-    * steps as if it were a 3d texture. This is perfect if all pixels hit
-    * the same face, but not so great at edges, I believe the max error
-    * should be sqrt(2) with no_rho_approx or 2 otherwise (essentially measuring
-    * the 3d distance between 2 points on the cube instead of measuring up/down
-    * the edge). Still this is possibly a win over just selecting the same face
-    * for all pixels. Unfortunately, something like that doesn't work for
-    * explicit derivatives.
+    * not all pixels lie on the same face.
     */
    struct lp_build_context *cint_bld = &bld->int_coord_bld;
    struct lp_type intctype = cint_bld->type;
@@ -2114,11 +2078,9 @@ lp_build_cube_lookup(struct lp_build_sample_context *bld,
    coords[2] = LLVMBuildOr(builder, face, signma, "face");
 
    /* project coords */
-   if (!need_derivs) {
-      imahalfpos = lp_build_cube_imapos(coord_bld, ma);
-      face_s = lp_build_mul(coord_bld, face_s, imahalfpos);
-      face_t = lp_build_mul(coord_bld, face_t, imahalfpos);
-   }
+   imahalfpos = lp_build_cube_imapos(coord_bld, ma);
+   face_s = lp_build_mul(coord_bld, face_s, imahalfpos);
+   face_t = lp_build_mul(coord_bld, face_t, imahalfpos);
 
    coords[0] = lp_build_add(coord_bld, face_s, posHalf);
    coords[1] = lp_build_add(coord_bld, face_t, posHalf);
index c5efaaf..91d9465 100644 (file)
@@ -574,7 +574,6 @@ lp_build_lod_selector(struct lp_build_sample_context *bld,
                       LLVMValueRef s,
                       LLVMValueRef t,
                       LLVMValueRef r,
-                      LLVMValueRef cube_rho,
                       const struct lp_derivatives *derivs,
                       LLVMValueRef lod_bias, /* optional */
                       LLVMValueRef explicit_lod, /* optional */
@@ -649,7 +648,6 @@ void
 lp_build_cube_lookup(struct lp_build_sample_context *bld,
                      LLVMValueRef *coords,
                      const struct lp_derivatives *derivs_in, /* optional */
-                     LLVMValueRef *rho,
                      struct lp_derivatives *derivs_out, /* optional */
                      boolean need_derivs);
 
index 6486442..d17c3a4 100644 (file)
@@ -2539,7 +2539,7 @@ lp_build_sample_common(struct lp_build_sample_context *bld,
    const unsigned mag_filter = bld->static_sampler_state->mag_img_filter;
    const unsigned target = bld->static_texture_state->target;
    const bool aniso = bld->static_sampler_state->aniso;
-   LLVMValueRef first_level, cube_rho = NULL;
+   LLVMValueRef first_level = NULL;
    LLVMValueRef lod_ipart = NULL;
    struct lp_derivatives cube_derivs;
 
@@ -2550,7 +2550,7 @@ lp_build_sample_common(struct lp_build_sample_context *bld,
 
    /*
     * Choose cube face, recompute texcoords for the chosen face and
-    * compute rho here too (as it requires transform of derivatives).
+    * calculate / transform derivatives.
     */
    if (target == PIPE_TEXTURE_CUBE || target == PIPE_TEXTURE_CUBE_ARRAY) {
       boolean need_derivs;
@@ -2558,7 +2558,7 @@ lp_build_sample_common(struct lp_build_sample_context *bld,
                       mip_filter != PIPE_TEX_MIPFILTER_NONE) &&
                       !bld->static_sampler_state->min_max_lod_equal &&
                       !explicit_lod);
-      lp_build_cube_lookup(bld, coords, derivs, &cube_rho, &cube_derivs, need_derivs);
+      lp_build_cube_lookup(bld, coords, derivs, &cube_derivs, need_derivs);
       if (need_derivs)
          derivs = &cube_derivs;
 
@@ -2618,7 +2618,7 @@ lp_build_sample_common(struct lp_build_sample_context *bld,
        * distinguish between minification/magnification with one mipmap level.
        */
       lp_build_lod_selector(bld, is_lodq, texture_index, sampler_index,
-                            coords[0], coords[1], coords[2], cube_rho,
+                            coords[0], coords[1], coords[2],
                             derivs, lod_bias, explicit_lod,
                             mip_filter, max_aniso, lod,
                             &lod_ipart, lod_fpart, lod_pos_or_zero);