Opening this year’s Edinburgh International Film Festival in darkly comic style is The Legend of Barney Thomson, the directorial debut of national treasure Robert Carlyle. He plays the titular Barney, an old-fashioned and unassuming 50-something barber who is becoming increasingly irrelevant in his industry and generally disliked by his colleagues because of his serious, un-chatty nature.

One day his quiet, relatively mundane life is turned upside when he accidentally becomes a killer. With a no-nonsense London detective (Ray Winstone) hot on his heels and his overbearing, sharp-tongued mother (Emma Thompson) to cope with, Barney’s life spins more and more out of control as the bodies start to pile up.

Jet-black comedy is a difficult thing to get right and for the most part Barney Thomson does exactly that. This is down to Carlyle’s astute direction and an often sharply funny script by Richard Cowan and Colin McLaren, matching colloquial Scottish humour with ridiculously over-the-top scenes of chopped off limbs and body disposal. You’ll know pretty quickly if it’s your cup of tea and if it is and you’re willing to just go with it then there’s much to enjoy.

Carlyle has assembled a great cast of local and not-so-local talent, with everyone from Martin Compston (Sweet Sixteen, TV’s Line of Duty) as Barney’s young gun fellow barber to Tom Courtenay as the police chief superintendent bewildered by the series of body parts being mailed to the victim’s family members, bringing real life to their characters.

Carlyle himself is tremendously soulful as the titular accidental serial killer, crucially bringing a lot of empathy and sympathy to a character that could have been utterly despicable in the hands of a lesser actor. Thompson steals the show as his sharp-tongued mother, with her array of garish outfits, spot-on Glaswegian accent, foul-mouthed putdowns and hilariously abrasive nature turning her into an unforgettable character. Despite the fact that Thompson is only two years older than Carlyle in real life, they make a convincing mother-son pair and both bring a gravitas and – largely thanks to a revealing scene about Barney’s past towards the end – even a sense of pathos to the piece.

The film also has a lot of fun with the idea of ineptitude, not just in the eponymous barber – although his lack of knowledge in serial killing can surely be forgiven – but in the cops bumbling around who are somehow always one step behind him, particularly a distractingly hammy Ashley Jensen as Winstone’s opportunistic rival officer. This is where the film drags its leg a little, simply because everyone seems a little too clueless to be truly believable. It also makes a few narratives missteps towards the film’s conclusion, including a final Western-inflected showdown of sorts that seems entirely out of place.

Carlyle has delivered a deliciously dark home-grown crime comedy, one that should tickle the funny bone of anyone who likes they’re humour on the ghoulish side and their characters idiosyncratic. It works best when it matches conversational humour with the macabre, showing off some of the most characterful areas of Glasgow not often shown on film as it goes, only losing some of its muster and energy when it ultimately tries to be more than it is. That said it’s worth the stumbles when the journey’s been so compellingly off-kilter. This is a startling, impressively eclectic debut from a legendary actor in his own right.