BradLarson / GPUImage3

GPUImage 3 is a BSD-licensed Swift framework for GPU-accelerated video and image processing using Metal.
BSD 3-Clause "New" or "Revised" License
2.73k stars 342 forks source link

Is the project in a buildable state? #8

Closed isadon closed 5 years ago

isadon commented 6 years ago

I checked out master and tried buiding the iOS framework and am getting various build issues. Is the project in a buildable state?

BradLarson commented 6 years ago

Yes, it is. Make sure you are targeting an actual device or the Generic iOS Device build target. Metal is not supported in the iOS Simulator, and you have to use the camera for most of our current examples, so this needs to be run on a device.

Alternatively, you can try out the Mac FilterShowcase and other sample applications, which will run natively on your Mac, to get an idea of how this works. Almost all code is shared between iOS and Mac targets for the framework.

hggz commented 6 years ago

Im getting an exception when I attempt to launch the Mac filter show case app:

[MTLRenderPipelineDescriptorInternal setRasterSampleCount:]: unrecognized selector sent to instance 0x600000199d90

Seems to be happening line 56 of the MTLCommandBuffer file of the linked gpuimage framework because it can't recognize this property. Any thoughts off the top of your head why? (I'm just returning to your repos after a few years and am combing through your work in Swift. Very nice)

Temporarily removing the line from the packaged framework seems to work fine at first glance.

func generateRenderPipelineState(device:MetalRenderingDevice, vertexFunctionName:String, fragmentFunctionName:String, operationName:String) -> MTLRenderPipelineState {
    guard let vertexFunction = device.shaderLibrary.makeFunction(name: vertexFunctionName) else {
        fatalError("\(operationName): could not compile vertex function \(vertexFunctionName)")
    }

    guard let fragmentFunction = device.shaderLibrary.makeFunction(name: fragmentFunctionName) else {
        fatalError("\(operationName): could not compile fragment function \(fragmentFunctionName)")
    }

    let descriptor = MTLRenderPipelineDescriptor()
    descriptor.colorAttachments[0].pixelFormat = MTLPixelFormat.bgra8Unorm
    **descriptor.rasterSampleCount = 1**
    descriptor.vertexFunction = vertexFunction
    descriptor.fragmentFunction = fragmentFunction

    do {
        return try device.device.makeRenderPipelineState(descriptor: descriptor)
    } catch {
        fatalError("Could not create render pipeline state for vertex:\(vertexFunctionName), fragment:\(fragmentFunctionName), error:\(error)")
    }
}
BradLarson commented 6 years ago

@hggz - That's weird. What OS and Xcode version are you seeing this with?

We originally had sampleCount there instead of rasterSampleCount, but the header noted that the former had been deprecated in favor of the latter. However, it didn't have a hard deprecation notice on it yet, and that might not exist prior to High Sierra. I should be getting a warning about that, due to the older deployment target, but I don't think it was denoted with the proper availability markings.

Try switching rasterSampleCount to sampleCount and see if this works. If so, I'll swap it back in the code.