<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Feb 28, 2017 at 9:29 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, Feb 28, 2017 at 08:07:35AM -0800, Jason Ekstrand wrote:<br>
> On Tue, Feb 28, 2017 at 8:02 AM, Nanley Chery <<a href="mailto:nanleychery@gmail.com">nanleychery@gmail.com</a>> wrote:<br>
><br>
> > On Mon, Feb 27, 2017 at 08:48:48PM -0800, Jason Ekstrand wrote:<br>
> > > On Feb 27, 2017 5:20 PM, "Nanley Chery" <<a href="mailto:nanleychery@gmail.com">nanleychery@gmail.com</a>> wrote:<br>
> > ><br>
> > > Validate the inputs and actually verify that this image has a depth<br>
> > > buffer.<br>
> > ><br>
> > > Signed-off-by: Nanley Chery <<a href="mailto:nanley.g.chery@intel.com">nanley.g.chery@intel.com</a>><br>
> > > ---<br>
> > > src/intel/vulkan/anv_blorp.c | 1 +<br>
> > > src/intel/vulkan/anv_image.c | 7 +++----<br>
> > > src/intel/vulkan/anv_private.h | 7 +++++--<br>
> > > 3 files changed, 9 insertions(+), 6 deletions(-)<br>
> > ><br>
> > > diff --git a/src/intel/vulkan/anv_blorp.c b/src/intel/vulkan/anv_blorp.c<br>
> > > index 2cde3b7689..05250de06a 100644<br>
> > > --- a/src/intel/vulkan/anv_blorp.c<br>
> > > +++ b/src/intel/vulkan/anv_blorp.c<br>
> > > @@ -1276,6 +1276,7 @@ anv_cmd_buffer_clear_subpass(<wbr>struct anv_cmd_buffer<br>
> > > *cmd_buffer)<br>
> > > clear_with_hiz = false;<br>
> > > } else if (gen == 8 &&<br>
> > > anv_can_sample_with_hiz(cmd_<br>
> > > buffer->device->info.gen,<br>
> > > + iview->aspect_mask,<br>
> > > iview->image->samples)) {<br>
> > > /* Only gen9+ supports returning ANV_HZ_FC_VAL when<br>
> > > sampling a<br>
> > > * fast-cleared portion of a HiZ buffer. Testing has<br>
> > > revealed<br>
> > > diff --git a/src/intel/vulkan/anv_image.c b/src/intel/vulkan/anv_image.c<br>
> > > index 716cdf3a38..f9f264094f 100644<br>
> > > --- a/src/intel/vulkan/anv_image.c<br>
> > > +++ b/src/intel/vulkan/anv_image.c<br>
> > > @@ -502,7 +502,6 @@ anv_layout_to_aux_usage(const uint8_t gen, const<br>
> > struct<br>
> > > anv_image * const image,<br>
> > > layout == VK_IMAGE_LAYOUT_<wbr>PREINITIALIZED)<br>
> > > layout = future_layout;<br>
> > ><br>
> > > - const bool has_depth = aspects & VK_IMAGE_ASPECT_DEPTH_BIT;<br>
> > > const bool color_aspect = aspects == VK_IMAGE_ASPECT_COLOR_BIT;<br>
> > ><br>
> > > /* The following switch currently only handles depth stencil aspects.<br>
> > > @@ -538,7 +537,7 @@ anv_layout_to_aux_usage(const uint8_t gen, const<br>
> > struct<br>
> > > anv_image * const image,<br>
> > > assert(!color_aspect);<br>
> > > /* Fall-through */<br>
> > > case VK_IMAGE_LAYOUT_SHADER_READ_<wbr>ONLY_OPTIMAL:<br>
> > > - if (has_depth && anv_can_sample_with_hiz(gen, image->samples))<br>
> > > + if (anv_can_sample_with_hiz(gen, aspects, image->samples))<br>
> > > return ISL_AUX_USAGE_HIZ;<br>
> > > else<br>
> > > return ISL_AUX_USAGE_NONE;<br>
> > > @@ -699,8 +698,8 @@ anv_CreateImageView(VkDevice _device,<br>
> > > float red_clear_color = 0.0f;<br>
> > > enum isl_aux_usage surf_usage = image->aux_usage;<br>
> > > if (image->aux_usage == ISL_AUX_USAGE_HIZ) {<br>
> > > - if (iview->aspect_mask & VK_IMAGE_ASPECT_DEPTH_BIT &&<br>
> > > - anv_can_sample_with_hiz(<wbr>device->info.gen, image->samples)) {<br>
> > > + if (anv_can_sample_with_hiz(<wbr>device->info.gen, iview->aspect_mask,<br>
> > > + image->samples)) {<br>
> > > /* When a HiZ buffer is sampled on gen9+, ensure that<br>
> > > * the constant fast clear value is set in the surface state.<br>
> > > */<br>
> > > diff --git a/src/intel/vulkan/anv_<wbr>private.h b/src/intel/vulkan/anv_<br>
> > private.h<br>
> > > index 5ce9027f88..b21a9fb359 100644<br>
> > > --- a/src/intel/vulkan/anv_<wbr>private.h<br>
> > > +++ b/src/intel/vulkan/anv_<wbr>private.h<br>
> > > @@ -1661,9 +1661,12 @@ struct anv_image {<br>
> > ><br>
> > > /* Returns true if a HiZ-enabled depth buffer can be sampled from. */<br>
> > > static inline bool<br>
> > > -anv_can_sample_with_hiz(<wbr>uint8_t gen, uint32_t samples)<br>
> > > +anv_can_sample_with_hiz(<wbr>uint8_t gen, VkImageAspectFlags aspect_mask,<br>
> > > + uint32_t samples)<br>
> > > {<br>
> > > - return gen >= 8 && samples == 1;<br>
> > > + /* Validate the inputs. */<br>
> > > + assert(gen >= 7 && aspect_mask && samples);<br>
> > > + return gen >= 8 && aspect_mask & VK_IMAGE_ASPECT_DEPTH_BIT && samples<br>
> > > == 1;<br>
> > ><br>
> > ><br>
> > > I think you want parents around the "aspect & DEPTH"<br>
> > ><br>
> ><br>
> > According to the C11 spec (footnote 85 found under section 6.5<br>
> > Expressions), the parenthesis are not necessary because the bitwise AND<br>
> > operator has higher precedence than the logical AND operator.<br>
> ><br>
><br>
> I figured but the compiler likes to warn about those things and I really<br>
> don't like having to look at the spec in order to figure out what a line of<br>
> code means. :-)<br>
<br>
<br>
</div></div>Below, is a tip on how to check the operator precedence that may sway<br>
your opinion. Nonetheless, if you'd still like the parenthesis, I can<br>
add it.<br></blockquote><div><br></div><div>Yes, I know how to check and I know that logical comes after bitwise. It's not a matter of how easy it is to check so much as whether or not I have to. A pair of parentheses is a small cost to pay for code obviousness. I'm very surprised you didn't see a GCC warning about this. It always warns on me whenever I mix "&" with "&&" or "||". Please add them. :-)<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Upon reading the aforementioned spec section today, I discovered that<br>
it's actually quite simple to check the precedence. The footnote<br>
explains the following rule and an exception to it: precedence follows<br>
the order of the subsections of section 6.5.<br>
<br>
>From the table of contents:<br>
6.5 Expressions<br>
6.5.1 Primary expressions<br>
6.5.2 Postfix operators<br>
6.5.3 Unary operators<br>
6.5.4 Cast operators<br>
6.5.5 Multiplicative operators<br>
6.5.6 Additive operators<br>
6.5.7 Bitwise shift operators<br>
6.5.8 Relational operators<br>
6.5.9 Equality operators<br>
6.5.10 Bitwise AND operator<br>
6.5.11 Bitwise exclusive OR operator<br>
6.5.12 Bitwise inclusive OR operator<br>
6.5.13 Logical AND operator<br>
6.5.14 Logical OR operator<br>
6.5.15 Conditional operator<br>
6.5.16 Assignment operators<br>
6.5.17 Comma operator<br>
<span class="HOEnZb"><font color="#888888"><br>
-Nanley<br>
</font></span></blockquote></div><br></div></div>