Single buffer + flush vs double buffer + swap
#1
Single buffer + flush vs double buffer + swap
Hello everyone,

Work is ongoing well, but I'm not sure whether to go for single or double buffers for the benchmark tool.

On my C8000, with a relatively modern FireGL, if I use single buffer, the image is a bit flickery.
If I change to double buffer, it's butter-smooth.

In both cases, the frame rate is the same.

I checked the OpenGL documentation and found out that single buffers are better for older hardware, where saving memory is important.
My C8000 is the oldest computer I own, so I can't test.
I don't think any of my tests will require too much memory, though.

What would you recommend? My goal is that you could build this and run on your SGIs as well.

The whole ordeal is GLUT + C, and it builds without a line of change to the code on modern Linux and Mac, plus HP-UX 11.11, on PPC, HPPA, Intel and ARM, and I intend to keep it this way.
Shiunbird
Administrator

Trade Count: (1)
Posts: 553
Threads: 45
Joined: Mar 2021
Location: Czech Republic
Find Reply
05-05-2021, 12:01 PM
#2
RE: Single buffer + flush vs double buffer + swap
Well wouldn't it depend on what you're benchmarking exactly? As single buffer will be more in-line with pure fill-rate and doublebuffer would be also be throwing graphics memory bandwidth in to the mix. If the benchmark includes textures then one can assume it *should* be run on a texture enabled card then double buffering would make sense.
stormy
Atari expert!

Trade Count: (1)
Posts: 180
Threads: 34
Joined: May 2019
Location: UK
Find Reply
05-05-2021, 04:19 PM
#3
RE: Single buffer + flush vs double buffer + swap
It depends entirely on the specific application. Indys are confined to 256M RAM, as are some Indigo2s. Octanes can have more than 1G of RAM

But yeah, if it's flickering with an FGL, use a double buffer.

I'm the system admin of this site. Private security technician, licensed locksmith, hack of a c developer and vintage computer enthusiast. 

https://contrib.irixnet.org/raion/ -- contributions and pieces that I'm working on currently. 

https://codeberg.org/SolusRaion -- Code repos I control

Technical problems should be sent my way.
Raion
Chief IRIX Officer

Trade Count: (9)
Posts: 4,240
Threads: 533
Joined: Nov 2017
Location: Eastern Virginia
Website Find Reply
05-05-2021, 04:35 PM
#4
RE: Single buffer + flush vs double buffer + swap
Double buffering is used to prevent flicker or "tearing" when significant parts of the scene are moving. If the scene is mostly static and only moves occasionally (as in a CAD application) single buffering is going to look fine.
The cause of the flicker is that the framebuffer is being read constantly to generate the RGB signal to the monitor, asynchronous to the program. So when you draw into it, it's unpredictable which parts of your drawn objects appear first. If the output was currently at the center of the screen (as the beam of a CRT passes the midpoint of the display), and you drew a rect covering the whole screen at that moment, the bottom of the rect would appear, then after the screen finishes refreshing, the video blanks for a few milliseconds, and begins refreshing at the top again, and finally the top half of the rect appears. This happens faster than you can think but you eyes see it as flicker. To get around that you can have two framebuffers: a current one that is being shown on screen, and a future one that you do your drawing into. When you've finished drawing a frame—all the objects that should be shown for the next moment in time—you tell the graphics to swap buffers at the next refresh. What you see on the monitor is the complete new frame without any flickering or artifacts.

Note that in OpenGL (and graphics workstations like SGIs generally) double-buffering is in hardware—the memory in the graphics unit is divided into two buffers. Some other computers perform something they call "double-buffering" in software, which is rather different. They use a backing-store in main memory to draw into, and then BLT the whole thing into display memory during the vertical blanking time. This was used by PC games in the VGA era, for example. This avoids tearing but puts more load on the system bus compared to hardware. If your graphics hardware lacks support for double-buffering this is an alternative. Another is to just use the framebuffer, but only write during the vertical blanking: you have less time to calculate your output, but if you can do it quickly there is no tearing. Yet another option is to "race the beam": keep track of where the current position being output is, and order your drawing so you only write below that point. In the extreme you can do without a framebuffer at all, and just output data directly as the monitor sees it. The Atari VCS did this. It requires cycle-exact control over instruction timing.

Because double-buffering requires the graphics subsystem to configure itself as two display buffers, it is only available when the display mode is set to a configuration that supports it.

There is also triple- and quad-buffering for use with stereo graphics modes. The reason this is needed is what happens when the software hasn't finished drawing a new frame by the time the display refresh happens: In mono (single perspective view) graphics, the active buffer can be left as it is, and the effect is that you just "drop a frame" (the previous frame is output twice and the new frame is delayed by one cycle). In stereo (two perspective views), this does not work, since the left perspective buffer must always be used on even cycles and the right buffer for odd cycles. So four buffers are used instead, a current and future left buffer, and a current and future right buffer.

Personaliris O2 Indigo2 R10000/IMPACT Indigo2 R10000/IMPACT Indigo2 Indy   (past: 4D70GT)
robespierre
refector peritus

Trade Count: (0)
Posts: 640
Threads: 3
Joined: Nov 2020
Location: Massholium
Find Reply
05-05-2021, 05:04 PM
#5
RE: Single buffer + flush vs double buffer + swap
Thank you, everyone.
This helps.

So far no textures are involved.

Some tests are graphics bound. I draw multicoloured triangles and shift them around.
Others shift the triangle around but have a complex collision detection running on the CPU.

Changing from one to another takes only 3 line changes, so I will build both.

Edit:
As a test, I rebooted my C8000 into Debian 10.
Under HP-UX, building using HP's compiler and using hardware acceleration, I get 150 fps.
Under Linux, using the software renderer, I get 5.
(with collision detection enabled - I'm assuming a huge difference without).
(This post was last modified: 05-05-2021, 07:21 PM by Shiunbird. Edit Reason: extra information )
Shiunbird
Administrator

Trade Count: (1)
Posts: 553
Threads: 45
Joined: Mar 2021
Location: Czech Republic
Find Reply
05-05-2021, 07:13 PM


Forum Jump:


Users browsing this thread: 2 Guest(s)