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

GL_ARB_cl_event workarounds #854

Open
stgatilov opened this issue Dec 22, 2022 · 2 comments
Open

GL_ARB_cl_event workarounds #854

stgatilov opened this issue Dec 22, 2022 · 2 comments

Comments

@stgatilov
Copy link
Contributor

I work on an application which uses both OpenGL and OpenCL, and relies a bit on interop between them.
The worst part of it is: when application starts, it checks for GL/CL extension and runs a simple diagnostic to verify that it indeed works properly. Right now this totally breaks replaying for me, even though I'm not interested in debugging any parts which actually use OpenCL.

It is clear that apitrace does not create OpenCL context and ignores all OpenCL calls, so any data getting from CL into GL is wrong. But the problem is that one interop function is in OpenGL: it is glCreateSyncFromCLeventARB from extension GL_ARB_cl_event. Apitrace honestly records this call to the trace, but fully skips it during replay. As the result, replay lacks a sync object which is used in subsequent GL calls that apitrace does replay... and crashes.

I know this is not something supported by apitrace, but maybe it's possible to avoid this crash with a simple fix?

Some ideas:

  1. Replay glCreateSyncFromCLeventARB, but call glFenceSync instead of original function. That would create a sync object which can be waited for and deleted. I think it should be fine in any GL calls that application can use with it. I have a working prototype of this.
  2. In all calls accepting sync object, skip the call if sync object does not exist. It's a matter of checking the result of std::map access. But I'm afraid the number of such calls can be pretty large.
  3. Blacklist GL_ARB_cl_event during recording. If an application checks for availability of this extension, then it will skip the code path which uses it. If it does not... that's its own problem then.
@jrfonseca
Copy link
Member

Ideas 1 and 3 sound good to me. Idea 1 has the advantage of not interfering with recording. Feel free to polish it up and post a PR.

BTW, what about other kinds of objects shared between OpenCL and OpenGL APIs, like buffers/textures? I'd expect any application which uses these two APIs to share some objects like this.

For the record, Direct3D APIs has similar issues, not with OpenCL but with interprocess communication, and we generally try to compensate like in your idea 1. One thing d3dretrace does, for example, is to replace a shared resource with a checker board texture. Obviously it won't give the same output, but at least the output is recognizable, and above all, it's not undefined (ie, unitialized data.)

@stgatilov
Copy link
Contributor Author

stgatilov commented Jan 18, 2023

Here is PR with my implementation:

As far as I understand, sharing buffers and images is done from OpenCL side.
Using cl_khr_gl_sharing, you can "import" GL resources into CL, and then use CL to fill them with your data.
Since these are CL calls, apitrace does not record them, and thus cannot replay.

During replay, I suppose the objects won't get filled with real data and will be left with black/garbage contents instead.
To me, it looks like the best / close-to-best outcome.
Replacing with checkerboard would be nice, but I'm afraid without a GL call in recorded trace it can't be done.

For some reason, GL_ARB_cl_event is the only interop extension that is on GL side.

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