Gallium Nine improvement: reduce overhead of fixed function rendering
Here is a list of improvements a contributor can make to improve fixed function rendering on nine.
Fixed function is mainly used for light rendering, or old games, so there hasn't been a huge interest in optimizing it so far.
Here is basically how it is handled right now: Whenever fixed function should be used for a draw call, many rendering states affecting ff are read in order to produce a unique key describing what the shader should do. The shader is build once, and after when we see the key again, the previously compiled shader is reused. Then, rendering states are checked to see which family of states that fill the shader constants were updated. According to that, a table containing all the shader constants needed is updated. In all cases, the whole set of shader constants are uploaded to GPU.
The advantage of this approach is maintainability: a lot of rendering states can affect fixed function, and just updating all the time avoided to maintain any logic related to that. The disadvantage is that any draw call using ff triggers a complete logic (the key computation) and bandwidth was (whole set of shader constants uploaded). The computation is occuring on the secondary thread, so fortunately it's not too bad.
To improve the situation, here is what could be done:
. Similar to what is done for programmable shaders, the list of constants actually used by the shader could be produced during the first production of the TGSI ff shader. Then the TGSI could be reproduced using shifted offsets for the constants in order to use a compacted set of constants. Then depending on the key, during shader constant upload we would extract the subset needed in a smaller table and upload this one.
. In order to reduce the time spent producing the key, one could precompute most of the key. In the functions that set the relevant states for ff, when needed functions could be called to update parts of the key. This avoid recomputing the whole key. To avoid maintainability difficulties and improve readability, it's better to cut the key in only a few well separated pieces.
. When setting a state relevant for ff shader constants, a function could be called to directly update the constant value at the right position in the table, rather than how we do now.