From 556e3e0c764ee5eff1eb02b97a01d4141d6ec58f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20D=C3=B6singer?= Date: Mon, 23 Sep 2013 13:29:16 +0200 Subject: [PATCH] wined3d: Use GL_APPLE_client_storage for volumes if available. --- dlls/wined3d/volume.c | 53 +++++++++++++++++++++++----------- dlls/wined3d/wined3d_private.h | 1 + 2 files changed, 37 insertions(+), 17 deletions(-) diff --git a/dlls/wined3d/volume.c b/dlls/wined3d/volume.c index 7be08115b05..d61f32f0a24 100644 --- a/dlls/wined3d/volume.c +++ b/dlls/wined3d/volume.c @@ -57,18 +57,48 @@ 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(const struct wined3d_volume *volume, +static void wined3d_volume_allocate_texture(struct wined3d_volume *volume, const struct wined3d_context *context, BOOL srgb) { const struct wined3d_gl_info *gl_info = context->gl_info; const struct wined3d_format *format = volume->resource.format; + void *mem = NULL; + + if (gl_info->supported[APPLE_CLIENT_STORAGE] && !format->convert + && volume_prepare_system_memory(volume)) + { + 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); + checkGLcall("glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_TRUE)"); + mem = volume->resource.heap_memory; + volume->flags |= WINED3D_VFLAG_CLIENT_STORAGE; + } GL_EXTCALL(glTexImage3DEXT(GL_TEXTURE_3D, volume->texture_level, srgb ? format->glGammaInternal : format->glInternal, volume->resource.width, volume->resource.height, volume->resource.depth, - 0, format->glFormat, format->glType, NULL)); + 0, format->glFormat, format->glType, mem)); checkGLcall("glTexImage3D"); + + if (mem) + { + gl_info->gl_ops.gl.p_glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_FALSE); + checkGLcall("glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_FALSE)"); + } } static void wined3d_volume_get_pitch(const struct wined3d_volume *volume, UINT *row_pitch, @@ -261,6 +291,8 @@ static BOOL wined3d_volume_can_evict(const struct wined3d_volume *volume) return FALSE; if (volume->resource.format->convert) return FALSE; + if (volume->flags & WINED3D_VFLAG_CLIENT_STORAGE) + return FALSE; return TRUE; } @@ -452,20 +484,6 @@ static void wined3d_volume_free_pbo(struct wined3d_volume *volume) context_release(context); } -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; -} - - static void volume_unload(struct wined3d_resource *resource) { struct wined3d_volume *volume = volume_from_resource(resource); @@ -501,7 +519,8 @@ static void volume_unload(struct wined3d_resource *resource) } /* The texture name is managed by the container. */ - volume->flags &= ~(WINED3D_VFLAG_ALLOCATED | WINED3D_VFLAG_SRGB_ALLOCATED); + volume->flags &= ~(WINED3D_VFLAG_ALLOCATED | WINED3D_VFLAG_SRGB_ALLOCATED + | WINED3D_VFLAG_CLIENT_STORAGE); resource_unload(resource); } diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h index 02c7aff6273..5525dd9dc84 100644 --- a/dlls/wined3d/wined3d_private.h +++ b/dlls/wined3d/wined3d_private.h @@ -2114,6 +2114,7 @@ void wined3d_texture_set_dirty(struct wined3d_texture *texture) DECLSPEC_HIDDEN; #define WINED3D_VFLAG_ALLOCATED 0x00000001 #define WINED3D_VFLAG_SRGB_ALLOCATED 0x00000002 #define WINED3D_VFLAG_PBO 0x00000004 +#define WINED3D_VFLAG_CLIENT_STORAGE 0x00000008 #define WINED3D_LOCATION_DISCARDED 0x00000001 #define WINED3D_LOCATION_SYSMEM 0x00000002