radv: add mipmaps support for DCC decompression on compute
[mesa.git] / src / amd / common / ac_llvm_build.c
index 613c1eef94299c0406d7ebff0ca18d42e3261270..b93fdde023e81e26201b5de2e0d9a56a4a699654 100644 (file)
@@ -441,6 +441,7 @@ LLVMValueRef
 ac_build_ballot(struct ac_llvm_context *ctx,
                LLVMValueRef value)
 {
+       const char *name = HAVE_LLVM >= 0x900 ? "llvm.amdgcn.icmp.i64.i32" : "llvm.amdgcn.icmp.i32";
        LLVMValueRef args[3] = {
                value,
                ctx->i32_0,
@@ -454,8 +455,7 @@ ac_build_ballot(struct ac_llvm_context *ctx,
 
        args[0] = ac_to_integer(ctx, args[0]);
 
-       return ac_build_intrinsic(ctx,
-                                 "llvm.amdgcn.icmp.i32",
+       return ac_build_intrinsic(ctx, name,
                                  ctx->i64, args, 3,
                                  AC_FUNC_ATTR_NOUNWIND |
                                  AC_FUNC_ATTR_READNONE |
@@ -465,6 +465,7 @@ ac_build_ballot(struct ac_llvm_context *ctx,
 LLVMValueRef ac_get_i1_sgpr_mask(struct ac_llvm_context *ctx,
                                 LLVMValueRef value)
 {
+       const char *name = HAVE_LLVM >= 0x900 ? "llvm.amdgcn.icmp.i64.i1" : "llvm.amdgcn.icmp.i1";
        LLVMValueRef args[3] = {
                value,
                ctx->i1false,
@@ -472,7 +473,7 @@ LLVMValueRef ac_get_i1_sgpr_mask(struct ac_llvm_context *ctx,
        };
 
        assert(HAVE_LLVM >= 0x0800);
-       return ac_build_intrinsic(ctx, "llvm.amdgcn.icmp.i1", ctx->i64, args, 3,
+       return ac_build_intrinsic(ctx, name, ctx->i64, args, 3,
                                  AC_FUNC_ATTR_NOUNWIND |
                                  AC_FUNC_ATTR_READNONE |
                                  AC_FUNC_ATTR_CONVERGENT);
@@ -1107,16 +1108,16 @@ LLVMValueRef ac_build_load_to_sgpr_uint_wraparound(struct ac_llvm_context *ctx,
 }
 
 static void
-ac_build_buffer_store_common(struct ac_llvm_context *ctx,
-                            LLVMValueRef rsrc,
-                            LLVMValueRef data,
-                            LLVMValueRef vindex,
-                            LLVMValueRef voffset,
-                            unsigned num_channels,
-                            bool glc,
-                            bool slc,
-                            bool writeonly_memory,
-                            bool use_format)
+ac_build_llvm7_buffer_store_common(struct ac_llvm_context *ctx,
+                                  LLVMValueRef rsrc,
+                                  LLVMValueRef data,
+                                  LLVMValueRef vindex,
+                                  LLVMValueRef voffset,
+                                  unsigned num_channels,
+                                  bool glc,
+                                  bool slc,
+                                  bool writeonly_memory,
+                                  bool use_format)
 {
        LLVMValueRef args[] = {
                data,
@@ -1167,7 +1168,7 @@ ac_build_llvm8_buffer_store_common(struct ac_llvm_context *ctx,
        args[idx++] = voffset ? voffset : ctx->i32_0;
        args[idx++] = soffset ? soffset : ctx->i32_0;
        args[idx++] = LLVMConstInt(ctx->i32, (glc ? 1 : 0) + (slc ? 2 : 0), 0);
-       unsigned func = HAVE_LLVM < 0x900 && num_channels == 3 ? 4 : num_channels;
+       unsigned func = !ac_has_vec3_support(ctx->chip_class, use_format) && num_channels == 3 ? 4 : num_channels;
        const char *indexing_kind = structurized ? "struct" : "raw";
        char name[256], type_name[8];
 
@@ -1194,17 +1195,18 @@ ac_build_buffer_store_format(struct ac_llvm_context *ctx,
                             LLVMValueRef voffset,
                             unsigned num_channels,
                             bool glc,
+                            bool slc,
                             bool writeonly_memory)
 {
        if (HAVE_LLVM >= 0x800) {
                ac_build_llvm8_buffer_store_common(ctx, rsrc, data, vindex,
                                                   voffset, NULL, num_channels,
-                                                  ctx->f32, glc, false,
+                                                  ctx->f32, glc, slc,
                                                   writeonly_memory, true, true);
        } else {
-               ac_build_buffer_store_common(ctx, rsrc, data, vindex, voffset,
-                                            num_channels, glc, false,
-                                            writeonly_memory, true);
+               ac_build_llvm7_buffer_store_common(ctx, rsrc, data, vindex, voffset,
+                                                  num_channels, glc, slc,
+                                                  writeonly_memory, true);
        }
 }
 
@@ -1227,7 +1229,7 @@ ac_build_buffer_store_dword(struct ac_llvm_context *ctx,
 {
        /* Split 3 channel stores, because only LLVM 9+ support 3-channel
         * intrinsics. */
-       if (num_channels == 3 && HAVE_LLVM < 0x900) {
+       if (num_channels == 3 && !ac_has_vec3_support(ctx->chip_class, false)) {
                LLVMValueRef v[3], v01;
 
                for (int i = 0; i < 3; i++) {
@@ -1271,11 +1273,11 @@ ac_build_buffer_store_dword(struct ac_llvm_context *ctx,
                        if (voffset)
                                offset = LLVMBuildAdd(ctx->builder, offset, voffset, "");
 
-                       ac_build_buffer_store_common(ctx, rsrc,
-                                                    ac_to_float(ctx, vdata),
-                                                    ctx->i32_0, offset,
-                                                    num_channels, glc, slc,
-                                                    writeonly_memory, false);
+                       ac_build_llvm7_buffer_store_common(ctx, rsrc,
+                                                          ac_to_float(ctx, vdata),
+                                                          ctx->i32_0, offset,
+                                                          num_channels, glc, slc,
+                                                          writeonly_memory, false);
                }
                return;
        }
@@ -1296,15 +1298,15 @@ ac_build_buffer_store_dword(struct ac_llvm_context *ctx,
 }
 
 static LLVMValueRef
-ac_build_buffer_load_common(struct ac_llvm_context *ctx,
-                           LLVMValueRef rsrc,
-                           LLVMValueRef vindex,
-                           LLVMValueRef voffset,
-                           unsigned num_channels,
-                           bool glc,
-                           bool slc,
-                           bool can_speculate,
-                           bool use_format)
+ac_build_llvm7_buffer_load_common(struct ac_llvm_context *ctx,
+                                 LLVMValueRef rsrc,
+                                 LLVMValueRef vindex,
+                                 LLVMValueRef voffset,
+                                 unsigned num_channels,
+                                 bool glc,
+                                 bool slc,
+                                 bool can_speculate,
+                                 bool use_format)
 {
        LLVMValueRef args[] = {
                LLVMBuildBitCast(ctx->builder, rsrc, ctx->v4i32, ""),
@@ -1354,7 +1356,7 @@ ac_build_llvm8_buffer_load_common(struct ac_llvm_context *ctx,
        args[idx++] = voffset ? voffset : ctx->i32_0;
        args[idx++] = soffset ? soffset : ctx->i32_0;
        args[idx++] = LLVMConstInt(ctx->i32, (glc ? 1 : 0) + (slc ? 2 : 0), 0);
-       unsigned func = HAVE_LLVM < 0x900 && num_channels == 3 ? 4 : num_channels;
+       unsigned func = !ac_has_vec3_support(ctx->chip_class, use_format) && num_channels == 3 ? 4 : num_channels;
        const char *indexing_kind = structurized ? "struct" : "raw";
        char name[256], type_name[8];
 
@@ -1420,7 +1422,7 @@ ac_build_buffer_load(struct ac_llvm_context *ctx,
                if (num_channels == 1)
                        return result[0];
 
-               if (num_channels == 3 && HAVE_LLVM < 0x900)
+               if (num_channels == 3 && !ac_has_vec3_support(ctx->chip_class, false))
                        result[num_channels++] = LLVMGetUndef(ctx->f32);
                return ac_build_gather_values(ctx, result, num_channels);
        }
@@ -1434,9 +1436,9 @@ ac_build_buffer_load(struct ac_llvm_context *ctx,
                                                         false);
        }
 
-       return ac_build_buffer_load_common(ctx, rsrc, vindex, offset,
-                                          num_channels, glc, slc,
-                                          can_speculate, false);
+       return ac_build_llvm7_buffer_load_common(ctx, rsrc, vindex, offset,
+                                                num_channels, glc, slc,
+                                                can_speculate, false);
 }
 
 LLVMValueRef ac_build_buffer_load_format(struct ac_llvm_context *ctx,
@@ -1453,9 +1455,9 @@ LLVMValueRef ac_build_buffer_load_format(struct ac_llvm_context *ctx,
                                                         glc, false,
                                                         can_speculate, true, true);
        }
-       return ac_build_buffer_load_common(ctx, rsrc, vindex, voffset,
-                                          num_channels, glc, false,
-                                          can_speculate, true);
+       return ac_build_llvm7_buffer_load_common(ctx, rsrc, vindex, voffset,
+                                                num_channels, glc, false,
+                                                can_speculate, true);
 }
 
 LLVMValueRef ac_build_buffer_load_format_gfx9_safe(struct ac_llvm_context *ctx,
@@ -1484,9 +1486,9 @@ LLVMValueRef ac_build_buffer_load_format_gfx9_safe(struct ac_llvm_context *ctx,
        LLVMValueRef new_rsrc = LLVMBuildInsertElement(ctx->builder, rsrc, new_elem_count,
                                                       LLVMConstInt(ctx->i32, 2, 0), "");
 
-       return ac_build_buffer_load_common(ctx, new_rsrc, vindex, voffset,
-                                          num_channels, glc, false,
-                                          can_speculate, true);
+       return ac_build_llvm7_buffer_load_common(ctx, new_rsrc, vindex, voffset,
+                                                num_channels, glc, false,
+                                                can_speculate, true);
 }
 
 static LLVMValueRef
@@ -1512,7 +1514,7 @@ ac_build_llvm8_tbuffer_load(struct ac_llvm_context *ctx,
        args[idx++] = soffset ? soffset : ctx->i32_0;
        args[idx++] = LLVMConstInt(ctx->i32, dfmt | (nfmt << 4), 0);
        args[idx++] = LLVMConstInt(ctx->i32, (glc ? 1 : 0) + (slc ? 2 : 0), 0);
-       unsigned func = HAVE_LLVM < 0x900 && num_channels == 3 ? 4 : num_channels;
+       unsigned func = !ac_has_vec3_support(ctx->chip_class, true) && num_channels == 3 ? 4 : num_channels;
        const char *indexing_kind = structurized ? "struct" : "raw";
        char name[256], type_name[8];
 
@@ -1811,7 +1813,7 @@ ac_build_opencoded_load_format(struct ac_llvm_context *ctx,
                                        can_speculate, false, true);
                } else {
                        tmp = LLVMBuildAdd(ctx->builder, voffset, tmp, "");
-                       loads[i] = ac_build_buffer_load_common(
+                       loads[i] = ac_build_llvm7_buffer_load_common(
                                        ctx, rsrc, vindex, tmp,
                                        1 << (load_log_size - 2), glc, slc, can_speculate, false);
                }
@@ -2011,7 +2013,7 @@ ac_build_llvm8_tbuffer_store(struct ac_llvm_context *ctx,
        args[idx++] = soffset ? soffset : ctx->i32_0;
        args[idx++] = LLVMConstInt(ctx->i32, dfmt | (nfmt << 4), 0);
        args[idx++] = LLVMConstInt(ctx->i32, (glc ? 1 : 0) + (slc ? 2 : 0), 0);
-       unsigned func = HAVE_LLVM < 0x900 && num_channels == 3 ? 4 : num_channels;
+       unsigned func = !ac_has_vec3_support(ctx->chip_class, true) && num_channels == 3 ? 4 : num_channels;
        const char *indexing_kind = structurized ? "struct" : "raw";
        char name[256], type_name[8];
 
@@ -4327,7 +4329,7 @@ ac_build_wg_scan_bottom(struct ac_llvm_context *ctx, struct ac_wg_scan *ws)
 
        /* ws->result_reduce is already the correct value */
        if (ws->enable_inclusive)
-               ws->result_inclusive = ac_build_alu_op(ctx, ws->result_exclusive, ws->src, ws->op);
+               ws->result_inclusive = ac_build_alu_op(ctx, ws->result_inclusive, ws->src, ws->op);
        if (ws->enable_exclusive)
                ws->result_exclusive = ac_build_alu_op(ctx, ws->result_exclusive, ws->extra, ws->op);
 }