mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-11-29 17:23:40 +01:00
Merge pull request #15929 from hrydgard/fix-tex-replace-race
Fix race condition in replacement texture loading
This commit is contained in:
6 files changed
+18
-13
No files matched your search
@@ -2360,11 +2360,13 @@ bool TextureCacheCommon::PrepareBuildTexture(BuildTexturePlan &plan, TexCacheEnt
|
||||
|
||||
if (plan.isVideo || isPPGETexture) {
|
||||
plan.replaced = &replacer_.FindNone();
|
||||
plan.replaceValid = false;
|
||||
} else {
|
||||
plan.replaced = &FindReplacement(entry, plan.w, plan.h, plan.depth);
|
||||
plan.replaceValid = plan.replaced->Valid();
|
||||
}
|
||||
|
||||
if (plan.replaced->Valid()) {
|
||||
if (plan.replaceValid) {
|
||||
// We're replacing, so we won't scale.
|
||||
plan.scaleFactor = 1;
|
||||
plan.levelsToLoad = plan.replaced->NumLevels();
|
||||
|
||||
@@ -273,9 +273,11 @@ struct BuildTexturePlan {
|
||||
|
||||
// The replacement for the texture.
|
||||
ReplacedTexture *replaced;
|
||||
// Need to only check once since it can change during the load!
|
||||
bool replaceValid;
|
||||
|
||||
void GetMipSize(int level, int *w, int *h) const {
|
||||
if (replaced->Valid()) {
|
||||
if (replaceValid) {
|
||||
replaced->GetSize(level, *w, *h);
|
||||
} else if (depth == 1) {
|
||||
*w = createW >> level;
|
||||
|
||||
@@ -277,7 +277,7 @@ void TextureCacheD3D11::BuildTexture(TexCacheEntry *const entry) {
|
||||
}
|
||||
|
||||
DXGI_FORMAT dstFmt = GetDestFormat(GETextureFormat(entry->format), gstate.getClutPaletteFormat());
|
||||
if (plan.replaced->Valid()) {
|
||||
if (plan.replaceValid) {
|
||||
dstFmt = ToDXGIFormat(plan.replaced->Format(plan.baseLevelSrc));
|
||||
} else if (plan.scaleFactor > 1) {
|
||||
dstFmt = DXGI_FORMAT_B8G8R8A8_UNORM;
|
||||
@@ -347,7 +347,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.replaced->Valid()) {
|
||||
if (plan.replaceValid) {
|
||||
bpp = (int)Draw::DataFormatSizeInBytes(plan.replaced->Format(srcLevel));
|
||||
} else {
|
||||
if (plan.scaleFactor > 1) {
|
||||
@@ -390,7 +390,7 @@ void TextureCacheD3D11::BuildTexture(TexCacheEntry *const entry) {
|
||||
entry->status &= ~TexCacheEntry::STATUS_NO_MIPS;
|
||||
}
|
||||
|
||||
if (plan.replaced->Valid()) {
|
||||
if (plan.replaceValid) {
|
||||
entry->SetAlphaStatus(TexCacheEntry::TexStatus(plan.replaced->AlphaStatus()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -239,7 +239,7 @@ void TextureCacheDX9::BuildTexture(TexCacheEntry *const entry) {
|
||||
}
|
||||
|
||||
D3DFORMAT dstFmt = GetDestFormat(GETextureFormat(entry->format), gstate.getClutPaletteFormat());
|
||||
if (plan.replaced->Valid()) {
|
||||
if (plan.replaceValid) {
|
||||
dstFmt = ToD3D9Format(plan.replaced->Format(plan.baseLevelSrc));
|
||||
} else if (plan.scaleFactor > 1) {
|
||||
dstFmt = D3DFMT_A8R8G8B8;
|
||||
@@ -325,7 +325,7 @@ void TextureCacheDX9::BuildTexture(TexCacheEntry *const entry) {
|
||||
entry->status |= TexCacheEntry::STATUS_3D;
|
||||
}
|
||||
|
||||
if (plan.replaced->Valid()) {
|
||||
if (plan.replaceValid) {
|
||||
entry->SetAlphaStatus(TexCacheEntry::TexStatus(plan.replaced->AlphaStatus()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -309,7 +309,7 @@ void TextureCacheGLES::BuildTexture(TexCacheEntry *const entry) {
|
||||
int stride = 0;
|
||||
int bpp;
|
||||
|
||||
if (plan.replaced->Valid()) {
|
||||
if (plan.replaceValid) {
|
||||
bpp = (int)Draw::DataFormatSizeInBytes(plan.replaced->Format(srcLevel));
|
||||
} else {
|
||||
if (plan.scaleFactor > 1) {
|
||||
@@ -358,7 +358,7 @@ void TextureCacheGLES::BuildTexture(TexCacheEntry *const entry) {
|
||||
render_->FinalizeTexture(entry->textureName, 1, false);
|
||||
}
|
||||
|
||||
if (plan.replaced->Valid()) {
|
||||
if (plan.replaceValid) {
|
||||
entry->SetAlphaStatus(TexCacheEntry::TexStatus(plan.replaced->AlphaStatus()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -464,7 +464,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.replaced->Valid()) {
|
||||
if (plan.replaceValid) {
|
||||
actualFmt = ToVulkanFormat(plan.replaced->Format(plan.baseLevelSrc));
|
||||
}
|
||||
|
||||
@@ -542,7 +542,8 @@ void TextureCacheVulkan::BuildTexture(TexCacheEntry *const entry) {
|
||||
|
||||
ReplacedTextureDecodeInfo replacedInfo;
|
||||
bool willSaveTex = false;
|
||||
if (replacer_.Enabled() && plan.replaced->IsInvalid() && plan.depth == 1) {
|
||||
if (replacer_.Enabled() && !plan.replaceValid && plan.depth == 1) {
|
||||
// TODO: Do we handle the race where a replacement becomes valid AFTER this but before we save?
|
||||
replacedInfo.cachekey = entry->CacheKey();
|
||||
replacedInfo.hash = entry->fullhash;
|
||||
replacedInfo.addr = entry->addr;
|
||||
@@ -596,7 +597,7 @@ void TextureCacheVulkan::BuildTexture(TexCacheEntry *const entry) {
|
||||
};
|
||||
|
||||
bool dataScaled = true;
|
||||
if (plan.replaced->Valid()) {
|
||||
if (plan.replaceValid) {
|
||||
// Directly load the replaced image.
|
||||
data = drawEngine_->GetPushBufferForTextureData()->PushAligned(uploadSize, &bufferOffset, &texBuf, pushAlignment);
|
||||
double replaceStart = time_now_d();
|
||||
@@ -668,7 +669,7 @@ void TextureCacheVulkan::BuildTexture(TexCacheEntry *const entry) {
|
||||
entry->status |= TexCacheEntry::STATUS_3D;
|
||||
}
|
||||
|
||||
if (plan.replaced->Valid()) {
|
||||
if (plan.replaceValid) {
|
||||
entry->SetAlphaStatus(TexCacheEntry::TexStatus(plan.replaced->AlphaStatus()));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user