[PATCH 01/12] wined3d: Only allow 256 vertex shader vec4's.

Henri Verbeet hverbeet at codeweavers.com
Tue May 17 07:01:45 CDT 2016


Signed-off-by: Henri Verbeet <hverbeet at codeweavers.com>
---
 dlls/wined3d/arb_program_shader.c | 11 +++--------
 dlls/wined3d/device.c             |  4 ++--
 dlls/wined3d/glsl_shader.c        | 17 ++++++-----------
 dlls/wined3d/stateblock.c         | 26 +++-----------------------
 dlls/wined3d/wined3d_private.h    |  7 ++++---
 5 files changed, 18 insertions(+), 47 deletions(-)

diff --git a/dlls/wined3d/arb_program_shader.c b/dlls/wined3d/arb_program_shader.c
index 266f5f5..662a92f 100644
--- a/dlls/wined3d/arb_program_shader.c
+++ b/dlls/wined3d/arb_program_shader.c
@@ -303,7 +303,8 @@ struct shader_arb_priv
     DWORD ps_sig_number;
 
     unsigned int highest_dirty_ps_const, highest_dirty_vs_const;
-    char *vshader_const_dirty, *pshader_const_dirty;
+    char vshader_const_dirty[WINED3D_MAX_VS_CONSTS_F];
+    char *pshader_const_dirty;
     const struct wined3d_context *last_context;
 
     const struct wined3d_vertex_pipe_ops *vertex_pipe;
@@ -4998,10 +4999,6 @@ static HRESULT shader_arb_alloc(struct wined3d_device *device, const struct wine
         return E_FAIL;
     }
 
-    priv->vshader_const_dirty = HeapAlloc(GetProcessHeap(), 0,
-            sizeof(*priv->vshader_const_dirty) * d3d_info->limits.vs_uniform_count);
-    if (!priv->vshader_const_dirty)
-        goto fail;
     memset(priv->vshader_const_dirty, 1,
            sizeof(*priv->vshader_const_dirty) * d3d_info->limits.vs_uniform_count);
 
