A fascinating question, but one which would easily trigger a flame war!
Spontaneously every population everywhere thought itself as 'different' [to clearly separate 'self' from 'non-self' is a basic requirement of Life] and automatically 'superior', the Sons of The Sun-God or whatever. But with *huge* differences when it came to practical application. Because the concept of 'race' was generally absent.
The Chinese always saw themselves as 'superior', but knew well China has be repeatedly invaded and that the current ruling class was made of half-breeds of the foreign invaders.
Many North American tribes saw themselves as 'superior', even the only 'true' humans, but they adopted in their tribe the 'best' of the enemy POW, and anyway took women of conquered tribes as wives.
The Romans thought they were chosen by the gods to lead humankind to civilization (the White Man's burden) but they knew their own (if mythical) history: that the founders of Rome had to take wives from another 'nation'; the Roman citizenship has be progressively extended from the inhabitants of a small town to whole Italy and beyond, most of the contemporary 'Romans' without a single drop of 'true Roman' blood in their veins. Thus every 'barbarian' was potentially a Roman: serve in the auxiliaries, or do an outstanding service to Rome and you get full Roman citizenship, your children, your bloodline is definitively Roman.
The point is there was no concern at all about 'racial purity': only the Arya of India, their society frozen into castes, took 'blood purity' seriously.
Universal religions, Christianity and Islam, kept the emphasis on culture, not 'race': the division was between faithful and heathens, but heathens are brother humans waiting for conversion; nothing to do with skin color.
When and where did modern racism appear? Progressively from the 2nd half of the 16th C. on, in oversea populations of European ascent.
Because of the unique combination of 2 factors: Reformation and slavery (an colonization).
Reformation: Protestant culture is far more deeply rooted in the Old Testament (see the traditional choice of christian names in religious Protestant communities). And in the Old Testament one finds the concept of 'Chosen People', and that to be part of the Chosen People you have to be born in it. The difference is hereditary, in the blood, definitive, irrevocable. Colonizations involving major population displacements: North America, Australia, New Zealand... were done mostly by Protestants; and think of the Afrikaners. Compare with how the Portuguese sired abundant populations of acknowledged half-breeds everywhere they went, with the blood mixing in all Latin America (and to some extent in French Canada, remember Riel).
Slavery: it exploded in the new colonies; now, if you treat people like beasts of burden, it's far more comfortable to think of them as beasts of burden rather than as 'true' humans. The same when you are to chase 'savages' from their lands. Ancient cultures had slaves, of course, but a citizen could be enslaved for debt: no 'racial' connotation.
Hence racism reached its maximum in oversea Protestant countries with a rich tradition of slavery, or where a native 'not White' population was largely eradicated such as Australia. Of course once known racism was so convenient that many Catholic 'elites' adopted it.