If your washing machine has a fabric softener dispenser then it's best to put the fabric softener in the fabric softener dispenser.
But if your washing machine doesn't have a fabric softener dispenser then yes it's perfectly fine to add the fabric softener to the washing machine directly.
But when you do add the fabric softener to the washing machine you should wait until the rinse cycle begins to put the fabric softener into the washing machine for it to work correctly.
If you put the fabric softener into the washing machine during the wash cycle then the wash cycle can wash the fabric softener away so be sure to put it in when the washing machine gets to the rinse cycle.
Pour the fabric softener into water pockets in the washing machine to avoid direct contact with clothes so it won't stain your clothes.