diff --git a/Source/Core/VideoCommon/ShaderCache.cpp b/Source/Core/VideoCommon/ShaderCache.cpp index 984793d9d8..38ac252832 100644 --- a/Source/Core/VideoCommon/ShaderCache.cpp +++ b/Source/Core/VideoCommon/ShaderCache.cpp @@ -1339,10 +1339,12 @@ const AbstractPipeline* ShaderCache::GetTextureReinterpretPipeline(TextureFormat return iiter.first->second.get(); } -const AbstractShader* ShaderCache::GetTextureDecodingShader(TextureFormat format, - TLUTFormat palette_format) +const AbstractShader* +ShaderCache::GetTextureDecodingShader(TextureFormat format, + std::optional palette_format) { - const auto key = std::make_pair(static_cast(format), static_cast(palette_format)); + const auto key = std::make_pair(static_cast(format), + static_cast(palette_format.value_or(TLUTFormat::IA8))); auto iter = m_texture_decoding_shaders.find(key); if (iter != m_texture_decoding_shaders.end()) return iter->second.get(); @@ -1355,9 +1357,13 @@ const AbstractShader* ShaderCache::GetTextureDecodingShader(TextureFormat format return nullptr; } - std::unique_ptr shader = g_renderer->CreateShaderFromSource( - ShaderStage::Compute, shader_source, - fmt::format("Texture decoding compute shader: {}, {}", format, palette_format)); + std::string name = + palette_format.has_value() ? + fmt::format("Texture decoding compute shader: {}", format) : + fmt::format("Texture decoding compute shader: {}, {}", format, *palette_format); + + std::unique_ptr shader = + g_renderer->CreateShaderFromSource(ShaderStage::Compute, shader_source, name); if (!shader) { m_texture_decoding_shaders.emplace(key, nullptr); diff --git a/Source/Core/VideoCommon/ShaderCache.h b/Source/Core/VideoCommon/ShaderCache.h index c1b8f55b55..ee59fe9ae7 100644 --- a/Source/Core/VideoCommon/ShaderCache.h +++ b/Source/Core/VideoCommon/ShaderCache.h @@ -110,7 +110,8 @@ public: TextureFormat to_format); // Texture decoding compute shaders - const AbstractShader* GetTextureDecodingShader(TextureFormat format, TLUTFormat palette_format); + const AbstractShader* GetTextureDecodingShader(TextureFormat format, + std::optional palette_format); private: static constexpr size_t NUM_PALETTE_CONVERSION_SHADERS = 3; diff --git a/Source/Core/VideoCommon/TextureCacheBase.cpp b/Source/Core/VideoCommon/TextureCacheBase.cpp index dc08fd90bc..0ed5ffe014 100644 --- a/Source/Core/VideoCommon/TextureCacheBase.cpp +++ b/Source/Core/VideoCommon/TextureCacheBase.cpp @@ -2809,7 +2809,8 @@ bool TextureCacheBase::DecodeTextureOnGPU(TCacheEntry* entry, u32 dst_level, con if (!info) return false; - const AbstractShader* shader = g_shader_cache->GetTextureDecodingShader(format, palette_format); + const AbstractShader* shader = g_shader_cache->GetTextureDecodingShader( + format, info->palette_size != 0 ? std::make_optional(palette_format) : std::nullopt); if (!shader) return false; diff --git a/Source/Core/VideoCommon/TextureConversionShader.cpp b/Source/Core/VideoCommon/TextureConversionShader.cpp index 1b9183846f..19f2a384f0 100644 --- a/Source/Core/VideoCommon/TextureConversionShader.cpp +++ b/Source/Core/VideoCommon/TextureConversionShader.cpp @@ -950,6 +950,7 @@ uint GetTiledTexelOffset(uint2 block_size, uint2 coords) return buffer_pos; } +#if defined(HAS_PALETTE) uint4 GetPaletteColor(uint index) { // Fetch and swap BE to LE. @@ -994,6 +995,7 @@ float4 GetPaletteColorNormalized(uint index) uint4 color = GetPaletteColor(index); return float4(color) / 255.0; } +#endif // defined(HAS_PALETTE) )"; @@ -1385,7 +1387,7 @@ std::pair GetDispatchCount(const DecodingShaderInfo* info, u32 width, (height + (info->group_size_y - 1)) / info->group_size_y}; } -std::string GenerateDecodingShader(TextureFormat format, TLUTFormat palette_format, +std::string GenerateDecodingShader(TextureFormat format, std::optional palette_format, APIType api_type) { const DecodingShaderInfo* info = GetDecodingShaderInfo(format); @@ -1393,17 +1395,20 @@ std::string GenerateDecodingShader(TextureFormat format, TLUTFormat palette_form return ""; std::ostringstream ss; - switch (palette_format) + if (palette_format.has_value()) { - case TLUTFormat::IA8: - ss << "#define PALETTE_FORMAT_IA8 1\n"; - break; - case TLUTFormat::RGB565: - ss << "#define PALETTE_FORMAT_RGB565 1\n"; - break; - case TLUTFormat::RGB5A3: - ss << "#define PALETTE_FORMAT_RGB5A3 1\n"; - break; + switch (*palette_format) + { + case TLUTFormat::IA8: + ss << "#define PALETTE_FORMAT_IA8 1\n"; + break; + case TLUTFormat::RGB565: + ss << "#define PALETTE_FORMAT_RGB565 1\n"; + break; + case TLUTFormat::RGB5A3: + ss << "#define PALETTE_FORMAT_RGB5A3 1\n"; + break; + } } ss << decoding_shader_header; diff --git a/Source/Core/VideoCommon/TextureConversionShader.h b/Source/Core/VideoCommon/TextureConversionShader.h index 31230da9ac..49dded02ae 100644 --- a/Source/Core/VideoCommon/TextureConversionShader.h +++ b/Source/Core/VideoCommon/TextureConversionShader.h @@ -3,6 +3,7 @@ #pragma once +#include #include #include @@ -41,7 +42,7 @@ const DecodingShaderInfo* GetDecodingShaderInfo(TextureFormat format); std::pair GetDispatchCount(const DecodingShaderInfo* info, u32 width, u32 height); // Returns the GLSL string containing the texture decoding shader for the specified format. -std::string GenerateDecodingShader(TextureFormat format, TLUTFormat palette_format, +std::string GenerateDecodingShader(TextureFormat format, std::optional palette_format, APIType api_type); // Returns the GLSL string containing the palette conversion shader for the specified format.