<div dir="ltr">On 4 February 2014 15:07, Jordan Justen <span dir="ltr"><<a href="mailto:jordan.l.justen@intel.com" target="_blank">jordan.l.justen@intel.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">v2:<br>
 * Make gl_InstanceID a system value<br>
<br>
v3:<br>
 * Properly shift from R0.1 into DST.4 by adding<br>
   GS_OPCODE_GET_INSTANCE_ID<br>
<br>
Signed-off-by: Jordan Justen <<a href="mailto:jordan.l.justen@intel.com">jordan.l.justen@intel.com</a>><br>
---<br>
 src/mesa/drivers/dri/i965/brw_defines.h           | 12 ++++++++++++<br>
 src/mesa/drivers/dri/i965/brw_shader.cpp          |  2 ++<br>
 src/mesa/drivers/dri/i965/brw_vec4.h              |  1 +<br>
 src/mesa/drivers/dri/i965/brw_vec4_generator.cpp  | 20 ++++++++++++++++++++<br>
 src/mesa/drivers/dri/i965/brw_vec4_gs_visitor.cpp | 16 +++++++++++++---<br>
 5 files changed, 48 insertions(+), 3 deletions(-)<br></blockquote><div><br></div><div>Hopefully I will get a chance to look at this in more detail soon, but for now, consider this:<br><br>Acked-by: Paul Berry <<a href="mailto:stereotype441@gmail.com">stereotype441@gmail.com</a>><br>
</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
diff --git a/src/mesa/drivers/dri/i965/brw_defines.h b/src/mesa/drivers/dri/i965/brw_defines.h<br>
index 75d09fc..199a699 100644<br>
--- a/src/mesa/drivers/dri/i965/brw_defines.h<br>
+++ b/src/mesa/drivers/dri/i965/brw_defines.h<br>
@@ -902,6 +902,13 @@ enum opcode {<br>
     *   form the final channel mask.<br>
     */<br>
    GS_OPCODE_SET_CHANNEL_MASKS,<br>
+<br>
+   /**<br>
+    * Get the "Instance ID" fields from the payload.<br>
+    *<br>
+    * - dst is the GRF for gl_InvocationID.<br>
+    */<br>
+   GS_OPCODE_GET_INSTANCE_ID,<br>
 };<br>
