<html>
    <head>
      <base href="https://bugs.freedesktop.org/">
    </head>
    <body>
      <p>
        <div>
            <b><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Textures are blocky in Crusader Kings 2"
   href="https://bugs.freedesktop.org/show_bug.cgi?id=91683#c4">Comment # 4</a>
              on <a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Textures are blocky in Crusader Kings 2"
   href="https://bugs.freedesktop.org/show_bug.cgi?id=91683">bug 91683</a>
              from <span class="vcard"><a class="email" href="mailto:jakub+mesa@streamcomputing.eu" title="Jakub Szuppe <jakub+mesa@streamcomputing.eu>"> <span class="fn">Jakub Szuppe</span></a>
</span></b>
        <pre>Tested hardware: Intel(R) HD Graphics 530 (Skylake GT2)

Mesa version: Mesa 17.1.0-devel (git-a2db9f9) (Yes, old, but we did this when
it was the newest commit.)

We confirmed error on:  
* Mesa DRI Intel(R) HD Graphics 530 (Skylake GT2) (Intel DRI)
* Gallium 0.4 on llvmpipe (LLVM 3.8, 256 bits)

It looks ok on NVIDIA drivers.

We found when rendered image stops looking OK:
In frame 940 up to the call 2255268  (including) image looks ok, starting with
next call - it looks "blocky". It seemed that program 163 does something bad.

We think that it's a bug in the shader code (vertex shader 165, program 163).

Commenting out VertexOut.uv += vHalfPixelOffset_Axis.xy; (line 405) in vertex
shader 165 (program 163) in call 1848358, fixes the problem. Setting the offset
to 0 also works.

In our opinion, this offset (vHalfPixelOffset) should be 0.0 in OpenGL, and
it's probably a legacy workaround for D3D9.

Full explanation:

Comparing to OpenGL and D3D10+, D3D9 has a different behaviour:

<a href="http://drilian.com/2008/11/25/understanding-half-pixel-and-half-texel-offsets/">http://drilian.com/2008/11/25/understanding-half-pixel-and-half-texel-offsets/</a>
<a href="http://www.asawicki.info/news_1516_half-pixel_offset_in_directx_11.html">http://www.asawicki.info/news_1516_half-pixel_offset_in_directx_11.html</a>
<a href="https://msdn.microsoft.com/en-us/library/windows/desktop/bb219690.aspx">https://msdn.microsoft.com/en-us/library/windows/desktop/bb219690.aspx</a>
<a href="https://msdn.microsoft.com/en-us/library/cc308049(VS.85).aspx">https://msdn.microsoft.com/en-us/library/cc308049(VS.85).aspx</a> (the note in the
beginning)

In this case we have 1 triangle with coordinates:

[3, -1], [-1, -1], [-1, 3]
VertexOut.uv = ( VertexIn.position + 1.0f ) * 0.5f; will give us texture
coordinates:

[2, 0], [0, 0], [0, 2]
After clipping this triangle by a viewport we will get a full-screen rectangle:

[-1, -1], [1, 1] - positions of its corners in screen space
[0, 0], [1, 1] - uv
In OpenGL every fragment will already have texture coordinates perfectly mapped
to centers of texels (0.5, 1.5, 2.5 and so on).

Adding the vHalfPixelOffset will return values right between texels (i.e. on
their borders), and considering that there is a small precision loss, the
values will be, for example, 1.0, 1.99999, 2.0, 3.00001, 4.0, 4.9999. 

GL_NEAREST is a simple flooring operation (because it returns the nearest texel
using its center), so in the example above the texels will be 1, 1, 2, 3, 4, 4.

Radeon on Mesa has no visible artefacts but all resulting pixels are moved by
one for x and y (comparing to the source texture). Maybe it returns something
like 1.0001, 2.00001, 3.0001... (i.e. always equal to or a bit more than an
integer), we are not sure. We did not checke how Radeon on Catalyst works.

Kind regards,
Stream HPC Team
<a href="https://streamhpc.com/">https://streamhpc.com/</a></pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are the QA Contact for the bug.</li>
          <li>You are the assignee for the bug.</li>
      </ul>
    </body>
</html>