i965/gen6/gs: Setup constant push buffers for gen6 geometry shaders.
authorIago Toral Quiroga <itoral@igalia.com>
Thu, 3 Jul 2014 14:33:32 +0000 (16:33 +0200)
committerIago Toral Quiroga <itoral@igalia.com>
Fri, 19 Sep 2014 13:01:15 +0000 (15:01 +0200)
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
Acked-by: Kenneth Graunke <kenneth@whitecape.org>
src/mesa/drivers/dri/i965/brw_state.h
src/mesa/drivers/dri/i965/brw_state_upload.c
src/mesa/drivers/dri/i965/gen6_gs_state.c

index bbaa85ce35d64ac8157e9bdfa851ad0e63dc98b0..2efe56e4c73fd3dd61e0969bb3723b5a7f2ea074 100644 (file)
@@ -101,6 +101,7 @@ extern const struct brw_tracked_state gen6_clip_vp;
 extern const struct brw_tracked_state gen6_color_calc_state;
 extern const struct brw_tracked_state gen6_depth_stencil_state;
 extern const struct brw_tracked_state gen6_gs_state;
+extern const struct brw_tracked_state gen6_gs_push_constants;
 extern const struct brw_tracked_state gen6_gs_binding_table;
 extern const struct brw_tracked_state gen6_multisample_state;
 extern const struct brw_tracked_state gen6_renderbuffer_surfaces;
index 87cc0eaba23dfb60e3b92fc7423ac30794d9ab20..59d5936a514b01587d0758adc8eeff49ed14fd87 100644 (file)
@@ -128,6 +128,7 @@ static const struct brw_tracked_state *gen6_atoms[] =
    &gen6_depth_stencil_state,  /* must do before cc unit */
 
    &gen6_vs_push_constants, /* Before vs_state */
