Commit 4dd4a691 authored by Stefan Dösinger's avatar Stefan Dösinger Committed by Alexandre Julliard

wined3d: Add a function for allocating aligned resource memory.

parent 9d75a517
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* Copyright 2002-2005 Raphael Junqueira * Copyright 2002-2005 Raphael Junqueira
* Copyright 2004 Christian Costa * Copyright 2004 Christian Costa
* Copyright 2005 Oliver Stieber * Copyright 2005 Oliver Stieber
* Copyright 2007-2010 Stefan Dösinger for CodeWeavers * Copyright 2007-2011, 2013 Stefan Dösinger for CodeWeavers
* Copyright 2009-2010 Henri Verbeet for CodeWeavers * Copyright 2009-2010 Henri Verbeet for CodeWeavers
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
...@@ -189,9 +189,9 @@ static void buffer_create_buffer_object(struct wined3d_buffer *This, const struc ...@@ -189,9 +189,9 @@ static void buffer_create_buffer_object(struct wined3d_buffer *This, const struc
} }
else else
{ {
HeapFree(GetProcessHeap(), 0, This->resource.heapMemory); wined3d_resource_free_sysmem(This->resource.heap_memory);
This->resource.allocatedMemory = NULL; This->resource.allocatedMemory = NULL;
This->resource.heapMemory = NULL; This->resource.heap_memory = NULL;
} }
return; return;
...@@ -492,8 +492,8 @@ BYTE *buffer_get_sysmem(struct wined3d_buffer *This, const struct wined3d_gl_inf ...@@ -492,8 +492,8 @@ BYTE *buffer_get_sysmem(struct wined3d_buffer *This, const struct wined3d_gl_inf
/* AllocatedMemory exists if the buffer is double buffered or has no buffer object at all */ /* AllocatedMemory exists if the buffer is double buffered or has no buffer object at all */
if(This->resource.allocatedMemory) return This->resource.allocatedMemory; if(This->resource.allocatedMemory) return This->resource.allocatedMemory;
This->resource.heapMemory = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, This->resource.size + RESOURCE_ALIGNMENT); This->resource.heap_memory = wined3d_resource_allocate_sysmem(This->resource.size);
This->resource.allocatedMemory = (BYTE *)(((ULONG_PTR)This->resource.heapMemory + (RESOURCE_ALIGNMENT - 1)) & ~(RESOURCE_ALIGNMENT - 1)); This->resource.allocatedMemory = This->resource.heap_memory;
if (This->buffer_type_hint == GL_ELEMENT_ARRAY_BUFFER_ARB) if (This->buffer_type_hint == GL_ELEMENT_ARRAY_BUFFER_ARB)
device_invalidate_state(This->resource.device, STATE_INDEXBUFFER); device_invalidate_state(This->resource.device, STATE_INDEXBUFFER);
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
* Copyright 2004 Christian Costa * Copyright 2004 Christian Costa
* Copyright 2005 Oliver Stieber * Copyright 2005 Oliver Stieber
* Copyright 2009-2010 Henri Verbeet for CodeWeavers * Copyright 2009-2010 Henri Verbeet for CodeWeavers
* Copyright 2006-2008, 2013 Stefan Dösinger for CodeWeavers
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
...@@ -111,8 +112,8 @@ HRESULT resource_init(struct wined3d_resource *resource, struct wined3d_device * ...@@ -111,8 +112,8 @@ HRESULT resource_init(struct wined3d_resource *resource, struct wined3d_device *
if (size) if (size)
{ {
resource->heapMemory = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size + RESOURCE_ALIGNMENT); resource->heap_memory = wined3d_resource_allocate_sysmem(size);
if (!resource->heapMemory) if (!resource->heap_memory)
{ {
ERR("Out of memory!\n"); ERR("Out of memory!\n");
return WINED3DERR_OUTOFVIDEOMEMORY; return WINED3DERR_OUTOFVIDEOMEMORY;
...@@ -120,10 +121,9 @@ HRESULT resource_init(struct wined3d_resource *resource, struct wined3d_device * ...@@ -120,10 +121,9 @@ HRESULT resource_init(struct wined3d_resource *resource, struct wined3d_device *
} }
else else
{ {
resource->heapMemory = NULL; resource->heap_memory = NULL;
} }
resource->allocatedMemory = (BYTE *)(((ULONG_PTR)resource->heapMemory resource->allocatedMemory = resource->heap_memory;
+ (RESOURCE_ALIGNMENT - 1)) & ~(RESOURCE_ALIGNMENT - 1));
/* Check that we have enough video ram left */ /* Check that we have enough video ram left */
if (pool == WINED3D_POOL_DEFAULT && d3d->flags & WINED3D_VIDMEM_ACCOUNTING) if (pool == WINED3D_POOL_DEFAULT && d3d->flags & WINED3D_VIDMEM_ACCOUNTING)
...@@ -131,7 +131,7 @@ HRESULT resource_init(struct wined3d_resource *resource, struct wined3d_device * ...@@ -131,7 +131,7 @@ HRESULT resource_init(struct wined3d_resource *resource, struct wined3d_device *
if (size > wined3d_device_get_available_texture_mem(device)) if (size > wined3d_device_get_available_texture_mem(device))
{ {
ERR("Out of adapter memory\n"); ERR("Out of adapter memory\n");
HeapFree(GetProcessHeap(), 0, resource->heapMemory); wined3d_resource_free_sysmem(resource->heap_memory);
return WINED3DERR_OUTOFVIDEOMEMORY; return WINED3DERR_OUTOFVIDEOMEMORY;
} }
adapter_adjust_memory(device->adapter, size); adapter_adjust_memory(device->adapter, size);
...@@ -165,9 +165,9 @@ void resource_cleanup(struct wined3d_resource *resource) ...@@ -165,9 +165,9 @@ void resource_cleanup(struct wined3d_resource *resource)
ERR("Failed to free private data when destroying resource %p, hr = %#x.\n", resource, hr); ERR("Failed to free private data when destroying resource %p, hr = %#x.\n", resource, hr);
} }
HeapFree(GetProcessHeap(), 0, resource->heapMemory); wined3d_resource_free_sysmem(resource->heap_memory);
resource->allocatedMemory = 0; resource->allocatedMemory = NULL;
resource->heapMemory = 0; resource->heap_memory = NULL;
device_resource_released(resource->device, resource); device_resource_released(resource->device, resource);
} }
...@@ -335,3 +335,28 @@ void CDECL wined3d_resource_get_desc(const struct wined3d_resource *resource, st ...@@ -335,3 +335,28 @@ void CDECL wined3d_resource_get_desc(const struct wined3d_resource *resource, st
desc->depth = resource->depth; desc->depth = resource->depth;
desc->size = resource->size; desc->size = resource->size;
} }
void *wined3d_resource_allocate_sysmem(SIZE_T size)
{
void **p;
SIZE_T align = RESOURCE_ALIGNMENT - 1 + sizeof(*p);
void *mem;
if (!(mem = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size + align)))
return NULL;
p = (void **)(((ULONG_PTR)mem + align) & ~(RESOURCE_ALIGNMENT - 1)) - 1;
*p = mem;
return ++p;
}
void wined3d_resource_free_sysmem(void *mem)
{
void **p = mem;
if (!mem)
return;
HeapFree(GetProcessHeap(), 0, *(--p));
}
...@@ -737,10 +737,10 @@ static void swapchain_gdi_present(struct wined3d_swapchain *swapchain, const REC ...@@ -737,10 +737,10 @@ static void swapchain_gdi_present(struct wined3d_swapchain *swapchain, const REC
front->resource.allocatedMemory = back->resource.allocatedMemory; front->resource.allocatedMemory = back->resource.allocatedMemory;
back->resource.allocatedMemory = tmp; back->resource.allocatedMemory = tmp;
if (front->resource.heapMemory) if (front->resource.heap_memory)
ERR("GDI Surface %p has heap memory allocated.\n", front); ERR("GDI Surface %p has heap memory allocated.\n", front);
if (back->resource.heapMemory) if (back->resource.heap_memory)
ERR("GDI Surface %p has heap memory allocated.\n", back); ERR("GDI Surface %p has heap memory allocated.\n", back);
} }
......
...@@ -1926,6 +1926,9 @@ struct wined3d_resource_ops ...@@ -1926,6 +1926,9 @@ struct wined3d_resource_ops
void (*resource_unload)(struct wined3d_resource *resource); void (*resource_unload)(struct wined3d_resource *resource);
}; };
void *wined3d_resource_allocate_sysmem(SIZE_T size) DECLSPEC_HIDDEN;
void wined3d_resource_free_sysmem(void *mem) DECLSPEC_HIDDEN;
struct wined3d_resource struct wined3d_resource
{ {
LONG ref; LONG ref;
...@@ -1935,19 +1938,19 @@ struct wined3d_resource ...@@ -1935,19 +1938,19 @@ struct wined3d_resource
enum wined3d_resource_type type; enum wined3d_resource_type type;
const struct wined3d_format *format; const struct wined3d_format *format;
enum wined3d_multisample_type multisample_type; enum wined3d_multisample_type multisample_type;
UINT multisample_quality; UINT multisample_quality;
DWORD usage; DWORD usage;
enum wined3d_pool pool; enum wined3d_pool pool;
DWORD access_flags; DWORD access_flags;
UINT width; UINT width;
UINT height; UINT height;
UINT depth; UINT depth;
UINT size; UINT size;
DWORD priority; DWORD priority;
BYTE *allocatedMemory; /* Pointer to the real data location */ BYTE *allocatedMemory; /* Pointer to the real data location */
BYTE *heapMemory; /* Pointer to the HeapAlloced block of memory */ void *heap_memory;
struct list privateData; struct list privateData;
struct list resource_list_entry; struct list resource_list_entry;
void *parent; void *parent;
const struct wined3d_parent_ops *parent_ops; const struct wined3d_parent_ops *parent_ops;
......
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