AIFeed

Shokado GPU Compiler Infrastructure

Original text(via Lobsters)

GPU compiler infrastructure.

Shokado does for GPU languages what LLVM does for CPU ones: an IR, a verifier, a linker, an optimizer, code generators, and a VM. It's one C library without dependencies, small enough to vendor, and safe to run on untrusted input.

Why Shokado and Bento

The GPU language

Bento

Bento is the GPU 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 generates code for 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 Direct3D 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.
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 Direct3D 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, a verifier, a linker, an optimizer, and code generators, all language agnostic. 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, CSE, and rule-driven algebraic simplification. 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. 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.

The text above was extracted automatically from the source page and may miss images, tables or code blocks. The original is authoritative.

Published by Lobsters
This site only summarises and aggregates; copyright stays with the original author. Headlines and summaries follow the source — where they differ, the original wins.
Read the original ↗