Hi DRC/All,
I have mucked around with the VirtualGL 2.3.2 code and have come up
with a solution that seems to work well. I have to mention that the
solution is rather rough around the edges. Some of the code / ideas
were drawn from Mesa's GLXGEARS program (i.e. calculating and reporting
the current FPS and the location to do so in).
Here is how this works:
1. User provides -fps3d <n> argument to vglrun. N is any double 0 or
greater.
2. The function 'glXSwapBuffers' (server/faker-glx.cpp) continually
monitors the current fps and adjusts 'delay' to keep the fps around the
requested fps value (the fps3d argument).
3. User can tweak the fps3d value via the vglconfig (CTRL+SHIFT+F9) GUI
utility.
I am sure that the algorithm for adjusting the delay can be improved.
It was what I could come up with in the limited time I had today.
I have attached a patch that applies to VirtualGL 2.3.2. Please feel
free to review / test and provide feedback.
---
Thanks,
Dyweni
On 2012-07-26 13:41, DRC wrote:
Since VirtualGL redirects the 3D rendering into offscreen buffers,
there
is no concept of VSync, because there is no monitor involved until the
pixels are drawn on the client machine, and by that time, the 3D
rendering is already done.
In the current implementation, there is no way to limit the 3D
rendering
rate except to disable frame spoiling. Disabling frame spoiling
couples
the 3D rendering and compress/send stages of the pipeline, so the
frame
rate will be the lesser of (a) the VGL_FPS setting or (b) the rate at
which the client can process frames. However, that's probably not
what
you want, because you may experience "mouse lag" when frame spoiling
is
disabled.
This issue has never come up, because in visualization apps, the frame
rate is ultimately limited by the sampling rate of the mouse, which is
generally 40-60 Hz. I'm honestly not sure what would be the best
approach to applying a frame rate governor on the 3D side (a VGL_3DFPS
option, if you will.) It might be as simple as putting a delay into
the
buffer swap function.
What I'm wondering, however, is whether our long-term plans to replace
Pbuffers with FBO's and hidden windows might magically fix this, since
VSync might still work when rendering to a hidden window.
If anyone else has further insight, please share.
On 7/26/12 12:56 PM, Dyweni - VirtualGL-Users wrote:
Hi All,
I'm wondering if VirgualGL has support for VSync? I know that
VirtualGL
has support to output only x frames per second, but that is different
from VSync.
I have a game (EVE Online) that can limit itself to the VSync. In
normal X, it limits itself to 60 FPS (my monitor refresh rate) thanks
to
VSync, and that keeps the CPU usage low. However, when running on
VirtualGL, it does not limit its FPS and they skyrocket to 120+ FPS
which drives the CPU usage high.
I would like to be able to lock the game to the VSync (say 60 FPS, to
keep the CPU usage low) and then export x frames per second (as I do
know with the -fps) switch.
Is this possible?
--
Thanks,
Dyweni
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond.
Discussions
will include endpoint security, mobile security and the latest in
malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
VirtualGL-Users mailing list
VirtualGL-Users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/virtualgl-users
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond.
Discussions
will include endpoint security, mobile security and the latest in
malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
VirtualGL-Users mailing list
VirtualGL-Users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/virtualgl-users
From 034863951ec2cfc1464df8593997243d9f48d491 Mon Sep 17 00:00:00 2001
From: root <r...@phenom.dyweni.com>
Date: Sun, 2 Jun 2013 15:47:23 -0500
Subject: [PATCH 1/2] Support limiting 3D application framerate into VirtualGL
---
.../work/VirtualGL-2.3.2/common/rr.h | 1 +
.../work/VirtualGL-2.3.2/server/faker-glx.cpp | 52 ++++++++++++++++++++++
.../work/VirtualGL-2.3.2/server/fakerconfig.cpp | 2 +
.../work/VirtualGL-2.3.2/server/vglconfig.cpp | 25 ++++++++++-
.../work/VirtualGL-2.3.2/server/vglrun | 3 ++
5 files changed, 81 insertions(+), 2 deletions(-)
diff --git a/virtualgl-2.3.2-r2/work/VirtualGL-2.3.2/common/rr.h b/virtualgl-2.3.2-r2/work/VirtualGL-2.3.2/common/rr.h
index 817b7e1..3cd9912 100644
--- a/virtualgl-2.3.2-r2/work/VirtualGL-2.3.2/common/rr.h
+++ b/virtualgl-2.3.2-r2/work/VirtualGL-2.3.2/common/rr.h
@@ -154,6 +154,7 @@ typedef struct _FakerConfig
double flushdelay;
int forcealpha;
double fps;
+ double fps3d;
double gamma;
unsigned char gamma_lut[256];
unsigned short gamma_lut16[65536];
diff --git a/virtualgl-2.3.2-r2/work/VirtualGL-2.3.2/server/faker-glx.cpp b/virtualgl-2.3.2-r2/work/VirtualGL-2.3.2/server/faker-glx.cpp
index 11fc0eb..ca09956 100644
--- a/virtualgl-2.3.2-r2/work/VirtualGL-2.3.2/server/faker-glx.cpp
+++ b/virtualgl-2.3.2-r2/work/VirtualGL-2.3.2/server/faker-glx.cpp
@@ -1726,12 +1726,36 @@ void glXSelectEventSGIX(Display *dpy, GLXDrawable drawable, unsigned long mask)
}
+
+#include <sys/time.h>
+#include <unistd.h>
+
+/* return current time (in seconds) */
+static double
+current_time(void)
+{
+ struct timeval tv;
+#ifdef __VMS
+ (void) gettimeofday(&tv, NULL );
+#else
+ struct timezone tz;
+ (void) gettimeofday(&tv, &tz);
+#endif
+ return (double) tv.tv_sec + tv.tv_usec / 1000000.0;
+}
+
+
// If the application is rendering to the back buffer, VirtualGL will read
// back and send the buffer whenever glXSwapBuffers() is called.
void glXSwapBuffers(Display* dpy, GLXDrawable drawable)
{
pbwin *pbw=NULL;
+ static int frames = 0, delay = 0, delayInc = 1;
+ static double tRate0 = -1.0;
+ double t = current_time();
+ GLfloat seconds;
+ GLfloat fps;
opentrace(glXSwapBuffers); prargd(dpy); prargx(drawable); starttrace();
@@ -1751,6 +1775,34 @@ void glXSwapBuffers(Display* dpy, GLXDrawable drawable)
}
else _glXSwapBuffers(_localdpy, drawable);
+ frames++;
+
+ if (tRate0 < 0.0)
+ tRate0 = t;
+
+ if (fconfig.fps3d > 0) {
+ if (delay > 0) {
+ usleep(delay);
+ }
+ if (t - tRate0 >= 1.0) {
+ seconds = t - tRate0;
+ fps = frames / seconds;
+ tRate0 = t;
+ printf("FAKER_GLX: %d frames in %3.1f seconds = %6.3f FPS\n", frames, seconds, fps);
+ printf("FAKER_GLX: %d %d\n", delay, delayInc);
+ if (delay == 0) {
+ delay = 1000 * (fps / fconfig.fps3d);
+ } else {
+ delayInc = (250 * (fps / fconfig.fps3d));
+ if (delayInc > 250)
+ delay += delayInc;
+ else if (delayInc < 250)
+ delay -= delayInc;
+ }
+ frames=0;
+ }
+ }
+
CATCH();
done:
diff --git a/virtualgl-2.3.2-r2/work/VirtualGL-2.3.2/server/fakerconfig.cpp b/virtualgl-2.3.2-r2/work/VirtualGL-2.3.2/server/fakerconfig.cpp
index 90e31f4..13b6f05 100644
--- a/virtualgl-2.3.2-r2/work/VirtualGL-2.3.2/server/fakerconfig.cpp
+++ b/virtualgl-2.3.2-r2/work/VirtualGL-2.3.2/server/fakerconfig.cpp
@@ -307,6 +307,7 @@ void fconfig_reloadenv(void)
}
fetchenv_bool("VGL_FORCEALPHA", forcealpha);
fetchenv_dbl("VGL_FPS", fps, 0.0, 1000000.0);
+ fetchenv_dbl("VGL_FPS3D", fps3d, 0.0, 1000000.0);
if((env=getenv("VGL_GAMMA"))!=NULL && strlen(env)>0)
{
if(!strcmp(env, "1"))
@@ -548,6 +549,7 @@ void fconfig_print(FakerConfig &fc)
prconfint(compress);
prconfstr(config);
prconfdbl(fps);
+ prconfdbl(fps3d);
prconfdbl(flushdelay);
prconfint(forcealpha);
prconfdbl(gamma);
diff --git a/virtualgl-2.3.2-r2/work/VirtualGL-2.3.2/server/vglconfig.cpp b/virtualgl-2.3.2-r2/work/VirtualGL-2.3.2/server/vglconfig.cpp
index 6389c60..2bf690a 100644
--- a/virtualgl-2.3.2-r2/work/VirtualGL-2.3.2/server/vglconfig.cpp
+++ b/virtualgl-2.3.2-r2/work/VirtualGL-2.3.2/server/vglconfig.cpp
@@ -39,7 +39,7 @@ Fl_Choice *compchoice=NULL, *sampchoice=NULL,
*stereochoice=NULL, *profchoice=NULL;
Fl_Light_Button *spoilbutton=NULL, *ifbutton=NULL;
Fl_Value_Slider *qualslider=NULL;
-Fl_Float_Input *gammainput=NULL, *fpsinput;
+Fl_Float_Input *gammainput=NULL, *fpsinput, *fps3dinput;
Fl_Check_Button *fpsbutton=NULL;
int ppid=-1;
@@ -162,6 +162,13 @@ void SetFPS(void)
fpsinput->value(temps);
}
+void SetFPS3D(void)
+{
+ char temps[20];
+ snprintf(temps, 19, "%.2f", fconfig.fps3d);
+ fps3dinput->value(temps);
+}
+
// Callbacks
@@ -254,6 +261,15 @@ void FPSCB(Fl_Widget *w, void *data)
input->value(temps);
}
+void FPS3DCB(Fl_Widget *w, void *data)
+{
+ Fl_Float_Input *input=(Fl_Float_Input *)w;
+ fconfig.fps3d=atof(input->value());
+ char temps[20];
+ snprintf(temps, 19, "%.2f", fconfig.fps3d);
+ input->value(temps);
+}
+
// Menus
@@ -340,7 +356,7 @@ void init(int argc, char **argv)
{
char temps[20];
- errifnot(win=new Fl_Double_Window(485, 340, "VirtualGL Configuration"));
+ errifnot(win=new Fl_Double_Window(485, 375, "VirtualGL Configuration"));
if(strlen(fconfig.transport)>0)
{
@@ -411,6 +427,11 @@ void init(int argc, char **argv)
fpsinput->callback(FPSCB, 0);
SetFPS();
+ errifnot(fps3dinput=new Fl_Float_Input(240, 340, 85, 25,
+ "Limit 3D Application Frames/second (0.0=no limit): "));
+ fps3dinput->callback(FPS3DCB, 0);
+ SetFPS3D();
+
win->end();
win->show(argc, argv);
}
diff --git a/virtualgl-2.3.2-r2/work/VirtualGL-2.3.2/server/vglrun b/virtualgl-2.3.2-r2/work/VirtualGL-2.3.2/server/vglrun
index 1b620e4..829c8aa 100644
--- a/virtualgl-2.3.2-r2/work/VirtualGL-2.3.2/server/vglrun
+++ b/virtualgl-2.3.2-r2/work/VirtualGL-2.3.2/server/vglrun
@@ -59,6 +59,8 @@ usage()
echo
echo "-fps <f> : Limit client/server frame rate to <f> frames/sec"
echo
+ echo "-fps3d <f>: Limit 3d application frame rate to <f> frames/sec"
+ echo
echo "-gamma <g>: Set gamma correction factor to <g> (see docs)"
echo
echo "-ge : Fool application into thinking that LD_PRELOAD is unset"
@@ -165,6 +167,7 @@ do
-v*) VGL_VERBOSE=0 ; export VGL_VERBOSE ;;
+v*) VGL_VERBOSE=1 ; export VGL_VERBOSE ;;
-fps) VGL_FPS=$2 ; export VGL_FPS ; shift ;;
+ -fps3d) VGL_FPS3D=$2 ; export VGL_FPS3D ; shift ;;
-ms) VGL_SAMPLES=$2 ; export VGL_SAMPLES ; shift ;;
-ld) LD_LIBRARY_PATH=$2:$LD_LIBRARY_PATH ;
export LD_LIBRARY_PATH ; shift ;;
--
1.8.1.5
------------------------------------------------------------------------------
Get 100% visibility into Java/.NET code with AppDynamics Lite
It's a free troubleshooting tool designed for production
Get down to code-level detail for bottlenecks, with <2% overhead.
Download for free and get started troubleshooting in minutes.
http://p.sf.net/sfu/appdyn_d2d_ap2
_______________________________________________
VirtualGL-Users mailing list
VirtualGL-Users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/virtualgl-users