diff options
| author | Rye Mutt <rye@alchemyviewer.org> | 2024-08-21 10:47:31 -0400 | 
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-08-21 09:47:31 -0500 | 
| commit | db84bf9567c27e266ccc6b1b6aed089c6022fe91 (patch) | |
| tree | bcf9edf9968e4087621a9e55ea02743671b45c12 /indra/llrender | |
| parent | a0da63db57b4799cf67df4618afe70760840a719 (diff) | |
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
Diffstat (limited to 'indra/llrender')
| -rw-r--r-- | indra/llrender/llcubemaparray.cpp | 14 | ||||
| -rw-r--r-- | indra/llrender/llimagegl.cpp | 19 | ||||
| -rw-r--r-- | indra/llrender/llimagegl.h | 2 | 
3 files changed, 19 insertions, 16 deletions
| diff --git a/indra/llrender/llcubemaparray.cpp b/indra/llrender/llcubemaparray.cpp index be69b997da..4f5e13765a 100644 --- a/indra/llrender/llcubemaparray.cpp +++ b/indra/llrender/llcubemaparray.cpp @@ -125,27 +125,25 @@ void LLCubeMapArray::allocate(U32 resolution, U32 components, U32 count, bool us      mImage->setHasMipMaps(use_mips);      bind(0); +    free_cur_tex_image();      U32 format = components == 4 ? GL_RGBA16F : GL_RGB16F; -      U32 mip = 0; - -    free_cur_tex_image(); - -    while (resolution >= 1) +    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); diff --git a/indra/llrender/llimagegl.cpp b/indra/llrender/llimagegl.cpp index 058afa0cf2..0746e21079 100644 --- a/indra/llrender/llimagegl.cpp +++ b/indra/llrender/llimagegl.cpp @@ -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)          { diff --git a/indra/llrender/llimagegl.h b/indra/llrender/llimagegl.h index 5073701c30..9a8d935b89 100644 --- a/indra/llrender/llimagegl.h +++ b/indra/llrender/llimagegl.h @@ -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(); | 
