Skip to content

Commit f2b7709

Browse files
almarkleinKorijn
andauthored
Update to wgpu-native 0.17.0.2 (#370)
* New webgpu.h and wgpu.h * Fix parsing * Codegen and apply fixes * Fix features and default backend * use undefined limits from lib * Fix handling of error messages. Shader messages are now also nicely formatted already * Fix min bind size and a few missed drops * these drop/release methods seem to work now * Support old feature names * revert last * flake * run codegen again * Fix shadertoy examples shader code * Fix loop to avoid hanging example-tests on the glsl examples * More renaming drop -> release * use matching manylinyx by cibuildwheel * try * wrong copy-paste * dont build 32bit Linux wheel, because we have no such binary for wgpu-native * more build tweaks * Hide repeating error messages. * changelog * lib calls raise Python errors * Fix features * Append to changelog * Fix tests * undo the undoing of an earlier change * Update CHANGELOG.md Co-authored-by: Korijn van Golen <[email protected]> --------- Co-authored-by: Korijn van Golen <[email protected]>
1 parent 7c2b096 commit f2b7709

25 files changed

+1298
-1074
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,11 @@ jobs:
214214
run: |
215215
python -m pip install --upgrade pip wheel setuptools twine
216216
- name: Build wheels
217-
uses: pypa/[email protected]
217+
uses: pypa/[email protected]
218+
env:
219+
CIBW_MANYLINUX_X86_64_IMAGE: quay.io/pypa/manylinux_2_28_x86_64
220+
CIBW_ARCHS_LINUX: x86_64
221+
CIBW_SKIP: cp39-musllinux_x86_64
218222
with:
219223
output-dir: dist
220224
- name: Twine check

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@ Added:
2525

2626
* New `wgpu.wgsl_language_features` property, which for now always returns an empty set.
2727
* The `GPUShaderModule.compilation_info` property (and its async version) are replaced with a `get_compilation_info()` method.
28+
* The WebGPU features "bgra8unorm-storage" and "float32-filterable" are now available.
29+
30+
Changed:
31+
32+
* The binary wheels are now based on manylinux 2.28, and the 32bit Linux wheels are no longer built.
33+
* In WGSL: toplevel constants must be defined using `const`, using `let` will now fail.
34+
* In WGSL: it is no longer possible to re-declare an existing variable name.
35+
* Error messages may look a bit different, since wgpu-native now produces nice messages replacing our custom ones.
36+
* Errors produced by a call into a wgpu-native function now produce a Python exception (no more async logging of errors).
2837

2938

3039
### [v0.9.5] - 02-10-2023

codegen/hparser.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,21 @@ def _get_wgpu_header():
1717
# Just removing them, plus a few extra lines, seems to do the trick.
1818
lines2 = []
1919
for line in lines1:
20-
if line.startswith("#"):
20+
if line.startswith("#define ") and len(line.split()) > 2 and "0x" in line:
21+
line = line.replace("(", "").replace(")", "")
22+
elif line.startswith("#"):
2123
continue
2224
elif 'extern "C"' in line:
2325
continue
24-
line = line.replace("WGPU_EXPORT ", "")
26+
for define_to_drop in [
27+
"WGPU_EXPORT ",
28+
"WGPU_NULLABLE ",
29+
" WGPU_OBJECT_ATTRIBUTE",
30+
" WGPU_ENUM_ATTRIBUTE",
31+
" WGPU_FUNCTION_ATTRIBUTE",
32+
" WGPU_STRUCTURE_ATTRIBUTE",
33+
]:
34+
line = line.replace(define_to_drop, "")
2535
lines2.append(line)
2636
return "\n".join(lines2)
2737

@@ -68,7 +78,7 @@ def _parse_from_h(self):
6878
code = self.source
6979

7080
# Collect enums and flags. This is easy.
71-
# Note that flags are defines as enums and then defined as flags later.
81+
# Note that flags are first defined as enums and then redefined as flags later.
7282
i1 = i2 = i3 = i4 = 0
7383
while True:
7484
# Find enum
@@ -113,7 +123,9 @@ def _parse_from_h(self):
113123
# Turn some enums into flags
114124
for line in code.splitlines():
115125
if line.startswith("typedef WGPUFlags "):
116-
name = line.strip().strip(";").split()[-1]
126+
parts = line.strip().strip(";").split()
127+
assert len(parts) == 3
128+
name = parts[-1]
117129
if name.endswith("Flags"):
118130
assert name.startswith("WGPU")
119131
name = name[4:-5]

codegen/rspatcher.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,15 @@ def apply(self, code):
190190
detected = set()
191191

192192
for line, i in self.iter_lines():
193-
if "lib.wgpu" in line:
194-
start = line.index("lib.wgpu") + 4
193+
if "lib.wgpu" in line or "libf.wgpu" in line:
194+
start = line.index(".wgpu") + 1
195195
end = line.index("(", start)
196196
name = line[start:end]
197197
indent = " " * (len(line) - len(line.lstrip()))
198+
if "lib.wgpu" in line:
199+
self.insert_line(
200+
i, f"{indent}# FIXME: wgpu func calls must be done from libf"
201+
)
198202
if name not in hp.functions:
199203
msg = f"unknown C function {name}"
200204
self.insert_line(i, f"{indent}# FIXME: {msg}")

codegen/tests/test_codegen_rspatcher.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ def dedent(code):
1010

1111
def test_patch_functions():
1212
code1 = """
13-
lib.wgpuAdapterRequestDevice(1, 2, 3)
14-
lib.wgpuFooBar(1, 2, 3)
13+
libf.wgpuAdapterRequestDevice(1, 2, 3)
14+
libf.wgpuFooBar(1, 2, 3)
1515
"""
1616

1717
code2 = patch_rs_backend(dedent(code1))

examples/shadertoy_blink.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
shader_code = """
44
5-
fn render(p: vec2<f32>) -> vec3<f32> {
5+
fn render(p_: vec2<f32>) -> vec3<f32> {
66
let s = sin(i_time) * sin(i_time) * sin(i_time) + 0.5;
7-
var p = p;
7+
var p = p_;
88
var d = length(p * 0.8) - pow(2.0 * abs(0.5 - fract(atan2(p.y, p.x) / 3.1416 * 2.5 + i_time * 0.3)), 2.5) * 0.1;
99
1010
var col = vec3<f32>(0.0);

examples/shadertoy_circuits.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
return mat2x2<f32>(c, s, -s, c);
1717
}
1818
19-
fn fractal(p: vec2<f32>) -> vec3<f32> {
20-
var p = vec2<f32>(p.x/p.y,1./p.y);
19+
fn fractal(p_: vec2<f32>) -> vec3<f32> {
20+
var p = vec2<f32>(p_.x/p_.y,1./p_.y);
2121
p.y+=i_time*sign(p.y);
2222
p.x+=sin(i_time*.1)*sign(p.y)*4.;
2323
p.y=fract(p.y*.05);

examples/shadertoy_flyby.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
return mat2x2<f32>(c, s, -s, c);
2929
}
3030
31-
fn fractal(p: vec2<f32>) -> vec3<f32> {
32-
var p = fract(p*0.1);
31+
fn fractal(p_: vec2<f32>) -> vec3<f32> {
32+
var p = fract(p_*0.1);
3333
var m = 1000.0;
3434
for (var i = 0; i < 7; i = i + 1) {
3535
p = ( abs(p) / clamp( abs(p.x*p.y), 0.25, 2.0 ) ) - 1.2;
@@ -39,8 +39,8 @@
3939
return m*vec3<f32>(abs(p.x),m,abs(p.y));
4040
}
4141
42-
fn coso(pp: vec3<f32>) -> f32 {
43-
var pp = pp;
42+
fn coso(pp_: vec3<f32>) -> f32 {
43+
var pp = pp_;
4444
pp*=.7;
4545
4646
pp = vec3<f32>( pp.xy * rot(pp.z*2.0), pp.z);
@@ -63,11 +63,11 @@
6363
return d;
6464
}
6565
66-
fn de(p: vec3<f32>) -> f32 {
66+
fn de(p_: vec3<f32>) -> f32 {
6767
hit=0.;
6868
br=1000.;
69-
let pp = p - sphpos;
70-
var p = p;
69+
let pp = p_ - sphpos;
70+
var p = p_;
7171
let pxy = p.xy - path(p.z).xy;
7272
p.x = pxy.x;
7373
p.y = pxy.y;
@@ -98,8 +98,8 @@
9898
}
9999
100100
101-
fn march(fro: vec3<f32>, dir: vec3<f32>) -> vec3<f32> {
102-
var dir = dir;
101+
fn march(fro: vec3<f32>, dir_: vec3<f32>) -> vec3<f32> {
102+
var dir = dir_;
103103
var uv: vec2<f32> = vec2<f32>( atan2( dir.x , dir.y ) + i_time * 0.5, length(dir.xy) + sin(i_time * 0.2));
104104
var col: vec3<f32> = fractal(uv);
105105
var d: f32 = 0.0;

examples/shadertoy_gen_art.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
55
// migrated from: https://www.shadertoy.com/view/mds3DX
66
7-
let SHAPE_SIZE : f32 = .618;
8-
let CHROMATIC_ABBERATION : f32 = .01;
9-
let ITERATIONS : f32 = 10.;
10-
let INITIAL_LUMA : f32= .5;
7+
const SHAPE_SIZE : f32 = .618;
8+
const CHROMATIC_ABBERATION : f32 = .01;
9+
const ITERATIONS : f32 = 10.;
10+
const INITIAL_LUMA : f32= .5;
1111
12-
let PI : f32 = 3.14159265359;
13-
let TWO_PI : f32 = 6.28318530718;
12+
const PI : f32 = 3.14159265359;
13+
const TWO_PI : f32 = 6.28318530718;
1414
1515
fn rotate2d(_angle : f32) -> mat2x2<f32> {
1616
return mat2x2<f32>(cos(_angle),-sin(_angle),sin(_angle),cos(_angle));

examples/shadertoy_glsl_flame.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
float d = 0.0, glow = 0.0, eps = 0.02;
3939
vec3 p = org;
4040
bool glowed = false;
41-
41+
4242
for(int i=0; i<64; i++)
4343
{
4444
d = scene(p) + eps;
@@ -58,15 +58,15 @@
5858
{
5959
vec2 v = -1.0 + 2.0 * fragCoord.xy / iResolution.xy;
6060
v.x *= iResolution.x/iResolution.y;
61-
61+
6262
vec3 org = vec3(0., -2., 4.);
6363
vec3 dir = normalize(vec3(v.x*1.6, -v.y, -1.5));
64-
64+
6565
vec4 p = raymarch(org, dir);
6666
float glow = p.w;
67-
67+
6868
vec4 col = mix(vec4(1.,.5,.1,1.), vec4(0.1,.5,1.,1.), p.y*.02+.4);
69-
69+
7070
fragColor = mix(vec4(0.), col, pow(glow*2.,4.));
7171
//fragColor = mix(vec4(1.), mix(vec4(1.,.5,.1,1.),vec4(0.1,.5,1.,1.),p.y*.02+.4), pow(glow*2.,4.));
7272

examples/shadertoy_liberation.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@
2222
return x - y * floor( x / y );
2323
}
2424
25-
fn de(pos: vec3<f32>) -> f32 {
25+
fn de(pos_: vec3<f32>) -> f32 {
2626
var t = mod1(i_time, 17.0);
2727
var a = smoothstep(13.0, 15.0, t) * 8.0 - smoothstep(4.0, 0.0, t) * 4.0;
2828
var f = sin(i_time * 5.0 + sin(i_time * 20.0) * 0.2);
2929
30-
var pos = pos;
30+
var pos = pos_;
3131
3232
let pxz = pos.xz * rot(i_time + 0.5);
3333
pos.x = pxz.x;
@@ -93,14 +93,14 @@
9393
return normalize( vec3<f32>( de(p + d.yxx), de(p + d.xyx), de(p + d.xxy) ) - de(p) );
9494
}
9595
96-
fn march(fro: vec3<f32>, dir: vec3<f32>, frag_coord: vec2<f32>) -> vec3<f32> {
96+
fn march(fro: vec3<f32>, dir_: vec3<f32>, frag_coord: vec2<f32>) -> vec3<f32> {
9797
var d = 0.0;
9898
var td = 0.0;
9999
var maxdist = 30.0;
100100
101101
var p = fro;
102102
var col = vec3<f32>(0.0);
103-
var dir = dir;
103+
var dir = dir_;
104104
105105
for (var i = 0; i < 100; i+=1) {
106106
var d2 = de(p) * (1.0 - hash12(frag_coord.xy + i_time) * 0.2);

examples/shadertoy_matrix.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
// migrated from https://www.shadertoy.com/view/NlsXDH, By Kali
66
7-
let det = 0.001;
7+
const det = 0.001;
88
99
var<private> t: f32;
1010
var<private> boxhit: f32;
@@ -38,8 +38,8 @@
3838
return p;
3939
}
4040
41-
fn fractal(p: vec2<f32>) -> f32 {
42-
var p = abs( 5.0 - mod_2( p*0.2, 10.0 ) ) - 5.0;
41+
fn fractal(p_: vec2<f32>) -> f32 {
42+
var p = abs( 5.0 - mod_2( p_*0.2, 10.0 ) ) - 5.0;
4343
var ot = 1000.;
4444
for (var i = 0; i < 7; i+=1) {
4545
p = abs(p) / clamp(p.x*p.y, 0.25, 2.0) - 1.0;
@@ -56,7 +56,8 @@
5656
return length(max(vec3<f32>(0.),c))+min(0.,max(c.x,max(c.y,c.z)));
5757
}
5858
59-
fn de(p: vec3<f32>) -> f32 {
59+
fn de(p_: vec3<f32>) -> f32 {
60+
var p = p_;
6061
boxhit = 0.0;
6162
var p2 = p-adv;
6263
@@ -74,7 +75,6 @@
7475
7576
let b = box(p2, vec3<f32>(1.0));
7677
77-
var p = p;
7878
let p_xy = p.xy - path(p.z).xy;
7979
p.x = p_xy.x;
8080
p.y = p_xy.y;
@@ -130,8 +130,8 @@
130130
return g;
131131
}
132132
133-
fn lookat(dir: vec3<f32>, up: vec3<f32>) -> mat3x3<f32> {
134-
let dir = normalize(dir);
133+
fn lookat(dir_: vec3<f32>, up: vec3<f32>) -> mat3x3<f32> {
134+
let dir = normalize(dir_);
135135
let rt = normalize(cross(dir, normalize(up)));
136136
return mat3x3<f32>(rt, cross(rt, dir), dir);
137137
}
@@ -141,8 +141,8 @@
141141
t=i_time*7.0;
142142
let fro=path(t);
143143
adv=path(t+6.+sin(t*.1)*3.);
144-
let dir=normalize(vec3<f32>(uv, 0.7));
145-
let dir=lookat(adv-fro, vec3<f32>(0.0, 1.0, 0.0)) * dir;
144+
var dir=normalize(vec3<f32>(uv, 0.7));
145+
dir=lookat(adv-fro, vec3<f32>(0.0, 1.0, 0.0)) * dir;
146146
let col=march(fro, dir, frag_coord);
147147
return vec4<f32>(col,1.0);
148148
}

examples/shadertoy_riders.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
return mat2x2<f32>(c, s, -s, c);
1111
}
1212
13-
fn render(p: vec2<f32>) -> vec3<f32> {
14-
var p = p;
13+
fn render(p_: vec2<f32>) -> vec3<f32> {
14+
var p = p_;
1515
p*=rot(i_time*.1)*(.0002+.7*pow(smoothstep(0.0,0.5,abs(0.5-fract(i_time*.01))),3.));
1616
p.y-=.2266;
1717
p.x+=.2082;

examples/shadertoy_sea.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,21 @@
44
55
// migrated from https://www.shadertoy.com/view/Ms2SD1, "Seascape" by Alexander Alekseev aka TDM - 2014
66
7-
let NUM_STEPS = 8;
8-
let PI = 3.141592;
9-
let EPSILON = 0.001;
7+
const NUM_STEPS = 8;
8+
const PI = 3.141592;
9+
const EPSILON = 0.001;
1010
11-
let ITER_GEOMETRY = 3;
12-
let ITER_FRAGMENT = 5;
11+
const ITER_GEOMETRY = 3;
12+
const ITER_FRAGMENT = 5;
1313
14-
let SEA_HEIGHT = 0.6;
15-
let SEA_CHOPPY = 4.0;
16-
let SEA_SPEED = 0.8;
17-
let SEA_FREQ = 0.16;
18-
let SEA_BASE = vec3<f32>(0.0,0.09,0.18);
19-
let SEA_WATER_COLOR = vec3<f32>(0.48, 0.54, 0.36);
14+
const SEA_HEIGHT = 0.6;
15+
const SEA_CHOPPY = 4.0;
16+
const SEA_SPEED = 0.8;
17+
const SEA_FREQ = 0.16;
18+
const SEA_BASE = vec3<f32>(0.0,0.09,0.18);
19+
const SEA_WATER_COLOR = vec3<f32>(0.48, 0.54, 0.36);
2020
21-
// let octave_m = mat2x2<f32>(1.6, 1.2, -1.2, 1.6);
21+
// const octave_m = mat2x2<f32>(1.6, 1.2, -1.2, 1.6);
2222
2323
fn hash( p : vec2<f32> ) -> f32 {
2424
// let h = dot(p,vec2<f32>(127.1,311.7)); // percession issue?
@@ -60,15 +60,15 @@
6060
}
6161
6262
// sky
63-
fn getSkyColor( e : vec3<f32> ) -> vec3<f32> {
64-
var e = e;
63+
fn getSkyColor( e_ : vec3<f32> ) -> vec3<f32> {
64+
var e = e_;
6565
e.y = (max(e.y,0.0) * 0.8 + 0.2) * 0.8;
6666
return vec3<f32>(pow(1.0-e.y, 2.0), 1.0-e.y, 0.6+(1.0-e.y)*0.4) * 1.1;
6767
}
6868
6969
// sea
70-
fn sea_octave( uv : vec2<f32>, choppy : f32 ) -> f32 {
71-
let uv = uv + noise(uv);
70+
fn sea_octave( uv_ : vec2<f32>, choppy : f32 ) -> f32 {
71+
let uv = uv_ + noise(uv_);
7272
var wv = 1.0-abs(sin(uv));
7373
let swv = abs(cos(uv));
7474
wv = mix(wv,swv,wv);
@@ -197,7 +197,7 @@
197197
}
198198
color = color / 9.0;
199199
200-
let color = getPixel(frag_coord, time);
200+
color = getPixel(frag_coord, time);
201201
202202
// post
203203
return vec4<f32>(pow(color, vec3<f32>(0.65)), 1.0);

0 commit comments

Comments
 (0)