Skip to content

Ruby 3.1+ / SPIR-V 1.0–1.6

Write shaders in Ruby. Emit SPIR‑V directly.

Electra builds compact vertex and fragment shaders without a GLSL compiler, native bindings, or runtime gem dependencies.

Ruby source fragment / main
mod.fragment_shader do |f|
  out = f.output(:vec4, location: 0)
  out.store(f.constant([1, 0, 0, 1]))
end
Emitted assembly 296 bytes
OpEntryPoint Fragment %1 "main" %8
OpExecutionMode %1 OriginUpperLeft
OpDecorate %8 Location 0
%8 = OpVariable %7 Output
%11 = OpConstantComposite %6 %9 %10 %10 %9
OpStore %8 %11
SPIR-V magic 0x07230203
Runtime
Pure Ruby
Dependencies
0 runtime gems
Shader stages
Vertex + fragment
License
MIT

A small surface for the shaders UI renderers actually need.

Work with typed values in Ruby, then inspect or store the exact bytes your Vulkan application consumes.

Typed where it matters

Compose vectors, matrices, comparisons, texture samples, GLSL.std.450 operations, and structured branches without writing raw opcodes.

Bytes you can inspect

Assemble and disassemble numeric-ID SPIR-V with byte-for-byte round trips, exact bounds, and preserved floating-point payloads.

Layout stays explicit

Set descriptor bindings, offsets, array strides, matrix layout, and push constants yourself. Electra never guesses the CPU/GPU ABI.

A deliberate boundary

A shader emitter, not another compiler toolchain.

Electra keeps deployment simple by doing one job in Ruby. The Vulkan implementation and SPIRV-Tools remain the authorities for complete semantic validation.

Inside the DSL

  • UI vertex and fragment shaders
  • Explicit resource layouts
  • Structured control flow
  • SPIR-V 1.0 through 1.6

Outside the DSL

  • GLSL parsing and optimization
  • Compute and ray tracing
  • GPU resource management
  • Complete semantic validation

Add Electra to your renderer.

Install version 0.1.0 from RubyGems. Ruby 3.1 or newer is required; SPIRV-Tools is optional for development validation.

$ gem install electra