intel/compiler: use nir_shader_instructions_pass in brw_nir_clamp_image_1d_2d_array_sizes
No functional changes. Signed-off-by: Marcin Ślusarz <marcin.slusarz@intel.com> Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13189>
This commit is contained in:
parent
9e22e0838a
commit
5b8c993d50
|
@ -36,123 +36,109 @@
|
|||
* MAX(array_size, 1) for array textures.
|
||||
*/
|
||||
|
||||
static bool
|
||||
brw_nir_clamp_image_1d_2d_array_sizes_instr(nir_builder *b,
|
||||
nir_instr *instr,
|
||||
UNUSED void *cb_data)
|
||||
{
|
||||
nir_ssa_def *image_size = NULL;
|
||||
|
||||
switch (instr->type) {
|
||||
case nir_instr_type_intrinsic: {
|
||||
nir_intrinsic_instr *intr = nir_instr_as_intrinsic(instr);
|
||||
|
||||
switch (intr->intrinsic) {
|
||||
case nir_intrinsic_image_size:
|
||||
case nir_intrinsic_bindless_image_size:
|
||||
if (!nir_intrinsic_image_array(intr))
|
||||
break;
|
||||
|
||||
image_size = &intr->dest.ssa;
|
||||
break;
|
||||
|
||||
case nir_intrinsic_image_deref_size: {
|
||||
nir_deref_instr *deref = nir_src_as_deref(intr->src[0]);
|
||||
|
||||
assert(glsl_type_is_image(deref->type));
|
||||
|
||||
if (!glsl_sampler_type_is_array(deref->type))
|
||||
break;
|
||||
|
||||
image_size = &intr->dest.ssa;
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case nir_instr_type_tex: {
|
||||
nir_tex_instr *tex_instr = nir_instr_as_tex(instr);
|
||||
if (tex_instr->op != nir_texop_txs)
|
||||
break;
|
||||
|
||||
if (!tex_instr->is_array)
|
||||
break;
|
||||
|
||||
image_size = &tex_instr->dest.ssa;
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (!image_size)
|
||||
return false;
|
||||
|
||||
b->cursor = nir_after_instr(instr);
|
||||
|
||||
nir_ssa_def *components[4];
|
||||
/* OR all the sizes for all components but the last. */
|
||||
nir_ssa_def *or_components = nir_imm_int(b, 0);
|
||||
for (int i = 0; i < image_size->num_components; i++) {
|
||||
if (i == (image_size->num_components - 1)) {
|
||||
nir_ssa_def *null_or_size[2] = {
|
||||
nir_imm_int(b, 0),
|
||||
nir_imax(b, nir_channel(b, image_size, i),
|
||||
nir_imm_int(b, 1)),
|
||||
};
|
||||
nir_ssa_def *vec2_null_or_size = nir_vec(b, null_or_size, 2);
|
||||
|
||||
/* Using the ORed sizes select either the element 0 or 1
|
||||
* from this vec2. For NULL textures which have a size of
|
||||
* 0x0x0, we'll select the first element which is 0 and for
|
||||
* the rest MAX(depth, 1).
|
||||
*/
|
||||
components[i] =
|
||||
nir_vector_extract(b, vec2_null_or_size,
|
||||
nir_imin(b, or_components,
|
||||
nir_imm_int(b, 1)));
|
||||
} else {
|
||||
components[i] = nir_channel(b, image_size, i);
|
||||
or_components = nir_ior(b, components[i], or_components);
|
||||
}
|
||||
}
|
||||
nir_ssa_def *image_size_replacement =
|
||||
nir_vec(b, components, image_size->num_components);
|
||||
|
||||
b->cursor = nir_after_instr(instr);
|
||||
|
||||
nir_ssa_def_rewrite_uses_after(image_size,
|
||||
image_size_replacement,
|
||||
image_size_replacement->parent_instr);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
brw_nir_clamp_image_1d_2d_array_sizes(nir_shader *shader)
|
||||
{
|
||||
bool progress = false;
|
||||
nir_builder b;
|
||||
|
||||
nir_foreach_function(func, shader) {
|
||||
bool function_progress = false;
|
||||
|
||||
if (!func->impl)
|
||||
continue;
|
||||
|
||||
nir_builder_init(&b, func->impl);
|
||||
|
||||
nir_foreach_block(block, func->impl) {
|
||||
nir_foreach_instr_safe(instr, block) {
|
||||
nir_ssa_def *image_size = NULL;
|
||||
|
||||
switch (instr->type) {
|
||||
case nir_instr_type_intrinsic: {
|
||||
nir_intrinsic_instr *intr = nir_instr_as_intrinsic(instr);
|
||||
|
||||
switch (intr->intrinsic) {
|
||||
case nir_intrinsic_image_size:
|
||||
case nir_intrinsic_bindless_image_size:
|
||||
if (!nir_intrinsic_image_array(intr))
|
||||
break;
|
||||
|
||||
image_size = &intr->dest.ssa;
|
||||
break;
|
||||
|
||||
case nir_intrinsic_image_deref_size: {
|
||||
nir_deref_instr *deref = nir_src_as_deref(intr->src[0]);
|
||||
|
||||
assert(glsl_type_is_image(deref->type));
|
||||
|
||||
if (!glsl_sampler_type_is_array(deref->type))
|
||||
break;
|
||||
|
||||
image_size = &intr->dest.ssa;
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case nir_instr_type_tex: {
|
||||
nir_tex_instr *tex_instr = nir_instr_as_tex(instr);
|
||||
if (tex_instr->op != nir_texop_txs)
|
||||
break;
|
||||
|
||||
if (!tex_instr->is_array)
|
||||
break;
|
||||
|
||||
image_size = &tex_instr->dest.ssa;
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (!image_size)
|
||||
continue;
|
||||
|
||||
b.cursor = nir_after_instr(instr);
|
||||
|
||||
nir_ssa_def *components[4];
|
||||
/* OR all the sizes for all components but the last. */
|
||||
nir_ssa_def *or_components = nir_imm_int(&b, 0);
|
||||
for (int i = 0; i < image_size->num_components; i++) {
|
||||
if (i == (image_size->num_components - 1)) {
|
||||
nir_ssa_def *null_or_size[2] = {
|
||||
nir_imm_int(&b, 0),
|
||||
nir_imax(&b, nir_channel(&b, image_size, i),
|
||||
nir_imm_int(&b, 1)),
|
||||
};
|
||||
nir_ssa_def *vec2_null_or_size = nir_vec(&b, null_or_size, 2);
|
||||
|
||||
/* Using the ORed sizes select either the element 0 or 1
|
||||
* from this vec2. For NULL textures which have a size of
|
||||
* 0x0x0, we'll select the first element which is 0 and for
|
||||
* the rest MAX(depth, 1).
|
||||
*/
|
||||
components[i] =
|
||||
nir_vector_extract(&b, vec2_null_or_size,
|
||||
nir_imin(&b, or_components,
|
||||
nir_imm_int(&b, 1)));
|
||||
} else {
|
||||
components[i] = nir_channel(&b, image_size, i);
|
||||
or_components = nir_ior(&b, components[i], or_components);
|
||||
}
|
||||
}
|
||||
nir_ssa_def *image_size_replacement =
|
||||
nir_vec(&b, components, image_size->num_components);
|
||||
|
||||
b.cursor = nir_after_instr(instr);
|
||||
|
||||
nir_ssa_def_rewrite_uses_after(image_size,
|
||||
image_size_replacement,
|
||||
image_size_replacement->parent_instr);
|
||||
|
||||
function_progress = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (function_progress) {
|
||||
nir_metadata_preserve(func->impl, nir_metadata_block_index |
|
||||
nir_metadata_dominance);
|
||||
progress = function_progress;
|
||||
} else {
|
||||
nir_metadata_preserve(func->impl, nir_metadata_all);
|
||||
}
|
||||
}
|
||||
|
||||
return progress;
|
||||
return nir_shader_instructions_pass(shader,
|
||||
brw_nir_clamp_image_1d_2d_array_sizes_instr,
|
||||
nir_metadata_block_index |
|
||||
nir_metadata_dominance,
|
||||
NULL);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue