Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (803)
Games in Android Showcase (237)
games submitted by our members
Games in WIP (867)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  How to get SLI (and Crossfire?) working with framebuffer objects  (Read 6511 times)
0 Members and 1 Guest are viewing this topic.
Offline theagentd
« Posted 2013-01-30 16:55:38 »

This is a tutorial covering how to get SLI (and presumably Crossfire) working with your OpenGL based game!

SLI and Crossfire are technologies of Nvidia and AMD respectively that enable users to cram in multiple GPUs into their computers and have them work in parallel to give (hopefully) almost linear scaling with the number of GPUs. In practice there are some problems, for example driver compatibility problems and micro-stuttering, but there sure are some heavy FPS wins possible. For good performance, the single one thing you have to avoid is data-dependency between frames. Since I have an Nvidia Geforce GTX 295, I can't tell you exactly how to do this with a Crossfire setup, but it should be doable to AMD drivers as well.

Enabling SLI for your game is easy as pie with Nvidia cards and can be done without any third-party programs like Nvidia Inspector.

1. Double-click the Nvidia icon on your tray bar to fire up the Nvidia Control Panel.
2. In the left-most panel, go to "Manage 3D settings" (under "3D settings").

Now, do either 3a or 3b:
3a. (the lazy way) In the Global Settings tab, find "SLI performance mode" and set it to "Force alternative frame rendering 2". This will enable SLI for all programs using DirectX or OpenGL, so remember to disable it after you're done!
3b. (the right way) Go to Program Settings and create a profile for java.exe and javaw.exe. Then find "SLI performance mode" and set it to "Force alternative frame rendering 2". This will only enable it for Java programs, but it might still screw up Java2D OpenGL acceleration if you're unlucky...

4. Run your Java program and enjoy much higher frame rates!

For most of you, that'll all you need to do. However, if you're using FBOs for anything (shadow maps, offscreen rendering, whatever) you'll notice that instead of a 90% performance boost, you got a 75% performance penalty!!! Surely there's something fishy going on here.

The problem is that since there's no hand-made SLI profile made for your game by Nvidia, the driver makes assumptions. In our case, bad assumptions. FBOs effectively cause your GPU to generate a texture on its own. Alternative frame rendering (AFR) makes each GPU work on every other frame. Therefore when we finish a frame, all render target textures are synchronized between all GPUs to ensure that they all have the generated textures, and there goes our parallelism. Not only can the GPUs not work in parallel at all, the copying overhead completely kills our frame-rate.

Our savior is an OpenGL extension called ARBInvalidateSubdata! This extension allows you to invalidate the contents of a texture, framebuffer or texture! At the end of the frame, just before we complete a frame and do a buffer swap, we invalidate all textures that we've rendered to that aren't needed in the next frame! That tells the driver that those textures won't need to be synchronized between GPUs, so we get perfect scaling!

Offline sproingie

JGO Kernel

Medals: 202

« Reply #1 - Posted 2013-01-31 02:45:41 »

Medal for you even though my puissant wit is no longer immortalized in your sig Wink
Offline ra4king

JGO Kernel

Medals: 508
Projects: 3
Exp: 5 years

I'm the King!

« Reply #2 - Posted 2013-01-31 03:51:14 »

Noooo our precious signature joke! Sad

Great post! I'm going to look into that and play with it Cheesy

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline theagentd
« Reply #3 - Posted 2013-01-31 10:44:00 »

Yeah, I realized my new one definitely isn't as funny when brought out of context...

Offline theagentd
« Reply #4 - Posted 2013-01-31 16:59:06 »

Some numbers from my testing (god, I love numbers):

Single GPU: 89 FPS (1.00x)
2 GPU AFR2: 46 FPS (0.52x)
2 GPU AFR2 /w glInvalidateTexImage(): 166 FPS (1.93x)

In this program I invalidate 4 textures used as render targets before swapping the buffers. The textures are are 3x 64bpp RGBA16F textures and 1x 32bpp depth-stencil texture. At 1920x1080 and 166 FPS, that's almost 9GBs of data copying avoided PER SECOND. It should also be noted that glInvalidateTexImage() is NOT the same as glClear(). glInvalidateTexImage() just marks the texture "invalid" and therefore doesn't have a measurable cost. It simply gives the driver enough information to allow it to do the necessary optimizations needed for AFR to work properly.

Pages: [1]
  ignore  |  Print  

Riven (397 views)
2019-09-04 15:33:17

hadezbladez (5280 views)
2018-11-16 13:46:03

hadezbladez (2204 views)
2018-11-16 13:41:33

hadezbladez (5544 views)
2018-11-16 13:35:35

hadezbladez (1150 views)
2018-11-16 13:32:03

EgonOlsen (4584 views)
2018-06-10 19:43:48

EgonOlsen (5462 views)
2018-06-10 19:43:44

EgonOlsen (3119 views)
2018-06-10 19:43:20

DesertCoockie (4015 views)
2018-05-13 18:23:11

nelsongames (4708 views)
2018-04-24 18:15:36
A NON-ideal modular configuration for Eclipse with JavaFX
by philfrei
2019-12-19 19:35:12

Java Gaming Resources
by philfrei
2019-05-14 16:15:13

Deployment and Packaging
by philfrei
2019-05-08 15:15:36

Deployment and Packaging
by philfrei
2019-05-08 15:13:34

Deployment and Packaging
by philfrei
2019-02-17 20:25:53

Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!