84 lines
2.9 KiB
C++
84 lines
2.9 KiB
C++
#pragma once
|
|
#include <cstddef>
|
|
#include <cstdint>
|
|
#include <memory>
|
|
#include <memory_resource>
|
|
#include <utility>
|
|
#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 <typename T, typename... Args>
|
|
std::shared_ptr<T> make_shared(Args&&... args) {
|
|
std::pmr::polymorphic_allocator<T> allocator(memory_resource());
|
|
return std::allocate_shared<T>(allocator, std::forward<Args>(args)...);
|
|
}
|
|
}
|