在光线追踪负载中存储“ray_data”

Storage of `ray_data` in ray tracing payload

我目前正在使用 Metal 的光线追踪 API。我记得我可以将数据从相交函数传递到启动射线相交过程的计算内核。在重新观看 Sean James 的 WWDC 2020 演讲 Discover ray tracing with Metal(链接 here)后,我在 16:13 周围找到了相关部分,他在其中谈到了光线有效载荷。

但是,我很好奇这个有效负载在传递给交集函数时存储在哪里。在交集函数中用相关[[ payload ]]属性声明时,必须在ray_data地址space。根据金属着色语言规范(2.3 版),pg。 64,传递给交集函数的数据被复制到ray_data地址space,一旦交集函数returns被复制回来。然而,这并没有具体说明,例如,数据是存储在 tile 内存中(如 threadgroup 地址中的数据 space 是)还是存储在每线程内存中(thread地址 space)。视频也没有具体说明。

事实上,包含有效负载项的 intersect 函数(参见第 204 页)的声明位于 thread 地址 space(这是有道理的)

那么内核中thread地址space存储的数据复制的ray_data“版本”到哪里去了?

根据我在 Apple Developer Forums 上收到的答复,

The way the GPU stores the payload varies between device and there is no particular size. All we can really say is that cost scales roughly with the size so you should minimize that payload. If the payload gets too large you may run into a dramatic performance drop.