@@ -5031,7 +5028,6 @@ static HRESULT shader_arb_alloc(struct wined3d_device *device, const struct wine
 
 fail:
     HeapFree(GetProcessHeap(), 0, priv->pshader_const_dirty);
-    HeapFree(GetProcessHeap(), 0, priv->vshader_const_dirty);
     fragment_pipe->free_private(device);
     vertex_pipe->vp_free(device);
     HeapFree(GetProcessHeap(), 0, priv);
@@ -5075,7 +5071,6 @@ static void shader_arb_free(struct wined3d_device *device)
 
     wine_rb_destroy(&priv->signature_tree, release_signature, NULL);
     HeapFree(GetProcessHeap(), 0, priv->pshader_const_dirty);
-    HeapFree(GetProcessHeap(), 0, priv->vshader_const_dirty);
     priv->fragment_pipe->free_private(device);
     priv->vertex_pipe->vp_free(device);
     HeapFree(GetProcessHeap(), 0, device->shader_priv);
@@ -5133,7 +5128,7 @@ static void shader_arb_get_caps(const struct wined3d_gl_info *gl_info, struct sh
             TRACE("Hardware vertex shader version 1.1 enabled (ARB_PROGRAM)\n");
         }
         caps->vs_version = min(wined3d_settings.max_sm_vs, vs_version);
-        caps->vs_uniform_count = vs_consts;
+        caps->vs_uniform_count = min(WINED3D_MAX_VS_CONSTS_F, vs_consts);
     }
     else
     {
diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c
index d1f77ca..c9d1d8f 100644
--- a/dlls/wined3d/device.c
+++ b/dlls/wined3d/device.c
@@ -2485,8 +2485,8 @@ HRESULT CDECL wined3d_device_set_vs_consts_f(struct wined3d_device *device,
     }
 
     if (device->recording)
-        memset(&device->recording->changed.vertexShaderConstantsF[start_idx], 1,
-                count * sizeof(*device->recording->changed.vertexShaderConstantsF));
+        memset(&device->recording->changed.vs_consts_f[start_idx], 1,
+                count * sizeof(*device->recording->changed.vs_consts_f));
     else
         device->shader_backend->shader_update_float_vertex_constants(device, start_idx, count);
 
diff --git a/dlls/wined3d/glsl_shader.c b/dlls/wined3d/glsl_shader.c
index f8c4a99..842e983 100644
--- a/dlls/wined3d/glsl_shader.c
+++ b/dlls/wined3d/glsl_shader.c
@@ -117,7 +117,7 @@ struct glsl_vs_program
     struct list shader_entry;
     GLuint id;
     GLenum vertex_color_clamp;
-    GLint *uniform_f_locations;
+    GLint uniform_f_locations[WINED3D_MAX_VS_CONSTS_F];
     GLint uniform_i_locations[MAX_CONST_I];
     GLint uniform_b_locations[MAX_CONST_B];
     GLint pos_fixup_location;
@@ -5136,7 +5136,6 @@ static void delete_glsl_program_entry(struct shader_glsl_priv *priv, const struc
         list_remove(&entry->gs.shader_entry);
     if (entry->ps.id)
         list_remove(&entry->ps.shader_entry);
-    HeapFree(GetProcessHeap(), 0, entry->vs.uniform_f_locations);
     HeapFree(GetProcessHeap(), 0, entry->ps.uniform_f_locations);
     HeapFree(GetProcessHeap(), 0, entry);
 }
@@ -7014,15 +7013,12 @@ static void shader_glsl_init_vs_uniform_locations(const struct wined3d_gl_info *
     unsigned int i;
     struct wined3d_string_buffer *name = string_buffer_get(&priv->string_buffers);
 
-    vs->uniform_f_locations = HeapAlloc(GetProcessHeap(), 0,
-            sizeof(GLuint) * gl_info->limits.glsl_vs_float_constants);
     for (i = 0; i < vs_c_count; ++i)
     {
         string_buffer_sprintf(name, "vs_c[%u]", i);
         vs->uniform_f_locations[i] = GL_EXTCALL(glGetUniformLocation(program_id, name->buffer));
     }
-    memset(&vs->uniform_f_locations[vs_c_count], 0xff,
-            (gl_info->limits.glsl_vs_float_constants - vs_c_count) * sizeof(GLuint));
+    memset(&vs->uniform_f_locations[vs_c_count], 0xff, (WINED3D_MAX_VS_CONSTS_F - vs_c_count) * sizeof(GLuint));
 
     for (i = 0; i < MAX_CONST_I; ++i)
     {
@@ -7372,7 +7368,7 @@ static void set_glsl_shader_program(const struct wined3d_context *context, const
     shader_glsl_validate_link(gl_info, program_id);
 
     shader_glsl_init_vs_uniform_locations(gl_info, priv, program_id, &entry->vs,
-            vshader ? min(vshader->limits->constant_float, gl_info->limits.glsl_vs_float_constants) : 0);
+            vshader ? vshader->limits->constant_float : 0);
     shader_glsl_init_ps_uniform_locations(gl_info, priv, program_id, &entry->ps,
             pshader ? min(pshader->limits->constant_float, gl_info->limits.glsl_ps_float_constants) : 0);
     checkGLcall("Find glsl program uniform locations");
@@ -7933,8 +7929,7 @@ static HRESULT shader_glsl_alloc(struct wined3d_device *device, const struct win
 {
     const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
     struct shader_glsl_priv *priv = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct shader_glsl_priv));
-    SIZE_T stack_size = wined3d_log2i(max(gl_info->limits.glsl_vs_float_constants,
-            gl_info->limits.glsl_ps_float_constants)) + 1;
+    SIZE_T stack_size = wined3d_log2i(max(WINED3D_MAX_VS_CONSTS_F, gl_info->limits.glsl_ps_float_constants)) + 1;
     struct fragment_caps fragment_caps;
     void *vertex_priv, *fragment_priv;
 
@@ -7968,7 +7963,7 @@ static HRESULT shader_glsl_alloc(struct wined3d_device *device, const struct win
         goto fail;
     }
 
-    if (!constant_heap_init(&priv->vconst_heap, gl_info->limits.glsl_vs_float_constants))
+    if (!constant_heap_init(&priv->vconst_heap, WINED3D_MAX_VS_CONSTS_F))
     {
         ERR("Failed to initialize vertex shader constant heap\n");
         goto fail;
@@ -8089,7 +8084,7 @@ static void shader_glsl_get_caps(const struct wined3d_gl_info *gl_info, struct s
     caps->gs_version = min(wined3d_settings.max_sm_gs, shader_model);
     caps->ps_version = min(wined3d_settings.max_sm_ps, shader_model);
 
-    caps->vs_uniform_count = gl_info->limits.glsl_vs_float_constants;
+    caps->vs_uniform_count = min(WINED3D_MAX_VS_CONSTS_F, gl_info->limits.glsl_vs_float_constants);
     caps->ps_uniform_count = gl_info->limits.glsl_ps_float_constants;
     caps->varying_count = gl_info->limits.glsl_varyings;
 
diff --git a/dlls/wined3d/stateblock.c b/dlls/wined3d/stateblock.c
index 036d594..388b0c6 100644
--- a/dlls/wined3d/stateblock.c
+++ b/dlls/wined3d/stateblock.c
@@ -200,14 +200,6 @@ static HRESULT stateblock_allocate_shader_constants(struct wined3d_stateblock *o
             sizeof(BOOL) * d3d_info->limits.ps_uniform_count);
     if (!object->changed.pixelShaderConstantsF) goto fail;
 
-    object->changed.vertexShaderConstantsF = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
-            sizeof(BOOL) * d3d_info->limits.vs_uniform_count);
-    if (!object->changed.vertexShaderConstantsF) goto fail;
-
-    object->contained_vs_consts_f = HeapAlloc(GetProcessHeap(), 0,
-            sizeof(DWORD) * d3d_info->limits.vs_uniform_count);
-    if (!object->contained_vs_consts_f) goto fail;
-
     object->contained_ps_consts_f = HeapAlloc(GetProcessHeap(), 0,
             sizeof(DWORD) * d3d_info->limits.ps_uniform_count);
     if (!object->contained_ps_consts_f) goto fail;
@@ -217,8 +209,6 @@ static HRESULT stateblock_allocate_shader_constants(struct wined3d_stateblock *o
 fail:
     ERR("Failed to allocate memory\n");
     HeapFree(GetProcessHeap(), 0, object->changed.pixelShaderConstantsF);
-    HeapFree(GetProcessHeap(), 0, object->changed.vertexShaderConstantsF);
-    HeapFree(GetProcessHeap(), 0, object->contained_vs_consts_f);
     HeapFree(GetProcessHeap(), 0, object->contained_ps_consts_f);
     return E_OUTOFMEMORY;
 }
@@ -261,7 +251,7 @@ static void stateblock_savedstates_set_all(struct wined3d_saved_states *states,
 
     /* Dynamically sized arrays */
     memset(states->pixelShaderConstantsF, TRUE, sizeof(BOOL) * ps_consts);
-    memset(states->vertexShaderConstantsF, TRUE, sizeof(BOOL) * vs_consts);
+    memset(states->vs_consts_f, TRUE, sizeof(BOOL) * vs_consts);
 }
 
 static void stateblock_savedstates_set_pixel(struct wined3d_saved_states *states, const DWORD num_constants)
@@ -314,7 +304,7 @@ static void stateblock_savedstates_set_vertex(struct wined3d_saved_states *state
     states->vertexShaderConstantsB = 0xffff;
     states->vertexShaderConstantsI = 0xffff;
 
-    memset(states->vertexShaderConstantsF, TRUE, sizeof(BOOL) * num_constants);
+    memset(states->vs_consts_f, TRUE, sizeof(BOOL) * num_constants);
 }
 
 void stateblock_init_contained_states(struct wined3d_stateblock *stateblock)
@@ -348,7 +338,7 @@ void stateblock_init_contained_states(struct wined3d_stateblock *stateblock)
 
     for (i = 0; i < d3d_info->limits.vs_uniform_count; ++i)
     {
-        if (stateblock->changed.vertexShaderConstantsF[i])
+        if (stateblock->changed.vs_consts_f[i])
         {
             stateblock->contained_vs_consts_f[stateblock->num_contained_vs_consts_f] = i;
             ++stateblock->num_contained_vs_consts_f;
@@ -565,7 +555,6 @@ void state_cleanup(struct wined3d_state *state)
         }
     }
 
-    HeapFree(GetProcessHeap(), 0, state->vs_consts_f);
     HeapFree(GetProcessHeap(), 0, state->ps_consts_f);
 }
 
@@ -579,9 +568,7 @@ ULONG CDECL wined3d_stateblock_decref(struct wined3d_stateblock *stateblock)
     {
         state_cleanup(&stateblock->state);
 
-        HeapFree(GetProcessHeap(), 0, stateblock->changed.vertexShaderConstantsF);
         HeapFree(GetProcessHeap(), 0, stateblock->changed.pixelShaderConstantsF);
-        HeapFree(GetProcessHeap(), 0, stateblock->contained_vs_consts_f);
         HeapFree(GetProcessHeap(), 0, stateblock->contained_ps_consts_f);
         HeapFree(GetProcessHeap(), 0, stateblock);
     }
@@ -1310,16 +1297,9 @@ HRESULT state_init(struct wined3d_state *state, struct wined3d_fb_state *fb,
         list_init(&state->light_map[i]);
     }
 
-    if (!(state->vs_consts_f = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
-            sizeof(*state->vs_consts_f) * d3d_info->limits.vs_uniform_count)))
-        return E_OUTOFMEMORY;
-
     if (!(state->ps_consts_f = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
             sizeof(*state->ps_consts_f) * d3d_info->limits.ps_uniform_count)))
-    {
-        HeapFree(GetProcessHeap(), 0, state->vs_consts_f);
         return E_OUTOFMEMORY;
-    }
 
     if (flags & WINED3D_STATE_INIT_DEFAULT)
         state_init_default(state, gl_info);
diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h
index 274f620..9f6a2a3 100644
--- a/dlls/wined3d/wined3d_private.h
+++ b/dlls/wined3d/wined3d_private.h
@@ -513,6 +513,7 @@ enum wined3d_shader_rel_op
 #define MAX_CONST_I 16
 #define MAX_CONST_B 16
 #define WINED3D_MAX_CBS 15
+#define WINED3D_MAX_VS_CONSTS_F 256
 
 /* FIXME: This needs to go up to 2048 for
  * Shader model 3 according to msdn (and for software shaders) */
@@ -2211,7 +2212,7 @@ struct wined3d_state
 
     BOOL vs_consts_b[MAX_CONST_B];
     INT vs_consts_i[MAX_CONST_I * 4];
-    struct wined3d_vec4 *vs_consts_f;
+    struct wined3d_vec4 vs_consts_f[WINED3D_MAX_VS_CONSTS_F];
 
     BOOL ps_consts_b[MAX_CONST_B];
     INT ps_consts_i[MAX_CONST_I * 4];
@@ -2779,7 +2780,7 @@ struct wined3d_saved_states
     BOOL *pixelShaderConstantsF;
     WORD vertexShaderConstantsB;                /* MAX_CONST_B, 16 */
     WORD vertexShaderConstantsI;                /* MAX_CONST_I, 16 */
-    BOOL *vertexShaderConstantsF;
+    BOOL vs_consts_f[WINED3D_MAX_VS_CONSTS_F];
     DWORD textures : 20;                        /* MAX_COMBINED_SAMPLERS, 20 */
     DWORD primitive_type : 1;
     DWORD indices : 1;
@@ -2815,7 +2816,7 @@ struct wined3d_stateblock
     unsigned int              num_contained_vs_consts_i;
     DWORD                     contained_vs_consts_b[MAX_CONST_B];
     unsigned int              num_contained_vs_consts_b;
-    DWORD                     *contained_vs_consts_f;
+    DWORD                     contained_vs_consts_f[WINED3D_MAX_VS_CONSTS_F];
     unsigned int              num_contained_vs_consts_f;
     DWORD                     contained_ps_consts_i[MAX_CONST_I];
     unsigned int              num_contained_ps_consts_i;
-- 
2.1.4




More information about the wine-patches mailing list