What problem does it solve?
Writing HLSL code generators in C++ involves repetitive string concatenation, formatting boilerplate, and managing embedded shader headers. This Skill documents the StringBuilder utilities, codegen patterns, and builtin header registry used in LuisaCompute's DirectX and Vulkan backends so you can generate shader source correctly and efficiently.
Core Features & Use Cases
- StringBuilder Code Generation: Append text, numbers, and formatted strings with
vstd::StringBuilder, vstd::to_string, and luisa::format while avoiding unnecessary allocations.
- Codegen Patterns: Ready-made patterns for function declarations, template parameters, call expressions, type-aware generation, RAII wrappers, and trailing-comma fixes.
- Builtin Headers and DXIL Embedding: Access precompiled
.bytes and .dxil builtins (ray tracing, bindless textures, BC6/BC7 compression, autodiff) via lc_hlsl::get_hlsl_builtin, and register new ones with LC_HLSL_DECL_VARNAME macros.
- Use Case: When adding a new compute kernel feature to the DirectX backend, use these patterns to emit the HLSL function signature, pull in the required builtin header, and set
LUISA_DUMP_SOURCE=1 to inspect the generated shader output.
Quick Start
Ask the assistant to generate an HLSL function declaration for a kernel with float3 arguments using the StringBuilder codegen patterns from this Skill.