Skip to content

Commit

Permalink
add constructors test file
Browse files Browse the repository at this point in the history
  • Loading branch information
teoxoy committed Mar 30, 2023
1 parent 3a92dbb commit 0fa81d2
Show file tree
Hide file tree
Showing 15 changed files with 1,346 additions and 1,224 deletions.
2 changes: 2 additions & 0 deletions tests/in/constructors.param.ron
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
(
)
67 changes: 67 additions & 0 deletions tests/in/constructors.wgsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
struct Foo {
a: vec4<f32>,
b: i32,
}

// const const1 = vec3<f32>(0.0); // TODO: this is now a splat and we need to const eval it
const const2 = vec3(0.0, 0.0, 0.0);
const const3 = mat2x2<f32>(0.0, 0.0, 0.0, 0.0);
const const4 = array<mat2x2<f32>, 1>(mat2x2<f32>(0.0, 0.0, 0.0, 0.0));

// zero value constructors
const cz0 = bool();
const cz1 = i32();
const cz2 = u32();
const cz3 = f32();
const cz4 = vec2<u32>();
const cz5 = mat2x2<f32>();
const cz6 = array<Foo, 3>();
const cz7 = Foo();

// constructors that infer their type from their parameters
// TODO: these also contain splats
// const cp1 = vec2(0u);
// const cp2 = mat2x2(vec2(0.), vec2(0.));
const cp3 = array(0, 1, 2, 3);

@compute @workgroup_size(1)
fn main() {
var foo: Foo;
foo = Foo(vec4<f32>(1.0), 1);

_ = mat2x2<f32>(
1.0, 0.0,
0.0, 1.0,
);
_ = mat4x4<f32>(
1.0, 0.0, 0.0, 0.0,
0.0, 1.0, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0,
);

// zero value constructors
_ = bool();
_ = i32();
_ = u32();
_ = f32();
_ = vec2<u32>();
_ = mat2x2<f32>();
_ = array<Foo, 3>();
_ = Foo();

// constructors that infer their type from their parameters
_ = vec2(0u);
_ = mat2x2(vec2(0.), vec2(0.));
_ = array(0, 1, 2, 3);

// identity constructors
_ = bool(bool());
_ = i32(i32());
_ = u32(u32());
_ = f32(f32());
_ = vec2<u32>(vec2<u32>());
_ = mat2x3<f32>(mat2x3<f32>());
_ = vec2(vec2<u32>());
_ = mat2x3(mat2x3<f32>());
}
50 changes: 0 additions & 50 deletions tests/in/operators.wgsl
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
//TODO: support splatting constructors for globals?
const v_f32_one = vec4<f32>(1.0, 1.0, 1.0, 1.0);
const v_f32_zero = vec4<f32>(0.0, 0.0, 0.0, 0.0);
const v_f32_half = vec4<f32>(0.5, 0.5, 0.5, 0.5);
Expand Down Expand Up @@ -41,54 +40,6 @@ fn bool_cast(x: vec3<f32>) -> vec3<f32> {
return vec3<f32>(y);
}

struct Foo {
a: vec4<f32>,
b: i32,
}

fn constructors() -> f32 {
var foo: Foo;
foo = Foo(vec4<f32>(1.0), 1);

let mat2comp = mat2x2<f32>(
1.0, 0.0,
0.0, 1.0,
);
let mat4comp = mat4x4<f32>(
1.0, 0.0, 0.0, 0.0,
0.0, 1.0, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0,
);

// zero value constructors
_ = bool();
_ = i32();
_ = u32();
_ = f32();
_ = vec2<u32>();
_ = mat2x2<f32>();
_ = array<Foo, 3>();
_ = Foo();

// constructors that infer their type from their parameters
_ = vec2(0u);
_ = mat2x2(vec2(0.), vec2(0.));
_ = array(0, 1, 2, 3);

// identity constructors
_ = bool(bool());
_ = i32(i32());
_ = u32(u32());
_ = f32(f32());
_ = vec2<u32>(vec2<u32>());
_ = mat2x3<f32>(mat2x3<f32>());
_ = vec2(vec2<u32>());
_ = mat2x3(mat2x3<f32>());

return foo.a.x;
}

fn logical() {
// unary
_ = !true;
Expand Down Expand Up @@ -304,7 +255,6 @@ fn main() {
_ = builtins();
_ = splat();
_ = bool_cast(v_f32_one.xyz);
_ = constructors();

logical();
arithmetic();
Expand Down
43 changes: 43 additions & 0 deletions tests/out/glsl/constructors.main.Compute.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#version 310 es

precision highp float;
precision highp int;

layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;

const vec3 const2_ = vec3(0.0, 0.0, 0.0);
const mat2x2 const3_ = mat2x2(vec2(0.0, 0.0), vec2(0.0, 0.0));
const mat2x2 const4_ = mat2x2[1](mat2x2(vec2(0.0, 0.0), vec2(0.0, 0.0)));
const bool cz0_ = false;
const int cz1_ = 0;
const uint cz2_ = 0u;
const float cz3_ = 0.0;
const uvec2 cz4_ = uvec2(0u);
const mat2x2 cz5_ = mat2x2(0.0);
const Foo cz6_ = Foo[3](Foo(vec4(0.0), 0), Foo(vec4(0.0), 0), Foo(vec4(0.0), 0));
const Foo cz7_ = Foo(vec4(0.0), 0);
const int cp3_ = int[4](0, 1, 2, 3);

struct Foo {
vec4 a;
int b;
};

void main() {
Foo foo = Foo(vec4(0.0), 0);
foo = Foo(vec4(1.0), 1);
mat2x2 unnamed = mat2x2(vec2(1.0, 0.0), vec2(0.0, 1.0));
mat4x4 unnamed_1 = mat4x4(vec4(1.0, 0.0, 0.0, 0.0), vec4(0.0, 1.0, 0.0, 0.0), vec4(0.0, 0.0, 1.0, 0.0), vec4(0.0, 0.0, 0.0, 1.0));
uvec2 unnamed_2 = uvec2(0u);
mat2x2 unnamed_3 = mat2x2(vec2(0.0), vec2(0.0));
int unnamed_4[4] = int[4](0, 1, 2, 3);
bool unnamed_5 = bool(false);
int unnamed_6 = int(0);
uint unnamed_7 = uint(0u);
float unnamed_8 = float(0.0);
uvec2 unnamed_9 = uvec2(uvec2(0u));
mat2x3 unnamed_10 = mat2x3(mat2x3(0.0));
uvec2 unnamed_11 = uvec2(0u);
mat2x3 unnamed_12 = mat2x3(0.0);
}

Loading

0 comments on commit 0fa81d2

Please sign in to comment.