I understand why the ternary operator branches on the GPU if there is any in-line computation, like:
// Branching on the (value+1)! float value = 3; value = (value < 4) ? (value) : (value+1);
but.. if the ternary operator is literally switching between two variables should it necessarily branch?
// Why should this branch? float value = 3; float valuePlus = value + 1; value = (value < 4) ? value : valuePlus; // It should be equivalent to: float value = 3; float valuePlus = value + 1; float values; values = value; values = valuePlus; int valueIndex = (int)(value < 4); value = values[valueIndex]; // And no branching!
At least in my head it should just be an address offset between two values.
I know this is a nitpicky branching concern, but it's an interesting mini-optimization depending on the usage.
Does anyone know if GPU drivers detect and make this sort of optimization or is this a non-concern?