  Modern hydrodynamic simulations of galaxy formation are able to predict
accurately the rates and locations of the assembly of giant molecular clouds in
early galaxies. These clouds could host star clusters with the masses and sizes
of real globular clusters. I describe current state-of-the-art simulations
aimed at understanding the origin of the cluster mass function and metallicity
distribution. Metallicity bimodality of globular cluster systems appears to be
a natural outcome of hierarchical formation and gradually declining fraction of
cold gas in galaxies. Globular cluster formation was most prominent at
redshifts z>3, when massive star clusters may have contributed as much as 20%
of all galactic star formation.
