From bacc53a16efd222f0bbe24aa6b2eb521ec52e9ba Mon Sep 17 00:00:00 2001 From: jatinchowdhury18 Date: Fri, 17 Nov 2023 12:37:12 -0800 Subject: [PATCH] Updates for Krusher with Jai on ARM (#336) * Updateds for Jai on ARM * Apply clang-format --------- Co-authored-by: github-actions[bot] --- src/CMakeLists.txt | 3 -- src/jai/SharedJaiContext.h | 9 +++-- src/jai/build.jai | 46 ++++++++++++++++++---- src/processors/modulation/CleanDelayType.h | 4 +- src/processors/other/krusher/Krusher.h | 6 +-- src/state/presets/PresetManager.h | 1 + 6 files changed, 52 insertions(+), 17 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3a0221c2..a041272d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -191,6 +191,3 @@ target_link_libraries(BYOD PRIVATE rnn_accelerated) if (MSVC) target_compile_options(BYOD PRIVATE /bigobj) endif () - -# pre-compiled header -target_precompile_headers(BYOD PRIVATE pch.h) diff --git a/src/jai/SharedJaiContext.h b/src/jai/SharedJaiContext.h index 7f4fc089..92e2462e 100644 --- a/src/jai/SharedJaiContext.h +++ b/src/jai/SharedJaiContext.h @@ -2,16 +2,19 @@ #include -struct jai_Context; +namespace jai +{ +struct Context; +} struct JaiContextWrapper { JaiContextWrapper(); ~JaiContextWrapper(); - operator jai_Context*() { return internal; }; // NOLINT + operator jai::Context*() { return internal; }; // NOLINT private: - jai_Context* internal = nullptr; + jai::Context* internal = nullptr; }; using SharedJaiContext = juce::SharedResourcePointer; diff --git a/src/jai/build.jai b/src/jai/build.jai index 2237c7c4..6ac36605 100644 --- a/src/jai/build.jai +++ b/src/jai/build.jai @@ -1,26 +1,27 @@ #import "Basic"; #import "Compiler"; -#import "generate_c_header"; - -#run build(); +#import "generate_cpp_header"; SRC_FILES :: string.[ "krusher/lofi_downsampler.jai", "krusher/bit_reduction.jai" ]; -build :: () { +build :: (building_arm64 := false, lib_postfix := "") { header_info : Header_Info; - header_info.jai_type_prefix = "jai_"; w := compiler_create_workspace(); target_options := get_build_options(w); - target_options.output_executable_name = "byod_jai_lib"; + target_options.output_executable_name = tprint("%0%", "byod_jai_lib", lib_postfix); target_options.output_type = .STATIC_LIBRARY; // specifies output to be a static library target_options.backend = .LLVM; target_options.text_output_flags = 1; set_optimization(*target_options, .OPTIMIZED); + if building_arm64 { + target_options.cpu_target = .ARM64; + target_options.llvm_options.target_system_triple = "arm64-apple-darwin20.1.0"; + } set_build_options(target_options, w); @@ -38,7 +39,38 @@ build :: () { } compiler_end_intercept(w); - generate_header(*header_info, "byod_jai_lib.h"); + if ! building_arm64 { + generate_header(*header_info, "byod_jai_lib.h"); + } set_build_options_dc(.{do_output=false}); // No executable for this workspace. } + +#if OS == .MACOS { + #run { + print("Building universal binary on MacOS...\n"); + + arm_lib := "byod_jai_lib_arm64.a"; + x64_lib := "byod_jai_lib_x64.a"; + + File.file_delete(arm_lib); + File.file_delete(x64_lib); + + build(false, "_x64"); + build(true, "_arm64"); + + // For some reason we need to wait a second for the ARM build to finish? + // sleep_milliseconds(500); + + lipo_command := string.["lipo", "-create", "-output", "byod_jai_lib.a", x64_lib, arm_lib]; + Process.run_command(..lipo_command); + + lipo_check_command := string.["lipo", "-info", "byod_jai_lib.a"]; + Process.run_command(..lipo_check_command); + } + + Process :: #import "Process"; + File :: #import "File"; +} else { + #run build(); +} diff --git a/src/processors/modulation/CleanDelayType.h b/src/processors/modulation/CleanDelayType.h index dbe64459..22a4d04c 100644 --- a/src/processors/modulation/CleanDelayType.h +++ b/src/processors/modulation/CleanDelayType.h @@ -1,5 +1,7 @@ #pragma once +#include + /* This class wraps chowdsp::DelayLine so it has an equivalent interface to chowdsp::BBBDelayWrapper @@ -24,6 +26,6 @@ struct CleanDelayType inline void pushSample (int channel, float sample) { delay.pushSample (channel, sample); } inline float popSample (int channel) { return lpf.processSample (channel, delay.popSample (channel)); } - chowdsp::SVFLowpass lpf; + chowdsp::SVFLowpass lpf {}; chowdsp::DelayLine delay { 1 << 18 }; }; diff --git a/src/processors/other/krusher/Krusher.h b/src/processors/other/krusher/Krusher.h index 12a1e6ef..d5c69dd3 100644 --- a/src/processors/other/krusher/Krusher.h +++ b/src/processors/other/krusher/Krusher.h @@ -2,7 +2,7 @@ #include "processors/BaseProcessor.h" -#define KRUSHER_USE_JAI_IMPL ! JUCE_ARM&& BYOD_BUILDING_JAI_MODULES +#define KRUSHER_USE_JAI_IMPL ! JUCE_IOS&& BYOD_BUILDING_JAI_MODULES #if KRUSHER_USE_JAI_IMPL #include "jai/byod_jai_lib.h" @@ -36,8 +36,8 @@ class Krusher : public BaseProcessor #if KRUSHER_USE_JAI_IMPL SharedJaiContext jai_context; - jai_Krusher_Lofi_Resample_State resample_state {}; - std::array brFilterStates {}; + jai::Krusher_Lofi_Resample_State resample_state {}; + std::array brFilterStates {}; #else std::unique_ptr jai_context; Krusher_Lofi_Resample_State resample_state {}; diff --git a/src/state/presets/PresetManager.h b/src/state/presets/PresetManager.h index 7a1839be..f4abd7de 100644 --- a/src/state/presets/PresetManager.h +++ b/src/state/presets/PresetManager.h @@ -3,6 +3,7 @@ #include "PresetsServerJobPool.h" #include "PresetsServerSyncManager.h" #include "PresetsServerUserManager.h" +#include namespace PresetConstants {