Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 多采样离屏渲染_Ios_Swift_Metal_Metalkit - Fatal编程技术网

Ios 多采样离屏渲染

Ios 多采样离屏渲染,ios,swift,metal,metalkit,Ios,Swift,Metal,Metalkit,我画了一个四边形并添加了纹理,画了一个小四边形并添加了纹理。当样本数为4时,当添加小四元时,我得到以下错误。当样本数为1时,工作正常 Execution of the command buffer was aborted due to an error during execution. Ignored (for causing prior/excessive GPU errors) (IOAF code 4) 如何使用样本计数4 guard let drawable = view.curre

我画了一个四边形并添加了纹理,画了一个小四边形并添加了纹理。当样本数为4时,当添加小四元时,我得到以下错误。当样本数为1时,工作正常

Execution of the command buffer was aborted due to an error during execution. Ignored (for causing prior/excessive GPU errors) (IOAF code 4)
如何使用样本计数4

guard let drawable = view.currentDrawable else { return }

let textureDescriptor = MTLTextureDescriptor()

textureDescriptor.textureType = MTLTextureType.type2DMultisample
textureDescriptor.width = drawable.texture.width
textureDescriptor.height = drawable.texture.height
textureDescriptor.pixelFormat = .bgra8Unorm
textureDescriptor.storageMode = .shared
 textureDescriptor.sampleCount = 4

textureDescriptor.usage = [.renderTarget, .shaderRead]
let sampleTexture = device.makeTexture(descriptor: textureDescriptor)


let renderPass = MTLRenderPassDescriptor()
renderPass.colorAttachments[0].texture = sampleTexture
renderPass.colorAttachments[0].resolveTexture = outTexture
renderPass.colorAttachments[0].loadAction = .clear
renderPass.colorAttachments[0].clearColor =
    MTLClearColor(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0)
 renderPass.colorAttachments[0].storeAction = .multisampleResolve

let commandBuffer = commandQueue.makeCommandBuffer()

let semaphore = inFlightSemaphore

commandBuffer?.addCompletedHandler { (_ commandBuffer)-> Swift.Void in
        semaphore.signal()
}

var commandEncoder = commandBuffer?.makeRenderCommandEncoder(descriptor: renderPass)

for scene in scenes {
    scene.render(commandEncoder: commandEncoder!)
}

commandEncoder?.endEncoding()


let descriptor = view.currentRenderPassDescriptor
commandEncoder = commandBuffer?.makeRenderCommandEncoder(descriptor: descriptor!)



for x in canvasScenes{
    x.updateCanvas(texture: sampleTexture!)
    x.render(commandEncoder: commandEncoder!)
}

commandEncoder?.endEncoding()


commandBuffer?.present(drawable)
commandBuffer?.commit()
commandBuffer?.waitUntilCompleted()

这是我的设置屏幕外渲染与多采样。我也使用深度纹理。下面是关于多重采样的小说明


如果使用MSAA绘制(即,渲染管道状态具有
sampleCount
>0),则必须满足以下条件:(1)渲染过程描述符颜色附件必须设置类型为
type2D
resolveTexture
;(2) 设置为颜色附件的
纹理的纹理必须是
类型。type2DMultisample
;(3)其
sampleCount
必须与渲染管道状态匹配。就我所见,在您发布的代码中没有一个是正确的,尽管这应该被验证层捕获。(是否在启用验证的情况下运行?)金属验证I已禁用。禁用时,我可以绘制一个四元错误出现在第二个四元图形中。Yh如果验证启用错误comes@warrenm我让textureDescriptors纹理类型转换为2D Multisample类型,样本数为4,并将纹理解析为outTexture类型MTLTexture的变量,和renderpass描述符将操作存储到multisample resolve当我这样做时,我收到以下错误消息失败断言'MTLRenderPassDescriptor MTLStoreActionMultisampleResolve存储操作需要解析纹理'textureDescriptor.textureType=MTLTextureType.type2DMultisample。textureDescriptor.sampleCount=4 renderPass.colorAttachments[0]。resolveTexture=outTexture。renderPass.colorAttachments[0]。storeAction=.multisampleResolve。这些是我在上述代码中所做的更改,并收到上述错误消息
    let offscreenTextureDescriptor = MTLTextureDescriptor()
    offscreenTextureDescriptor.width = size.width
    offscreenTextureDescriptor.height = size.height
    offscreenTextureDescriptor.depth = size.depth
    offscreenTextureDescriptor.pixelFormat = RenderPixelFormat.offscreen.rawValue.mtlPixelFormat()
    offscreenTextureDescriptor.textureType = .type2DMultisample
    offscreenTextureDescriptor.storageMode = .shared
    offscreenTextureDescriptor.usage = [.renderTarget, .shaderRead, .shaderWrite, .pixelFormatView]
    offscreenTextureDescriptor.sampleCount = 4

    self.offScreenTexture = device.makeTexture(descriptor: offscreenTextureDescriptor)

    offscreenTextureDescriptor.textureType = .type2D
    offscreenTextureDescriptor.sampleCount = 1
    offscreenTextureDescriptor.usage = [.shaderWrite]

    self.resolveOffScreenTexture = device.makeTexture(descriptor: offscreenTextureDescriptor)

    let depthTextureDescriptor = MTLTextureDescriptor.texture2DDescriptor(pixelFormat: .depth32Float, width: self.offScreenTexture.width, height: self.offScreenTexture.height, mipmapped: false)
    depthTextureDescriptor.usage = [.renderTarget, .shaderRead, .shaderWrite, .pixelFormatView]
    depthTextureDescriptor.textureType = .type2DMultisample
    depthTextureDescriptor.storageMode = .private
    depthTextureDescriptor.resourceOptions = [.storageModePrivate]
    depthTextureDescriptor.sampleCount = 4

    let depthAttachementTexureDescriptor = MTLRenderPassDepthAttachmentDescriptor()
    depthAttachementTexureDescriptor.clearDepth = 1.0
    depthAttachementTexureDescriptor.loadAction = .clear
    depthAttachementTexureDescriptor.storeAction = .store
    depthAttachementTexureDescriptor.texture = device.makeTexture(descriptor: depthTextureDescriptor)

    let renderPassDescriptor = MTLRenderPassDescriptor()
    renderPassDescriptor.colorAttachments[0].texture = self.offScreenTexture
    renderPassDescriptor.colorAttachments[0].resolveTexture = self.resolveOffScreenTexture
    renderPassDescriptor.colorAttachments[0].clearColor = MTLClearColorMake(0, 0, 0, 1)
    renderPassDescriptor.colorAttachments[0].loadAction = .clear
    renderPassDescriptor.colorAttachments[0].storeAction = .multisampleResolve
    renderPassDescriptor.depthAttachment = depthAttachementTexureDescriptor
    self.renderPassDescriptor = renderPassDescriptor