Merge branch 'dev/nir_lower_null_descriptors' into 'main'

nir: commonize lower_null_descriptors pass

See merge request mesa/mesa!37659
This commit is contained in:
Simon Perretta 2025-12-20 00:28:27 +00:00
commit b1289926e6
6 changed files with 36 additions and 31 deletions

View file

@ -201,6 +201,7 @@ else
'nir_lower_memcpy.c',
'nir_lower_memory_model.c',
'nir_lower_non_uniform_access.c',
'nir_lower_null_descriptors.c',
'nir_lower_packing.c',
'nir_lower_passthrough_edgeflags.c',
'nir_lower_patch_vertices.c',

View file

@ -6946,6 +6946,18 @@ bool nir_unlower_io_to_vars(nir_shader *nir, bool keep_intrinsics);
bool nir_opt_barycentric(nir_shader *shader, bool lower_sample_to_pos);
typedef enum {
nir_lower_null_descriptor_ubo = BITFIELD_BIT(0),
nir_lower_null_descriptor_ssbo = BITFIELD_BIT(1),
nir_lower_null_descriptor_global = BITFIELD_BIT(2),
nir_lower_null_descriptor_texture = BITFIELD_BIT(3),
nir_lower_null_descriptor_image = BITFIELD_BIT(4),
nir_lower_null_descriptor_all = BITFIELD_MASK(5),
} nir_lower_null_descriptor_options;
bool nir_lower_null_descriptors(nir_shader *shader, nir_lower_null_descriptor_options options);
#include "nir_inline_helpers.h"
#ifdef __cplusplus

View file

@ -8,12 +8,17 @@
#include "compiler/nir/nir.h"
#include "compiler/nir/nir_builder.h"
#include "pco_internal.h"
static nir_def *get_is_null(nir_builder *b,
nir_instr *instr,
nir_def **def,
pco_nir_lower_null_descriptor_options options)
/* This pass provides a primitive implementation of VK_EXT_robustness2's
* nullDescriptor feature for hardware that lacks native support for it, by
* wrapping the selected descriptor access in control flow.
*/
static nir_def *
get_is_null(nir_builder *b,
nir_instr *instr,
nir_def **def,
nir_lower_null_descriptor_options options)
{
bool is_deref = false;
*def = NULL;
@ -28,7 +33,7 @@ static nir_def *get_is_null(nir_builder *b,
case nir_intrinsic_image_deref_store:
case nir_intrinsic_image_deref_atomic:
case nir_intrinsic_image_deref_atomic_swap:
if (!(options & pco_nir_lower_null_descriptor_image))
if (!(options & nir_lower_null_descriptor_image))
return NULL;
is_deref = true;
@ -43,14 +48,14 @@ static nir_def *get_is_null(nir_builder *b,
case nir_intrinsic_global_atomic_swap_2x32:
case nir_intrinsic_store_global:
case nir_intrinsic_store_global_2x32:
if (!(options & pco_nir_lower_null_descriptor_global))
if (!(options & nir_lower_null_descriptor_global))
return NULL;
break;
case nir_intrinsic_get_ubo_size:
case nir_intrinsic_load_ubo:
if (!(options & pco_nir_lower_null_descriptor_ubo))
if (!(options & nir_lower_null_descriptor_ubo))
return NULL;
break;
@ -60,7 +65,7 @@ static nir_def *get_is_null(nir_builder *b,
case nir_intrinsic_ssbo_atomic:
case nir_intrinsic_ssbo_atomic_swap:
case nir_intrinsic_store_ssbo:
if (!(options & pco_nir_lower_null_descriptor_ssbo))
if (!(options & nir_lower_null_descriptor_ssbo))
return NULL;
break;
@ -80,7 +85,7 @@ static nir_def *get_is_null(nir_builder *b,
}
if (instr->type == nir_instr_type_tex) {
if (!(options & pco_nir_lower_null_descriptor_texture))
if (!(options & nir_lower_null_descriptor_texture))
return NULL;
nir_tex_instr *tex = nir_instr_as_tex(instr);
@ -95,9 +100,10 @@ static nir_def *get_is_null(nir_builder *b,
return NULL;
}
static bool lower(nir_builder *b, nir_instr *instr, void *data)
static bool
lower(nir_builder *b, nir_instr *instr, void *data)
{
pco_nir_lower_null_descriptor_options *options = data;
nir_lower_null_descriptor_options *options = data;
b->cursor = nir_before_instr(instr);
nir_def *def;
@ -134,9 +140,10 @@ static bool lower(nir_builder *b, nir_instr *instr, void *data)
return true;
}
bool pco_nir_lower_null_descriptors(
bool
nir_lower_null_descriptors(
nir_shader *shader,
pco_nir_lower_null_descriptor_options options)
nir_lower_null_descriptor_options options)
{
return nir_shader_instructions_pass(shader,
lower,

View file

@ -18,7 +18,6 @@ libpowervr_compiler_files = files(
'pco_nir.c',
'pco_nir_compute.c',
'pco_nir_io.c',
'pco_nir_lower_null_descriptors.c',
'pco_nir_pvfio.c',
'pco_nir_sync.c',
'pco_nir_tex.c',

View file

@ -1782,20 +1782,6 @@ bool pco_ra(pco_shader *shader);
bool pco_schedule(pco_shader *shader);
bool pco_shrink_vecs(pco_shader *shader);
typedef enum {
pco_nir_lower_null_descriptor_ubo = (1 << 0),
pco_nir_lower_null_descriptor_ssbo = (1 << 1),
pco_nir_lower_null_descriptor_global = (1 << 2),
pco_nir_lower_null_descriptor_texture = (1 << 3),
pco_nir_lower_null_descriptor_image = (1 << 4),
pco_nir_lower_null_descriptor_all = BITFIELD_MASK(5),
} pco_nir_lower_null_descriptor_options;
bool pco_nir_lower_null_descriptors(
nir_shader *shader,
pco_nir_lower_null_descriptor_options options);
/**
* \brief Returns the PCO bits for a bit size.
*

View file

@ -858,8 +858,8 @@ void pco_lower_nir(pco_ctx *ctx, nir_shader *nir, pco_data *data)
if (data->common.null_descriptor) {
NIR_PASS(_,
nir,
pco_nir_lower_null_descriptors,
pco_nir_lower_null_descriptor_all);
nir_lower_null_descriptors,
nir_lower_null_descriptor_all);
}
NIR_PASS(_, nir, pco_nir_lower_vk, data);