1617a3babSopenharmony_ci#version 450 2617a3babSopenharmony_ci 3617a3babSopenharmony_cilayout(constant_id = 200) const float sp_float = 3.1415926; 4617a3babSopenharmony_cilayout(constant_id = 201) const int sp_int = 10; 5617a3babSopenharmony_cilayout(constant_id = 202) const uint sp_uint = 100; 6617a3babSopenharmony_cilayout(constant_id = 203) const int sp_sint = -10; 7617a3babSopenharmony_cilayout(constant_id = 204) const double sp_double = 2.718281828459; 8617a3babSopenharmony_ci 9617a3babSopenharmony_ci// 10617a3babSopenharmony_ci// Scalars 11617a3babSopenharmony_ci// 12617a3babSopenharmony_ci 13617a3babSopenharmony_ci// float <-> double conversion 14617a3babSopenharmony_ciconst float float_from_double = float(sp_double); 15617a3babSopenharmony_ciconst double double_from_float = double(sp_float); 16617a3babSopenharmony_ci 17617a3babSopenharmony_ci// uint/int <-> bool conversion 18617a3babSopenharmony_ciconst bool bool_from_int = bool(sp_int); 19617a3babSopenharmony_ciconst bool bool_from_uint = bool(sp_uint); 20617a3babSopenharmony_ciconst int int_from_bool = int(bool_from_int); 21617a3babSopenharmony_ciconst uint uint_from_bool = uint(bool_from_int); 22617a3babSopenharmony_ci 23617a3babSopenharmony_ci// uint <-> int 24617a3babSopenharmony_ciconst uint sp_uint_from_sint = uint(sp_sint); 25617a3babSopenharmony_ciconst int sp_sint_from_uint = int(sp_uint); 26617a3babSopenharmony_ci 27617a3babSopenharmony_ci// Negate and Not 28617a3babSopenharmony_ciconst int negate_int = -sp_int; 29617a3babSopenharmony_ciconst int not_int = ~sp_int; 30617a3babSopenharmony_ci 31617a3babSopenharmony_ci// Add and Subtract 32617a3babSopenharmony_ciconst int sp_int_add_two = sp_int + 2; 33617a3babSopenharmony_ciconst int sp_int_add_two_sub_three = sp_int + 2 - 3; 34617a3babSopenharmony_ciconst int sp_int_add_two_sub_four = sp_int_add_two - 4; 35617a3babSopenharmony_ci 36617a3babSopenharmony_ci// Mul, Div and Rem 37617a3babSopenharmony_ciconst int sp_sint_mul_two = sp_sint * 2; 38617a3babSopenharmony_ciconst uint sp_uint_mul_two = sp_uint * 2; 39617a3babSopenharmony_ciconst int sp_sint_mul_two_div_five = sp_sint_mul_two / 5; 40617a3babSopenharmony_ciconst uint sp_uint_mul_two_div_five = sp_uint_mul_two / 5; 41617a3babSopenharmony_ciconst int sp_sint_rem_four = sp_sint % 4; 42617a3babSopenharmony_ciconst uint sp_uint_rem_four = sp_uint % 4; 43617a3babSopenharmony_ciconst int sp_sint_mul_three_div_five = sp_sint * 3 / 5; 44617a3babSopenharmony_ci 45617a3babSopenharmony_ci// Shift 46617a3babSopenharmony_ciconst int sp_sint_shift_right_arithmetic = sp_sint >> 10; 47617a3babSopenharmony_ciconst uint sp_uint_shift_right_arithmetic = sp_uint >> 20; 48617a3babSopenharmony_ciconst int sp_sint_shift_left = sp_sint << 1; 49617a3babSopenharmony_ciconst uint sp_uint_shift_left = sp_uint << 2; 50617a3babSopenharmony_ci 51617a3babSopenharmony_ci// Bitwise And, Or, Xor 52617a3babSopenharmony_ciconst int sp_sint_or_256 = sp_sint | 0x100; 53617a3babSopenharmony_ciconst uint sp_uint_xor_512 = sp_uint ^ 0x200; 54617a3babSopenharmony_ci 55617a3babSopenharmony_ci/* // Scalar comparison */ 56617a3babSopenharmony_ciconst bool sp_int_lt_sp_sint = sp_int < sp_sint; 57617a3babSopenharmony_ciconst bool sp_uint_equal_sp_uint = sp_uint == sp_uint; 58617a3babSopenharmony_ciconst bool sp_int_gt_sp_sint = sp_int > sp_sint; 59617a3babSopenharmony_ci 60617a3babSopenharmony_ci// 61617a3babSopenharmony_ci// Vectors 62617a3babSopenharmony_ci// 63617a3babSopenharmony_ciconst ivec4 iv = ivec4(20, 30, sp_int, sp_int); 64617a3babSopenharmony_ciconst uvec4 uv = uvec4(sp_uint, sp_uint, -1, -2); 65617a3babSopenharmony_ci//const vec4 fv = vec4(sp_float, 1.25, sp_float, 1.25); 66617a3babSopenharmony_ci 67617a3babSopenharmony_ci// uint/int <-> bool conversion 68617a3babSopenharmony_ciconst bvec4 bv_from_iv = bvec4(iv); 69617a3babSopenharmony_ciconst bvec4 bv_from_uv = bvec4(uv); 70617a3babSopenharmony_ciconst ivec4 iv_from_bv = ivec4(bv_from_iv); 71617a3babSopenharmony_ciconst uvec4 uv_from_bv = uvec4(bv_from_iv); 72617a3babSopenharmony_ci 73617a3babSopenharmony_ci// uint <-> int 74617a3babSopenharmony_ciconst uvec4 uv_from_iv = uvec4(iv); 75617a3babSopenharmony_ciconst ivec4 iv_from_uv = ivec4(uv); 76617a3babSopenharmony_ci 77617a3babSopenharmony_ci// Negate and Not 78617a3babSopenharmony_ciconst ivec4 not_iv = ~iv; 79617a3babSopenharmony_ciconst ivec4 negate_iv = -iv; 80617a3babSopenharmony_ci 81617a3babSopenharmony_ci// Add and Subtract 82617a3babSopenharmony_ciconst ivec4 iv_add_two = iv + 2; 83617a3babSopenharmony_ciconst ivec4 iv_add_two_sub_three = iv + 2 - 3; 84617a3babSopenharmony_ciconst ivec4 iv_add_two_sub_four = iv_add_two_sub_three - 4; 85617a3babSopenharmony_ci 86617a3babSopenharmony_ci// Mul, Div and Rem 87617a3babSopenharmony_ciconst ivec4 iv_mul_two = iv * 2; 88617a3babSopenharmony_ciconst ivec4 iv_mul_two_div_five = iv_mul_two / 5; 89617a3babSopenharmony_ciconst ivec4 iv_rem_four = iv % 4; 90617a3babSopenharmony_ci 91617a3babSopenharmony_ci// Shift 92617a3babSopenharmony_ciconst ivec4 iv_shift_right_arithmetic = iv >> 10; 93617a3babSopenharmony_ciconst ivec4 iv_shift_left = iv << 2; 94617a3babSopenharmony_ci 95617a3babSopenharmony_ci// Bitwise And, Or, Xor 96617a3babSopenharmony_ciconst ivec4 iv_or_1024 = iv | 0x400; 97617a3babSopenharmony_ciconst uvec4 uv_xor_2048 = uv ^ 0x800; 98617a3babSopenharmony_ci 99617a3babSopenharmony_ci// Swizzles 100617a3babSopenharmony_ciconst int iv_x = iv.x; 101617a3babSopenharmony_ciconst ivec2 iv_yx = iv.yx; 102617a3babSopenharmony_ciconst ivec3 iv_zyx = iv.zyx; 103617a3babSopenharmony_ciconst ivec4 iv_yzxw = iv.yzxw; 104617a3babSopenharmony_ci 105617a3babSopenharmony_ciint non_const_array_size_from_spec_const() { 106617a3babSopenharmony_ci int array[sp_int + 2]; 107617a3babSopenharmony_ci for (int i = 0; i < sp_int + 2; i++) { 108617a3babSopenharmony_ci array[i] = 1023; 109617a3babSopenharmony_ci } 110617a3babSopenharmony_ci return array[sp_int + 1]; 111617a3babSopenharmony_ci} 112617a3babSopenharmony_ci 113617a3babSopenharmony_ci// ternary 114617a3babSopenharmony_cilayout(constant_id = 210) const int a = 4; 115617a3babSopenharmony_cilayout(constant_id = 211) const int b = 6; 116617a3babSopenharmony_cilayout(constant_id = 212) const bool c = true; 117617a3babSopenharmony_ciint ternayArray1[a > b ? a : b]; 118617a3babSopenharmony_ciconst int t1 = c ? 13 : 17; 119617a3babSopenharmony_ciconst int t2 = c ? a : 17; 120617a3babSopenharmony_ciconst int t3 = true ? a : 17; 121617a3babSopenharmony_ciconst int t4 = a > b ? 13 + a : 17 * b; 122617a3babSopenharmony_ciconst vec2 v2 = !c ? vec2(1.0) : vec2(2.0); 123617a3babSopenharmony_ci 124617a3babSopenharmony_civoid main() {} 125