<div dir="ltr">On 20 August 2013 11:30, Paul Berry <span dir="ltr"><<a href="mailto:stereotype441@gmail.com" target="_blank">stereotype441@gmail.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">Both 3DSTATE_VS and 3DSTATE_GS have a dispatch_grf_start_reg control,<br>
which determines the register where the hardware delivers data sourced<br>
from the URB (push constants followed by per-vertex input data).<br>
<br>
For vertex shaders, we always set dispatch_grf_start_reg to 1, since<br>
R1 is always the first register available for push constants in vertex<br>
shaders.<br>
<br>
For geometry shaders, we'll need the flexibility to set<br>
dispatch_grf_start_reg to different values depending on the behvaiour<br>
of the geometry shader; if it accesses gl_PrimitiveIDIn, we'll need to<br>
set it to 2 to allow the primitive ID to be delivered to the thread in<br>
R1.<br>
<br>
This patch eliminates the assumption that dispatch_grf_start_reg is<br>
always 1. In vec4_visitor, we record the regnum that was passed to<br>
vec4_visitor::setup_uniforms() in prog_data for later use. In<br>
vec4_generator, we consult this value when converting an abstract<br>
UNIFORM register to a concrete hardware register. And in the code<br>
that emits 3DSTATE_VS, we set dispatch_grf_start_reg based on the<br>
value recorded in prog_data.<br>
<br>
This will allow us to set dispatch_grf_start_reg to the appropriate<br>
value when compiling geometry shaders. Vertex shaders will continue<br>
to always use a dispatch_grf_start_reg of 1.<br>
---<br>
src/mesa/drivers/dri/i965/brw_context.h | 6 ++++++<br>
src/mesa/drivers/dri/i965/brw_vec4.cpp | 4 +++-<br>
src/mesa/drivers/dri/i965/brw_vec4.h | 2 +-<br>
src/mesa/drivers/dri/i965/brw_vec4_emit.cpp | 7 ++++---<br>
src/mesa/drivers/dri/i965/brw_vs_state.c | 3 ++-<br>
src/mesa/drivers/dri/i965/gen6_vs_state.c | 3 ++-<br>
src/mesa/drivers/dri/i965/gen7_vs_state.c | 3 ++-<br>
7 files changed, 20 insertions(+), 8 deletions(-)<br>
<br>
diff --git a/src/mesa/drivers/dri/i965/brw_context.h b/src/mesa/drivers/dri/i965/brw_context.h<br>
index dae3219..0c4aab6 100644<br>
--- a/src/mesa/drivers/dri/i965/brw_context.h<br>
+++ b/src/mesa/drivers/dri/i965/brw_context.h<br>
@@ -480,6 +480,12 @@ struct brw_gs_prog_data {<br>
struct brw_vec4_prog_data {<br>
struct brw_vue_map vue_map;<br>
<br>
+ /**<br>
+ * Register where the thread expects to find input data from the URB<br>
+ * (typically uniforms, followed by per-vertex inputs).<br>
+ */<br>
+ GLuint dispatch_grf_start_reg;<br>
+<br></blockquote><div><br></div><div>From our in-person code review yesterday: in the i965 back-end, we'd like to start moving away from using GL typedefs like GLuint, and instead use built-in C types like unsigned. But it's difficult to schedule a "flag day" to change everything because that means merging nightmares for people carrying work-in-progress branches, and it makes it difficult to cherry-pick bug fixes back to stable branches.<br>
<br>However, we agreed that regardless of when (or if) we have a flag day to change everything, we should start using the built-in C types in newly added code ASAP. Which means dispatch_grf_start_reg should be "unsigned".<br>
</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
GLuint curb_read_length;<br>
GLuint urb_read_length;<br>
GLuint total_grf;<br>
diff --git a/src/mesa/drivers/dri/i965/brw_vec4.cpp b/src/mesa/drivers/dri/i965/brw_vec4.cpp<br>
index 36527cd..bfef8e0 100644<br>
--- a/src/mesa/drivers/dri/i965/brw_vec4.cpp<br>
+++ b/src/mesa/drivers/dri/i965/brw_vec4.cpp<br>
@@ -1260,6 +1260,8 @@ vec4_vs_visitor::setup_attributes(int payload_reg)<br>
int<br>
vec4_visitor::setup_uniforms(int reg)<br>
{<br>
+ prog_data->dispatch_grf_start_reg = reg;<br>
+<br>
/* The pre-gen6 VS requires that some push constants get loaded no<br>
* matter what, or the GPU would hang.<br>
*/<br>
@@ -1280,7 +1282,7 @@ vec4_visitor::setup_uniforms(int reg)<br>
<br>
prog_data->nr_params = this->uniforms * 4;<br>
<br>
- prog_data->curb_read_length = reg - 1;<br>
+ prog_data->curb_read_length = reg - prog_data->dispatch_grf_start_reg;<br>
<br>
return reg;<br>
}<br>
diff --git a/src/mesa/drivers/dri/i965/brw_vec4.h b/src/mesa/drivers/dri/i965/brw_vec4.h<br>
index 512b6b3..587cb45 100644<br>
--- a/src/mesa/drivers/dri/i965/brw_vec4.h<br>
+++ b/src/mesa/drivers/dri/i965/brw_vec4.h<br>
@@ -206,7 +206,7 @@ public:<br>
src_reg src2 = src_reg());<br>
<br>
struct brw_reg get_dst(void);<br>
- struct brw_reg get_src(int i);<br>
+ struct brw_reg get_src(const struct brw_vec4_prog_data *prog_data, int i);<br>
<br>
dst_reg dst;<br>
src_reg src[3];<br>
diff --git a/src/mesa/drivers/dri/i965/brw_vec4_emit.cpp b/src/mesa/drivers/dri/i965/brw_vec4_emit.cpp<br>
index ce9bcd0..53b4bf2 100644<br>
--- a/src/mesa/drivers/dri/i965/brw_vec4_emit.cpp<br>
+++ b/src/mesa/drivers/dri/i965/brw_vec4_emit.cpp<br>
@@ -66,7 +66,7 @@ vec4_instruction::get_dst(void)<br>
}<br>
<br>
struct brw_reg<br>
-vec4_instruction::get_src(int i)<br>
+vec4_instruction::get_src(const struct brw_vec4_prog_data *prog_data, int i)<br>
{<br>
struct brw_reg brw_reg;<br>
<br>
@@ -100,7 +100,8 @@ vec4_instruction::get_src(int i)<br>
break;<br>
<br>
case UNIFORM:<br>
- brw_reg = stride(brw_vec4_grf(1 + (src[i].reg + src[i].reg_offset) / 2,<br>
+ brw_reg = stride(brw_vec4_grf(prog_data->dispatch_grf_start_reg +<br>
+ (src[i].reg + src[i].reg_offset) / 2,<br>
((src[i].reg + src[i].reg_offset) % 2) * 4),<br>
0, 4, 1);<br>
brw_reg = retype(brw_reg, src[i].type);<br>
@@ -946,7 +947,7 @@ vec4_generator::generate_code(exec_list *instructions)<br>
}<br>
<br>
for (unsigned int i = 0; i < 3; i++) {<br>
- src[i] = inst->get_src(i);<br>
+ src[i] = inst->get_src(this->prog_data, i);<br>
}<br>
dst = inst->get_dst();<br>
<br>
diff --git a/src/mesa/drivers/dri/i965/brw_vs_state.c b/src/mesa/drivers/dri/i965/brw_vs_state.c<br>
index a8729df..e5421f1 100644<br>
--- a/src/mesa/drivers/dri/i965/brw_vs_state.c<br>
+++ b/src/mesa/drivers/dri/i965/brw_vs_state.c<br>
@@ -92,7 +92,8 @@ brw_upload_vs_unit(struct brw_context *brw)<br>
vs->thread3.urb_entry_read_length = brw->vs.prog_data->base.urb_read_length;<br>
vs->thread3.const_urb_entry_read_length<br>
= brw->vs.prog_data->base.curb_read_length;<br>
- vs->thread3.dispatch_grf_start_reg = 1;<br>
+ vs->thread3.dispatch_grf_start_reg =<br>
+ brw->vs.prog_data->base.dispatch_grf_start_reg;<br>
vs->thread3.urb_entry_read_offset = 0;<br>
<br>
/* BRW_NEW_CURBE_OFFSETS, _NEW_TRANSFORM, BRW_NEW_VERTEX_PROGRAM */<br>
diff --git a/src/mesa/drivers/dri/i965/gen6_vs_state.c b/src/mesa/drivers/dri/i965/gen6_vs_state.c<br>
index 4af7cda..c5f2fd0 100644<br>
--- a/src/mesa/drivers/dri/i965/gen6_vs_state.c<br>
+++ b/src/mesa/drivers/dri/i965/gen6_vs_state.c<br>
@@ -159,7 +159,8 @@ upload_vs_state(struct brw_context *brw)<br>
OUT_BATCH(0);<br>
}<br>
<br>
- OUT_BATCH((1 << GEN6_VS_DISPATCH_START_GRF_SHIFT) |<br>
+ OUT_BATCH((brw->vs.prog_data->base.dispatch_grf_start_reg <<<br>
+ GEN6_VS_DISPATCH_START_GRF_SHIFT) |<br>
(brw->vs.prog_data->base.urb_read_length << GEN6_VS_URB_READ_LENGTH_SHIFT) |<br>
(0 << GEN6_VS_URB_ENTRY_READ_OFFSET_SHIFT));<br>
<br>
diff --git a/src/mesa/drivers/dri/i965/gen7_vs_state.c b/src/mesa/drivers/dri/i965/gen7_vs_state.c<br>
index 7a6ba59..b2493cf 100644<br>
--- a/src/mesa/drivers/dri/i965/gen7_vs_state.c<br>
+++ b/src/mesa/drivers/dri/i965/gen7_vs_state.c<br>
@@ -99,7 +99,8 @@ upload_vs_state(struct brw_context *brw)<br>
OUT_BATCH(0);<br>
}<br>
<br>
- OUT_BATCH((1 << GEN6_VS_DISPATCH_START_GRF_SHIFT) |<br>
+ OUT_BATCH((brw->vs.prog_data->base.dispatch_grf_start_reg <<<br>
+ GEN6_VS_DISPATCH_START_GRF_SHIFT) |<br>
(brw->vs.prog_data->base.urb_read_length << GEN6_VS_URB_READ_LENGTH_SHIFT) |<br>
(0 << GEN6_VS_URB_ENTRY_READ_OFFSET_SHIFT));<br>
<span class="HOEnZb"><font color="#888888"><br>
--<br>
1.8.3.4<br>
<br>
</font></span></blockquote></div><br></div></div>