EnumUtils: Add Common::ToUnderlying

Mirrors the C++23 <utility> function, std::to_underlying
This commit is contained in:
get
2023-06-17 00:08:07 -05:00
parent 5029924ba1
commit 07ad75f34f
22 changed files with 118 additions and 78 deletions

View File

@ -7,6 +7,7 @@
#include <type_traits>
#include "Common/ChunkFile.h"
#include "Common/EnumUtils.h"
#include "Common/Logging/Log.h"
#include "Core/DolphinAnalytics.h"
#include "VideoCommon/CommandProcessor.h"
@ -110,7 +111,7 @@ void CPState::LoadCPReg(u8 sub_cmd, u32 value)
WARN_LOG_FMT(VIDEO,
"CP MATINDEX_A: an exact value of {:02x} was expected "
"but instead a value of {:02x} was seen",
static_cast<u16>(MATINDEX_A), sub_cmd);
Common::ToUnderlying(MATINDEX_A), sub_cmd);
}
matrix_index_a.Hex = value;
@ -123,7 +124,7 @@ void CPState::LoadCPReg(u8 sub_cmd, u32 value)
WARN_LOG_FMT(VIDEO,
"CP MATINDEX_B: an exact value of {:02x} was expected "
"but instead a value of {:02x} was seen",
static_cast<u16>(MATINDEX_B), sub_cmd);
Common::ToUnderlying(MATINDEX_B), sub_cmd);
}
matrix_index_b.Hex = value;
@ -136,7 +137,7 @@ void CPState::LoadCPReg(u8 sub_cmd, u32 value)
WARN_LOG_FMT(VIDEO,
"CP VCD_LO: an exact value of {:02x} was expected "
"but instead a value of {:02x} was seen",
static_cast<u16>(VCD_LO), sub_cmd);
Common::ToUnderlying(VCD_LO), sub_cmd);
}
vtx_desc.low.Hex = value;
@ -149,7 +150,7 @@ void CPState::LoadCPReg(u8 sub_cmd, u32 value)
WARN_LOG_FMT(VIDEO,
"CP VCD_HI: an exact value of {:02x} was expected "
"but instead a value of {:02x} was seen",
static_cast<u16>(VCD_HI), sub_cmd);
Common::ToUnderlying(VCD_HI), sub_cmd);
}
vtx_desc.high.Hex = value;

View File

