I have created a small OpenGL 3.3 (Core) program using freeglut. The whole geometry is two boxes and one plane with some textures. I can move around like in an FPS and that's it. The problem is I face a big slow down of fps when I make my window large (i.e. above 1920x1080). I have monitors GPU usage when in full-screen and it shows GPU load of nearly 100% and Memory Controller load of ~85%. When at 600x600, these numbers are at about 45%, my CPU is also at full load. I use deferred rendering at the moment but even when forward rendering, the slow down was nearly as severe. I can't imagine my GPU is not powerful enough for something this simple when I play many games at 1080p (I have a GeForce GT 120M btw). Below are my shaders,

First Pass

#version 330 core

uniform mat4 ModelViewMatrix;
uniform mat3 NormalMatrix;
uniform mat4 MVPMatrix;

uniform float scale;

layout(location = 0) in vec3 in_Position;
layout(location = 1) in vec3 in_Normal;
layout(location = 2) in vec2 in_TexCoord;

smooth out vec3 pass_Normal;
smooth out vec3 pass_Position;
smooth out vec2 TexCoord;

void main(void){

    pass_Position = (ModelViewMatrix * vec4(scale * in_Position, 1.0)).xyz;
    pass_Normal = NormalMatrix * in_Normal; 
    TexCoord = in_TexCoord;

    gl_Position = MVPMatrix * vec4(scale * in_Position, 1.0);

#version 330 core

uniform sampler2D inSampler;

smooth in vec3 pass_Normal;
smooth in vec3 pass_Position;
smooth in vec2 TexCoord;

layout(location = 0) out vec3 outPosition;
layout(location = 1) out vec3 outDiffuse;
layout(location = 2) out vec3 outNormal;

void main(void){
    outPosition = pass_Position;
    outDiffuse = texture(inSampler, TexCoord).xyz;
    outNormal = pass_Normal;

Second Pass

#version 330 core

uniform float scale;

layout(location = 0) in vec3 in_Position;

void main(void){
    gl_Position = mat4(1.0) * vec4(scale * in_Position, 1.0);

#version 330 core

struct Light{
    vec3 direction;

uniform ivec2 ScreenSize;
uniform Light light;

uniform sampler2D PositionMap;
uniform sampler2D ColorMap;
uniform sampler2D NormalMap;

out vec4 out_Color;

vec2 CalcTexCoord(void){
    return gl_FragCoord.xy / ScreenSize;

vec4 CalcLight(vec3 position, vec3 normal){

    vec4 DiffuseColor = vec4(0.0);
    vec4 SpecularColor = vec4(0.0);

    vec3 light_Direction = -normalize(light.direction);
    float diffuse = max(0.0, dot(normal, light_Direction));

    if(diffuse > 0.0){
        DiffuseColor = diffuse * vec4(1.0);

        vec3 camera_Direction = normalize(-position);
        vec3 half_vector = normalize(camera_Direction + light_Direction);

        float specular = max(0.0, dot(normal, half_vector));
        float fspecular = pow(specular, 128.0);
        SpecularColor = fspecular * vec4(1.0);
    return DiffuseColor + SpecularColor + vec4(0.1);

void main(void){

    vec2 TexCoord = CalcTexCoord();
    vec3 Position = texture(PositionMap, TexCoord).xyz;
    vec3 Color = texture(ColorMap, TexCoord).xyz;
    vec3 Normal = normalize(texture(NormalMap, TexCoord).xyz);

    out_Color = vec4(Color, 1.0) * CalcLight(Position, Normal);

Is it normal for the GPU to be used that much under the described circumstances? Is it due to poor performance of freeglut?

I understand that the problem could be specific to my code, but I can't paste the whole code here, if you need more info, please tell me.

  • 3
    \$\begingroup\$ An odd thought I have is can you also monitor your GPU temperatures? I ran across a situation once upon a time where the main loop was running as fast as possible with no limiter on it and the video card would overheat and underclock itself massively to save itself from burning out. \$\endgroup\$ Jun 14 '12 at 6:33
  • \$\begingroup\$ No, the temepratures only rise by about 5C compared to idle and the clocks remain steady too. I have tried both with limiting the game loop and without, with no differences. \$\endgroup\$ Jun 14 '12 at 13:02
  • \$\begingroup\$ @PatrickHughes I ran into a similar problem in the past, except it was my CPU that was the culprit, not the GPU. Once I replaced the old, dry thermal paste the problem went away. \$\endgroup\$ Jul 14 '12 at 12:26

The problem is that the framerate is too low given the simplicity of the rendering job.

Simplicity? You're doing deferred rendering.

That's not simple.

You're obviously fillrate-limited (as part of the point of deferred rendering is to be fillrate-limited). And your GeForce GT 120M only has 32 shaders. Which is good for a mobile chip, but pretty poor for serious work.

For every additional light, you're walking the entire screen and doing lighting on every point. Each light will require executing your shader over 2 million times.

If you have a lot of lights (you didn't say how many, which would be useful information to provide), I would suggest packing multiple lighting computations into a single shader invocation. That is, have variations of your shader for 1 light, 5, 10, and 25 if you have that many. This way, if you have 38 lights, you only need to run your full-screen lighting pass 5 times.

  • \$\begingroup\$ Hi, I wasn't watching this site regularly lately, so I didn't respond right away. I only use one directional light, so it takes up the whole screen. I had done some timings on shaders I used, which made me realize that I am gpu bound indeed. I don't have the data anymore but I'll come back with it and try to put some data from my forward renderer too, which also has shadow mapping, unlike my deferred renderer and barely stays at 60fps at high resolution. \$\endgroup\$ Jul 17 '12 at 0:11

High GPU usage is not necessarily a bad thing and not necessarily performance-related. It means that you've got a hardware resource that is actually being used to do useful work for you, instead of just sitting there idle. It is perfectly normal to see high GPU usage with a game-loop and in cases where you're not CPU-bound. If that is not what you want then you can limit the framerate by e.g. enabling vsync.

  • \$\begingroup\$ The problem is that the framerate is too low given the simplicity of the rendering job. \$\endgroup\$ Jun 14 '12 at 13:00
  • 2
    \$\begingroup\$ It would help a lot if you gave some actual figures here. Right now the only info we have to go on is load percentages, which are in no way indicative of performance. What framerate do you get at low-res? What framerate do you get at high-res? You seem to have derived a conclusion that your performance drop is entirely related to the GPU load, but that's not always the case (you may often even see performance go up as GPU load increases) so you have invalid data to begin with. \$\endgroup\$ Jul 15 '12 at 0:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.