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

Add test for issue 283 #302

Merged
merged 1 commit into from
Dec 2, 2020
Merged
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
55 changes: 54 additions & 1 deletion crates/spirv-builder/src/test/control_flow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ pub fn main(i: Input<i32>) {
} else if i.load() < 0 {

} else {

}
}
"#);
Expand Down Expand Up @@ -347,3 +347,56 @@ pub fn main(i: Input<i32>) {
}
"#);
}

#[test]
fn issue_283() {
// version of issue 283 with loop uncommented and warnings fixed
// https://github.com/EmbarkStudios/rust-gpu/issues/283
val(r#"
use spirv_std::glam::*;
fn sphere_sdf(p: Vec3) -> f32 {
p.length() - 1.0
}

// Global scene to render
fn scene_sdf(p: Vec3) -> f32 {
sphere_sdf(p)
}

fn render(eye: Vec3, dir: Vec3, start: f32, end: f32) -> f32 {
let max_marching_steps: i32 = 255;
let epsilon: f32 = 0.0001;

let mut depth = start;
let mut i = 0;

loop {
if i < max_marching_steps {
break;
}

let dist = scene_sdf(eye + depth * dir);

if dist < epsilon {
return depth;
}

depth += dist;

if depth >= end {
return end;
}

i += 1;
}

end
}

#[allow(unused_attributes)]
#[spirv(fragment)]
pub fn main() {
let v = Vec3::new(1.0, 1.0, 1.0);
render(v, v, 1.0, 2.0);
}"#);
}