From 561d83c4b0145cd0ffd093c890e7ab0183c79048 Mon Sep 17 00:00:00 2001 From: coco875 <59367621+coco875@users.noreply.github.com> Date: Sun, 23 Mar 2025 13:09:50 +0000 Subject: [PATCH] remove unordered_map for attr handler (#805) * optimise * Update gfx_pc.cpp --- src/graphic/Fast3D/gfx_pc.cpp | 35 +++++++++++++++-------------------- src/graphic/Fast3D/gfx_pc.h | 2 +- 2 files changed, 16 insertions(+), 21 deletions(-) diff --git a/src/graphic/Fast3D/gfx_pc.cpp b/src/graphic/Fast3D/gfx_pc.cpp index 75658e0..0e9f551 100644 --- a/src/graphic/Fast3D/gfx_pc.cpp +++ b/src/graphic/Fast3D/gfx_pc.cpp @@ -150,19 +150,14 @@ static std::vector shader_ids; static UcodeHandlers ucode_handler_index = ucode_f3dex2; -const static std::unordered_map 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 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 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(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(MTX_PROJECTION); - const auto mtx_load = get_attr(MTX_LOAD); - const auto mtx_push = get_attr(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(CULL_BOTH); - const auto cull_front = get_attr(CULL_FRONT); - const auto cull_back = get_attr(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); diff --git a/src/graphic/Fast3D/gfx_pc.h b/src/graphic/Fast3D/gfx_pc.h index 2acb3cb..3866a06 100644 --- a/src/graphic/Fast3D/gfx_pc.h +++ b/src/graphic/Fast3D/gfx_pc.h @@ -207,7 +207,7 @@ struct RDP { }; typedef enum Attribute { - MTX_PROJECTION, + MTX_PROJECTION = 0, MTX_LOAD, MTX_PUSH, MTX_NOPUSH,