llvmpipe: Put color/depth directly into the quad structure.
authorJosé Fonseca <jfonseca@vmware.com>
Wed, 19 Aug 2009 08:24:20 +0000 (09:24 +0100)
committerJosé Fonseca <jfonseca@vmware.com>
Sat, 29 Aug 2009 08:21:35 +0000 (09:21 +0100)
src/gallium/drivers/llvmpipe/lp_quad_fs.c
src/gallium/drivers/llvmpipe/lp_state.h
src/gallium/drivers/llvmpipe/lp_state_fs.c

index 5a4cadcd6bb8ffedc812455c3c2e0acb7290450c..8fa357dd4f3bde57c5e9224c079fe75a61ccb260 100644 (file)
@@ -55,7 +55,6 @@ struct quad_shade_stage
 
    union tgsi_exec_channel ALIGN16_ATTRIB pos[NUM_CHANNELS];
 
-   struct tgsi_exec_vector ALIGN16_ATTRIB outputs[PIPE_MAX_ATTRIBS];
    uint32_t ALIGN16_ATTRIB mask[NUM_CHANNELS];
 };
 
@@ -111,7 +110,6 @@ shade_quad(struct quad_stage *qs, struct quad_header *quad)
    void *constants;
    struct tgsi_sampler **samplers;
    unsigned chan_index;
-   boolean z_written;
 
    /* Compute X, Y, Z, W vals for this quad */
    setup_pos_vector(qss,
@@ -131,8 +129,9 @@ shade_quad(struct quad_stage *qs, struct quad_header *quad)
                                quad->coef->dadx,
                                quad->coef->dady,
                                constants,
-                               qss->outputs,
                                qss->mask,
+                               quad->output.color,
+                               quad->output.depth,
                                samplers);
 
    for (chan_index = 0; chan_index < NUM_CHANNELS; ++chan_index)
@@ -141,36 +140,6 @@ shade_quad(struct quad_stage *qs, struct quad_header *quad)
    if (quad->inout.mask == 0)
       return FALSE;
 
-   /* store outputs */
-   z_written = FALSE;
-   {
-      const ubyte *sem_name = llvmpipe->fs->info.output_semantic_name;
-      const ubyte *sem_index = llvmpipe->fs->info.output_semantic_index;
-      const uint n = qss->stage.llvmpipe->fs->info.num_outputs;
-      uint i;
-      for (i = 0; i < n; i++) {
-         switch (sem_name[i]) {
-         case TGSI_SEMANTIC_COLOR:
-            {
-               uint cbuf = sem_index[i];
-               memcpy(quad->output.color[cbuf],
-                      &qss->outputs[i].xyzw[0].f[0],
-                      sizeof(quad->output.color[0]) );
-            }
-            break;
-         case TGSI_SEMANTIC_POSITION:
-            {
-               uint j;
-               for (j = 0; j < 4; j++) {
-                  quad->output.depth[j] = qss->outputs[0].xyzw[2].f[j];
-               }
-               z_written = TRUE;
-            }
-            break;
-         }
-      }
-   }
-
    return TRUE;
 }
 
index f823762c46506fb20d06bcd24aecc6a4d991cb4b..df7fff9d38cff3bb11064a8848aac614b9d1bbee 100644 (file)
@@ -64,8 +64,9 @@ typedef void
                      const void *dadx,
                      const void *dady,
                      const void *consts,
-                     void *outputs,
                      uint32_t *mask,
+                     void *color,
+                     void *depth,
                      struct tgsi_sampler **samplers);
 
 /**
index 1397f948b2753a50236bd5abc28e17979a579fbb..814ed0f1427e62830b9311213255920131eaf567 100644 (file)
@@ -52,22 +52,25 @@ shader_generate(struct llvmpipe_screen *screen,
    LLVMTypeRef elem_type;
    LLVMTypeRef vec_type;
    LLVMTypeRef int_vec_type;
-   LLVMTypeRef arg_types[8];
+   LLVMTypeRef arg_types[9];
    LLVMTypeRef func_type;
    LLVMValueRef pos_ptr;
    LLVMValueRef a0_ptr;
    LLVMValueRef dadx_ptr;
    LLVMValueRef dady_ptr;
    LLVMValueRef consts_ptr;
-   LLVMValueRef outputs_ptr;
    LLVMValueRef mask_ptr;
+   LLVMValueRef color_ptr;
+   LLVMValueRef depth_ptr;
    LLVMValueRef samplers_ptr;
    LLVMBasicBlockRef block;
    LLVMBuilderRef builder;
    LLVMValueRef pos[NUM_CHANNELS];
    LLVMValueRef outputs[PIPE_MAX_SHADER_OUTPUTS][NUM_CHANNELS];
    LLVMValueRef mask;
-   unsigned i, j;
+   unsigned i;
+   unsigned attrib;
+   unsigned chan;
 
    type.value = 0;
    type.floating = TRUE;
@@ -85,9 +88,10 @@ shader_generate(struct llvmpipe_screen *screen,
    arg_types[2] = LLVMPointerType(elem_type, 0);       /* dadx */
    arg_types[3] = LLVMPointerType(elem_type, 0);       /* dady */
    arg_types[4] = LLVMPointerType(elem_type, 0);       /* consts */
