When the Compiler Gives You Errors, Make SFINAE
summary
HLSL 2021 adds templates so SFINAE-style tricks and type traits are implemented inside shader code to detect an enum and bypass a compiler bug (#5553 in DirectXShaderCompiler) that makes sizeof on structs with enums bug refuse to compile. The workaround hoists enums into a base class, provides a custom size_of helper and enable_if-like traits, restores serialization offsets and static_assert checks, and successfully lets unit tests and serializers run despite HLSL static_assert and error-message quirks.
AI-written summary · about
chapters (10)
- 0:00Introduction: Serialization and Offsets
- 0:29Adding Fields and the Hidden Offset Bug
- 0:44sizeof Enum Bug and Compiler Error
- 1:08Surprise! This Isn't C++, It's HLSL
- 1:28HLSL 2021: Templates Arrive
- 1:43Writing Type Traits and enable_if in HLSL
- 2:10Static Assert in HLSL vs C++
- 2:38A Workaround Using Inheritance
- 3:08Don't Be DenverCoder9: Share Your Fixes
- 3:51Conclusion and Talk Preview
related talks
01h 01mA Soupçon of SFINAE
55mCustom Overload Sets and Inline SFINAE for Truly Generic Interfaces
53mThe Detection Idiom - a simpler way to SFINAE
56m“Type Traits - what are they and why should I use them?"
01h 28mC++ Concepts "Lite" in Practice
01h 05mC++ Run-Time Optimizations for Compile-Time Reflection
42mC++ Horizons
01h 30mRethinking the Way We Do Templates in C++
