Skip to content

Commit

Permalink
VideoCommon: Make use of fmt outside of shader generators
Browse files Browse the repository at this point in the history
Migrates most of VideoCommon over to using fmt, with the exception being
the shader generator code. The shader generators are quite large and
have more corner cases to deal with in terms of conversion (shaders have
braces in them, so we need to make sure to escape them).

Because of the large amount of code that would need to be converted, the
conversion of VideoCommon will be in two parts:

- This change (which converts over the general case string formatting),
- A follow up change that will specifically deal with converting over
  the shader generators.
  • Loading branch information
lioncash committed Nov 23, 2019
1 parent bc449fb commit 6fbbc26
Show file tree
Hide file tree
Showing 12 changed files with 201 additions and 182 deletions.
189 changes: 94 additions & 95 deletions Source/Core/VideoCommon/BPStructs.cpp
Expand Up @@ -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"
Expand Down Expand Up @@ -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;


Expand All @@ -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;


Expand Down Expand Up @@ -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;


Expand All @@ -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
Expand All @@ -1016,43 +1017,42 @@ 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
{ {
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",
Expand All @@ -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;
Expand Down Expand Up @@ -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;


Expand All @@ -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;


Expand All @@ -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;


Expand All @@ -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;


Expand Down Expand Up @@ -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;
} }


Expand Down Expand Up @@ -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;
} }


Expand Down Expand Up @@ -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;
} }


Expand Down
1 change: 1 addition & 0 deletions Source/Core/VideoCommon/CMakeLists.txt
Expand Up @@ -132,6 +132,7 @@ target_link_libraries(videocommon
PUBLIC PUBLIC
core core
PRIVATE PRIVATE
fmt::fmt
png png
xxhash xxhash
imgui imgui
Expand Down
6 changes: 3 additions & 3 deletions Source/Core/VideoCommon/FrameDump.cpp
Expand Up @@ -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>
Expand Down Expand Up @@ -233,9 +235,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;
} }


Expand Down

0 comments on commit 6fbbc26

Please sign in to comment.