I do not understand why solar fields do not take the ample roof areas. That is usually just wasted, even worse the roofs are mostly of some dark color where I live, they heat up the area for no good reason at all.
But yes, it would be nice with building codes requiring to either have solar or green roofs. That would certainly help drive down costs, and in the case of green roofs, reduce cooling demands as well as providing (depending on what you plant, granted) a haven for biodiversity.
Also the grid is really not designed for large amounts of decentralized power generation. While modifying the grid is probably easier than replacing roofs en masse, it's still expensive. Dedicated solar plants can take advantage of economies of scale.