Changeset View
Changeset View
Standalone View
Standalone View
source/blender/gpu/metal/mtl_memory.mm
| Show First 20 Lines • Show All 427 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| /* Increments from active GPUContext thread. */ | /* Increments from active GPUContext thread. */ | ||||
| void MTLSafeFreeList::increment_reference() | void MTLSafeFreeList::increment_reference() | ||||
| { | { | ||||
| lock_.lock(); | lock_.lock(); | ||||
| BLI_assert(in_free_queue_ == false); | BLI_assert(in_free_queue_ == false); | ||||
| reference_count_++; | reference_count_++; | ||||
| referenced_by_workload_ = true; | |||||
| lock_.unlock(); | lock_.unlock(); | ||||
| } | } | ||||
| /* Reference decrements and addition to completed list queue can occur from MTLCommandBuffer | /* Reference decrements and addition to completed list queue can occur from MTLCommandBuffer | ||||
| * 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(); | ||||
| } | } | ||||
| bool MTLSafeFreeList::should_flush() | |||||
| { | |||||
| /* We should only consider refreshing a list if it has been referenced by active workloads, and | |||||
| * contains a sufficient buffer count to avoid overheads associated with flushing the list. If | |||||
| * the reference count is only equal to 1, buffers may have been added, but no command | |||||
| * submissions will have been issued, hence buffers could be returned to the pool prematurely if | |||||
| * associated workload submission occurs later. */ | |||||
| return ((reference_count_ > 1 || referenced_by_workload_) && | |||||
| current_list_index_ > MIN_BUFFER_FLUSH_COUNT); | |||||
| } | |||||
| /** \} */ | /** \} */ | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name MTLBuffer wrapper class implementation. | /** \name MTLBuffer wrapper class implementation. | ||||
| * \{ */ | * \{ */ | ||||
| /* Construct a gpu::MTLBuffer wrapper around a newly created metal::MTLBuffer. */ | /* Construct a gpu::MTLBuffer wrapper around a newly created metal::MTLBuffer. */ | ||||
| MTLBuffer::MTLBuffer(id<MTLDevice> mtl_device, | MTLBuffer::MTLBuffer(id<MTLDevice> mtl_device, | ||||
| ▲ Show 20 Lines • Show All 450 Lines • Show Last 20 Lines | |||||