From: Józef Kucia Subject: [PATCH 2/9] wined3d: Introduce wined3d_buffer_load_location(). Message-Id: <1476960658-29001-2-git-send-email-jkucia@codeweavers.com> Date: Thu, 20 Oct 2016 12:50:51 +0200 In-Reply-To: <1476960658-29001-1-git-send-email-jkucia@codeweavers.com> References: <1476960658-29001-1-git-send-email-jkucia@codeweavers.com> Signed-off-by: Józef Kucia --- 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 558be1b..94b290f 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 (buffer->locations & location) + { + TRACE("Location (%#x) is already up to date.\n", location); + return WINED3D_OK; + } + + 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); + } + + 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; - if (!wined3d_buffer_prepare_location(buffer, context, WINED3D_LOCATION_SYSMEM)) - return NULL; + case WINED3D_LOCATION_BUFFER: + FIXME("Not implemented yet.\n"); + return FALSE; - 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; + default: + ERR("Invalid location %s.\n", wined3d_debug_location(location)); + return FALSE; + } - wined3d_buffer_validate_location(buffer, WINED3D_LOCATION_SYSMEM); + 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 45a24f1..8001e5e 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; -- 2.7.3