From 1bb98b41944dadf69645cf3b99bcabd9834f9240 Mon Sep 17 00:00:00 2001 From: Mitchell Stokes Date: Wed, 17 Nov 2010 05:28:25 +0000 Subject: Adding monitoring for (approximate) VRAM used by textures. The information is currently only used in the profiling data of the BGE. Here is a image of it in action: http://www.pasteall.org/pic/show.php?id=6351 What it monitors: * VRAM used by textures created via bf_gpu and BL_Textures What it does not monitor: * VRAM used by the Blender ui * VRAM used by 2d filters * VRAM allocated by the user via KX_Scene.pre_draw and KX_Scene.pre_draw --- source/gameengine/Ketsji/BL_Texture.cpp | 16 +++++++++++++++- source/gameengine/Ketsji/BL_Texture.h | 1 + source/gameengine/Ketsji/KX_KetsjiEngine.cpp | 14 ++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) (limited to 'source/gameengine/Ketsji') diff --git a/source/gameengine/Ketsji/BL_Texture.cpp b/source/gameengine/Ketsji/BL_Texture.cpp index e708775b184..446ad0c47d5 100644 --- a/source/gameengine/Ketsji/BL_Texture.cpp +++ b/source/gameengine/Ketsji/BL_Texture.cpp @@ -22,6 +22,8 @@ #include "KX_GameObject.h" +#include "GPU_extensions.h" + #define spit(x) std::cout << x << std::endl; #include "MEM_guardedalloc.h" @@ -61,7 +63,8 @@ BL_Texture::BL_Texture() mNeedsDeleted(0), mType(0), mUnit(0), - mEnvState(0) + mEnvState(0), + mTexSize(0) { // -- } @@ -77,6 +80,9 @@ void BL_Texture::DeleteTex() glDeleteTextures(1, (GLuint*)&mTexture); mNeedsDeleted = 0; mOk = 0; + + GPU_texture_vram_subtract(mTexSize); + mTexSize = 0; } if(mEnvState) { @@ -165,11 +171,15 @@ void BL_Texture::InitGLTex(unsigned int *pix,int x,int y,bool mipmap) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); gluBuild2DMipmaps( GL_TEXTURE_2D, GL_RGBA, x, y, GL_RGBA, GL_UNSIGNED_BYTE, pix ); + mTexSize = (x*y*4)+(x*y*4)/3; + GPU_texture_vram_add(mTexSize); } else { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, x, y, 0, GL_RGBA, GL_UNSIGNED_BYTE, pix ); + mTexSize = x*y*4; + GPU_texture_vram_add(mTexSize); } glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); @@ -190,11 +200,15 @@ void BL_Texture::InitNonPow2Tex(unsigned int *pix,int x,int y,bool mipmap) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); gluBuild2DMipmaps( GL_TEXTURE_2D, GL_RGBA, nx, ny, GL_RGBA, GL_UNSIGNED_BYTE, newPixels ); + mTexSize = (x*y*4)+(x*y*4)/3; + GPU_texture_vram_add(mTexSize); } else { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, nx, ny, 0, GL_RGBA, GL_UNSIGNED_BYTE, newPixels ); + mTexSize = x*y*4; + GPU_texture_vram_add(mTexSize); } glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); free(newPixels); diff --git a/source/gameengine/Ketsji/BL_Texture.h b/source/gameengine/Ketsji/BL_Texture.h index eb3888b4862..93204910e54 100644 --- a/source/gameengine/Ketsji/BL_Texture.h +++ b/source/gameengine/Ketsji/BL_Texture.h @@ -27,6 +27,7 @@ private: int mUnit; // Texture unit associated with mTexture unsigned int mEnvState; // cache textureEnv static unsigned int mDisableState; // speed up disabling calls + unsigned int mTexSize; // Size of texture in video ram void InitNonPow2Tex(unsigned int *p,int x,int y,bool mipmap ); void InitGLTex(unsigned int *p,int x,int y,bool mipmap ); diff --git a/source/gameengine/Ketsji/KX_KetsjiEngine.cpp b/source/gameengine/Ketsji/KX_KetsjiEngine.cpp index a1c7957dc72..fc43c03df31 100644 --- a/source/gameengine/Ketsji/KX_KetsjiEngine.cpp +++ b/source/gameengine/Ketsji/KX_KetsjiEngine.cpp @@ -75,6 +75,8 @@ #include "DNA_world_types.h" #include "DNA_scene_types.h" +#include "GPU_extensions.h" + // If define: little test for Nzc: guarded drawing. If the canvas is // not valid, skip rendering this frame. //#define NZC_GUARDED_OUTPUT @@ -1439,6 +1441,18 @@ void KX_KetsjiEngine::RenderDebugProperties() m_canvas->GetHeight()); ycoord += 14; } + + // Put an extra gap in the printed results + ycoord += 14; + + /* Print texture vram usage */ + debugtxt.Format("Texture VRAM: %.2f MB", GPU_texture_vram_usage()/1048576.f); + m_rendertools->RenderText2D(RAS_IRenderTools::RAS_TEXT_PADDED, + debugtxt.Ptr(), + xcoord, ycoord, + m_canvas->GetWidth(), + m_canvas->GetHeight()); + ycoord += 14; } /* Property display*/ -- cgit v1.2.3