[Mesa-dev] [PATCH v2 1/3] ac: add support for more types with struct/raw LLVM intrinsics
Samuel Pitoiset
samuel.pitoiset at gmail.com
Mon Apr 15 16:43:54 UTC 2019
LLVM 9+ now supports 8-bit and 16-bit types.
v2: - rebase on master (without the vec3 change)
Signed-off-by: Samuel Pitoiset <samuel.pitoiset at gmail.com>
---
src/amd/common/ac_llvm_build.c | 46 +++++++++++++++++++---------------
1 file changed, 26 insertions(+), 20 deletions(-)
diff --git a/src/amd/common/ac_llvm_build.c b/src/amd/common/ac_llvm_build.c
index 8f40ddda0b5..92dd4104592 100644
--- a/src/amd/common/ac_llvm_build.c
+++ b/src/amd/common/ac_llvm_build.c
@@ -1135,6 +1135,7 @@ ac_build_llvm8_buffer_store_common(struct ac_llvm_context *ctx,
LLVMValueRef voffset,
LLVMValueRef soffset,
unsigned num_channels,
+ LLVMTypeRef base_type,
bool glc,
bool slc,
bool writeonly_memory,
@@ -1150,18 +1151,19 @@ 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 = CLAMP(num_channels, 1, 3) - 1;
-
- const char *type_names[] = {"f32", "v2f32", "v4f32"};
+ unsigned func = num_channels == 3 ? 4 : num_channels;
const char *indexing_kind = structurized ? "struct" : "raw";
- char name[256];
+ char name[256], type_name[8];
+
+ LLVMTypeRef type = func > 1 ? LLVMVectorType(base_type, func) : base_type;
+ ac_build_type_name_for_intr(type, type_name, sizeof(type_name));
if (use_format) {
snprintf(name, sizeof(name), "llvm.amdgcn.%s.buffer.store.format.%s",
- indexing_kind, type_names[func]);
+ indexing_kind, type_name);
} else {
snprintf(name, sizeof(name), "llvm.amdgcn.%s.buffer.store.%s",
- indexing_kind, type_names[func]);
+ indexing_kind, type_name);
}
ac_build_intrinsic(ctx, name, ctx->voidt, args, idx,
@@ -1181,8 +1183,8 @@ ac_build_buffer_store_format(struct ac_llvm_context *ctx,
if (HAVE_LLVM >= 0x800) {
ac_build_llvm8_buffer_store_common(ctx, rsrc, data, vindex,
voffset, NULL, num_channels,
- glc, false, writeonly_memory,
- true, true);
+ ctx->f32, glc, false,
+ writeonly_memory, true, true);
} else {
ac_build_buffer_store_common(ctx, rsrc, data, vindex, voffset,
num_channels, glc, false,
@@ -1245,6 +1247,7 @@ ac_build_buffer_store_dword(struct ac_llvm_context *ctx,
ctx->i32_0,
voffset, offset,
num_channels,
+ ctx->f32,
glc, slc,
writeonly_memory,
false, false);
@@ -1320,6 +1323,7 @@ ac_build_llvm8_buffer_load_common(struct ac_llvm_context *ctx,
LLVMValueRef voffset,
LLVMValueRef soffset,
unsigned num_channels,
+ LLVMTypeRef base_type,
bool glc,
bool slc,
bool can_speculate,
@@ -1334,23 +1338,22 @@ 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 = CLAMP(num_channels, 1, 3) - 1;
-
- LLVMTypeRef types[] = {ctx->f32, ctx->v2f32, ctx->v4f32};
- const char *type_names[] = {"f32", "v2f32", "v4f32"};
+ unsigned func = num_channels == 3 ? 4 : num_channels;
const char *indexing_kind = structurized ? "struct" : "raw";
- char name[256];
+ char name[256], type_name[8];
+
+ LLVMTypeRef type = func > 1 ? LLVMVectorType(base_type, func) : base_type;
+ ac_build_type_name_for_intr(type, type_name, sizeof(type_name));
if (use_format) {
snprintf(name, sizeof(name), "llvm.amdgcn.%s.buffer.load.format.%s",
- indexing_kind, type_names[func]);
+ indexing_kind, type_name);
} else {
snprintf(name, sizeof(name), "llvm.amdgcn.%s.buffer.load.%s",
- indexing_kind, type_names[func]);
+ indexing_kind, type_name);
}
- return ac_build_intrinsic(ctx, name, types[func], args,
- idx,
+ return ac_build_intrinsic(ctx, name, type, args, idx,
ac_get_load_intr_attribs(can_speculate));
}
@@ -1409,7 +1412,8 @@ ac_build_buffer_load(struct ac_llvm_context *ctx,
if (HAVE_LLVM >= 0x0800) {
return ac_build_llvm8_buffer_load_common(ctx, rsrc, vindex,
offset, ctx->i32_0,
- num_channels, glc, slc,
+ num_channels, ctx->f32,
+ glc, slc,
can_speculate, false,
false);
}
@@ -1429,7 +1433,8 @@ LLVMValueRef ac_build_buffer_load_format(struct ac_llvm_context *ctx,
{
if (HAVE_LLVM >= 0x800) {
return ac_build_llvm8_buffer_load_common(ctx, rsrc, vindex, voffset, ctx->i32_0,
- num_channels, glc, false,
+ num_channels, ctx->f32,
+ glc, false,
can_speculate, true, true);
}
return ac_build_buffer_load_common(ctx, rsrc, vindex, voffset,
@@ -1447,7 +1452,8 @@ LLVMValueRef ac_build_buffer_load_format_gfx9_safe(struct ac_llvm_context *ctx,
{
if (HAVE_LLVM >= 0x800) {
return ac_build_llvm8_buffer_load_common(ctx, rsrc, vindex, voffset, ctx->i32_0,
- num_channels, glc, false,
+ num_channels, ctx->f32,
+ glc, false,
can_speculate, true, true);
}
--
2.21.0
More information about the mesa-dev
mailing list