Texture color format doesn't belong as a per-level property, that's not supported.

All levels of a texture must have the same format.
This commit is contained in:
Henrik Rydgård 2023-03-09 00:05:24 +01:00
parent 4ba2001479
commit bda09be109
7 changed files with 27 additions and 26 deletions

View File

@ -87,7 +87,9 @@ static ReplacedImageType Identify(VFSBackend *vfs, VFSOpenFile *openFile, std::s
return IdentifyMagic(magic);
}
TextureReplacer::TextureReplacer() {}
TextureReplacer::TextureReplacer(Draw::DrawContext *draw) {
// TODO: Check draw for supported texture formats.
}
TextureReplacer::~TextureReplacer() {
for (auto &iter : cache_) {
@ -274,7 +276,7 @@ bool TextureReplacer::LoadIniValues(IniFile &ini, bool isOverride) {
alias += level.second + "|";
mipIndex++;
} else {
WARN_LOG(G3D, "Non-sequential mip index %d, breaking", level.first);
WARN_LOG(G3D, "Non-sequential mip index %d, breaking. filenames=%s", level.first, level.second.c_str());
break;
}
}
@ -531,9 +533,12 @@ void TextureReplacer::PopulateReplacement(ReplacedTexture *texture, u64 cachekey
// TODO: Here, if we find a file with multiple built-in mipmap levels,
// we'll have to change a bit how things work...
ReplacedTextureLevel level;
level.fmt = Draw::DataFormat::R8G8B8A8_UNORM;
level.file = filename;
if (i == 0) {
texture->fmt = Draw::DataFormat::R8G8B8A8_UNORM;
}
bool good;
VFSFileReference *fileRef = vfs_->GetFile(filenames[i].c_str());

View File

@ -55,19 +55,13 @@ enum class ReplacedTextureHash {
// Metadata about a given texture level.
struct ReplacedTextureLevel {
ReplacedTextureLevel() {}
int w = 0;
int h = 0;
Draw::DataFormat fmt = Draw::DataFormat::UNDEFINED; // NOTE: Right now, the only supported format is Draw::DataFormat::R8G8B8A8_UNORM.
Path file;
// Can be ignored for hashing/equal, since file has all uniqueness.
// To be able to reload, we need to be able to reopen, unfortunate we can't use zip_file_t.
// TODO: This really belongs on the level in the cache, not in the individual ReplacedTextureLevel objects.
VFSFileReference *fileRef = nullptr;
bool operator ==(const ReplacedTextureLevel &other) const {
if (w != other.w || h != other.h || fmt != other.fmt)
return false;
return file == other.file;
}
};
struct ReplacedLevelsCache {
@ -135,13 +129,13 @@ struct ReplacedTexture {
return (int)levels_.size();
}
Draw::DataFormat Format(int level) const {
Draw::DataFormat Format() const {
if (initDone_) {
if ((size_t)level < levels_.size()) {
return levels_[level].fmt;
}
return fmt;
} else {
// Shouldn't get here.
return Draw::DataFormat::UNDEFINED;
}
return Draw::DataFormat::R8G8B8A8_UNORM;
}
u8 AlphaStatus() const {
@ -164,6 +158,7 @@ protected:
double lastUsed_ = 0.0;
LimitedWaitable *threadWaitable_ = nullptr;
std::mutex mutex_;
Draw::DataFormat fmt = Draw::DataFormat::UNDEFINED; // NOTE: Right now, the only supported format is Draw::DataFormat::R8G8B8A8_UNORM.
bool cancelPrepare_ = false;
bool initDone_ = false;
@ -171,8 +166,8 @@ protected:
VFSBackend *vfs_ = nullptr;
friend TextureReplacer;
friend ReplacedTextureTask;
friend class TextureReplacer;
friend class ReplacedTextureTask;
};
struct ReplacedTextureDecodeInfo {
@ -193,7 +188,8 @@ enum class ReplacerDecimateMode {
class TextureReplacer {
public:
TextureReplacer();
// The draw context will be checked for supported texture formats.
TextureReplacer(Draw::DrawContext *draw);
~TextureReplacer();
void Init();

View File

@ -107,7 +107,7 @@ inline int dimHeight(u16 dim) {
}
TextureCacheCommon::TextureCacheCommon(Draw::DrawContext *draw, Draw2D *draw2D)
: draw_(draw), draw2D_(draw2D) {
: draw_(draw), draw2D_(draw2D), replacer_(draw) {
decimationCounter_ = TEXCACHE_DECIMATION_INTERVAL;
// It's only possible to have 1KB of palette entries, although we allow 2KB in a hack.

View File

@ -263,7 +263,7 @@ void TextureCacheD3D11::BuildTexture(TexCacheEntry *const entry) {
DXGI_FORMAT dstFmt = GetDestFormat(GETextureFormat(entry->format), gstate.getClutPaletteFormat());
if (plan.replaceValid) {
dstFmt = ToDXGIFormat(plan.replaced->Format(plan.baseLevelSrc));
dstFmt = ToDXGIFormat(plan.replaced->Format());
} else if (plan.scaleFactor > 1 || plan.saveTexture) {
dstFmt = DXGI_FORMAT_B8G8R8A8_UNORM;
} else if (plan.decodeToClut8) {
@ -339,7 +339,7 @@ void TextureCacheD3D11::BuildTexture(TexCacheEntry *const entry) {
// For UpdateSubresource, we can't decode directly into the texture so we allocate a buffer :(
// NOTE: Could reuse it between levels or textures!
if (plan.replaceValid) {
bpp = (int)Draw::DataFormatSizeInBytes(plan.replaced->Format(srcLevel));
bpp = (int)Draw::DataFormatSizeInBytes(plan.replaced->Format());
} else {
if (plan.scaleFactor > 1) {
bpp = 4;

View File

@ -235,7 +235,7 @@ void TextureCacheDX9::BuildTexture(TexCacheEntry *const entry) {
D3DFORMAT dstFmt = GetDestFormat(GETextureFormat(entry->format), gstate.getClutPaletteFormat());
if (plan.replaceValid) {
dstFmt = ToD3D9Format(plan.replaced->Format(plan.baseLevelSrc));
dstFmt = ToD3D9Format(plan.replaced->Format());
} else if (plan.scaleFactor > 1 || plan.saveTexture) {
dstFmt = D3DFMT_A8R8G8B8;
} else if (plan.decodeToClut8) {

View File

@ -247,7 +247,7 @@ void TextureCacheGLES::BuildTexture(TexCacheEntry *const entry) {
Draw::DataFormat dstFmt = GetDestFormat(GETextureFormat(entry->format), gstate.getClutPaletteFormat());
if (plan.replaced->GetSize(plan.baseLevelSrc, tw, th)) {
dstFmt = plan.replaced->Format(plan.baseLevelSrc);
dstFmt = plan.replaced->Format();
} else if (plan.scaleFactor > 1 || plan.saveTexture) {
dstFmt = Draw::DataFormat::R8G8B8A8_UNORM;
} else if (plan.decodeToClut8) {
@ -294,7 +294,7 @@ void TextureCacheGLES::BuildTexture(TexCacheEntry *const entry) {
int bpp;
if (plan.replaceValid) {
bpp = (int)Draw::DataFormatSizeInBytes(plan.replaced->Format(srcLevel));
bpp = (int)Draw::DataFormatSizeInBytes(plan.replaced->Format());
} else {
if (plan.scaleFactor > 1) {
bpp = 4;

View File

@ -443,7 +443,7 @@ void TextureCacheVulkan::BuildTexture(TexCacheEntry *const entry) {
// Any texture scaling is gonna move away from the original 16-bit format, if any.
VkFormat actualFmt = plan.scaleFactor > 1 ? VULKAN_8888_FORMAT : dstFmt;
if (plan.replaceValid) {
actualFmt = ToVulkanFormat(plan.replaced->Format(plan.baseLevelSrc));
actualFmt = ToVulkanFormat(plan.replaced->Format());
}
bool computeUpload = false;