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 <kenneth@whitecape.org>
This commit is contained in:
Jason Ekstrand 2018-08-16 10:16:41 -05:00
parent b1c414ef28
commit 4289143899
2 changed files with 20 additions and 29 deletions

View 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);

View 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 ?