1) Discerning between solid and granular
It is the distribution of the touch receptors in your skin that enables the distinction between solid and granular objects.
The ability to recognize two separate points applied simultaneously to
the skin from a single point is called two point discrimination.
Two point discrimination varies with location on body surface. It is
about 2 mm on the finger tip and increases to over 40 mm on the back.
Image source: Annals of Neurology, CC licence
2) Touch vs pain
The sense of touch is enabled by touch receptors and pain by pain receptors (nociceptors). In general, pain receptors are activated by greater pressure than touch receptors. Walking on gravel (sharp-edged stones) likely applies greater force on a certain area of your skin than walking on rounded pieces of sand, so it will more likely cause pain.
Mechanoreceptive nociceptors have a high threshold for activation—they
respond to mechanical stimulation that is so intense it might damage
the tissue. (nobaproject.com)