"Missing buffer binding" with MTLIndirectCommandBuffer

Hi! I am currently trying to solve an issue with my use of indirect command buffers and would appreciate your help. I have set up a minimal example project that encodes a draw call into the ICB on the CPU and then executes the commands of the ICB as part of the main render command encoder. In the corresponding fragment shader, I am reading a value from a buffer and simply returning it.

ICB setup:

indirectCommandBuffer = {
    let descriptor = MTLIndirectCommandBufferDescriptor()
    descriptor.commandTypes = [.draw]
    descriptor.inheritBuffers = false
    descriptor.inheritPipelineState = false
    descriptor.maxVertexBufferBindCount = 0
    descriptor.maxFragmentBufferBindCount = 1
    descriptor.maxKernelBufferBindCount = 0
    return device.makeIndirectCommandBuffer(descriptor: descriptor, maxCommandCount: 1, options: .storageModeShared)!
}()
        
indirectCommandBuffer.reset(0..<1)
let command = indirectCommandBuffer.indirectRenderCommandAt(0)
command.setFragmentBuffer(colorBuffer, offset: 0, at: 0)
command.setRenderPipelineState(mainRenderPipelineState)
command.drawPrimitives(.triangle, vertexStart: 0, vertexCount: 6, instanceCount: 1, baseInstance: 0)

Fragment shader:

fragment half main_fragment(constant float& color [[buffer(0)]]) {
    return half(color);
}

Execution:

let commandBuffer = commandQueue.makeCommandBuffer()!

let mainRenderPassDescriptor = MTLRenderPassDescriptor()
mainRenderPassDescriptor.colorAttachments[0].texture = mainTarget
mainRenderPassDescriptor.colorAttachments[0].loadAction = .clear
mainRenderPassDescriptor.colorAttachments[0].clearColor = MTLClearColor(red: 0, green: 0, blue: 0, alpha: 0)
mainRenderPassDescriptor.colorAttachments[0].storeAction = .store
        
let mainRenderCommandEncoder = commandBuffer.makeRenderCommandEncoder(descriptor: mainRenderPassDescriptor)!
mainRenderCommandEncoder.useResources([colorBuffer], usage: [.read], stages: [.fragment])
mainRenderCommandEncoder.executeCommandsInBuffer(indirectCommandBuffer, range: 0..<1)
mainRenderCommandEncoder.endEncoding()

commandBuffer.commit()

However, when I run the program with shader validation enabled, I get the following error:

Render Encoder "0x600000d1cc60" has missing Fragment Buffer (color) binding at index 0 for RenderPipelineState "Main".

Thank you for your help!

"Missing buffer binding" with MTLIndirectCommandBuffer
 
 
Q