Skip to content

Commit 81a56fd

Browse files
LegNeatoFirestar99
andauthored
Update deps (#33)
* Update to latest rust-gpu and deps Note this currently depends on a git version of winit as they are changing apis in the next release. * move spirv-builder and spirv-std version declaration to a central place to minimize mismatches * workaround naga failing by using spirv-passthrough for now * Use workspace dependencies * Uncomment shader * Turn off validation and debug * Dynamically detect passthrough * Add back env_logger * Feature gate shaders that don't currently work on macOS * Update to latest winit main and rust-gpu main * Update to latest wgpu Just one more fix to land before I can move the last feature gating * Enable all shaders now that wgpu is fixed --------- Co-authored-by: Firestar99 <[email protected]>
1 parent 9aa4819 commit 81a56fd

35 files changed

+2975
-1912
lines changed

Cargo.lock

Lines changed: 2311 additions & 1315 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
[package]
22
name = "shadertoys-wgpu"
33
version = "0.0.0"
4+
publish = false
45
authors = []
5-
edition = "2018"
6+
edition = "2021"
67

78
[features]
89
default = ["use-compiled-tools"]
@@ -11,20 +12,28 @@ use-compiled-tools = ["spirv-builder/use-compiled-tools"]
1112

1213
[dependencies]
1314
shared = { path = "shared" }
14-
futures = { version = "0.3", default-features = false, features = ["std", "executor"] }
15-
wgpu = "0.6.0"
16-
winit = { version = "0.23", features = ["web-sys"] }
17-
wgpu-subscriber = "0.1.0"
15+
futures = { version = "0.3", default-features = false, features = [
16+
"std",
17+
"executor"
18+
] }
19+
wgpu = { git = "https://github.com/gfx-rs/wgpu.git", rev = "8010203281d2f7c1accf8bfcc24de399278b9562", features = [
20+
"spirv",
21+
"vulkan-portability"
22+
] }
23+
winit = { git = "https://github.com/rust-windowing/winit.git", rev = "cdbdd974fbf79b82b3fb1a4bc84ed717312a3bd2" }
24+
bytemuck = "1.20.0"
25+
env_logger = "0.11.6"
26+
ouroboros = "0.18.5"
1827

1928
[build-dependencies]
20-
spirv-builder = { version = "*", default-features = false }
29+
spirv-builder.workspace = true
2130

2231
[workspace]
23-
members = ["shaders"]
32+
members = ["shaders", "shared"]
2433

25-
[patch.crates-io]
26-
spirv-builder = { git = "https://github.com/EmbarkStudios/rust-gpu", rev = "a173208d803aeac9295464df703c53d987db2664" }
27-
spirv-std = { git = "https://github.com/EmbarkStudios/rust-gpu", rev = "a173208d803aeac9295464df703c53d987db2664" }
34+
[workspace.dependencies]
35+
spirv-builder = { git = "https://github.com/Rust-GPU/rust-gpu", rev = "ac0c7035d53ae0bf87fbff12cc8ad4e6f6628834", default-features = false }
36+
spirv-std = { git = "https://github.com/Rust-GPU/rust-gpu", rev = "ac0c7035d53ae0bf87fbff12cc8ad4e6f6628834" }
2837

2938
# Compile build-dependencies in release mode with
3039
# the same settings as regular dependencies.
@@ -43,3 +52,8 @@ opt-level = 3
4352
# a long time (10 minutes if itself was optimized, over an hour otherwise).
4453
[profile.release.package."shadertoys-shaders"]
4554
opt-level = 0
55+
56+
[workspace.lints.rust]
57+
unexpected_cfgs = { level = "allow", check-cfg = [
58+
'cfg(target_arch, values("spirv"))'
59+
] }

build.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
use spirv_builder::SpirvBuilder;
1+
use spirv_builder::{MetadataPrintout, SpirvBuilder};
22
use std::error::Error;
33

4-
fn build_shader(path_to_create: &str) -> Result<(), Box<dyn Error>> {
5-
SpirvBuilder::new(path_to_create)
6-
.spirv_version(1, 0)
7-
.build()?;
4+
fn build_shader(path_to_crate: &str) -> Result<(), Box<dyn Error>> {
5+
let builder = SpirvBuilder::new(path_to_crate, "spirv-unknown-vulkan1.2")
6+
.print_metadata(MetadataPrintout::Full);
7+
8+
let _result = builder.build()?;
89
Ok(())
910
}
1011

rust-toolchain

Lines changed: 0 additions & 9 deletions
This file was deleted.

rust-toolchain.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[toolchain]
2+
channel = "nightly-2024-11-22"
3+
components = ["rust-src", "rustc-dev", "llvm-tools"]

shaders/Cargo.toml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22
name = "shadertoys-shaders"
33
version = "0.0.0"
44
authors = []
5-
edition = "2018"
5+
edition = "2021"
66

77
[lib]
88
crate-type = ["dylib"]
99

1010
[dependencies]
11-
spirv-std = "*"
11+
spirv-std.workspace = true
1212
shared = { path = "../shared" }
13+
14+
[lints]
15+
workspace = true

shaders/src/a_lot_of_spheres.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
//! ```
1313
1414
use shared::*;
15-
use spirv_std::glam::{const_mat2, vec2, vec3, Mat2, Vec2, Vec3, Vec3Swizzles, Vec4};
15+
use spirv_std::glam::{mat2, vec2, vec3, Mat2, Vec2, Vec3, Vec3Swizzles, Vec4};
1616

1717
// Note: This cfg is incorrect on its surface, it really should be "are we compiling with std", but
1818
// we tie #[no_std] above to the same condition, so it's fine.
@@ -41,7 +41,7 @@ const SPEED: f32 = 0.5;
4141
// math functions
4242
//
4343

44-
const _MR: Mat2 = const_mat2!([0.84147, 0.54030, 0.54030, -0.84147]);
44+
const _MR: Mat2 = mat2(vec2(0.84147, 0.54030), vec2(0.54030, -0.84147));
4545
fn hash(n: f32) -> f32 {
4646
(n.sin() * 43758.5453).gl_fract()
4747
}
@@ -135,16 +135,16 @@ impl Inputs {
135135
*dist = MAXDISTANCE;
136136
let mut distcheck: f32 = 0.0;
137137

138-
let mut sphere_center: Vec3 = Vec3::zero();
138+
let mut sphere_center: Vec3 = Vec3::ZERO;
139139
let mut col: Vec3;
140-
let mut normalcheck: Vec3 = Vec3::zero();
140+
let mut normalcheck: Vec3 = Vec3::ZERO;
141141
if intersect_plane(ro, rd, 0.0, &mut distcheck) && distcheck < MAXDISTANCE {
142142
*dist = distcheck;
143143
*material = 1;
144144
*normal = vec3(0.0, 1.0, 0.0);
145-
col = Vec3::one();
145+
col = Vec3::ONE;
146146
} else {
147-
col = Vec3::zero();
147+
col = Vec3::ZERO;
148148
}
149149

150150
// trace grid
@@ -159,7 +159,7 @@ impl Inputs {
159159
if *material > 1 || ro.xz().distance(pos.xz()) > *dist + GRIDSIZE {
160160
break;
161161
}
162-
let mut offset: Vec2 = Vec2::zero();
162+
let mut offset: Vec2 = Vec2::ZERO;
163163
get_sphere_offset(pos.xz(), &mut offset);
164164

165165
self.get_moving_sphere_position(pos.xz(), -offset, &mut sphere_center);
@@ -187,7 +187,7 @@ impl Inputs {
187187
i += 1;
188188
}
189189

190-
let mut color: Vec3 = Vec3::zero();
190+
let mut color: Vec3 = Vec3::ZERO;
191191
if *material > 0 {
192192
*intersection = ro + rd * *dist;
193193
let map: Vec2 = (intersection.xz() / GRIDSIZE).floor() * GRIDSIZE;
@@ -200,10 +200,10 @@ impl Inputs {
200200
let mut y = 0;
201201
while y < 3 {
202202
let mapoffset: Vec2 = map + vec2([c.x, c.y, c.z][x], [c.x, c.y, c.z][y]);
203-
let mut offset: Vec2 = Vec2::zero();
203+
let mut offset: Vec2 = Vec2::ZERO;
204204
get_sphere_offset(mapoffset, &mut offset);
205205
let lcolor: Vec3 = get_sphere_color(mapoffset);
206-
let mut lpos: Vec3 = Vec3::zero();
206+
let mut lpos: Vec3 = Vec3::ZERO;
207207
self.get_moving_sphere_position(mapoffset, -offset, &mut lpos);
208208

209209
let mut shadow: f32 = 1.0;
@@ -220,10 +220,10 @@ impl Inputs {
220220

221221
let smapoffset: Vec2 =
222222
map + vec2([c.x, c.y, c.z][x], [c.x, c.y, c.z][y]);
223-
let mut soffset: Vec2 = Vec2::zero();
223+
let mut soffset: Vec2 = Vec2::ZERO;
224224
get_sphere_offset(smapoffset, &mut soffset);
225-
let mut slpos: Vec3 = Vec3::zero();
226-
let mut sn: Vec3 = Vec3::zero();
225+
let mut slpos: Vec3 = Vec3::ZERO;
226+
let mut sn: Vec3 = Vec3::ZERO;
227227
get_sphere_position(smapoffset, soffset, &mut slpos);
228228
let mut sd: f32 = 0.0;
229229
if intersect_unit_sphere(
@@ -285,8 +285,8 @@ impl Inputs {
285285
let mut rd: Vec3 = (p.x * cu + p.y * cv + 1.5 * cw).normalize();
286286
// raytrace
287287
let mut material: i32 = 0;
288-
let mut normal: Vec3 = Vec3::zero();
289-
let mut intersection: Vec3 = Vec3::zero();
288+
let mut normal: Vec3 = Vec3::ZERO;
289+
let mut intersection: Vec3 = Vec3::ZERO;
290290
let mut dist: f32 = 0.0;
291291

292292
let mut col: Vec3 = self.trace(
@@ -312,7 +312,7 @@ impl Inputs {
312312
}
313313

314314
col = col.powf_vec(vec3(EXPOSURE, EXPOSURE, EXPOSURE));
315-
col = col.clamp(Vec3::zero(), Vec3::one());
315+
col = col.clamp(Vec3::ZERO, Vec3::ONE);
316316
// vigneting
317317
col *= 0.25 + 0.75 * (16.0 * q.x * q.y * (1.0 - q.x) * (1.0 - q.y)).powf(0.15);
318318

shaders/src/a_question_of_time.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ fn stroke(d: f32, w: f32, s: f32, i: f32) -> f32 {
6262
}
6363
// a simple palette
6464
fn pal(d: f32) -> Vec3 {
65-
0.5 * ((6.283 * d * vec3(2.0, 2.0, 1.0) + vec3(0.0, 1.4, 0.0)).cos() + Vec3::one())
65+
0.5 * ((6.283 * d * vec3(2.0, 2.0, 1.0) + vec3(0.0, 1.4, 0.0)).cos() + Vec3::ONE)
6666
}
6767
// 2d rotation matrix
6868
fn uvr_rotate(a: f32) -> Mat2 {
@@ -83,7 +83,7 @@ fn apollonian(uv: Vec2) -> Vec3 {
8383
// the algorithm is recursive and must start with a initial descartes configuration
8484
// each vec3 represents a circle with the form vec3(centerx, centery, 1./radius)
8585
// the signed inverse radius is also called the bend (refer to the article above)
86-
let mut dec: [Vec3; 4] = [Vec3::zero(), Vec3::zero(), Vec3::zero(), Vec3::zero()];
86+
let mut dec: [Vec3; 4] = [Vec3::ZERO, Vec3::ZERO, Vec3::ZERO, Vec3::ZERO];
8787
// a DEC is a configuration of 4 circles tangent to each other
8888
// the easiest way to build the initial one it to construct a symetric Steiner Chain.
8989
// http://mathworld.wolfram.com/SteinerChain.html
@@ -155,7 +155,7 @@ fn apollonian(uv: Vec2) -> Vec3 {
155155

156156
impl Inputs {
157157
fn scene(&self, mut uv: Vec2, ms: Vec4) -> Vec3 {
158-
let mut ci: Vec2 = Vec2::zero();
158+
let mut ci: Vec2 = Vec2::ZERO;
159159

160160
// drag your mouse to apply circle inversion
161161
if ms.y != -2.0 && ms.w > -2.0 {

shaders/src/apollonian.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ impl State {
3333
pub fn new(inputs: Inputs) -> Self {
3434
State {
3535
inputs,
36-
orb: Vec4::zero(),
36+
orb: Vec4::ZERO,
3737
}
3838
}
3939
}
@@ -101,7 +101,7 @@ impl State {
101101

102102
fn render(&mut self, ro: Vec3, rd: Vec3, anim: f32) -> Vec3 {
103103
// trace
104-
let mut col: Vec3 = Vec3::zero();
104+
let mut col: Vec3 = Vec3::ZERO;
105105
let t: f32 = self.trace(ro, rd, anim);
106106
if t > 0.0 {
107107
let tra: Vec4 = self.orb;
@@ -121,7 +121,7 @@ impl State {
121121
brdf += 1.0 * vec3(0.40, 0.40, 0.40) * bac * ao;
122122

123123
// material
124-
let mut rgb: Vec3 = Vec3::one();
124+
let mut rgb: Vec3 = Vec3::ONE;
125125
rgb = mix(rgb, vec3(1.0, 0.80, 0.2), (6.0 * tra.y).clamp(0.0, 1.0));
126126
rgb = mix(
127127
rgb,
@@ -139,7 +139,7 @@ impl State {
139139
pub fn main_image(&mut self, frag_color: &mut Vec4, frag_coord: Vec2) {
140140
let time: f32 = self.inputs.time * 0.25 + 0.01 * self.inputs.mouse.x;
141141
let anim: f32 = 1.1 + 0.5 * smoothstep(-0.3, 0.3, (0.1 * self.inputs.time).cos());
142-
let mut tot: Vec3 = Vec3::zero();
142+
let mut tot: Vec3 = Vec3::ZERO;
143143

144144
let mut jj = 0;
145145
while jj < AA {

shaders/src/atmosphere_system_test.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
//! ```
1212
1313
use shared::*;
14-
use spirv_std::glam::{const_vec3, vec2, vec3, Mat3, Vec2, Vec3, Vec3Swizzles, Vec4};
14+
use spirv_std::glam::{vec2, vec3, Mat3, Vec2, Vec3, Vec3Swizzles, Vec4};
1515

1616
// Note: This cfg is incorrect on its surface, it really should be "are we compiling with std", but
1717
// we tie #[no_std] above to the same condition, so it's fine.
@@ -38,7 +38,7 @@ impl State {
3838
}
3939
}
4040

41-
const PI: f32 = 3.14159265359;
41+
use core::f32::consts::PI;
4242

4343
#[derive(Copy, Clone)]
4444
struct Ray {
@@ -93,8 +93,8 @@ fn isect_sphere(ray: Ray, sphere: Sphere, t0: &mut f32, t1: &mut f32) -> bool {
9393
}
9494

9595
// scattering coefficients at sea level (m)
96-
const BETA_R: Vec3 = const_vec3!([5.5e-6, 13.0e-6, 22.4e-6]); // Rayleigh
97-
const BETA_M: Vec3 = const_vec3!([21e-6, 21e-6, 21e-6]); // Mie
96+
const BETA_R: Vec3 = vec3(5.5e-6, 13.0e-6, 22.4e-6); // Rayleigh
97+
const BETA_M: Vec3 = vec3(21e-6, 21e-6, 21e-6); // Mie
9898

9999
// scale height (m)
100100
// thickness of the atmosphere if its density were uniform
@@ -133,7 +133,7 @@ const ATMOSPHERE_RADIUS: f32 = 6420e3; // (m)
133133
const SUN_POWER: f32 = 20.0;
134134

135135
const ATMOSPHERE: Sphere = Sphere {
136-
origin: Vec3::zero(),
136+
origin: Vec3::ZERO,
137137
radius: ATMOSPHERE_RADIUS,
138138
_material: 0,
139139
};
@@ -172,7 +172,7 @@ impl State {
172172
let mut t0: f32 = 0.0;
173173
let mut t1: f32 = 0.0;
174174
if !isect_sphere(ray, ATMOSPHERE, &mut t0, &mut t1) {
175-
return Vec3::zero();
175+
return Vec3::ZERO;
176176
}
177177

178178
let march_step: f32 = t1 / NUM_SAMPLES as f32;
@@ -199,8 +199,8 @@ impl State {
199199
let mut optical_depth_r: f32 = 0.0;
200200
let mut optical_depth_m: f32 = 0.0;
201201

202-
let mut sum_r: Vec3 = Vec3::zero();
203-
let mut sum_m: Vec3 = Vec3::zero();
202+
let mut sum_r: Vec3 = Vec3::ZERO;
203+
let mut sum_m: Vec3 = Vec3::ZERO;
204204
let mut march_pos: f32 = 0.0;
205205

206206
let mut i = 0;
@@ -247,7 +247,7 @@ impl State {
247247
let aspect_ratio: Vec2 = vec2(self.inputs.resolution.x / self.inputs.resolution.y, 1.0);
248248
let fov: f32 = 45.0.deg_to_radians().tan();
249249
let point_ndc: Vec2 = frag_coord / self.inputs.resolution.xy();
250-
let point_cam: Vec3 = ((2.0 * point_ndc - Vec2::one()) * aspect_ratio * fov).extend(-1.0);
250+
let point_cam: Vec3 = ((2.0 * point_ndc - Vec2::ONE) * aspect_ratio * fov).extend(-1.0);
251251

252252
let col: Vec3;
253253

0 commit comments

Comments
 (0)