My 18yr old cat had dementia for the last year or so of her life (she had to be put to sleep recently due to heart failure).
She used to walk into a room, meow a lot, then walk out again. She also used to wake me at least 3 times every night (sometimes up to 6 times)which was tiring for me, but I put up with it as I guessed she was lonely/scared/confused. I used to feed her at 5am if that's what she wanted. My vet prescribed Tramadol, to settle her down. I gave it to her once only, as it made her dazed and uncoordinated.
Now that she's gone, I miss her constant meowing for attention/reassurance. My other cat misses her too I think, but he's a quiet cat who loves to cuddle.
Dementia is a terrible condition (as a carer with 22 years' experience, I've seen it hundreds of times in people). Think of how confused and scared your dog might be, and try to be patient. You are all he's got, and his time with you might not be much longer.
Best wishes.