On Monday 02 June 2008 12:04:54 Stefan Dösinger wrote:
Am Montag, 2. Juni 2008 11:57:21 schrieb Ivan Gyurdiev:
The patch being reverted seems interesting - it basically undoes a prior effort to get local constants into the same namespace as global ones due to relative addressing. I assume this is done for performance reasons, is this correct ? I see your patch is special-case disabled in the case of relative addressing. Do we really want to support multiple constant loading code paths for performance savings ?
Yes, it is for performance reasons, and yes, we want the multiple paths. It may be a small, non-algorithmic improvement, but those small improvements are where you get the performance from in 3D rendering.
The reason for this is not only avoiding reloading the local constants each shader change or constant change, but by moving the local constants away from the global constant space we don't have to reload unchanged global constants due to a local constant change.
On MacOS I achived a 5-15% performance gain with those constant loading optimizations, depending on the app, this is quite a lot. On the Linux Nvidia driver it was smaller, around 2-3% because the constant loading seems to be more efficient there.
The shader compiler can also do better optimization with hard-coded constants (particularly if the constants are 0 or 1). I've seen the nvidia-compiler remove entire code paths because of this in a hl2-shader.