Discussion:
[vlc] Trying to use AssignNVidiaAffinity to assign OpenGL a specific graphics card
David R Robison
2013-08-13 20:24:42 UTC
Permalink
We have an application that uses two nvidia cards and four monitors. We
are attempting to display 48 videos. However, when using vout=opengl it
appears that all the OpenGL acceleration is being preformed by only one
of the graphics adapters. I have been playing with the
AssignNVidiaAffinity function to try and assign the OpenGL to one of the
two graphics adapters. I have the following function that creates the
affinity mask:

static void AssignNVidiaAffinity(vout_display_t *vd, UINT
nVidiaAffinity, HGPUNV *GpuMask) {
UINT GPUIdx = 0;
HGPUNV hGPU;
while(wglEnumGpusNV(GPUIdx, &hGPU)) {
if (GPUIdx == nVidiaAffinity) GpuMask[0] = hGPU;
GPUIdx++;
}
}

To get it to link I have to define

#define GLEW_STATIC

Everything compiles, but when I try to run the program it crashes when
executing the wglEnumGpusNV call.

Has anyone attempted this before? Any thoughts on what I may be doing
wrong? We are running under Windows 7.
Thanks, David
--
David R Robison
Open Roads Consulting, Inc.
103 Watson Road, Chesapeake, VA 23320
phone: (757) 546-3401
e-mail: drrobison at openroadsconsulting.com
web: http://openroadsconsulting.com
blog: http://therobe.blogspot.com
book: http://www.xulonpress.com/bookstore/bookdetail.php?PB_ISBN=9781597816526



This email communication (including any attachments) may contain confidential and/or privileged material intended solely for the individual or entity to which it is addressed.
If you are not the intended recipient, please delete this email immediately.
Jean-Baptiste Kempf
2013-08-21 08:51:35 UTC
Permalink
Post by David R Robison
Has anyone attempted this before? Any thoughts on what I may be doing
wrong? We are running under Windows 7.
Did you fix it, in the end?

Best regards,
--
Jean-Baptiste Kempf
http://www.jbkempf.com/ - +33 672 704 734
Sent from my Electronic Device
David R Robison
2013-08-21 11:29:49 UTC
Permalink
I've come close. Here is the code I used to assign the nVidia affinity

#undef wglEnumGpusNV
#undef wglCreateAffinityDCNV
static PFNWGLENUMGPUSNVPROC wglEnumGpusNV;
static PFNWGLCREATEAFFINITYDCNVPROC wglCreateAffinityDCNV;

static void AssignNVidiaAffinity(vout_display_t *vd, UINT nVidiaAffinity) {

// initialize the wgl context
if (wglEnumGpusNV == NULL) {
msg_Dbg(vd, "Initialize wgl context" );
HDC winDC = GetDC(vd->sys->hvideownd);
PIXELFORMATDESCRIPTOR pfd;
memset(&pfd, 0, sizeof(pfd));
pfd.nSize = sizeof(pfd);
pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL |
PFD_DOUBLEBUFFER;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 24;
pfd.cDepthBits = 16;
pfd.iLayerType = PFD_MAIN_PLANE;
SetPixelFormat(winDC, ChoosePixelFormat(winDC, &pfd), &pfd);
HGLRC hGLRC = wglCreateContext(winDC);
wglMakeCurrent(winDC, hGLRC);
wglEnumGpusNV =
(PFNWGLENUMGPUSNVPROC)wglGetProcAddress("wglEnumGpusNV");
wglCreateAffinityDCNV =
(PFNWGLCREATEAFFINITYDCNVPROC)wglGetProcAddress("wglCreateAffinityDCNV");
wglDeleteContext(hGLRC);
}

// see if we have the extensions
if (!wglEnumGpusNV || !wglCreateAffinityDCNV) {
msg_Dbg(vd, "OpenGL nVidia extensions do not seem to be present" );
return;
}

// find the graphics card
HGPUNV GpuMask[2];
GpuMask[0] = NULL;
GpuMask[1] = NULL;
HGPUNV hGPU;
if (!wglEnumGpusNV(nVidiaAffinity, &hGPU)) {
msg_Warn(vd, "Could not enumerate nVidia adapter %d",
nVidiaAffinity );
return;
}

// make the new context
GpuMask[0] = hGPU;
vd->sys->hGLDC = wglCreateAffinityDCNV(GpuMask);
}

This is called in the glwin32.c program as

// process card specific affinities
int nVidiaAffinity = var_InheritInteger(vd, "nvidia-affinity");
if (nVidiaAffinity >= 0) {
msg_Dbg(vd, "nVidia affinity using adapter %d", nVidiaAffinity );
AssignNVidiaAffinity(vd, nVidiaAffinity);
}

/*
* use default card affinity
*/
if (sys->hGLDC == NULL) sys->hGLDC = GetDC(sys->hvideownd);

It works, in the since that I can select the card and see the card's
memory and activity increase, but it plays no video. I'm not sure what
I'm doing wrong, but I guess there is more investigation on my part that
is needed. Any thoughts?
David

David R Robison
Open Roads Consulting, Inc.
103 Watson Road, Chesapeake, VA 23320
phone: (757) 546-3401
e-mail: drrobison at openroadsconsulting.com
web: http://openroadsconsulting.com
blog: http://therobe.blogspot.com
book: http://www.xulonpress.com/bookstore/bookdetail.php?PB_ISBN=9781597816526
Post by Jean-Baptiste Kempf
Post by David R Robison
Has anyone attempted this before? Any thoughts on what I may be doing
wrong? We are running under Windows 7.
Did you fix it, in the end?
Best regards,
This email communication (including any attachments) may contain confidential and/or privileged material intended solely for the individual or entity to which it is addressed.
If you are not the intended recipient, please delete this email immediately.
Loading...