Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/122.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 金属API验证崩溃_Ios_Opengl Es_Metal - Fatal编程技术网

Ios 金属API验证崩溃

Ios 金属API验证崩溃,ios,opengl-es,metal,Ios,Opengl Es,Metal,我编写了以下代码来实现对金属纹理的屏幕外渲染的添加混合,但如果启用了金属API验证,则会崩溃: validateRenderPassDescriptor:487: failed assertion `Texture at colorAttachment[0] has usage (0x02) which doesn't specify MTLTextureUsageRenderTarget (0x04)' 代码如下: let renderPipelineDescriptorGreen = MT

我编写了以下代码来实现对金属纹理的屏幕外渲染的添加混合,但如果启用了金属API验证,则会崩溃:

validateRenderPassDescriptor:487: failed assertion `Texture at colorAttachment[0] has usage (0x02) which doesn't specify MTLTextureUsageRenderTarget (0x04)'
代码如下:

let renderPipelineDescriptorGreen = MTLRenderPipelineDescriptor()
renderPipelineDescriptorGreen.vertexFunction = vertexFunctionGreen
renderPipelineDescriptorGreen.fragmentFunction = fragmentFunctionAccumulator
renderPipelineDescriptorGreen.colorAttachments[0].pixelFormat = .bgra8Unorm
renderPipelineDescriptorGreen.colorAttachments[0].isBlendingEnabled = true
renderPipelineDescriptorGreen.colorAttachments[0].rgbBlendOperation = .add
renderPipelineDescriptorGreen.colorAttachments[0].sourceRGBBlendFactor = .one
renderPipelineDescriptorGreen.colorAttachments[0]。destinationRGBBlendFactor=.one

我想要实现的就是添加颜色混合,类似于OpenGLES中的:

glBlendEquation(GL_FUNC_ADD);
glBlendFunc(GL_ONE, GL_ONE);
glEnable(GL_BLEND);

我的代码出了什么问题?

好的,我找到了解决方案。解决方案是在创建纹理时,除了(或根据使用情况,替代)shaderRead或shaderWrite之外,还设置纹理使用标志MTLTextureUsage.renderTarget:

        let textureDescriptor = MTLTextureDescriptor()
        textureDescriptor.textureType = .type3D
        textureDescriptor.pixelFormat = .bgra8Unorm
        textureDescriptor.width = 256
        textureDescriptor.height = 1
        textureDescriptor.usage = .renderTarget

        let texture = device.makeTexture(descriptor: textureDescriptor)

好的,我找到了解决方案。解决方案是在创建纹理时,除了设置纹理使用标志MTLTextureUsage.renderTarget之外(或根据使用情况,替代shaderRead或shaderWrite):

        let textureDescriptor = MTLTextureDescriptor()
        textureDescriptor.textureType = .type3D
        textureDescriptor.pixelFormat = .bgra8Unorm
        textureDescriptor.width = 256
        textureDescriptor.height = 1
        textureDescriptor.usage = .renderTarget

        let texture = device.makeTexture(descriptor: textureDescriptor)

您知道这个问题的答案–即如何修复验证崩溃–那么剩下什么呢?此外,纹理描述符
用法
可以包含多个用法值。您至少需要
.renderTarget
,但这不必是“代替”
.shaderRead
.shaderWrite
。它可以与它们结合使用。我不确定我写的OpenGLES代码是否完全等同于我上面写的金属代码行。我是否遗漏了什么,因为金属代码应该比OpenGLES更快,而不是更慢。我建议您提供并接受您自己对此问题的答案stion(关于验证崩溃)。也就是说,从问题中删除您的注释,并提供第一部分作为答案。然后,就混合配置的正确性提出一个新问题(如果它确实不能正常工作)。也许还有一个关于性能的问题。好的,我在这里发布了一个新问题-你知道这个问题的答案-即,如何修复验证崩溃-那么剩下什么呢?另外,纹理描述符
用法
可以包含多个用法值。你至少需要
。renderTarget
,但这不需要必须是“代替”
.shaderRead
.shaderWrite
。它可以与它们结合使用。我不确定我写的OpenGLES代码是否完全等同于我上面写的金属代码行。我是否遗漏了什么,因为金属代码应该比OpenGLES更快,而不是更慢。我建议您提供并接受您自己对此问题的答案stion(关于验证崩溃)。也就是说,从问题中删除注释,并提供第一部分作为答案。然后,就混合配置的正确性(如果它确实不能正常工作)提出一个新问题。也许还有一个关于性能问题。好的,我在这里发布了新问题-