hlsl

Generates HLSL shader code using StringBuilder patterns and embedded builtin headers.

1.0k|108|Updated Nov 20, 2020
One-click install
npx skills add https://github.com/LuisaGroup/LuisaCompute --skill hlsl
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: hlsl
Source: https://github.com/LuisaGroup/LuisaCompute/tree/main/.agents/skills/hlsl
Command: npx skills add https://github.com/LuisaGroup/LuisaCompute --skill hlsl

SYSTEM DOCUMENTATION & REQUIREMENTS

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.

Frequently Asked Questions about hlsl

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I generate HLSL code with StringBuilder in C++?

Use vstd::StringBuilder with operator<< for chaining and operator+= for single items. Prefer "text"sv string-view literals to avoid allocations, and use vstd::to_string for integers since it is faster than luisa::format.

How do I access embedded HLSL builtin headers?

Include backends/common/hlsl/builtin/hlsl_builtin.hpp and call lc_hlsl::get_hlsl_builtin with a key like "hlsl_header". The returned struct provides a pointer and size you can convert to a std::string_view.

How do I add a new HLSL builtin file?

Add the .bytes or .dxil file to src/backends/common/hlsl/builtin/, declare it with LC_HLSL_DECL_VARNAME(my_bytes), and register it with LC_HLSL_INSERT_VARNAME(my_bytes, "my_key"). The build converts .hlsl to .bytes and shaders to .dxil via bin2obj.

How do I dump generated HLSL source for debugging?

Set the environment variable LUISA_DUMP_SOURCE=1 to write per-shader files named hlsl_output_<shader_name>.hlsl in the working directory. Naming priority uses ShaderOption::name, then Function::name(), then the function hash in hex.

Can Vulkan compute shaders use the HLSL codegen path?

No. Vulkan user compute shaders must use native SPIR-V codegen via LUISA_XIR_TO_SPIRV or LUISA_AST_LLVM_TO_SPIRV. The Vulkan Function compute path must not call HLSL/DXC; only internal builtin helpers compile HLSL to SPIR-V.

Why does my generated argument list have a trailing comma?

Appending a comma after every item leaves a trailing comma before the closing parenthesis. Fix it by overwriting the last character: if the list is non-empty, set str[str.size() - 1] = ')', otherwise just append ')'.