gallivm: use common code to select texel type
authorDave Airlie <airlied@redhat.com>
Mon, 31 Aug 2020 00:22:35 +0000 (10:22 +1000)
committerDave Airlie <airlied@redhat.com>
Mon, 31 Aug 2020 03:20:11 +0000 (13:20 +1000)
This was suggested by Roland, and fixes stencil images.

Fixes:
dEQP-VK.renderpass.dedicated_allocation.formats.d24_unorm_s8_uint.*
dEQP-VK.renderpass.dedicated_allocation.formats.d32_sfloat_s8_uint.*

Reviewed-by: Roland Scheidegger <sroland@vmware.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6381>

src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c

index 0f0c2fade21c5ac8e0e3a3552ab22efb223cf021..f3ec99139db412f7559eb07710f9db75a1cd3774 100644 (file)
@@ -2770,6 +2770,29 @@ lp_build_sample_nop(struct gallivm_state *gallivm,
    }  
 }
 
+static struct lp_type
+lp_build_texel_type(struct lp_type texel_type,
+                    const struct util_format_description *format_desc)
+{
+   /* always using the first channel hopefully should be safe,
+    * if not things WILL break in other places anyway.
+    */
+   if (format_desc->colorspace == UTIL_FORMAT_COLORSPACE_RGB &&
+       format_desc->channel[0].pure_integer) {
+      if (format_desc->channel[0].type == UTIL_FORMAT_TYPE_SIGNED) {
+         texel_type = lp_type_int_vec(texel_type.width, texel_type.width * texel_type.length);
+      } else if (format_desc->channel[0].type == UTIL_FORMAT_TYPE_UNSIGNED) {
+         texel_type = lp_type_uint_vec(texel_type.width, texel_type.width * texel_type.length);
+      }
+   }
+   else if (util_format_has_stencil(format_desc) &&
+       !util_format_has_depth(format_desc)) {
+      /* for stencil only formats, sample stencil (uint) */
+      texel_type = lp_type_uint_vec(texel_type.width, texel_type.width * texel_type.length);
+   }
+   return texel_type;
+}
+
 
 /**
  * Build the actual texture sampling code.
@@ -2893,25 +2916,8 @@ lp_build_sample_soa_code(struct gallivm_state *gallivm,
    bld.float_size_in_type = lp_type_float(32);
    bld.float_size_in_type.length = dims > 1 ? 4 : 1;
    bld.int_size_in_type = lp_int_type(bld.float_size_in_type);
-   bld.texel_type = type;
 
-   /* always using the first channel hopefully should be safe,
-    * if not things WILL break in other places anyway.
-    */
-   if (bld.format_desc->colorspace == UTIL_FORMAT_COLORSPACE_RGB &&
-       bld.format_desc->channel[0].pure_integer) {
-      if (bld.format_desc->channel[0].type == UTIL_FORMAT_TYPE_SIGNED) {
-         bld.texel_type = lp_type_int_vec(type.width, type.width * type.length);
-      }
-      else if (bld.format_desc->channel[0].type == UTIL_FORMAT_TYPE_UNSIGNED) {
-         bld.texel_type = lp_type_uint_vec(type.width, type.width * type.length);
-      }
-   }
-   else if (util_format_has_stencil(bld.format_desc) &&
-       !util_format_has_depth(bld.format_desc)) {
-      /* for stencil only formats, sample stencil (uint) */
-      bld.texel_type = lp_type_uint_vec(type.width, type.width * type.length);
-   }
+   bld.texel_type = lp_build_texel_type(type, bld.format_desc);
 
    if (!static_texture_state->level_zero_only ||
        !static_sampler_state->max_lod_pos || op_is_lodq) {
@@ -4126,22 +4132,6 @@ lp_build_img_op_no_format(struct gallivm_state *gallivm,
    }
 }
 
-static struct lp_type
-lp_build_img_texel_type(struct gallivm_state *gallivm,
-                        struct lp_type texel_type,
-                        const struct util_format_description *format_desc)
-{
-   if (format_desc->colorspace == UTIL_FORMAT_COLORSPACE_RGB &&
-       format_desc->channel[0].pure_integer) {
-      if (format_desc->channel[0].type == UTIL_FORMAT_TYPE_SIGNED) {
-         texel_type = lp_type_int_vec(texel_type.width, texel_type.width * texel_type.length);
-      } else if (format_desc->channel[0].type == UTIL_FORMAT_TYPE_UNSIGNED) {
-         texel_type = lp_type_uint_vec(texel_type.width, texel_type.width * texel_type.length);
-      }
-   }
-   return texel_type;
-}
-
 void
 lp_build_img_op_soa(const struct lp_static_texture_state *static_texture_state,
                     struct lp_sampler_dynamic_state *dynamic_state,
@@ -4228,7 +4218,7 @@ lp_build_img_op_soa(const struct lp_static_texture_state *static_texture_state,
                                          ms_index));
    }
    if (params->img_op == LP_IMG_LOAD) {
-      struct lp_type texel_type = lp_build_img_texel_type(gallivm, params->type, format_desc);
+      struct lp_type texel_type = lp_build_texel_type(params->type, format_desc);
 
       offset = lp_build_andnot(&int_coord_bld, offset, out_of_bounds);
       struct lp_build_context texel_bld;