VideoCommon/ShaderGenCommon: Convert helper functions over to fmt

A very trivial conversion, this simply converts calls to Write over to
WriteFmt and adjusts the formatting specifiers as necessary.

This also allows the const char* parameters to become std::string_view
instances, allowing for ease of use with other string types.
This commit is contained in:
Lioncash 2019-12-22 13:05:42 -05:00
parent 68706973d2
commit e3506ff4ef
1 changed files with 22 additions and 22 deletions

View File

@ -194,29 +194,29 @@ std::string GetDiskShaderCacheFileName(APIType api_type, const char* type, bool
bool include_host_config, bool include_api = true);
template <class T>
inline void DefineOutputMember(T& object, APIType api_type, const char* qualifier, const char* type,
const char* name, int var_index, const char* semantic = "",
int semantic_index = -1)
void DefineOutputMember(T& object, APIType api_type, std::string_view qualifier,
std::string_view type, std::string_view name, int var_index,
std::string_view semantic = {}, int semantic_index = -1)
{
object.Write("\t%s %s %s", qualifier, type, name);
object.WriteFmt("\t{} {} {}", qualifier, type, name);
if (var_index != -1)
object.Write("%d", var_index);
object.WriteFmt("{}", var_index);
if (api_type == APIType::D3D && strlen(semantic) > 0)
if (api_type == APIType::D3D && !semantic.empty())
{
if (semantic_index != -1)
object.Write(" : %s%d", semantic, semantic_index);
object.WriteFmt(" : {}{}", semantic, semantic_index);
else
object.Write(" : %s", semantic);
object.WriteFmt(" : {}", semantic);
}
object.Write(";\n");
object.WriteFmt(";\n");
}
template <class T>
inline void GenerateVSOutputMembers(T& object, APIType api_type, u32 texgens,
const ShaderHostConfig& host_config, const char* qualifier)
void GenerateVSOutputMembers(T& object, APIType api_type, u32 texgens,
const ShaderHostConfig& host_config, std::string_view qualifier)
{
DefineOutputMember(object, api_type, qualifier, "float4", "pos", -1, "SV_Position");
DefineOutputMember(object, api_type, qualifier, "float4", "colors_", 0, "COLOR", 0);
@ -244,29 +244,29 @@ inline void GenerateVSOutputMembers(T& object, APIType api_type, u32 texgens,
}
template <class T>
inline void AssignVSOutputMembers(T& object, const char* a, const char* b, u32 texgens,
void AssignVSOutputMembers(T& object, std::string_view a, std::string_view b, u32 texgens,
const ShaderHostConfig& host_config)
{
object.Write("\t%s.pos = %s.pos;\n", a, b);
object.Write("\t%s.colors_0 = %s.colors_0;\n", a, b);
object.Write("\t%s.colors_1 = %s.colors_1;\n", a, b);
object.WriteFmt("\t{}.pos = {}.pos;\n", a, b);
object.WriteFmt("\t{}.colors_0 = {}.colors_0;\n", a, b);
object.WriteFmt("\t{}.colors_1 = {}.colors_1;\n", a, b);
for (unsigned int i = 0; i < texgens; ++i)
object.Write("\t%s.tex%d = %s.tex%d;\n", a, i, b, i);
object.WriteFmt("\t{}.tex{} = {}.tex{};\n", a, i, b, i);
if (!host_config.fast_depth_calc)
object.Write("\t%s.clipPos = %s.clipPos;\n", a, b);
object.WriteFmt("\t{}.clipPos = {}.clipPos;\n", a, b);
if (host_config.per_pixel_lighting)
{
object.Write("\t%s.Normal = %s.Normal;\n", a, b);
object.Write("\t%s.WorldPos = %s.WorldPos;\n", a, b);
object.WriteFmt("\t{}.Normal = {}.Normal;\n", a, b);
object.WriteFmt("\t{}.WorldPos = {}.WorldPos;\n", a, b);
}
if (host_config.backend_geometry_shaders)
{
object.Write("\t%s.clipDist0 = %s.clipDist0;\n", a, b);
object.Write("\t%s.clipDist1 = %s.clipDist1;\n", a, b);
object.WriteFmt("\t{}.clipDist0 = {}.clipDist0;\n", a, b);
object.WriteFmt("\t{}.clipDist1 = {}.clipDist1;\n", a, b);
}
}