File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -196,6 +196,10 @@ int GetWarpSize(id<MTLDevice> dev) {
196196
197197void MetalWorkspace::FreeDataSpace (Device dev, void * ptr) {
198198 AUTORELEASEPOOL {
199+ // need to make sure buffer is not in use in command buffer
200+ // before set the purgeable state to empty
201+ // otherwise can cause issues sometimes
202+ this ->StreamSync (dev, nullptr );
199203 // MTLBuffer PurgeableState should be set to empty before manual
200204 // release in order to prevent memory leak
201205 [(id <MTLBuffer >)ptr setPurgeableState: MTLPurgeableStateEmpty ];
@@ -336,6 +340,10 @@ int GetWarpSize(id<MTLDevice> dev) {
336340 if (temp_buffer_[dev.device_id] == nil || temp_buffer_[dev.device_id].length < size) {
337341 id <MTLDevice > mtl_dev = MetalWorkspace::Global ()->GetDevice (dev);
338342 if (temp_buffer_[dev.device_id] != nil ) {
343+ // need to make sure buffer is not in use in command buffer
344+ // before set the purgeable state to empty
345+ // otherwise can cause issues sometimes
346+ MetalWorkspace::Global ()->StreamSync (dev, nullptr );
339347 [temp_buffer_[dev.device_id] setPurgeableState: MTLPurgeableStateEmpty ];
340348 [temp_buffer_[dev.device_id] release ];
341349 }
You can’t perform that action at this time.
0 commit comments