Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replacement of shader via glDetachShader + glAttachShader leads to link error #879

Open
10110111 opened this issue Jul 26, 2023 · 2 comments

Comments

@10110111
Copy link
Contributor

10110111 commented Jul 26, 2023

An OpenGL program (on Ubuntu 20.04 x86_64, Intel UHD Graphics 620) replaces a shader of a linked program by detaching an old shader and attaching a new one. When I apitrace it and then glretrace, things look correct unless I enable state dumping. If I enable state dumping, glLinkProgram fails after attaching the new shader in place of the old one with the following error:

9090 @0 glLinkProgram(program = 45)
9090: warning: link failed
9090: warning: error: function `main' is multiply defined

The reason for this behavior appears to be due to 5b14394. If I revert it, these unexpected errors no longer happen.

With the following trace (8.6MiB zipped) you can reproduce the problem using the following command:

glretrace -D 9090 stellarium.trace

stellarium.trace.zip

@jrfonseca
Copy link
Member

Ah.... perhaps the !retrace::dumpingState condition should be replaced with not dumping state and not replacing?

Or perhaps shader replacing should ensure all shader sources are deleted before adding (at least when dumping state)?

@10110111
Copy link
Contributor Author

The problem here is not in deletion, but rather in detaching. If you try to attach a shader with main() to a program that already has such a shader attached, you get multiple definition error. So I guess glDetachShader should be left alone.

My current workaround looks as follows, and I don't know of any reason how it could break (maybe you do?).

diff --git a/retrace/glretrace.py b/retrace/glretrace.py
index 19e994d3..4a891355 100644
--- a/retrace/glretrace.py
+++ b/retrace/glretrace.py
@@ -421,10 +421,6 @@ class GlRetracer(Retracer):
             print(r'    } else {')
             Retracer.invokeFunction(self, function)
             print(r'    }')
-        elif function.name in ('glDetachShader', 'glDetachObjectARB'):
-            print(r'    if (!retrace::dumpingState) {')
-            Retracer.invokeFunction(self, function)
-            print(r'    }')
         elif function.name == 'glClientWaitSync':
             print(r'    _result = glretrace::clientWaitSync(call, sync, flags, timeout);')
             print(r'    (void)_result;')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants