From: Zebediah Figura Subject: [PATCH 3/6] wined3d: Handle WINED3D_LOCATION_DISCARDED in wined3d_buffer_get_memory(). Message-Id: <20210618041939.228411-3-z.figura12@gmail.com> Date: Thu, 17 Jun 2021 23:19:36 -0500 In-Reply-To: <20210618041939.228411-1-z.figura12@gmail.com> References: <20210618041939.228411-1-z.figura12@gmail.com> This can't currently happen. However, we'd like to use wined3d_buffer_get_memory() in wined3d_cs_exec_update_sub_resource(). This would probably also help in implementing ID3D11DeviceContext1::DiscardResource(). Signed-off-by: Zebediah Figura --- dlls/wined3d/buffer.c | 26 ++++++++++++++++++++------ dlls/wined3d/context.c | 2 +- dlls/wined3d/view.c | 2 +- dlls/wined3d/wined3d_private.h | 3 ++- 4 files changed, 24 insertions(+), 9 deletions(-) diff --git a/dlls/wined3d/buffer.c b/dlls/wined3d/buffer.c index 267a8a0bd9c..cbf33df5539 100644 --- a/dlls/wined3d/buffer.c +++ b/dlls/wined3d/buffer.c @@ -603,13 +603,26 @@ BYTE *wined3d_buffer_load_sysmem(struct wined3d_buffer *buffer, struct wined3d_c return buffer->resource.heap_memory; } -DWORD wined3d_buffer_get_memory(struct wined3d_buffer *buffer, struct wined3d_bo_address *data) +DWORD wined3d_buffer_get_memory(struct wined3d_buffer *buffer, struct wined3d_context *context, + struct wined3d_bo_address *data) { unsigned int locations = buffer->locations; - TRACE("buffer %p, data %p, locations %s.\n", - buffer, data, wined3d_debug_location(locations)); + TRACE("buffer %p, context %p, data %p, locations %s.\n", + buffer, context, data, wined3d_debug_location(locations)); + if (locations & WINED3D_LOCATION_DISCARDED) + { + locations = ((buffer->flags & WINED3D_BUFFER_USE_BO) ? WINED3D_LOCATION_BUFFER : WINED3D_LOCATION_SYSMEM); + if (!wined3d_buffer_prepare_location(buffer, context, locations)) + { + data->buffer_object = 0; + data->addr = NULL; + return 0; + } + wined3d_buffer_validate_location(buffer, locations); + wined3d_buffer_invalidate_location(buffer, WINED3D_LOCATION_DISCARDED); + } if (locations & WINED3D_LOCATION_BUFFER) { data->buffer_object = buffer->buffer_object; @@ -1006,13 +1019,14 @@ void wined3d_buffer_copy(struct wined3d_buffer *dst_buffer, unsigned int dst_off TRACE("dst_buffer %p, dst_offset %u, src_buffer %p, src_offset %u, size %u.\n", dst_buffer, dst_offset, src_buffer, src_offset, size); - dst_location = wined3d_buffer_get_memory(dst_buffer, &dst); + context = context_acquire(dst_buffer->resource.device, NULL, 0); + + dst_location = wined3d_buffer_get_memory(dst_buffer, context, &dst); dst.addr += dst_offset; - wined3d_buffer_get_memory(src_buffer, &src); + wined3d_buffer_get_memory(src_buffer, context, &src); src.addr += src_offset; - context = context_acquire(dst_buffer->resource.device, NULL, 0); wined3d_context_copy_bo_address(context, &dst, &src, size); context_release(context); diff --git a/dlls/wined3d/context.c b/dlls/wined3d/context.c index 8b35b9da17f..a44e979d32c 100644 --- a/dlls/wined3d/context.c +++ b/dlls/wined3d/context.c @@ -304,7 +304,7 @@ void context_update_stream_info(struct wined3d_context *context, const struct wi else { wined3d_buffer_load(buffer, context, state); - wined3d_buffer_get_memory(buffer, &data); + wined3d_buffer_get_memory(buffer, context, &data); element->data.buffer_object = data.buffer_object; element->data.addr += (ULONG_PTR)data.addr; } diff --git a/dlls/wined3d/view.c b/dlls/wined3d/view.c index 9baa0ae0cd3..67f4b03e9d3 100644 --- a/dlls/wined3d/view.c +++ b/dlls/wined3d/view.c @@ -1611,7 +1611,7 @@ void wined3d_unordered_access_view_copy_counter(struct wined3d_unordered_access_ if (!view->counter_bo) return; - dst_location = wined3d_buffer_get_memory(buffer, &dst); + dst_location = wined3d_buffer_get_memory(buffer, context, &dst); dst.addr += offset; src.buffer_object = view->counter_bo; diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h index 6ada1fa3642..400d20b94b4 100644 --- a/dlls/wined3d/wined3d_private.h +++ b/dlls/wined3d/wined3d_private.h @@ -4899,7 +4899,8 @@ static inline struct wined3d_buffer *buffer_from_resource(struct wined3d_resourc void wined3d_buffer_cleanup(struct wined3d_buffer *buffer) DECLSPEC_HIDDEN; void 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; -DWORD wined3d_buffer_get_memory(struct wined3d_buffer *buffer, struct wined3d_bo_address *data) DECLSPEC_HIDDEN; +DWORD wined3d_buffer_get_memory(struct wined3d_buffer *buffer, struct wined3d_context *context, + struct wined3d_bo_address *data) 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; -- 2.30.2