[Mesa-dev] [PATCH] radv: handle multi-component shared load/stores.

Bas Nieuwenhuizen bas at basnieuwenhuizen.nl
Fri Dec 23 09:50:24 UTC 2016


On Fri, Dec 23, 2016 at 6:42 AM, Dave Airlie <airlied at gmail.com> wrote:
> From: Dave Airlie <airlied at redhat.com>
>
> This was seen in doom shaders, so handle it properly.

I was trying to just change the type and keep a single load/store.
Turns out that has some issues indeed, and is not that helpful for
shared accesses anyway, as LLVM can merge them.

Reviewed-by: Bas Nieuwenhuizen <bas at basnieuwenhuizen.nl>

>
> Signed-off-by: Dave AIrlie <airlied at redhat.com>
> ---
>  src/amd/common/ac_nir_to_llvm.c | 41 +++++++++++++++++++++++++++++------------
>  1 file changed, 29 insertions(+), 12 deletions(-)
>
> diff --git a/src/amd/common/ac_nir_to_llvm.c b/src/amd/common/ac_nir_to_llvm.c
> index 44696b0..cbad8d2 100644
> --- a/src/amd/common/ac_nir_to_llvm.c
> +++ b/src/amd/common/ac_nir_to_llvm.c
> @@ -2253,13 +2253,15 @@ static LLVMValueRef visit_load_var(struct nir_to_llvm_context *ctx,
>                                       &const_index, &indir_index);
>                 LLVMValueRef ptr = get_shared_memory_ptr(ctx, idx, ctx->i32);
>                 LLVMValueRef derived_ptr;
> -               LLVMValueRef index = ctx->i32zero;
> -               if (indir_index)
> -                       index = LLVMBuildAdd(ctx->builder, index, indir_index, "");
> -               derived_ptr = LLVMBuildGEP(ctx->builder, ptr, &index, 1, "");
>
> -               return to_integer(ctx, LLVMBuildLoad(ctx->builder, derived_ptr, ""));
> -               break;
> +               for (unsigned chan = 0; chan < ve; chan++) {
> +                       LLVMValueRef index = LLVMConstInt(ctx->i32, chan, false);
> +                       if (indir_index)
> +                               index = LLVMBuildAdd(ctx->builder, index, indir_index, "");
> +                       derived_ptr = LLVMBuildGEP(ctx->builder, ptr, &index, 1, "");
> +                       values[chan] = LLVMBuildLoad(ctx->builder, derived_ptr, "");
> +               }
> +               return to_integer(ctx, build_gather_values(ctx, values, ve));
>         }
>         default:
>                 break;
> @@ -2354,14 +2356,29 @@ visit_store_var(struct nir_to_llvm_context *ctx,
>                                       &const_index, &indir_index);
>
>                 ptr = get_shared_memory_ptr(ctx, idx, ctx->i32);
> -               LLVMValueRef index = ctx->i32zero;
>                 LLVMValueRef derived_ptr;
>
> -               if (indir_index)
> -                       index = LLVMBuildAdd(ctx->builder, index, indir_index, "");
> -               derived_ptr = LLVMBuildGEP(ctx->builder, ptr, &index, 1, "");
> -               LLVMBuildStore(ctx->builder,
> -                              to_integer(ctx, src), derived_ptr);
> +               for (unsigned chan = 0; chan < 4; chan++) {
> +                       if (!(writemask & (1 << chan)))
> +                               continue;
> +
> +                       LLVMValueRef index = LLVMConstInt(ctx->i32, chan, false);
> +
> +                       if (get_llvm_num_components(src) == 1)
> +                               value = src;
> +                       else
> +                               value = LLVMBuildExtractElement(ctx->builder, src,
> +                                                               LLVMConstInt(ctx->i32,
> +                                                                            chan, false),
> +                                                               "");
> +
> +                       if (indir_index)
> +                               index = LLVMBuildAdd(ctx->builder, index, indir_index, "");
> +
> +                       derived_ptr = LLVMBuildGEP(ctx->builder, ptr, &index, 1, "");
> +                       LLVMBuildStore(ctx->builder,
> +                                      to_integer(ctx, value), derived_ptr);
> +               }
>                 break;
>         }
>         default:
> --
> 2.7.4
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev


More information about the mesa-dev mailing list