I don't see it that black and white. The military successes of the Ukrainian Armed Forces seem to prove beneficial to #Putin: The announced referenda will enable Russia to annex those territories and declare them Russian state territory. Further assaults by #Ukraine (and western allies via weapons deliveries) can then be framed as a direct assault on Russian territory in which the Russian security doctrine of early 2001 allows a declaration of state of war, a general mobilisation, and the use of tactical nuclear weapons in the theatre by local commanders.
Even if Putin won't use nuclear weapons, he achieves an important mood change in the Russian populace: Russia being attacked by the West, a framing the regime for years has pushed for. A closer identification of regime and polupace, a gathering around the flag, will be the result. (As of late August, 80% of Russians approve of Putin, but that doesn't translate into a majority support for the "special operation".) Now Putin broadened his options: With more people supporting the war effort (at least the older generation), he can "intensify" the war; he can declare a meager ceasefire (for "humanitarian reasons"); and even in case of defeat he and his regime will stay in power due to the "guilt association" between him and the populace.
Honestly, I think this is not an act of desperation of his, a running out of options, as many commentators think. Quite the contrary: Things couldn't be better for Putin right now.