On 22 May 2012 12:12, Eric Anholt <span dir="ltr">&lt;<a href="mailto:eric@anholt.net" target="_blank">eric@anholt.net</a>&gt;</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 Fri, 11 May 2012 11:03:44 -0700, Paul Berry &lt;<a href="mailto:stereotype441@gmail.com">stereotype441@gmail.com</a>&gt; wrote:<br>
&gt; Gen6 MSAA buffers (and Gen7 MSAA depth/stencil buffers) interleave<br>
&gt; MSAA samples in a complex pattern that repeats every 2x2 pixel block.<br>
&gt; Therefore, when allocating an MSAA buffer, we need to make sure to<br>
&gt; allocate an integer number of 2x2 blocks; if we don&#39;t, then some of<br>
&gt; the samples in the last row and column will be cut off.<br>
&gt;<br>
&gt; Fixes piglit tests &quot;EXT_framebuffer_multisample/unaligned-blit {2,4}<br>
&gt; color msaa&quot; on i965/Gen6.<br>
<br>
</div>Given that you had to go through this two with us, I think the<br>
following comment would help here:<br>
<br>
/* In the Sandy Bridge PRM, volume 4, part 1, page 31, it says:<br>
 *<br>
 *     &quot;Any of the other messages (sample*, LOD, load4) used with a<br>
 *      (4x) multisampled surface will in-effect sample a surface with<br>
 *      double the height and width as that indicated in the surface<br>
 *      state. Each pixel position on the original-sized surface is<br>
 *      replaced with a 2x2 of samples with the following arrangement:<br>
 *<br>
 *         sample 0 sample 2<br>
 *         sample 1 sample 3&quot;<br>
 *<br>
 * You would read this as saying that the layout in memory of a 2x2<br>
 * pixel area for (x,y,sample) is:<br>
 *<br>
 *      (0,0,0) (0,0,2)   (1,0,0) (1,0,2)<br>
 *      (0,0,1) (0,0,3)   (1,0,1) (1,0,3)<br>
 *<br>
 *      (0,1,0) (0,1,2)   (1,1,0) (1,1,2)<br>
 *      (0,1,1) (0,1,3)   (1,1,1) (1,1,3)<br>
 *<br>
 * That is a lie.  The actual layout is:<br>
 *<br>
 *      (0,0,0) (1,0,0)   (0,0,2) (1,0,2)<br>
 *      (0,1,0) (1,1,0)   (0,1,2) (1,1,2)<br>
 *<br>
 *      (0,0,1) (1,0,1)   (0,0,3) (1,0,3)<br>
 *      (0,1,1) (1,1,1)   (0,1,3) (1,1,3)<br>
 *<br>
 * As a result, when calculating the size of our 4-sample buffer for<br>
 * an odd width or height, we have to align before scaling up because<br>
 * sample 3 is in that bottom right 2x2 block.<br>
 */<br>
<br>
I may have swapped pixels (0,1) and (1,0)&#39;s position in the &quot;actual<br>
layout&quot; blocks, though.<br>
</blockquote></div><br>Thanks for the comment.  On further rereading, I&#39;ve realized that the documentation is technically *not* lying, because it&#39;s not making any claims about the layout of samples in memory--it&#39;s just telling us how the X and Y coordinates are interpreted when sampling from an MSAA buffer.  But it&#39;s extremely misleading because in the absence of any other documentation, it&#39;s natural to assume that samples are laid out in this fashion in memory, and that&#39;s not the case.<br>
<br>With that accounted for, and correcting a minor error in the actual layout, I&#39;ve changed the comment to this:<br><br>   /* Adjust width/height for MSAA.<br>    *<br>    * In the Sandy Bridge PRM, volume 4, part 1, page 31, it says:<br>
    *<br>    *     &quot;Any of the other messages (sample*, LOD, load4) used with a<br>    *      (4x) multisampled surface will in-effect sample a surface with<br>    *      double the height and width as that indicated in the surface<br>
    *      state. Each pixel position on the original-sized surface is<br>    *      replaced with a 2x2 of samples with the following arrangement:<br>    *<br>    *         sample 0 sample 2<br>    *         sample 1 sample 3&quot;<br>
    *<br>    * Thus, when sampling from a multisampled texture, it behaves as though<br>    * the layout in memory for (x,y,sample) is:<br>    *<br>    *      (0,0,0) (0,0,2)   (1,0,0) (1,0,2)<br>    *      (0,0,1) (0,0,3)   (1,0,1) (1,0,3)<br>
    *<br>    *      (0,1,0) (0,1,2)   (1,1,0) (1,1,2)<br>    *      (0,1,1) (0,1,3)   (1,1,1) (1,1,3)<br>    *<br>    * However, the actual layout of multisampled data in memory is:<br>    *<br>    *      (0,0,0) (1,0,0)   (0,0,1) (1,0,1)<br>
    *      (0,1,0) (1,1,0)   (0,1,1) (1,1,1)<br>    *<br>    *      (0,0,2) (1,0,2)   (0,0,3) (1,0,3)<br>    *      (0,1,2) (1,1,2)   (0,1,3) (1,1,3)<br>    *<br>    * This pattern repeats for each 2x2 pixel block.<br>    *<br>
    * As a result, when calculating the size of our 4-sample buffer for<br>    * an odd width or height, we have to align before scaling up because<br>    * sample 3 is in that bottom right 2x2 block.<br>    */<br><br>