• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

iOS Metal Swift newComputePipelineStateWithFunction 不工作错误

[复制链接]
菜鸟教程小白 发表于 2022-12-11 16:38:56 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

我刚刚开始在 Swift 中使用 Metal 来尝试在 GPU 上进行一些并行计算,但我在使用 newComputePipelineStateWithFunction 时遇到了一些问题。我查看了多个网站,例如 Apple's Documentation for Data-Parallel Compute Processing但我也遇到了错误。

这是我目前遇到的错误:

Incorrect argument label in call (have '_:error:', expected '_:completionHandler:')

我尝试用完成处理程序替换“错误”,但在那里也遇到了困难。提前致谢。这是我的代码:

import UIKit
import Metal

class ViewController: UIViewController {

    var device: MTLDevice! = nil
    var defaultLibrary: MTLLibrary! = nil
    var thefunc: MTLFunction! = nil
    var pipelineState: MTLComputePipelineState!
    var commandQueue: MTLCommandQueue! = nil

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.

        setupMetal()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }



    func setupMetal()
    {
        // Our default MTLDevice
        device = MTLCreateSystemDefaultDevice()
        defaultLibrary = device.newDefaultLibrary()
        commandQueue = device.newCommandQueue()

        // Define the kernel function
        let kernelFunction: MTLFunction = defaultLibrary.newFunctionWithName("particleRendererShader")!

        // Define the pipeline state
        let pipelineState: MTLComputePipelineState = device.newComputePipelineStateWithFunction(kernelFunction, error: nil)

        // Define the command buffer
        let commandBuffer: MTLCommandBuffer = commandQueue.commandBuffer()

        // Define the command encoder
        let commandEncoder: MTLComputeCommandEncoder = commandBuffer.computeCommandEncoder()
        commandEncoder.setComputePipelineState(pipelineState)



        // thefunc = library.newFunctionWithName("filter_main");
        // filterState = device.newComputePipelineStateWithFunction(thefunc, error: nil);
        // let kernelFunction = library.newFunctionWithName("filter_main")
        // pipelineState = device.newComputePipelineStateWithFunction(kernelFunction!, error: nil)



        // do {
        //     try pipelineState = device.newComputePipelineStateWithDescriptor(pipelineStateDescriptor)
        // } catch _ {
        //     print("Failed to create pipeline state, error")
        // }

    }

}



Best Answer-推荐答案


我认为你需要:

device.newComputePipelineStateWithFunction(function) { (state:MTLComputePipelineState?, error:NSError?) in

    }

关于iOS Metal Swift newComputePipelineStateWithFunction 不工作错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37605155/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap