From 07f198919b8ed062e8ca17c3f36b40cf52cd3d41 Mon Sep 17 00:00:00 2001 From: bolrog <81111887+bolrog@users.noreply.github.com> Date: Thu, 1 Apr 2021 19:24:53 +0200 Subject: [PATCH] Fix bug causing occasional texture glitches. Also fix tests. --- README.md | 5 ++- src/d2dx/TextureCache.cpp | 10 +++-- src/d2dx/TextureCachePolicyBitPmru.cpp | 2 - src/d2dxtests/TestSimd.cpp | 2 +- src/d2dxtests/TestTextureCache.cpp | 17 +++----- src/d2dxtests/d2dxtests.vcxproj | 33 +++++++++++--- src/d2dxtests/d2dxtests.vcxproj.filters | 58 ++++++++++++++++++++++++- src/d2dxtests/pch.h | 12 ----- 8 files changed, 102 insertions(+), 37 deletions(-) delete mode 100644 src/d2dxtests/pch.h diff --git a/README.md b/README.md index 7a61a67..6454c44 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ D2DX is a preservation project for running classic Diablo II/LoD on modern PCs. -Version 0.99.401 +Version 0.99.401b ## Mission statement - Preserve the classic Diablo 2/LoD experience as much as possible. @@ -91,11 +91,12 @@ This project uses the following third party libraries: ## Release history -### 0.99.401 +### 0.99.401b - Add experimental support for widescreen modes using a fork of SlashDiablo-HD by Mir Drualga and Bartosz Jankowski. - Remove the use of "AA bilinear" filtering, in favor of point filtering. This is part of a work in progress and will be tweaked further. - Cut VRAM footprint by 75% and reduce performance overhead. - Source code is now in the git. + - Updated: fix occasional glitches due to the wrong texture cache policy being used. ### 0.99.329b - Add support for 1024x768, tested with MedianXL which now seems to work. diff --git a/src/d2dx/TextureCache.cpp b/src/d2dx/TextureCache.cpp index 982fa89..c0816ce 100644 --- a/src/d2dx/TextureCache.cpp +++ b/src/d2dx/TextureCache.cpp @@ -20,8 +20,6 @@ #include "TextureCache.h" #include "TextureCachePolicyBitPmru.h" -#define USE_BIT_MRU 1 - using namespace d2dx; using namespace std; @@ -36,7 +34,7 @@ TextureCache::TextureCache(int32_t width, int32_t height, uint32_t capacity, ID3 _textureProcessor(textureProcessor), _policy(make_unique(capacity, simd)) { -#ifndef GX_UNITTEST +#ifndef D2DX_UNITTEST #ifdef D2DX_TEXTURE_CACHE_IS_ARRAY_BASED _atlasWidth = _width; @@ -157,7 +155,7 @@ TextureCacheLocation TextureCache::InsertTexture(uint32_t contentKey, Batch& bat DEBUG_PRINT("Evicted %ix%i texture %i from cache.", batch.GetWidth(), batch.GetHeight(), replacementIndex); } -#ifndef GX_UNITTEST +#ifndef D2DX_UNITTEST CD3D11_BOX box; #ifdef D2DX_TEXTURE_CACHE_IS_ARRAY_BASED box.left = 0; @@ -202,9 +200,13 @@ TextureCacheLocation TextureCache::InsertTexture(uint32_t contentKey, Batch& bat #else return { tileX * _width, tileY * _height, arrayIndex }; #endif +#else +#ifdef D2DX_TEXTURE_CACHE_IS_ARRAY_BASED + return { 0, 0, replacementIndex }; #else return { 0,0,0 }; #endif +#endif } uint32_t TextureCache::GetCapacity() const diff --git a/src/d2dx/TextureCachePolicyBitPmru.cpp b/src/d2dx/TextureCachePolicyBitPmru.cpp index 07c5b65..17c16f9 100644 --- a/src/d2dx/TextureCachePolicyBitPmru.cpp +++ b/src/d2dx/TextureCachePolicyBitPmru.cpp @@ -54,10 +54,8 @@ int32_t TextureCachePolicyBitPmru::Find(uint32_t contentKey, int32_t lastIndex) if (findIndex >= 0) { -#if USE_BIT_MRU _usedInFrameBits.items[findIndex >> 5] |= 1 << (findIndex & 31); _mruBits.items[findIndex >> 5] |= 1 << (findIndex & 31); -#endif return findIndex; } diff --git a/src/d2dxtests/TestSimd.cpp b/src/d2dxtests/TestSimd.cpp index c13b2ea..c32007e 100644 --- a/src/d2dxtests/TestSimd.cpp +++ b/src/d2dxtests/TestSimd.cpp @@ -17,7 +17,7 @@ #include "pch.h" #include #include "CppUnitTest.h" -#include "../d2gex/Simd.h" +#include "../d2dx/Simd.h" using namespace Microsoft::VisualStudio::CppUnitTestFramework; using namespace d2dx; diff --git a/src/d2dxtests/TestTextureCache.cpp b/src/d2dxtests/TestTextureCache.cpp index e8bc0e3..4ab1e6b 100644 --- a/src/d2dxtests/TestTextureCache.cpp +++ b/src/d2dxtests/TestTextureCache.cpp @@ -18,10 +18,10 @@ #include #include "CppUnitTest.h" -#include "../d2gex/Batch.h" -#include "../d2gex/Simd.h" -#include "../d2gex/Types.h" -#include "../d2gex/TextureCache.h" +#include "../d2dx/Batch.h" +#include "../d2dx/Simd.h" +#include "../d2dx/Types.h" +#include "../d2dx/TextureCache.h" using namespace Microsoft::VisualStudio::CppUnitTestFramework; using namespace d2dx; @@ -58,7 +58,6 @@ namespace d2dxtests auto simd = Simd::Create(); auto textureProcessor = std::make_shared(); std::array tmuData; - std::array palette; Batch batch; batch.SetTextureStartAddress(0); @@ -69,7 +68,7 @@ namespace d2dxtests for (uint32_t i = 0; i < 64; ++i) { uint32_t hash = (0xFF << 24) | (i << 16) | (i << 8) | i; - textureCache.InsertTexture(hash, batch, (const uint8_t*)tmuData.data(), palette.data()); + textureCache.InsertTexture(hash, batch, (const uint8_t*)tmuData.data()); } for (uint32_t i = 0; i < 64; ++i) @@ -85,7 +84,6 @@ namespace d2dxtests auto simd = Simd::Create(); auto textureProcessor = std::make_shared(); std::array tmuData; - std::array palette; Batch batch; batch.SetTextureStartAddress(0); @@ -96,7 +94,7 @@ namespace d2dxtests for (uint32_t i = 0; i < 65; ++i) { uint32_t hash = (0xFF << 24) | (i << 16) | (i << 8) | i; - auto tcl = textureCache.InsertTexture(hash, batch, (const uint8_t*)tmuData.data(), palette.data()); + auto tcl = textureCache.InsertTexture(hash, batch, (const uint8_t*)tmuData.data()); if (i == 64) { @@ -133,7 +131,6 @@ namespace d2dxtests auto simd = Simd::Create(); auto textureProcessor = std::make_shared(); std::array tmuData; - std::array palette; Batch batch; batch.SetTextureStartAddress(0); @@ -152,7 +149,7 @@ namespace d2dxtests Assert::AreEqual(0, textureCache.FindTexture(0xFF000000, -1).ArrayIndex); } - auto tcl = textureCache.InsertTexture(hash, batch, (const uint8_t*)tmuData.data(), palette.data()); + auto tcl = textureCache.InsertTexture(hash, batch, (const uint8_t*)tmuData.data()); if (i == 64) { diff --git a/src/d2dxtests/d2dxtests.vcxproj b/src/d2dxtests/d2dxtests.vcxproj index f0b0fa6..eed8188 100644 --- a/src/d2dxtests/d2dxtests.vcxproj +++ b/src/d2dxtests/d2dxtests.vcxproj @@ -57,14 +57,15 @@ Use Level3 true - $(VCInstallDir)UnitTest\include;..\..\thirdparty\glide3;%(AdditionalIncludeDirectories) - WIN32;_DEBUG;%(PreprocessorDefinitions);GX_UNITTEST + $(VCInstallDir)UnitTest\include;..\..\thirdparty\glide3;..\d2dx;%(AdditionalIncludeDirectories) + WIN32;_DEBUG;%(PreprocessorDefinitions);D2DX_UNITTEST true pch.h Windows $(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories) + comctl32.lib;dxgi.lib;d3d11.lib;version.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) @@ -74,8 +75,8 @@ true true true - $(VCInstallDir)UnitTest\include;..\..\thirdparty\glide3;%(AdditionalIncludeDirectories) - WIN32;NDEBUG;%(PreprocessorDefinitions);GX_UNITTEST + $(VCInstallDir)UnitTest\include;..\..\thirdparty\glide3;..\d2dx;%(AdditionalIncludeDirectories) + WIN32;NDEBUG;%(PreprocessorDefinitions);D2DX_UNITTEST true pch.h @@ -84,9 +85,18 @@ true true $(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories) + comctl32.lib;dxgi.lib;d3d11.lib;version.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + + CompileAsCpp + CompileAsCpp + + + + + @@ -103,7 +113,20 @@ - + + + + + + + + + + + + + + diff --git a/src/d2dxtests/d2dxtests.vcxproj.filters b/src/d2dxtests/d2dxtests.vcxproj.filters index c21e965..1d63dd4 100644 --- a/src/d2dxtests/d2dxtests.vcxproj.filters +++ b/src/d2dxtests/d2dxtests.vcxproj.filters @@ -33,8 +33,64 @@ d2dx + + d2dx + + + d2dx + + + d2dx + + + d2dx + + + d2dx + - + + d2dx + + + d2dx + + + d2dx + + + d2dx + + + d2dx + + + d2dx + + + d2dx + + + d2dx + + + d2dx + + + d2dx + + + d2dx + + + d2dx + + + d2dx + + + d2dx + \ No newline at end of file diff --git a/src/d2dxtests/pch.h b/src/d2dxtests/pch.h deleted file mode 100644 index b082b6f..0000000 --- a/src/d2dxtests/pch.h +++ /dev/null @@ -1,12 +0,0 @@ -// pch.h: This is a precompiled header file. -// Files listed below are compiled only once, improving build performance for future builds. -// This also affects IntelliSense performance, including code completion and many code browsing features. -// However, files listed here are ALL re-compiled if any one of them is updated between builds. -// Do not add files here that you will be updating frequently as this negates the performance advantage. - -#ifndef PCH_H -#define PCH_H - -#include "../d2dx/pch.h" - -#endif //PCH_H