John Kessenich | f792295 | 2013-02-12 06:53:13 +0000 | [diff] [blame] | 1 | #version 430
|
John Kessenich | 9fd55bd | 2012-12-13 00:05:26 +0000 | [diff] [blame] | 2 |
|
| 3 | #extension GL_3DL_array_objects : enable
|
| 4 |
|
| 5 | out Vertex {
|
| 6 | vec4 Position; // API transform/feedback will use Vertex.Position
|
| 7 | vec2 Texture;
|
| 8 | } Coords; // shader will use Coords.Position
|
| 9 |
|
| 10 | out Vertex2 {
|
| 11 | vec4 Color; // API will use Color
|
| 12 | };
|
| 13 |
|
| 14 | uniform Transform { // API uses Transform[2] to refer to instance 2
|
| 15 | mat4 ModelViewMatrix;
|
| 16 | mat4 ModelViewProjectionMatrix;
|
| 17 | vec4 a[]; // array will get implicitly sized
|
| 18 | float Deformation;
|
| 19 | } transforms[4];
|
| 20 |
|
| 21 | layout(location = 3) in vec4 normal;
|
| 22 | layout(location = 6) in vec4 colors[3];
|
| 23 | layout(location = 9) in mat4 transforms[2];
|
| 24 |
|
| 25 | layout(location = 3) struct S {
|
John Kessenich | 8f13e13 | 2013-10-18 03:56:23 +0000 | [diff] [blame] | 26 | vec3 a1;
|
John Kessenich | 9fd55bd | 2012-12-13 00:05:26 +0000 | [diff] [blame] | 27 | mat2 b;
|
| 28 | vec4 c[2];
|
| 29 | } s;
|
| 30 |
|
| 31 | layout(triangles, invocations = 6) in;
|
| 32 |
|
| 33 | layout(lines) in; // legal for Color2, input size is 2, matching Color2
|
| 34 |
|
| 35 | layout(triangle_strip, max_vertices = 60) out; // order does not matter
|
| 36 | layout(max_vertices = 60) out; // redeclaration okay
|
| 37 | layout(triangle_strip) out; // redeclaration okay
|
| 38 | //layout(points) out; // error, contradicts triangle_strip
|
| 39 | //layout(max_vertices = 30) out; // error, contradicts 60
|
| 40 |
|
| 41 | layout(stream = 1) out;
|
| 42 |
|
| 43 | layout(stream=1) out; // default is now stream 1
|
| 44 | out vec4 var1; // var1 gets default stream (1)
|
| 45 | layout(stream=2) out Block1 { // "Block1" belongs to stream 2
|
| 46 | layout(stream=2) vec4 var2; // redundant block member stream decl
|
| 47 | layout(stream=3) vec2 var3; // ILLEGAL (must match block stream)
|
| 48 | vec3 var4; // belongs to stream 2
|
| 49 | };
|
| 50 | layout(stream=0) out; // default is now stream 0
|
| 51 | out vec4 var5; // var5 gets default stream (0)
|
| 52 | out Block2 { // "Block2" gets default stream (0)
|
| 53 | vec4 var6;
|
| 54 | };
|
| 55 | layout(stream=3) out vec4 var7; // var7 belongs to stream 3
|
| 56 |
|
| 57 | layout(shared, column_major) uniform;
|
| 58 | layout(shared, column_major) buffer;
|
| 59 |
|
| 60 | layout(row_major, column_major)
|
| 61 |
|
| 62 | layout(shared, row_major) uniform; // default is now shared and row_major
|
| 63 |
|
John Kessenich | f6648dc | 2013-04-10 02:06:46 +0000 | [diff] [blame] | 64 | layout(std140) uniform Transform2 { // layout of this block is std140
|
John Kessenich | 9fd55bd | 2012-12-13 00:05:26 +0000 | [diff] [blame] | 65 | mat4 M1; // row_major
|
| 66 | layout(column_major) mat4 M2; // column major
|
| 67 | mat3 N1; // row_major
|
| 68 | };
|
| 69 |
|
John Kessenich | f59bfa0 | 2013-01-10 01:47:54 +0000 | [diff] [blame] | 70 | layout(column_major) uniform T3 { // shared and column_major
|
John Kessenich | ba04210 | 2013-04-10 20:15:16 +0000 | [diff] [blame] | 71 | mat4 M13; // column_major
|
| 72 | layout(row_major) mat4 m14; // row major
|
| 73 | mat3 N12; // column_major
|
John Kessenich | 9fd55bd | 2012-12-13 00:05:26 +0000 | [diff] [blame] | 74 | };
|
| 75 |
|
| 76 | // in one compilation unit...
|
John Kessenich | ba04210 | 2013-04-10 20:15:16 +0000 | [diff] [blame] | 77 | layout(binding=3) uniform sampler2D s17; // s bound to unit 3
|
John Kessenich | 9fd55bd | 2012-12-13 00:05:26 +0000 | [diff] [blame] | 78 |
|
| 79 | // in another compilation unit...
|
John Kessenich | ba04210 | 2013-04-10 20:15:16 +0000 | [diff] [blame] | 80 | uniform sampler2D s17; // okay, s still bound at 3
|
John Kessenich | 9fd55bd | 2012-12-13 00:05:26 +0000 | [diff] [blame] | 81 |
|
| 82 | // in another compilation unit...
|
| 83 | //layout(binding=4) uniform sampler2D s; // ERROR: contradictory bindings
|
| 84 |
|
John Kessenich | 8f13e13 | 2013-10-18 03:56:23 +0000 | [diff] [blame] | 85 | layout (binding = 2, offset = 4) uniform atomic_uint a2;
|
John Kessenich | 9fd55bd | 2012-12-13 00:05:26 +0000 | [diff] [blame] | 86 |
|
| 87 | layout (binding = 2) uniform atomic_uint bar;
|
| 88 |
|
| 89 | layout (binding = 2, offset = 4) uniform atomic_uint;
|
| 90 |
|
| 91 | layout (binding = 2) uniform atomic_uint bar; // offset is 4
|
| 92 | layout (offset = 8) uniform atomic_uint bar; // error, no default binding
|
| 93 |
|
| 94 | layout (binding=3, offset=4) uniform atomic_uint a2; // offset = 4
|
| 95 | layout (binding=2) uniform atomic_uint b2; // offset = 0
|
| 96 | layout (binding=3) uniform atomic_uint c2; // offset = 8
|
| 97 | layout (binding=2) uniform atomic_uint d2; // offset = 4
|
| 98 |
|
| 99 | //layout (offset=4) // error, must include binding
|
John Kessenich | 60d9f7a | 2013-06-19 20:44:17 +0000 | [diff] [blame] | 100 | //layout (binding=1, offset=0) a; // okay
|
| 101 | //layout (binding=2, offset=0) b; // okay
|
John Kessenich | 9fd55bd | 2012-12-13 00:05:26 +0000 | [diff] [blame] | 102 | //layout (binding=1, offset=0) c; // error, offsets must not be shared
|
| 103 | // // between a and c
|
| 104 | //layout (binding=1, offset=2) d; // error, overlaps offset 0 of a
|
| 105 |
|
| 106 | flat in vec4 gl_FrontColor; // input to geometry shader, no gl_in[]
|
| 107 | flat out vec4 gl_FrontColor; // output from geometry shader
|
| 108 |
|
| 109 | invariant gl_Position; // make existing gl_Position be invariant
|
| 110 |
|
John Kessenich | a4ea131 | 2013-10-11 19:46:10 +0000 | [diff] [blame] | 111 | out vec3 ColorInv;
|
| 112 | invariant ColorIvn; // make existing Color be invariant
|
John Kessenich | 9fd55bd | 2012-12-13 00:05:26 +0000 | [diff] [blame] | 113 |
|
| 114 | invariant centroid out vec3 Color4;
|
| 115 | precise out vec4 position;
|
| 116 |
|
| 117 | out vec3 Color5;
|
| 118 | precise Color5; // make existing Color be precise
|
| 119 | in vec4 a, b, c, d;
|
| 120 | precise out vec4 v;
|
| 121 |
|
| 122 | coherent buffer Block {
|
| 123 | readonly vec4 member1;
|
| 124 | vec4 member2;
|
| 125 | };
|
| 126 |
|
John Kessenich | a4ea131 | 2013-10-11 19:46:10 +0000 | [diff] [blame] | 127 | buffer Block2a {
|
| 128 | coherent readonly vec4 member1A;
|
| 129 | coherent vec4 member2A;
|
John Kessenich | 9fd55bd | 2012-12-13 00:05:26 +0000 | [diff] [blame] | 130 | };
|
| 131 |
|
| 132 | shared vec4 shv;
|
| 133 |
|
| 134 | vec4 funcA(restrict image2D a) { }
|
| 135 |
|
| 136 | vec4 funcB(image2D a) { }
|
| 137 | layout(rgba32f) uniform image2D img1;
|
| 138 | layout(rgba32f) coherent uniform image2D img2;
|
| 139 |
|
| 140 | float func(float e, float f, float g, float h)
|
| 141 | {
|
| 142 | return (e*f) + (g*h); // no constraint on order or
|
| 143 | // operator consistency
|
| 144 | }
|
| 145 |
|
| 146 | float func2(float e, float f, float g, float h)
|
| 147 | {
|
| 148 | precise float result = (e*f) + (g*h); // ensures same precision for
|
| 149 | // the two multiplies
|
| 150 | return result;
|
| 151 | }
|
| 152 |
|
| 153 | float func3(float i, float j, precise out float k)
|
| 154 | {
|
| 155 | k = i * i + j; // precise, due to <k> declaration
|
| 156 | }
|
| 157 |
|
| 158 | void main()
|
| 159 | {
|
| 160 | vec3 r = vec3(a * b); // precise, used to compute v.xyz
|
| 161 | vec3 s = vec3(c * d); // precise, used to compute v.xyz
|
| 162 | v.xyz = r + s; // precise
|
| 163 | v.w = (a.w * b.w) + (c.w * d.w); // precise
|
| 164 | v.x = func(a.x, b.x, c.x, d.x); // values computed in func()
|
| 165 | // are NOT precise
|
| 166 | v.x = func2(a.x, b.x, c.x, d.x); // precise!
|
| 167 | func3(a.x * b.x, c.x * d.x, v.x); // precise!
|
| 168 |
|
| 169 | funcA(img1); // OK, adding "restrict" is allowed
|
| 170 | funcB(img2); // illegal, stripping "coherent" is not
|
| 171 |
|
| 172 | {
|
| 173 | struct light {
|
| 174 | float intensity;
|
| 175 | vec3 position;
|
| 176 | };
|
| 177 |
|
| 178 | light lightVar = light(3.0, vec3(1.0, 2.0, 3.0));
|
| 179 | }
|
| 180 | {
|
John Kessenich | f59bfa0 | 2013-01-10 01:47:54 +0000 | [diff] [blame] | 181 | const float c[3] = float[3](5.0, 7.2, 1.1);
|
John Kessenich | 9fd55bd | 2012-12-13 00:05:26 +0000 | [diff] [blame] | 182 | const float d[3] = float[](5.0, 7.2, 1.1);
|
| 183 |
|
| 184 | float g;
|
| 185 | float a[5] = float[5](g, 1, g, 2.3, g);
|
| 186 | float b[3];
|
| 187 |
|
| 188 | b = float[3](g, g + 1.0, g + 2.0);
|
| 189 | }
|
| 190 | {
|
| 191 | vec4 b[2] = { vec4(1.0), vec4(1.0) };
|
| 192 | vec4[3][2](b, b, b); // constructor
|
| 193 | vec4[][2](b, b, b); // constructor, valid, size deduced
|
| 194 | vec4[3][](b, b, b); // compile-time error, invalid type constructed
|
| 195 | }
|
| 196 | }
|