← All resources

Branching on a GPU (Jason Booth, Dec 2021)

Auto-discovered

Blog Intermediate

Jason Booth, Dec 2021

Visit resource ↗

Description

Branching on a GPU is Jason Booth's December 2021 Medium essay on when shader branches help or hurt on modern GPUs. He challenges folklore that every if-statement should become step() math, drawing on Amplify Shader Editor and shipped Unity shader work.

Cost depends on whether predicates stay uniform across warps or vary per pixel from texture noise, and on whether branches only select values or trigger texture samples. Compilers may execute both paths; UNITY_BRANCH and explicit derivatives protect 2x2 quad sampling when textures sit inside a branch.

Intermediate authors profiling real materials benefit most. Unity HLSL illustrates the patterns, but simd divergence and flattening heuristics apply broadly.

One free Medium article, often paired with Booth's Stalling a GPU note. Unity forum threads cite it for flat interpolants versus mask-driven branches.