Does XNA 4 fx compiler support static and/or dynamic branching and if not....

Started by
6 comments, last by danromeo 11 years, 12 months ago
Can't seem to find a straight forward answer to this anywhere: Does XNA 4 fx compiler support static and/or dynamic branching and if not how can I get branching working?

Thanks
Advertisement
Dynamic branching is supported as long as you use vs_3_0 and ps_3_0 shader profiles. Static branching is supported for vs_2_0 and up, and ps_2_a and up.
Note that the compiler tends to favour static branching, if the logic can be expressed in a static way and the instruction count doesn't skyrocket as a result.

It is possible to hint the compiler to use dynamic branching by using the [branch] attribute preceding your "if" statements. [flatten] attribute is also available to hint static branching. Loop and switch unrolling behavior can also be hinted by using similar (but different) attributes.

Niko Suni


[flatten] attribute is also available to hint static branching.


A static branch isn't a flattened branch, it's a branch on constant boolean register.
Ah, that is true.

Niko Suni

I have XNA 4 with ps 3.0 and vs 3.0. I see absolutely no performance difference even when exluding huge sections of code with dynamic branching. Any suggestions?
Could be for several reasons:

- Are you sure dynamic branching is being used? Check the assembly that is output (you can see this in PIX, for instance). For instance, if there are any tex2D instructions inside an if statement, you can't use dynamic branching.
- To see any performance improvement, large groups of pixels near each other all need to take the same branch.
- Finally, your performance bottleneck might not be your shader's instruction count at all, in which case your dynamic branching won't help.
Thank you all for the help.

This topic is closed to new replies.

Advertisement