Allocate correct memory size for FMT_DXT1 / FMT_DXT5 compressed images, fully init renderEntity_t in ReadFromDemoFile()

This commit is contained in:
Stephen Saunders 2023-12-12 18:30:22 -05:00 committed by Robert Beckebans
parent aeb3e21bb9
commit 341b90bc05
4 changed files with 12 additions and 2 deletions

View file

@ -903,6 +903,13 @@ bool idBinaryImage::LoadFromGeneratedFile( idFile* bFile, ID_TIME_T sourceTimeSt
{
img.Alloc( img.dataSize * 2 );
}
// SRS - For compressed formats, match allocation to what nvrhi expects for the texture's mip variants
else if( ( textureFormat_t )fileData.format == FMT_DXT1 || ( textureFormat_t )fileData.format == FMT_DXT5 )
{
int mipCols = ( ( ( ( fileData.width + 3 ) & ~3 ) >> img.level ) + 3 ) / 4;
int mipRows = ( ( ( ( fileData.height + 3 ) & ~3 ) >> img.level ) + 3 ) / 4;
img.Alloc( Max( img.dataSize, mipCols * mipRows * BlockSizeForFormat( ( textureFormat_t )fileData.format ) ) );
}
else
{
img.Alloc( img.dataSize );

View file

@ -114,6 +114,7 @@ enum textureFormat_t
};
int BitsForFormat( textureFormat_t format );
int BlockSizeForFormat( const textureFormat_t& format );
/*
================================================

View file

@ -718,7 +718,7 @@ void idImage::FinalizeImage( bool fromBackEnd, nvrhi::ICommandList* commandList
bufferW = ( img.width + 3 ) & ~3;
}
commandList->writeTexture( texture, img.destZ, img.level, pic, GetRowPitch( opts.format, img.width ) );
commandList->writeTexture( texture, img.destZ, img.level, pic, GetRowPitch( opts.format, bufferW ) );
}
}
commandList->setPermanentTextureState( texture, nvrhi::ResourceStates::ShaderResource );

View file

@ -165,7 +165,9 @@ int RenderEnvprobeLocal::GetIndex()
void idRenderEntityLocal::ReadFromDemoFile( class idDemoFile* f )
{
int i;
renderEntity_t ent = {};
renderEntity_t ent;
// SRS - fully initialize ent so that memcmp() in UpdateEntityDef() works properly
memset( &ent, 0, sizeof( renderEntity_t ) );
/* Initialize Pointers */
decals = NULL;
overlays = NULL;