Improve accuracy of texture memory tracking (#2371)

* Fix alloc_tex_image to account for more missing texture memory
Change alloc_tex_image calls to pass internal format to properly account for used image type

* Fix scaleDown passing primary format in place of internal format to glTexImage2D

* Make texture debug view and texture bias calculation consistent and remove double accounting for render target textures
master
Rye Mutt 2024-08-21 10:47:31 -04:00 committed by GitHub
parent a0da63db57
commit db84bf9567
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 28 additions and 23 deletions

View File

@ -125,27 +125,25 @@ void LLCubeMapArray::allocate(U32 resolution, U32 components, U32 count, bool us
mImage->setHasMipMaps(use_mips);
bind(0);
U32 format = components == 4 ? GL_RGBA16F : GL_RGB16F;
U32 mip = 0;
free_cur_tex_image();
while (resolution >= 1)
U32 format = components == 4 ? GL_RGBA16F : GL_RGB16F;
U32 mip = 0;
U32 mip_resolution = resolution;
while (mip_resolution >= 1)
{
glTexImage3D(GL_TEXTURE_CUBE_MAP_ARRAY, mip, format, resolution, resolution, count * 6, 0,
glTexImage3D(GL_TEXTURE_CUBE_MAP_ARRAY, mip, format, mip_resolution, mip_resolution, count * 6, 0,
GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
if (!use_mips)
{
break;
}
resolution /= 2;
mip_resolution /= 2;
++mip;
}
alloc_tex_image(resolution * 6, resolution, format);
alloc_tex_image(resolution, resolution, format, count * 6);
mImage->setAddressMode(LLTexUnit::TAM_CLAMP);

View File

@ -67,11 +67,12 @@ static U64 sTextureBytes = 0;
// track a texture alloc on the currently bound texture.
// asserts that no currently tracked alloc exists
void LLImageGLMemory::alloc_tex_image(U32 width, U32 height, U32 pixformat)
void LLImageGLMemory::alloc_tex_image(U32 width, U32 height, U32 intformat, U32 count)
{
U32 texUnit = gGL.getCurrentTexUnitIndex();
U32 texName = gGL.getTexUnit(texUnit)->getCurrTexture();
U64 size = LLImageGL::dataFormatBytes(pixformat, width, height);
U64 size = LLImageGL::dataFormatBytes(intformat, width, height);
size *= count;
llassert(size >= 0);
@ -291,9 +292,13 @@ S32 LLImageGL::dataFormatBits(S32 dataformat)
case GL_SRGB: return 24;
case GL_RGB8: return 24;
case GL_RGBA: return 32;
case GL_RGBA8: return 32;
case GL_SRGB_ALPHA: return 32;
case GL_BGRA: return 32; // Used for QuickTime media textures on the Mac
case GL_DEPTH_COMPONENT: return 24;
case GL_DEPTH_COMPONENT24: return 24;
case GL_R16F: return 16;
case GL_RG16F: return 32;
case GL_RGB16F: return 48;
case GL_RGBA16F: return 64;
default:
@ -1384,7 +1389,7 @@ void LLImageGL::setManualImage(U32 target, S32 miplevel, S32 intformat, S32 widt
sub_image_lines(target, miplevel, 0, 0, width, height, pixformat, pixtype, src, width);
}
}
alloc_tex_image(width, height, pixformat);
alloc_tex_image(width, height, intformat, 1);
}
stop_glerror();
@ -2370,11 +2375,11 @@ bool LLImageGL::scaleDown(S32 desired_discard)
gGL.getTexUnit(0)->bindManual(LLTexUnit::TT_TEXTURE, temp_texname, true);
{
LL_PROFILE_ZONE_NAMED_CATEGORY_TEXTURE("scaleDown - glTexImage2D");
glTexImage2D(mTarget, 0, mFormatPrimary, desired_width, desired_height, 0, mFormatPrimary, mFormatType, NULL);
glTexImage2D(mTarget, 0, mFormatInternal, desired_width, desired_height, 0, mFormatPrimary, mFormatType, NULL);
}
// account for new texture getting created
alloc_tex_image(desired_width, desired_height, mFormatPrimary);
alloc_tex_image(desired_width, desired_height, mFormatInternal, 1);
// Use render-to-texture to scale down the texture
{
@ -2428,10 +2433,10 @@ bool LLImageGL::scaleDown(S32 desired_discard)
glBindBuffer(GL_PIXEL_PACK_BUFFER, 0);
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, sScratchPBO);
glTexImage2D(mTarget, 0, mFormatPrimary, desired_width, desired_height, 0, mFormatPrimary, mFormatType, nullptr);
glTexImage2D(mTarget, 0, mFormatInternal, desired_width, desired_height, 0, mFormatPrimary, mFormatType, nullptr);
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
alloc_tex_image(desired_width, desired_height, mFormatPrimary);
alloc_tex_image(desired_width, desired_height, mFormatInternal, 1);
if (mHasMipMaps)
{

View File

@ -50,7 +50,7 @@ class LLWindow;
namespace LLImageGLMemory
{
void alloc_tex_image(U32 width, U32 height, U32 pixformat);
void alloc_tex_image(U32 width, U32 height, U32 intformat, U32 count);
void free_tex_image(U32 texName);
void free_tex_images(U32 count, const U32* texNames);
void free_cur_tex_image();

View File

@ -80,6 +80,9 @@ void load_exr(const std::string& filename)
gGL.getTexUnit(0)->bind(gEXRImage);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16F, width, height, 0, GL_RGBA, GL_FLOAT, out);
LLImageGLMemory::alloc_tex_image(width, height, GL_RGB16F, 1);
free(out); // release memory of image data
glGenerateMipmap(GL_TEXTURE_2D);

View File

@ -525,9 +525,9 @@ void LLGLTexMemBar::draw()
F64 raw_image_bytes_MB = raw_image_bytes / (1024.0 * 1024.0);
F64 saved_raw_image_bytes_MB = saved_raw_image_bytes / (1024.0 * 1024.0);
F64 aux_raw_image_bytes_MB = aux_raw_image_bytes / (1024.0 * 1024.0);
F64 texture_bytes_alloc = LLImageGL::getTextureBytesAllocated() / 1024.0 / 1024.0 * 1.3333f; // add 33% for mipmaps
F64 vertex_bytes_alloc = LLVertexBuffer::getBytesAllocated() / 1024.0 / 1024.0;
F64 render_bytes_alloc = LLRenderTarget::sBytesAllocated / 1024.0 / 1024.0;
F64 texture_bytes_alloc = LLImageGL::getTextureBytesAllocated() / 1024.0 / 512.0;
F64 vertex_bytes_alloc = LLVertexBuffer::getBytesAllocated() / 1024.0 / 512.0;
F64 render_bytes_alloc = LLRenderTarget::sBytesAllocated / 1024.0 / 512.0;
//----------------------------------------------------------------------------
LLGLSUIDefault gls_ui;
@ -579,7 +579,7 @@ void LLGLTexMemBar::draw()
texture_bytes_alloc,
vertex_bytes_alloc,
render_bytes_alloc,
texture_bytes_alloc+vertex_bytes_alloc+render_bytes_alloc);
texture_bytes_alloc+vertex_bytes_alloc);
LLFontGL::getFontMonospace()->renderUTF8(text, 0, 0, v_offset + line_height * 6,
text_color, LLFontGL::LEFT, LLFontGL::TOP);

View File

@ -497,11 +497,10 @@ void LLViewerTexture::updateClass()
F64 texture_bytes_alloc = LLImageGL::getTextureBytesAllocated() / 1024.0 / 512.0;
F64 vertex_bytes_alloc = LLVertexBuffer::getBytesAllocated() / 1024.0 / 512.0;
F64 render_bytes_alloc = LLRenderTarget::sBytesAllocated / 1024.0 / 512.0;
// get an estimate of how much video memory we're using
// NOTE: our metrics miss about half the vram we use, so this biases high but turns out to typically be within 5% of the real number
F32 used = (F32)ll_round(texture_bytes_alloc + vertex_bytes_alloc + render_bytes_alloc);
F32 used = (F32)ll_round(texture_bytes_alloc + vertex_bytes_alloc);
F32 budget = max_vram_budget == 0 ? (F32)gGLManager.mVRAM : (F32)max_vram_budget;