限制符/关键字“线程”是什么平均金属(MSL)函数的末端?
我如何理解关键字thread
在金属着色器语言(MSL)函数中执行什么?我知道“必须使用地址空间属性来声明指针或对类型的图形或内核函数的所有参数”,并且thread
是这些adress空间之一。 线程
是指在此地址空间中分配的每个线程内存地址空间和变量,而不是其他线程。此外,参考文献说:“图形或内核函数内声明的变量分配在线程地址空间中。”。到目前为止,一切都很好。
现在,让我感到困惑的是,如果您查看标准库的签名,您会发现thread
也出现在成员函数的 end 上。 让我们从标准库中查看ray
struct ray
{
METAL_FUNC ray(float3 origin = 0.0f, float3 direction = 0.0f, float min_distance = 0.0f, float max_distance = INFINITY) thread
: origin(origin),
direction(direction),
min_distance(min_distance),
max_distance(max_distance)
{
}
METAL_FUNC ray(const thread ray &) thread = default;
METAL_FUNC thread ray &operator=(const thread ray &) thread = default;
float3 origin;
float3 direction;
float min_distance;
float max_distance;
};
例如
METAL_FUNC ray(const thread ray &) thread = default;
, (在同一通话线程中,对吗?)。 thread
在 the end 做什么?如果我们省略它会怎样?
另一方面,请参阅“默认复制分配运算符”。返回的射线引用在哪里?是在不同的线程地址空间中吗?
How can I understand what the keyword thread
does in a metal shader language (MSL) function? I know that "all arguments to a graphics or kernel function that are a pointer or reference to a type must be declared with an address space attribute" and that thread
is one of those adress spaces. thread
refers to the per-thread memory address space and variables allocated in this adress space and not visible to other threads. Moreover, the reference says that "Variables declared inside a graphics or kernel function are allocated in the thread address space.". So far so good.
Now, what confuses me is that if you look at the signatures of the standard library, you will find that thread
also appears at the end of member functions. For example, let's look a ray
from the standard library (METAL_FUNC
just means always inline):
struct ray
{
METAL_FUNC ray(float3 origin = 0.0f, float3 direction = 0.0f, float min_distance = 0.0f, float max_distance = INFINITY) thread
: origin(origin),
direction(direction),
min_distance(min_distance),
max_distance(max_distance)
{
}
METAL_FUNC ray(const thread ray &) thread = default;
METAL_FUNC thread ray &operator=(const thread ray &) thread = default;
float3 origin;
float3 direction;
float min_distance;
float max_distance;
};
For instance on the default copy constructor
METAL_FUNC ray(const thread ray &) thread = default;
The parameter argument is a const reference to a ray (in the same calling thread, right?). What does thread
at the end do? what happens if we omit it?
On the other hand, see the default copy assignment operator. Where does the returning ray reference live? is it in a different thread address space?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
金属支持参数地址空间上的额外过载。在当前对象(this)的成员函数之后指定它:
来自1.4.1 https://developer.apple.com/metal/Metal-Shading-Language-规格.pdf
Metal supports additional overloading on address spaces of argument. it is specified after member functions for current object(this):
from 1.4.1 https://developer.apple.com/metal/Metal-Shading-Language-Specification.pdf