<html dir="ltr"><head></head><body style="text-align:left; direction:ltr;"><div>On Fri, 2019-02-08 at 15:47 -0600, Jason Ekstrand wrote:</div><blockquote type="cite" style="margin:0 0 0 .8ex; border-left:2px #729fcf solid;padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Feb 8, 2019 at 7:15 AM Juan A. Suarez Romero <<a href="mailto:jasuarez@igalia.com">jasuarez@igalia.com</a>> wrote:<br></div><blockquote type="cite" style="margin:0 0 0 .8ex; border-left:2px #729fcf solid;padding-left:1ex">This can happen when we record a VkCmdDraw in a secondary buffer that<br>
was created inheriting from the primary buffer, but with the framebuffer<br>
set to NULL in the VkCommandBufferInheritanceInfo.<br>
<br>
Vulkan 1.1.81 spec says that "the application must ensure (using scissor<br>
if neccesary) that all rendering is contained in the render area [...]<br>
[which] must be contained within the framebuffer dimesions".<br>
<br>
While this should be done by the application, commit 465e5a86 added the<br>
clamp to the framebuffer size, in case of application does not do it.<br>
But this requires to know the framebuffer dimensions.<br>
<br>
If we do not have a framebuffer at that moment, the best compromise we<br>
can do is to just apply the scissor as it is, and let the application to<br>
ensure the rendering is contained in the render area.<br>
<br>
v2: do not clamp to framebuffer if there isn't a framebuffer<br>
<br>
Fixes: 465e5a86 ("anv: Clamp scissors to the framebuffer boundary")<br>
CC: Jason Ekstrand <<a href="mailto:jason@jlekstrand.net" target="_blank">jason@jlekstrand.net</a>><br>
---<br>
src/intel/vulkan/gen7_cmd_buffer.c | 15 +++++++++++++--<br>
1 file changed, 13 insertions(+), 2 deletions(-)<br>
<br>
diff --git a/src/intel/vulkan/gen7_cmd_buffer.c b/src/intel/vulkan/gen7_cmd_buffer.c<br>
index 352892aee33..6e3c8079dc5 100644<br>
--- a/src/intel/vulkan/gen7_cmd_buffer.c<br>
+++ b/src/intel/vulkan/gen7_cmd_buffer.c<br>
@@ -70,12 +70,23 @@ gen7_cmd_buffer_emit_scissor(struct anv_cmd_buffer *cmd_buffer)<br>
};<br>
<br>
const int max = 0xffff;<br>
+<br>
+ uint32_t max_height, max_width;<br>
+<br>
+ if (fb) {<br>
+ max_height = fb->height;<br>
+ max_width = fb->width;<br></blockquote><div><br></div><div>Why aren't we clamping here?</div><div><br></div></div></div></blockquote><div>Right, a mistake.</div><div><br></div><blockquote type="cite" style="margin:0 0 0 .8ex; border-left:2px #729fcf solid;padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><div>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.<br></div></div></div></blockquote><div><br></div><div>OK. </div><div><br></div><div>I'm sending a v3.</div><div><br></div><div> J.A.</div><div><br></div><blockquote type="cite" style="margin:0 0 0 .8ex; border-left:2px #729fcf solid;padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><div> </div><blockquote type="cite" style="margin:0 0 0 .8ex; border-left:2px #729fcf solid;padding-left:1ex">
+ } else {<br>
+ max_height = s->offset.y + s->extent.height;<br>
+ max_width = s->offset.x + s->extent.width;<br>
+ }<br>
+<br>
struct GEN7_SCISSOR_RECT scissor = {<br>
/* Do this math using int64_t so overflow gets clamped correctly. */<br>
.ScissorRectangleYMin = clamp_int64(s->offset.y, 0, max),<br>
.ScissorRectangleXMin = clamp_int64(s->offset.x, 0, max),<br>
- .ScissorRectangleYMax = clamp_int64((uint64_t) s->offset.y + s->extent.height - 1, 0, fb->height - 1),<br>
- .ScissorRectangleXMax = clamp_int64((uint64_t) s->offset.x + s->extent.width - 1, 0, fb->width - 1)<br>
+ .ScissorRectangleYMax = clamp_int64((uint64_t) s->offset.y + s->extent.height - 1, 0, max_height - 1),<br>
+ .ScissorRectangleXMax = clamp_int64((uint64_t) s->offset.x + s->extent.width - 1, 0, max_width - 1)<br>
};<br>
<br>
if (s->extent.width <= 0 || s->extent.height <= 0) {<br>
</blockquote></div></div></blockquote></body></html>