[PATCH 02/12] wined3d: Only allow 224 pixel shader vec4's.

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


Signed-off-by: Henri Verbeet <hverbeet at codeweavers.com>
---
 dlls/wined3d/arb_program_shader.c | 24 +++++------------
 dlls/wined3d/cs.c                 | 15 +++--------
 dlls/wined3d/device.c             | 17 +++++-------
 dlls/wined3d/glsl_shader.c        | 16 +++++-------
 dlls/wined3d/stateblock.c         | 54 ++++-----------------------------------
 dlls/wined3d/wined3d_private.h    |  9 ++++---
 6 files changed, 33 insertions(+), 102 deletions(-)

diff --git a/dlls/wined3d/arb_program_shader.c b/dlls/wined3d/arb_program_shader.c
index 662a92f..9b93478 100644
--- a/dlls/wined3d/arb_program_shader.c
+++ b/dlls/wined3d/arb_program_shader.c
@@ -304,7 +304,7 @@ struct shader_arb_priv
 
     unsigned int highest_dirty_ps_const, highest_dirty_vs_const;
     char vshader_const_dirty[WINED3D_MAX_VS_CONSTS_F];
-    char *pshader_const_dirty;
+    char pshader_const_dirty[WINED3D_MAX_PS_CONSTS_F];
     const struct wined3d_context *last_context;
 
     const struct wined3d_vertex_pipe_ops *vertex_pipe;
@@ -5001,18 +5001,16 @@ static HRESULT shader_arb_alloc(struct wined3d_device *device, const struct wine
 
     memset(priv->vshader_const_dirty, 1,
            sizeof(*priv->vshader_const_dirty) * d3d_info->limits.vs_uniform_count);
-
-    priv->pshader_const_dirty = HeapAlloc(GetProcessHeap(), 0,
-            sizeof(*priv->pshader_const_dirty) * d3d_info->limits.ps_uniform_count);
-    if (!priv->pshader_const_dirty)
-        goto fail;
     memset(priv->pshader_const_dirty, 1,
             sizeof(*priv->pshader_const_dirty) * d3d_info->limits.ps_uniform_count);
 
-    if(wine_rb_init(&priv->signature_tree, &sig_tree_functions) == -1)
+    if (wine_rb_init(&priv->signature_tree, &sig_tree_functions) == -1)
     {
         ERR("RB tree init failed\n");
-        goto fail;
+        fragment_pipe->free_private(device);
+        vertex_pipe->vp_free(device);
+        HeapFree(GetProcessHeap(), 0, priv);
+        return E_OUTOFMEMORY;
     }
 
     priv->vertex_pipe = vertex_pipe;
@@ -5025,13 +5023,6 @@ static HRESULT shader_arb_alloc(struct wined3d_device *device, const struct wine
     device->shader_priv = priv;
 
     return WINED3D_OK;
-
-fail:
-    HeapFree(GetProcessHeap(), 0, priv->pshader_const_dirty);
-    fragment_pipe->free_private(device);
-    vertex_pipe->vp_free(device);
-    HeapFree(GetProcessHeap(), 0, priv);
-    return E_OUTOFMEMORY;
 }
 
 static void release_signature(struct wine_rb_entry *entry, void *context)
@@ -5070,7 +5061,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);
     priv->fragment_pipe->free_private(device);
     priv->vertex_pipe->vp_free(device);
     HeapFree(GetProcessHeap(), 0, device->shader_priv);
@@ -5169,7 +5159,7 @@ static void shader_arb_get_caps(const struct wined3d_gl_info *gl_info, struct sh
             TRACE("Hardware pixel shader version 1.4 enabled (ARB_PROGRAM)\n");
         }
         caps->ps_version = min(wined3d_settings.max_sm_ps, ps_version);
-        caps->ps_uniform_count = ps_consts;
+        caps->ps_uniform_count = min(WINED3D_MAX_PS_CONSTS_F, ps_consts);
         caps->ps_1x_max_value = 8.0f;
     }
     else
