ac/llvm: implement nir_export_amd
authorQiang Yu <yuq825@gmail.com>
Mon, 19 Dec 2022 06:27:56 +0000 (14:27 +0800)
committerMarge Bot <emma+marge@anholt.net>
Fri, 3 Feb 2023 12:27:43 +0000 (12:27 +0000)
Reviewed-by: Timur Kristóf <timur.kristof@gmail.com>
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Signed-off-by: Qiang Yu <yuq825@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/20691>

src/amd/common/ac_nir.h
src/amd/llvm/ac_nir_to_llvm.c

index 56483a1..971d0b4 100644 (file)
@@ -50,6 +50,12 @@ enum
    AC_EXP_PARAM_UNDEFINED = 255, /* deprecated, use AC_EXP_PARAM_DEFAULT_VAL_0000 instead */
 };
 
+enum {
+   AC_EXP_FLAG_COMPRESSED = (1 << 0),
+   AC_EXP_FLAG_DONE       = (1 << 1),
+   AC_EXP_FLAG_VALID_MASK = (1 << 2),
+};
+
 /* Maps I/O semantics to the actual location used by the lowering pass. */
 typedef unsigned (*ac_nir_map_io_driver_location)(unsigned semantic);
 
index 154c6e9..cfabe42 100644 (file)
@@ -28,6 +28,7 @@
 #include "ac_llvm_util.h"
 #include "ac_shader_abi.h"
 #include "ac_shader_util.h"
+#include "ac_nir.h"
 #include "nir/nir.h"
 #include "nir/nir_deref.h"
 #include "sid.h"
@@ -4299,6 +4300,27 @@ static bool visit_intrinsic(struct ac_nir_context *ctx, nir_intrinsic_instr *ins
       result = ac_build_gather_values(&ctx->ac, global_count, instr->num_components);
       break;
    }
+   case nir_intrinsic_export_amd: {
+      unsigned flags = nir_intrinsic_flags(instr);
+      unsigned target = nir_intrinsic_base(instr);
+      unsigned write_mask = nir_intrinsic_write_mask(instr);
+
+      struct ac_export_args args = {
+         .target = target,
+         .enabled_channels = write_mask,
+         .compr = flags & AC_EXP_FLAG_COMPRESSED,
+         .done = flags & AC_EXP_FLAG_DONE,
+         .valid_mask = flags & AC_EXP_FLAG_VALID_MASK,
+      };
+
+      LLVMValueRef value = get_src(ctx, instr->src[0]);
+      int num_components = ac_get_llvm_num_components(value);
+      for (int i = 0; i < num_components; i++)
+         args.out[i] = ac_llvm_extract_elem(&ctx->ac, value, i);
+
+      ac_build_export(&ctx->ac, &args);
+      break;
+   }
    default:
       fprintf(stderr, "Unknown intrinsic: ");
       nir_print_instr(&instr->instr, stderr);