"Jackass" star Ryan Dunn spent four hours in a Philadelphia-area bar before he got behind the wheel of his Porsche 911 this morning ... drinking at least 3 beers and 3 shots ... TMZ has learned.
Dunn arrived to a bar called Barnaby's of America in West Chester, PA around 10:30 PM ... to hang out with a small group of male friends.
One of the friends tells TMZ ... Dunn had 3 Miller Lites and 3 "girly shots" between 10:30 PM and 2:10 AM -- nearly a 4 hour span -- but he was "not too drunk to drive."
But according to another person who was inside the bar that night, Dunn was "wasted" -- and "had a lot to drink."
As TMZ previously reported, Dunn crashed his Porsche soon after -- killing himself and an unidentified passenger. Cops believe speed may have been a factor.