限制符/关键字“线程”是什么平均金属(MSL)函数的末端?

发布于 2025-02-13 08:13:50 字数 1093 浏览 0 评论 0原文

我如何理解关键字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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

本宫微胖 2025-02-20 08:13:50

金属支持参数地址空间上的额外过载。在当前对象(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):

enter image description here

from 1.4.1 https://developer.apple.com/metal/Metal-Shading-Language-Specification.pdf

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文