簡體   English   中英

金屬內核功能缺少緩沖區綁定以隨時間變化嗎?

[英]Metal kernel function is missing buffer binding to change with time?

我已經開發了一個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緩沖區以解決錯誤? 非常感謝。

在您的應用程序代碼中,您沒有在MTLComputeCommandEncoderMTLComputeCommandEncoder索引為0的setBuffer()setBytes() 您的應用程序沒有為着色器提供所需的緩沖區。

順便說一句,您應該為timeDelta使用constant地址空間,而不是device 另外,假設只有一個值,請不要使用數組語法,而應使用引用語法。 所以:

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

並直接在代碼中直接使用timeDelta (不需要[0]或聲明本地副本time 。)

感謝Ken Thomases的回答,您對我有很大幫助。 我已經通過添加代碼解決了這個問題

computeEncoder.setBytes(&timing, length: MemoryLayout<Float>.size, index: 0)

timing是一個隨機浮點數,每次更改我自己喜歡的動畫時都會更改computeEncoder的字節。 希望我的問題對任何有相同問題的人有所幫助。 感謝大家。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM