radv/gfx10: fix crash when emitting NGG GS prologue
authorSamuel Pitoiset <samuel.pitoiset@gmail.com>
Sun, 14 Jul 2019 10:55:48 +0000 (12:55 +0200)
committerSamuel Pitoiset <samuel.pitoiset@gmail.com>
Mon, 15 Jul 2019 06:51:53 +0000 (08:51 +0200)
ac_nir_context is initialized after the driver emits the NGG GS
prologue so it's likely to crash.

Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
src/amd/vulkan/radv_nir_to_llvm.c

index e4ab584772967398b0c0faaca54f9e38ab27cfe7..00c7df8574b7bae536bdf937fa6529fb328b4ebc 100644 (file)
@@ -3382,15 +3382,22 @@ static void gfx10_ngg_gs_emit_prologue(struct radv_shader_context *ctx)
        LLVMBuilderRef builder = ctx->ac.builder;
        LLVMValueRef scratchptr = ctx->gs_ngg_scratch;
        LLVMValueRef tid = get_thread_id_in_tg(ctx);
-       LLVMValueRef tmp;
+       LLVMBasicBlockRef merge_block;
+       LLVMValueRef cond;
 
-       tmp = LLVMBuildICmp(builder, LLVMIntULT, tid, LLVMConstInt(ctx->ac.i32, 4, false), "");
-       ac_build_ifcc(&ctx->ac, tmp, 5090);
-       {
-               LLVMValueRef ptr = ac_build_gep0(&ctx->ac, scratchptr, tid);
-               LLVMBuildStore(builder, ctx->ac.i32_0, ptr);
-       }
-       ac_build_endif(&ctx->ac, 5090);
+       LLVMValueRef fn = LLVMGetBasicBlockParent(LLVMGetInsertBlock(ctx->ac.builder));
+       LLVMBasicBlockRef then_block = LLVMAppendBasicBlockInContext(ctx->ac.context, fn, "");
+       merge_block = LLVMAppendBasicBlockInContext(ctx->ac.context, fn, "");
+
+       cond = LLVMBuildICmp(builder, LLVMIntULT, tid, LLVMConstInt(ctx->ac.i32, 4, false), "");
+       LLVMBuildCondBr(ctx->ac.builder, cond, then_block, merge_block);
+       LLVMPositionBuilderAtEnd(ctx->ac.builder, then_block);
+
+       LLVMValueRef ptr = ac_build_gep0(&ctx->ac, scratchptr, tid);
+       LLVMBuildStore(builder, ctx->ac.i32_0, ptr);
+
+       LLVMBuildBr(ctx->ac.builder, merge_block);
+       LLVMPositionBuilderAtEnd(ctx->ac.builder, merge_block);
 
        ac_build_s_barrier(&ctx->ac);
 }