如何计算 HLSL 中的寄存器数量?

发布于 2024-09-13 11:53:29 字数 399 浏览 3 评论 0原文

使用着色器模型 2.0,您可以拥有 256 个常量寄存器。我一直在研究各种着色器,并试图找出单个寄存器的构成是什么?

例如,在我的实例着色器中,我在函数外部的顶部声明了以下变量:

float4x4 InstanceTransforms[40];
float4 InstanceDiffuses[40];

float4x4 View;
float4x4 Projection;

float3 LightDirection = normalize(float3(-1, -1, -1));
float3 DiffuseLight = 1;
float3 AmbientLight = 0.66; 

float Alpha;

texture Texture;

我消耗了多少个寄存器?我如何计算它们?

With shader model 2.0, you can have 256 constant registers. I have been looking at various shaders, and trying to figure out what constitutes a single register?

For example, in my instancing shader, I have the following variables declared at the top, outside of functions:

float4x4 InstanceTransforms[40];
float4 InstanceDiffuses[40];

float4x4 View;
float4x4 Projection;

float3 LightDirection = normalize(float3(-1, -1, -1));
float3 DiffuseLight = 1;
float3 AmbientLight = 0.66; 

float Alpha;

texture Texture;

How many registers have I consumed? How do I count them?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

无人问我粥可暖 2024-09-20 11:53:29

每个常量寄存器都是一个float4

float3float2float 将分别分配整个寄存器。 float4x4 将使用 4 个寄存器。数组将简单地将分配的寄存器数量乘以元素数量。编译器可能会自己分配一些寄存器作为各种计算中的常量。

真正了解着色器正在使用什么的唯一方法是对其进行反汇编。为此,您可能对我不久前提出的这个问题感兴趣: HLSL:在编译时强制执行常量寄存器限制

您可能还会发现这个值得一看:HLSL:未对齐/压缩浮点数的索引。它解释了为什么 40 个浮点数组将使用 40 个寄存器,以及如何让它使用 10 个寄存器。

您的纹理将使用纹理采样器(您有 16 个),而不是常量寄存器。

作为参考,以下是 ps_2_0 寄存器的列表< /a> 和 vs_2_0 寄存器

Each constant register is a float4.

float3, float2 and float will each allocate a whole register. float4x4 will use 4 registers. Arrays will simply multiply the number of registers allocated by the number of elements. And the compiler will probably allocate a few registers itself to use as constants in various calculations.

The only way to really tell what the shader is using is to disassemble it. To that end you may be interested in this question that I asked a while ago: HLSL: Enforce Constant Register Limit at Compile Time

You might also find this one worth a look: HLSL: Index to unaligned/packed floats. It explains why an array of 40 floats will use 40 registers, and how you can make it use 10 instead.

Your texture will use a texture sampler (you have 16 of these), not a constant register.

For reference, here are the list of ps_2_0 registers and vs_2_0 registers.

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