summaryrefslogtreecommitdiff
path: root/Source/Plugins
diff options
context:
space:
mode:
authorNeoBrainX <NeoBrainX@googlemail.com>2012-01-31 19:58:26 +0100
committerNeoBrainX <NeoBrainX@googlemail.com>2012-01-31 19:58:32 +0100
commit013bda74ee4e7fb2615455826bd6a301ca7e7c64 (patch)
tree87157c9cf4e6f14578b864bf5c67c0c18d996288 /Source/Plugins
parent04a7e33f0b629622ff851f962b9ab707f70a1b35 (diff)
parentd1605abfa98c39de0e9b9e57944f9dc864c03b42 (diff)
Merge branch 'texcache-cleanup'
Diffstat (limited to 'Source/Plugins')
-rw-r--r--Source/Plugins/Plugin_VideoDX11/Src/Render.cpp7
-rw-r--r--Source/Plugins/Plugin_VideoDX11/Src/TextureCache.cpp22
-rw-r--r--Source/Plugins/Plugin_VideoDX11/Src/VertexManager.cpp2
-rw-r--r--Source/Plugins/Plugin_VideoDX9/Src/Render.cpp7
-rw-r--r--Source/Plugins/Plugin_VideoDX9/Src/TextureCache.cpp42
-rw-r--r--Source/Plugins/Plugin_VideoDX9/Src/TextureConverter.cpp90
-rw-r--r--Source/Plugins/Plugin_VideoDX9/Src/TextureConverter.h6
-rw-r--r--Source/Plugins/Plugin_VideoDX9/Src/VertexManager.cpp2
-rw-r--r--Source/Plugins/Plugin_VideoOGL/Src/Render.cpp3
-rw-r--r--Source/Plugins/Plugin_VideoOGL/Src/TextureCache.cpp20
-rw-r--r--Source/Plugins/Plugin_VideoOGL/Src/TextureConverter.cpp86
-rw-r--r--Source/Plugins/Plugin_VideoOGL/Src/TextureConverter.h6
-rw-r--r--Source/Plugins/Plugin_VideoOGL/Src/VertexManager.cpp2
13 files changed, 73 insertions, 222 deletions
diff --git a/Source/Plugins/Plugin_VideoDX11/Src/Render.cpp b/Source/Plugins/Plugin_VideoDX11/Src/Render.cpp
index 07fe88d2b5..9328969abf 100644
--- a/Source/Plugins/Plugin_VideoDX11/Src/Render.cpp
+++ b/Source/Plugins/Plugin_VideoDX11/Src/Render.cpp
@@ -1106,12 +1106,11 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons
DLCache::ProgressiveCleanup();
TextureCache::Cleanup();
- // reload textures if these settings changed
- if (g_Config.bSafeTextureCache != g_ActiveConfig.bSafeTextureCache ||
- g_Config.bUseNativeMips != g_ActiveConfig.bUseNativeMips)
+ // Reload textures if this settings changes
+ if (g_Config.bUseNativeMips != g_ActiveConfig.bUseNativeMips)
TextureCache::Invalidate(false);
- // Enable any configuration changes
+ // Enable configuration changes
UpdateActiveConfig();
SetWindowSize(fbWidth, fbHeight);
diff --git a/Source/Plugins/Plugin_VideoDX11/Src/TextureCache.cpp b/Source/Plugins/Plugin_VideoDX11/Src/TextureCache.cpp
index 39018c83bc..e59fbd496e 100644
--- a/Source/Plugins/Plugin_VideoDX11/Src/TextureCache.cpp
+++ b/Source/Plugins/Plugin_VideoDX11/Src/TextureCache.cpp
@@ -102,12 +102,12 @@ void TextureCache::TCacheEntry::FromRenderTarget(u32 dstAddr, unsigned int dstFo
bool isIntensity, bool scaleByHalf, unsigned int cbufid,
const float *colmat)
{
- if (!isDynamic || g_ActiveConfig.bCopyEFBToTexture)
+ if (type != TCET_EC_DYNAMIC || g_ActiveConfig.bCopyEFBToTexture)
{
g_renderer->ResetAPIState();
// stretch picture with increased internal resolution
- const D3D11_VIEWPORT vp = CD3D11_VIEWPORT(0.f, 0.f, (float)virtualW, (float)virtualH);
+ const D3D11_VIEWPORT vp = CD3D11_VIEWPORT(0.f, 0.f, (float)virtual_width, (float)virtual_height);
D3D::context->RSSetViewports(1, &vp);
// set transformation
@@ -149,17 +149,15 @@ void TextureCache::TCacheEntry::FromRenderTarget(u32 dstAddr, unsigned int dstFo
if (!g_ActiveConfig.bCopyEFBToTexture)
{
u8* dst = Memory::GetPointer(dstAddr);
- size_t encodeSize = g_encoder->Encode(dst, dstFormat, srcFormat, srcRect, isIntensity, scaleByHalf);
- hash = GetHash64(dst, encodeSize, g_ActiveConfig.iSafeTextureCache_ColorSamples);
- if (g_ActiveConfig.bEFBCopyCacheEnable)
- {
- // If the texture in RAM is already in the texture cache,
- // do not copy it again as it has not changed.
- if (TextureCache::Find(dstAddr, hash))
- return;
- }
+ size_t encoded_size = g_encoder->Encode(dst, dstFormat, srcFormat, srcRect, isIntensity, scaleByHalf);
+
+ hash = GetHash64(dst, (int)encoded_size, g_ActiveConfig.iSafeTextureCache_ColorSamples);
- TextureCache::MakeRangeDynamic(dstAddr, encodeSize);
+ // Mark texture entries in destination address range dynamic unless caching is enabled and the texture entry is up to date
+ if (!g_ActiveConfig.bEFBCopyCacheEnable)
+ TextureCache::MakeRangeDynamic(addr, (u32)encoded_size);
+ else if (!TextureCache::Find(addr, hash))
+ TextureCache::MakeRangeDynamic(addr, (u32)encoded_size);
}
}
diff --git a/Source/Plugins/Plugin_VideoDX11/Src/VertexManager.cpp b/Source/Plugins/Plugin_VideoDX11/Src/VertexManager.cpp
index e1e40047e4..9087b6dac1 100644
--- a/Source/Plugins/Plugin_VideoDX11/Src/VertexManager.cpp
+++ b/Source/Plugins/Plugin_VideoDX11/Src/VertexManager.cpp
@@ -233,7 +233,7 @@ void VertexManager::vFlush()
if (tentry)
{
// 0s are probably for no manual wrapping needed.
- PixelShaderManager::SetTexDims(i, tentry->realW, tentry->realH, 0, 0);
+ PixelShaderManager::SetTexDims(i, tentry->native_width, tentry->native_height, 0, 0);
}
else
ERROR_LOG(VIDEO, "error loading texture");
diff --git a/Source/Plugins/Plugin_VideoDX9/Src/Render.cpp b/Source/Plugins/Plugin_VideoDX9/Src/Render.cpp
index 773172b0b8..f649323b73 100644
--- a/Source/Plugins/Plugin_VideoDX9/Src/Render.cpp
+++ b/Source/Plugins/Plugin_VideoDX9/Src/Render.cpp
@@ -1114,12 +1114,11 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons
DLCache::ProgressiveCleanup();
TextureCache::Cleanup();
- // reload textures if these settings changed
- if (g_Config.bSafeTextureCache != g_ActiveConfig.bSafeTextureCache ||
- g_Config.bUseNativeMips != g_ActiveConfig.bUseNativeMips)
+ // Reload textures if these settings changed
+ if (g_Config.bUseNativeMips != g_ActiveConfig.bUseNativeMips)
TextureCache::Invalidate(false);
- // Enable any configuration changes
+ // Enable configuration changes
UpdateActiveConfig();
SetWindowSize(fbWidth, fbHeight);
diff --git a/Source/Plugins/Plugin_VideoDX9/Src/TextureCache.cpp b/Source/Plugins/Plugin_VideoDX9/Src/TextureCache.cpp
index 7c741e08a9..2a3f12ddcf 100644
--- a/Source/Plugins/Plugin_VideoDX9/Src/TextureCache.cpp
+++ b/Source/Plugins/Plugin_VideoDX9/Src/TextureCache.cpp
@@ -21,6 +21,7 @@
#include "Statistics.h"
#include "MemoryUtil.h"
#include "Hash.h"
+#include "HW/Memmap.h"
#include "CommonPaths.h"
#include "FileUtil.h"
@@ -78,7 +79,7 @@ void TextureCache::TCacheEntry::FromRenderTarget(u32 dstAddr, unsigned int dstFo
FramebufferManager::GetEFBDepthTexture() :
FramebufferManager::GetEFBColorTexture();
- if (!isDynamic || g_ActiveConfig.bCopyEFBToTexture)
+ if (type != TCET_EC_DYNAMIC || g_ActiveConfig.bCopyEFBToTexture)
{
LPDIRECT3DSURFACE9 Rendersurf = NULL;
texture->GetSurfaceLevel(0, &Rendersurf);
@@ -90,15 +91,15 @@ void TextureCache::TCacheEntry::FromRenderTarget(u32 dstAddr, unsigned int dstFo
// Stretch picture with increased internal resolution
vp.X = 0;
vp.Y = 0;
- vp.Width = virtualW;
- vp.Height = virtualH;
+ vp.Width = virtual_width;
+ vp.Height = virtual_height;
vp.MinZ = 0.0f;
vp.MaxZ = 1.0f;
D3D::dev->SetViewport(&vp);
RECT destrect;
- destrect.bottom = virtualH;
+ destrect.bottom = virtual_height;
destrect.left = 0;
- destrect.right = virtualW;
+ destrect.right = virtual_width;
destrect.top = 0;
PixelShaderManager::SetColorMatrix(colmat); // set transformation
@@ -133,7 +134,7 @@ void TextureCache::TCacheEntry::FromRenderTarget(u32 dstAddr, unsigned int dstFo
D3D::drawShadedTexQuad(read_texture, &sourcerect,
Renderer::GetTargetWidth(), Renderer::GetTargetHeight(),
- virtualW, virtualH,
+ virtual_width, virtual_height,
// TODO: why is D3DFMT_D24X8 singled out here? why not D3DFMT_D24X4S4/D24S8/D24FS8/D32/D16/D15S1 too, or none of them?
PixelShaderCache::GetDepthMatrixProgram(SSAAMode, (srcFormat == PIXELFMT_Z24) && bformat != FOURCC_RAWZ && bformat != D3DFMT_D24X8),
VertexShaderCache::GetSimpleVertexShader(SSAAMode));
@@ -143,16 +144,25 @@ void TextureCache::TCacheEntry::FromRenderTarget(u32 dstAddr, unsigned int dstFo
if (!g_ActiveConfig.bCopyEFBToTexture)
{
- hash = TextureConverter::EncodeToRamFromTexture(
- addr,
- read_texture,
- Renderer::GetTargetWidth(),
- Renderer::GetTargetHeight(),
- srcFormat == PIXELFMT_Z24,
- isIntensity,
- dstFormat,
- scaleByHalf,
- srcRect);
+ int encoded_size = TextureConverter::EncodeToRamFromTexture(
+ addr,
+ read_texture,
+ Renderer::GetTargetWidth(),
+ Renderer::GetTargetHeight(),
+ srcFormat == PIXELFMT_Z24,
+ isIntensity,
+ dstFormat,
+ scaleByHalf,
+ srcRect);
+
+ u8* dst = Memory::GetPointer(addr);
+ hash = GetHash64(dst,encoded_size,g_ActiveConfig.iSafeTextureCache_ColorSamples);
+
+ // Mark texture entries in destination address range dynamic unless caching is enabled and the texture entry is up to date
+ if (!g_ActiveConfig.bEFBCopyCacheEnable)
+ TextureCache::MakeRangeDynamic(addr,encoded_size);
+ else if (!TextureCache::Find(addr, hash))
+ TextureCache::MakeRangeDynamic(addr,encoded_size);
}
D3D::RefreshSamplerState(0, D3DSAMP_MINFILTER);
diff --git a/Source/Plugins/Plugin_VideoDX9/Src/TextureConverter.cpp b/Source/Plugins/Plugin_VideoDX9/Src/TextureConverter.cpp
index d14a3f29ea..7c38b154b9 100644
--- a/Source/Plugins/Plugin_VideoDX9/Src/TextureConverter.cpp
+++ b/Source/Plugins/Plugin_VideoDX9/Src/TextureConverter.cpp
@@ -252,10 +252,10 @@ void EncodeToRamUsingShader(LPDIRECT3DPIXELSHADER9 shader, LPDIRECT3DTEXTURE9 sr
s_texConvReadSurface = TrnBuffers[index].ReadSurface;
Rendersurf = TrnBuffers[index].RenderSurface;
-
+
hr = D3D::dev->SetDepthStencilSurface(NULL);
hr = D3D::dev->SetRenderTarget(0, Rendersurf);
-
+
if (linearFilter)
{
D3D::ChangeSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
@@ -290,7 +290,7 @@ void EncodeToRamUsingShader(LPDIRECT3DPIXELSHADER9 shader, LPDIRECT3DTEXTURE9 sr
D3D::RefreshSamplerState(0, D3DSAMP_MINFILTER);
// .. and then read back the results.
// TODO: make this less slow.
-
+
hr = D3D::dev->GetRenderTargetData(Rendersurf,s_texConvReadSurface);
D3DLOCKED_RECT drect;
@@ -313,76 +313,7 @@ void EncodeToRamUsingShader(LPDIRECT3DPIXELSHADER9 shader, LPDIRECT3DTEXTURE9 sr
hr = s_texConvReadSurface->UnlockRect();
}
-void EncodeToRam(u32 address, bool bFromZBuffer, bool bIsIntensityFmt, u32 copyfmt, int bScaleByHalf, const EFBRectangle& source)
-{
- u32 format = copyfmt;
-
- if (bFromZBuffer)
- {
- format |= _GX_TF_ZTF;
- if (copyfmt == 11)
- format = GX_TF_Z16;
- else if (format < GX_TF_Z8 || format > GX_TF_Z24X8)
- format |= _GX_TF_CTF;
- }
- else
- if (copyfmt > GX_TF_RGBA8 || (copyfmt < GX_TF_RGB565 && !bIsIntensityFmt))
- format |= _GX_TF_CTF;
-
- LPDIRECT3DPIXELSHADER9 texconv_shader = GetOrCreateEncodingShader(format);
- if (!texconv_shader)
- return;
-
- u8 *dest_ptr = Memory::GetPointer(address);
-
- LPDIRECT3DTEXTURE9 source_texture = bFromZBuffer ? FramebufferManager::GetEFBDepthTexture() : FramebufferManager::GetEFBColorTexture();
- int width = (source.right - source.left) >> bScaleByHalf;
- int height = (source.bottom - source.top) >> bScaleByHalf;
-
- int size_in_bytes = TexDecoder_GetTextureSizeInBytes(width, height, format);
-
- // Invalidate any existing texture covering this memory range.
- // TODO - don't delete the texture if it already exists, just replace the contents.
- TextureCache::InvalidateRange(address, size_in_bytes);
-
- u16 blkW = TexDecoder_GetBlockWidthInTexels(format) - 1;
- u16 blkH = TexDecoder_GetBlockHeightInTexels(format) - 1;
- u16 samples = TextureConversionShader::GetEncodedSampleCount(format);
-
- // only copy on cache line boundaries
- // extra pixels are copied but not displayed in the resulting texture
- s32 expandedWidth = (width + blkW) & (~blkW);
- s32 expandedHeight = (height + blkH) & (~blkH);
-
- float sampleStride = bScaleByHalf ? 2.f : 1.f;
- TextureConversionShader::SetShaderParameters(
- (float)expandedWidth,
- (float)Renderer::EFBToScaledY(expandedHeight), // TODO: Why do we scale this?
- (float)Renderer::EFBToScaledX(source.left),
- (float)Renderer::EFBToScaledY(source.top),
- Renderer::EFBToScaledXf(sampleStride),
- Renderer::EFBToScaledYf(sampleStride),
- (float)Renderer::GetTargetWidth(),
- (float)Renderer::GetTargetHeight());
-
- TargetRectangle scaledSource;
- scaledSource.top = 0;
- scaledSource.bottom = expandedHeight;
- scaledSource.left = 0;
- scaledSource.right = expandedWidth / samples;
- int cacheBytes = 32;
- if ((format & 0x0f) == 6)
- cacheBytes = 64;
-
- int readStride = (expandedWidth * cacheBytes) / TexDecoder_GetBlockWidthInTexels(format);
- g_renderer->ResetAPIState();
- EncodeToRamUsingShader(texconv_shader, source_texture, scaledSource, dest_ptr, expandedWidth / samples, expandedHeight, readStride, true, bScaleByHalf > 0,1.0f);
- D3D::dev->SetRenderTarget(0, FramebufferManager::GetEFBColorRTSurface());
- D3D::dev->SetDepthStencilSurface(FramebufferManager::GetEFBDepthRTSurface());
- g_renderer->RestoreAPIState();
-}
-
-u64 EncodeToRamFromTexture(u32 address,LPDIRECT3DTEXTURE9 source_texture, u32 SourceW, u32 SourceH, bool bFromZBuffer, bool bIsIntensityFmt, u32 copyfmt, int bScaleByHalf, const EFBRectangle& source)
+int EncodeToRamFromTexture(u32 address,LPDIRECT3DTEXTURE9 source_texture, u32 SourceW, u32 SourceH, bool bFromZBuffer, bool bIsIntensityFmt, u32 copyfmt, int bScaleByHalf, const EFBRectangle& source)
{
u32 format = copyfmt;
@@ -440,16 +371,7 @@ u64 EncodeToRamFromTexture(u32 address,LPDIRECT3DTEXTURE9 source_texture, u32 So
int readStride = (expandedWidth * cacheBytes) / TexDecoder_GetBlockWidthInTexels(format);
EncodeToRamUsingShader(texconv_shader, source_texture, scaledSource, dest_ptr, expandedWidth / samples, expandedHeight, readStride, true, bScaleByHalf > 0,1.0f);
- u64 hash = GetHash64(dest_ptr,size_in_bytes,g_ActiveConfig.iSafeTextureCache_ColorSamples);
- if (g_ActiveConfig.bEFBCopyCacheEnable)
- {
- // If the texture in RAM is already in the texture cache, do not copy it again as it has not changed.
- if (TextureCache::Find(address, hash))
- return hash;
- }
-
- TextureCache::MakeRangeDynamic(address,size_in_bytes);
- return hash;
+ return size_in_bytes; // TODO: D3D11 is calculating this value differently!
}
void EncodeToRamYUYV(LPDIRECT3DTEXTURE9 srcTexture, const TargetRectangle& sourceRc, u8* destAddr, int dstWidth, int dstHeight,float Gamma)
@@ -490,7 +412,7 @@ void DecodeToTexture(u32 xfbAddr, int srcWidth, int srcHeight, LPDIRECT3DTEXTURE
destTexture->GetSurfaceLevel(0,&Rendersurf);
D3D::dev->SetDepthStencilSurface(NULL);
D3D::dev->SetRenderTarget(0, Rendersurf);
-
+
D3DVIEWPORT9 vp;
// Stretch picture with increased internal resolution
diff --git a/Source/Plugins/Plugin_VideoDX9/Src/TextureConverter.h b/Source/Plugins/Plugin_VideoDX9/Src/TextureConverter.h
index aa4757e4c9..4036f21447 100644
--- a/Source/Plugins/Plugin_VideoDX9/Src/TextureConverter.h
+++ b/Source/Plugins/Plugin_VideoDX9/Src/TextureConverter.h
@@ -35,15 +35,13 @@ namespace TextureConverter
void Init();
void Shutdown();
-void EncodeToRam(u32 address, bool bFromZBuffer, bool bIsIntensityFmt,
- u32 copyfmt, int bScaleByHalf, const EFBRectangle& source);
-
void EncodeToRamYUYV(LPDIRECT3DTEXTURE9 srcTexture, const TargetRectangle& sourceRc,
u8* destAddr, int dstWidth, int dstHeight,float Gamma);
void DecodeToTexture(u32 xfbAddr, int srcWidth, int srcHeight, LPDIRECT3DTEXTURE9 destTexture);
-u64 EncodeToRamFromTexture(u32 address,LPDIRECT3DTEXTURE9 source_texture, u32 SourceW, u32 SourceH, bool bFromZBuffer, bool bIsIntensityFmt, u32 copyfmt, int bScaleByHalf, const EFBRectangle& source);
+// returns size of the encoded data (in bytes)
+int EncodeToRamFromTexture(u32 address,LPDIRECT3DTEXTURE9 source_texture, u32 SourceW, u32 SourceH, bool bFromZBuffer, bool bIsIntensityFmt, u32 copyfmt, int bScaleByHalf, const EFBRectangle& source);
}
diff --git a/Source/Plugins/Plugin_VideoDX9/Src/VertexManager.cpp b/Source/Plugins/Plugin_VideoDX9/Src/VertexManager.cpp
index d9c33b67ef..c6bddb7468 100644
--- a/Source/Plugins/Plugin_VideoDX9/Src/VertexManager.cpp
+++ b/Source/Plugins/Plugin_VideoDX9/Src/VertexManager.cpp
@@ -142,7 +142,7 @@ void VertexManager::vFlush()
if (tentry)
{
// 0s are probably for no manual wrapping needed.
- PixelShaderManager::SetTexDims(i, tentry->realW, tentry->realH, 0, 0);
+ PixelShaderManager::SetTexDims(i, tentry->native_width, tentry->native_height, 0, 0);
}
else
ERROR_LOG(VIDEO, "error loading texture");
diff --git a/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp b/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp
index e4c9dd8511..9883d35fbb 100644
--- a/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp
+++ b/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp
@@ -1394,8 +1394,7 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons
g_Config.iSaveTargetId = 0;
// reload textures if these settings changed
- if (g_Config.bSafeTextureCache != g_ActiveConfig.bSafeTextureCache ||
- g_Config.bUseNativeMips != g_ActiveConfig.bUseNativeMips)
+ if (g_Config.bUseNativeMips != g_ActiveConfig.bUseNativeMips)
TextureCache::Invalidate(false);
if (g_Config.bCopyEFBToTexture != g_ActiveConfig.bCopyEFBToTexture)
diff --git a/Source/Plugins/Plugin_VideoOGL/Src/TextureCache.cpp b/Source/Plugins/Plugin_VideoOGL/Src/TextureCache.cpp
index 4a9431a563..f78eb11905 100644
--- a/Source/Plugins/Plugin_VideoOGL/Src/TextureCache.cpp
+++ b/Source/Plugins/Plugin_VideoOGL/Src/TextureCache.cpp
@@ -39,6 +39,7 @@
#include "Globals.h"
#include "Hash.h"
#include "HiresTextures.h"
+#include "HW/Memmap.h"
#include "ImageWrite.h"
#include "MemoryUtil.h"
#include "PixelShaderCache.h"
@@ -124,7 +125,7 @@ bool TextureCache::TCacheEntry::Save(const char filename[])
std::string tga_filename(filename);
tga_filename.replace(tga_filename.size() - 3, 3, "tga");
- return SaveTexture(tga_filename.c_str(), GL_TEXTURE_2D, texture, realW, realH);
+ return SaveTexture(tga_filename.c_str(), GL_TEXTURE_2D, texture, virtual_width, virtual_height);
}
TextureCache::TCacheEntryBase* TextureCache::CreateTexture(unsigned int width,
@@ -278,7 +279,7 @@ void TextureCache::TCacheEntry::FromRenderTarget(u32 dstAddr, unsigned int dstFo
GL_REPORT_ERRORD();
- if (false == isDynamic || g_ActiveConfig.bCopyEFBToTexture)
+ if (type != TCET_EC_DYNAMIC || g_ActiveConfig.bCopyEFBToTexture)
{
if (s_TempFramebuffer == 0)
glGenFramebuffersEXT(1, (GLuint*)&s_TempFramebuffer);
@@ -294,7 +295,7 @@ void TextureCache::TCacheEntry::FromRenderTarget(u32 dstAddr, unsigned int dstFo
glEnable(GL_TEXTURE_RECTANGLE_ARB);
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, read_texture);
- glViewport(0, 0, virtualW, virtualH);
+ glViewport(0, 0, virtual_width, virtual_height);
PixelShaderCache::SetCurrentShader((srcFormat == PIXELFMT_Z24) ? PixelShaderCache::GetDepthMatrixProgram() : PixelShaderCache::GetColorMatrixProgram());
PixelShaderManager::SetColorMatrix(colmat); // set transformation
@@ -317,7 +318,7 @@ void TextureCache::TCacheEntry::FromRenderTarget(u32 dstAddr, unsigned int dstFo
if (false == g_ActiveConfig.bCopyEFBToTexture)
{
- hash = TextureConverter::EncodeToRamFromTexture(
+ int encoded_size = TextureConverter::EncodeToRamFromTexture(
addr,
read_texture,
srcFormat == PIXELFMT_Z24,
@@ -325,6 +326,15 @@ void TextureCache::TCacheEntry::FromRenderTarget(u32 dstAddr, unsigned int dstFo
dstFormat,
scaleByHalf,
srcRect);
+
+ u8* dst = Memory::GetPointer(addr);
+ hash = GetHash64(dst,encoded_size,g_ActiveConfig.iSafeTextureCache_ColorSamples);
+
+ // Mark texture entries in destination address range dynamic unless caching is enabled and the texture entry is up to date
+ if (!g_ActiveConfig.bEFBCopyCacheEnable)
+ TextureCache::MakeRangeDynamic(addr,encoded_size);
+ else if (!TextureCache::Find(addr, hash))
+ TextureCache::MakeRangeDynamic(addr,encoded_size);
}
FramebufferManager::SetFramebuffer(0);
@@ -337,7 +347,7 @@ void TextureCache::TCacheEntry::FromRenderTarget(u32 dstAddr, unsigned int dstFo
{
static int count = 0;
SaveTexture(StringFromFormat("%sefb_frame_%i.tga", File::GetUserPath(D_DUMPTEXTURES_IDX).c_str(),
- count++).c_str(), GL_TEXTURE_2D, texture, realW, realH);
+ count++).c_str(), GL_TEXTURE_2D, texture, virtual_width, virtual_height);
}
}
diff --git a/Source/Plugins/Plugin_VideoOGL/Src/TextureConverter.cpp b/Source/Plugins/Plugin_VideoOGL/Src/TextureConverter.cpp
index c715775194..c73d3abdbf 100644
--- a/Source/Plugins/Plugin_VideoOGL/Src/TextureConverter.cpp
+++ b/Source/Plugins/Plugin_VideoOGL/Src/TextureConverter.cpp
@@ -250,78 +250,7 @@ void EncodeToRamUsingShader(FRAGMENTSHADER& shader, GLuint srcTexture, const Tar
}
-void EncodeToRam(u32 address, bool bFromZBuffer, bool bIsIntensityFmt, u32 copyfmt, int bScaleByHalf, const EFBRectangle& source)
-{
- u32 format = copyfmt;
-
- if (bFromZBuffer)
- {
- format |= _GX_TF_ZTF;
- if (copyfmt == 11)
- format = GX_TF_Z16;
- else if (format < GX_TF_Z8 || format > GX_TF_Z24X8)
- format |= _GX_TF_CTF;
- }
- else
- if (copyfmt > GX_TF_RGBA8 || (copyfmt < GX_TF_RGB565 && !bIsIntensityFmt))
- format |= _GX_TF_CTF;
-
- FRAGMENTSHADER& texconv_shader = GetOrCreateEncodingShader(format);
- if (texconv_shader.glprogid == 0)
- return;
-
- u8 *dest_ptr = Memory::GetPointer(address);
-
- GLuint source_texture = bFromZBuffer ? FramebufferManager::ResolveAndGetDepthTarget(source) : FramebufferManager::ResolveAndGetRenderTarget(source);
-
- int width = (source.right - source.left) >> bScaleByHalf;
- int height = (source.bottom - source.top) >> bScaleByHalf;
-
- int size_in_bytes = TexDecoder_GetTextureSizeInBytes(width, height, format);
-
- // Invalidate any existing texture covering this memory range.
- // TODO - don't delete the texture if it already exists, just replace the contents.
- TextureCache::InvalidateRange(address, size_in_bytes);
-
- u16 blkW = TexDecoder_GetBlockWidthInTexels(format) - 1;
- u16 blkH = TexDecoder_GetBlockHeightInTexels(format) - 1;
- u16 samples = TextureConversionShader::GetEncodedSampleCount(format);
-
- // only copy on cache line boundaries
- // extra pixels are copied but not displayed in the resulting texture
- s32 expandedWidth = (width + blkW) & (~blkW);
- s32 expandedHeight = (height + blkH) & (~blkH);
-
- float sampleStride = bScaleByHalf ? 2.f : 1.f;
- TextureConversionShader::SetShaderParameters(
- (float)expandedWidth,
- (float)Renderer::EFBToScaledY(expandedHeight), // TODO: Why do we scale this?
- (float)Renderer::EFBToScaledX(source.left),
- (float)Renderer::EFBToScaledY(EFB_HEIGHT - source.top - expandedHeight),
- Renderer::EFBToScaledXf(sampleStride),
- Renderer::EFBToScaledYf(sampleStride));
-
- TargetRectangle scaledSource;
- scaledSource.top = 0;
- scaledSource.bottom = expandedHeight;
- scaledSource.left = 0;
- scaledSource.right = expandedWidth / samples;
- int cacheBytes = 32;
- if ((format & 0x0f) == 6)
- cacheBytes = 64;
-
- int readStride = (expandedWidth * cacheBytes) / TexDecoder_GetBlockWidthInTexels(format);
- g_renderer->ResetAPIState();
- EncodeToRamUsingShader(texconv_shader, source_texture, scaledSource, dest_ptr, expandedWidth / samples, expandedHeight, readStride, true, bScaleByHalf > 0);
- FramebufferManager::SetFramebuffer(0);
- VertexShaderManager::SetViewportChanged();
- glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 0);
- TextureCache::DisableStage(0);
- g_renderer->RestoreAPIState();
- GL_REPORT_ERRORD();
-}
-
-u64 EncodeToRamFromTexture(u32 address,GLuint source_texture, bool bFromZBuffer, bool bIsIntensityFmt, u32 copyfmt, int bScaleByHalf, const EFBRectangle& source)
+int EncodeToRamFromTexture(u32 address,GLuint source_texture, bool bFromZBuffer, bool bIsIntensityFmt, u32 copyfmt, int bScaleByHalf, const EFBRectangle& source)
{
u32 format = copyfmt;
@@ -379,19 +308,8 @@ u64 EncodeToRamFromTexture(u32 address,GLuint source_texture, bool bFromZBuffer,
EncodeToRamUsingShader(texconv_shader, source_texture, scaledSource,
dest_ptr, expandedWidth / samples, expandedHeight, readStride,
true, bScaleByHalf > 0 && !bFromZBuffer);
+ return size_in_bytes; // TODO: D3D11 is calculating this value differently!
- u64 hash = GetHash64(dest_ptr, size_in_bytes,
- g_ActiveConfig.iSafeTextureCache_ColorSamples);
- if (g_ActiveConfig.bEFBCopyCacheEnable)
- {
- // If the texture in RAM is already in the texture cache,
- // do not copy it again as it has not changed.
- if (TextureCache::Find(address, hash))
- return hash;
- }
-
- TextureCache::MakeRangeDynamic(address,size_in_bytes);
- return hash;
}
void EncodeToRamYUYV(GLuint srcTexture, const TargetRectangle& sourceRc, u8* destAddr, int dstWidth, int dstHeight)
diff --git a/Source/Plugins/Plugin_VideoOGL/Src/TextureConverter.h b/Source/Plugins/Plugin_VideoOGL/Src/TextureConverter.h
index 719ac1b7fc..4113778603 100644
--- a/Source/Plugins/Plugin_VideoOGL/Src/TextureConverter.h
+++ b/Source/Plugins/Plugin_VideoOGL/Src/TextureConverter.h
@@ -32,15 +32,13 @@ namespace TextureConverter
void Init();
void Shutdown();
-void EncodeToRam(u32 address, bool bFromZBuffer, bool bIsIntensityFmt,
- u32 copyfmt, int bScaleByHalf, const EFBRectangle& source);
-
void EncodeToRamYUYV(GLuint srcTexture, const TargetRectangle& sourceRc,
u8* destAddr, int dstWidth, int dstHeight);
void DecodeToTexture(u32 xfbAddr, int srcWidth, int srcHeight, GLuint destTexture);
-u64 EncodeToRamFromTexture(u32 address, GLuint source_texture, bool bFromZBuffer, bool bIsIntensityFmt, u32 copyfmt, int bScaleByHalf, const EFBRectangle& source);
+// returns size of the encoded data (in bytes)
+int EncodeToRamFromTexture(u32 address, GLuint source_texture, bool bFromZBuffer, bool bIsIntensityFmt, u32 copyfmt, int bScaleByHalf, const EFBRectangle& source);
}
diff --git a/Source/Plugins/Plugin_VideoOGL/Src/VertexManager.cpp b/Source/Plugins/Plugin_VideoOGL/Src/VertexManager.cpp
index 5144c328d9..e3b55987ec 100644
--- a/Source/Plugins/Plugin_VideoOGL/Src/VertexManager.cpp
+++ b/Source/Plugins/Plugin_VideoOGL/Src/VertexManager.cpp
@@ -160,7 +160,7 @@ void VertexManager::vFlush()
if (tentry)
{
// 0s are probably for no manual wrapping needed.
- PixelShaderManager::SetTexDims(i, tentry->realW, tentry->realH, 0, 0);
+ PixelShaderManager::SetTexDims(i, tentry->native_width, tentry->native_height, 0, 0);
if (g_ActiveConfig.iLog & CONF_SAVETEXTURES)
{