比較2D float4數組的計算著色器紋理


3

我想知道使用浮點紋理作為2D float4數組與僅傳遞2D float4數組之間在性能上有區別嗎?

2D浮點數組消除了進行紋理查找以獲取顏色值的需要,但是我不確定紋理是否可以在GPU上獲得某種性能提升,而數組卻不能歸因於GPU可以進行的明智優化。

1

It depends on what you’re doing. If any given thread of your shader is working with data from multiple nearby pixels, like by sampling from fractional between-pixel locations or doing some calculation involving a pixel’s immediate neighbors, then you should probably use a texture: the GPU can do some caching and even load multiple values in a single operation in that case. If your threads are more independent and working on individual values, an array is fine.