diff --git a/dlls/wined3d/cs.c b/dlls/wined3d/cs.c
index 2e5a3a6..ea4778c 100644
--- a/dlls/wined3d/cs.c
+++ b/dlls/wined3d/cs.c
@@ -999,13 +999,11 @@ void wined3d_cs_emit_set_material(struct wined3d_cs *cs, const struct wined3d_ma
 static void wined3d_cs_exec_reset_state(struct wined3d_cs *cs, const void *data)
 {
     struct wined3d_adapter *adapter = cs->device->adapter;
-    HRESULT hr;
 
     state_cleanup(&cs->state);
     memset(&cs->state, 0, sizeof(cs->state));
-    if (FAILED(hr = state_init(&cs->state, &cs->fb, &adapter->gl_info, &adapter->d3d_info,
-            WINED3D_STATE_NO_REF | WINED3D_STATE_INIT_DEFAULT)))
-        ERR("Failed to initialize CS state, hr %#x.\n", hr);
+    state_init(&cs->state, &cs->fb, &adapter->gl_info, &adapter->d3d_info,
+            WINED3D_STATE_NO_REF | WINED3D_STATE_INIT_DEFAULT);
 }
 
 void wined3d_cs_emit_reset_state(struct wined3d_cs *cs)
@@ -1093,13 +1091,8 @@ struct wined3d_cs *wined3d_cs_create(struct wined3d_device *device)
         return NULL;
     }
 
-    if (FAILED(state_init(&cs->state, &cs->fb, gl_info, &device->adapter->d3d_info,
-            WINED3D_STATE_NO_REF | WINED3D_STATE_INIT_DEFAULT)))
-    {
-        HeapFree(GetProcessHeap(), 0, cs->fb.render_targets);
-        HeapFree(GetProcessHeap(), 0, cs);
-        return NULL;
-    }
+    state_init(&cs->state, &cs->fb, gl_info, &device->adapter->d3d_info,
+            WINED3D_STATE_NO_REF | WINED3D_STATE_INIT_DEFAULT);
 
     cs->ops = &wined3d_cs_st_ops;
     cs->device = device;
diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c
index c9d1d8f..6b03d75 100644
--- a/dlls/wined3d/device.c
+++ b/dlls/wined3d/device.c
@@ -2713,8 +2713,8 @@ HRESULT CDECL wined3d_device_set_ps_consts_f(struct wined3d_device *device,
     }
 
     if (device->recording)
-        memset(&device->recording->changed.pixelShaderConstantsF[start_idx], 1,
-                count * sizeof(*device->recording->changed.pixelShaderConstantsF));
+        memset(&device->recording->changed.ps_consts_f[start_idx], 1,
+                count * sizeof(*device->recording->changed.ps_consts_f));
     else
         device->shader_backend->shader_update_float_pixel_constants(device, start_idx, count);
 
@@ -4887,9 +4887,8 @@ HRESULT CDECL wined3d_device_reset(struct wined3d_device *device,
         if (device->d3d_initialized)
             delete_opengl_contexts(device, swapchain);
 
-        if (FAILED(hr = state_init(&device->state, &device->fb, &device->adapter->gl_info,
-                &device->adapter->d3d_info, WINED3D_STATE_INIT_DEFAULT)))
-            ERR("Failed to initialize device state, hr %#x.\n", hr);
+        state_init(&device->state, &device->fb, &device->adapter->gl_info,
+                &device->adapter->d3d_info, WINED3D_STATE_INIT_DEFAULT);
         device->update_state = &device->state;
 
         device_init_swapchain_state(device, swapchain);
@@ -5143,12 +5142,8 @@ HRESULT device_init(struct wined3d_device *device, struct wined3d *wined3d,
 
     device->blitter = adapter->blitter;
 
-    if (FAILED(hr = state_init(&device->state, &device->fb, &adapter->gl_info,
-            &adapter->d3d_info, WINED3D_STATE_INIT_DEFAULT)))
-    {
-        ERR("Failed to initialize device state, hr %#x.\n", hr);
-        goto err;
-    }
+    state_init(&device->state, &device->fb, &adapter->gl_info,
+            &adapter->d3d_info, WINED3D_STATE_INIT_DEFAULT);
     device->update_state = &device->state;
 
     if (!(device->cs = wined3d_cs_create(device)))
diff --git a/dlls/wined3d/glsl_shader.c b/dlls/wined3d/glsl_shader.c
index 842e983..a360df8 100644
--- a/dlls/wined3d/glsl_shader.c
+++ b/dlls/wined3d/glsl_shader.c
@@ -165,7 +165,7 @@ struct glsl_ps_program
 {
     struct list shader_entry;
     GLuint id;
-    GLint *uniform_f_locations;
+    GLint uniform_f_locations[WINED3D_MAX_PS_CONSTS_F];
     GLint uniform_i_locations[MAX_CONST_I];
     GLint uniform_b_locations[MAX_CONST_B];
     GLint bumpenv_mat_location[MAX_TEXTURES];
@@ -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->ps.uniform_f_locations);
     HeapFree(GetProcessHeap(), 0, entry);
 }
 
@@ -7095,15 +7094,12 @@ static void shader_glsl_init_ps_uniform_locations(const struct wined3d_gl_info *
     unsigned int i;
     struct wined3d_string_buffer *name = string_buffer_get(&priv->string_buffers);
 
-    ps->uniform_f_locations = HeapAlloc(GetProcessHeap(), 0,
-            sizeof(GLuint) * gl_info->limits.glsl_ps_float_constants);
     for (i = 0; i < ps_c_count; ++i)
     {
         string_buffer_sprintf(name, "ps_c[%u]", i);
         ps->uniform_f_locations[i] = GL_EXTCALL(glGetUniformLocation(program_id, name->buffer));
     }
-    memset(&ps->uniform_f_locations[ps_c_count], 0xff,
-            (gl_info->limits.glsl_ps_float_constants - ps_c_count) * sizeof(GLuint));
+    memset(&ps->uniform_f_locations[ps_c_count], 0xff, (WINED3D_MAX_PS_CONSTS_F - ps_c_count) * sizeof(GLuint));
 
     for (i = 0; i < MAX_CONST_I; ++i)
     {
@@ -7370,7 +7366,7 @@ static void set_glsl_shader_program(const struct wined3d_context *context, const
     shader_glsl_init_vs_uniform_locations(gl_info, priv, program_id, &entry->vs,
             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);
+            pshader ? pshader->limits->constant_float : 0);
     checkGLcall("Find glsl program uniform locations");
 
     if (gl_info->supported[WINED3D_GL_LEGACY_CONTEXT])
@@ -7929,7 +7925,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(WINED3D_MAX_VS_CONSTS_F, gl_info->limits.glsl_ps_float_constants)) + 1;
+    SIZE_T stack_size = wined3d_log2i(max(WINED3D_MAX_VS_CONSTS_F, WINED3D_MAX_PS_CONSTS_F)) + 1;
     struct fragment_caps fragment_caps;
     void *vertex_priv, *fragment_priv;
 
@@ -7969,7 +7965,7 @@ static HRESULT shader_glsl_alloc(struct wined3d_device *device, const struct win
         goto fail;
     }
 
-    if (!constant_heap_init(&priv->pconst_heap, gl_info->limits.glsl_ps_float_constants))
+    if (!constant_heap_init(&priv->pconst_heap, WINED3D_MAX_PS_CONSTS_F))
     {
         ERR("Failed to initialize pixel shader constant heap\n");
         goto fail;
@@ -8085,7 +8081,7 @@ static void shader_glsl_get_caps(const struct wined3d_gl_info *gl_info, struct s
     caps->ps_version = min(wined3d_settings.max_sm_ps, shader_model);
 
     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->ps_uniform_count = min(WINED3D_MAX_PS_CONSTS_F, gl_info->limits.glsl_ps_float_constants);
     caps->varying_count = gl_info->limits.glsl_varyings;
 
     /* FIXME: The following line is card dependent. -8.0 to 8.0 is the
diff --git a/dlls/wined3d/stateblock.c b/dlls/wined3d/stateblock.c
index 388b0c6..2b45d9c 100644
--- a/dlls/wined3d/stateblock.c
+++ b/dlls/wined3d/stateblock.c
@@ -189,30 +189,6 @@ static const DWORD vertex_states_sampler[] =
     WINED3D_SAMP_DMAP_OFFSET,
 };
 
-/* Allocates the correct amount of space for pixel and vertex shader constants,
- * along with their set/changed flags on the given stateblock object
- */
-static HRESULT stateblock_allocate_shader_constants(struct wined3d_stateblock *object)
-{
-    const struct wined3d_d3d_info *d3d_info = &object->device->adapter->d3d_info;
-
-    object->changed.pixelShaderConstantsF = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
-            sizeof(BOOL) * d3d_info->limits.ps_uniform_count);
-    if (!object->changed.pixelShaderConstantsF) 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;
-
-    return WINED3D_OK;
-
-fail:
-    ERR("Failed to allocate memory\n");
-    HeapFree(GetProcessHeap(), 0, object->changed.pixelShaderConstantsF);
-    HeapFree(GetProcessHeap(), 0, object->contained_ps_consts_f);
-    return E_OUTOFMEMORY;
-}
-
 static inline void stateblock_set_bits(DWORD *map, UINT map_size)
 {
     DWORD mask = (1u << (map_size & 0x1f)) - 1;
@@ -250,7 +226,7 @@ static void stateblock_savedstates_set_all(struct wined3d_saved_states *states,
     states->vertexShaderConstantsI = 0xffff;
 
     /* Dynamically sized arrays */
-    memset(states->pixelShaderConstantsF, TRUE, sizeof(BOOL) * ps_consts);
+    memset(states->ps_consts_f, TRUE, sizeof(BOOL) * ps_consts);
     memset(states->vs_consts_f, TRUE, sizeof(BOOL) * vs_consts);
 }
 
@@ -277,7 +253,7 @@ static void stateblock_savedstates_set_pixel(struct wined3d_saved_states *states
     states->pixelShaderConstantsB = 0xffff;
     states->pixelShaderConstantsI = 0xffff;
 
-    memset(states->pixelShaderConstantsF, TRUE, sizeof(BOOL) * num_constants);
+    memset(states->ps_consts_f, TRUE, sizeof(BOOL) * num_constants);
 }
 
 static void stateblock_savedstates_set_vertex(struct wined3d_saved_states *states, const DWORD num_constants)
@@ -365,7 +341,7 @@ void stateblock_init_contained_states(struct wined3d_stateblock *stateblock)
 
     for (i = 0; i < d3d_info->limits.ps_uniform_count; ++i)
     {
-        if (stateblock->changed.pixelShaderConstantsF[i])
+        if (stateblock->changed.ps_consts_f[i])
         {
             stateblock->contained_ps_consts_f[stateblock->num_contained_ps_consts_f] = i;
             ++stateblock->num_contained_ps_consts_f;
@@ -554,8 +530,6 @@ void state_cleanup(struct wined3d_state *state)
             HeapFree(GetProcessHeap(), 0, light);
         }
     }
-
-    HeapFree(GetProcessHeap(), 0, state->ps_consts_f);
 }
 
 ULONG CDECL wined3d_stateblock_decref(struct wined3d_stateblock *stateblock)
@@ -567,9 +541,6 @@ ULONG CDECL wined3d_stateblock_decref(struct wined3d_stateblock *stateblock)
     if (!refcount)
     {
         state_cleanup(&stateblock->state);
-
-        HeapFree(GetProcessHeap(), 0, stateblock->changed.pixelShaderConstantsF);
-        HeapFree(GetProcessHeap(), 0, stateblock->contained_ps_consts_f);
         HeapFree(GetProcessHeap(), 0, stateblock);
     }
 
@@ -1283,7 +1254,7 @@ static void state_init_default(struct wined3d_state *state, const struct wined3d
     }
 }
 
-HRESULT state_init(struct wined3d_state *state, struct wined3d_fb_state *fb,
+void state_init(struct wined3d_state *state, struct wined3d_fb_state *fb,
         const struct wined3d_gl_info *gl_info, const struct wined3d_d3d_info *d3d_info,
         DWORD flags)
 {
@@ -1297,33 +1268,18 @@ HRESULT state_init(struct wined3d_state *state, struct wined3d_fb_state *fb,
         list_init(&state->light_map[i]);
     }
 
-    if (!(state->ps_consts_f = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
-            sizeof(*state->ps_consts_f) * d3d_info->limits.ps_uniform_count)))
-        return E_OUTOFMEMORY;
-
     if (flags & WINED3D_STATE_INIT_DEFAULT)
         state_init_default(state, gl_info);
-
-    return WINED3D_OK;
 }
 
 static HRESULT stateblock_init(struct wined3d_stateblock *stateblock,
         struct wined3d_device *device, enum wined3d_stateblock_type type)
 {
-    HRESULT hr;
     const struct wined3d_d3d_info *d3d_info = &device->adapter->d3d_info;
 
     stateblock->ref = 1;
     stateblock->device = device;
-
-    if (FAILED(hr = state_init(&stateblock->state, NULL, &device->adapter->gl_info, d3d_info, 0)))
-        return hr;
-
-    if (FAILED(hr = stateblock_allocate_shader_constants(stateblock)))
-    {
-        state_cleanup(&stateblock->state);
-        return hr;
-    }
+    state_init(&stateblock->state, NULL, &device->adapter->gl_info, d3d_info, 0);
 
     if (type == WINED3D_SBT_RECORDED)
         return WINED3D_OK;
diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h
index 9f6a2a3..d69fbec 100644
--- a/dlls/wined3d/wined3d_private.h
+++ b/dlls/wined3d/wined3d_private.h
@@ -514,6 +514,7 @@ enum wined3d_shader_rel_op
 #define MAX_CONST_B 16
 #define WINED3D_MAX_CBS 15
 #define WINED3D_MAX_VS_CONSTS_F 256
+#define WINED3D_MAX_PS_CONSTS_F 224
 
 /* FIXME: This needs to go up to 2048 for
  * Shader model 3 according to msdn (and for software shaders) */
@@ -2216,7 +2217,7 @@ struct wined3d_state
 
     BOOL ps_consts_b[MAX_CONST_B];
     INT ps_consts_i[MAX_CONST_I * 4];
-    struct wined3d_vec4 *ps_consts_f;
+    struct wined3d_vec4 ps_consts_f[WINED3D_MAX_PS_CONSTS_F];
 
     struct wined3d_texture *textures[MAX_COMBINED_SAMPLERS];
     DWORD sampler_states[MAX_COMBINED_SAMPLERS][WINED3D_HIGHEST_SAMPLER_STATE + 1];
@@ -2777,7 +2778,7 @@ struct wined3d_saved_states
     DWORD clipplane;                            /* WINED3DMAXUSERCLIPPLANES, 32 */
     WORD pixelShaderConstantsB;                 /* MAX_CONST_B, 16 */
     WORD pixelShaderConstantsI;                 /* MAX_CONST_I, 16 */
-    BOOL *pixelShaderConstantsF;
+    BOOL ps_consts_f[WINED3D_MAX_PS_CONSTS_F];
     WORD vertexShaderConstantsB;                /* MAX_CONST_B, 16 */
     WORD vertexShaderConstantsI;                /* MAX_CONST_I, 16 */
     BOOL vs_consts_f[WINED3D_MAX_VS_CONSTS_F];
@@ -2822,7 +2823,7 @@ struct wined3d_stateblock
     unsigned int              num_contained_ps_consts_i;
     DWORD                     contained_ps_consts_b[MAX_CONST_B];
     unsigned int              num_contained_ps_consts_b;
-    DWORD                     *contained_ps_consts_f;
+    DWORD                     contained_ps_consts_f[WINED3D_MAX_PS_CONSTS_F];
     unsigned int              num_contained_ps_consts_f;
     struct StageState         contained_tss_states[MAX_TEXTURES * (WINED3D_HIGHEST_TEXTURE_STATE + 1)];
     unsigned int              num_contained_tss_states;
@@ -2833,7 +2834,7 @@ struct wined3d_stateblock
 void stateblock_init_contained_states(struct wined3d_stateblock *stateblock) DECLSPEC_HIDDEN;
 
 void state_cleanup(struct wined3d_state *state) DECLSPEC_HIDDEN;
-HRESULT state_init(struct wined3d_state *state, struct wined3d_fb_state *fb,
+void state_init(struct wined3d_state *state, struct wined3d_fb_state *fb,
         const struct wined3d_gl_info *gl_info, const struct wined3d_d3d_info *d3d_info,
         DWORD flags) DECLSPEC_HIDDEN;
 void state_unbind_resources(struct wined3d_state *state) DECLSPEC_HIDDEN;
-- 
2.1.4




More information about the wine-patches mailing list