Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to wgpu-native v0.14.2.3 #329

Merged
merged 20 commits into from
Jan 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,20 @@ Possible sections in each release:
* Security: in case of vulnerabilities.



### [v0.9.0]


In this release the API is aligned with the latest webgpu.idl, and
we updated to the latest release of wgpu-native (v0.14.2.3).

Changed:

* Aligned API with the latest webgpu.idl.
* To use the default `min_binding_size` in `create_bind_group_layout`, it should be `None` instead of zero.
* If the depth-stencil texture has not room for stencil data, the `stencil_read_mask` and `stencil_write_mask` fields in the `DepthStencilState` struct passed to `create_render_pipeline()` must be set to 0.
* In WGSL, `@stage(compute)` must now be `@compute`. Same for `vertex` and `fragment`.
* In WGSL, the list of reserved words has been extended, including e.g. `mod`, `matrix` and `ref`.
* In WGSL, `smoothStep` is now `smoothstep`.

Added:

Expand Down
31 changes: 26 additions & 5 deletions codegen/hparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,29 @@ def _parse_from_h(self):
name = name1[4:]
self.enums[name] = enum = {}
for f in code[i2 + 1 : i3].strip().strip(";").split(","):
parts = remove_c_comments(f).strip().split()
key, val = parts[0], parts[-1]
f = remove_c_comments(f).strip()
if not f:
continue # happens when last item has a comma
key, _, val = f.partition("=")
# Handle key
key = key.strip()
assert key.startswith("WGPU") and "_" in key
key = key.split("_")[1]
enum[key] = int(val, 16) if val.startswith("0x") else int(val)
key = key.split("_", 1)[1]
# Turn value into an int
val = val.strip()
if val.startswith("0x"):
enum[key] = int(val, 16)
elif "<<" in val:
val1, _, val2 = val.partition("<<")
enum[key] = int(val1) << int(val2)
elif "|" in val: # field is an OR of the earlier fields :/
keys = [k.strip().split("_", 1)[1] for k in val.split("|")]
val = 0
for k in keys:
val |= enum[k]
enum[key] = val
else:
enum[key] = int(val)

# Turn some enums into flags
for line in code.splitlines():
Expand Down Expand Up @@ -119,7 +137,10 @@ def _parse_from_h(self):
name = code[i3 + 1 : i4].strip()
self.structs[name] = struct = {}
for f in code[i2 + 1 : i3].strip().strip(";").split(";"):
parts = remove_c_comments(f).strip().split()
f = remove_c_comments(f).strip()
if not f:
continue # probably last item ended with a comma
parts = f.strip().split()
typename = " ".join(parts[:-1])
typename = typename.replace("const ", "")
key = parts[-1].strip("*")
Expand Down
6 changes: 3 additions & 3 deletions download-wgpu-native.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,11 @@ def main(version, os_string, arch, upstream):
headerfile2 = "wgpu.h"
binaryfile = None
if os_string == "linux":
binaryfile = "libwgpu.so"
binaryfile = "libwgpu_native.so"
elif os_string == "macos":
binaryfile = "libwgpu.dylib"
binaryfile = "libwgpu_native.dylib"
elif os_string == "windows":
binaryfile = "libwgpu.dll"
binaryfile = "wgpu_native.dll"
else:
raise RuntimeError(f"Platform '{os_string}' not supported")
root, ext = os.path.splitext(binaryfile)
Expand Down
2 changes: 1 addition & 1 deletion examples/compute_noop.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
@group(0) @binding(1)
var<storage,read_write> data2: array<i32>;

@stage(compute)
@compute
@workgroup_size(1)
fn main(@builtin(global_invocation_id) index: vec3<u32>) {
let i: u32 = index.x;
Expand Down
15 changes: 10 additions & 5 deletions examples/cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@
{
"offset": 0,
"bytes_per_row": texture_data.strides[0],
"rows_per_image": 0,
},
texture_size,
)
Expand All @@ -163,8 +162,12 @@
@location(0) texcoord: vec2<f32>,
@builtin(position) pos: vec4<f32>,
};
struct FragmentOutput {
@location(0) color : vec4<f32>,
};


