From 4e89174b85ce242d5b93698dff26cda4fa1c7e60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Fri, 5 Aug 2022 11:09:16 +0200 Subject: [PATCH] OpenGL: Fix shader depal too. --- Common/GPU/D3D11/thin3d_d3d11.cpp | 2 +- Common/GPU/D3D9/thin3d_d3d9.cpp | 2 +- Common/GPU/OpenGL/thin3d_gl.cpp | 20 ++++++++++++-------- Common/GPU/Vulkan/thin3d_vulkan.cpp | 2 +- Common/GPU/thin3d.h | 4 ++-- GPU/GLES/TextureCacheGLES.cpp | 12 +++++++----- 6 files changed, 24 insertions(+), 18 deletions(-) diff --git a/Common/GPU/D3D11/thin3d_d3d11.cpp b/Common/GPU/D3D11/thin3d_d3d11.cpp index eeba9d24a3..702ff10a97 100644 --- a/Common/GPU/D3D11/thin3d_d3d11.cpp +++ b/Common/GPU/D3D11/thin3d_d3d11.cpp @@ -163,7 +163,7 @@ public: } } - uint64_t GetNativeObject(NativeObject obj) override { + uint64_t GetNativeObject(NativeObject obj, void *srcObject) override { switch (obj) { case NativeObject::DEVICE: return (uint64_t)(uintptr_t)device_; diff --git a/Common/GPU/D3D9/thin3d_d3d9.cpp b/Common/GPU/D3D9/thin3d_d3d9.cpp index 2b0f1a0faa..ad2cfd78d3 100644 --- a/Common/GPU/D3D9/thin3d_d3d9.cpp +++ b/Common/GPU/D3D9/thin3d_d3d9.cpp @@ -560,7 +560,7 @@ public: void DrawUP(const void *vdata, int vertexCount) override; void Clear(int mask, uint32_t colorval, float depthVal, int stencilVal) override; - uint64_t GetNativeObject(NativeObject obj) override { + uint64_t GetNativeObject(NativeObject obj, void *srcObject) override { switch (obj) { case NativeObject::CONTEXT: return (uint64_t)(uintptr_t)d3d_; diff --git a/Common/GPU/OpenGL/thin3d_gl.cpp b/Common/GPU/OpenGL/thin3d_gl.cpp index 84580710f3..6656de3f82 100644 --- a/Common/GPU/OpenGL/thin3d_gl.cpp +++ b/Common/GPU/OpenGL/thin3d_gl.cpp @@ -456,14 +456,7 @@ public: } } - uint64_t GetNativeObject(NativeObject obj) override { - switch (obj) { - case NativeObject::RENDER_MANAGER: - return (uint64_t)(uintptr_t)&renderManager_; - default: - return 0; - } - } + uint64_t GetNativeObject(NativeObject obj, void *srcObject) override; void HandleEvent(Event ev, int width, int height, void *param1, void *param2) override {} @@ -1427,6 +1420,17 @@ void OpenGLContext::GetFramebufferDimensions(Framebuffer *fbo, int *w, int *h) { } } +uint64_t OpenGLContext::GetNativeObject(NativeObject obj, void *srcObject) { + switch (obj) { + case NativeObject::RENDER_MANAGER: + return (uint64_t)(uintptr_t)&renderManager_; + case NativeObject::TEXTURE: // Gets the GLRTexture * + return (uint64_t)(((OpenGLTexture *)srcObject)->GetTex()); + default: + return 0; + } +} + uint32_t OpenGLContext::GetDataFormatSupport(DataFormat fmt) const { switch (fmt) { case DataFormat::R4G4B4A4_UNORM_PACK16: diff --git a/Common/GPU/Vulkan/thin3d_vulkan.cpp b/Common/GPU/Vulkan/thin3d_vulkan.cpp index 1a84cb5ecb..28084e731d 100644 --- a/Common/GPU/Vulkan/thin3d_vulkan.cpp +++ b/Common/GPU/Vulkan/thin3d_vulkan.cpp @@ -464,7 +464,7 @@ public: std::vector GetFeatureList() const override; std::vector GetExtensionList() const override; - uint64_t GetNativeObject(NativeObject obj) override { + uint64_t GetNativeObject(NativeObject obj, void *srcObject) override { switch (obj) { case NativeObject::CONTEXT: return (uint64_t)vulkan_; diff --git a/Common/GPU/thin3d.h b/Common/GPU/thin3d.h index 1f8350f42c..8d29fed18e 100644 --- a/Common/GPU/thin3d.h +++ b/Common/GPU/thin3d.h @@ -246,7 +246,7 @@ enum class NativeObject { BOUND_TEXTURE0_IMAGEVIEW, BOUND_TEXTURE1_IMAGEVIEW, RENDER_MANAGER, - TEXTURE_IMAGEVIEW, + TEXTURE, NULL_IMAGEVIEW, }; @@ -700,7 +700,7 @@ public: } virtual std::string GetInfoString(InfoField info) const = 0; - virtual uint64_t GetNativeObject(NativeObject obj) = 0; + virtual uint64_t GetNativeObject(NativeObject obj, void *srcObject = nullptr) = 0; // Most uses don't need an srcObject. virtual void HandleEvent(Event ev, int width, int height, void *param1 = nullptr, void *param2 = nullptr) = 0; diff --git a/GPU/GLES/TextureCacheGLES.cpp b/GPU/GLES/TextureCacheGLES.cpp index f761d24875..e791bdf31e 100644 --- a/GPU/GLES/TextureCacheGLES.cpp +++ b/GPU/GLES/TextureCacheGLES.cpp @@ -333,9 +333,9 @@ protected: }; void TextureCacheGLES::BindAsClutTexture(Draw::Texture *tex) { - draw_->BindTexture(1, tex); - GLRTexture *glrTex = (GLRTexture *)draw_->GetNativeObject(Draw::NativeObject::BOUND_TEXTURE1_IMAGEVIEW); + GLRTexture *glrTex = (GLRTexture *)draw_->GetNativeObject(Draw::NativeObject::TEXTURE, tex); render_->BindTexture(TEX_SLOT_CLUT, glrTex); + render_->SetTextureSampler(TEX_SLOT_CLUT, GL_REPEAT, GL_CLAMP_TO_EDGE, GL_NEAREST, GL_NEAREST, 0.0f); } void TextureCacheGLES::ApplyTextureFramebuffer(VirtualFramebuffer *framebuffer, GETextureFormat texFormat, FramebufferNotificationChannel channel) { @@ -353,18 +353,17 @@ void TextureCacheGLES::ApplyTextureFramebuffer(VirtualFramebuffer *framebuffer, if (need_depalettize && !g_Config.bDisableSlowFramebufEffects) { if (useShaderDepal) { const GEPaletteFormat clutFormat = gstate.getClutPaletteFormat(); - // Very icky conflation here of native and thin3d rendering. This will need careful work per backend. + + // Very icky conflation here of native and thin3d rendering. This will need careful work per backend in BindAsClutTexture. Draw::Texture *clutTexture = depalShaderCache_->GetClutTexture(clutFormat, clutHash_, clutBuf_); BindAsClutTexture(clutTexture); - render_->SetTextureSampler(TEX_SLOT_CLUT, GL_REPEAT, GL_CLAMP_TO_EDGE, GL_NEAREST, GL_NEAREST, 0.0f); framebufferManagerGL_->BindFramebufferAsColorTexture(0, framebuffer, BINDFBCOLOR_MAY_COPY_WITH_UV | BINDFBCOLOR_APPLY_TEX_OFFSET); SamplerCacheKey samplerKey = GetFramebufferSamplingParams(framebuffer->bufferWidth, framebuffer->bufferHeight); samplerKey.magFilt = false; samplerKey.minFilt = false; samplerKey.mipEnable = false; ApplySamplingParams(samplerKey); - InvalidateLastTexture(); // Since we started/ended render passes, might need these. gstate_c.Dirty(DIRTY_DEPAL); @@ -374,6 +373,9 @@ void TextureCacheGLES::ApplyTextureFramebuffer(VirtualFramebuffer *framebuffer, const u32 clutTotalColors = clutMaxBytes_ / bytesPerColor; CheckAlphaResult alphaStatus = CheckAlpha((const uint8_t *)clutBuf_, getClutDestFormat(clutFormat), clutTotalColors); gstate_c.SetTextureFullAlpha(alphaStatus == CHECKALPHA_FULL); + + draw_->InvalidateCachedState(); + InvalidateLastTexture(); return; }