在 HLSL 中初始化未知大小的数组
我有一个小型片段着色器,它对数组中的多个值进行操作,但是数组的大小存储在常量中。
该数组声明如下:
float4 colors[(blurRadius*2+1)*(blurRadius*2+1)];
然后我继续使用 for 循环为它们分配值
for(int i = -blurRadius; i<= blurRadius; i++)
{
for(int j = -blurRadius; j<=blurRadius;j++)
{
colors[j + blurRadius + ((i+blurRadius)*blurRadius)]=float4(0,0,0,0);
}
}
,但是,运行时代码返回以下编译器错误:
error X4000: variable 'colors' used without having been completely initialized
如何完全初始化一个我在 HLSL 中不知道大小的数组?
I have a small fragment shader that operates on a number of values in an array, however the size of the array is stored in a constant.
The array is declared as follows:
float4 colors[(blurRadius*2+1)*(blurRadius*2+1)];
and then I proceed to assign them values using a for loop
for(int i = -blurRadius; i<= blurRadius; i++)
{
for(int j = -blurRadius; j<=blurRadius;j++)
{
colors[j + blurRadius + ((i+blurRadius)*blurRadius)]=float4(0,0,0,0);
}
}
however, when run the code comes back with the following compiler error:
error X4000: variable 'colors' used without having been completely initialized
How do I completely initialize an array whose size I don't know in HLSL?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看来我今天有点白痴了。只要你的步幅正确,上面列出的方法就非常有效。
结果是:
没有寻址整个数组,因此当我尚未分配值时,其中一些数组后来被访问。
Seems I'm a bit of an idiot today. The method listed above works perfectly fine, as long as your stride is correct.
Turns out:
Doesn't address the whole array, so some of it was later being accessed when I'd yet to assign a value.