@ -3,6 +3,7 @@
#include "VideoCommon/UberShaderCommon.h"
#include "Common/EnumUtils.h"
#include "VideoCommon/NativeVertexFormat.h"
#include "VideoCommon/ShaderGenCommon.h"
#include "VideoCommon/VideoCommon.h"
@ -119,11 +120,11 @@ void WriteVertexLighting(ShaderCode& out, APIType api_type, std::string_view wor
out.Write(" if ({} != 0u) {{\n", BitfieldExtract<&LitChannel::enablelighting>("alphareg"));
out.Write(" if ({} != 0u) {{\n", BitfieldExtract<&LitChannel::ambsource>("alphareg"));
out.Write(" if ((components & ({}u << chan)) != 0u) // VB_HAS_COL0\n",
static_cast<u32>(VB_HAS_COL0));
Common::ToUnderlying(VB_HAS_COL0));
out.Write(" lacc.w = int(round(((chan == 0u) ? {}.w : {}.w) * 255.0));\n", in_color_0_var,
in_color_1_var);
out.Write(" else if ((components & {}u) != 0u) // VB_HAS_COLO0\n",
static_cast<u32>(VB_HAS_COL0));
Common::ToUnderlying(VB_HAS_COL0));
out.Write(" lacc.w = int(round({}.w * 255.0));\n", in_color_0_var);
out.Write(" else\n"
" lacc.w = 255;\n"

View File

@ -3,6 +3,7 @@
#include "VideoCommon/UberShaderVertex.h"
#include "Common/EnumUtils.h"
#include "VideoCommon/ConstantManager.h"
#include "VideoCommon/DriverDetails.h"
#include "VideoCommon/NativeVertexFormat.h"
@ -223,7 +224,7 @@ float3 load_input_float3_rawtex(uint vtx_offset, uint attr_offset) {{
"float3 N2;\n"
"\n"
"if ((components & {}u) != 0u) {{ // VB_HAS_POSMTXIDX\n",
static_cast<u32>(VB_HAS_POSMTXIDX));
Common::ToUnderlying(VB_HAS_POSMTXIDX));
LoadVertexAttribute(out, host_config, 2, "posmtx", "uint4", "ubyte4");
out.Write(" // Vertex format has a per-vertex matrix\n"
" int posidx = int(posmtx.r);\n"
@ -258,7 +259,7 @@ float3 load_input_float3_rawtex(uint vtx_offset, uint attr_offset) {{
"float3 _normal = float3(0.0, 0.0, 0.0);\n"
"if ((components & {}u) != 0u) // VB_HAS_NORMAL\n"
"{{\n",
static_cast<u32>(VB_HAS_NORMAL));
Common::ToUnderlying(VB_HAS_NORMAL));
LoadVertexAttribute(out, host_config, 2, "rawnormal", "float3", "float3");
out.Write(" _normal = normalize(float3(dot(N0, rawnormal), dot(N1, rawnormal), dot(N2, "
"rawnormal)));\n"
@ -267,7 +268,7 @@ float3 load_input_float3_rawtex(uint vtx_offset, uint attr_offset) {{
"float3 _tangent = float3(0.0, 0.0, 0.0);\n"
"if ((components & {}u) != 0u) // VB_HAS_TANGENT\n"
"{{\n",
static_cast<u32>(VB_HAS_TANGENT));
Common::ToUnderlying(VB_HAS_TANGENT));
LoadVertexAttribute(out, host_config, 2, "rawtangent", "float3", "float3");
out.Write(" _tangent = float3(dot(N0, rawtangent), dot(N1, rawtangent), dot(N2, rawtangent));\n"
"}}\n"
@ -280,7 +281,7 @@ float3 load_input_float3_rawtex(uint vtx_offset, uint attr_offset) {{
"float3 _binormal = float3(0.0, 0.0, 0.0);\n"
"if ((components & {}u) != 0u) // VB_HAS_BINORMAL\n"
"{{\n",
static_cast<u32>(VB_HAS_BINORMAL));
Common::ToUnderlying(VB_HAS_BINORMAL));
LoadVertexAttribute(out, host_config, 2, "rawbinormal", "float3", "float3");
out.Write(" _binormal = float3(dot(N0, rawbinormal), dot(N1, rawbinormal), dot(N2, "
"rawbinormal));\n"
@ -313,14 +314,14 @@ float3 load_input_float3_rawtex(uint vtx_offset, uint attr_offset) {{
"}}\n"
"else if ((components & {}u) != 0u) // VB_HAS_COL0\n"
"{{\n",
static_cast<u32>(VB_HAS_COL0));
Common::ToUnderlying(VB_HAS_COL0));
LoadVertexAttribute(out, host_config, 2, "rawcolor0", "float4", "ubyte4");
out.Write(" vertex_color_0 = rawcolor0;\n"
" vertex_color_1 = rawcolor0;\n"
"}}\n"
"else if ((components & {}u) != 0u) // VB_HAS_COL1\n"
"{{\n",
static_cast<u32>(VB_HAS_COL1));
Common::ToUnderlying(VB_HAS_COL1));
LoadVertexAttribute(out, host_config, 2, "rawcolor1", "float4", "ubyte4");
out.Write(" vertex_color_0 = rawcolor1;\n"
" vertex_color_1 = rawcolor1;\n"
@ -340,7 +341,7 @@ float3 load_input_float3_rawtex(uint vtx_offset, uint attr_offset) {{
if (host_config.backend_vs_point_line_expand)
{
out.Write("if (vs_expand == {}u) {{ // Line\n", static_cast<u32>(VSExpand::Line));
out.Write("if (vs_expand == {}u) {{ // Line\n", Common::ToUnderlying(VSExpand::Line));
out.Write(" bool is_bottom = (gl_VertexID & 2) != 0;\n"
" bool is_right = (gl_VertexID & 1) != 0;\n"
" uint other_base_offset = vertex_base_offset;\n"
@ -355,7 +356,7 @@ float3 load_input_float3_rawtex(uint vtx_offset, uint attr_offset) {{
" float4 other_p1 = P1;\n"
" float4 other_p2 = P2;\n"
" if ((components & {}u) != 0u) {{ // VB_HAS_POSMTXIDX\n",
static_cast<u32>(VB_HAS_POSMTXIDX));
Common::ToUnderlying(VB_HAS_POSMTXIDX));
out.Write(" uint other_posidx = load_input_uint4_ubyte4(other_base_offset, "
"vertex_offset_posmtx).r;\n"
" other_p0 = " I_TRANSFORMMATRICES "[other_posidx];\n"
@ -365,7 +366,7 @@ float3 load_input_float3_rawtex(uint vtx_offset, uint attr_offset) {{
" float4 other_pos = float4(dot(other_p0, other_rawpos), "
"dot(other_p1, other_rawpos), dot(other_p2, other_rawpos), 1.0);\n");
GenerateVSLineExpansion(out, " ", num_texgen);
out.Write("}} else if (vs_expand == {}u) {{ // Point\n", static_cast<u32>(VSExpand::Point));
out.Write("}} else if (vs_expand == {}u) {{ // Point\n", Common::ToUnderlying(VSExpand::Point));
out.Write(" bool is_bottom = (gl_VertexID & 2) != 0;\n"
" bool is_right = (gl_VertexID & 1) != 0;\n");
GenerateVSPointExpansion(out, " ", num_texgen);
@ -545,7 +546,7 @@ static void GenVertexShaderTexGens(APIType api_type, const ShaderHostConfig& hos
out.Write(" case {:s}:\n", SourceRow::Normal);
out.Write(" if ((components & {}u) != 0u) // VB_HAS_NORMAL\n"
" {{\n",
static_cast<u32>(VB_HAS_NORMAL));
Common::ToUnderlying(VB_HAS_NORMAL));
LoadVertexAttribute(out, host_config, 6, "rawnormal", "float3", "float3");
out.Write(" coord.xyz = rawnormal.xyz;\n"
" }}\n"
@ -553,7 +554,7 @@ static void GenVertexShaderTexGens(APIType api_type, const ShaderHostConfig& hos
out.Write(" case {:s}:\n", SourceRow::BinormalT);
out.Write(" if ((components & {}u) != 0u) // VB_HAS_TANGENT\n"
" {{\n",
static_cast<u32>(VB_HAS_TANGENT));
Common::ToUnderlying(VB_HAS_TANGENT));
LoadVertexAttribute(out, host_config, 6, "rawtangent", "float3", "float3");
out.Write(" coord.xyz = rawtangent.xyz;\n"
" }}\n"
@ -561,14 +562,14 @@ static void GenVertexShaderTexGens(APIType api_type, const ShaderHostConfig& hos
out.Write(" case {:s}:\n", SourceRow::BinormalB);
out.Write(" if ((components & {}u) != 0u) // VB_HAS_BINORMAL\n"
" {{\n",
static_cast<u32>(VB_HAS_BINORMAL));
Common::ToUnderlying(VB_HAS_BINORMAL));
LoadVertexAttribute(out, host_config, 6, "rawbinormal", "float3", "float3");
out.Write(" coord.xyz = rawbinormal.xyz;\n"
" }}\n"
" break;\n\n");
for (u32 i = 0; i < 8; i++)
{
out.Write(" case {:s}:\n", static_cast<SourceRow>(static_cast<u32>(SourceRow::Tex0) + i));
out.Write(" case {:s}:\n", static_cast<SourceRow>(Common::ToUnderlying(SourceRow::Tex0) + i));
out.Write(" if ((components & {}u) != 0u) // VB_HAS_UV{}\n"
" {{\n",
VB_HAS_UV0 << i, i);
@ -625,7 +626,7 @@ static void GenVertexShaderTexGens(APIType api_type, const ShaderHostConfig& hos
out.Write(" default:\n"
" {{\n");
out.Write(" if ((components & ({}u /* VB_HAS_TEXMTXIDX0 */ << texgen)) != 0u) {{\n",
static_cast<u32>(VB_HAS_TEXMTXIDX0));
Common::ToUnderlying(VB_HAS_TEXMTXIDX0));
if (host_config.backend_dynamic_vertex_loader || host_config.backend_vs_point_line_expand)
{
out.Write(" int tmp = int(load_input_float3_rawtex(vertex_base_offset, "