• 9
• 9
• 11
• 13
• 9

# Why is the Fixed Function Pipeline performing better than using Vertex Buffer Objects?

This topic is 759 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I am in the process prototyping some ideas and learning some graphics programming. I have 2 separate renderers set up in my project, one uses the Fixed Function Pipeline and one uses VBOs and Shaders to do my 2D rendering. I am having a significant slow down and jittering with the one using VBOs. I notice it will render a few frames pause for a few frames then continue to render. I have attached some source code if someone who is experienced can take a quick look. I included my shaders and both renderers (Render_SDL_GL.cc and Render_SDL_GL_FFP.cc). Both are interchangeable so you can #include one or the other without having to make any changes to anything. I have also included an image of my performance graph I draw and the frame time differences. Also I would like to add on if you see something else wrong with what I am doing please do let me know. At request I can upload the entire source.

NOTE: In my graph the longer and more red each bar is the higher the frame time. The red spike in the graph is me grabbing the window to move it.

The functions of interest are:

* DebugDrawTexturedRectangle: Draws a rectangle with a texture

* DebugDrawFilledRectangle: Draws a rectangle filled with a color you specify

If there is anything I need to explain or add on to make it easier for the reader please do let me know.

Link to source can be found here: https://drive.google.com/file/d/0B2hFWVdJkDXgMmYxTjdoY1BneGs/view?usp=sharing

##### Share on other sites

Eh? For 60 FPS, you have a budget of 16.67ms per frame. To go from 0.00733ms to 0.0177ms per frame is an increase from 0.044% to 0.106% of your total budget. While it’s a 25x increase, it’s still only < 0.1% of your total budget and is therefore not worth worrying about.

That aside, you are also making too many trips to the GPU. Rendering 1000 individual quads is many times more costly than making one individual call to draw 1000 quads. Also, the gameloop is missing from your code, if you’re having jittering, the gameloop is the next place I’d suspect.

EDIT:
To answer your question, “why is the Fixed Function Pipeline performing better than using Vertex Buffer Objects”: It is because you are doing it wrong.

I am aware I was doing it wrong, I just wanted to know why it was wrong and how to fix it. I suspect, if the game loop was responsible for the jittering it would be jittering with both renderers and not just the one.

##### Share on other sites

No. To perform benchmarks, you have to perform realistic benchmarks. Drivers perform workload analysis and switch behavior according to detected patterns. Your workload does not even begin being a realistic load and most of your components will likely be sleeping. In those conditions simple delays in buffer transfers will change your perf in a way you have no control about.

##### Share on other sites

No. To perform benchmarks, you have to perform realistic benchmarks. Drivers perform workload analysis and switch behavior according to detected patterns. Your workload does not even begin being a realistic load and most of your components will likely be sleeping. In those conditions simple delays in buffer transfers will change your perf in a way you have no control about.

Maybe I should mention this isn't about a jitter in the benchmark. This is a visual jitter where I see movement on the screen jitter. And the jittering only occurs with the code that uses VBOs.

##### Share on other sites

First, put your code in a more accessible storage such as PasteBin.

Secondly, Performance issues may relate to two things: Cpu and memory (which ironicly are the only thing that matter for us right now).

CPU- Probably not since you are using the same code (I cant see any code so if you have any changes to how you handle your data then it may relate).

Memory- a better place to start investigating.

You need to determine how is your memory allocated, how and when it is transfered to the GPU and why.. (Drawing calls).

It is easy to misuse VBOs or even calls to the draw methods.

##### Share on other sites

It is easy to misuse VBOs or even calls to the draw methods.

This, basically.

VBOs are not a magic bullet that you just implement and instantly get improved performance everywhere.  Particularly if you update them at runtime, and particularly with OpenGL, you have to know what you're doing, understand CPU/GPU synchronization, understand why you shouldn't try to read from one (and how the compiler can trip you up with this), and even then it may be the case that vertex submission was not even your bottleneck to begin with.

Immediate mode (glBegin/glEnd) on the other hand just lets you blast vertices at the GPU without having to know or understand these things, and the driver works it all out for you.

So VBOs can be faster, but it's also easier to do a bad implementation where performance just collapses.  I'm not going to read your code (it would have been better if you'd just pastebinned the 2 functions you mentioned) but I would point you at VBO updates as a first place to look.

I'd also suggest that you could work some more to isolate the performance differential.  So you could write a path that uses VBOs with the fixed pipeline, and another path that uses immediate mode with shaders, which would all enable you to better home in on where your problems are coming from.

##### Share on other sites

You are worrying about the wrong things. Having a noticeable jitter is a problem but when you have fps in the ten thousands I am surprised you can notice. Without really seeing your render code it's hard to tell if you are doing something wrong.

Visible jitter doesn't have to be related to performance at all, but rather to clock/timing issues.

##### Share on other sites

It is easy to misuse VBOs or even calls to the draw methods.

This, basically.

VBOs are not a magic bullet that you just implement and instantly get improved performance everywhere.  Particularly if you update them at runtime, and particularly with OpenGL, you have to know what you're doing, understand CPU/GPU synchronization, understand why you shouldn't try to read from one (and how the compiler can trip you up with this), and even then it may be the case that vertex submission was not even your bottleneck to begin with.

Immediate mode (glBegin/glEnd) on the other hand just lets you blast vertices at the GPU without having to know or understand these things, and the driver works it all out for you.

So VBOs can be faster, but it's also easier to do a bad implementation where performance just collapses.  I'm not going to read your code (it would have been better if you'd just pastebinned the 2 functions you mentioned) but I would point you at VBO updates as a first place to look.

I'd also suggest that you could work some more to isolate the performance differential.  So you could write a path that uses VBOs with the fixed pipeline, and another path that uses immediate mode with shaders, which would all enable you to better home in on where your problems are coming from.

I chose to use VBOs so I could use shaders. I didn't go into it expecting any performance impacts one way or the other. I see now it is quite easy to use them wrong.

You are worrying about the wrong things. Having a noticeable jitter is a problem but when you have fps in the ten thousands I am surprised you can notice. Without really seeing your render code it's hard to tell if you are doing something wrong.

Visible jitter doesn't have to be related to performance at all, but rather to clock/timing issues.

I have determined that my jitter has indeed something to do with my timing for frames. If maybe someone could take a look. I used the suggestion from here. Perhaps I implemented it wrong.

http://gafferongames.com/game-physics/fix-your-timestep/

f64 Accumulator = 0.0;
f64 DeltaTime = 1.0 / 60.0;
f64 CurrentTime = GetTimeInSeconds();
f64 Time = 0.0f;

GameState->Running = true;
while (GameState->Running) {
f64 NewTime = GetTimeInSeconds();
f64 FrameTime = NewTime - CurrentTime;

//printf("Frame Time: %fms   \r", FrameTime);

if (FrameTime > 0.25f) {
FrameTime = 0.25f;
}

CurrentTime = NewTime;
Accumulator += FrameTime;

while (Accumulator >= DeltaTime) {
GameState->DeltaTime = DeltaTime;

ProcessEvents(GameState); // Proceses SDL events like input
UpdateGame(&GameMemory);

Time += DeltaTime;
Accumulator -= DeltaTime;
}

RenderGame(&GameMemory);
}


Also I took the day to play around with VBOs and learn some stuff about instancing and drawing in batches. I improved my render code a bit and made it a bit more sane.