wined3d: Factor out context_copy_bo_address() function.

Signed-off-by: Józef Kucia <jkucia@codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Józef Kucia 2017-08-04 19:53:47 +02:00 committed by Alexandre Julliard
parent 395a65bdc6
commit 5d71c48cb3
3 changed files with 55 additions and 46 deletions

View File

@ -1194,68 +1194,26 @@ static void wined3d_buffer_unmap(struct wined3d_buffer *buffer)
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)
{
const struct wined3d_gl_info *gl_info;
struct wined3d_bo_address dst, src;
struct wined3d_context *context;
struct wined3d_device *device;
BYTE *dst_ptr, *src_ptr;
DWORD dst_location;
buffer_mark_used(dst_buffer);
buffer_mark_used(src_buffer);
device = dst_buffer->resource.device;
context = context_acquire(device, NULL, 0);
gl_info = context->gl_info;
dst_location = wined3d_buffer_get_memory(dst_buffer, &dst, dst_buffer->locations);
dst.addr += dst_offset;
wined3d_buffer_get_memory(src_buffer, &src, src_buffer->locations);
src.addr += src_offset;
if (dst.buffer_object && src.buffer_object)
{
if (gl_info->supported[ARB_COPY_BUFFER])
{
GL_EXTCALL(glBindBuffer(GL_COPY_READ_BUFFER, src.buffer_object));
GL_EXTCALL(glBindBuffer(GL_COPY_WRITE_BUFFER, dst.buffer_object));
GL_EXTCALL(glCopyBufferSubData(GL_COPY_READ_BUFFER, GL_COPY_WRITE_BUFFER,
src_offset, dst_offset, size));
checkGLcall("direct buffer copy");
}
else
{
src_ptr = context_map_bo_address(context, &src, size, src_buffer->buffer_type_hint, WINED3D_MAP_READONLY);
dst_ptr = context_map_bo_address(context, &dst, size, dst_buffer->buffer_type_hint, 0);
memcpy(dst_ptr, src_ptr, size);
context_unmap_bo_address(context, &dst, dst_buffer->buffer_type_hint);
context_unmap_bo_address(context, &src, src_buffer->buffer_type_hint);
}
}
else if (!dst.buffer_object && src.buffer_object)
{
buffer_bind(src_buffer, context);
GL_EXTCALL(glGetBufferSubData(src_buffer->buffer_type_hint, src_offset, size, dst.addr));
checkGLcall("buffer download");
}
else if (dst.buffer_object && !src.buffer_object)
{
buffer_bind(dst_buffer, context);
GL_EXTCALL(glBufferSubData(dst_buffer->buffer_type_hint, dst_offset, size, src.addr));
checkGLcall("buffer upload");
}
else
{
memcpy(dst.addr, src.addr, size);
}
context = context_acquire(dst_buffer->resource.device, NULL, 0);
context_copy_bo_address(context, &dst, dst_buffer->buffer_type_hint,
&src, src_buffer->buffer_type_hint, size);
context_release(context);
wined3d_buffer_invalidate_range(dst_buffer, ~dst_location, dst_offset, size);
context_release(context);
return WINED3D_OK;
}

View File

@ -2752,6 +2752,54 @@ void context_unmap_bo_address(struct wined3d_context *context,
checkGLcall("Unmap buffer object");
}
void context_copy_bo_address(struct wined3d_context *context,
const struct wined3d_bo_address *dst, GLenum dst_binding,
const struct wined3d_bo_address *src, GLenum src_binding, size_t size)
{
const struct wined3d_gl_info *gl_info;
BYTE *dst_ptr, *src_ptr;
gl_info = context->gl_info;
if (dst->buffer_object && src->buffer_object)
{
if (gl_info->supported[ARB_COPY_BUFFER])
{
GL_EXTCALL(glBindBuffer(GL_COPY_READ_BUFFER, src->buffer_object));
GL_EXTCALL(glBindBuffer(GL_COPY_WRITE_BUFFER, dst->buffer_object));
GL_EXTCALL(glCopyBufferSubData(GL_COPY_READ_BUFFER, GL_COPY_WRITE_BUFFER,
(GLintptr)src->addr, (GLintptr)dst->addr, size));
checkGLcall("direct buffer copy");
}
else
{
src_ptr = context_map_bo_address(context, src, size, src_binding, WINED3D_MAP_READONLY);
dst_ptr = context_map_bo_address(context, dst, size, dst_binding, 0);
memcpy(dst_ptr, src_ptr, size);
context_unmap_bo_address(context, dst, dst_binding);
context_unmap_bo_address(context, src, src_binding);
}
}
else if (!dst->buffer_object && src->buffer_object)
{
context_bind_bo(context, src_binding, src->buffer_object);
GL_EXTCALL(glGetBufferSubData(src_binding, (GLintptr)src->addr, size, dst->addr));
checkGLcall("buffer download");
}
else if (dst->buffer_object && !src->buffer_object)
{
context_bind_bo(context, dst_binding, dst->buffer_object);
GL_EXTCALL(glBufferSubData(dst_binding, (GLintptr)dst->addr, size, src->addr));
checkGLcall("buffer upload");
}
else
{
memcpy(dst->addr, src->addr, size);
}
}
static void context_set_render_offscreen(struct wined3d_context *context, BOOL offscreen)
{
if (context->render_offscreen == offscreen)

View File

@ -2073,6 +2073,9 @@ void context_bind_dummy_textures(const struct wined3d_device *device,
const struct wined3d_context *context) DECLSPEC_HIDDEN;
void context_bind_texture(struct wined3d_context *context, GLenum target, GLuint name) DECLSPEC_HIDDEN;
void context_check_fbo_status(const struct wined3d_context *context, GLenum target) DECLSPEC_HIDDEN;
void context_copy_bo_address(struct wined3d_context *context,
const struct wined3d_bo_address *dst, GLenum dst_binding,
const struct wined3d_bo_address *src, GLenum src_binding, size_t size) DECLSPEC_HIDDEN;
struct wined3d_context *context_create(struct wined3d_swapchain *swapchain, struct wined3d_texture *target,
const struct wined3d_format *ds_format) DECLSPEC_HIDDEN;
HGLRC context_create_wgl_attribs(const struct wined3d_gl_info *gl_info, HDC hdc, HGLRC share_ctx) DECLSPEC_HIDDEN;