<html>
    <head>
      <base href="https://bugs.freedesktop.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_ASSIGNED "
   title="ASSIGNED - eglMakeCurrent does not always ensure dri_drawable->update_drawable_info has been called for a new EGLSurface if another has been created and destroyed first"
   href="https://bugs.freedesktop.org/show_bug.cgi?id=106126">106126</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>eglMakeCurrent does not always ensure dri_drawable->update_drawable_info has been called for a new EGLSurface if another has been created and destroyed first
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>Mesa
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>18.0
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>x86-64 (AMD64)
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux (All)
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>ASSIGNED
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>major
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>medium
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Drivers/Gallium/llvmpipe
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>mesa-dev@lists.freedesktop.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>johan.helsing@qt.io
          </td>
        </tr>

        <tr>
          <th>QA Contact</th>
          <td>mesa-dev@lists.freedesktop.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=138907" name="attach_138907" title="Apitrace of the failing test">attachment 138907</a> <a href="attachment.cgi?id=138907&action=edit" title="Apitrace of the failing test">[details]</a></span>
Apitrace of the failing test

This is pretty timing sensitive, and I haven't been able to reproduce on
anything except a Qt unit test running against a headless Weston
compositor.

Start Weston with: weston --backend=headless-backend.so -i 0

Qt unit test: <a href="https://codereview.qt-project.org/#/c/225522/2//ALL">https://codereview.qt-project.org/#/c/225522/2//ALL</a>

The symptom is that glReadPixels will only return 1 pixel instead of 16
which is the surface size.

Why it fails:

In the test, a temporary EGLSurface will be created as part of the window
setup. After that surface has been destroyed, the real window surface is
created. When that happens the malloc in driCreateNewDrawable may return
the same address the first surface's drawable had. Consequently, when
dri_make_current later tries to determine if it should update the
texture_stamp it compares the surface's drawable pointer against the
drawable in the last call to dri_make_current and assumes it's the same
surface (which it isn't).

When texture_stamp is left unset then dri_st_framebuffer_validate thinks it
has already called update_drawable_info for that drawable, which is why, in
the test above, the size of the surface is not updated to match the Wayland
window and glReadPixels later is only going to return only one pixel.

The solution is to clear the dangling pointer to the destroyed drawable,
dri_context::dPriv. I've confirmed that this fixes the flakiness of my test
and will post a patch on the mailing list shortly.

I've tagged this bug with Drivers/Gallium/llvmpipe, but it really affects all
gallium dri drivers (and I've reproduced the issue with softpipe as well).

Related bug report in Qt: <a href="https://bugreports.qt.io/browse/QTBUG-67678">https://bugreports.qt.io/browse/QTBUG-67678</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>