forcecase-missing-on-ps-switch
Status: stub. The full-length analysis is queued for a v1.0.x patch release per ADR 0018, section 5, criterion #6. The companion rule page at docs/rules/forcecase-missing-on-ps-switch.md contains the canonical detection logic + GPU reasoning.
TL;DR
The HLSL switch statement has multiple valid lowerings: a true jump-table (one indirect branch, one taken target per lane), a chained if/else ladder (linear scan over case labels), or — in some compiler versions — a branch-free predicate fan that evaluates every case body and selects the right result. The [forcecase] attribute pins the compiler to the jump-table form. Without [forcecase], the compiler is free to pick the chained-if form, and that's where the pixel-shader hazard appears: chained ifs mean each case introduces a new branch, and per-pixel divergence on case selection retires quad lanes one-arm-at-a-time. Derivatives sampled inside the case body then see undefined neighbour values from retired lanes — exactly the same failure mode as a per-lane if containing a Sample (see derivative-in-divergent-cf and quadany-quadall-opportunity).
What the rule fires on
A switch statement inside a pixel-shader entry point where at least one case body contains a derivative-bearing operation — Sample, SampleBias, SampleGrad, ddx, ddy, ddx_fine, ddy_fine, or any function call that transitively invokes one — and the switch lacks the [forcecase] attribute. The rule fires only on PS entry points (the hazard is specific to the quad / derivative model); compute and other stages are not flagged.
See the What it detects section of the rule page for the full pattern definition.
Why it matters
The full GPU-mechanism analysis lives in the Why it matters on a GPU section of the companion rule page.
Examples
The bad / good code snippets are kept canonical on the rule page; see forcecase-missing-on-ps-switch.md -> Examples.
See also
- Rule page -- canonical reference + change log.
- control-flow overview -- broader context.
- ADR 0018 -- v1.0 readiness plan.
This is a v1.0-ship stub. Full analysis pending; track issue link TBD.