gallivm: Separate freeing LLVM intermediate data from freeing final code.
[mesa.git] / src / gallium / auxiliary / gallivm / lp_bld_tgsi_aos.c
index 53013f75f2e1f4ca7b845cf54cfce65234ec1cbb..4dee9bb4dd41e0d3c8c3495803282c5c7d6dbeb9 100644 (file)
@@ -56,6 +56,7 @@
 #include "lp_bld_quad.h"
 #include "lp_bld_tgsi.h"
 #include "lp_bld_debug.h"
+#include "lp_bld_sample.h"
 
 
 /**
@@ -93,7 +94,7 @@ swizzle_scalar_aos(struct lp_build_tgsi_aos_context *bld,
                    unsigned chan)
 {
    chan = bld->swizzles[chan];
-   return lp_build_swizzle_scalar_aos(&bld->bld_base.base, a, chan);
+   return lp_build_swizzle_scalar_aos(&bld->bld_base.base, a, chan, 4);
 }
 
 
@@ -101,7 +102,8 @@ static LLVMValueRef
 emit_fetch_constant(
    struct lp_build_tgsi_context * bld_base,
    const struct tgsi_full_src_register * reg,
-   const unsigned swizzle)
+   enum tgsi_opcode_type stype,
+   unsigned swizzle)
 {
    struct lp_build_tgsi_aos_context * bld = lp_aos_context(bld_base);
    LLVMBuilderRef builder = bld_base->base.gallivm->builder;
@@ -171,7 +173,8 @@ static LLVMValueRef
 emit_fetch_immediate(
    struct lp_build_tgsi_context * bld_base,
    const struct tgsi_full_src_register * reg,
-   const unsigned swizzle)
+   enum tgsi_opcode_type stype,
+   unsigned swizzle)
 {
    struct lp_build_tgsi_aos_context * bld = lp_aos_context(bld_base);
    LLVMValueRef res = bld->immediates[reg->Register.Index];
@@ -183,7 +186,8 @@ static LLVMValueRef
 emit_fetch_input(
    struct lp_build_tgsi_context * bld_base,
    const struct tgsi_full_src_register * reg,
-   const unsigned swizzle)
+   enum tgsi_opcode_type stype,
+   unsigned swizzle)
 {
    struct lp_build_tgsi_aos_context * bld = lp_aos_context(bld_base);
    LLVMValueRef res = bld->inputs[reg->Register.Index];
@@ -196,7 +200,8 @@ static LLVMValueRef
 emit_fetch_temporary(
    struct lp_build_tgsi_context * bld_base,
    const struct tgsi_full_src_register * reg,
-   const unsigned swizzle)
+   enum tgsi_opcode_type stype,
+   unsigned swizzle)
 {
    struct lp_build_tgsi_aos_context * bld = lp_aos_context(bld_base);
    LLVMBuilderRef builder = bld_base->base.gallivm->builder;
@@ -321,8 +326,11 @@ lp_emit_store_aos(
    if (reg->Register.WriteMask != TGSI_WRITEMASK_XYZW) {
       LLVMValueRef writemask;
 
-      writemask = lp_build_const_mask_aos(bld->bld_base.base.gallivm, bld->bld_base.base.type,
-                                          reg->Register.WriteMask);
+      writemask = lp_build_const_mask_aos_swizzled(bld->bld_base.base.gallivm,
+                                                   bld->bld_base.base.type,
+                                                   reg->Register.WriteMask,
+                                                   TGSI_NUM_CHANNELS,
+                                                   bld->swizzles);
 
       if (mask) {
          mask = LLVMBuildAnd(builder, mask, writemask, "");
@@ -355,8 +363,7 @@ emit_tex(struct lp_build_tgsi_aos_context *bld,
    unsigned target;
    unsigned unit;
    LLVMValueRef coords;
-   LLVMValueRef ddx;
-   LLVMValueRef ddy;
+   struct lp_derivatives derivs = { {NULL}, {NULL} };
 
    if (!bld->sampler) {
       _debug_printf("warning: found texture instruction but no sampler generator supplied\n");
@@ -368,25 +375,18 @@ emit_tex(struct lp_build_tgsi_aos_context *bld,
    coords = lp_build_emit_fetch( &bld->bld_base, inst, 0 , LP_CHAN_ALL);
 
    if (modifier == LP_BLD_TEX_MODIFIER_EXPLICIT_DERIV) {
-      ddx = lp_build_emit_fetch( &bld->bld_base, inst, 1 , LP_CHAN_ALL);
-      ddy = lp_build_emit_fetch( &bld->bld_base, inst, 2 , LP_CHAN_ALL);
+      /* probably not going to work */
+      derivs.ddx[0] = lp_build_emit_fetch( &bld->bld_base, inst, 1 , LP_CHAN_ALL);
+      derivs.ddy[0] = lp_build_emit_fetch( &bld->bld_base, inst, 2 , LP_CHAN_ALL);
       unit = inst->Src[3].Register.Index;
