Merge pull request #10752 from tellowkrinkle/BetterShaderNames
VideoCommon: Better shader names
This commit is contained in:
commit
1faca4bfc7
|
@ -430,7 +430,8 @@ ShaderCache::CompileVertexUberShader(const UberShader::VertexShaderUid& uid) con
|
||||||
{
|
{
|
||||||
const ShaderCode source_code =
|
const ShaderCode source_code =
|
||||||
UberShader::GenVertexShader(m_api_type, m_host_config, uid.GetUidData());
|
UberShader::GenVertexShader(m_api_type, m_host_config, uid.GetUidData());
|
||||||
return g_renderer->CreateShaderFromSource(ShaderStage::Vertex, source_code.GetBuffer());
|
return g_renderer->CreateShaderFromSource(ShaderStage::Vertex, source_code.GetBuffer(),
|
||||||
|
fmt::to_string(*uid.GetUidData()));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<AbstractShader> ShaderCache::CompilePixelShader(const PixelShaderUid& uid) const
|
std::unique_ptr<AbstractShader> ShaderCache::CompilePixelShader(const PixelShaderUid& uid) const
|
||||||
|
@ -445,7 +446,8 @@ ShaderCache::CompilePixelUberShader(const UberShader::PixelShaderUid& uid) const
|
||||||
{
|
{
|
||||||
const ShaderCode source_code =
|
const ShaderCode source_code =
|
||||||
UberShader::GenPixelShader(m_api_type, m_host_config, uid.GetUidData());
|
UberShader::GenPixelShader(m_api_type, m_host_config, uid.GetUidData());
|
||||||
return g_renderer->CreateShaderFromSource(ShaderStage::Pixel, source_code.GetBuffer());
|
return g_renderer->CreateShaderFromSource(ShaderStage::Pixel, source_code.GetBuffer(),
|
||||||
|
fmt::to_string(*uid.GetUidData()));
|
||||||
}
|
}
|
||||||
|
|
||||||
const AbstractShader* ShaderCache::InsertVertexShader(const VertexShaderUid& uid,
|
const AbstractShader* ShaderCache::InsertVertexShader(const VertexShaderUid& uid,
|
||||||
|
@ -1339,15 +1341,17 @@ const AbstractPipeline* ShaderCache::GetTextureReinterpretPipeline(TextureFormat
|
||||||
return iiter.first->second.get();
|
return iiter.first->second.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
const AbstractShader* ShaderCache::GetTextureDecodingShader(TextureFormat format,
|
const AbstractShader*
|
||||||
TLUTFormat palette_format)
|
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),
|
||||||
auto iter = m_texture_decoding_shaders.find(key);
|
static_cast<u32>(palette_format.value_or(TLUTFormat::IA8)));
|
||||||
|
const auto iter = m_texture_decoding_shaders.find(key);
|
||||||
if (iter != m_texture_decoding_shaders.end())
|
if (iter != m_texture_decoding_shaders.end())
|
||||||
return iter->second.get();
|
return iter->second.get();
|
||||||
|
|
||||||
std::string shader_source =
|
const std::string shader_source =
|
||||||
TextureConversionShaderTiled::GenerateDecodingShader(format, palette_format, APIType::OpenGL);
|
TextureConversionShaderTiled::GenerateDecodingShader(format, palette_format, APIType::OpenGL);
|
||||||
if (shader_source.empty())
|
if (shader_source.empty())
|
||||||
{
|
{
|
||||||
|
@ -1355,16 +1359,20 @@ const AbstractShader* ShaderCache::GetTextureDecodingShader(TextureFormat format
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<AbstractShader> shader = g_renderer->CreateShaderFromSource(
|
const std::string name =
|
||||||
ShaderStage::Compute, shader_source,
|
palette_format.has_value() ?
|
||||||
fmt::format("Texture decoding compute shader: {}, {}", format, palette_format));
|
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)
|
if (!shader)
|
||||||
{
|
{
|
||||||
m_texture_decoding_shaders.emplace(key, nullptr);
|
m_texture_decoding_shaders.emplace(key, nullptr);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto iiter = m_texture_decoding_shaders.emplace(key, std::move(shader));
|
const auto iiter = m_texture_decoding_shaders.emplace(key, std::move(shader));
|
||||||
return iiter.first->second.get();
|
return iiter.first->second.get();
|
||||||
}
|
}
|
||||||
} // namespace VideoCommon
|
} // namespace VideoCommon
|
||||||
|
|
|
@ -110,7 +110,8 @@ public:
|
||||||
TextureFormat to_format);
|
TextureFormat to_format);
|
||||||
|
|
||||||
// Texture decoding compute shaders
|
// Texture decoding compute shaders
|
||||||
const AbstractShader* GetTextureDecodingShader(TextureFormat format, TLUTFormat palette_format);
|
const AbstractShader* GetTextureDecodingShader(TextureFormat format,
|
||||||
|
std::optional<TLUTFormat> palette_format);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static constexpr size_t NUM_PALETTE_CONVERSION_SHADERS = 3;
|
static constexpr size_t NUM_PALETTE_CONVERSION_SHADERS = 3;
|
||||||
|
|
|
@ -2809,7 +2809,8 @@ bool TextureCacheBase::DecodeTextureOnGPU(TCacheEntry* entry, u32 dst_level, con
|
||||||
if (!info)
|
if (!info)
|
||||||
return false;
|
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)
|
if (!shader)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|
|
@ -950,6 +950,7 @@ uint GetTiledTexelOffset(uint2 block_size, uint2 coords)
|
||||||
return buffer_pos;
|
return buffer_pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(HAS_PALETTE)
|
||||||
uint4 GetPaletteColor(uint index)
|
uint4 GetPaletteColor(uint index)
|
||||||
{
|
{
|
||||||
// Fetch and swap BE to LE.
|
// Fetch and swap BE to LE.
|
||||||
|
@ -994,6 +995,7 @@ float4 GetPaletteColorNormalized(uint index)
|
||||||
uint4 color = GetPaletteColor(index);
|
uint4 color = GetPaletteColor(index);
|
||||||
return float4(color) / 255.0;
|
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};
|
(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)
|
APIType api_type)
|
||||||
{
|
{
|
||||||
const DecodingShaderInfo* info = GetDecodingShaderInfo(format);
|
const DecodingShaderInfo* info = GetDecodingShaderInfo(format);
|
||||||
|
@ -1393,7 +1395,9 @@ std::string GenerateDecodingShader(TextureFormat format, TLUTFormat palette_form
|
||||||
return "";
|
return "";
|
||||||
|
|
||||||
std::ostringstream ss;
|
std::ostringstream ss;
|
||||||
switch (palette_format)
|
if (palette_format.has_value())
|
||||||
|
{
|
||||||
|
switch (*palette_format)
|
||||||
{
|
{
|
||||||
case TLUTFormat::IA8:
|
case TLUTFormat::IA8:
|
||||||
ss << "#define PALETTE_FORMAT_IA8 1\n";
|
ss << "#define PALETTE_FORMAT_IA8 1\n";
|
||||||
|
@ -1405,6 +1409,7 @@ std::string GenerateDecodingShader(TextureFormat format, TLUTFormat palette_form
|
||||||
ss << "#define PALETTE_FORMAT_RGB5A3 1\n";
|
ss << "#define PALETTE_FORMAT_RGB5A3 1\n";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ss << decoding_shader_header;
|
ss << decoding_shader_header;
|
||||||
ss << info->shader_body;
|
ss << info->shader_body;
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <optional>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
|
@ -41,7 +42,7 @@ const DecodingShaderInfo* GetDecodingShaderInfo(TextureFormat format);
|
||||||
std::pair<u32, u32> GetDispatchCount(const DecodingShaderInfo* info, u32 width, u32 height);
|
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.
|
// 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);
|
APIType api_type);
|
||||||
|
|
||||||
// Returns the GLSL string containing the palette conversion shader for the specified format.
|
// Returns the GLSL string containing the palette conversion shader for the specified format.
|
||||||
|
|
|
@ -66,8 +66,7 @@ ShaderCode GenPixelShader(APIType api_type, const ShaderHostConfig& host_config,
|
||||||
const u32 numTexgen = uid_data->num_texgens;
|
const u32 numTexgen = uid_data->num_texgens;
|
||||||
ShaderCode out;
|
ShaderCode out;
|
||||||
|
|
||||||
out.Write("// Pixel UberShader for {} texgens{}{}\n", numTexgen,
|
out.Write("// {}\n", *uid_data);
|
||||||
early_depth ? ", early-depth" : "", per_pixel_depth ? ", per-pixel depth" : "");
|
|
||||||
WriteBitfieldExtractHeader(out, api_type, host_config);
|
WriteBitfieldExtractHeader(out, api_type, host_config);
|
||||||
WritePixelShaderCommonHeader(out, api_type, host_config, bounding_box);
|
WritePixelShaderCommonHeader(out, api_type, host_config, bounding_box);
|
||||||
if (per_pixel_lighting)
|
if (per_pixel_lighting)
|
||||||
|
|
|
@ -34,3 +34,17 @@ void EnumeratePixelShaderUids(const std::function<void(const PixelShaderUid&)>&
|
||||||
void ClearUnusedPixelShaderUidBits(APIType api_type, const ShaderHostConfig& host_config,
|
void ClearUnusedPixelShaderUidBits(APIType api_type, const ShaderHostConfig& host_config,
|
||||||
PixelShaderUid* uid);
|
PixelShaderUid* uid);
|
||||||
} // namespace UberShader
|
} // namespace UberShader
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct fmt::formatter<UberShader::pixel_ubershader_uid_data>
|
||||||
|
{
|
||||||
|
constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); }
|
||||||
|
template <typename FormatContext>
|
||||||
|
auto format(const UberShader::pixel_ubershader_uid_data& uid, FormatContext& ctx) const
|
||||||
|
{
|
||||||
|
return fmt::format_to(ctx.out(), "Pixel UberShader for {} texgens{}{}{}", uid.num_texgens,
|
||||||
|
uid.early_depth ? ", early-depth" : "",
|
||||||
|
uid.per_pixel_depth ? ", per-pixel depth" : "",
|
||||||
|
uid.uint_output ? ", uint output" : "");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
|
@ -34,7 +34,7 @@ ShaderCode GenVertexShader(APIType api_type, const ShaderHostConfig& host_config
|
||||||
const u32 num_texgen = uid_data->num_texgens;
|
const u32 num_texgen = uid_data->num_texgens;
|
||||||
ShaderCode out;
|
ShaderCode out;
|
||||||
|
|
||||||
out.Write("// Vertex UberShader\n\n");
|
out.Write("// {}\n\n", *uid_data);
|
||||||
out.Write("{}", s_lighting_struct);
|
out.Write("{}", s_lighting_struct);
|
||||||
|
|
||||||
// uniforms
|
// uniforms
|
||||||
|
|
|
@ -25,3 +25,14 @@ ShaderCode GenVertexShader(APIType api_type, const ShaderHostConfig& host_config
|
||||||
const vertex_ubershader_uid_data* uid_data);
|
const vertex_ubershader_uid_data* uid_data);
|
||||||
void EnumerateVertexShaderUids(const std::function<void(const VertexShaderUid&)>& callback);
|
void EnumerateVertexShaderUids(const std::function<void(const VertexShaderUid&)>& callback);
|
||||||
} // namespace UberShader
|
} // namespace UberShader
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct fmt::formatter<UberShader::vertex_ubershader_uid_data>
|
||||||
|
{
|
||||||
|
constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); }
|
||||||
|
template <typename FormatContext>
|
||||||
|
auto format(const UberShader::vertex_ubershader_uid_data& uid, FormatContext& ctx) const
|
||||||
|
{
|
||||||
|
return fmt::format_to(ctx.out(), "Vertex UberShader for {} texgens", uid.num_texgens);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
Loading…
Reference in New Issue