bool agx_nir_opt_ixor_bcsel(struct nir_shader *shader);
bool agx_nir_lower_algebraic_late(struct nir_shader *shader);
bool agx_nir_fuse_algebraic_late(struct nir_shader *shader);
+bool agx_nir_fence_images(struct nir_shader *shader);
#endif
--- /dev/null
+/*
+ * Copyright 2023 Valve Corporation
+ * SPDX-License-Identifier: MIT
+ */
+
+#include "compiler/nir/nir_builder.h"
+#include "agx_nir.h"
+#include "nir.h"
+#include "nir_builder_opcodes.h"
+#include "nir_intrinsics.h"
+
+static bool
+pass(struct nir_builder *b, nir_instr *instr, void *data)
+{
+ if (instr->type != nir_instr_type_intrinsic)
+ return false;
+
+ b->cursor = nir_after_instr(instr);
+
+ nir_intrinsic_instr *intr = nir_instr_as_intrinsic(instr);
+ switch (intr->intrinsic) {
+ case nir_intrinsic_image_store:
+ case nir_intrinsic_bindless_image_store:
+ nir_fence_pbe_to_tex_agx(b);
+ return true;
+
+ case nir_intrinsic_image_atomic:
+ case nir_intrinsic_bindless_image_atomic:
+ case nir_intrinsic_image_atomic_swap:
+ case nir_intrinsic_bindless_image_atomic_swap:
+ nir_fence_mem_to_tex_agx(b);
+ return true;
+
+ default:
+ return false;
+ }
+}
+
+bool
+agx_nir_fence_images(nir_shader *s)
+{
+ return nir_shader_instructions_pass(
+ s, pass, nir_metadata_block_index | nir_metadata_dominance, NULL);
+}
#include "compiler/nir/nir_builtin_builder.h"
#include "agx_compiler.h"
#include "agx_internal_formats.h"
+#include "agx_nir.h"
#include "nir_builder_opcodes.h"
#include "nir_intrinsics.h"
#include "nir_intrinsics_indices.h"
};
NIR_PASS(progress, s, nir_lower_tex, &lower_tex_options);
+
+ /* Insert fences before lowering image atomics, since image atomics need
+ * different fencing than other image operations.
+ */
+ NIR_PASS(progress, s, agx_nir_fence_images);
+
NIR_PASS(progress, s, nir_lower_image_atomics_to_global);
/* Lower bias after nir_lower_tex (to get rid of txd) but before
'agx_dce.c',
'agx_liveness.c',
'agx_insert_waits.c',
+ 'agx_nir_fence_images.c',
'agx_nir_lower_address.c',
'agx_nir_lower_frag_sidefx.c',
'agx_nir_lower_sample_mask.c',