Tint
WebGPU F2F ‒ Feb 12, 2020
dsinclair@google.com
Proposal
WebGPU ingests a new text based language which is bijective to SPIR-V.
Alternatives
| Ingest | Ecosystem |
1 | SPIR-V | Offline tools to compile Tint |
2 | SPIR-V | TintToSPIRV method in WebGPU |
3 | SPIR-V and Tint | |
4 | Tint | SPIRVToTint method in WebGPU |
5 | Tint | Offline tools to convert SPIR-V to Tint |
Example
[[location 0]] var<out> gl_FragColor : vec4<f32>;
fn main() -> void {
gl_FragColor = vec4<f32>(0.4, 0.4, 0.8, 1.0);
return;
}
entry_point fragment = main;
Imports
import "GLSL.std.450" as std;
var angle : f32 = -std::atan2(a_particleVel.x, a_particleVel.y);
Variables
var<in> my_var : vec4<f32>;
var<out> out_var : mat3x2<f32>;
var fn_var : array<f32, 5>;
var fn_var2 : vec2<f32> = vec2<f32>(0.2, 4.3);
const b : i32 = 1;
Attributes
[[builtin position]] var<out> pos : vec4<f32>;
[[binding 0, set 1]] var<in> data : vec2<i32>;
type B = [[block]] struct { a : i32; }
type C = struct {
[[offset 4]] d : f32;
}
OpDecorate %pos Builtin Position
OpDecorate %data Binding 0
OpDecorate %data DescriptorSet 1
OpDecorate %B Block
OpMemberDecorate %C 1 Offset 4
Types
type A = struct {
b : i32;
c : f32;
}
vec{2,3,4}<type>
mat{2,3,4}x{2,3,4}<type>
i32, u32, f32, bool, void
ptr<storage_class, type>
array<type, size>, array<type>
If statements
if (a) {
} elseif (b) {
} else {
}
Switch
switch(a) {
case 1: {
# The break is implicit
}
case 2: {
fallthrough;
}
default: {
}
}
Loop statements
var i : i32 = 0;
var b : f32 = 2.4;
loop {
break if (i == 4);
b = b * 3.2;
continuing {
i = i + 1;
}
}
Functions
fn do_stuff(i : f32, b: f32) -> f32 {
return i * b;
}
Ecosystem
Evolution
Next Steps?