Quick answer: Unreal custom shader complaining of uniform buffer overflow? The shader permutation table compiled too many variants, each carrying the full UB — trim permutations or shrink your UB struct.
A custom material+global shader pair fails to compile with an overflow error on D3D12. The permutation count exploded because of multi-bool defines.
Permutation Explosion
Each SHADER_PERMUTATION_BOOL doubles the variant count. Five bools = 32 permutations; ten = 1024. Each carries the full uniform buffer — total UB allocation overflows.
Use Enums and Ranges
Combine related bools into a SHADER_PERMUTATION_INT or SHADER_PERMUTATION_RANGE_INT. 4 modes encoded as one INT = 4 permutations, not 16.
Shrink the UB
Pack UB fields tightly. Use uint and bit-pack flags instead of bool-per-flag. Move per-instance data to an SRV rather than the UB.
Permutation Gating
Define ShouldCompilePermutation on your global shader to reject impossible combinations (e.g. shadow off but cascade count > 0). Cuts the variant count without losing flexibility.
Verifying
The shader compiles on all target platforms; the permutation count is bounded and known.
“Overflow is a permutation-count problem. Combine bools, gate impossible variants, and shrink the UB.”
Track permutation counts via r.ShaderPipelineCache.PrintMetrics 1 — runs at PSO precache and tells you which globals are the worst offenders.