2

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;
}

しかし、それを使用するカーネル関数をビルドすると、エラーが発生します。何か案は?

4

1 に答える 1

4

Metal シェーディング言語は C++ 11 に基づいていますが、いくつかの特定の拡張機能と制限があります。制限の 1 つは、再帰的な関数呼び出しが許可されていないことです。したがって、短い答えはノーです。これを行うことはできません。

どの程度変更される可能性があるか分からないので、相違点の完全なリストには貼り付けませんが、Apple の Metal Shading Language Guide のセクション「Metal and C++ 11」で説明されています。

于 2015-01-27T20:45:26.310 に答える