         }
     }
     
-    func make_context(commandQueue: MTLCommandQueue, outputPremultiplied: Bool) -> CIContext? {
-        
-        cache.lck.lock()
-        defer { cache.lck.unlock() }
-        
-        if cache.pool[commandQueue] == nil {
-            cache.pool[commandQueue] = CIContextPool(commandQueue: commandQueue)
-        }
-        
-        return cache.pool[commandQueue]?.makeContext(colorSpace: colorSpace, outputPremultiplied: outputPremultiplied)
-    }
-    
-    func render(to texture: MTLTexture, commandBuffer: MTLCommandBuffer, bounds: Rect) {
-        
-        guard let renderer = self.make_context(commandQueue: commandBuffer.commandQueue, outputPremultiplied: colorSpace == nil) else { return }
-        guard let texture_renderer = colorSpace == nil ? renderer : self.make_context(commandQueue: commandBuffer.commandQueue, outputPremultiplied: true) else { return }
+    func render(to surface: IOSurfaceRef, bounds: Rect) {
+        
+        guard let renderer = pool.makeContext(colorSpace: colorSpace, outputPremultiplied: colorSpace == nil) else { return }
+        guard let texture_renderer = colorSpace == nil ? renderer : pool.makeContext(colorSpace: colorSpace, outputPremultiplied: true) else { return }
         let workingColorSpace = texture_renderer.workingColorSpace ?? CGColorSpaceCreateDeviceRGB()
         
         guard let minX = Int(exactly: floor(bounds.minX)) else { return }

        
        let lck = SDLock()
        
        var pool = WeakDictionary<MTLCommandQueue, CIContextPool>()
        
        var table: [Block: CIImage] = [:]
        
        subscript(block: Block) -> CIImage? {

    }
}

private class TiledCacheKernel: CIImageProcessorKernel {
    
    fileprivate struct Info {
        
        let image: CIImage
        let blockSize: Int
        let maxBlockSize: Int
        
        let colorSpace: ColorSpace<RGBColorModel>?
        
        let cache = Cache()
        let pool = CIContextPool()
    }
    
    override class func process(with inputs: [CIImageProcessorInput]?, arguments: [String : Any]?, output: CIImageProcessorOutput) throws {
        guard let info = arguments?["info"] as? Info else { return }
        info.render(to: output.surface, bounds: Rect(output.region))
    }
}

extension TiledCacheKernel.Info {
    
    struct Block: Hashable {
