Merge pull request #8487 from lioncash/video-fmt

VideoCommon: Make use of fmt outside of shader generators
This commit is contained in:
Anthony 2019-11-28 15:03:23 -08:00 committed by GitHub
commit 4a0611df54
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 201 additions and 182 deletions

View File

@ -8,9 +8,10 @@
#include <cstring> #include <cstring>
#include <string> #include <string>
#include <fmt/format.h>
#include "Common/CommonTypes.h"
#include "Common/Logging/Log.h" #include "Common/Logging/Log.h"
#include "Common/StringUtil.h"
#include "Common/Thread.h"
#include "Core/ConfigManager.h" #include "Core/ConfigManager.h"
#include "Core/CoreTiming.h" #include "Core/CoreTiming.h"
#include "Core/FifoPlayer/FifoPlayer.h" #include "Core/FifoPlayer/FifoPlayer.h"
@ -921,19 +922,19 @@ void GetBPRegInfo(const u8* data, std::string* name, std::string* desc)
const char* logicmodes[] = {"0", "s & d", "s & ~d", "s", "~s & d", "d", const char* logicmodes[] = {"0", "s & d", "s & ~d", "s", "~s & d", "d",
"s ^ d", "s | d", "~(s | d)", "~(s ^ d)", "~d", "s | ~d", "s ^ d", "s | d", "~(s | d)", "~(s ^ d)", "~d", "s | ~d",
"~s", "~s | d", "~(s & d)", "1"}; "~s", "~s | d", "~(s & d)", "1"};
*desc = StringFromFormat( *desc =
"Enable: %s\n" fmt::format("Enable: {}\n"
"Logic ops: %s\n" "Logic ops: {}\n"
"Dither: %s\n" "Dither: {}\n"
"Color write: %s\n" "Color write: {}\n"
"Alpha write: %s\n" "Alpha write: {}\n"
"Dest factor: %s\n" "Dest factor: {}\n"
"Source factor: %s\n" "Source factor: {}\n"
"Subtract: %s\n" "Subtract: {}\n"
"Logic mode: %s\n", "Logic mode: {}\n",
no_yes[mode.blendenable], no_yes[mode.logicopenable], no_yes[mode.dither], no_yes[mode.blendenable], no_yes[mode.logicopenable], no_yes[mode.dither],
no_yes[mode.colorupdate], no_yes[mode.alphaupdate], dstfactors[mode.dstfactor], no_yes[mode.colorupdate], no_yes[mode.alphaupdate], dstfactors[mode.dstfactor],
srcfactors[mode.srcfactor], no_yes[mode.subtract], logicmodes[mode.logicmode]); srcfactors[mode.srcfactor], no_yes[mode.subtract], logicmodes[mode.logicmode]);
} }
break; break;
@ -952,11 +953,11 @@ void GetBPRegInfo(const u8* data, std::string* name, std::string* desc)
const char* zformats[] = { const char* zformats[] = {
"linear", "compressed (near)", "compressed (mid)", "compressed (far)", "linear", "compressed (near)", "compressed (mid)", "compressed (far)",
"inv linear", "compressed (inv near)", "compressed (inv mid)", "compressed (inv far)"}; "inv linear", "compressed (inv near)", "compressed (inv mid)", "compressed (inv far)"};
*desc = StringFromFormat("EFB pixel format: %s\n" *desc = fmt::format("EFB pixel format: {}\n"
"Depth format: %s\n" "Depth format: {}\n"
"Early depth test: %s\n", "Early depth test: {}\n",
pixel_formats[config.pixel_format], zformats[config.zformat], pixel_formats[config.pixel_format], zformats[config.zformat],
no_yes[config.early_ztest]); no_yes[config.early_ztest]);
} }
break; break;
@ -990,7 +991,7 @@ void GetBPRegInfo(const u8* data, std::string* name, std::string* desc)
SetRegName(BPMEM_EFB_TL); SetRegName(BPMEM_EFB_TL);
X10Y10 left_top; X10Y10 left_top;
left_top.hex = cmddata; left_top.hex = cmddata;
*desc = StringFromFormat("Left: %d\nTop: %d", left_top.x, left_top.y); *desc = fmt::format("Left: {}\nTop: {}", left_top.x, left_top.y);
} }
break; break;
@ -1000,13 +1001,13 @@ void GetBPRegInfo(const u8* data, std::string* name, std::string* desc)
SetRegName(BPMEM_EFB_BR); SetRegName(BPMEM_EFB_BR);
X10Y10 width_height; X10Y10 width_height;
width_height.hex = cmddata; width_height.hex = cmddata;
*desc = StringFromFormat("Width: %d\nHeight: %d", width_height.x + 1, width_height.y + 1); *desc = fmt::format("Width: {}\nHeight: {}", width_height.x + 1, width_height.y + 1);
} }
break; break;
case BPMEM_EFB_ADDR: // 0x4B case BPMEM_EFB_ADDR: // 0x4B
SetRegName(BPMEM_EFB_ADDR); SetRegName(BPMEM_EFB_ADDR);
*desc = StringFromFormat("Target address (32 byte aligned): 0x%06X", cmddata << 5); *desc = fmt::format("Target address (32 byte aligned): 0x{:06X}", cmddata << 5);
break; break;
case BPMEM_MIPMAP_STRIDE: // 0x4D case BPMEM_MIPMAP_STRIDE: // 0x4D
@ -1016,24 +1017,23 @@ void GetBPRegInfo(const u8* data, std::string* name, std::string* desc)
case BPMEM_COPYYSCALE: // 0x4E case BPMEM_COPYYSCALE: // 0x4E
SetRegName(BPMEM_COPYYSCALE); SetRegName(BPMEM_COPYYSCALE);
*desc = StringFromFormat("Scaling factor (XFB copy only): 0x%X (%f or inverted %f)", cmddata, *desc = fmt::format("Scaling factor (XFB copy only): 0x{:X} ({} or inverted {})", cmddata,
(float)cmddata / 256.f, 256.f / (float)cmddata); static_cast<float>(cmddata) / 256.f, 256.f / static_cast<float>(cmddata));
break; break;
case BPMEM_CLEAR_AR: // 0x4F case BPMEM_CLEAR_AR: // 0x4F
SetRegName(BPMEM_CLEAR_AR); SetRegName(BPMEM_CLEAR_AR);
*desc = StringFromFormat("Alpha: 0x%02X\nRed: 0x%02X", (cmddata & 0xFF00) >> 8, cmddata & 0xFF); *desc = fmt::format("Alpha: 0x{:02X}\nRed: 0x{:02X}", (cmddata & 0xFF00) >> 8, cmddata & 0xFF);
break; break;
case BPMEM_CLEAR_GB: // 0x50 case BPMEM_CLEAR_GB: // 0x50
SetRegName(BPMEM_CLEAR_GB); SetRegName(BPMEM_CLEAR_GB);
*desc = *desc = fmt::format("Green: 0x{:02X}\nBlue: 0x{:02X}", (cmddata & 0xFF00) >> 8, cmddata & 0xFF);
StringFromFormat("Green: 0x%02X\nBlue: 0x%02X", (cmddata & 0xFF00) >> 8, cmddata & 0xFF);
break; break;
case BPMEM_CLEAR_Z: // 0x51 case BPMEM_CLEAR_Z: // 0x51
SetRegName(BPMEM_CLEAR_Z); SetRegName(BPMEM_CLEAR_Z);
*desc = StringFromFormat("Z value: 0x%06X", cmddata); *desc = fmt::format("Z value: 0x{:06X}", cmddata);
break; break;
case BPMEM_TRIGGER_EFB_COPY: // 0x52 case BPMEM_TRIGGER_EFB_COPY: // 0x52
@ -1041,18 +1041,18 @@ void GetBPRegInfo(const u8* data, std::string* name, std::string* desc)
SetRegName(BPMEM_TRIGGER_EFB_COPY); SetRegName(BPMEM_TRIGGER_EFB_COPY);
UPE_Copy copy; UPE_Copy copy;
copy.Hex = cmddata; copy.Hex = cmddata;
*desc = StringFromFormat( *desc = fmt::format(
"Clamping: %s\n" "Clamping: {}\n"
"Converting from RGB to YUV: %s\n" "Converting from RGB to YUV: {}\n"
"Target pixel format: 0x%X\n" "Target pixel format: 0x{:X}\n"
"Gamma correction: %s\n" "Gamma correction: {}\n"
"Mipmap filter: %s\n" "Mipmap filter: {}\n"
"Vertical scaling: %s\n" "Vertical scaling: {}\n"
"Clear: %s\n" "Clear: {}\n"
"Frame to field: 0x%01X\n" "Frame to field: 0x{:01X}\n"
"Copy to XFB: %s\n" "Copy to XFB: {}\n"
"Intensity format: %s\n" "Intensity format: {}\n"
"Automatic color conversion: %s", "Automatic color conversion: {}",
(copy.clamp_top && copy.clamp_bottom) ? (copy.clamp_top && copy.clamp_bottom) ?
"Top and Bottom" : "Top and Bottom" :
(copy.clamp_top) ? "Top only" : (copy.clamp_bottom) ? "Bottom only" : "None", (copy.clamp_top) ? "Top only" : (copy.clamp_bottom) ? "Bottom only" : "None",
@ -1061,7 +1061,7 @@ void GetBPRegInfo(const u8* data, std::string* name, std::string* desc)
"1.0" : "1.0" :
(copy.gamma == 1) ? "1.7" : (copy.gamma == 2) ? "2.2" : "Invalid value 0x3?", (copy.gamma == 1) ? "1.7" : (copy.gamma == 2) ? "2.2" : "Invalid value 0x3?",
no_yes[copy.half_scale], no_yes[copy.scale_invert], no_yes[copy.clear], no_yes[copy.half_scale], no_yes[copy.scale_invert], no_yes[copy.clear],
(u32)copy.frame_to_field, no_yes[copy.copy_to_xfb], no_yes[copy.intensity_fmt], static_cast<u32>(copy.frame_to_field), no_yes[copy.copy_to_xfb], no_yes[copy.intensity_fmt],
no_yes[copy.auto_conv]); no_yes[copy.auto_conv]);
} }
break; break;
@ -1181,11 +1181,11 @@ void GetBPRegInfo(const u8* data, std::string* name, std::string* desc)
(cmd < BPMEM_TX_SETIMAGE0_4) ? cmd - BPMEM_TX_SETIMAGE0 : cmd - BPMEM_TX_SETIMAGE0_4 + 4; (cmd < BPMEM_TX_SETIMAGE0_4) ? cmd - BPMEM_TX_SETIMAGE0 : cmd - BPMEM_TX_SETIMAGE0_4 + 4;
TexImage0 teximg; TexImage0 teximg;
teximg.hex = cmddata; teximg.hex = cmddata;
*desc = StringFromFormat("Texture Unit: %i\n" *desc = fmt::format("Texture Unit: {}\n"
"Width: %i\n" "Width: {}\n"
"Height: %i\n" "Height: {}\n"
"Format: %x\n", "Format: {:x}\n",
texnum, teximg.width + 1, teximg.height + 1, teximg.format); texnum, teximg.width + 1, teximg.height + 1, teximg.format);
} }
break; break;
@ -1203,13 +1203,13 @@ void GetBPRegInfo(const u8* data, std::string* name, std::string* desc)
(cmd < BPMEM_TX_SETIMAGE1_4) ? cmd - BPMEM_TX_SETIMAGE1 : cmd - BPMEM_TX_SETIMAGE1_4 + 4; (cmd < BPMEM_TX_SETIMAGE1_4) ? cmd - BPMEM_TX_SETIMAGE1 : cmd - BPMEM_TX_SETIMAGE1_4 + 4;
TexImage1 teximg; TexImage1 teximg;
teximg.hex = cmddata; teximg.hex = cmddata;
*desc = StringFromFormat("Texture Unit: %i\n" *desc = fmt::format("Texture Unit: {}\n"
"Even TMEM Offset: %x\n" "Even TMEM Offset: {:x}\n"
"Even TMEM Width: %i\n" "Even TMEM Width: {}\n"
"Even TMEM Height: %i\n" "Even TMEM Height: {}\n"
"Cache is manually managed: %s\n", "Cache is manually managed: {}\n",
texnum, teximg.tmem_even, teximg.cache_width, teximg.cache_height, texnum, teximg.tmem_even, teximg.cache_width, teximg.cache_height,
no_yes[teximg.image_type]); no_yes[teximg.image_type]);
} }
break; break;
@ -1227,11 +1227,11 @@ void GetBPRegInfo(const u8* data, std::string* name, std::string* desc)
(cmd < BPMEM_TX_SETIMAGE2_4) ? cmd - BPMEM_TX_SETIMAGE2 : cmd - BPMEM_TX_SETIMAGE2_4 + 4; (cmd < BPMEM_TX_SETIMAGE2_4) ? cmd - BPMEM_TX_SETIMAGE2 : cmd - BPMEM_TX_SETIMAGE2_4 + 4;
TexImage2 teximg; TexImage2 teximg;
teximg.hex = cmddata; teximg.hex = cmddata;
*desc = StringFromFormat("Texture Unit: %i\n" *desc = fmt::format("Texture Unit: {}\n"
"Odd TMEM Offset: %x\n" "Odd TMEM Offset: {:x}\n"
"Odd TMEM Width: %i\n" "Odd TMEM Width: {}\n"
"Odd TMEM Height: %i\n", "Odd TMEM Height: {}\n",
texnum, teximg.tmem_odd, teximg.cache_width, teximg.cache_height); texnum, teximg.tmem_odd, teximg.cache_width, teximg.cache_height);
} }
break; break;
@ -1249,8 +1249,8 @@ void GetBPRegInfo(const u8* data, std::string* name, std::string* desc)
(cmd < BPMEM_TX_SETIMAGE3_4) ? cmd - BPMEM_TX_SETIMAGE3 : cmd - BPMEM_TX_SETIMAGE3_4 + 4; (cmd < BPMEM_TX_SETIMAGE3_4) ? cmd - BPMEM_TX_SETIMAGE3 : cmd - BPMEM_TX_SETIMAGE3_4 + 4;
TexImage3 teximg; TexImage3 teximg;
teximg.hex = cmddata; teximg.hex = cmddata;
*desc = StringFromFormat("Texture %i source address (32 byte aligned): 0x%06X", texnum, *desc = fmt::format("Texture {} source address (32 byte aligned): 0x{:06X}", texnum,
teximg.image_base << 5); teximg.image_base << 5);
} }
break; break;
@ -1293,19 +1293,19 @@ void GetBPRegInfo(const u8* data, std::string* name, std::string* desc)
const char* tevop[] = {"add", "sub"}; const char* tevop[] = {"add", "sub"};
const char* tevscale[] = {"1", "2", "4", "0.5"}; const char* tevscale[] = {"1", "2", "4", "0.5"};
const char* tevout[] = {"prev.rgb", "c0.rgb", "c1.rgb", "c2.rgb"}; const char* tevout[] = {"prev.rgb", "c0.rgb", "c1.rgb", "c2.rgb"};
*desc = StringFromFormat("Tev stage: %d\n" *desc = fmt::format("Tev stage: {}\n"
"a: %s\n" "a: {}\n"
"b: %s\n" "b: {}\n"
"c: %s\n" "c: {}\n"
"d: %s\n" "d: {}\n"
"Bias: %s\n" "Bias: {}\n"
"Op: %s\n" "Op: {}\n"
"Clamp: %s\n" "Clamp: {}\n"
"Scale factor: %s\n" "Scale factor: {}\n"
"Dest: %s\n", "Dest: {}\n",
(data[0] - BPMEM_TEV_COLOR_ENV) / 2, tevin[cc.a], tevin[cc.b], (data[0] - BPMEM_TEV_COLOR_ENV) / 2, tevin[cc.a], tevin[cc.b], tevin[cc.c],
tevin[cc.c], tevin[cc.d], tevbias[cc.bias], tevop[cc.op], tevin[cc.d], tevbias[cc.bias], tevop[cc.op], no_yes[cc.clamp],
no_yes[cc.clamp], tevscale[cc.shift], tevout[cc.dest]); tevscale[cc.shift], tevout[cc.dest]);
break; break;
} }
@ -1336,22 +1336,21 @@ void GetBPRegInfo(const u8* data, std::string* name, std::string* desc)
const char* tevop[] = {"add", "sub"}; const char* tevop[] = {"add", "sub"};
const char* tevscale[] = {"1", "2", "4", "0.5"}; const char* tevscale[] = {"1", "2", "4", "0.5"};
const char* tevout[] = {"prev", "c0", "c1", "c2"}; const char* tevout[] = {"prev", "c0", "c1", "c2"};
*desc = *desc = fmt::format("Tev stage: {}\n"
StringFromFormat("Tev stage: %d\n" "a: {}\n"
"a: %s\n" "b: {}\n"
"b: %s\n" "c: {}\n"
"c: %s\n" "d: {}\n"
"d: %s\n" "Bias: {}\n"
"Bias: %s\n" "Op: {}\n"
"Op: %s\n" "Clamp: {}\n"
"Clamp: %s\n" "Scale factor: {}\n"
"Scale factor: %s\n" "Dest: {}\n"
"Dest: %s\n" "Ras sel: {}\n"
"Ras sel: %d\n" "Tex sel: {}\n",
"Tex sel: %d\n", (data[0] - BPMEM_TEV_ALPHA_ENV) / 2, tevin[ac.a], tevin[ac.b], tevin[ac.c],
(data[0] - BPMEM_TEV_ALPHA_ENV) / 2, tevin[ac.a], tevin[ac.b], tevin[ac.c], tevin[ac.d], tevbias[ac.bias], tevop[ac.op], no_yes[ac.clamp],
tevin[ac.d], tevbias[ac.bias], tevop[ac.op], no_yes[ac.clamp], tevscale[ac.shift], tevout[ac.dest], ac.rswap.Value(), ac.tswap.Value());
tevscale[ac.shift], tevout[ac.dest], ac.rswap.Value(), ac.tswap.Value());
break; break;
} }
@ -1414,11 +1413,11 @@ void GetBPRegInfo(const u8* data, std::string* name, std::string* desc)
const char* functions[] = {"NEVER", "LESS", "EQUAL", "LEQUAL", const char* functions[] = {"NEVER", "LESS", "EQUAL", "LEQUAL",
"GREATER", "NEQUAL", "GEQUAL", "ALWAYS"}; "GREATER", "NEQUAL", "GEQUAL", "ALWAYS"};
const char* logic[] = {"AND", "OR", "XOR", "XNOR"}; const char* logic[] = {"AND", "OR", "XOR", "XNOR"};
*desc = StringFromFormat("Test 1: %s (ref: %#02x)\n" *desc = fmt::format("Test 1: {} (ref: 0x{:02x})\n"
"Test 2: %s (ref: %#02x)\n" "Test 2: {} (ref: 0x{:02x})\n"
"Logic: %s\n", "Logic: {}\n",
functions[test.comp0], (int)test.ref0, functions[test.comp1], functions[test.comp0], test.ref0.Value(), functions[test.comp1],
(int)test.ref1, logic[test.logic]); test.ref1.Value(), logic[test.logic]);
break; break;
} }

