ac: add support for 16bit UBO loads
authorDaniel Schürmann <daniel.schuermann@campus.tu-berlin.de>
Wed, 7 Feb 2018 18:40:43 +0000 (19:40 +0100)
committerBas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Mon, 23 Jul 2018 21:16:25 +0000 (23:16 +0200)
Reviewed-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
src/amd/common/ac_llvm_build.c
src/amd/common/ac_llvm_build.h
src/amd/common/ac_nir_to_llvm.c

index 4078b005e540a046d5860560241d94accc87d1fc..54b7e98701585c13682a7a99a2955d8b66d5fce0 100644 (file)
@@ -1103,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
index 4e7cbcd5fa0f44c13da04b282dc2cfc11f7b0e10..c5753037e7bca75ec1fdd2f086c4be7889651a94 100644 (file)
@@ -252,6 +252,14 @@ LLVMValueRef ac_build_buffer_load_format_gfx9_safe(struct ac_llvm_context *ctx,
                                                   bool glc,
                                                   bool can_speculate);
 
+LLVMValueRef
+ac_build_tbuffer_load_short(struct ac_llvm_context *ctx,
+                           LLVMValueRef rsrc,
+                           LLVMValueRef vindex,
+                           LLVMValueRef voffset,
+                               LLVMValueRef soffset,
+                               LLVMValueRef immoffset);
+
 LLVMValueRef
 ac_get_thread_id(struct ac_llvm_context *ctx);
 
index e3b5ae49fdf1aa8573516e0b6eea117a5da2bf57..3fde66097969b298834f4f467551690b0da88688 100644 (file)
@@ -1677,9 +1677,24 @@ static LLVMValueRef visit_load_ubo_buffer(struct ac_nir_context *ctx,
        if (instr->dest.ssa.bit_size == 64)
                num_components *= 2;
 
-       ret = ac_build_buffer_load(&ctx->ac, rsrc, num_components, NULL, offset,
-                                  NULL, 0, false, false, true, true);
-       ret = ac_trim_vector(&ctx->ac, ret, num_components);
+       if (instr->dest.ssa.bit_size == 16) {
+               LLVMValueRef results[num_components];
+               for (unsigned i = 0; i < num_components; ++i) {
+                       results[i] = ac_build_tbuffer_load_short(&ctx->ac,
+                                                                rsrc,
+                                                                ctx->ac.i32_0,
+                                                                offset,
+                                                                ctx->ac.i32_0,
+                                                                LLVMConstInt(ctx->ac.i32, 2 * i, 0));
+               }
+               ret = ac_build_gather_values(&ctx->ac, results, num_components);
+       } else {
+               ret = ac_build_buffer_load(&ctx->ac, rsrc, num_components, NULL, offset,
+                                          NULL, 0, false, false, true, true);
+
+               ret = ac_trim_vector(&ctx->ac, ret, num_components);
+       }
+
        return LLVMBuildBitCast(ctx->ac.builder, ret,
                                get_def_type(ctx, &instr->dest.ssa), "");
 }