Re: [Mesa-dev] [PATCH 1/3] ac: add support for more types with struct/raw LLVM intrinsics

2019-04-17 Thread Bas Nieuwenhuizen
r-b for the series

On Tue, Mar 26, 2019 at 12:36 PM Samuel Pitoiset
 wrote:
>
> LLVM 9+ now supports 8-bit and 16-bit types.
>
> This changes requires LLVM r356465.
>
> Signed-off-by: Samuel Pitoiset 
> ---
>  src/amd/common/ac_llvm_build.c | 51 +++---
>  1 file changed, 28 insertions(+), 23 deletions(-)
>
> diff --git a/src/amd/common/ac_llvm_build.c b/src/amd/common/ac_llvm_build.c
> index a816327ce95..88df82dcc54 100644
> --- a/src/amd/common/ac_llvm_build.c
> +++ b/src/amd/common/ac_llvm_build.c
> @@ -1136,6 +1136,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,
> @@ -1151,21 +1152,22 @@ 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, 4) - 1;
> +   unsigned func = CLAMP(num_channels, 1, 4);
> +   const char *indexing_kind = structurized ? "struct" : "raw";
> +   char name[256], type_name[8];
>
> -   if (HAVE_LLVM == 0x800 && func == 2)
> -   func = 3; /* Only LLVM 9+ supports vec3 */
> +   if (HAVE_LLVM == 0x800 && func == 3)
> +   func = 4; /* Only LLVM 9+ supports vec3 */
>
> -   const char *type_names[] = {"f32", "v2f32", "v3f32", "v4f32"};
> -   const char *indexing_kind = structurized ? "struct" : "raw";
> -   char name[256];
> +   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,
> @@ -1185,8 +1187,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,
> @@ -1249,6 +1251,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);
> @@ -1324,6 +1327,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,
> @@ -1338,26 +1342,26 @@ 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, 4) - 1;
> +   unsigned func = CLAMP(num_channels, 1, 4);
>
> -   if (HAVE_LLVM == 0x800 && func == 2)
> -   func = 3; /* Only LLVM 9+ supports vec3 */
> +   if (HAVE_LLVM == 0x800 

[Mesa-dev] [PATCH 1/3] ac: add support for more types with struct/raw LLVM intrinsics

2019-03-26 Thread Samuel Pitoiset
LLVM 9+ now supports 8-bit and 16-bit types.

This changes requires LLVM r356465.

Signed-off-by: Samuel Pitoiset 
---
 src/amd/common/ac_llvm_build.c | 51 +++---
 1 file changed, 28 insertions(+), 23 deletions(-)

diff --git a/src/amd/common/ac_llvm_build.c b/src/amd/common/ac_llvm_build.c
index a816327ce95..88df82dcc54 100644
--- a/src/amd/common/ac_llvm_build.c
+++ b/src/amd/common/ac_llvm_build.c
@@ -1136,6 +1136,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,
@@ -1151,21 +1152,22 @@ 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, 4) - 1;
+   unsigned func = CLAMP(num_channels, 1, 4);
+   const char *indexing_kind = structurized ? "struct" : "raw";
+   char name[256], type_name[8];
 
-   if (HAVE_LLVM == 0x800 && func == 2)
-   func = 3; /* Only LLVM 9+ supports vec3 */
+   if (HAVE_LLVM == 0x800 && func == 3)
+   func = 4; /* Only LLVM 9+ supports vec3 */
 
-   const char *type_names[] = {"f32", "v2f32", "v3f32", "v4f32"};
-   const char *indexing_kind = structurized ? "struct" : "raw";
-   char name[256];
+   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,
@@ -1185,8 +1187,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,
@@ -1249,6 +1251,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);
@@ -1324,6 +1327,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,
@@ -1338,26 +1342,26 @@ 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, 4) - 1;
+   unsigned func = CLAMP(num_channels, 1, 4);
 
-   if (HAVE_LLVM == 0x800 && func == 2)
-   func = 3; /* Only LLVM 9+ supports vec3 */
+   if (HAVE_LLVM == 0x800 && func == 3)
+   func = 4; /* Only LLVM 9+ supports vec3 */
 
-   LLVMTypeRef types[] = {ctx->f32, ctx->v2f32, ctx->v3f32, ctx->v4f32};
-   const char *type_names[] = {"f32", "v2f32", "v3f32", "v4f32"};
+   LLVMTypeRef type = func > 1 ?