View File

@ -132,6 +132,7 @@ target_link_libraries(videocommon
PUBLIC PUBLIC
core core
PRIVATE PRIVATE
fmt::fmt
png png
xxhash xxhash
imgui imgui

View File

@ -9,6 +9,8 @@
#include <sstream> #include <sstream>
#include <string> #include <string>
#include <fmt/format.h>
extern "C" { extern "C" {
#include <libavcodec/avcodec.h> #include <libavcodec/avcodec.h>
#include <libavformat/avformat.h> #include <libavformat/avformat.h>
@ -232,9 +234,7 @@ bool FrameDump::CreateVideoFile()
return false; return false;
} }
OSD::AddMessage( OSD::AddMessage(fmt::format("Dumping Frames to \"{}\" ({}x{})", dump_path, s_width, s_height));
StringFromFormat("Dumping Frames to \"%s\" (%dx%d)", dump_path.c_str(), s_width, s_height));
return true; return true;
} }

View File

@ -5,22 +5,22 @@
#include "VideoCommon/HiresTextures.h" #include "VideoCommon/HiresTextures.h"
#include <algorithm> #include <algorithm>
#include <cinttypes>
#include <cstring>
#include <memory> #include <memory>
#include <mutex> #include <mutex>
#include <string> #include <string>
#include <string_view>
#include <thread> #include <thread>
#include <unordered_map> #include <unordered_map>
#include <utility> #include <utility>
#include <vector> #include <vector>
#include <xxhash.h> #include <xxhash.h>
#include <fmt/format.h>
#include "Common/File.h" #include "Common/File.h"
#include "Common/FileSearch.h" #include "Common/FileSearch.h"
#include "Common/FileUtil.h" #include "Common/FileUtil.h"
#include "Common/Flag.h" #include "Common/Flag.h"
#include "Common/Hash.h"
#include "Common/Image.h" #include "Common/Image.h"
#include "Common/Logging/Log.h" #include "Common/Logging/Log.h"
#include "Common/MemoryUtil.h" #include "Common/MemoryUtil.h"
@ -39,6 +39,8 @@ struct DiskTexture
bool has_arbitrary_mipmaps; bool has_arbitrary_mipmaps;
}; };
constexpr std::string_view s_format_prefix{"tex1_"};
static std::unordered_map<std::string, DiskTexture> s_textureMap; static std::unordered_map<std::string, DiskTexture> s_textureMap;
static std::unordered_map<std::string, std::shared_ptr<HiresTexture>> s_textureCache; static std::unordered_map<std::string, std::shared_ptr<HiresTexture>> s_textureCache;
static std::mutex s_textureCacheMutex; static std::mutex s_textureCacheMutex;
@ -46,8 +48,6 @@ static Common::Flag s_textureCacheAbortLoading;
static std::thread s_prefetcher; static std::thread s_prefetcher;
static const std::string s_format_prefix = "tex1_";
void HiresTexture::Init() void HiresTexture::Init()
{ {
Update(); Update();
@ -135,12 +135,13 @@ void HiresTexture::Prefetch()
Common::SetCurrentThreadName("Prefetcher"); Common::SetCurrentThreadName("Prefetcher");
size_t size_sum = 0; size_t size_sum = 0;
size_t sys_mem = Common::MemPhysical(); const size_t sys_mem = Common::MemPhysical();
size_t recommended_min_mem = 2 * size_t(1024 * 1024 * 1024); const size_t recommended_min_mem = 2 * size_t(1024 * 1024 * 1024);
// keep 2GB memory for system stability if system RAM is 4GB+ - use half of memory in other cases // keep 2GB memory for system stability if system RAM is 4GB+ - use half of memory in other cases
size_t max_mem = const size_t max_mem =
(sys_mem / 2 < recommended_min_mem) ? (sys_mem / 2) : (sys_mem - recommended_min_mem); (sys_mem / 2 < recommended_min_mem) ? (sys_mem / 2) : (sys_mem - recommended_min_mem);
u32 starttime = Common::Timer::GetTimeMs();
const u32 start_time = Common::Timer::GetTimeMs();
for (const auto& entry : s_textureMap) for (const auto& entry : s_textureMap)
{ {
const std::string& base_filename = entry.first; const std::string& base_filename = entry.first;
@ -180,16 +181,17 @@ void HiresTexture::Prefetch()
Config::SetCurrent(Config::GFX_HIRES_TEXTURES, false); Config::SetCurrent(Config::GFX_HIRES_TEXTURES, false);
OSD::AddMessage( OSD::AddMessage(
StringFromFormat( fmt::format(
"Custom Textures prefetching after %.1f MB aborted, not enough RAM available", "Custom Textures prefetching after {:.1f} MB aborted, not enough RAM available",
size_sum / (1024.0 * 1024.0)), size_sum / (1024.0 * 1024.0)),
10000); 10000);
return; return;
} }
} }
u32 stoptime = Common::Timer::GetTimeMs();
OSD::AddMessage(StringFromFormat("Custom Textures loaded, %.1f MB in %.1f s", const u32 stop_time = Common::Timer::GetTimeMs();
size_sum / (1024.0 * 1024.0), (stoptime - starttime) / 1000.0), OSD::AddMessage(fmt::format("Custom Textures loaded, {:.1f} MB in {:.1f}s",
size_sum / (1024.0 * 1024.0), (stop_time - start_time) / 1000.0),
10000); 10000);
} }
@ -244,22 +246,26 @@ std::string HiresTexture::GenBaseName(const u8* texture, size_t texture_size, co
tlut += 2 * min; tlut += 2 * min;
} }
u64 tex_hash = XXH64(texture, texture_size, 0); const u64 tex_hash = XXH64(texture, texture_size, 0);
u64 tlut_hash = tlut_size ? XXH64(tlut, tlut_size, 0) : 0; const u64 tlut_hash = tlut_size ? XXH64(tlut, tlut_size, 0) : 0;
std::string basename = s_format_prefix + StringFromFormat("%dx%d%s_%016" PRIx64, width, height, const std::string base_name = fmt::format("{}{}x{}{}_{:016x}", s_format_prefix, width, height,
has_mipmaps ? "_m" : "", tex_hash); has_mipmaps ? "_m" : "", tex_hash);
std::string tlutname = tlut_size ? StringFromFormat("_%016" PRIx64, tlut_hash) : ""; const std::string tlut_name = tlut_size ? fmt::format("_{:016x}", tlut_hash) : "";
std::string formatname = StringFromFormat("_%d", static_cast<int>(format)); const std::string format_name = fmt::format("_{}", static_cast<int>(format));
std::string fullname = basename + tlutname + formatname; const std::string full_name = base_name + tlut_name + format_name;
// try to match a wildcard template // try to match a wildcard template
if (!dump && s_textureMap.find(basename + "_$" + formatname) != s_textureMap.end()) if (!dump)
return basename + "_$" + formatname; {
const std::string texture_name = fmt::format("{}_${}", base_name, format_name);
if (s_textureMap.find(texture_name) != s_textureMap.end())
return texture_name;
}
// else generate the complete texture // else generate the complete texture
if (dump || s_textureMap.find(fullname) != s_textureMap.end()) if (dump || s_textureMap.find(full_name) != s_textureMap.end())
return fullname; return full_name;
return ""; return "";
} }
@ -326,7 +332,7 @@ std::unique_ptr<HiresTexture> HiresTexture::Load(const std::string& base_filenam
{ {
std::string filename = base_filename; std::string filename = base_filename;
if (mip_level != 0) if (mip_level != 0)
filename += StringFromFormat("_mip%u", mip_level); filename += fmt::format("_mip{}", mip_level);
filename_iter = s_textureMap.find(filename); filename_iter = s_textureMap.find(filename);
if (filename_iter == s_textureMap.end()) if (filename_iter == s_textureMap.end())

View File

@ -2,14 +2,13 @@
// Licensed under GPLv2+ // Licensed under GPLv2+
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include "Common/StringUtil.h"
#include "Core/NetPlayClient.h"
#include "VideoCommon/NetPlayGolfUI.h" #include "VideoCommon/NetPlayGolfUI.h"
#include <fmt/format.h>
#include <imgui.h> #include <imgui.h>
#include "Core/NetPlayClient.h"
constexpr float DEFAULT_WINDOW_WIDTH = 220.0f; constexpr float DEFAULT_WINDOW_WIDTH = 220.0f;
constexpr float DEFAULT_WINDOW_HEIGHT = 45.0f; constexpr float DEFAULT_WINDOW_HEIGHT = 45.0f;
@ -57,7 +56,7 @@ void NetPlayGolfUI::Display()
if (client->IsLocalPlayer(player->pid) || !client->PlayerHasControllerMapped(player->pid)) if (client->IsLocalPlayer(player->pid) || !client->PlayerHasControllerMapped(player->pid))
continue; continue;
if (ImGui::Button(StringFromFormat("Give Control to %s", player->name.c_str()).c_str())) if (ImGui::Button(fmt::format("Give Control to {}", player->name).c_str()))
{ {
client->RequestGolfControl(player->pid); client->RequestGolfControl(player->pid);
} }

View File

@ -2,21 +2,21 @@
// Licensed under GPLv2+ // Licensed under GPLv2+
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include "VideoCommon/OnScreenDisplay.h"
#include <algorithm> #include <algorithm>
#include <map> #include <map>
#include <mutex> #include <mutex>
#include <string> #include <string>
#include <fmt/format.h>
#include <imgui.h> #include <imgui.h>
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
#include "Common/StringUtil.h"
#include "Common/Timer.h" #include "Common/Timer.h"
#include "Core/ConfigManager.h" #include "Core/ConfigManager.h"
#include "VideoCommon/OnScreenDisplay.h"
namespace OSD namespace OSD
{ {
constexpr float LEFT_MARGIN = 10.0f; // Pixels to the left of OSD messages. constexpr float LEFT_MARGIN = 10.0f; // Pixels to the left of OSD messages.
@ -49,7 +49,7 @@ static float DrawMessage(int index, const Message& msg, const ImVec2& position,
{ {
// We have to provide a window name, and these shouldn't be duplicated. // We have to provide a window name, and these shouldn't be duplicated.
// So instead, we generate a name based on the number of messages drawn. // So instead, we generate a name based on the number of messages drawn.
const std::string window_name = StringFromFormat("osd_%d", index); const std::string window_name = fmt::format("osd_{}", index);
// The size must be reset, otherwise the length of old messages could influence new ones. // The size must be reset, otherwise the length of old messages could influence new ones.
ImGui::SetNextWindowPos(position); ImGui::SetNextWindowPos(position);

View File

@ -8,6 +8,8 @@
#include <string> #include <string>
#include <string_view> #include <string_view>
#include <fmt/format.h>
#include "Common/Assert.h" #include "Common/Assert.h"
#include "Common/CommonPaths.h" #include "Common/CommonPaths.h"
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
@ -286,8 +288,10 @@ void PostProcessingConfiguration::SaveOptionsConfiguration()
{ {
std::string value; std::string value;
for (size_t i = 0; i < it.second.m_integer_values.size(); ++i) for (size_t i = 0; i < it.second.m_integer_values.size(); ++i)
value += StringFromFormat("%d%s", it.second.m_integer_values[i], {
i == (it.second.m_integer_values.size() - 1) ? "" : ", "); value += fmt::format("{}{}", it.second.m_integer_values[i],
i == (it.second.m_integer_values.size() - 1) ? "" : ", ");
}
ini.GetOrCreateSection(section)->Set(it.second.m_option_name, value); ini.GetOrCreateSection(section)->Set(it.second.m_option_name, value);
} }
break; break;
@ -453,7 +457,7 @@ std::string PostProcessing::GetUniformBufferHeader() const
if (it.second.m_type == if (it.second.m_type ==
PostProcessingConfiguration::ConfigurationOption::OptionType::OPTION_BOOL) PostProcessingConfiguration::ConfigurationOption::OptionType::OPTION_BOOL)
{ {
ss << StringFromFormat(" int %s;\n", it.first.c_str()); ss << fmt::format(" int {};\n", it.first);
for (u32 i = 0; i < 3; i++) for (u32 i = 0; i < 3; i++)
ss << " int ubo_align_" << unused_counter++ << "_;\n"; ss << " int ubo_align_" << unused_counter++ << "_;\n";
} }
@ -462,9 +466,9 @@ std::string PostProcessing::GetUniformBufferHeader() const
{ {
u32 count = static_cast<u32>(it.second.m_integer_values.size()); u32 count = static_cast<u32>(it.second.m_integer_values.size());
if (count == 1) if (count == 1)
ss << StringFromFormat(" int %s;\n", it.first.c_str()); ss << fmt::format(" int {};\n", it.first);
else else
ss << StringFromFormat(" int%u %s;\n", count, it.first.c_str()); ss << fmt::format(" int{} {};\n", count, it.first);
for (u32 i = count; i < 4; i++) for (u32 i = count; i < 4; i++)
ss << " int ubo_align_" << unused_counter++ << "_;\n"; ss << " int ubo_align_" << unused_counter++ << "_;\n";
@ -474,9 +478,9 @@ std::string PostProcessing::GetUniformBufferHeader() const
{ {
u32 count = static_cast<u32>(it.second.m_float_values.size()); u32 count = static_cast<u32>(it.second.m_float_values.size());
if (count == 1) if (count == 1)
ss << StringFromFormat(" float %s;\n", it.first.c_str()); ss << fmt::format(" float {};\n", it.first);
else else
ss << StringFromFormat(" float%u %s;\n", count, it.first.c_str()); ss << fmt::format(" float{} {};\n", count, it.first);
for (u32 i = count; i < 4; i++) for (u32 i = count; i < 4; i++)
ss << " float ubo_align_" << unused_counter++ << "_;\n"; ss << " float ubo_align_" << unused_counter++ << "_;\n";

View File

@ -22,6 +22,7 @@
#include <string> #include <string>
#include <tuple> #include <tuple>
#include <fmt/format.h>
#include <imgui.h> #include <imgui.h>
#include "Common/Assert.h" #include "Common/Assert.h"
@ -1589,8 +1590,8 @@ void Renderer::StopFrameDumpToFFMPEG()
std::string Renderer::GetFrameDumpNextImageFileName() const std::string Renderer::GetFrameDumpNextImageFileName() const
{ {
return StringFromFormat("%sframedump_%u.png", File::GetUserPath(D_DUMPFRAMES_IDX).c_str(), return fmt::format("{}framedump_{}.png", File::GetUserPath(D_DUMPFRAMES_IDX),
m_frame_dump_image_counter); m_frame_dump_image_counter);
} }
bool Renderer::StartFrameDumpToImage(const FrameDumpConfig& config) bool Renderer::StartFrameDumpToImage(const FrameDumpConfig& config)

View File

@ -3,7 +3,9 @@
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include "VideoCommon/ShaderGenCommon.h" #include "VideoCommon/ShaderGenCommon.h"
#include "Common/CommonPaths.h"
#include <fmt/format.h>
#include "Common/FileUtil.h" #include "Common/FileUtil.h"
#include "Core/ConfigManager.h" #include "Core/ConfigManager.h"
@ -76,7 +78,7 @@ std::string GetDiskShaderCacheFileName(APIType api_type, const char* type, bool
{ {
// We're using 21 bits, so 6 hex characters. // We're using 21 bits, so 6 hex characters.
ShaderHostConfig host_config = ShaderHostConfig::GetCurrent(); ShaderHostConfig host_config = ShaderHostConfig::GetCurrent();
filename += StringFromFormat("-%06X", host_config.bits); filename += fmt::format("-{:06X}", host_config.bits);
} }
filename += ".cache"; filename += ".cache";

View File

@ -2,6 +2,8 @@
// Licensed under GPLv2+ // Licensed under GPLv2+
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include "VideoCommon/TextureCacheBase.h"
#include <algorithm> #include <algorithm>
#include <cmath> #include <cmath>
#include <cstring> #include <cstring>
@ -13,6 +15,8 @@
#include <pmmintrin.h> #include <pmmintrin.h>
#endif #endif
#include <fmt/format.h>
#include "Common/Align.h" #include "Common/Align.h"
#include "Common/Assert.h" #include "Common/Assert.h"
#include "Common/ChunkFile.h" #include "Common/ChunkFile.h"
@ -22,7 +26,6 @@
#include "Common/Logging/Log.h" #include "Common/Logging/Log.h"
#include "Common/MathUtil.h" #include "Common/MathUtil.h"
#include "Common/MemoryUtil.h" #include "Common/MemoryUtil.h"
#include "Common/StringUtil.h"
#include "Core/Config/GraphicsSettings.h" #include "Core/Config/GraphicsSettings.h"
#include "Core/ConfigManager.h" #include "Core/ConfigManager.h"
@ -40,7 +43,6 @@
#include "VideoCommon/SamplerCommon.h" #include "VideoCommon/SamplerCommon.h"
#include "VideoCommon/ShaderCache.h" #include "VideoCommon/ShaderCache.h"
#include "VideoCommon/Statistics.h" #include "VideoCommon/Statistics.h"
#include "VideoCommon/TextureCacheBase.h"
#include "VideoCommon/TextureConversionShader.h" #include "VideoCommon/TextureConversionShader.h"
#include "VideoCommon/TextureConverterShaderGen.h" #include "VideoCommon/TextureConverterShaderGen.h"
#include "VideoCommon/TextureDecoder.h" #include "VideoCommon/TextureDecoder.h"
@ -917,13 +919,14 @@ void TextureCacheBase::DumpTexture(TCacheEntry* entry, std::string basename, uns
if (level > 0) if (level > 0)
{ {
basename += StringFromFormat("_mip%i", level); basename += fmt::format("_mip{}", level);
} }
std::string filename = szDir + "/" + basename + ".png"; const std::string filename = fmt::format("{}/{}.png", szDir, basename);
if (File::Exists(filename))
return;
if (!File::Exists(filename)) entry->texture->Save(filename, level);
entry->texture->Save(filename, level);
} }
static u32 CalculateLevelSize(u32 level_0_size, u32 level) static u32 CalculateLevelSize(u32 level_0_size, u32 level)
@ -1751,10 +1754,8 @@ TextureCacheBase::GetXFBTexture(u32 address, u32 width, u32 height, u32 stride,
{ {
// While this isn't really an xfb copy, we can treat it as such for dumping purposes // While this isn't really an xfb copy, we can treat it as such for dumping purposes
static int xfb_count = 0; static int xfb_count = 0;
entry->texture->Save(StringFromFormat("%sxfb_loaded_%i.png", entry->texture->Save(
File::GetUserPath(D_DUMPTEXTURES_IDX).c_str(), fmt::format("{}xfb_loaded_{}.png", File::GetUserPath(D_DUMPTEXTURES_IDX), xfb_count++), 0);
xfb_count++),
0);
} }
GetDisplayRectForXFBEntry(entry, width, height, display_rect); GetDisplayRectForXFBEntry(entry, width, height, display_rect);
@ -2164,19 +2165,17 @@ void TextureCacheBase::CopyRenderTargetToTexture(
if (g_ActiveConfig.bDumpEFBTarget && !is_xfb_copy) if (g_ActiveConfig.bDumpEFBTarget && !is_xfb_copy)
{ {
static int efb_count = 0; static int efb_count = 0;
entry->texture->Save(StringFromFormat("%sefb_frame_%i.png", entry->texture->Save(
File::GetUserPath(D_DUMPTEXTURES_IDX).c_str(), fmt::format("{}efb_frame_{}.png", File::GetUserPath(D_DUMPTEXTURES_IDX), efb_count++),
efb_count++), 0);
0);
} }
if (g_ActiveConfig.bDumpXFBTarget && is_xfb_copy) if (g_ActiveConfig.bDumpXFBTarget && is_xfb_copy)
{ {
static int xfb_count = 0; static int xfb_count = 0;
entry->texture->Save(StringFromFormat("%sxfb_copy_%i.png", entry->texture->Save(
File::GetUserPath(D_DUMPTEXTURES_IDX).c_str(), fmt::format("{}xfb_copy_{}.png", File::GetUserPath(D_DUMPTEXTURES_IDX), xfb_count++),
xfb_count++), 0);
0);
} }
} }
} }

View File

@ -4,6 +4,11 @@
#pragma once #pragma once
#include <string>
#include <string_view>
#include <fmt/format.h>
#include "VideoCommon/ShaderGenCommon.h" #include "VideoCommon/ShaderGenCommon.h"
#include "VideoCommon/VideoCommon.h" #include "VideoCommon/VideoCommon.h"
@ -22,9 +27,9 @@ void WriteVertexLighting(ShaderCode& out, APIType api_type, const char* world_po
// bitfieldExtract generator for BitField types // bitfieldExtract generator for BitField types
template <typename T> template <typename T>
std::string BitfieldExtract(const std::string& source, T type) std::string BitfieldExtract(std::string_view source, T type)
{ {
return StringFromFormat("bitfieldExtract(%s, %u, %u)", source.c_str(), return fmt::format("bitfieldExtract({}, {}, {})", source, static_cast<u32>(type.StartBit()),
static_cast<u32>(type.StartBit()), static_cast<u32>(type.NumBits())); static_cast<u32>(type.NumBits()));
} }
} // namespace UberShader } // namespace UberShader

View File

@ -11,10 +11,11 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include <fmt/format.h>
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
#include "Common/Logging/Log.h" #include "Common/Logging/Log.h"
#include "Common/MsgHandler.h" #include "Common/MsgHandler.h"
#include "Common/StringUtil.h"
#include "VideoCommon/DataReader.h" #include "VideoCommon/DataReader.h"
#include "VideoCommon/VertexLoader.h" #include "VideoCommon/VertexLoader.h"
@ -107,37 +108,39 @@ std::string VertexLoaderBase::ToString() const
"Inv", "Inv",
}}; }};
dest += StringFromFormat("%ib skin: %i P: %i %s-%s ", m_VertexSize, (u32)m_VtxDesc.PosMatIdx, dest += fmt::format("{}b skin: {} P: {} {}-{} ", m_VertexSize, m_VtxDesc.PosMatIdx,
m_VtxAttr.PosElements ? 3 : 2, pos_mode[m_VtxDesc.Position], m_VtxAttr.PosElements ? 3 : 2, pos_mode[m_VtxDesc.Position],
pos_formats[m_VtxAttr.PosFormat]); pos_formats[m_VtxAttr.PosFormat]);
if (m_VtxDesc.Normal) if (m_VtxDesc.Normal)
{ {
dest += StringFromFormat("Nrm: %i %s-%s ", m_VtxAttr.NormalElements, pos_mode[m_VtxDesc.Normal], dest += fmt::format("Nrm: {} {}-{} ", m_VtxAttr.NormalElements, pos_mode[m_VtxDesc.Normal],
pos_formats[m_VtxAttr.NormalFormat]); pos_formats[m_VtxAttr.NormalFormat]);
} }
const std::array<u64, 2> color_mode{{m_VtxDesc.Color0, m_VtxDesc.Color1}}; const std::array<u64, 2> color_mode{{m_VtxDesc.Color0, m_VtxDesc.Color1}};
for (size_t i = 0; i < color_mode.size(); i++) for (size_t i = 0; i < color_mode.size(); i++)
{ {
if (color_mode[i]) if (color_mode[i] == 0)
{ continue;
dest += StringFromFormat("C%zu: %i %s-%s ", i, m_VtxAttr.color[i].Elements,
pos_mode[color_mode[i]], color_format[m_VtxAttr.color[i].Comp]); const auto& color = m_VtxAttr.color[i];
} dest += fmt::format("C{}: {} {}-{} ", i, color.Elements, pos_mode[color_mode[i]],
color_format[color.Comp]);
} }
const std::array<u64, 8> tex_mode{{m_VtxDesc.Tex0Coord, m_VtxDesc.Tex1Coord, m_VtxDesc.Tex2Coord, const std::array<u64, 8> tex_mode{{m_VtxDesc.Tex0Coord, m_VtxDesc.Tex1Coord, m_VtxDesc.Tex2Coord,
m_VtxDesc.Tex3Coord, m_VtxDesc.Tex4Coord, m_VtxDesc.Tex5Coord, m_VtxDesc.Tex3Coord, m_VtxDesc.Tex4Coord, m_VtxDesc.Tex5Coord,
m_VtxDesc.Tex6Coord, m_VtxDesc.Tex7Coord}}; m_VtxDesc.Tex6Coord, m_VtxDesc.Tex7Coord}};
for (size_t i = 0; i < tex_mode.size(); i++) for (size_t i = 0; i < tex_mode.size(); i++)
{ {
if (tex_mode[i]) if (tex_mode[i] == 0)
{ continue;
dest += StringFromFormat("T%zu: %i %s-%s ", i, m_VtxAttr.texCoord[i].Elements,
pos_mode[tex_mode[i]], pos_formats[m_VtxAttr.texCoord[i].Format]); const auto& tex_coord = m_VtxAttr.texCoord[i];
} dest += fmt::format("T{}: {} {}-{} ", i, tex_coord.Elements, pos_mode[tex_mode[i]],
pos_formats[tex_coord.Format]);
} }
dest += StringFromFormat(" - %i v", m_numLoadedVertices); dest += fmt::format(" - {} v", m_numLoadedVertices);
return dest; return dest;
} }