Skip to content

Commit

Permalink
[glsl-in] Add collatz shader and test quad shader
Browse files Browse the repository at this point in the history
  • Loading branch information
JCapucho committed Jun 9, 2021
1 parent 5ab7d4a commit 8603393
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
34 changes: 34 additions & 0 deletions tests/in/glsl/246-collatz.comp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// AUTHOR: Unknown
// ISSUE: #246
// NOTE: Taken from the wgpu repo
#version 450
layout(local_size_x = 1) in;

layout(set = 0, binding = 0) buffer PrimeIndices {
uint[] indices;
}; // this is used as both input and output for convenience

// The Collatz Conjecture states that for any integer n:
// If n is even, n = n/2
// If n is odd, n = 3n+1
// And repeat this process for each new n, you will always eventually reach 1.
// Though the conjecture has not been proven, no counterexample has ever been found.
// This function returns how many times this recurrence needs to be applied to reach 1.
uint collatz_iterations(uint n) {
uint i = 0;
while(n != 1) {
if (mod(n, 2) == 0) {
n = n / 2;
}
else {
n = (3 * n) + 1;
}
i++;
}
return i;
}

void main() {
uint index = gl_GlobalInvocationID.x;
indices[index] = collatz_iterations(indices[index]);
}
10 changes: 6 additions & 4 deletions tests/out/quad-glsl.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ struct FragmentOutput {
[[location(0), interpolate(perspective)]] member2: vec4<f32>;
};

var<private> c_scale: f32;
var<private> a_pos: vec2<f32>;
var<private> a_uv: vec2<f32>;
var<private> v_uv: vec2<f32>;
Expand All @@ -15,10 +16,11 @@ var<private> v_uv1: vec2<f32>;
var<private> o_color: vec4<f32>;

fn vert_main() {
let _e2: vec2<f32> = a_pos;
let _e4: vec2<f32> = a_uv;
v_uv = _e4;
gl_Position = vec4<f32>((1.2000000476837158 * _e2), 0.0, 1.0);
let _e1: f32 = c_scale;
let _e3: vec2<f32> = a_pos;
let _e5: vec2<f32> = a_uv;
v_uv = _e5;
gl_Position = vec4<f32>((_e1 * _e3), 0.0, 1.0);
return;
}

Expand Down

0 comments on commit 8603393

Please sign in to comment.