So as to allow the "buffer_object" field to point to other another wined3d_bo_vk; namely, one allocated and still in use by the client thread.
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- dlls/wined3d/adapter_vk.c | 4 ++-- dlls/wined3d/buffer.c | 13 ++++++++----- dlls/wined3d/context_vk.c | 8 ++++---- dlls/wined3d/view.c | 14 ++++++++++---- dlls/wined3d/wined3d_private.h | 2 +- 5 files changed, 25 insertions(+), 16 deletions(-)
diff --git a/dlls/wined3d/adapter_vk.c b/dlls/wined3d/adapter_vk.c index 2bd3aa31e49..2e14972f4d8 100644 --- a/dlls/wined3d/adapter_vk.c +++ b/dlls/wined3d/adapter_vk.c @@ -1745,7 +1745,7 @@ static void adapter_vk_draw_primitive(struct wined3d_device *device,
if (parameters->indirect) { - struct wined3d_bo_vk *bo = &indirect_vk->bo; + struct wined3d_bo_vk *bo = (struct wined3d_bo_vk *)indirect_vk->b.buffer_object; uint32_t stride, size;
wined3d_context_vk_reference_bo(context_vk, bo); @@ -1817,7 +1817,7 @@ static void adapter_vk_dispatch_compute(struct wined3d_device *device,
if (parameters->indirect) { - struct wined3d_bo_vk *bo = &indirect_vk->bo; + struct wined3d_bo_vk *bo = (struct wined3d_bo_vk *)indirect_vk->b.buffer_object;
wined3d_context_vk_reference_bo(context_vk, bo); VK_CALL(vkCmdDispatchIndirect(vk_command_buffer, bo->vk_buffer, diff --git a/dlls/wined3d/buffer.c b/dlls/wined3d/buffer.c index 62f84c96f96..0a72f19935b 100644 --- a/dlls/wined3d/buffer.c +++ b/dlls/wined3d/buffer.c @@ -1459,11 +1459,13 @@ static BOOL wined3d_buffer_vk_create_buffer_object(struct wined3d_buffer_vk *buf
const VkDescriptorBufferInfo *wined3d_buffer_vk_get_buffer_info(struct wined3d_buffer_vk *buffer_vk) { + struct wined3d_bo_vk *bo = (struct wined3d_bo_vk *)buffer_vk->b.buffer_object; + if (buffer_vk->b.bo_user.valid) return &buffer_vk->buffer_info;
- buffer_vk->buffer_info.buffer = buffer_vk->bo.vk_buffer; - buffer_vk->buffer_info.offset = buffer_vk->bo.buffer_offset; + buffer_vk->buffer_info.buffer = bo->vk_buffer; + buffer_vk->buffer_info.offset = bo->buffer_offset; buffer_vk->buffer_info.range = buffer_vk->b.resource.size; buffer_vk->b.bo_user.valid = true;
@@ -1537,7 +1539,7 @@ static void wined3d_buffer_vk_upload_ranges(struct wined3d_buffer *buffer, struc if (!ranges->offset && ranges->size == resource->size) flags |= WINED3D_MAP_DISCARD;
- dst_bo = &wined3d_buffer_vk(buffer)->bo; + dst_bo = (struct wined3d_bo_vk *)buffer->buffer_object; if (!(dst_bo->memory_type & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) || (!(flags & WINED3D_MAP_DISCARD) && dst_bo->command_buffer_id > context_vk->completed_command_buffer_id)) { @@ -1629,6 +1631,7 @@ void wined3d_buffer_vk_barrier(struct wined3d_buffer_vk *buffer_vk,
if (src_bind_mask) { + const struct wined3d_bo_vk *bo = (struct wined3d_bo_vk *)buffer_vk->b.buffer_object; const struct wined3d_vk_info *vk_info = context_vk->vk_info; VkBufferMemoryBarrier vk_barrier;
@@ -1643,8 +1646,8 @@ void wined3d_buffer_vk_barrier(struct wined3d_buffer_vk *buffer_vk, vk_barrier.dstAccessMask = vk_access_mask_from_bind_flags(bind_mask); vk_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; vk_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; - vk_barrier.buffer = buffer_vk->bo.vk_buffer; - vk_barrier.offset = buffer_vk->bo.buffer_offset; + vk_barrier.buffer = bo->vk_buffer; + vk_barrier.offset = bo->buffer_offset; vk_barrier.size = buffer_vk->b.resource.size; VK_CALL(vkCmdPipelineBarrier(wined3d_context_vk_get_command_buffer(context_vk), vk_pipeline_stage_mask_from_bind_flags(src_bind_mask), diff --git a/dlls/wined3d/context_vk.c b/dlls/wined3d/context_vk.c index 54c5eb6bc24..854a800c0e4 100644 --- a/dlls/wined3d/context_vk.c +++ b/dlls/wined3d/context_vk.c @@ -2496,7 +2496,7 @@ static void wined3d_context_vk_bind_vertex_buffers(struct wined3d_context_vk *co { buffer_vk = wined3d_buffer_vk(buffer); buffer_info = wined3d_buffer_vk_get_buffer_info(buffer_vk); - wined3d_context_vk_reference_bo(context_vk, &buffer_vk->bo); + wined3d_context_vk_reference_bo(context_vk, (struct wined3d_bo_vk *)buffer->buffer_object); buffers[count] = buffer_info->buffer; offsets[count] = buffer_info->offset + stream->offset; ++count; @@ -2535,7 +2535,7 @@ static void wined3d_context_vk_bind_stream_output_buffers(struct wined3d_context { buffer_vk = wined3d_buffer_vk(buffer); buffer_info = wined3d_buffer_vk_get_buffer_info(buffer_vk); - wined3d_context_vk_reference_bo(context_vk, &buffer_vk->bo); + wined3d_context_vk_reference_bo(context_vk, (struct wined3d_bo_vk *)buffer->buffer_object); buffers[count] = buffer_info->buffer; if ((offsets[count] = stream->offset) == ~0u) { @@ -2737,7 +2737,7 @@ static bool wined3d_shader_descriptor_writes_vk_add_cbv_write(struct wined3d_sha if (!wined3d_shader_descriptor_writes_vk_add_write(writes, vk_descriptor_set, binding->binding_idx, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, buffer_info, NULL, NULL)) return false; - wined3d_context_vk_reference_bo(context_vk, &buffer_vk->bo); + wined3d_context_vk_reference_bo(context_vk, (struct wined3d_bo_vk *)buffer->buffer_object); return true; }
@@ -3385,7 +3385,7 @@ VkCommandBuffer wined3d_context_vk_apply_draw_state(struct wined3d_context_vk *c idx_type = VK_INDEX_TYPE_UINT32; buffer_vk = wined3d_buffer_vk(state->index_buffer); buffer_info = wined3d_buffer_vk_get_buffer_info(buffer_vk); - wined3d_context_vk_reference_bo(context_vk, &buffer_vk->bo); + wined3d_context_vk_reference_bo(context_vk, (struct wined3d_bo_vk *)buffer_vk->b.buffer_object); VK_CALL(vkCmdBindIndexBuffer(vk_command_buffer, buffer_info->buffer, buffer_info->offset + state->index_offset, idx_type)); } diff --git a/dlls/wined3d/view.c b/dlls/wined3d/view.c index 374e693b17d..ee398be15f0 100644 --- a/dlls/wined3d/view.c +++ b/dlls/wined3d/view.c @@ -672,17 +672,19 @@ static VkBufferView wined3d_view_vk_create_vk_buffer_view(struct wined3d_context struct wined3d_device_vk *device_vk; VkBufferView vk_buffer_view; unsigned int offset, size; + struct wined3d_bo_vk *bo; VkResult vr;
get_buffer_view_range(&buffer_vk->b, desc, &view_format_vk->f, &offset, &size); wined3d_buffer_prepare_location(&buffer_vk->b, &context_vk->c, WINED3D_LOCATION_BUFFER); + bo = (struct wined3d_bo_vk *)buffer_vk->b.buffer_object;
create_info.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO; create_info.pNext = NULL; create_info.flags = 0; - create_info.buffer = buffer_vk->bo.vk_buffer; + create_info.buffer = bo->vk_buffer; create_info.format = view_format_vk->vk_format; - create_info.offset = buffer_vk->bo.buffer_offset + offset; + create_info.offset = bo->buffer_offset + offset; create_info.range = size;
device_vk = wined3d_device_vk(buffer_vk->b.resource.device); @@ -1082,6 +1084,7 @@ static void wined3d_shader_resource_view_vk_cs_init(void *object) VkBufferView vk_buffer_view; uint32_t default_flags = 0; VkImageView vk_image_view; + struct wined3d_bo_vk *bo;
TRACE("srv_vk %p.\n", srv_vk);
@@ -1099,12 +1102,13 @@ static void wined3d_shader_resource_view_vk_cs_init(void *object)
if (!vk_buffer_view) return; + bo = (struct wined3d_bo_vk *)buffer_vk->b.buffer_object;
TRACE("Created buffer view 0x%s.\n", wine_dbgstr_longlong(vk_buffer_view));
srv_vk->view_vk.u.vk_buffer_view = vk_buffer_view; srv_vk->view_vk.bo_user.valid = true; - list_add_head(&buffer_vk->bo.b.users, &srv_vk->view_vk.bo_user.entry); + list_add_head(&bo->b.users, &srv_vk->view_vk.bo_user.entry);
return; } @@ -2204,11 +2208,13 @@ static void wined3d_unordered_access_view_vk_cs_init(void *object)
if ((vk_buffer_view = wined3d_view_vk_create_vk_buffer_view(context_vk, desc, buffer_vk, format_vk))) { + struct wined3d_bo_vk *bo = (struct wined3d_bo_vk *)buffer_vk->b.buffer_object; + TRACE("Created buffer view 0x%s.\n", wine_dbgstr_longlong(vk_buffer_view));
uav_vk->view_vk.u.vk_buffer_view = vk_buffer_view; uav_vk->view_vk.bo_user.valid = true; - list_add_head(&buffer_vk->bo.b.users, &view_vk->bo_user.entry); + list_add_head(&bo->b.users, &view_vk->bo_user.entry); }
if (desc->flags & (WINED3D_VIEW_BUFFER_COUNTER | WINED3D_VIEW_BUFFER_APPEND)) diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h index 8da8a60d28e..dd04569d86a 100644 --- a/dlls/wined3d/wined3d_private.h +++ b/dlls/wined3d/wined3d_private.h @@ -6315,7 +6315,7 @@ static inline void wined3d_context_vk_reference_resource(const struct wined3d_co struct wined3d_resource *resource) { if (resource->type == WINED3D_RTYPE_BUFFER) - wined3d_context_vk_reference_bo(context_vk, &wined3d_buffer_vk(buffer_from_resource(resource))->bo); + wined3d_context_vk_reference_bo(context_vk, (struct wined3d_bo_vk *)buffer_from_resource(resource)->buffer_object); else wined3d_context_vk_reference_texture(context_vk, wined3d_texture_vk(texture_from_resource(resource))); }
So as to allow chunks to be mapped from the client thread.
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- dlls/wined3d/adapter_vk.c | 2 +- dlls/wined3d/context_vk.c | 25 ++++++++++++++++++++++++- dlls/wined3d/wined3d_private.h | 5 +++++ 3 files changed, 30 insertions(+), 2 deletions(-)
diff --git a/dlls/wined3d/adapter_vk.c b/dlls/wined3d/adapter_vk.c index 2e14972f4d8..8335a030b6b 100644 --- a/dlls/wined3d/adapter_vk.c +++ b/dlls/wined3d/adapter_vk.c @@ -380,7 +380,7 @@ static void wined3d_allocator_vk_destroy_chunk(struct wined3d_allocator_chunk *c
TRACE("chunk %p.\n", chunk);
- device_vk = CONTAINING_RECORD(chunk_vk->c.allocator, struct wined3d_device_vk, allocator); + device_vk = wined3d_device_vk_from_allocator(chunk_vk->c.allocator); vk_info = &device_vk->vk_info;
if (chunk_vk->c.map_ptr) diff --git a/dlls/wined3d/context_vk.c b/dlls/wined3d/context_vk.c index 854a800c0e4..46769be516e 100644 --- a/dlls/wined3d/context_vk.c +++ b/dlls/wined3d/context_vk.c @@ -247,16 +247,29 @@ static VkStencilOp vk_stencil_op_from_wined3d(enum wined3d_stencil_op op) } }
+static void wined3d_allocator_chunk_vk_lock(struct wined3d_allocator_chunk_vk *chunk_vk) +{ + wined3d_device_vk_allocator_lock(wined3d_device_vk_from_allocator(chunk_vk->c.allocator)); +} + +static void wined3d_allocator_chunk_vk_unlock(struct wined3d_allocator_chunk_vk *chunk_vk) +{ + wined3d_device_vk_allocator_unlock(wined3d_device_vk_from_allocator(chunk_vk->c.allocator)); +} + void *wined3d_allocator_chunk_vk_map(struct wined3d_allocator_chunk_vk *chunk_vk, struct wined3d_context_vk *context_vk) { struct wined3d_device_vk *device_vk = wined3d_device_vk(context_vk->c.device); const struct wined3d_vk_info *vk_info = context_vk->vk_info; + void *map_ptr; VkResult vr;
TRACE("chunk %p, memory 0x%s, map_ptr %p.\n", chunk_vk, wine_dbgstr_longlong(chunk_vk->vk_memory), chunk_vk->c.map_ptr);
+ wined3d_allocator_chunk_vk_lock(chunk_vk); + if (!chunk_vk->c.map_ptr && (vr = VK_CALL(vkMapMemory(device_vk->vk_device, chunk_vk->vk_memory, 0, VK_WHOLE_SIZE, 0, &chunk_vk->c.map_ptr))) < 0) { @@ -265,8 +278,11 @@ void *wined3d_allocator_chunk_vk_map(struct wined3d_allocator_chunk_vk *chunk_vk }
++chunk_vk->c.map_count; + map_ptr = chunk_vk->c.map_ptr;
- return chunk_vk->c.map_ptr; + wined3d_allocator_chunk_vk_unlock(chunk_vk); + + return map_ptr; }
void wined3d_allocator_chunk_vk_unmap(struct wined3d_allocator_chunk_vk *chunk_vk, @@ -277,11 +293,18 @@ void wined3d_allocator_chunk_vk_unmap(struct wined3d_allocator_chunk_vk *chunk_v
TRACE("chunk_vk %p, context_vk %p.\n", chunk_vk, context_vk);
+ wined3d_allocator_chunk_vk_lock(chunk_vk); + if (--chunk_vk->c.map_count) + { + wined3d_allocator_chunk_vk_unlock(chunk_vk); return; + }
VK_CALL(vkUnmapMemory(device_vk->vk_device, chunk_vk->vk_memory)); chunk_vk->c.map_ptr = NULL; + + wined3d_allocator_chunk_vk_unlock(chunk_vk); }
VkDeviceMemory wined3d_context_vk_allocate_vram_chunk_memory(struct wined3d_context_vk *context_vk, diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h index dd04569d86a..e0cae322179 100644 --- a/dlls/wined3d/wined3d_private.h +++ b/dlls/wined3d/wined3d_private.h @@ -4101,6 +4101,11 @@ static inline struct wined3d_device_vk *wined3d_device_vk(struct wined3d_device return CONTAINING_RECORD(device, struct wined3d_device_vk, d); }
+static inline struct wined3d_device_vk *wined3d_device_vk_from_allocator(struct wined3d_allocator *allocator) +{ + return CONTAINING_RECORD(allocator, struct wined3d_device_vk, allocator); +} + static inline void wined3d_device_vk_allocator_lock(struct wined3d_device_vk *device_vk) { EnterCriticalSection(&device_vk->allocator_cs);
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com
That is, no longer allocate a wined3d_bo_vk as part of the wined3d_buffer_vk structure.
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- dlls/wined3d/buffer.c | 23 +++++++++++++---------- dlls/wined3d/wined3d_private.h | 1 - 2 files changed, 13 insertions(+), 11 deletions(-)
diff --git a/dlls/wined3d/buffer.c b/dlls/wined3d/buffer.c index 0a72f19935b..56069cb9f16 100644 --- a/dlls/wined3d/buffer.c +++ b/dlls/wined3d/buffer.c @@ -1440,18 +1440,22 @@ static BOOL wined3d_buffer_vk_create_buffer_object(struct wined3d_buffer_vk *buf struct wined3d_context_vk *context_vk) { struct wined3d_resource *resource = &buffer_vk->b.resource; + struct wined3d_bo_vk *bo_vk; + + if (!(bo_vk = heap_alloc(sizeof(*bo_vk)))) + return FALSE;
if (!(wined3d_context_vk_create_bo(context_vk, resource->size, vk_buffer_usage_from_bind_flags(resource->bind_flags), - vk_memory_type_from_access_flags(resource->access, resource->usage), &buffer_vk->bo))) + vk_memory_type_from_access_flags(resource->access, resource->usage), bo_vk))) { WARN("Failed to create Vulkan buffer.\n"); return FALSE; }
list_init(&buffer_vk->b.bo_user.entry); - list_add_head(&buffer_vk->bo.b.users, &buffer_vk->b.bo_user.entry); - buffer_vk->b.buffer_object = (uintptr_t)&buffer_vk->bo; + list_add_head(&bo_vk->b.users, &buffer_vk->b.bo_user.entry); + buffer_vk->b.buffer_object = (uintptr_t)bo_vk; buffer_invalidate_bo_range(&buffer_vk->b, 0, 0);
return TRUE; @@ -1495,20 +1499,19 @@ static BOOL wined3d_buffer_vk_prepare_location(struct wined3d_buffer *buffer, static void wined3d_buffer_vk_unload_location(struct wined3d_buffer *buffer, struct wined3d_context *context, unsigned int location) { + struct wined3d_bo_vk *bo_vk = (struct wined3d_bo_vk *)buffer->buffer_object; struct wined3d_context_vk *context_vk = wined3d_context_vk(context); - struct wined3d_buffer_vk *buffer_vk = wined3d_buffer_vk(buffer);
TRACE("buffer %p, context %p, location %s.\n", buffer, context, wined3d_debug_location(location));
switch (location) { case WINED3D_LOCATION_BUFFER: - buffer_vk->b.bo_user.valid = false; - list_remove(&buffer_vk->b.bo_user.entry); - wined3d_context_vk_destroy_bo(context_vk, &buffer_vk->bo); - buffer_vk->bo.vk_buffer = VK_NULL_HANDLE; - buffer_vk->bo.memory = NULL; - buffer_vk->b.buffer_object = 0u; + buffer->bo_user.valid = false; + list_remove(&buffer->bo_user.entry); + wined3d_context_vk_destroy_bo(context_vk, bo_vk); + heap_free(bo_vk); + buffer->buffer_object = 0u; break;
default: diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h index e0cae322179..398bd73c5c0 100644 --- a/dlls/wined3d/wined3d_private.h +++ b/dlls/wined3d/wined3d_private.h @@ -5097,7 +5097,6 @@ struct wined3d_buffer_vk { struct wined3d_buffer b;
- struct wined3d_bo_vk bo; VkDescriptorBufferInfo buffer_info; uint32_t bind_mask; };
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- dlls/wined3d/adapter_gl.c | 7 ++++ dlls/wined3d/adapter_vk.c | 49 +++++++++++++++++++++++++++ dlls/wined3d/buffer.c | 60 ++++++++++++++++++++++++++++++++-- dlls/wined3d/cs.c | 16 ++++++++- dlls/wined3d/directx.c | 7 ++++ dlls/wined3d/wined3d_private.h | 13 ++++++++ 6 files changed, 149 insertions(+), 3 deletions(-)
diff --git a/dlls/wined3d/adapter_gl.c b/dlls/wined3d/adapter_gl.c index 7ec30cb4356..8ec59c5cbc3 100644 --- a/dlls/wined3d/adapter_gl.c +++ b/dlls/wined3d/adapter_gl.c @@ -4606,6 +4606,12 @@ static void adapter_gl_flush_bo_address(struct wined3d_context *context, wined3d_context_gl_flush_bo_address(wined3d_context_gl(context), data, size); }
+static bool adapter_gl_alloc_bo(struct wined3d_device *device, struct wined3d_resource *resource, + unsigned int sub_resource_idx, struct wined3d_bo_address *addr) +{ + return false; +} + static HRESULT adapter_gl_create_swapchain(struct wined3d_device *device, struct wined3d_swapchain_desc *desc, struct wined3d_swapchain_state_parent *state_parent, void *parent, const struct wined3d_parent_ops *parent_ops, struct wined3d_swapchain **swapchain) @@ -5059,6 +5065,7 @@ static const struct wined3d_adapter_ops wined3d_adapter_gl_ops = .adapter_unmap_bo_address = adapter_gl_unmap_bo_address, .adapter_copy_bo_address = adapter_gl_copy_bo_address, .adapter_flush_bo_address = adapter_gl_flush_bo_address, + .adapter_alloc_bo = adapter_gl_alloc_bo, .adapter_create_swapchain = adapter_gl_create_swapchain, .adapter_destroy_swapchain = adapter_gl_destroy_swapchain, .adapter_create_buffer = adapter_gl_create_buffer, diff --git a/dlls/wined3d/adapter_vk.c b/dlls/wined3d/adapter_vk.c index 8335a030b6b..3e1d63234ec 100644 --- a/dlls/wined3d/adapter_vk.c +++ b/dlls/wined3d/adapter_vk.c @@ -23,6 +23,7 @@ #include "wine/vulkan_driver.h"
WINE_DEFAULT_DEBUG_CHANNEL(d3d); +WINE_DECLARE_DEBUG_CHANNEL(d3d_perf);
static const struct wined3d_state_entry_template misc_state_template_vk[] = { @@ -1216,6 +1217,53 @@ static void adapter_vk_flush_bo_address(struct wined3d_context *context, flush_bo_range(context_vk, bo, (uintptr_t)data->addr, size); }
+struct wined3d_client_bo_vk_map_ctx +{ + struct wined3d_device *device; + struct wined3d_client_bo_vk *client_bo; +}; + +static bool adapter_vk_alloc_bo(struct wined3d_device *device, struct wined3d_resource *resource, + unsigned int sub_resource_idx, struct wined3d_bo_address *addr) +{ + struct wined3d_device_vk *device_vk = wined3d_device_vk(device); + struct wined3d_context_vk *context_vk = &device_vk->context_vk; + + wined3d_not_from_cs(device->cs); + assert(device->context_count); + + if (resource->type == WINED3D_RTYPE_BUFFER) + { + struct wined3d_bo_vk *bo_vk; + + if (!(bo_vk = heap_alloc(sizeof(*bo_vk)))) + return false; + + if (!(wined3d_context_vk_create_bo(context_vk, resource->size, + vk_buffer_usage_from_bind_flags(resource->bind_flags), + vk_memory_type_from_access_flags(resource->access, resource->usage), bo_vk))) + { + WARN("Failed to create Vulkan buffer.\n"); + return false; + } + + if (!bo_vk->b.map_ptr) + { + WARN_(d3d_perf)("BO %p (chunk %p, slab %p) is not persistently mapped.\n", + bo_vk, bo_vk->memory ? bo_vk->memory->chunk : NULL, bo_vk->slab); + + if (!wined3d_bo_vk_map(bo_vk, context_vk)) + ERR("Failed to map bo.\n"); + } + + addr->buffer_object = (uintptr_t)bo_vk; + addr->addr = NULL; + return true; + } + + return false; +} + static HRESULT adapter_vk_create_swapchain(struct wined3d_device *device, struct wined3d_swapchain_desc *desc, struct wined3d_swapchain_state_parent *state_parent, void *parent, const struct wined3d_parent_ops *parent_ops, struct wined3d_swapchain **swapchain) @@ -1868,6 +1916,7 @@ static const struct wined3d_adapter_ops wined3d_adapter_vk_ops = .adapter_unmap_bo_address = adapter_vk_unmap_bo_address, .adapter_copy_bo_address = adapter_vk_copy_bo_address, .adapter_flush_bo_address = adapter_vk_flush_bo_address, + .adapter_alloc_bo = adapter_vk_alloc_bo, .adapter_create_swapchain = adapter_vk_create_swapchain, .adapter_destroy_swapchain = adapter_vk_destroy_swapchain, .adapter_create_buffer = adapter_vk_create_buffer, diff --git a/dlls/wined3d/buffer.c b/dlls/wined3d/buffer.c index 56069cb9f16..a9beba023de 100644 --- a/dlls/wined3d/buffer.c +++ b/dlls/wined3d/buffer.c @@ -1061,6 +1061,16 @@ static HRESULT buffer_resource_sub_resource_unmap(struct wined3d_resource *resou return WINED3D_OK; }
+void wined3d_buffer_set_bo(struct wined3d_buffer *buffer, struct wined3d_context *context, struct wined3d_bo *bo) +{ + TRACE("buffer %p, context %p, bo %p.\n", buffer, context, bo); + + buffer->buffer_ops->buffer_set_bo(buffer, context, bo); + buffer->buffer_object = (uintptr_t)bo; + wined3d_buffer_validate_location(buffer, WINED3D_LOCATION_BUFFER); + wined3d_buffer_invalidate_location(buffer, ~WINED3D_LOCATION_BUFFER); +} + void wined3d_buffer_copy_bo_address(struct wined3d_buffer *dst_buffer, struct wined3d_context *context, unsigned int dst_offset, const struct wined3d_const_bo_address *src_addr, unsigned int size) { @@ -1256,12 +1266,19 @@ static void wined3d_buffer_no3d_download_ranges(struct wined3d_buffer *buffer, s FIXME("Not implemented.\n"); }
+static void wined3d_buffer_no3d_set_bo(struct wined3d_buffer *buffer, + struct wined3d_context *context, struct wined3d_bo *bo) +{ + FIXME("Not implemented.\n"); +} + static const struct wined3d_buffer_ops wined3d_buffer_no3d_ops = { wined3d_buffer_no3d_prepare_location, wined3d_buffer_no3d_unload_location, wined3d_buffer_no3d_upload_ranges, wined3d_buffer_no3d_download_ranges, + wined3d_buffer_no3d_set_bo, };
HRESULT wined3d_buffer_no3d_init(struct wined3d_buffer *buffer_no3d, struct wined3d_device *device, @@ -1366,12 +1383,19 @@ static void wined3d_buffer_gl_download_ranges(struct wined3d_buffer *buffer, str checkGLcall("buffer download"); }
+static void wined3d_buffer_gl_set_bo(struct wined3d_buffer *buffer, + struct wined3d_context *context, struct wined3d_bo *bo) +{ + FIXME("Not implemented.\n"); +} + static const struct wined3d_buffer_ops wined3d_buffer_gl_ops = { wined3d_buffer_gl_prepare_location, wined3d_buffer_gl_unload_location, wined3d_buffer_gl_upload_ranges, wined3d_buffer_gl_download_ranges, + wined3d_buffer_gl_set_bo, };
HRESULT wined3d_buffer_gl_init(struct wined3d_buffer_gl *buffer_gl, struct wined3d_device *device, @@ -1399,7 +1423,7 @@ HRESULT wined3d_buffer_gl_init(struct wined3d_buffer_gl *buffer_gl, struct wined return wined3d_buffer_init(&buffer_gl->b, device, desc, data, parent, parent_ops, &wined3d_buffer_gl_ops); }
-static VkBufferUsageFlags vk_buffer_usage_from_bind_flags(uint32_t bind_flags) +VkBufferUsageFlags vk_buffer_usage_from_bind_flags(uint32_t bind_flags) { VkBufferUsageFlags usage;
@@ -1423,7 +1447,7 @@ static VkBufferUsageFlags vk_buffer_usage_from_bind_flags(uint32_t bind_flags) return usage; }
-static VkMemoryPropertyFlags vk_memory_type_from_access_flags(uint32_t access, uint32_t usage) +VkMemoryPropertyFlags vk_memory_type_from_access_flags(uint32_t access, uint32_t usage) { VkMemoryPropertyFlags memory_type = 0;
@@ -1580,12 +1604,44 @@ static void wined3d_buffer_vk_download_ranges(struct wined3d_buffer *buffer, str FIXME("Not implemented.\n"); }
+static void wined3d_buffer_vk_set_bo(struct wined3d_buffer *buffer, + struct wined3d_context *context, struct wined3d_bo *bo) +{ + struct wined3d_bo_vk *prev_bo = (struct wined3d_bo_vk *)buffer->buffer_object; + struct wined3d_context_vk *context_vk = wined3d_context_vk(context); + struct wined3d_buffer_vk *buffer_vk = wined3d_buffer_vk(buffer); + struct wined3d_bo_vk *bo_vk = wined3d_bo_vk(bo); + + /* We can't just copy the contents of bo_vk into buffer_vk->bo, because the + * new BO might still be in use by the client thread. We could allow both to + * be valid, although knowing when to destroy a BO then becomes tricky, and + * ensuring it's not mapped more than once also becomes tricky. */ + + if (prev_bo) + { + struct wined3d_bo_user *bo_user; + + LIST_FOR_EACH_ENTRY(bo_user, &prev_bo->b.users, struct wined3d_bo_user, entry) + bo_user->valid = false; + assert(list_empty(&bo_vk->b.users)); + list_move_head(&bo_vk->b.users, &prev_bo->b.users); + + wined3d_context_vk_destroy_bo(context_vk, prev_bo); + heap_free(prev_bo); + } + else + { + list_add_head(&bo_vk->b.users, &buffer_vk->b.bo_user.entry); + } +} + static const struct wined3d_buffer_ops wined3d_buffer_vk_ops = { wined3d_buffer_vk_prepare_location, wined3d_buffer_vk_unload_location, wined3d_buffer_vk_upload_ranges, wined3d_buffer_vk_download_ranges, + wined3d_buffer_vk_set_bo, };
HRESULT wined3d_buffer_vk_init(struct wined3d_buffer_vk *buffer_vk, struct wined3d_device *device, diff --git a/dlls/wined3d/cs.c b/dlls/wined3d/cs.c index e6ff448b028..ac7799e17b2 100644 --- a/dlls/wined3d/cs.c +++ b/dlls/wined3d/cs.c @@ -2747,6 +2747,9 @@ static void wined3d_cs_exec_update_sub_resource(struct wined3d_cs *cs, const voi struct wined3d_buffer *buffer = buffer_from_resource(resource); size_t size = box->right - box->left;
+ if (op->bo.flags & UPLOAD_BO_RENAME_ON_UNMAP) + wined3d_buffer_set_bo(buffer, context, (struct wined3d_bo *)op->bo.addr.buffer_object); + if (op->bo.addr.buffer_object && op->bo.addr.buffer_object == buffer->buffer_object) wined3d_context_flush_bo_address(context, &op->bo.addr, size); else @@ -3121,12 +3124,20 @@ static bool wined3d_cs_map_upload_bo(struct wined3d_device_context *context, str { /* Limit NOOVERWRITE maps to buffers for now; there are too many ways that * a texture can be invalidated to even count. */ - if (wined3d_map_persistent() && resource->type == WINED3D_RTYPE_BUFFER && (flags & WINED3D_MAP_NOOVERWRITE)) + if (wined3d_map_persistent() && resource->type == WINED3D_RTYPE_BUFFER + && (flags & (WINED3D_MAP_DISCARD | WINED3D_MAP_NOOVERWRITE))) { struct wined3d_client_resource *client = &resource->client; + struct wined3d_device *device = context->device; const struct wined3d_bo *bo; uint8_t *map_ptr;
+ if (flags & WINED3D_MAP_DISCARD) + { + if (!device->adapter->adapter_ops->adapter_alloc_bo(device, resource, sub_resource_idx, &client->addr)) + return false; + } + bo = (const struct wined3d_bo *)client->addr.buffer_object; map_ptr = bo ? bo->map_ptr : NULL; map_ptr += (uintptr_t)client->addr.addr; @@ -3150,6 +3161,9 @@ static bool wined3d_cs_map_upload_bo(struct wined3d_device_context *context, str } map_desc->data = resource_offset_map_pointer(resource, sub_resource_idx, map_ptr, box);
+ if (flags & WINED3D_MAP_DISCARD) + client->mapped_upload.flags |= UPLOAD_BO_UPLOAD_ON_UNMAP | UPLOAD_BO_RENAME_ON_UNMAP; + client->mapped_box = *box;
TRACE("Returning bo %s, flags %#x.\n", debug_const_bo_address(&client->mapped_upload.addr), diff --git a/dlls/wined3d/directx.c b/dlls/wined3d/directx.c index c265bdc8c95..f14f57fd3f4 100644 --- a/dlls/wined3d/directx.c +++ b/dlls/wined3d/directx.c @@ -2805,6 +2805,12 @@ static void adapter_no3d_flush_bo_address(struct wined3d_context *context, { }
+static bool adapter_no3d_alloc_bo(struct wined3d_device *device, struct wined3d_resource *resource, + unsigned int sub_resource_idx, struct wined3d_bo_address *addr) +{ + return false; +} + static HRESULT adapter_no3d_create_swapchain(struct wined3d_device *device, struct wined3d_swapchain_desc *desc, struct wined3d_swapchain_state_parent *state_parent, void *parent, const struct wined3d_parent_ops *parent_ops, struct wined3d_swapchain **swapchain) @@ -3075,6 +3081,7 @@ static const struct wined3d_adapter_ops wined3d_adapter_no3d_ops = .adapter_unmap_bo_address = adapter_no3d_unmap_bo_address, .adapter_copy_bo_address = adapter_no3d_copy_bo_address, .adapter_flush_bo_address = adapter_no3d_flush_bo_address, + .adapter_alloc_bo = adapter_no3d_alloc_bo, .adapter_create_swapchain = adapter_no3d_create_swapchain, .adapter_destroy_swapchain = adapter_no3d_destroy_swapchain, .adapter_create_buffer = adapter_no3d_create_buffer, diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h index 398bd73c5c0..b2a9e1d6958 100644 --- a/dlls/wined3d/wined3d_private.h +++ b/dlls/wined3d/wined3d_private.h @@ -331,6 +331,8 @@ VkPipelineStageFlags vk_pipeline_stage_mask_from_bind_flags(uint32_t bind_flags) VkShaderStageFlagBits vk_shader_stage_from_wined3d(enum wined3d_shader_type shader_type) DECLSPEC_HIDDEN; VkAccessFlags vk_access_mask_from_buffer_usage(VkBufferUsageFlags usage) DECLSPEC_HIDDEN; VkPipelineStageFlags vk_pipeline_stage_mask_from_buffer_usage(VkBufferUsageFlags usage) DECLSPEC_HIDDEN; +VkBufferUsageFlags vk_buffer_usage_from_bind_flags(uint32_t bind_flags) DECLSPEC_HIDDEN; +VkMemoryPropertyFlags vk_memory_type_from_access_flags(uint32_t access, uint32_t usage) DECLSPEC_HIDDEN;
static inline enum wined3d_cmp_func wined3d_sanitize_cmp_func(enum wined3d_cmp_func func) { @@ -1642,6 +1644,11 @@ struct wined3d_bo_vk bool host_synced; };
+static inline struct wined3d_bo_vk *wined3d_bo_vk(struct wined3d_bo *bo) +{ + return CONTAINING_RECORD(bo, struct wined3d_bo_vk, b); +} + struct wined3d_bo_slab_vk_key { VkMemoryPropertyFlags memory_type; @@ -3343,6 +3350,7 @@ bool wined3d_driver_info_init(struct wined3d_driver_info *driver_info, UINT64 vram_bytes, UINT64 sysmem_bytes) DECLSPEC_HIDDEN;
#define UPLOAD_BO_UPLOAD_ON_UNMAP 0x1 +#define UPLOAD_BO_RENAME_ON_UNMAP 0x2
struct upload_bo { @@ -3375,6 +3383,8 @@ struct wined3d_adapter_ops const struct wined3d_bo_address *dst, const struct wined3d_bo_address *src, size_t size); 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, + unsigned int sub_resource_idx, struct wined3d_bo_address *addr); HRESULT (*adapter_create_swapchain)(struct wined3d_device *device, struct wined3d_swapchain_desc *desc, struct wined3d_swapchain_state_parent *state_parent, void *parent, @@ -5022,6 +5032,7 @@ struct wined3d_buffer_ops unsigned int data_offset, unsigned int range_count, const struct wined3d_range *ranges); void (*buffer_download_ranges)(struct wined3d_buffer *buffer, struct wined3d_context *context, void *data, unsigned int data_offset, unsigned int range_count, const struct wined3d_range *ranges); + void (*buffer_set_bo)(struct wined3d_buffer *buffer, struct wined3d_context *context, struct wined3d_bo *bo); };
struct wined3d_buffer @@ -5067,6 +5078,8 @@ BOOL wined3d_buffer_load_location(struct wined3d_buffer *buffer, BYTE *wined3d_buffer_load_sysmem(struct wined3d_buffer *buffer, struct wined3d_context *context) DECLSPEC_HIDDEN; BOOL wined3d_buffer_prepare_location(struct wined3d_buffer *buffer, struct wined3d_context *context, unsigned int location) DECLSPEC_HIDDEN; +void wined3d_buffer_set_bo(struct wined3d_buffer *buffer, + struct wined3d_context *context, struct wined3d_bo *bo) DECLSPEC_HIDDEN;
HRESULT wined3d_buffer_no3d_init(struct wined3d_buffer *buffer_no3d, struct wined3d_device *device, const struct wined3d_buffer_desc *desc, const struct wined3d_sub_resource_data *data,
On Fri, 5 Nov 2021 at 04:52, Zebediah Figura zfigura@codeweavers.com wrote:
+struct wined3d_client_bo_vk_map_ctx +{
- struct wined3d_device *device;
- struct wined3d_client_bo_vk *client_bo;
+};
We don't need this anymore.
+static bool adapter_vk_alloc_bo(struct wined3d_device *device, struct wined3d_resource *resource,
unsigned int sub_resource_idx, struct wined3d_bo_address *addr)
+{
- struct wined3d_device_vk *device_vk = wined3d_device_vk(device);
- struct wined3d_context_vk *context_vk = &device_vk->context_vk;
- wined3d_not_from_cs(device->cs);
- assert(device->context_count);
- if (resource->type == WINED3D_RTYPE_BUFFER)
- {
struct wined3d_bo_vk *bo_vk;
if (!(bo_vk = heap_alloc(sizeof(*bo_vk))))
return false;
if (!(wined3d_context_vk_create_bo(context_vk, resource->size,
vk_buffer_usage_from_bind_flags(resource->bind_flags),
vk_memory_type_from_access_flags(resource->access, resource->usage), bo_vk)))
{
WARN("Failed to create Vulkan buffer.\n");
return false;
}
We leak "bo_vk" here.
if (!bo_vk->b.map_ptr)
{
WARN_(d3d_perf)("BO %p (chunk %p, slab %p) is not persistently mapped.\n",
bo_vk, bo_vk->memory ? bo_vk->memory->chunk : NULL, bo_vk->slab);
if (!wined3d_bo_vk_map(bo_vk, context_vk))
ERR("Failed to map bo.\n");
}
I suppose we could clean up and return "false" if mapping the bo fails here. On the other hand, I suppose it shouldn't fail in the first place.
+void wined3d_buffer_set_bo(struct wined3d_buffer *buffer, struct wined3d_context *context, struct wined3d_bo *bo) +{
- TRACE("buffer %p, context %p, bo %p.\n", buffer, context, bo);
- buffer->buffer_ops->buffer_set_bo(buffer, context, bo);
- buffer->buffer_object = (uintptr_t)bo;
- wined3d_buffer_validate_location(buffer, WINED3D_LOCATION_BUFFER);
- wined3d_buffer_invalidate_location(buffer, ~WINED3D_LOCATION_BUFFER);
+}
Is wined3d_buffer_set_bo() the proper place for the validate/invalidate? Arguably it would be more appropriate to do that in wined3d_cs_exec_update_sub_resource(). I suppose it mirrors wined3d_buffer_copy_bo_address().
+static void wined3d_buffer_vk_set_bo(struct wined3d_buffer *buffer,
struct wined3d_context *context, struct wined3d_bo *bo)
+{
- struct wined3d_bo_vk *prev_bo = (struct wined3d_bo_vk *)buffer->buffer_object;
- struct wined3d_context_vk *context_vk = wined3d_context_vk(context);
- struct wined3d_buffer_vk *buffer_vk = wined3d_buffer_vk(buffer);
- struct wined3d_bo_vk *bo_vk = wined3d_bo_vk(bo);
- /* We can't just copy the contents of bo_vk into buffer_vk->bo, because the
* new BO might still be in use by the client thread. We could allow both to
* be valid, although knowing when to destroy a BO then becomes tricky, and
* ensuring it's not mapped more than once also becomes tricky. */
There's probably less of a need for the comment now.
- if (prev_bo)
- {
struct wined3d_bo_user *bo_user;
LIST_FOR_EACH_ENTRY(bo_user, &prev_bo->b.users, struct wined3d_bo_user, entry)
bo_user->valid = false;
assert(list_empty(&bo_vk->b.users));
list_move_head(&bo_vk->b.users, &prev_bo->b.users);
wined3d_context_vk_destroy_bo(context_vk, prev_bo);
heap_free(prev_bo);
- }
- else
- {
list_add_head(&bo_vk->b.users, &buffer_vk->b.bo_user.entry);
- }
+}
Note that aside from the wined3d_context_vk_destroy_bo() call, this is all just generic code now.
On 11/5/21 12:39 PM, Henri Verbeet wrote:
On Fri, 5 Nov 2021 at 04:52, Zebediah Figura zfigura@codeweavers.com wrote:
+struct wined3d_client_bo_vk_map_ctx +{
- struct wined3d_device *device;
- struct wined3d_client_bo_vk *client_bo;
+};
We don't need this anymore.
+static bool adapter_vk_alloc_bo(struct wined3d_device *device, struct wined3d_resource *resource,
unsigned int sub_resource_idx, struct wined3d_bo_address *addr)
+{
- struct wined3d_device_vk *device_vk = wined3d_device_vk(device);
- struct wined3d_context_vk *context_vk = &device_vk->context_vk;
- wined3d_not_from_cs(device->cs);
- assert(device->context_count);
- if (resource->type == WINED3D_RTYPE_BUFFER)
- {
struct wined3d_bo_vk *bo_vk;
if (!(bo_vk = heap_alloc(sizeof(*bo_vk))))
return false;
if (!(wined3d_context_vk_create_bo(context_vk, resource->size,
vk_buffer_usage_from_bind_flags(resource->bind_flags),
vk_memory_type_from_access_flags(resource->access, resource->usage), bo_vk)))
{
WARN("Failed to create Vulkan buffer.\n");
return false;
}
We leak "bo_vk" here.
if (!bo_vk->b.map_ptr)
{
WARN_(d3d_perf)("BO %p (chunk %p, slab %p) is not persistently mapped.\n",
bo_vk, bo_vk->memory ? bo_vk->memory->chunk : NULL, bo_vk->slab);
if (!wined3d_bo_vk_map(bo_vk, context_vk))
ERR("Failed to map bo.\n");
}
I suppose we could clean up and return "false" if mapping the bo fails here. On the other hand, I suppose it shouldn't fail in the first place.
Cleaning up is a bit nontrivial; I'd rather leave it as is (or use an assert?)
+void wined3d_buffer_set_bo(struct wined3d_buffer *buffer, struct wined3d_context *context, struct wined3d_bo *bo) +{
- TRACE("buffer %p, context %p, bo %p.\n", buffer, context, bo);
- buffer->buffer_ops->buffer_set_bo(buffer, context, bo);
- buffer->buffer_object = (uintptr_t)bo;
- wined3d_buffer_validate_location(buffer, WINED3D_LOCATION_BUFFER);
- wined3d_buffer_invalidate_location(buffer, ~WINED3D_LOCATION_BUFFER);
+}
Is wined3d_buffer_set_bo() the proper place for the validate/invalidate? Arguably it would be more appropriate to do that in wined3d_cs_exec_update_sub_resource(). I suppose it mirrors wined3d_buffer_copy_bo_address().
It definitely seems that most validation logic is done within buffer.c, and that makes more sense to me, along the lines of letting that be a buffer-specific implementation detail. I can change it if you feel strongly otherwise, though.
+static void wined3d_buffer_vk_set_bo(struct wined3d_buffer *buffer,
struct wined3d_context *context, struct wined3d_bo *bo)
+{
- struct wined3d_bo_vk *prev_bo = (struct wined3d_bo_vk *)buffer->buffer_object;
- struct wined3d_context_vk *context_vk = wined3d_context_vk(context);
- struct wined3d_buffer_vk *buffer_vk = wined3d_buffer_vk(buffer);
- struct wined3d_bo_vk *bo_vk = wined3d_bo_vk(bo);
- /* We can't just copy the contents of bo_vk into buffer_vk->bo, because the
* new BO might still be in use by the client thread. We could allow both to
* be valid, although knowing when to destroy a BO then becomes tricky, and
* ensuring it's not mapped more than once also becomes tricky. */
There's probably less of a need for the comment now.
- if (prev_bo)
- {
struct wined3d_bo_user *bo_user;
LIST_FOR_EACH_ENTRY(bo_user, &prev_bo->b.users, struct wined3d_bo_user, entry)
bo_user->valid = false;
assert(list_empty(&bo_vk->b.users));
list_move_head(&bo_vk->b.users, &prev_bo->b.users);
wined3d_context_vk_destroy_bo(context_vk, prev_bo);
heap_free(prev_bo);
- }
- else
- {
list_add_head(&bo_vk->b.users, &buffer_vk->b.bo_user.entry);
- }
+}
Note that aside from the wined3d_context_vk_destroy_bo() call, this is all just generic code now.
Yes, which is why I wanted to turn destroy_bo() into an adapter op earlier. I guess if we had a wined3d_texture_set_bo() it would also be all generic code except for a destroy_bo() call, so maybe it does make sense to make destroy_bo() an adapter op, if not per se for unload_location() as well.
On Mon, 8 Nov 2021 at 18:01, Zebediah Figura zfigura@codeweavers.com wrote:
On 11/5/21 12:39 PM, Henri Verbeet wrote:
On Fri, 5 Nov 2021 at 04:52, Zebediah Figura zfigura@codeweavers.com wrote:
if (!bo_vk->b.map_ptr)
{
WARN_(d3d_perf)("BO %p (chunk %p, slab %p) is not persistently mapped.\n",
bo_vk, bo_vk->memory ? bo_vk->memory->chunk : NULL, bo_vk->slab);
if (!wined3d_bo_vk_map(bo_vk, context_vk))
ERR("Failed to map bo.\n");
}
I suppose we could clean up and return "false" if mapping the bo fails here. On the other hand, I suppose it shouldn't fail in the first place.
Cleaning up is a bit nontrivial; I'd rather leave it as is (or use an assert?)
The ERR is fine.
+void wined3d_buffer_set_bo(struct wined3d_buffer *buffer, struct wined3d_context *context, struct wined3d_bo *bo) +{
- TRACE("buffer %p, context %p, bo %p.\n", buffer, context, bo);
- buffer->buffer_ops->buffer_set_bo(buffer, context, bo);
- buffer->buffer_object = (uintptr_t)bo;
- wined3d_buffer_validate_location(buffer, WINED3D_LOCATION_BUFFER);
- wined3d_buffer_invalidate_location(buffer, ~WINED3D_LOCATION_BUFFER);
+}
Is wined3d_buffer_set_bo() the proper place for the validate/invalidate? Arguably it would be more appropriate to do that in wined3d_cs_exec_update_sub_resource(). I suppose it mirrors wined3d_buffer_copy_bo_address().
It definitely seems that most validation logic is done within buffer.c, and that makes more sense to me, along the lines of letting that be a buffer-specific implementation detail. I can change it if you feel strongly otherwise, though.
The issue isn't so much that it's in buffer.c; in principle it would be fine to introduce e.g. wined3d_buffer_update_sub_resource() containing the implementation of wined3d_cs_exec_update_sub_resource() for buffers. The reason that doesn't already exist is mostly just that the buffer part of wined3d_cs_exec_update_sub_resource() is fairly straightforward. The issue here is more that wined3d_buffer_set_bo() seems like something that's conceptually on a lower level than sub-resource updates, much like e.g. wined3d_resource_prepare_sysmem(), wined3d_buffer_vk_create_buffer_object(), or wined3d_buffer_gl_create_buffer_object(). I.e., it's not obvious to me that replacing a buffer's bo should modify its location flags.
- if (prev_bo)
- {
struct wined3d_bo_user *bo_user;
LIST_FOR_EACH_ENTRY(bo_user, &prev_bo->b.users, struct wined3d_bo_user, entry)
bo_user->valid = false;
assert(list_empty(&bo_vk->b.users));
list_move_head(&bo_vk->b.users, &prev_bo->b.users);
wined3d_context_vk_destroy_bo(context_vk, prev_bo);
heap_free(prev_bo);
- }
- else
- {
list_add_head(&bo_vk->b.users, &buffer_vk->b.bo_user.entry);
- }
+}
Note that aside from the wined3d_context_vk_destroy_bo() call, this is all just generic code now.
Yes, which is why I wanted to turn destroy_bo() into an adapter op earlier. I guess if we had a wined3d_texture_set_bo() it would also be all generic code except for a destroy_bo() call, so maybe it does make sense to make destroy_bo() an adapter op, if not per se for unload_location() as well.
Right, I think doing bo destruction through the adapter ops would make sense for this purpose.
On 11/8/21 1:35 PM, Henri Verbeet wrote:
+void wined3d_buffer_set_bo(struct wined3d_buffer *buffer, struct wined3d_context *context, struct wined3d_bo *bo) +{
- TRACE("buffer %p, context %p, bo %p.\n", buffer, context, bo);
- buffer->buffer_ops->buffer_set_bo(buffer, context, bo);
- buffer->buffer_object = (uintptr_t)bo;
- wined3d_buffer_validate_location(buffer, WINED3D_LOCATION_BUFFER);
- wined3d_buffer_invalidate_location(buffer, ~WINED3D_LOCATION_BUFFER);
+}
Is wined3d_buffer_set_bo() the proper place for the validate/invalidate? Arguably it would be more appropriate to do that in wined3d_cs_exec_update_sub_resource(). I suppose it mirrors wined3d_buffer_copy_bo_address().
It definitely seems that most validation logic is done within buffer.c, and that makes more sense to me, along the lines of letting that be a buffer-specific implementation detail. I can change it if you feel strongly otherwise, though.
The issue isn't so much that it's in buffer.c; in principle it would be fine to introduce e.g. wined3d_buffer_update_sub_resource() containing the implementation of wined3d_cs_exec_update_sub_resource() for buffers. The reason that doesn't already exist is mostly just that the buffer part of wined3d_cs_exec_update_sub_resource() is fairly straightforward. The issue here is more that wined3d_buffer_set_bo() seems like something that's conceptually on a lower level than sub-resource updates, much like e.g. wined3d_resource_prepare_sysmem(), wined3d_buffer_vk_create_buffer_object(), or wined3d_buffer_gl_create_buffer_object(). I.e., it's not obvious to me that replacing a buffer's bo should modify its location flags.
Okay, that makes sense to me. I'll add a wined3d_buffer_update_sub_resource() helper.