Reality is perception. It is one set of logical possibities that allow the thinking agent to exist and to produce the thoughts it is producing right now. It is the output of a pure function in which it creates itself and maintains its existence, constantly feeding its output to its input.
Dreams are the exploration step of that function. Once in a while, the function creates a sandbox, feeds it with output gathered and classified as semi-coherent (adding in a few random bits), it simulates outcomes and picks out those fragments that didn't crash it.
Those are then integrated back into its main code, into the world it imagines it inhabits, "reality".