[Mesa-dev] [PATCH] [rfc] ac/nir->llvm: workaround llvm lowering kill to exec mask
Nicolai Hähnle
nhaehnle at gmail.com
Tue Nov 1 13:49:13 UTC 2016
On 01.11.2016 05:32, Dave Airlie wrote:
> From: Dave Airlie <airlied at redhat.com>
>
> This just a discussion holder patch, radv has generated a shader
> using discard that lowers the kilp intrinsic into
>
> s_mov_b64 exec, 0 ; BEFE0180
>
> however that means exports never happen, and I think this leads
> to a GPU hang as the frag shader must make at least one NULL export.
>
> This hacks just replaces kilp intrinsic with an explcit export
> and endpgm for now. I'm sure it's probably all sorts of wrong.
>
> Either way I expect the fix has to be in the compiler, but this
> patch lets me get CTS to run again
Unfortunately, this will end up messing up other stuff when the kill
_isn't_ uniform, because now you have two places where you return from
the function, which is bound to mess with control flow in hilarious ways.
If you want to workaround the problem that you mentioned, I suggest
trying to see whether you can use some NIR transformation to lower the
kill as
kill(condition)
rather than
br condition, die, live
die:
kill
live:
Nicolai
> ---
> src/amd/common/ac_nir_to_llvm.c | 26 ++++++++++++++++++++++----
> 1 file changed, 22 insertions(+), 4 deletions(-)
>
> diff --git a/src/amd/common/ac_nir_to_llvm.c b/src/amd/common/ac_nir_to_llvm.c
> index a655806..4dd0d79 100644
> --- a/src/amd/common/ac_nir_to_llvm.c
> +++ b/src/amd/common/ac_nir_to_llvm.c
> @@ -2614,6 +2614,27 @@ static void emit_barrier(struct nir_to_llvm_context *ctx)
> ctx->voidt, NULL, 0, 0);
> }
>
> +static void
> +si_export_mrt_color(struct nir_to_llvm_context *ctx,
> + LLVMValueRef *color, unsigned param, bool is_last);
> +
> +static void emit_discard(struct nir_to_llvm_context *ctx)
> +{
> + ctx->shader_info->fs.can_discard = true;
> +
> + /* workaround LLVM lowering kilp to an execmask set to 0,
> + * which later means we don't do an export and hang the GPU.
> + */
> + if (1) {
> + si_export_mrt_color(ctx, NULL, V_008DFC_SQ_EXP_NULL, true);
> + LLVMBuildRetVoid(ctx->builder);
> + } else {
> + emit_llvm_intrinsic(ctx, "llvm.AMDGPU.kilp",
> + LLVMVoidTypeInContext(ctx->context),
> + NULL, 0, 0);
> + }
> +}
> +
> static LLVMValueRef
> visit_load_local_invocation_index(struct nir_to_llvm_context *ctx)
> {
> @@ -2921,10 +2942,7 @@ static void visit_intrinsic(struct nir_to_llvm_context *ctx,
> result = visit_image_size(ctx, instr);
> break;
> case nir_intrinsic_discard:
> - ctx->shader_info->fs.can_discard = true;
> - emit_llvm_intrinsic(ctx, "llvm.AMDGPU.kilp",
> - LLVMVoidTypeInContext(ctx->context),
> - NULL, 0, 0);
> + emit_discard(ctx);
> break;
> case nir_intrinsic_memory_barrier:
> emit_waitcnt(ctx);
>
More information about the mesa-dev
mailing list