I am new to Metal. How many MTLRenderpassdescriptor we can create in a single Application any limit ?
I want to have three MTLRenderpassdescriptor is it possible. One I need to draw quads according to finger position. It is like Offscreen Rendering. There will be texture output.
I want to pass the output texture to another renderpass descriptor to process the color of it which is also similar to Offscreen Rendering.Here new output texture will be available
I want to present new output Texture to the screen. Is it Possible ? When I create three renderpass descriptors only two is available.
First offscreen rendering It works fine
let renderPass = MTLRenderPassDescriptor()
renderPass.colorAttachments[0].texture = ssTexture
renderPass.colorAttachments[0].loadAction = .clear
renderPass.colorAttachments[0].clearColor = MTLClearColorMake( 0.0, 0.0, 0.0, 0.0)
renderPass.colorAttachments[0].storeAction = .store
let commandBuffer = commandQueue.makeCommandBuffer()
var commandEncoder = commandBuffer?.makeRenderCommandEncoder(descriptor: renderPass)
for scene in scenesTool{
scene.render(commandEncoder: commandEncoder!)
}
commandEncoder?.endEncoding()
This renderpass descriptor is not available in Debug as well.
let renderPassWC = MTLRenderPassDescriptor()
renderPassWC.colorAttachments[0].texture = ssCurrentTexture
renderPassWC.colorAttachments[0].loadAction = .clear
renderPassWC.colorAttachments[0].clearColor = MTLClearColorMake( 0.0, 0.0, 0.0, 0.0)
renderPassWC.colorAttachments[0].storeAction = .store
let commandBufferWC = commandQueue.makeCommandBuffer()
let commandEncoderWC = commandBufferWC?.makeRenderCommandEncoder(descriptor: renderPassWC)
for scene in scenesWCTool{
print(" msbksadbdksabfkasbd")
scene.render(commandEncoder: commandEncoderWC!)
}
commandEncoderWC?.endEncoding()
Third Renderpass Descriptor is working Fine.
let descriptor = view.currentRenderPassDescriptor
commandEncoder = commandBuffer?.makeRenderCommandEncoder(descriptor: descriptor!)
for x in canvasTemporaryScenes{
x.updateCanvas(texture: ssTexture!)
x.render(commandEncoder: commandEncoder!)
}
commandEncoder?.endEncoding()
guard let drawable = view.currentDrawable else { return }
commandBuffer?.present(drawable)
commandBuffer?.commit()
commandBuffer?.waitUntilCompleted()
MTLRenderPassDescriptor
objects are cheap to create, unlike some other kinds of objects in Metal (e.g. pipeline state objects). You are expected to create descriptors any time you need them. You don't need to keep them for a long period of time. Just recreate them each time you are going to create a render command encoder. For example, creating multiple render pass descriptors per frame is perfectly normal. There's no specific limit on the number you can create.
I have no idea what you mean by "When I create three renderpass descriptors only two is available" and "This renderpass descriptor is not available in Debug". What do you mean by "available" in these sentences? Explain exactly what results you want and expect and what's actually happening that's different than that.