[PATCH] WineD3D: Don't load INT and BOOL constants needlessly=0A=

Stefan Doesinger stefan at codeweavers.com
Thu Nov 27 01:21:36 CST 2008


=0A=
Should give a small performance boost. The constants weren't=0A=
actually loaded before either, but they were rejected on a=0A=
per-constant basis. Most shaders don't use any of those=0A=
constants, so we can skip checking the constants=0A=
---=0A=
 dlls/wined3d/baseshader.c      |    8 ++++++++=0A=
 dlls/wined3d/glsl_shader.c     |   36 =
++++++++++++++++++++++--------------=0A=
 dlls/wined3d/wined3d_private.h |    1 +=0A=
 3 files changed, 31 insertions(+), 14 deletions(-)=0A=
=0A=
diff --git a/dlls/wined3d/baseshader.c b/dlls/wined3d/baseshader.c=0A=
index 1427faa..177ec98 100644=0A=
--- a/dlls/wined3d/baseshader.c=0A=
+++ b/dlls/wined3d/baseshader.c=0A=
@@ -333,6 +333,8 @@ HRESULT shader_get_registers_used(=0A=
                 max_loop_depth =3D cur_loop_depth;=0A=
             pToken +=3D curOpcode->num_params;=0A=
 =0A=
+            /* Rep and Loop always use an integer constant for the =
control parameters */=0A=
+            This->baseShader.uses_int_consts =3D TRUE;=0A=
         } else if (WINED3DSIO_ENDLOOP =3D=3D curOpcode->opcode ||=0A=
                    WINED3DSIO_ENDREP =3D=3D curOpcode->opcode) {=0A=
             cur_loop_depth--;=0A=
@@ -478,6 +480,12 @@ HRESULT shader_get_registers_used(=0A=
                         reg_maps->usesrelconstF =3D TRUE;=0A=
                     }=0A=
                 }=0A=
+                else if(WINED3DSPR_CONSTINT =3D=3D regtype) {=0A=
+                    This->baseShader.uses_int_consts =3D TRUE;=0A=
+                }=0A=
+                else if(WINED3DSPR_CONSTBOOL =3D=3D regtype) {=0A=
+                    This->baseShader.uses_bool_consts =3D TRUE;=0A=
+                }=0A=
 =0A=
                 /* WINED3DSPR_TEXCRDOUT is the same as =
WINED3DSPR_OUTPUT. _OUTPUT can be > MAX_REG_TEXCRD and is used=0A=
                  * in >=3D 3.0 shaders. Filter 3.0 shaders to prevent =
overflows, and also filter pixel shaders because TECRDOUT=0A=
diff --git a/dlls/wined3d/glsl_shader.c b/dlls/wined3d/glsl_shader.c=0A=
index 239dfff..a0a5738 100644=0A=
--- a/dlls/wined3d/glsl_shader.c=0A=
+++ b/dlls/wined3d/glsl_shader.c=0A=
@@ -420,15 +420,19 @@ static void shader_glsl_load_constants(=0A=
                 stateBlock->vertexShaderConstantF, constant_locations, =
constant_list);=0A=
 =0A=
         /* Load DirectX 9 integer constants/uniforms for vertex shader =
*/=0A=
-        shader_glsl_load_constantsI(vshader, gl_info, programId,=0A=
-                                    prog->vuniformI_locations, =
MAX_CONST_I,=0A=
-                                    stateBlock->vertexShaderConstantI,=0A=
-                                    =
stateBlock->changed.vertexShaderConstantsI);=0A=
+        if(vshader->baseShader.uses_int_consts) {=0A=
+            shader_glsl_load_constantsI(vshader, gl_info, programId,=0A=
+                                        prog->vuniformI_locations, =
MAX_CONST_I,=0A=
+                                        =
stateBlock->vertexShaderConstantI,=0A=
+                                        =
stateBlock->changed.vertexShaderConstantsI);=0A=
+        }=0A=
 =0A=
         /* Load DirectX 9 boolean constants/uniforms for vertex shader =
*/=0A=
-        shader_glsl_load_constantsB(vshader, gl_info, programId, =
MAX_CONST_B,=0A=
-                                    stateBlock->vertexShaderConstantB,=0A=
-                                    =
stateBlock->changed.vertexShaderConstantsB);=0A=
+        if(vshader->baseShader.uses_bool_consts) {=0A=
+            shader_glsl_load_constantsB(vshader, gl_info, programId, =
MAX_CONST_B,=0A=
+                                        =
stateBlock->vertexShaderConstantB,=0A=
+                                        =
stateBlock->changed.vertexShaderConstantsB);=0A=
+        }=0A=
 =0A=
         /* Upload the position fixup params */=0A=
         GL_EXTCALL(glUniform4fvARB(prog->posFixup_location, 1, =
&deviceImpl->posFixup[0]));=0A=
@@ -447,15 +451,19 @@ static void shader_glsl_load_constants(=0A=
                 stateBlock->pixelShaderConstantF, constant_locations, =
constant_list);=0A=
 =0A=
         /* Load DirectX 9 integer constants/uniforms for pixel shader */=0A=
-        shader_glsl_load_constantsI(pshader, gl_info, programId,=0A=
-                                    prog->puniformI_locations, =
MAX_CONST_I,=0A=
-                                    stateBlock->pixelShaderConstantI, =0A=
-                                    =
stateBlock->changed.pixelShaderConstantsI);=0A=
+        if(pshader->baseShader.uses_int_consts) {=0A=
+            shader_glsl_load_constantsI(pshader, gl_info, programId,=0A=
+                                        prog->puniformI_locations, =
MAX_CONST_I,=0A=
+                                        =
stateBlock->pixelShaderConstantI,=0A=
+                                        =
stateBlock->changed.pixelShaderConstantsI);=0A=
+        }=0A=
 =0A=
         /* Load DirectX 9 boolean constants/uniforms for pixel shader */=0A=
-        shader_glsl_load_constantsB(pshader, gl_info, programId, =
MAX_CONST_B,=0A=
-                                    stateBlock->pixelShaderConstantB, =0A=
-                                    =
stateBlock->changed.pixelShaderConstantsB);=0A=
+        if(pshader->baseShader.uses_bool_consts) {=0A=
+            shader_glsl_load_constantsB(pshader, gl_info, programId, =
MAX_CONST_B,=0A=
+                                        =
stateBlock->pixelShaderConstantB,=0A=
+                                        =
stateBlock->changed.pixelShaderConstantsB);=0A=
+        }=0A=
 =0A=
         /* Upload the environment bump map matrix if needed. The =
needsbumpmat member specifies the texture stage to load the matrix from.=0A=
          * It can't be 0 for a valid texbem instruction.=0A=
diff --git a/dlls/wined3d/wined3d_private.h =
b/dlls/wined3d/wined3d_private.h=0A=
index d6ad1fd..12a952a 100644=0A=
--- a/dlls/wined3d/wined3d_private.h=0A=
+++ b/dlls/wined3d/wined3d_private.h=0A=
@@ -2141,6 +2141,7 @@ typedef struct IWineD3DBaseShaderClass=0A=
     BOOL                            is_compiled;=0A=
     UINT                            cur_loop_depth, cur_loop_regno;=0A=
     BOOL                            load_local_constsF;=0A=
+    BOOL                            uses_bool_consts, uses_int_consts;=0A=
 =0A=
     /* Type of shader backend */=0A=
     int shader_mode;=0A=
-- =0A=
1.5.6.4=0A=
=0A=

------=_NextPart_000_0019_01C95030.2A4929E0--




More information about the wine-patches mailing list