mirror of
https://github.com/Kbz-8/42_vox.git
synced 2026-01-13 15:43:34 +00:00
fixing allocator
This commit is contained in:
@@ -20,11 +20,12 @@ namespace Scop
|
||||
|
||||
enum class Event
|
||||
{
|
||||
SceneHasChangedEventCode = 55,
|
||||
ResizeEventCode = 56,
|
||||
FrameBeginEventCode = 57,
|
||||
FatalErrorEventCode = 168,
|
||||
QuitEventCode = 168,
|
||||
SceneHasChangedEventCode,
|
||||
ResizeEventCode,
|
||||
FrameBeginEventCode,
|
||||
FatalErrorEventCode,
|
||||
QuitEventCode,
|
||||
MemoryChunkAllocationFailed,
|
||||
|
||||
EndEnum
|
||||
};
|
||||
|
||||
@@ -12,13 +12,15 @@ namespace Scop
|
||||
class MemoryChunk
|
||||
{
|
||||
public:
|
||||
MemoryChunk(VkDevice device, VkPhysicalDevice physical, VkDeviceSize size, std::int32_t memory_type_index, bool is_dedicated);
|
||||
MemoryChunk(VkDevice device, VkPhysicalDevice physical, VkDeviceSize size, std::int32_t memory_type_index, bool is_dedicated, std::uint32_t& vram_usage, std::uint32_t& vram_host_visible_usage);
|
||||
|
||||
[[nodiscard]] std::optional<MemoryBlock> Allocate(VkDeviceSize size, VkDeviceSize alignment);
|
||||
void Deallocate(const MemoryBlock& block);
|
||||
[[nodiscard]] inline bool Has(const MemoryBlock& block) const noexcept { return block.memory == m_memory; }
|
||||
[[nodiscard]] inline std::int32_t GetMemoryTypeIndex() const noexcept { return m_memory_type_index; }
|
||||
[[nodiscard]] inline bool IsDedicated() const noexcept { return m_is_dedicated; }
|
||||
[[nodiscard]] inline void* GetMap() const noexcept { return p_map; }
|
||||
[[nodiscard]] inline VkDeviceSize GetSize() const noexcept { return m_size; }
|
||||
|
||||
~MemoryChunk();
|
||||
|
||||
|
||||
@@ -11,8 +11,9 @@
|
||||
|
||||
namespace Scop
|
||||
{
|
||||
constexpr std::size_t SMALL_HEAP_MAX_SIZE = (1024ULL * 1024 * 1024);
|
||||
constexpr std::size_t DEFAULT_LARGE_HEAP_BLOCK_SIZE = (256ULL * 1024 * 1024);
|
||||
constexpr std::size_t SMALL_HEAP_MAX_SIZE = (1024ULL * 1024 * 1024); // 1GB
|
||||
constexpr std::size_t DEFAULT_LARGE_HEAP_BLOCK_SIZE = (256ULL * 1024 * 1024); // 256MiB
|
||||
constexpr std::uint32_t NEW_BLOCK_SIZE_SHIFT_MAX = 3;
|
||||
|
||||
class DeviceAllocator
|
||||
{
|
||||
@@ -26,6 +27,9 @@ namespace Scop
|
||||
[[nodiscard]] MemoryBlock Allocate(VkDeviceSize size, VkDeviceSize alignment, std::int32_t memory_type_index, bool dedicated_chunk = false);
|
||||
void Deallocate(const MemoryBlock& block);
|
||||
|
||||
[[nodiscard]] inline std::uint32_t GetVramUsage() const noexcept { return m_vram_usage; }
|
||||
[[nodiscard]] inline std::uint32_t GetVramHostVisibleUsage() const noexcept { return m_vram_host_visible_usage; }
|
||||
|
||||
~DeviceAllocator() = default;
|
||||
|
||||
private:
|
||||
@@ -39,6 +43,9 @@ namespace Scop
|
||||
std::size_t m_allocations_count = 0;
|
||||
std::mutex m_alloc_mutex;
|
||||
std::mutex m_dealloc_mutex;
|
||||
std::uint32_t m_vram_usage = 0;
|
||||
std::uint32_t m_vram_host_visible_usage = 0;
|
||||
bool m_last_chunk_creation_failed = false;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user