Shader compiler infrastructure for building shaders and shader tools.

Shokado is an IR and a set of tools that lower it directly to what your graphics API requires. The whole infrastructure is one C library without dependencies, small enough to vendor, and safe to run on untrusted input.

The shading language

Bento

Bento is the shading language built on Shokado. Barriers, subgroups, uniformity, and uber shaders are concepts it understands rather than thinly typed intrinsics and macros bolted onto C.

Meet Bento Language tour Getting started

import std;

struct Pixel {
	[[location(0)]] uv: f32x2,
}

struct Color {
	[[color(0)]] rgba: f32x4,
}

[[stage(.Fragment)]]
fn main(px: Pixel) -> Color {
	let corner = px.uv.x * px.uv.y;
	let glow = std::smoothstep(0.0, 1.0, corner);
	return { f32x4 { px.uv, glow, 1.0 } };
}

Write once, run anywhere

Shokado IR lowers to SPIR-V, DXIL, AIR, and GLSL with no other compiler in between. Targets

Bento, or your own language, node graph, or material graph, builds Shokado IR. Shokado IR is lowered to SPIR-V for Vulkan 1.0 to 1.4 and OpenGL 4.5 to 4.6, DXIL for DirectX 12, AIR for Metal 3 and 4, and GLSL for OpenGL 4.5 to 4.6 and OpenGL ES 3.1 to 3.2 as a fallback for OpenGL drivers without SPIR-V support.

Infrastructure

An IR and a set of language agnostic tools that work on it. Bento is a small client on top of all that, much like clang is the C and C++ frontend for LLVM. Tools, IR and bytecode, Library

Structured SSA

Blocks belong to if and loop instructions rather than to a control flow graph. IR can be built, edited, printed, and verified from other programs.

Bytecode

Modules can be linked at build time or at run time, left incomplete, and mixed with IR from any source.

Tools

Linker, optimizer, code generator, disassembler, validator, and stripper, for modules from any frontend.

Optimizer

Inlining, mem2reg, scalar replacement of aggregates, loop inversion, CSE, and comprehensive rule-driven algebraic simplifications. Competitive with spirv-opt and with the highest optimization level of DXC.

Library

One C header. Memory, files, and diagnostics are provided by the host through callbacks.

Untrusted input

No source or bytecode can crash the library, hang it, or run it out of memory without the failure being reported and handled. An input that proves otherwise is worth up to $500 USD under the bug bounty.

Rationale

“The shader situation in Vulkan and Direct3D 12 is somewhat dire and this is an attempt at trying to address it.”

The rationale is about the lessons from past mistakes, why Shokado is not a transpiler, and why the library comes first. Status is on the roadmap.