1 of 15

Tint

WebGPU F2F ‒ Feb 12, 2020

dsinclair@google.com

2 of 15

Proposal

WebGPU ingests a new text based language which is bijective to SPIR-V.

3 of 15

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

4 of 15

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;

5 of 15

Imports

import "GLSL.std.450" as std;

var angle : f32 = -std::atan2(a_particleVel.x, a_particleVel.y);

6 of 15

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;

7 of 15

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

8 of 15

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>

9 of 15

If statements

if (a) {

} elseif (b) {

} else {

}

10 of 15

Switch

switch(a) {

case 1: {

# The break is implicit

}

case 2: {

fallthrough;

}

default: {

}

}

11 of 15

Loop statements

var i : i32 = 0;

var b : f32 = 2.4;

loop {

break if (i == 4);

b = b * 3.2;

continuing {

i = i + 1;

}

}

12 of 15

Functions

fn do_stuff(i : f32, b: f32) -> f32 {

return i * b;

}

13 of 15

Ecosystem

  • Input
    • Tint
    • SPIR-V (optionally)
  • Output
    • SPIR-V
    • Tint
    • MSL
    • HLSL
    • GLSL
    • DXIL?

14 of 15

Evolution

  • Tint is potentially useful outside WebGPU
    • Potential to add full SPIR-V parsing as a build time option
    • WebGPU compatible would be the default compile settings
  • Features must have SPIR-V generation examples
    • Features can desugar down to features spec’d as SPIV-V (e.g. for -> loop)

15 of 15

Next Steps?

  • Setup repo (googlesource? github?)
  • Open source Tint source and spec
  • Start building out the various parsing and backend components
    • SPIRV-Cross shim to start?