intel/compiler: Use two components for 1D array image sizes
authorJason Ekstrand <jason.ekstrand@intel.com>
Thu, 16 Aug 2018 15:16:41 +0000 (10:16 -0500)
committerJason Ekstrand <jason.ekstrand@intel.com>
Wed, 29 Aug 2018 19:04:02 +0000 (14:04 -0500)
Having the array length component stored in .z was a small convenience
for the ISL image param filling code and an annoyance in the NIR
lowering code.  The only convenience of treating 1D arrays like 2D
arrays in the lowering code is in the address calculation code so let's
put all the complexity there as well.

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
src/intel/compiler/brw_nir_lower_image_load_store.c
src/intel/isl/isl_storage_image.c

index b931a6d351275a12c0dd4c093e182a4eb8943cc9..4494dccccd2801acfc3deb2faa25069f247966d8 100644 (file)
@@ -118,31 +118,16 @@ _load_image_param(nir_builder *b, nir_deref_instr *deref, unsigned offset)
 #define load_image_param(b, d, o) \
    _load_image_param(b, d, BRW_IMAGE_PARAM_##o##_OFFSET)
 
-static nir_ssa_def *
-sanitize_image_coord(nir_builder *b, nir_deref_instr *deref, nir_ssa_def *coord)
-{
-   if (glsl_get_sampler_dim(deref->type) == GLSL_SAMPLER_DIM_1D &&
-       glsl_sampler_type_is_array(deref->type)) {
-      /* It's easier if 1D arrays are treated like 2D arrays */
-      return nir_vec3(b, nir_channel(b, coord, 0),
-                         nir_imm_int(b, 0),
-                         nir_channel(b, coord, 1));
-   } else {
-      unsigned dims = glsl_get_sampler_coordinate_components(deref->type);
-      return nir_channels(b, coord, (1 << dims) - 1);
-   }
-}
-
 static nir_ssa_def *
 image_coord_is_in_bounds(nir_builder *b, nir_deref_instr *deref,
                          nir_ssa_def *coord)
 {
-   coord = sanitize_image_coord(b, deref, coord);
    nir_ssa_def *size = load_image_param(b, deref, SIZE);
-
    nir_ssa_def *cmp = nir_ilt(b, coord, size);
+
+   unsigned coord_comps = glsl_get_sampler_coordinate_components(deref->type);
    nir_ssa_def *in_bounds = nir_imm_int(b, NIR_TRUE);
-   for (unsigned i = 0; i < coord->num_components; i++)
+   for (unsigned i = 0; i < coord_comps; i++)
       in_bounds = nir_iand(b, in_bounds, nir_channel(b, cmp, i));
 
    return in_bounds;
@@ -164,7 +149,16 @@ static nir_ssa_def *
 image_address(nir_builder *b, const struct gen_device_info *devinfo,
               nir_deref_instr *deref, nir_ssa_def *coord)
 {
-   coord = sanitize_image_coord(b, deref, coord);
+   if (glsl_get_sampler_dim(deref->type) == GLSL_SAMPLER_DIM_1D &&
+       glsl_sampler_type_is_array(deref->type)) {
+      /* It's easier if 1D arrays are treated like 2D arrays */
+      coord = nir_vec3(b, nir_channel(b, coord, 0),
+                          nir_imm_int(b, 0),
+                          nir_channel(b, coord, 1));
+   } else {
+      unsigned dims = glsl_get_sampler_coordinate_components(deref->type);
+      coord = nir_channels(b, coord, (1 << dims) - 1);
+   }
 
    nir_ssa_def *offset = load_image_param(b, deref, OFFSET);
    nir_ssa_def *tiling = load_image_param(b, deref, TILING);
@@ -741,10 +735,7 @@ lower_image_size_instr(nir_builder *b,
    enum glsl_sampler_dim dim = glsl_get_sampler_dim(deref->type);
    unsigned coord_comps = glsl_get_sampler_coordinate_components(deref->type);
    for (unsigned c = 0; c < coord_comps; c++) {
-      if (c == 1 && dim == GLSL_SAMPLER_DIM_1D) {
-         /* The array length for 1D arrays is in .z */
-         comps[1] = nir_channel(b, size, 2);
-      } else if (c == 2 && dim == GLSL_SAMPLER_DIM_CUBE) {
+      if (c == 2 && dim == GLSL_SAMPLER_DIM_CUBE) {
          comps[2] = nir_idiv(b, nir_channel(b, size, 2), nir_imm_int(b, 6));
       } else {
          comps[c] = nir_channel(b, size, c);
index 43398e8a020e21080a5ec9eac79e46e44e09f364..c36985af127d037e5dfbd371a1dddcc2a5cd2bc4 100644 (file)
@@ -233,12 +233,12 @@ isl_surf_fill_image_param(const struct isl_device *dev,
              surf->logical_level0_px.array_len);
    }
    param->size[0] = isl_minify(surf->logical_level0_px.w, view->base_level);
-   param->size[1] = isl_minify(surf->logical_level0_px.h, view->base_level);
-   if (surf->dim == ISL_SURF_DIM_3D) {
-      param->size[2] = isl_minify(surf->logical_level0_px.d, view->base_level);
-   } else {
-      param->size[2] = view->array_len;
-   }
+   param->size[1] = surf->dim == ISL_SURF_DIM_1D ?
+                    view->array_len :
+                    isl_minify(surf->logical_level0_px.h, view->base_level);
+   param->size[2] = surf->dim == ISL_SURF_DIM_2D ?
+                    view->array_len :
+                    isl_minify(surf->logical_level0_px.d, view->base_level);
 
    isl_surf_get_image_offset_el(surf, view->base_level,
                                 surf->dim == ISL_SURF_DIM_3D ?