Skip to content

Commit fe1e2a9

Browse files
author
hartsantler
committed
new documentation for GPU backend.
1 parent 4ca94a0 commit fe1e2a9

1 file changed

Lines changed: 60 additions & 0 deletions

File tree

doc/gpu.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
GPU Translation
2+
---------------
3+
A subset of Python with extra type information can be translated into a GLSL fragment shader. The `@gpu` decorator marks a function for translation to GLSL. All variables inside the function must be typed using GLSL types. You can type your variables using decorators or special PythonJS type syntax.
4+
5+
Typing with Decorators
6+
----------------------
7+
8+
```
9+
@returns( array=[512,512] )
10+
@typedef( x=float, y=float, tempX=float, i=int, runaway=int, c=vec2)
11+
@gpu.main
12+
def gpu_mandelbrot():
13+
c = get_global_id()
14+
x = 0.0
15+
y = 0.0
16+
tempX = 0.0
17+
i = 0
18+
runaway = 0
19+
for i in range(100):
20+
tempX = x * x - y * y + float(c.x)
21+
y = 2.0 * x * y + float(c.y)
22+
x = tempX
23+
if runaway == 0 and x * x + y * y > 100.0:
24+
runaway = i
25+
return float(runaway) * 0.01
26+
27+
```
28+
29+
30+
Typing C-style
31+
----------------------
32+
33+
```
34+
@returns( array=[512,512] )
35+
@gpu.main
36+
def gpu_mandelbrot():
37+
vec2 c = get_global_id()
38+
float x = 0.0
39+
float y = 0.0
40+
float tempX = 0.0
41+
int i = 0
42+
int runaway = 0
43+
for i in range(100):
44+
tempX = x * x - y * y + float(c.x)
45+
y = 2.0 * x * y + float(c.y)
46+
x = tempX
47+
if runaway == 0 and x * x + y * y > 100.0:
48+
runaway = i
49+
return float(runaway) * 0.01
50+
51+
```
52+
53+
@returns
54+
---------
55+
The main entry point function marked with `@gpu.main` must also use the `@returns(array=[w,h])` decorator to declare the width and height of the 2D array that it will return. Subroutines must also use the `@returns` decorator to declare their GLSL return type like this: `@returns(float)`
56+
57+
58+
get_global_id()
59+
--------------
60+
The GLSL function `get_global_id()` is part of the WebCLGL API and returns a vec2 that contains the current `x` and `y` index.

0 commit comments

Comments
 (0)