Skip to content

Commit

Permalink
avoid invalidating textures by hashing it's value
Browse files Browse the repository at this point in the history
also increase upload buffer size once again
  • Loading branch information
RSDuck committed Jul 15, 2021
1 parent 0666d4e commit 8d56af7
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
29 changes: 26 additions & 3 deletions src/GPU3D_Deko.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
#include <assert.h>
#include <switch.h>

#define XXH_STATIC_LINKING_ONLY
#include "xxhash/xxhash.h"

#include <arm_neon.h>

using Gfx::EmuCmdBuf;
Expand Down Expand Up @@ -635,9 +638,10 @@ DekoRenderer::TexCacheEntry& DekoRenderer::GetTexture(u32 texParam, u32 palBase)
if (fmt != 7)
{
key |= (u64)palBase << 32;
if (fmt != 5)
if (fmt == 5)
key &= ~((u64)1 << 29);
}
//printf("%" PRIx64 " %" PRIx32 " %" PRIx32 "\n", key, texParam, palBase);

assert(fmt != 0 && "no texture is not a texture format!");

Expand Down Expand Up @@ -724,6 +728,8 @@ DekoRenderer::TexCacheEntry& DekoRenderer::GetTexture(u32 texParam, u32 palBase)
u8* texData = &GPU::VRAMFlat_Texture[addr];
u16* palData = (u16*)(GPU::VRAMFlat_TexPal + palAddr);

//assert(entry.TexPalStart+entry.TexPalSize <= 128*1024*1024);

bool color0Transparent = texParam & (1 << 29);

switch (fmt)
Expand All @@ -736,6 +742,14 @@ DekoRenderer::TexCacheEntry& DekoRenderer::GetTexture(u32 texParam, u32 palBase)
}
}

for (int i = 0; i < 2; i++)
{
if (entry.TextureRAMSize[i])
entry.TextureHash[i] = XXH3_64bits(&GPU::VRAMFlat_Texture[entry.TextureRAMStart[i]], entry.TextureRAMSize[i]);
}
if (entry.TexPalSize)
entry.TexPalHash = XXH3_64bits(&GPU::VRAMFlat_TexPal[entry.TexPalStart], entry.TexPalSize);

auto& texArrays = TexArrays[widthLog2][heightLog2];
auto& freeTextures = FreeTextures[widthLog2][heightLog2];

Expand Down Expand Up @@ -846,7 +860,12 @@ void DekoRenderer::RenderFrame()
for (u32 j = startEntry; j < startEntry + entriesCount; j++)
{
if (GetRangedBitMask(j, startBit, bitsCount) & textureDirty.Data[j])
goto invalidate;
{
u64 newTexHash = XXH3_64bits(&GPU::VRAMFlat_Texture[entry.TextureRAMStart[i]], entry.TextureRAMSize[i]);

if (newTexHash != entry.TextureHash[i])
goto invalidate;
}
}
}
}
Expand All @@ -861,7 +880,11 @@ void DekoRenderer::RenderFrame()
for (u32 j = startEntry; j < startEntry + entriesCount; j++)
{
if (GetRangedBitMask(j, startBit, bitsCount) & texPalDirty.Data[j])
goto invalidate;
{
u64 newPalHash = XXH3_64bits(&GPU::VRAMFlat_TexPal[entry.TexPalStart], entry.TexPalSize);
if (newPalHash != entry.TexPalHash)
goto invalidate;
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/GPU3D_Deko.h
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,9 @@ class DekoRenderer : public Renderer3D
u32 TexPalStart, TexPalSize;
u8 WidthLog2, HeightLog2;
TexArrayEntry Texture;

u64 TextureHash[2];
u64 TexPalHash;
};
std::unordered_map<u64, TexCacheEntry> TexCache;

Expand Down
4 changes: 2 additions & 2 deletions src/frontend/switch/UploadBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ DkGpuAddr UploadBuffer::UploadData(dk::CmdBuf cmdbuf, u32 size, u8* data)
DkGpuAddr srcGpu = Gfx::DataHeap->GpuAddr(Buffers[CurBuffer]) + CurOffset;
memcpy(srcCpu, data, size);

CurOffset += size + 31;
CurOffset &= ~31;
CurOffset += size + 63;
CurOffset &= ~63;
return srcGpu;
}

Expand Down
2 changes: 1 addition & 1 deletion src/frontend/switch/UploadBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class UploadBuffer

u32 LastFlushBuffer = 0;
private:
static const u32 SegmentSize = 8*1024*1024;
static const u32 SegmentSize = 16*1024*1024;
GpuMemHeap::Allocation Buffers[3];
dk::Fence Fences[3] = {};
u32 CurBuffer = 0, CurOffset = 0;
Expand Down

0 comments on commit 8d56af7

Please sign in to comment.