st/nine: Implement EvictManagedResources
authorAxel Davy <axel.davy@ens.fr>
Fri, 8 May 2015 14:54:53 +0000 (16:54 +0200)
committerAxel Davy <axel.davy@ens.fr>
Fri, 21 Aug 2015 20:21:46 +0000 (22:21 +0200)
EvictManagedResources is used by apps to free
the gpu memory of MANAGED textures (which have
a cpu memory backing)

Signed-off-by: Axel Davy <axel.davy@ens.fr>
src/gallium/state_trackers/nine/basetexture9.c
src/gallium/state_trackers/nine/basetexture9.h
src/gallium/state_trackers/nine/device9.c

index c38a31010a109ab48c30d1bd9fb2f5c6f75c6072..110df79769e75501fea1dabc449477b3d4065a72 100644 (file)
@@ -587,6 +587,21 @@ NineBaseTexture9_PreLoad( struct NineBaseTexture9 *This )
         NineBaseTexture9_UploadSelf(This);
 }
 
+void
+NineBaseTexture9_UnLoad( struct NineBaseTexture9 *This )
+{
+    if (This->base.pool != D3DPOOL_MANAGED ||
+        This->managed.lod_resident == -1)
+        return;
+
+    pipe_resource_reference(&This->base.resource, NULL);
+    This->managed.lod_resident = -1;
+    This->managed.dirty = TRUE;
+
+    /* If the texture is bound, we have to re-upload it */
+    BASETEX_REGISTER_UPDATE(This);
+}
+
 #ifdef DEBUG
 void
 NineBaseTexture9_Dump( struct NineBaseTexture9 *This )
index 9489824299fd71446fa6993675428f01e49ab3ae..b19a62195fc979ce87352939fa214b3d86fdfe78 100644 (file)
@@ -95,6 +95,9 @@ NineBaseTexture9_GenerateMipSubLevels( struct NineBaseTexture9 *This );
 void WINAPI
 NineBaseTexture9_PreLoad( struct NineBaseTexture9 *This );
 
+void
+NineBaseTexture9_UnLoad( struct NineBaseTexture9 *This );
+
 /* For D3DPOOL_MANAGED only (after SetLOD change): */
 HRESULT
 NineBaseTexture9_CreatePipeResource( struct NineBaseTexture9 *This,
index 34199ca9ef2fe823991e81aaa3a3b0131893d054..2ac49a13a8820d7288bc82b8faf3a878f1acbac2 100644 (file)
@@ -548,10 +548,14 @@ NineDevice9_GetAvailableTextureMem( struct NineDevice9 *This )
 HRESULT WINAPI
 NineDevice9_EvictManagedResources( struct NineDevice9 *This )
 {
-    /* We don't really need to do anything here, but might want to free up
-     * the GPU virtual address space by killing pipe_resources.
-     */
-    STUB(D3D_OK);
+    struct NineBaseTexture9 *tex;
+
+    DBG("This=%p\n", This);
+    LIST_FOR_EACH_ENTRY(tex, &This->managed_textures, list2) {
+        NineBaseTexture9_UnLoad(tex);
+    }
+
+    return D3D_OK;
 }
 
 HRESULT WINAPI