如何从着色器中访问大于32位的地址或索引?

huangapple go评论78阅读模式
英文:

How does a GPU access addresses or indices greater than 32 bit from the shader?

问题

以下是您要翻译的内容:

"让我们假设我在存储缓冲区中有一个结构体,或者根据您的API称之为其他名称,可以从着色器中访问。

struct SomeStructType
{
vec4;
};

我的存储缓冲区是上述结构体的数组:

SomeStructType big_array[];

由于在GPU着色器中,您通常只使用4字节类型,单精度浮点数和4字节整数,因此您可以使用整数(一个4字节或32位类型)访问数组,所以我可以访问的最高索引是2^32或大约42亿。

如果您有一个整数值,比如40亿,想要访问该数组,GPU需要获取的缓冲区地址以获取该结构/对象的索引是40亿 * sizeof(SomeStructType),即40亿 * 16 = 640亿。

这是否导致32位整数溢出?它是如何做到的?

如何在着色器中从更高的索引位置访问缓冲区?

鉴于GPU使用32位类型,类似缓冲器设备地址的东西是如何工作的?您能否解释一下?"

英文:

Let's just I have a struct in a storage buffer or whatever it's called depending on your API, accessed from the shader.

struct SomeStructType
{
    vec4;
};

My storage buffer is an array of the above struct:

SomeStructType big_array[];

Since in a GPU shader you only (mostly) use 4 byte types, single-precision floats and 4-byte ints, you access arrays with an int (a 4-byte or 32-bit type), so he highest index I could access is 2^32 or roughly 4.2 billion.

If you have integer value of say 4 billion, and you want to access that array, the buffer address that the GPU needs to fetch to fetch that index of that struct/object is 4 billion * sizeof(SomeStructType), which is 4 billion * 16 = 64 billion.

Does this lead to an overflow of a 32-bit integer? How does it do this?

How can you index into a buffer from the shader at a higher index than the maximum value of a 4 byte integer?

How does something like buffer device address work given that the GPU used 32-bit types? Could you please explain?

答案1

得分: 1

你的结论基于错误的前提。

自OpenGL 4.0以来,64位类型已成为GPU的必要功能,种类也越来越多。shaderInt64是Vulkan和GLSL的可选功能。如果硬件支持设备地址,那么它还会在着色器中支持其他所需的内部功能,以使设备地址在着色器中正常工作。

GPU不仅仅使用32位类型。

英文:

Your conclusion is drawn from a false premise.

64-bit types, of an increasing variety of kinds, have been a required feature of GPUs since OpenGL 4.0. shaderInt64 is an optional feature of Vulkan and GLSL. If the hardware support device addresses, then it also supports whatever else is needed internally to make device addresses work in shaders.

The GPU does not only use 32-bit types.

huangapple
  • 本文由 发表于 2023年6月26日 19:00:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/76556068.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定