<div dir="ltr">On 18 August 2013 22:15, Kenneth Graunke <span dir="ltr"><<a href="mailto:kenneth@whitecape.org" target="_blank">kenneth@whitecape.org</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">SURF_INDEX_DRAW() has been the identity function since the dawn of time,<br>
and both the shader code and binding table upload code relied on that,<br>
simply using X rather than SURF_INDEX_DRAW(X).<br>
<br>
Even if that continues to be true, using the macro clarifies the code.<br>
<br>
The comment about draw buffers needing to be first in order for<br>
headerless render target writes to work turned out to be wrong; with<br>
this change, SURF_INDEX_DRAW can be changed to arbitrary indices and<br>
everything continues working.<br>
<br>
The confusion was over the "Render Target Index" field in the FB write<br>
message header. If it were a binding table index, then RT 0 would have<br>
to be at index 0 for headerless FB writes to work. However, it's<br>
actually an index into the blend state table, so there's no problem.<br>
<br>
Signed-off-by: Kenneth Graunke <<a href="mailto:kenneth@whitecape.org">kenneth@whitecape.org</a>><br>
Cc: Paul Berry <<a href="mailto:stereotype441@gmail.com">stereotype441@gmail.com</a>><br></blockquote><div><br></div><div>Reviewed-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>
src/mesa/drivers/dri/i965/brw_context.h | 4 ----<br>
src/mesa/drivers/dri/i965/brw_fs_emit.cpp | 2 +-<br>
src/mesa/drivers/dri/i965/brw_wm_surface_state.c | 12 ++++++------<br>
src/mesa/drivers/dri/i965/gen7_wm_surface_state.c | 14 ++++++++------<br>
4 files changed, 15 insertions(+), 17 deletions(-)<br>
<br>
In order to fix the comment as Paul requested, I had to do some digging.<br>
The end result was discovering that the comment was entirely wrong - the<br>
only reason SURF_INDEX_DRAW had to be the identity function was that we<br>
weren't calling it. With that fixed, it can be arbitrary, so there's<br>
no need for the comment at all.<br>
<br>
I did try totally scrambling the order of the binding table indexes<br>
after applying the patch, and there were no Piglit regressions on IVB.<br>
So I'm confident that it works (at least on Gen7+).<br>
<br>
diff --git a/src/mesa/drivers/dri/i965/brw_context.h b/src/mesa/drivers/dri/i965/brw_context.h<br>
index acd8e3f..e0deee0 100644<br>
--- a/src/mesa/drivers/dri/i965/brw_context.h<br>
+++ b/src/mesa/drivers/dri/i965/brw_context.h<br>
@@ -602,10 +602,6 @@ struct brw_vs_prog_data {<br>
* | : | : |<br>
* | 63 | SOL Binding 63 |<br>
* +-----+-------------------------+<br>
- *<br>
- * Note that nothing actually uses the SURF_INDEX_DRAW macro, so it has to be<br>
- * the identity function or things will break. We do want to keep draw buffers<br>
- * first so we can use headerless render target writes for RT 0.<br>
*/<br>
#define SURF_INDEX_DRAW(d) (d)<br>
#define SURF_INDEX_FRAG_CONST_BUFFER (BRW_MAX_DRAW_BUFFERS + 1)<br>
diff --git a/src/mesa/drivers/dri/i965/brw_fs_emit.cpp b/src/mesa/drivers/dri/i965/brw_fs_emit.cpp<br>
index 4225922..b90cf0f 100644<br>
--- a/src/mesa/drivers/dri/i965/brw_fs_emit.cpp<br>
+++ b/src/mesa/drivers/dri/i965/brw_fs_emit.cpp<br>
@@ -170,7 +170,7 @@ fs_generator::generate_fb_write(fs_inst *inst)<br>
inst->base_mrf,<br>
implied_header,<br>
msg_control,<br>
- inst->target,<br>
+ SURF_INDEX_DRAW(inst->target),<br>
inst->mlen,<br>
0,<br>
eot,<br>
diff --git a/src/mesa/drivers/dri/i965/brw_wm_surface_state.c b/src/mesa/drivers/dri/i965/brw_wm_surface_state.c<br>
index 8847f91..16579f9 100644<br>
--- a/src/mesa/drivers/dri/i965/brw_wm_surface_state.c<br>
+++ b/src/mesa/drivers/dri/i965/brw_wm_surface_state.c<br>
@@ -533,8 +533,8 @@ brw_update_null_renderbuffer_surface(struct brw_context *brw, unsigned int unit)<br>
/* _NEW_BUFFERS */<br>
const struct gl_framebuffer *fb = ctx->DrawBuffer;<br>
<br>
- surf = brw_state_batch(brw, AUB_TRACE_SURFACE_STATE,<br>
- 6 * 4, 32, &brw->wm.surf_offset[unit]);<br>
+ surf = brw_state_batch(brw, AUB_TRACE_SURFACE_STATE, 6 * 4, 32,<br>
+ &brw->wm.surf_offset[SURF_INDEX_DRAW(unit)]);<br>
<br>
if (fb->Visual.samples > 1) {<br>
/* On Gen6, null render targets seem to cause GPU hangs when<br>
@@ -587,7 +587,7 @@ brw_update_null_renderbuffer_surface(struct brw_context *brw, unsigned int unit)<br>
<br>
if (bo) {<br>
drm_intel_bo_emit_reloc(brw-><a href="http://batch.bo" target="_blank">batch.bo</a>,<br>
- brw->wm.surf_offset[unit] + 4,<br>
+ brw->wm.surf_offset[SURF_INDEX_DRAW(unit)] + 4,<br>
bo, 0,<br>
I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER);<br>
}<br>
@@ -635,8 +635,8 @@ brw_update_renderbuffer_surface(struct brw_context *brw,<br>
<br>
region = irb->mt->region;<br>
<br>
- surf = brw_state_batch(brw, AUB_TRACE_SURFACE_STATE,<br>
- 6 * 4, 32, &brw->wm.surf_offset[unit]);<br>
+ surf = brw_state_batch(brw, AUB_TRACE_SURFACE_STATE, 6 * 4, 32,<br>
+ &brw->wm.surf_offset[SURF_INDEX_DRAW(unit)]);<br>
<br>
format = brw->render_target_format[rb_format];<br>
if (unlikely(!brw->format_supported_as_render_target[rb_format])) {<br>
@@ -692,7 +692,7 @@ brw_update_renderbuffer_surface(struct brw_context *brw,<br>
}<br>
<br>
drm_intel_bo_emit_reloc(brw-><a href="http://batch.bo" target="_blank">batch.bo</a>,<br>
- brw->wm.surf_offset[unit] + 4,<br>
+ brw->wm.surf_offset[SURF_INDEX_DRAW(unit)] + 4,<br>
region->bo,<br>
surf[1] - region->bo->offset,<br>
I915_GEM_DOMAIN_RENDER,<br>
diff --git a/src/mesa/drivers/dri/i965/gen7_wm_surface_state.c b/src/mesa/drivers/dri/i965/gen7_wm_surface_state.c<br>
index 34cf63b..cdd2242 100644<br>
--- a/src/mesa/drivers/dri/i965/gen7_wm_surface_state.c<br>
+++ b/src/mesa/drivers/dri/i965/gen7_wm_surface_state.c<br>
@@ -475,8 +475,8 @@ gen7_update_null_renderbuffer_surface(struct brw_context *brw, unsigned unit)<br>
/* _NEW_BUFFERS */<br>
const struct gl_framebuffer *fb = ctx->DrawBuffer;<br>
<br>
- uint32_t *surf = brw_state_batch(brw, AUB_TRACE_SURFACE_STATE,<br>
- 8 * 4, 32, &brw->wm.surf_offset[unit]);<br>
+ uint32_t *surf = brw_state_batch(brw, AUB_TRACE_SURFACE_STATE, 8 * 4, 32,<br>
+ &brw->wm.surf_offset[SURF_INDEX_DRAW(unit)]);<br>
memset(surf, 0, 8 * 4);<br>
<br>
/* From the Ivybridge PRM, Volume 4, Part 1, page 65,<br>
@@ -518,8 +518,10 @@ gen7_update_renderbuffer_surface(struct brw_context *brw,<br>
GLenum gl_target = rb->TexImage ?<br>
rb->TexImage->TexObject->Target : GL_TEXTURE_2D;<br>
<br>
- uint32_t *surf = brw_state_batch(brw, AUB_TRACE_SURFACE_STATE,<br>
- 8 * 4, 32, &brw->wm.surf_offset[unit]);<br>
+ uint32_t surf_index = SURF_INDEX_DRAW(unit);<br>
+<br>
+ uint32_t *surf = brw_state_batch(brw, AUB_TRACE_SURFACE_STATE, 8 * 4, 32,<br>
+ &brw->wm.surf_offset[surf_index]);<br>
memset(surf, 0, 8 * 4);<br>
<br>
intel_miptree_used_for_rendering(irb->mt);<br>
@@ -588,7 +590,7 @@ gen7_update_renderbuffer_surface(struct brw_context *brw,<br>
(depth - 1) << GEN7_SURFACE_RENDER_TARGET_VIEW_EXTENT_SHIFT;<br>
<br>
if (irb->mt->mcs_mt) {<br>
- gen7_set_surface_mcs_info(brw, surf, brw->wm.surf_offset[unit],<br>
+ gen7_set_surface_mcs_info(brw, surf, brw->wm.surf_offset[surf_index],<br>
irb->mt->mcs_mt, true /* is RT */);<br>
}<br>
<br>
@@ -602,7 +604,7 @@ gen7_update_renderbuffer_surface(struct brw_context *brw,<br>
}<br>
<br>
drm_intel_bo_emit_reloc(brw-><a href="http://batch.bo" target="_blank">batch.bo</a>,<br>
- brw->wm.surf_offset[unit] + 4,<br>
+ brw->wm.surf_offset[surf_index] + 4,<br>
region->bo,<br>
surf[1] - region->bo->offset,<br>
I915_GEM_DOMAIN_RENDER,<br>
<span class="HOEnZb"><font color="#888888">--<br>
1.8.3.4<br>
<br>
</font></span></blockquote></div><br></div></div>