【发布时间】:2019-11-29 21:10:57
【问题描述】:
我确实有一个 Metal 渲染管道设置,它对渲染命令进行编码并在 texture: MTLTexture 对象上运行以加载和存储输出。这个texture 相当大,并且每个渲染命令只对整个纹理的一小部分进行操作。基本设置大致如下:
// texture: MTLTexture, pipelineState: MTLRenderPipelineState, commandBuffer: MTLCommandBuffer
// create and setup MTLRenderPassDescriptor with loadAction = .load
let renderPassDescriptor = MTLRenderPassDescriptor()
if let attachment = self.renderPassDescriptor?.colorAttachments[0] {
attachment.clearColor = MTLClearColorMake(0.0, 0.0, 0.0, 0.0)
attachment.texture = texture // texture size is rather large
attachment.loadAction = .load
attachment.storeAction = .store
}
// create MTLRenderCommandEncoder
guard let renderCommandEncoder = commandBuffer.makeRenderCommandEncoder(descriptor: renderPassDescriptor) else { return }
// limit rendering to small fraction of texture
let scissorRect = CGRect(origin: CGPoint.zero, size: 0.1 * CGSize(width: CGFloat(texture.width), height: CGFloat(texture.height))) // create rect begin small fraction of texture rect
let metalScissorRect = MTLScissorRect(x: Int(scissorRect.origin.x), y: Int(scissorRect.origin.y), width: Int(scissorRect.width), height: Int(scissorRect.height))
renderCommandEncoder.setScissorRect(metalScissorRect)
renderCommandEncoder.setRenderPipelineState(pipelineState)
renderCommandEncoder.setScissorRect(metalScissorRect)
// encode some commands here
renderCommandEncoder.endEncoding()
实际上会创建许多renderCommandEncoder 对象,每次只对一小部分纹理进行操作。 不幸的是,每次提交renderCommandEncoder 时都会加载整个纹理并存储在最后,这是由renderPassDescriptor 指定的,因为它的colorAttachment loadAction 和@987654328 的相应设置@。
我的问题是:
是否可以将加载和存储过程限制在texture 的区域内?(以避免浪费计算时间来加载和存储大量只需要一小部分时的纹理)
【问题讨论】: