Сбой валидации API металла - PullRequest
0 голосов
/ 27 мая 2018

Я написал следующий код для реализации аддитивного смешивания для закадрового рендеринга в текстуру Metal, но он падает, если включена проверка API 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);

Что не так в моем коде?

1 Ответ

0 голосов
/ 28 мая 2018

Хорошо, я нашел решение.Решением было установить флаг использования текстуры 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)
...