No one knows, but it seems a reasonable guess that cognition and consciousness co-evolved. Whether there can be unconscious organisms is an open question.
Most people think consciousness arose with the evolution of the nervous system.
For those are the only factors to which the Blind Watchmaker is responsive. No one knows. I happen to think consciousness just piggy-backed on cognition, because it cannot have an independent causal role. Probably all organisms with nervous systems are conscious. So is reproducing.