<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Oct 12, 2016 at 9:01 AM, Nanley Chery <span dir="ltr"><<a href="mailto:nanleychery@gmail.com" target="_blank">nanleychery@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On Tue, Oct 11, 2016 at 06:55:53PM -0700, Jason Ekstrand wrote:<br>
> On Tue, Oct 11, 2016 at 6:16 PM, Nanley Chery <<a href="mailto:nanleychery@gmail.com">nanleychery@gmail.com</a>> wrote:<br>
><br>
> > On Mon, Oct 10, 2016 at 06:00:49PM -0700, Jason Ekstrand wrote:<br>
> > > On Mon, Oct 10, 2016 at 2:23 PM, Nanley Chery <<a href="mailto:nanleychery@gmail.com">nanleychery@gmail.com</a>><br>
> > wrote:<br>
> > ><br>
> > > > On Fri, Oct 07, 2016 at 09:41:14PM -0700, Jason Ekstrand wrote:<br>
> > > > > If we don't, we can end up with corruption in the portion of the<br>
> > depth<br>
> > > > > buffer that lies outside the render area when we do a HiZ resolve at<br>
> > the<br>
> > > > > end. The only reason we weren't seeing this before was that all of<br>
> > the<br>
> > > > > meta-based clears such as VkCmdClearDepthStencilImage were internally<br>
> > > > using<br>
> > > > > HiZ so the HiZ buffer never truly got out-of-sync. If the CTS ever<br>
> > > > tested<br>
> > > > > a depth upload (which doesn't care about HiZ) and then a partial<br>
> > render<br>
> > > > we<br>
> > > > > would have seen problems. Soon, we will be using blorp to do depth<br>
> > > > clears<br>
> > > > > and it won't bother with HiZ so we would get CTS regressions without<br>
> > > > this.<br>
> > > > ><br>
> > > ><br>
> > > > I understand the problem, but I think this solution unnecessarily<br>
> > > > penalizes the user's renderpass.<br>
> > > ><br>
> > > > Since depth buffer updates via vkCopy*ToImage and<br>
> > > > vkCmdClearDepthStencilImage cause the HiZ buffer to become stale,<br>
> > > > calling<br>
> > > ><br>
> > > > genX(cmd_buffer_emit_hz_op)(<wbr>cmd_buffer, BLORP_HIZ_OP_HIZ_RESOLVE);<br>
> > > ><br>
> > > > at the bottom of those commands should fix the issue without the extra<br>
> > > > penalty. I'd imagine that as a prequisite, blorp would have to learn to<br>
> > > > emit enough depth stencil state for this command.<br>
> > > ><br>
> > ><br>
> > > I think that's dangerously mixing HiZ data validity models. There are 3<br>
> > > basic aux data validity models that we've thrown around:<br>
> > ><br>
> > > 1) AUX is always correct.<br>
> > > 2) AUX is correct within a render pass and invalid outside.<br>
> > > 3) Track whether or not AUX is valid and resolve only as needed.<br>
> > ><br>
> ><br>
> > What is the definition of correct here? I'd assume you mean that the<br>
> > data matches what's in the depth buffer, but that sometimes may not be<br>
> > the case (STORE_OP_DONTCARE) yet the program behavior is correct<br>
> > nonetheless.<br>
> ><br>
><br>
> By "correct" I mean "consistent with the depth buffer" or, more precicely,<br>
> "all well-defined pixels of the depth buffer are consistent with the HiZ<br>
> buffer". We *may* be able to avoid the depth resolve at the end if you<br>
> have STORE_OP_DONT_CARE. However, we would probably not do anything<br>
> interesting with LOAD_OP_DONT_CARE.<br>
><br>
<br>
<br>
</div></div>With this definition of correct (accessing either buffer will give you<br>
the correct value due to their being consistent with each other), the<br>
current implementation is arguably a course-grained version of (3) (no<br>
tracking, let's call this 4) than it is (2). The HiZ buffer is only<br>
consistent with the depth buffer when a user performs an operation that<br>
likely requires it to be so. For example:<br>
<br>
* LOAD_OP_LOAD -> HiZ Resolve (consistent)<br>
* LOAD_OP_CLEAR -> No resolve, Fast Depth Clear (inconsistent)<br>
* vkCmdDraw* -> No resolve (inconsistent)<br>
* STORE_OP_STORE -> Depth Resolve (consistent)<br>
<span class=""><br>
><br>
> > Also, could you please explain where the danger comes into play?<br>
> ><br>
><br>
> We need to have a solid mental model of when HiZ and depth are consistent.<br>
> Otherwise, we'll make mistakes, things will get inconsistent, and we'll<br>
<br>
</span>Agreed.<br>
<span class=""><br>
> have weird bugs. This bug is a good example of this. Our mental model (2)<br>
> works fine except that we were leaking garbage depth from DONT_CARE when we<br>
> have a partial areat. Just doing a HiZ resolve after a blorp clear "fixes"<br>
> the bug by making things always consistent (mental model 1). But then it<br>
<br>
</span>As mentioned above, I'm not advocating mixing 1 and 2, but covering a<br>
missed case in 4. Whether or not that mental model is solid seems like<br>
a subjective claim.<br>
<span class=""><br>
> means that we have LOAD_OP_LOAD, we're doing two HiZ resolves which we<br>
> don't want either.<br>
><br>
<br>
</span>I wouldn't expect Vulkan apps to submit image copies as frequently as<br>
render passes, so my thinking is that an extra HiZ resolve at the end of<br>
an Image copy should have less of an impact on FPS than performing the<br>
resolve on every clearing RP that doesn't use a full render area. I<br>
did not write the patch to test my suggestion, but I was able to get a<br>
measurable difference by forcing HiZ resolves on the triangle demo. I<br>
won't post the numbers I obtained from the questionable method of<br>
eye-balling the FPS counter (especially with the amount of variance<br>
involved), so feel free to take a look at it yourself.<br></blockquote><div><br></div><div>I wouldn't expect copies to happen particularly frequently either and I certainly don't think we should optimize for them.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I think the temporarily minor dip in performance introduced here is a<br>
small price to pay for the removal of meta. I also think my suggestion<br>
may be a lot more work than it seemed initially, so it's likely best to<br>
revisit this later.<br></blockquote><div><br></div><div>Agreed. I think we need to do some reading and thinking about image layouts. I believe that's how we're intended to do these sorts of things in Vulkan. My initial thought would be to have a mapping from image layout to a "use HiZ" flag that would look something like this:<br><br></div><div>GENERAL -> no<br>DEPTH_STENCIL_ATTACHMENT_OPTIMAL -> yes<br></div><div>SHADER_READ_ONLY_OPTIMAL -> gen >= 8<br></div><div>TRANSFER_SRC_OPTIMAL -> gen >= 8<br></div><div>TRANSFER_DST_OPTIMAL -> no<br><br></div><div>And then, when they do a CmdPipelineBarrier that transitions the layout in such a way that "use HiZ" goes from yes to no we do a depth resolve and when it goes from no to yes, we do a HiZ resolve. The layout transitions are per-layer and per-miplevel so the client is required to do basically the exact same tracking we do in the GL driver today.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
This patch is:<br>
Reviewed-by: Nanley Chery <<a href="mailto:nanley.g.chery@intel.com">nanley.g.chery@intel.com</a>><br></blockquote><div><br></div><div>Thanks!<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="HOEnZb"><div class="h5"><br>
> As I intended to say below, I don't mind moving to (1), but if that's what<br>
> we want to do we should commit to it and change rather than going with<br>
> half-and-half.<br>
><br>
><br>
> > > So far, our initial enabling strategy has been (2). We can move to (1)<br>
> > or<br>
> > > maybe even (3) with layout transitions, but that's not what we've done so<br>
> > > far. Your suggestion is to mix in a little of (1) because there is a bug<br>
> > > in our implementation of (2).<br>
> > ><br>
> > > I'm Ok, for gen8+ HiZ, with moving to (2) eventually since gen8 is<br>
> > capable<br>
> > ^<br>
> > I'm not sure which model you're<br>
> > referring to here since you<br>
> > said this was our initial<br>
> > enabling model.<br>
> ><br>
><br>
> I meant "moving to (1)". Sorry for the typo.<br>
><br>
><br>
> ><br>
> > -Nanley<br>
> ><br>
> > > of sampling with HiZ. (Maybe we can even move to (3).) However, that's<br>
> > > not where we are right now and I don't really want to start mixing mental<br>
> > > models.<br>
> > ><br>
> > > --Jason<br>
> > ><br>
> > ><br>
> > > > -Nanley<br>
> > > ><br>
> > > > > Signed-off-by: Jason Ekstrand <<a href="mailto:jason@jlekstrand.net">jason@jlekstrand.net</a>><br>
> > > > > ---<br>
> > > > > src/intel/vulkan/gen8_cmd_<wbr>buffer.c | 12 +++++++++++-<br>
> > > > > 1 file changed, 11 insertions(+), 1 deletion(-)<br>
> > > > ><br>
> > > > > diff --git a/src/intel/vulkan/gen8_cmd_<wbr>buffer.c<br>
> > > > b/src/intel/vulkan/gen8_cmd_<wbr>buffer.c<br>
> > > > > index e6a3c3d..44ffcbf 100644<br>
> > > > > --- a/src/intel/vulkan/gen8_cmd_<wbr>buffer.c<br>
> > > > > +++ b/src/intel/vulkan/gen8_cmd_<wbr>buffer.c<br>
> > > > > @@ -513,7 +513,17 @@ genX(cmd_buffer_emit_hz_op)(<wbr>struct<br>
> > anv_cmd_buffer<br>
> > > > *cmd_buffer,<br>
> > > > > return;<br>
> > > > > break;<br>
> > > > > case BLORP_HIZ_OP_HIZ_RESOLVE:<br>
> > > > > - if (cmd_buffer->state.pass-><wbr>attachments[ds].load_op !=<br>
> > > > > + /* If the render area covers the entire surface *and* load_op<br>
> > is<br>
> > > > either<br>
> > > > > + * CLEAR or DONT_CARE then the previous contents of the depth<br>
> > > > buffer<br>
> > > > > + * will be entirely discarded. In this case, we can skip the<br>
> > HiZ<br>
> > > > > + * resolve.<br>
> > > > > + *<br>
> > > > > + * If the render area is not the full surface, we need to do<br>
> > > > > + * the resolve because otherwise data outside the render area<br>
> > may<br>
> > > > get<br>
> > > > > + * garbled by the resolve at the end of the render pass.<br>
> > > > > + */<br>
> > > > > + if (full_surface_op &&<br>
> > > > > + cmd_buffer->state.pass-><wbr>attachments[ds].load_op !=<br>
> > > > > VK_ATTACHMENT_LOAD_OP_LOAD)<br>
> > > > > return;<br>
> > > > > break;<br>
> > > > > --<br>
> > > > > 2.5.0.400.gff86faf<br>
> > > > ><br>
> > > > > ______________________________<wbr>_________________<br>
> > > > > mesa-dev mailing list<br>
> > > > > <a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
> > > > > <a href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev" rel="noreferrer" target="_blank">https://lists.freedesktop.org/<wbr>mailman/listinfo/mesa-dev</a><br>
> > > ><br>
> ><br>
</div></div></blockquote></div><br></div></div>