Qt5.1 + QPA + OpenCL-GL interop
I have written posts earlier related to this topic, but since those issues have been resolved, and the solution coming closer, I would like to open a topic that ultimately would serve people with a usable base class for an interop application.
I have gotten as far as hacking the example "here":http://qt-project.org/doc/qt-5.0/qtgui/openglwindow.html to a point where it has a base class InteropWindow that has similar guarantees as the OpenGLWindow in the example (init is ensured to be called before first resize or expose...) but it creates an interop capable OpenGL 3.3 context with an OpenCL context preferably with an OpenCL GPU device, or if it is not found, it falls back to CPU. CPU-interop works fine, however GPU-interop segfaults. It enumerates my GPU properly when looking for a matching device corresponding to the underlying QWindow, but it segfaults inside amdocl.dll every time it tries to use one of the interop resources.
Simply put, the application would do something ridiculous: it interrupts the openGL MVP multiplication in a way, that an OpenCL kernel does the Model matrix multiplication on the VBO, and then the resulting interop buffer is fed to OpenGL to finish with ViewProjection multiplication. This is nonsense, but should prove interop capability.
I want to ask, what could I do wrong. I believe the undocumented QPA part is correct, because there is an alternative way of obtaining these handles with Window functions, and it works just the same. Other interop applications work, this is the only one that doesn't.
I would like to ask for comments about the code. It can be found "here":https://skydrive.live.com/redir?resid=F942CBA43DCB6260!18652&authkey=!AHZAlRiylaSqmMU, and it is the QInterop_test project which holds source code for this app, and the VS2012 solution in the root directory. I use Qt5.1 alpha with -opengl desktop compile option.
I altered the OpenGL example project a bit, because I really don't like code that mixes init and render commands. I like to maximize performance of applications, and inside a render loop, I'd like only render commands, do all the resize functions in their respective places. The code is heavily documented, but I got a few questions beside interop too:
How to do proper text overlay in a base class like InteropWindow? It exposes a render(QPainter*) function to be implemented, but I cannot get it to work without wrecking the underlying OpenGL render.
How can one implement a faster FPS/IPS limiter? I use QElapsedTimer, and it reduces refresh rates from 500-1000 FPS down to 50 FPS at max, only because I'm using timers, although they never limit. (Default max FPS is humongous) Are QElapsedTimers really this slow?
All remarks are appreciated. Specially if someone knows the magic string for QPA to obtain a Display* plus GLXContext that is needed for linux interop.
Edit: since I'm not 100% sure whether the issue is Qt or interop related, I "linked":http://devgurus.amd.com/thread/166415 this post on the AMD OpenCL forum too.
Let me bump this problem again with a few questions that might solve the issue:
- Does Qt do any sort of thread magic that might break the interop? Such as render commands being moved to another thread, or anything like that.
- How can one mix OpenGL 3.3+ and QPainter? I know there are dozens of topics on this, all of them use QGLWidget which in itself is an obscure wrapper. None of my QPainter commands show on screen, no matter how I use begin/end.
- Would it make my life easier if I used seperate contexts for QPainter and my native render? Then I could use 3.3 Core context, because right now Core Context does not allow to build QPainter shaders, so I'm restricted to Compatibility Profile contexts.
- Why does window.format() never equal to context.format() when ALL queryable values are identical. I got code like this, and output as follows:
@if(m_gl_context->format() != requestedFormat())
qWarning("InteropWindow: The requested window format and the acquired context format mismatch");
InteropWindow: The requested window format and the acquired context format mismatch
InteropWindow: Property name | Requested | Acquired
InteropWindow: RenderableType | OpenGL | OpenGL
InteropWindow: ContextProfile | Compat | Compat
InteropWindow: SwapBehavior | Double | Double
InteropWindow: OpenGL version | 3.3 | 3.3
InteropWindow: R.G.B.A bits | 18.104.22.168 | 22.214.171.124
InteropWindow: Depth bits | 24 | 24
InteropWindow: Stencil bits | 8 | 8
InteropWindow: Stereo | 0 | 0
Since there was not much activity here, I would like to link again the "AMD forum":http://devgurus.amd.com/message/1297051#1297051, where I have posted my progress of debugging the issue.
Some reflection on the format mismatch would be appreciated too.
Thanks in advance.
Has anyone else went through qt-labs/opencl project to make it compile under Qt 5.1.1?
I am unfamiliar with the development environment - but I hacked some fixes in to get all demo's and examples running in Qt 5.1.... I would LOVE for someone to look at what I did and tell me how I could have done it right.
Where do I post stuff like this request>?