Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add compressed texture format support checks
  • Loading branch information
hrydgard committed Mar 12, 2023
1 parent c04acaf commit a4b5641
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 4 deletions.
4 changes: 4 additions & 0 deletions Common/GPU/OpenGL/GLFeatures.cpp
Expand Up @@ -593,8 +593,12 @@ bool CheckGLExtensions() {
switch (compressedFormats[i]) {
case GL_COMPRESSED_RGB8_ETC2: gl_extensions.supportsETC2 = true; break;
case GL_COMPRESSED_RGBA_ASTC_4x4_KHR: gl_extensions.supportsASTC = true; break;
#if !PPSSPP_PLATFORM(IOS) && !PPSSPP_PLATFORM(MAC)
case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: gl_extensions.supportsBC123 = true; break;
#endif
#if PPSSPP_PLATFORM(WINDOWS)
case GL_COMPRESSED_RGBA_BPTC_UNORM: gl_extensions.supportsBC7 = true; break;
#endif
}
}
}
Expand Down
12 changes: 10 additions & 2 deletions GPU/Common/ReplacedTexture.cpp
Expand Up @@ -262,14 +262,22 @@ bool ReplacedTexture::LoadLevelData(ReplacedTextureLevel &level, int mipLevel, D
switch (format) {
case 98: // DXGI_FORMAT_BC7_UNORM:
case 99: // DXGI_FORMAT_BC7_UNORM_SRGB:
if (!desc_->formatSupport.bc7) {
WARN_LOG(G3D, "BC1-3 formats not supported, skipping texture");
good = false;
}
ddsBytesToRead = RoundUpTo4(header.dwWidth) * RoundUpTo4(header.dwHeight); // 1 byte per pixel so this should be right.
*pixelFormat = Draw::DataFormat::BC7_UNORM_BLOCK;
break;
default:
ERROR_LOG(G3D, "DXGI pixel format %d not supported.", header10.dxgiFormat);
WARN_LOG(G3D, "DXGI pixel format %d not supported.", header10.dxgiFormat);
good = false;
}
} else {
if (!desc_->formatSupport.bc123) {
WARN_LOG(G3D, "BC1-3 formats not supported");
good = false;
}
ddsBytesToRead = header.dwPitchOrLinearSize;
format = header.ddspf.dwFourCC;
// OK, there are a number of possible formats we might have ended up with. We choose just a few
Expand Down Expand Up @@ -370,7 +378,7 @@ bool ReplacedTexture::LoadLevelData(ReplacedTextureLevel &level, int mipLevel, D
out.resize(ddsBytesToRead);
size_t read_bytes = vfs_->Read(openFile, &out[0], ddsBytesToRead);
if (read_bytes != ddsBytesToRead) {
WARN_LOG(G3D, "DDS: Expected %d bytes, got %d", ddsBytesToRead, read_bytes);
WARN_LOG(G3D, "DDS: Expected %d bytes, got %d", ddsBytesToRead, (int)read_bytes);
}
} else if (imageType == ReplacedImageType::ZIM) {
std::unique_ptr<uint8_t[]> zim(new uint8_t[fileSize]);
Expand Down
8 changes: 8 additions & 0 deletions GPU/Common/ReplacedTexture.h
Expand Up @@ -72,6 +72,13 @@ enum class ReplacementState : uint32_t {

const char *StateString(ReplacementState state);

struct GPUFormatSupport {
bool bc123;
bool astc;
bool bc7;
bool etc2;
};

struct ReplacementDesc {
int newW;
int newH;
Expand All @@ -85,6 +92,7 @@ struct ReplacementDesc {
std::vector<std::string> filenames;
std::string logId;
ReplacedLevelsCache *cache;
GPUFormatSupport formatSupport;
};

struct ReplacedLevelsCache {
Expand Down
7 changes: 6 additions & 1 deletion GPU/Common/TextureReplacer.cpp
Expand Up @@ -55,7 +55,11 @@ static const int VERSION = 1;
static const double MAX_CACHE_SIZE = 4.0;

TextureReplacer::TextureReplacer(Draw::DrawContext *draw) {
// TODO: Check draw for supported texture formats.
// We don't want to keep the draw object around, so extract the info we need.
if (draw->GetDataFormatSupport(Draw::DataFormat::BC3_UNORM_BLOCK)) formatSupport_.bc123 = true;
if (draw->GetDataFormatSupport(Draw::DataFormat::ASTC_4x4_UNORM_BLOCK)) formatSupport_.astc = true;
if (draw->GetDataFormatSupport(Draw::DataFormat::BC7_UNORM_BLOCK)) formatSupport_.bc7 = true;
if (draw->GetDataFormatSupport(Draw::DataFormat::ETC2_R8G8B8_UNORM_BLOCK)) formatSupport_.etc2 = true;
}

TextureReplacer::~TextureReplacer() {
Expand Down Expand Up @@ -487,6 +491,7 @@ void TextureReplacer::PopulateReplacement(ReplacedTexture *texture, u64 cachekey
desc->cachekey = cachekey;
desc->hash = hash;
desc->basePath = basePath_;
desc->formatSupport = formatSupport_;
LookupHashRange(cachekey >> 32, desc->newW, desc->newH);

if (ignoreAddress_) {
Expand Down
3 changes: 2 additions & 1 deletion GPU/Common/TextureReplacer.h
Expand Up @@ -93,7 +93,7 @@ enum class ReplacerDecimateMode {

class TextureReplacer {
public:
// The draw context will be checked for supported texture formats.
// The draw context is checked for supported texture formats.
TextureReplacer(Draw::DrawContext *draw);
~TextureReplacer();

Expand Down Expand Up @@ -152,6 +152,7 @@ class TextureReplacer {

VFSBackend *vfs_ = nullptr;
bool vfsIsZip_ = false;
GPUFormatSupport formatSupport_{};

typedef std::pair<int, int> WidthHeightPair;
std::unordered_map<u64, WidthHeightPair> hashranges_;
Expand Down

0 comments on commit a4b5641

Please sign in to comment.