-   }  else {
-#if 0
-      ddx = lp_build_ddx( &bld->bld_base.base, coords );
-      ddy = lp_build_ddy( &bld->bld_base.base, coords );
-#else
-      /* TODO */
-      ddx = bld->bld_base.base.one;
-      ddy = bld->bld_base.base.one;
-#endif
+   }
+   else {
       unit = inst->Src[1].Register.Index;
    }
-
    return bld->sampler->emit_fetch_texel(bld->sampler,
                                          &bld->bld_base.base,
                                          target, unit,
-                                         coords, ddx, ddy,
+                                         coords, derivs,
                                          modifier);
 }
 
@@ -406,7 +406,7 @@ lp_emit_declaration_aos(
    for (idx = first; idx <= last; ++idx) {
       switch (decl->Declaration.File) {
       case TGSI_FILE_TEMPORARY:
-         assert(idx < LP_MAX_TGSI_TEMPS);
+         assert(idx < LP_MAX_INLINED_TEMPS);
          if (bld->indirect_files & (1 << TGSI_FILE_TEMPORARY)) {
             LLVMValueRef array_size = lp_build_const_int32(gallivm, last + 1);
             bld->temps_array = lp_build_array_alloca(bld->bld_base.base.gallivm,
@@ -529,7 +529,7 @@ lp_emit_instruction_aos(
    case TGSI_OPCODE_MIN:
       src0 = lp_build_emit_fetch(&bld->bld_base, inst, 0, LP_CHAN_ALL);
       src1 = lp_build_emit_fetch(&bld->bld_base, inst, 1, LP_CHAN_ALL);
-      dst0 = lp_build_max(&bld->bld_base.base, src0, src1);
+      dst0 = lp_build_min(&bld->bld_base.base, src0, src1);
       break;
 
    case TGSI_OPCODE_MAX:
@@ -616,7 +616,7 @@ lp_emit_instruction_aos(
 
    case TGSI_OPCODE_EX2:
       src0 = lp_build_emit_fetch(&bld->bld_base, inst, 0, LP_CHAN_ALL);
-      tmp0 = lp_build_swizzle_scalar_aos(&bld->bld_base.base, src0, TGSI_SWIZZLE_X);
+      tmp0 = lp_build_swizzle_scalar_aos(&bld->bld_base.base, src0, TGSI_SWIZZLE_X, TGSI_NUM_CHANNELS);
       dst0 = lp_build_exp2(&bld->bld_base.base, tmp0);
       break;
 
@@ -657,12 +657,10 @@ lp_emit_instruction_aos(
    case TGSI_OPCODE_DDY:
       return FALSE;
 
-   case TGSI_OPCODE_KILP:
-      /* predicated kill */
+   case TGSI_OPCODE_KILL:
       return FALSE;
 
-   case TGSI_OPCODE_KIL:
-      /* conditional kill */
+   case TGSI_OPCODE_KILL_IF:
       return FALSE;
 
    case TGSI_OPCODE_PK2H:
@@ -837,6 +835,7 @@ lp_emit_instruction_aos(
       return FALSE;
 
    case TGSI_OPCODE_IF:
+   case TGSI_OPCODE_UIF:
       return FALSE;
 
    case TGSI_OPCODE_BGNLOOP:
@@ -991,6 +990,8 @@ lp_build_tgsi_aos(struct gallivm_state *gallivm,
    /* Setup build context */
    memset(&bld, 0, sizeof bld);
    lp_build_context_init(&bld.bld_base.base, gallivm, type);
+   lp_build_context_init(&bld.bld_base.uint_bld, gallivm, lp_uint_type(type));
+   lp_build_context_init(&bld.bld_base.int_bld, gallivm, lp_int_type(type));
    lp_build_context_init(&bld.int_bld, gallivm, lp_int_type(type));
 
    for (chan = 0; chan < 4; ++chan) {
@@ -1041,7 +1042,7 @@ lp_build_tgsi_aos(struct gallivm_state *gallivm,
             const uint size = parse.FullToken.FullImmediate.Immediate.NrTokens - 1;
             float imm[4];
             assert(size <= 4);
-            assert(num_immediates < LP_MAX_TGSI_IMMEDIATES);
+            assert(num_immediates < LP_MAX_INLINED_IMMEDIATES);
             for (chan = 0; chan < 4; ++chan) {
                imm[chan] = 0.0f;
             }
@@ -1083,6 +1084,7 @@ lp_build_tgsi_aos(struct gallivm_state *gallivm,
       debug_printf("2222222222222222222222222222 \n");
    }
    tgsi_parse_free(&parse);
+   FREE(bld.bld_base.instructions);
 
    if (0) {
       LLVMModuleRef module = LLVMGetGlobalParent(