From 67a02123f952848206ec900b47a696f6588cc604 Mon Sep 17 00:00:00 2001 From: Gin <> Date: Thu, 19 Dec 2024 13:09:14 -0800 Subject: [PATCH 1/2] Add test for mac neon failure --- .../PokemonSwSh_SelectionArrowFinder.cpp | 7 +++++-- SerialPrograms/Source/Tests/PokemonSwSh_Tests.cpp | 15 +++++++++++++++ SerialPrograms/Source/Tests/PokemonSwSh_Tests.h | 2 ++ SerialPrograms/Source/Tests/TestMap.cpp | 1 + 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/SerialPrograms/Source/PokemonSwSh/Inference/PokemonSwSh_SelectionArrowFinder.cpp b/SerialPrograms/Source/PokemonSwSh/Inference/PokemonSwSh_SelectionArrowFinder.cpp index 6ff30ca52..fd43b5d83 100644 --- a/SerialPrograms/Source/PokemonSwSh/Inference/PokemonSwSh_SelectionArrowFinder.cpp +++ b/SerialPrograms/Source/PokemonSwSh/Inference/PokemonSwSh_SelectionArrowFinder.cpp @@ -83,7 +83,8 @@ bool is_selection_arrow(const ImageViewRGB32& image, const WaterfillObject& obje } std::vector find_selection_arrows(const ImageViewRGB32& image, size_t min_area){ if (PreloadSettings::debug().IMAGE_TEMPLATE_MATCHING){ - std::cout << "Match SwSh selection arrow by waterfill, size range (" << min_area << ", SIZE_MAX)" << std::endl; + std::cout << "Match SwSh selection arrow by waterfill, size range (" << min_area << ", SIZE_MAX) " + << "input image size " << image.width() << " x " << image.height() << std::endl; } PackedBinaryMatrix matrix = compress_rgb32_to_binary_max(image, 63, 63, 63); auto session = make_WaterfillSession(matrix); @@ -91,7 +92,9 @@ std::vector find_selection_arrows(const ImageViewRGB32& image, si std::vector ret; WaterfillObject object; while (finder->find_next(object, true)){ -// cout << object.min_x << "-" << object.max_x << ", " << object.min_y << "-" << object.max_y << endl; + if (PreloadSettings::debug().IMAGE_TEMPLATE_MATCHING){ + std::cout << "Found object: " << object.min_x << "-" << object.max_x << ", " << object.min_y << "-" << object.max_y << std::endl; + } if (is_selection_arrow(image, object)){ ret.emplace_back(object); } diff --git a/SerialPrograms/Source/Tests/PokemonSwSh_Tests.cpp b/SerialPrograms/Source/Tests/PokemonSwSh_Tests.cpp index 954b56783..9b40d92d1 100644 --- a/SerialPrograms/Source/Tests/PokemonSwSh_Tests.cpp +++ b/SerialPrograms/Source/Tests/PokemonSwSh_Tests.cpp @@ -30,6 +30,12 @@ using std::endl; namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonSwSh{ +std::vector find_selection_arrows(const ImageViewRGB32& image, size_t min_area); +} +} + using namespace NintendoSwitch::PokemonSwSh; int test_pokemonSwSh_YCommMenuDetector(const ImageViewRGB32& image, bool target){ @@ -125,4 +131,13 @@ int test_pokemonSwSh_BoxGenderDetector(const ImageViewRGB32& image, int target){ return 0; } +int test_pokemonSwSh_SelectionArrowFinder(const ImageViewRGB32& image, int target){ + std::vector boxes = find_selection_arrows(image, 10); + for(const auto& box : boxes){ + std::cout << "Found box: " << box.min_x << " " << box.max_x << " " << box.min_y << " " << box.max_y << std::endl; + } + TEST_RESULT_EQUAL(boxes.size(), (size_t)target); + return 0; +} + } diff --git a/SerialPrograms/Source/Tests/PokemonSwSh_Tests.h b/SerialPrograms/Source/Tests/PokemonSwSh_Tests.h index af50469e7..ab46d6506 100644 --- a/SerialPrograms/Source/Tests/PokemonSwSh_Tests.h +++ b/SerialPrograms/Source/Tests/PokemonSwSh_Tests.h @@ -38,6 +38,8 @@ int test_pokemonSwSh_BoxShinySymbolDetector(const ImageViewRGB32& image, bool ta int test_pokemonSwSh_BoxGenderDetector(const ImageViewRGB32& image, int target); +int test_pokemonSwSh_SelectionArrowFinder(const ImageViewRGB32& image, int target); + } #endif diff --git a/SerialPrograms/Source/Tests/TestMap.cpp b/SerialPrograms/Source/Tests/TestMap.cpp index 26c99bcf4..0f27fa2b7 100644 --- a/SerialPrograms/Source/Tests/TestMap.cpp +++ b/SerialPrograms/Source/Tests/TestMap.cpp @@ -240,6 +240,7 @@ const std::map TEST_MAP = { {"PokemonSwSh_BlackDialogBoxDetector", std::bind(image_bool_detector_helper, test_pokemonSwSh_BlackDialogBoxDetector, _1)}, {"PokemonSwSh_BoxShinySymbolDetector", std::bind(image_bool_detector_helper, test_pokemonSwSh_BoxShinySymbolDetector, _1)}, {"PokemonSwSh_BoxGenderDetector", std::bind(image_int_detector_helper, test_pokemonSwSh_BoxGenderDetector, _1)}, + {"PokemonSwSh_SelectionArrowFinder", std::bind(image_int_detector_helper, test_pokemonSwSh_SelectionArrowFinder, _1)}, {"PokemonLA_BattleMenuDetector", std::bind(image_bool_detector_helper, test_pokemonLA_BattleMenuDetector, _1)}, {"PokemonLA_BattlePokemonSwitchDetector", std::bind(image_bool_detector_helper, test_pokemonLA_BattlePokemonSwitchDetector, _1)}, {"PokemonLA_TransparentDialogueDetector", std::bind(image_bool_detector_helper, test_pokemonLA_TransparentDialogueDetector, _1)}, From 163aa8f30abea7d25cce8ce6e03570546688fec8 Mon Sep 17 00:00:00 2001 From: Gin <> Date: Thu, 19 Dec 2024 17:27:20 -0800 Subject: [PATCH 2/2] fix neon bug --- ...naryImage_BasicFilters_Core_64x8_arm64_NEON.cpp | 3 +++ .../Kernels_BinaryImage_BasicFilters_arm64_NEON.h | 14 +++++++------- .../Waterfill/Kernels_Waterfill_Session.tpp | 6 +++--- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/SerialPrograms/Source/Kernels/BinaryImageFilters/Kernels_BinaryImage_BasicFilters_Core_64x8_arm64_NEON.cpp b/SerialPrograms/Source/Kernels/BinaryImageFilters/Kernels_BinaryImage_BasicFilters_Core_64x8_arm64_NEON.cpp index 716259ebe..52d718340 100644 --- a/SerialPrograms/Source/Kernels/BinaryImageFilters/Kernels_BinaryImage_BasicFilters_Core_64x8_arm64_NEON.cpp +++ b/SerialPrograms/Source/Kernels/BinaryImageFilters/Kernels_BinaryImage_BasicFilters_Core_64x8_arm64_NEON.cpp @@ -10,6 +10,7 @@ #include "Kernels_BinaryImage_BasicFilters_Routines.h" #include "Kernels_BinaryImage_BasicFilters_arm64_NEON.h" + namespace PokemonAutomation{ namespace Kernels{ @@ -24,6 +25,8 @@ void filter_by_mask_64x8_arm64_NEON( } + + void compress_rgb32_to_binary_range_64x8_arm64_NEON( const uint32_t* image, size_t bytes_per_row, PackedBinaryMatrix_IB& matrix0, uint32_t mins0, uint32_t maxs0 diff --git a/SerialPrograms/Source/Kernels/BinaryImageFilters/Kernels_BinaryImage_BasicFilters_arm64_NEON.h b/SerialPrograms/Source/Kernels/BinaryImageFilters/Kernels_BinaryImage_BasicFilters_arm64_NEON.h index 848e1d49d..514908197 100644 --- a/SerialPrograms/Source/Kernels/BinaryImageFilters/Kernels_BinaryImage_BasicFilters_arm64_NEON.h +++ b/SerialPrograms/Source/Kernels/BinaryImageFilters/Kernels_BinaryImage_BasicFilters_arm64_NEON.h @@ -9,9 +9,9 @@ #include "Kernels/PartialWordAccess/Kernels_PartialWordAccess_arm64_NEON.h" -#include -using std::cout; -using std::endl; +// #include +// using std::cout; +// using std::endl; namespace PokemonAutomation{ namespace Kernels{ @@ -149,8 +149,6 @@ class FilterByMask_arm64_NEON{ const uint32x4_t m_zeros; }; - - // Compress given pixels buffer (of up to 64-pixel long) into bit map and store in one uint64_t. class Compressor_RgbRange_arm64_NEON{ public: @@ -178,13 +176,14 @@ class Compressor_RgbRange_arm64_NEON{ bits |= convert16(pixels + c) << c; c += 16; } - for(; c < count; c += 4){ + + count %= 16; + for(size_t i = 0; i < count / 4; i++, c+=4){ const uint8x16_t pixel = vld1q_u8((const uint8_t*)(pixels + c)); bits |= convert4(pixel) << c; } count %= 4; if (count){ - c -= 4; PartialWordAccess_arm64_NEON loader(count * sizeof(uint32_t)); const uint8x16_t pixel = loader.load(pixels + c); const uint64_t mask = ((uint64_t)1 << count) - 1; @@ -273,6 +272,7 @@ class Compressor_RgbEuclidean_arm64_NEON{ for(size_t i = 0; i < count / 4; i++, c+=4){ bits |= convert4(pixels + c) << c; } + count %= 4; if (count){ PartialWordAccess_arm64_NEON loader(count * sizeof(uint32_t)); const uint8x16_t pixel = loader.load(pixels + c); diff --git a/SerialPrograms/Source/Kernels/Waterfill/Kernels_Waterfill_Session.tpp b/SerialPrograms/Source/Kernels/Waterfill/Kernels_Waterfill_Session.tpp index b6d7db850..880128c9a 100644 --- a/SerialPrograms/Source/Kernels/Waterfill/Kernels_Waterfill_Session.tpp +++ b/SerialPrograms/Source/Kernels/Waterfill/Kernels_Waterfill_Session.tpp @@ -16,9 +16,9 @@ #include "Kernels/BinaryMatrix/Kernels_SparseBinaryMatrixCore.h" #include "Kernels_Waterfill_Session.h" -//#include -//using std::cout; -//using std::endl; +// #include +// using std::cout; +// using std::endl; namespace PokemonAutomation{ namespace Kernels{