  We study the counting problem of BPS D-branes wrapping holomorphic cycles of
a general toric Calabi-Yau manifold. We evaluate the Jeffrey-Kirwan residues
for the flavoured Witten index for the supersymmetric quiver quantum mechanics
on the worldvolume of the D-branes, and find that BPS degeneracies are
described by a statistical mechanical model of crystal melting. For Calabi-Yau
threefolds, we reproduce the crystal melting models long known in the
literature. For Calabi-Yau fourfolds, however, we find that the crystal does
not contain the full information for the BPS degeneracy and we need to
explicitly evaluate non-trivial weights assigned to the crystal configurations.
Our discussions treat Calabi-Yau threefolds and fourfolds on equal footing, and
include discussions on elliptic and rational generalizations of the BPS states
counting, connections to the mathematical definition of generalized
Donaldson-Thomas invariants, examples of wall crossings, and of trialities in
quiver gauge theories.