@stage(vertex)
@vertex
fn vs_main(in: VertexInput) -> VertexOutput {
let ndc: vec4<f32> = r_locals.transform * in.pos;
var out: VertexOutput;
Expand All @@ -179,11 +182,13 @@
@group(0) @binding(2)
var r_sampler: sampler;

@stage(fragment)
fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
@fragment
fn fs_main(in: VertexOutput) -> FragmentOutput {
let value = textureSample(r_tex, r_sampler, in.texcoord).r;
let physical_color = vec3<f32>(pow(value, 2.2)); // gamma correct
return vec4<f32>(physical_color.rgb, 1.0);
var out: FragmentOutput;
out.color = vec4<f32>(physical_color.rgb, 1.0);
return out;
}
"""

Expand Down
30 changes: 15 additions & 15 deletions examples/shadertoy_flyby.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@

pos = p;

tub = -length(p.xy) + 0.45 + sin(p.z*10.0) * 0.1 * smoothStep(0.4,0.5,abs(0.5-fract(p.z*0.05))*2.0);
tub = -length(p.xy) + 0.45 + sin(p.z*10.0) * 0.1 * smoothstep(0.4,0.5,abs(0.5-fract(p.z*0.05))*2.0);
var co = coso(pp);
co=min(co, coso(pp + 0.7) );
co=min(co, coso(pp - 0.7) );
Expand All @@ -98,26 +98,26 @@
}


fn march(from: vec3<f32>, dir: vec3<f32>) -> vec3<f32> {
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;
var td: f32 = 0.0;
var g: f32 = 0.0;
var ref: f32 = 0.0;
var reff: f32 = 0.0;
var ltd: f32 = 0.0;
var li: f32 = 0.0;
var p: vec3<f32> = from;
var p: vec3<f32> = fro;
for(var i: i32 = 0; i < 200; i += 1) {
p += dir * d;
d = de(p);
if (d < det && ref == 0.0 && hit == 1.0) {
if (d < det && reff == 0.0 && hit == 1.0) {
var e: vec2<f32> = vec2<f32>(0.0, 0.1);
var n: vec3<f32> = normalize(vec3<f32>(de(p + e.yxx), de(p + e.xyx), de(p + e.xxy)) - de(p));
p -= dir * d * 2.0;
dir = reflect(dir, n);
ref = 1.0;
reff = 1.0;
td = 0.0;
ltd = td;
continue;
Expand All @@ -131,7 +131,7 @@
}
g = max(g, li * 0.15);
var f: f32 = 1.0 - td / 3.0;
if (ref == 1.0) {
if (reff == 1.0) {
f = 1.0 - ltd / 3.0;
}
if (d < 0.01) {
Expand All @@ -153,11 +153,11 @@
glo = vec3<f32>(glo_rb.x, glo.y, glo_rb.y);
col += glo;
col *= vec3<f32>(0.8, 0.7, 0.7);
col = mix(col, vec3<f32>(1.0), ref * 0.3);
col = mix(col, vec3<f32>(1.0), reff * 0.3);
return col;
}

fn mod( x : f32, y : f32 ) -> f32 {
fn mod1( x : f32, y : f32 ) -> f32 {
return x - y * floor( x / y );
}

Expand All @@ -168,17 +168,17 @@

var t = i_time;

var from = path(t);
if (mod(t, 10.0) > 5.0) {
from = path(floor(t / 4.0 + 0.5) * 4.0);
var fro = path(t);
if (mod1(t, 10.0) > 5.0) {
fro = path(floor(t / 4.0 + 0.5) * 4.0);
}
sphpos = path(t + 0.5);
from.x += 0.2;
var fw = normalize(path(t + 0.5) - from);
fro.x += 0.2;
var fw = normalize(path(t + 0.5) - fro);
var dir = normalize(vec3<f32>(uv, 0.5));
dir = lookat(fw, vec3<f32>(fw.x * 2.0, 1.0, 0.0)) * dir;
dir = vec3<f32>(dir.x+sin(t) * 0.3, dir.y, dir.z+sin(t) * 0.3);
var col = march(from, dir);
var col = march(fro, dir);
col = mix(vec3<f32>(0.5) * length(col), col, 0.8);
return vec4<f32>(col, 1.0);
}
Expand Down
8 changes: 4 additions & 4 deletions examples/shadertoy_gen_art.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
return mat2x2<f32>(cos(_angle),-sin(_angle),sin(_angle),cos(_angle));
}

fn mod( v: vec2<f32>, y : f32 ) -> vec2<f32> {
fn mod2( v: vec2<f32>, y : f32 ) -> vec2<f32> {
return vec2<f32>(v.x - y * floor( v.x / y ), v.y - y * floor( v.y / y ));
}

Expand All @@ -26,10 +26,10 @@
}

fn getColorComponent( st: vec2<f32>, modScale : f32, blur : f32 ) -> f32 {
let modSt = mod(st, 1. / modScale) * modScale * 2. - 1.;
let modSt = mod2(st, 1. / modScale) * modScale * 2. - 1.;
let dist = length(modSt);
let angle = atan2(modSt.x, modSt.y) + sin(i_time * .08) * 9.0;
let shapeMap = smoothStep(SHAPE_SIZE + blur, SHAPE_SIZE - blur, sin(dist * 3.0) * .5 + .5);
let shapeMap = smoothstep(SHAPE_SIZE + blur, SHAPE_SIZE - blur, sin(dist * 3.0) * .5 + .5);
return shapeMap;
}

Expand Down Expand Up @@ -75,7 +75,7 @@
let origDist = length(origSt);
let colorGrading = mix(topGrading, bottomGrading, origDist - .5);
var fragColor = vec4<f32>(pow(color.rgb, colorGrading), 1.);
// fragColor *= smoothStep(2.1, .7, origDist);
// fragColor *= smoothstep(2.1, .7, origDist);
return fragColor;
}

Expand Down
14 changes: 7 additions & 7 deletions examples/shadertoy_liberation.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
return mat2x2<f32>(c, s, -s, c);
}

fn mod( x : f32, y : f32 ) -> f32 {
fn mod1( x : f32, y : f32 ) -> f32 {
return x - y * floor( x / y );
}

fn de(pos: vec3<f32>) -> f32 {
var t = mod(i_time, 17.0);
var a = smoothStep(13.0, 15.0, t) * 8.0 - smoothStep(4.0, 0.0, t) * 4.0;
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;
Expand Down Expand Up @@ -93,12 +93,12 @@
return normalize( vec3<f32>( de(p + d.yxx), de(p + d.xyx), de(p + d.xxy) ) - de(p) );
}

fn march(from: 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 = from;
var p = fro;
var col = vec3<f32>(0.0);
var dir = dir;

Expand Down Expand Up @@ -128,10 +128,10 @@
var uv = frag_coord / i_resolution - 0.5;
uv.x *= i_resolution.x / i_resolution.y;

var from = vec3<f32>(0.0, 0.0, -10.0);
var fro = vec3<f32>(0.0, 0.0, -10.0);
var dir = normalize(vec3<f32>(uv, 1.0));

var col = march(from, dir, frag_coord);
var col = march(fro, dir, frag_coord);

return vec4<f32>(col, 1.0);
}
Expand Down
16 changes: 8 additions & 8 deletions examples/shadertoy_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
return mat2x2<f32>(c, s, -s, c);
}

fn mod( x : f32, y : f32 ) -> f32 {
fn mod1( x : f32, y : f32 ) -> f32 {
return x - y * floor( x / y );
}

Expand All @@ -34,7 +34,7 @@

fn path(t: f32) -> vec3<f32> {
var p = vec3<f32>(sin(t*.1)*10., cos(t*.05)*10., t);
p.x += smoothStep(.0,.5,abs(.5-fract(t*.02)))*10.;
p.x += smoothstep(.0,.5,abs(.5-fract(t*.02)))*10.;
return p;
}

Expand Down Expand Up @@ -81,7 +81,7 @@

let s = sign(p.y);
p.y = -abs(p.y) - 3.0;
p.z = mod(p.z, 20.0) - 10.0;
p.z = mod1(p.z, 20.0) - 10.0;

for (var i = 0; i < 5; i+=1) {
p = abs(p) - 1.0;
Expand All @@ -105,7 +105,7 @@
return d*0.7;
}

fn march(from: 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 p = vec3<f32>(0.);
var n = vec3<f32>(0.);
var g = vec3<f32>(0.);
Expand All @@ -114,7 +114,7 @@
var td = 0.0;

for (var i = 0; i < 80; i+=1) {
p = from + td*dir;
p = fro + td*dir;
d = de(p) * (1.0- hash( frag_coord.xy + vec2<f32>(t) )*0.3);
if (d < det && boxhit < 0.5) {
break;
Expand All @@ -139,11 +139,11 @@
fn shader_main(frag_coord: vec2<f32>) -> vec4<f32> {
let uv = (frag_coord-i_resolution.xy*.5)/i_resolution.y;
t=i_time*7.0;
let from=path(t);
let fro=path(t);
adv=path(t+6.+sin(t*.1)*3.);
let dir=normalize(vec3<f32>(uv, 0.7));
let dir=lookat(adv-from, vec3<f32>(0.0, 1.0, 0.0)) * dir;
let col=march(from, dir, frag_coord);
let 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
2 changes: 1 addition & 1 deletion examples/shadertoy_riders.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

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*=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;
var ot = vec2<f32>(100.0);
Expand Down
2 changes: 1 addition & 1 deletion examples/shadertoy_sea.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@
return mix(
getSkyColor(dir),
getSeaColor(p,n,light,dir,dist),
pow(smoothStep(0.0,-0.02,dir.y),0.2)
pow(smoothstep(0.0,-0.02,dir.y),0.2)
);
}

Expand Down
Loading