From: Józef Kucia jkucia@codeweavers.com
Avoids allocating system memory for depth/stencil and 3D textures.
Signed-off-by: Józef Kucia jkucia@codeweavers.com ---
It's a small step to reduce unncessary system memory allocations in wined3d. We shouldn't need to allocate system memory to initialize content for GPU resources, instead we should use glClearBuffer() and glClearTexImage().
--- dlls/wined3d/buffer.c | 6 +++--- dlls/wined3d/resource.c | 13 +++++-------- dlls/wined3d/texture.c | 17 ++++++++++------- 3 files changed, 18 insertions(+), 18 deletions(-)
diff --git a/dlls/wined3d/buffer.c b/dlls/wined3d/buffer.c index 5b924704dfff..3f4552f2bbe5 100644 --- a/dlls/wined3d/buffer.c +++ b/dlls/wined3d/buffer.c @@ -615,10 +615,7 @@ static BOOL wined3d_buffer_prepare_location(struct wined3d_buffer *buffer, return TRUE;
if (!wined3d_resource_allocate_sysmem(&buffer->resource)) - { - ERR("Failed to allocate system memory.\n"); return FALSE; - } return TRUE;
case WINED3D_LOCATION_BUFFER: @@ -1359,6 +1356,9 @@ static HRESULT buffer_init(struct wined3d_buffer *buffer, struct wined3d_device buffer->bind_flags = bind_flags; buffer->locations = WINED3D_LOCATION_SYSMEM;
+ if (!wined3d_resource_allocate_sysmem(&buffer->resource)) + return E_OUTOFMEMORY; + TRACE("buffer %p, size %#x, usage %#x, format %s, memory @ %p.\n", buffer, buffer->resource.size, buffer->resource.usage, debug_d3dformat(buffer->resource.format->id), buffer->resource.heap_memory); diff --git a/dlls/wined3d/resource.c b/dlls/wined3d/resource.c index 2a6fa6ad7ec2..b5dcdf012db7 100644 --- a/dlls/wined3d/resource.c +++ b/dlls/wined3d/resource.c @@ -191,12 +191,7 @@ HRESULT resource_init(struct wined3d_resource *resource, struct wined3d_device * resource->parent_ops = parent_ops; resource->resource_ops = resource_ops; resource->map_binding = WINED3D_LOCATION_SYSMEM; - - if (!wined3d_resource_allocate_sysmem(resource)) - { - ERR("Failed to allocate system memory.\n"); - return E_OUTOFMEMORY; - } + resource->heap_memory = NULL;
if (!(usage & WINED3DUSAGE_PRIVATE)) { @@ -205,8 +200,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"); - wined3d_resource_free_sysmem(resource); + ERR("Out of adapter memory.\n"); return WINED3DERR_OUTOFVIDEOMEMORY; } adapter_adjust_memory(device->adapter, size); @@ -383,7 +377,10 @@ BOOL wined3d_resource_allocate_sysmem(struct wined3d_resource *resource) void *mem;
if (!(mem = heap_alloc_zero(resource->size + align))) + { + ERR("Failed to allocate system memory.\n"); return FALSE; + }
p = (void **)(((ULONG_PTR)mem + align) & ~(RESOURCE_ALIGNMENT - 1)) - 1; *p = mem; diff --git a/dlls/wined3d/texture.c b/dlls/wined3d/texture.c index b56e6e4e65e2..b9b304eb9ecd 100644 --- a/dlls/wined3d/texture.c +++ b/dlls/wined3d/texture.c @@ -1683,10 +1683,7 @@ BOOL wined3d_texture_prepare_location(struct wined3d_texture *texture, unsigned return TRUE;
if (!wined3d_resource_allocate_sysmem(&texture->resource)) - { - ERR("Failed to allocate system memory.\n"); return FALSE; - } return TRUE;
case WINED3D_LOCATION_USER_MEMORY: @@ -2674,11 +2671,17 @@ static HRESULT wined3d_texture_init(struct wined3d_texture *texture, const struc TRACE("x scale %.8e, y scale %.8e.\n", texture->pow2_matrix[0], texture->pow2_matrix[5]);
if (wined3d_texture_use_pbo(texture, gl_info)) - { - if (desc->resource_type == WINED3D_RTYPE_TEXTURE_3D - || (texture->resource.usage & WINED3DUSAGE_DEPTHSTENCIL)) - wined3d_resource_free_sysmem(&texture->resource); texture->resource.map_binding = WINED3D_LOCATION_BUFFER; + + if ((desc->resource_type != WINED3D_RTYPE_TEXTURE_3D + && !(texture->resource.usage & WINED3DUSAGE_DEPTHSTENCIL)) + || !wined3d_texture_use_pbo(texture, gl_info)) + { + if (!wined3d_resource_allocate_sysmem(&texture->resource)) + { + wined3d_texture_cleanup_sync(texture); + return E_OUTOFMEMORY; + } }
sub_count = level_count * layer_count;