sharing opengl context on different displays using ubuntu

1.2k views Asked by At

We have an application with multiple windows on different screens using 3 graphic cards. Each window uses opengl to render fonts, images etc... This works very well so far, except for sharing resources. we tried to implement something like this (fenster is a custom class to store information like context, etc...):

//a list of display names
vector<string> displays;
displays.push_back(":0.0");
displays.push_back(":0.1");
displays.push_back(":0.2");
displays.push_back(":0.3");    
displays.push_back(":0.4");


//and then we loop them
FOREACH(string dispName in displays): //dummy code

static int dblBuf[]  = {GLX_RGBA, GLX_DEPTH_SIZE, 16, GLX_DOUBLEBUFFER, None};

Display* disp;
if(dispName != "default")
    disp = XOpenDisplay(dispName.c_str());
else
    disp = XOpenDisplay(NULL);

if(disp == NULL)
{
    cout << "ERROR GETING DISPLAY " << dispName << endl;
    return NULL;
}

cout << "CREATING WINDOW ON SCREEN "<< dispName << endl;

XVisualInfo *vi = glXChooseVisual(disp, DefaultScreen(disp), dblBuf);

fenster->display = disp;

fenster->window = XCreateSimpleWindow(disp, RootWindow(disp, vi->screen), 1, 1, 500, 500, 0, BlackPixel (disp, 0), BlackPixel(disp, 0));

XSetStandardProperties(fenster->display, fenster->window, "main", "main", None,NULL, 0, NULL);

XMapWindow(disp, fenster->window);

if(fensterList.size()==0)
    fenster->glXContext = glXCreateContext(disp, vi, NULL, GL_TRUE);
else
    fenster->glXContext = glXCreateContext(fensterList[0]->display, vi, fensterList[0]->glXContext, GL_TRUE);

XSelectInput(disp, fenster->window, ButtonPressMask|KeyPressMask);

glXMakeCurrent(disp, fenster->window, fenster->glXContext);

glEnable(GL_DEPTH_TEST);
glClearColor(0.0, 0.0, 0.0, 0.0);

XFlush(disp);

fenster->id = fensterList.size();

fensterList.push_back(fenster);

fenster->setup();

This compiles fine, but produces the following error on runtime:

CREATING WINDOW ON SCREEN :0.0
CREATING WINDOW ON SCREEN :0.1
X Error of failed request: BadMatch (invalid parameter attributes)
  Major opcode of failed request: 137 (GLX)
  Minor opcode of failed request: 3 (X_GLXCreateContext)
  Serial number of failed request: 90
  Current serial number in output stream: 91

The code works when I try to create multiple windows on the same desktop (using display :0.0).

The system is ubuntu 10.10, using the proprietary ATI driver.

Any ideas? Is it even possible?

2

There are 2 answers

0
Nathan Kidd On BEST ANSWER

From http://www.opengl.org/sdk/docs/man/xhtml/glXCreateContext.xml :

BadMatch is generated if the context to be created would not share the address space or the screen of the context specified by shareList.

The spec wording suggests this should work if you have direct rendering contexts and they're all created by the same process, but in practice the X server and/or libGL might think differently.

2
Ben Voigt On

using 3 graphic cards

Each graphic card has its own state, its own texture memory, etc. Maybe if you're running in Crossfire mode they could access each others' memory directly, but you haven't said anything about that.

Sharing resources requires a common address space as Nathan found in the spec. But I think this is talking about GDRAM address space, not a single process.