From 243ac3ed75e3ee2ac570dba6f72398320327ab5a Mon Sep 17 00:00:00 2001 From: Roderick Colenbrander Date: Sun, 23 Sep 2007 00:46:21 +0200 Subject: [PATCH] wined3d: Move video memory tracking to the adapter. --- dlls/wined3d/device.c | 21 +++++---------------- dlls/wined3d/directx.c | 31 +++++++++++++++++++++---------- dlls/wined3d/resource.c | 2 +- dlls/wined3d/wined3d_main.c | 20 -------------------- dlls/wined3d/wined3d_private.h | 20 +++----------------- include/wine/wined3d_gl.h | 1 + 6 files changed, 31 insertions(+), 64 deletions(-) diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c index b93bb335154..9cf8ab191dd 100644 --- a/dlls/wined3d/device.c +++ b/dlls/wined3d/device.c @@ -99,7 +99,7 @@ static void WINAPI IWineD3DDeviceImpl_AddResource(IWineD3DDevice *iface, IWineD3 *pp##type = NULL; \ return WINED3DERR_OUTOFVIDEOMEMORY; \ } \ - globalChangeGlRam(_size); \ + WineD3DAdapterChangeGLRam(This, _size); \ } \ object->resource.allocatedMemory = (0 == _size ? NULL : Pool == WINED3DPOOL_DEFAULT ? NULL : HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, _size)); \ if (object->resource.allocatedMemory == NULL && _size != 0 && Pool != WINED3DPOOL_DEFAULT) { \ @@ -2295,24 +2295,13 @@ static HRESULT WINAPI IWineD3DDeviceImpl_GetDirect3D(IWineD3DDevice *iface, IWin } static UINT WINAPI IWineD3DDeviceImpl_GetAvailableTextureMem(IWineD3DDevice *iface) { - /** NOTE: There's a probably a hack-around for this one by putting as many pbuffers, VBOs (or whatever) - * into the video ram as possible and seeing how many fit - * you can also get the correct initial value from nvidia and ATI's driver via X - * texture memory is video memory + AGP memory - *******************/ IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface; - static BOOL showfixmes = TRUE; - if (showfixmes) { - FIXME("(%p) : stub, simulating %dMB for now, returning %dMB left\n", This, - (wined3d_settings.emulated_textureram/(1024*1024)), - ((wined3d_settings.emulated_textureram - wineD3DGlobalStatistics->glsurfaceram) / (1024*1024))); - showfixmes = FALSE; - } + TRACE("(%p) : simulating %dMB, returning %dMB left\n", This, - (wined3d_settings.emulated_textureram/(1024*1024)), - ((wined3d_settings.emulated_textureram - wineD3DGlobalStatistics->glsurfaceram) / (1024*1024))); + (This->adapter->TextureRam/(1024*1024)), + ((This->adapter->TextureRam - This->adapter->UsedTextureRam) / (1024*1024))); /* return simulated texture memory left */ - return (wined3d_settings.emulated_textureram - wineD3DGlobalStatistics->glsurfaceram); + return (This->adapter->TextureRam - This->adapter->UsedTextureRam); } diff --git a/dlls/wined3d/directx.c b/dlls/wined3d/directx.c index 747caae37c1..ce72d88d693 100644 --- a/dlls/wined3d/directx.c +++ b/dlls/wined3d/directx.c @@ -277,6 +277,14 @@ static BOOL WineD3D_CreateFakeGLContext(void) { return FALSE; } +/* Adjust the amount of used texture memory */ +long WineD3DAdapterChangeGLRam(IWineD3DDeviceImpl *D3DDevice, long glram){ + UINT Adapter = D3DDevice->adapterNo; + + Adapters[Adapter].UsedTextureRam += glram; + TRACE("Adjusted gl ram by %ld to %d\n", glram, Adapters[Adapter].UsedTextureRam); + return Adapters[Adapter].UsedTextureRam; +} /********************************************************** * IUnknown parts follows @@ -1034,16 +1042,11 @@ BOOL IWineD3DImpl_FillGLCaps(WineD3D_GL_Info *gl_info) { } TRACE("FOUND (fake) card: 0x%x (vendor id), 0x%x (device id)\n", gl_info->gl_vendor, gl_info->gl_card); - /* Unless VideoMemorySize is set in the registry, the default is 0 - * TODO: put emulated_textureram in the device */ - if(wined3d_settings.emulated_textureram == 0) { - /* If we have an estimate use it, else default to 64MB */ - if(vidmem) - wined3d_settings.emulated_textureram = vidmem*1024*1024; /* convert from MBs to bytes */ - else - wined3d_settings.emulated_textureram = WINE_DEFAULT_VIDMEM; - TRACE("Emulating %d MB of texture memory\n", wined3d_settings.emulated_textureram); - } + /* If we have an estimate use it, else default to 64MB; */ + if(vidmem) + gl_info->vidmem = vidmem*1024*1024; /* convert from MBs to bytes */ + else + gl_info->vidmem = WINE_DEFAULT_VIDMEM; /* Load all the lookup tables TODO: It may be a good idea to make minLookup and maxLookup const and populate them in wined3d_private.h where they are declared */ @@ -2743,6 +2746,14 @@ BOOL InitAdapters(void) { Adapters[0].driver = "Display"; Adapters[0].description = "Direct3D HAL"; + /* Use the VideoRamSize registry setting when set */ + if(wined3d_settings.emulated_textureram) + Adapters[0].TextureRam = wined3d_settings.emulated_textureram; + else + Adapters[0].TextureRam = Adapters[0].gl_info.vidmem; + Adapters[0].UsedTextureRam = 0; + TRACE("Emulating %dMB of texture ram\n", Adapters[0].TextureRam); + /* Initialize the Adapter's DeviceName which is required for ChangeDisplaySettings and friends */ DisplayDevice.cb = sizeof(DisplayDevice); EnumDisplayDevicesW(NULL, 0 /* Adapter 0 = iDevNum 0 */, &DisplayDevice, 0); diff --git a/dlls/wined3d/resource.c b/dlls/wined3d/resource.c index 6999f060c05..a75bcbd46ca 100644 --- a/dlls/wined3d/resource.c +++ b/dlls/wined3d/resource.c @@ -71,7 +71,7 @@ void IWineD3DResourceImpl_CleanUp(IWineD3DResource *iface){ TRACE("(%p) Cleaning up resource\n", This); if (This->resource.pool == WINED3DPOOL_DEFAULT) { TRACE("Decrementing device memory pool by %u\n", This->resource.size); - globalChangeGlRam(-This->resource.size); + WineD3DAdapterChangeGLRam(This->resource.wineD3DDevice, -This->resource.size); } LIST_FOR_EACH_SAFE(e1, e2, &This->resource.privateData) { diff --git a/dlls/wined3d/wined3d_main.c b/dlls/wined3d/wined3d_main.c index 5886df5a60d..ebe09bd2605 100644 --- a/dlls/wined3d/wined3d_main.c +++ b/dlls/wined3d/wined3d_main.c @@ -46,19 +46,6 @@ wined3d_settings_t wined3d_settings = NULL /* No wine logo by default */ }; -WineD3DGlobalStatistics *wineD3DGlobalStatistics = NULL; - -long globalChangeGlRam(long glram){ - /* FIXME: replace this function with object tracking */ - int result; - - wineD3DGlobalStatistics->glsurfaceram += glram; - TRACE("Adjusted gl ram by %ld to %d\n", glram, wineD3DGlobalStatistics->glsurfaceram); - result = wineD3DGlobalStatistics->glsurfaceram; - return result; - -} - IWineD3D* WINAPI WineDirect3DCreate(UINT SDKVersion, UINT dxVersion, IUnknown *parent) { IWineD3DImpl* object; @@ -76,13 +63,6 @@ IWineD3D* WINAPI WineDirect3DCreate(UINT SDKVersion, UINT dxVersion, IUnknown *p object->ref = 1; object->parent = parent; - /*Create a structure for storing global data in*/ - if(wineD3DGlobalStatistics == NULL){ - TRACE("Creating global statistics store\n"); - wineD3DGlobalStatistics = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*wineD3DGlobalStatistics)); - - } - TRACE("Created WineD3D object @ %p for d3d%d support\n", object, dxVersion); return (IWineD3D *)object; diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h index 286a61afbee..67edc0a3000 100644 --- a/dlls/wined3d/wined3d_private.h +++ b/dlls/wined3d/wined3d_private.h @@ -326,23 +326,6 @@ typedef struct IWineD3DSurfaceImpl IWineD3DSurfaceImpl; typedef struct IWineD3DPaletteImpl IWineD3DPaletteImpl; typedef struct IWineD3DDeviceImpl IWineD3DDeviceImpl; -/* Tracking */ - -/* TODO: Move some of this to the device */ -long globalChangeGlRam(long glram); - -/* Memory and object tracking */ - -/*Structure for holding information on all direct3d objects -useful for making sure tracking is ok and when release is called on a device! -and probably quite handy for debugging and dumping states out -*/ -typedef struct WineD3DGlobalStatistics { - int glsurfaceram; /* The aproximate amount of glTexture memory allocated for textures */ -} WineD3DGlobalStatistics; - -extern WineD3DGlobalStatistics* wineD3DGlobalStatistics; - /* Global variables */ extern const float identity[16]; @@ -597,10 +580,13 @@ struct WineD3DAdapter WCHAR DeviceName[CCHDEVICENAME]; /* DeviceName for use with e.g. ChangeDisplaySettings */ int nCfgs; WineD3D_PixelFormat *cfgs; + unsigned int TextureRam; /* Amount of texture memory both video ram + AGP/TurboCache/HyperMemory/.. */ + unsigned int UsedTextureRam; }; extern BOOL InitAdapters(void); extern BOOL initPixelFormats(WineD3D_GL_Info *gl_info); +extern long WineD3DAdapterChangeGLRam(IWineD3DDeviceImpl *D3DDevice, long glram); /***************************************************************************** * High order patch management diff --git a/include/wine/wined3d_gl.h b/include/wine/wined3d_gl.h index f2d9dabcea7..3da14ef81b6 100644 --- a/include/wine/wined3d_gl.h +++ b/include/wine/wined3d_gl.h @@ -3702,6 +3702,7 @@ typedef struct _WineD3D_GL_Info { GL_Vendors gl_vendor; GL_Cards gl_card; + UINT vidmem; DWORD gl_driver_version; CHAR gl_renderer[255]; /** -- 2.11.4.GIT