[Mesa-dev] [PATCH v2] anv/cmd_buffer: check for NULL framebuffer

Juan A. Suarez Romero jasuarez at igalia.com
Mon Feb 11 11:29:33 UTC 2019


On Fri, 2019-02-08 at 15:47 -0600, Jason Ekstrand wrote:
> On Fri, Feb 8, 2019 at 7:15 AM Juan A. Suarez Romero <jasuarez at igalia.com> wrote:
> > This can happen when we record a VkCmdDraw in a secondary buffer that
> > 
> > was created inheriting from the primary buffer, but with the framebuffer
> > 
> > set to NULL in the VkCommandBufferInheritanceInfo.
> > 
> > 
> > 
> > Vulkan 1.1.81 spec says that "the application must ensure (using scissor
> > 
> > if neccesary) that all rendering is contained in the render area [...]
> > 
> > [which] must be contained within the framebuffer dimesions".
> > 
> > 
> > 
> > While this should be done by the application, commit 465e5a86 added the
> > 
> > clamp to the framebuffer size, in case of application does not do it.
> > 
> > But this requires to know the framebuffer dimensions.
> > 
> > 
> > 
> > If we do not have a framebuffer at that moment, the best compromise we
> > 
> > can do is to just apply the scissor as it is, and let the application to
> > 
> > ensure the rendering is contained in the render area.
> > 
> > 
> > 
> > v2: do not clamp to framebuffer if there isn't a framebuffer
> > 
> > 
> > 
> > Fixes: 465e5a86 ("anv: Clamp scissors to the framebuffer boundary")
> > 
> > CC: Jason Ekstrand <jason at jlekstrand.net>
> > 
> > ---
> > 
> >  src/intel/vulkan/gen7_cmd_buffer.c | 15 +++++++++++++--
> > 
> >  1 file changed, 13 insertions(+), 2 deletions(-)
> > 
> > 
> > 
> > diff --git a/src/intel/vulkan/gen7_cmd_buffer.c b/src/intel/vulkan/gen7_cmd_buffer.c
> > 
> > index 352892aee33..6e3c8079dc5 100644
> > 
> > --- a/src/intel/vulkan/gen7_cmd_buffer.c
> > 
> > +++ b/src/intel/vulkan/gen7_cmd_buffer.c
> > 
> > @@ -70,12 +70,23 @@ gen7_cmd_buffer_emit_scissor(struct anv_cmd_buffer *cmd_buffer)
> > 
> >        };
> > 
> > 
> > 
> >        const int max = 0xffff;
> > 
> > +
> > 
> > +      uint32_t max_height, max_width;
> > 
> > +
> > 
> > +      if (fb) {
> > 
> > +         max_height = fb->height;
> > 
> > +         max_width = fb->width;
> 
> Why aren't we clamping here?
> 
Right, a mistake.
> Also, I realized while we were e-mailing that if we're in the primary command buffer, we can actually clamp to renderArea instead of the framebuffer.  That'd be even better.

OK. 
I'm sending a v3.
	J.A.
>  
> > +      } else {
> > 
> > +         max_height = s->offset.y + s->extent.height;
> > 
> > +         max_width = s->offset.x + s->extent.width;
> > 
> > +      }
> > 
> > +
> > 
> >        struct GEN7_SCISSOR_RECT scissor = {
> > 
> >           /* Do this math using int64_t so overflow gets clamped correctly. */
> > 
> >           .ScissorRectangleYMin = clamp_int64(s->offset.y, 0, max),
> > 
> >           .ScissorRectangleXMin = clamp_int64(s->offset.x, 0, max),
> > 
> > -         .ScissorRectangleYMax = clamp_int64((uint64_t) s->offset.y + s->extent.height - 1, 0, fb->height - 1),
> > 
> > -         .ScissorRectangleXMax = clamp_int64((uint64_t) s->offset.x + s->extent.width - 1, 0, fb->width - 1)
> > 
> > +         .ScissorRectangleYMax = clamp_int64((uint64_t) s->offset.y + s->extent.height - 1, 0, max_height - 1),
> > 
> > +         .ScissorRectangleXMax = clamp_int64((uint64_t) s->offset.x + s->extent.width - 1, 0, max_width - 1)
> > 
> >        };
> > 
> > 
> > 
> >        if (s->extent.width <= 0 || s->extent.height <= 0) {
> > 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20190211/a7a9e8b4/attachment-0001.html>


More information about the mesa-dev mailing list