Skip to content

Commit

Permalink
Update to wgpu-native 0.17.0.2 (#370)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
almarklein and Korijn authored Oct 9, 2023
1 parent 7c2b096 commit f2b7709
Show file tree
Hide file tree
Showing 25 changed files with 1,298 additions and 1,074 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,11 @@ jobs:
run: |
python -m pip install --upgrade pip wheel setuptools twine
- name: Build wheels
uses: pypa/[email protected]
uses: pypa/[email protected]
env:
CIBW_MANYLINUX_X86_64_IMAGE: quay.io/pypa/manylinux_2_28_x86_64
CIBW_ARCHS_LINUX: x86_64
CIBW_SKIP: cp39-musllinux_x86_64
with:
output-dir: dist
- name: Twine check
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ Added:

* New `wgpu.wgsl_language_features` property, which for now always returns an empty set.
* The `GPUShaderModule.compilation_info` property (and its async version) are replaced with a `get_compilation_info()` method.
* The WebGPU features "bgra8unorm-storage" and "float32-filterable" are now available.

Changed:

* The binary wheels are now based on manylinux 2.28, and the 32bit Linux wheels are no longer built.
* In WGSL: toplevel constants must be defined using `const`, using `let` will now fail.
* In WGSL: it is no longer possible to re-declare an existing variable name.
* Error messages may look a bit different, since wgpu-native now produces nice messages replacing our custom ones.
* Errors produced by a call into a wgpu-native function now produce a Python exception (no more async logging of errors).


### [v0.9.5] - 02-10-2023
Expand Down
20 changes: 16 additions & 4 deletions codegen/hparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,21 @@ def _get_wgpu_header():
# Just removing them, plus a few extra lines, seems to do the trick.
lines2 = []
for line in lines1:
if line.startswith("#"):
if line.startswith("#define ") and len(line.split()) > 2 and "0x" in line:
line = line.replace("(", "").replace(")", "")
elif line.startswith("#"):
continue
elif 'extern "C"' in line:
continue
line = line.replace("WGPU_EXPORT ", "")
for define_to_drop in [
"WGPU_EXPORT ",
"WGPU_NULLABLE ",
" WGPU_OBJECT_ATTRIBUTE",
" WGPU_ENUM_ATTRIBUTE",
" WGPU_FUNCTION_ATTRIBUTE",
" WGPU_STRUCTURE_ATTRIBUTE",
]:
line = line.replace(define_to_drop, "")
lines2.append(line)
return "\n".join(lines2)

Expand Down Expand Up @@ -68,7 +78,7 @@ def _parse_from_h(self):
code = self.source

# Collect enums and flags. This is easy.
# Note that flags are defines as enums and then defined as flags later.
# Note that flags are first defined as enums and then redefined as flags later.
i1 = i2 = i3 = i4 = 0
while True:
# Find enum
Expand Down Expand Up @@ -113,7 +123,9 @@ def _parse_from_h(self):
# Turn some enums into flags
for line in code.splitlines():
if line.startswith("typedef WGPUFlags "):
name = line.strip().strip(";").split()[-1]
parts = line.strip().strip(";").split()
assert len(parts) == 3
name = parts[-1]
if name.endswith("Flags"):
assert name.startswith("WGPU")
name = name[4:-5]
Expand Down
8 changes: 6 additions & 2 deletions codegen/rspatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,15 @@ def apply(self, code):
detected = set()

for line, i in self.iter_lines():
if "lib.wgpu" in line:
start = line.index("lib.wgpu") + 4
if "lib.wgpu" in line or "libf.wgpu" in line:
start = line.index(".wgpu") + 1
end = line.index("(", start)
name = line[start:end]
indent = " " * (len(line) - len(line.lstrip()))
if "lib.wgpu" in line:
self.insert_line(
i, f"{indent}# FIXME: wgpu func calls must be done from libf"
)
if name not in hp.functions:
msg = f"unknown C function {name}"
self.insert_line(i, f"{indent}# FIXME: {msg}")
Expand Down
4 changes: 2 additions & 2 deletions codegen/tests/test_codegen_rspatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ def dedent(code):

def test_patch_functions():
code1 = """
lib.wgpuAdapterRequestDevice(1, 2, 3)
lib.wgpuFooBar(1, 2, 3)
libf.wgpuAdapterRequestDevice(1, 2, 3)
libf.wgpuFooBar(1, 2, 3)
"""

code2 = patch_rs_backend(dedent(code1))
Expand Down
4 changes: 2 additions & 2 deletions examples/shadertoy_blink.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

shader_code = """
fn render(p: vec2<f32>) -> vec3<f32> {
fn render(p_: vec2<f32>) -> vec3<f32> {
let s = sin(i_time) * sin(i_time) * sin(i_time) + 0.5;
var p = p;
var p = p_;
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;
var col = vec3<f32>(0.0);
Expand Down
4 changes: 2 additions & 2 deletions examples/shadertoy_circuits.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
return mat2x2<f32>(c, s, -s, c);
}
fn fractal(p: vec2<f32>) -> vec3<f32> {
var p = vec2<f32>(p.x/p.y,1./p.y);
fn fractal(p_: vec2<f32>) -> vec3<f32> {
var p = vec2<f32>(p_.x/p_.y,1./p_.y);
p.y+=i_time*sign(p.y);
p.x+=sin(i_time*.1)*sign(p.y)*4.;
p.y=fract(p.y*.05);
Expand Down
18 changes: 9 additions & 9 deletions examples/shadertoy_flyby.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
return mat2x2<f32>(c, s, -s, c);
}
fn fractal(p: vec2<f32>) -> vec3<f32> {
var p = fract(p*0.1);
fn fractal(p_: vec2<f32>) -> vec3<f32> {
var p = fract(p_*0.1);
var m = 1000.0;
for (var i = 0; i < 7; i = i + 1) {
p = ( abs(p) / clamp( abs(p.x*p.y), 0.25, 2.0 ) ) - 1.2;
Expand All @@ -39,8 +39,8 @@
return m*vec3<f32>(abs(p.x),m,abs(p.y));
}
fn coso(pp: vec3<f32>) -> f32 {
var pp = pp;
fn coso(pp_: vec3<f32>) -> f32 {
var pp = pp_;
pp*=.7;
pp = vec3<f32>( pp.xy * rot(pp.z*2.0), pp.z);
Expand All @@ -63,11 +63,11 @@
return d;
}
fn de(p: vec3<f32>) -> f32 {
fn de(p_: vec3<f32>) -> f32 {
hit=0.;
br=1000.;
let pp = p - sphpos;
var p = p;
let pp = p_ - sphpos;
var p = p_;
let pxy = p.xy - path(p.z).xy;
p.x = pxy.x;
p.y = pxy.y;
Expand Down Expand Up @@ -98,8 +98,8 @@
}
fn march(fro: vec3<f32>, dir: vec3<f32>) -> vec3<f32> {
var dir = dir;
fn march(fro: vec3<f32>, dir_: vec3<f32>) -> vec3<f32> {
var dir = dir_;
var uv: vec2<f32> = vec2<f32>( atan2( dir.x , dir.y ) + i_time * 0.5, length(dir.xy) + sin(i_time * 0.2));
var col: vec3<f32> = fractal(uv);
var d: f32 = 0.0;
Expand Down
12 changes: 6 additions & 6 deletions examples/shadertoy_gen_art.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
// migrated from: https://www.shadertoy.com/view/mds3DX
let SHAPE_SIZE : f32 = .618;
let CHROMATIC_ABBERATION : f32 = .01;
let ITERATIONS : f32 = 10.;
let INITIAL_LUMA : f32= .5;
const SHAPE_SIZE : f32 = .618;
const CHROMATIC_ABBERATION : f32 = .01;
const ITERATIONS : f32 = 10.;
const INITIAL_LUMA : f32= .5;
let PI : f32 = 3.14159265359;
let TWO_PI : f32 = 6.28318530718;
const PI : f32 = 3.14159265359;
const TWO_PI : f32 = 6.28318530718;
fn rotate2d(_angle : f32) -> mat2x2<f32> {
return mat2x2<f32>(cos(_angle),-sin(_angle),sin(_angle),cos(_angle));
Expand Down
10 changes: 5 additions & 5 deletions examples/shadertoy_glsl_flame.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
float d = 0.0, glow = 0.0, eps = 0.02;
vec3 p = org;
bool glowed = false;
for(int i=0; i<64; i++)
{
d = scene(p) + eps;
Expand All @@ -58,15 +58,15 @@
{
vec2 v = -1.0 + 2.0 * fragCoord.xy / iResolution.xy;
v.x *= iResolution.x/iResolution.y;
vec3 org = vec3(0., -2., 4.);
vec3 dir = normalize(vec3(v.x*1.6, -v.y, -1.5));
vec4 p = raymarch(org, dir);
float glow = p.w;
vec4 col = mix(vec4(1.,.5,.1,1.), vec4(0.1,.5,1.,1.), p.y*.02+.4);
fragColor = mix(vec4(0.), col, pow(glow*2.,4.));
//fragColor = mix(vec4(1.), mix(vec4(1.,.5,.1,1.),vec4(0.1,.5,1.,1.),p.y*.02+.4), pow(glow*2.,4.));
Expand Down
8 changes: 4 additions & 4 deletions examples/shadertoy_liberation.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
return x - y * floor( x / y );
}
fn de(pos: vec3<f32>) -> f32 {
fn de(pos_: vec3<f32>) -> f32 {
var t = mod1(i_time, 17.0);
var a = smoothstep(13.0, 15.0, t) * 8.0 - smoothstep(4.0, 0.0, t) * 4.0;
var f = sin(i_time * 5.0 + sin(i_time * 20.0) * 0.2);
var pos = pos;
var pos = pos_;
let pxz = pos.xz * rot(i_time + 0.5);
pos.x = pxz.x;
Expand Down Expand Up @@ -93,14 +93,14 @@
return normalize( vec3<f32>( de(p + d.yxx), de(p + d.xyx), de(p + d.xxy) ) - de(p) );
}
fn march(fro: vec3<f32>, dir: vec3<f32>, frag_coord: vec2<f32>) -> vec3<f32> {
fn march(fro: vec3<f32>, dir_: vec3<f32>, frag_coord: vec2<f32>) -> vec3<f32> {
var d = 0.0;
var td = 0.0;
var maxdist = 30.0;
var p = fro;
var col = vec3<f32>(0.0);
var dir = dir;
var dir = dir_;
for (var i = 0; i < 100; i+=1) {
var d2 = de(p) * (1.0 - hash12(frag_coord.xy + i_time) * 0.2);
Expand Down
18 changes: 9 additions & 9 deletions examples/shadertoy_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// migrated from https://www.shadertoy.com/view/NlsXDH, By Kali
let det = 0.001;
const det = 0.001;
var<private> t: f32;
var<private> boxhit: f32;
Expand Down Expand Up @@ -38,8 +38,8 @@
return p;
}
fn fractal(p: vec2<f32>) -> f32 {
var p = abs( 5.0 - mod_2( p*0.2, 10.0 ) ) - 5.0;
fn fractal(p_: vec2<f32>) -> f32 {
var p = abs( 5.0 - mod_2( p_*0.2, 10.0 ) ) - 5.0;
var ot = 1000.;
for (var i = 0; i < 7; i+=1) {
p = abs(p) / clamp(p.x*p.y, 0.25, 2.0) - 1.0;
Expand All @@ -56,7 +56,8 @@
return length(max(vec3<f32>(0.),c))+min(0.,max(c.x,max(c.y,c.z)));
}
fn de(p: vec3<f32>) -> f32 {
fn de(p_: vec3<f32>) -> f32 {
var p = p_;
boxhit = 0.0;
var p2 = p-adv;
Expand All @@ -74,7 +75,6 @@
let b = box(p2, vec3<f32>(1.0));
var p = p;
let p_xy = p.xy - path(p.z).xy;
p.x = p_xy.x;
p.y = p_xy.y;
Expand Down Expand Up @@ -130,8 +130,8 @@
return g;
}
fn lookat(dir: vec3<f32>, up: vec3<f32>) -> mat3x3<f32> {
let dir = normalize(dir);
fn lookat(dir_: vec3<f32>, up: vec3<f32>) -> mat3x3<f32> {
let dir = normalize(dir_);
let rt = normalize(cross(dir, normalize(up)));
return mat3x3<f32>(rt, cross(rt, dir), dir);
}
Expand All @@ -141,8 +141,8 @@
t=i_time*7.0;
let fro=path(t);
adv=path(t+6.+sin(t*.1)*3.);
let dir=normalize(vec3<f32>(uv, 0.7));
let dir=lookat(adv-fro, vec3<f32>(0.0, 1.0, 0.0)) * dir;
var dir=normalize(vec3<f32>(uv, 0.7));
dir=lookat(adv-fro, vec3<f32>(0.0, 1.0, 0.0)) * dir;
let col=march(fro, dir, frag_coord);
return vec4<f32>(col,1.0);
}
Expand Down
4 changes: 2 additions & 2 deletions examples/shadertoy_riders.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
return mat2x2<f32>(c, s, -s, c);
}
fn render(p: vec2<f32>) -> vec3<f32> {
var p = p;
fn render(p_: vec2<f32>) -> vec3<f32> {
var p = p_;
p*=rot(i_time*.1)*(.0002+.7*pow(smoothstep(0.0,0.5,abs(0.5-fract(i_time*.01))),3.));
p.y-=.2266;
p.x+=.2082;
Expand Down
34 changes: 17 additions & 17 deletions examples/shadertoy_sea.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@
// migrated from https://www.shadertoy.com/view/Ms2SD1, "Seascape" by Alexander Alekseev aka TDM - 2014
let NUM_STEPS = 8;
let PI = 3.141592;
let EPSILON = 0.001;
const NUM_STEPS = 8;
const PI = 3.141592;
const EPSILON = 0.001;
let ITER_GEOMETRY = 3;
let ITER_FRAGMENT = 5;
const ITER_GEOMETRY = 3;
const ITER_FRAGMENT = 5;
let SEA_HEIGHT = 0.6;
let SEA_CHOPPY = 4.0;
let SEA_SPEED = 0.8;
let SEA_FREQ = 0.16;
let SEA_BASE = vec3<f32>(0.0,0.09,0.18);
let SEA_WATER_COLOR = vec3<f32>(0.48, 0.54, 0.36);
const SEA_HEIGHT = 0.6;
const SEA_CHOPPY = 4.0;
const SEA_SPEED = 0.8;
const SEA_FREQ = 0.16;
const SEA_BASE = vec3<f32>(0.0,0.09,0.18);
const SEA_WATER_COLOR = vec3<f32>(0.48, 0.54, 0.36);
// let octave_m = mat2x2<f32>(1.6, 1.2, -1.2, 1.6);
// const octave_m = mat2x2<f32>(1.6, 1.2, -1.2, 1.6);
fn hash( p : vec2<f32> ) -> f32 {
// let h = dot(p,vec2<f32>(127.1,311.7)); // percession issue?
Expand Down Expand Up @@ -60,15 +60,15 @@
}
// sky
fn getSkyColor( e : vec3<f32> ) -> vec3<f32> {
var e = e;
fn getSkyColor( e_ : vec3<f32> ) -> vec3<f32> {
var e = e_;
e.y = (max(e.y,0.0) * 0.8 + 0.2) * 0.8;
return vec3<f32>(pow(1.0-e.y, 2.0), 1.0-e.y, 0.6+(1.0-e.y)*0.4) * 1.1;
}
// sea
fn sea_octave( uv : vec2<f32>, choppy : f32 ) -> f32 {
let uv = uv + noise(uv);
fn sea_octave( uv_ : vec2<f32>, choppy : f32 ) -> f32 {
let uv = uv_ + noise(uv_);
var wv = 1.0-abs(sin(uv));
let swv = abs(cos(uv));
wv = mix(wv,swv,wv);
Expand Down Expand Up @@ -197,7 +197,7 @@
}
color = color / 9.0;
let color = getPixel(frag_coord, time);
color = getPixel(frag_coord, time);
// post
return vec4<f32>(pow(color, vec3<f32>(0.65)), 1.0);
Expand Down
Loading

0 comments on commit f2b7709

Please sign in to comment.