From 645d3cac14b1303d0152ac6463586ce147c25b9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B3zef=20Kucia?= Date: Thu, 20 Oct 2016 12:50:51 +0200 Subject: [PATCH] wined3d: Introduce wined3d_buffer_load_location(). MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Józef Kucia Signed-off-by: Henri Verbeet Signed-off-by: Alexandre Julliard --- dlls/wined3d/buffer.c | 66 +++++++++++++++++++++++++++------- dlls/wined3d/wined3d_private.h | 2 ++ 2 files changed, 56 insertions(+), 12 deletions(-) diff --git a/dlls/wined3d/buffer.c b/dlls/wined3d/buffer.c index 558be1b31fd..94b290fe658 100644 --- a/dlls/wined3d/buffer.c +++ b/dlls/wined3d/buffer.c @@ -564,25 +564,67 @@ static BOOL wined3d_buffer_prepare_location(struct wined3d_buffer *buffer, } } -/* Context activation is done by the caller. */ -BYTE *wined3d_buffer_load_sysmem(struct wined3d_buffer *buffer, struct wined3d_context *context) +BOOL wined3d_buffer_load_location(struct wined3d_buffer *buffer, + struct wined3d_context *context, DWORD location) { const struct wined3d_gl_info *gl_info = context->gl_info; - /* Heap_memory exists if the buffer is double buffered or has no buffer object at all. */ - if (buffer->resource.heap_memory) - return buffer->resource.heap_memory; + TRACE("buffer %p, context %p, location %s.\n", + buffer, context, wined3d_debug_location(location)); - if (!wined3d_buffer_prepare_location(buffer, context, WINED3D_LOCATION_SYSMEM)) - return NULL; + if (buffer->locations & location) + { + TRACE("Location (%#x) is already up to date.\n", location); + return WINED3D_OK; + } - buffer_bind(buffer, context); - GL_EXTCALL(glGetBufferSubData(buffer->buffer_type_hint, 0, buffer->resource.size, buffer->resource.heap_memory)); - checkGLcall("buffer download"); - buffer->flags |= WINED3D_BUFFER_DOUBLEBUFFER; + if (!buffer->locations) + { + ERR("Buffer %p does not have any up to date location.\n", buffer); + wined3d_buffer_validate_location(buffer, WINED3D_LOCATION_DISCARDED); + return wined3d_buffer_load_location(buffer, context, location); + } - wined3d_buffer_validate_location(buffer, WINED3D_LOCATION_SYSMEM); + TRACE("Current buffer location %s.\n", wined3d_debug_location(buffer->locations)); + if (!wined3d_buffer_prepare_location(buffer, context, location)) + return FALSE; + + if (buffer->locations & WINED3D_LOCATION_DISCARDED) + { + TRACE("Buffer previously discarded, nothing to do.\n"); + wined3d_buffer_validate_location(buffer, location); + wined3d_buffer_invalidate_location(buffer, WINED3D_LOCATION_DISCARDED); + return TRUE; + } + + switch (location) + { + case WINED3D_LOCATION_SYSMEM: + buffer_bind(buffer, context); + GL_EXTCALL(glGetBufferSubData(buffer->buffer_type_hint, 0, buffer->resource.size, + buffer->resource.heap_memory)); + checkGLcall("buffer download"); + buffer->flags |= WINED3D_BUFFER_DOUBLEBUFFER; + break; + + case WINED3D_LOCATION_BUFFER: + FIXME("Not implemented yet.\n"); + return FALSE; + + default: + ERR("Invalid location %s.\n", wined3d_debug_location(location)); + return FALSE; + } + + wined3d_buffer_validate_location(buffer, location); + return TRUE; +} + +/* Context activation is done by the caller. */ +BYTE *wined3d_buffer_load_sysmem(struct wined3d_buffer *buffer, struct wined3d_context *context) +{ + wined3d_buffer_load_location(buffer, context, WINED3D_LOCATION_SYSMEM); return buffer->resource.heap_memory; } diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h index 45a24f19f49..8001e5e412d 100644 --- a/dlls/wined3d/wined3d_private.h +++ b/dlls/wined3d/wined3d_private.h @@ -3185,6 +3185,8 @@ void buffer_mark_used(struct wined3d_buffer *buffer) DECLSPEC_HIDDEN; void wined3d_buffer_invalidate_location(struct wined3d_buffer *buffer, DWORD location) DECLSPEC_HIDDEN; void wined3d_buffer_load(struct wined3d_buffer *buffer, struct wined3d_context *context, const struct wined3d_state *state) DECLSPEC_HIDDEN; +BOOL wined3d_buffer_load_location(struct wined3d_buffer *buffer, struct wined3d_context *context, + DWORD location) DECLSPEC_HIDDEN; BYTE *wined3d_buffer_load_sysmem(struct wined3d_buffer *buffer, struct wined3d_context *context) DECLSPEC_HIDDEN; HRESULT wined3d_buffer_copy(struct wined3d_buffer *dst_buffer, unsigned int dst_offset, struct wined3d_buffer *src_buffer, unsigned int src_offset, unsigned int size) DECLSPEC_HIDDEN;