Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In D3D11, force block compressed textures to have dimensions divisible by 4 #17749

Merged
merged 1 commit into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions GPU/Common/ReplacedTexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,10 @@ ReplacedTexture::LoadLevelResult ReplacedTexture::LoadLevelData(VFSFileReference
bool bc = Draw::DataFormatIsBlockCompressed(*pixelFormat, &blockSize);
_dbg_assert_(bc || *pixelFormat == Draw::DataFormat::R8G8B8A8_UNORM);

if (bc && (level.w & 3) != 0 || (level.h & 3) != 0) {
WARN_LOG(G3D, "Block compressed replacement texture '%s' not divisible by 4x4 (%dx%d). In D3D11 (only!) we will have to expand (potentially causing glitches).", filename.c_str(), level.w, level.h);
}

data_.resize(numMips);

basist::ktx2_transcoder_state transcodeState; // Each thread needs one of these.
Expand Down Expand Up @@ -546,6 +550,7 @@ ReplacedTexture::LoadLevelResult ReplacedTexture::LoadLevelData(VFSFileReference
}
transcoder.clear();
vfs_->CloseFile(openFile);

return LoadLevelResult::DONE; // don't read more levels
} else if (imageType == ReplacedImageType::DDS) {
// TODO: Do better with alphaStatus, it's possible.
Expand All @@ -562,6 +567,10 @@ ReplacedTexture::LoadLevelResult ReplacedTexture::LoadLevelData(VFSFileReference
bool bc = Draw::DataFormatIsBlockCompressed(*pixelFormat, &blockSize);
_dbg_assert_(bc);

if (bc && (level.w & 3) != 0 || (level.h & 3) != 0) {
WARN_LOG(G3D, "Block compressed replacement texture '%s' not divisible by 4x4 (%dx%d). In D3D11 (only!) we will have to expand (potentially causing glitches).", filename.c_str(), level.w, level.h);
}

data_.resize(numMips);

// A DDS File can contain multiple mipmaps.
Expand All @@ -583,6 +592,7 @@ ReplacedTexture::LoadLevelResult ReplacedTexture::LoadLevelData(VFSFileReference
level.fileRef = nullptr; // We only provide a fileref on level 0 if we have mipmaps.
}
vfs_->CloseFile(openFile);

return LoadLevelResult::DONE; // don't read more levels

} else if (imageType == ReplacedImageType::ZIM) {
Expand Down
3 changes: 3 additions & 0 deletions GPU/Common/TextureReplacer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,9 @@ bool TextureReplacer::LoadIniValues(IniFile &ini, VFSBackend *dir, bool isOverri
}
}

auto gr = GetI18NCategory(I18NCat::GRAPHICS);

g_OSD.Show(OSDType::MESSAGE_SUCCESS, gr->T("Texture replacement pack activated"));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forget if this can cause duplicates. It should be at the end of LoadIni(), since LoadIniValues() can be called multiple times for region overrides.

-[Unknown]

return true;
}

Expand Down
8 changes: 8 additions & 0 deletions GPU/D3D11/TextureCacheD3D11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,14 @@ void TextureCacheD3D11::BuildTexture(TexCacheEntry *const entry) {
if (th > 16384)
th = 16384;

// NOTE: For block-compressed textures, we'll force the size up to the closest 4x4. This is due to an
// unfortunate restriction in D3D11 (and early D3D12). We'll warn about it in the log to give texture pack
// authors notice to fix it.
if (plan.doReplace && Draw::DataFormatIsBlockCompressed(plan.replaced->Format(), nullptr)) {
tw = (tw + 3) & ~3;
th = (th + 3) & ~3;
}

if (plan.depth == 1) {
// We don't yet have mip generation, so clamp the number of levels to the ones we can load directly.
levels = std::min(plan.levelsToCreate, plan.levelsToLoad);
Expand Down
1 change: 1 addition & 0 deletions assets/lang/en_US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,7 @@ Stereo rendering = Stereo rendering
Stretch = Stretch
Texture Filter = Texture filtering
Texture Filtering = Texture filtering
Texture replacement pack activated = Texture replacement pack activated
Texture Scaling = Texture scaling
Texture Shader = Texture shader
Turn off Hardware Tessellation - unsupported = Turn off "hardware tessellation": unsupported
Expand Down