Skip to content

Commit

Permalink
Fix bug causing occasional texture glitches.
Browse files Browse the repository at this point in the history
Also fix tests.
  • Loading branch information
bolrog committed Apr 1, 2021
1 parent 64ade10 commit 07f1989
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 37 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
10 changes: 6 additions & 4 deletions src/d2dx/TextureCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
#include "TextureCache.h"
#include "TextureCachePolicyBitPmru.h"

#define USE_BIT_MRU 1

using namespace d2dx;
using namespace std;

Expand All @@ -36,7 +34,7 @@ TextureCache::TextureCache(int32_t width, int32_t height, uint32_t capacity, ID3
_textureProcessor(textureProcessor),
_policy(make_unique<TextureCachePolicyBitPmru>(capacity, simd))
{
#ifndef GX_UNITTEST
#ifndef D2DX_UNITTEST

#ifdef D2DX_TEXTURE_CACHE_IS_ARRAY_BASED
_atlasWidth = _width;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions src/d2dx/TextureCachePolicyBitPmru.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/d2dxtests/TestSimd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include "pch.h"
#include <array>
#include "CppUnitTest.h"
#include "../d2gex/Simd.h"
#include "../d2dx/Simd.h"

using namespace Microsoft::VisualStudio::CppUnitTestFramework;
using namespace d2dx;
Expand Down
17 changes: 7 additions & 10 deletions src/d2dxtests/TestTextureCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
#include <array>
#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;
Expand Down Expand Up @@ -58,7 +58,6 @@ namespace d2dxtests
auto simd = Simd::Create();
auto textureProcessor = std::make_shared<TextureProcessor>();
std::array<uint32_t, 2 * 256 * 128> tmuData;
std::array<uint32_t, 1024> palette;

Batch batch;
batch.SetTextureStartAddress(0);
Expand All @@ -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)
Expand All @@ -85,7 +84,6 @@ namespace d2dxtests
auto simd = Simd::Create();
auto textureProcessor = std::make_shared<TextureProcessor>();
std::array<uint32_t, 2 * 256 * 128> tmuData;
std::array<uint32_t, 1024> palette;

Batch batch;
batch.SetTextureStartAddress(0);
Expand All @@ -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)
{
Expand Down Expand Up @@ -133,7 +131,6 @@ namespace d2dxtests
auto simd = Simd::Create();
auto textureProcessor = std::make_shared<TextureProcessor>();
std::array<uint32_t, 2 * 256 * 128> tmuData;
std::array<uint32_t, 1024> palette;

Batch batch;
batch.SetTextureStartAddress(0);
Expand All @@ -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)
{
Expand Down
33 changes: 28 additions & 5 deletions src/d2dxtests/d2dxtests.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,15 @@
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>$(VCInstallDir)UnitTest\include;..\..\thirdparty\glide3;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_DEBUG;%(PreprocessorDefinitions);GX_UNITTEST</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(VCInstallDir)UnitTest\include;..\..\thirdparty\glide3;..\d2dx;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_DEBUG;%(PreprocessorDefinitions);D2DX_UNITTEST</PreprocessorDefinitions>
<UseFullPaths>true</UseFullPaths>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<AdditionalLibraryDirectories>$(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>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)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
Expand All @@ -74,8 +75,8 @@
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>$(VCInstallDir)UnitTest\include;..\..\thirdparty\glide3;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;NDEBUG;%(PreprocessorDefinitions);GX_UNITTEST</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(VCInstallDir)UnitTest\include;..\..\thirdparty\glide3;..\d2dx;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;NDEBUG;%(PreprocessorDefinitions);D2DX_UNITTEST</PreprocessorDefinitions>
<UseFullPaths>true</UseFullPaths>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
</ClCompile>
Expand All @@ -84,9 +85,18 @@
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalLibraryDirectories>$(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>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)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\..\thirdparty\fnv\hash_32a.c">
<CompileAs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">CompileAsCpp</CompileAs>
<CompileAs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">CompileAsCpp</CompileAs>
</ClCompile>
<ClCompile Include="..\d2dx\D2DXContext.cpp" />
<ClCompile Include="..\d2dx\D2DXDetours.cpp" />
<ClCompile Include="..\d2dx\D2DXIntegrationImpl.cpp" />
<ClCompile Include="..\d2dx\D3D11Context.cpp" />
<ClCompile Include="..\d2dx\GameHelper.cpp" />
<ClCompile Include="..\d2dx\glide3x.cpp" />
<ClCompile Include="..\d2dx\Simd.cpp" />
Expand All @@ -103,7 +113,20 @@
<ClCompile Include="TestSimd.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="pch.h" />
<ClInclude Include="..\d2dx\Batch.h" />
<ClInclude Include="..\d2dx\Buffer.h" />
<ClInclude Include="..\d2dx\D2DXContext.h" />
<ClInclude Include="..\d2dx\D2DXDetours.h" />
<ClInclude Include="..\d2dx\D3D11Context.h" />
<ClInclude Include="..\d2dx\dx256_bmp.h" />
<ClInclude Include="..\d2dx\GameHelper.h" />
<ClInclude Include="..\d2dx\TextureCache.h" />
<ClInclude Include="..\d2dx\TextureCachePolicy.h" />
<ClInclude Include="..\d2dx\TextureCachePolicyBitPmru.h" />
<ClInclude Include="..\d2dx\TextureProcessor.h" />
<ClInclude Include="..\d2dx\Types.h" />
<ClInclude Include="..\d2dx\Utils.h" />
<ClInclude Include="..\d2dx\Vertex.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
Expand Down
58 changes: 57 additions & 1 deletion src/d2dxtests/d2dxtests.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,64 @@
<ClCompile Include="..\d2dx\Utils.cpp">
<Filter>d2dx</Filter>
</ClCompile>
<ClCompile Include="..\d2dx\D2DXContext.cpp">
<Filter>d2dx</Filter>
</ClCompile>
<ClCompile Include="..\d2dx\D2DXDetours.cpp">
<Filter>d2dx</Filter>
</ClCompile>
<ClCompile Include="..\d2dx\D2DXIntegrationImpl.cpp">
<Filter>d2dx</Filter>
</ClCompile>
<ClCompile Include="..\d2dx\D3D11Context.cpp">
<Filter>d2dx</Filter>
</ClCompile>
<ClCompile Include="..\..\thirdparty\fnv\hash_32a.c">
<Filter>d2dx</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="pch.h" />
<ClInclude Include="..\d2dx\Batch.h">
<Filter>d2dx</Filter>
</ClInclude>
<ClInclude Include="..\d2dx\Buffer.h">
<Filter>d2dx</Filter>
</ClInclude>
<ClInclude Include="..\d2dx\D2DXContext.h">
<Filter>d2dx</Filter>
</ClInclude>
<ClInclude Include="..\d2dx\D2DXDetours.h">
<Filter>d2dx</Filter>
</ClInclude>
<ClInclude Include="..\d2dx\D3D11Context.h">
<Filter>d2dx</Filter>
</ClInclude>
<ClInclude Include="..\d2dx\dx256_bmp.h">
<Filter>d2dx</Filter>
</ClInclude>
<ClInclude Include="..\d2dx\GameHelper.h">
<Filter>d2dx</Filter>
</ClInclude>
<ClInclude Include="..\d2dx\TextureCache.h">
<Filter>d2dx</Filter>
</ClInclude>
<ClInclude Include="..\d2dx\TextureCachePolicy.h">
<Filter>d2dx</Filter>
</ClInclude>
<ClInclude Include="..\d2dx\TextureCachePolicyBitPmru.h">
<Filter>d2dx</Filter>
</ClInclude>
<ClInclude Include="..\d2dx\TextureProcessor.h">
<Filter>d2dx</Filter>
</ClInclude>
<ClInclude Include="..\d2dx\Types.h">
<Filter>d2dx</Filter>
</ClInclude>
<ClInclude Include="..\d2dx\Utils.h">
<Filter>d2dx</Filter>
</ClInclude>
<ClInclude Include="..\d2dx\Vertex.h">
<Filter>d2dx</Filter>
</ClInclude>
</ItemGroup>
</Project>
12 changes: 0 additions & 12 deletions src/d2dxtests/pch.h

This file was deleted.

0 comments on commit 07f1989

Please sign in to comment.