gosl

command
v0.1.21 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 3, 2026 License: BSD-3-Clause Imports: 2 Imported by: 0

README

GoSL: Go as a shader language

GoSL (via the gosl executable) allows you to write Go programs that run on [[GPU]] hardware, by transpiling Go into the WGSL shader language used by WebGPU, thereby establishing the Go shader language.

GoSL uses the core gpu compute shader system, and can take advantage of the [[Goal]] transpiler to provide a more natural tensor indexing syntax.

Functionally, GoSL is similar to NVIDIA warp -- docs, which uses python as the original source and converts it to either C++ or CUDA code. In GoSL, the original code is directly Go, so we just need to do the WGSL part. Unlike warp, WGSL runs on all GPU platforms, including the web (warp only runs on NVIDIA GPUs, on desktop).

See examples/basic and rand for complete working examples.

See the Cogent Lab Docs for full documentation.

Documentation

Overview

gosl translates Go source code into WGSL compatible shader code. Use //gosl:start and //gosl:end to bracket code to generate.

pass filenames or directory names for files to process.

Usage:

gosl [flags] [path ...]

The flags are:

-debug
  	enable debugging messages while running
-exclude string
  	comma-separated list of names of functions to exclude from exporting to WGSL (default "Update,Defaults")
-keep
  	keep temporary converted versions of the source files, for debugging
-out string
  	output directory for shader code, relative to where gosl is invoked -- must not be an empty string (default "shaders")

Directories

Path Synopsis
package alignsl performs 16-byte alignment checking of struct fields and total size modulus checking of struct types to ensure WGSL (and GSL) compatibility.
package alignsl performs 16-byte alignment checking of struct fields and total size modulus checking of struct types to ensure WGSL (and GSL) compatibility.
examples
basic command
This example just does some basic calculations on data structures and reports the time difference between the CPU and GPU.
This example just does some basic calculations on data structures and reports the time difference between the CPU and GPU.
rand command
Code generated by "goal build"; DO NOT EDIT.
Code generated by "goal build"; DO NOT EDIT.
package slbool defines a WGSL friendly int32 Bool type.
package slbool defines a WGSL friendly int32 Bool type.
Package slmath defines special math functions that operate on the cogentcore.org/core/math32 vector, matrix and quaternion types.
Package slmath defines special math functions that operate on the cogentcore.org/core/math32 vector, matrix and quaternion types.
Package threading provides a simple parallel run function.
Package threading provides a simple parallel run function.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL