Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- dlls/wined3d/buffer.c | 56 +++++++++++++++++----------------- dlls/wined3d/wined3d_private.h | 2 -- 2 files changed, 28 insertions(+), 30 deletions(-)
diff --git a/dlls/wined3d/buffer.c b/dlls/wined3d/buffer.c index 854fa71aefe..54291f1d9dd 100644 --- a/dlls/wined3d/buffer.c +++ b/dlls/wined3d/buffer.c @@ -136,6 +136,34 @@ static void wined3d_buffer_gl_bind(struct wined3d_buffer_gl *buffer_gl, struct w wined3d_context_gl_bind_bo(context_gl, buffer_gl->bo.binding, buffer_gl->bo.id); }
+static GLenum wined3d_buffer_gl_binding_from_bind_flags(const struct wined3d_gl_info *gl_info, uint32_t bind_flags) +{ + if (!bind_flags) + return GL_PIXEL_UNPACK_BUFFER; + + if (bind_flags == WINED3D_BIND_INDEX_BUFFER) + return GL_ELEMENT_ARRAY_BUFFER; + + if (bind_flags & (WINED3D_BIND_SHADER_RESOURCE | WINED3D_BIND_UNORDERED_ACCESS) + && gl_info->supported[ARB_TEXTURE_BUFFER_OBJECT]) + return GL_TEXTURE_BUFFER; + + if (bind_flags & WINED3D_BIND_CONSTANT_BUFFER) + return GL_UNIFORM_BUFFER; + + if (bind_flags & WINED3D_BIND_STREAM_OUTPUT) + return GL_TRANSFORM_FEEDBACK_BUFFER; + + if (bind_flags & WINED3D_BIND_INDIRECT_BUFFER + && gl_info->supported[ARB_DRAW_INDIRECT]) + return GL_DRAW_INDIRECT_BUFFER; + + if (bind_flags & ~(WINED3D_BIND_VERTEX_BUFFER | WINED3D_BIND_INDEX_BUFFER)) + FIXME("Unhandled bind flags %#x.\n", bind_flags); + + return GL_ARRAY_BUFFER; +} + /* Context activation is done by the caller. */ static void wined3d_buffer_gl_destroy_buffer_object(struct wined3d_buffer_gl *buffer_gl, struct wined3d_context_gl *context_gl) @@ -1116,34 +1144,6 @@ static const struct wined3d_resource_ops buffer_resource_ops = buffer_resource_sub_resource_unmap, };
-GLenum wined3d_buffer_gl_binding_from_bind_flags(const struct wined3d_gl_info *gl_info, uint32_t bind_flags) -{ - if (!bind_flags) - return GL_PIXEL_UNPACK_BUFFER; - - if (bind_flags == WINED3D_BIND_INDEX_BUFFER) - return GL_ELEMENT_ARRAY_BUFFER; - - if (bind_flags & (WINED3D_BIND_SHADER_RESOURCE | WINED3D_BIND_UNORDERED_ACCESS) - && gl_info->supported[ARB_TEXTURE_BUFFER_OBJECT]) - return GL_TEXTURE_BUFFER; - - if (bind_flags & WINED3D_BIND_CONSTANT_BUFFER) - return GL_UNIFORM_BUFFER; - - if (bind_flags & WINED3D_BIND_STREAM_OUTPUT) - return GL_TRANSFORM_FEEDBACK_BUFFER; - - if (bind_flags & WINED3D_BIND_INDIRECT_BUFFER - && gl_info->supported[ARB_DRAW_INDIRECT]) - return GL_DRAW_INDIRECT_BUFFER; - - if (bind_flags & ~(WINED3D_BIND_VERTEX_BUFFER | WINED3D_BIND_INDEX_BUFFER)) - FIXME("Unhandled bind flags %#x.\n", bind_flags); - - return GL_ARRAY_BUFFER; -} - static HRESULT wined3d_buffer_init(struct wined3d_buffer *buffer, struct wined3d_device *device, const struct wined3d_buffer_desc *desc, const struct wined3d_sub_resource_data *data, void *parent, const struct wined3d_parent_ops *parent_ops, const struct wined3d_buffer_ops *buffer_ops) diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h index 588e39db9b2..9ece1954018 100644 --- a/dlls/wined3d/wined3d_private.h +++ b/dlls/wined3d/wined3d_private.h @@ -5055,8 +5055,6 @@ static inline const struct wined3d_buffer_gl *wined3d_buffer_gl_const(const stru return CONTAINING_RECORD(buffer, struct wined3d_buffer_gl, b); }
-GLenum wined3d_buffer_gl_binding_from_bind_flags(const struct wined3d_gl_info *gl_info, - uint32_t bind_flags) DECLSPEC_HIDDEN; HRESULT wined3d_buffer_gl_init(struct wined3d_buffer_gl *buffer_gl, struct wined3d_device *device, const struct wined3d_buffer_desc *desc, const struct wined3d_sub_resource_data *data, void *parent, const struct wined3d_parent_ops *parent_ops) DECLSPEC_HIDDEN;
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- dlls/wined3d/buffer.c | 18 +++++++++--------- dlls/wined3d/context_gl.c | 20 ++++++++++---------- dlls/wined3d/context_vk.c | 8 ++++---- dlls/wined3d/state.c | 6 +++--- dlls/wined3d/wined3d_private.h | 3 +-- 5 files changed, 27 insertions(+), 28 deletions(-)
diff --git a/dlls/wined3d/buffer.c b/dlls/wined3d/buffer.c index 54291f1d9dd..55dcd9e67e8 100644 --- a/dlls/wined3d/buffer.c +++ b/dlls/wined3d/buffer.c @@ -187,8 +187,8 @@ static void wined3d_buffer_gl_destroy_buffer_object(struct wined3d_buffer_gl *bu wined3d_context_gl_end_transform_feedback(context_gl); }
- buffer_gl->bo_user.valid = false; - list_remove(&buffer_gl->bo_user.entry); + buffer_gl->b.bo_user.valid = false; + list_remove(&buffer_gl->b.bo_user.entry); wined3d_context_gl_destroy_bo(context_gl, &buffer_gl->bo); buffer_gl->b.buffer_object = 0; } @@ -225,7 +225,7 @@ static BOOL wined3d_buffer_gl_create_buffer_object(struct wined3d_buffer_gl *buf return FALSE; }
- list_add_head(&buffer_gl->bo.b.users, &buffer_gl->bo_user.entry); + list_add_head(&buffer_gl->bo.b.users, &buffer_gl->b.bo_user.entry); buffer_gl->b.buffer_object = (uintptr_t)bo; buffer_invalidate_bo_range(&buffer_gl->b, 0, 0);
@@ -1439,8 +1439,8 @@ static BOOL wined3d_buffer_vk_create_buffer_object(struct wined3d_buffer_vk *buf return FALSE; }
- list_init(&buffer_vk->bo_user.entry); - list_add_head(&buffer_vk->bo.b.users, &buffer_vk->bo_user.entry); + 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; buffer_invalidate_bo_range(&buffer_vk->b, 0, 0);
@@ -1449,13 +1449,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) { - if (buffer_vk->bo_user.valid) + 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.range = buffer_vk->b.resource.size; - buffer_vk->bo_user.valid = true; + buffer_vk->b.bo_user.valid = true;
return &buffer_vk->buffer_info; } @@ -1491,8 +1491,8 @@ static void wined3d_buffer_vk_unload_location(struct wined3d_buffer *buffer, switch (location) { case WINED3D_LOCATION_BUFFER: - buffer_vk->bo_user.valid = false; - list_remove(&buffer_vk->bo_user.entry); + 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; diff --git a/dlls/wined3d/context_gl.c b/dlls/wined3d/context_gl.c index 83cf87f8404..d2dd9e0bd09 100644 --- a/dlls/wined3d/context_gl.c +++ b/dlls/wined3d/context_gl.c @@ -3816,7 +3816,7 @@ static void context_gl_load_shader_resources(struct wined3d_context_gl *context_ buffer_gl = wined3d_buffer_gl(state->cb[i][j].buffer); wined3d_buffer_load(&buffer_gl->b, &context_gl->c, state); wined3d_context_gl_reference_bo(context_gl, &buffer_gl->bo); - if (!buffer_gl->bo_user.valid) + if (!buffer_gl->b.bo_user.valid) device_invalidate_state(context_gl->c.device, STATE_CONSTANT_BUFFER(i)); }
@@ -3902,7 +3902,7 @@ static void context_gl_load_stream_output_buffers(struct wined3d_context_gl *con wined3d_buffer_load(&buffer_gl->b, &context_gl->c, state); wined3d_buffer_invalidate_location(&buffer_gl->b, ~WINED3D_LOCATION_BUFFER); wined3d_context_gl_reference_bo(context_gl, &buffer_gl->bo); - if (!buffer_gl->bo_user.valid) + if (!buffer_gl->b.bo_user.valid) device_invalidate_state(context_gl->c.device, STATE_STREAM_OUTPUT); } } @@ -3959,7 +3959,7 @@ static BOOL context_apply_draw_state(struct wined3d_context *context, e = &context->stream_info.elements[wined3d_bit_scan(&map)]; buffer_gl = wined3d_buffer_gl(state->streams[e->stream_idx].buffer);
- if (!buffer_gl->bo_user.valid) + if (!buffer_gl->b.bo_user.valid) device_invalidate_state(device, STATE_STREAMSRC); else wined3d_buffer_load(&buffer_gl->b, context, state); @@ -3976,7 +3976,7 @@ static BOOL context_apply_draw_state(struct wined3d_context *context, if (context->stream_info.all_vbo) { wined3d_buffer_load(&buffer_gl->b, context, state); - if (!buffer_gl->bo_user.valid) + if (!buffer_gl->b.bo_user.valid) device_invalidate_state(device, STATE_INDEXBUFFER); wined3d_context_gl_reference_bo(context_gl, &buffer_gl->bo); } @@ -5101,7 +5101,7 @@ void wined3d_context_gl_load_tex_coords(const struct wined3d_context_gl *context gl_info->gl_ops.gl.p_glTexCoordPointer(format_gl->vtx_format, format_gl->vtx_type, e->stride, e->data.addr + state->load_base_vertex_index * e->stride); gl_info->gl_ops.gl.p_glEnableClientState(GL_TEXTURE_COORD_ARRAY); - wined3d_buffer_gl(state->streams[e->stream_idx].buffer)->bo_user.valid = true; + state->streams[e->stream_idx].buffer->bo_user.valid = true; } else { @@ -5190,7 +5190,7 @@ static void wined3d_context_gl_load_vertex_data(struct wined3d_context_gl *conte checkGLcall("glVertexPointer(...)"); gl_info->gl_ops.gl.p_glEnableClientState(GL_VERTEX_ARRAY); checkGLcall("glEnableClientState(GL_VERTEX_ARRAY)"); - wined3d_buffer_gl(state->streams[e->stream_idx].buffer)->bo_user.valid = true; + state->streams[e->stream_idx].buffer->bo_user.valid = true; }
/* Normals */ @@ -5214,7 +5214,7 @@ static void wined3d_context_gl_load_vertex_data(struct wined3d_context_gl *conte checkGLcall("glNormalPointer(...)"); gl_info->gl_ops.gl.p_glEnableClientState(GL_NORMAL_ARRAY); checkGLcall("glEnableClientState(GL_NORMAL_ARRAY)"); - wined3d_buffer_gl(state->streams[e->stream_idx].buffer)->bo_user.valid = true; + state->streams[e->stream_idx].buffer->bo_user.valid = true; } else { @@ -5244,7 +5244,7 @@ static void wined3d_context_gl_load_vertex_data(struct wined3d_context_gl *conte checkGLcall("glColorPointer(4, GL_UNSIGNED_BYTE, ...)"); gl_info->gl_ops.gl.p_glEnableClientState(GL_COLOR_ARRAY); checkGLcall("glEnableClientState(GL_COLOR_ARRAY)"); - wined3d_buffer_gl(state->streams[e->stream_idx].buffer)->bo_user.valid = true; + state->streams[e->stream_idx].buffer->bo_user.valid = true; } else { @@ -5313,7 +5313,7 @@ static void wined3d_context_gl_load_vertex_data(struct wined3d_context_gl *conte } gl_info->gl_ops.gl.p_glEnableClientState(GL_SECONDARY_COLOR_ARRAY_EXT); checkGLcall("glEnableClientState(GL_SECONDARY_COLOR_ARRAY_EXT)"); - wined3d_buffer_gl(state->streams[e->stream_idx].buffer)->bo_user.valid = true; + state->streams[e->stream_idx].buffer->bo_user.valid = true; } else { @@ -5407,7 +5407,7 @@ static void wined3d_context_gl_load_numbered_arrays(struct wined3d_context_gl *c
format_gl = wined3d_format_gl(element->format); stream = &state->streams[element->stream_idx]; - wined3d_buffer_gl(stream->buffer)->bo_user.valid = true; + stream->buffer->bo_user.valid = true;
if ((stream->flags & WINED3DSTREAMSOURCE_INSTANCEDATA) && !context->instance_count) context->instance_count = state->streams[0].frequency; diff --git a/dlls/wined3d/context_vk.c b/dlls/wined3d/context_vk.c index 8bcd6d61eb3..ad7b0a8ba86 100644 --- a/dlls/wined3d/context_vk.c +++ b/dlls/wined3d/context_vk.c @@ -3091,7 +3091,7 @@ static void wined3d_context_vk_load_shader_resources(struct wined3d_context_vk *
buffer_vk = wined3d_buffer_vk(buffer); wined3d_buffer_load(buffer, &context_vk->c, state); - if (!buffer_vk->bo_user.valid) + if (!buffer_vk->b.bo_user.valid) { if (pipeline == WINED3D_PIPELINE_GRAPHICS) context_invalidate_state(&context_vk->c, STATE_GRAPHICS_CONSTANT_BUFFER(binding->shader_type)); @@ -3257,7 +3257,7 @@ VkCommandBuffer wined3d_context_vk_apply_draw_state(struct wined3d_context_vk *c buffer_vk = wined3d_buffer_vk(buffer); wined3d_buffer_load(&buffer_vk->b, &context_vk->c, state); wined3d_buffer_vk_barrier(buffer_vk, context_vk, WINED3D_BIND_VERTEX_BUFFER); - if (!buffer_vk->bo_user.valid) + if (!buffer_vk->b.bo_user.valid) context_invalidate_state(&context_vk->c, STATE_STREAMSRC); }
@@ -3272,7 +3272,7 @@ VkCommandBuffer wined3d_context_vk_apply_draw_state(struct wined3d_context_vk *c wined3d_buffer_load(&buffer_vk->b, &context_vk->c, state); wined3d_buffer_vk_barrier(buffer_vk, context_vk, WINED3D_BIND_STREAM_OUTPUT); wined3d_buffer_invalidate_location(&buffer_vk->b, ~WINED3D_LOCATION_BUFFER); - if (!buffer_vk->bo_user.valid) + if (!buffer_vk->b.bo_user.valid) context_vk->update_stream_output = 1; } context_vk->c.transform_feedback_active = 1; @@ -3283,7 +3283,7 @@ VkCommandBuffer wined3d_context_vk_apply_draw_state(struct wined3d_context_vk *c buffer_vk = wined3d_buffer_vk(state->index_buffer); wined3d_buffer_load(&buffer_vk->b, &context_vk->c, state); wined3d_buffer_vk_barrier(buffer_vk, context_vk, WINED3D_BIND_INDEX_BUFFER); - if (!buffer_vk->bo_user.valid) + if (!buffer_vk->b.bo_user.valid) context_invalidate_state(&context_vk->c, STATE_INDEXBUFFER); }
diff --git a/dlls/wined3d/state.c b/dlls/wined3d/state.c index c7f041066d1..fd2ade572c8 100644 --- a/dlls/wined3d/state.c +++ b/dlls/wined3d/state.c @@ -4458,7 +4458,7 @@ static void indexbuffer(struct wined3d_context *context, const struct wined3d_st
buffer_gl = wined3d_buffer_gl(state->index_buffer); GL_EXTCALL(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffer_gl->bo.id)); - buffer_gl->bo_user.valid = true; + buffer_gl->b.bo_user.valid = true; }
static void depth_clip(const struct wined3d_rasterizer_state *r, const struct wined3d_gl_info *gl_info) @@ -4575,7 +4575,7 @@ static void state_cb(struct wined3d_context *context, const struct wined3d_state buffer_gl = wined3d_buffer_gl(buffer_state->buffer); GL_EXTCALL(glBindBufferRange(GL_UNIFORM_BUFFER, base + i, buffer_gl->bo.id, buffer_state->offset, buffer_state->size)); - buffer_gl->bo_user.valid = true; + buffer_gl->b.bo_user.valid = true; } checkGLcall("bind constant buffers"); } @@ -4649,7 +4649,7 @@ static void state_so(struct wined3d_context *context, const struct wined3d_state } size = buffer_gl->b.resource.size - offset; GL_EXTCALL(glBindBufferRange(GL_TRANSFORM_FEEDBACK_BUFFER, i, buffer_gl->bo.id, offset, size)); - buffer_gl->bo_user.valid = true; + buffer_gl->b.bo_user.valid = true; } checkGLcall("bind transform feedback buffers"); } diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h index 9ece1954018..8666d9699c9 100644 --- a/dlls/wined3d/wined3d_private.h +++ b/dlls/wined3d/wined3d_private.h @@ -5000,6 +5000,7 @@ struct wined3d_buffer DWORD locations; void *map_ptr; uintptr_t buffer_object; + struct wined3d_bo_user bo_user;
struct wined3d_range *maps; SIZE_T maps_size, modified_areas; @@ -5042,7 +5043,6 @@ struct wined3d_buffer_gl struct wined3d_buffer b;
struct wined3d_bo_gl bo; - struct wined3d_bo_user bo_user; };
static inline struct wined3d_buffer_gl *wined3d_buffer_gl(struct wined3d_buffer *buffer) @@ -5064,7 +5064,6 @@ struct wined3d_buffer_vk struct wined3d_buffer b;
struct wined3d_bo_vk bo; - struct wined3d_bo_user bo_user; 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 | 23 ++++++++ dlls/wined3d/adapter_vk.c | 10 ++++ dlls/wined3d/buffer.c | 98 ++++------------------------------ dlls/wined3d/directx.c | 5 ++ dlls/wined3d/wined3d_private.h | 13 ++++- 5 files changed, 59 insertions(+), 90 deletions(-)
diff --git a/dlls/wined3d/adapter_gl.c b/dlls/wined3d/adapter_gl.c index f1cdbffe718..86fe40aa73f 100644 --- a/dlls/wined3d/adapter_gl.c +++ b/dlls/wined3d/adapter_gl.c @@ -4604,6 +4604,28 @@ static void adapter_gl_flush_bo_address(struct wined3d_context *context, wined3d_context_gl_flush_bo_address(wined3d_context_gl(context), data, size); }
+static void adapter_gl_destroy_bo(struct wined3d_context *context, struct wined3d_bo *bo) +{ + struct wined3d_context_gl *context_gl = wined3d_context_gl(context); + struct wined3d_bo_gl *bo_gl = wined3d_bo_gl(bo); + + if (context_gl->c.transform_feedback_active && bo_gl->binding == GL_TRANSFORM_FEEDBACK_BUFFER + && wined3d_context_is_graphics_state_dirty(&context_gl->c, STATE_STREAM_OUTPUT)) + { + /* It's illegal to (un)bind GL_TRANSFORM_FEEDBACK_BUFFER while transform + * feedback is active. Deleting a buffer implicitly unbinds it, so we + * need to end transform feedback here if this buffer was bound. + * + * This should only be possible if STATE_STREAM_OUTPUT is dirty; if we + * do a draw call before destroying this buffer then the draw call will + * already rebind the GL target. */ + WARN("Deleting buffer object %p, disabling transform feedback.\n", bo_gl); + wined3d_context_gl_end_transform_feedback(context_gl); + } + + wined3d_context_gl_destroy_bo(context_gl, bo_gl); +} + 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) @@ -5057,6 +5079,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_destroy_bo = adapter_gl_destroy_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 02a359c4f07..9251f790064 100644 --- a/dlls/wined3d/adapter_vk.c +++ b/dlls/wined3d/adapter_vk.c @@ -1182,6 +1182,15 @@ static void adapter_vk_flush_bo_address(struct wined3d_context *context, flush_bo_range(context_vk, bo, (uintptr_t)data->addr, size); }
+static void adapter_vk_destroy_bo(struct wined3d_context *context, struct wined3d_bo *bo) +{ + struct wined3d_bo_vk *bo_vk = wined3d_bo_vk(bo); + + wined3d_context_vk_destroy_bo(wined3d_context_vk(context), bo_vk); + bo_vk->vk_buffer = VK_NULL_HANDLE; + bo_vk->memory = NULL; +} + 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) @@ -1834,6 +1843,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_destroy_bo = adapter_vk_destroy_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 55dcd9e67e8..4aa450bcc28 100644 --- a/dlls/wined3d/buffer.c +++ b/dlls/wined3d/buffer.c @@ -164,35 +164,6 @@ static GLenum wined3d_buffer_gl_binding_from_bind_flags(const struct wined3d_gl_ return GL_ARRAY_BUFFER; }
-/* Context activation is done by the caller. */ -static void wined3d_buffer_gl_destroy_buffer_object(struct wined3d_buffer_gl *buffer_gl, - struct wined3d_context_gl *context_gl) -{ - struct wined3d_resource *resource = &buffer_gl->b.resource; - - if (!buffer_gl->b.buffer_object) - return; - - if (context_gl->c.transform_feedback_active && (resource->bind_flags & WINED3D_BIND_STREAM_OUTPUT) - && wined3d_context_is_graphics_state_dirty(&context_gl->c, STATE_STREAM_OUTPUT)) - { - /* It's illegal to (un)bind GL_TRANSFORM_FEEDBACK_BUFFER while transform - * feedback is active. Deleting a buffer implicitly unbinds it, so we - * need to end transform feedback here if this buffer was bound. - * - * This should only be possible if STATE_STREAM_OUTPUT is dirty; if we - * do a draw call before destroying this buffer then the draw call will - * already rebind the GL target. */ - WARN("Deleting buffer object for buffer %p, disabling transform feedback.\n", buffer_gl); - wined3d_context_gl_end_transform_feedback(context_gl); - } - - buffer_gl->b.bo_user.valid = false; - list_remove(&buffer_gl->b.bo_user.entry); - wined3d_context_gl_destroy_bo(context_gl, &buffer_gl->bo); - buffer_gl->b.buffer_object = 0; -} - /* Context activation is done by the caller. */ static BOOL wined3d_buffer_gl_create_buffer_object(struct wined3d_buffer_gl *buffer_gl, struct wined3d_context_gl *context_gl) @@ -557,12 +528,6 @@ BOOL wined3d_buffer_prepare_location(struct wined3d_buffer *buffer, return buffer->buffer_ops->buffer_prepare_location(buffer, context, location); }
-static void wined3d_buffer_unload_location(struct wined3d_buffer *buffer, - struct wined3d_context *context, unsigned int location) -{ - buffer->buffer_ops->buffer_unload_location(buffer, context, location); -} - BOOL wined3d_buffer_load_location(struct wined3d_buffer *buffer, struct wined3d_context *context, DWORD location) { @@ -674,6 +639,14 @@ DWORD wined3d_buffer_get_memory(struct wined3d_buffer *buffer, struct wined3d_co return 0; }
+static void wined3d_buffer_unload_bo(struct wined3d_buffer *buffer, struct wined3d_context *context) +{ + buffer->bo_user.valid = false; + list_remove(&buffer->bo_user.entry); + context->device->adapter->adapter_ops->adapter_destroy_bo(context, (struct wined3d_bo *)buffer->buffer_object); + buffer->buffer_object = 0u; +} + static void buffer_resource_unload(struct wined3d_resource *resource) { struct wined3d_buffer *buffer = buffer_from_resource(resource); @@ -688,7 +661,7 @@ static void buffer_resource_unload(struct wined3d_resource *resource)
wined3d_buffer_load_location(buffer, context, WINED3D_LOCATION_SYSMEM); wined3d_buffer_invalidate_location(buffer, WINED3D_LOCATION_BUFFER); - wined3d_buffer_unload_location(buffer, context, WINED3D_LOCATION_BUFFER); + wined3d_buffer_unload_bo(buffer, context); buffer_clear_dirty_areas(buffer);
context_release(context); @@ -719,7 +692,7 @@ static void wined3d_buffer_destroy_object(void *object) if (buffer->buffer_object) { context = context_acquire(buffer->resource.device, NULL, 0); - wined3d_buffer_unload_location(buffer, context, WINED3D_LOCATION_BUFFER); + wined3d_buffer_unload_bo(buffer, context); context_release(context); } heap_free(buffer->conversion_map); @@ -1238,12 +1211,6 @@ static BOOL wined3d_buffer_no3d_prepare_location(struct wined3d_buffer *buffer, return FALSE; }
-static void wined3d_buffer_no3d_unload_location(struct wined3d_buffer *buffer, - struct wined3d_context *context, unsigned int location) -{ - TRACE("buffer %p, context %p, location %s.\n", buffer, context, wined3d_debug_location(location)); -} - static void wined3d_buffer_no3d_upload_ranges(struct wined3d_buffer *buffer, struct wined3d_context *context, const void *data, unsigned int data_offset, unsigned int range_count, const struct wined3d_range *ranges) { @@ -1259,7 +1226,6 @@ static void wined3d_buffer_no3d_download_ranges(struct wined3d_buffer *buffer, s 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, }; @@ -1302,23 +1268,6 @@ static BOOL wined3d_buffer_gl_prepare_location(struct wined3d_buffer *buffer, } }
-static void wined3d_buffer_gl_unload_location(struct wined3d_buffer *buffer, - struct wined3d_context *context, unsigned int location) -{ - TRACE("buffer %p, context %p, location %s.\n", buffer, context, wined3d_debug_location(location)); - - switch (location) - { - case WINED3D_LOCATION_BUFFER: - wined3d_buffer_gl_destroy_buffer_object(wined3d_buffer_gl(buffer), wined3d_context_gl(context)); - break; - - default: - ERR("Unhandled location %s.\n", wined3d_debug_location(location)); - break; - } -} - /* Context activation is done by the caller. */ static void wined3d_buffer_gl_upload_ranges(struct wined3d_buffer *buffer, struct wined3d_context *context, const void *data, unsigned int data_offset, unsigned int range_count, const struct wined3d_range *ranges) @@ -1369,7 +1318,6 @@ static void wined3d_buffer_gl_download_ranges(struct wined3d_buffer *buffer, str 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, }; @@ -1480,31 +1428,6 @@ 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_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; - break; - - default: - ERR("Unhandled location %s.\n", wined3d_debug_location(location)); - break; - } -} - static void wined3d_buffer_vk_upload_ranges(struct wined3d_buffer *buffer, struct wined3d_context *context, const void *data, unsigned int data_offset, unsigned int range_count, const struct wined3d_range *ranges) { @@ -1568,7 +1491,6 @@ static void wined3d_buffer_vk_download_ranges(struct wined3d_buffer *buffer, str 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, }; diff --git a/dlls/wined3d/directx.c b/dlls/wined3d/directx.c index c265bdc8c95..8a5b61dcd68 100644 --- a/dlls/wined3d/directx.c +++ b/dlls/wined3d/directx.c @@ -2805,6 +2805,10 @@ static void adapter_no3d_flush_bo_address(struct wined3d_context *context, { }
+static void adapter_no3d_destroy_bo(struct wined3d_context *context, struct wined3d_bo *bo) +{ +} + 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 +3079,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_destroy_bo = adapter_no3d_destroy_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 8666d9699c9..246fd1d60ea 100644 --- a/dlls/wined3d/wined3d_private.h +++ b/dlls/wined3d/wined3d_private.h @@ -1609,6 +1609,11 @@ struct wined3d_bo_gl uint64_t command_fence_id; };
+static inline struct wined3d_bo_gl *wined3d_bo_gl(struct wined3d_bo *bo) +{ + return CONTAINING_RECORD(bo, struct wined3d_bo_gl, b); +} + static inline GLuint wined3d_bo_gl_id(uintptr_t bo) { return bo ? ((struct wined3d_bo_gl *)bo)->id : 0; @@ -1639,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; @@ -3370,6 +3380,7 @@ 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); + void (*adapter_destroy_bo)(struct wined3d_context *context, struct wined3d_bo *bo); HRESULT (*adapter_create_swapchain)(struct wined3d_device *device, struct wined3d_swapchain_desc *desc, struct wined3d_swapchain_state_parent *state_parent, void *parent, @@ -4982,8 +4993,6 @@ struct wined3d_buffer_ops { BOOL (*buffer_prepare_location)(struct wined3d_buffer *buffer, struct wined3d_context *context, unsigned int location); - void (*buffer_unload_location)(struct wined3d_buffer *buffer, - struct wined3d_context *context, unsigned int location); void (*buffer_upload_ranges)(struct wined3d_buffer *buffer, struct wined3d_context *context, const void *data, 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,
On Wed, 20 Oct 2021 at 07:28, Zebediah Figura zfigura@codeweavers.com wrote:
+static void adapter_gl_destroy_bo(struct wined3d_context *context, struct wined3d_bo *bo) +{
- struct wined3d_context_gl *context_gl = wined3d_context_gl(context);
- struct wined3d_bo_gl *bo_gl = wined3d_bo_gl(bo);
- if (context_gl->c.transform_feedback_active && bo_gl->binding == GL_TRANSFORM_FEEDBACK_BUFFER
&& wined3d_context_is_graphics_state_dirty(&context_gl->c, STATE_STREAM_OUTPUT))
- {
/* It's illegal to (un)bind GL_TRANSFORM_FEEDBACK_BUFFER while transform
* feedback is active. Deleting a buffer implicitly unbinds it, so we
* need to end transform feedback here if this buffer was bound.
*
* This should only be possible if STATE_STREAM_OUTPUT is dirty; if we
* do a draw call before destroying this buffer then the draw call will
* already rebind the GL target. */
WARN("Deleting buffer object %p, disabling transform feedback.\n", bo_gl);
wined3d_context_gl_end_transform_feedback(context_gl);
- }
Is there any particular reason this belongs in adapter_gl_destroy_bo() instead of wined3d_context_gl_destroy_bo()?
+static void adapter_vk_destroy_bo(struct wined3d_context *context, struct wined3d_bo *bo) +{
- struct wined3d_bo_vk *bo_vk = wined3d_bo_vk(bo);
- wined3d_context_vk_destroy_bo(wined3d_context_vk(context), bo_vk);
- bo_vk->vk_buffer = VK_NULL_HANDLE;
- bo_vk->memory = NULL;
+}
Similarly, it seems somewhat arbitrary to clear the "vk_buffer" and "memory" fields in adapter_vk_destroy_bo() instead of wined3d_context_vk_destroy_bo().
@@ -3370,6 +3380,7 @@ 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);
- void (*adapter_destroy_bo)(struct wined3d_context *context, struct wined3d_bo *bo); HRESULT (*adapter_create_swapchain)(struct wined3d_device *device, struct wined3d_swapchain_desc *desc, struct wined3d_swapchain_state_parent *state_parent, void *parent,
@@ -4982,8 +4993,6 @@ struct wined3d_buffer_ops { BOOL (*buffer_prepare_location)(struct wined3d_buffer *buffer, struct wined3d_context *context, unsigned int location);
- void (*buffer_unload_location)(struct wined3d_buffer *buffer,
void (*buffer_upload_ranges)(struct wined3d_buffer *buffer, struct wined3d_context *context, const void *data, 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,struct wined3d_context *context, unsigned int location);
Is that the direction we want to go in? The original idea was to unify wined3d_buffer_ops and wined3d_texture_ops, and then merge them into wined3d_resource_ops. If there are additional reasons to introduce adapter_destroy_bo(), perhaps that's fine though.
On 11/1/21 09:20, Henri Verbeet wrote:
On Wed, 20 Oct 2021 at 07:28, Zebediah Figura zfigura@codeweavers.com wrote:
+static void adapter_gl_destroy_bo(struct wined3d_context *context, struct wined3d_bo *bo) +{
- struct wined3d_context_gl *context_gl = wined3d_context_gl(context);
- struct wined3d_bo_gl *bo_gl = wined3d_bo_gl(bo);
- if (context_gl->c.transform_feedback_active && bo_gl->binding == GL_TRANSFORM_FEEDBACK_BUFFER
&& wined3d_context_is_graphics_state_dirty(&context_gl->c, STATE_STREAM_OUTPUT))
- {
/* It's illegal to (un)bind GL_TRANSFORM_FEEDBACK_BUFFER while transform
* feedback is active. Deleting a buffer implicitly unbinds it, so we
* need to end transform feedback here if this buffer was bound.
*
* This should only be possible if STATE_STREAM_OUTPUT is dirty; if we
* do a draw call before destroying this buffer then the draw call will
* already rebind the GL target. */
WARN("Deleting buffer object %p, disabling transform feedback.\n", bo_gl);
wined3d_context_gl_end_transform_feedback(context_gl);
- }
Is there any particular reason this belongs in adapter_gl_destroy_bo() instead of wined3d_context_gl_destroy_bo()?
+static void adapter_vk_destroy_bo(struct wined3d_context *context, struct wined3d_bo *bo) +{
- struct wined3d_bo_vk *bo_vk = wined3d_bo_vk(bo);
- wined3d_context_vk_destroy_bo(wined3d_context_vk(context), bo_vk);
- bo_vk->vk_buffer = VK_NULL_HANDLE;
- bo_vk->memory = NULL;
+}
Similarly, it seems somewhat arbitrary to clear the "vk_buffer" and "memory" fields in adapter_vk_destroy_bo() instead of wined3d_context_vk_destroy_bo().
The answer to both of these is "well, wined3d_context_*_destroy_bo() didn't already do those things". That could be changed, though.
@@ -3370,6 +3380,7 @@ 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);
- void (*adapter_destroy_bo)(struct wined3d_context *context, struct wined3d_bo *bo); HRESULT (*adapter_create_swapchain)(struct wined3d_device *device, struct wined3d_swapchain_desc *desc, struct wined3d_swapchain_state_parent *state_parent, void *parent,
@@ -4982,8 +4993,6 @@ struct wined3d_buffer_ops { BOOL (*buffer_prepare_location)(struct wined3d_buffer *buffer, struct wined3d_context *context, unsigned int location);
- void (*buffer_unload_location)(struct wined3d_buffer *buffer,
struct wined3d_context *context, unsigned int location); void (*buffer_upload_ranges)(struct wined3d_buffer *buffer, struct wined3d_context *context, const void *data, 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,
Is that the direction we want to go in? The original idea was to unify wined3d_buffer_ops and wined3d_texture_ops, and then merge them into wined3d_resource_ops. If there are additional reasons to introduce adapter_destroy_bo(), perhaps that's fine though.
I guess not really. I don't think I had a particular reason for this commit except to effect some deduplication.
Of course we could do a similar thing with textures, but there are quite a few more locations to deal with...
I'll just drop the patch.