[dx39] Avoid use of glGet

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



As pointed out to me (thanks Lucho), a glGet has a large overhead
compared to a simple lookup, and if we already know the information, we
might as well use it. I changed all the ones used by the SDK sample
Billboard and if improved things by about half a frame/sec, which isnt
much but every bit of performance counts. I'll probably fix the stencil
pass/fail ones at some point too.

Changelog

Avoids the use of glGet when we know the information locally

Jason
Index: dlls/d3d8/d3d8_private.h
===================================================================
RCS file: /home/wine/wine/dlls/d3d8/d3d8_private.h,v
retrieving revision 1.27
diff -u -r1.27 d3d8_private.h
--- dlls/d3d8/d3d8_private.h	17 May 2003 18:33:02 -0000	1.27
+++ dlls/d3d8/d3d8_private.h	24 May 2003 15:05:40 -0000
@@ -263,6 +263,8 @@
 
     UINT                          srcBlend;
     UINT                          dstBlend;
+    UINT                          alphafunc;
+    UINT                          stencilfunc;
 
     /* State block related */
     BOOL                          isRecordingState;
Index: dlls/d3d8/stateblock.c
===================================================================
RCS file: /home/wine/wine/dlls/d3d8/stateblock.c,v
retrieving revision 1.5
diff -u -r1.5 stateblock.c
--- dlls/d3d8/stateblock.c	17 May 2003 18:33:02 -0000	1.5
+++ dlls/d3d8/stateblock.c	24 May 2003 15:06:18 -0000
@@ -106,9 +106,16 @@
     IDirect3DDevice8Impl_SetRenderState(iface, D3DRS_STENCILFAIL, D3DSTENCILOP_KEEP);
     IDirect3DDevice8Impl_SetRenderState(iface, D3DRS_STENCILZFAIL, D3DSTENCILOP_KEEP);
     IDirect3DDevice8Impl_SetRenderState(iface, D3DRS_STENCILPASS, D3DSTENCILOP_KEEP);
+
+    /* Setting stencil func also uses values for stencil ref/mask, so manually set defaults
+     * so only a single call performed (and ensure defaults initialized before making that call)    
+     *
+     * IDirect3DDevice8Impl_SetRenderState(iface, D3DRS_STENCILREF, 0);
+     * IDirect3DDevice8Impl_SetRenderState(iface, D3DRS_STENCILMASK, 0xFFFFFFFF);
+     */
+    This->StateBlock->renderstate[D3DRS_STENCILREF] = 0;
+    This->StateBlock->renderstate[D3DRS_STENCILMASK] = 0xFFFFFFFF;
     IDirect3DDevice8Impl_SetRenderState(iface, D3DRS_STENCILFUNC, D3DCMP_ALWAYS);
-    IDirect3DDevice8Impl_SetRenderState(iface, D3DRS_STENCILREF, 0);
-    IDirect3DDevice8Impl_SetRenderState(iface, D3DRS_STENCILMASK, 0xFFFFFFFF);
     IDirect3DDevice8Impl_SetRenderState(iface, D3DRS_STENCILWRITEMASK, 0xFFFFFFFF);
     IDirect3DDevice8Impl_SetRenderState(iface, D3DRS_TEXTUREFACTOR, 0xFFFFFFFF);
     IDirect3DDevice8Impl_SetRenderState(iface, D3DRS_WRAP0, 0);
--- dlls/d3d8/device.dx38	2003-05-24 16:12:29.000000000 +0100
+++ dlls/d3d8/device.c	2003-05-24 16:57:35.000000000 +0100
@@ -1484,7 +1484,8 @@
     ENTER_GL();
 
     glXSwapBuffers(This->display, This->win);
-    checkGLcall("glXSwapBuffers");
+    /* Dont call checkGLcall, as glGetError is not applicable here */
+    TRACE("glXSwapBuffers called, Starting new frame");
 
     LEAVE_GL();
 
