Commit 4a3cefab authored by Zebediah Figura's avatar Zebediah Figura Committed by Alexandre Julliard

wined3d: Protect access to the OpenGL wined3d_allocator with a critical section.

parent 7c16fb7c
......@@ -4274,6 +4274,8 @@ static HRESULT adapter_gl_create_device(struct wined3d *wined3d, const struct wi
return hr;
}
wined3d_lock_init(&device_gl->allocator_cs, "wined3d_device_gl.allocator_cs");
*device = &device_gl->d;
return WINED3D_OK;
}
......@@ -4283,6 +4285,8 @@ static void adapter_gl_destroy_device(struct wined3d_device *device)
struct wined3d_device_gl *device_gl = wined3d_device_gl(device);
wined3d_device_cleanup(&device_gl->d);
wined3d_lock_cleanup(&device_gl->allocator_cs);
heap_free(device_gl->retired_blocks);
heap_free(device_gl);
}
......
......@@ -2629,6 +2629,14 @@ static void wined3d_context_gl_poll_fences(struct wined3d_context_gl *context_gl
}
}
static void wined3d_device_gl_free_memory(struct wined3d_device_gl *device_gl, struct wined3d_allocator_block *block)
{
assert(block->chunk->allocator == &device_gl->allocator);
wined3d_device_gl_allocator_lock(device_gl);
wined3d_allocator_block_free(block);
wined3d_device_gl_allocator_unlock(device_gl);
}
static void wined3d_context_gl_cleanup_resources(struct wined3d_context_gl *context_gl)
{
struct wined3d_device_gl *device_gl = wined3d_device_gl(context_gl->c.device);
......@@ -2651,7 +2659,7 @@ static void wined3d_context_gl_cleanup_resources(struct wined3d_context_gl *cont
continue;
}
wined3d_allocator_block_free(r->block);
wined3d_device_gl_free_memory(device_gl, r->block);
if (i != --count)
*r = blocks[count];
else
......@@ -2718,7 +2726,7 @@ static void wined3d_context_gl_destroy_allocator_block(struct wined3d_context_gl
if (device_gl->completed_fence_id > fence_id)
{
wined3d_allocator_block_free(block);
wined3d_device_gl_free_memory(device_gl, block);
TRACE("Freed block %p.\n", block);
return;
}
......
......@@ -1059,20 +1059,25 @@ static struct wined3d_allocator_block *wined3d_device_gl_allocate_memory(struct
struct wined3d_allocator *allocator = &device_gl->allocator;
struct wined3d_allocator_block *block;
wined3d_device_gl_allocator_lock(device_gl);
if (size > WINED3D_ALLOCATOR_CHUNK_SIZE / 2)
{
*id = wined3d_context_gl_allocate_vram_chunk_buffer(context_gl, memory_type, size);
wined3d_device_gl_allocator_unlock(device_gl);
return NULL;
}
if (!(block = wined3d_allocator_allocate(allocator, &context_gl->c, memory_type, size)))
{
wined3d_device_gl_allocator_unlock(device_gl);
*id = 0;
return NULL;
}
*id = wined3d_allocator_chunk_gl(block->chunk)->gl_buffer;
wined3d_device_gl_allocator_unlock(device_gl);
return block;
}
......
......@@ -4194,6 +4194,7 @@ struct wined3d_device_gl
/* Textures for when no other textures are bound. */
struct wined3d_dummy_textures dummy_textures;
CRITICAL_SECTION allocator_cs;
struct wined3d_allocator allocator;
uint64_t completed_fence_id;
uint64_t current_fence_id;
......@@ -4212,6 +4213,16 @@ static inline struct wined3d_device_gl *wined3d_device_gl(struct wined3d_device
return CONTAINING_RECORD(device, struct wined3d_device_gl, d);
}
static inline void wined3d_device_gl_allocator_lock(struct wined3d_device_gl *device_gl)
{
EnterCriticalSection(&device_gl->allocator_cs);
}
static inline void wined3d_device_gl_allocator_unlock(struct wined3d_device_gl *device_gl)
{
LeaveCriticalSection(&device_gl->allocator_cs);
}
bool wined3d_device_gl_create_bo(struct wined3d_device_gl *device_gl,
struct wined3d_context_gl *context_gl, GLsizeiptr size, GLenum binding,
GLenum usage, bool coherent, GLbitfield flags, struct wined3d_bo_gl *bo) DECLSPEC_HIDDEN;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment