It really depends for me. I usually have the 'theme' for a song in mind as I start it, or the 'theme' suggests itself as I work with the melody/riff. Often I am inspired with a melody or riff which I then play over and over again until I can play it well and I've ironed out the weaknesses, then I will start to do variations on it - add some harmony bits, maybe some passing notes, or a pedal note - until new riffs and melodies start suggesting themselves. Even playing the riff in a different key or the relative major/minor (although my songs tend to be so atonal/modal that songs tend to have wandering tonic notes) can help give a new look at the riff that might expand your thinking.
Mixing and matching odd/old riffs with new ideas is also a good way to move a piece along or at least give you a different look at the same thing. I also like to change instruments; playing a guitar riff on the bass might suggest a simpler, more coherent way of writing the idea, and playing it on the keyboard might suggest a more subtle, secondary role for the guitar, etc.
Generally, I would say most of my writing is more subconcious, while most of the editing is concious.