mirror of
https://github.com/gfx-rs/wgpu.git
synced 2026-04-22 03:02:01 -04:00
[glsl-in] Add collatz shader and test quad shader
This commit is contained in:
committed by
Dzmitry Malyshau
parent
fb71e49501
commit
06c8588fcd
34
tests/in/glsl/246-collatz.comp
Normal file
34
tests/in/glsl/246-collatz.comp
Normal file
@@ -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]);
|
||||
}
|
||||
@@ -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>;
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user