Cleaned up texture VRAM usage tracking.

--HG--
branch : minor
This commit is contained in:
Alex Szpakowski
2017-05-06 23:56:10 -03:00
parent b590edf27d
commit b019a4a64c
13 changed files with 71 additions and 69 deletions
+16 -21
View File
@@ -158,7 +158,6 @@ Canvas::Canvas(const Settings &settings)
, texture(0)
, renderbuffer(0)
, actualSamples(0)
, textureMemory(0)
{
format = getSizedFormat(format);
@@ -245,6 +244,13 @@ bool Canvas::loadVolatile()
renderbuffer = 0;
status = GL_FRAMEBUFFER_COMPLETE;
// getMaxRenderbufferSamples will be 0 on systems that don't support
// multisampled renderbuffers / don't export FBO multisample extensions.
actualSamples = getRequestedMSAA();
actualSamples = std::min(actualSamples, gl.getMaxRenderbufferSamples());
actualSamples = std::max(actualSamples, 0);
actualSamples = actualSamples == 1 ? 0 : actualSamples;
if (isReadable())
{
glGenTextures(1, &texture);
@@ -292,29 +298,19 @@ bool Canvas::loadVolatile()
}
}
// getMaxRenderbufferSamples will be 0 on systems that don't support
// multisampled renderbuffers / don't export FBO multisample extensions.
actualSamples = getRequestedMSAA();
actualSamples = std::min(actualSamples, gl.getMaxRenderbufferSamples());
actualSamples = std::max(actualSamples, 0);
actualSamples = actualSamples == 1 ? 0 : actualSamples;
if (!isReadable() || actualSamples > 0)
createRenderbuffer(pixelWidth, pixelHeight, actualSamples, format, renderbuffer);
size_t prevmemsize = textureMemory;
textureMemory = getPixelFormatSize(format) * pixelWidth * pixelHeight;
if (actualSamples > 0 && isReadable())
textureMemory += (textureMemory * actualSamples);
else if (actualSamples > 0)
textureMemory *= actualSamples;
int64 memsize = getPixelFormatSize(format) * pixelWidth * pixelHeight;
if (getMipmapCount() > 1)
textureMemory *= 1.33334;
memsize *= 1.33334;
gl.updateTextureMemorySize(prevmemsize, textureMemory);
if (actualSamples > 1 && isReadable())
memsize += getPixelFormatSize(format) * pixelWidth * pixelHeight * actualSamples;
else if (actualSamples > 1)
memsize *= actualSamples;
setGraphicsMemorySize(memsize);
return true;
}
@@ -334,8 +330,7 @@ void Canvas::unloadVolatile()
renderbuffer = 0;
texture = 0;
gl.updateTextureMemorySize(textureMemory, 0);
textureMemory = 0;
setGraphicsMemorySize(0);
}
void Canvas::setFilter(const Texture::Filter &f)
-2
View File
@@ -112,8 +112,6 @@ private:
int actualSamples;
size_t textureMemory;
static SupportedFormat supportedFormats[PIXELFORMAT_MAX_ENUM];
static SupportedFormat checkedFormats[PIXELFORMAT_MAX_ENUM];
+3 -18
View File
@@ -126,7 +126,6 @@ love::graphics::Canvas *Graphics::newCanvas(const Canvas::Settings &settings)
return new Canvas(settings);
}
love::graphics::Shader *Graphics::newShader(const Shader::ShaderSource &source)
{
return new Shader(source);
@@ -1446,24 +1445,10 @@ Graphics::RendererInfo Graphics::getRendererInfo() const
return info;
}
Graphics::Stats Graphics::getStats() const
void Graphics::getAPIStats(int &drawcalls, int &shaderswitches) const
{
int drawcalls = gl.stats.drawCalls;
if (streamBufferState.vertexCount > 0)
drawcalls++;
Stats stats;
stats.drawCalls = drawcalls;
stats.canvasSwitches = canvasSwitchCount;
stats.shaderSwitches = gl.stats.shaderSwitches;
stats.canvases = Canvas::canvasCount;
stats.images = Image::imageCount;
stats.fonts = Font::fontCount;
stats.textureMemory = gl.stats.textureMemory;
return stats;
drawcalls = gl.stats.drawCalls;
shaderswitches = gl.stats.shaderSwitches;
}
double Graphics::getSystemLimit(SystemLimit limittype) const
+1 -1
View File
@@ -126,13 +126,13 @@ public:
bool isImageFormatSupported(PixelFormat format) const override;
Renderer getRenderer() const override;
RendererInfo getRendererInfo() const override;
Stats getStats() const override;
Shader::Language getShaderLanguageTarget() const override;
private:
love::graphics::StreamBuffer *newStreamBuffer(BufferType type, size_t size) override;
void getAPIStats(int &drawcalls, int &shaderswitches) const override;
void endPass();
void bindCachedFBO(const RenderTargets &targets);
+5 -7
View File
@@ -268,16 +268,15 @@ bool Image::loadVolatile()
throw;
}
size_t prevmemsize = textureMemorySize;
textureMemorySize = 0;
int64 memsize = 0;
for (int slice = 0; slice < data.getSliceCount(0); slice++)
textureMemorySize += data.get(slice, 0)->getSize();
memsize += data.get(slice, 0)->getSize();
if (getMipmapCount() > 1)
textureMemorySize *= 1.33334;
memsize *= 1.33334;
gl.updateTextureMemorySize(prevmemsize, textureMemorySize);
setGraphicsMemorySize(memsize);
usingDefaultTexture = false;
return true;
@@ -291,8 +290,7 @@ void Image::unloadVolatile()
gl.deleteTexture(texture);
texture = 0;
gl.updateTextureMemorySize(textureMemorySize, 0);
textureMemorySize = 0;
setGraphicsMemorySize(0);
}
ptrdiff_t Image::getHandle() const
-6
View File
@@ -1181,12 +1181,6 @@ float OpenGL::getMaxLODBias() const
return maxLODBias;
}
void OpenGL::updateTextureMemorySize(size_t oldsize, size_t newsize)
{
int64 memsize = (int64) stats.textureMemory + ((int64) newsize - (int64) oldsize);
stats.textureMemory = (size_t) std::max(memsize, (int64) 0);
}
bool OpenGL::isCoreProfile() const
{
return coreProfile;
+2 -6
View File
@@ -114,9 +114,8 @@ public:
struct Stats
{
size_t textureMemory;
int drawCalls;
int shaderSwitches;
int drawCalls;
int shaderSwitches;
} stats;
struct Bugs
@@ -366,9 +365,6 @@ public:
float getMaxLODBias() const;
void updateTextureMemorySize(size_t oldsize, size_t newsize);
/**
* Gets whether the context is Core Profile OpenGL 3.2+.
**/