Trouble driving a 240 Hz monitor through vsync reliably

#1

I’m using OpenGL to display a pattern on a 240 Hz screen with Nvidia GTX 1070 1582 MHz graphics card, and I’m encountering some problems with frame dropping/ skipping. To simplify the problem, I created a program that change the background color of the screen between black and white for every frame. The behavior that I observed is this:

  • During the first 11 seconds, 2-4 small glitches (a frame dropped or a frame skipped) will occur
  • At around 30 seconds, a “big glitch” occurs. This is either a white or black flash that span several frames.
  • After that, the black-white-black transitions perfectly every frame (the longest test I’ve run is 5 mins).

I’m not sure why the errors occur in a systematic manner like that. The simple program ensured that graphics rendering time is very fast, and the gpu should be fast enough to copy pixels to the screen.

Any ideas on what might be causing this.?

Code of the simple program:



int main(void)
{
	// Initialise GLFW
	if (!glfwInit())
	{
		fprintf(stderr, "Failed to initialize GLFW
");
		getchar();
		return -1;
	}
 
	glfwWindowHint(GLFW_SAMPLES, 4);
	glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
	glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
	glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // To make MacOS happy; should not be needed
	glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
 
	int count;
 
	GLFWmonitor* primaryMonitor = glfwGetPrimaryMonitor();
	const GLFWvidmode* mode = glfwGetVideoMode(primaryMonitor);
 
	// Open a window and create its OpenGL context
	window = glfwCreateWindow(mode->width, mode->height, "Playground", primaryMonitor, NULL);
 
	if (window == NULL) {
		fprintf(stderr, "Failed to open GLFW window. If you have an Intel GPU, they are not 3.3 compatible. Try the 2.1 version of the tutorials.
");
		getchar();
		glfwTerminate();
		return -1;
	}
	glfwMakeContextCurrent(window);
 
	// Initialize GLEW
	glewExperimental = true; // Needed for core profile
	if (glewInit() != GLEW_OK) {
		fprintf(stderr, "Failed to initialize GLEW
");
		getchar();
		glfwTerminate();
		return -1;
	}
 
	// Ensure we can capture the escape key being pressed below
	glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE);
 
	// Enable VSync
	glfwSwapInterval(1);
	float grayValueNormal1 = 0.0f;
	do {
		grayValueNormal1 = 1 - grayValueNormal1;
 
		// Alternate the screen from black to white to black every frame
		glClearColor(grayValueNormal1, grayValueNormal1, grayValueNormal1, 0.0f);
                glClear(GL_COLOR_BUFFER_BIT);
		glfwSwapBuffers(window);
 
		glfwPollEvents();
 
	} // Check if the ESC key was pressed or the window was closed
	while (glfwGetKey(window, GLFW_KEY_ESCAPE) != GLFW_PRESS &&
		glfwWindowShouldClose(window) == 0);
 
	// Close OpenGL window and terminate GLFW
	glfwTerminate();
 
	return 0;
}

#2

[QUOTE=tobielolness;1292525]+ During the first 11 seconds, 2-4 small glitches (a frame dropped or a frame skipped) will occur

  • At around 30 seconds, a “big glitch” occurs. This is either a white or black flash that span several frames.
  • After that, the black-white-black transitions perfectly every frame (the longest test I’ve run is 5 mins).

I’m not sure why the errors occur in a systematic manner like that. The simple program ensured that graphics rendering time is very fast, and the gpu should be fast enough to copy pixels to the screen.

Any ideas on what might be causing this.?[/QUOTE]

Welcome to Real-time Graphics!

Not off-hand, no. I would recommend using a profiling tool to try and catch these frame spikes in-the-act. Nail down in which call(s) all the time appears to be spent. If it looks like it’s down in the GL driver, tools like Insight and GPUView can be useful. Before you go there though, make sure that your app’s threads are being consistently scheduled for CPU time. If not, you should be able to determine why it’s being preempted.

In these cases, it’s very useful to disable all non-essential processes/services on the machine. And definitely disable any performance-wasting compositor on your system if you can, if one is running. You want to refine this so that you have as direct a path to the GPU as possible with no other processes coming along and screwing that up. On some systems/OSs, you want to target Full-Screen Exclusive mode here.

I’d also suggest that you start getting this solid at 60Hz first. Then go to 120Hz. Then 240Hz. If you can’t make 60Hz (the common case), you won’t be able to make anything higher.

What GPU driver and OS are you targetting?