From 42891438990ce170a2ce08f71a1360842d5897a1 Mon Sep 17 00:00:00 2001 From: Jason Ekstrand Date: Thu, 16 Aug 2018 10:16:41 -0500 Subject: [PATCH] intel/compiler: Use two components for 1D array image sizes 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 --- .../compiler/brw_nir_lower_image_load_store.c | 37 +++++++------------ src/intel/isl/isl_storage_image.c | 12 +++--- 2 files changed, 20 insertions(+), 29 deletions(-) diff --git a/src/intel/compiler/brw_nir_lower_image_load_store.c b/src/intel/compiler/brw_nir_lower_image_load_store.c index b931a6d3512..4494dccccd2 100644 --- a/src/intel/compiler/brw_nir_lower_image_load_store.c +++ b/src/intel/compiler/brw_nir_lower_image_load_store.c @@ -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); diff --git a/src/intel/isl/isl_storage_image.c b/src/intel/isl/isl_storage_image.c index 43398e8a020..c36985af127 100644 --- a/src/intel/isl/isl_storage_image.c +++ b/src/intel/isl/isl_storage_image.c @@ -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 ? -- 2.30.2