Changeset View
Changeset View
Standalone View
Standalone View
source/blender/gpu/metal/mtl_memory.hh
| Show First 20 Lines • Show All 333 Lines • ▼ Show 20 Lines | |||||
| * * Once command buffers complete, MTLSafeFreeList's associated with the current | * * Once command buffers complete, MTLSafeFreeList's associated with the current | ||||
| * command buffer submission are added to the `completed_safelist_queue_`. | * command buffer submission are added to the `completed_safelist_queue_`. | ||||
| * | * | ||||
| * * At a set point in time, all MTLSafeFreeList's in `completed_safelist_queue_` have their | * * At a set point in time, all MTLSafeFreeList's in `completed_safelist_queue_` have their | ||||
| * MTLBuffers re-inserted into the Memory Manager's pools. */ | * MTLBuffers re-inserted into the Memory Manager's pools. */ | ||||
| class MTLBufferPool { | class MTLBufferPool { | ||||
| private: | private: | ||||
| #if MTL_DEBUG_MEMORY_STATISTICS == 1 | |||||
| /* Memory statistics. */ | /* Memory statistics. */ | ||||
| int64_t total_allocation_bytes_ = 0; | std::atomic<int64_t> total_allocation_bytes_; | ||||
| #if MTL_DEBUG_MEMORY_STATISTICS == 1 | |||||
| /* Debug statistics. */ | /* Debug statistics. */ | ||||
| std::atomic<int> per_frame_allocation_count_; | std::atomic<int> per_frame_allocation_count_; | ||||
| std::atomic<int64_t> allocations_in_pool_; | std::atomic<int64_t> allocations_in_pool_; | ||||
| std::atomic<int64_t> buffers_in_pool_; | std::atomic<int64_t> buffers_in_pool_; | ||||
| #endif | #endif | ||||
| /* Metal resources. */ | /* Metal resources. */ | ||||
| bool ensure_initialised_ = false; | bool ensure_initialised_ = false; | ||||
| Show All 9 Lines | #endif | ||||
| * The current value of 1.26 is calibrated for optimal performance and memory utilization. */ | * The current value of 1.26 is calibrated for optimal performance and memory utilization. */ | ||||
| static constexpr float mtl_buffer_size_threshold_factor_ = 1.26; | static constexpr float mtl_buffer_size_threshold_factor_ = 1.26; | ||||
| /* Buffer pools using MTLResourceOptions as key for allocation type. | /* Buffer pools using MTLResourceOptions as key for allocation type. | ||||
| * Aliased as 'uint64_t' for map type compatibility. | * Aliased as 'uint64_t' for map type compatibility. | ||||
| * - A size-ordered list (MultiSet) of allocated buffers is kept per MTLResourceOptions | * - A size-ordered list (MultiSet) of allocated buffers is kept per MTLResourceOptions | ||||
| * permutation. This allows efficient lookup for buffers of a given requested size. | * permutation. This allows efficient lookup for buffers of a given requested size. | ||||
| * - MTLBufferHandle wraps a gpu::MTLBuffer pointer to achieve easy size-based sorting | * - MTLBufferHandle wraps a gpu::MTLBuffer pointer to achieve easy size-based sorting | ||||
| * via CompareMTLBuffer. */ | * via CompareMTLBuffer. | ||||
| * | |||||
| * NOTE: buffer_pool_lock_ guards against concurrent access to the memory allocator. This | |||||
| * can occur during light baking or rendering operations. */ | |||||
| using MTLBufferPoolOrderedList = std::multiset<MTLBufferHandle, CompareMTLBuffer>; | using MTLBufferPoolOrderedList = std::multiset<MTLBufferHandle, CompareMTLBuffer>; | ||||
| using MTLBufferResourceOptions = uint64_t; | using MTLBufferResourceOptions = uint64_t; | ||||
| std::mutex buffer_pool_lock_; | |||||
| blender::Map<MTLBufferResourceOptions, MTLBufferPoolOrderedList *> buffer_pools_; | blender::Map<MTLBufferResourceOptions, MTLBufferPoolOrderedList *> buffer_pools_; | ||||
| blender::Vector<gpu::MTLBuffer *> allocations_; | blender::Vector<gpu::MTLBuffer *> allocations_; | ||||
| /* Maintain a queue of all MTLSafeFreeList's that have been released | /* Maintain a queue of all MTLSafeFreeList's that have been released | ||||
| * by the GPU and are ready to have their buffers re-inserted into the | * by the GPU and are ready to have their buffers re-inserted into the | ||||
| * MemoryManager pools. | * MemoryManager pools. | ||||
| * Access to this queue is made thread-safe through safelist_lock_. */ | * Access to this queue is made thread-safe through safelist_lock_. */ | ||||
| std::mutex safelist_lock_; | std::mutex safelist_lock_; | ||||
| ▲ Show 20 Lines • Show All 100 Lines • Show Last 20 Lines | |||||