1#version 460 2 3#define MAX_VER 81 4#define MAX_PRIM 32 5 6#define BARRIER() \ 7 memoryBarrierShared(); \ 8 barrier(); 9 10#extension GL_EXT_mesh_shader : enable 11 12layout(local_size_x = 32, local_size_y=1, local_size_z=1) in; 13 14layout(max_vertices=MAX_VER) out; 15layout(max_primitives=MAX_PRIM) out; 16layout(triangles) out; 17 18// test use of builtins in mesh shaders: 19 20void main() 21{ 22 uint iid = gl_LocalInvocationID.x; 23 uint gid = gl_WorkGroupID.x; 24 uvec3 numWorkGrous = gl_NumWorkGroups; 25 uint vertexCount = MAX_VER; // vertexCount <= max_vertices 26 uint primitiveCount = MAX_PRIM; // primitiveCount <= max_primtives 27 SetMeshOutputsEXT(vertexCount, primitiveCount); 28 29 gl_MeshVerticesEXT[iid].gl_Position = vec4(1.0); 30 gl_MeshVerticesEXT[iid].gl_PointSize = 2.0; 31 gl_MeshVerticesEXT[iid].gl_ClipDistance[3] = 3.0; 32 gl_MeshVerticesEXT[iid].gl_CullDistance[2] = 4.0; 33 34 BARRIER(); 35 36 gl_MeshVerticesEXT[iid+1].gl_Position = gl_MeshVerticesEXT[iid].gl_Position; 37 gl_MeshVerticesEXT[iid+1].gl_PointSize = gl_MeshVerticesEXT[iid].gl_PointSize; 38 gl_MeshVerticesEXT[iid+1].gl_ClipDistance[3] = gl_MeshVerticesEXT[iid].gl_ClipDistance[3]; 39 gl_MeshVerticesEXT[iid+1].gl_CullDistance[2] = gl_MeshVerticesEXT[iid].gl_CullDistance[2]; 40 41 BARRIER(); 42 43 gl_MeshPrimitivesEXT[iid].gl_PrimitiveID = 6; 44 gl_MeshPrimitivesEXT[iid].gl_Layer = 7; 45 gl_MeshPrimitivesEXT[iid].gl_ViewportIndex = 8; 46 gl_MeshPrimitivesEXT[iid].gl_CullPrimitiveEXT = false; 47 48 BARRIER(); 49 50 gl_MeshPrimitivesEXT[iid+1].gl_PrimitiveID = gl_MeshPrimitivesEXT[iid].gl_PrimitiveID; 51 gl_MeshPrimitivesEXT[iid+1].gl_Layer = gl_MeshPrimitivesEXT[iid].gl_Layer; 52 gl_MeshPrimitivesEXT[iid+1].gl_ViewportIndex = gl_MeshPrimitivesEXT[iid].gl_ViewportIndex; 53 gl_MeshPrimitivesEXT[iid+1].gl_CullPrimitiveEXT = gl_MeshPrimitivesEXT[iid].gl_CullPrimitiveEXT; 54 55 BARRIER(); 56 57 // check bound limits 58 gl_PrimitiveTriangleIndicesEXT[0] = uvec3(257); // should truncate 257 -> 1, range is between [0, vertexCount-1] 59 gl_PrimitiveTriangleIndicesEXT[primitiveCount - 1] = uvec3(2); // array size is primitiveCount*3 for triangle 60 gl_PrimitiveTriangleIndicesEXT[gid] = gl_PrimitiveTriangleIndicesEXT[gid-1]; 61 62 BARRIER(); 63} 64 65// test use of builtins enabled by other extensions 66#extension GL_ARB_shader_draw_parameters : enable 67#extension GL_EXT_multiview : enable 68 69void testAdditionalBuiltins() 70{ 71 int id = gl_DrawIDARB; // GL_ARB_shader_draw_parameters 72 int viewIdx = gl_ViewIndex; // GL_EXT_multiview 73 74}