Why does no GPU debugger work properly with LWJGL?

Started by asyx, August 15, 2016, 01:42:28

Previous topic - Next topic

asyx

Hi!

I tried to debug an LWJGL application with a GPU debugger.

CodeXL ignores most calls (breakpoint didn't hit on glCreateShader) and I only see stuff like the front and back buffer if I pause the application manually. No VBOs, no shaders or anything like that.

RenderDoc just does nothing.

This doesn't even make sense. LWJGL is only a wrapper... why does no debugger actually work?

baldurk

Hey, about RenderDoc. I am very unfamiliar with java so maybe my testing wasn't right (I had to grab some random lwjgl demos and try to get them running in some IDE I downloaded), but I was able to get it working normally.

By default it seems like the glfw is configured to create a legacy context, so the RenderDoc overlay appears saying "Context not created via CreateContextAttribs. Capturing disabled. Only OpenGL 3.2+ contexts are supported". If I changed glfw to create a 3.2 core context, I was able to capture and replay successfully (although the sample I chose didn't seem to update well to 3.2, it seemed at least normal.

What trouble are you running into?

asyx

I don't even get the overlay. There's just nothing. So I can't even check what RenderDoc would actually give (just like CodeXL only gives me front, back and depth buffer and stuff like that). It's literally reacting like it does if I use a program written in C++ except that I can't capture a frame due to the missing overlay.

I do create a 4.4 core profile context.

GL_VENDOR, GL_RENDERER, GL_VERSION and GL_SHADING_LANGUAGE_VERSION top to bottom

NVIDIA Corporation
GeForce GTX 860M/PCIe/SSE2
4.4.0 NVIDIA 365.10
4.40 NVIDIA via Cg compiler

baldurk

Are you able to share a program that shows the problem? (Ideally binaries for me, but I can probably figure out how to build something if it's just source :) ).

How did you invoke the program - when I configured it I set the executable as java.exe and then put command line options taken from the IDE I was using to be able to invoke the specific program.

asyx

Sure

https://owncloud.asyxx.eu/s/trDWGTaSn9jOdgc

Start with

java -Djava.library.path=natives -jar OpenGLTest-1.0-SNAPSHOT.jar


Requires OpenGL 4.4. Let me know if that's a problem.

Oh and I'm pretty much doing the same. java.exe for the executable, the target folder for the working directory and then the arguments I've posted above.

baldurk

I think I have found the culprit. When stepping through, it seems like the dlls in the natives folder are skipping past my library hooks and going directly to the 'real' functions in opengl32.dll, kernel32.dll, gdi32.dll which is why there's no overlay that shows up. I believe this is because they have been compressed with the executable/dll compressor upx. I don't know how it works exactly but I think it removes and breaks some of the dll import data that I need for proper hooking.

Judging by the release notes in this release https://github.com/LWJGL/lwjgl3/releases/tag/3.0.0 it says "Stopped using UPX compression for binaries. This eliminates various integration issues and virus scanning false-positives." so I think this might fix your problem. I tried to drop the newer release into your program but it seems like it's not a drop-in replacement as I got java errors.

I'm not sure if this version is more or less stable than 3.0.0b that you're using (does that mean 3.0.0 beta? if so maybe it is more stable), but that might explain not only why RenderDoc was getting confused but also perhaps other debuggers.

I will need to investigate more to see if I can find a way to fix or at least reliably detect this compression, I'm actually not sure if either is possible.

asyx

I'm not sure what the "b" exactly means but it's the newest version on maven central :/

But there's an awful lot of fun stuff in there. Especially the Swing integration since I'm looking for a nice way to create tools for my game and rendering to a Swing GUI widget is perfect for that.

I'll take a look at the release version. If everything fails I just install it in a local repository. Thanks for investigating!

Edit: It's NOT the newest version in maven... Netbeans just hates me.

Edit2: The java error was from the changes to glfwWindowShouldClose which used to return int and now returns boolean.

Edit3: Ok. I can run it, I get the overlay, but RenderDoc doesn't let me capture frames. It says that it failed for "unknown reasons".

baldurk

Great! glad it's working for you now.

I think I've seen that happen if the frame is empty (no drawing or other API events). There might be an off-by-one error in there, so if you only have e.g. a glClear call try adding in another couple to see if it works then.

spasi

Sorry about the Maven versioning, it is my bad. It indeed thinks that 3.0.0b is newer than 3.0.0, but that's not the case.

Normally in a project that starts from scratch, you'd have a few 0.x builds followed by the 1.0 release. Since we started at 3 and 3 is completely different from 2, I added the 'a' (alpha) and 'b' (beta) suffixes to mark those builds as "pre-release quality" builds of 3.0.0. It was a bad idea after all, or maybe I should have added a 'r' (release) suffix to the final build. Anyway, 3.0.1 will be released soon, so hopefully it won't be an issue anymore.

On topic: There shouldn't be any issues with GPU debuggers and LWJGL. If you encounter something weird, please post here and I'll have it fixed asap. Also, if you need to override the OpenGL library that LWJGL loads, see the Configuration.OPENGL_LIBRARY_NAME option (or the -Dorg.lwjgl.opengl.libname system property).

asyx

Ok I will. I think it works now. My little demo never clears the color buffer so that might have throws off the debugger.

However, now it works. Even if I also open a JavaFX window which throws a D3D11 context in there.