Changeset View
Changeset View
Standalone View
Standalone View
source/blender/gpu/metal/mtl_memory.mm
| Show First 20 Lines • Show All 156 Lines • ▼ Show 20 Lines | #endif | ||||
| /* Ensure buffer memory is correctly backed. */ | /* Ensure buffer memory is correctly backed. */ | ||||
| BLI_assert(new_buffer->get_metal_buffer()); | BLI_assert(new_buffer->get_metal_buffer()); | ||||
| } | } | ||||
| /* Flag buffer as actively in-use. */ | /* Flag buffer as actively in-use. */ | ||||
| new_buffer->flag_in_use(true); | new_buffer->flag_in_use(true); | ||||
| #if MTL_DEBUG_MEMORY_STATISTICS == 1 | #if MTL_DEBUG_MEMORY_STATISTICS == 1 | ||||
| this->per_frame_allocation_count++; | per_frame_allocation_count_++; | ||||
| #endif | #endif | ||||
| return new_buffer; | return new_buffer; | ||||
| } | } | ||||
| gpu::MTLBuffer *MTLBufferPool::allocate_aligned_with_data(uint64_t size, | gpu::MTLBuffer *MTLBufferPool::allocate_aligned_with_data(uint64_t size, | ||||
| uint32_t alignment, | uint32_t alignment, | ||||
| bool cpu_visible, | bool cpu_visible, | ||||
| ▲ Show 20 Lines • Show All 87 Lines • ▼ Show 20 Lines | #endif | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| #if MTL_DEBUG_MEMORY_STATISTICS == 1 | #if MTL_DEBUG_MEMORY_STATISTICS == 1 | ||||
| printf("--- Allocation Stats ---\n"); | printf("--- Allocation Stats ---\n"); | ||||
| printf(" Num buffers processed in pool (this frame): %u\n", num_buffers_added); | printf(" Num buffers processed in pool (this frame): %u\n", num_buffers_added); | ||||
| uint framealloc = (uint)this->per_frame_allocation_count; | uint framealloc = (uint)per_frame_allocation_count_; | ||||
| printf(" Allocations in frame: %u\n", framealloc); | printf(" Allocations in frame: %u\n", framealloc); | ||||
| printf(" Total Buffers allocated: %u\n", (uint)allocations_.size()); | printf(" Total Buffers allocated: %u\n", (uint)allocations_.size()); | ||||
| printf(" Total Memory allocated: %u MB\n", (uint)total_allocation_bytes_ / (1024 * 1024)); | printf(" Total Memory allocated: %u MB\n", (uint)total_allocation_bytes_ / (1024 * 1024)); | ||||
| uint allocs = (uint)(allocations_in_pool_) / 1024 / 2024; | uint allocs = (uint)(allocations_in_pool_) / 1024 / 2024; | ||||
| printf(" Free memory in pools: %u MB\n", allocs); | printf(" Free memory in pools: %u MB\n", allocs); | ||||
| uint buffs = (uint)buffers_in_pool_; | uint buffs = (uint)buffers_in_pool_; | ||||
| Show All 14 Lines | printf(" Buffers in pool (%u)(%llu): %u (%u MB)\n", | ||||
| (uint)*key_iterator, | (uint)*key_iterator, | ||||
| iters, | iters, | ||||
| (uint)((*value_iterator)->size()), | (uint)((*value_iterator)->size()), | ||||
| (uint)mem_in_pool / 1024 / 1024); | (uint)mem_in_pool / 1024 / 1024); | ||||
| ++key_iterator; | ++key_iterator; | ||||
| ++value_iterator; | ++value_iterator; | ||||
| } | } | ||||
| this->per_frame_allocation_count = 0; | per_frame_allocation_count_ = 0; | ||||
| #endif | #endif | ||||
| /* Clear safe pools list */ | /* Clear safe pools list */ | ||||
| completed_safelist_queue_.clear(); | completed_safelist_queue_.clear(); | ||||
| safelist_lock_.unlock(); | safelist_lock_.unlock(); | ||||
| } | } | ||||
| void MTLBufferPool::push_completed_safe_list(MTLSafeFreeList *safe_list) | void MTLBufferPool::push_completed_safe_list(MTLSafeFreeList *safe_list) | ||||
| ▲ Show 20 Lines • Show All 118 Lines • ▼ Show 20 Lines | |||||
| * completion callback thread. */ | * completion callback thread. */ | ||||
| void MTLSafeFreeList::decrement_reference() | void MTLSafeFreeList::decrement_reference() | ||||
| { | { | ||||
| lock_.lock(); | lock_.lock(); | ||||
| BLI_assert(in_free_queue_ == false); | BLI_assert(in_free_queue_ == false); | ||||
| int ref_count = --reference_count_; | int ref_count = --reference_count_; | ||||
| if (ref_count == 0) { | if (ref_count == 0) { | ||||
| MTLContext::get_global_memory_manager().push_completed_safe_list(this); | MTLContext::get_global_memory_manager()->push_completed_safe_list(this); | ||||
| } | } | ||||
| lock_.unlock(); | lock_.unlock(); | ||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name MTLBuffer wrapper class implementation. | /** \name MTLBuffer wrapper class implementation. | ||||
| Show All 13 Lines | MTLBuffer::MTLBuffer(id<MTLDevice> mtl_device, | ||||
| device_ = mtl_device; | device_ = mtl_device; | ||||
| is_external_ = false; | is_external_ = false; | ||||
| options_ = options; | options_ = options; | ||||
| this->flag_in_use(false); | this->flag_in_use(false); | ||||
| metal_buffer_ = [device_ newBufferWithLength:aligned_alloc_size options:options]; | metal_buffer_ = [device_ newBufferWithLength:aligned_alloc_size options:options]; | ||||
| BLI_assert(metal_buffer_); | BLI_assert(metal_buffer_); | ||||
| [metal_buffer_ retain]; | |||||
| size_ = aligned_alloc_size; | size_ = aligned_alloc_size; | ||||
| this->set_usage_size(size_); | this->set_usage_size(size_); | ||||
| if (!(options_ & MTLResourceStorageModePrivate)) { | if (!(options_ & MTLResourceStorageModePrivate)) { | ||||
| data_ = [metal_buffer_ contents]; | data_ = [metal_buffer_ contents]; | ||||
| } | } | ||||
| else { | else { | ||||
| data_ = nullptr; | data_ = nullptr; | ||||
| Show All 25 Lines | if (metal_buffer_ != nil) { | ||||
| [metal_buffer_ release]; | [metal_buffer_ release]; | ||||
| metal_buffer_ = nil; | metal_buffer_ = nil; | ||||
| } | } | ||||
| } | } | ||||
| void gpu::MTLBuffer::free() | void gpu::MTLBuffer::free() | ||||
| { | { | ||||
| if (!is_external_) { | if (!is_external_) { | ||||
| MTLContext::get_global_memory_manager().free_buffer(this); | MTLContext::get_global_memory_manager()->free_buffer(this); | ||||
| } | } | ||||
| else { | else { | ||||
| if (metal_buffer_ != nil) { | if (metal_buffer_ != nil) { | ||||
| [metal_buffer_ release]; | [metal_buffer_ release]; | ||||
| metal_buffer_ = nil; | metal_buffer_ = nil; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 383 Lines • Show Last 20 Lines | |||||