Changeset 281160 in webkit
- Timestamp:
- Aug 17, 2021, 1:32:30 PM (5 years ago)
- Location:
- trunk/Source/ThirdParty/ANGLE
- Files:
-
- 9 edited
-
ChangeLog (modified) (1 diff)
-
src/libANGLE/renderer/metal/DisplayMtl.h (modified) (1 diff)
-
src/libANGLE/renderer/metal/DisplayMtl.mm (modified) (6 diffs)
-
src/libANGLE/renderer/metal/IOSurfaceSurfaceMtl.mm (modified) (3 diffs)
-
src/libANGLE/renderer/metal/ProgramMtl.mm (modified) (4 diffs)
-
src/libANGLE/renderer/metal/ProvokingVertexHelper.mm (modified) (1 diff)
-
src/libANGLE/renderer/metal/SurfaceMtl.mm (modified) (3 diffs)
-
src/libANGLE/renderer/metal/mtl_common.h (modified) (5 diffs)
-
src/libANGLE/renderer/metal/mtl_state_cache.mm (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/ThirdParty/ANGLE/ChangeLog
r281088 r281160 1 2021-08-17 David Kilzer <ddkilzer@apple.com> 2 3 [Metal ANGLE] Fix over-autorelease of rx::DisplayMtl::getMetalDeviceMatchingAttribute() and various Objective-C leaks 4 <https://webkit.org/b/229128> 5 <rdar://problem/81964007> 6 7 Reviewed by Alex Christensen. 8 9 * src/libANGLE/renderer/metal/DisplayMtl.h: 10 (rx::DisplayMtl::getMetalDeviceMatchingAttribute): 11 - Change to return mtl::AutoObjCPtr<> to make ownership clear. 12 (rx::DisplayMtl::mMetalDevice): 13 - No need to initialize to nil. 14 15 * src/libANGLE/renderer/metal/DisplayMtl.mm: 16 (rx::DisplayMtl::initializeImpl): 17 - Update for changes to getMetalDeviceMatchingAttribute(). 18 (rx::DisplayMtl::getMetalDeviceMatchingAttribute): 19 - Change to return mtl::AutoObjCPtr<> to make ownership clear. 20 - Fix leak of `deviceList`, `externalGPUs`, `integratedGPUs`, and 21 `discreteGPUs`. 22 - Use mtl::adoptObjCObj<>() to prevent leak of 23 MTLCreateSystemDefaultDevice(). 24 25 * src/libANGLE/renderer/metal/IOSurfaceSurfaceMtl.mm: 26 - Fix leak of `captureDescriptor` in two different if blocks. 27 28 * src/libANGLE/renderer/metal/ProgramMtl.mm: 29 - Fix leak of `funcConstants` in early return on error path. 30 31 * src/libANGLE/renderer/metal/ProvokingVertexHelper.mm: 32 (rx::ProvokingVertexHelper::getSpecializedShader): 33 - Fix leak of `fcValues`. 34 35 * src/libANGLE/renderer/metal/SurfaceMtl.mm: 36 - Fix leak of `captureDescriptor` in two different if blocks. 37 38 * src/libANGLE/renderer/metal/mtl_common.h: 39 (rx::mtl::WrappedObject::retainAssign): 40 - Move statement inside #if/#endif that isn't needed for ARC. 41 (rx::mtl::WrappedObject::unretainAssign): Add. 42 (rx::mtl::AutoObjCPtr::AutoObjCPtr): Add. 43 (rx::mtl::adoptObjCObj): Add. 44 - Add a helper method to adopt an Objective-C object to 45 eliminate the need to autorelease a +1 retained object before 46 an mtl::AutoObjCPtr<> object wraps it. Modeled after 47 WTF::RetainPtr<> in WebKit. 48 49 * src/libANGLE/renderer/metal/mtl_state_cache.mm: 50 (rx::mtl::RenderPipelineCache::createRenderPipelineState): 51 (rx::mtl::ProvokingVertexComputePipelineCache::createComputePipelineState): 52 - Use adoptObjCObj<>() to fix potential leak on the early return 53 path since these methods return an mtl::AutoObjCPtr<>. 54 1 55 2021-08-16 David Kilzer <ddkilzer@apple.com> 2 56 -
trunk/Source/ThirdParty/ANGLE/src/libANGLE/renderer/metal/DisplayMtl.h
r279143 r281160 176 176 void initializeLimitations(); 177 177 EGLenum EGLDrawingBufferTextureTarget(); 178 id<MTLDevice> getMetalDeviceMatchingAttribute(const egl::AttributeMap &attribs);178 mtl::AutoObjCPtr<id<MTLDevice>> getMetalDeviceMatchingAttribute(const egl::AttributeMap &attribs); 179 179 angle::Result initializeShaderLibrary(); 180 180 181 mtl::AutoObjCPtr<id<MTLDevice>> mMetalDevice = nil;181 mtl::AutoObjCPtr<id<MTLDevice>> mMetalDevice; 182 182 uint32_t mMetalDeviceVendorId = 0; 183 183 -
trunk/Source/ThirdParty/ANGLE/src/libANGLE/renderer/metal/DisplayMtl.mm
r280010 r281160 140 140 ANGLE_MTL_OBJC_SCOPE 141 141 { 142 mMetalDevice = [getMetalDeviceMatchingAttribute(display->getAttributeMap()) ANGLE_MTL_AUTORELEASE];142 mMetalDevice = getMetalDeviceMatchingAttribute(display->getAttributeMap()); 143 143 //If we can't create a device, fail initialization. 144 144 if(!mMetalDevice.get()) … … 245 245 246 246 247 id<MTLDevice> DisplayMtl::getMetalDeviceMatchingAttribute(const egl::AttributeMap &attribs)247 mtl::AutoObjCPtr<id<MTLDevice>> DisplayMtl::getMetalDeviceMatchingAttribute(const egl::AttributeMap &attribs) 248 248 { 249 249 #if defined(ANGLE_PLATFORM_MACOS) || defined(ANGLE_PLATFORM_MACCATALYST) 250 250 const std::string anglePreferredDevice = angle::GetEnvironmentVar(kANGLEPreferredDeviceEnv); 251 NSArray<id<MTLDevice>> *deviceList = MTLCopyAllDevices();251 auto deviceList = mtl::adoptObjCObj(MTLCopyAllDevices()); 252 252 if (anglePreferredDevice != "") 253 253 { 254 for (id<MTLDevice> device in deviceList )254 for (id<MTLDevice> device in deviceList.get()) 255 255 { 256 256 if ([device.name.lowercaseString … … 259 259 { 260 260 NSLog(@"Using Metal Device: %@", [device name]); 261 return device;261 return device; 262 262 break; 263 263 } … … 265 265 } 266 266 267 NSMutableArray<id<MTLDevice>> *externalGPUs = [[NSMutableArray alloc] init];268 NSMutableArray<id<MTLDevice>> *integratedGPUs = [[NSMutableArray alloc] init];269 NSMutableArray<id<MTLDevice>> *discreteGPUs = [[NSMutableArray alloc] init];270 for (id <MTLDevice> device in deviceList ) {267 auto externalGPUs = mtl::adoptObjCObj<NSMutableArray<id<MTLDevice>>>([[NSMutableArray alloc] init]); 268 auto integratedGPUs = mtl::adoptObjCObj<NSMutableArray<id<MTLDevice>>>([[NSMutableArray alloc] init]); 269 auto discreteGPUs = mtl::adoptObjCObj<NSMutableArray<id<MTLDevice>>>([[NSMutableArray alloc] init]); 270 for (id <MTLDevice> device in deviceList.get()) { 271 271 if (device.removable) 272 272 { … … 287 287 { 288 288 //Search for a discrete GPU first. 289 for (id<MTLDevice> device in discreteGPUs ) {289 for (id<MTLDevice> device in discreteGPUs.get()) { 290 290 if(![device isHeadless]) 291 291 return device; … … 293 293 } 294 294 //If we've selected a low power device, look through integrated devices. 295 for (id<MTLDevice> device in integratedGPUs ) {295 for (id<MTLDevice> device in integratedGPUs.get()) { 296 296 if(![device isHeadless]) 297 297 return device; 298 298 } 299 299 //If we selected a low power device and there's no low-power devices avaialble, return the first (default) device. 300 if (deviceList.count > 0)300 if (deviceList.get().count > 0) 301 301 return deviceList[0]; 302 302 #endif 303 303 //If we can't find anything, or are on a platform that doesn't support power options, create a default device. 304 return MTLCreateSystemDefaultDevice();304 return mtl::adoptObjCObj(MTLCreateSystemDefaultDevice()); 305 305 } 306 306 -
trunk/Source/ThirdParty/ANGLE/src/libANGLE/renderer/metal/IOSurfaceSurfaceMtl.mm
r273516 r281160 169 169 if (ANGLE_APPLE_AVAILABLE_XCI(10.15, 13.0, 13)) 170 170 { 171 MTLCaptureDescriptor *captureDescriptor = [[MTLCaptureDescriptor alloc] init];172 captureDescriptor. captureObject= metalDevice;173 const std::string filePath = GetMetalCaptureFile();171 auto captureDescriptor = mtl::adoptObjCObj([[MTLCaptureDescriptor alloc] init]); 172 captureDescriptor.get().captureObject = metalDevice; 173 const std::string filePath = GetMetalCaptureFile(); 174 174 if (filePath != "") 175 175 { 176 176 const std::string numberedPath = 177 177 filePath + std::to_string(gFrameCaptured - 1) + ".gputrace"; 178 captureDescriptor. destination = MTLCaptureDestinationGPUTraceDocument;179 captureDescriptor. outputURL =178 captureDescriptor.get().destination = MTLCaptureDestinationGPUTraceDocument; 179 captureDescriptor.get().outputURL = 180 180 [NSURL fileURLWithPath:[NSString stringWithUTF8String:numberedPath.c_str()] 181 181 isDirectory:false]; … … 184 184 { 185 185 // This will pause execution only if application is being debugged inside Xcode 186 captureDescriptor. destination = MTLCaptureDestinationDeveloperTools;186 captureDescriptor.get().destination = MTLCaptureDestinationDeveloperTools; 187 187 } 188 188 189 189 NSError *error; 190 if (![captureManager startCaptureWithDescriptor:captureDescriptor error:&error])190 if (![captureManager startCaptureWithDescriptor:captureDescriptor.get() error:&error]) 191 191 { 192 192 NSLog(@"Failed to start capture, error %@", error); … … 197 197 if (ANGLE_APPLE_AVAILABLE_XCI(10.15, 13.0, 13)) 198 198 { 199 MTLCaptureDescriptor *captureDescriptor = [[MTLCaptureDescriptor alloc] init];200 captureDescriptor. captureObject= metalDevice;199 auto captureDescriptor = mtl::adoptObjCObj([[MTLCaptureDescriptor alloc] init]); 200 captureDescriptor.get().captureObject = metalDevice; 201 201 202 202 NSError *error; 203 if (![captureManager startCaptureWithDescriptor:captureDescriptor error:&error])203 if (![captureManager startCaptureWithDescriptor:captureDescriptor.get() error:&error]) 204 204 { 205 205 NSLog(@"Failed to start capture, error %@", error); -
trunk/Source/ThirdParty/ANGLE/src/libANGLE/renderer/metal/ProgramMtl.mm
r279606 r281160 599 599 mtl::TranslatedShaderInfo *translatedMslInfo = &mMslShaderTranslateInfo[shaderType]; 600 600 ProgramShaderObjVariantMtl *shaderVariant; 601 MTLFunctionConstantValues *funcConstants = nil;601 mtl::AutoObjCObj<MTLFunctionConstantValues> funcConstants; 602 602 603 603 if (shaderType == gl::ShaderType::Vertex) … … 635 635 } 636 636 637 funcConstants = [[MTLFunctionConstantValues alloc] init];637 funcConstants = mtl::adoptObjCObj([[MTLFunctionConstantValues alloc] init]); 638 638 [funcConstants setConstantValue:&emulateDiscard 639 639 type:MTLDataTypeBool … … 673 673 } 674 674 675 funcConstants = [[MTLFunctionConstantValues alloc] init];675 funcConstants = mtl::adoptObjCObj([[MTLFunctionConstantValues alloc] init]); 676 676 [funcConstants setConstantValue:&emulateCoverageMask 677 677 type:MTLDataTypeBool … … 695 695 ANGLE_MTL_OBJC_SCOPE 696 696 { 697 ANGLE_TRY(CreateMslShader(context, translatedMslInfo->metalLibrary, SHADER_ENTRY_NAME, funcConstants ,697 ANGLE_TRY(CreateMslShader(context, translatedMslInfo->metalLibrary, SHADER_ENTRY_NAME, funcConstants.get(), 698 698 &shaderVariant->metalShader)); 699 [funcConstants ANGLE_MTL_AUTORELEASE];700 699 } 701 700 -
trunk/Source/ThirdParty/ANGLE/src/libANGLE/renderer/metal/ProvokingVertexHelper.mm
r277741 r281160 175 175 { 176 176 uint indexBufferKey = buildIndexBufferKey(pipelineDesc); 177 MTLFunctionConstantValues * fcValues = [[MTLFunctionConstantValues alloc]init];177 auto fcValues = mtl::adoptObjCObj([[MTLFunctionConstantValues alloc] init]); 178 178 [fcValues setConstantValue:&indexBufferKey type:MTLDataTypeUInt withName:@"fixIndexBufferKey"]; 179 179 180 return CreateMslShader(context, mProvokingVertexLibrary, @"fixIndexBuffer", fcValues, shaderOut); 181 } 180 return CreateMslShader(context, mProvokingVertexLibrary, @"fixIndexBuffer", fcValues.get(), shaderOut); 181 } 182 182 183 //Private command buffer 183 184 bool ProvokingVertexHelper::hasSpecializedShader(gl::ShaderType shaderType, -
trunk/Source/ThirdParty/ANGLE/src/libANGLE/renderer/metal/SurfaceMtl.mm
r277824 r281160 178 178 if (ANGLE_APPLE_AVAILABLE_XCI(10.15, 13.0, 13)) 179 179 { 180 MTLCaptureDescriptor *captureDescriptor = [[MTLCaptureDescriptor alloc] init];181 captureDescriptor. captureObject= metalDevice;182 const std::string filePath = GetMetalCaptureFile();180 auto captureDescriptor = mtl::adoptObjCObj([[MTLCaptureDescriptor alloc] init]); 181 captureDescriptor.get().captureObject = metalDevice; 182 const std::string filePath = GetMetalCaptureFile(); 183 183 if (filePath != "") 184 184 { 185 185 const std::string numberedPath = 186 186 filePath + std::to_string(gFrameCaptured - 1) + ".gputrace"; 187 captureDescriptor. destination = MTLCaptureDestinationGPUTraceDocument;188 captureDescriptor. outputURL =187 captureDescriptor.get().destination = MTLCaptureDestinationGPUTraceDocument; 188 captureDescriptor.get().outputURL = 189 189 [NSURL fileURLWithPath:[NSString stringWithUTF8String:numberedPath.c_str()] 190 190 isDirectory:false]; … … 193 193 { 194 194 // This will pause execution only if application is being debugged inside Xcode 195 captureDescriptor. destination = MTLCaptureDestinationDeveloperTools;195 captureDescriptor.get().destination = MTLCaptureDestinationDeveloperTools; 196 196 } 197 197 198 198 NSError *error; 199 if (![captureManager startCaptureWithDescriptor:captureDescriptor error:&error])199 if (![captureManager startCaptureWithDescriptor:captureDescriptor.get() error:&error]) 200 200 { 201 201 NSLog(@"Failed to start capture, error %@", error); … … 206 206 if (ANGLE_APPLE_AVAILABLE_XCI(10.15, 13.0, 13)) 207 207 { 208 MTLCaptureDescriptor *captureDescriptor = [[MTLCaptureDescriptor alloc] init];209 captureDescriptor. captureObject= metalDevice;208 auto captureDescriptor = mtl::adoptObjCObj([[MTLCaptureDescriptor alloc] init]); 209 captureDescriptor.get().captureObject = metalDevice; 210 210 211 211 NSError *error; 212 if (![captureManager startCaptureWithDescriptor:captureDescriptor error:&error])212 if (![captureManager startCaptureWithDescriptor:captureDescriptor.get() error:&error]) 213 213 { 214 214 NSLog(@"Failed to start capture, error %@", error); -
trunk/Source/ThirdParty/ANGLE/src/libANGLE/renderer/metal/mtl_common.h
r279143 r281160 209 209 void retainAssign(T obj) 210 210 { 211 #if !__has_feature(objc_arc) 211 212 T retained = obj; 212 #if !__has_feature(objc_arc)213 213 [retained retain]; 214 214 #endif … … 217 217 } 218 218 219 void unretainAssign(T obj) 220 { 221 release(); 222 mMetalObject = obj; 223 } 224 219 225 private: 220 226 void release() … … 228 234 T mMetalObject = nil; 229 235 }; 236 237 // Because ARC enablement is a compile-time choice, and we compile this header 238 // both ways, we need a separate copy of our code when ARC is enabled. 239 #if __has_feature(objc_arc) 240 #define adoptObjCObj adoptObjCObjArc 241 #endif 242 243 template <typename T> 244 class AutoObjCPtr; 245 246 template <typename T> 247 using AutoObjCObj = AutoObjCPtr<T *>; 248 249 template <typename U> 250 AutoObjCObj<U> adoptObjCObj(U* NS_RELEASES_ARGUMENT) __attribute__((__warn_unused_result__)); 230 251 231 252 // This class is similar to WrappedObject, however, it allows changing the … … 294 315 using ParentType::retainAssign; 295 316 317 template <typename U> 318 friend AutoObjCObj<U> adoptObjCObj(U* NS_RELEASES_ARGUMENT) __attribute__((__warn_unused_result__)); 319 296 320 private: 321 enum AdoptTag { Adopt }; 322 AutoObjCPtr(T src, AdoptTag) { this->unretainAssign(src); } 323 297 324 void transfer(AutoObjCPtr &&src) 298 325 { … … 302 329 }; 303 330 304 template <typename T> 305 using AutoObjCObj = AutoObjCPtr<T *>; 331 template <typename U> 332 inline AutoObjCObj<U> adoptObjCObj(U* NS_RELEASES_ARGUMENT src) 333 { 334 #if __has_feature(objc_arc) 335 return src; 336 #elif defined(OBJC_NO_GC) 337 return AutoObjCPtr<U*>(src, AutoObjCPtr<U*>::Adopt); 338 #else 339 #error "ObjC GC not supported." 340 #endif 341 } 342 306 343 307 344 // NOTE: SharedEvent is only declared on iOS 12.0+ or mac 10.14+ -
trunk/Source/ThirdParty/ANGLE/src/libANGLE/renderer/metal/mtl_state_cache.mm
r277741 r281160 1042 1042 // Create pipeline state 1043 1043 NSError *err = nil; 1044 id<MTLRenderPipelineState>newState =1045 [metalDevice newRenderPipelineStateWithDescriptor:objCDesc error:&err];1044 auto newState = 1045 adoptObjCObj([metalDevice newRenderPipelineStateWithDescriptor:objCDesc error:&err]); 1046 1046 if (err) 1047 1047 { … … 1050 1050 } 1051 1051 1052 return [newState ANGLE_MTL_AUTORELEASE];1052 return newState; 1053 1053 } 1054 1054 } … … 1234 1234 // Convert to Objective-C desc: 1235 1235 NSError *err = nil; 1236 id<MTLComputePipelineState>newState =1237 [metalDevice newComputePipelineStateWithFunction:computeFunction error:&err];1236 auto newState = 1237 adoptObjCObj([metalDevice newComputePipelineStateWithFunction:computeFunction error:&err]); 1238 1238 if (err) 1239 1239 { … … 1242 1242 } 1243 1243 1244 return [newState ANGLE_MTL_AUTORELEASE];1244 return newState; 1245 1245 } 1246 1246 }
Note:
See TracChangeset
for help on using the changeset viewer.