簡體   English   中英

金屬ios中的遞歸

[英]Recursion in Metal ios

Metal着色語言是否支持遞歸? 我有代碼:

 Intersection traceScene(Ray ray, int step) {
    Intersection retIntersection = Intersection();
    Intersection i1 = trianglePrism.intersect(ray);
    Intersection i2 = image.intersect(ray);
    if (i1.intersect) {
        Ray newRay = Ray(i1.position, Refract(ray.direction, trianglePrism.normal, 0.71));
        return traceScene(newRay, step + 1);
    } else {
        if (i2.intersect) {
            return i2;
        } else {
            return Intersection();
        }
    }
    return retIntersection;
}

但是當我構建使用它的內核函數時,它會發生錯誤。 有任何想法嗎?

Metal着色語言基於C ++ 11,但具有一些特定的擴展和限制。 其中一個限制是不允許遞歸函數調用,所以簡短的答案是否定的,你不能這樣做。

我不會粘貼完整的差異列表,因為我不知道改變它的可能性有多少,但它們在Apple的Metal Shading語言指南的“Metal and C ++ 11”一節中有所介紹。

暫無
暫無

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

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