[PATCH 7/7] wined3d: Do not allocate framebuffer state structures dynamically.
Józef Kucia
joseph.kucia at gmail.com
Sun Feb 25 16:23:34 CST 2018
From: Józef Kucia <jkucia at codeweavers.com>
Signed-off-by: Józef Kucia <jkucia at codeweavers.com>
---
dlls/wined3d/context.c | 75 +++++++++++++++---------------------------
dlls/wined3d/wined3d_private.h | 6 ++--
2 files changed, 29 insertions(+), 52 deletions(-)
diff --git a/dlls/wined3d/context.c b/dlls/wined3d/context.c
index 2ae1715e249b..c5fb5f494c9c 100644
--- a/dlls/wined3d/context.c
+++ b/dlls/wined3d/context.c
@@ -372,18 +372,19 @@ void context_check_fbo_status(const struct wined3d_context *context, GLenum targ
const struct wined3d_gl_info *gl_info = context->gl_info;
GLenum status;
- if (!FIXME_ON(d3d)) return;
+ if (!FIXME_ON(d3d))
+ return;
status = gl_info->fbo_ops.glCheckFramebufferStatus(target);
if (status == GL_FRAMEBUFFER_COMPLETE)
{
- TRACE("FBO complete\n");
+ TRACE("FBO complete.\n");
}
else
{
unsigned int i;
- FIXME("FBO status %s (%#x)\n", debug_fbostatus(status), status);
+ FIXME("FBO status %s (%#x).\n", debug_fbostatus(status), status);
if (!context->current_fbo)
{
@@ -396,7 +397,6 @@ void context_check_fbo_status(const struct wined3d_context *context, GLenum targ
for (i = 0; i < gl_info->limits.buffers; ++i)
context_dump_fbo_attachment(gl_info, target, GL_COLOR_ATTACHMENT0 + i);
- checkGLcall("Dump FBO attachments");
}
}
@@ -493,9 +493,9 @@ static inline void context_set_fbo_key_for_render_target(const struct wined3d_co
static void context_generate_fbo_key(const struct wined3d_context *context,
struct wined3d_fbo_entry_key *key, struct wined3d_rendertarget_info *render_targets,
- struct wined3d_surface *depth_stencil_surface, DWORD color_location,
- DWORD ds_location)
+ struct wined3d_surface *depth_stencil_surface, DWORD color_location, DWORD ds_location)
{
+ unsigned int buffers = context->gl_info->limits.buffers;
struct wined3d_rendertarget_info depth_stencil = {{0}};
unsigned int i;
@@ -508,8 +508,10 @@ static void context_generate_fbo_key(const struct wined3d_context *context,
}
context_set_fbo_key_for_render_target(context, key, 0, &depth_stencil, ds_location);
- for (i = 0; i < context->gl_info->limits.buffers; ++i)
+ for (i = 0; i < buffers; ++i)
context_set_fbo_key_for_render_target(context, key, i + 1, &render_targets[i], color_location);
+
+ memset(&key->objects[buffers + 1], 0, (ARRAY_SIZE(key->objects) - buffers - 1) * sizeof(*key->objects));
}
static struct fbo_entry *context_create_fbo_entry(const struct wined3d_context *context,
@@ -517,11 +519,9 @@ static struct fbo_entry *context_create_fbo_entry(const struct wined3d_context *
DWORD color_location, DWORD ds_location)
{
const struct wined3d_gl_info *gl_info = context->gl_info;
- unsigned int object_count = gl_info->limits.buffers + 1;
struct fbo_entry *entry;
- entry = heap_alloc(FIELD_OFFSET(struct fbo_entry, key.objects[object_count]));
- memset(&entry->key, 0, FIELD_OFFSET(struct wined3d_fbo_entry_key, objects[object_count]));
+ entry = heap_alloc(sizeof(*entry));
context_generate_fbo_key(context, &entry->key, render_targets, depth_stencil, color_location, ds_location);
entry->flags = 0;
if (depth_stencil)
@@ -579,8 +579,8 @@ static struct fbo_entry *context_find_fbo_entry(struct wined3d_context *context,
DWORD color_location, DWORD ds_location)
{
const struct wined3d_gl_info *gl_info = context->gl_info;
- unsigned int object_count = gl_info->limits.buffers + 1;
struct wined3d_texture *rt_texture, *ds_texture;
+ struct wined3d_fbo_entry_key fbo_key;
struct fbo_entry *entry;
unsigned int i, level;
@@ -610,8 +610,7 @@ static struct fbo_entry *context_find_fbo_entry(struct wined3d_context *context,
surface_set_compatible_renderbuffer(depth_stencil, &render_targets[0]);
}
- context_generate_fbo_key(context, context->fbo_key, render_targets, depth_stencil, color_location,
- ds_location);
+ context_generate_fbo_key(context, &fbo_key, render_targets, depth_stencil, color_location, ds_location);
if (TRACE_ON(d3d))
{
@@ -641,8 +640,8 @@ static struct fbo_entry *context_find_fbo_entry(struct wined3d_context *context,
TRACE(" Color attachment %u: %p, %u format %s, %s %u, %ux%u, %u samples.\n",
i, resource, render_targets[i].sub_resource_idx, debug_d3dformat(resource->format->id),
- context->fbo_key->rb_namespace & (1 << (i + 1)) ? "renderbuffer" : resource_type,
- context->fbo_key->objects[i + 1].object, width, height, resource->multisample_type);
+ fbo_key.rb_namespace & (1 << (i + 1)) ? "renderbuffer" : resource_type,
+ fbo_key.objects[i + 1].object, width, height, resource->multisample_type);
}
}
if (depth_stencil)
@@ -650,8 +649,7 @@ static struct fbo_entry *context_find_fbo_entry(struct wined3d_context *context,
ds_texture = depth_stencil->container;
TRACE(" Depth attachment: %p format %s, %s %u, %ux%u, %u samples.\n",
depth_stencil, debug_d3dformat(ds_texture->resource.format->id),
- context->fbo_key->rb_namespace & (1 << 0) ? "renderbuffer" : "texture",
- context->fbo_key->objects[0].object,
+ fbo_key.rb_namespace & (1 << 0) ? "renderbuffer" : "texture", fbo_key.objects[0].object,
wined3d_texture_get_level_pow2_width(ds_texture, depth_stencil->texture_level),
wined3d_texture_get_level_pow2_height(ds_texture, depth_stencil->texture_level),
ds_texture->resource.multisample_type);
@@ -660,7 +658,7 @@ static struct fbo_entry *context_find_fbo_entry(struct wined3d_context *context,
LIST_FOR_EACH_ENTRY(entry, &context->fbo_list, struct fbo_entry, entry)
{
- if (memcmp(context->fbo_key, &entry->key, FIELD_OFFSET(struct wined3d_fbo_entry_key, objects[object_count])))
+ if (memcmp(&fbo_key, &entry->key, sizeof(fbo_key)))
continue;
list_remove(&entry->entry);
@@ -762,7 +760,7 @@ static void context_apply_fbo_state(struct wined3d_context *context, GLenum targ
void context_apply_fbo_state_blit(struct wined3d_context *context, GLenum target,
struct wined3d_surface *render_target, struct wined3d_surface *depth_stencil, DWORD location)
{
- memset(context->blit_targets, 0, context->gl_info->limits.buffers * sizeof(*context->blit_targets));
+ memset(context->blit_targets, 0, sizeof(context->blit_targets));
if (render_target)
{
context->blit_targets[0].resource = &render_target->container->resource;
@@ -1001,7 +999,7 @@ typedef void (context_fbo_entry_func_t)(struct wined3d_context *context, struct
static void context_enum_fbo_entries(const struct wined3d_device *device,
GLuint name, BOOL rb_namespace, context_fbo_entry_func_t *callback)
{
- UINT i;
+ unsigned int i, j;
for (i = 0; i < device->context_count; ++i)
{
@@ -1011,8 +1009,6 @@ static void context_enum_fbo_entries(const struct wined3d_device *device,
LIST_FOR_EACH_ENTRY_SAFE(entry, entry2, &context->fbo_list, struct fbo_entry, entry)
{
- UINT j;
-
for (j = 0; j < gl_info->limits.buffers + 1; ++j)
{
if (entry->key.objects[j].object == name
@@ -1868,16 +1864,6 @@ struct wined3d_context *context_create(struct wined3d_swapchain *swapchain,
if (!(ret = heap_alloc_zero(sizeof(*ret))))
return NULL;
- if (!(ret->blit_targets = heap_calloc(gl_info->limits.buffers, sizeof(*ret->blit_targets))))
- goto out;
-
- if (!(ret->draw_buffers = heap_calloc(gl_info->limits.buffers, sizeof(*ret->draw_buffers))))
- goto out;
-
- if (!(ret->fbo_key = heap_alloc_zero(FIELD_OFFSET(struct wined3d_fbo_entry_key,
- objects[gl_info->limits.buffers + 1]))))
- goto out;
-
ret->free_timestamp_query_size = 4;
if (!(ret->free_timestamp_queries = heap_calloc(ret->free_timestamp_query_size,
sizeof(*ret->free_timestamp_queries))))
@@ -2252,9 +2238,6 @@ out:
heap_free(ret->free_fences);
heap_free(ret->free_occlusion_queries);
heap_free(ret->free_timestamp_queries);
- heap_free(ret->fbo_key);
- heap_free(ret->draw_buffers);
- heap_free(ret->blit_targets);
heap_free(ret);
return NULL;
}
@@ -2298,9 +2281,6 @@ void context_destroy(struct wined3d_device *device, struct wined3d_context *cont
device->shader_backend->shader_free_context_data(context);
device->adapter->fragment_pipe->free_context_data(context);
heap_free(context->texture_type);
- heap_free(context->fbo_key);
- heap_free(context->draw_buffers);
- heap_free(context->blit_targets);
device_context_remove(device, context);
if (destroy)
heap_free(context);
@@ -2629,16 +2609,15 @@ static inline GLenum draw_buffer_from_rt_mask(DWORD rt_mask)
static void context_apply_draw_buffers(struct wined3d_context *context, DWORD rt_mask)
{
const struct wined3d_gl_info *gl_info = context->gl_info;
+ GLenum draw_buffers[MAX_RENDER_TARGET_VIEWS];
if (!rt_mask)
{
gl_info->gl_ops.gl.p_glDrawBuffer(GL_NONE);
- checkGLcall("glDrawBuffer()");
}
else if (is_rt_mask_onscreen(rt_mask))
{
gl_info->gl_ops.gl.p_glDrawBuffer(draw_buffer_from_rt_mask(rt_mask));
- checkGLcall("glDrawBuffer()");
}
else
{
@@ -2649,9 +2628,9 @@ static void context_apply_draw_buffers(struct wined3d_context *context, DWORD rt
while (rt_mask)
{
if (rt_mask & 1)
- context->draw_buffers[i] = GL_COLOR_ATTACHMENT0 + i;
+ draw_buffers[i] = GL_COLOR_ATTACHMENT0 + i;
else
- context->draw_buffers[i] = GL_NONE;
+ draw_buffers[i] = GL_NONE;
rt_mask >>= 1;
++i;
@@ -2659,13 +2638,11 @@ static void context_apply_draw_buffers(struct wined3d_context *context, DWORD rt
if (gl_info->supported[ARB_DRAW_BUFFERS])
{
- GL_EXTCALL(glDrawBuffers(i, context->draw_buffers));
- checkGLcall("glDrawBuffers()");
+ GL_EXTCALL(glDrawBuffers(i, draw_buffers));
}
else
{
- gl_info->gl_ops.gl.p_glDrawBuffer(context->draw_buffers[0]);
- checkGLcall("glDrawBuffer()");
+ gl_info->gl_ops.gl.p_glDrawBuffer(draw_buffers[0]);
}
}
else
@@ -2673,6 +2650,8 @@ static void context_apply_draw_buffers(struct wined3d_context *context, DWORD rt
ERR("Unexpected draw buffers mask with backbuffer ORM.\n");
}
}
+
+ checkGLcall("apply draw buffers");
}
/* Context activation is done by the caller. */
@@ -3037,7 +3016,7 @@ BOOL context_apply_clear_state(struct wined3d_context *context, const struct win
if (!rt_count || wined3d_resource_is_offscreen(rts[0]->resource))
{
- memset(context->blit_targets, 0, gl_info->limits.buffers * sizeof(*context->blit_targets));
+ memset(context->blit_targets, 0, sizeof(context->blit_targets));
for (i = 0; i < rt_count; ++i)
{
if (rts[i])
@@ -3172,7 +3151,7 @@ void context_state_fb(struct wined3d_context *context, const struct wined3d_stat
{
unsigned int i;
- memset(context->blit_targets, 0, context->gl_info->limits.buffers * sizeof (*context->blit_targets));
+ memset(context->blit_targets, 0, sizeof(context->blit_targets));
for (i = 0; i < context->gl_info->limits.buffers; ++i)
{
if (fb->render_targets[i])
diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h
index 7813df5b6ef3..f085f2d8b85e 100644
--- a/dlls/wined3d/wined3d_private.h
+++ b/dlls/wined3d/wined3d_private.h
@@ -1945,9 +1945,7 @@ struct wined3d_context
struct fbo_entry *current_fbo;
GLuint fbo_read_binding;
GLuint fbo_draw_binding;
- struct wined3d_rendertarget_info *blit_targets;
- struct wined3d_fbo_entry_key *fbo_key;
- GLenum *draw_buffers;
+ struct wined3d_rendertarget_info blit_targets[MAX_RENDER_TARGET_VIEWS];
DWORD draw_buffers_mask; /* Enabled draw buffers, 31 max. */
/* Queries */
@@ -3299,7 +3297,7 @@ struct fbo_entry
struct wined3d_fbo_entry_key
{
DWORD rb_namespace;
- struct wined3d_fbo_resource objects[1];
+ struct wined3d_fbo_resource objects[MAX_RENDER_TARGET_VIEWS + 1];
} key;
};
--
2.16.1
More information about the wine-devel
mailing list