diff --git a/CMakeLists.txt b/CMakeLists.txt index 5be55987dc..db1d065202 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1436,8 +1436,6 @@ set(GPU_GLES GPU/GLES/StencilBufferGLES.cpp GPU/GLES/TextureCacheGLES.cpp GPU/GLES/TextureCacheGLES.h - GPU/GLES/TextureScalerGLES.cpp - GPU/GLES/TextureScalerGLES.h GPU/GLES/DrawEngineGLES.cpp GPU/GLES/DrawEngineGLES.h ) @@ -1462,8 +1460,6 @@ set(GPU_VULKAN GPU/Vulkan/StencilBufferVulkan.cpp GPU/Vulkan/TextureCacheVulkan.cpp GPU/Vulkan/TextureCacheVulkan.h - GPU/Vulkan/TextureScalerVulkan.cpp - GPU/Vulkan/TextureScalerVulkan.h GPU/Vulkan/VulkanUtil.cpp GPU/Vulkan/VulkanUtil.h ) @@ -1484,8 +1480,6 @@ set(GPU_D3D9 GPU/Directx9/StencilBufferDX9.cpp GPU/Directx9/TextureCacheDX9.cpp GPU/Directx9/TextureCacheDX9.h - GPU/Directx9/TextureScalerDX9.cpp - GPU/Directx9/TextureScalerDX9.h ) set(GPU_D3D11 @@ -1506,8 +1500,6 @@ set(GPU_D3D11 GPU/D3D11/StencilBufferD3D11.cpp GPU/D3D11/TextureCacheD3D11.cpp GPU/D3D11/TextureCacheD3D11.h - GPU/D3D11/TextureScalerD3D11.cpp - GPU/D3D11/TextureScalerD3D11.h ) # We build Vulkan even on Apple to avoid annoying build differences. diff --git a/GPU/Common/TextureCacheCommon.cpp b/GPU/Common/TextureCacheCommon.cpp index 339cc6c80f..a6530aa374 100644 --- a/GPU/Common/TextureCacheCommon.cpp +++ b/GPU/Common/TextureCacheCommon.cpp @@ -1543,17 +1543,18 @@ CheckAlphaResult TextureCacheCommon::DecodeTextureLevel(u8 *out, int outPitch, G if (!swizzled) { // Just a simple copy, we swizzle the color format. fullAlphaMask = TfmtRawToFullAlpha(format); - if (reverseColors) { + if (expandTo32bit) { + // This is OK even if reverseColors is on, because it expands to the 8888 format which is the same in reverse mode. + for (int y = 0; y < h; ++y) { + CheckMask16((const u16 *)(texptr + bufw * sizeof(u16) * y), w, &alphaSum); + ConvertFormatToRGBA8888(format, (u32 *)(out + outPitch * y), (const u16 *)texptr + bufw * y, w); + } + } else if (reverseColors) { // Just check the input's alpha to reuse code. TODO: make a specialized ReverseColors that checks as we go. for (int y = 0; y < h; ++y) { CheckMask16((const u16 *)(texptr + bufw * sizeof(u16) * y), w, &alphaSum); ReverseColors(out + outPitch * y, texptr + bufw * sizeof(u16) * y, format, w); } - } else if (expandTo32bit) { - for (int y = 0; y < h; ++y) { - CheckMask16((const u16 *)(texptr + bufw * sizeof(u16) * y), w, &alphaSum); - ConvertFormatToRGBA8888(format, (u32 *)(out + outPitch * y), (const u16 *)texptr + bufw * y, w); - } } else { for (int y = 0; y < h; ++y) { CopyAndSumMask16((u16 *)(out + outPitch * y), (u16 *)(texptr + bufw * sizeof(u16) * y), w, &alphaSum); @@ -1573,18 +1574,19 @@ CheckAlphaResult TextureCacheCommon::DecodeTextureLevel(u8 *out, int outPitch, G const u8 *unswizzled = (u8 *)tmpTexBuf32_.data(); fullAlphaMask = TfmtRawToFullAlpha(format); - if (reverseColors) { - // Just check the swizzled input's alpha to reuse code. TODO: make a specialized ReverseColors that checks as we go. - for (int y = 0; y < h; ++y) { - CheckMask16((const u16 *)(unswizzled + bufw * sizeof(u16) * y), w, &alphaSum); - ReverseColors(out + outPitch * y, unswizzled + bufw * sizeof(u16) * y, format, w); - } - } else if (expandTo32bit) { + if (expandTo32bit) { + // This is OK even if reverseColors is on, because it expands to the 8888 format which is the same in reverse mode. // Just check the swizzled input's alpha to reuse code. TODO: make a specialized ConvertFormatToRGBA8888 that checks as we go. for (int y = 0; y < h; ++y) { CheckMask16((const u16 *)(unswizzled + bufw * sizeof(u16) * y), w, &alphaSum); ConvertFormatToRGBA8888(format, (u32 *)(out + outPitch * y), (const u16 *)unswizzled + bufw * y, w); } + } else if (reverseColors) { + // Just check the swizzled input's alpha to reuse code. TODO: make a specialized ReverseColors that checks as we go. + for (int y = 0; y < h; ++y) { + CheckMask16((const u16 *)(unswizzled + bufw * sizeof(u16) * y), w, &alphaSum); + ReverseColors(out + outPitch * y, unswizzled + bufw * sizeof(u16) * y, format, w); + } } else { for (int y = 0; y < h; ++y) { CopyAndSumMask16((u16 *)(out + outPitch * y), (const u16 *)(unswizzled + bufw * sizeof(u16) * y), w, &alphaSum); diff --git a/GPU/Common/TextureCacheCommon.h b/GPU/Common/TextureCacheCommon.h index 5f8be30d96..e573cdeb7f 100644 --- a/GPU/Common/TextureCacheCommon.h +++ b/GPU/Common/TextureCacheCommon.h @@ -27,6 +27,7 @@ #include "Core/System.h" #include "GPU/Common/GPUDebugInterface.h" #include "GPU/Common/TextureDecoder.h" +#include "GPU/Common/TextureScalerCommon.h" enum FramebufferNotification { NOTIFY_FB_CREATED, @@ -376,6 +377,7 @@ protected: Draw::DrawContext *draw_; TextureReplacer replacer_; + TextureScalerCommon scaler_; FramebufferManagerCommon *framebufferManager_; bool clearCacheNextFrame_ = false; diff --git a/GPU/Common/TextureScalerCommon.cpp b/GPU/Common/TextureScalerCommon.cpp index 6f69a360e4..46d80f0aad 100644 --- a/GPU/Common/TextureScalerCommon.cpp +++ b/GPU/Common/TextureScalerCommon.cpp @@ -499,30 +499,22 @@ TextureScalerCommon::TextureScalerCommon() { TextureScalerCommon::~TextureScalerCommon() { } -bool TextureScalerCommon::IsEmptyOrFlat(u32* data, int pixels, int fmt) { - int pixelsPerWord = 4 / BytesPerPixel(fmt); +bool TextureScalerCommon::IsEmptyOrFlat(u32* data, int pixels) { + int pixelsPerWord = 1; u32 ref = data[0]; - if (pixelsPerWord > 1 && (ref & 0x0000FFFF) != (ref >> 16)) { - return false; - } - for (int i = 0; i < pixels / pixelsPerWord; ++i) { - if (data[i] != ref) return false; + // TODO: SIMD-ify this (although, for most textures we'll get our very early) + for (int i = 0; i < pixels; ++i) { + if (data[i] != ref) + return false; } return true; } -void TextureScalerCommon::ScaleAlways(u32 *out, u32 *src, u32 &dstFmt, int &width, int &height, int factor) { - if (IsEmptyOrFlat(src, width*height, dstFmt)) { +void TextureScalerCommon::ScaleAlways(u32 *out, u32 *src, int &width, int &height, int factor) { + if (IsEmptyOrFlat(src, width * height)) { // This means it was a flat texture. Vulkan wants the size up front, so we need to make it happen. - u32 pixel; - // Since it's flat, one pixel is enough. It might end up pointing to data, though. - u32 *pixelPointer = &pixel; - ConvertTo8888(dstFmt, src, pixelPointer, 1, 1); - if (pixelPointer != &pixel) { - pixel = *pixelPointer; - } + u32 pixel = *src; - dstFmt = Get8888Format(); width *= factor; height *= factor; @@ -536,24 +528,20 @@ void TextureScalerCommon::ScaleAlways(u32 *out, u32 *src, u32 &dstFmt, int &widt } } } else { - ScaleInto(out, src, dstFmt, width, height, factor); + ScaleInto(out, src, width, height, factor); } } -bool TextureScalerCommon::ScaleInto(u32 *outputBuf, u32 *src, u32 &dstFmt, int &width, int &height, int factor) { +bool TextureScalerCommon::ScaleInto(u32 *outputBuf, u32 *src, int &width, int &height, int factor) { #ifdef SCALING_MEASURE_TIME double t_start = time_now_d(); #endif - bufInput.resize(width*height); // used to store the input image image if it needs to be reformatted - u32 *inputBuf = bufInput.data(); - - // convert texture to correct format for scaling - ConvertTo8888(dstFmt, src, inputBuf, width, height); + u32 *inputBuf = src; // deposterize if (g_Config.bTexDeposterize) { - bufDeposter.resize(width*height); + bufDeposter.resize(width * height); DePosterize(inputBuf, bufDeposter.data(), width, height); inputBuf = bufDeposter.data(); } @@ -577,7 +565,6 @@ bool TextureScalerCommon::ScaleInto(u32 *outputBuf, u32 *src, u32 &dstFmt, int & } // update values accordingly - dstFmt = Get8888Format(); width *= factor; height *= factor; @@ -592,18 +579,18 @@ bool TextureScalerCommon::ScaleInto(u32 *outputBuf, u32 *src, u32 &dstFmt, int & return true; } -bool TextureScalerCommon::Scale(u32* &data, u32 &dstFmt, int &width, int &height, int factor) { +bool TextureScalerCommon::Scale(u32* &data, int &width, int &height, int factor) { // prevent processing empty or flat textures (this happens a lot in some games) // doesn't hurt the standard case, will be very quick for textures with actual texture - if (IsEmptyOrFlat(data, width*height, dstFmt)) { + if (IsEmptyOrFlat(data, width*height)) { DEBUG_LOG(G3D, "TextureScaler: early exit -- empty/flat texture"); return false; } - bufOutput.resize(width*height*factor*factor); // used to store the upscaled image + bufOutput.resize(width * height * (factor * factor)); // used to store the upscaled image u32 *outputBuf = bufOutput.data(); - if (ScaleInto(outputBuf, data, dstFmt, width, height, factor)) { + if (ScaleInto(outputBuf, data, width, height, factor)) { data = outputBuf; return true; } diff --git a/GPU/Common/TextureScalerCommon.h b/GPU/Common/TextureScalerCommon.h index 96c0e86390..80ce86d6e4 100644 --- a/GPU/Common/TextureScalerCommon.h +++ b/GPU/Common/TextureScalerCommon.h @@ -22,22 +22,21 @@ static const int MIN_TEXSCALE_LINES_PER_THREAD = 4; +// The texture scaler requires input to be in R8G8B8A8. +// (It's OK if you flip R and B as they are not treated very differently from each other. +// They will of course not unflip during the operation so be aware of that). class TextureScalerCommon { public: TextureScalerCommon(); ~TextureScalerCommon(); - void ScaleAlways(u32 *out, u32 *src, u32 &dstFmt, int &width, int &height, int factor); - bool Scale(u32 *&data, u32 &dstfmt, int &width, int &height, int factor); - bool ScaleInto(u32 *out, u32 *src, u32 &dstfmt, int &width, int &height, int factor); + void ScaleAlways(u32 *out, u32 *src, int &width, int &height, int factor); + bool Scale(u32 *&data, int &width, int &height, int factor); + bool ScaleInto(u32 *out, u32 *src, int &width, int &height, int factor); enum { XBRZ = 0, HYBRID = 1, BICUBIC = 2, HYBRID_BICUBIC = 3 }; protected: - virtual void ConvertTo8888(u32 format, u32 *source, u32 *&dest, int width, int height) = 0; - virtual int BytesPerPixel(u32 format) = 0; - virtual u32 Get8888Format() = 0; - void ScaleXBRZ(int factor, u32* source, u32* dest, int width, int height); void ScaleBilinear(int factor, u32* source, u32* dest, int width, int height); void ScaleBicubicBSpline(int factor, u32* source, u32* dest, int width, int height); @@ -46,10 +45,10 @@ protected: void DePosterize(u32* source, u32* dest, int width, int height); - bool IsEmptyOrFlat(u32* data, int pixels, int fmt); + bool IsEmptyOrFlat(u32* data, int pixels); // depending on the factor and texture sizes, these can get pretty large // maximum is (100 MB total for a 512 by 512 texture with scaling factor 5 and hybrid scaling) // of course, scaling factor 5 is totally silly anyway - SimpleBuf bufInput, bufDeposter, bufOutput, bufTmp1, bufTmp2, bufTmp3; + SimpleBuf bufDeposter, bufOutput, bufTmp1, bufTmp2, bufTmp3; }; diff --git a/GPU/D3D11/TextureCacheD3D11.cpp b/GPU/D3D11/TextureCacheD3D11.cpp index 1544bb028c..503dd69f99 100644 --- a/GPU/D3D11/TextureCacheD3D11.cpp +++ b/GPU/D3D11/TextureCacheD3D11.cpp @@ -461,14 +461,13 @@ void TextureCacheD3D11::BuildTexture(TexCacheEntry *const entry) { ID3D11ShaderResourceView *view; ID3D11Texture2D *texture = DxTex(entry); _assert_(texture == nullptr); - DXGI_FORMAT tfmt = dstFmt; if (plan.replaced->GetSize(plan.baseLevelSrc, tw, th)) { - tfmt = ToDXGIFormat(plan.replaced->Format(plan.baseLevelSrc)); + dstFmt = ToDXGIFormat(plan.replaced->Format(plan.baseLevelSrc)); } else { tw *= plan.scaleFactor; th *= plan.scaleFactor; if (plan.scaleFactor > 1) { - tfmt = DXGI_FORMAT_B8G8R8A8_UNORM; + dstFmt = DXGI_FORMAT_B8G8R8A8_UNORM; } } @@ -482,7 +481,7 @@ void TextureCacheD3D11::BuildTexture(TexCacheEntry *const entry) { desc.SampleDesc.Count = 1; desc.Width = tw; desc.Height = th; - desc.Format = tfmt; + desc.Format = dstFmt; desc.MipLevels = levels; desc.BindFlags = D3D11_BIND_SHADER_RESOURCE; @@ -603,18 +602,15 @@ void TextureCacheD3D11::LoadTextureLevel(TexCacheEntry &entry, ReplacedTexture & decPitch = mapRowPitch; } - bool expand32 = !gstate_c.Supports(GPU_SUPPORTS_16BIT_FORMATS); + bool expand32 = !gstate_c.Supports(GPU_SUPPORTS_16BIT_FORMATS) || scaleFactor > 1; CheckAlphaResult alphaResult = DecodeTextureLevel((u8 *)pixelData, decPitch, tfmt, clutformat, texaddr, srcLevel, bufw, false, expand32); entry.SetAlphaStatus(alphaResult, srcLevel); if (scaleFactor > 1) { - u32 scaleFmt = (u32)dstFmt; - scaler.ScaleAlways((u32 *)mapData, pixelData, scaleFmt, w, h, scaleFactor); + scaler_.ScaleAlways((u32 *)mapData, pixelData, w, h, scaleFactor); pixelData = (u32 *)mapData; - // We always end up at 8888. Other parts assume this. - _assert_(scaleFmt == DXGI_FORMAT_B8G8R8A8_UNORM); bpp = sizeof(u32); decPitch = w * bpp; diff --git a/GPU/D3D11/TextureCacheD3D11.h b/GPU/D3D11/TextureCacheD3D11.h index ae71d79bb9..fcd4458b6d 100644 --- a/GPU/D3D11/TextureCacheD3D11.h +++ b/GPU/D3D11/TextureCacheD3D11.h @@ -23,7 +23,6 @@ #include "GPU/GPU.h" #include "GPU/GPUInterface.h" -#include "GPU/D3D11/TextureScalerD3D11.h" #include "GPU/Common/TextureCacheCommon.h" struct VirtualFramebuffer; @@ -86,8 +85,6 @@ private: return (ID3D11ShaderResourceView *)entry->textureView; } - TextureScalerD3D11 scaler; - SamplerCacheD3D11 samplerCache_; ID3D11ShaderResourceView *lastBoundTexture; diff --git a/GPU/D3D11/TextureScalerD3D11.cpp b/GPU/D3D11/TextureScalerD3D11.cpp deleted file mode 100644 index 0a40d617c8..0000000000 --- a/GPU/D3D11/TextureScalerD3D11.cpp +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright (c) 2012- PPSSPP 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 or later versions. - -// 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 git repository and contact information can be found at -// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/. - -#include - -#include -#include "Common/Data/Convert/ColorConv.h" -#include "Core/ThreadPools.h" -#include "Common/Thread/ParallelLoop.h" -#include "GPU/Common/TextureScalerCommon.h" -#include "GPU/D3D11/TextureScalerD3D11.h" -#include "GPU/D3D11/GPU_D3D11.h" - -int TextureScalerD3D11::BytesPerPixel(u32 format) { - return format == DXGI_FORMAT_B8G8R8A8_UNORM ? 4 : 2; -} - -u32 TextureScalerD3D11::Get8888Format() { - return DXGI_FORMAT_B8G8R8A8_UNORM; -} - -void TextureScalerD3D11::ConvertTo8888(u32 format, u32* source, u32* &dest, int width, int height) { - switch (format) { - case DXGI_FORMAT_B8G8R8A8_UNORM: - dest = source; // already fine - break; - - case DXGI_FORMAT_B4G4R4A4_UNORM: - ParallelRangeLoop(&g_threadManager, std::bind(&convert4444_dx9, (u16*)source, dest, width, std::placeholders::_1, std::placeholders::_2), 0, height, MIN_TEXSCALE_LINES_PER_THREAD); - break; - - case DXGI_FORMAT_B5G6R5_UNORM: - ParallelRangeLoop(&g_threadManager, std::bind(&convert565_dx9, (u16*)source, dest, width, std::placeholders::_1, std::placeholders::_2), 0, height, MIN_TEXSCALE_LINES_PER_THREAD); - break; - - case DXGI_FORMAT_B5G5R5A1_UNORM: - ParallelRangeLoop(&g_threadManager, std::bind(&convert5551_dx9, (u16*)source, dest, width, std::placeholders::_1, std::placeholders::_2), 0, height, MIN_TEXSCALE_LINES_PER_THREAD); - break; - - default: - dest = source; - ERROR_LOG(G3D, "iXBRZTexScaling: unsupported texture format"); - } -} diff --git a/GPU/D3D11/TextureScalerD3D11.h b/GPU/D3D11/TextureScalerD3D11.h deleted file mode 100644 index 298045342a..0000000000 --- a/GPU/D3D11/TextureScalerD3D11.h +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (c) 2012- PPSSPP 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 or later versions. - -// 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 git repository and contact information can be found at -// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/. - -#pragma once - -#include "Common/CommonTypes.h" -#include "GPU/Common/TextureScalerCommon.h" - -class TextureScalerD3D11 : public TextureScalerCommon { -private: - // NOTE: We use GE formats, D3D11 doesn't support 4444 - void ConvertTo8888(u32 format, u32* source, u32* &dest, int width, int height) override; - int BytesPerPixel(u32 format) override; - u32 Get8888Format() override; -}; \ No newline at end of file diff --git a/GPU/Directx9/TextureCacheDX9.cpp b/GPU/Directx9/TextureCacheDX9.cpp index 001bb571be..be56de79bc 100644 --- a/GPU/Directx9/TextureCacheDX9.cpp +++ b/GPU/Directx9/TextureCacheDX9.cpp @@ -416,22 +416,21 @@ void TextureCacheDX9::BuildTexture(TexCacheEntry *const entry) { LPDIRECT3DTEXTURE9 &texture = DxTex(entry); D3DFORMAT dstFmt = GetDestFormat(GETextureFormat(entry->format), gstate.getClutPaletteFormat()); D3DPOOL pool = D3DPOOL_DEFAULT; - D3DFORMAT tfmt = (D3DFORMAT)(dstFmt); int usage = D3DUSAGE_DYNAMIC; if (plan.replaced->GetSize(plan.baseLevelSrc, tw, th)) { - tfmt = ToD3D9Format(plan.replaced->Format(plan.baseLevelSrc)); + dstFmt = ToD3D9Format(plan.replaced->Format(plan.baseLevelSrc)); } else { tw *= plan.scaleFactor; th *= plan.scaleFactor; if (plan.scaleFactor > 1) { - tfmt = D3DFMT_A8R8G8B8; + dstFmt = D3DFMT_A8R8G8B8; } } // We don't yet have mip generation, so clamp the number of levels to the ones we can load directly. int levels = std::min(plan.levelsToCreate, plan.levelsToLoad); - HRESULT hr = device_->CreateTexture(tw, th, levels, usage, tfmt, pool, &texture, NULL); + HRESULT hr = device_->CreateTexture(tw, th, levels, usage, dstFmt, pool, &texture, NULL); if (FAILED(hr)) { INFO_LOG(G3D, "Failed to create D3D texture: %dx%d", tw, th); @@ -532,11 +531,13 @@ void TextureCacheDX9::LoadTextureLevel(TexCacheEntry &entry, uint8_t *data, int decPitch = w * bpp; } - CheckAlphaResult alphaResult = DecodeTextureLevel((u8 *)pixelData, decPitch, tfmt, clutformat, texaddr, level, bufw, false, false); + bool expand32 = scaleFactor > 1; + + CheckAlphaResult alphaResult = DecodeTextureLevel((u8 *)pixelData, decPitch, tfmt, clutformat, texaddr, level, bufw, false, expand32); entry.SetAlphaStatus(alphaResult, level); if (scaleFactor > 1) { - scaler.ScaleAlways((u32 *)data, pixelData, dstFmt, w, h, scaleFactor); + scaler_.ScaleAlways((u32 *)data, pixelData, w, h, scaleFactor); pixelData = (u32 *)data; // We always end up at 8888. Other parts assume this. diff --git a/GPU/Directx9/TextureCacheDX9.h b/GPU/Directx9/TextureCacheDX9.h index 8191516118..9b7fe62eb2 100644 --- a/GPU/Directx9/TextureCacheDX9.h +++ b/GPU/Directx9/TextureCacheDX9.h @@ -21,7 +21,6 @@ #include "GPU/GPU.h" #include "GPU/GPUInterface.h" -#include "GPU/Directx9/TextureScalerDX9.h" #include "GPU/Common/TextureCacheCommon.h" struct VirtualFramebuffer; @@ -77,8 +76,6 @@ private: LPDIRECT3DDEVICE9 device_; LPDIRECT3DDEVICE9EX deviceEx_; - TextureScalerDX9 scaler; - LPDIRECT3DVERTEXDECLARATION9 pFramebufferVertexDecl; LPDIRECT3DTEXTURE9 lastBoundTexture; diff --git a/GPU/Directx9/TextureScalerDX9.cpp b/GPU/Directx9/TextureScalerDX9.cpp deleted file mode 100644 index 755c06cf2d..0000000000 --- a/GPU/Directx9/TextureScalerDX9.cpp +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright (c) 2012- PPSSPP 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 or later versions. - -// 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 git repository and contact information can be found at -// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/. - -#include - -#include "Common/CommonTypes.h" -#include "Common/Data/Convert/ColorConv.h" -#include "Common/Thread/ParallelLoop.h" -#include "Core/ThreadPools.h" -#include "GPU/Common/TextureScalerCommon.h" -#include "GPU/Directx9/TextureScalerDX9.h" -#include "GPU/Directx9/GPU_DX9.h" - -namespace DX9 { - -int TextureScalerDX9::BytesPerPixel(u32 format) { - return format == D3DFMT_A8R8G8B8 ? 4 : 2; -} - -u32 TextureScalerDX9::Get8888Format() { - return D3DFMT_A8R8G8B8; -} - -void TextureScalerDX9::ConvertTo8888(u32 format, u32* source, u32* &dest, int width, int height) { - switch(format) { - case D3DFMT_A8R8G8B8: - dest = source; // already fine - break; - - case D3DFMT_A4R4G4B4: - ParallelRangeLoop(&g_threadManager, std::bind(&convert4444_dx9, (u16*)source, dest, width, std::placeholders::_1, std::placeholders::_2), 0, height, MIN_TEXSCALE_LINES_PER_THREAD); - break; - - case D3DFMT_R5G6B5: - ParallelRangeLoop(&g_threadManager, std::bind(&convert565_dx9, (u16*)source, dest, width, std::placeholders::_1, std::placeholders::_2), 0, height, MIN_TEXSCALE_LINES_PER_THREAD); - break; - - case D3DFMT_A1R5G5B5: - ParallelRangeLoop(&g_threadManager, std::bind(&convert5551_dx9, (u16*)source, dest, width, std::placeholders::_1, std::placeholders::_2), 0, height, MIN_TEXSCALE_LINES_PER_THREAD); - break; - - default: - dest = source; - ERROR_LOG(G3D, "iXBRZTexScaling: unsupported texture format"); - } -} - -} // namespace diff --git a/GPU/Directx9/TextureScalerDX9.h b/GPU/Directx9/TextureScalerDX9.h deleted file mode 100644 index bbae698130..0000000000 --- a/GPU/Directx9/TextureScalerDX9.h +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (c) 2012- PPSSPP 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 or later versions. - -// 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 git repository and contact information can be found at -// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/. - -#pragma once - -#include "Common/CommonTypes.h" -#include "GPU/Common/TextureScalerCommon.h" - -namespace DX9 { - -class TextureScalerDX9 : public TextureScalerCommon { -private: - void ConvertTo8888(u32 format, u32* source, u32* &dest, int width, int height) override; - int BytesPerPixel(u32 format) override; - u32 Get8888Format() override; -}; - -}; diff --git a/GPU/GLES/TextureCacheGLES.cpp b/GPU/GLES/TextureCacheGLES.cpp index 38a7858e5c..b1b70bde06 100644 --- a/GPU/GLES/TextureCacheGLES.cpp +++ b/GPU/GLES/TextureCacheGLES.cpp @@ -439,13 +439,21 @@ void TextureCacheGLES::BuildTexture(TexCacheEntry *const entry) { // the bottom few levels or rely on OpenGL's autogen mipmaps instead, which might not // be as good quality as the game's own (might even be better in some cases though). - // TODO: Actually pass in correct size here. The size here is (in GL) not yet used for anything else - // than determining if we can wrap this texture size, that is, it's pow2 or not on very old hardware, else true. - // This will be easy after .. well, yet another refactoring, where I hoist the size calculation out of LoadTextureLevel - // and unify BuildTexture. - entry->textureName = render_->CreateTexture(GL_TEXTURE_2D, plan.w, plan.h, plan.levelsToCreate); + int tw = plan.w; + int th = plan.h; Draw::DataFormat dstFmt = GetDestFormat(GETextureFormat(entry->format), gstate.getClutPaletteFormat()); + if (plan.replaced->GetSize(plan.baseLevelSrc, tw, th)) { + dstFmt = plan.replaced->Format(plan.baseLevelSrc); + } else { + tw *= plan.scaleFactor; + th *= plan.scaleFactor; + if (plan.scaleFactor > 1) { + dstFmt = Draw::DataFormat::R8G8B8A8_UNORM; + } + } + + entry->textureName = render_->CreateTexture(GL_TEXTURE_2D, tw, tw, plan.levelsToCreate); // Apply some additional compatibility checks. if (plan.levelsToLoad > 1) { @@ -541,19 +549,20 @@ void TextureCacheGLES::LoadTextureLevel(TexCacheEntry &entry, ReplacedTexture &r int bufw = GetTextureBufw(srcLevel, texaddr, GETextureFormat(entry.format)); int pixelSize = dstFmt == Draw::DataFormat::R8G8B8A8_UNORM ? 4 : 2; + // We leave GL_UNPACK_ALIGNMENT at 4, so this must be at least 4. decPitch = std::max(w * pixelSize, 4); pixelData = (uint8_t *)AllocateAlignedMemory(decPitch * h * pixelSize, 16); - CheckAlphaResult alphaStatus = DecodeTextureLevel(pixelData, decPitch, GETextureFormat(entry.format), clutformat, texaddr, srcLevel, bufw, true, false); + bool expand32 = scaleFactor > 1; + + CheckAlphaResult alphaStatus = DecodeTextureLevel(pixelData, decPitch, GETextureFormat(entry.format), clutformat, texaddr, srcLevel, bufw, true, expand32); entry.SetAlphaStatus(alphaStatus, srcLevel); if (scaleFactor > 1) { uint8_t *rearrange = (uint8_t *)AllocateAlignedMemory(w * scaleFactor * h * scaleFactor * 4, 16); - u32 dFmt = (u32)dstFmt; - scaler.ScaleAlways((u32 *)rearrange, (u32 *)pixelData, dFmt, w, h, scaleFactor); - dstFmt = (Draw::DataFormat)dFmt; + scaler_.ScaleAlways((u32 *)rearrange, (u32 *)pixelData, w, h, scaleFactor); FreeAlignedMemory(pixelData); pixelData = rearrange; decPitch = w * 4; diff --git a/GPU/GLES/TextureCacheGLES.h b/GPU/GLES/TextureCacheGLES.h index dff63689fc..edf0a6b21f 100644 --- a/GPU/GLES/TextureCacheGLES.h +++ b/GPU/GLES/TextureCacheGLES.h @@ -22,7 +22,6 @@ #include "Common/GPU/OpenGL/GLRenderManager.h" #include "GPU/GPUInterface.h" #include "GPU/GPUState.h" -#include "GPU/GLES/TextureScalerGLES.h" #include "GPU/Common/TextureCacheCommon.h" struct VirtualFramebuffer; @@ -81,8 +80,6 @@ private: GLRenderManager *render_; - TextureScalerGLES scaler; - GLRTexture *lastBoundTexture = nullptr; FramebufferManagerGLES *framebufferManagerGL_; diff --git a/GPU/GLES/TextureScalerGLES.cpp b/GPU/GLES/TextureScalerGLES.cpp deleted file mode 100644 index b535dcd291..0000000000 --- a/GPU/GLES/TextureScalerGLES.cpp +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright (c) 2012- PPSSPP 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 or later versions. - -// 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 git repository and contact information can be found at -// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/. - -#include - -#include "Common/Data/Convert/ColorConv.h" -#include "Common/Log.h" -#include "Common/Thread/ParallelLoop.h" -#include "Common/GPU/OpenGL/GLCommon.h" -#include "Common/GPU/DataFormat.h" - -#include "Core/ThreadPools.h" -#include "GPU/Common/TextureScalerCommon.h" -#include "GPU/GLES/TextureScalerGLES.h" - -int TextureScalerGLES::BytesPerPixel(u32 format) { - return ((Draw::DataFormat)format == Draw::DataFormat::R8G8B8A8_UNORM) ? 4 : 2; -} - -u32 TextureScalerGLES::Get8888Format() { - return (u32)Draw::DataFormat::R8G8B8A8_UNORM; -} - -void TextureScalerGLES::ConvertTo8888(u32 format, u32* source, u32* &dest, int width, int height) { - Draw::DataFormat fmt = (Draw::DataFormat)format; - switch (fmt) { - case Draw::DataFormat::R8G8B8A8_UNORM: - dest = source; // already fine - break; - - case Draw::DataFormat::R4G4B4A4_UNORM_PACK16: - ParallelRangeLoop(&g_threadManager, std::bind(&convert4444_gl, (u16*)source, dest, width, std::placeholders::_1, std::placeholders::_2), 0, height, MIN_TEXSCALE_LINES_PER_THREAD); - break; - - case Draw::DataFormat::R5G6B5_UNORM_PACK16: - ParallelRangeLoop(&g_threadManager, std::bind(&convert565_gl, (u16*)source, dest, width, std::placeholders::_1, std::placeholders::_2), 0, height, MIN_TEXSCALE_LINES_PER_THREAD); - break; - - case Draw::DataFormat::R5G5B5A1_UNORM_PACK16: - ParallelRangeLoop(&g_threadManager, std::bind(&convert5551_gl, (u16*)source, dest, width, std::placeholders::_1, std::placeholders::_2), 0, height, MIN_TEXSCALE_LINES_PER_THREAD); - break; - - default: - dest = source; - ERROR_LOG(G3D, "iXBRZTexScaling: unsupported texture format"); - } -} diff --git a/GPU/GLES/TextureScalerGLES.h b/GPU/GLES/TextureScalerGLES.h deleted file mode 100644 index bf82d8599d..0000000000 --- a/GPU/GLES/TextureScalerGLES.h +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (c) 2012- PPSSPP 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 or later versions. - -// 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 git repository and contact information can be found at -// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/. - -#pragma once - -#include "Common/CommonTypes.h" -#include "GPU/Common/TextureScalerCommon.h" - -class TextureScalerGLES : public TextureScalerCommon { - void ConvertTo8888(u32 format, u32* source, u32* &dest, int width, int height) override; - int BytesPerPixel(u32 format) override; - u32 Get8888Format() override; -}; diff --git a/GPU/GPU.vcxproj b/GPU/GPU.vcxproj index 76bf48ac5e..49db8ec9c4 100644 --- a/GPU/GPU.vcxproj +++ b/GPU/GPU.vcxproj @@ -367,7 +367,6 @@ - @@ -379,7 +378,6 @@ - @@ -425,12 +423,6 @@ true true - - true - true - true - true - true true @@ -463,7 +455,6 @@ - @@ -524,7 +515,6 @@ - @@ -537,7 +527,6 @@ - @@ -595,12 +584,6 @@ true true - - true - true - true - true - true true @@ -635,7 +618,6 @@ - diff --git a/GPU/GPU.vcxproj.filters b/GPU/GPU.vcxproj.filters index b0e829d136..2f26b61aa6 100644 --- a/GPU/GPU.vcxproj.filters +++ b/GPU/GPU.vcxproj.filters @@ -66,9 +66,6 @@ DirectX9 - - DirectX9 - DirectX9 @@ -162,9 +159,6 @@ Vulkan - - Vulkan - Vulkan @@ -177,9 +171,6 @@ GLES - - GLES - GLES @@ -210,9 +201,6 @@ D3D11 - - D3D11 - D3D11 @@ -323,9 +311,6 @@ DirectX9 - - DirectX9 - Common @@ -419,9 +404,6 @@ Vulkan - - Vulkan - Vulkan @@ -434,9 +416,6 @@ GLES - - GLES - GLES @@ -473,9 +452,6 @@ D3D11 - - D3D11 - D3D11 diff --git a/GPU/Vulkan/TextureCacheVulkan.cpp b/GPU/Vulkan/TextureCacheVulkan.cpp index f4769e8d73..8d9a19bb01 100644 --- a/GPU/Vulkan/TextureCacheVulkan.cpp +++ b/GPU/Vulkan/TextureCacheVulkan.cpp @@ -861,7 +861,7 @@ void TextureCacheVulkan::LoadTextureLevel(TexCacheEntry &entry, uint8_t *writePt u32 *pixelData = (u32 *)writePtr; int decPitch = rowPitch; - bool expand32 = !gstate_c.Supports(GPU_SUPPORTS_16BIT_FORMATS) || dstFmt == VK_FORMAT_R8G8B8A8_UNORM; + bool expand32 = !gstate_c.Supports(GPU_SUPPORTS_16BIT_FORMATS) || dstFmt == VK_FORMAT_R8G8B8A8_UNORM || scaleFactor > 1; if (scaleFactor > 1) { tmpTexBufRearrange_.resize(std::max(bufw, w) * h); @@ -879,7 +879,7 @@ void TextureCacheVulkan::LoadTextureLevel(TexCacheEntry &entry, uint8_t *writePt u32 fmt = dstFmt; // CPU scaling reads from the destination buffer so we want cached RAM. uint8_t *rearrange = (uint8_t *)AllocateAlignedMemory(w * scaleFactor * h * scaleFactor * 4, 16); - scaler.ScaleAlways((u32 *)rearrange, pixelData, fmt, w, h, scaleFactor); + scaler_.ScaleAlways((u32 *)rearrange, pixelData, w, h, scaleFactor); pixelData = (u32 *)writePtr; // We always end up at 8888. Other parts assume this. diff --git a/GPU/Vulkan/TextureCacheVulkan.h b/GPU/Vulkan/TextureCacheVulkan.h index 599ad0bce7..a84bfd3a6c 100644 --- a/GPU/Vulkan/TextureCacheVulkan.h +++ b/GPU/Vulkan/TextureCacheVulkan.h @@ -21,7 +21,6 @@ #include "GPU/GPUInterface.h" #include "GPU/GPUState.h" #include "Common/GPU/Vulkan/VulkanContext.h" -#include "GPU/Vulkan/TextureScalerVulkan.h" #include "GPU/Common/TextureCacheCommon.h" #include "GPU/Vulkan/VulkanUtil.h" @@ -122,8 +121,6 @@ private: SamplerCache samplerCache_; - TextureScalerVulkan scaler; - DepalShaderCacheVulkan *depalShaderCache_; ShaderManagerVulkan *shaderManagerVulkan_; DrawEngineVulkan *drawEngine_; diff --git a/GPU/Vulkan/TextureScalerVulkan.cpp b/GPU/Vulkan/TextureScalerVulkan.cpp deleted file mode 100644 index 3b060f0d8f..0000000000 --- a/GPU/Vulkan/TextureScalerVulkan.cpp +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright (c) 2012- PPSSPP 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 or later versions. - -// 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 git repository and contact information can be found at -// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/. - -#include - -#include "Common/CommonTypes.h" -#include "Common/Data/Convert/ColorConv.h" -#include "Common/GPU/Vulkan/VulkanContext.h" -#include "Common/Log.h" -#include "Common/Thread/ParallelLoop.h" -#include "Core/ThreadPools.h" -#include "GPU/Common/TextureScalerCommon.h" -#include "GPU/Vulkan/TextureScalerVulkan.h" -#include "GPU/Vulkan/VulkanUtil.h" - -int TextureScalerVulkan::BytesPerPixel(u32 format) { - return (format == VULKAN_8888_FORMAT) ? 4 : 2; -} - -u32 TextureScalerVulkan::Get8888Format() { - return VULKAN_8888_FORMAT; -} - -void TextureScalerVulkan::ConvertTo8888(u32 format, u32* source, u32* &dest, int width, int height) { - switch (format) { - case VULKAN_8888_FORMAT: - dest = source; // already fine - break; - - case VULKAN_4444_FORMAT: - ParallelRangeLoop(&g_threadManager, std::bind(&convert4444_dx9, (u16*)source, dest, width, std::placeholders::_1, std::placeholders::_2), 0, height, MIN_TEXSCALE_LINES_PER_THREAD); - break; - - case VULKAN_565_FORMAT: - ParallelRangeLoop(&g_threadManager, std::bind(&convert565_dx9, (u16*)source, dest, width, std::placeholders::_1, std::placeholders::_2), 0, height, MIN_TEXSCALE_LINES_PER_THREAD); - break; - - case VULKAN_1555_FORMAT: - ParallelRangeLoop(&g_threadManager, std::bind(&convert5551_dx9, (u16*)source, dest, width, std::placeholders::_1, std::placeholders::_2), 0, height, MIN_TEXSCALE_LINES_PER_THREAD); - break; - - default: - dest = source; - ERROR_LOG(G3D, "iXBRZTexScaling: unsupported texture format"); - } -} diff --git a/GPU/Vulkan/TextureScalerVulkan.h b/GPU/Vulkan/TextureScalerVulkan.h deleted file mode 100644 index dfa8408806..0000000000 --- a/GPU/Vulkan/TextureScalerVulkan.h +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (c) 2012- PPSSPP 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 or later versions. - -// 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 git repository and contact information can be found at -// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/. - -#pragma once - -#include "Common/CommonTypes.h" -#include "GPU/Common/TextureScalerCommon.h" - -class TextureScalerVulkan : public TextureScalerCommon { -protected: - void ConvertTo8888(u32 format, u32* source, u32* &dest, int width, int height) override; - int BytesPerPixel(u32 format) override; - u32 Get8888Format() override; -}; diff --git a/Windows/MainWindowMenu.cpp b/Windows/MainWindowMenu.cpp index 7d4f010242..6aba9d275a 100644 --- a/Windows/MainWindowMenu.cpp +++ b/Windows/MainWindowMenu.cpp @@ -23,7 +23,6 @@ #include "Common/GPU/Vulkan/VulkanLoader.h" #include "Common/StringUtils.h" #if PPSSPP_API(ANY_GL) -#include "GPU/GLES/TextureScalerGLES.h" #include "GPU/GLES/TextureCacheGLES.h" #include "GPU/GLES/FramebufferManagerGLES.h" #endif diff --git a/android/jni/Android.mk b/android/jni/Android.mk index d133898544..ae109b91d1 100644 --- a/android/jni/Android.mk +++ b/android/jni/Android.mk @@ -135,7 +135,6 @@ VULKAN_FILES := \ $(SRC)/GPU/Vulkan/StateMappingVulkan.cpp \ $(SRC)/GPU/Vulkan/StencilBufferVulkan.cpp \ $(SRC)/GPU/Vulkan/TextureCacheVulkan.cpp \ - $(SRC)/GPU/Vulkan/TextureScalerVulkan.cpp \ $(SRC)/GPU/Vulkan/DepalettizeShaderVulkan.cpp \ $(SRC)/GPU/Vulkan/VulkanUtil.cpp \ $(SRC)/GPU/Vulkan/DebugVisVulkan.cpp @@ -358,7 +357,6 @@ EXEC_AND_LIB_FILES := \ $(SRC)/GPU/GLES/StateMappingGLES.cpp.arm \ $(SRC)/GPU/GLES/ShaderManagerGLES.cpp.arm \ $(SRC)/GPU/GLES/FragmentTestCacheGLES.cpp.arm \ - $(SRC)/GPU/GLES/TextureScalerGLES.cpp \ $(SRC)/GPU/Software/BinManager.cpp \ $(SRC)/GPU/Software/Clipper.cpp \ $(SRC)/GPU/Software/DrawPixel.cpp.arm \