ac: add support for 16bit UBO loads
[mesa.git] / src / amd / common / ac_llvm_build.c
index a77c29270d1960102c3465e8271bcd96b4d2a2d0..54b7e98701585c13682a7a99a2955d8b66d5fce0 100644 (file)
@@ -175,6 +175,8 @@ ac_get_type_size(LLVMTypeRef type)
        switch (kind) {
        case LLVMIntegerTypeKind:
                return LLVMGetIntTypeWidth(type) / 8;
+       case LLVMHalfTypeKind:
+               return 2;
        case LLVMFloatTypeKind:
                return 4;
        case LLVMDoubleTypeKind:
@@ -320,6 +322,9 @@ void ac_build_type_name_for_intr(LLVMTypeRef type, char *buf, unsigned bufsize)
        case LLVMIntegerTypeKind:
                snprintf(buf, bufsize, "i%d", LLVMGetIntTypeWidth(elem_type));
                break;
+       case LLVMHalfTypeKind:
+               snprintf(buf, bufsize, "f16");
+               break;
        case LLVMFloatTypeKind:
                snprintf(buf, bufsize, "f32");
                break;
@@ -1098,6 +1103,31 @@ LLVMValueRef ac_build_buffer_load_format_gfx9_safe(struct ac_llvm_context *ctx,
                                           can_speculate, true);
 }
 
+LLVMValueRef
+ac_build_tbuffer_load_short(struct ac_llvm_context *ctx,
+                           LLVMValueRef rsrc,
+                           LLVMValueRef vindex,
+                           LLVMValueRef voffset,
+                               LLVMValueRef soffset,
+                               LLVMValueRef immoffset)
+{
+       const char *name = "llvm.amdgcn.tbuffer.load.i32";
+       LLVMTypeRef type = ctx->i32;
+       LLVMValueRef params[] = {
+                               rsrc,
+                               vindex,
+                               voffset,
+                               soffset,
+                               immoffset,
+                               LLVMConstInt(ctx->i32, V_008F0C_BUF_DATA_FORMAT_16, false),
+                               LLVMConstInt(ctx->i32, V_008F0C_BUF_NUM_FORMAT_UINT, false),
+                               ctx->i1false,
+                               ctx->i1false,
+       };
+       LLVMValueRef res = ac_build_intrinsic(ctx, name, type, params, 9, 0);
+       return LLVMBuildTrunc(ctx->builder, res, ctx->i16, "");
+}
+
 /**
  * Set range metadata on an instruction.  This can only be used on load and
  * call instructions.  If you know an instruction can only produce the values
@@ -1819,11 +1849,9 @@ LLVMValueRef ac_build_cvt_pkrtz_f16(struct ac_llvm_context *ctx,
 {
        LLVMTypeRef v2f16 =
                LLVMVectorType(LLVMHalfTypeInContext(ctx->context), 2);
-       LLVMValueRef res =
-               ac_build_intrinsic(ctx, "llvm.amdgcn.cvt.pkrtz",
-                                  v2f16, args, 2,
-                                  AC_FUNC_ATTR_READNONE);
-       return LLVMBuildBitCast(ctx->builder, res, ctx->i32, "");
+
+       return ac_build_intrinsic(ctx, "llvm.amdgcn.cvt.pkrtz", v2f16,
+                                 args, 2, AC_FUNC_ATTR_READNONE);
 }
 
 /* Upper 16 bits must be zero. */