remove unordered_map for attr handler (#805)

* optimise

* Update gfx_pc.cpp
This commit is contained in:
coco875
2025-03-23 09:09:50 -04:00
committed by GitHub
parent bf6adc9438
commit 561d83c4b0
2 changed files with 16 additions and 21 deletions
+15 -20
View File
@@ -150,19 +150,14 @@ static std::vector<std::string> shader_ids;
static UcodeHandlers ucode_handler_index = ucode_f3dex2;
const static std::unordered_map<Attribute, std::any> f3dex2AttrHandler = {
{ MTX_PROJECTION, F3DEX2_G_MTX_PROJECTION }, { MTX_LOAD, F3DEX2_G_MTX_LOAD }, { MTX_PUSH, F3DEX2_G_MTX_PUSH },
{ MTX_NOPUSH, F3DEX_G_MTX_NOPUSH }, { CULL_FRONT, F3DEX2_G_CULL_FRONT }, { CULL_BACK, F3DEX2_G_CULL_BACK },
{ CULL_BOTH, F3DEX2_G_CULL_BOTH },
const static uint32_t f3dex2AttrHandler[] = {
F3DEX2_G_MTX_PROJECTION, F3DEX2_G_MTX_LOAD, F3DEX2_G_MTX_PUSH, F3DEX_G_MTX_NOPUSH,
F3DEX2_G_CULL_FRONT, F3DEX2_G_CULL_BACK, F3DEX2_G_CULL_BOTH,
};
const static std::unordered_map<Attribute, std::any> f3dexAttrHandler = { { MTX_PROJECTION, F3DEX_G_MTX_PROJECTION },
{ MTX_LOAD, F3DEX_G_MTX_LOAD },
{ MTX_PUSH, F3DEX_G_MTX_PUSH },
{ MTX_NOPUSH, F3DEX_G_MTX_NOPUSH },
{ CULL_FRONT, F3DEX_G_CULL_FRONT },
{ CULL_BACK, F3DEX_G_CULL_BACK },
{ CULL_BOTH, F3DEX_G_CULL_BOTH } };
const static uint32_t f3dexAttrHandler[] = { F3DEX_G_MTX_PROJECTION, F3DEX_G_MTX_LOAD, F3DEX_G_MTX_PUSH,
F3DEX_G_MTX_NOPUSH, F3DEX_G_CULL_FRONT, F3DEX_G_CULL_BACK,
F3DEX_G_CULL_BOTH };
static constexpr std::array ucode_attr_handlers = {
&f3dexAttrHandler, // ucode_f3db
@@ -173,10 +168,10 @@ static constexpr std::array ucode_attr_handlers = {
&f3dex2AttrHandler, // ucode_s2dex
};
template <typename T> static constexpr T get_attr(Attribute attr) {
static uint32_t get_attr(Attribute attr) {
const auto ucode_map = ucode_attr_handlers[ucode_handler_index];
assert(ucode_map->contains(attr) && "Attribute not found in the current ucode handler");
return std::any_cast<T>(ucode_map->at(attr));
// assert(ucode_map->contains(attr) && "Attribute not found in the current ucode handler");
return (*ucode_map)[attr];
}
static std::string GetPathWithoutFileName(char* filePath) {
@@ -1165,9 +1160,9 @@ static void gfx_sp_matrix(uint8_t parameters, const int32_t* addr) {
#endif
}
const auto mtx_projection = get_attr<int8_t>(MTX_PROJECTION);
const auto mtx_load = get_attr<int8_t>(MTX_LOAD);
const auto mtx_push = get_attr<int8_t>(MTX_PUSH);
const int8_t mtx_projection = get_attr(MTX_PROJECTION);
const int8_t mtx_load = get_attr(MTX_LOAD);
const int8_t mtx_push = get_attr(MTX_PUSH);
if (parameters & mtx_projection) {
if (parameters & mtx_load) {
@@ -1442,9 +1437,9 @@ static void gfx_sp_tri1(uint8_t vtx1_idx, uint8_t vtx2_idx, uint8_t vtx3_idx, bo
return;
}
const auto cull_both = get_attr<uint32_t>(CULL_BOTH);
const auto cull_front = get_attr<uint32_t>(CULL_FRONT);
const auto cull_back = get_attr<uint32_t>(CULL_BACK);
const uint32_t cull_both = get_attr(CULL_BOTH);
const uint32_t cull_front = get_attr(CULL_FRONT);
const uint32_t cull_back = get_attr(CULL_BACK);
if ((g_rsp.geometry_mode & cull_both) != 0) {
float dx1 = v1->x / (v1->w) - v2->x / (v2->w);
+1 -1
View File
@@ -207,7 +207,7 @@ struct RDP {
};
typedef enum Attribute {
MTX_PROJECTION,
MTX_PROJECTION = 0,
MTX_LOAD,
MTX_PUSH,
MTX_NOPUSH,