wined3d: Use a bitmask to store which bool and int constants are set.

Henri Verbeet hverbeet at codeweavers.com
Tue Dec 2 11:41:33 CST 2008


Note that constants_set was never actually NULL for
shader_glsl_load_constantsB() and shader_glsl_load_constantsI().
---
 dlls/wined3d/device.c          |   28 ++++++++------
 dlls/wined3d/glsl_shader.c     |   80 +++++++++++++++++----------------------
 dlls/wined3d/stateblock.c      |   16 ++++----
 dlls/wined3d/wined3d_private.h |    8 ++--
 4 files changed, 63 insertions(+), 69 deletions(-)

diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c
index d9fda6e..4db3692 100644
--- a/dlls/wined3d/device.c
+++ b/dlls/wined3d/device.c
@@ -457,12 +457,12 @@ static HRESULT WINAPI IWineD3DDeviceImpl_CreateStateBlock(IWineD3DDevice* iface,
         object->num_contained_ps_consts_f = GL_LIMITS(pshader_constantsF);
         for (i = 0; i < MAX_CONST_B; ++i) {
             object->contained_ps_consts_b[i] = i;
-            object->changed.pixelShaderConstantsB[i] = TRUE;
+            object->changed.pixelShaderConstantsB |= (1 << i);
         }
         object->num_contained_ps_consts_b = MAX_CONST_B;
         for (i = 0; i < MAX_CONST_I; ++i) {
             object->contained_ps_consts_i[i] = i;
-            object->changed.pixelShaderConstantsI[i] = TRUE;
+            object->changed.pixelShaderConstantsI |= (1 << i);
         }
         object->num_contained_ps_consts_i = MAX_CONST_I;
 
@@ -514,13 +514,13 @@ static HRESULT WINAPI IWineD3DDeviceImpl_CreateStateBlock(IWineD3DDevice* iface,
         }
         object->num_contained_vs_consts_f = GL_LIMITS(vshader_constantsF);
         for (i = 0; i < MAX_CONST_B; ++i) {
-            object->changed.vertexShaderConstantsB[i] = TRUE;
             object->contained_vs_consts_b[i] = i;
+            object->changed.vertexShaderConstantsB |= (1 << i);
         }
         object->num_contained_vs_consts_b = MAX_CONST_B;
         for (i = 0; i < MAX_CONST_I; ++i) {
-            object->changed.vertexShaderConstantsI[i] = TRUE;
             object->contained_vs_consts_i[i] = i;
+            object->changed.vertexShaderConstantsI |= (1 << i);
         }
         object->num_contained_vs_consts_i = MAX_CONST_I;
         for (i = 0; i < NUM_SAVEDVERTEXSTATES_R; i++) {
@@ -3538,7 +3538,7 @@ static HRESULT WINAPI IWineD3DDeviceImpl_SetVertexShaderConstantB(
         TRACE("Set BOOL constant %u to %s\n", start + i, srcData[i]? "true":"false");
 
     for (i = start; i < cnt + start; ++i) {
-        This->updateStateBlock->changed.vertexShaderConstantsB[i] = TRUE;
+        This->updateStateBlock->changed.vertexShaderConstantsB |= (1 << i);
     }
 
     IWineD3DDeviceImpl_MarkStateDirty(This, STATE_VERTEXSHADERCONSTANT);
@@ -3586,7 +3586,7 @@ static HRESULT WINAPI IWineD3DDeviceImpl_SetVertexShaderConstantI(
            srcData[i*4], srcData[i*4+1], srcData[i*4+2], srcData[i*4+3]);
 
     for (i = start; i < cnt + start; ++i) {
-        This->updateStateBlock->changed.vertexShaderConstantsI[i] = TRUE;
+        This->updateStateBlock->changed.vertexShaderConstantsI |= (1 << i);
     }
 
     IWineD3DDeviceImpl_MarkStateDirty(This, STATE_VERTEXSHADERCONSTANT);
@@ -3971,7 +3971,7 @@ static HRESULT WINAPI IWineD3DDeviceImpl_SetPixelShaderConstantB(
         TRACE("Set BOOL constant %u to %s\n", start + i, srcData[i]? "true":"false");
 
     for (i = start; i < cnt + start; ++i) {
-        This->updateStateBlock->changed.pixelShaderConstantsB[i] = TRUE;
+        This->updateStateBlock->changed.pixelShaderConstantsB |= (1 << i);
     }
 
     IWineD3DDeviceImpl_MarkStateDirty(This, STATE_PIXELSHADERCONSTANT);
@@ -4019,7 +4019,7 @@ static HRESULT WINAPI IWineD3DDeviceImpl_SetPixelShaderConstantI(
            srcData[i*4], srcData[i*4+1], srcData[i*4+2], srcData[i*4+3]);
 
     for (i = start; i < cnt + start; ++i) {
-        This->updateStateBlock->changed.pixelShaderConstantsI[i] = TRUE;
+        This->updateStateBlock->changed.pixelShaderConstantsI |= (1 << i);
     }
 
     IWineD3DDeviceImpl_MarkStateDirty(This, STATE_PIXELSHADERCONSTANT);
@@ -4903,25 +4903,29 @@ static HRESULT WINAPI IWineD3DDeviceImpl_EndStateBlock(IWineD3DDevice *iface, IW
         }
     }
     for(i = 0; i < MAX_CONST_I; i++) {
-        if(object->changed.vertexShaderConstantsI[i]) {
+        if (object->changed.vertexShaderConstantsI & (1 << i))
+        {
             object->contained_vs_consts_i[object->num_contained_vs_consts_i] = i;
             object->num_contained_vs_consts_i++;
         }
     }
     for(i = 0; i < MAX_CONST_B; i++) {
-        if(object->changed.vertexShaderConstantsB[i]) {
+        if (object->changed.vertexShaderConstantsB & (1 << i))
+        {
             object->contained_vs_consts_b[object->num_contained_vs_consts_b] = i;
             object->num_contained_vs_consts_b++;
         }
     }
     for(i = 0; i < MAX_CONST_I; i++) {
-        if(object->changed.pixelShaderConstantsI[i]) {
+        if (object->changed.pixelShaderConstantsI & (1 << i))
+        {
             object->contained_ps_consts_i[object->num_contained_ps_consts_i] = i;
             object->num_contained_ps_consts_i++;
         }
     }
     for(i = 0; i < MAX_CONST_B; i++) {
-        if(object->changed.pixelShaderConstantsB[i]) {
+        if (object->changed.pixelShaderConstantsB & (1 << i))
+        {
             object->contained_ps_consts_b[object->num_contained_ps_consts_b] = i;
             object->num_contained_ps_consts_b++;
         }
diff --git a/dlls/wined3d/glsl_shader.c b/dlls/wined3d/glsl_shader.c
index 8f9ec16..16e8f27 100644
--- a/dlls/wined3d/glsl_shader.c
+++ b/dlls/wined3d/glsl_shader.c
@@ -291,27 +291,23 @@ static void shader_glsl_load_constantsF(IWineD3DBaseShaderImpl *This, const Wine
     checkGLcall("glUniform4fvARB()");
 }
 
-/** 
- * Loads integer constants (aka uniforms) into the currently set GLSL program.
- * When @constants_set == NULL, it will load all the constants.
- */
+/* Loads integer constants (aka uniforms) into the currently set GLSL program. */
 static void shader_glsl_load_constantsI(IWineD3DBaseShaderImpl *This, const WineD3D_GL_Info *gl_info,
-        GLhandleARB programId, const GLhandleARB locations[MAX_CONST_I], unsigned int max_constants,
-        const int *constants, const BOOL *constants_set)
+        const GLhandleARB locations[MAX_CONST_I], const int *constants, WORD constants_set)
 {
     unsigned int i;
     struct list* ptr;
 
-    for (i=0; i<max_constants; ++i) {
-        if (NULL == constants_set || constants_set[i]) {
+    for (i = 0; constants_set; constants_set >>= 1, ++i)
+    {
+        if (!(constants_set & 1)) continue;
 
-            TRACE_(d3d_constants)("Loading constants %u: %i, %i, %i, %i\n",
-                  i, constants[i*4], constants[i*4+1], constants[i*4+2], constants[i*4+3]);
+        TRACE_(d3d_constants)("Loading constants %u: %i, %i, %i, %i\n",
+                i, constants[i*4], constants[i*4+1], constants[i*4+2], constants[i*4+3]);
 
-            /* We found this uniform name in the program - go ahead and send the data */
-            GL_EXTCALL(glUniform4ivARB(locations[i], 1, &constants[i*4]));
-            checkGLcall("glUniform4ivARB");
-        }
+        /* We found this uniform name in the program - go ahead and send the data */
+        GL_EXTCALL(glUniform4ivARB(locations[i], 1, &constants[i*4]));
+        checkGLcall("glUniform4ivARB");
     }
 
     /* Load immediate constants */
@@ -331,12 +327,9 @@ static void shader_glsl_load_constantsI(IWineD3DBaseShaderImpl *This, const Wine
     }
 }
 
-/** 
- * Loads boolean constants (aka uniforms) into the currently set GLSL program.
- * When @constants_set == NULL, it will load all the constants.
- */
+/* Loads boolean constants (aka uniforms) into the currently set GLSL program. */
 static void shader_glsl_load_constantsB(IWineD3DBaseShaderImpl *This, const WineD3D_GL_Info *gl_info,
-        GLhandleARB programId, unsigned int max_constants, const BOOL *constants, const BOOL *constants_set)
+        GLhandleARB programId, const BOOL *constants, WORD constants_set)
 {
     GLhandleARB tmp_loc;
     unsigned int i;
@@ -345,20 +338,23 @@ static void shader_glsl_load_constantsB(IWineD3DBaseShaderImpl *This, const Wine
     const char* prefix = is_pshader? "PB":"VB";
     struct list* ptr;
 
-    for (i=0; i<max_constants; ++i) {
-        if (NULL == constants_set || constants_set[i]) {
+    /* TODO: Benchmark and see if it would be beneficial to store the 
+     * locations of the constants to avoid looking up each time */
+    for (i = 0; constants_set; constants_set >>= 1, ++i)
+    {
+        if (!(constants_set & 1)) continue;
 
-            TRACE_(d3d_constants)("Loading constants %u: %i;\n", i, constants[i]);
+        TRACE_(d3d_constants)("Loading constants %i: %i;\n", i, constants[i]);
 
-            /* TODO: Benchmark and see if it would be beneficial to store the 
-             * locations of the constants to avoid looking up each time */
-            snprintf(tmp_name, sizeof(tmp_name), "%s[%u]", prefix, i);
-            tmp_loc = GL_EXTCALL(glGetUniformLocationARB(programId, tmp_name));
-            if (tmp_loc != -1) {
-                /* We found this uniform name in the program - go ahead and send the data */
-                GL_EXTCALL(glUniform1ivARB(tmp_loc, 1, &constants[i]));
-                checkGLcall("glUniform1ivARB");
-            }
+        /* TODO: Benchmark and see if it would be beneficial to store the 
+         * locations of the constants to avoid looking up each time */
+        snprintf(tmp_name, sizeof(tmp_name), "%s[%i]", prefix, i);
+        tmp_loc = GL_EXTCALL(glGetUniformLocationARB(programId, tmp_name));
+        if (tmp_loc != -1)
+        {
+            /* We found this uniform name in the program - go ahead and send the data */
+            GL_EXTCALL(glUniform1ivARB(tmp_loc, 1, &constants[i]));
+            checkGLcall("glUniform1ivARB");
         }
     }
 
@@ -420,15 +416,12 @@ static void shader_glsl_load_constants(
                 stateBlock->vertexShaderConstantF, constant_locations, constant_list);
 
         /* Load DirectX 9 integer constants/uniforms for vertex shader */
-        shader_glsl_load_constantsI(vshader, gl_info, programId,
-                                    prog->vuniformI_locations, MAX_CONST_I,
-                                    stateBlock->vertexShaderConstantI,
-                                    stateBlock->changed.vertexShaderConstantsI);
+        shader_glsl_load_constantsI(vshader, gl_info, prog->vuniformI_locations,
+                stateBlock->vertexShaderConstantI, stateBlock->changed.vertexShaderConstantsI);
 
         /* Load DirectX 9 boolean constants/uniforms for vertex shader */
-        shader_glsl_load_constantsB(vshader, gl_info, programId, MAX_CONST_B,
-                                    stateBlock->vertexShaderConstantB,
-                                    stateBlock->changed.vertexShaderConstantsB);
+        shader_glsl_load_constantsB(vshader, gl_info, programId,
+                stateBlock->vertexShaderConstantB, stateBlock->changed.vertexShaderConstantsB);
 
         /* Upload the position fixup params */
         GL_EXTCALL(glUniform4fvARB(prog->posFixup_location, 1, &deviceImpl->posFixup[0]));
@@ -447,15 +440,12 @@ static void shader_glsl_load_constants(
                 stateBlock->pixelShaderConstantF, constant_locations, constant_list);
 
         /* Load DirectX 9 integer constants/uniforms for pixel shader */
-        shader_glsl_load_constantsI(pshader, gl_info, programId,
-                                    prog->puniformI_locations, MAX_CONST_I,
-                                    stateBlock->pixelShaderConstantI, 
-                                    stateBlock->changed.pixelShaderConstantsI);
+        shader_glsl_load_constantsI(pshader, gl_info, prog->puniformI_locations,
+                stateBlock->pixelShaderConstantI, stateBlock->changed.pixelShaderConstantsI);
 
         /* Load DirectX 9 boolean constants/uniforms for pixel shader */
-        shader_glsl_load_constantsB(pshader, gl_info, programId, MAX_CONST_B,
-                                    stateBlock->pixelShaderConstantB, 
-                                    stateBlock->changed.pixelShaderConstantsB);
+        shader_glsl_load_constantsB(pshader, gl_info, programId,
+                stateBlock->pixelShaderConstantB, stateBlock->changed.pixelShaderConstantsB);
 
         /* Upload the environment bump map matrix if needed. The needsbumpmat member specifies the texture stage to load the matrix from.
          * It can't be 0 for a valid texbem instruction.
diff --git a/dlls/wined3d/stateblock.c b/dlls/wined3d/stateblock.c
index c5859d4..3faa5a0 100644
--- a/dlls/wined3d/stateblock.c
+++ b/dlls/wined3d/stateblock.c
@@ -87,10 +87,10 @@ static void stateblock_savedstates_copy(IWineD3DStateBlock* iface, SAVEDSTATES *
     memcpy(dest->textureState, source->textureState, bsize * MAX_TEXTURES * (WINED3D_HIGHEST_TEXTURE_STATE + 1));
     memcpy(dest->samplerState, source->samplerState, bsize * MAX_COMBINED_SAMPLERS * (WINED3D_HIGHEST_SAMPLER_STATE + 1));
     memcpy(dest->clipplane, source->clipplane, bsize * MAX_CLIPPLANES);
-    memcpy(dest->pixelShaderConstantsB, source->pixelShaderConstantsB, bsize * MAX_CONST_B);
-    memcpy(dest->pixelShaderConstantsI, source->pixelShaderConstantsI, bsize * MAX_CONST_I);
-    memcpy(dest->vertexShaderConstantsB, source->vertexShaderConstantsB, bsize * MAX_CONST_B);
-    memcpy(dest->vertexShaderConstantsI, source->vertexShaderConstantsI, bsize * MAX_CONST_I);
+    dest->pixelShaderConstantsB = source->pixelShaderConstantsB;
+    dest->pixelShaderConstantsI = source->pixelShaderConstantsI;
+    dest->vertexShaderConstantsB = source->vertexShaderConstantsB;
+    dest->vertexShaderConstantsI = source->vertexShaderConstantsI;
 
     /* Dynamically sized arrays */
     memcpy(dest->pixelShaderConstantsF, source->pixelShaderConstantsF, bsize * GL_LIMITS(pshader_constantsF));
@@ -125,10 +125,10 @@ void stateblock_savedstates_set(
     memset(states->textureState, value, bsize * MAX_TEXTURES * (WINED3D_HIGHEST_TEXTURE_STATE + 1));
     memset(states->samplerState, value, bsize * MAX_COMBINED_SAMPLERS * (WINED3D_HIGHEST_SAMPLER_STATE + 1));
     memset(states->clipplane, value, bsize * MAX_CLIPPLANES);
-    memset(states->pixelShaderConstantsB, value, bsize * MAX_CONST_B);
-    memset(states->pixelShaderConstantsI, value, bsize * MAX_CONST_I);
-    memset(states->vertexShaderConstantsB, value, bsize * MAX_CONST_B);
-    memset(states->vertexShaderConstantsI, value, bsize * MAX_CONST_I);
+    states->pixelShaderConstantsB = value ? 0xffff : 0;
+    states->pixelShaderConstantsI = value ? 0xffff : 0;
+    states->vertexShaderConstantsB = value ? 0xffff : 0;
+    states->vertexShaderConstantsI = value ? 0xffff : 0;
 
     /* Dynamically sized arrays */
     memset(states->pixelShaderConstantsF, value, bsize * GL_LIMITS(pshader_constantsF));
diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h
index dfbe6c7..0ad75c9 100644
--- a/dlls/wined3d/wined3d_private.h
+++ b/dlls/wined3d/wined3d_private.h
@@ -1662,12 +1662,12 @@ typedef struct SAVEDSTATES {
         BOOL                      clipplane[MAX_CLIPPLANES];
         BOOL                      vertexDecl;
         BOOL                      pixelShader;
-        BOOL                      pixelShaderConstantsB[MAX_CONST_B];
-        BOOL                      pixelShaderConstantsI[MAX_CONST_I];
+        WORD                      pixelShaderConstantsB;
+        WORD                      pixelShaderConstantsI;
         BOOL                     *pixelShaderConstantsF;
         BOOL                      vertexShader;
-        BOOL                      vertexShaderConstantsB[MAX_CONST_B];
-        BOOL                      vertexShaderConstantsI[MAX_CONST_I];
+        WORD                      vertexShaderConstantsB;
+        WORD                      vertexShaderConstantsI;
         BOOL                     *vertexShaderConstantsF;
         BOOL                      scissorRect;
 } SAVEDSTATES;
-- 
1.5.6.4



--------------060107090806030202070606--



More information about the wine-patches mailing list