From 341b90bc050fb1299587a65c32223a149c78aac1 Mon Sep 17 00:00:00 2001 From: Stephen Saunders Date: Tue, 12 Dec 2023 18:30:22 -0500 Subject: [PATCH] Allocate correct memory size for FMT_DXT1 / FMT_DXT5 compressed images, fully init renderEntity_t in ReadFromDemoFile() --- neo/renderer/BinaryImage.cpp | 7 +++++++ neo/renderer/Image.h | 1 + neo/renderer/Image_load.cpp | 2 +- neo/renderer/RenderEntity.cpp | 4 +++- 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/neo/renderer/BinaryImage.cpp b/neo/renderer/BinaryImage.cpp index 269bd2d6..8b25b2a2 100644 --- a/neo/renderer/BinaryImage.cpp +++ b/neo/renderer/BinaryImage.cpp @@ -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 ); diff --git a/neo/renderer/Image.h b/neo/renderer/Image.h index 1f1fba15..e7167409 100644 --- a/neo/renderer/Image.h +++ b/neo/renderer/Image.h @@ -114,6 +114,7 @@ enum textureFormat_t }; int BitsForFormat( textureFormat_t format ); +int BlockSizeForFormat( const textureFormat_t& format ); /* ================================================ diff --git a/neo/renderer/Image_load.cpp b/neo/renderer/Image_load.cpp index 96d1b049..e59db057 100644 --- a/neo/renderer/Image_load.cpp +++ b/neo/renderer/Image_load.cpp @@ -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 ); diff --git a/neo/renderer/RenderEntity.cpp b/neo/renderer/RenderEntity.cpp index bfef531e..e878568d 100644 --- a/neo/renderer/RenderEntity.cpp +++ b/neo/renderer/RenderEntity.cpp @@ -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;