From 8603393928bcbfd3c6fb91497afcf22eb97be7ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Capucho?= Date: Wed, 9 Jun 2021 11:04:42 +0100 Subject: [PATCH] [glsl-in] Add collatz shader and test quad shader --- tests/in/glsl/246-collatz.comp | 34 ++++++++++++++++++++++++++++++++++ tests/out/quad-glsl.wgsl | 10 ++++++---- 2 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 tests/in/glsl/246-collatz.comp diff --git a/tests/in/glsl/246-collatz.comp b/tests/in/glsl/246-collatz.comp new file mode 100644 index 0000000000..274cdca1c3 --- /dev/null +++ b/tests/in/glsl/246-collatz.comp @@ -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]); +} diff --git a/tests/out/quad-glsl.wgsl b/tests/out/quad-glsl.wgsl index fccd8cc2ab..6be3e0caa3 100644 --- a/tests/out/quad-glsl.wgsl +++ b/tests/out/quad-glsl.wgsl @@ -7,6 +7,7 @@ struct FragmentOutput { [[location(0), interpolate(perspective)]] member2: vec4; }; +var c_scale: f32; var a_pos: vec2; var a_uv: vec2; var v_uv: vec2; @@ -15,10 +16,11 @@ var v_uv1: vec2; var o_color: vec4; fn vert_main() { - let _e2: vec2 = a_pos; - let _e4: vec2 = a_uv; - v_uv = _e4; - gl_Position = vec4((1.2000000476837158 * _e2), 0.0, 1.0); + let _e1: f32 = c_scale; + let _e3: vec2 = a_pos; + let _e5: vec2 = a_uv; + v_uv = _e5; + gl_Position = vec4((_e1 * _e3), 0.0, 1.0); return; }