intel/nir: add options to storage image lowering
authorLionel Landwerlin <lionel.g.landwerlin@intel.com>
Tue, 4 Apr 2023 17:42:39 +0000 (20:42 +0300)
committerMarge Bot <emma+marge@anholt.net>
Tue, 18 Apr 2023 08:38:55 +0000 (08:38 +0000)
Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Reviewed-by: Ivan Briano <ivan.briano@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22302>

src/gallium/drivers/crocus/crocus_program.c
src/gallium/drivers/iris/iris_program.c
src/intel/compiler/brw_nir.h
src/intel/compiler/brw_nir_lower_storage_image.c
src/intel/vulkan/anv_pipeline.c
src/intel/vulkan_hasvk/anv_pipeline.c

index b1de026..4cd02e9 100644 (file)
@@ -2711,7 +2711,14 @@ crocus_create_uncompiled_shader(struct pipe_context *ctx,
    struct brw_nir_compiler_opts opts = {};
    brw_preprocess_nir(screen->compiler, nir, &opts);
 
-   NIR_PASS_V(nir, brw_nir_lower_storage_image, devinfo);
+   NIR_PASS_V(nir, brw_nir_lower_storage_image,
+              &(struct brw_nir_lower_storage_image_opts) {
+                 .devinfo = devinfo,
+                 .lower_loads = true,
+                 .lower_stores = true,
+                 .lower_atomics = true,
+                 .lower_get_size = true,
+              });
    NIR_PASS_V(nir, crocus_lower_storage_image_derefs);
 
    nir_sweep(nir);
index 7d598ec..96abc28 100644 (file)
@@ -2964,7 +2964,14 @@ iris_finalize_nir(struct pipe_screen *_screen, void *nirptr)
    struct brw_nir_compiler_opts opts = {};
    brw_preprocess_nir(screen->compiler, nir, &opts);
 
-   NIR_PASS_V(nir, brw_nir_lower_storage_image, devinfo);
+   NIR_PASS_V(nir, brw_nir_lower_storage_image,
+              &(struct brw_nir_lower_storage_image_opts) {
+                 .devinfo = devinfo,
+                 .lower_loads = true,
+                 .lower_stores = true,
+                 .lower_atomics = true,
+                 .lower_get_size = true,
+              });
    NIR_PASS_V(nir, iris_lower_storage_image_derefs);
 
    nir_sweep(nir);
index 1a564f0..7cdd4df 100644 (file)
@@ -130,8 +130,17 @@ bool brw_nir_lower_conversions(nir_shader *nir);
 
 bool brw_nir_lower_shading_rate_output(nir_shader *nir);
 
+struct brw_nir_lower_storage_image_opts {
+   const struct intel_device_info *devinfo;
+
+   bool lower_loads;
+   bool lower_stores;
+   bool lower_atomics;
+   bool lower_get_size;
+};
+
 bool brw_nir_lower_storage_image(nir_shader *nir,
-                                 const struct intel_device_info *devinfo);
+                                 const struct brw_nir_lower_storage_image_opts *opts);
 
 bool brw_nir_lower_mem_access_bit_sizes(nir_shader *shader,
                                         const struct
index 5d872d1..1e97f85 100644 (file)
@@ -686,15 +686,19 @@ brw_nir_lower_storage_image_instr(nir_builder *b,
 {
    if (instr->type != nir_instr_type_intrinsic)
       return false;
-   const struct intel_device_info *devinfo = cb_data;
+   const struct brw_nir_lower_storage_image_opts *opts = cb_data;
 
    nir_intrinsic_instr *intrin = nir_instr_as_intrinsic(instr);
    switch (intrin->intrinsic) {
    case nir_intrinsic_image_deref_load:
-      return lower_image_load_instr(b, devinfo, intrin);
+      if (opts->lower_loads)
+         return lower_image_load_instr(b, opts->devinfo, intrin);
+      return false;
 
    case nir_intrinsic_image_deref_store:
-      return lower_image_store_instr(b, devinfo, intrin);
+      if (opts->lower_stores)
+         return lower_image_store_instr(b, opts->devinfo, intrin);
+      return false;
 
    case nir_intrinsic_image_deref_atomic_add:
    case nir_intrinsic_image_deref_atomic_imin:
@@ -706,10 +710,14 @@ brw_nir_lower_storage_image_instr(nir_builder *b,
    case nir_intrinsic_image_deref_atomic_xor:
    case nir_intrinsic_image_deref_atomic_exchange:
    case nir_intrinsic_image_deref_atomic_comp_swap:
-      return lower_image_atomic_instr(b, devinfo, intrin);
+      if (opts->lower_atomics)
+         return lower_image_atomic_instr(b, opts->devinfo, intrin);
+      return false;
 
    case nir_intrinsic_image_deref_size:
-      return lower_image_size_instr(b, devinfo, intrin);
+      if (opts->lower_get_size)
+         return lower_image_size_instr(b, opts->devinfo, intrin);
+      return false;
 
    default:
       /* Nothing to do */
@@ -719,7 +727,7 @@ brw_nir_lower_storage_image_instr(nir_builder *b,
 
 bool
 brw_nir_lower_storage_image(nir_shader *shader,
-                            const struct intel_device_info *devinfo)
+                            const struct brw_nir_lower_storage_image_opts *opts)
 {
    bool progress = false;
 
@@ -733,7 +741,7 @@ brw_nir_lower_storage_image(nir_shader *shader,
    progress |= nir_shader_instructions_pass(shader,
                                             brw_nir_lower_storage_image_instr,
                                             nir_metadata_none,
-                                            (void *)devinfo);
+                                            (void *)opts);
 
    return progress;
 }
index 5834e97..12dcd57 100644 (file)
@@ -911,7 +911,14 @@ anv_pipeline_lower_nir(struct anv_pipeline *pipeline,
 
    nir_shader_gather_info(nir, nir_shader_get_entrypoint(nir));
 
-   NIR_PASS(_, nir, brw_nir_lower_storage_image, compiler->devinfo);
+   NIR_PASS(_, nir, brw_nir_lower_storage_image,
+            &(struct brw_nir_lower_storage_image_opts) {
+               .devinfo = compiler->devinfo,
+               .lower_loads = true,
+               .lower_stores = true,
+               .lower_atomics = true,
+               .lower_get_size = true,
+            });
 
    NIR_PASS(_, nir, nir_lower_explicit_io, nir_var_mem_global,
             nir_address_format_64bit_global);
index 306fcd9..0d79c08 100644 (file)
@@ -566,7 +566,14 @@ anv_pipeline_lower_nir(struct anv_pipeline *pipeline,
 
    nir_shader_gather_info(nir, nir_shader_get_entrypoint(nir));
 
-   NIR_PASS(_, nir, brw_nir_lower_storage_image, compiler->devinfo);
+   NIR_PASS(_, nir, brw_nir_lower_storage_image,
+            &(struct brw_nir_lower_storage_image_opts) {
+               .devinfo = compiler->devinfo,
+               .lower_loads = true,
+               .lower_stores = true,
+               .lower_atomics = true,
+               .lower_get_size = true,
+            });
 
    NIR_PASS(_, nir, nir_lower_explicit_io, nir_var_mem_global,
             nir_address_format_64bit_global);