wined3d: Introduce wined3d_context_gl_reference_buffer().

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:09 +01:00 committed by Alexandre Julliard
parent 996cfb841e
commit 4b22faa94e
2 changed files with 41 additions and 32 deletions

View File

@ -3796,8 +3796,8 @@ static void context_gl_load_shader_resources(struct wined3d_context_gl *context_
struct wined3d_shader_sampler_map_entry *entry; struct wined3d_shader_sampler_map_entry *entry;
struct wined3d_shader_resource_view_gl *srv_gl; struct wined3d_shader_resource_view_gl *srv_gl;
struct wined3d_shader_resource_view *view; struct wined3d_shader_resource_view *view;
struct wined3d_buffer_gl *buffer_gl;
struct wined3d_shader *shader; struct wined3d_shader *shader;
struct wined3d_buffer *buffer;
unsigned int i, j; unsigned int i, j;
for (i = 0; i < WINED3D_SHADER_TYPE_COUNT; ++i) for (i = 0; i < WINED3D_SHADER_TYPE_COUNT; ++i)
@ -3813,10 +3813,10 @@ static void context_gl_load_shader_resources(struct wined3d_context_gl *context_
if (!state->cb[i][j].buffer) if (!state->cb[i][j].buffer)
continue; continue;
buffer_gl = wined3d_buffer_gl(state->cb[i][j].buffer); buffer = state->cb[i][j].buffer;
wined3d_buffer_load(&buffer_gl->b, &context_gl->c, state); wined3d_buffer_load(buffer, &context_gl->c, state);
wined3d_context_gl_reference_bo(context_gl, &buffer_gl->bo); wined3d_context_gl_reference_buffer(context_gl, buffer);
if (!buffer_gl->b.bo_user.valid) if (!buffer->bo_user.valid)
device_invalidate_state(context_gl->c.device, STATE_CONSTANT_BUFFER(i)); device_invalidate_state(context_gl->c.device, STATE_CONSTANT_BUFFER(i));
} }
@ -3829,9 +3829,9 @@ static void context_gl_load_shader_resources(struct wined3d_context_gl *context_
if (view->resource->type == WINED3D_RTYPE_BUFFER) if (view->resource->type == WINED3D_RTYPE_BUFFER)
{ {
buffer_gl = wined3d_buffer_gl(buffer_from_resource(view->resource)); buffer = buffer_from_resource(view->resource);
wined3d_buffer_load(&buffer_gl->b, &context_gl->c, state); wined3d_buffer_load(buffer, &context_gl->c, state);
wined3d_context_gl_reference_bo(context_gl, &buffer_gl->bo); wined3d_context_gl_reference_buffer(context_gl, buffer);
srv_gl = wined3d_shader_resource_view_gl(view); srv_gl = wined3d_shader_resource_view_gl(view);
if (!srv_gl->bo_user.valid) if (!srv_gl->bo_user.valid)
@ -3850,8 +3850,8 @@ static void context_gl_load_unordered_access_resources(struct wined3d_context_gl
{ {
struct wined3d_unordered_access_view_gl *uav_gl; struct wined3d_unordered_access_view_gl *uav_gl;
struct wined3d_unordered_access_view *view; struct wined3d_unordered_access_view *view;
struct wined3d_buffer_gl *buffer_gl;
struct wined3d_texture *texture; struct wined3d_texture *texture;
struct wined3d_buffer *buffer;
unsigned int i; unsigned int i;
context_gl->c.uses_uavs = 0; context_gl->c.uses_uavs = 0;
@ -3866,10 +3866,10 @@ static void context_gl_load_unordered_access_resources(struct wined3d_context_gl
if (view->resource->type == WINED3D_RTYPE_BUFFER) if (view->resource->type == WINED3D_RTYPE_BUFFER)
{ {
buffer_gl = wined3d_buffer_gl(buffer_from_resource(view->resource)); buffer = buffer_from_resource(view->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, ~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);
uav_gl = wined3d_unordered_access_view_gl(view); uav_gl = wined3d_unordered_access_view_gl(view);
if (!uav_gl->bo_user.valid) if (!uav_gl->bo_user.valid)
@ -3889,20 +3889,18 @@ static void context_gl_load_unordered_access_resources(struct wined3d_context_gl
static void context_gl_load_stream_output_buffers(struct wined3d_context_gl *context_gl, static void context_gl_load_stream_output_buffers(struct wined3d_context_gl *context_gl,
const struct wined3d_state *state) const struct wined3d_state *state)
{ {
struct wined3d_buffer *buffer;
unsigned int i; unsigned int i;
for (i = 0; i < ARRAY_SIZE(state->stream_output); ++i) for (i = 0; i < ARRAY_SIZE(state->stream_output); ++i)
{ {
struct wined3d_buffer_gl *buffer_gl; if (!(buffer = state->stream_output[i].buffer))
if (!state->stream_output[i].buffer)
continue; continue;
buffer_gl = wined3d_buffer_gl(state->stream_output[i].buffer); wined3d_buffer_load(buffer, &context_gl->c, state);
wined3d_buffer_load(&buffer_gl->b, &context_gl->c, state); wined3d_buffer_invalidate_location(buffer, ~WINED3D_LOCATION_BUFFER);
wined3d_buffer_invalidate_location(&buffer_gl->b, ~WINED3D_LOCATION_BUFFER); wined3d_context_gl_reference_buffer(context_gl, buffer);
wined3d_context_gl_reference_bo(context_gl, &buffer_gl->bo); if (!buffer->bo_user.valid)
if (!buffer_gl->b.bo_user.valid)
device_invalidate_state(context_gl->c.device, STATE_STREAM_OUTPUT); device_invalidate_state(context_gl->c.device, STATE_STREAM_OUTPUT);
} }
} }
@ -3954,15 +3952,15 @@ static BOOL context_apply_draw_state(struct wined3d_context *context,
while (map) while (map)
{ {
const struct wined3d_stream_info_element *e; const struct wined3d_stream_info_element *e;
struct wined3d_buffer_gl *buffer_gl; struct wined3d_buffer *buffer;
e = &context->stream_info.elements[wined3d_bit_scan(&map)]; e = &context->stream_info.elements[wined3d_bit_scan(&map)];
buffer_gl = wined3d_buffer_gl(state->streams[e->stream_idx].buffer); buffer = state->streams[e->stream_idx].buffer;
if (!buffer_gl->b.bo_user.valid) if (!buffer->bo_user.valid)
device_invalidate_state(device, STATE_STREAMSRC); device_invalidate_state(device, STATE_STREAMSRC);
else else
wined3d_buffer_load(&buffer_gl->b, context, state); wined3d_buffer_load(buffer, context, state);
} }
/* Loading the buffers above may have invalidated the stream info. */ /* Loading the buffers above may have invalidated the stream info. */
if (wined3d_context_is_graphics_state_dirty(context, STATE_STREAMSRC)) if (wined3d_context_is_graphics_state_dirty(context, STATE_STREAMSRC))
@ -3972,28 +3970,28 @@ static BOOL context_apply_draw_state(struct wined3d_context *context,
while (map) while (map)
{ {
const struct wined3d_stream_info_element *e; const struct wined3d_stream_info_element *e;
struct wined3d_buffer_gl *buffer_gl; struct wined3d_buffer *buffer;
e = &context->stream_info.elements[wined3d_bit_scan(&map)]; e = &context->stream_info.elements[wined3d_bit_scan(&map)];
buffer_gl = wined3d_buffer_gl(state->streams[e->stream_idx].buffer); buffer = state->streams[e->stream_idx].buffer;
wined3d_context_gl_reference_bo(context_gl, &buffer_gl->bo); wined3d_context_gl_reference_buffer(context_gl, buffer);
} }
if (indexed && state->index_buffer) if (indexed && state->index_buffer)
{ {
struct wined3d_buffer_gl *buffer_gl = wined3d_buffer_gl(state->index_buffer); struct wined3d_buffer *buffer = state->index_buffer;
if (context->stream_info.all_vbo) if (context->stream_info.all_vbo)
{ {
wined3d_buffer_load(&buffer_gl->b, context, state); wined3d_buffer_load(buffer, context, state);
if (!buffer_gl->b.bo_user.valid) if (!buffer->bo_user.valid)
device_invalidate_state(device, STATE_INDEXBUFFER); device_invalidate_state(device, STATE_INDEXBUFFER);
wined3d_context_gl_reference_bo(context_gl, &buffer_gl->bo); wined3d_context_gl_reference_buffer(context_gl, buffer);
} }
else else
{ {
wined3d_buffer_load_sysmem(&buffer_gl->b, context); wined3d_buffer_load_sysmem(buffer, context);
} }
} }

View File

@ -1612,6 +1612,11 @@ struct wined3d_bo_gl
uint64_t command_fence_id; 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) static inline GLuint wined3d_bo_gl_id(uintptr_t bo)
{ {
return bo ? ((struct wined3d_bo_gl *)bo)->id : 0; return bo ? ((struct wined3d_bo_gl *)bo)->id : 0;
@ -6581,6 +6586,12 @@ static inline void wined3d_context_gl_reference_bo(struct wined3d_context_gl *co
bo_gl->command_fence_id = device_gl->current_fence_id; 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) static inline bool wined3d_map_persistent(void)
{ {
return sizeof(void *) >= sizeof(uint64_t); return sizeof(void *) >= sizeof(uint64_t);