<br>
 enum brw_urb_write_flags {<br>
@@ -1538,6 +1545,11 @@ enum brw_message_target {<br>
 # define BRW_GS_EDGE_INDICATOR_0                       (1 << 8)<br>
 # define BRW_GS_EDGE_INDICATOR_1                       (1 << 9)<br>
<br>
+/* GS Thread Payload<br>
+ */<br>
+/* R0 */<br>
+# define GEN7_GS_PAYLOAD_INSTANCE_ID_SHIFT             27<br>
+<br>
 /* 3DSTATE_GS "Output Vertex Size" has an effective maximum of 62.  It's<br>
  * counted in multiples of 16 bytes.<br>
  */<br>
diff --git a/src/mesa/drivers/dri/i965/brw_shader.cpp b/src/mesa/drivers/dri/i965/brw_shader.cpp<br>
index 6cc2595..5e3005a 100644<br>
--- a/src/mesa/drivers/dri/i965/brw_shader.cpp<br>
+++ b/src/mesa/drivers/dri/i965/brw_shader.cpp<br>
@@ -525,6 +525,8 @@ brw_instruction_name(enum opcode op)<br>
       return "prepare_channel_masks";<br>
    case GS_OPCODE_SET_CHANNEL_MASKS:<br>
       return "set_channel_masks";<br>
+   case GS_OPCODE_GET_INSTANCE_ID:<br>
+      return "get_instance_id";<br>
<br>
    default:<br>
       /* Yes, this leaks.  It's in debug code, it should never occur, and if<br>
diff --git a/src/mesa/drivers/dri/i965/brw_vec4.h b/src/mesa/drivers/dri/i965/brw_vec4.h<br>
index e17b5cd..182a1e1 100644<br>
--- a/src/mesa/drivers/dri/i965/brw_vec4.h<br>
+++ b/src/mesa/drivers/dri/i965/brw_vec4.h<br>
@@ -616,6 +616,7 @@ private:<br>
    void generate_gs_set_dword_2_immed(struct brw_reg dst, struct brw_reg src);<br>
    void generate_gs_prepare_channel_masks(struct brw_reg dst);<br>
    void generate_gs_set_channel_masks(struct brw_reg dst, struct brw_reg src);<br>
+   void generate_gs_get_instance_id(struct brw_reg dst);<br>
    void generate_oword_dual_block_offsets(struct brw_reg m1,<br>
                                          struct brw_reg index);<br>
    void generate_scratch_write(vec4_instruction *inst,<br>
diff --git a/src/mesa/drivers/dri/i965/brw_vec4_generator.cpp b/src/mesa/drivers/dri/i965/brw_vec4_generator.cpp<br>
index 94d1e79..a48d829 100644<br>
--- a/src/mesa/drivers/dri/i965/brw_vec4_generator.cpp<br>
+++ b/src/mesa/drivers/dri/i965/brw_vec4_generator.cpp<br>
@@ -639,6 +639,22 @@ vec4_generator::generate_gs_set_channel_masks(struct brw_reg dst,<br>
 }<br>
<br>
 void<br>
+vec4_generator::generate_gs_get_instance_id(struct brw_reg dst)<br>
+{<br>
+   /* We want to right shift R0.0 & R0.1 by GEN7_GS_PAYLOAD_INSTANCE_ID_SHIFT<br>
+    * and store into dst.0 & dst.4. So generate the instruction:<br>
+    *<br>
+    *     shr(8) dst<1> R0<1,4,0> GEN7_GS_PAYLOAD_INSTANCE_ID_SHIFT { align1 WE_all }<br>
+    */<br>
+   brw_push_insn_state(p);<br>
+   brw_set_access_mode(p, BRW_ALIGN_1);<br>
+   dst = retype(dst, BRW_REGISTER_TYPE_UD);<br>
+   struct brw_reg r0(retype(brw_vec8_grf(0, 0), BRW_REGISTER_TYPE_UD));<br>
+   brw_SHR(p, dst, stride(r0, 1, 4, 0), brw_imm_ud(GEN7_GS_PAYLOAD_INSTANCE_ID_SHIFT));<br>
+   brw_pop_insn_state(p);<br>
+}<br>
+<br>
+void<br>
 vec4_generator::generate_oword_dual_block_offsets(struct brw_reg m1,<br>
                                                   struct brw_reg index)<br>
 {<br>
@@ -1218,6 +1234,10 @@ vec4_generator::generate_vec4_instruction(vec4_instruction *instruction,<br>
       generate_gs_set_channel_masks(dst, src[0]);<br>
       break;<br>
<br>
+   case GS_OPCODE_GET_INSTANCE_ID:<br>
+      generate_gs_get_instance_id(dst);<br>
+      break;<br>
+<br>
    case SHADER_OPCODE_SHADER_TIME_ADD:<br>
       brw_shader_time_add(p, src[0],<br>
                           prog_data->base.binding_table.shader_time_start);<br>
diff --git a/src/mesa/drivers/dri/i965/brw_vec4_gs_visitor.cpp b/src/mesa/drivers/dri/i965/brw_vec4_gs_visitor.cpp<br>
index 40743cc..360703b 100644<br>
--- a/src/mesa/drivers/dri/i965/brw_vec4_gs_visitor.cpp<br>
+++ b/src/mesa/drivers/dri/i965/brw_vec4_gs_visitor.cpp<br>
@@ -51,9 +51,19 @@ vec4_gs_visitor::vec4_gs_visitor(struct brw_context *brw,<br>
 dst_reg *<br>
 vec4_gs_visitor::make_reg_for_system_value(ir_variable *ir)<br>
 {<br>
-   /* Geometry shaders don't use any system values. */<br>
-   assert(!"Unreached");<br>
-   return NULL;<br>
+   dst_reg *reg = new(mem_ctx) dst_reg(this, ir->type);<br>
+<br>
+   switch (ir->data.location) {<br>
+   case SYSTEM_VALUE_INVOCATION_ID:<br>
+      this->current_annotation = "initialize gl_InvocationID";<br>
+      emit(GS_OPCODE_GET_INSTANCE_ID, *reg);<br>
+      break;<br>
+   default:<br>
+      assert(!"not reached");<br>
+      break;<br>
+   }<br>
+<br>
+   return reg;<br>
 }<br>
<span class="HOEnZb"><font color="#888888"><br>
<br>
--<br>
1.8.5.3<br>
<br>
_______________________________________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/mesa-dev" target="_blank">http://lists.freedesktop.org/mailman/listinfo/mesa-dev</a><br>
</font></span></blockquote></div><br></div></div>