Skip to content

Commit 6abd2ad

Browse files
committed
Test
Signed-off-by: sagudev <[email protected]>
1 parent 47305eb commit 6abd2ad

File tree

6 files changed

+285
-0
lines changed

6 files changed

+285
-0
lines changed

naga/tests/in/local-const.param.ron

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
()

naga/tests/in/local-const.wgsl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
const ga = 4; // AbstractInt with a value of 4.
2+
const gb : i32 = 4; // i32 with a value of 4.
3+
const gc : u32 = 4; // u32 with a value of 4.
4+
const gd : f32 = 4; // f32 with a value of 4.
5+
const ge = vec3(ga, ga, ga); // vec3 of AbstractInt with a value of (4, 4, 4).
6+
const gf = 2.0; // AbstractFloat with a value of 2.
7+
8+
fn const_in_fn() {
9+
const a = 4; // AbstractInt with a value of 4.
10+
const b: i32 = 4; // i32 with a value of 4.
11+
const c: u32 = 4; // u32 with a value of 4.
12+
const d: f32 = 4; // f32 with a value of 4.
13+
const e = vec3(a, a, a); // vec3 of AbstractInt with a value of (4, 4, 4).
14+
const f = 2.0; // AbstractFloat with a value of 2.
15+
// TODO: Make it per spec, currently not possible
16+
// because naga does not support automatic conversions
17+
// of Abstract types
18+
}
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
(
2+
types: [
3+
(
4+
name: None,
5+
inner: Scalar((
6+
kind: Sint,
7+
width: 4,
8+
)),
9+
),
10+
(
11+
name: None,
12+
inner: Scalar((
13+
kind: Uint,
14+
width: 4,
15+
)),
16+
),
17+
(
18+
name: None,
19+
inner: Scalar((
20+
kind: Float,
21+
width: 4,
22+
)),
23+
),
24+
(
25+
name: None,
26+
inner: Vector(
27+
size: Tri,
28+
scalar: (
29+
kind: Sint,
30+
width: 4,
31+
),
32+
),
33+
),
34+
],
35+
special_types: (
36+
ray_desc: None,
37+
ray_intersection: None,
38+
predeclared_types: {},
39+
),
40+
constants: [
41+
(
42+
name: Some("ga"),
43+
ty: 0,
44+
init: 0,
45+
),
46+
(
47+
name: Some("gb"),
48+
ty: 0,
49+
init: 1,
50+
),
51+
(
52+
name: Some("gc"),
53+
ty: 1,
54+
init: 2,
55+
),
56+
(
57+
name: Some("gd"),
58+
ty: 2,
59+
init: 3,
60+
),
61+
(
62+
name: Some("ge"),
63+
ty: 3,
64+
init: 4,
65+
),
66+
(
67+
name: Some("gf"),
68+
ty: 2,
69+
init: 5,
70+
),
71+
],
72+
overrides: [],
73+
global_variables: [],
74+
global_expressions: [
75+
Literal(I32(4)),
76+
Literal(I32(4)),
77+
Literal(U32(4)),
78+
Literal(F32(4.0)),
79+
Compose(
80+
ty: 3,
81+
components: [
82+
0,
83+
0,
84+
0,
85+
],
86+
),
87+
Literal(F32(2.0)),
88+
],
89+
functions: [
90+
(
91+
name: Some("const_in_fn"),
92+
arguments: [],
93+
result: None,
94+
local_variables: [],
95+
expressions: [
96+
Literal(I32(4)),
97+
Literal(I32(4)),
98+
Literal(U32(4)),
99+
Literal(F32(4.0)),
100+
Compose(
101+
ty: 3,
102+
components: [
103+
0,
104+
0,
105+
0,
106+
],
107+
),
108+
Literal(F32(2.0)),
109+
],
110+
named_expressions: {
111+
0: "a",
112+
1: "b",
113+
2: "c",
114+
3: "d",
115+
4: "e",
116+
5: "f",
117+
},
118+
body: [
119+
Emit((
120+
start: 4,
121+
end: 5,
122+
)),
123+
],
124+
),
125+
],
126+
entry_points: [],
127+
)

