VideoCommon: Reduce duplicates of non-palette-requiring texture decode shaders
This commit is contained in:
parent
70bf89fa59
commit
23c1721fbd
|
@ -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<TLUTFormat> palette_format)
|
||||
{
|
||||
const auto key = std::make_pair(static_cast<u32>(format), static_cast<u32>(palette_format));
|
||||
const auto key = std::make_pair(static_cast<u32>(format),
|
||||
static_cast<u32>(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<AbstractShader> 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<AbstractShader> shader =
|
||||
g_renderer->CreateShaderFromSource(ShaderStage::Compute, shader_source, name);
|
||||
if (!shader)
|
||||
{
|
||||
m_texture_decoding_shaders.emplace(key, nullptr);
|
||||
|
|
|
@ -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<TLUTFormat> palette_format);
|
||||
|
||||
private:
|
||||
static constexpr size_t NUM_PALETTE_CONVERSION_SHADERS = 3;
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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<u32, u32> 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<TLUTFormat> 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;
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
|
@ -41,7 +42,7 @@ const DecodingShaderInfo* GetDecodingShaderInfo(TextureFormat format);
|
|||
std::pair<u32, u32> 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<TLUTFormat> palette_format,
|
||||
APIType api_type);
|
||||
|
||||
// Returns the GLSL string containing the palette conversion shader for the specified format.
|
||||
|
|
Loading…
Reference in New Issue