summaryrefslogtreecommitdiff
path: root/Source/Core/VideoCommon
diff options
context:
space:
mode:
authorShawn Hoffman <godisgovernment@gmail.com>2012-02-27 22:36:41 -0800
committerShawn Hoffman <godisgovernment@gmail.com>2012-02-27 22:36:41 -0800
commit6eb2cb266663d6a7a70f6e9e233cb1bf2967cd4d (patch)
treefe60ac36b66199f775b9606aaea259bcc448c3d5 /Source/Core/VideoCommon
parent6ccb30ac5fd7dfb51f41adf2d7fce159d4d0c174 (diff)
parentee09def802f9883056a2dc43136e65922dcccee2 (diff)
Merge branch 'master' into wii-network
Diffstat (limited to 'Source/Core/VideoCommon')
-rw-r--r--Source/Core/VideoCommon/Src/AVIDump.cpp2
-rw-r--r--Source/Core/VideoCommon/Src/BPMemory.cpp2
-rw-r--r--Source/Core/VideoCommon/Src/BPMemory.h41
-rw-r--r--Source/Core/VideoCommon/Src/BPStructs.cpp27
-rw-r--r--Source/Core/VideoCommon/Src/CommandProcessor.cpp13
-rw-r--r--Source/Core/VideoCommon/Src/CommandProcessor.h1
-rw-r--r--Source/Core/VideoCommon/Src/ImageWrite.h1
-rw-r--r--Source/Core/VideoCommon/Src/PixelShaderGen.cpp14
-rw-r--r--Source/Core/VideoCommon/Src/PixelShaderGen.h19
-rw-r--r--Source/Core/VideoCommon/Src/PixelShaderManager.cpp42
-rw-r--r--Source/Core/VideoCommon/Src/PixelShaderManager.h6
-rw-r--r--Source/Core/VideoCommon/Src/TextureCacheBase.cpp322
-rw-r--r--Source/Core/VideoCommon/Src/TextureCacheBase.h97
-rw-r--r--Source/Core/VideoCommon/Src/TextureDecoder.h4
-rw-r--r--Source/Core/VideoCommon/Src/VideoConfig.cpp12
-rw-r--r--Source/Core/VideoCommon/Src/VideoConfig.h1
16 files changed, 345 insertions, 259 deletions
diff --git a/Source/Core/VideoCommon/Src/AVIDump.cpp b/Source/Core/VideoCommon/Src/AVIDump.cpp
index 469e00d9f5..670693690b 100644
--- a/Source/Core/VideoCommon/Src/AVIDump.cpp
+++ b/Source/Core/VideoCommon/Src/AVIDump.cpp
@@ -263,7 +263,7 @@ bool AVIDump::CreateFile()
s_Stream->codec->bit_rate = 400000;
s_Stream->codec->width = s_width;
s_Stream->codec->height = s_height;
- s_Stream->codec->time_base = (AVRational){1, VideoInterface::TargetRefreshRate};
+ s_Stream->codec->time_base = (AVRational){1, static_cast<int>(VideoInterface::TargetRefreshRate)};
s_Stream->codec->gop_size = 12;
s_Stream->codec->pix_fmt = g_Config.bUseFFV1 ? PIX_FMT_BGRA : PIX_FMT_YUV420P;
diff --git a/Source/Core/VideoCommon/Src/BPMemory.cpp b/Source/Core/VideoCommon/Src/BPMemory.cpp
index da09893f35..5c4ed457e3 100644
--- a/Source/Core/VideoCommon/Src/BPMemory.cpp
+++ b/Source/Core/VideoCommon/Src/BPMemory.cpp
@@ -61,7 +61,7 @@ void BPReload()
// Cases in which we DON'T want to reload the BP
continue;
default:
- BPCmd bp = {i, 0xFFFFFF, ((u32*)&bpmem)[i]};
+ BPCmd bp = {i, 0xFFFFFF, static_cast<int>(((u32*)&bpmem)[i])};
BPWritten(bp);
}
}
diff --git a/Source/Core/VideoCommon/Src/BPMemory.h b/Source/Core/VideoCommon/Src/BPMemory.h
index 1f6f453a77..0bb2bf9013 100644
--- a/Source/Core/VideoCommon/Src/BPMemory.h
+++ b/Source/Core/VideoCommon/Src/BPMemory.h
@@ -65,10 +65,10 @@
#define BPMEM_UNKOWN_57 0x57
#define BPMEM_REVBITS 0x58
#define BPMEM_SCISSOROFFSET 0x59
-#define BPMEM_UNKNOWN_60 0x60
-#define BPMEM_UNKNOWN_61 0x61
-#define BPMEM_UNKNOWN_62 0x62
-#define BPMEM_TEXMODESYNC 0x63
+#define BPMEM_PRELOAD_ADDR 0x60
+#define BPMEM_PRELOAD_TMEMEVEN 0x61
+#define BPMEM_PRELOAD_TMEMODD 0x62
+#define BPMEM_PRELOAD_MODE 0x63
#define BPMEM_LOADTLUT0 0x64
#define BPMEM_LOADTLUT1 0x65
#define BPMEM_TEXINVALIDATE 0x66
@@ -487,10 +487,10 @@ union TexImage1
{
struct
{
- u32 tmem_offset : 15; // we ignore texture caching for now, we do it ourselves
- u32 cache_width : 3;
+ u32 tmem_even : 15; // tmem line index for even LODs
+ u32 cache_width : 3;
u32 cache_height : 3;
- u32 image_type : 1;
+ u32 image_type : 1; // 1 if this texture is managed manually (0 means we'll autofetch the texture data whenever it changes)
};
u32 hex;
};
@@ -499,7 +499,7 @@ union TexImage2
{
struct
{
- u32 tmem_offset : 15; // we ignore texture caching for now, we do it ourselves
+ u32 tmem_odd : 15; // tmem line index for odd LODs
u32 cache_width : 3;
u32 cache_height : 3;
};
@@ -893,6 +893,25 @@ union UPE_Copy
}
};
+union BPU_PreloadTileInfo
+{
+ u32 hex;
+ struct {
+ u32 count : 15;
+ u32 type : 2;
+ };
+};
+
+struct BPS_TmemConfig
+{
+ u32 preload_addr;
+ u32 preload_tmem_even;
+ u32 preload_tmem_odd;
+ BPU_PreloadTileInfo preload_tile_info;
+ u32 tlut_src;
+ u32 tlut_dest;
+ u32 texinvalidate;
+};
// All of BP memory
@@ -951,10 +970,8 @@ struct BPMemory
u32 boundbox1;//56
u32 unknown7[2];//57,58
X10Y10 scissorOffset; //59
- u32 unknown8[10]; //5a,5b,5c,5d, 5e,5f,60,61, 62, 63 (GXTexModeSync), 0x60-0x63 have to do with preloaded textures?
- u32 tlutXferSrc; //64
- u32 tlutXferDest; //65
- u32 texinvalidate;//66
+ u32 unknown8[6]; //5a,5b,5c,5d, 5e,5f
+ BPS_TmemConfig tmem_config; // 60-66
u32 metric; //67
FieldMode fieldmode;//68
u32 unknown10[7];//69-6F
diff --git a/Source/Core/VideoCommon/Src/BPStructs.cpp b/Source/Core/VideoCommon/Src/BPStructs.cpp
index d06f1de8b9..6cb102555b 100644
--- a/Source/Core/VideoCommon/Src/BPStructs.cpp
+++ b/Source/Core/VideoCommon/Src/BPStructs.cpp
@@ -30,6 +30,7 @@
#include "VertexLoader.h"
#include "VertexShaderManager.h"
#include "Thread.h"
+#include "HW/Memmap.h"
using namespace BPFunctions;
@@ -301,14 +302,14 @@ void BPWritten(const BPCmd& bp)
// TODO - figure out a cleaner way.
if (GetConfig(CONFIG_ISWII))
- ptr = GetPointer(bpmem.tlutXferSrc << 5);
+ ptr = GetPointer(bpmem.tmem_config.tlut_src << 5);
else
- ptr = GetPointer((bpmem.tlutXferSrc & 0xFFFFF) << 5);
+ ptr = GetPointer((bpmem.tmem_config.tlut_src & 0xFFFFF) << 5);
if (ptr)
memcpy_gc(texMem + tlutTMemAddr, ptr, tlutXferCount);
else
- PanicAlert("Invalid palette pointer %08x %08x %08x", bpmem.tlutXferSrc, bpmem.tlutXferSrc << 5, (bpmem.tlutXferSrc & 0xFFFFF)<< 5);
+ PanicAlert("Invalid palette pointer %08x %08x %08x", bpmem.tmem_config.tlut_src, bpmem.tmem_config.tlut_src << 5, (bpmem.tmem_config.tlut_src & 0xFFFFF)<< 5);
// TODO(ector) : kill all textures that use this palette
// Not sure if it's a good idea, though. For now, we hash texture palettes
@@ -466,14 +467,22 @@ void BPWritten(const BPCmd& bp)
DEBUG_LOG(VIDEO, "Uknown BP Reg 0x57: %08x", bp.newvalue);
break;
- case BPMEM_UNKNOWN_60:
- case BPMEM_UNKNOWN_61:
- case BPMEM_UNKNOWN_62:
- // Cases added due to: http://code.google.com/p/dolphin-emu/issues/detail?id=360#c90
- // Are these related to BBox?
+ case BPMEM_PRELOAD_ADDR:
+ case BPMEM_PRELOAD_TMEMEVEN:
+ case BPMEM_PRELOAD_TMEMODD: // Used when PRELOAD_MODE is set
break;
- case BPMEM_TEXMODESYNC: // Always set to 0 when GX_TexModeSync() is called.
+ case BPMEM_PRELOAD_MODE: // Set to 0 when GX_TexModeSync() is called.
+ // if this is different from 0, manual TMEM management is used.
+ if (bp.newvalue != 0)
+ {
+ // NOTE(neobrain): Apparently tmemodd doesn't affect hardware behavior at all (libogc uses it just as a buffer and switches its contents with tmemeven whenever this is called)
+ BPS_TmemConfig& tmem_cfg = bpmem.tmem_config;
+ u8* ram_ptr = Memory::GetPointer(tmem_cfg.preload_addr << 5);
+ u32 tmem_addr = tmem_cfg.preload_tmem_even * TMEM_LINE_SIZE;
+ u32 size = tmem_cfg.preload_tile_info.count * 32;
+ memcpy(texMem + tmem_addr, ram_ptr, size);
+ }
break;
// ------------------------------------------------
diff --git a/Source/Core/VideoCommon/Src/CommandProcessor.cpp b/Source/Core/VideoCommon/Src/CommandProcessor.cpp
index 67c8f411fa..fc85b8e39d 100644
--- a/Source/Core/VideoCommon/Src/CommandProcessor.cpp
+++ b/Source/Core/VideoCommon/Src/CommandProcessor.cpp
@@ -311,6 +311,7 @@ void Write16(const u16 _Value, const u32 _Address)
UCPClearReg tmpCtrl(_Value);
m_CPClearReg.Hex = tmpCtrl.Hex;
DEBUG_LOG(COMMANDPROCESSOR,"\t write to CLEAR_REGISTER : %04x", _Value);
+ SetCpClearRegister();
}
break;
@@ -677,13 +678,15 @@ void SetCpControlRegister()
}
+// NOTE: The implementation of this function should be correct, but we intentionally aren't using it at the moment.
+// We don't emulate proper GP timing anyway at the moment, so this code would just slow down emulation.
void SetCpClearRegister()
{
- if (IsOnThread())
- {
- if (!m_CPClearReg.ClearFifoUnderflow && m_CPClearReg.ClearFifoOverflow)
- bProcessFifoToLoWatermark = true;
- }
+// if (IsOnThread())
+// {
+// if (!m_CPClearReg.ClearFifoUnderflow && m_CPClearReg.ClearFifoOverflow)
+// bProcessFifoToLoWatermark = true;
+// }
}
} // end of namespace CommandProcessor
diff --git a/Source/Core/VideoCommon/Src/CommandProcessor.h b/Source/Core/VideoCommon/Src/CommandProcessor.h
index 7fb4e5a45f..db6772d66d 100644
--- a/Source/Core/VideoCommon/Src/CommandProcessor.h
+++ b/Source/Core/VideoCommon/Src/CommandProcessor.h
@@ -158,6 +158,7 @@ void UpdateInterruptsFromVideoBackend(u64 userdata);
bool AllowIdleSkipping();
+void SetCpClearRegister();
void SetCpControlRegister();
void SetCpStatusRegister();
void SetOverflowStatusFromGatherPipe();
diff --git a/Source/Core/VideoCommon/Src/ImageWrite.h b/Source/Core/VideoCommon/Src/ImageWrite.h
index 962ee5b5e7..9ea6cab859 100644
--- a/Source/Core/VideoCommon/Src/ImageWrite.h
+++ b/Source/Core/VideoCommon/Src/ImageWrite.h
@@ -21,7 +21,6 @@
#include "Common.h"
bool SaveTGA(const char* filename, int width, int height, void* pdata);
-bool SaveTexture(const char* filename, u32 textarget, u32 tex, int width, int height);
bool SaveData(const char* filename, const char* pdata);
#endif // _IMAGEWRITE_H
diff --git a/Source/Core/VideoCommon/Src/PixelShaderGen.cpp b/Source/Core/VideoCommon/Src/PixelShaderGen.cpp
index 1726855d54..fe5827de05 100644
--- a/Source/Core/VideoCommon/Src/PixelShaderGen.cpp
+++ b/Source/Core/VideoCommon/Src/PixelShaderGen.cpp
@@ -560,6 +560,10 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType
WRITE(p, "uniform float4 "I_KCOLORS"[4] : register(c%d);\n", C_KCOLORS);
WRITE(p, "uniform float4 "I_ALPHA"[1] : register(c%d);\n", C_ALPHA);
WRITE(p, "uniform float4 "I_TEXDIMS"[8] : register(c%d);\n", C_TEXDIMS);
+ if (ApiType & API_D3D9)
+ {
+ WRITE(p, "uniform float4 "I_VTEXSCALE"[4] : register(c%d);\n", C_VTEXSCALE);
+ }
WRITE(p, "uniform float4 "I_ZBIAS"[2] : register(c%d);\n", C_ZBIAS);
WRITE(p, "uniform float4 "I_INDTEXSCALE"[2] : register(c%d);\n", C_INDTEXSCALE);
WRITE(p, "uniform float4 "I_INDTEXMTX"[6] : register(c%d);\n", C_INDTEXMTX);
@@ -1099,9 +1103,15 @@ static void WriteStage(char *&p, int n, API_TYPE ApiType)
void SampleTexture(char *&p, const char *destination, const char *texcoords, const char *texswap, int texmap, API_TYPE ApiType)
{
if (ApiType == API_D3D11)
- WRITE(p, "%s=Tex%d.Sample(samp%d,%s.xy * "I_TEXDIMS"[%d].xy).%s;\n", destination, texmap,texmap, texcoords, texmap, texswap);
+ WRITE(p, "%s=Tex%d.Sample(samp%d, %s.xy * "I_TEXDIMS"[%d].xy).%s;\n", destination, texmap,texmap, texcoords, texmap, texswap);
+ else if (ApiType & API_D3D9)
+ {
+ // D3D9 uses different pixel to texel mapping, so we need to offset our sampling address by half a pixel (assuming native and virtual texture dimensions match each other, otherwise some math is involved).
+ // Read the MSDN article "Directly Mapping Texels to Pixels (Direct3D 9)" for further info.
+ WRITE(p, "%s=tex2D(samp%d, (%s.xy + 0.5f*"I_VTEXSCALE"[%d].%s) * "I_TEXDIMS"[%d].xy).%s;\n", destination, texmap, texcoords, texmap/2, (texmap&1)?"zw":"xy", texmap, texswap);
+ }
else
- WRITE(p, "%s=tex2D(samp%d,%s.xy * "I_TEXDIMS"[%d].xy).%s;\n", destination, texmap, texcoords, texmap, texswap);
+ WRITE(p, "%s=tex2D(samp%d, %s.xy * "I_TEXDIMS"[%d].xy).%s;\n", destination, texmap, texcoords, texmap, texswap);
}
static const char *tevAlphaFuncsTable[] =
diff --git a/Source/Core/VideoCommon/Src/PixelShaderGen.h b/Source/Core/VideoCommon/Src/PixelShaderGen.h
index 31242a916e..7374251c96 100644
--- a/Source/Core/VideoCommon/Src/PixelShaderGen.h
+++ b/Source/Core/VideoCommon/Src/PixelShaderGen.h
@@ -24,26 +24,27 @@
#define I_KCOLORS "k"
#define I_ALPHA "alphaRef"
#define I_TEXDIMS "texdim"
+#define I_VTEXSCALE "vtexscale"
#define I_ZBIAS "czbias"
#define I_INDTEXSCALE "cindscale"
#define I_INDTEXMTX "cindmtx"
#define I_FOG "cfog"
#define I_PLIGHTS "cLights"
-#define I_PMATERIALS "cmtrl"
+#define I_PMATERIALS "cmtrl"
#define C_COLORMATRIX 0 // 0
#define C_COLORS 0 // 0
#define C_KCOLORS (C_COLORS + 4) // 4
#define C_ALPHA (C_KCOLORS + 4) // 8
#define C_TEXDIMS (C_ALPHA + 1) // 9
-#define C_ZBIAS (C_TEXDIMS + 8) //17
-#define C_INDTEXSCALE (C_ZBIAS + 2) //19
-#define C_INDTEXMTX (C_INDTEXSCALE + 2) //21
-#define C_FOG (C_INDTEXMTX + 6) //27
-
-#define C_PLIGHTS (C_FOG + 3)
-#define C_PMATERIALS (C_PLIGHTS + 40)
-#define C_PENVCONST_END (C_PMATERIALS + 4)
+#define C_VTEXSCALE (C_TEXDIMS + 8) //17 - virtual texture scaling factor (e.g. custom textures, scaled EFB copies)
+#define C_ZBIAS (C_VTEXSCALE + 4) //21
+#define C_INDTEXSCALE (C_ZBIAS + 2) //23
+#define C_INDTEXMTX (C_INDTEXSCALE + 2) //25
+#define C_FOG (C_INDTEXMTX + 6) //31
+#define C_PLIGHTS (C_FOG + 3) //34
+#define C_PMATERIALS (C_PLIGHTS + 40) //74
+#define C_PENVCONST_END (C_PMATERIALS + 4) //78
#define PIXELSHADERUID_MAX_VALUES 70
#define PIXELSHADERUID_MAX_VALUES_SAFE 120
diff --git a/Source/Core/VideoCommon/Src/PixelShaderManager.cpp b/Source/Core/VideoCommon/Src/PixelShaderManager.cpp
index 2521f80500..3e0f6d73c4 100644
--- a/Source/Core/VideoCommon/Src/PixelShaderManager.cpp
+++ b/Source/Core/VideoCommon/Src/PixelShaderManager.cpp
@@ -36,9 +36,11 @@ static bool s_bFogRangeAdjustChanged;
static int nLightsChanged[2]; // min,max
static float lastRGBAfull[2][4][4];
static u8 s_nTexDimsChanged;
+static u8 s_nVirtualTexScalesChanged;
static u8 s_nIndTexScaleChanged;
static u32 lastAlpha;
static u32 lastTexDims[8]; // width | height << 16 | wrap_s << 28 | wrap_t << 30
+static float lastVirtualTexScales[16]; // even fields: width ratio; odd fields: height ratio
static u32 lastZBias;
static int nMaterialsChanged;
@@ -61,6 +63,7 @@ void PixelShaderManager::Init()
{
lastAlpha = 0;
memset(lastTexDims, 0, sizeof(lastTexDims));
+ memset(lastVirtualTexScales, 0, sizeof(lastVirtualTexScales));
lastZBias = 0;
memset(lastRGBAfull, 0, sizeof(lastRGBAfull));
Dirty();
@@ -70,6 +73,7 @@ void PixelShaderManager::Dirty()
{
s_nColorsChanged[0] = s_nColorsChanged[1] = 15;
s_nTexDimsChanged = 0xFF;
+ s_nVirtualTexScalesChanged = 0xFF;
s_nIndTexScaleChanged = 0xFF;
s_nIndTexMtxChanged = 15;
s_bAlphaChanged = s_bZBiasChanged = s_bZTextureTypeChanged = s_bDepthRangeChanged = true;
@@ -83,7 +87,7 @@ void PixelShaderManager::Shutdown()
}
-void PixelShaderManager::SetConstants()
+void PixelShaderManager::SetConstants(API_TYPE api_type)
{
for (int i = 0; i < 2; ++i)
{
@@ -109,6 +113,16 @@ void PixelShaderManager::SetConstants()
s_nTexDimsChanged = 0;
}
+ if ((api_type & API_D3D9) && s_nVirtualTexScalesChanged)
+ {
+ for (int i = 0; i < 8; i += 2)
+ {
+ if (s_nVirtualTexScalesChanged & (3<<i))
+ SetPSVirtualTexScalePair(i/2);
+ }
+ s_nVirtualTexScalesChanged = 0;
+ }
+
if (s_bAlphaChanged)
{
SetPSConstant4f(C_ALPHA, (lastAlpha&0xff)/255.0f, ((lastAlpha>>8)&0xff)/255.0f, 0, ((lastAlpha>>16)&0xff)/255.0f);
@@ -338,6 +352,13 @@ void PixelShaderManager::SetPSTextureDims(int texid)
SetPSConstant4fv(C_TEXDIMS + texid, fdims);
}
+void PixelShaderManager::SetPSVirtualTexScalePair(int texpairid)
+{
+ PRIM_LOG("vtexscale%d: %f %f %f %f\n", texpairid, lastVirtualTexScales[texpairid*4], lastVirtualTexScales[texpairid*4+1],
+ lastVirtualTexScales[texpairid*4+2], lastVirtualTexScales[texpairid*4+3]);
+ SetPSConstant4fv(C_VTEXSCALE + texpairid, &lastVirtualTexScales[texpairid*4]);
+}
+
// This one is high in profiles (0.5%). TODO: Move conversion out, only store the raw color value
// and update it when the shader constant is set, only.
void PixelShaderManager::SetColorChanged(int type, int num, bool high)
@@ -376,14 +397,25 @@ void PixelShaderManager::SetDestAlpha(const ConstantAlpha& alpha)
}
}
-void PixelShaderManager::SetTexDims(int texmapid, u32 width, u32 height, u32 wraps, u32 wrapt)
+void PixelShaderManager::SetTexDims(int texmapid, u32 width, u32 height, u32 virtual_width, u32 virtual_height, u32 wraps, u32 wrapt, API_TYPE api_type)
{
u32 wh = width | (height << 16) | (wraps << 28) | (wrapt << 30);
- if (lastTexDims[texmapid] != wh)
+
+ bool refresh = lastTexDims[texmapid] != wh;
+ if (api_type & API_D3D9)
{
- lastTexDims[texmapid] = wh;
+ refresh |= (lastVirtualTexScales[texmapid*2] != (float)width / (float)virtual_width);
+ refresh |= (lastVirtualTexScales[texmapid*2+1] != (float)height / (float)virtual_height);
+ }
+
+ if (refresh)
+ {
+ lastTexDims[texmapid] = wh;
+ lastVirtualTexScales[texmapid*2] = (float)width / (float)virtual_width;
+ lastVirtualTexScales[texmapid*2+1] = (float)height / (float)virtual_height;
s_nTexDimsChanged |= 1 << texmapid;
- }
+ s_nVirtualTexScalesChanged |= 1 << texmapid;
+ }
}
void PixelShaderManager::SetZTextureBias(u32 bias)
diff --git a/Source/Core/VideoCommon/Src/PixelShaderManager.h b/Source/Core/VideoCommon/Src/PixelShaderManager.h
index 2d1c01cad6..5cbe86cae4 100644
--- a/Source/Core/VideoCommon/Src/PixelShaderManager.h
+++ b/Source/Core/VideoCommon/Src/PixelShaderManager.h
@@ -26,18 +26,20 @@
class PixelShaderManager
{
static void SetPSTextureDims(int texid);
+ static void SetPSVirtualTexScalePair(int texpairid);
+
public:
static void Init();
static void Dirty();
static void Shutdown();
- static void SetConstants(); // sets pixel shader constants
+ static void SetConstants(API_TYPE api_type); // sets pixel shader constants
// constant management, should be called after memory is committed
static void SetColorChanged(int type, int index, bool high);
static void SetAlpha(const AlphaFunc& alpha);
static void SetDestAlpha(const ConstantAlpha& alpha);
- static void SetTexDims(int texmapid, u32 width, u32 height, u32 wraps, u32 wrapt);
+ static void SetTexDims(int texmapid, u32 width, u32 height, u32 virtual_width, u32 virtual_height, u32 wraps, u32 wrapt, API_TYPE api_type);
static void SetZTextureBias(u32 bias);
static void SetViewportChanged();
static void SetIndMatrixChanged(int matrixidx);
diff --git a/Source/Core/VideoCommon/Src/TextureCacheBase.cpp b/Source/Core/VideoCommon/Src/TextureCacheBase.cpp
index 3550227389..cc14499330 100644
--- a/Source/Core/VideoCommon/Src/TextureCacheBase.cpp
+++ b/Source/Core/VideoCommon/Src/TextureCacheBase.cpp
@@ -1,3 +1,19 @@
+// Copyright (C) 2003 Dolphin Project.
+
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, version 2.0.
+
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License 2.0 for more details.
+
+// A copy of the GPL 2.0 should have been included with the program.
+// If not, see http://www.gnu.org/licenses/
+
+// Official SVN repository and contact information can be found at
+// http://code.google.com/p/dolphin-emu/
#include "MemoryUtil.h"
@@ -23,28 +39,19 @@ enum
TextureCache *g_texture_cache;
- GC_ALIGNED16(u8 *TextureCache::temp) = NULL;
+GC_ALIGNED16(u8 *TextureCache::temp) = NULL;
TextureCache::TexCache TextureCache::textures;
bool TextureCache::DeferredInvalidate;
TextureCache::TCacheEntryBase::~TCacheEntryBase()
{
- if (0 == addr)
- return;
-
- if (!isRenderTarget && !g_ActiveConfig.bSafeTextureCache)
- {
- u32 *const ptr = (u32*)Memory::GetPointer(addr);
- if (ptr && *ptr == hash)
- *ptr = oldpixel;
- }
}
TextureCache::TextureCache()
{
if (!temp)
- temp =(u8*) AllocateAlignedMemory(TEMP_SIZE,16);
+ temp = (u8*)AllocateAlignedMemory(TEMP_SIZE,16);
TexDecoder_SetTexFmtOverlayOptions(g_ActiveConfig.bTexFmtOverlayEnable, g_ActiveConfig.bTexFmtOverlayCenter);
if(g_ActiveConfig.bHiresTextures && !g_ActiveConfig.bDumpTextures)
HiresTextures::Init(SConfig::GetInstance().m_LocalCoreStartupParameter.m_strUniqueID.c_str());
@@ -88,12 +95,11 @@ TextureCache::~TextureCache()
void TextureCache::Cleanup()
{
- TexCache::iterator
- iter = textures.begin(),
- tcend = textures.end();
+ TexCache::iterator iter = textures.begin();
+ TexCache::iterator tcend = textures.end();
while (iter != tcend)
{
- if (frameCount > TEXTURE_KILL_THRESHOLD + iter->second->frameCount)
+ if (frameCount > TEXTURE_KILL_THRESHOLD + iter->second->frameCount) // TODO: Deleting EFB copies might not be a good idea here...
{
delete iter->second;
textures.erase(iter++);
@@ -135,7 +141,7 @@ void TextureCache::MakeRangeDynamic(u32 start_address, u32 size)
const int rangePosition = iter->second->IntersectsMemoryRange(start_address, size);
if (0 == rangePosition)
{
- iter->second->hash = 0;
+ iter->second->SetHashes(TEXHASH_INVALID);
}
}
}
@@ -167,19 +173,16 @@ void TextureCache::ClearRenderTargets()
iter = textures.begin(),
tcend = textures.end();
for (; iter!=tcend; ++iter)
- iter->second->isRenderTarget = false;
+ iter->second->type = TCET_NORMAL;
}
TextureCache::TCacheEntryBase* TextureCache::Load(unsigned int stage,
u32 address, unsigned int width, unsigned int height, int texformat,
- unsigned int tlutaddr, int tlutfmt, bool UseNativeMips, unsigned int maxlevel)
+ unsigned int tlutaddr, int tlutfmt, bool UseNativeMips, unsigned int maxlevel, bool from_tmem)
{
- // necessary?
if (0 == address)
return NULL;
- u8* ptr = Memory::GetPointer(address);
-
// TexelSizeInNibbles(format)*width*height/16;
const unsigned int bsw = TexDecoder_GetBlockWidthInTexels(texformat) - 1;
const unsigned int bsh = TexDecoder_GetBlockHeightInTexels(texformat) - 1;
@@ -188,111 +191,82 @@ TextureCache::TCacheEntryBase* TextureCache::Load(unsigned int stage,
unsigned int expandedHeight = (height + bsh) & (~bsh);
const unsigned int nativeW = width;
const unsigned int nativeH = height;
- bool isPow2;
- u64 hash_value = 0;
- u64 texHash = 0;
u32 texID = address;
+ u64 tex_hash = TEXHASH_INVALID; // Hash assigned to texcache entry (also used to generate filenames used for texture dumping and custom texture lookup)
+ u64 tlut_hash = TEXHASH_INVALID;
+
u32 full_format = texformat;
- const u32 texture_size = TexDecoder_GetTextureSizeInBytes(expandedWidth, expandedHeight, texformat);
- const u32 palette_size = TexDecoder_GetPaletteSize(texformat);
- bool texture_is_dynamic = false;
- unsigned int texLevels;
PC_TexFormat pcfmt = PC_TEX_FMT_NONE;
const bool isPaletteTexture = (texformat == GX_TF_C4 || texformat == GX_TF_C8 || texformat == GX_TF_C14X2);
-
if (isPaletteTexture)
full_format = texformat | (tlutfmt << 16);
- // hires texture loading and texture dumping require accurate hashes
- if (g_ActiveConfig.bSafeTextureCache || g_ActiveConfig.bHiresTextures || g_ActiveConfig.bDumpTextures)
- {
- texHash = GetHash64(ptr, texture_size, g_ActiveConfig.iSafeTextureCache_ColorSamples);
-
- if (isPaletteTexture)
- {
- // WARNING! texID != address now => may break CopyRenderTargetToTexture (cf. TODO up)
- // tlut size can be up to 32768B (GX_TF_C14X2) but Safer == Slower.
- // This trick (to change the texID depending on the TLUT addr) is a trick to get around
- // an issue with metroid prime's fonts, where it has multiple sets of fonts on top of
- // each other stored in a single texture, and uses the palette to make different characters
- // visible or invisible. Thus, unless we want to recreate the textures for every drawn character,
- // we must make sure that texture with different tluts get different IDs.
-
- const u64 tlutHash = GetHash64(texMem + tlutaddr, palette_size,
- g_ActiveConfig.iSafeTextureCache_ColorSamples);
-
- texHash ^= tlutHash;
-
- if (g_ActiveConfig.bSafeTextureCache)
- texID ^= ((u32)tlutHash) ^ (u32)(tlutHash >> 32);
- }
+ const u32 texture_size = TexDecoder_GetTextureSizeInBytes(expandedWidth, expandedHeight, texformat);
+ u8* src_data;
+ if (from_tmem) src_data = &texMem[bpmem.tex[stage/4].texImage1[stage%4].tmem_even * TMEM_LINE_SIZE];
+ else src_data = Memory::GetPointer(address);
- if (g_ActiveConfig.bSafeTextureCache)
- hash_value = texHash;
+ tex_hash = GetHash64(src_data, texture_size, g_ActiveConfig.iSafeTextureCache_ColorSamples);
+ if (isPaletteTexture)
+ {
+ const u32 palette_size = TexDecoder_GetPaletteSize(texformat);
+ tlut_hash = GetHash64(&texMem[tlutaddr], palette_size, g_ActiveConfig.iSafeTextureCache_ColorSamples);
+
+ // NOTE: For non-paletted textures, texID is equal to the texture address.
+ // A paletted texture, however, may have multiple texIDs assigned though depending on the currently used tlut.
+ // This (changing texID depending on the tlut_hash) is a trick to get around
+ // an issue with Metroid Prime's fonts (it has multiple sets of fonts on each other
+ // stored in a single texture and uses the palette to make different characters
+ // visible or invisible. Thus, unless we want to recreate the textures for every drawn character,
+ // we must make sure that a paletted texture gets assigned multiple IDs for each tlut used.
+ //
+ // TODO: Because texID isn't always the same as the address now, CopyRenderTargetToTexture might be broken now
+ texID ^= ((u32)tlut_hash) ^(u32)(tlut_hash >> 32);
+ tex_hash ^= tlut_hash;
}
TCacheEntryBase *entry = textures[texID];
if (entry)
{
- if (!g_ActiveConfig.bSafeTextureCache)
- {
- if (entry->isRenderTarget || entry->isDynamic)
- {
- if (!g_ActiveConfig.bCopyEFBToTexture)
- {
- hash_value = GetHash64(ptr, texture_size, g_ActiveConfig.iSafeTextureCache_ColorSamples);
+ // 1. Calculate reference hash:
+ // calculated from RAM texture data for normal textures. Hashes for paletted textures are modified by tlut_hash. 0 for virtual EFB copies.
+ if (g_ActiveConfig.bCopyEFBToTexture && entry->IsEfbCopy())
+ tex_hash = TEXHASH_INVALID;
- if (isPaletteTexture)
- {
- hash_value ^= GetHash64(&texMem[tlutaddr], palette_size,
- g_ActiveConfig.iSafeTextureCache_ColorSamples);
- }
- }
- else
- {
- hash_value = 0;
- }
- }
- else
- {
- hash_value = *(u32*)ptr;
- }
- }
- else if ((entry->isRenderTarget || entry->isDynamic) && g_ActiveConfig.bCopyEFBToTexture)
+ // 2. a) For EFB copies, only the hash and the texture address need to match
+ if (entry->IsEfbCopy() && tex_hash == entry->hash && address == entry->addr)
{
- hash_value = 0;
+ // TODO: Print a warning if the format changes! In this case, we could reinterpret the internal texture object data to the new pixel format (similiar to what is already being done in Renderer::ReinterpretPixelFormat())
+ goto return_entry;
}
- if (((entry->isRenderTarget || entry->isDynamic) && hash_value == entry->hash && address == entry->addr)
- || ((address == entry->addr) && (hash_value == entry->hash) && full_format == entry->format && entry->mipLevels == maxlevel))
+ // 2. b) For normal textures, all texture parameters need to match
+ if (address == entry->addr && tex_hash == entry->hash && full_format == entry->format &&
+ entry->num_mipmaps == maxlevel && entry->native_width == nativeW && entry->native_height == nativeH)
{
- entry->isDynamic = false;
goto return_entry;
}
+
+ // 3. If we reach this line, we'll have to upload the new texture data to VRAM.
+ // If we're lucky, the texture parameters didn't change and we can reuse the internal texture object instead of destroying and recreating it.
+ //
+ // TODO: Don't we need to force texture decoding to RGBA8 for dynamic EFB copies?
+ // TODO: Actually, it should be enough if the internal texture format matches...
+ if ((entry->type == TCET_NORMAL && width == entry->native_width && height == entry->native_height && full_format == entry->format && entry->num_mipmaps == maxlevel)
+ || (entry->type == TCET_EC_DYNAMIC && entry->native_width == width && entry->native_height == height))
+ {
+ // reuse the texture
+ }
else
{
- // Let's reload the new texture data into the same texture,
- // instead of destroying it and having to create a new one.
- // Might speed up movie playback very, very slightly.
- texture_is_dynamic = (entry->isRenderTarget || entry->isDynamic) && !g_ActiveConfig.bCopyEFBToTexture;
-
- if (!entry->isRenderTarget &&
- ((!entry->isDynamic && width == entry->realW && height == entry->realH && full_format == entry->format && entry->mipLevels == maxlevel)
- || (entry->isDynamic && entry->realW == width && entry->realH == height)))
- {
- // reuse the texture
- }
- else
- {
- // delete the texture and make a new one
- delete entry;
- entry = NULL;
- }
+ // delete the texture and make a new one
+ delete entry;
+ entry = NULL;
}
}
-
+
if (g_ActiveConfig.bHiresTextures)
{
// Load Custom textures
@@ -301,23 +275,24 @@ TextureCache::TCacheEntryBase* TextureCache::Load(unsigned int stage,
unsigned int newWidth = width;
unsigned int newHeight = height;
- sprintf(texPathTemp, "%s_%08x_%i", SConfig::GetInstance().m_LocalCoreStartupParameter.m_strUniqueID.c_str(), (u32) (texHash & 0x00000000FFFFFFFFLL), texformat);
+ sprintf(texPathTemp, "%s_%08x_%i", SConfig::GetInstance().m_LocalCoreStartupParameter.m_strUniqueID.c_str(), (u32) (tex_hash & 0x00000000FFFFFFFFLL), texformat);
pcfmt = HiresTextures::GetHiresTex(texPathTemp, &newWidth, &newHeight, texformat, temp);
if (pcfmt != PC_TEX_FMT_NONE)
{
expandedWidth = width = newWidth;
expandedHeight = height = newHeight;
-
- // TODO: shouldn't generating mips be forced on now?
- // native mips with a custom texture wouldn't make sense
}
}
+ // TODO: RGBA8 textures are stored non-continuously in tmem, that might cause problems when preloading is enabled
if (pcfmt == PC_TEX_FMT_NONE)
- pcfmt = TexDecoder_Decode(temp, ptr, expandedWidth,
- expandedHeight, texformat, tlutaddr, tlutfmt, g_ActiveConfig.backend_info.bUseRGBATextures);
+ pcfmt = TexDecoder_Decode(temp, src_data, expandedWidth,
+ expandedHeight, texformat, tlutaddr, tlutfmt, g_ActiveConfig.backend_info.bUseRGBATextures);
+ bool isPow2;
+ unsigned int texLevels;
+ UseNativeMips = UseNativeMips && (width == nativeW && height == nativeH); // Only load native mips if their dimensions fit to our virtual texture dimensions
isPow2 = !((width & (width - 1)) || (height & (height - 1)));
texLevels = (isPow2 && UseNativeMips && maxlevel) ?
GetPow2(std::max(width, height)) : !isPow2;
@@ -329,40 +304,27 @@ TextureCache::TCacheEntryBase* TextureCache::Load(unsigned int stage,
if (NULL == entry) {
textures[texID] = entry = g_texture_cache->CreateTexture(width, height, expandedWidth, texLevels, pcfmt);
- // Sometimes, we can get around recreating a texture if only the number of mip levels gets changes
+ // Sometimes, we can get around recreating a texture if only the number of mip levels changes
// e.g. if our texture cache entry got too many mipmap levels we can limit the number of used levels by setting the appropriate render states
// Thus, we don't update this member for every Load, but just whenever the texture gets recreated
- entry->mipLevels = maxlevel;
+ //
+ // TODO: Won't we end up recreating textures all the time because maxlevel doesn't necessarily equal texLevels?
+ entry->num_mipmaps = maxlevel; // TODO: Does this actually work? We can't really adjust mipmap settings per-stage...
+ entry->type = TCET_NORMAL;
GFX_DEBUGGER_PAUSE_AT(NEXT_NEW_TEXTURE, true);
}
- entry->addr = address;
- entry->format = full_format;
- entry->size_in_bytes = texture_size;
-
- entry->virtualW = width;
- entry->virtualH = height;
-
- entry->realW = nativeW;
- entry->realH = nativeH;
-
- entry->isRenderTarget = false;
- entry->isNonPow2 = false;
- entry->isDynamic = texture_is_dynamic;
-
- entry->oldpixel = *(u32*)ptr;
-
- if (g_ActiveConfig.bSafeTextureCache || entry->isDynamic)
- entry->hash = hash_value;
- else
- // don't like rand() here
- entry->hash = *(u32*)ptr = (u32)(((double)rand() / RAND_MAX) * 0xFFFFFFFF);
+ entry->SetGeneralParameters(address, texture_size, full_format, entry->num_mipmaps);
+ entry->SetDimensions(nativeW, nativeH, width, height);
+ entry->hash = tex_hash;
+ if (g_ActiveConfig.bCopyEFBToTexture) entry->type = TCET_NORMAL;
+ else if (entry->IsEfbCopy()) entry->type = TCET_EC_DYNAMIC;
// load texture
entry->Load(width, height, expandedWidth, 0, (texLevels == 0));
- // load mips
+ // load mips - TODO: Loading mipmaps from tmem is untested!
if (texLevels > 1 && pcfmt != PC_TEX_FMT_NONE)
{
const unsigned int bsdepth = TexDecoder_GetTexelSizeInNibbles(texformat);
@@ -370,20 +332,31 @@ TextureCache::TCacheEntryBase* TextureCache::Load(unsigned int stage,
unsigned int level = 1;
unsigned int mipWidth = (width + 1) >> 1;
unsigned int mipHeight = (height + 1) >> 1;
- ptr += texture_size;
+
+ u8* ptr_even = NULL, *ptr_odd = NULL;
+ if (from_tmem)
+ {
+ ptr_even = &texMem[bpmem.tex[stage/4].texImage1[stage%4].tmem_even * TMEM_LINE_SIZE + texture_size];
+ ptr_odd = &texMem[bpmem.tex[stage/4].texImage2[stage%4].tmem_odd * TMEM_LINE_SIZE];
+ }
+ src_data += texture_size;
while ((mipHeight || mipWidth) && (level < texLevels))
{
+ u8** ptr;
+ if (from_tmem) ptr = (level % 2) ? &ptr_odd : &ptr_even;
+ else ptr = &src_data;
+
const unsigned int currentWidth = (mipWidth > 0) ? mipWidth : 1;
const unsigned int currentHeight = (mipHeight > 0) ? mipHeight : 1;
expandedWidth = (currentWidth + bsw) & (~bsw);
expandedHeight = (currentHeight + bsh) & (~bsh);
- TexDecoder_Decode(temp, ptr, expandedWidth, expandedHeight, texformat, tlutaddr, tlutfmt, g_ActiveConfig.backend_info.bUseRGBATextures);
- entry->Load(currentWidth, currentHeight, expandedWidth, level);
+ TexDecoder_Decode(temp, *ptr, expandedWidth, expandedHeight, texformat, tlutaddr, tlutfmt, g_ActiveConfig.backend_info.bUseRGBATextures);
+ entry->Load(currentWidth, currentHeight, expandedWidth, level, false);
- ptr += ((std::max(mipWidth, bsw) * std::max(mipHeight, bsh) * bsdepth) >> 1);
+ *ptr += ((std::max(mipWidth, bsw) * std::max(mipHeight, bsh) * bsdepth) >> 1);
mipWidth >>= 1;
mipHeight >>= 1;
++level;
@@ -404,7 +377,7 @@ TextureCache::TCacheEntryBase* TextureCache::Load(unsigned int stage,
sprintf(szTemp, "%s/%s_%08x_%i.png", szDir.c_str(),
SConfig::GetInstance().m_LocalCoreStartupParameter.m_strUniqueID.c_str(),
- (u32) (texHash & 0x00000000FFFFFFFFLL), texformat);
+ (u32) (tex_hash & 0x00000000FFFFFFFFLL), texformat);
if (false == File::Exists(szTemp))
entry->Save(szTemp);
@@ -426,6 +399,45 @@ return_entry:
void TextureCache::CopyRenderTargetToTexture(u32 dstAddr, unsigned int dstFormat, unsigned int srcFormat,
const EFBRectangle& srcRect, bool isIntensity, bool scaleByHalf)
{
+ // Emulation methods:
+ // - EFB to RAM:
+ // Encodes the requested EFB data at its native resolution to the emulated RAM using shaders.
+ // Load() decodes the data from there again (using TextureDecoder) if the EFB copy is being used as a texture again.
+ // Advantage: CPU can read data from the EFB copy and we don't lose any important updates to the texture
+ // Disadvantage: Encoding+decoding steps often are redundant because only some games read or modify EFB copies before using them as textures.
+ // - EFB to texture:
+ // Copies the requested EFB data to a texture object in VRAM, performing any color conversion using shaders.
+ // Advantage: Works for many games, since in most cases EFB copies aren't read or modified at all before being used as a texture again.
+ // Since we don't do any further encoding or decoding here, this method is much faster.
+ // It also allows enhancing the visual quality by doing scaled EFB copies.
+ // - hybrid EFB copies:
+ // 1a) Whenever this function gets called, encode the requested EFB data to RAM (like EFB to RAM)
+ // 1b) Set type to TCET_EC_DYNAMIC for all texture cache entries in the destination address range.
+ // If EFB copy caching is enabled, further checks will (try to) prevent redundant EFB copies.
+ // 2) Check if a texture cache entry for the specified dstAddr already exists (i.e. if an EFB copy was triggered to that address before):
+ // 2a) Entry doesn't exist:
+ // - Also copy the requested EFB data to a texture object in VRAM (like EFB to texture)
+ // - Create a texture cache entry for the target (type = TCET_EC_VRAM)
+ // - Store a hash of the encoded RAM data in the texcache entry.
+ // 2b) Entry exists AND type is TCET_EC_VRAM:
+ // - Like case 2a, but reuse the old texcache entry instead of creating a new one.
+ // 2c) Entry exists AND type is TCET_EC_DYNAMIC:
+ // - Only encode the texture to RAM (like EFB to RAM) and store a hash of the encoded data in the existing texcache entry.
+ // - Do NOT copy the requested EFB data to a VRAM object. Reason: the texture is dynamic, i.e. the CPU is modifying it. Storing a VRAM copy is useless, because we'd always end up deleting it and reloading the data from RAM anyway.
+ // 3) If the EFB copy gets used as a texture, compare the source RAM hash with the hash you stored when encoding the EFB data to RAM.
+ // 3a) If the two hashes match AND type is TCET_EC_VRAM, reuse the VRAM copy you created
+ // 3b) If the two hashes differ AND type is TCET_EC_VRAM, screw your existing VRAM copy. Set type to TCET_EC_DYNAMIC.
+ // Redecode the source RAM data to a VRAM object. The entry basically behaves like a normal texture now.
+ // 3c) If type is TCET_EC_DYNAMIC, treat the EFB copy like a normal texture.
+ // Advantage: Non-dynamic EFB copies can be visually enhanced like with EFB to texture.
+ // Compatibility is as good as EFB to RAM.
+ // Disadvantage: Slower than EFB to texture and often even slower than EFB to RAM.
+ // EFB copy cache depends on accurate texture hashing being enabled. However, with accurate hashing you end up being as slow as without a copy cache anyway.
+ //
+ // Disadvantage of all methods: Calling this function requires the GPU to perform a pipeline flush which stalls any further CPU processing.
+ //
+ // For historical reasons, Dolphin doesn't actually implement "pure" EFB to RAM emulation, but only EFB to texture and hybrid EFB copies.
+
float colmat[28] = {0};
float *const fConstAdd = colmat + 16;
float *const ColorMask = colmat + 20;
@@ -472,9 +484,9 @@ void TextureCache::CopyRenderTargetToTexture(u32 dstAddr, unsigned int dstFormat
cbufid = 5;
break;
- case 12: // Z16L - copy lower 16 depth bits
- // expected to be used as an IA8 texture (upper 8 bits stored as intensity, lower 8 bits stored as alpha)
- // Used e.g. in Zelda: Skyward Sword
+ case 12: // Z16L - copy lower 16 depth bits
+ // expected to be used as an IA8 texture (upper 8 bits stored as intensity, lower 8 bits stored as alpha)
+ // Used e.g. in Zelda: Skyward Sword
colmat[1] = colmat[5] = colmat[9] = colmat[14] = 1.0f;
cbufid = 6;
break;
@@ -628,15 +640,15 @@ void TextureCache::CopyRenderTargetToTexture(u32 dstAddr, unsigned int dstFormat
unsigned int scaled_tex_w = g_ActiveConfig.bCopyEFBScaled ? Renderer::EFBToScaledX(tex_w) : tex_w;
unsigned int scaled_tex_h = g_ActiveConfig.bCopyEFBScaled ? Renderer::EFBToScaledY(tex_h) : tex_h;
- bool texture_is_dynamic = false;
TCacheEntryBase *entry = textures[dstAddr];
if (entry)
{
- if ((entry->isRenderTarget && entry->virtualW == scaled_tex_w && entry->virtualH == scaled_tex_h)
- || (entry->isDynamic && entry->realW == tex_w && entry->realH == tex_h))
+ if ((entry->type == TCET_EC_VRAM && entry->virtual_width == scaled_tex_w && entry->virtual_height == scaled_tex_h)
+ || (entry->type == TCET_EC_DYNAMIC && entry->native_width == tex_w && entry->native_height == tex_h))
{
- texture_is_dynamic = entry->isDynamic;
+ scaled_tex_w = tex_w;
+ scaled_tex_h = tex_h;
}
else
{
@@ -646,32 +658,16 @@ void TextureCache::CopyRenderTargetToTexture(u32 dstAddr, unsigned int dstFormat
}
}
- if (texture_is_dynamic)
- {
- scaled_tex_w = tex_w;
- scaled_tex_h = tex_h;
- }
-
if (NULL == entry)
{
// create the texture
textures[dstAddr] = entry = g_texture_cache->CreateRenderTargetTexture(scaled_tex_w, scaled_tex_h);
- entry->addr = dstAddr;
- entry->hash = 0;
-
- entry->realW = tex_w;
- entry->realH = tex_h;
-
- entry->virtualW = scaled_tex_w;
- entry->virtualH = scaled_tex_h;
-
- entry->format = dstFormat;
- entry->mipLevels = 0;
-
- entry->isRenderTarget = true;
- entry->isNonPow2 = true;
- entry->isDynamic = false;
+ // TODO: Using the wrong dstFormat, dumb...
+ entry->SetGeneralParameters(dstAddr, 0, dstFormat, 0);
+ entry->SetDimensions(tex_w, tex_h, scaled_tex_w, scaled_tex_h);
+ entry->SetHashes(TEXHASH_INVALID);
+ entry->type = TCET_EC_VRAM;
}
entry->frameCount = frameCount;
diff --git a/Source/Core/VideoCommon/Src/TextureCacheBase.h b/Source/Core/VideoCommon/Src/TextureCacheBase.h
index 1c86e64006..2924c5871f 100644
--- a/Source/Core/VideoCommon/Src/TextureCacheBase.h
+++ b/Source/Core/VideoCommon/Src/TextureCacheBase.h
@@ -1,3 +1,19 @@
+// Copyright (C) 2003 Dolphin Project.
+
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, version 2.0.
+
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License 2.0 for more details.
+
+// A copy of the GPL 2.0 should have been included with the program.
+// If not, see http://www.gnu.org/licenses/
+
+// Official SVN repository and contact information can be found at
+// http://code.google.com/p/dolphin-emu/
#ifndef _TEXTURECACHEBASE_H
#define _TEXTURECACHEBASE_H
@@ -14,47 +30,56 @@
class TextureCache
{
public:
+ enum TexCacheEntryType
+ {
+ TCET_NORMAL,
+ TCET_EC_VRAM, // EFB copy which sits in VRAM and is ready to be used
+ TCET_EC_DYNAMIC, // EFB copy which sits in RAM and needs to be decoded before being used
+ };
+
struct TCacheEntryBase
{
- // TODO: organize
+#define TEXHASH_INVALID 0
+
+ // common members
u32 addr;
u32 size_in_bytes;
u64 hash;
- //u32 paletteHash;
- u32 oldpixel;
+ //u32 pal_hash;
u32 format;
-
+
+ enum TexCacheEntryType type;
+
+ unsigned int num_mipmaps;
+ unsigned int native_width, native_height; // Texture dimensions from the GameCube's point of view
+ unsigned int virtual_width, virtual_height; // Texture dimensions from OUR point of view - for hires textures or scaled EFB copies
+
+ // used to delete textures which haven't been used for TEXTURE_KILL_THRESHOLD frames
int frameCount;
- unsigned int realW, realH; // Texture dimensions from the GameCube's point of view
- unsigned int virtualW, virtualH; // Texture dimensions from OUR point of view
- // Real and virtual dimensions are usually the same, but may be
- // different if e.g. we use high-res textures. Then, realW,realH will
- // be the dimensions of the original GameCube texture and
- // virtualW,virtualH will be the dimensions of the high-res texture.
-
- unsigned int mipLevels;
-
- bool isRenderTarget; // copied from EFB
- bool isDynamic; // Used for hybrid EFB copies to enable checks for CPU modifications
- bool isNonPow2; // doesn't seem to be used anywhere
-
- //TCacheEntryBase()
- //{
- // // TODO: remove these
- // isRenderTarget = 0;
- // hash = 0;
- // //paletteHash = 0;
- // oldpixel = 0;
- // addr = 0;
- // size_in_bytes = 0;
- // frameCount = 0;
- // isNonPow2 = true;
- // w = 0;
- // h = 0;
- // scaledW = 0;
- // scaledH = 0;
- //}
+
+ void SetGeneralParameters(u32 addr, u32 size, u32 format, unsigned int num_mipmaps)
+ {
+ this->addr = addr;
+ this->size_in_bytes = size;
+ this->format = format;
+ this->num_mipmaps = num_mipmaps;
+ }
+
+ void SetDimensions(unsigned int native_width, unsigned int native_height, unsigned int virtual_width, unsigned int virtual_height)
+ {
+ this->native_width = native_width;
+ this->native_height = native_height;
+ this->virtual_width = virtual_width;
+ this->virtual_height = virtual_height;
+ }
+
+ void SetHashes(u64 hash/*, u32 pal_hash*/)
+ {
+ this->hash = hash;
+ //this->pal_hash = pal_hash;
+ }
+
virtual ~TCacheEntryBase();
@@ -62,13 +87,15 @@ public:
virtual bool Save(const char filename[]) = 0;
virtual void Load(unsigned int width, unsigned int height,
- unsigned int expanded_width, unsigned int level, bool autogen_mips = false) = 0;
+ unsigned int expanded_width, unsigned int level, bool autogen_mips) = 0;
virtual void FromRenderTarget(u32 dstAddr, unsigned int dstFormat,
unsigned int srcFormat, const EFBRectangle& srcRect,
bool isIntensity, bool scaleByHalf, unsigned int cbufid,
const float *colmat) = 0;
int IntersectsMemoryRange(u32 range_address, u32 range_size) const;
+
+ bool IsEfbCopy() { return (type == TCET_EC_VRAM || type == TCET_EC_DYNAMIC); }
};
virtual ~TextureCache(); // needs virtual for DX11 dtor
@@ -87,7 +114,7 @@ public:
virtual TCacheEntryBase* CreateRenderTargetTexture(unsigned int scaled_tex_w, unsigned int scaled_tex_h) = 0;
static TCacheEntryBase* Load(unsigned int stage, u32 address, unsigned int width, unsigned int height,
- int format, unsigned int tlutaddr, int tlutfmt, bool UseNativeMips, unsigned int maxlevel);
+ int format, unsigned int tlutaddr, int tlutfmt, bool UseNativeMips, unsigned int maxlevel, bool from_tmem);
static void CopyRenderTargetToTexture(u32 dstAddr, unsigned int dstFormat, unsigned int srcFormat,
const EFBRectangle& srcRect, bool isIntensity, bool scaleByHalf);
diff --git a/Source/Core/VideoCommon/Src/TextureDecoder.h b/Source/Core/VideoCommon/Src/TextureDecoder.h
index d990d21545..1901c86d27 100644
--- a/Source/Core/VideoCommon/Src/TextureDecoder.h
+++ b/Source/Core/VideoCommon/Src/TextureDecoder.h
@@ -20,8 +20,8 @@
#include "Hash.h"
enum
{
- TMEM_SIZE = 1024*1024,
- HALFTMEM_SIZE = 512*1024
+ TMEM_SIZE = 1024*1024,
+ TMEM_LINE_SIZE = 32,
};
extern GC_ALIGNED16(u8 texMem[TMEM_SIZE]);
diff --git a/Source/Core/VideoCommon/Src/VideoConfig.cpp b/Source/Core/VideoCommon/Src/VideoConfig.cpp
index b6ba76f45e..5bb6e4dd99 100644
--- a/Source/Core/VideoCommon/Src/VideoConfig.cpp
+++ b/Source/Core/VideoCommon/Src/VideoConfig.cpp
@@ -57,12 +57,8 @@ void VideoConfig::Load(const char *ini_file)
iniFile.Get("Settings", "Crop", &bCrop, false);
iniFile.Get("Settings", "UseXFB", &bUseXFB, 0);
iniFile.Get("Settings", "UseRealXFB", &bUseRealXFB, 0);
- iniFile.Get("Settings", "UseNativeMips", &bUseNativeMips, false);
-
- iniFile.Get("Settings", "SafeTextureCache", &bSafeTextureCache, true); // Settings
- //Safe texture cache params
+ iniFile.Get("Settings", "UseNativeMips", &bUseNativeMips, false);
iniFile.Get("Settings", "SafeTextureCacheColorSamples", &iSafeTextureCache_ColorSamples,128);
-
iniFile.Get("Settings", "ShowFPS", &bShowFPS, false); // Settings
iniFile.Get("Settings", "ShowInputDisplay", &bShowInputDisplay, false);
iniFile.Get("Settings", "OverlayStats", &bOverlayStats, false);
@@ -134,7 +130,6 @@ void VideoConfig::GameIniLoad(const char *ini_file)
iniFile.GetIfExists("Video_Settings", "UseXFB", &bUseXFB);
iniFile.GetIfExists("Video_Settings", "UseRealXFB", &bUseRealXFB);
iniFile.GetIfExists("Video_Settings", "UseNativeMips", &bUseNativeMips);
- iniFile.GetIfExists("Video_Settings", "SafeTextureCache", &bSafeTextureCache);
iniFile.GetIfExists("Video_Settings", "SafeTextureCacheColorSamples", &iSafeTextureCache_ColorSamples);
iniFile.GetIfExists("Video_Settings", "DLOptimize", &iCompileDLsLevel);
iniFile.GetIfExists("Video_Settings", "HiresTextures", &bHiresTextures);
@@ -196,11 +191,7 @@ void VideoConfig::Save(const char *ini_file)
iniFile.Set("Settings", "UseXFB", bUseXFB);
iniFile.Set("Settings", "UseRealXFB", bUseRealXFB);
iniFile.Set("Settings", "UseNativeMips", bUseNativeMips);
-
- iniFile.Set("Settings", "SafeTextureCache", bSafeTextureCache);
- //safe texture cache params
iniFile.Set("Settings", "SafeTextureCacheColorSamples", iSafeTextureCache_ColorSamples);
-
iniFile.Set("Settings", "ShowFPS", bShowFPS);
iniFile.Set("Settings", "ShowInputDisplay", bShowInputDisplay);
iniFile.Set("Settings", "OverlayStats", bOverlayStats);
@@ -279,7 +270,6 @@ void VideoConfig::GameIniSave(const char* default_ini, const char* game_ini)
SET_IF_DIFFERS("Video_Settings", "UseXFB", bUseXFB);
SET_IF_DIFFERS("Video_Settings", "UseRealXFB", bUseRealXFB);
SET_IF_DIFFERS("Video_Settings", "UseNativeMips", bUseNativeMips);
- SET_IF_DIFFERS("Video_Settings", "SafeTextureCache", bSafeTextureCache);
SET_IF_DIFFERS("Video_Settings", "SafeTextureCacheColorSamples", iSafeTextureCache_ColorSamples);
SET_IF_DIFFERS("Video_Settings", "DLOptimize", iCompileDLsLevel);
SET_IF_DIFFERS("Video_Settings", "HiresTextures", bHiresTextures);
diff --git a/Source/Core/VideoCommon/Src/VideoConfig.h b/Source/Core/VideoCommon/Src/VideoConfig.h
index 3bd833cc73..7c846676bb 100644
--- a/Source/Core/VideoCommon/Src/VideoConfig.h
+++ b/Source/Core/VideoCommon/Src/VideoConfig.h
@@ -129,7 +129,6 @@ struct VideoConfig
bool bOSDHotKey;
bool bCopyEFBToTexture;
bool bCopyEFBScaled;
- bool bSafeTextureCache;
int iSafeTextureCache_ColorSamples;
int iPhackvalue[4];
std::string sPhackvalue[2];