<div dir="ltr">On 13 September 2013 23:10, 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">This was an embarassingly large amount of copy and pasted code,<br>
and it wasn't particularly simple code either. By factoring it out<br>
into a helper function, we consolidate the complexity.<br></blockquote><div><br></div><div>I believe the off-by-one error with buffer_size that I mentioned in patch 1 applies to this patch too.<br><br>With that fixed, the patch is:<br>
<br>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>
Signed-off-by: Kenneth Graunke <<a href="mailto:kenneth@whitecape.org">kenneth@whitecape.org</a>><br>
---<br>
src/mesa/drivers/dri/i965/brw_wm_surface_state.c | 98 +++++++++---------------<br>
1 file changed, 37 insertions(+), 61 deletions(-)<br>
<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 8d87786..bbe7803 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>
@@ -190,6 +190,36 @@ brw_get_texture_swizzle(const struct gl_context *ctx,<br>
swizzles[GET_SWZ(t->_Swizzle, 3)]);<br>
}<br>
<br>
+static void<br>
+gen4_emit_buffer_surface_state(struct brw_context *brw,<br>
+ uint32_t *out_offset,<br>
+ drm_intel_bo *bo,<br>
+ unsigned buffer_offset,<br>
+ unsigned surface_format,<br>
+ unsigned buffer_size,<br>
+ unsigned pitch)<br>
+{<br>
+ uint32_t *surf = brw_state_batch(brw, AUB_TRACE_SURFACE_STATE,<br>
+ 6 * 4, 32, out_offset);<br>
+ memset(surf, 0, 6 * 4);<br>
+<br>
+ surf[0] = BRW_SURFACE_BUFFER << BRW_SURFACE_TYPE_SHIFT |<br>
+ surface_format << BRW_SURFACE_FORMAT_SHIFT |<br>
+ (brw->gen >= 6 ? BRW_SURFACE_RC_READ_WRITE : 0);<br>
+ surf[1] = bo->offset + buffer_offset; /* reloc */<br>
+ surf[2] = (buffer_size & 0x7f) << BRW_SURFACE_WIDTH_SHIFT |<br>
+ ((buffer_size >> 7) & 0x1fff) << BRW_SURFACE_HEIGHT_SHIFT;<br>
+ surf[3] = ((buffer_size >> 20) & 0x7f) << BRW_SURFACE_DEPTH_SHIFT |<br>
+ (pitch - 1) << BRW_SURFACE_PITCH_SHIFT;<br>
+<br>
+ /* Emit relocation to surface contents. The 965 PRM, Volume 4, section<br>
+ * 5.1.2 "Data Cache" says: "the data cache does not exist as a separate<br>
+ * physical cache. It is mapped in hardware to the sampler cache."<br>
+ */<br>
+ drm_intel_bo_emit_reloc(brw-><a href="http://batch.bo" target="_blank">batch.bo</a>, *out_offset + 4,<br>
+ bo, buffer_offset,<br>
+ I915_GEM_DOMAIN_SAMPLER, 0);<br>
+}<br>
<br>
static void<br>
brw_update_buffer_texture_surface(struct gl_context *ctx,<br>
@@ -198,49 +228,22 @@ brw_update_buffer_texture_surface(struct gl_context *ctx,<br>
{<br>
struct brw_context *brw = brw_context(ctx);<br>
struct gl_texture_object *tObj = ctx->Texture.Unit[unit]._Current;<br>
- uint32_t *surf;<br>
struct intel_buffer_object *intel_obj =<br>
intel_buffer_object(tObj->BufferObject);<br>
drm_intel_bo *bo = intel_obj ? intel_obj->buffer : NULL;<br>
gl_format format = tObj->_BufferObjectFormat;<br>
uint32_t brw_format = brw_format_for_mesa_format(format);<br>
int texel_size = _mesa_get_format_bytes(format);<br>
+ int w = intel_obj ? intel_obj->Base.Size / texel_size : 0;<br>
<br>
if (brw_format == 0 && format != MESA_FORMAT_RGBA_FLOAT32) {<br>
_mesa_problem(NULL, "bad format %s for texture buffer\n",<br>
_mesa_get_format_name(format));<br>
}<br>
<br>
- surf = brw_state_batch(brw, AUB_TRACE_SURFACE_STATE,<br>
- 6 * 4, 32, surf_offset);<br>
-<br>
- surf[0] = (BRW_SURFACE_BUFFER << BRW_SURFACE_TYPE_SHIFT |<br>
- (brw_format_for_mesa_format(format) << BRW_SURFACE_FORMAT_SHIFT));<br>
-<br>
- if (brw->gen >= 6)<br>
- surf[0] |= BRW_SURFACE_RC_READ_WRITE;<br>
-<br>
- if (bo) {<br>
- surf[1] = bo->offset; /* reloc */<br>
-<br>
- /* Emit relocation to surface contents. */<br>
- drm_intel_bo_emit_reloc(brw-><a href="http://batch.bo" target="_blank">batch.bo</a>,<br>
- *surf_offset + 4,<br>
- bo, 0, I915_GEM_DOMAIN_SAMPLER, 0);<br>
-<br>
- int w = intel_obj->Base.Size / texel_size;<br>
- surf[2] = ((w & 0x7f) << BRW_SURFACE_WIDTH_SHIFT |<br>
- ((w >> 7) & 0x1fff) << BRW_SURFACE_HEIGHT_SHIFT);<br>
- surf[3] = (((w >> 20) & 0x7f) << BRW_SURFACE_DEPTH_SHIFT |<br>
- (texel_size - 1) << BRW_SURFACE_PITCH_SHIFT);<br>
- } else {<br>
- surf[1] = 0;<br>
- surf[2] = 0;<br>
- surf[3] = 0;<br>
- }<br>
-<br>
- surf[4] = 0;<br>
- surf[5] = 0;<br>
+ gen4_emit_buffer_surface_state(brw, surf_offset, bo, 0,<br>
+ brw_format,<br>
+ w, texel_size);<br>
}<br>
<br>
static void<br>
@@ -311,37 +314,10 @@ brw_create_constant_surface(struct brw_context *brw,<br>
{<br>
uint32_t stride = dword_pitch ? 4 : 16;<br>
uint32_t elements = ALIGN(size, stride) / stride;<br>
- const GLint w = elements - 1;<br>
- uint32_t *surf;<br>
-<br>
- surf = brw_state_batch(brw, AUB_TRACE_SURFACE_STATE,<br>
- 6 * 4, 32, out_offset);<br>
-<br>
- surf[0] = (BRW_SURFACE_BUFFER << BRW_SURFACE_TYPE_SHIFT |<br>
- BRW_SURFACEFORMAT_R32G32B32A32_FLOAT << BRW_SURFACE_FORMAT_SHIFT);<br>
-<br>
- if (brw->gen >= 6)<br>
- surf[0] |= BRW_SURFACE_RC_READ_WRITE;<br>
-<br>
- surf[1] = bo->offset + offset; /* reloc */<br>
-<br>
- surf[2] = ((w & 0x7f) << BRW_SURFACE_WIDTH_SHIFT |<br>
- ((w >> 7) & 0x1fff) << BRW_SURFACE_HEIGHT_SHIFT);<br>
-<br>
- surf[3] = (((w >> 20) & 0x7f) << BRW_SURFACE_DEPTH_SHIFT |<br>
- (stride - 1) << BRW_SURFACE_PITCH_SHIFT);<br>
<br>
- surf[4] = 0;<br>
- surf[5] = 0;<br>
-<br>
- /* Emit relocation to surface contents. The 965 PRM, Volume 4, section<br>
- * 5.1.2 "Data Cache" says: "the data cache does not exist as a separate<br>
- * physical cache. It is mapped in hardware to the sampler cache."<br>
- */<br>
- drm_intel_bo_emit_reloc(brw-><a href="http://batch.bo" target="_blank">batch.bo</a>,<br>
- *out_offset + 4,<br>
- bo, offset,<br>
- I915_GEM_DOMAIN_SAMPLER, 0);<br>
+ gen4_emit_buffer_surface_state(brw, out_offset, bo, offset,<br>
+ BRW_SURFACEFORMAT_R32G32B32A32_FLOAT,<br>
+ elements - 1, stride);<br>
}<br>
<br>
/**<br>
<span class="HOEnZb"><font color="#888888">--<br>
1.8.3.4<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>