• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#version 450
2
3layout(constant_id = 200) const float sp_float = 3.1415926;
4layout(constant_id = 201) const int sp_int = 10;
5layout(constant_id = 202) const uint sp_uint = 100;
6layout(constant_id = 203) const int sp_sint = -10;
7layout(constant_id = 204) const double sp_double = 2.718281828459;
8
9//
10// Scalars
11//
12
13// float <-> double conversion
14const float float_from_double = float(sp_double);
15const double double_from_float = double(sp_float);
16
17// uint/int <-> bool conversion
18const bool bool_from_int = bool(sp_int);
19const bool bool_from_uint = bool(sp_uint);
20const int int_from_bool = int(bool_from_int);
21const uint uint_from_bool = uint(bool_from_int);
22
23// uint <-> int
24const uint sp_uint_from_sint = uint(sp_sint);
25const int sp_sint_from_uint = int(sp_uint);
26
27// Negate and Not
28const int negate_int = -sp_int;
29const int not_int = ~sp_int;
30
31// Add and Subtract
32const int sp_int_add_two = sp_int + 2;
33const int sp_int_add_two_sub_three = sp_int + 2 - 3;
34const int sp_int_add_two_sub_four = sp_int_add_two - 4;
35
36// Mul, Div and Rem
37const int sp_sint_mul_two = sp_sint * 2;
38const uint sp_uint_mul_two = sp_uint * 2;
39const int sp_sint_mul_two_div_five = sp_sint_mul_two / 5;
40const uint sp_uint_mul_two_div_five = sp_uint_mul_two / 5;
41const int sp_sint_rem_four = sp_sint % 4;
42const uint sp_uint_rem_four = sp_uint % 4;
43const int sp_sint_mul_three_div_five = sp_sint * 3 / 5;
44
45// Shift
46const int sp_sint_shift_right_arithmetic = sp_sint >> 10;
47const uint sp_uint_shift_right_arithmetic = sp_uint >> 20;
48const int sp_sint_shift_left = sp_sint << 1;
49const uint sp_uint_shift_left = sp_uint << 2;
50
51// Bitwise And, Or, Xor
52const int sp_sint_or_256 = sp_sint | 0x100;
53const uint sp_uint_xor_512 = sp_uint ^ 0x200;
54
55/* // Scalar comparison */
56const bool sp_int_lt_sp_sint = sp_int < sp_sint;
57const bool sp_uint_equal_sp_uint = sp_uint == sp_uint;
58const bool sp_int_gt_sp_sint = sp_int > sp_sint;
59
60//
61// Vectors
62//
63const ivec4 iv = ivec4(20, 30, sp_int, sp_int);
64const uvec4 uv = uvec4(sp_uint, sp_uint, -1, -2);
65//const vec4 fv = vec4(sp_float, 1.25, sp_float, 1.25);
66
67// uint/int <-> bool conversion
68const bvec4 bv_from_iv = bvec4(iv);
69const bvec4 bv_from_uv = bvec4(uv);
70const ivec4 iv_from_bv = ivec4(bv_from_iv);
71const uvec4 uv_from_bv = uvec4(bv_from_iv);
72
73// uint <-> int
74const uvec4 uv_from_iv = uvec4(iv);
75const ivec4 iv_from_uv = ivec4(uv);
76
77// Negate and Not
78const ivec4 not_iv = ~iv;
79const ivec4 negate_iv = -iv;
80
81// Add and Subtract
82const ivec4 iv_add_two = iv + 2;
83const ivec4 iv_add_two_sub_three = iv + 2 - 3;
84const ivec4 iv_add_two_sub_four = iv_add_two_sub_three - 4;
85
86// Mul, Div and Rem
87const ivec4 iv_mul_two = iv * 2;
88const ivec4 iv_mul_two_div_five = iv_mul_two / 5;
89const ivec4 iv_rem_four = iv % 4;
90
91// Shift
92const ivec4 iv_shift_right_arithmetic = iv >> 10;
93const ivec4 iv_shift_left = iv << 2;
94
95// Bitwise And, Or, Xor
96const ivec4 iv_or_1024 = iv | 0x400;
97const uvec4 uv_xor_2048 = uv ^ 0x800;
98
99// Swizzles
100const int iv_x = iv.x;
101const ivec2 iv_yx = iv.yx;
102const ivec3 iv_zyx = iv.zyx;
103const ivec4 iv_yzxw = iv.yzxw;
104
105int non_const_array_size_from_spec_const() {
106    int array[sp_int + 2];
107    for (int i = 0; i < sp_int + 2; i++) {
108        array[i] = 1023;
109    }
110    return array[sp_int + 1];
111}
112
113// ternary
114layout(constant_id = 210) const int a = 4;
115layout(constant_id = 211) const int b = 6;
116layout(constant_id = 212) const bool c = true;
117int ternayArray1[a > b ? a : b];
118const int t1 = c ? 13 : 17;
119const int t2 = c ? a : 17;
120const int t3 = true ? a : 17;
121const int t4 = a > b ? 13 + a : 17 * b;
122const vec2 v2 = !c ? vec2(1.0) : vec2(2.0);
123
124void main() {}
125