-   arg_types[5] = LLVMPointerType(vec_type, 0);        /* outputs */
-   arg_types[6] = LLVMPointerType(int_vec_type, 0);    /* mask */
-   arg_types[7] = LLVMPointerType(LLVMInt8Type(), 0);  /* samplers */
+   arg_types[5] = LLVMPointerType(int_vec_type, 0);    /* mask */
+   arg_types[6] = LLVMPointerType(vec_type, 0);        /* color */
+   arg_types[7] = LLVMPointerType(vec_type, 0);        /* depth */
+   arg_types[8] = LLVMPointerType(LLVMInt8Type(), 0);  /* samplers */
 
    func_type = LLVMFunctionType(LLVMVoidType(), arg_types, Elements(arg_types), 0);
 
@@ -101,27 +105,29 @@ shader_generate(struct llvmpipe_screen *screen,
    dadx_ptr = LLVMGetParam(shader->function, 2);
    dady_ptr = LLVMGetParam(shader->function, 3);
    consts_ptr = LLVMGetParam(shader->function, 4);
-   outputs_ptr = LLVMGetParam(shader->function, 5);
-   mask_ptr = LLVMGetParam(shader->function, 6);
-   samplers_ptr = LLVMGetParam(shader->function, 7);
+   mask_ptr = LLVMGetParam(shader->function, 5);
+   color_ptr = LLVMGetParam(shader->function, 6);
+   depth_ptr = LLVMGetParam(shader->function, 7);
+   samplers_ptr = LLVMGetParam(shader->function, 8);
 
    lp_build_name(pos_ptr, "pos");
    lp_build_name(a0_ptr, "a0");
    lp_build_name(dadx_ptr, "dadx");
    lp_build_name(dady_ptr, "dady");
    lp_build_name(consts_ptr, "consts");
-   lp_build_name(outputs_ptr, "outputs");
    lp_build_name(mask_ptr, "mask");
+   lp_build_name(color_ptr, "color");
+   lp_build_name(depth_ptr, "depth");
    lp_build_name(samplers_ptr, "samplers");
 
    block = LLVMAppendBasicBlock(shader->function, "entry");
    builder = LLVMCreateBuilder();
    LLVMPositionBuilderAtEnd(builder, block);
 
-   for(j = 0; j < NUM_CHANNELS; ++j) {
-      LLVMValueRef index = LLVMConstInt(LLVMInt32Type(), j, 0);
-      pos[j] = LLVMBuildLoad(builder, LLVMBuildGEP(builder, pos_ptr, &index, 1, ""), "");
-      lp_build_name(pos[j], "pos.%c", "xyzw"[j]);
+   for(chan = 0; chan < NUM_CHANNELS; ++chan) {
+      LLVMValueRef index = LLVMConstInt(LLVMInt32Type(), chan, 0);
+      pos[chan] = LLVMBuildLoad(builder, LLVMBuildGEP(builder, pos_ptr, &index, 1, ""), "");
+      lp_build_name(pos[chan], "pos.%c", "xyzw"[chan]);
    }
 
    memset(outputs, 0, sizeof outputs);
@@ -130,12 +136,27 @@ shader_generate(struct llvmpipe_screen *screen,
                             pos, a0_ptr, dadx_ptr, dady_ptr,
                             consts_ptr, outputs, samplers_ptr);
 
-   for(i = 0; i < PIPE_MAX_SHADER_OUTPUTS; ++i) {
-      for(j = 0; j < NUM_CHANNELS; ++j) {
-         if(outputs[i][j]) {
-            LLVMValueRef index = LLVMConstInt(LLVMInt32Type(), i*NUM_CHANNELS + j, 0);
-            LLVMBuildStore(builder, outputs[i][j], LLVMBuildGEP(builder, outputs_ptr, &index, 1, ""));
-            lp_build_name(pos[j], "output%u.%c", i, "xyzw"[j]);
+   for (attrib = 0; attrib < shader->info.num_outputs; ++attrib) {
+      for(chan = 0; chan < NUM_CHANNELS; ++chan) {
+         if(outputs[attrib][chan]) {
+            lp_build_name(outputs[attrib][chan], "output%u.%c", attrib, "xyzw"[chan]);
+
+            switch (shader->info.output_semantic_name[attrib]) {
+            case TGSI_SEMANTIC_COLOR:
+               {
+                  unsigned cbuf = shader->info.output_semantic_index[attrib];
+                  LLVMValueRef index = LLVMConstInt(LLVMInt32Type(), cbuf*NUM_CHANNELS + chan, 0);
+                  LLVMValueRef output_ptr = LLVMBuildGEP(builder, color_ptr, &index, 1, "");
+                  lp_build_name(outputs[attrib][chan], "color%u.%c", attrib, "rgba"[chan]);
+                  LLVMBuildStore(builder, outputs[attrib][chan], output_ptr);
+                  break;
+               }
+
+            case TGSI_SEMANTIC_POSITION:
+               if(chan == 3)
+                  LLVMBuildStore(builder, outputs[attrib][chan], depth_ptr);
+               break;
+            }
          }
       }
    }