ARTICLE AD BOX
I have partially built this compute shader. However, I am not sure how to finish it.
import MetalKit import PlaygroundSupport guard let varDevice = MTLCreateSystemDefaultDevice() else { fatalError("GPU is not supported")} let varFrame = CGRect(x: 0, y: 0, width: 600, height: 800) let varView = MTKView(frame: varFrame, device: varDevice) varView.clearColor = MTLClearColor(red: 1, green: 1, blue: 0.8, alpha: 1) PlaygroundPage.current.liveView = varView let varCommandQueue = varDevice.makeCommandQueue()! let varShaders = """ #include <metal_stdlib> using namespace metal; kernel void hello_world (texture2d<float, access::write> output [[texture(0)]], uint2 Gid [[thread_position_in_grid]]) { if (Gid.x >= output.get_width() || Gid.y >= output.get_height()) { return; } output.write(float4(1, 0, 0, 1), Gid); } """ let varComputeShader = try! varDevice.makeLibrary(source: varShaders, options: nil).makeFunction(name: "hello_world") let varPipelineState = try! varDevice.makeComputePipelineState(function: varComputeShader!) guard let varCommandBuffer = varCommandQueue.makeCommandBuffer(), let varEncoder = varCommandBuffer.makeComputeCommandEncoder() else { fatalError() }The image contains what I want to achieve from this shader because right now the compute shader shows nothing:
Also, this may be important: -[_MTLCommandEncoder dealloc]:134: failed assertion `Command encoder released without endEncoding'

