qining | 0840838 | 2016-03-21 09:51:37 -0400 | [diff] [blame] | 1 | #version 450 |
| 2 | |
| 3 | // constant_id specified scalar spec constants |
| 4 | layout(constant_id = 200) const int spec_int = 3; |
| 5 | layout(constant_id = 201) const float spec_float = 3.14; |
| 6 | layout(constant_id = 202) const |
| 7 | double spec_double = 3.1415926535897932384626433832795; |
| 8 | layout(constant_id = 203) const bool spec_bool = true; |
| 9 | |
John Kessenich | d82c906 | 2016-05-23 16:07:07 -0600 | [diff] [blame] | 10 | // const float cast_spec_float = float(spec_float); |
qining | 0840838 | 2016-03-21 09:51:37 -0400 | [diff] [blame] | 11 | |
| 12 | // Flat struct |
| 13 | struct flat_struct { |
| 14 | int i; |
| 15 | float f; |
| 16 | double d; |
| 17 | bool b; |
| 18 | }; |
| 19 | |
| 20 | // Nesting struct |
| 21 | struct nesting_struct { |
| 22 | flat_struct nested; |
| 23 | vec4 v; |
| 24 | int i; |
| 25 | }; |
| 26 | |
| 27 | // Expect OpSpecConstantComposite |
| 28 | // Flat struct initializer |
John Kessenich | d82c906 | 2016-05-23 16:07:07 -0600 | [diff] [blame] | 29 | //const flat_struct spec_flat_struct_all_spec = {spec_int, spec_float, |
| 30 | // spec_double, spec_bool}; |
| 31 | //const flat_struct spec_flat_struct_partial_spec = {30, 30.14, spec_double, |
| 32 | // spec_bool}; |
qining | 0840838 | 2016-03-21 09:51:37 -0400 | [diff] [blame] | 33 | |
| 34 | // Nesting struct initializer |
John Kessenich | d82c906 | 2016-05-23 16:07:07 -0600 | [diff] [blame] | 35 | //const nesting_struct nesting_struct_ctor = { |
| 36 | // {spec_int, spec_float, spec_double, false}, |
| 37 | // vec4(0.1, 0.1, 0.1, 0.1), |
| 38 | // spec_int}; |
qining | 0840838 | 2016-03-21 09:51:37 -0400 | [diff] [blame] | 39 | |
| 40 | // Vector constructor |
John Kessenich | d82c906 | 2016-05-23 16:07:07 -0600 | [diff] [blame] | 41 | //const vec4 spec_vec4_all_spec = |
| 42 | // vec4(spec_float, spec_float, spec_float, spec_float); |
| 43 | //const vec4 spec_vec4_partial_spec = |
| 44 | // vec4(spec_float, spec_float, 300.14, 300.14); |
| 45 | //const vec4 spec_vec4_from_one_scalar = vec4(spec_float); |
qining | 27e04a0 | 2016-04-14 16:40:20 -0400 | [diff] [blame] | 46 | |
| 47 | // Matrix constructor |
John Kessenich | d82c906 | 2016-05-23 16:07:07 -0600 | [diff] [blame] | 48 | //const mat2x3 spec_mat2x3 = mat2x3(spec_float, spec_float, spec_float, 1.1, 2.2, 3.3); |
| 49 | //const mat2x3 spec_mat2x3_from_one_scalar = mat2x3(spec_float); |
qining | 0840838 | 2016-03-21 09:51:37 -0400 | [diff] [blame] | 50 | |
| 51 | // Struct nesting constructor |
John Kessenich | d82c906 | 2016-05-23 16:07:07 -0600 | [diff] [blame] | 52 | //const nesting_struct spec_nesting_struct_all_spec = { |
| 53 | // spec_flat_struct_all_spec, spec_vec4_all_spec, spec_int}; |
| 54 | //const nesting_struct spec_nesting_struct_partial_spec = { |
| 55 | // spec_flat_struct_partial_spec, spec_vec4_partial_spec, 3000}; |
qining | 0840838 | 2016-03-21 09:51:37 -0400 | [diff] [blame] | 56 | |
John Kessenich | d82c906 | 2016-05-23 16:07:07 -0600 | [diff] [blame] | 57 | //const float spec_float_array[5] = {spec_float, spec_float, 1.0, 2.0, 3.0}; |
| 58 | //const int spec_int_array[5] = {spec_int, spec_int, 1, 2, 30}; |
qining | 0840838 | 2016-03-21 09:51:37 -0400 | [diff] [blame] | 59 | |
| 60 | // global_vec4_array_with_spec_length is not a spec constant, but its array |
| 61 | // size is. When calling global_vec4_array_with_spec_length.length(), A |
John Kessenich | d82c906 | 2016-05-23 16:07:07 -0600 | [diff] [blame] | 62 | // TIntermSymbol Node should be returned, instead of a TIntermConstantUnion |
qining | 0840838 | 2016-03-21 09:51:37 -0400 | [diff] [blame] | 63 | // node which represents a known constant value. |
| 64 | in vec4 global_vec4_array_with_spec_length[spec_int]; |
| 65 | |
| 66 | out vec4 color; |
| 67 | |
| 68 | void refer_primary_spec_const() { |
| 69 | if (spec_bool) color *= spec_int; |
| 70 | } |
| 71 | |
| 72 | void refer_composite_spec_const() { |
John Kessenich | d82c906 | 2016-05-23 16:07:07 -0600 | [diff] [blame] | 73 | //color += spec_vec4_all_spec; |
| 74 | //color -= spec_vec4_partial_spec; |
qining | 0840838 | 2016-03-21 09:51:37 -0400 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | void refer_copmosite_dot_dereference() { |
John Kessenich | d82c906 | 2016-05-23 16:07:07 -0600 | [diff] [blame] | 78 | //color *= spec_nesting_struct_all_spec.i; |
| 79 | //color += spec_vec4_all_spec.x; |
qining | 0840838 | 2016-03-21 09:51:37 -0400 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | void refer_composite_bracket_dereference() { |
John Kessenich | d82c906 | 2016-05-23 16:07:07 -0600 | [diff] [blame] | 83 | //color -= spec_float_array[1]; |
| 84 | //color /= spec_int_array[spec_int_array[spec_int]]; |
qining | 0840838 | 2016-03-21 09:51:37 -0400 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | int refer_spec_const_array_length() { |
| 88 | int len = global_vec4_array_with_spec_length.length(); |
| 89 | return len; |
| 90 | } |
| 91 | |
| 92 | void declare_spec_const_in_func() { |
John Kessenich | d82c906 | 2016-05-23 16:07:07 -0600 | [diff] [blame] | 93 | //const nesting_struct spec_const_declared_in_func = { |
| 94 | // spec_flat_struct_partial_spec, spec_vec4_partial_spec, 10}; |
| 95 | //color /= spec_const_declared_in_func.i; |
qining | 0840838 | 2016-03-21 09:51:37 -0400 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | void main() {} |