naga/tests/out/ir/local-const.ron

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
(
2+
types: [
3+
(
4+
name: None,
5+
inner: Scalar((
6+
kind: Sint,
7+
width: 4,
8+
)),
9+
),
10+
(
11+
name: None,
12+
inner: Scalar((
13+
kind: Uint,
14+
width: 4,
15+
)),
16+
),
17+
(
18+
name: None,
19+
inner: Scalar((
20+
kind: Float,
21+
width: 4,
22+
)),
23+
),
24+
(
25+
name: None,
26+
inner: Vector(
27+
size: Tri,
28+
scalar: (
29+
kind: Sint,
30+
width: 4,
31+
),
32+
),
33+
),
34+
],
35+
special_types: (
36+
ray_desc: None,
37+
ray_intersection: None,
38+
predeclared_types: {},
39+
),
40+
constants: [
41+
(
42+
name: Some("ga"),
43+
ty: 0,
44+
init: 0,
45+
),
46+
(
47+
name: Some("gb"),
48+
ty: 0,
49+
init: 1,
50+
),
51+
(
52+
name: Some("gc"),
53+
ty: 1,
54+
init: 2,
55+
),
56+
(
57+
name: Some("gd"),
58+
ty: 2,
59+
init: 3,
60+
),
61+
(
62+
name: Some("ge"),
63+
ty: 3,
64+
init: 4,
65+
),
66+
(
67+
name: Some("gf"),
68+
ty: 2,
69+
init: 5,
70+
),
71+
],
72+
overrides: [],
73+
global_variables: [],
74+
global_expressions: [
75+
Literal(I32(4)),
76+
Literal(I32(4)),
77+
Literal(U32(4)),
78+
Literal(F32(4.0)),
79+
Compose(
80+
ty: 3,
81+
components: [
82+
0,
83+
0,
84+
0,
85+
],
86+
),
87+
Literal(F32(2.0)),
88+
],
89+
functions: [
90+
(
91+
name: Some("const_in_fn"),
92+
arguments: [],
93+
result: None,
94+
local_variables: [],
95+
expressions: [
96+
Literal(I32(4)),
97+
Literal(I32(4)),
98+
Literal(U32(4)),
99+
Literal(F32(4.0)),
100+
Compose(
101+
ty: 3,
102+
components: [
103+
0,
104+
0,
105+
0,
106+
],
107+
),
108+
Literal(F32(2.0)),
109+
],
110+
named_expressions: {
111+
0: "a",
112+
1: "b",
113+
2: "c",
114+
3: "d",
115+
4: "e",
116+
5: "f",
117+
},
118+
body: [
119+
Emit((
120+
start: 4,
121+
end: 5,
122+
)),
123+
],
124+
),
125+
],
126+
entry_points: [],
127+
)

naga/tests/out/wgsl/local-const.wgsl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const ga: i32 = 4i;
2+
const gb: i32 = 4i;
3+
const gc: u32 = 4u;
4+
const gd: f32 = 4f;
5+
const ge: vec3<i32> = vec3<i32>(4i, 4i, 4i);
6+
const gf: f32 = 2f;
7+
8+
fn const_in_fn() {
9+
const e = vec3<i32>(4i, 4i, 4i);
10+
}
11+

naga/tests/snapshots.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -818,6 +818,7 @@ fn convert_wgsl() {
818818
"use-gl-ext-over-grad-workaround-if-instructed",
819819
Targets::GLSL,
820820
),
821+
("local-const", Targets::IR | Targets::WGSL),
821822
(
822823
"math-functions",
823824
Targets::SPIRV | Targets::METAL | Targets::GLSL | Targets::HLSL | Targets::WGSL,

0 commit comments

Comments
 (0)