<div dir="ltr"><div>I need to recind this patch. I thought it worked but it's far more half-baked than I realized. There's some issue with swizzles interacting with the clear color. :-(<br></div>--Jason<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, May 10, 2016 at 9:45 PM, Jason Ekstrand <span dir="ltr"><<a href="mailto:jason@jlekstrand.net" target="_blank">jason@jlekstrand.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">The current MSAA resolve code has a special-case for if the MCS value is 0.<br>
In this case we can only sample once because we know that all values are in<br>
slice 0. This commit adds a second optimization that detecs the magic MCS<br>
value that indicates the clear color and grabs the color from a push<br>
constant and avoids sampling altogether. On a microbenchmark written by<br>
Neil Roberts that tests resolving surfaces with just clear color, this<br>
improves performance by 60% for 8x, 40% for 4x, and 28% for 2x MSAA on my<br>
SKL gte3 laptop. The benchmark can be found on the ML archive:<br>
<br>
<a href="https://lists.freedesktop.org/archives/mesa-dev/2016-February/108077.html" rel="noreferrer" target="_blank">https://lists.freedesktop.org/archives/mesa-dev/2016-February/108077.html</a><br>
---<br>
src/mesa/drivers/dri/i965/brw_blorp.h | 4 +-<br>
src/mesa/drivers/dri/i965/brw_blorp_blit.cpp | 72 ++++++++++++++++++++++++++--<br>
2 files changed, 71 insertions(+), 5 deletions(-)<br>
<br>
diff --git a/src/mesa/drivers/dri/i965/brw_blorp.h b/src/mesa/drivers/dri/i965/brw_blorp.h<br>
index 5f7569c..550c6c5 100644<br>
--- a/src/mesa/drivers/dri/i965/brw_blorp.h<br>
+++ b/src/mesa/drivers/dri/i965/brw_blorp.h<br>
@@ -197,7 +197,9 @@ struct brw_blorp_wm_push_constants<br>
uint32_t src_z;<br>
<br>
/* Pad out to an integral number of registers */<br>
- uint32_t pad[5];<br>
+ uint32_t pad;<br>
+<br>
+ union gl_color_union clear_color;<br>
};<br>
<br>
#define BRW_BLORP_NUM_PUSH_CONSTANT_DWORDS \<br>
diff --git a/src/mesa/drivers/dri/i965/brw_blorp_blit.cpp b/src/mesa/drivers/dri/i965/brw_blorp_blit.cpp<br>
index 97e3908..314034e 100644<br>
--- a/src/mesa/drivers/dri/i965/brw_blorp_blit.cpp<br>
+++ b/src/mesa/drivers/dri/i965/brw_blorp_blit.cpp<br>
@@ -346,6 +346,7 @@ struct brw_blorp_blit_vars {<br>
nir_variable *offset;<br>
} u_x_transform, u_y_transform;<br>
nir_variable *u_src_z;<br>
+ nir_variable *u_clear_color;<br>
<br>
/* gl_FragCoord */<br>
nir_variable *frag_coord;<br>
@@ -374,6 +375,7 @@ brw_blorp_blit_vars_init(nir_builder *b, struct brw_blorp_blit_vars *v,<br>
LOAD_UNIFORM(y_transform.multiplier, glsl_float_type())<br>
LOAD_UNIFORM(y_transform.offset, glsl_float_type())<br>
LOAD_UNIFORM(src_z, glsl_uint_type())<br>
+ LOAD_UNIFORM(clear_color, glsl_vec4_type())<br>
<br>
#undef DECL_UNIFORM<br>
<br>
@@ -858,7 +860,8 @@ static nir_ssa_def *<br>
blorp_nir_manual_blend_average(nir_builder *b, nir_ssa_def *pos,<br>
unsigned tex_samples,<br>
enum intel_msaa_layout tex_layout,<br>
- enum brw_reg_type dst_type)<br>
+ enum brw_reg_type dst_type,<br>
+ struct brw_blorp_blit_vars *v)<br>
{<br>
/* If non-null, this is the outer-most if statement */<br>
nir_if *outer_if = NULL;<br>
@@ -867,9 +870,53 @@ blorp_nir_manual_blend_average(nir_builder *b, nir_ssa_def *pos,<br>
nir_local_variable_create(b->impl, glsl_vec4_type(), "color");<br>
<br>
nir_ssa_def *mcs = NULL;<br>
- if (tex_layout == INTEL_MSAA_LAYOUT_CMS)<br>
+ if (tex_layout == INTEL_MSAA_LAYOUT_CMS) {<br>
mcs = blorp_nir_txf_ms_mcs(b, pos);<br>
<br>
+ /* The MCS buffer stores a packed value that provides a mapping from<br>
+ * samples to array slices. The magic value of all ones means that all<br>
+ * samples have the clear color. In this case, we can short-circuit the<br>
+ * sampling process and just use the clear color that we pushed into the<br>
+ * shader.<br>
+ */<br>
+ nir_ssa_def *is_clear_color;<br>
+ switch (tex_samples) {<br>
+ case 2:<br>
+ /* Empirical evidence suggests that the value returned from the<br>
+ * sampler is not always 0x3 for clear color so we need to mask it.<br>
+ */<br>
+ is_clear_color =<br>
+ nir_ieq(b, nir_iand(b, nir_channel(b, mcs, 0), nir_imm_int(b, 0x3)),<br>
+ nir_imm_int(b, 0x3));<br>
+ break;<br>
+ case 4:<br>
+ is_clear_color =<br>
+ nir_ieq(b, nir_channel(b, mcs, 0), nir_imm_int(b, 0xff));<br>
+ break;<br>
+ case 8:<br>
+ is_clear_color =<br>
+ nir_ieq(b, nir_channel(b, mcs, 0), nir_imm_int(b, ~0));<br>
+ break;<br>
+ case 16:<br>
+ is_clear_color =<br>
+ nir_ior(b, nir_ieq(b, nir_channel(b, mcs, 0), nir_imm_int(b, ~0)),<br>
+ nir_ieq(b, nir_channel(b, mcs, 1), nir_imm_int(b, ~0)));<br>
+ break;<br>
+ default:<br>
+ unreachable("Invalid sample count");<br>
+ }<br>
+<br>
+ nir_if *if_stmt = nir_if_create(b->shader);<br>
+ if_stmt->condition = nir_src_for_ssa(is_clear_color);<br>
+ nir_cf_node_insert(b->cursor, &if_stmt->cf_node);<br>
+<br>
+ b->cursor = nir_after_cf_list(&if_stmt->then_list);<br>
+ nir_store_var(b, color, nir_load_var(b, v->u_clear_color), 0xf);<br>
+<br>
+ b->cursor = nir_after_cf_list(&if_stmt->else_list);<br>
+ outer_if = if_stmt;<br>
+ }<br>
+<br>
/* We add together samples using a binary tree structure, e.g. for 4x MSAA:<br>
*<br>
* result = ((sample[0] + sample[1]) + (sample[2] + sample[3])) / 4<br>
@@ -937,7 +984,8 @@ blorp_nir_manual_blend_average(nir_builder *b, nir_ssa_def *pos,<br>
nir_store_var(b, color, texture_data[0], 0xf);<br>
<br>
b->cursor = nir_after_cf_list(&if_stmt->else_list);<br>
- outer_if = if_stmt;<br>
+ if (!outer_if)<br>
+ outer_if = if_stmt;<br>
}<br>
<br>
for (int j = 0; j < count_trailing_one_bits(i); j++) {<br>
@@ -1345,7 +1393,7 @@ brw_blorp_build_nir_shader(struct brw_context *brw,<br>
/* Gen7+ hardware doesn't automaticaly blend. */<br>
color = blorp_nir_manual_blend_average(&b, src_pos, key->src_samples,<br>
key->src_layout,<br>
- key->texture_data_type);<br>
+ key->texture_data_type, &v);<br>
}<br>
} else if (key->blend && key->blit_scaled) {<br>
color = blorp_nir_manual_blend_bilinear(&b, src_pos, key->src_samples, key, &v);<br>
@@ -1669,6 +1717,22 @@ brw_blorp_blit_miptrees(struct brw_context *brw,<br>
params.src.num_samples <= 1 && params.dst.num_samples <= 1)<br>
wm_prog_key.bilinear_filter = true;<br>
<br>
+ union gl_color_union clear_color;<br>
+ if (brw->gen >= 9) {<br>
+ clear_color = src_mt->gen9_fast_clear_color;<br>
+ } else if (_mesa_is_format_integer(src_mt->format)) {<br>
+ clear_color.i[0] = (src_mt->fast_clear_color_value & (1 << 0)) != 0;<br>
+ clear_color.i[1] = (src_mt->fast_clear_color_value & (1 << 1)) != 0;<br>
+ clear_color.i[2] = (src_mt->fast_clear_color_value & (1 << 2)) != 0;<br>
+ clear_color.i[3] = (src_mt->fast_clear_color_value & (1 << 3)) != 0;<br>
+ } else {<br>
+ clear_color.f[0] = (src_mt->fast_clear_color_value & (1 << 0)) != 0;<br>
+ clear_color.f[1] = (src_mt->fast_clear_color_value & (1 << 1)) != 0;<br>
+ clear_color.f[2] = (src_mt->fast_clear_color_value & (1 << 2)) != 0;<br>
+ clear_color.f[3] = (src_mt->fast_clear_color_value & (1 << 3)) != 0;<br>
+ }<br>
+ params.wm_push_consts.clear_color = clear_color;<br>
+<br>
GLenum base_format = _mesa_get_format_base_format(src_mt->format);<br>
if (base_format != GL_DEPTH_COMPONENT && /* TODO: what about depth/stencil? */<br>
base_format != GL_STENCIL_INDEX &&<br>
<span class="HOEnZb"><font color="#888888">--<br>
2.5.0.400.gff86faf<br>
<br>
</font></span></blockquote></div><br></div>