+   &gen6_gs_push_constants, /* Before gs_state */
    &gen6_wm_push_constants, /* Before wm_state */
 
    /* Surface state setup.  Must come before the VS/WM unit.  The binding
index 0b718c9a87f701acfcb4bcf7ac3d209ae891aaf4..917a3faa47870b7a169df1994d8ff84789358aca 100644 (file)
 #include "brw_defines.h"
 #include "intel_batchbuffer.h"
 
+static void
+gen6_upload_gs_push_constants(struct brw_context *brw)
+{
+   /* BRW_NEW_GEOMETRY_PROGRAM */
+   const struct brw_geometry_program *gp =
+      (struct brw_geometry_program *) brw->geometry_program;
+
+   if (gp) {
+      /* CACHE_NEW_GS_PROG */
+      struct brw_stage_state *stage_state = &brw->gs.base;
+      struct brw_stage_prog_data *prog_data = &brw->gs.prog_data->base.base;
+
+      gen6_upload_push_constants(brw, &gp->program.Base, prog_data,
+                                 stage_state, AUB_TRACE_VS_CONSTANTS);
+   }
+}
+
+const struct brw_tracked_state gen6_gs_push_constants = {
+   .dirty = {
+      .mesa  = _NEW_TRANSFORM | _NEW_PROGRAM_CONSTANTS,
+      .brw   = (BRW_NEW_BATCH |
+                BRW_NEW_GEOMETRY_PROGRAM |
+                BRW_NEW_PUSH_CONSTANT_ALLOCATION),
+      .cache = CACHE_NEW_GS_PROG,
+   },
+   .emit = gen6_upload_gs_push_constants,
+};
+
 static void
 upload_gs_state_for_tf(struct brw_context *brw)
 {
@@ -61,8 +89,8 @@ upload_gs_state(struct brw_context *brw)
    const struct brw_vec4_prog_data *prog_data = &brw->gs.prog_data->base;
    const struct brw_stage_state *stage_state = &brw->gs.base;
 
-   if (active) {
-      /* FIXME: enable constant buffers */
+   if (!active || stage_state->push_const_size == 0) {
+      /* Disable the push constant buffers. */
       BEGIN_BATCH(5);
       OUT_BATCH(_3DSTATE_CONSTANT_GS << 16 | (5 - 2));
       OUT_BATCH(0);
@@ -70,7 +98,23 @@ upload_gs_state(struct brw_context *brw)
       OUT_BATCH(0);
       OUT_BATCH(0);
       ADVANCE_BATCH();
+   } else {
+      BEGIN_BATCH(5);
+      OUT_BATCH(_3DSTATE_CONSTANT_GS << 16 |
+               GEN6_CONSTANT_BUFFER_0_ENABLE |
+               (5 - 2));
+      /* Pointer to the GS constant buffer.  Covered by the set of
+       * state flags from gen6_upload_vs_constants
+       */
+      OUT_BATCH(stage_state->push_const_offset +
+                stage_state->push_const_size - 1);
+      OUT_BATCH(0);
+      OUT_BATCH(0);
+      OUT_BATCH(0);
+      ADVANCE_BATCH();
+   }
 
+   if (active) {
       BEGIN_BATCH(7);
       OUT_BATCH(_3DSTATE_GS << 16 | (7 - 2));
       OUT_BATCH(stage_state->prog_offset);
@@ -126,45 +170,34 @@ upload_gs_state(struct brw_context *brw)
          OUT_BATCH(GEN6_GS_REORDER | GEN6_GS_ENABLE);
       }
       ADVANCE_BATCH();
+   } else if (brw->ff_gs.prog_active) {
+      /* In gen6, transform feedback for the VS stage is done with an ad-hoc GS
+       * program. This function provides the needed 3DSTATE_GS for this.
+       */
+      upload_gs_state_for_tf(brw);
    } else {
-      /* Disable all the constant buffers. */
-      BEGIN_BATCH(5);
-      OUT_BATCH(_3DSTATE_CONSTANT_GS << 16 | (5 - 2));
-      OUT_BATCH(0);
-      OUT_BATCH(0);
-      OUT_BATCH(0);
-      OUT_BATCH(0);
+      /* No GS function required */
+      BEGIN_BATCH(7);
+      OUT_BATCH(_3DSTATE_GS << 16 | (7 - 2));
+      OUT_BATCH(0); /* prog_bo */
+      OUT_BATCH((0 << GEN6_GS_SAMPLER_COUNT_SHIFT) |
+                (0 << GEN6_GS_BINDING_TABLE_ENTRY_COUNT_SHIFT));
+      OUT_BATCH(0); /* scratch space base offset */
+      OUT_BATCH((1 << GEN6_GS_DISPATCH_START_GRF_SHIFT) |
+                (0 << GEN6_GS_URB_READ_LENGTH_SHIFT) |
+                (0 << GEN6_GS_URB_ENTRY_READ_OFFSET_SHIFT));
+      OUT_BATCH((0 << GEN6_GS_MAX_THREADS_SHIFT) |
+                GEN6_GS_STATISTICS_ENABLE |
+                GEN6_GS_RENDERING_ENABLE);
+                OUT_BATCH(0);
       ADVANCE_BATCH();
-
-      if (brw->ff_gs.prog_active) {
-         /* In gen6, transform feedback for the VS stage is done with an ad-hoc GS
-          * program. This function provides the needed 3DSTATE_GS for this.
-          */
-         upload_gs_state_for_tf(brw);
-      } else {
-         /* No GS function required */
-         BEGIN_BATCH(7);
-         OUT_BATCH(_3DSTATE_GS << 16 | (7 - 2));
-         OUT_BATCH(0); /* prog_bo */
-         OUT_BATCH((0 << GEN6_GS_SAMPLER_COUNT_SHIFT) |
-                  (0 << GEN6_GS_BINDING_TABLE_ENTRY_COUNT_SHIFT));
-         OUT_BATCH(0); /* scratch space base offset */
-         OUT_BATCH((1 << GEN6_GS_DISPATCH_START_GRF_SHIFT) |
-                  (0 << GEN6_GS_URB_READ_LENGTH_SHIFT) |
-                  (0 << GEN6_GS_URB_ENTRY_READ_OFFSET_SHIFT));
-         OUT_BATCH((0 << GEN6_GS_MAX_THREADS_SHIFT) |
-                  GEN6_GS_STATISTICS_ENABLE |
-                  GEN6_GS_RENDERING_ENABLE);
-         OUT_BATCH(0);
-         ADVANCE_BATCH();
-      }
    }
    brw->gs.enabled = active;
 }
 
 const struct brw_tracked_state gen6_gs_state = {
    .dirty = {
-      .mesa  = _NEW_TRANSFORM,
+      .mesa  = _NEW_TRANSFORM | _NEW_PROGRAM_CONSTANTS,
       .brw   = BRW_NEW_CONTEXT | BRW_NEW_PUSH_CONSTANT_ALLOCATION,
       .cache = (CACHE_NEW_GS_PROG | CACHE_NEW_FF_GS_PROG)
    },