<p dir="ltr"><br>
On Nov 18, 2015 5:02 PM, "Jason Ekstrand" <<a href="mailto:jason@jlekstrand.net">jason@jlekstrand.net</a>> wrote:<br>
><br>
> On Wed, Nov 18, 2015 at 4:06 PM, Kenneth Graunke <<a href="mailto:kenneth@whitecape.org">kenneth@whitecape.org</a>> wrote:<br>
> > On Wednesday, November 18, 2015 03:46:54 PM Ian Romanick wrote:<br>
> >> From: Ian Romanick <<a href="mailto:ian.d.romanick@intel.com">ian.d.romanick@intel.com</a>><br>
> >><br>
> >> Signed-off-by: Ian Romanick <<a href="mailto:ian.d.romanick@intel.com">ian.d.romanick@intel.com</a>><br>
> >> ---<br>
> >> src/mesa/drivers/dri/i965/brw_fs_nir.cpp | 1 +<br>
> >> src/mesa/drivers/dri/i965/brw_fs_visitor.cpp | 16 ++++++++++++++++<br>
> >> src/mesa/drivers/dri/i965/brw_vec4_nir.cpp | 1 +<br>
> >> src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp | 11 +++++++++++<br>
> >> src/mesa/drivers/dri/i965/intel_extensions.c | 1 +<br>
> >> 5 files changed, 30 insertions(+)<br>
> >><br>
> >> diff --git a/src/mesa/drivers/dri/i965/brw_fs_nir.cpp b/src/mesa/drivers/dri/i965/brw_fs_nir.cpp<br>
> >> index 1f71f66..4af1234 100644<br>
> >> --- a/src/mesa/drivers/dri/i965/brw_fs_nir.cpp<br>
> >> +++ b/src/mesa/drivers/dri/i965/brw_fs_nir.cpp<br>
> >> @@ -2550,6 +2550,7 @@ fs_visitor::nir_emit_texture(const fs_builder &bld, nir_tex_instr *instr)<br>
> >> switch (instr->op) {<br>
> >> case nir_texop_txf:<br>
> >> case nir_texop_txf_ms:<br>
> >> + case nir_texop_samples_identical:<br>
> >> coordinate = retype(src, BRW_REGISTER_TYPE_D);<br>
> >> break;<br>
> >> default:<br>
> >> diff --git a/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp b/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp<br>
> >> index a7bd9ce..6688f6a 100644<br>
> >> --- a/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp<br>
> >> +++ b/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp<br>
> >> @@ -259,6 +259,22 @@ fs_visitor::emit_texture(ir_texture_opcode op,<br>
> >> lod = fs_reg(0u);<br>
> >> }<br>
> >><br>
> >> + if (op == ir_samples_identical) {<br>
> >> + fs_reg dst = vgrf(glsl_type::get_instance(dest_type->base_type, 1, 1));<br>
> >> +<br>
> >> + if (mcs.file == BRW_IMMEDIATE_VALUE) {<br>
> >> + fs_reg tmp = vgrf(glsl_type::uint_type);<br>
> >> +<br>
> >> + bld.MOV(tmp, mcs);<br>
> >> + bld.CMP(dst, tmp, src_reg(0u), BRW_CONDITIONAL_EQ);<br>
> ><br>
> > Seems a little strange to emit assembly to do the comparison when<br>
> > you've already determined that the value is a compile time constant.<br>
> ><br>
> > Why not just:<br>
> ><br>
> > bld.MOV(dst, fs_reg(mcs.ud == 0u ? ~0u : 0u));<br>
><br>
> Actually, getting an immediate here means we don't have an MCS and we<br>
> have no idea of the samples are identical, so we should return false<br>
> always.<br>
><br>
> >> + } else {<br>
> >> + bld.CMP(dst, mcs, src_reg(0u), BRW_CONDITIONAL_EQ);<br>
><br>
> We should also consider handling the clear color case. In this case,<br>
> we'll get 0xff for 2x and 0xffffffff for 4x or 8x. Do we know the<br>
> number of samples in the shader? We should be able to get that from<br>
> the sampler or something but then we would have to pass that through<br>
> the key and that would get gross.</p>
<p dir="ltr">First off, I realized that the numbers I have there are wrong. It's 0xff for 2x and 4x and 0xffffffff for 8x. However, I also just realized that the 8 8-bit values you get for 8x MSAA range from 0 to 7 but take up 4 bits each. This means that no valid 8x MSAA MCS value can have 0xff as its bottom 8 bits unless it's the clear color. This means that a simple and with 0xff will get us a clear color check on all but 16x. Unfortunately, 16x has a 64-bit MCS value and, unless the hardware provides is with some extra guarantees, 0xff would be valid in the bottom 8 bits.</p>
<p dir="ltr">Going off into the world of speculation just a bit, can we make some assumptions about the hardware? Suppose for a moment that the used a fairly greedy algorithm for determining which plane to store a value in:</p>
<p dir="ltr"> 1) If all samples are affected, store in slice zero<br>
2) If not, store in the first available empty or completely overwritten slice.</p>
<p dir="ltr">Such an algorithm would make sense and have the nice property of tending to pack the samples in the earlier slices this decreasing the possibility of ever touching slice 15. This is good for cache locality. It also has another property that would be very useful for us, namely that it only touches slice 15 if all 16 samples have different colors. In particular, it would mean that you can never have two samples that both lie in slice 15 and, more specifically, 0xff would also be invalid for 16x.</p>
<p dir="ltr">Unfortunately, that's entirely based on my speculation as to how the hardware works. Given that we don't actually know, it's not documented, and that we're not liable to ever find anyone willing to give us those kinds of details, we're not likely to find out without a very clever experiment.</p>
<p dir="ltr">OK, enough hardware speculation for one night...<br>
--Jason</p>
<p dir="ltr">> One other thought, 16x MSAA will break all this because it gives you a<br>
> ivec4 value from the MCS (if I remember correctly). Not sure if we've<br>
> landed 16x MSAA yet though.<br>
> --Jason<br>
><br>
> >> + }<br>
> >> +<br>
> >> + this->result = dst;<br>
> >> + return;<br>
> >> + }<br>
> >> +<br>
> >> if (coordinate.file != BAD_FILE) {<br>
> >> /* FINISHME: Texture coordinate rescaling doesn't work with non-constant<br>
> >> * samplers. This should only be a problem with GL_CLAMP on Gen7.<br>
> >> diff --git a/src/mesa/drivers/dri/i965/brw_vec4_nir.cpp b/src/mesa/drivers/dri/i965/brw_vec4_nir.cpp<br>
> >> index 3c2674d..41c3c10 100644<br>
> >> --- a/src/mesa/drivers/dri/i965/brw_vec4_nir.cpp<br>
> >> +++ b/src/mesa/drivers/dri/i965/brw_vec4_nir.cpp<br>
> >> @@ -1615,6 +1615,7 @@ vec4_visitor::nir_emit_texture(nir_tex_instr *instr)<br>
> >> switch (instr->op) {<br>
> >> case nir_texop_txf:<br>
> >> case nir_texop_txf_ms:<br>
> >> + case nir_texop_samples_identical:<br>
> >> coordinate = get_nir_src(instr->src[i].src, BRW_REGISTER_TYPE_D,<br>
> >> src_size);<br>
> >> coord_type = glsl_type::ivec(src_size);<br>
> >> diff --git a/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp b/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp<br>
> >> index fda3d7c..2190a86 100644<br>
> >> --- a/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp<br>
> >> +++ b/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp<br>
> >> @@ -909,6 +909,17 @@ vec4_visitor::emit_texture(ir_texture_opcode op,<br>
> >> unreachable("TXB is not valid for vertex shaders.");<br>
> >> case ir_lod:<br>
> >> unreachable("LOD is not valid for vertex shaders.");<br>
> >> + case ir_samples_identical: {<br>
> >> + if (mcs.file == BRW_IMMEDIATE_VALUE) {<br>
> >> + const src_reg temp = src_reg(this, glsl_type::uint_type);<br>
> >> +<br>
> >> + emit(MOV(dst_reg(temp), mcs));<br>
> >> + emit(CMP(dest, temp, src_reg(0u), BRW_CONDITIONAL_EQ));<br>
> ><br>
> > Ditto.<br>
> ><br>
> > bld.MOV(dst, src_reg(mcs.ud == 0u ? ~0u : 0u));<br>
> ><br>
> >> + } else {<br>
> >> + emit(CMP(dest, mcs, src_reg(0u), BRW_CONDITIONAL_EQ));<br>
> >> + }<br>
> >> + return;<br>
> >> + }<br>
> >> default:<br>
> >> unreachable("Unrecognized tex op");<br>
> >> }<br>
> >> diff --git a/src/mesa/drivers/dri/i965/intel_extensions.c b/src/mesa/drivers/dri/i965/intel_extensions.c<br>
> >> index 386b63c..2e2459c 100644<br>
> >> --- a/src/mesa/drivers/dri/i965/intel_extensions.c<br>
> >> +++ b/src/mesa/drivers/dri/i965/intel_extensions.c<br>
> >> @@ -333,6 +333,7 @@ intelInitExtensions(struct gl_context *ctx)<br>
> >> ctx->Extensions.ARB_texture_compression_bptc = true;<br>
> >> ctx->Extensions.ARB_texture_view = true;<br>
> >> ctx->Extensions.ARB_shader_storage_buffer_object = true;<br>
> >> + ctx->Extensions.EXT_shader_samples_identical = true;<br>
> >><br>
> >> if (can_do_pipelined_register_writes(brw)) {<br>
> >> ctx->Extensions.ARB_draw_indirect = true;<br>
> >><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">http://lists.freedesktop.org/mailman/listinfo/mesa-dev</a><br>
> ><br>
</p>