OSDN Git Service

nvc0: handle discontiguous outputs in stream_output_info
authorChristoph Bumiller <e0425955@student.tuwien.ac.at>
Fri, 20 Jan 2012 12:29:42 +0000 (13:29 +0100)
committerChristoph Bumiller <e0425955@student.tuwien.ac.at>
Fri, 20 Jan 2012 18:24:31 +0000 (19:24 +0100)
src/gallium/drivers/nvc0/nvc0_program.c
src/gallium/drivers/nvc0/nvc0_program.h
src/gallium/drivers/nvc0/nvc0_shader_state.c

index 60abc22..44c7a65 100644 (file)
@@ -492,28 +492,31 @@ nvc0_program_create_tfb_state(const struct nv50_ir_prog_info *info,
                               const struct pipe_stream_output_info *pso)
 {
    struct nvc0_transform_feedback_state *tfb;
-   int n = 0;
-   int i, c, b;
+   unsigned b, i, c;
 
-   tfb = MALLOC(sizeof(*tfb) + pso->num_outputs * 4 * sizeof(uint8_t));
+   tfb = MALLOC_STRUCT(nvc0_transform_feedback_state);
    if (!tfb)
       return NULL;
-
    for (b = 0; b < 4; ++b) {
+      tfb->stride[b] = pso->stride[b] * 4;
       tfb->varying_count[b] = 0;
+   }
+   memset(tfb->varying_index, 0xff, sizeof(tfb->varying_index)); /* = skip */
 
-      for (i = 0; i < pso->num_outputs; ++i) {
-         unsigned startc = pso->output[i].start_component;
-         if (pso->output[i].output_buffer != b)
-            continue;
-         for (c = 0; c < pso->output[i].num_components; ++c) {
-            tfb->varying_count[b]++;
-            tfb->varying_index[n++] =
-               info->out[pso->output[i].register_index].slot[startc + c];
-         }
-      }
-      tfb->stride[b] = pso->stride[b] * 4;
+   for (i = 0; i < pso->num_outputs; ++i) {
+      unsigned s = pso->output[i].start_component;
+      unsigned p = pso->output[i].dst_offset;
+      b = pso->output[i].output_buffer;
+
+      for (c = 0; c < pso->output[i].num_components; ++c)
+         tfb->varying_index[b][p++] =
+            info->out[pso->output[i].register_index].slot[s + c];
+
+      tfb->varying_count[b] = MAX2(tfb->varying_count[b], p);
    }
+   for (b = 0; b < 4; ++b) // zero unused indices (looks nicer)
+      for (c = tfb->varying_count[b]; c & 3; ++c)
+         tfb->varying_index[b][c] = 0;
 
    return tfb;
 }
index 6eb8c96..c90f364 100644 (file)
@@ -10,7 +10,7 @@
 struct nvc0_transform_feedback_state {
    uint32_t stride[4];
    uint8_t varying_count[4];
-   uint8_t varying_index[0];
+   uint8_t varying_index[4][128];
 };
 
 
index 630ad20..9945b8e 100644 (file)
@@ -207,7 +207,7 @@ nvc0_tfb_validate(struct nvc0_context *nvc0)
 {
    struct nouveau_channel *chan = nvc0->screen->base.channel;
    struct nvc0_transform_feedback_state *tfb;
-   unsigned b, n, i;
+   unsigned b;
 
    if (nvc0->gmtyprog) tfb = nvc0->gmtyprog->tfb;
    else
@@ -218,22 +218,16 @@ nvc0_tfb_validate(struct nvc0_context *nvc0)
    IMMED_RING(chan, RING_3D(TFB_ENABLE), (tfb && nvc0->num_tfbbufs) ? 1 : 0);
 
    if (tfb && tfb != nvc0->state.tfb) {
-      uint8_t var[128];
-
-      for (n = 0, b = 0; b < 4; n += tfb->varying_count[b++]) {
+      for (b = 0; b < 4; ++b) {
          if (tfb->varying_count[b]) {
+            unsigned n = (tfb->varying_count[b] + 3) / 4;
+
             BEGIN_RING(chan, RING_3D(TFB_STREAM(b)), 3);
             OUT_RING  (chan, 0);
             OUT_RING  (chan, tfb->varying_count[b]);
             OUT_RING  (chan, tfb->stride[b]);
-
-            for (i = 0; i < tfb->varying_count[b]; ++i)
-               var[i] = tfb->varying_index[n + i];
-            for (; i & 3; ++i)
-               var[i] = 0; /* zero rest of method word bits */
-
-            BEGIN_RING(chan, RING_3D(TFB_VARYING_LOCS(b, 0)), i / 4);
-            OUT_RINGp (chan, var, i / 4);
+            BEGIN_RING(chan, RING_3D(TFB_VARYING_LOCS(b, 0)), n);
+            OUT_RINGp (chan, tfb->varying_index[b], n);
 
             if (nvc0->tfbbuf[b])
                nvc0_so_target(nvc0->tfbbuf[b])->stride = tfb->stride[b];