Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- dlls/wined3d/buffer.c | 14 +++++++++----- dlls/wined3d/context_gl.c | 22 ++++++++++++---------- dlls/wined3d/state.c | 20 ++++++++++++++++---- dlls/wined3d/view.c | 22 +++++++++++++++------- dlls/wined3d/wined3d_private.h | 11 +++++++++++ 5 files changed, 63 insertions(+), 26 deletions(-)
diff --git a/dlls/wined3d/buffer.c b/dlls/wined3d/buffer.c index be4d095eba0..a3004fcecff 100644 --- a/dlls/wined3d/buffer.c +++ b/dlls/wined3d/buffer.c @@ -133,7 +133,9 @@ void wined3d_buffer_invalidate_location(struct wined3d_buffer *buffer, DWORD loc /* Context activation is done by the caller. */ static void wined3d_buffer_gl_bind(struct wined3d_buffer_gl *buffer_gl, struct wined3d_context_gl *context_gl) { - wined3d_context_gl_bind_bo(context_gl, buffer_gl->bo.binding, buffer_gl->bo.id); + const struct wined3d_bo_gl *bo_gl = wined3d_bo_gl(buffer_gl->b.buffer_object); + + wined3d_context_gl_bind_bo(context_gl, bo_gl->binding, bo_gl->id); }
static GLenum wined3d_buffer_gl_binding_from_bind_flags(const struct wined3d_gl_info *gl_info, uint32_t bind_flags) @@ -225,7 +227,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->b.bo_user.entry); + list_add_head(&bo->b.users, &buffer_gl->b.bo_user.entry); buffer_gl->b.buffer_object = &bo->b; buffer_invalidate_bo_range(&buffer_gl->b, 0, 0);
@@ -1324,6 +1326,7 @@ static void wined3d_buffer_gl_upload_ranges(struct wined3d_buffer *buffer, struc const void *data, unsigned int data_offset, unsigned int range_count, const struct wined3d_range *ranges) { struct wined3d_context_gl *context_gl = wined3d_context_gl(context); + struct wined3d_bo_gl *bo_gl = wined3d_bo_gl(buffer->buffer_object); struct wined3d_buffer_gl *buffer_gl = wined3d_buffer_gl(buffer); const struct wined3d_gl_info *gl_info = context_gl->gl_info; const struct wined3d_range *range; @@ -1336,10 +1339,10 @@ static void wined3d_buffer_gl_upload_ranges(struct wined3d_buffer *buffer, struc while (range_count--) { range = &ranges[range_count]; - GL_EXTCALL(glBufferSubData(buffer_gl->bo.binding, + GL_EXTCALL(glBufferSubData(bo_gl->binding, range->offset, range->size, (BYTE *)data + range->offset - data_offset)); } - wined3d_context_gl_reference_bo(context_gl, &buffer_gl->bo); + wined3d_context_gl_reference_bo(context_gl, bo_gl); checkGLcall("buffer upload"); }
@@ -1348,6 +1351,7 @@ static void wined3d_buffer_gl_download_ranges(struct wined3d_buffer *buffer, str void *data, unsigned int data_offset, unsigned int range_count, const struct wined3d_range *ranges) { struct wined3d_context_gl *context_gl = wined3d_context_gl(context); + struct wined3d_bo_gl *bo_gl = wined3d_bo_gl(buffer->buffer_object); struct wined3d_buffer_gl *buffer_gl = wined3d_buffer_gl(buffer); const struct wined3d_gl_info *gl_info = context_gl->gl_info; const struct wined3d_range *range; @@ -1360,7 +1364,7 @@ static void wined3d_buffer_gl_download_ranges(struct wined3d_buffer *buffer, str while (range_count--) { range = &ranges[range_count]; - GL_EXTCALL(glGetBufferSubData(buffer_gl->bo.binding, + GL_EXTCALL(glGetBufferSubData(bo_gl->binding, range->offset, range->size, (BYTE *)data + range->offset - data_offset)); } checkGLcall("buffer download"); diff --git a/dlls/wined3d/context_gl.c b/dlls/wined3d/context_gl.c index 09c871efcd4..22e82302b9d 100644 --- a/dlls/wined3d/context_gl.c +++ b/dlls/wined3d/context_gl.c @@ -3815,7 +3815,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); + wined3d_context_gl_reference_buffer(context_gl, &buffer_gl->b); if (!buffer_gl->b.bo_user.valid) device_invalidate_state(context_gl->c.device, STATE_CONSTANT_BUFFER(i)); } @@ -3831,7 +3831,7 @@ static void context_gl_load_shader_resources(struct wined3d_context_gl *context_ { buffer_gl = wined3d_buffer_gl(buffer_from_resource(view->resource)); wined3d_buffer_load(&buffer_gl->b, &context_gl->c, state); - wined3d_context_gl_reference_bo(context_gl, &buffer_gl->bo); + wined3d_context_gl_reference_buffer(context_gl, &buffer_gl->b);
srv_gl = wined3d_shader_resource_view_gl(view); if (!srv_gl->bo_user.valid) @@ -3869,7 +3869,7 @@ static void context_gl_load_unordered_access_resources(struct wined3d_context_gl buffer_gl = wined3d_buffer_gl(buffer_from_resource(view->resource)); wined3d_buffer_load_location(&buffer_gl->b, &context_gl->c, WINED3D_LOCATION_BUFFER); wined3d_unordered_access_view_invalidate_location(view, ~WINED3D_LOCATION_BUFFER); - wined3d_context_gl_reference_bo(context_gl, &buffer_gl->bo); + wined3d_context_gl_reference_buffer(context_gl, &buffer_gl->b);
uav_gl = wined3d_unordered_access_view_gl(view); if (!uav_gl->bo_user.valid) @@ -3901,7 +3901,7 @@ static void context_gl_load_stream_output_buffers(struct wined3d_context_gl *con buffer_gl = wined3d_buffer_gl(state->stream_output[i].buffer); 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); + wined3d_context_gl_reference_buffer(context_gl, &buffer_gl->b); if (!buffer_gl->b.bo_user.valid) device_invalidate_state(context_gl->c.device, STATE_STREAM_OUTPUT); } @@ -3977,7 +3977,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);
- wined3d_context_gl_reference_bo(context_gl, &buffer_gl->bo); + wined3d_context_gl_reference_buffer(context_gl, &buffer_gl->b); }
if (indexed && state->index_buffer) @@ -3989,7 +3989,7 @@ static BOOL context_apply_draw_state(struct wined3d_context *context, wined3d_buffer_load(&buffer_gl->b, context, state); if (!buffer_gl->b.bo_user.valid) device_invalidate_state(device, STATE_INDEXBUFFER); - wined3d_context_gl_reference_bo(context_gl, &buffer_gl->bo); + wined3d_context_gl_reference_buffer(context_gl, &buffer_gl->b); } else { @@ -4338,11 +4338,12 @@ void dispatch_compute(struct wined3d_device *device, const struct wined3d_state { const struct wined3d_indirect_dispatch_parameters *indirect = ¶meters->u.indirect; struct wined3d_buffer_gl *buffer_gl = wined3d_buffer_gl(indirect->buffer); + struct wined3d_bo_gl *bo_gl = wined3d_bo_gl(buffer_gl->b.buffer_object);
- GL_EXTCALL(glBindBuffer(GL_DISPATCH_INDIRECT_BUFFER, buffer_gl->bo.id)); + GL_EXTCALL(glBindBuffer(GL_DISPATCH_INDIRECT_BUFFER, bo_gl->id)); GL_EXTCALL(glDispatchComputeIndirect((GLintptr)indirect->offset)); GL_EXTCALL(glBindBuffer(GL_DISPATCH_INDIRECT_BUFFER, 0)); - wined3d_context_gl_reference_bo(context_gl, &buffer_gl->bo); + wined3d_context_gl_reference_bo(context_gl, bo_gl); } else { @@ -4725,6 +4726,7 @@ static void wined3d_context_gl_draw_indirect(struct wined3d_context_gl *context_ { GLenum gl_primitive_type = gl_primitive_type_from_d3d(state->primitive_type); struct wined3d_buffer_gl *buffer_gl = wined3d_buffer_gl(parameters->buffer); + struct wined3d_bo_gl *bo_gl = wined3d_bo_gl(buffer_gl->b.buffer_object); const struct wined3d_gl_info *gl_info = context_gl->gl_info; const void *offset;
@@ -4734,7 +4736,7 @@ static void wined3d_context_gl_draw_indirect(struct wined3d_context_gl *context_ return; }
- GL_EXTCALL(glBindBuffer(GL_DRAW_INDIRECT_BUFFER, buffer_gl->bo.id)); + GL_EXTCALL(glBindBuffer(GL_DRAW_INDIRECT_BUFFER, bo_gl->id));
offset = (void *)(GLintptr)parameters->offset; if (idx_size) @@ -4750,7 +4752,7 @@ static void wined3d_context_gl_draw_indirect(struct wined3d_context_gl *context_ }
GL_EXTCALL(glBindBuffer(GL_DRAW_INDIRECT_BUFFER, 0)); - wined3d_context_gl_reference_bo(context_gl, &buffer_gl->bo); + wined3d_context_gl_reference_bo(context_gl, bo_gl);
checkGLcall("draw indirect"); } diff --git a/dlls/wined3d/state.c b/dlls/wined3d/state.c index 5e41f681c75..788ccb580dd 100644 --- a/dlls/wined3d/state.c +++ b/dlls/wined3d/state.c @@ -4466,6 +4466,7 @@ static void indexbuffer(struct wined3d_context *context, const struct wined3d_st const struct wined3d_gl_info *gl_info = wined3d_context_gl(context)->gl_info; const struct wined3d_stream_info *stream_info = &context->stream_info; struct wined3d_buffer_gl *buffer_gl; + const struct wined3d_bo_gl *bo_gl;
if (!state->index_buffer || !stream_info->all_vbo) { @@ -4474,8 +4475,15 @@ 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->b.bo_user.valid = true; + if ((bo_gl = wined3d_bo_gl(buffer_gl->b.buffer_object))) + { + GL_EXTCALL(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bo_gl->id)); + buffer_gl->b.bo_user.valid = true; + } + else + { + GL_EXTCALL(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); + } }
static void depth_clip(const struct wined3d_rasterizer_state *r, const struct wined3d_gl_info *gl_info) @@ -4569,6 +4577,7 @@ static void state_cb(struct wined3d_context *context, const struct wined3d_state const struct wined3d_gl_info *gl_info = wined3d_context_gl(context)->gl_info; enum wined3d_shader_type shader_type; struct wined3d_buffer_gl *buffer_gl; + struct wined3d_bo_gl *bo_gl; unsigned int i, base, count;
TRACE("context %p, state %p, state_id %#x.\n", context, state, state_id); @@ -4590,7 +4599,8 @@ 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, + bo_gl = wined3d_bo_gl(buffer_gl->b.buffer_object); + GL_EXTCALL(glBindBufferRange(GL_UNIFORM_BUFFER, base + i, bo_gl->id, buffer_state->offset, buffer_state->size)); buffer_gl->b.bo_user.valid = true; } @@ -4644,6 +4654,7 @@ static void state_so(struct wined3d_context *context, const struct wined3d_state const struct wined3d_gl_info *gl_info = context_gl->gl_info; struct wined3d_buffer_gl *buffer_gl; unsigned int offset, size, i; + struct wined3d_bo_gl *bo_gl;
TRACE("context %p, state %p, state_id %#x.\n", context, state, state_id);
@@ -4658,6 +4669,7 @@ static void state_so(struct wined3d_context *context, const struct wined3d_state }
buffer_gl = wined3d_buffer_gl(state->stream_output[i].buffer); + bo_gl = wined3d_bo_gl(buffer_gl->b.buffer_object); offset = state->stream_output[i].offset; if (offset == ~0u) { @@ -4665,7 +4677,7 @@ static void state_so(struct wined3d_context *context, const struct wined3d_state offset = 0; } size = buffer_gl->b.resource.size - offset; - GL_EXTCALL(glBindBufferRange(GL_TRANSFORM_FEEDBACK_BUFFER, i, buffer_gl->bo.id, offset, size)); + GL_EXTCALL(glBindBufferRange(GL_TRANSFORM_FEEDBACK_BUFFER, i, bo_gl->id, offset, size)); buffer_gl->b.bo_user.valid = true; } checkGLcall("bind transform feedback buffers"); diff --git a/dlls/wined3d/view.c b/dlls/wined3d/view.c index 8746d9168c2..77e98f27a75 100644 --- a/dlls/wined3d/view.c +++ b/dlls/wined3d/view.c @@ -249,6 +249,7 @@ static void create_buffer_texture(struct wined3d_gl_view *view, struct wined3d_c unsigned int offset, unsigned int size) { const struct wined3d_gl_info *gl_info = context_gl->gl_info; + const struct wined3d_bo_gl *bo_gl;
if (!gl_info->supported[ARB_TEXTURE_BUFFER_OBJECT]) { @@ -264,6 +265,7 @@ static void create_buffer_texture(struct wined3d_gl_view *view, struct wined3d_c }
wined3d_buffer_load_location(&buffer_gl->b, &context_gl->c, WINED3D_LOCATION_BUFFER); + bo_gl = wined3d_bo_gl(buffer_gl->b.buffer_object);
view->target = GL_TEXTURE_BUFFER; if (!view->name) @@ -272,13 +274,13 @@ static void create_buffer_texture(struct wined3d_gl_view *view, struct wined3d_c wined3d_context_gl_bind_texture(context_gl, GL_TEXTURE_BUFFER, view->name); if (gl_info->supported[ARB_TEXTURE_BUFFER_RANGE]) { - GL_EXTCALL(glTexBufferRange(GL_TEXTURE_BUFFER, view_format_gl->internal, buffer_gl->bo.id, offset, size)); + GL_EXTCALL(glTexBufferRange(GL_TEXTURE_BUFFER, view_format_gl->internal, bo_gl->id, offset, size)); } else { if (offset || size != buffer_gl->b.resource.size) FIXME("OpenGL implementation does not support ARB_texture_buffer_range.\n"); - GL_EXTCALL(glTexBuffer(GL_TEXTURE_BUFFER, view_format_gl->internal, buffer_gl->bo.id)); + GL_EXTCALL(glTexBuffer(GL_TEXTURE_BUFFER, view_format_gl->internal, bo_gl->id)); } checkGLcall("Create buffer texture");
@@ -972,11 +974,13 @@ static void wined3d_shader_resource_view_gl_cs_init(void *object) { struct wined3d_buffer *buffer = buffer_from_resource(resource); struct wined3d_context *context; + struct wined3d_bo *bo;
context = context_acquire(resource->device, NULL, 0); create_buffer_view(&view_gl->gl_view, context, desc, buffer, view_format); + bo = (struct wined3d_bo *)buffer->buffer_object; view_gl->bo_user.valid = true; - list_add_head(&wined3d_buffer_gl(buffer)->bo.b.users, &view_gl->bo_user.entry); + list_add_head(&bo->users, &view_gl->bo_user.entry); context_release(context); } else @@ -1482,6 +1486,7 @@ void wined3d_unordered_access_view_gl_clear(struct wined3d_unordered_access_view const struct wined3d_format_gl *format_gl; struct wined3d_buffer_gl *buffer_gl; struct wined3d_resource *resource; + struct wined3d_bo_gl *bo_gl; unsigned int offset, size;
resource = view_gl->v.resource; @@ -1591,11 +1596,12 @@ void wined3d_unordered_access_view_gl_clear(struct wined3d_unordered_access_view wined3d_buffer_load_location(&buffer_gl->b, &context_gl->c, WINED3D_LOCATION_BUFFER); wined3d_unordered_access_view_invalidate_location(&view_gl->v, ~WINED3D_LOCATION_BUFFER);
+ bo_gl = wined3d_bo_gl(buffer_gl->b.buffer_object); get_buffer_view_range(&buffer_gl->b, &view_gl->v.desc, &format_gl->f, &offset, &size); - wined3d_context_gl_bind_bo(context_gl, buffer_gl->bo.binding, buffer_gl->bo.id); - GL_EXTCALL(glClearBufferSubData(buffer_gl->bo.binding, format_gl->internal, + wined3d_context_gl_bind_bo(context_gl, bo_gl->binding, bo_gl->id); + GL_EXTCALL(glClearBufferSubData(bo_gl->binding, format_gl->internal, offset, size, format_gl->format, format_gl->type, clear_value)); - wined3d_context_gl_reference_bo(context_gl, &buffer_gl->bo); + wined3d_context_gl_reference_bo(context_gl, bo_gl); checkGLcall("clear unordered access view"); }
@@ -1658,11 +1664,13 @@ static void wined3d_unordered_access_view_gl_cs_init(void *object) { struct wined3d_buffer *buffer = buffer_from_resource(resource); struct wined3d_context_gl *context_gl; + struct wined3d_bo *bo;
context_gl = wined3d_context_gl(context_acquire(resource->device, NULL, 0)); create_buffer_view(&view_gl->gl_view, &context_gl->c, desc, buffer, view_gl->v.format); + bo = (struct wined3d_bo *)buffer->buffer_object; view_gl->bo_user.valid = true; - list_add_head(&wined3d_buffer_gl(buffer)->bo.b.users, &view_gl->bo_user.entry); + list_add_head(&bo->users, &view_gl->bo_user.entry); if (desc->flags & (WINED3D_VIEW_BUFFER_COUNTER | WINED3D_VIEW_BUFFER_APPEND)) { struct wined3d_bo_gl *bo = &view_gl->counter_bo; diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h index 63fea9da0e7..e04f2682c88 100644 --- a/dlls/wined3d/wined3d_private.h +++ b/dlls/wined3d/wined3d_private.h @@ -1612,6 +1612,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; @@ -6579,6 +6584,12 @@ static inline void wined3d_context_gl_reference_bo(struct wined3d_context_gl *co bo_gl->command_fence_id = device_gl->current_fence_id; }
+static inline void wined3d_context_gl_reference_buffer(struct wined3d_context_gl *context_gl, + struct wined3d_buffer *buffer) +{ + wined3d_context_gl_reference_bo(context_gl, wined3d_bo_gl(buffer->buffer_object)); +} + static inline bool wined3d_map_persistent(void) { return sizeof(void *) >= sizeof(uint64_t);