[PATCH 5/5] wined3d: Move buffer creation into the resource.
Stefan Dösinger
stefan at codeweavers.com
Tue Oct 1 06:05:43 CDT 2013
More code from volume_unload can be moved to resource_unload eventually.
Before doing that, surfaces and buffers have to be migrated to the new
location scheme. Otherwise the unimplemented buffer_load_location and
surface_load_location will write a lot of ERRs.
---
dlls/wined3d/resource.c | 66 +++++++++++++++++++++++++++++++++++
dlls/wined3d/volume.c | 78 ++----------------------------------------
dlls/wined3d/wined3d_private.h | 3 ++
3 files changed, 72 insertions(+), 75 deletions(-)
diff --git a/dlls/wined3d/resource.c b/dlls/wined3d/resource.c
index 8a42cb6..9663169 100644
--- a/dlls/wined3d/resource.c
+++ b/dlls/wined3d/resource.c
@@ -149,6 +149,18 @@ HRESULT resource_init(struct wined3d_resource *resource, struct wined3d_device *
return WINED3D_OK;
}
+static void wined3d_resource_free_bo(struct wined3d_resource *resource)
+{
+ struct wined3d_context *context = context_acquire(resource->device, NULL);
+ const struct wined3d_gl_info *gl_info = context->gl_info;
+
+ TRACE("Deleting GL buffer %u belonging to resource %p.\n", resource->buffer_object, resource);
+ GL_EXTCALL(glDeleteBuffersARB(1, &resource->buffer_object));
+ checkGLcall("glDeleteBuffersARB");
+ resource->buffer_object = 0;
+ context_release(context);
+}
+
void resource_cleanup(struct wined3d_resource *resource)
{
const struct wined3d *d3d = resource->device->wined3d;
@@ -172,6 +184,9 @@ void resource_cleanup(struct wined3d_resource *resource)
ERR("Failed to free private data when destroying resource %p, hr = %#x.\n", resource, hr);
}
+ if (resource->buffer_object)
+ wined3d_resource_free_bo(resource);
+
wined3d_resource_free_sysmem(resource);
resource->allocatedMemory = NULL;
@@ -183,6 +198,9 @@ void resource_unload(struct wined3d_resource *resource)
if (resource->map_count)
ERR("Resource %p is being unloaded while mapped.\n", resource);
+ if (resource->buffer_object)
+ wined3d_resource_free_bo(resource);
+
context_resource_unloaded(resource->device,
resource, resource->type);
}
@@ -549,3 +567,51 @@ void wined3d_resource_release_map_ptr(const struct wined3d_resource *resource,
return;
}
}
+
+/* Context activation is done by the caller. */
+static void wined3d_resource_prepare_bo(struct wined3d_resource *resource, const struct wined3d_context *context)
+{
+ const struct wined3d_gl_info *gl_info = context->gl_info;
+
+ if (resource->buffer_object)
+ return;
+
+ GL_EXTCALL(glGenBuffersARB(1, &resource->buffer_object));
+ GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, resource->buffer_object));
+ GL_EXTCALL(glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_ARB, resource->size, NULL, GL_STREAM_DRAW_ARB));
+ GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0));
+ checkGLcall("Create GL buffer");
+
+ TRACE("Created GL buffer %u for resource %p.\n", resource->buffer_object, resource);
+}
+
+BOOL wined3d_resource_prepare_system_memory(struct wined3d_resource *resource)
+{
+ if (resource->heap_memory)
+ return TRUE;
+
+ if (!wined3d_resource_allocate_sysmem(resource))
+ {
+ ERR("Failed to allocate system memory.\n");
+ return FALSE;
+ }
+ return TRUE;
+}
+
+/* Context activation is done by the caller. */
+BOOL wined3d_resource_prepare_map_memory(struct wined3d_resource *resource, struct wined3d_context *context)
+{
+ switch (resource->map_binding)
+ {
+ case WINED3D_LOCATION_BUFFER:
+ wined3d_resource_prepare_bo(resource, context);
+ return TRUE;
+
+ case WINED3D_LOCATION_SYSMEM:
+ return wined3d_resource_prepare_system_memory(resource);
+
+ default:
+ ERR("Unexpected map binding %s.\n", wined3d_debug_location(resource->map_binding));
+ return FALSE;
+ }
+}
diff --git a/dlls/wined3d/volume.c b/dlls/wined3d/volume.c
index 22e5523..bd8f611 100644
--- a/dlls/wined3d/volume.c
+++ b/dlls/wined3d/volume.c
@@ -57,19 +57,6 @@ void volume_set_container(struct wined3d_volume *volume, struct wined3d_texture
volume->container = container;
}
-static BOOL volume_prepare_system_memory(struct wined3d_volume *volume)
-{
- if (volume->resource.heap_memory)
- return TRUE;
-
- if (!wined3d_resource_allocate_sysmem(&volume->resource))
- {
- ERR("Failed to allocate system memory.\n");
- return FALSE;
- }
- return TRUE;
-}
-
/* Context activation is done by the caller. */
static void wined3d_volume_allocate_texture(struct wined3d_volume *volume,
const struct wined3d_context *context, BOOL srgb)
@@ -79,7 +66,7 @@ static void wined3d_volume_allocate_texture(struct wined3d_volume *volume,
void *mem = NULL;
if (gl_info->supported[APPLE_CLIENT_STORAGE] && !format->convert
- && volume_prepare_system_memory(volume))
+ && wined3d_resource_prepare_system_memory(&volume->resource))
{
TRACE("Enabling GL_UNPACK_CLIENT_STORAGE_APPLE for volume %p\n", volume);
gl_info->gl_ops.gl.p_glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_TRUE);
@@ -416,35 +403,6 @@ void wined3d_volume_load(struct wined3d_volume *volume, struct wined3d_context *
}
}
-/* Context activation is done by the caller. */
-static void wined3d_volume_prepare_pbo(struct wined3d_volume *volume, struct wined3d_context *context)
-{
- const struct wined3d_gl_info *gl_info = context->gl_info;
-
- if (volume->resource.buffer_object)
- return;
-
- GL_EXTCALL(glGenBuffersARB(1, &volume->resource.buffer_object));
- GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, volume->resource.buffer_object));
- GL_EXTCALL(glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_ARB, volume->resource.size, NULL, GL_STREAM_DRAW_ARB));
- GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0));
- checkGLcall("Create PBO");
-
- TRACE("Created PBO %u for volume %p.\n", volume->resource.buffer_object, volume);
-}
-
-static void wined3d_volume_free_pbo(struct wined3d_volume *volume)
-{
- struct wined3d_context *context = context_acquire(volume->resource.device, NULL);
- const struct wined3d_gl_info *gl_info = context->gl_info;
-
- TRACE("Deleting PBO %u belonging to volume %p.\n", volume->resource.buffer_object, volume);
- GL_EXTCALL(glDeleteBuffersARB(1, &volume->resource.buffer_object));
- checkGLcall("glDeleteBuffersARB");
- volume->resource.buffer_object = 0;
- context_release(context);
-}
-
static void volume_unload(struct wined3d_resource *resource)
{
struct wined3d_volume *volume = volume_from_resource(resource);
@@ -456,7 +414,7 @@ static void volume_unload(struct wined3d_resource *resource)
TRACE("texture %p.\n", resource);
- if (volume_prepare_system_memory(volume))
+ if (wined3d_resource_prepare_system_memory(&volume->resource))
{
context = context_acquire(device, NULL);
wined3d_resource_load_location(&volume->resource, context, WINED3D_LOCATION_SYSMEM);
@@ -470,15 +428,6 @@ static void volume_unload(struct wined3d_resource *resource)
wined3d_resource_invalidate_location(&volume->resource, ~WINED3D_LOCATION_DISCARDED);
}
- if (volume->resource.buffer_object)
- {
- /* Should not happen because only dynamic default pool volumes
- * have a buffer, and those are not evicted by device_evit_managed_resources
- * and must be freed before a non-ex device reset. */
- ERR("Unloading a volume with a buffer\n");
- wined3d_volume_free_pbo(volume);
- }
-
/* The texture name is managed by the container. */
volume->flags &= ~(WINED3D_VFLAG_ALLOCATED | WINED3D_VFLAG_SRGB_ALLOCATED
| WINED3D_VFLAG_CLIENT_STORAGE);
@@ -519,9 +468,6 @@ ULONG CDECL wined3d_volume_decref(struct wined3d_volume *volume)
if (!refcount)
{
- if (volume->resource.buffer_object)
- wined3d_volume_free_pbo(volume);
-
resource_cleanup(&volume->resource);
volume->resource.parent_ops->wined3d_object_destroyed(volume->resource.parent);
HeapFree(GetProcessHeap(), 0, volume);
@@ -609,24 +555,6 @@ static BOOL wined3d_volume_check_box_dimensions(const struct wined3d_volume *vol
return TRUE;
}
-/* Context activation is done by the caller. */
-static BOOL wined3d_volume_prepare_map_memory(struct wined3d_volume *volume, struct wined3d_context *context)
-{
- switch (volume->resource.map_binding)
- {
- case WINED3D_LOCATION_BUFFER:
- wined3d_volume_prepare_pbo(volume, context);
- return TRUE;
-
- case WINED3D_LOCATION_SYSMEM:
- return volume_prepare_system_memory(volume);
-
- default:
- ERR("Unexpected map binding %s.\n", wined3d_debug_location(volume->resource.map_binding));
- return FALSE;
- }
-}
-
HRESULT CDECL wined3d_volume_map(struct wined3d_volume *volume,
struct wined3d_map_desc *map_desc, const struct wined3d_box *box, DWORD flags)
{
@@ -664,7 +592,7 @@ HRESULT CDECL wined3d_volume_map(struct wined3d_volume *volume,
flags = wined3d_resource_sanitize_map_flags(&volume->resource, flags);
context = context_acquire(device, NULL);
- if (!wined3d_volume_prepare_map_memory(volume, context))
+ if (!wined3d_resource_prepare_map_memory(&volume->resource, context))
{
WARN("Out of memory.\n");
map_desc->data = NULL;
diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h
index c2f1333..cbc5fee 100644
--- a/dlls/wined3d/wined3d_private.h
+++ b/dlls/wined3d/wined3d_private.h
@@ -2048,6 +2048,9 @@ BYTE *wined3d_resource_get_map_ptr(const struct wined3d_resource *resource,
const struct wined3d_context *context, DWORD flags) DECLSPEC_HIDDEN;
void wined3d_resource_release_map_ptr(const struct wined3d_resource *resource,
const struct wined3d_context *context) DECLSPEC_HIDDEN;
+BOOL wined3d_resource_prepare_system_memory(struct wined3d_resource *resource) DECLSPEC_HIDDEN;
+BOOL wined3d_resource_prepare_map_memory(struct wined3d_resource *resource,
+ struct wined3d_context *context) DECLSPEC_HIDDEN;
/* Tests show that the start address of resources is 32 byte aligned */
#define RESOURCE_ALIGNMENT 16
--
1.8.1.5
More information about the wine-patches
mailing list