gallium/radeon: add basic code for setting shader return values
authorMarek Olšák <marek.olsak@amd.com>
Tue, 22 Dec 2015 19:55:53 +0000 (20:55 +0100)
committerMarek Olšák <marek.olsak@amd.com>
Sun, 21 Feb 2016 20:08:57 +0000 (21:08 +0100)
LLVMBuildInsertValue will be used on return_value.

Reviewed-by: Nicolai Hähnle <nicolai.haehnle@amd.com>
src/gallium/drivers/r600/r600_llvm.c
src/gallium/drivers/radeon/radeon_llvm.h
src/gallium/drivers/radeon/radeon_setup_tgsi_llvm.c
src/gallium/drivers/radeonsi/si_shader.c

index 981bb12f90076f24fd3dd8a00f9f199207be4574..7eab29c6eb41ce50e097f177a4224d203b5b9bf0 100644 (file)
@@ -789,7 +789,7 @@ LLVMModuleRef r600_tgsi_llvm(
        unsigned ArgumentsCount = 0;
        for (unsigned i = 0; i < ctx->inputs_count; i++)
                Arguments[ArgumentsCount++] = LLVMVectorType(bld_base->base.elem_type, 4);
-       radeon_llvm_create_func(ctx, Arguments, ArgumentsCount);
+       radeon_llvm_create_func(ctx, NULL, 0, Arguments, ArgumentsCount);
        for (unsigned i = 0; i < ctx->inputs_count; i++) {
                LLVMValueRef P = LLVMGetParam(ctx->main_fn, i);
                LLVMAddAttribute(P, LLVMInRegAttribute);
index 9f7d03909e963b5a5edf68104b1df93252b1dcc6..bdee2f8020ab37bd3edbfd66877a35e9b6a6101c 100644 (file)
@@ -113,6 +113,7 @@ struct radeon_llvm_context {
        struct tgsi_declaration_range *arrays;
 
        LLVMValueRef main_fn;
+       LLVMTypeRef return_type;
 
        struct gallivm_state gallivm;
 };
@@ -162,7 +163,8 @@ void radeon_llvm_context_init(struct radeon_llvm_context * ctx,
                               const char *triple);
 
 void radeon_llvm_create_func(struct radeon_llvm_context * ctx,
-                             LLVMTypeRef *ParamTypes, unsigned ParamCount);
+                            LLVMTypeRef *return_types, unsigned num_return_elems,
+                            LLVMTypeRef *ParamTypes, unsigned ParamCount);
 
 void radeon_llvm_dispose(struct radeon_llvm_context * ctx);
 
index 076d70ebc0bbb395ada46cf0507de0b1815a680e..c74397fb5c94c35275e8a2ad9401d58876594607 100644 (file)
@@ -1701,14 +1701,22 @@ void radeon_llvm_context_init(struct radeon_llvm_context * ctx, const char *trip
 }
 
 void radeon_llvm_create_func(struct radeon_llvm_context * ctx,
+                            LLVMTypeRef *return_types, unsigned num_return_elems,
                             LLVMTypeRef *ParamTypes, unsigned ParamCount)
 {
-       LLVMTypeRef main_fn_type;
+       LLVMTypeRef main_fn_type, ret_type;
        LLVMBasicBlockRef main_fn_body;
 
+       if (num_return_elems)
+               ret_type = LLVMStructTypeInContext(ctx->gallivm.context,
+                                                  return_types,
+                                                  num_return_elems, true);
+       else
+               ret_type = LLVMVoidTypeInContext(ctx->gallivm.context);
+
        /* Setup the function */
-       main_fn_type = LLVMFunctionType(LLVMVoidTypeInContext(ctx->gallivm.context),
-                                       ParamTypes, ParamCount, 0);
+       ctx->return_type = ret_type;
+       main_fn_type = LLVMFunctionType(ret_type, ParamTypes, ParamCount, 0);
        ctx->main_fn = LLVMAddFunction(ctx->gallivm.module, "main", main_fn_type);
        main_fn_body = LLVMAppendBasicBlockInContext(ctx->gallivm.context,
                        ctx->main_fn, "main_body");
index d1482de209d101803d5581a3d6021a81437211c0..422608eb4cee40f58909d877154ca4742dc4d906 100644 (file)
@@ -96,6 +96,7 @@ struct si_shader_context
        LLVMValueRef esgs_ring;
        LLVMValueRef gsvs_ring[4];
        LLVMValueRef gs_next_vertex[4];
+       LLVMValueRef return_value;
 
        LLVMTypeRef voidt;
        LLVMTypeRef i1;
@@ -3711,8 +3712,10 @@ static void create_function(struct si_shader_context *ctx)
        }
 
        assert(num_params <= Elements(params));
-       radeon_llvm_create_func(&ctx->radeon_bld, params, num_params);
+       radeon_llvm_create_func(&ctx->radeon_bld, NULL, 0,
+                               params, num_params);
        radeon_llvm_shader_type(ctx->radeon_bld.main_fn, ctx->type);
+       ctx->return_value = LLVMGetUndef(ctx->radeon_bld.return_type);
 
        for (i = 0; i <= last_sgpr; ++i) {
                LLVMValueRef P = LLVMGetParam(ctx->radeon_bld.main_fn, i);
@@ -4241,7 +4244,7 @@ static int si_generate_gs_copy_shader(struct si_screen *sscreen,
 
        si_llvm_export_vs(bld_base, outputs, gsinfo->num_outputs);
 
-       LLVMBuildRetVoid(bld_base->base.gallivm->builder);
+       LLVMBuildRet(gallivm->builder, ctx->return_value);
 
        /* Dump LLVM IR before any optimization passes */
        if (sscreen->b.debug_flags & DBG_PREOPT_IR &&
@@ -4475,7 +4478,7 @@ int si_shader_create(struct si_screen *sscreen, LLVMTargetMachineRef tm,
                goto out;
        }
 
-       LLVMBuildRetVoid(bld_base->base.gallivm->builder);
+       LLVMBuildRet(bld_base->base.gallivm->builder, ctx.return_value);
        mod = bld_base->base.gallivm->module;
 
        /* Dump LLVM IR before any optimization passes */