KhronosGroup/SPIRV-Reflect logo

KhronosGroup/SPIRV-Reflect

Free

SPIRV-Reflect is a lightweight library that provides a C/C++ reflection API for SPIR-V shader bytecode in Vulkan applications.

FreeFree tier
Type
Open Source
Company
Khronos Group

About KhronosGroup/SPIRV-Reflect

SPIRV-Reflect is a lightweight library that provides a C/C++ reflection API for SPIR-V shader bytecode, specifically designed for Vulkan applications. It enables developers to extract descriptor bindings, push constant block sizes, and full layout data for uniform buffer and push constant blocks from SPIR-V bytecode. The library also extracts input/output variables, including semantic decorations for HLSL shaders, and supports runtime remapping of descriptor bindings with updates to the source SPIR-V bytecode. All reflection data can be logged as human-readable text. Integration is simple: only spirv_reflect.h and spirv_reflect.c need to be added to a project, with no external dependencies beyond the Vulkan SDK. The repository includes sample applications demonstrating descriptor binding retrieval, HLSL resource type representation, and input/output variable extraction for pipeline vertex input state creation.

Key Features

Extract descriptor bindings from SPIR-V bytecode to assist in generating Vulkan descriptor set and pipeline layouts
Extract push constant block size from SPIR-V bytecode for pipeline layout generation
Extract full layout data for uniform buffer and push constant blocks to facilitate application updates
Extract input/output variables from SPIR-V bytecode, including semantic decorations for HLSL shaders, to validate pipeline input/output settings
Remap descriptor bindings at runtime and update the source SPIR-V bytecode accordingly
Log all reflection data as human-readable text
Lightweight integration with only spirv_reflect.h and spirv_reflect.c; no external dependencies beyond the Vulkan SDK

Pros & Cons

Pros
  • Lightweight library with minimal dependencies (only Vulkan SDK)
  • Simple integration: just add two source files to project
  • Provides comprehensive reflection data including descriptor bindings, push constants, and IO variables
  • Supports runtime remapping of descriptor bindings
  • Human-readable logging of all reflection data
  • Includes sample applications for common use cases
Cons
  • Limited to SPIR-V shader bytecode targeting Vulkan; not applicable to other graphics APIs directly
  • Does not support all SPIR-V features; coverage may be incomplete for advanced shader constructs
  • No built-in support for non-SPIR-V shader formats
  • Requires Vulkan SDK for compilation and examples

Best For

Generating Vulkan descriptor set and pipeline layouts from SPIR-V shader bytecodeValidating pipeline input/output settings by extracting shader input/output variablesUpdating uniform buffer and push constant structures based on reflection dataRuntime remapping of descriptor bindings in SPIR-V bytecodeDebugging and analysis of shader resource bindings via human-readable logs

FAQ

What is SPIRV-Reflect?
SPIRV-Reflect is a lightweight C/C++ library that provides a reflection API for SPIR-V shader bytecode, designed to assist Vulkan applications in extracting shader resource information such as descriptor bindings, push constants, and input/output variables.
How do I integrate SPIRV-Reflect into my project?
Simply add spirv_reflect.h and spirv_reflect.c to your project's build, and include spirv_reflect.h from the necessary source files. The only external dependency is the Vulkan SDK.
Does SPIRV-Reflect support HLSL shaders?
Yes, SPIRV-Reflect can extract semantic decorations from SPIR-V bytecode that originates from HLSL shaders, allowing validation of pipeline input/output settings.
Can SPIRV-Reflect remap descriptor bindings?
Yes, it supports runtime remapping of descriptor bindings and can update the source SPIR-V bytecode accordingly.