[PATCH 02/10] wined3d: Use a single allocation for texture sub-resource objects.
Henri Verbeet
hverbeet at codeweavers.com
Wed Mar 2 12:24:13 CST 2016
Signed-off-by: Henri Verbeet <hverbeet at codeweavers.com>
---
dlls/wined3d/surface.c | 57 +-----------------
dlls/wined3d/texture.c | 130 ++++++++++++++++++++++++++++++-----------
dlls/wined3d/volume.c | 47 +--------------
dlls/wined3d/wined3d_private.h | 25 ++++----
4 files changed, 117 insertions(+), 142 deletions(-)
diff --git a/dlls/wined3d/surface.c b/dlls/wined3d/surface.c
index 01095e9..303bdc7 100644
--- a/dlls/wined3d/surface.c
+++ b/dlls/wined3d/surface.c
@@ -40,7 +40,7 @@ static const DWORD surface_simple_locations =
WINED3D_LOCATION_SYSMEM | WINED3D_LOCATION_USER_MEMORY
| WINED3D_LOCATION_DIB | WINED3D_LOCATION_BUFFER;
-static void surface_cleanup(struct wined3d_surface *surface)
+void wined3d_surface_cleanup(struct wined3d_surface *surface)
{
struct wined3d_surface *overlay, *cur;
@@ -107,15 +107,6 @@ static void surface_cleanup(struct wined3d_surface *surface)
resource_cleanup(&surface->resource);
}
-void wined3d_surface_destroy(struct wined3d_surface *surface)
-{
- TRACE("surface %p.\n", surface);
-
- surface_cleanup(surface);
- surface->resource.parent_ops->wined3d_object_destroyed(surface->resource.parent);
- HeapFree(GetProcessHeap(), 0, surface);
-}
-
void surface_get_drawable_size(const struct wined3d_surface *surface, const struct wined3d_context *context,
unsigned int *width, unsigned int *height)
{
@@ -5012,7 +5003,7 @@ cpu:
return surface_cpu_blt(dst_surface, dst_rect, src_surface, src_rect, flags, fx, filter);
}
-static HRESULT surface_init(struct wined3d_surface *surface, struct wined3d_texture *container,
+HRESULT wined3d_surface_init(struct wined3d_surface *surface, struct wined3d_texture *container,
const struct wined3d_resource_desc *desc, GLenum target, unsigned int level, unsigned int layer, DWORD flags)
{
struct wined3d_device *device = container->resource.device;
@@ -5090,7 +5081,7 @@ static HRESULT surface_init(struct wined3d_surface *surface, struct wined3d_text
if (FAILED(hr = surface->surface_ops->surface_private_setup(surface)))
{
ERR("Private setup failed, hr %#x.\n", hr);
- surface_cleanup(surface);
+ wined3d_surface_cleanup(surface);
return hr;
}
@@ -5111,48 +5102,6 @@ static HRESULT surface_init(struct wined3d_surface *surface, struct wined3d_text
return hr;
}
-HRESULT wined3d_surface_create(struct wined3d_texture *container, const struct wined3d_resource_desc *desc,
- GLenum target, unsigned int level, unsigned int layer, DWORD flags, struct wined3d_surface **surface)
-{
- struct wined3d_device_parent *device_parent = container->resource.device->device_parent;
- const struct wined3d_parent_ops *parent_ops;
- struct wined3d_surface *object;
- void *parent;
- HRESULT hr;
-
- TRACE("container %p, width %u, height %u, format %s, usage %s (%#x), pool %s, "
- "multisample_type %#x, multisample_quality %u, target %#x, level %u, layer %u, flags %#x, surface %p.\n",
- container, desc->width, desc->height, debug_d3dformat(desc->format),
- debug_d3dusage(desc->usage), desc->usage, debug_d3dpool(desc->pool),
- desc->multisample_type, desc->multisample_quality, target, level, layer, flags, surface);
-
- if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
- return E_OUTOFMEMORY;
-
- if (FAILED(hr = surface_init(object, container, desc, target, level, layer, flags)))
- {
- WARN("Failed to initialize surface, returning %#x.\n", hr);
- HeapFree(GetProcessHeap(), 0, object);
- return hr;
- }
-
- if (FAILED(hr = device_parent->ops->surface_created(device_parent,
- container, layer * container->level_count + level, &parent, &parent_ops)))
- {
- WARN("Failed to create surface parent, hr %#x.\n", hr);
- wined3d_surface_destroy(object);
- return hr;
- }
-
- TRACE("Created surface %p, parent %p, parent_ops %p.\n", object, parent, parent_ops);
-
- object->resource.parent = parent;
- object->resource.parent_ops = parent_ops;
- *surface = object;
-
- return hr;
-}
-
/* Context activation is done by the caller. */
void wined3d_surface_prepare(struct wined3d_surface *surface, struct wined3d_context *context, DWORD location)
{
diff --git a/dlls/wined3d/texture.c b/dlls/wined3d/texture.c
index e96b029..a664155 100644
--- a/dlls/wined3d/texture.c
+++ b/dlls/wined3d/texture.c
@@ -108,19 +108,9 @@ static void wined3d_texture_unload_gl_texture(struct wined3d_texture *texture)
static void wined3d_texture_cleanup(struct wined3d_texture *texture)
{
- UINT sub_count = texture->level_count * texture->layer_count;
- UINT i;
-
TRACE("texture %p.\n", texture);
- for (i = 0; i < sub_count; ++i)
- {
- struct wined3d_resource *sub_resource = texture->sub_resources[i].resource;
-
- if (sub_resource)
- texture->texture_ops->texture_sub_resource_cleanup(sub_resource);
- }
-
+ texture->texture_ops->texture_cleanup_sub_resources(texture);
wined3d_texture_unload_gl_texture(texture);
resource_cleanup(&texture->resource);
}
@@ -804,13 +794,6 @@ static void texture2d_sub_resource_add_dirty_region(struct wined3d_resource *sub
surface_invalidate_location(surface, ~surface->resource.map_binding);
}
-static void texture2d_sub_resource_cleanup(struct wined3d_resource *sub_resource)
-{
- struct wined3d_surface *surface = surface_from_resource(sub_resource);
-
- wined3d_surface_destroy(surface);
-}
-
static void texture2d_sub_resource_invalidate_location(struct wined3d_resource *sub_resource, DWORD location)
{
struct wined3d_surface *surface = surface_from_resource(sub_resource);
@@ -904,15 +887,34 @@ static void texture2d_prepare_texture(struct wined3d_texture *texture, struct wi
}
}
+static void texture2d_cleanup_sub_resources(struct wined3d_texture *texture)
+{
+ unsigned int sub_count = texture->level_count * texture->layer_count;
+ struct wined3d_surface *surface;
+ unsigned int i;
+
+ for (i = 0; i < sub_count; ++i)
+ {
+ if ((surface = texture->sub_resources[i].u.surface))
+ {
+ TRACE("surface %p.\n", surface);
+
+ wined3d_surface_cleanup(surface);
+ surface->resource.parent_ops->wined3d_object_destroyed(surface->resource.parent);
+ }
+ }
+ HeapFree(GetProcessHeap(), 0, texture->sub_resources[0].u.surface);
+}
+
static const struct wined3d_texture_ops texture2d_ops =
{
texture2d_sub_resource_load,
texture2d_sub_resource_add_dirty_region,
- texture2d_sub_resource_cleanup,
texture2d_sub_resource_invalidate_location,
texture2d_sub_resource_validate_location,
texture2d_sub_resource_upload_data,
texture2d_prepare_texture,
+ texture2d_cleanup_sub_resources,
};
static ULONG texture_resource_incref(struct wined3d_resource *resource)
@@ -978,8 +980,10 @@ static HRESULT texture_init(struct wined3d_texture *texture, const struct wined3
unsigned int layer_count, unsigned int level_count, DWORD flags, struct wined3d_device *device,
void *parent, const struct wined3d_parent_ops *parent_ops)
{
+ struct wined3d_device_parent *device_parent = device->device_parent;
const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
struct wined3d_resource_desc surface_desc;
+ struct wined3d_surface *surfaces;
UINT pow2_width, pow2_height;
unsigned int i, j;
HRESULT hr;
@@ -1088,6 +1092,12 @@ static HRESULT texture_init(struct wined3d_texture *texture, const struct wined3
}
TRACE("xf(%f) yf(%f)\n", texture->pow2_matrix[0], texture->pow2_matrix[5]);
+ if (!(surfaces = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*surfaces) * level_count * layer_count)))
+ {
+ wined3d_texture_cleanup(texture);
+ return E_OUTOFMEMORY;
+ }
+
/* Generate all the surfaces. */
surface_desc = *desc;
surface_desc.resource_type = WINED3D_RTYPE_SURFACE;
@@ -1108,16 +1118,32 @@ static HRESULT texture_init(struct wined3d_texture *texture, const struct wined3
unsigned int idx = j * texture->level_count + i;
struct wined3d_surface *surface;
- if (FAILED(hr = wined3d_surface_create(texture, &surface_desc,
- target, i, j, flags, &surface)))
+ surface = &surfaces[idx];
+ if (FAILED(hr = wined3d_surface_init(surface, texture, &surface_desc, target, i, j, flags)))
+ {
+ WARN("Failed to initialize surface, returning %#x.\n", hr);
+ wined3d_texture_cleanup(texture);
+ if (!idx)
+ HeapFree(GetProcessHeap(), 0, surfaces);
+ return hr;
+ }
+
+ if (FAILED(hr = device_parent->ops->surface_created(device_parent,
+ texture, idx, &parent, &parent_ops)))
{
- WARN("Failed to create surface, hr %#x.\n", hr);
+ WARN("Failed to create surface parent, hr %#x.\n", hr);
+ wined3d_surface_cleanup(surface);
wined3d_texture_cleanup(texture);
return hr;
}
+ TRACE("parent %p, parent_ops %p.\n", parent, parent_ops);
+
+ surface->resource.parent = parent;
+ surface->resource.parent_ops = parent_ops;
texture->sub_resources[idx].resource = &surface->resource;
- TRACE("Created surface level %u @ %p.\n", i, surface);
+ texture->sub_resources[idx].u.surface = surface;
+ TRACE("Created surface level %u, layer %u @ %p.\n", i, j, surface);
}
/* Calculate the next mipmap level. */
surface_desc.width = max(1, surface_desc.width >> 1);
@@ -1139,13 +1165,6 @@ static void texture3d_sub_resource_add_dirty_region(struct wined3d_resource *sub
wined3d_texture_set_dirty(volume_from_resource(sub_resource)->container);
}
-static void texture3d_sub_resource_cleanup(struct wined3d_resource *sub_resource)
-{
- struct wined3d_volume *volume = volume_from_resource(sub_resource);
-
- wined3d_volume_destroy(volume);
-}
-
static void texture3d_sub_resource_invalidate_location(struct wined3d_resource *sub_resource, DWORD location)
{
struct wined3d_volume *volume = volume_from_resource(sub_resource);
@@ -1198,15 +1217,34 @@ static void texture3d_prepare_texture(struct wined3d_texture *texture, struct wi
}
}
+static void texture3d_cleanup_sub_resources(struct wined3d_texture *texture)
+{
+ unsigned int sub_count = texture->level_count * texture->layer_count;
+ struct wined3d_volume *volume;
+ unsigned int i;
+
+ for (i = 0; i < sub_count; ++i)
+ {
+ if ((volume = texture->sub_resources[i].u.volume))
+ {
+ TRACE("volume %p.\n", volume);
+
+ wined3d_volume_cleanup(volume);
+ volume->resource.parent_ops->wined3d_object_destroyed(volume->resource.parent);
+ }
+ }
+ HeapFree(GetProcessHeap(), 0, texture->sub_resources[0].u.volume);
+}
+
static const struct wined3d_texture_ops texture3d_ops =
{
texture3d_sub_resource_load,
texture3d_sub_resource_add_dirty_region,
- texture3d_sub_resource_cleanup,
texture3d_sub_resource_invalidate_location,
texture3d_sub_resource_validate_location,
texture3d_sub_resource_upload_data,
texture3d_prepare_texture,
+ texture3d_cleanup_sub_resources,
};
BOOL wined3d_texture_check_block_align(const struct wined3d_texture *texture,
@@ -1271,8 +1309,10 @@ static const struct wined3d_resource_ops texture3d_resource_ops =
static HRESULT volumetexture_init(struct wined3d_texture *texture, const struct wined3d_resource_desc *desc,
UINT levels, struct wined3d_device *device, void *parent, const struct wined3d_parent_ops *parent_ops)
{
+ struct wined3d_device_parent *device_parent = device->device_parent;
const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
struct wined3d_resource_desc volume_desc;
+ struct wined3d_volume *volumes;
unsigned int i;
HRESULT hr;
@@ -1347,6 +1387,12 @@ static HRESULT volumetexture_init(struct wined3d_texture *texture, const struct
texture->pow2_matrix[15] = 1.0f;
texture->target = GL_TEXTURE_3D;
+ if (!(volumes = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*volumes) * levels)))
+ {
+ wined3d_texture_cleanup(texture);
+ return E_OUTOFMEMORY;
+ }
+
/* Generate all the surfaces. */
volume_desc = *desc;
volume_desc.resource_type = WINED3D_RTYPE_VOLUME;
@@ -1354,14 +1400,32 @@ static HRESULT volumetexture_init(struct wined3d_texture *texture, const struct
{
struct wined3d_volume *volume;
- if (FAILED(hr = wined3d_volume_create(texture, &volume_desc, i, &volume)))
+ volume = &volumes[i];
+ if (FAILED(hr = wined3d_volume_init(volume, texture, &volume_desc, i)))
+ {
+ WARN("Failed to initialize volume, returning %#x.\n", hr);
+ wined3d_texture_cleanup(texture);
+ if (!i)
+ HeapFree(GetProcessHeap(), 0, volumes);
+ return hr;
+ }
+
+ if (FAILED(hr = device_parent->ops->volume_created(device_parent,
+ texture, i, &parent, &parent_ops)))
{
- ERR("Creating a volume for the volume texture failed, hr %#x.\n", hr);
+ WARN("Failed to create volume parent, hr %#x.\n", hr);
+ wined3d_volume_cleanup(volume);
wined3d_texture_cleanup(texture);
return hr;
}
+ TRACE("parent %p, parent_ops %p.\n", parent, parent_ops);
+
+ volume->resource.parent = parent;
+ volume->resource.parent_ops = parent_ops;
texture->sub_resources[i].resource = &volume->resource;
+ texture->sub_resources[i].u.volume = volume;
+ TRACE("Created volume level %u @ %p.\n", i, volume);
/* Calculate the next mipmap level. */
volume_desc.width = max(1, volume_desc.width >> 1);
diff --git a/dlls/wined3d/volume.c b/dlls/wined3d/volume.c
index 6f5de73..4b726d7 100644
--- a/dlls/wined3d/volume.c
+++ b/dlls/wined3d/volume.c
@@ -382,7 +382,7 @@ static void wined3d_volume_free_pbo(struct wined3d_volume *volume)
context_release(context);
}
-void wined3d_volume_destroy(struct wined3d_volume *volume)
+void wined3d_volume_cleanup(struct wined3d_volume *volume)
{
TRACE("volume %p.\n", volume);
@@ -390,8 +390,6 @@ void wined3d_volume_destroy(struct wined3d_volume *volume)
wined3d_volume_free_pbo(volume);
resource_cleanup(&volume->resource);
- volume->resource.parent_ops->wined3d_object_destroyed(volume->resource.parent);
- HeapFree(GetProcessHeap(), 0, volume);
}
static void volume_unload(struct wined3d_resource *resource)
@@ -665,7 +663,7 @@ static const struct wined3d_resource_ops volume_resource_ops =
volume_resource_sub_resource_unmap,
};
-static HRESULT volume_init(struct wined3d_volume *volume, struct wined3d_texture *container,
+HRESULT wined3d_volume_init(struct wined3d_volume *volume, struct wined3d_texture *container,
const struct wined3d_resource_desc *desc, UINT level)
{
struct wined3d_device *device = container->resource.device;
@@ -708,44 +706,3 @@ static HRESULT volume_init(struct wined3d_volume *volume, struct wined3d_texture
return WINED3D_OK;
}
-
-HRESULT wined3d_volume_create(struct wined3d_texture *container, const struct wined3d_resource_desc *desc,
- unsigned int level, struct wined3d_volume **volume)
-{
- struct wined3d_device_parent *device_parent = container->resource.device->device_parent;
- const struct wined3d_parent_ops *parent_ops;
- struct wined3d_volume *object;
- void *parent;
- HRESULT hr;
-
- TRACE("container %p, width %u, height %u, depth %u, level %u, format %s, "
- "usage %#x, pool %s, volume %p.\n",
- container, desc->width, desc->height, desc->depth, level, debug_d3dformat(desc->format),
- desc->usage, debug_d3dpool(desc->pool), volume);
-
- if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
- return E_OUTOFMEMORY;
-
- if (FAILED(hr = volume_init(object, container, desc, level)))
- {
- WARN("Failed to initialize volume, returning %#x.\n", hr);
- HeapFree(GetProcessHeap(), 0, object);
- return hr;
- }
-
- if (FAILED(hr = device_parent->ops->volume_created(device_parent,
- container, level, &parent, &parent_ops)))
- {
- WARN("Failed to create volume parent, hr %#x.\n", hr);
- wined3d_volume_destroy(object);
- return hr;
- }
-
- TRACE("Created volume %p, parent %p, parent_ops %p.\n", object, parent, parent_ops);
-
- object->resource.parent = parent;
- object->resource.parent_ops = parent_ops;
- *volume = object;
-
- return WINED3D_OK;
-}
diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h
index d89bd24..1774039 100644
--- a/dlls/wined3d/wined3d_private.h
+++ b/dlls/wined3d/wined3d_private.h
@@ -2326,13 +2326,13 @@ struct wined3d_texture_ops
struct wined3d_context *context, BOOL srgb);
void (*texture_sub_resource_add_dirty_region)(struct wined3d_resource *sub_resource,
const struct wined3d_box *dirty_region);
- void (*texture_sub_resource_cleanup)(struct wined3d_resource *sub_resource);
void (*texture_sub_resource_invalidate_location)(struct wined3d_resource *sub_resource, DWORD location);
void (*texture_sub_resource_validate_location)(struct wined3d_resource *sub_resource, DWORD location);
void (*texture_sub_resource_upload_data)(struct wined3d_resource *sub_resource,
const struct wined3d_context *context, const struct wined3d_sub_resource_data *data);
void (*texture_prepare_texture)(struct wined3d_texture *texture,
struct wined3d_context *context, BOOL srgb);
+ void (*texture_cleanup_sub_resources)(struct wined3d_texture *texture);
};
#define WINED3D_TEXTURE_COND_NP2 0x00000001
@@ -2386,6 +2386,11 @@ struct wined3d_texture
struct
{
struct wined3d_resource *resource;
+ union
+ {
+ struct wined3d_surface *surface;
+ struct wined3d_volume *volume;
+ } u;
} sub_resources[1];
};
@@ -2449,12 +2454,12 @@ static inline struct wined3d_volume *volume_from_resource(struct wined3d_resourc
}
BOOL volume_prepare_system_memory(struct wined3d_volume *volume) DECLSPEC_HIDDEN;
-HRESULT wined3d_volume_create(struct wined3d_texture *container, const struct wined3d_resource_desc *desc,
- unsigned int level, struct wined3d_volume **volume) DECLSPEC_HIDDEN;
-void wined3d_volume_destroy(struct wined3d_volume *volume) DECLSPEC_HIDDEN;
+void wined3d_volume_cleanup(struct wined3d_volume *volume) DECLSPEC_HIDDEN;
+HRESULT wined3d_volume_init(struct wined3d_volume *volume, struct wined3d_texture *container,
+ const struct wined3d_resource_desc *desc, UINT level) DECLSPEC_HIDDEN;
+void wined3d_volume_invalidate_location(struct wined3d_volume *volume, DWORD location) DECLSPEC_HIDDEN;
void wined3d_volume_load(struct wined3d_volume *volume, struct wined3d_context *context,
BOOL srgb_mode) DECLSPEC_HIDDEN;
-void wined3d_volume_invalidate_location(struct wined3d_volume *volume, DWORD location) DECLSPEC_HIDDEN;
HRESULT wined3d_volume_map(struct wined3d_volume *volume,
struct wined3d_map_desc *map_desc, const struct wined3d_box *box, DWORD flags) DECLSPEC_HIDDEN;
void wined3d_volume_validate_location(struct wined3d_volume *volume, DWORD location) DECLSPEC_HIDDEN;
@@ -2563,13 +2568,16 @@ static inline GLuint surface_get_texture_name(const struct wined3d_surface *surf
HRESULT wined3d_surface_blt(struct wined3d_surface *dst_surface, const RECT *dst_rect,
struct wined3d_surface *src_surface, const RECT *src_rect, DWORD flags,
const struct wined3d_blt_fx *blt_fx, enum wined3d_texture_filter_type filter) DECLSPEC_HIDDEN;
-void surface_set_dirty(struct wined3d_surface *surface) DECLSPEC_HIDDEN;
+void wined3d_surface_cleanup(struct wined3d_surface *surface) DECLSPEC_HIDDEN;
HRESULT surface_color_fill(struct wined3d_surface *s,
const RECT *rect, const struct wined3d_color *color) DECLSPEC_HIDDEN;
HRESULT surface_create_dib_section(struct wined3d_surface *surface) DECLSPEC_HIDDEN;
GLenum surface_get_gl_buffer(const struct wined3d_surface *surface) DECLSPEC_HIDDEN;
void surface_get_drawable_size(const struct wined3d_surface *surface, const struct wined3d_context *context,
unsigned int *width, unsigned int *height) DECLSPEC_HIDDEN;
+HRESULT wined3d_surface_init(struct wined3d_surface *surface,
+ struct wined3d_texture *container, const struct wined3d_resource_desc *desc,
+ GLenum target, unsigned int level, unsigned int layer, DWORD flags) DECLSPEC_HIDDEN;
void surface_invalidate_location(struct wined3d_surface *surface, DWORD location) DECLSPEC_HIDDEN;
void surface_load(struct wined3d_surface *surface, struct wined3d_context *context, BOOL srgb) DECLSPEC_HIDDEN;
void surface_load_ds_location(struct wined3d_surface *surface,
@@ -2585,6 +2593,7 @@ void wined3d_surface_prepare(struct wined3d_surface *surface, struct wined3d_con
DWORD location) DECLSPEC_HIDDEN;
void surface_set_compatible_renderbuffer(struct wined3d_surface *surface,
const struct wined3d_surface *rt) DECLSPEC_HIDDEN;
+void surface_set_dirty(struct wined3d_surface *surface) DECLSPEC_HIDDEN;
void surface_set_texture_target(struct wined3d_surface *surface, GLenum target, GLint level) DECLSPEC_HIDDEN;
void surface_translate_drawable_coords(const struct wined3d_surface *surface, HWND window, RECT *rect) DECLSPEC_HIDDEN;
HRESULT wined3d_surface_unmap(struct wined3d_surface *surface) DECLSPEC_HIDDEN;
@@ -2593,10 +2602,6 @@ HRESULT wined3d_surface_update_desc(struct wined3d_surface *surface,
HRESULT surface_upload_from_surface(struct wined3d_surface *dst_surface, const POINT *dst_point,
struct wined3d_surface *src_surface, const RECT *src_rect) DECLSPEC_HIDDEN;
void surface_validate_location(struct wined3d_surface *surface, DWORD location) DECLSPEC_HIDDEN;
-HRESULT wined3d_surface_create(struct wined3d_texture *container, const struct wined3d_resource_desc *desc,
- GLenum target, unsigned int level, unsigned int layer, DWORD flags,
- struct wined3d_surface **surface) DECLSPEC_HIDDEN;
-void wined3d_surface_destroy(struct wined3d_surface *surface) DECLSPEC_HIDDEN;
void surface_prepare_map_memory(struct wined3d_surface *surface) DECLSPEC_HIDDEN;
void wined3d_surface_upload_data(struct wined3d_surface *surface, const struct wined3d_gl_info *gl_info,
const struct wined3d_format *format, const RECT *src_rect, UINT src_pitch, const POINT *dst_point,
--
2.1.4
More information about the wine-patches
mailing list