Simplify CPU upscaling code

Use the existing expandTo32bit mode in the texture decoder instead of
the backend-specific switches and stuff.

Just gets rid of a bunch of redundant code and makes further changes
easier.
This commit is contained in:
Henrik Rydgård committed 2022-07-30 15:06:25 +02:00
1 parent 3e39f62c3d
commit 063cd18254
25 files changed
+74 -500

No files matched your search

-8
View File
@@ -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.
+15 -13
View File
@@ -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);
+2
View File
@@ -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;
+17 -30
View File
@@ -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;
}
+8 -9
View File
@@ -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<u32> bufInput, bufDeposter, bufOutput, bufTmp1, bufTmp2, bufTmp3;
SimpleBuf<u32> bufDeposter, bufOutput, bufTmp1, bufTmp2, bufTmp3;
};
+5 -9
View File
@@ -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;
-3
View File
@@ -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;
-58
View File
@@ -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 <algorithm>
#include <d3d11.h>
#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");
}
}
-29
View File
@@ -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;
};
+7 -6
View File
@@ -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.
-3
View File
@@ -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;
-62
View File
@@ -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 <algorithm>
#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
-32
View File
@@ -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;
};
};
+18 -9
View File
@@ -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;
-3
View File
@@ -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_;
-61
View File
@@ -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 <algorithm>
#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");
}
}
-27
View File
@@ -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;
};
-18
View File
@@ -367,7 +367,6 @@
<ClInclude Include="D3D11\ShaderManagerD3D11.h" />
<ClInclude Include="D3D11\StateMappingD3D11.h" />
<ClInclude Include="D3D11\TextureCacheD3D11.h" />
<ClInclude Include="D3D11\TextureScalerD3D11.h" />
<ClInclude Include="Debugger\Breakpoints.h" />
<ClInclude Include="Debugger\Debugger.h" />
<ClInclude Include="Debugger\Playback.h" />
@@ -379,7 +378,6 @@
<ClInclude Include="Directx9\GPU_DX9.h" />
<ClInclude Include="Directx9\ShaderManagerDX9.h" />
<ClInclude Include="Directx9\TextureCacheDX9.h" />
<ClInclude Include="Directx9\TextureScalerDX9.h" />
<ClInclude Include="Directx9\DrawEngineDX9.h" />
<ClInclude Include="ge_constants.h" />
<ClInclude Include="GeDisasm.h" />
@@ -425,12 +423,6 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</ExcludedFromBuild>
</ClInclude>
<ClInclude Include="GLES\TextureScalerGLES.h">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</ExcludedFromBuild>
</ClInclude>
<ClInclude Include="GLES\DrawEngineGLES.h">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</ExcludedFromBuild>
@@ -463,7 +455,6 @@
<ClInclude Include="Vulkan\ShaderManagerVulkan.h" />
<ClInclude Include="Vulkan\StateMappingVulkan.h" />
<ClInclude Include="Vulkan\TextureCacheVulkan.h" />
<ClInclude Include="Vulkan\TextureScalerVulkan.h" />
<ClInclude Include="Vulkan\VulkanUtil.h" />
</ItemGroup>
<ItemGroup>
@@ -524,7 +515,6 @@
<ClCompile Include="D3D11\StateMappingD3D11.cpp" />
<ClCompile Include="D3D11\StencilBufferD3D11.cpp" />
<ClCompile Include="D3D11\TextureCacheD3D11.cpp" />
<ClCompile Include="D3D11\TextureScalerD3D11.cpp" />
<ClCompile Include="Debugger\Breakpoints.cpp" />
<ClCompile Include="Debugger\Debugger.cpp" />
<ClCompile Include="Debugger\Playback.cpp" />
@@ -537,7 +527,6 @@
<ClCompile Include="Directx9\StateMappingDX9.cpp" />
<ClCompile Include="Directx9\StencilBufferDX9.cpp" />
<ClCompile Include="Directx9\TextureCacheDX9.cpp" />
<ClCompile Include="Directx9\TextureScalerDX9.cpp" />
<ClCompile Include="Directx9\DrawEngineDX9.cpp" />
<ClCompile Include="GeDisasm.cpp" />
<ClCompile Include="GeConstants.cpp" />
@@ -595,12 +584,6 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="GLES\TextureScalerGLES.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="GLES\DrawEngineGLES.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</ExcludedFromBuild>
@@ -635,7 +618,6 @@
<ClCompile Include="Vulkan\StateMappingVulkan.cpp" />
<ClCompile Include="Vulkan\StencilBufferVulkan.cpp" />
<ClCompile Include="Vulkan\TextureCacheVulkan.cpp" />
<ClCompile Include="Vulkan\TextureScalerVulkan.cpp" />
<ClCompile Include="Vulkan\VulkanUtil.cpp" />
</ItemGroup>
<ItemGroup>
-24
View File
@@ -66,9 +66,6 @@
<ClInclude Include="Directx9\DrawEngineDX9.h">
<Filter>DirectX9</Filter>
</ClInclude>
<ClInclude Include="Directx9\TextureScalerDX9.h">
<Filter>DirectX9</Filter>
</ClInclude>
<ClInclude Include="Directx9\TextureCacheDX9.h">
<Filter>DirectX9</Filter>
</ClInclude>
@@ -162,9 +159,6 @@
<ClInclude Include="Vulkan\TextureCacheVulkan.h">
<Filter>Vulkan</Filter>
</ClInclude>
<ClInclude Include="Vulkan\TextureScalerVulkan.h">
<Filter>Vulkan</Filter>
</ClInclude>
<ClInclude Include="Vulkan\VulkanUtil.h">
<Filter>Vulkan</Filter>
</ClInclude>
@@ -177,9 +171,6 @@
<ClInclude Include="GLES\StateMappingGLES.h">
<Filter>GLES</Filter>
</ClInclude>
<ClInclude Include="GLES\TextureScalerGLES.h">
<Filter>GLES</Filter>
</ClInclude>
<ClInclude Include="GLES\DepalettizeShaderGLES.h">
<Filter>GLES</Filter>
</ClInclude>
@@ -210,9 +201,6 @@
<ClInclude Include="D3D11\DepalettizeShaderD3D11.h">
<Filter>D3D11</Filter>
</ClInclude>
<ClInclude Include="D3D11\TextureScalerD3D11.h">
<Filter>D3D11</Filter>
</ClInclude>
<ClInclude Include="D3D11\D3D11Util.h">
<Filter>D3D11</Filter>
</ClInclude>
@@ -323,9 +311,6 @@
<ClCompile Include="Directx9\ShaderManagerDX9.cpp">
<Filter>DirectX9</Filter>
</ClCompile>
<ClCompile Include="Directx9\TextureScalerDX9.cpp">
<Filter>DirectX9</Filter>
</ClCompile>
<ClCompile Include="Common\IndexGenerator.cpp">
<Filter>Common</Filter>
</ClCompile>
@@ -419,9 +404,6 @@
<ClCompile Include="Vulkan\TextureCacheVulkan.cpp">
<Filter>Vulkan</Filter>
</ClCompile>
<ClCompile Include="Vulkan\TextureScalerVulkan.cpp">
<Filter>Vulkan</Filter>
</ClCompile>
<ClCompile Include="Vulkan\VulkanUtil.cpp">
<Filter>Vulkan</Filter>
</ClCompile>
@@ -434,9 +416,6 @@
<ClCompile Include="GLES\StateMappingGLES.cpp">
<Filter>GLES</Filter>
</ClCompile>
<ClCompile Include="GLES\TextureScalerGLES.cpp">
<Filter>GLES</Filter>
</ClCompile>
<ClCompile Include="GLES\StencilBufferGLES.cpp">
<Filter>GLES</Filter>
</ClCompile>
@@ -473,9 +452,6 @@
<ClCompile Include="D3D11\DepalettizeShaderD3D11.cpp">
<Filter>D3D11</Filter>
</ClCompile>
<ClCompile Include="D3D11\TextureScalerD3D11.cpp">
<Filter>D3D11</Filter>
</ClCompile>
<ClCompile Include="D3D11\D3D11Util.cpp">
<Filter>D3D11</Filter>
</ClCompile>
+2 -2
View File
@@ -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.
-3
View File
@@ -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_;
-60
View File
@@ -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 <algorithm>
#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");
}
}
-28
View File
@@ -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;
};
-1
View File
@@ -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
-2
View File
@@ -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 \