glslang

Constructs SPIR-V modules programmatically using the glslang SpvBuilder API.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Building SPIR-V binaries by hand is error-prone and verbose; this Skill provides a complete reference for the glslang SpvBuilder API so you can programmatically generate types, instructions, control flow, and decorations for shader modules inside LuisaCompute.

Core Features & Use Cases

  • Module and Type Construction: Create canonicalized scalar, vector, matrix, struct, image, and cooperative matrix types, plus constants and variables.
  • Structured Control Flow: Generate if-then-else, switch, and loop constructs with helpers like Builder::If, makeSwitch, and LoopBlocks.
  • Traverser Patterns: Apply proven GlslangToSpv visitor patterns (visitSymbol, visitBinary, visitSelection, visitLoop) for AST-to-SPIR-V lowering, including access-chain management and debug info emission.
  • Use Case: When adding a new backend or extending LuisaCompute's SPIR-V codegen, use this Skill to correctly emit an entry point, declare descriptor bindings, build arithmetic expressions, and serialize the module with builder.dump().

Quick Start

Ask the AI to generate a SPIR-V fragment shader entry point with a float uniform and an OpFAdd computation using the glslang SpvBuilder API.

Frequently Asked Questions about glslang

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

FAQPage Schema
How do I build a SPIR-V module with glslang SpvBuilder?

Create a spv::Builder with a target SPIR-V version, set the source language and memory model, add required capabilities, then emit types, functions, and instructions. Finally call builder.dump() to serialize the module into a word vector.

How to create structured if-else and loops in SPIR-V builder?

Use spv::Builder::If with makeBeginElse and makeEndIf for selections, and makeNewLoop with createLoopMerge, createConditionalBranch, and closeLoop for loops. These helpers maintain valid structured control flow automatically.

Does glslang SpvBuilder support ray tracing and cooperative matrix types?

Yes, the builder provides makeAccelerationStructureType, makeRayQueryType, makeHitObjectEXTType, and makeCooperativeMatrixTypeKHR. You must add the corresponding extensions such as SPV_KHR_ray_tracing before use.

Why does OpSwitch disassembly read wrong case values?

OpSwitch case literals are sized by the selector's OpTypeInt width, not a fixed word count. A 64-bit selector uses two literal words per case, so parsers must consume ceil(bit_width/32) words before reading each target label.

What causes invalid SPIR-V after postProcessCFG in SpvBuilder?

Invalid topology arises when an outer selection merge is also an inner arm branching to the inner merge, causing inReadableOrder traversal to misclassify blocks. Fix the producer's physical control-flow plan by rotating merge declarations rather than patching serialization.