On 9 April 2012 10:59, Kenneth Graunke <span dir="ltr"><<a href="mailto:kenneth@whitecape.org">kenneth@whitecape.org</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">On 04/09/2012 09:43 AM, Paul Berry wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
When using a separate stencil buffer, i965 requires that the pitch of<br>
the buffer (in the 3DSTATE_STENCIL_BUFFER command) be specified as 2x<br>
the actual pitch.<br>
<br>
Previously this was accomplished by doubling the "cpp" and "pitch"<br>
values stored in the intel_region data structure, and halving the<br>
height. However, this was confusing, and it led to a subtle (but<br>
benign) bug: since a stencil buffer is W-tiled, its true height must<br>
be aligned to a multiple of 64; we were accidentally aligning its faux<br>
height to a multiple of 64, causing memory to be wasted.<br>
<br>
Note that for window system stencil buffers, the X server also doubles<br>
the cpp and pitch values. To facilitate fixing this X server bug in<br>
the future, we fix the cpp and pitch values we receive from the X<br>
server only if cpp has the "incorrect" value of 2.<br>
</blockquote>
<br></div>
Paul,<br>
<br>
This seems like a nice clean-up. I'm glad to see this.<br>
<br>
I reviewed the code and it seems to make sense, but I'd really want to see Chad or Eric's review on it before it gets pushed.<br>
<br>
Acked-by: Kenneth Graunke <<a href="mailto:kenneth@whitecape.org" target="_blank">kenneth@whitecape.org</a>><br>
<br>
One small comment below:<div><div class="h5"><br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
diff --git a/src/mesa/drivers/dri/intel/<u></u>intel_context.c b/src/mesa/drivers/dri/intel/<u></u>intel_context.c<br>
index 16a9887..fc3258b 100644<br>
--- a/src/mesa/drivers/dri/intel/<u></u>intel_context.c<br>
+++ b/src/mesa/drivers/dri/intel/<u></u>intel_context.c<br>
@@ -1251,17 +1251,34 @@ intel_process_dri2_buffer_<u></u>with_separate_stencil(struct intel_context *intel,<br>
<br>
int buffer_width;<br>
int buffer_height;<br>
+ int buffer_cpp = buffer->cpp;<br>
+ int buffer_pitch = buffer->pitch;<br>
if (buffer->attachment == __DRI_BUFFER_STENCIL) {<br>
- /* The stencil buffer has quirky pitch requirements. From Section<br>
- * 2.11.5.6.2.1 3DSTATE_STENCIL_BUFFER, field "Surface Pitch":<br>
- * The pitch must be set to 2x the value computed based on width, as<br>
- * the stencil buffer is stored with two rows interleaved.<br>
+ /* Stencil buffers use W tiling, a tiling format that the DRM functions<br>
+ * don't properly account for. Therefore, when we allocate a stencil<br>
+ * buffer that is private to Mesa (see intel_miptree_create), we round<br>
+ * the height and width up to the next multiple of the tile size (64x64)<br>
+ * and then ask DRM to allocate an untiled buffer. Consequently, the<br>
+ * height and the width stored in the stencil buffer's region structure<br>
+ * are always multiples of 64, even if the stencil buffer itself is<br>
+ * smaller.<br>
*<br>
- * To satisfy the pitch requirement, the X driver allocated the region<br>
- * with the following dimensions.<br>
+ * To avoid inconsistencies between how we represent private buffers and<br>
+ * buffers shared with the window system, round up the height and width<br>
+ * for window system buffers too.<br>
*/<br>
buffer_width = ALIGN(drawable->w, 64);<br>
- buffer_height = ALIGN(ALIGN(drawable->h, 2) / 2, 64);<br>
+ buffer_height = ALIGN(drawable->h, 64);<br>
+<br>
+ /* As of 4/6/2012, the X server lies and sends cpp and pitch values<br>
+ * that are two times too large for stencil buffers. Hopefully this<br>
+ * will be fixed someday, but for now detect the bug by checking if cpp<br>
+ * is 2, and fixing cpp and pitch if it is.<br>
+ */<br>
+ if (buffer_cpp == 2) {<br>
+ buffer_cpp = 1;<br>
+ buffer_pitch /= 2;<br>
+ }<br>
} else {<br>
buffer_width = drawable->w;<br>
buffer_height = drawable->h;<br>
</blockquote>
<br></div></div>
I was going to suggest saying "xserver 1.12 lies and sends..." rather than using a date...but...I don't think it's the X server that's really at fault. Isn't it xf86-video-intel (sometimes called the DDX)?<br>
<br>
So, maybe "As of 4/6/2012, the DDX lies and sends cpp and pitch values"?<br></blockquote><div><br>(After some discussion with Chad) how about: "xf86-video-intel versions 2.17.0 and earlier lie and send.... Hopefully this will be fixed in a future version of xf86-video-intel."<br>
</div><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
Sadly, I'm not sure how to fix that without breaking new DDX + old Mesa.<br>
</blockquote></div><br>Chad and I have had some discussion about this. We are hoping to add GetParam and SetParam messages to the DDX protocol, to allow Mesa and the DDX to exchange arbitrary integer parameters describing protocol/behavior options. GetParam() will return 0 when queried about a parameter that it does not recognize. The idea is that at startup, Mesa will query the DDX with GetParam to ask "are you capable of telling the truth about cpp and pitch of stencil buffers?" If it gets back a 1 (meaning yes), it will then send a SetParam message to say "henceforth, please tell the truth about cpp and pitch of stencil buffers." Not the prettiest thing in the world, I know, but it would allow old and new versions of the DDX and Mesa to be arbitrarily intermingled.<br>