VVMetalKit is a framework that contains a couple basic Metal-based utilities I use for the various projects I work on. The pool for recycling textures and buffers is the main feature offered by this framework- most of the other classes are intended to simplify workflows around rendering to, populating, converting, or displaying textures.
RenderPropertiesis a global singleton for conveniently storing/retrieving values you'll use frequently. This is the first thing you'll want to configure if you're using this framework.VVMTLPoolis a texture and buffer pool- recycling textures and buffers is significantly faster than trashing and re-creating them every time you need one. If you're working with Metal textures/buffers, this is probably the second thing you'll want to create.VVMTLTextureImage-protocolis a protocol/class that describes a poolable image in a Metal texture. Instances of this class always come fromVVMTLPool. The texture may or may not be backed by either a CPU-based resource or a GPU-based resource, depending on how the texture/image was created by the pool.VVMTLBuffer-protocolis a protocol/class that describes a poolable buffer accessible to Metal. Instances of this class always come fromVVMTLPool. The buffer may or may not be backed by shared memory, depending on how it was created by the pool.VVMTLTextureImageViewis a high-level NSView subclass that uses Metal to display aVVMTLTextureImage-protocolas large as possible without cropping. Under the hood, it usesCustomMetalView, which is an NSView that uses Metal to draw its contents- kind of likeMTKView, which makes it more configurable...
VVMTLSceneis a superclass that contains a number of properties and methods used to "render content to a texture". You probably won't work with it directly, but will instead want to subclass one of its subclasses:VVMTLComputeSceneis a subclass of VVMTLScene that is used to perform compute-based rendering operations (id<MTLComputeCommandEncoder>). This class is intended to be subclassed-CopierMTLSceneis one such example.VVMTLOrthoRenderSceneis a subclass of VVMTLRenderScene that is used to perform orthographic render-to-texture operations usingid<MTLRenderCommandEncoder>. This class is intended to be subclassed-CMVMTLDrawObjectSceneis one such example.VVMTLPerspRenderSceneis a subclass of VVMTLRenderScene similar that performs non-orthographic render-to-texture operations usingid<MTLRenderCommandEncoder>. This class is also intended to be subclassed.CIMTLSceneis a subclass ofVVMTLSceneand a convenient way to renderCIImageinstances to texture/images.CopierMTLSceneis a subclass ofVVMTLComputeSceneand a convenient way to copy a texture by running it through a compute shader, while optionally resizing the image using different sizing modes (fit/fill/copy).CMVMTLDrawObjectis intended to simplify the process of drawing 2D shapes to textures- it encodes draw commands to geometry buffers which can be executed in arbitrary render contexts.CMVMTLDrawObjectSceneis a companion object- a subclass ofVVMTLScenethat allows you to render one or more draw objects to a texture.CMVMTLDrawObjectViewis another companion object that renders a draw object directly to a Metal view (it doesn't render to a texture).VVMTLTextureLUT-protocolis a protocol/class for a poolable, texture-backed LUT you can fetch fromVVMTLPool.VVMTLTimestampis a class that is used to timestamp objects vended byVVMTLPool.VVMTLUtilities.hcontains a number of handy functions, particularly for boucing CGImageRefs to VVMTLTextureImages and vice versa.AAPLMathUtilties.his provided by Apple, and contains a bunch of handy general-purpose math functions suited for using matrices to manipulate geometry.CIImageAdditions.his aCIImageclass addition that adds a strong ref toCIImageinstances that retains aVVMTLTextureImage-protocolfor the lifetime of theCIImage.SwizzleMTLSceneis a class that uses Metal compute to do pixel format conversion on the GPU.
Documentation is provided in Apple's "DocC" format- it's also documented heavily with traditional inline comments.
This is all BSD licensed, you can do whatever you want with it and feel good about yourself! If you have any ideas for improvements (or you find any bugs or problems), please open an issue and let me know.