<div dir="ltr"><div>You seem to be right about 2 things: Your implementation and the fact that it's entirely INSANE! I checked and double-checked the bspec and this looks correct. I trust you with the rest of the state bits.<br></div>Reviewed-by: Jason Ekstrand <<a href="mailto:jason.ekstrand@intel.com">jason.ekstrand@intel.com</a>><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Feb 6, 2015 at 4:32 AM, Kenneth Graunke <span dir="ltr"><<a href="mailto:kenneth@whitecape.org" target="_blank">kenneth@whitecape.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">+82 Piglits - 100% of border color tests now pass on Haswell.<br>
<br>
Signed-off-by: Kenneth Graunke <<a href="mailto:kenneth@whitecape.org">kenneth@whitecape.org</a>><br>
Cc: Chris Forbes <<a href="mailto:chrisf@ijw.co.nz">chrisf@ijw.co.nz</a>><br>
Cc: <a href="mailto:mesa-stable@lists.freedesktop.org">mesa-stable@lists.freedesktop.org</a><br>
---<br>
src/mesa/drivers/dri/i965/brw_defines.h | 1 +<br>
src/mesa/drivers/dri/i965/brw_sampler_state.c | 62 +++++++++++++++++++++++<br>
src/mesa/drivers/dri/i965/gen7_wm_surface_state.c | 3 ++<br>
3 files changed, 66 insertions(+)<br>
<br>
I finally figured out what the documentation was trying to say! Buried<br>
within thirteen pages of tables were a few extra bizarre bits - RG is<br>
broken and treated as RB (like it is for textureGather), and 16-bit<br>
skip a DWord for no obvious reason.<br>
<br>
With all the strange corner cases in place, everything seems to work.<br>
<br>
diff --git a/src/mesa/drivers/dri/i965/brw_defines.h b/src/mesa/drivers/dri/i965/brw_defines.h<br>
index f02a0b8..a597d6b 100644<br>
--- a/src/mesa/drivers/dri/i965/brw_defines.h<br>
+++ b/src/mesa/drivers/dri/i965/brw_defines.h<br>
@@ -551,6 +551,7 @@<br>
#define BRW_SURFACE_PITCH_MASK INTEL_MASK(19, 3)<br>
#define BRW_SURFACE_TILED (1 << 1)<br>
#define BRW_SURFACE_TILED_Y (1 << 0)<br>
+#define HSW_SURFACE_IS_INTEGER_FORMAT (1 << 18)<br>
<br>
/* Surface state DW4 */<br>
#define BRW_SURFACE_MIN_LOD_SHIFT 28<br>
diff --git a/src/mesa/drivers/dri/i965/brw_sampler_state.c b/src/mesa/drivers/dri/i965/brw_sampler_state.c<br>
index c6a8ab1..be85660 100644<br>
--- a/src/mesa/drivers/dri/i965/brw_sampler_state.c<br>
+++ b/src/mesa/drivers/dri/i965/brw_sampler_state.c<br>
@@ -271,6 +271,68 @@ upload_default_color(struct brw_context *brw,<br>
uint32_t *sdc = brw_state_batch(brw, AUB_TRACE_SAMPLER_DEFAULT_COLOR,<br>
4 * 4, 64, sdc_offset);<br>
memcpy(sdc, color.ui, 4 * 4);<br>
+ } else if (brw->is_haswell && texObj->_IsIntegerFormat) {<br>
+ /* Haswell's integer border color support is completely insane:<br>
+ * SAMPLER_BORDER_COLOR_STATE is 20 DWords. The first four are<br>
+ * for float colors. The next 12 DWords are MBZ and only exist to<br>
+ * pad it out to a 64 byte cacheline boundary. DWords 16-19 then<br>
+ * contain integer colors; these are only used if SURFACE_STATE<br>
+ * has the "Integer Surface Format" bit set. Even then, the<br>
+ * arrangement of the RGBA data devolves into madness.<br>
+ */<br>
+ uint32_t *sdc = brw_state_batch(brw, AUB_TRACE_SAMPLER_DEFAULT_COLOR,<br>
+ 20 * 4, 512, sdc_offset);<br>
+ memset(sdc, 0, 20 * 4);<br>
+ sdc = &sdc[16];<br>
+<br>
+ mesa_format format = firstImage->TexFormat;<br>
+ int bits_per_channel = _mesa_get_format_bits(format, GL_RED_BITS);<br>
+<br>
+ /* From the Haswell PRM, "Command Reference: Structures", Page 36:<br>
+ * "If any color channel is missing from the surface format,<br>
+ * corresponding border color should be programmed as zero and if<br>
+ * alpha channel is missing, corresponding Alpha border color should<br>
+ * be programmed as 1."<br>
+ */<br>
+ unsigned c[4] = { 0, 0, 0, 1 };<br>
+ for (int i = 0; i < 4; i++) {<br>
+ if (_mesa_format_has_color_component(format, i))<br>
+ c[i] = color.ui[i];<br>
+ }<br>
+<br>
+ switch (bits_per_channel) {<br>
+ case 8:<br>
+ /* Copy RGBA in order. */<br>
+ for (int i = 0; i < 4; i++)<br>
+ ((uint8_t *) sdc)[i] = c[i];<br>
+ break;<br>
+ case 10:<br>
+ /* R10G10B10A2_UINT is treated like a 16-bit format. */<br>
+ case 16:<br>
+ ((uint16_t *) sdc)[0] = c[0]; /* R -> DWord 0, bits 15:0 */<br>
+ ((uint16_t *) sdc)[1] = c[1]; /* G -> DWord 0, bits 31:16 */<br>
+ /* DWord 1 is Reserved/MBZ! */<br>
+ ((uint16_t *) sdc)[4] = c[2]; /* B -> DWord 2, bits 15:0 */<br>
+ ((uint16_t *) sdc)[5] = c[3]; /* A -> DWord 3, bits 31:16 */<br>
+ break;<br>
+ case 32:<br>
+ if (firstImage->_BaseFormat == GL_RG) {<br>
+ /* Careful inspection of the tables reveals that for RG32 formats,<br>
+ * the green channel needs to go where blue normally belongs.<br>
+ */<br>
+ sdc[0] = c[0];<br>
+ sdc[2] = c[1];<br>
+ sdc[3] = 1;<br>
+ } else {<br>
+ /* Copy RGBA in order. */<br>
+ for (int i = 0; i < 4; i++)<br>
+ sdc[i] = c[i];<br>
+ }<br>
+ break;<br>
+ default:<br>
+ assert(!"Invalid number of bits per channel in integer format.");<br>
+ break;<br>
+ }<br>
} else if (brw->gen == 5 || brw->gen == 6) {<br>
struct gen5_sampler_default_color *sdc;<br>
<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 07db678..29553cd 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>
@@ -321,6 +321,9 @@ gen7_update_texture_surface(struct gl_context *ctx,<br>
surf[3] = SET_FIELD(effective_depth - 1, BRW_SURFACE_DEPTH) |<br>
(mt->pitch - 1);<br>
<br>
+ if (brw->is_haswell && tObj->_IsIntegerFormat)<br>
+ surf[3] |= HSW_SURFACE_IS_INTEGER_FORMAT;<br>
+<br>
surf[4] = gen7_surface_msaa_bits(mt->num_samples, mt->msaa_layout) |<br>
SET_FIELD(tObj->MinLayer, GEN7_SURFACE_MIN_ARRAY_ELEMENT) |<br>
SET_FIELD((effective_depth - 1),<br>
<span class="HOEnZb"><font color="#888888">--<br>
2.2.2<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>