[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     |   24 ++++++++++++++++--------=0A=
 dlls/wined3d/wined3d_private.h |    1 +=0A=
 3 files changed, 25 insertions(+), 8 deletions(-)=0A=
=0A=
diff --git a/dlls/wined3d/baseshader.c b/dlls/wined3d/baseshader.c=0A=
index 8cd2490..1f6e043 100644=0A=
--- a/dlls/wined3d/baseshader.c=0A=
+++ b/dlls/wined3d/baseshader.c=0A=
@@ -342,6 +342,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=
@@ -487,6 +489,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 6ec2591..3f54170 100644=0A=
--- a/dlls/wined3d/glsl_shader.c=0A=
+++ b/dlls/wined3d/glsl_shader.c=0A=
@@ -418,12 +418,16 @@ 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, =
prog->vuniformI_locations,=0A=
-                stateBlock->vertexShaderConstantI, =
stateBlock->changed.vertexShaderConstantsI);=0A=
+        if(vshader->baseShader.uses_int_consts) {=0A=
+            shader_glsl_load_constantsI(vshader, gl_info, =
prog->vuniformI_locations,=0A=
+                    stateBlock->vertexShaderConstantI, =
stateBlock->changed.vertexShaderConstantsI);=0A=
+        }=0A=
 =0A=
         /* Load DirectX 9 boolean constants/uniforms for vertex shader =
*/=0A=
-        shader_glsl_load_constantsB(vshader, gl_info, programId,=0A=
-                stateBlock->vertexShaderConstantB, =
stateBlock->changed.vertexShaderConstantsB);=0A=
+        if(vshader->baseShader.uses_bool_consts) {=0A=
+            shader_glsl_load_constantsB(vshader, gl_info, programId,=0A=
+                    stateBlock->vertexShaderConstantB, =
stateBlock->changed.vertexShaderConstantsB);=0A=
+        }=0A=
 =0A=
         /* Upload the position fixup params */=0A=
         GL_EXTCALL(glUniform4fvARB(prog->posFixup_location, 1, =
&deviceImpl->posFixup[0]));=0A=
@@ -442,12 +446,16 @@ 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, =
prog->puniformI_locations,=0A=
-                stateBlock->pixelShaderConstantI, =
stateBlock->changed.pixelShaderConstantsI);=0A=
+        if(pshader->baseShader.uses_int_consts) {=0A=
+            shader_glsl_load_constantsI(pshader, gl_info, =
prog->puniformI_locations,=0A=
+                    stateBlock->pixelShaderConstantI, =
stateBlock->changed.pixelShaderConstantsI);=0A=
+        }=0A=
 =0A=
         /* Load DirectX 9 boolean constants/uniforms for pixel shader */=0A=
-        shader_glsl_load_constantsB(pshader, gl_info, programId,=0A=
-                stateBlock->pixelShaderConstantB, =
stateBlock->changed.pixelShaderConstantsB);=0A=
+        if(pshader->baseShader.uses_bool_consts) {=0A=
+            shader_glsl_load_constantsB(pshader, gl_info, programId,=0A=
+                    stateBlock->pixelShaderConstantB, =
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 f8e2a8c..85f32a8 100644=0A=
--- a/dlls/wined3d/wined3d_private.h=0A=
+++ b/dlls/wined3d/wined3d_private.h=0A=
@@ -2194,6 +2194,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_0001_01C95B85.55D1CA80--




More information about the wine-patches mailing list