Commit 723cd0a4 authored by Stefan Dösinger's avatar Stefan Dösinger Committed by Alexandre Julliard

wined3d: Make video memory accounting a per-resource flag.

parent d62e2268
......@@ -371,7 +371,7 @@ static inline unsigned int wined3d_usage_from_d3d(D3DPOOL pool, DWORD usage)
usage |= WINED3DUSAGE_SCRATCH;
else if (pool == D3DPOOL_MANAGED)
usage |= WINED3DUSAGE_MANAGED;
return usage;
return usage | WINED3DUSAGE_VIDMEM_ACCOUNTING;
}
static inline unsigned int wined3d_bind_flags_from_d3d8_usage(DWORD usage)
......
......@@ -473,10 +473,10 @@ static const struct IDirect3D8Vtbl d3d8_vtbl =
BOOL d3d8_init(struct d3d8 *d3d8)
{
DWORD flags = WINED3D_LEGACY_DEPTH_BIAS | WINED3D_VIDMEM_ACCOUNTING
| WINED3D_HANDLE_RESTORE | WINED3D_PIXEL_CENTER_INTEGER
| WINED3D_LEGACY_UNBOUND_RESOURCE_COLOR | WINED3D_NO_PRIMITIVE_RESTART
| WINED3D_LEGACY_CUBEMAP_FILTERING | WINED3D_NO_DRAW_INDIRECT;
DWORD flags = WINED3D_LEGACY_DEPTH_BIAS | WINED3D_HANDLE_RESTORE
| WINED3D_PIXEL_CENTER_INTEGER | WINED3D_LEGACY_UNBOUND_RESOURCE_COLOR
| WINED3D_NO_PRIMITIVE_RESTART | WINED3D_LEGACY_CUBEMAP_FILTERING
| WINED3D_NO_DRAW_INDIRECT;
unsigned int adapter_idx, output_idx, adapter_count, output_count = 0;
struct wined3d_adapter *wined3d_adapter;
......
......@@ -312,6 +312,9 @@ HRESULT vertexbuffer_init(struct d3d9_vertexbuffer *buffer, struct d3d9_device *
desc.misc_flags = 0;
desc.structure_byte_stride = 0;
if (!device->d3d_parent->extended)
desc.usage |= WINED3DUSAGE_VIDMEM_ACCOUNTING;
if (desc.access & WINED3D_RESOURCE_ACCESS_GPU)
{
desc.bind_flags = WINED3D_BIND_VERTEX_BUFFER;
......@@ -620,6 +623,9 @@ HRESULT indexbuffer_init(struct d3d9_indexbuffer *buffer, struct d3d9_device *de
desc.misc_flags = 0;
desc.structure_byte_stride = 0;
if (!device->d3d_parent->extended)
desc.usage |= WINED3DUSAGE_VIDMEM_ACCOUNTING;
if (desc.access & WINED3D_RESOURCE_ACCESS_GPU)
desc.bind_flags = WINED3D_BIND_INDEX_BUFFER;
......
......@@ -1986,6 +1986,9 @@ static HRESULT WINAPI d3d9_device_CreateOffscreenPlainSurface(IDirect3DDevice9Ex
access = wined3daccess_from_d3dpool(pool, 0)
| WINED3D_RESOURCE_ACCESS_MAP_R | WINED3D_RESOURCE_ACCESS_MAP_W;
if (!device->d3d_parent->extended)
usage |= WINED3DUSAGE_VIDMEM_ACCOUNTING;
return d3d9_device_create_surface(device, 0, wined3dformat_from_d3dformat(format),
WINED3D_MULTISAMPLE_NONE, 0, usage, 0, access, width, height, user_mem, surface);
}
......
......@@ -689,9 +689,7 @@ BOOL d3d9_init(struct d3d9 *d3d9, BOOL extended)
unsigned int adapter_idx, output_idx, adapter_count, output_count = 0;
struct wined3d_adapter *wined3d_adapter;
if (!extended)
flags |= WINED3D_VIDMEM_ACCOUNTING;
else
if (extended)
flags |= WINED3D_RESTORE_MODE_ON_ACTIVATE;
d3d9->IDirect3D9Ex_iface.lpVtbl = &d3d9_vtbl;
......
......@@ -1409,6 +1409,9 @@ HRESULT d3d9_texture_2d_init(struct d3d9_texture *texture, struct d3d9_device *d
desc.depth = 1;
desc.size = 0;
if (!device->d3d_parent->extended)
desc.usage |= WINED3DUSAGE_VIDMEM_ACCOUNTING;
texture->IDirect3DBaseTexture9_iface.lpVtbl = (const IDirect3DBaseTexture9Vtbl *)&d3d9_texture_2d_vtbl;
return d3d9_texture_init(texture, device, &desc, pool, usage, 1, level_count);
}
......@@ -1430,6 +1433,9 @@ HRESULT d3d9_texture_cube_init(struct d3d9_texture *texture, struct d3d9_device
desc.depth = 1;
desc.size = 0;
if (!device->d3d_parent->extended)
desc.usage |= WINED3DUSAGE_VIDMEM_ACCOUNTING;
texture->IDirect3DBaseTexture9_iface.lpVtbl = (const IDirect3DBaseTexture9Vtbl *)&d3d9_texture_cube_vtbl;
return d3d9_texture_init(texture, device, &desc, pool, usage, 6, level_count);
}
......@@ -1455,6 +1461,9 @@ HRESULT d3d9_texture_3d_init(struct d3d9_texture *texture, struct d3d9_device *d
desc.depth = depth;
desc.size = 0;
if (!device->d3d_parent->extended)
desc.usage |= WINED3DUSAGE_VIDMEM_ACCOUNTING;
texture->IDirect3DBaseTexture9_iface.lpVtbl = (const IDirect3DBaseTexture9Vtbl *)&d3d9_texture_3d_vtbl;
return d3d9_texture_init(texture, device, &desc, pool, usage, 1, level_count);
}
......@@ -63,10 +63,9 @@ struct FvfToDecl
#define DDRAW_STRIDE_ALIGNMENT 8
#define DDRAW_WINED3D_FLAGS (WINED3D_LEGACY_DEPTH_BIAS | WINED3D_VIDMEM_ACCOUNTING \
| WINED3D_RESTORE_MODE_ON_ACTIVATE | WINED3D_FOCUS_MESSAGES | WINED3D_PIXEL_CENTER_INTEGER \
| WINED3D_LEGACY_UNBOUND_RESOURCE_COLOR | WINED3D_NO_PRIMITIVE_RESTART \
| WINED3D_LEGACY_CUBEMAP_FILTERING | WINED3D_NO_DRAW_INDIRECT)
#define DDRAW_WINED3D_FLAGS (WINED3D_LEGACY_DEPTH_BIAS | WINED3D_RESTORE_MODE_ON_ACTIVATE \
| WINED3D_FOCUS_MESSAGES | WINED3D_PIXEL_CENTER_INTEGER | WINED3D_LEGACY_UNBOUND_RESOURCE_COLOR \
| WINED3D_NO_PRIMITIVE_RESTART | WINED3D_LEGACY_CUBEMAP_FILTERING | WINED3D_NO_DRAW_INDIRECT)
#define DDRAW_MAX_ACTIVE_LIGHTS 32
#define DDRAW_MAX_TEXTURES 8
......
......@@ -6031,7 +6031,7 @@ static void wined3d_resource_desc_from_ddraw(struct ddraw *ddraw,
wined3d_desc->format = wined3dformat_from_ddrawformat(&desc->u4.ddpfPixelFormat);
wined3d_desc->multisample_type = WINED3D_MULTISAMPLE_NONE;
wined3d_desc->multisample_quality = 0;
wined3d_desc->usage = 0;
wined3d_desc->usage = WINED3DUSAGE_VIDMEM_ACCOUNTING;
wined3d_desc->bind_flags = 0;
wined3d_desc->access = WINED3D_RESOURCE_ACCESS_GPU | WINED3D_RESOURCE_ACCESS_MAP_R | WINED3D_RESOURCE_ACCESS_MAP_W;
wined3d_desc->width = desc->dwWidth;
......@@ -6158,7 +6158,7 @@ static HRESULT ddraw_texture_init(struct ddraw_texture *texture, struct ddraw *d
draw_texture_desc = wined3d_desc;
draw_texture_desc.bind_flags = bind_flags;
draw_texture_desc.access = WINED3D_RESOURCE_ACCESS_GPU;
draw_texture_desc.usage = WINED3DUSAGE_PRIVATE;
draw_texture_desc.usage = 0;
if (FAILED(hr = wined3d_texture_create(wined3d_device, &draw_texture_desc, layers,
levels, 0, NULL, texture, &ddraw_texture_wined3d_parent_ops, &draw_texture)))
......
......@@ -111,7 +111,7 @@ static HRESULT d3d_vertex_buffer_create_wined3d_buffer(struct d3d_vertex_buffer
struct wined3d_buffer_desc desc;
desc.byte_width = buffer->size;
desc.usage = WINED3DUSAGE_STATICDECL;
desc.usage = WINED3DUSAGE_STATICDECL | WINED3DUSAGE_VIDMEM_ACCOUNTING;
if (dynamic)
desc.usage |= WINED3DUSAGE_DYNAMIC;
desc.bind_flags = WINED3D_BIND_VERTEX_BUFFER;
......
......@@ -210,21 +210,19 @@ HRESULT resource_init(struct wined3d_resource *resource, struct wined3d_device *
resource->map_binding = WINED3D_LOCATION_SYSMEM;
resource->heap_memory = NULL;
if (!(usage & WINED3DUSAGE_PRIVATE))
/* Check that we have enough video ram left */
if (!(access & WINED3D_RESOURCE_ACCESS_CPU) && usage & WINED3DUSAGE_VIDMEM_ACCOUNTING)
{
/* Check that we have enough video ram left */
if (!(access & WINED3D_RESOURCE_ACCESS_CPU) && device->wined3d->flags & WINED3D_VIDMEM_ACCOUNTING)
if (size > wined3d_device_get_available_texture_mem(device))
{
if (size > wined3d_device_get_available_texture_mem(device))
{
ERR("Out of adapter memory.\n");
return WINED3DERR_OUTOFVIDEOMEMORY;
}
adapter_adjust_memory(device->adapter, size);
ERR("Out of adapter memory.\n");
return WINED3DERR_OUTOFVIDEOMEMORY;
}
adapter_adjust_memory(device->adapter, size);
}
if (!(usage & WINED3DUSAGE_PRIVATE))
device_resource_add(device, resource);
}
return WINED3D_OK;
}
......@@ -241,20 +239,17 @@ static void wined3d_resource_destroy_object(void *object)
void resource_cleanup(struct wined3d_resource *resource)
{
const struct wined3d *d3d = resource->device->wined3d;
TRACE("Cleaning up resource %p.\n", resource);
if (!(resource->usage & WINED3DUSAGE_PRIVATE))
if (!(resource->access & WINED3D_RESOURCE_ACCESS_CPU) && resource->usage & WINED3DUSAGE_VIDMEM_ACCOUNTING)
{
if (!(resource->access & WINED3D_RESOURCE_ACCESS_CPU) && d3d->flags & WINED3D_VIDMEM_ACCOUNTING)
{
TRACE("Decrementing device memory pool by %u.\n", resource->size);
adapter_adjust_memory(resource->device->adapter, (INT64)0 - resource->size);
}
TRACE("Decrementing device memory pool by %u.\n", resource->size);
adapter_adjust_memory(resource->device->adapter, (INT64)0 - resource->size);
}
if (!(resource->usage & WINED3DUSAGE_PRIVATE))
device_resource_released(resource->device, resource);
}
wined3d_resource_reference(resource);
wined3d_cs_destroy_object(resource->device->cs, wined3d_resource_destroy_object, resource);
}
......
......@@ -1899,7 +1899,6 @@ HRESULT CDECL wined3d_texture_update_desc(struct wined3d_texture *texture, unsig
const struct wined3d_format *format;
struct wined3d_device *device;
unsigned int resource_size;
const struct wined3d *d3d;
unsigned int slice_pitch;
bool update_memory_only;
bool create_dib = false;
......@@ -1910,7 +1909,6 @@ HRESULT CDECL wined3d_texture_update_desc(struct wined3d_texture *texture, unsig
sub_resource_idx);
device = texture->resource.device;
d3d = device->wined3d;
gl_info = &device->adapter->gl_info;
d3d_info = &device->adapter->d3d_info;
format = wined3d_get_format(device->adapter, format_id, texture->resource.bind_flags);
......@@ -2008,7 +2006,8 @@ HRESULT CDECL wined3d_texture_update_desc(struct wined3d_texture *texture, unsig
texture->resource.multisample_quality = multisample_quality;
texture->resource.width = width;
texture->resource.height = height;
if (!(texture->resource.access & WINED3D_RESOURCE_ACCESS_CPU) && d3d->flags & WINED3D_VIDMEM_ACCOUNTING)
if (!(texture->resource.access & WINED3D_RESOURCE_ACCESS_CPU)
&& texture->resource.usage & WINED3DUSAGE_VIDMEM_ACCOUNTING)
adapter_adjust_memory(device->adapter, (INT64)texture->slice_pitch - texture->resource.size);
texture->resource.size = texture->slice_pitch;
sub_resource->size = texture->slice_pitch;
......
......@@ -4952,6 +4952,7 @@ const char *debug_d3dusage(uint32_t usage)
WINED3DUSAGE_TO_STR(WINED3DUSAGE_STATICDECL);
WINED3DUSAGE_TO_STR(WINED3DUSAGE_OVERLAY);
WINED3DUSAGE_TO_STR(WINED3DUSAGE_MANAGED);
WINED3DUSAGE_TO_STR(WINED3DUSAGE_VIDMEM_ACCOUNTING);
WINED3DUSAGE_TO_STR(WINED3DUSAGE_QUERY_FILTER);
WINED3DUSAGE_TO_STR(WINED3DUSAGE_QUERY_GENMIPMAP);
WINED3DUSAGE_TO_STR(WINED3DUSAGE_QUERY_LEGACYBUMPMAP);
......
......@@ -927,6 +927,7 @@ enum wined3d_memory_segment_group
#define WINED3DUSAGE_STATICDECL 0x04000000
#define WINED3DUSAGE_OVERLAY 0x08000000
#define WINED3DUSAGE_MANAGED 0x20000000
#define WINED3DUSAGE_VIDMEM_ACCOUNTING 0x40000000
#define WINED3DUSAGE_QUERY_GENMIPMAP 0x00000400
#define WINED3DUSAGE_QUERY_LEGACYBUMPMAP 0x00008000
......@@ -1311,7 +1312,6 @@ enum wined3d_memory_segment_group
#define WINED3D_LEGACY_DEPTH_BIAS 0x00000001
#define WINED3D_NO3D 0x00000002
#define WINED3D_VIDMEM_ACCOUNTING 0x00000004
#define WINED3D_PRESENT_CONVERSION 0x00000008
#define WINED3D_RESTORE_MODE_ON_ACTIVATE 0x00000010
#define WINED3D_FOCUS_MESSAGES 0x00000020
......
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