wined3d: Avoid accessing the "bo" member of struct wined3d_buffer_gl.

Signed-off-by: Zebediah Figura <zfigura@codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Zebediah Figura 2021-11-10 11:36:10 +01:00 committed by Alexandre Julliard
parent 4b22faa94e
commit c465f339a7
4 changed files with 56 additions and 41 deletions

View File

@ -133,7 +133,9 @@ void wined3d_buffer_invalidate_location(struct wined3d_buffer *buffer, DWORD loc
/* Context activation is done by the caller. */ /* 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) 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) 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; 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_gl->b.buffer_object = &bo->b;
buffer_invalidate_bo_range(&buffer_gl->b, 0, 0); buffer_invalidate_bo_range(&buffer_gl->b, 0, 0);
@ -1333,6 +1335,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) 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_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); struct wined3d_buffer_gl *buffer_gl = wined3d_buffer_gl(buffer);
const struct wined3d_gl_info *gl_info = context_gl->gl_info; const struct wined3d_gl_info *gl_info = context_gl->gl_info;
const struct wined3d_range *range; const struct wined3d_range *range;
@ -1345,10 +1348,10 @@ static void wined3d_buffer_gl_upload_ranges(struct wined3d_buffer *buffer, struc
while (range_count--) while (range_count--)
{ {
range = &ranges[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)); 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"); checkGLcall("buffer upload");
} }
@ -1357,6 +1360,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) 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_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); struct wined3d_buffer_gl *buffer_gl = wined3d_buffer_gl(buffer);
const struct wined3d_gl_info *gl_info = context_gl->gl_info; const struct wined3d_gl_info *gl_info = context_gl->gl_info;
const struct wined3d_range *range; const struct wined3d_range *range;
@ -1369,7 +1373,7 @@ static void wined3d_buffer_gl_download_ranges(struct wined3d_buffer *buffer, str
while (range_count--) while (range_count--)
{ {
range = &ranges[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)); range->offset, range->size, (BYTE *)data + range->offset - data_offset));
} }
checkGLcall("buffer download"); checkGLcall("buffer download");

View File

@ -4335,12 +4335,12 @@ void dispatch_compute(struct wined3d_device *device, const struct wined3d_state
if (parameters->indirect) if (parameters->indirect)
{ {
const struct wined3d_indirect_dispatch_parameters *indirect = &parameters->u.indirect; const struct wined3d_indirect_dispatch_parameters *indirect = &parameters->u.indirect;
struct wined3d_buffer_gl *buffer_gl = wined3d_buffer_gl(indirect->buffer); struct wined3d_bo_gl *bo_gl = wined3d_bo_gl(indirect->buffer->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(glDispatchComputeIndirect((GLintptr)indirect->offset));
GL_EXTCALL(glBindBuffer(GL_DISPATCH_INDIRECT_BUFFER, 0)); 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 else
{ {
@ -4721,8 +4721,8 @@ static void draw_primitive_immediate_mode(struct wined3d_context_gl *context_gl,
static void wined3d_context_gl_draw_indirect(struct wined3d_context_gl *context_gl, const struct wined3d_state *state, static void wined3d_context_gl_draw_indirect(struct wined3d_context_gl *context_gl, const struct wined3d_state *state,
const struct wined3d_indirect_draw_parameters *parameters, unsigned int idx_size) const struct wined3d_indirect_draw_parameters *parameters, unsigned int idx_size)
{ {
struct wined3d_bo_gl *bo_gl = wined3d_bo_gl(parameters->buffer->buffer_object);
GLenum gl_primitive_type = gl_primitive_type_from_d3d(state->primitive_type); GLenum gl_primitive_type = gl_primitive_type_from_d3d(state->primitive_type);
struct wined3d_buffer_gl *buffer_gl = wined3d_buffer_gl(parameters->buffer);
const struct wined3d_gl_info *gl_info = context_gl->gl_info; const struct wined3d_gl_info *gl_info = context_gl->gl_info;
const void *offset; const void *offset;
@ -4732,7 +4732,7 @@ static void wined3d_context_gl_draw_indirect(struct wined3d_context_gl *context_
return; 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; offset = (void *)(GLintptr)parameters->offset;
if (idx_size) if (idx_size)
@ -4748,7 +4748,7 @@ static void wined3d_context_gl_draw_indirect(struct wined3d_context_gl *context_
} }
GL_EXTCALL(glBindBuffer(GL_DRAW_INDIRECT_BUFFER, 0)); 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"); checkGLcall("draw indirect");
} }

View File

@ -4465,7 +4465,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_gl_info *gl_info = wined3d_context_gl(context)->gl_info;
const struct wined3d_stream_info *stream_info = &context->stream_info; const struct wined3d_stream_info *stream_info = &context->stream_info;
struct wined3d_buffer_gl *buffer_gl; struct wined3d_buffer *buffer;
if (!state->index_buffer || !stream_info->all_vbo) if (!state->index_buffer || !stream_info->all_vbo)
{ {
@ -4473,9 +4473,16 @@ static void indexbuffer(struct wined3d_context *context, const struct wined3d_st
return; return;
} }
buffer_gl = wined3d_buffer_gl(state->index_buffer); buffer = state->index_buffer;
GL_EXTCALL(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffer_gl->bo.id)); if (buffer->buffer_object)
buffer_gl->b.bo_user.valid = true; {
GL_EXTCALL(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, wined3d_bo_gl(buffer->buffer_object)->id));
buffer->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) static void depth_clip(const struct wined3d_rasterizer_state *r, const struct wined3d_gl_info *gl_info)
@ -4568,7 +4575,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; const struct wined3d_gl_info *gl_info = wined3d_context_gl(context)->gl_info;
enum wined3d_shader_type shader_type; enum wined3d_shader_type shader_type;
struct wined3d_buffer_gl *buffer_gl; struct wined3d_buffer *buffer;
unsigned int i, base, count; unsigned int i, base, count;
TRACE("context %p, state %p, state_id %#x.\n", context, state, state_id); TRACE("context %p, state %p, state_id %#x.\n", context, state, state_id);
@ -4589,10 +4596,10 @@ static void state_cb(struct wined3d_context *context, const struct wined3d_state
continue; continue;
} }
buffer_gl = wined3d_buffer_gl(buffer_state->buffer); buffer = buffer_state->buffer;
GL_EXTCALL(glBindBufferRange(GL_UNIFORM_BUFFER, base + i, buffer_gl->bo.id, GL_EXTCALL(glBindBufferRange(GL_UNIFORM_BUFFER, base + i,
buffer_state->offset, buffer_state->size)); wined3d_bo_gl(buffer->buffer_object)->id, buffer_state->offset, buffer_state->size));
buffer_gl->b.bo_user.valid = true; buffer->bo_user.valid = true;
} }
checkGLcall("bind constant buffers"); checkGLcall("bind constant buffers");
} }
@ -4642,7 +4649,7 @@ static void state_so(struct wined3d_context *context, const struct wined3d_state
{ {
struct wined3d_context_gl *context_gl = wined3d_context_gl(context); struct wined3d_context_gl *context_gl = wined3d_context_gl(context);
const struct wined3d_gl_info *gl_info = context_gl->gl_info; const struct wined3d_gl_info *gl_info = context_gl->gl_info;
struct wined3d_buffer_gl *buffer_gl; struct wined3d_buffer *buffer;
unsigned int offset, size, i; unsigned int offset, size, i;
TRACE("context %p, state %p, state_id %#x.\n", context, state, state_id); TRACE("context %p, state %p, state_id %#x.\n", context, state, state_id);
@ -4657,16 +4664,17 @@ static void state_so(struct wined3d_context *context, const struct wined3d_state
continue; continue;
} }
buffer_gl = wined3d_buffer_gl(state->stream_output[i].buffer); buffer = state->stream_output[i].buffer;
offset = state->stream_output[i].offset; offset = state->stream_output[i].offset;
if (offset == ~0u) if (offset == ~0u)
{ {
FIXME("Appending to stream output buffers not implemented.\n"); FIXME("Appending to stream output buffers not implemented.\n");
offset = 0; offset = 0;
} }
size = buffer_gl->b.resource.size - offset; size = buffer->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,
buffer_gl->b.bo_user.valid = true; wined3d_bo_gl(buffer->buffer_object)->id, offset, size));
buffer->bo_user.valid = true;
} }
checkGLcall("bind transform feedback buffers"); checkGLcall("bind transform feedback buffers");
} }

View File

@ -245,10 +245,11 @@ static void create_texture_view(struct wined3d_gl_view *view, GLenum view_target
} }
static void create_buffer_texture(struct wined3d_gl_view *view, struct wined3d_context_gl *context_gl, static void create_buffer_texture(struct wined3d_gl_view *view, struct wined3d_context_gl *context_gl,
struct wined3d_buffer_gl *buffer_gl, const struct wined3d_format_gl *view_format_gl, struct wined3d_buffer *buffer, const struct wined3d_format_gl *view_format_gl,
unsigned int offset, unsigned int size) unsigned int offset, unsigned int size)
{ {
const struct wined3d_gl_info *gl_info = context_gl->gl_info; 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]) if (!gl_info->supported[ARB_TEXTURE_BUFFER_OBJECT])
{ {
@ -263,7 +264,8 @@ static void create_buffer_texture(struct wined3d_gl_view *view, struct wined3d_c
return; return;
} }
wined3d_buffer_load_location(&buffer_gl->b, &context_gl->c, WINED3D_LOCATION_BUFFER); wined3d_buffer_load_location(buffer, &context_gl->c, WINED3D_LOCATION_BUFFER);
bo_gl = wined3d_bo_gl(buffer->buffer_object);
view->target = GL_TEXTURE_BUFFER; view->target = GL_TEXTURE_BUFFER;
if (!view->name) 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); wined3d_context_gl_bind_texture(context_gl, GL_TEXTURE_BUFFER, view->name);
if (gl_info->supported[ARB_TEXTURE_BUFFER_RANGE]) 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 else
{ {
if (offset || size != buffer_gl->b.resource.size) if (offset || size != buffer->resource.size)
FIXME("OpenGL implementation does not support ARB_texture_buffer_range.\n"); 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"); checkGLcall("Create buffer texture");
@ -309,8 +311,7 @@ static void create_buffer_view(struct wined3d_gl_view *view, struct wined3d_cont
unsigned int offset, size; unsigned int offset, size;
get_buffer_view_range(buffer, desc, view_format, &offset, &size); get_buffer_view_range(buffer, desc, view_format, &offset, &size);
create_buffer_texture(view, wined3d_context_gl(context), create_buffer_texture(view, wined3d_context_gl(context), buffer, wined3d_format_gl(view_format), offset, size);
wined3d_buffer_gl(buffer), wined3d_format_gl(view_format), offset, size);
} }
static void wined3d_view_invalidate_location(struct wined3d_resource *resource, static void wined3d_view_invalidate_location(struct wined3d_resource *resource,
@ -976,7 +977,7 @@ static void wined3d_shader_resource_view_gl_cs_init(void *object)
context = context_acquire(resource->device, NULL, 0); context = context_acquire(resource->device, NULL, 0);
create_buffer_view(&view_gl->gl_view, context, desc, buffer, view_format); create_buffer_view(&view_gl->gl_view, context, desc, buffer, view_format);
view_gl->bo_user.valid = true; view_gl->bo_user.valid = true;
list_add_head(&wined3d_buffer_gl(buffer)->bo.b.users, &view_gl->bo_user.entry); list_add_head(&buffer->buffer_object->users, &view_gl->bo_user.entry);
context_release(context); context_release(context);
} }
else else
@ -1480,8 +1481,9 @@ void wined3d_unordered_access_view_gl_clear(struct wined3d_unordered_access_view
{ {
const struct wined3d_gl_info *gl_info = context_gl->gl_info; const struct wined3d_gl_info *gl_info = context_gl->gl_info;
const struct wined3d_format_gl *format_gl; const struct wined3d_format_gl *format_gl;
struct wined3d_buffer_gl *buffer_gl;
struct wined3d_resource *resource; struct wined3d_resource *resource;
struct wined3d_buffer *buffer;
struct wined3d_bo_gl *bo_gl;
unsigned int offset, size; unsigned int offset, size;
resource = view_gl->v.resource; resource = view_gl->v.resource;
@ -1587,15 +1589,16 @@ void wined3d_unordered_access_view_gl_clear(struct wined3d_unordered_access_view
return; return;
} }
buffer_gl = wined3d_buffer_gl(buffer_from_resource(resource)); buffer = buffer_from_resource(resource);
wined3d_buffer_load_location(&buffer_gl->b, &context_gl->c, WINED3D_LOCATION_BUFFER); wined3d_buffer_load_location(buffer, &context_gl->c, WINED3D_LOCATION_BUFFER);
wined3d_unordered_access_view_invalidate_location(&view_gl->v, ~WINED3D_LOCATION_BUFFER); wined3d_unordered_access_view_invalidate_location(&view_gl->v, ~WINED3D_LOCATION_BUFFER);
get_buffer_view_range(&buffer_gl->b, &view_gl->v.desc, &format_gl->f, &offset, &size); bo_gl = wined3d_bo_gl(buffer->buffer_object);
wined3d_context_gl_bind_bo(context_gl, buffer_gl->bo.binding, buffer_gl->bo.id); get_buffer_view_range(buffer, &view_gl->v.desc, &format_gl->f, &offset, &size);
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)); 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"); checkGLcall("clear unordered access view");
} }
@ -1662,7 +1665,7 @@ static void wined3d_unordered_access_view_gl_cs_init(void *object)
context_gl = wined3d_context_gl(context_acquire(resource->device, NULL, 0)); 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); create_buffer_view(&view_gl->gl_view, &context_gl->c, desc, buffer, view_gl->v.format);
view_gl->bo_user.valid = true; view_gl->bo_user.valid = true;
list_add_head(&wined3d_buffer_gl(buffer)->bo.b.users, &view_gl->bo_user.entry); list_add_head(&buffer->buffer_object->users, &view_gl->bo_user.entry);
if (desc->flags & (WINED3D_VIEW_BUFFER_COUNTER | WINED3D_VIEW_BUFFER_APPEND)) if (desc->flags & (WINED3D_VIEW_BUFFER_COUNTER | WINED3D_VIEW_BUFFER_APPEND))
{ {
struct wined3d_bo_gl *bo = &view_gl->counter_bo; struct wined3d_bo_gl *bo = &view_gl->counter_bo;