Commit 9f8b5670 authored by Zebediah Figura's avatar Zebediah Figura Committed by Alexandre Julliard

wined3d: Pass a wined3d_range array to wined3d_context_copy_bo_address().

parent a2653a94
......@@ -4597,9 +4597,10 @@ static void adapter_gl_unmap_bo_address(struct wined3d_context *context,
}
static void adapter_gl_copy_bo_address(struct wined3d_context *context,
const struct wined3d_bo_address *dst, const struct wined3d_bo_address *src, size_t size)
const struct wined3d_bo_address *dst, const struct wined3d_bo_address *src,
unsigned int range_count, const struct wined3d_range *ranges)
{
wined3d_context_gl_copy_bo_address(wined3d_context_gl(context), dst, src, size);
wined3d_context_gl_copy_bo_address(wined3d_context_gl(context), dst, src, range_count, ranges);
}
static void adapter_gl_flush_bo_address(struct wined3d_context *context,
......
......@@ -1095,7 +1095,8 @@ static void adapter_vk_unmap_bo_address(struct wined3d_context *context,
}
void adapter_vk_copy_bo_address(struct wined3d_context *context,
const struct wined3d_bo_address *dst, const struct wined3d_bo_address *src, size_t size)
const struct wined3d_bo_address *dst, const struct wined3d_bo_address *src,
unsigned int range_count, const struct wined3d_range *ranges)
{
struct wined3d_context_vk *context_vk = wined3d_context_vk(context);
const struct wined3d_vk_info *vk_info = context_vk->vk_info;
......@@ -1103,16 +1104,18 @@ void adapter_vk_copy_bo_address(struct wined3d_context *context,
VkAccessFlags src_access_mask, dst_access_mask;
VkBufferMemoryBarrier vk_barrier[2];
DWORD map_flags = WINED3D_MAP_WRITE;
const struct wined3d_range *range;
struct wined3d_bo_address staging;
VkCommandBuffer vk_command_buffer;
struct wined3d_range range;
void *dst_ptr, *src_ptr;
uint8_t *dst_ptr, *src_ptr;
VkBufferCopy region;
size_t size = 0;
unsigned int i;
src_bo = src->buffer_object ? wined3d_bo_vk(src->buffer_object) : NULL;
dst_bo = dst->buffer_object ? wined3d_bo_vk(dst->buffer_object) : NULL;
if (dst_bo && !dst->addr && size == dst_bo->size)
if (dst_bo && !dst->addr && !ranges->offset && ranges->size == dst_bo->size)
map_flags |= WINED3D_MAP_DISCARD;
if (src_bo && dst_bo)
......@@ -1128,43 +1131,52 @@ void adapter_vk_copy_bo_address(struct wined3d_context *context,
src_access_mask = vk_access_mask_from_buffer_usage(src_bo->usage);
dst_access_mask = vk_access_mask_from_buffer_usage(dst_bo->usage);
region.srcOffset = src_bo->b.buffer_offset + (uintptr_t)src->addr;
region.dstOffset = dst_bo->b.buffer_offset + (uintptr_t)dst->addr;
region.size = size;
vk_barrier[0].sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
vk_barrier[0].pNext = NULL;
vk_barrier[0].srcAccessMask = src_access_mask;
vk_barrier[0].dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT;
vk_barrier[0].srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
vk_barrier[0].dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
vk_barrier[0].buffer = src_bo->vk_buffer;
vk_barrier[0].offset = region.srcOffset;
vk_barrier[0].size = region.size;
vk_barrier[1].sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
vk_barrier[1].pNext = NULL;
vk_barrier[1].srcAccessMask = dst_access_mask;
vk_barrier[1].dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
vk_barrier[1].srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
vk_barrier[1].dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
vk_barrier[1].buffer = dst_bo->vk_buffer;
vk_barrier[1].offset = region.dstOffset;
vk_barrier[1].size = region.size;
VK_CALL(vkCmdPipelineBarrier(vk_command_buffer, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 0, NULL, 2, vk_barrier, 0, NULL));
for (i = 0; i < range_count; ++i)
{
range = &ranges[i];
region.srcOffset = src_bo->b.buffer_offset + (uintptr_t)src->addr + range->offset;
region.dstOffset = dst_bo->b.buffer_offset + (uintptr_t)dst->addr + range->offset;
region.size = range->size;
vk_barrier[0].offset = region.srcOffset;
vk_barrier[0].size = region.size;
vk_barrier[1].offset = region.dstOffset;
vk_barrier[1].size = region.size;
VK_CALL(vkCmdCopyBuffer(vk_command_buffer, src_bo->vk_buffer, dst_bo->vk_buffer, 1, &region));
vk_barrier[0].srcAccessMask = src_access_mask;
vk_barrier[0].dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT;
vk_barrier[0].srcAccessMask = VK_ACCESS_TRANSFER_READ_BIT;
vk_barrier[0].dstAccessMask = src_access_mask;
vk_barrier[1].srcAccessMask = dst_access_mask;
vk_barrier[1].dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
vk_barrier[1].srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
vk_barrier[1].dstAccessMask = dst_access_mask;
VK_CALL(vkCmdPipelineBarrier(vk_command_buffer, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 0, NULL, 2, vk_barrier, 0, NULL));
VK_CALL(vkCmdCopyBuffer(vk_command_buffer, src_bo->vk_buffer, dst_bo->vk_buffer, 1, &region));
VK_CALL(vkCmdPipelineBarrier(vk_command_buffer, VK_PIPELINE_STAGE_TRANSFER_BIT,
VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, NULL, 2, vk_barrier, 0, NULL));
vk_barrier[0].srcAccessMask = VK_ACCESS_TRANSFER_READ_BIT;
vk_barrier[0].dstAccessMask = src_access_mask;
vk_barrier[1].srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
vk_barrier[1].dstAccessMask = dst_access_mask;
VK_CALL(vkCmdPipelineBarrier(vk_command_buffer, VK_PIPELINE_STAGE_TRANSFER_BIT,
VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, NULL, 2, vk_barrier, 0, NULL));
}
wined3d_context_vk_reference_bo(context_vk, src_bo);
wined3d_context_vk_reference_bo(context_vk, dst_bo);
......@@ -1174,7 +1186,7 @@ void adapter_vk_copy_bo_address(struct wined3d_context *context,
if (src_bo && !(src_bo->memory_type & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT))
{
if (!(wined3d_context_vk_create_bo(context_vk, size, VK_BUFFER_USAGE_TRANSFER_DST_BIT,
if (!(wined3d_context_vk_create_bo(context_vk, src_bo->size, VK_BUFFER_USAGE_TRANSFER_DST_BIT,
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, &staging_bo)))
{
ERR("Failed to create staging bo.\n");
......@@ -1183,8 +1195,8 @@ void adapter_vk_copy_bo_address(struct wined3d_context *context,
staging.buffer_object = &staging_bo.b;
staging.addr = NULL;
adapter_vk_copy_bo_address(context, &staging, src, size);
adapter_vk_copy_bo_address(context, dst, &staging, size);
adapter_vk_copy_bo_address(context, &staging, src, range_count, ranges);
adapter_vk_copy_bo_address(context, dst, &staging, range_count, ranges);
wined3d_context_vk_destroy_bo(context_vk, &staging_bo);
......@@ -1194,7 +1206,7 @@ void adapter_vk_copy_bo_address(struct wined3d_context *context,
if (dst_bo && (!(dst_bo->memory_type & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) || (!(map_flags & WINED3D_MAP_DISCARD)
&& dst_bo->command_buffer_id > context_vk->completed_command_buffer_id)))
{
if (!(wined3d_context_vk_create_bo(context_vk, size, VK_BUFFER_USAGE_TRANSFER_SRC_BIT,
if (!(wined3d_context_vk_create_bo(context_vk, dst_bo->size, VK_BUFFER_USAGE_TRANSFER_SRC_BIT,
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, &staging_bo)))
{
ERR("Failed to create staging bo.\n");
......@@ -1203,22 +1215,24 @@ void adapter_vk_copy_bo_address(struct wined3d_context *context,
staging.buffer_object = &staging_bo.b;
staging.addr = NULL;
adapter_vk_copy_bo_address(context, &staging, src, size);
adapter_vk_copy_bo_address(context, dst, &staging, size);
adapter_vk_copy_bo_address(context, &staging, src, range_count, ranges);
adapter_vk_copy_bo_address(context, dst, &staging, range_count, ranges);
wined3d_context_vk_destroy_bo(context_vk, &staging_bo);
return;
}
for (i = 0; i < range_count; ++i)
size = max(size, ranges[i].offset + ranges[i].size);
src_ptr = adapter_vk_map_bo_address(context, src, size, WINED3D_MAP_READ);
dst_ptr = adapter_vk_map_bo_address(context, dst, size, map_flags);
memcpy(dst_ptr, src_ptr, size);
for (i = 0; i < range_count; ++i)
memcpy(dst_ptr + ranges[i].offset, src_ptr + ranges[i].offset, ranges[i].size);
range.offset = 0;
range.size = size;
adapter_vk_unmap_bo_address(context, dst, 1, &range);
adapter_vk_unmap_bo_address(context, dst, range_count, ranges);
adapter_vk_unmap_bo_address(context, src, 0, NULL);
}
......
......@@ -1128,12 +1128,15 @@ void wined3d_buffer_copy_bo_address(struct wined3d_buffer *dst_buffer, struct wi
unsigned int dst_offset, const struct wined3d_const_bo_address *src_addr, unsigned int size)
{
struct wined3d_bo_address dst_addr;
struct wined3d_range range;
DWORD dst_location;
dst_location = wined3d_buffer_get_memory(dst_buffer, context, &dst_addr);
dst_addr.addr += dst_offset;
wined3d_context_copy_bo_address(context, &dst_addr, (const struct wined3d_bo_address *)src_addr, size);
range.offset = 0;
range.size = size;
wined3d_context_copy_bo_address(context, &dst_addr, (const struct wined3d_bo_address *)src_addr, 1, &range);
wined3d_buffer_invalidate_range(dst_buffer, ~dst_location, dst_offset, size);
}
......@@ -1426,16 +1429,11 @@ static void wined3d_buffer_gl_upload_ranges(struct wined3d_buffer *buffer, struc
buffer, context, data, data_offset, range_count, ranges);
dst.buffer_object = buffer->buffer_object;
dst.addr = 0;
src.buffer_object = NULL;
src.addr = (uint8_t *)data - data_offset;
while (range_count--)
{
const struct wined3d_range *range = &ranges[range_count];
src.addr = (uint8_t *)data + range->offset - data_offset;
dst.addr = (void *)(uintptr_t)range->offset;
wined3d_context_copy_bo_address(context, &dst, &src, range->size);
}
wined3d_context_copy_bo_address(context, &dst, &src, range_count, ranges);
}
/* Context activation is done by the caller. */
......@@ -1644,15 +1642,8 @@ static void wined3d_buffer_vk_upload_ranges(struct wined3d_buffer *buffer, struc
&& dst_bo->command_buffer_id > context_vk->completed_command_buffer_id))
{
src.buffer_object = 0;
while (range_count--)
{
range = &ranges[range_count];
src.addr = (uint8_t *)data + range->offset - data_offset;
dst.addr = (void *)(uintptr_t)range->offset;
wined3d_context_copy_bo_address(context, &dst, &src, range->size);
}
src.addr = (uint8_t *)data - data_offset;
wined3d_context_copy_bo_address(context, &dst, &src, range_count, ranges);
return;
}
......
......@@ -3057,12 +3057,13 @@ void wined3d_context_gl_flush_bo_address(struct wined3d_context_gl *context_gl,
}
void wined3d_context_gl_copy_bo_address(struct wined3d_context_gl *context_gl,
const struct wined3d_bo_address *dst, const struct wined3d_bo_address *src, size_t size)
const struct wined3d_bo_address *dst, const struct wined3d_bo_address *src,
unsigned int range_count, const struct wined3d_range *ranges)
{
const struct wined3d_gl_info *gl_info;
struct wined3d_bo_gl *src_bo, *dst_bo;
struct wined3d_range range;
BYTE *dst_ptr, *src_ptr;
unsigned int i;
gl_info = context_gl->gl_info;
src_bo = src->buffer_object ? wined3d_bo_gl(src->buffer_object) : NULL;
......@@ -3074,9 +3075,11 @@ void wined3d_context_gl_copy_bo_address(struct wined3d_context_gl *context_gl,
{
GL_EXTCALL(glBindBuffer(GL_COPY_READ_BUFFER, src_bo->id));
GL_EXTCALL(glBindBuffer(GL_COPY_WRITE_BUFFER, dst_bo->id));
GL_EXTCALL(glCopyBufferSubData(GL_COPY_READ_BUFFER, GL_COPY_WRITE_BUFFER,
src_bo->b.buffer_offset + (GLintptr)src->addr,
dst_bo->b.buffer_offset + (GLintptr)dst->addr, size));
for (i = 0; i < range_count; ++i)
GL_EXTCALL(glCopyBufferSubData(GL_COPY_READ_BUFFER, GL_COPY_WRITE_BUFFER,
src_bo->b.buffer_offset + (GLintptr)src->addr + ranges[i].offset,
dst_bo->b.buffer_offset + (GLintptr)dst->addr + ranges[i].offset, ranges[i].size));
checkGLcall("direct buffer copy");
wined3d_context_gl_reference_bo(context_gl, src_bo);
......@@ -3084,21 +3087,25 @@ void wined3d_context_gl_copy_bo_address(struct wined3d_context_gl *context_gl,
}
else
{
src_ptr = wined3d_context_gl_map_bo_address(context_gl, src, size, WINED3D_MAP_READ);
dst_ptr = wined3d_context_gl_map_bo_address(context_gl, dst, size, WINED3D_MAP_WRITE);
src_ptr = wined3d_context_gl_map_bo_address(context_gl, src,
src_bo->size - (uintptr_t)src->addr, WINED3D_MAP_READ);
dst_ptr = wined3d_context_gl_map_bo_address(context_gl, dst,
dst_bo->size - (uintptr_t)dst->addr, WINED3D_MAP_WRITE);
memcpy(dst_ptr, src_ptr, size);
for (i = 0; i < range_count; ++i)
memcpy(dst_ptr + ranges[i].offset, src_ptr + ranges[i].offset, ranges[i].size);
range.offset = 0;
range.size = size;
wined3d_context_gl_unmap_bo_address(context_gl, dst, 1, &range);
wined3d_context_gl_unmap_bo_address(context_gl, dst, range_count, ranges);
wined3d_context_gl_unmap_bo_address(context_gl, src, 0, NULL);
}
}
else if (!dst_bo && src_bo)
{
wined3d_context_gl_bind_bo(context_gl, src_bo->binding, src_bo->id);
GL_EXTCALL(glGetBufferSubData(src_bo->binding, src_bo->b.buffer_offset + (GLintptr)src->addr, size, dst->addr));
for (i = 0; i < range_count; ++i)
GL_EXTCALL(glGetBufferSubData(src_bo->binding,
src_bo->b.buffer_offset + (GLintptr)src->addr + ranges[i].offset,
ranges[i].size, dst->addr + ranges[i].offset));
checkGLcall("buffer download");
wined3d_context_gl_reference_bo(context_gl, src_bo);
......@@ -3106,14 +3113,18 @@ void wined3d_context_gl_copy_bo_address(struct wined3d_context_gl *context_gl,
else if (dst_bo && !src_bo)
{
wined3d_context_gl_bind_bo(context_gl, dst_bo->binding, dst_bo->id);
GL_EXTCALL(glBufferSubData(dst_bo->binding, dst_bo->b.buffer_offset + (GLintptr)dst->addr, size, src->addr));
for (i = 0; i < range_count; ++i)
GL_EXTCALL(glBufferSubData(dst_bo->binding,
dst_bo->b.buffer_offset + (GLintptr)dst->addr + ranges[i].offset,
ranges[i].size, src->addr + ranges[i].offset));
checkGLcall("buffer upload");
wined3d_context_gl_reference_bo(context_gl, dst_bo);
}
else
{
memcpy(dst->addr, src->addr, size);
for (i = 0; i < range_count; ++i)
memcpy(dst->addr + ranges[i].offset, src->addr + ranges[i].offset, ranges[i].size);
}
}
......
......@@ -2804,15 +2804,20 @@ static void adapter_no3d_unmap_bo_address(struct wined3d_context *context,
}
static void adapter_no3d_copy_bo_address(struct wined3d_context *context,
const struct wined3d_bo_address *dst, const struct wined3d_bo_address *src, size_t size)
const struct wined3d_bo_address *dst, const struct wined3d_bo_address *src,
unsigned int range_count, const struct wined3d_range *ranges)
{
unsigned int i;
if (dst->buffer_object)
ERR("Unsupported dst buffer object %p.\n", dst->buffer_object);
if (src->buffer_object)
ERR("Unsupported src buffer object %p.\n", src->buffer_object);
if (dst->buffer_object || src->buffer_object)
return;
memcpy(dst->addr, src->addr, size);
for (i = 0; i < range_count; ++i)
memcpy(dst->addr + ranges[i].offset, src->addr + ranges[i].offset, ranges[i].size);
}
static void adapter_no3d_flush_bo_address(struct wined3d_context *context,
......
......@@ -798,14 +798,16 @@ BOOL wined3d_texture_load_location(struct wined3d_texture *texture,
if ((location & wined3d_texture_sysmem_locations) && (current & wined3d_texture_sysmem_locations))
{
unsigned int size = texture->sub_resources[sub_resource_idx].size;
struct wined3d_bo_address source, destination;
struct wined3d_range range;
if (!wined3d_texture_prepare_location(texture, sub_resource_idx, context, location))
return FALSE;
wined3d_texture_get_memory(texture, sub_resource_idx, &source, current);
wined3d_texture_get_memory(texture, sub_resource_idx, &destination, location);
wined3d_context_copy_bo_address(context, &destination, &source, size);
range.offset = 0;
range.size = texture->sub_resources[sub_resource_idx].size;
wined3d_context_copy_bo_address(context, &destination, &source, 1, &range);
ret = TRUE;
}
else
......
......@@ -1616,6 +1616,7 @@ void wined3d_unordered_access_view_set_counter(struct wined3d_unordered_access_v
{
struct wined3d_bo_address dst, src;
struct wined3d_context *context;
struct wined3d_range range;
if (!view->counter_bo)
return;
......@@ -1628,7 +1629,9 @@ void wined3d_unordered_access_view_set_counter(struct wined3d_unordered_access_v
dst.buffer_object = view->counter_bo;
dst.addr = NULL;
wined3d_context_copy_bo_address(context, &dst, &src, sizeof(uint32_t));
range.offset = 0;
range.size = sizeof(value);
wined3d_context_copy_bo_address(context, &dst, &src, 1, &range);
context_release(context);
}
......@@ -1914,6 +1917,7 @@ void wined3d_unordered_access_view_vk_clear(struct wined3d_unordered_access_view
struct wined3d_bo_vk constants_bo;
VkWriteDescriptorSet vk_writes[2];
VkBufferView vk_buffer_view;
struct wined3d_range range;
VkMemoryBarrier vk_barrier;
VkPipeline vk_pipeline;
DWORD uav_location;
......@@ -2111,7 +2115,9 @@ void wined3d_unordered_access_view_vk_clear(struct wined3d_unordered_access_view
cb_destination_address.buffer_object = &constants_bo.b;
cb_destination_address.addr = 0;
adapter_vk_copy_bo_address(&context_vk->c, &cb_destination_address, &cb_source_address, sizeof(constants));
range.offset = 0;
range.size = sizeof(constants);
adapter_vk_copy_bo_address(&context_vk->c, &cb_destination_address, &cb_source_address, 1, &range);
buffer_info.buffer = constants_bo.vk_buffer;
buffer_info.range = constants_bo.size;
......
......@@ -2380,7 +2380,8 @@ void wined3d_context_gl_bind_texture(struct wined3d_context_gl *context_gl,
GLenum target, GLuint name) DECLSPEC_HIDDEN;
void wined3d_context_gl_check_fbo_status(const struct wined3d_context_gl *context_gl, GLenum target) DECLSPEC_HIDDEN;
void wined3d_context_gl_copy_bo_address(struct wined3d_context_gl *context_gl,
const struct wined3d_bo_address *dst, const struct wined3d_bo_address *src, size_t size) DECLSPEC_HIDDEN;
const struct wined3d_bo_address *dst, const struct wined3d_bo_address *src,
unsigned int range_count, const struct wined3d_range *ranges) DECLSPEC_HIDDEN;
bool wined3d_context_gl_create_bo(struct wined3d_context_gl *context_gl, GLsizeiptr size, GLenum binding,
GLenum usage, bool coherent, GLbitfield flags, struct wined3d_bo_gl *bo) DECLSPEC_HIDDEN;
void wined3d_context_gl_destroy(struct wined3d_context_gl *context_gl) DECLSPEC_HIDDEN;
......@@ -3412,7 +3413,8 @@ struct wined3d_adapter_ops
void (*adapter_unmap_bo_address)(struct wined3d_context *context, const struct wined3d_bo_address *data,
unsigned int range_count, const struct wined3d_range *ranges);
void (*adapter_copy_bo_address)(struct wined3d_context *context,
const struct wined3d_bo_address *dst, const struct wined3d_bo_address *src, size_t size);
const struct wined3d_bo_address *dst, const struct wined3d_bo_address *src,
unsigned int range_count, const struct wined3d_range *ranges);
void (*adapter_flush_bo_address)(struct wined3d_context *context,
const struct wined3d_const_bo_address *data, size_t size);
bool (*adapter_alloc_bo)(struct wined3d_device *device, struct wined3d_resource *resource,
......@@ -3555,7 +3557,8 @@ struct wined3d_adapter *wined3d_adapter_vk_create(unsigned int ordinal,
unsigned int wined3d_adapter_vk_get_memory_type_index(const struct wined3d_adapter_vk *adapter_vk,
uint32_t memory_type_mask, VkMemoryPropertyFlags flags) DECLSPEC_HIDDEN;
void adapter_vk_copy_bo_address(struct wined3d_context *context, const struct wined3d_bo_address *dst,
const struct wined3d_bo_address *src, size_t size) DECLSPEC_HIDDEN;
const struct wined3d_bo_address *src,
unsigned int range_count, const struct wined3d_range *ranges) DECLSPEC_HIDDEN;
struct wined3d_caps_gl_ctx
{
......@@ -6400,9 +6403,10 @@ static inline void wined3d_context_unmap_bo_address(struct wined3d_context *cont
}
static inline void wined3d_context_copy_bo_address(struct wined3d_context *context,
const struct wined3d_bo_address *dst, const struct wined3d_bo_address *src, size_t size)
const struct wined3d_bo_address *dst, const struct wined3d_bo_address *src,
unsigned int range_count, const struct wined3d_range *ranges)
{
context->device->adapter->adapter_ops->adapter_copy_bo_address(context, dst, src, size);
context->device->adapter->adapter_ops->adapter_copy_bo_address(context, dst, src, range_count, ranges);
}
static inline void wined3d_context_flush_bo_address(struct wined3d_context *context,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment