【问题标题】:Metal kernel function is missing buffer binding to change with time?金属核函数缺少随时间变化的缓冲区绑定?
【发布时间】:2019-04-16 13:54:00
【问题描述】:

我开发了一个 iOS 金属相机应用,但出现错误:

Compute Function(kernel_function): missing buffer binding at index 0 for timeDelta[0].

内核代码如下:

kernel void kernel_function(
         texture2d<float, access::sample> inTexture [[texture(0)]],
         texture2d<float, access::write> outTexture [[texture(1)]],
         const device float *timeDelta [[buffer(0)]],
         uint2 gid [[thread_position_in_grid]],
         uint2 tpg [[threads_per_grid]])
{

    float time = timeDelta[0];
    .......

问题似乎是timeDelta 错过了缓冲区绑定。如果我删除 timeDelta[0] 并设置

float time = 1.0

没有错误,应用程序可以流畅运行。但是屏幕效果是固定的画面而不是动画。所以timeDelta就是让效果随时间变化成为一个视频。有没有人知道如何在内核函数上应用时间或在 iOS Metal 中绑定 timeDelta 缓冲区来解决错误?非常感谢。

【问题讨论】:

    标签: ios swift metal


    【解决方案1】:

    在您的应用代码中,您没有调用setBuffer()setBytes()MTLComputeCommandEncoder 上的索引为 0。您的应用没有为着色器提供它需要的缓冲区。

    顺便说一句,您应该为timeDelta 使用constant 地址空间,而不是device。另外,假设只有一个值,不要使用数组语法,使用引用语法。所以:

         constant float &timeDelta [[buffer(0)]],
    

    只需在代码中直接使用timeDelta。 (无需[0] 或声明本地副本time。)

    【讨论】:

      【解决方案2】:

      感谢 Ken Thomases 的回答,您对我帮助很大。我已经通过添加代码解决了这个问题

      computeEncoder.setBytes(&amp;timing, length: MemoryLayout&lt;Float&gt;.size, index: 0)

      timing 是一个随机浮点数,每次更改computeEncoder 的字节以创建我喜欢的动画。希望我的问题能帮助任何有同样问题的人。谢谢大家。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-06-15
        • 2017-03-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-07-20
        相关资源
        最近更新 更多