[PATCH] d3d: d3d9ex does not do video memory accounting for D3DPOOL_DEFAULT resources (try 2)

Stefan Dösinger stefan at codeweavers.com
Sun May 19 16:13:30 CDT 2013


try 2: Use a wined3d flag rather than a device flag, invert the meaning
of the flag.

I'm not resubmitting the test because of its potential unreliability on
Windows if other applications create or release video memory resources.
If this is not a concern, patch 96256 should still apply and pass make
test after this patch.

For the record, a IDirect3DDevice9 (non-ex) created via
IDirect3D9Ex::CreateDevice behaves just like an extended device created
by IDirect3D9Ex::CreateDeviceEx.
---
 dlls/d3d8/directx.c     | 4 +++-
 dlls/d3d9/directx.c     | 3 ++-
 dlls/ddraw/ddraw.c      | 2 +-
 dlls/wined3d/resource.c | 7 +++++--
 include/wine/wined3d.h  | 1 +
 5 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/dlls/d3d8/directx.c b/dlls/d3d8/directx.c
index 61d187d..4aac722 100644
--- a/dlls/d3d8/directx.c
+++ b/dlls/d3d8/directx.c
@@ -404,11 +404,13 @@ static const struct IDirect3D8Vtbl d3d8_vtbl =
 
 BOOL d3d8_init(struct d3d8 *d3d8)
 {
+    DWORD flags = WINED3D_LEGACY_DEPTH_BIAS | WINED3D_VIDMEM_ACCOUNTING;
+
     d3d8->IDirect3D8_iface.lpVtbl = &d3d8_vtbl;
     d3d8->refcount = 1;
 
     wined3d_mutex_lock();
-    d3d8->wined3d = wined3d_create(8, WINED3D_LEGACY_DEPTH_BIAS);
+    d3d8->wined3d = wined3d_create(8, flags);
     wined3d_mutex_unlock();
     if (!d3d8->wined3d)
         return FALSE;
diff --git a/dlls/d3d9/directx.c b/dlls/d3d9/directx.c
index a335375..537e6af 100644
--- a/dlls/d3d9/directx.c
+++ b/dlls/d3d9/directx.c
@@ -632,11 +632,12 @@ static const struct IDirect3D9ExVtbl d3d9_vtbl =
 
 BOOL d3d9_init(struct d3d9 *d3d9, BOOL extended)
 {
+    DWORD flags = extended ? 0 : WINED3D_VIDMEM_ACCOUNTING;
     d3d9->IDirect3D9Ex_iface.lpVtbl = &d3d9_vtbl;
     d3d9->refcount = 1;
 
     wined3d_mutex_lock();
-    d3d9->wined3d = wined3d_create(9, 0);
+    d3d9->wined3d = wined3d_create(9, flags);
     wined3d_mutex_unlock();
     if (!d3d9->wined3d)
         return FALSE;
diff --git a/dlls/ddraw/ddraw.c b/dlls/ddraw/ddraw.c
index a459e5f..b2b637e 100644
--- a/dlls/ddraw/ddraw.c
+++ b/dlls/ddraw/ddraw.c
@@ -5234,7 +5234,7 @@ HRESULT ddraw_init(struct ddraw *ddraw, enum wined3d_device_type device_type)
     ddraw->numIfaces = 1;
     ddraw->ref7 = 1;
 
-    flags = WINED3D_LEGACY_DEPTH_BIAS;
+    flags = WINED3D_LEGACY_DEPTH_BIAS | WINED3D_VIDMEM_ACCOUNTING;
     if (DefaultSurfaceType != DDRAW_SURFACE_TYPE_OPENGL)
         flags |= WINED3D_NO3D;
 
diff --git a/dlls/wined3d/resource.c b/dlls/wined3d/resource.c
index d784622..0e0678d 100644
--- a/dlls/wined3d/resource.c
+++ b/dlls/wined3d/resource.c
@@ -84,6 +84,8 @@ HRESULT resource_init(struct wined3d_resource *resource, struct wined3d_device *
         void *parent, const struct wined3d_parent_ops *parent_ops,
         const struct wined3d_resource_ops *resource_ops)
 {
+    const struct wined3d *d3d = device->wined3d;
+
     resource->ref = 1;
     resource->device = device;
     resource->type = type;
@@ -124,7 +126,7 @@ HRESULT resource_init(struct wined3d_resource *resource, struct wined3d_device *
             + (RESOURCE_ALIGNMENT - 1)) & ~(RESOURCE_ALIGNMENT - 1));
 
     /* Check that we have enough video ram left */
-    if (pool == WINED3D_POOL_DEFAULT)
+    if (pool == WINED3D_POOL_DEFAULT && d3d->flags & WINED3D_VIDMEM_ACCOUNTING)
     {
         if (size > wined3d_device_get_available_texture_mem(device))
         {
@@ -142,13 +144,14 @@ HRESULT resource_init(struct wined3d_resource *resource, struct wined3d_device *
 
 void resource_cleanup(struct wined3d_resource *resource)
 {
+    const struct wined3d *d3d = resource->device->wined3d;
     struct private_data *data;
     struct list *e1, *e2;
     HRESULT hr;
 
     TRACE("Cleaning up resource %p.\n", resource);
 
-    if (resource->pool == WINED3D_POOL_DEFAULT)
+    if (resource->pool == WINED3D_POOL_DEFAULT && d3d->flags & WINED3D_VIDMEM_ACCOUNTING)
     {
         TRACE("Decrementing device memory pool by %u.\n", resource->size);
         adapter_adjust_memory(resource->device->adapter, 0 - resource->size);
diff --git a/include/wine/wined3d.h b/include/wine/wined3d.h
index 75cba55..27575bb 100644
--- a/include/wine/wined3d.h
+++ b/include/wine/wined3d.h
@@ -1216,6 +1216,7 @@ enum wined3d_display_rotation
 
 #define WINED3D_LEGACY_DEPTH_BIAS                               0x00000001
 #define WINED3D_NO3D                                            0x00000002
+#define WINED3D_VIDMEM_ACCOUNTING                               0x00000004
 
 #define WINED3D_RESZ_CODE                                       0x7fa05000
 
-- 
1.8.1.5




More information about the wine-patches mailing list