Bug 31194 - The mesa meta save/restore code doesn't ref the current GLSL program
Summary: The mesa meta save/restore code doesn't ref the current GLSL program
Alias: None
Product: Mesa
Classification: Unclassified
Component: Drivers/DRI/i965 (show other bugs)
Version: git
Hardware: Other All
: medium normal
Assignee: Eric Anholt
QA Contact:
Depends on:
Reported: 2010-10-28 05:59 UTC by Neil Roberts
Modified: 2010-10-29 11:40 UTC (History)
0 users

See Also:
i915 platform:
i915 features:

Example showing the bug (2.95 KB, text/x-csrc)
2010-10-28 06:00 UTC, Neil Roberts

Description Neil Roberts 2010-10-28 05:59:08 UTC
The documentation for glDeleteProgram says that if the program to be deleted is currently bound then it won't actually be deleted until another program is selected. The mesa meta code tries to save and restore most of the GL state before using GL calls to do some operations including saving the GL program. However it just stores the GL program number and then calls glUseProgram(0) to disable it. If glDeleteProgram was already called on this program then this will end up freeing the program. When the meta code later tries to restore the state glUseProgram will throw a GL error because the saved program number is no longer valid.

Attached is an example program demonstrating the bug. It creates a fragment shader which just sets the fragment color to green. It makes the program current and then immediately deletes it. It then draws two quads while the program is active but it calls glDrawPixels in between. glDrawPixels ends up using the meta save/restore code which causes the program to be deleted so the second quad ends up red.
Comment 1 Neil Roberts 2010-10-28 06:00:28 UTC
Created attachment 39843 [details]
Example showing the bug
Comment 2 Eric Anholt 2010-10-29 11:40:22 UTC
Thanks for the testcase!  I converted it into a piglit test:

commit 782738e3cc4a6bb032a94f3cf7a2286f73d6a210
Author: Eric Anholt <eric@anholt.net>
Date:   Fri Oct 29 11:06:27 2010 -0700

    useprogram-refcount-1: New test for a bug in Mesa metaops.

and fixed the bug:

commit a974949f3b586eee2bc8d6d97d3adb71796fe167
Author: Eric Anholt <eric@anholt.net>
Date:   Fri Oct 29 11:28:38 2010 -0700

    mesa: Make metaops use program refcounts instead of names.
    Fixes failure on restoring state when the program was active but
    deleted, and the name no longer exists.
    Bug #31194

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.