ac: add v2f32 to the common code and make use of it
authorTimothy Arceri <tarceri@itsqueeze.com>
Thu, 2 Nov 2017 02:24:27 +0000 (13:24 +1100)
committerTimothy Arceri <tarceri@itsqueeze.com>
Fri, 3 Nov 2017 03:54:46 +0000 (14:54 +1100)
Reviewed-by: Marek Olšák <marek.olsak@amd.com
Acked-by: Nicolai Hähnle <nicolai.haehnle@amd.com>
src/amd/common/ac_llvm_build.c
src/amd/common/ac_llvm_build.h
src/amd/common/ac_nir_to_llvm.c

index 1519262b3ddd601143a495e7f0eb9c7921d1dea7..5640a23b8aa32a0db52e0a2eb360a97bc7f39ef9 100644 (file)
@@ -69,6 +69,7 @@ ac_llvm_context_init(struct ac_llvm_context *ctx, LLVMContextRef context,
        ctx->v2i32 = LLVMVectorType(ctx->i32, 2);
        ctx->v3i32 = LLVMVectorType(ctx->i32, 3);
        ctx->v4i32 = LLVMVectorType(ctx->i32, 4);
+       ctx->v2f32 = LLVMVectorType(ctx->f32, 2);
        ctx->v4f32 = LLVMVectorType(ctx->f32, 4);
        ctx->v8i32 = LLVMVectorType(ctx->i32, 8);
 
index f662cc4dd89fab729eb61a3dc78679adfaf74ce2..1f51937c9e132029689b57c4312f545213041be8 100644 (file)
@@ -55,6 +55,7 @@ struct ac_llvm_context {
        LLVMTypeRef v2i32;
        LLVMTypeRef v3i32;
        LLVMTypeRef v4i32;
+       LLVMTypeRef v2f32;
        LLVMTypeRef v4f32;
        LLVMTypeRef v8i32;
 
index 1e1a1c0276a893da7cccd200779a66d0c66d49a7..ac50debdde61039cf99a954c3661318d67456ef0 100644 (file)
@@ -134,7 +134,6 @@ struct nir_to_llvm_context {
        LLVMValueRef persp_sample, persp_center, persp_centroid;
        LLVMValueRef linear_sample, linear_center, linear_centroid;
 
-       LLVMTypeRef v2f32;
        LLVMTypeRef v4f32;
 
        unsigned uniform_md_kind;
@@ -985,7 +984,6 @@ static void create_function(struct nir_to_llvm_context *ctx,
 
 static void setup_types(struct nir_to_llvm_context *ctx)
 {
-       ctx->v2f32 = LLVMVectorType(ctx->ac.f32, 2);
        ctx->v4f32 = LLVMVectorType(ctx->ac.f32, 4);
 
        ctx->uniform_md_kind =
@@ -1450,8 +1448,7 @@ static LLVMValueRef emit_unpack_half_2x16(struct ac_llvm_context *ctx,
                temps[i] = LLVMBuildFPExt(ctx->builder, val, ctx->f32, "");
        }
 
-       LLVMTypeRef v2f32 = LLVMVectorType(ctx->f32, 2);
-       result = LLVMBuildInsertElement(ctx->builder, LLVMGetUndef(v2f32), temps[0],
+       result = LLVMBuildInsertElement(ctx->builder, LLVMGetUndef(ctx->v2f32), temps[0],
                                        ctx->i32_0, "");
        result = LLVMBuildInsertElement(ctx->builder, result, temps[1],
                                        ctx->i32_1, "");
@@ -2305,11 +2302,9 @@ static void visit_store_ssbo(struct ac_nir_context *ctx,
                        store_name = "llvm.amdgcn.buffer.store.v4f32";
                        data = base_data;
                } else if (count == 2) {
-                       LLVMTypeRef v2f32 = LLVMVectorType(ctx->ac.f32, 2);
-
                        tmp = LLVMBuildExtractElement(ctx->ac.builder,
                                                      base_data, LLVMConstInt(ctx->ac.i32, start, false), "");
-                       data = LLVMBuildInsertElement(ctx->ac.builder, LLVMGetUndef(v2f32), tmp,
+                       data = LLVMBuildInsertElement(ctx->ac.builder, LLVMGetUndef(ctx->ac.v2f32), tmp,
                                                      ctx->ac.i32_0, "");
 
                        tmp = LLVMBuildExtractElement(ctx->ac.builder,
@@ -3803,7 +3798,7 @@ static LLVMValueRef load_sample_position(struct nir_to_llvm_context *ctx,
        LLVMValueRef ptr = ac_build_gep0(&ctx->ac, ctx->ring_offsets, LLVMConstInt(ctx->ac.i32, RING_PS_SAMPLE_POSITIONS, false));
 
        ptr = LLVMBuildBitCast(ctx->builder, ptr,
-                              const_array(ctx->v2f32, 64), "");
+                              const_array(ctx->ac.v2f32, 64), "");
 
        sample_id = LLVMBuildAdd(ctx->builder, sample_id, ctx->sample_pos_offset, "");
        result = ac_build_load_invariant(&ctx->ac, ptr, sample_id);
@@ -3906,7 +3901,7 @@ static LLVMValueRef visit_interp(struct nir_to_llvm_context *ctx,
 
                if (interp_param) {
                        interp_param = LLVMBuildBitCast(ctx->builder,
-                                                       interp_param, LLVMVectorType(ctx->ac.f32, 2), "");
+                                                       interp_param, ctx->ac.v2f32, "");
                        LLVMValueRef i = LLVMBuildExtractElement(
                                ctx->builder, interp_param, ctx->ac.i32_0, "");
                        LLVMValueRef j = LLVMBuildExtractElement(
@@ -5045,7 +5040,7 @@ static void interp_fs_input(struct nir_to_llvm_context *ctx,
         */
        if (interp) {
                interp_param = LLVMBuildBitCast(ctx->builder, interp_param,
-                                               LLVMVectorType(ctx->ac.f32, 2), "");
+                                               ctx->ac.v2f32, "");
 
                i = LLVMBuildExtractElement(ctx->builder, interp_param,
                                                ctx->ac.i32_0, "");