From 707e9cf7ac80f6de28b8c9fcbbe1f79d7ce8534c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sun, 20 Sep 2020 20:35:42 +0200 Subject: [PATCH 1/2] Remove some unnecessary function parameters, improve some comments. --- GPU/Common/DrawEngineCommon.cpp | 2 ++ GPU/Common/ShaderCommon.h | 2 +- GPU/Common/TextureCacheCommon.cpp | 6 +----- GPU/Common/TextureCacheCommon.h | 7 +++++-- GPU/D3D11/TextureCacheD3D11.cpp | 9 +++------ GPU/D3D11/TextureCacheD3D11.h | 2 +- GPU/Directx9/TextureCacheDX9.cpp | 8 +++----- GPU/Directx9/TextureCacheDX9.h | 2 +- GPU/GLES/TextureCacheGLES.cpp | 4 +++- GPU/GLES/TextureCacheGLES.h | 6 ++---- GPU/Vulkan/TextureCacheVulkan.cpp | 9 +++------ GPU/Vulkan/TextureCacheVulkan.h | 6 ++---- assets/lang | 2 +- ext/native/thin3d/GLRenderManager.h | 5 +++-- 14 files changed, 31 insertions(+), 39 deletions(-) diff --git a/GPU/Common/DrawEngineCommon.cpp b/GPU/Common/DrawEngineCommon.cpp index 8285191699..b326a832ad 100644 --- a/GPU/Common/DrawEngineCommon.cpp +++ b/GPU/Common/DrawEngineCommon.cpp @@ -698,6 +698,8 @@ void DrawEngineCommon::SubmitPrim(void *verts, void *inds, GEPrimitiveType prim, } *bytesRead = vertexCount * dec_->VertexSize(); + + // Check that we have enough vertices to form the requested primitive. if ((vertexCount < 2 && prim > 0) || (vertexCount < 3 && prim > 2 && prim != GE_PRIM_RECTANGLES)) return; diff --git a/GPU/Common/ShaderCommon.h b/GPU/Common/ShaderCommon.h index b8827dd03d..3280c765b6 100644 --- a/GPU/Common/ShaderCommon.h +++ b/GPU/Common/ShaderCommon.h @@ -104,7 +104,7 @@ enum : uint64_t { // Other dirty elements that aren't uniforms! DIRTY_FRAMEBUF = 1ULL << 40, - DIRTY_TEXTURE_IMAGE = 1ULL << 41, + DIRTY_TEXTURE_IMAGE = 1ULL << 41, // Means that the definition of the texture image has changed (address, stride etc), and we need to look up again. DIRTY_TEXTURE_PARAMS = 1ULL << 42, // Render State diff --git a/GPU/Common/TextureCacheCommon.cpp b/GPU/Common/TextureCacheCommon.cpp index 369c4c2ea7..c3eaf6703a 100644 --- a/GPU/Common/TextureCacheCommon.cpp +++ b/GPU/Common/TextureCacheCommon.cpp @@ -321,11 +321,7 @@ void TextureCacheCommon::UpdateMaxSeenV(TexCacheEntry *entry, bool throughMode) } } -TexCacheEntry *TextureCacheCommon::SetTexture(bool force) { - if (force) { - InvalidateLastTexture(); - } - +TexCacheEntry *TextureCacheCommon::SetTexture() { u8 level = 0; if (IsFakeMipmapChange()) level = std::max(0, gstate.getTexLevelOffset16() / 16); diff --git a/GPU/Common/TextureCacheCommon.h b/GPU/Common/TextureCacheCommon.h index 7ed78e911d..1241476a0a 100644 --- a/GPU/Common/TextureCacheCommon.h +++ b/GPU/Common/TextureCacheCommon.h @@ -231,7 +231,10 @@ public: void LoadClut(u32 clutAddr, u32 loadBytes); bool GetCurrentClutBuffer(GPUDebugBuffer &buffer); - TexCacheEntry *SetTexture(bool force = false); + // This updates nextTexture_ / nextFramebufferTexture_, which is then used by ApplyTexture. + // TODO: Return stuff directly instead of keeping state. + TexCacheEntry *SetTexture(); + void ApplyTexture(); bool SetOffsetTexture(u32 yOffset); void Invalidate(u32 addr, int size, GPUInvalidationType type); @@ -239,7 +242,7 @@ public: void ClearNextFrame(); virtual void ForgetLastTexture() = 0; - virtual void InvalidateLastTexture(TexCacheEntry *entry = nullptr) = 0; + virtual void InvalidateLastTexture() = 0; virtual void Clear(bool delete_them); virtual void NotifyConfigChanged(); diff --git a/GPU/D3D11/TextureCacheD3D11.cpp b/GPU/D3D11/TextureCacheD3D11.cpp index 78e7327716..5a0f63e600 100644 --- a/GPU/D3D11/TextureCacheD3D11.cpp +++ b/GPU/D3D11/TextureCacheD3D11.cpp @@ -149,10 +149,8 @@ void TextureCacheD3D11::ForgetLastTexture() { context_->PSSetShaderResources(0, 2, nullTex); } -void TextureCacheD3D11::InvalidateLastTexture(TexCacheEntry *entry) { - if (!entry || entry->texturePtr == lastBoundTexture) { - lastBoundTexture = INVALID_TEX; - } +void TextureCacheD3D11::InvalidateLastTexture() { + lastBoundTexture = INVALID_TEX; } void TextureCacheD3D11::StartFrame() { @@ -410,7 +408,6 @@ void TextureCacheD3D11::ApplyTextureFramebuffer(VirtualFramebuffer *framebuffer, gstate_c.Dirty(DIRTY_VIEWPORTSCISSOR_STATE | DIRTY_RASTER_STATE | DIRTY_DEPTHSTENCIL_STATE | DIRTY_BLEND_STATE | DIRTY_FRAGMENTSHADER_STATE); } - void TextureCacheD3D11::BuildTexture(TexCacheEntry *const entry) { entry->status &= ~TexCacheEntry::STATUS_ALPHA_MASK; @@ -736,7 +733,7 @@ void TextureCacheD3D11::LoadTextureLevel(TexCacheEntry &entry, ReplacedTexture & } bool TextureCacheD3D11::GetCurrentTextureDebug(GPUDebugBuffer &buffer, int level) { - SetTexture(false); + SetTexture(); if (!nextTexture_) { if (nextFramebufferTexture_) { VirtualFramebuffer *vfb = nextFramebufferTexture_; diff --git a/GPU/D3D11/TextureCacheD3D11.h b/GPU/D3D11/TextureCacheD3D11.h index 6aa3bcda9e..ceaf64b150 100644 --- a/GPU/D3D11/TextureCacheD3D11.h +++ b/GPU/D3D11/TextureCacheD3D11.h @@ -58,7 +58,7 @@ public: } void ForgetLastTexture() override; - void InvalidateLastTexture(TexCacheEntry *entry = nullptr) override; + void InvalidateLastTexture() override; bool GetCurrentTextureDebug(GPUDebugBuffer &buffer, int level) override; diff --git a/GPU/Directx9/TextureCacheDX9.cpp b/GPU/Directx9/TextureCacheDX9.cpp index f2557ab92d..56bd153bef 100644 --- a/GPU/Directx9/TextureCacheDX9.cpp +++ b/GPU/Directx9/TextureCacheDX9.cpp @@ -97,10 +97,8 @@ void TextureCacheDX9::ForgetLastTexture() { gstate_c.Dirty(DIRTY_TEXTURE_PARAMS); } -void TextureCacheDX9::InvalidateLastTexture(TexCacheEntry *entry) { - if (!entry || entry->texturePtr == lastBoundTexture) { - lastBoundTexture = INVALID_TEX; - } +void TextureCacheDX9::InvalidateLastTexture() { + lastBoundTexture = INVALID_TEX; } D3DFORMAT getClutDestFormat(GEPaletteFormat format) { @@ -690,7 +688,7 @@ void TextureCacheDX9::LoadTextureLevel(TexCacheEntry &entry, ReplacedTexture &re } bool TextureCacheDX9::GetCurrentTextureDebug(GPUDebugBuffer &buffer, int level) { - SetTexture(true); + SetTexture(); ApplyTexture(); int w = gstate.getTextureWidth(level); int h = gstate.getTextureHeight(level); diff --git a/GPU/Directx9/TextureCacheDX9.h b/GPU/Directx9/TextureCacheDX9.h index 3a0c291586..1ebf3bb5fc 100644 --- a/GPU/Directx9/TextureCacheDX9.h +++ b/GPU/Directx9/TextureCacheDX9.h @@ -50,7 +50,7 @@ public: } void ForgetLastTexture() override; - void InvalidateLastTexture(TexCacheEntry *entry = nullptr) override; + void InvalidateLastTexture() override; bool GetCurrentTextureDebug(GPUDebugBuffer &buffer, int level) override; diff --git a/GPU/GLES/TextureCacheGLES.cpp b/GPU/GLES/TextureCacheGLES.cpp index de6852d556..ba953676d4 100644 --- a/GPU/GLES/TextureCacheGLES.cpp +++ b/GPU/GLES/TextureCacheGLES.cpp @@ -730,7 +730,9 @@ bool TextureCacheGLES::GetCurrentTextureDebug(GPUDebugBuffer &buffer, int level) gstate.texbufwidth[0] = gstate.texbufwidth[level]; } - SetTexture(true); + InvalidateLastTexture(); + SetTexture(); + if (!nextTexture_) { if (nextFramebufferTexture_) { VirtualFramebuffer *vfb = nextFramebufferTexture_; diff --git a/GPU/GLES/TextureCacheGLES.h b/GPU/GLES/TextureCacheGLES.h index 7564b635b5..e196a358dc 100644 --- a/GPU/GLES/TextureCacheGLES.h +++ b/GPU/GLES/TextureCacheGLES.h @@ -57,10 +57,8 @@ public: lastBoundTexture = nullptr; gstate_c.Dirty(DIRTY_TEXTURE_PARAMS); } - void InvalidateLastTexture(TexCacheEntry *entry = nullptr) override { - if (!entry || entry->textureName == lastBoundTexture) { - lastBoundTexture = nullptr; - } + void InvalidateLastTexture() override { + lastBoundTexture = nullptr; } bool GetCurrentTextureDebug(GPUDebugBuffer &buffer, int level) override; diff --git a/GPU/Vulkan/TextureCacheVulkan.cpp b/GPU/Vulkan/TextureCacheVulkan.cpp index c6d9971770..c33e6c73c4 100644 --- a/GPU/Vulkan/TextureCacheVulkan.cpp +++ b/GPU/Vulkan/TextureCacheVulkan.cpp @@ -509,11 +509,8 @@ void TextureCacheVulkan::UpdateCurrentClut(GEPaletteFormat clutFormat, u32 clutB } void TextureCacheVulkan::BindTexture(TexCacheEntry *entry) { - if (!entry || !entry->vkTex) { - imageView_ = VK_NULL_HANDLE; - curSampler_ = VK_NULL_HANDLE; - return; - } + _assert_(entry); + _assert_(entry->vkTex); entry->vkTex->Touch(); imageView_ = entry->vkTex->GetImageView(); @@ -1114,7 +1111,7 @@ void TextureCacheVulkan::LoadTextureLevel(TexCacheEntry &entry, uint8_t *writePt } bool TextureCacheVulkan::GetCurrentTextureDebug(GPUDebugBuffer &buffer, int level) { - SetTexture(false); + SetTexture(); if (!nextTexture_) { if (nextFramebufferTexture_) { VirtualFramebuffer *vfb = nextFramebufferTexture_; diff --git a/GPU/Vulkan/TextureCacheVulkan.h b/GPU/Vulkan/TextureCacheVulkan.h index 7aaa04d56e..8622b5d974 100644 --- a/GPU/Vulkan/TextureCacheVulkan.h +++ b/GPU/Vulkan/TextureCacheVulkan.h @@ -88,10 +88,8 @@ public: gstate_c.Dirty(DIRTY_TEXTURE_PARAMS); } - void InvalidateLastTexture(TexCacheEntry *entry = nullptr) override { - if (!entry || entry->vkTex == lastBoundTexture) { - lastBoundTexture = nullptr; - } + void InvalidateLastTexture() override { + lastBoundTexture = nullptr; } void NotifyConfigChanged() override; diff --git a/assets/lang b/assets/lang index 1c64b8fbd3..d5a2a51942 160000 --- a/assets/lang +++ b/assets/lang @@ -1 +1 @@ -Subproject commit 1c64b8fbd3cb6bd87935eb53f302f7de6f86e209 +Subproject commit d5a2a51942377820764604d9bb424fa9a879c4bd diff --git a/ext/native/thin3d/GLRenderManager.h b/ext/native/thin3d/GLRenderManager.h index 3e5870507d..d9721bf4ae 100644 --- a/ext/native/thin3d/GLRenderManager.h +++ b/ext/native/thin3d/GLRenderManager.h @@ -30,7 +30,8 @@ public: } GLuint texture = 0; - // Could also trust OpenGL defaults I guess.. + + // We don't trust OpenGL defaults - setting wildly off values ensures that we'll end up overwriting these parameters. GLenum target = 0xFFFF; GLenum wrapS = 0xFFFF; GLenum wrapT = 0xFFFF; @@ -63,7 +64,7 @@ public: int width; int height; - GLuint colorDepth; + GLuint colorDepth = 0; bool z_stencil_; }; From bdcf2c5cff4a8b02e3b8eeb2e9dd897fc9a7f94e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sun, 20 Sep 2020 20:42:28 +0200 Subject: [PATCH 2/2] Have to invalidate "lastBoundTexture" when binding framebuffers as texture. Fixes parts of #13431 for D3D11 at least. Will probably soon get rid of this concept, it's only useful in D3D9/11 and those are probably not gonna lose much perf if we remove this minor state caching. --- GPU/Common/TextureCacheCommon.cpp | 1 + GPU/D3D11/TextureCacheD3D11.cpp | 1 + 2 files changed, 2 insertions(+) diff --git a/GPU/Common/TextureCacheCommon.cpp b/GPU/Common/TextureCacheCommon.cpp index c3eaf6703a..64c687bf1e 100644 --- a/GPU/Common/TextureCacheCommon.cpp +++ b/GPU/Common/TextureCacheCommon.cpp @@ -1588,6 +1588,7 @@ void TextureCacheCommon::ApplyTexture() { // Maybe we bound a framebuffer? if (nextFramebufferTexture_) { bool depth = Memory::IsDepthTexVRAMAddress(gstate.getTextureAddress(0)); + InvalidateLastTexture(); ApplyTextureFramebuffer(nextFramebufferTexture_, gstate.getTextureFormat(), depth ? NOTIFY_FB_DEPTH : NOTIFY_FB_COLOR); nextFramebufferTexture_ = nullptr; } diff --git a/GPU/D3D11/TextureCacheD3D11.cpp b/GPU/D3D11/TextureCacheD3D11.cpp index 5a0f63e600..3a9dbda64a 100644 --- a/GPU/D3D11/TextureCacheD3D11.cpp +++ b/GPU/D3D11/TextureCacheD3D11.cpp @@ -145,6 +145,7 @@ void TextureCacheD3D11::ReleaseTexture(TexCacheEntry *entry, bool delete_them) { void TextureCacheD3D11::ForgetLastTexture() { InvalidateLastTexture(); gstate_c.Dirty(DIRTY_TEXTURE_PARAMS); + ID3D11ShaderResourceView *nullTex[2]{}; context_->PSSetShaderResources(0, 2, nullTex); }