@@ -3134,10 +3135,7 @@
     case D3DRS_ALPHAFUNC                 :
         {
             int glParm = GL_LESS;
-            float ref = 1.0;
-
-            glGetFloatv(GL_ALPHA_TEST_REF, &ref);
-            checkGLcall("glGetFloatv(GL_ALPHA_TEST_REF, &ref);");
+            float ref = ((float) This->StateBlock->renderstate[D3DRS_ALPHAREF]) / 255.0f;
 
             switch ((D3DCMPFUNC) Value) {
             case D3DCMP_NEVER:         glParm=GL_NEVER; break;
@@ -3153,18 +3151,16 @@
             }
             TRACE("glAlphaFunc with Parm=%x, ref=%f\n", glParm, ref);
             glAlphaFunc(glParm, ref);
+            This->alphafunc = glParm;
             checkGLcall("glAlphaFunc");
         }
         break;
 
     case D3DRS_ALPHAREF                  :
         {
-            int glParm = GL_LESS;
+            int glParm = This->alphafunc;
             float ref = 1.0f;
 
-            glGetIntegerv(GL_ALPHA_TEST_FUNC, &glParm);
-            checkGLcall("glGetFloatv(GL_ALPHA_TEST_FUNC, &glParm);");
-
             ref = ((float) Value) / 255.0f;
             TRACE("glAlphaFunc with Parm=%x, ref=%f\n", glParm, ref);
             glAlphaFunc(glParm, ref);
@@ -3293,13 +3289,8 @@
     case D3DRS_STENCILFUNC               :
         {
            int glParm = GL_ALWAYS;
-           int ref = 0;
-           GLuint mask = 0xFFFFFFFF;
-
-           glGetIntegerv(GL_STENCIL_REF, &ref);
-           checkGLcall("glGetFloatv(GL_STENCIL_REF, &ref);");
-           glGetIntegerv(GL_STENCIL_VALUE_MASK, &mask);
-           checkGLcall("glGetFloatv(GL_STENCIL_VALUE_MASK, &glParm);");
+           int ref = This->StateBlock->renderstate[D3DRS_STENCILREF];
+           GLuint mask = This->StateBlock->renderstate[D3DRS_STENCILMASK];
 
            switch ((D3DCMPFUNC) Value) {
            case D3DCMP_NEVER:         glParm=GL_NEVER; break;
@@ -3321,14 +3312,9 @@
 
     case D3DRS_STENCILREF                :
         {
-           int glParm = GL_ALWAYS;
+           int glParm = This->stencilfunc;
            int ref = 0;
-           GLuint mask = 0xFFFFFFFF;
-
-           glGetIntegerv(GL_STENCIL_FUNC, &glParm);
-           checkGLcall("glGetFloatv(GL_STENCIL_FUNC, &glParm);");
-           glGetIntegerv(GL_STENCIL_VALUE_MASK, &mask);
-           checkGLcall("glGetFloatv(GL_STENCIL_VALUE_MASK, &glParm);");
+           GLuint mask = This->StateBlock->renderstate[D3DRS_STENCILMASK];
 
            ref = Value;
            TRACE("glStencilFunc with Parm=%x, ref=%d, mask=%x\n", glParm, ref, mask);
@@ -3339,15 +3325,10 @@
 
     case D3DRS_STENCILMASK               :
         {
-           int glParm = GL_ALWAYS;
-           int ref = 0.0;
+           int glParm = This->stencilfunc;
+           int ref = This->StateBlock->renderstate[D3DRS_STENCILREF];
            GLuint mask = Value;
 
-           glGetIntegerv(GL_STENCIL_REF, &ref);
-           checkGLcall("glGetFloatv(GL_STENCIL_REF, &ref);");
-           glGetIntegerv(GL_STENCIL_FUNC, &glParm);
-           checkGLcall("glGetFloatv(GL_STENCIL_FUNC, &glParm);");
-
            TRACE("glStencilFunc with Parm=%x, ref=%d, mask=%x\n", glParm, ref, mask);
            glStencilFunc(glParm, ref, mask);
            checkGLcall("glStencilFunc");

[Index of Archives]     [Gimp for Windows]     [Red Hat]     [Samba]     [Yosemite Camping]     [Graphics Cards]     [Wine Home]

  Powered by Linux