我有一個包含以下代碼的 HLSL 檔案:
struct particle
{
float2 pos;
float next_pos;
float angle;
};
particle nearby[32];
float angles[32];
for (uint i = 0; i < number_of_particles; i )
{
if ((particle_buffer[i].pos.y <= pos.y sight && particle_buffer[i].pos.y >= pos.y - sight) && (particle_buffer[i].pos.x <= pos.x sight && particle_buffer[i].pos.x >= pos.x - sight))//is it within sight square
{
nearby[i] = particle_buffer[i];
count ;
}
if (count >= 32)
{
break;
}
}
for (uint j = 0; j < count; j )
{
angles[j] = atan((pos.y - nearby[j].pos.y) / (pos.x - nearby[j].pos.x)); //angle in radians from current to next particle converted to degrees
}
和行:
nearby[i] = particle_buffer[i];
angles[j] = atan((pos.y - nearby[j].pos.y) / (pos.x - nearby[j].pos.x)); //angle in radians from current to next particle converted to degrees
兩者都對 L 值和陣列參考拋出相同的錯誤:
Shader warning in 'hlsl_file': array reference cannot be used as an l-value; not natively addressable, forcing loop to unroll at kernel move at hlsl_file.compute(line_num) (on d3d11)
我查看了 Microsoft 檔案和其他一些論壇,但我不了解許多解決方案,并且大多數答案都是針對頂點著色器而不是像我這樣的計算著色器。我能做出的最好猜測是,這是因為陣列在分配給另一個陣列時不能接受不同的索引輸入,但我完全不確定。
編輯:在統一論壇上進一步了解之后,對于某些硬體,您可以通過嘗試使用不是回圈變數(i 或 j)的索引變數來尋址回圈內的陣列來獲得此錯誤,我的代碼不這樣做,但也許它是相關的?
uj5u.com熱心網友回復:
我最終只使用 aRWStructuredBuffer而不是陣列,一切都完美無缺。不確定這是否有效。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/405093.html
標籤:
