From 383adcb8706c307badb3ecb5fe0e69128a356814 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Mon, 22 Aug 2022 11:17:50 +0200 Subject: [PATCH 1/4] Simplify depal shader apply code a bit. --- GPU/Common/DepalettizeCommon.h | 65 +++++++------------------------ GPU/Common/TextureCacheCommon.cpp | 4 +- 2 files changed, 15 insertions(+), 54 deletions(-) diff --git a/GPU/Common/DepalettizeCommon.h b/GPU/Common/DepalettizeCommon.h index fbac86300d..6e3ef680ef 100644 --- a/GPU/Common/DepalettizeCommon.h +++ b/GPU/Common/DepalettizeCommon.h @@ -83,35 +83,18 @@ private: // TODO: Merge with DepalShaderCache? class TextureShaderApplier { public: - struct Pos { - float x; - float y; - }; - struct UV { - float u; - float v; - }; - TextureShaderApplier(Draw::DrawContext *draw, DepalShader *shader, float bufferW, float bufferH, int renderW, int renderH) : draw_(draw), shader_(shader), bufferW_(bufferW), bufferH_(bufferH), renderW_(renderW), renderH_(renderH) { - static const Pos pos[4] = { - {-1, -1 }, - { 1, -1 }, - {-1, 1 }, - { 1, 1 }, + static const Draw2DVertex defaultVerts[4] = { + {-1, -1, 0, 0 }, + { 1, -1, 1, 0 }, + {-1, 1, 0, 1 }, + { 1, 1, 1, 1 }, }; - memcpy(pos_, pos, sizeof(pos_)); - - static const UV uv[4] = { - { 0, 0 }, - { 1, 0 }, - { 0, 1 }, - { 1, 1 }, - }; - memcpy(uv_, uv, sizeof(uv_)); + memcpy(verts_, defaultVerts, sizeof(defaultVerts)); } - void ApplyBounds(const KnownVertexBounds &bounds, u32 uoff, u32 voff) { + void Shade(const KnownVertexBounds &bounds, u32 uoff, u32 voff) { // If min is not < max, then we don't have values (wasn't set during decode.) if (bounds.minV < bounds.maxV) { const float invWidth = 1.0f / bufferW_; @@ -129,41 +112,23 @@ public: const float right = u2 * invHalfWidth - 1.0f; const float top = v1 * invHalfHeight - 1.0f; const float bottom = v2 * invHalfHeight - 1.0f; - // Points are: BL, BR, TR, TL. - pos_[0] = Pos{ left, bottom }; - pos_[1] = Pos{ right, bottom }; - pos_[2] = Pos{ left, top }; - pos_[3] = Pos{ right, top }; - // And also the UVs, same order. const float uvleft = u1 * invWidth; const float uvright = u2 * invWidth; const float uvtop = v1 * invHeight; const float uvbottom = v2 * invHeight; - uv_[0] = UV{ uvleft, uvbottom }; - uv_[1] = UV{ uvright, uvbottom }; - uv_[2] = UV{ uvleft, uvtop }; - uv_[3] = UV{ uvright, uvtop }; + + // Points are: BL, BR, TR, TL. + verts_[0] = Draw2DVertex{ left, bottom, uvleft, uvbottom }; + verts_[1] = Draw2DVertex{ right, bottom, uvright, uvbottom }; + verts_[2] = Draw2DVertex{ left, top, uvleft, uvtop }; + verts_[3] = Draw2DVertex{ right, top, uvright, uvtop }; // We need to reapply the texture next time since we cropped UV. gstate_c.Dirty(DIRTY_TEXTURE_PARAMS); } - } - - void Use() { - draw_->BindPipeline(shader_->pipeline); - struct SimpleVertex { - float pos[2]; - float uv[2]; - }; - for (int i = 0; i < 4; i++) { - memcpy(&verts_[i].x, &pos_[i], sizeof(Pos)); - memcpy(&verts_[i].u, &uv_[i], sizeof(UV)); - } - } - - void Shade() { Draw::Viewport vp{ 0.0f, 0.0f, (float)renderW_, (float)renderH_, 0.0f, 1.0f }; + draw_->BindPipeline(shader_->pipeline); draw_->SetViewports(1, &vp); draw_->SetScissorRect(0, 0, renderW_, renderH_); draw_->DrawUP((const uint8_t *)verts_, 4); @@ -172,8 +137,6 @@ public: protected: Draw::DrawContext *draw_; DepalShader *shader_; - Pos pos_[4]; - UV uv_[4]; Draw2DVertex verts_[4]; float bufferW_; float bufferH_; diff --git a/GPU/Common/TextureCacheCommon.cpp b/GPU/Common/TextureCacheCommon.cpp index a5b2749d62..3022f1d1c4 100644 --- a/GPU/Common/TextureCacheCommon.cpp +++ b/GPU/Common/TextureCacheCommon.cpp @@ -1930,8 +1930,6 @@ void TextureCacheCommon::ApplyTextureFramebuffer(VirtualFramebuffer *framebuffer draw_->SetViewports(1, &vp); TextureShaderApplier shaderApply(draw_, depalShader, framebuffer->bufferWidth, framebuffer->bufferHeight, framebuffer->renderWidth, framebuffer->renderHeight); - shaderApply.ApplyBounds(gstate_c.vertBounds, gstate_c.curTextureXOffset, gstate_c.curTextureYOffset); - shaderApply.Use(); draw_->BindFramebufferAsTexture(framebuffer->fbo, 0, depth ? Draw::FB_DEPTH_BIT : Draw::FB_COLOR_BIT, 0); draw_->BindTexture(1, clutTexture); @@ -1939,7 +1937,7 @@ void TextureCacheCommon::ApplyTextureFramebuffer(VirtualFramebuffer *framebuffer draw_->BindSamplerStates(0, 1, &nearest); draw_->BindSamplerStates(1, 1, &nearest); - shaderApply.Shade(); + shaderApply.Shade(gstate_c.vertBounds, gstate_c.curTextureXOffset, gstate_c.curTextureYOffset); draw_->BindTexture(0, nullptr); framebufferManager_->RebindFramebuffer("ApplyTextureFramebuffer"); From 58a6fd3395fe9674a526d68098e5f9a070497ec1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Mon, 22 Aug 2022 11:45:52 +0200 Subject: [PATCH 2/4] Convert TextureShaderApplier to a member function in DepalCache. --- GPU/Common/DepalettizeCommon.cpp | 49 +++++++++++++++++++++++ GPU/Common/DepalettizeCommon.h | 66 +------------------------------ GPU/Common/TextureCacheCommon.cpp | 7 ++-- 3 files changed, 55 insertions(+), 67 deletions(-) diff --git a/GPU/Common/DepalettizeCommon.cpp b/GPU/Common/DepalettizeCommon.cpp index 185eecdbc4..f23e2607ba 100644 --- a/GPU/Common/DepalettizeCommon.cpp +++ b/GPU/Common/DepalettizeCommon.cpp @@ -243,3 +243,52 @@ std::string DepalShaderCache::DebugGetShaderString(std::string idstr, DebugShade return ""; } } + +// TODO: Merge with DepalShaderCache? +void DepalShaderCache::ApplyShader(DepalShader *shader, float bufferW, float bufferH, int renderW, int renderH, const KnownVertexBounds &bounds, u32 uoff, u32 voff) { + Draw2DVertex verts[4] = { + {-1, -1, 0, 0 }, + { 1, -1, 1, 0 }, + {-1, 1, 0, 1 }, + { 1, 1, 1, 1 }, + }; + + // If min is not < max, then we don't have values (wasn't set during decode.) + if (bounds.minV < bounds.maxV) { + const float invWidth = 1.0f / bufferW; + const float invHeight = 1.0f / bufferH; + // Inverse of half = double. + const float invHalfWidth = invWidth * 2.0f; + const float invHalfHeight = invHeight * 2.0f; + + const int u1 = bounds.minU + uoff; + const int v1 = bounds.minV + voff; + const int u2 = bounds.maxU + uoff; + const int v2 = bounds.maxV + voff; + + const float left = u1 * invHalfWidth - 1.0f; + const float right = u2 * invHalfWidth - 1.0f; + const float top = v1 * invHalfHeight - 1.0f; + const float bottom = v2 * invHalfHeight - 1.0f; + + const float uvleft = u1 * invWidth; + const float uvright = u2 * invWidth; + const float uvtop = v1 * invHeight; + const float uvbottom = v2 * invHeight; + + // Points are: BL, BR, TR, TL. + verts[0] = Draw2DVertex{ left, bottom, uvleft, uvbottom }; + verts[1] = Draw2DVertex{ right, bottom, uvright, uvbottom }; + verts[2] = Draw2DVertex{ left, top, uvleft, uvtop }; + verts[3] = Draw2DVertex{ right, top, uvright, uvtop }; + + // We need to reapply the texture next time since we cropped UV. + gstate_c.Dirty(DIRTY_TEXTURE_PARAMS); + } + + Draw::Viewport vp{ 0.0f, 0.0f, (float)renderW, (float)renderH, 0.0f, 1.0f }; + draw_->BindPipeline(shader->pipeline); + draw_->SetViewports(1, &vp); + draw_->SetScissorRect(0, 0, renderW, renderH); + draw_->DrawUP((const uint8_t *)verts, 4); +} diff --git a/GPU/Common/DepalettizeCommon.h b/GPU/Common/DepalettizeCommon.h index 6e3ef680ef..169e7e8b9d 100644 --- a/GPU/Common/DepalettizeCommon.h +++ b/GPU/Common/DepalettizeCommon.h @@ -54,6 +54,8 @@ public: Draw::SamplerState *GetSampler(); + void ApplyShader(DepalShader *shader, float bufferW, float bufferH, int renderW, int renderH, const KnownVertexBounds &bounds, u32 uoff, u32 voff); + void Clear(); void Decimate(); std::vector DebugGetShaderIDs(DebugShaderType type); @@ -79,67 +81,3 @@ private: std::map cache_; std::map texCache_; }; - -// TODO: Merge with DepalShaderCache? -class TextureShaderApplier { -public: - TextureShaderApplier(Draw::DrawContext *draw, DepalShader *shader, float bufferW, float bufferH, int renderW, int renderH) - : draw_(draw), shader_(shader), bufferW_(bufferW), bufferH_(bufferH), renderW_(renderW), renderH_(renderH) { - static const Draw2DVertex defaultVerts[4] = { - {-1, -1, 0, 0 }, - { 1, -1, 1, 0 }, - {-1, 1, 0, 1 }, - { 1, 1, 1, 1 }, - }; - memcpy(verts_, defaultVerts, sizeof(defaultVerts)); - } - - void Shade(const KnownVertexBounds &bounds, u32 uoff, u32 voff) { - // If min is not < max, then we don't have values (wasn't set during decode.) - if (bounds.minV < bounds.maxV) { - const float invWidth = 1.0f / bufferW_; - const float invHeight = 1.0f / bufferH_; - // Inverse of half = double. - const float invHalfWidth = invWidth * 2.0f; - const float invHalfHeight = invHeight * 2.0f; - - const int u1 = bounds.minU + uoff; - const int v1 = bounds.minV + voff; - const int u2 = bounds.maxU + uoff; - const int v2 = bounds.maxV + voff; - - const float left = u1 * invHalfWidth - 1.0f; - const float right = u2 * invHalfWidth - 1.0f; - const float top = v1 * invHalfHeight - 1.0f; - const float bottom = v2 * invHalfHeight - 1.0f; - - const float uvleft = u1 * invWidth; - const float uvright = u2 * invWidth; - const float uvtop = v1 * invHeight; - const float uvbottom = v2 * invHeight; - - // Points are: BL, BR, TR, TL. - verts_[0] = Draw2DVertex{ left, bottom, uvleft, uvbottom }; - verts_[1] = Draw2DVertex{ right, bottom, uvright, uvbottom }; - verts_[2] = Draw2DVertex{ left, top, uvleft, uvtop }; - verts_[3] = Draw2DVertex{ right, top, uvright, uvtop }; - - // We need to reapply the texture next time since we cropped UV. - gstate_c.Dirty(DIRTY_TEXTURE_PARAMS); - } - Draw::Viewport vp{ 0.0f, 0.0f, (float)renderW_, (float)renderH_, 0.0f, 1.0f }; - draw_->BindPipeline(shader_->pipeline); - draw_->SetViewports(1, &vp); - draw_->SetScissorRect(0, 0, renderW_, renderH_); - draw_->DrawUP((const uint8_t *)verts_, 4); - } - -protected: - Draw::DrawContext *draw_; - DepalShader *shader_; - Draw2DVertex verts_[4]; - float bufferW_; - float bufferH_; - int renderW_; - int renderH_; -}; diff --git a/GPU/Common/TextureCacheCommon.cpp b/GPU/Common/TextureCacheCommon.cpp index 3022f1d1c4..9b092f0e7c 100644 --- a/GPU/Common/TextureCacheCommon.cpp +++ b/GPU/Common/TextureCacheCommon.cpp @@ -1929,15 +1929,16 @@ void TextureCacheCommon::ApplyTextureFramebuffer(VirtualFramebuffer *framebuffer Draw::Viewport vp{ 0.0f, 0.0f, (float)framebuffer->renderWidth, (float)framebuffer->renderHeight, 0.0f, 1.0f }; draw_->SetViewports(1, &vp); - TextureShaderApplier shaderApply(draw_, depalShader, framebuffer->bufferWidth, framebuffer->bufferHeight, framebuffer->renderWidth, framebuffer->renderHeight); - draw_->BindFramebufferAsTexture(framebuffer->fbo, 0, depth ? Draw::FB_DEPTH_BIT : Draw::FB_COLOR_BIT, 0); draw_->BindTexture(1, clutTexture); Draw::SamplerState *nearest = depalShaderCache_->GetSampler(); draw_->BindSamplerStates(0, 1, &nearest); draw_->BindSamplerStates(1, 1, &nearest); - shaderApply.Shade(gstate_c.vertBounds, gstate_c.curTextureXOffset, gstate_c.curTextureYOffset); + depalShaderCache_->ApplyShader(depalShader, + framebuffer->bufferWidth, framebuffer->bufferHeight, framebuffer->renderWidth, framebuffer->renderHeight, + gstate_c.vertBounds, gstate_c.curTextureXOffset, gstate_c.curTextureYOffset); + draw_->BindTexture(0, nullptr); framebufferManager_->RebindFramebuffer("ApplyTextureFramebuffer"); From 82a6c42e174fef9670581997efe26069031d5a25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Mon, 22 Aug 2022 12:20:21 +0200 Subject: [PATCH 3/4] DepalettizeCommon -> TextureShaderCommon. Simplifications. --- CMakeLists.txt | 4 +- GPU/Common/DepalettizeShaderCommon.cpp | 4 +- GPU/Common/DepalettizeShaderCommon.h | 2 +- GPU/Common/TextureCacheCommon.cpp | 4 +- GPU/Common/TextureCacheCommon.h | 6 +- ...tizeCommon.cpp => TextureShaderCommon.cpp} | 114 +++++++++--------- ...alettizeCommon.h => TextureShaderCommon.h} | 26 ++-- GPU/D3D11/GPU_D3D11.h | 2 +- GPU/D3D11/TextureCacheD3D11.cpp | 2 +- GPU/D3D11/TextureCacheD3D11.h | 2 +- GPU/Directx9/GPU_DX9.h | 2 +- GPU/Directx9/TextureCacheDX9.cpp | 2 +- GPU/Directx9/TextureCacheDX9.h | 2 +- GPU/GLES/GPU_GLES.h | 2 +- GPU/GLES/TextureCacheGLES.cpp | 2 +- GPU/GLES/TextureCacheGLES.h | 4 +- GPU/GPU.vcxproj | 4 +- GPU/GPU.vcxproj.filters | 4 +- GPU/Vulkan/GPU_Vulkan.h | 2 +- GPU/Vulkan/TextureCacheVulkan.cpp | 2 +- GPU/Vulkan/TextureCacheVulkan.h | 2 +- UWP/GPU_UWP/GPU_UWP.vcxproj | 6 +- UWP/GPU_UWP/GPU_UWP.vcxproj.filters | 6 +- android/jni/Android.mk | 2 +- libretro/Makefile.common | 2 +- unittest/TestShaderGenerators.cpp | 2 +- 26 files changed, 105 insertions(+), 107 deletions(-) rename GPU/Common/{DepalettizeCommon.cpp => TextureShaderCommon.cpp} (78%) rename GPU/Common/{DepalettizeCommon.h => TextureShaderCommon.h} (68%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8c5dbcd989..09cae88753 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1536,8 +1536,8 @@ set(GPU_SOURCES ${GPU_NEON} GPU/Common/Draw2D.cpp GPU/Common/Draw2D.h - GPU/Common/DepalettizeCommon.cpp - GPU/Common/DepalettizeCommon.h + GPU/Common/TextureShaderCommon.cpp + GPU/Common/TextureShaderCommon.h GPU/Common/DepalettizeShaderCommon.cpp GPU/Common/DepalettizeShaderCommon.h GPU/Common/FragmentShaderGenerator.cpp diff --git a/GPU/Common/DepalettizeShaderCommon.cpp b/GPU/Common/DepalettizeShaderCommon.cpp index af2bf13437..2b9ddca413 100644 --- a/GPU/Common/DepalettizeShaderCommon.cpp +++ b/GPU/Common/DepalettizeShaderCommon.cpp @@ -34,7 +34,7 @@ static const InputDef vsInputs[2] = { { "vec2", "a_texcoord0", Draw::SEM_TEXCOORD0, }, }; -// TODO: Deduplicate with DepalettizeCommon.cpp +// TODO: Deduplicate with TextureShaderCommon.cpp static const SamplerDef samplers[2] = { { "tex" }, { "pal" }, @@ -309,7 +309,7 @@ void GenerateDepalFs(char *buffer, const DepalConfig &config, const ShaderLangua writer.EndFSMain("outColor", FSFLAG_NONE); } -void GenerateDepalVs(char *buffer, const ShaderLanguageDesc &lang) { +void GenerateVs(char *buffer, const ShaderLanguageDesc &lang) { ShaderWriter writer(buffer, lang, ShaderStage::Vertex, nullptr, 0); writer.BeginVSMain(vsInputs, Slice::empty(), varyings); writer.C(" v_texcoord = a_texcoord0;\n"); diff --git a/GPU/Common/DepalettizeShaderCommon.h b/GPU/Common/DepalettizeShaderCommon.h index 74bb38d196..91186f5d20 100644 --- a/GPU/Common/DepalettizeShaderCommon.h +++ b/GPU/Common/DepalettizeShaderCommon.h @@ -34,4 +34,4 @@ struct DepalConfig { }; void GenerateDepalFs(char *buffer, const DepalConfig &config, const ShaderLanguageDesc &lang); -void GenerateDepalVs(char *buffer, const ShaderLanguageDesc &lang); +void GenerateVs(char *buffer, const ShaderLanguageDesc &lang); diff --git a/GPU/Common/TextureCacheCommon.cpp b/GPU/Common/TextureCacheCommon.cpp index 9b092f0e7c..b237c3a97e 100644 --- a/GPU/Common/TextureCacheCommon.cpp +++ b/GPU/Common/TextureCacheCommon.cpp @@ -124,7 +124,7 @@ TextureCacheCommon::TextureCacheCommon(Draw::DrawContext *draw) replacer_.Init(); - depalShaderCache_ = new DepalShaderCache(draw); + depalShaderCache_ = new TextureShaderCache(draw); } TextureCacheCommon::~TextureCacheCommon() { @@ -1860,7 +1860,7 @@ bool CanDepalettize(GETextureFormat texFormat, GEBufferFormat bufferFormat) { } void TextureCacheCommon::ApplyTextureFramebuffer(VirtualFramebuffer *framebuffer, GETextureFormat texFormat, RasterChannel channel) { - DepalShader *depalShader = nullptr; + TextureShader *depalShader = nullptr; uint32_t clutMode = gstate.clutformat & 0xFFFFFF; bool depth = channel == RASTER_DEPTH; diff --git a/GPU/Common/TextureCacheCommon.h b/GPU/Common/TextureCacheCommon.h index 12f0d64213..8be81d3433 100644 --- a/GPU/Common/TextureCacheCommon.h +++ b/GPU/Common/TextureCacheCommon.h @@ -29,7 +29,7 @@ #include "GPU/Common/GPUDebugInterface.h" #include "GPU/Common/TextureDecoder.h" #include "GPU/Common/TextureScalerCommon.h" -#include "GPU/Common/DepalettizeCommon.h" +#include "GPU/Common/TextureShaderCommon.h" enum FramebufferNotification { NOTIFY_FB_CREATED, @@ -291,7 +291,7 @@ public: void InvalidateAll(GPUInvalidationType type); void ClearNextFrame(); - DepalShaderCache *GetDepalShaderCache() { return depalShaderCache_; } + TextureShaderCache *GetDepalShaderCache() { return depalShaderCache_; } virtual void ForgetLastTexture() = 0; virtual void InvalidateLastTexture() = 0; @@ -403,7 +403,7 @@ protected: TextureReplacer replacer_; TextureScalerCommon scaler_; FramebufferManagerCommon *framebufferManager_; - DepalShaderCache *depalShaderCache_; + TextureShaderCache *depalShaderCache_; ShaderManagerCommon *shaderManager_; bool clearCacheNextFrame_ = false; diff --git a/GPU/Common/DepalettizeCommon.cpp b/GPU/Common/TextureShaderCommon.cpp similarity index 78% rename from GPU/Common/DepalettizeCommon.cpp rename to GPU/Common/TextureShaderCommon.cpp index f23e2607ba..77072565ea 100644 --- a/GPU/Common/DepalettizeCommon.cpp +++ b/GPU/Common/TextureShaderCommon.cpp @@ -25,8 +25,8 @@ #include "Core/Reporting.h" #include "GPU/Common/DrawEngineCommon.h" #include "GPU/Common/TextureCacheCommon.h" +#include "GPU/Common/TextureShaderCommon.h" #include "GPU/Common/DepalettizeShaderCommon.h" -#include "GPU/Common/DepalettizeCommon.h" static const VaryingDef varyings[1] = { { "vec2", "v_texcoord", Draw::SEM_TEXCOORD0, 0, "highp" }, @@ -37,22 +37,23 @@ static const SamplerDef samplers[2] = { { "pal" }, }; -DepalShaderCache::DepalShaderCache(Draw::DrawContext *draw) : draw_(draw) { } +TextureShaderCache::TextureShaderCache(Draw::DrawContext *draw) : draw_(draw) { } -DepalShaderCache::~DepalShaderCache() { +TextureShaderCache::~TextureShaderCache() { DeviceLost(); } -void DepalShaderCache::DeviceRestore(Draw::DrawContext *draw) { +void TextureShaderCache::DeviceRestore(Draw::DrawContext *draw) { draw_ = draw; } -void DepalShaderCache::DeviceLost() { +void TextureShaderCache::DeviceLost() { Clear(); } -Draw::Texture *DepalShaderCache::GetClutTexture(GEPaletteFormat clutFormat, const u32 clutHash, u32 *rawClut) { - u32 clutId = GetClutID(clutFormat, clutHash); +Draw::Texture *TextureShaderCache::GetClutTexture(GEPaletteFormat clutFormat, const u32 clutHash, u32 *rawClut) { + // Simplistic, but works well enough. + u32 clutId = clutHash ^ (uint32_t)clutFormat; auto oldtex = texCache_.find(clutId); if (oldtex != texCache_.end()) { @@ -100,15 +101,14 @@ Draw::Texture *DepalShaderCache::GetClutTexture(GEPaletteFormat clutFormat, cons return tex->texture; } -void DepalShaderCache::Clear() { - for (auto shader = cache_.begin(); shader != cache_.end(); ++shader) { - shader->second->fragShader->Release(); +void TextureShaderCache::Clear() { + for (auto shader = depalCache_.begin(); shader != depalCache_.end(); ++shader) { if (shader->second->pipeline) { shader->second->pipeline->Release(); } delete shader->second; } - cache_.clear(); + depalCache_.clear(); for (auto tex = texCache_.begin(); tex != texCache_.end(); ++tex) { tex->second->texture->Release(); delete tex->second; @@ -124,7 +124,7 @@ void DepalShaderCache::Clear() { } } -void DepalShaderCache::Decimate() { +void TextureShaderCache::Decimate() { for (auto tex = texCache_.begin(); tex != texCache_.end(); ) { if (tex->second->lastFrame + DEPAL_TEXTURE_OLD_AGE < gpuStats.numFlips) { tex->second->texture->Release(); @@ -136,7 +136,7 @@ void DepalShaderCache::Decimate() { } } -Draw::SamplerState *DepalShaderCache::GetSampler() { +Draw::SamplerState *TextureShaderCache::GetSampler() { if (!nearestSampler_) { Draw::SamplerStateDesc desc{}; desc.wrapU = Draw::TextureAddressMode::CLAMP_TO_EDGE; @@ -147,39 +147,16 @@ Draw::SamplerState *DepalShaderCache::GetSampler() { return nearestSampler_; } -DepalShader *DepalShaderCache::GetDepalettizeShader(uint32_t clutMode, GETextureFormat textureFormat, GEBufferFormat bufferFormat) { +TextureShader *TextureShaderCache::CreateShader(const char *fs) { using namespace Draw; - - u32 id = GenerateShaderID(clutMode, textureFormat, bufferFormat); - - auto shader = cache_.find(id); - if (shader != cache_.end()) { - DepalShader *depal = shader->second; - return shader->second; - } - - char *buffer = new char[4096]; - if (!vertexShader_) { - GenerateDepalVs(buffer, draw_->GetShaderLanguageDesc()); + char *buffer = new char[4096]; + GenerateVs(buffer, draw_->GetShaderLanguageDesc()); vertexShader_ = draw_->CreateShaderModule(ShaderStage::Vertex, draw_->GetShaderLanguageDesc().shaderLanguage, (const uint8_t *)buffer, strlen(buffer), "depal_vs"); + delete[] buffer; } - // TODO: Parse these out of clutMode some nice way, to become a bit more stateless. - DepalConfig config; - config.clutFormat = gstate.getClutPaletteFormat(); - config.startPos = gstate.getClutIndexStartPos(); - config.shift = gstate.getClutIndexShift(); - config.mask = gstate.getClutIndexMask(); - config.bufferFormat = bufferFormat; - config.textureFormat = textureFormat; - - GenerateDepalFs(buffer, config, draw_->GetShaderLanguageDesc()); - - std::string src(buffer); - ShaderModule *fragShader = draw_->CreateShaderModule(ShaderStage::Fragment, draw_->GetShaderLanguageDesc().shaderLanguage, (const uint8_t *)buffer, strlen(buffer), "depal_fs"); - - DepalShader *depal = new DepalShader(); + ShaderModule *fragShader = draw_->CreateShaderModule(ShaderStage::Fragment, draw_->GetShaderLanguageDesc().shaderLanguage, (const uint8_t *)fs, strlen(fs), "depal_fs"); static const InputLayoutDesc desc = { { @@ -201,38 +178,67 @@ DepalShader *DepalShaderCache::GetDepalettizeShader(uint32_t clutMode, GETexture { vertexShader_, fragShader }, inputLayout, noDepthStencil, blendOff, rasterNoCull, nullptr, samplers }; - + Pipeline *pipeline = draw_->CreateGraphicsPipeline(depalPipelineDesc); inputLayout->Release(); blendOff->Release(); noDepthStencil->Release(); rasterNoCull->Release(); + fragShader->Release(); _assert_(pipeline); + TextureShader *depal = new TextureShader(); depal->pipeline = pipeline; - depal->fragShader = fragShader; - depal->code = buffer; - cache_[id] = depal; - - delete[] buffer; - return depal->pipeline ? depal : nullptr; + depal->code = fs; // to std::string + return depal; } -std::vector DepalShaderCache::DebugGetShaderIDs(DebugShaderType type) { +TextureShader *TextureShaderCache::GetDepalettizeShader(uint32_t clutMode, GETextureFormat textureFormat, GEBufferFormat bufferFormat) { + using namespace Draw; + + // Generate an ID for depal shaders. + u32 id = (clutMode & 0xFFFFFF) | (textureFormat << 24) | (bufferFormat << 28); + + auto shader = depalCache_.find(id); + if (shader != depalCache_.end()) { + TextureShader *depal = shader->second; + return shader->second; + } + + // TODO: Parse these out of clutMode some nice way, to become a bit more stateless. + DepalConfig config; + config.clutFormat = gstate.getClutPaletteFormat(); + config.startPos = gstate.getClutIndexStartPos(); + config.shift = gstate.getClutIndexShift(); + config.mask = gstate.getClutIndexMask(); + config.bufferFormat = bufferFormat; + config.textureFormat = textureFormat; + + char *buffer = new char[4096]; + GenerateDepalFs(buffer, config, draw_->GetShaderLanguageDesc()); + TextureShader *ts = CreateShader(buffer); + delete[] buffer; + + depalCache_[id] = ts; + + return ts->pipeline ? ts : nullptr; +} + +std::vector TextureShaderCache::DebugGetShaderIDs(DebugShaderType type) { std::vector ids; - for (auto &iter : cache_) { + for (auto &iter : depalCache_) { ids.push_back(StringFromFormat("%08x", iter.first)); } return ids; } -std::string DepalShaderCache::DebugGetShaderString(std::string idstr, DebugShaderType type, DebugShaderStringType stringType) { +std::string TextureShaderCache::DebugGetShaderString(std::string idstr, DebugShaderType type, DebugShaderStringType stringType) { uint32_t id; sscanf(idstr.c_str(), "%08x", &id); - auto iter = cache_.find(id); - if (iter == cache_.end()) + auto iter = depalCache_.find(id); + if (iter == depalCache_.end()) return ""; switch (stringType) { case SHADER_STRING_SHORT_DESC: @@ -245,7 +251,7 @@ std::string DepalShaderCache::DebugGetShaderString(std::string idstr, DebugShade } // TODO: Merge with DepalShaderCache? -void DepalShaderCache::ApplyShader(DepalShader *shader, float bufferW, float bufferH, int renderW, int renderH, const KnownVertexBounds &bounds, u32 uoff, u32 voff) { +void TextureShaderCache::ApplyShader(TextureShader *shader, float bufferW, float bufferH, int renderW, int renderH, const KnownVertexBounds &bounds, u32 uoff, u32 voff) { Draw2DVertex verts[4] = { {-1, -1, 0, 0 }, { 1, -1, 1, 0 }, diff --git a/GPU/Common/DepalettizeCommon.h b/GPU/Common/TextureShaderCommon.h similarity index 68% rename from GPU/Common/DepalettizeCommon.h rename to GPU/Common/TextureShaderCommon.h index 169e7e8b9d..628746b465 100644 --- a/GPU/Common/DepalettizeCommon.h +++ b/GPU/Common/TextureShaderCommon.h @@ -29,9 +29,8 @@ #include "GPU/Common/ShaderCommon.h" #include "GPU/Common/DepalettizeShaderCommon.h" -class DepalShader { +class TextureShader { public: - Draw::ShaderModule *fragShader; Draw::Pipeline *pipeline; std::string code; }; @@ -42,19 +41,19 @@ public: int lastFrame; }; +// For CLUT depal shaders, and other pre-bind texture shaders. // Caches both shaders and palette textures. -class DepalShaderCache { +class TextureShaderCache { public: - DepalShaderCache(Draw::DrawContext *draw); - ~DepalShaderCache(); + TextureShaderCache(Draw::DrawContext *draw); + ~TextureShaderCache(); - // This also uploads the palette and binds the correct texture. - DepalShader *GetDepalettizeShader(uint32_t clutMode, GETextureFormat texFormat, GEBufferFormat pixelFormat); + TextureShader *GetDepalettizeShader(uint32_t clutMode, GETextureFormat texFormat, GEBufferFormat pixelFormat); Draw::Texture *GetClutTexture(GEPaletteFormat clutFormat, const u32 clutHash, u32 *rawClut); Draw::SamplerState *GetSampler(); - void ApplyShader(DepalShader *shader, float bufferW, float bufferH, int renderW, int renderH, const KnownVertexBounds &bounds, u32 uoff, u32 voff); + void ApplyShader(TextureShader *shader, float bufferW, float bufferH, int renderW, int renderH, const KnownVertexBounds &bounds, u32 uoff, u32 voff); void Clear(); void Decimate(); @@ -65,19 +64,12 @@ public: void DeviceRestore(Draw::DrawContext *draw); private: - static uint32_t GenerateShaderID(uint32_t clutMode, GETextureFormat texFormat, GEBufferFormat pixelFormat) { - return (clutMode & 0xFFFFFF) | (pixelFormat << 24) | (texFormat << 28); - } - - static uint32_t GetClutID(GEPaletteFormat clutFormat, uint32_t clutHash) { - // Simplistic. - return clutHash ^ (uint32_t)clutFormat; - } + TextureShader *CreateShader(const char *fs); Draw::DrawContext *draw_; Draw::ShaderModule *vertexShader_ = nullptr; Draw::SamplerState *nearestSampler_ = nullptr; - std::map cache_; + std::map depalCache_; std::map texCache_; }; diff --git a/GPU/D3D11/GPU_D3D11.h b/GPU/D3D11/GPU_D3D11.h index 94a0aef915..33790c7f99 100644 --- a/GPU/D3D11/GPU_D3D11.h +++ b/GPU/D3D11/GPU_D3D11.h @@ -23,7 +23,7 @@ #include "GPU/GPUCommon.h" #include "GPU/D3D11/DrawEngineD3D11.h" -#include "GPU/Common/DepalettizeCommon.h" +#include "GPU/Common/TextureShaderCommon.h" #include "GPU/Common/VertexDecoderCommon.h" class FramebufferManagerD3D11; diff --git a/GPU/D3D11/TextureCacheD3D11.cpp b/GPU/D3D11/TextureCacheD3D11.cpp index 2fea477610..fabb7cca4a 100644 --- a/GPU/D3D11/TextureCacheD3D11.cpp +++ b/GPU/D3D11/TextureCacheD3D11.cpp @@ -31,7 +31,7 @@ #include "GPU/D3D11/TextureCacheD3D11.h" #include "GPU/D3D11/FramebufferManagerD3D11.h" #include "GPU/D3D11/ShaderManagerD3D11.h" -#include "GPU/Common/DepalettizeCommon.h" +#include "GPU/Common/TextureShaderCommon.h" #include "GPU/D3D11/D3D11Util.h" #include "GPU/Common/FramebufferManagerCommon.h" #include "GPU/Common/TextureDecoder.h" diff --git a/GPU/D3D11/TextureCacheD3D11.h b/GPU/D3D11/TextureCacheD3D11.h index 433f6e824e..b641c72866 100644 --- a/GPU/D3D11/TextureCacheD3D11.h +++ b/GPU/D3D11/TextureCacheD3D11.h @@ -28,7 +28,7 @@ struct VirtualFramebuffer; class FramebufferManagerD3D11; -class DepalShaderCache; +class TextureShaderCache; class ShaderManagerD3D11; class SamplerCacheD3D11 { diff --git a/GPU/Directx9/GPU_DX9.h b/GPU/Directx9/GPU_DX9.h index 349d2bd0a8..35ac9817e1 100644 --- a/GPU/Directx9/GPU_DX9.h +++ b/GPU/Directx9/GPU_DX9.h @@ -23,7 +23,7 @@ #include "GPU/GPUCommon.h" #include "GPU/Directx9/FramebufferManagerDX9.h" #include "GPU/Directx9/DrawEngineDX9.h" -#include "GPU/Common/DepalettizeCommon.h" +#include "GPU/Common/TextureShaderCommon.h" #include "GPU/Common/VertexDecoderCommon.h" class ShaderManagerDX9; diff --git a/GPU/Directx9/TextureCacheDX9.cpp b/GPU/Directx9/TextureCacheDX9.cpp index ea6b47e2e9..905f445c1c 100644 --- a/GPU/Directx9/TextureCacheDX9.cpp +++ b/GPU/Directx9/TextureCacheDX9.cpp @@ -28,7 +28,7 @@ #include "GPU/Directx9/FramebufferManagerDX9.h" #include "GPU/Directx9/ShaderManagerDX9.h" #include "Common/GPU/D3D9/D3D9StateCache.h" -#include "GPU/Common/DepalettizeCommon.h" +#include "GPU/Common/TextureShaderCommon.h" #include "GPU/Common/FramebufferManagerCommon.h" #include "GPU/Common/TextureDecoder.h" #include "Core/Config.h" diff --git a/GPU/Directx9/TextureCacheDX9.h b/GPU/Directx9/TextureCacheDX9.h index 47005cbd5c..40351be611 100644 --- a/GPU/Directx9/TextureCacheDX9.h +++ b/GPU/Directx9/TextureCacheDX9.h @@ -24,7 +24,7 @@ #include "GPU/Common/TextureCacheCommon.h" struct VirtualFramebuffer; -class DepalShaderCache; +class TextureShaderCache; class FramebufferManagerDX9; class ShaderManagerDX9; diff --git a/GPU/GLES/GPU_GLES.h b/GPU/GLES/GPU_GLES.h index a6e521763a..f308d15445 100644 --- a/GPU/GLES/GPU_GLES.h +++ b/GPU/GLES/GPU_GLES.h @@ -23,7 +23,7 @@ #include "Common/File/Path.h" #include "GPU/GPUCommon.h" -#include "GPU/Common/DepalettizeCommon.h" +#include "GPU/Common/TextureShaderCommon.h" #include "GPU/GLES/FramebufferManagerGLES.h" #include "GPU/GLES/DrawEngineGLES.h" #include "GPU/GLES/FragmentTestCacheGLES.h" diff --git a/GPU/GLES/TextureCacheGLES.cpp b/GPU/GLES/TextureCacheGLES.cpp index fb3c1a01b3..ddaad253bc 100644 --- a/GPU/GLES/TextureCacheGLES.cpp +++ b/GPU/GLES/TextureCacheGLES.cpp @@ -36,7 +36,7 @@ #include "GPU/GLES/TextureCacheGLES.h" #include "GPU/GLES/FramebufferManagerGLES.h" #include "GPU/Common/FragmentShaderGenerator.h" -#include "GPU/Common/DepalettizeCommon.h" +#include "GPU/Common/TextureShaderCommon.h" #include "GPU/GLES/ShaderManagerGLES.h" #include "GPU/GLES/DrawEngineGLES.h" #include "GPU/Common/TextureDecoder.h" diff --git a/GPU/GLES/TextureCacheGLES.h b/GPU/GLES/TextureCacheGLES.h index ac5313c3cb..b23af129f5 100644 --- a/GPU/GLES/TextureCacheGLES.h +++ b/GPU/GLES/TextureCacheGLES.h @@ -27,7 +27,7 @@ struct VirtualFramebuffer; class FramebufferManagerGLES; -class DepalShaderCache; +class TextureShaderCache; class ShaderManagerGLES; class DrawEngineGLES; class GLRTexture; @@ -41,7 +41,7 @@ public: void StartFrame() override; void SetFramebufferManager(FramebufferManagerGLES *fbManager); - void SetDepalShaderCache(DepalShaderCache *dpCache) { + void SetDepalShaderCache(TextureShaderCache *dpCache) { depalShaderCache_ = dpCache; } void SetDrawEngine(DrawEngineGLES *td) { diff --git a/GPU/GPU.vcxproj b/GPU/GPU.vcxproj index 86d21d3690..1f37652321 100644 --- a/GPU/GPU.vcxproj +++ b/GPU/GPU.vcxproj @@ -338,7 +338,7 @@ - + @@ -452,7 +452,7 @@ - + diff --git a/GPU/GPU.vcxproj.filters b/GPU/GPU.vcxproj.filters index cb2832c032..d581cb4bad 100644 --- a/GPU/GPU.vcxproj.filters +++ b/GPU/GPU.vcxproj.filters @@ -255,7 +255,7 @@ Common - + Common @@ -503,7 +503,7 @@ Common - + Common diff --git a/GPU/Vulkan/GPU_Vulkan.h b/GPU/Vulkan/GPU_Vulkan.h index 87e54dbf19..18da82e6b0 100644 --- a/GPU/Vulkan/GPU_Vulkan.h +++ b/GPU/Vulkan/GPU_Vulkan.h @@ -25,7 +25,7 @@ #include "GPU/GPUCommon.h" #include "GPU/Vulkan/DrawEngineVulkan.h" #include "GPU/Vulkan/PipelineManagerVulkan.h" -#include "GPU/Common/DepalettizeCommon.h" +#include "GPU/Common/TextureShaderCommon.h" class FramebufferManagerVulkan; class ShaderManagerVulkan; diff --git a/GPU/Vulkan/TextureCacheVulkan.cpp b/GPU/Vulkan/TextureCacheVulkan.cpp index 603b064f8b..132c0e081a 100644 --- a/GPU/Vulkan/TextureCacheVulkan.cpp +++ b/GPU/Vulkan/TextureCacheVulkan.cpp @@ -41,7 +41,7 @@ #include "GPU/ge_constants.h" #include "GPU/GPUState.h" -#include "GPU/Common/DepalettizeCommon.h" +#include "GPU/Common/TextureShaderCommon.h" #include "GPU/Common/PostShader.h" #include "GPU/Common/TextureCacheCommon.h" #include "GPU/Common/TextureDecoder.h" diff --git a/GPU/Vulkan/TextureCacheVulkan.h b/GPU/Vulkan/TextureCacheVulkan.h index c3fc55945e..c56652d2c9 100644 --- a/GPU/Vulkan/TextureCacheVulkan.h +++ b/GPU/Vulkan/TextureCacheVulkan.h @@ -22,7 +22,7 @@ #include "GPU/GPUState.h" #include "Common/GPU/Vulkan/VulkanContext.h" #include "GPU/Common/TextureCacheCommon.h" -#include "GPU/Common/DepalettizeCommon.h" +#include "GPU/Common/TextureShaderCommon.h" #include "GPU/Vulkan/VulkanUtil.h" struct VirtualFramebuffer; diff --git a/UWP/GPU_UWP/GPU_UWP.vcxproj b/UWP/GPU_UWP/GPU_UWP.vcxproj index 9a24b23185..277526509c 100644 --- a/UWP/GPU_UWP/GPU_UWP.vcxproj +++ b/UWP/GPU_UWP/GPU_UWP.vcxproj @@ -379,7 +379,7 @@ - + @@ -439,7 +439,7 @@ - + @@ -527,4 +527,4 @@ - \ No newline at end of file + diff --git a/UWP/GPU_UWP/GPU_UWP.vcxproj.filters b/UWP/GPU_UWP/GPU_UWP.vcxproj.filters index affb707ff7..2a797c0d2e 100644 --- a/UWP/GPU_UWP/GPU_UWP.vcxproj.filters +++ b/UWP/GPU_UWP/GPU_UWP.vcxproj.filters @@ -57,7 +57,7 @@ - + @@ -117,6 +117,6 @@ - + - \ No newline at end of file + diff --git a/android/jni/Android.mk b/android/jni/Android.mk index 71fcf8de3a..7f3afa7849 100644 --- a/android/jni/Android.mk +++ b/android/jni/Android.mk @@ -319,7 +319,7 @@ EXEC_AND_LIB_FILES := \ $(SRC)/GPU/GeConstants.cpp \ $(SRC)/GPU/GeDisasm.cpp \ $(SRC)/GPU/Common/Draw2D.cpp \ - $(SRC)/GPU/Common/DepalettizeCommon.cpp \ + $(SRC)/GPU/Common/TextureShaderCommon.cpp \ $(SRC)/GPU/Common/DepalettizeShaderCommon.cpp \ $(SRC)/GPU/Common/FragmentShaderGenerator.cpp \ $(SRC)/GPU/Common/FramebufferManagerCommon.cpp \ diff --git a/libretro/Makefile.common b/libretro/Makefile.common index 183afdf060..6e5a9726cb 100644 --- a/libretro/Makefile.common +++ b/libretro/Makefile.common @@ -327,7 +327,7 @@ SOURCES_CXX += \ $(GPUCOMMONDIR)/ShaderCommon.cpp \ $(GPUCOMMONDIR)/ShaderUniforms.cpp \ $(GPUCOMMONDIR)/GPUDebugInterface.cpp \ - $(GPUCOMMONDIR)/DepalettizeCommon.cpp \ + $(GPUCOMMONDIR)/TextureShaderCommon.cpp \ $(GPUCOMMONDIR)/DepalettizeShaderCommon.cpp \ $(GPUCOMMONDIR)/TransformCommon.cpp \ $(GPUCOMMONDIR)/IndexGenerator.cpp \ diff --git a/unittest/TestShaderGenerators.cpp b/unittest/TestShaderGenerators.cpp index a96df6657c..2463fde971 100644 --- a/unittest/TestShaderGenerators.cpp +++ b/unittest/TestShaderGenerators.cpp @@ -321,7 +321,7 @@ bool TestDepalShaders() { printf("===\n%s\n===\n", buffer); } - GenerateDepalVs(buffer, desc); + GenerateVs(buffer, desc); if (!TestCompileShader(buffer, languages[k], ShaderStage::Vertex, &errorMessage)) { printf("Error compiling depal shader:\n\n%s\n\n%s\n", LineNumberString(buffer).c_str(), errorMessage.c_str()); failed = true; From b39b74e602d36d9ff2b433670bd5cdfa36d09902 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Mon, 22 Aug 2022 12:28:46 +0200 Subject: [PATCH 4/4] More renaming. Fix shader view for Vulkan --- GPU/Common/ShaderCommon.h | 2 +- GPU/Common/TextureCacheCommon.cpp | 22 +++++++++++----------- GPU/Common/TextureCacheCommon.h | 4 ++-- GPU/Common/TextureShaderCommon.cpp | 3 +-- GPU/Common/TextureShaderCommon.h | 4 ++-- GPU/D3D11/GPU_D3D11.cpp | 8 ++++---- GPU/Directx9/GPU_DX9.cpp | 8 ++++---- GPU/GLES/GPU_GLES.cpp | 8 ++++---- GPU/GLES/TextureCacheGLES.cpp | 4 ++-- GPU/GLES/TextureCacheGLES.h | 2 +- GPU/Vulkan/GPU_Vulkan.cpp | 9 ++++----- GPU/Vulkan/TextureCacheVulkan.cpp | 6 +++--- UI/DevScreens.cpp | 2 +- 13 files changed, 40 insertions(+), 42 deletions(-) diff --git a/GPU/Common/ShaderCommon.h b/GPU/Common/ShaderCommon.h index d15d666e0f..1a69e5c387 100644 --- a/GPU/Common/ShaderCommon.h +++ b/GPU/Common/ShaderCommon.h @@ -29,7 +29,7 @@ enum DebugShaderType { SHADER_TYPE_GEOMETRY = 2, SHADER_TYPE_VERTEXLOADER = 3, // Not really a shader, but might as well re-use this mechanism SHADER_TYPE_PIPELINE = 4, // Vulkan and DX12 combines a bunch of state into pipeline objects. Might as well make them inspectable. - SHADER_TYPE_DEPAL = 5, + SHADER_TYPE_TEXTURE = 5, SHADER_TYPE_SAMPLER = 6, // Not really a shader either. Need to rename this enum... }; diff --git a/GPU/Common/TextureCacheCommon.cpp b/GPU/Common/TextureCacheCommon.cpp index b237c3a97e..de6c840722 100644 --- a/GPU/Common/TextureCacheCommon.cpp +++ b/GPU/Common/TextureCacheCommon.cpp @@ -124,11 +124,11 @@ TextureCacheCommon::TextureCacheCommon(Draw::DrawContext *draw) replacer_.Init(); - depalShaderCache_ = new TextureShaderCache(draw); + textureShaderCache_ = new TextureShaderCache(draw); } TextureCacheCommon::~TextureCacheCommon() { - delete depalShaderCache_; + delete textureShaderCache_; FreeAlignedMemory(clutBufConverted_); FreeAlignedMemory(clutBufRaw_); @@ -1860,7 +1860,7 @@ bool CanDepalettize(GETextureFormat texFormat, GEBufferFormat bufferFormat) { } void TextureCacheCommon::ApplyTextureFramebuffer(VirtualFramebuffer *framebuffer, GETextureFormat texFormat, RasterChannel channel) { - TextureShader *depalShader = nullptr; + TextureShader *textureShader = nullptr; uint32_t clutMode = gstate.clutformat & 0xFFFFFF; bool depth = channel == RASTER_DEPTH; @@ -1886,7 +1886,7 @@ void TextureCacheCommon::ApplyTextureFramebuffer(VirtualFramebuffer *framebuffer const GEPaletteFormat clutFormat = gstate.getClutPaletteFormat(); // 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_, clutBufRaw_); + Draw::Texture *clutTexture = textureShaderCache_->GetClutTexture(clutFormat, clutHash_, clutBufRaw_); BindAsClutTexture(clutTexture); framebufferManager_->BindFramebufferAsColorTexture(0, framebuffer, BINDFBCOLOR_MAY_COPY_WITH_UV | BINDFBCOLOR_APPLY_TEX_OFFSET); @@ -1913,13 +1913,13 @@ void TextureCacheCommon::ApplyTextureFramebuffer(VirtualFramebuffer *framebuffer return; } - depalShader = depalShaderCache_->GetDepalettizeShader(clutMode, texFormat, depth ? GE_FORMAT_DEPTH16 : framebuffer->drawnFormat); + textureShader = textureShaderCache_->GetDepalettizeShader(clutMode, texFormat, depth ? GE_FORMAT_DEPTH16 : framebuffer->drawnFormat); gstate_c.SetUseShaderDepal(false); } - if (depalShader) { + if (textureShader) { const GEPaletteFormat clutFormat = gstate.getClutPaletteFormat(); - Draw::Texture *clutTexture = depalShaderCache_->GetClutTexture(clutFormat, clutHash_, clutBufRaw_); + Draw::Texture *clutTexture = textureShaderCache_->GetClutTexture(clutFormat, clutHash_, clutBufRaw_); Draw::Framebuffer *depalFBO = framebufferManager_->GetTempFBO(TempFBO::DEPAL, framebuffer->renderWidth, framebuffer->renderHeight); draw_->BindTexture(0, nullptr); draw_->BindTexture(1, nullptr); @@ -1931,11 +1931,11 @@ void TextureCacheCommon::ApplyTextureFramebuffer(VirtualFramebuffer *framebuffer draw_->BindFramebufferAsTexture(framebuffer->fbo, 0, depth ? Draw::FB_DEPTH_BIT : Draw::FB_COLOR_BIT, 0); draw_->BindTexture(1, clutTexture); - Draw::SamplerState *nearest = depalShaderCache_->GetSampler(); + Draw::SamplerState *nearest = textureShaderCache_->GetSampler(); draw_->BindSamplerStates(0, 1, &nearest); draw_->BindSamplerStates(1, 1, &nearest); - depalShaderCache_->ApplyShader(depalShader, + textureShaderCache_->ApplyShader(textureShader, framebuffer->bufferWidth, framebuffer->bufferHeight, framebuffer->renderWidth, framebuffer->renderHeight, gstate_c.vertBounds, gstate_c.curTextureXOffset, gstate_c.curTextureYOffset); @@ -1970,7 +1970,7 @@ void TextureCacheCommon::ApplyTextureFramebuffer(VirtualFramebuffer *framebuffer } void TextureCacheCommon::Clear(bool delete_them) { - depalShaderCache_->Clear(); + textureShaderCache_->Clear(); ForgetLastTexture(); for (TexCache::iterator iter = cache_.begin(); iter != cache_.end(); ++iter) { @@ -2412,5 +2412,5 @@ CheckAlphaResult TextureCacheCommon::CheckCLUTAlpha(const uint8_t *pixelData, GE } void TextureCacheCommon::StartFrame() { - depalShaderCache_->Decimate(); + textureShaderCache_->Decimate(); } diff --git a/GPU/Common/TextureCacheCommon.h b/GPU/Common/TextureCacheCommon.h index 8be81d3433..080e11a00b 100644 --- a/GPU/Common/TextureCacheCommon.h +++ b/GPU/Common/TextureCacheCommon.h @@ -291,7 +291,7 @@ public: void InvalidateAll(GPUInvalidationType type); void ClearNextFrame(); - TextureShaderCache *GetDepalShaderCache() { return depalShaderCache_; } + TextureShaderCache *GetTextureShaderCache() { return textureShaderCache_; } virtual void ForgetLastTexture() = 0; virtual void InvalidateLastTexture() = 0; @@ -403,7 +403,7 @@ protected: TextureReplacer replacer_; TextureScalerCommon scaler_; FramebufferManagerCommon *framebufferManager_; - TextureShaderCache *depalShaderCache_; + TextureShaderCache *textureShaderCache_; ShaderManagerCommon *shaderManager_; bool clearCacheNextFrame_ = false; diff --git a/GPU/Common/TextureShaderCommon.cpp b/GPU/Common/TextureShaderCommon.cpp index 77072565ea..defbeb1575 100644 --- a/GPU/Common/TextureShaderCommon.cpp +++ b/GPU/Common/TextureShaderCommon.cpp @@ -63,7 +63,7 @@ Draw::Texture *TextureShaderCache::GetClutTexture(GEPaletteFormat clutFormat, co int texturePixels = clutFormat == GE_CMODE_32BIT_ABGR8888 ? 256 : 512; - DepalTexture *tex = new DepalTexture(); + ClutTexture *tex = new ClutTexture(); Draw::TextureDesc desc{}; desc.width = texturePixels; @@ -250,7 +250,6 @@ std::string TextureShaderCache::DebugGetShaderString(std::string idstr, DebugSha } } -// TODO: Merge with DepalShaderCache? void TextureShaderCache::ApplyShader(TextureShader *shader, float bufferW, float bufferH, int renderW, int renderH, const KnownVertexBounds &bounds, u32 uoff, u32 voff) { Draw2DVertex verts[4] = { {-1, -1, 0, 0 }, diff --git a/GPU/Common/TextureShaderCommon.h b/GPU/Common/TextureShaderCommon.h index 628746b465..e2967ea89c 100644 --- a/GPU/Common/TextureShaderCommon.h +++ b/GPU/Common/TextureShaderCommon.h @@ -35,7 +35,7 @@ public: std::string code; }; -class DepalTexture { +class ClutTexture { public: Draw::Texture *texture; int lastFrame; @@ -71,5 +71,5 @@ private: Draw::SamplerState *nearestSampler_ = nullptr; std::map depalCache_; - std::map texCache_; + std::map texCache_; }; diff --git a/GPU/D3D11/GPU_D3D11.cpp b/GPU/D3D11/GPU_D3D11.cpp index ba41521fde..956d17fc85 100644 --- a/GPU/D3D11/GPU_D3D11.cpp +++ b/GPU/D3D11/GPU_D3D11.cpp @@ -332,8 +332,8 @@ std::vector GPU_D3D11::DebugGetShaderIDs(DebugShaderType type) { switch (type) { case SHADER_TYPE_VERTEXLOADER: return drawEngine_.DebugGetVertexLoaderIDs(); - case SHADER_TYPE_DEPAL: - return textureCache_->GetDepalShaderCache()->DebugGetShaderIDs(type); + case SHADER_TYPE_TEXTURE: + return textureCache_->GetTextureShaderCache()->DebugGetShaderIDs(type); default: return shaderManagerD3D11_->DebugGetShaderIDs(type); } @@ -343,8 +343,8 @@ std::string GPU_D3D11::DebugGetShaderString(std::string id, DebugShaderType type switch (type) { case SHADER_TYPE_VERTEXLOADER: return drawEngine_.DebugGetVertexLoaderString(id, stringType); - case SHADER_TYPE_DEPAL: - return textureCache_->GetDepalShaderCache()->DebugGetShaderString(id, type, stringType); + case SHADER_TYPE_TEXTURE: + return textureCache_->GetTextureShaderCache()->DebugGetShaderString(id, type, stringType); default: return shaderManagerD3D11_->DebugGetShaderString(id, type, stringType); } diff --git a/GPU/Directx9/GPU_DX9.cpp b/GPU/Directx9/GPU_DX9.cpp index b36cb34288..deaeeafb68 100644 --- a/GPU/Directx9/GPU_DX9.cpp +++ b/GPU/Directx9/GPU_DX9.cpp @@ -375,8 +375,8 @@ std::vector GPU_DX9::DebugGetShaderIDs(DebugShaderType type) { switch (type) { case SHADER_TYPE_VERTEXLOADER: return drawEngine_.DebugGetVertexLoaderIDs(); - case SHADER_TYPE_DEPAL: - return textureCache_->GetDepalShaderCache()->DebugGetShaderIDs(type); + case SHADER_TYPE_TEXTURE: + return textureCache_->GetTextureShaderCache()->DebugGetShaderIDs(type); default: return shaderManagerDX9_->DebugGetShaderIDs(type); } @@ -386,8 +386,8 @@ std::string GPU_DX9::DebugGetShaderString(std::string id, DebugShaderType type, switch (type) { case SHADER_TYPE_VERTEXLOADER: return drawEngine_.DebugGetVertexLoaderString(id, stringType); - case SHADER_TYPE_DEPAL: - return textureCache_->GetDepalShaderCache()->DebugGetShaderString(id, type, stringType); + case SHADER_TYPE_TEXTURE: + return textureCache_->GetTextureShaderCache()->DebugGetShaderString(id, type, stringType); default: return shaderManagerDX9_->DebugGetShaderString(id, type, stringType); } diff --git a/GPU/GLES/GPU_GLES.cpp b/GPU/GLES/GPU_GLES.cpp index f774e4bebd..1dd004aab8 100644 --- a/GPU/GLES/GPU_GLES.cpp +++ b/GPU/GLES/GPU_GLES.cpp @@ -453,8 +453,8 @@ std::vector GPU_GLES::DebugGetShaderIDs(DebugShaderType type) { switch (type) { case SHADER_TYPE_VERTEXLOADER: return drawEngine_.DebugGetVertexLoaderIDs(); - case SHADER_TYPE_DEPAL: - return textureCache_->GetDepalShaderCache()->DebugGetShaderIDs(type); + case SHADER_TYPE_TEXTURE: + return textureCache_->GetTextureShaderCache()->DebugGetShaderIDs(type); default: return shaderManagerGL_->DebugGetShaderIDs(type); } @@ -464,8 +464,8 @@ std::string GPU_GLES::DebugGetShaderString(std::string id, DebugShaderType type, switch (type) { case SHADER_TYPE_VERTEXLOADER: return drawEngine_.DebugGetVertexLoaderString(id, stringType); - case SHADER_TYPE_DEPAL: - return textureCache_->GetDepalShaderCache()->DebugGetShaderString(id, type, stringType); + case SHADER_TYPE_TEXTURE: + return textureCache_->GetTextureShaderCache()->DebugGetShaderString(id, type, stringType); default: return shaderManagerGL_->DebugGetShaderString(id, type, stringType); } diff --git a/GPU/GLES/TextureCacheGLES.cpp b/GPU/GLES/TextureCacheGLES.cpp index ddaad253bc..6fb19338d9 100644 --- a/GPU/GLES/TextureCacheGLES.cpp +++ b/GPU/GLES/TextureCacheGLES.cpp @@ -430,7 +430,7 @@ bool TextureCacheGLES::GetCurrentTextureDebug(GPUDebugBuffer &buffer, int level) } void TextureCacheGLES::DeviceLost() { - depalShaderCache_->DeviceLost(); + textureShaderCache_->DeviceLost(); Clear(false); draw_ = nullptr; render_ = nullptr; @@ -439,5 +439,5 @@ void TextureCacheGLES::DeviceLost() { void TextureCacheGLES::DeviceRestore(Draw::DrawContext *draw) { draw_ = draw; render_ = (GLRenderManager *)draw_->GetNativeObject(Draw::NativeObject::RENDER_MANAGER); - depalShaderCache_->DeviceRestore(draw); + textureShaderCache_->DeviceRestore(draw); } diff --git a/GPU/GLES/TextureCacheGLES.h b/GPU/GLES/TextureCacheGLES.h index b23af129f5..d192a2369a 100644 --- a/GPU/GLES/TextureCacheGLES.h +++ b/GPU/GLES/TextureCacheGLES.h @@ -42,7 +42,7 @@ public: void SetFramebufferManager(FramebufferManagerGLES *fbManager); void SetDepalShaderCache(TextureShaderCache *dpCache) { - depalShaderCache_ = dpCache; + textureShaderCache_ = dpCache; } void SetDrawEngine(DrawEngineGLES *td) { drawEngine_ = td; diff --git a/GPU/Vulkan/GPU_Vulkan.cpp b/GPU/Vulkan/GPU_Vulkan.cpp index 7d2dc8b5c0..adc0a9c127 100644 --- a/GPU/Vulkan/GPU_Vulkan.cpp +++ b/GPU/Vulkan/GPU_Vulkan.cpp @@ -604,9 +604,8 @@ std::vector GPU_Vulkan::DebugGetShaderIDs(DebugShaderType type) { return drawEngine_.DebugGetVertexLoaderIDs(); } else if (type == SHADER_TYPE_PIPELINE) { return pipelineManager_->DebugGetObjectIDs(type); - } else if (type == SHADER_TYPE_DEPAL) { - ///... - return std::vector(); + } else if (type == SHADER_TYPE_TEXTURE) { + return textureCache_->GetTextureShaderCache()->DebugGetShaderIDs(type); } else if (type == SHADER_TYPE_VERTEX || type == SHADER_TYPE_FRAGMENT) { return shaderManagerVulkan_->DebugGetShaderIDs(type); } else if (type == SHADER_TYPE_SAMPLER) { @@ -621,8 +620,8 @@ std::string GPU_Vulkan::DebugGetShaderString(std::string id, DebugShaderType typ return drawEngine_.DebugGetVertexLoaderString(id, stringType); } else if (type == SHADER_TYPE_PIPELINE) { return pipelineManager_->DebugGetObjectString(id, type, stringType); - } else if (type == SHADER_TYPE_DEPAL) { - return ""; + } else if (type == SHADER_TYPE_TEXTURE) { + return textureCache_->GetTextureShaderCache()->DebugGetShaderString(id, type, stringType); } else if (type == SHADER_TYPE_SAMPLER) { return textureCacheVulkan_->DebugGetSamplerString(id, stringType); } else if (type == SHADER_TYPE_VERTEX || type == SHADER_TYPE_FRAGMENT) { diff --git a/GPU/Vulkan/TextureCacheVulkan.cpp b/GPU/Vulkan/TextureCacheVulkan.cpp index 132c0e081a..6c15264b1f 100644 --- a/GPU/Vulkan/TextureCacheVulkan.cpp +++ b/GPU/Vulkan/TextureCacheVulkan.cpp @@ -200,7 +200,7 @@ void TextureCacheVulkan::SetFramebufferManager(FramebufferManagerVulkan *fbManag } void TextureCacheVulkan::DeviceLost() { - depalShaderCache_->DeviceLost(); + textureShaderCache_->DeviceLost(); VulkanContext *vulkan = draw_ ? (VulkanContext *)draw_->GetNativeObject(Draw::NativeObject::CONTEXT) : nullptr; @@ -227,7 +227,7 @@ void TextureCacheVulkan::DeviceRestore(Draw::DrawContext *draw) { _assert_(!allocator_); samplerCache_.DeviceRestore(vulkan); - depalShaderCache_->DeviceRestore(draw); + textureShaderCache_->DeviceRestore(draw); VkSamplerCreateInfo samp{ VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO }; samp.addressModeU = VK_SAMPLER_ADDRESS_MODE_REPEAT; @@ -320,7 +320,7 @@ void TextureCacheVulkan::StartFrame() { TextureCacheCommon::StartFrame(); InvalidateLastTexture(); - depalShaderCache_->Decimate(); + textureShaderCache_->Decimate(); timesInvalidatedAllThisFrame_ = 0; texelsScaledThisFrame_ = 0; diff --git a/UI/DevScreens.cpp b/UI/DevScreens.cpp index 1c938596ac..a804eb98f0 100644 --- a/UI/DevScreens.cpp +++ b/UI/DevScreens.cpp @@ -1151,7 +1151,7 @@ struct { DebugShaderType type; const char *name; } shaderTypes[] = { // { SHADER_TYPE_GEOMETRY, "Geometry" }, { SHADER_TYPE_VERTEXLOADER, "VertexLoader" }, { SHADER_TYPE_PIPELINE, "Pipeline" }, - { SHADER_TYPE_DEPAL, "Depal" }, + { SHADER_TYPE_TEXTURE, "Texture" }, { SHADER_TYPE_SAMPLER, "Sampler" }, };