#pragma once #include #include #include #include #include #include "../architecture/global.h" #ifndef RENDERIVE_MEMORY_DOMAIN_STATS #define RENDERIVE_MEMORY_DOMAIN_STATS 1 #endif #ifndef RENDERIVE_MEMORY_GLOBAL_POOL #define RENDERIVE_MEMORY_GLOBAL_POOL 1 #endif namespace renderive { struct Memory_Callbacks { void* context{}; void* (*allocate)(void* context, std::size_t size, std::size_t alignment){}; void (*deallocate)(void* context, void* address, std::size_t size, std::size_t alignment){}; }; struct Memory_Stats { std::uint64_t upstream_allocation_count{}; std::uint64_t upstream_deallocation_count{}; std::uint64_t upstream_current_bytes{}; std::uint64_t upstream_peak_bytes{}; }; /// @brief Allocation statistics tag used by Core memory resources. enum class Memory_Domain : std::uint8_t { /// @brief Renderable facade and render-data objects. Renderable, /// @brief Pending input packet buffers. Input_Buffer, /// @brief Waterfall data and image working storage. Waterfall, /// @brief Spectrum data and rendering storage. Spectrum, /// @brief Per-frame temporary arena overflow storage. Frame_Arena, /// @brief Generic ring-buffer storage. Ring_Buffer, /// @brief Image pixel storage. Image, /// @brief Audio-frequency data and rendering storage. Audio, /// @brief Afterglow data and rendering storage. Afterglow, /// @brief Planisphere data and rendering storage. Constellation_Diagram, /// @brief Curve data and rendering storage. Curve, /// @brief Point-set data and rendering storage. Point_Set, /// @brief Axis data and rendering storage. Axis, /// @brief Scheduler task objects. Scheduler_Task, /// @brief Renderable local cache images. Renderable_Cache_Image, /// @brief Plot frame images and metadata. Plot_Frame, /// @brief Update completion state and waiters. Update_Completion, /// @brief Fallback tag for allocations without a narrower category. Other }; struct Memory_Domain_Stats { std::uint64_t allocation_count{}; std::uint64_t deallocation_count{}; std::uint64_t current_bytes{}; std::uint64_t peak_bytes{}; }; LIB_DECL void set_memory_callbacks(const Memory_Callbacks& callbacks); LIB_DECL Memory_Stats memory_stats() noexcept; LIB_DECL Memory_Domain_Stats memory_domain_stats(Memory_Domain domain) noexcept; LIB_DECL std::pmr::memory_resource* memory_resource(); LIB_DECL std::pmr::memory_resource* memory_resource(Memory_Domain domain); LIB_DECL void release_unused_memory(); LIB_DECL void shutdown_memory(); template std::shared_ptr make_shared(Args&&... args) { std::pmr::polymorphic_allocator allocator(memory_resource()); return std::allocate_shared(allocator, std::forward(args)...); } }