I'm trying to create a custom Metal-based visual effect as a UIView to be used inside an existing UIKit-based interface. (An example might be a view that applies a blur effect to what's behind it.) I need to capture the MTLTexture of what's behind the view so that I can feed it to MTLRenderCommandEncoder.setFragmentTexture(_:index:). Can someone show me how or point me to an example? Thanks!
For simpler effects like blur you may want to consider UIVisualEffect, and UIBlurEffect in particular.
Otherwise, the approach above is viable for compositing but costly. We recommend trying it and profiling the result to see if it's within your performance budget.