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 @@
* Copyright 2002-2005 Raphael Junqueira
* Copyright 2004 Christian Costa
* 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
*
* 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
}
else
{
HeapFree(GetProcessHeap(), 0, This->resource.heapMemory);
wined3d_resource_free_sysmem(This->resource.heap_memory);
This->resource.allocatedMemory = NULL;
This->resource.heapMemory = NULL;
This->resource.heap_memory = NULL;
}
return;
......@@ -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 */
if(This->resource.allocatedMemory) return This->resource.allocatedMemory;
This->resource.heapMemory = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, This->resource.size + RESOURCE_ALIGNMENT);
This->resource.allocatedMemory = (BYTE *)(((ULONG_PTR)This->resource.heapMemory + (RESOURCE_ALIGNMENT - 1)) & ~(RESOURCE_ALIGNMENT - 1));
This->resource.heap_memory = wined3d_resource_allocate_sysmem(This->resource.size);
This->resource.allocatedMemory = This->resource.heap_memory;
if (This->buffer_type_hint == GL_ELEMENT_ARRAY_BUFFER_ARB)
device_invalidate_state(This->resource.device, STATE_INDEXBUFFER);
......
......@@ -4,6 +4,7 @@
* Copyright 2004 Christian Costa
* Copyright 2005 Oliver Stieber
* 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
* 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 *
if (size)
{
resource->heapMemory = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size + RESOURCE_ALIGNMENT);
if (!resource->heapMemory)
resource->heap_memory = wined3d_resource_allocate_sysmem(size);
if (!resource->heap_memory)
{
ERR("Out of memory!\n");
return WINED3DERR_OUTOFVIDEOMEMORY;
......@@ -120,10 +121,9 @@ HRESULT resource_init(struct wined3d_resource *resource, struct wined3d_device *
}
else
{
resource->heapMemory = NULL;
resource->heap_memory = NULL;
}
resource->allocatedMemory = (BYTE *)(((ULONG_PTR)resource->heapMemory
+ (RESOURCE_ALIGNMENT - 1)) & ~(RESOURCE_ALIGNMENT - 1));
resource->allocatedMemory = resource->heap_memory;
/* Check that we have enough video ram left */
if (pool == WINED3D_POOL_DEFAULT && d3d->flags & WINED3D_VIDMEM_ACCOUNTING)
......@@ -131,7 +131,7 @@ HRESULT resource_init(struct wined3d_resource *resource, struct wined3d_device *
if (size > wined3d_device_get_available_texture_mem(device))
{
ERR("Out of adapter memory\n");
HeapFree(GetProcessHeap(), 0, resource->heapMemory);
wined3d_resource_free_sysmem(resource->heap_memory);
return WINED3DERR_OUTOFVIDEOMEMORY;
}
adapter_adjust_memory(device->adapter, size);
......@@ -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);
}
HeapFree(GetProcessHeap(), 0, resource->heapMemory);
resource->allocatedMemory = 0;
resource->heapMemory = 0;
wined3d_resource_free_sysmem(resource->heap_memory);
resource->allocatedMemory = NULL;
resource->heap_memory = NULL;
device_resource_released(resource->device, resource);
}
......@@ -335,3 +335,28 @@ void CDECL wined3d_resource_get_desc(const struct wined3d_resource *resource, st
desc->depth = resource->depth;
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
front->resource.allocatedMemory = back->resource.allocatedMemory;
back->resource.allocatedMemory = tmp;
if (front->resource.heapMemory)
if (front->resource.heap_memory)
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);
}
......
......@@ -1926,6 +1926,9 @@ struct wined3d_resource_ops
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
{
LONG ref;
......@@ -1935,19 +1938,19 @@ struct wined3d_resource
enum wined3d_resource_type type;
const struct wined3d_format *format;
enum wined3d_multisample_type multisample_type;
UINT multisample_quality;
DWORD usage;
UINT multisample_quality;
DWORD usage;
enum wined3d_pool pool;
DWORD access_flags;
UINT width;
UINT height;
UINT depth;
UINT size;
DWORD priority;
BYTE *allocatedMemory; /* Pointer to the real data location */
BYTE *heapMemory; /* Pointer to the HeapAlloced block of memory */
struct list privateData;
struct list resource_list_entry;
UINT size;
DWORD priority;
BYTE *allocatedMemory; /* Pointer to the real data location */
void *heap_memory;
struct list privateData;
struct list resource_list_entry;
void *parent;
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