IOSurface

RSS for tag

Share hardware-accelerated buffer data across multiple processes and frameworks using IOSurface.

Posts under IOSurface tag

6 Posts
Sort by:

Post

Replies

Boosts

Views

Activity

IOSurface objects aren't released in ScreenCaptureKit
I use ScreenCaptureKit, CoreVideo, CoreImage, CoreMedia frameworks to capture screenshots on macOS 14.0 and higher. Example of creating CGImageRef: CVImageBufferRef cvImageBufferRef = ..; CIImage* temporaryImage = [CIImage imageWithCVPixelBuffer:cvImageBufferRef]; CIContext* temporaryContext = [CIContext context]; CGImageRef imageRef = [temporaryContext createCGImage:temporaryImage fromRect:CGRectMake(0, 0, CVPixelBufferGetWidth(cvImageBufferRef), CVPixelBufferGetHeight(cvImageBufferRef))]; I have the next results of profiling with XCode Instruments Memory Leaks & Allocations: there is constantly increasing memory usage, but no memory leaks are detected, and there are many calls to create IOSurface objects, that have been never released. The most part of memory - All Anonymous VM - VM: IOSurface. The heaviest stack trace: [RPIOSurfaceObject initWithCoder:] [IOSurface initWithMachPort:] IOSurfaceClientLookupFromMachPort I don't have any of IOSurface objects created by myself. There are low-level calls to it. In Allocation List I can see many allocations of IOSurface objects, but there are no info about releasing it. Due to this info, how can I release them to avoid permanent increasing memory consumption?
2
0
385
May ’24
"IOSurface creation failed" drawing to CGContext
(more details on StackOverflow) I'm getting messages like the following, SOMETIMES, when I draw to a CGContext IOSurface creation failed: e00002c2 parentID: 00000000 properties: { IOSurfaceAddress = 5207703552; IOSurfaceAllocSize = 9461418; IOSurfaceCacheMode = 0; IOSurfaceName = CMPhoto; IOSurfacePixelFormat = 1246774599; } call to context.draw(): context.draw(photo.image, in: CGRect(x: 0, y: top, width: width, height: height), byTiling: false) The results are just fine, so the draw seems to be working. It also, most often, draws without producing this error, but it fails pretty often. I'm not sure where to begin looking to sort out what I might need to do differently to avoid this error message in the console. Complete code: import Foundation import SwiftUI func generateSpritesImage(thumbPhotos: [Photo], width: Int, filename: URL) -> [Int] { var indices = [Int]() let totalHeight = thumbPhotos.reduce(0) { $0 + $1.heightOfImage(ofWidth: width) } debugPrint("creating context") let context = CGContext(data: nil, width: width, height: totalHeight, bitsPerComponent: 8, bytesPerRow: 0, space: CGColorSpace(name: CGColorSpace.sRGB)!, bitmapInfo: CGImageAlphaInfo.noneSkipLast.rawValue)! var top = totalHeight for photo in thumbPhotos { let height = photo.heightOfImage(ofWidth: width) indices.append(top - totalHeight) top -= height debugPrint("drawing \(photo.filteredFileURL())") context.draw(photo.image, in: CGRect(x: 0, y: top, width: width, height: height), byTiling: false) } debugPrint("write jpeg") writeJpegFromContext(context: context, filename: filename) return indices } func writeJpegFromContext(context: CGContext, filename: URL) { let cgImage = context.makeImage()! let bitmapRep = NSBitmapImageRep(cgImage: cgImage) let jpegData = bitmapRep.representation(using: NSBitmapImageRep.FileType.jpeg, properties: [:])! try! jpegData.write(to: filename) } sample of output: "drawing 0002-_MG_8542.jpg" "drawing 0003-_MG_8545.jpg" "drawing 0004-_MG_8550.jpg" IOSurface creation failed: e00002c2 parentID: 00000000 properties: { IOSurfaceAddress = 5211357184; IOSurfaceAllocSize = 9983331; IOSurfaceCacheMode = 0; IOSurfaceName = CMPhoto; IOSurfacePixelFormat = 1246774599; } "drawing 0005-_MG_8555.jpg" IOSurface creation failed: e00002c2 parentID: 00000000 properties: { IOSurfaceAddress = 5221351424; IOSurfaceAllocSize = 10041215; IOSurfaceCacheMode = 0; IOSurfaceName = CMPhoto; IOSurfacePixelFormat = 1246774599; } "drawing 0006-_MG_8562.jpg" "drawing 0007-_MG_8563.jpg" IOSurface creation failed: e00002c2 parentID: 00000000 properties: { IOSurfaceAddress = 5376163840; IOSurfaceAllocSize = 10109756; IOSurfaceCacheMode = 0; IOSurfaceName = CMPhoto; IOSurfacePixelFormat = 1246774599; } "drawing 0008-_MG_8584.jpg" "drawing 0009-_MG_8618.jpg" IOSurface creation failed: e00002c2 parentID: 00000000 properties: { IOSurfaceAddress = 5394612224; IOSurfaceAllocSize = 8425564; IOSurfaceCacheMode = 0; IOSurfaceName = CMPhoto; IOSurfacePixelFormat = 1246774599; } "drawing 0010-_MG_8627.jpg" "drawing 0011-_MG_8649.jpg" "drawing 0012-_MG_8658.jpg" "drawing 0013-_MG_8665.jpg" "drawing 0014-_MG_8677.jpg" "drawing 0015-_MG_8675.jpg" "drawing 0016-_MG_8676.jpg" "drawing 0017-IMGP0873.jpg" "drawing 0018-_MG_8719.jpg" "drawing 0019-_MG_8743.jpg" ...
2
0
674
Jan ’24
IOSurface-based MTLTexture gets corrupted
I have this code to create an IOSurface from a bitmap image: auto src = loadSource32f(); // rgba 32-bit float image const auto desc = src->getDescriptor(); // metadata for that image auto pixelFmt = CGMTLBufferManager::getCVPixelFormat( desc.channelBitDepth, desc.channelOrder ); // returns proper `RGfA` int width = static_cast<int>( desc.width ); int height = static_cast<int>( desc.height ); int trowbytes = static_cast<int>( desc.trueRowbytes() ); // returns proper rowbytes value CFMutableDictionaryRef properties = CFDictionaryCreateMutable( kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks ); CFDictionarySetValue( properties, kIOSurfaceWidth, CFNumberCreate( kCFAllocatorDefault, kCFNumberIntType, &width ) ); CFDictionarySetValue( properties, kIOSurfaceHeight, CFNumberCreate( kCFAllocatorDefault, kCFNumberIntType, &height ) ); CFDictionarySetValue( properties, kIOSurfacePixelFormat, CFNumberCreate( kCFAllocatorDefault, kCFNumberIntType, &pixelFmt ) ); CFDictionarySetValue( properties, kIOSurfaceBytesPerRow, CFNumberCreate( kCFAllocatorDefault, kCFNumberIntType, &trowbytes ) ); NSDictionary *nsprops = ( __bridge NSDictionary * )properties; IOSurface *oSurface = [[IOSurface alloc] initWithProperties:nsprops]; CFRelease( properties ); ASSERT_TRUE( oSurface ); auto ioSurface = (IOSurfaceRef) oSurface; I tested that the pixels are properly written into the iosurface: // copy data to surface memcpy([oSurface baseAddress], src->getRawPtr(), src->getSizeInBytes()); auto surfPtr = (uint8_t*)[oSurface baseAddress]; // extract raw surface data and write it into a file saveOutputRaw(desc, surfPtr, getFileName("IOSurfaceTestSurfaceRaw")); And I see this: Now I want to create a MTLTexture based on the iosurface: // create texture auto fmt = IOSurfaceGetPixelFormat( ioSurface ); auto w = IOSurfaceGetWidth( ioSurface ); auto h = IOSurfaceGetHeight( ioSurface ); auto rowbytes = IOSurfaceGetBytesPerRow( ioSurface ); MTLTextureDescriptor *textureDescriptor = [MTLTextureDescriptor texture2DDescriptorWithPixelFormat:CGMTLBufferManager::getMTLPixelFormat( fmt ) width:w height:h mipmapped:NO]; textureDescriptor.usage = MTLTextureUsageShaderRead | MTLTextureUsageShaderWrite; textureDescriptor.storageMode = MTLStorageModeShared; auto device = MTLCreateSystemDefaultDevice(); id<MTLTexture> surfaceTex = [device newTextureWithDescriptor:textureDescriptor iosurface:ioSurface plane:0]; And now I want to test this: auto region = MTLRegionMake2D(0, 0, w, h); auto bufSize = [oSurface allocationSize]; // get texture bytes auto outBuf2 = std::vector<uint8_t>(bufSize); [surfaceTex getBytes:outBuf2.data() bytesPerRow:rowbytes fromRegion:region mipmapLevel:0]; // save to file saveOutputRaw(desc, outBuf2.data(), getFileName("IOSurfaceTestCreateTex")); // get bytes saveOutputRaw(desc, surfPtr, getFileName("IOSurfaceTestCreateRaw")); And I get this result: I also tried replaceRegion and blitEncoder copyFromTexture: toTexture: as well as managed texture with syncing, but the result is always the same - only the first 22 pixels get filled and the rest is transparent. I have no idea what I'm missing. Please help.
0
0
544
Jan ’24
Apple Scammed me
I purchase apple developer program membership i enrolled for it i paid to apple for 1 year membership they send me mail and showing my active subscription in Purchases and apple developer app also but they didn't give me appstoreconnect access what it is mean why i buy apple developer program membership ? because i want to publish my app on appstore i attached screenshot of proof that i have active membership but i didn't get access of appstoreconnect they didn't reply me on mail and on call i contacted apple developer support on call and vie email also they didn't give me any solution They not refunding my money they don't have me product for what i paid means Scam
0
0
428
Nov ’23
SceneKit leaks IOSurface memory after releasing diffuse contents
I've watched this issue for a long time but it seems this hasn't been fixed yet. My use case is to assign a UIView to the 'contents' variable of SCNMaterialProperty. It works without problem in terms of rendering, but when I assign 'nil' to the variable the allocated memory of IOSurface by SceneKit does not being destroyed I've searched about this and many other developers have been suffered by this issue. I did a 'Game Memory' profiling of my toy example and the allocated memory (134MB) by SceneKit hadn't been released after I've assigned nil. I'm sure I released every relavant UIViews and view controllers used for the 'contents'.
0
0
476
Oct ’23