[PATCH] WineD3D: Put the ps compile parameters into the glsl =

Stefan Doesinger stefan at codeweavers.com
Fri Nov 21 19:48:36 CST 2008


program hashmap=0A=
=0A=
This avoids the double search for a pixel shader. The pixel shader =
compilation parameter=0A=
structure is recorded in the GLSL program hashmap, together with the =
WineD3D pixel shader.=0A=
=0A=
This means that if a compiled+linked GLSL program exists, wined3d only =
has to look into the GLSL=0A=
hashmap, and doesn't have to do a separate search for the fragment =
shader id. If no program is=0A=
found, the pixel shader array is still used. This avoids generating =
multiple identical GLSL=0A=
fragment shaders.=0A=
=0A=
Note that the pixelshader compilation argument structure isn't hashed. =
Its only taken into=0A=
account in the final full comparison. This reflects the consideration =
that this structure=0A=
usually doesn't change, and we have only one pair of the same (d3d) =
pixel+vertex shader=0A=
most of the time=0A=
---=0A=
 dlls/wined3d/glsl_shader.c |   63 =
++++++++++++++++++++++++++-----------------=0A=
 1 files changed, 38 insertions(+), 25 deletions(-)=0A=
=0A=
diff --git a/dlls/wined3d/glsl_shader.c b/dlls/wined3d/glsl_shader.c=0A=
index d0d7491..a32c3c0 100644=0A=
--- a/dlls/wined3d/glsl_shader.c=0A=
+++ b/dlls/wined3d/glsl_shader.c=0A=
@@ -62,26 +62,28 @@ struct shader_glsl_priv {=0A=
 =0A=
 /* Struct to maintain data about a linked GLSL program */=0A=
 struct glsl_shader_prog_link {=0A=
-    struct list             vshader_entry;=0A=
-    struct list             pshader_entry;=0A=
-    GLhandleARB             programId;=0A=
-    GLhandleARB             *vuniformF_locations;=0A=
-    GLhandleARB             *puniformF_locations;=0A=
-    GLhandleARB             vuniformI_locations[MAX_CONST_I];=0A=
-    GLhandleARB             puniformI_locations[MAX_CONST_I];=0A=
-    GLhandleARB             posFixup_location;=0A=
-    GLhandleARB             bumpenvmat_location[MAX_TEXTURES];=0A=
-    GLhandleARB             luminancescale_location[MAX_TEXTURES];=0A=
-    GLhandleARB             luminanceoffset_location[MAX_TEXTURES];=0A=
-    GLhandleARB             ycorrection_location;=0A=
-    GLenum                  vertex_color_clamp;=0A=
-    GLhandleARB             vshader;=0A=
-    GLhandleARB             pshader;=0A=
+    struct list                 vshader_entry;=0A=
+    struct list                 pshader_entry;=0A=
+    GLhandleARB                 programId;=0A=
+    GLhandleARB                 *vuniformF_locations;=0A=
+    GLhandleARB                 *puniformF_locations;=0A=
+    GLhandleARB                 vuniformI_locations[MAX_CONST_I];=0A=
+    GLhandleARB                 puniformI_locations[MAX_CONST_I];=0A=
+    GLhandleARB                 posFixup_location;=0A=
+    GLhandleARB                 bumpenvmat_location[MAX_TEXTURES];=0A=
+    GLhandleARB                 luminancescale_location[MAX_TEXTURES];=0A=
+    GLhandleARB                 luminanceoffset_location[MAX_TEXTURES];=0A=
+    GLhandleARB                 ycorrection_location;=0A=
+    GLenum                      vertex_color_clamp;=0A=
+    GLhandleARB                 vshader;=0A=
+    IWineD3DPixelShader         *pshader;=0A=
+    struct ps_compile_args      ps_args;=0A=
 };=0A=
 =0A=
 typedef struct {=0A=
-    GLhandleARB vshader;=0A=
-    GLhandleARB pshader;=0A=
+    GLhandleARB                 vshader;=0A=
+    IWineD3DPixelShader         *pshader;=0A=
+    struct ps_compile_args      ps_args;=0A=
 } glsl_program_key_t;=0A=
 =0A=
 =0A=
@@ -2817,16 +2819,18 @@ static void add_glsl_program_entry(struct =
shader_glsl_priv *priv, struct glsl_sh=0A=
     key =3D HeapAlloc(GetProcessHeap(), 0, sizeof(glsl_program_key_t));=0A=
     key->vshader =3D entry->vshader;=0A=
     key->pshader =3D entry->pshader;=0A=
+    key->ps_args =3D entry->ps_args;=0A=
 =0A=
     hash_table_put(priv->glsl_program_lookup, key, entry);=0A=
 }=0A=
 =0A=
 static struct glsl_shader_prog_link *get_glsl_program_entry(struct =
shader_glsl_priv *priv,=0A=
-        GLhandleARB vshader, GLhandleARB pshader) {=0A=
+        GLhandleARB vshader, IWineD3DPixelShader *pshader, struct =
ps_compile_args *ps_args) {=0A=
     glsl_program_key_t key;=0A=
 =0A=
     key.vshader =3D vshader;=0A=
     key.pshader =3D pshader;=0A=
+    key.ps_args =3D *ps_args;=0A=
 =0A=
     return (struct glsl_shader_prog_link =
*)hash_table_get(priv->glsl_program_lookup, &key);=0A=
 }=0A=
@@ -2837,6 +2841,7 @@ static void delete_glsl_program_entry(struct =
shader_glsl_priv *priv, WineD3D_GL_=0A=
     key =3D HeapAlloc(GetProcessHeap(), 0, sizeof(glsl_program_key_t));=0A=
     key->vshader =3D entry->vshader;=0A=
     key->pshader =3D entry->pshader;=0A=
+    key->ps_args =3D entry->ps_args;=0A=
     hash_table_remove(priv->glsl_program_lookup, key);=0A=
 =0A=
     GL_EXTCALL(glDeleteObjectARB(entry->programId));=0A=
@@ -3186,6 +3191,7 @@ static void set_glsl_shader_program(IWineD3DDevice =
*iface, BOOL use_ps, BOOL use=0A=
     int i;=0A=
     char glsl_name[8];=0A=
     GLhandleARB vshader_id, pshader_id;=0A=
+    struct ps_compile_args compile_args;=0A=
 =0A=
     if(use_vs) {=0A=
         IWineD3DVertexShaderImpl_CompileShader(vshader);=0A=
@@ -3194,13 +3200,12 @@ static void =
set_glsl_shader_program(IWineD3DDevice *iface, BOOL use_ps, BOOL use=0A=
         vshader_id =3D 0;=0A=
     }=0A=
     if(use_ps) {=0A=
-        struct ps_compile_args compile_args;=0A=
         =
find_ps_compile_args((IWineD3DPixelShaderImpl*)This->stateBlock->pixelSha=
der, This->stateBlock, &compile_args);=0A=
-        pshader_id =3D find_gl_pshader((IWineD3DPixelShaderImpl *) =
pshader, &compile_args);=0A=
     } else {=0A=
-        pshader_id =3D 0;=0A=
+        /* FIXME: Do we really have to spend CPU cycles to generate a =
few zeroed bytes? */=0A=
+        memset(&compile_args, 0, sizeof(compile_args));=0A=
     }=0A=
-    entry =3D get_glsl_program_entry(priv, vshader_id, pshader_id);=0A=
+    entry =3D get_glsl_program_entry(priv, vshader_id, pshader, =
&compile_args);=0A=
     if (entry) {=0A=
         priv->glsl_program =3D entry;=0A=
         return;=0A=
@@ -3214,7 +3219,8 @@ static void set_glsl_shader_program(IWineD3DDevice =
*iface, BOOL use_ps, BOOL use=0A=
     entry =3D HeapAlloc(GetProcessHeap(), 0, sizeof(struct =
glsl_shader_prog_link));=0A=
     entry->programId =3D programId;=0A=
     entry->vshader =3D vshader_id;=0A=
-    entry->pshader =3D pshader_id;=0A=
+    entry->pshader =3D pshader;=0A=
+    entry->ps_args =3D compile_args;=0A=
     /* Add the hash table entry */=0A=
     add_glsl_program_entry(priv, entry);=0A=
 =0A=
@@ -3259,6 +3265,12 @@ static void =
set_glsl_shader_program(IWineD3DDevice *iface, BOOL use_ps, BOOL use=0A=
         list_add_head(&((IWineD3DBaseShaderImpl =
*)vshader)->baseShader.linked_programs, &entry->vshader_entry);=0A=
     }=0A=
 =0A=
+    if(use_ps) {=0A=
+        pshader_id =3D find_gl_pshader((IWineD3DPixelShaderImpl *) =
pshader, &compile_args);=0A=
+    } else {=0A=
+        pshader_id =3D 0;=0A=
+    }=0A=
+=0A=
     /* Attach GLSL pshader */=0A=
     if (pshader_id) {=0A=
         TRACE("Attaching GLSL shader object %u to program %u\n", =
pshader_id, programId);=0A=
@@ -3552,7 +3564,7 @@ static void shader_glsl_destroy(IWineD3DBaseShader =
*iface) {=0A=
 static unsigned int glsl_program_key_hash(void *key) {=0A=
     glsl_program_key_t *k =3D (glsl_program_key_t *)key;=0A=
 =0A=
-    unsigned int hash =3D k->vshader | k->pshader << 16;=0A=
+    unsigned int hash =3D k->vshader | ((DWORD_PTR) k->pshader) << 16;=0A=
     hash +=3D ~(hash << 15);=0A=
     hash ^=3D  (hash >> 10);=0A=
     hash +=3D  (hash << 3);=0A=
@@ -3567,7 +3579,8 @@ static BOOL glsl_program_key_compare(void *keya, =
void *keyb) {=0A=
     glsl_program_key_t *ka =3D (glsl_program_key_t *)keya;=0A=
     glsl_program_key_t *kb =3D (glsl_program_key_t *)keyb;=0A=
 =0A=
-    return ka->vshader =3D=3D kb->vshader && ka->pshader =3D=3D =
kb->pshader;=0A=
+    return ka->vshader =3D=3D kb->vshader && ka->pshader =3D=3D =
kb->pshader &&=0A=
+           (memcmp(&ka->ps_args, &kb->ps_args, sizeof(kb->ps_args)) =
=3D=3D 0);=0A=
 }=0A=
 =0A=
 static HRESULT shader_glsl_alloc(IWineD3DDevice *iface) {=0A=
-- =0A=
1.5.6.4=0A=
=0A=

------=_NextPart_000_0018_01C94E6E.1BE8A3D0--




More information about the wine-patches mailing list