hn.today

Killing what can't be handled – putting a spaghetti demon to eternal rest

themaister.net30 points3 comments
Screenshot of Killing what can't be handled – putting a spaghetti demon to eternal rest

The DXIL-to-SPIR-V control-flow structurizer had become a fragile, roughly 9,000-line system that repeatedly broke on extreme game shaders. Its author argues that trying to handle every case while preserving readable output made the implementation too complex to reason about; a particularly difficult shader and a second validation failure prompted a redesign focused on correctness, with performance retained where possible. The replacement borrows Mesa’s `goto_if` approach, used for unstructured OpenCL control flow. A test mode first sent unstructured SPIR-V directly to drivers: games worked, and RADV performance matched the old path, making the two-week gamble on the new strategy viable.

The new method recursively organizes control flow into levels. When a branch targets a block that cannot be reached directly, it records the intended path in selector variables and routes execution through an outer merge; helper blocks handle divergent branches, while skip analysis records when entire levels can be bypassed. Switches are split into conditional branches rather than preserving complicated fall-through behavior. The rewrite also abandons manual PHI-node maintenance: PHIs become variables and stores before structurization, with occasional extra loads and stores repairing SSA dominance afterward. Fuzzing passed highly unusual forward-flow patterns, and the design guarantees maximal reconvergence - the largest possible group of threads follows any executed block. The account ends as it turns to the remaining challenge of handling loops.

Read on themaister.net3 comments on Hacker News

Summary generated by AI from the linked article. hn.today is not affiliated with Hacker News or Y Combinator.

More in Programming

Tangled in a Box

Tangled in a Box

Tangled in a Box packages Tangled’s Git collaboration stack for local or private-network use, launched with Docker Compose. It’s a proof of concept with hardcoded secrets that should be replaced before any real deployment. (jola.dev)

The daily digest

Today's best Hacker News stories, summarized and screenshotted, one email a day.