#version 450 /* Copyright (c) 2023-2025, Holochip Corporation * * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 the "License"; * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #extension GL_EXT_mesh_shader: require #extension GL_GOOGLE_include_directive: require #include "mesh_shader_shared.h" layout(local_size_x = numMeshInvocationsX, local_size_y = numMeshInvocationsY, local_size_z = 1) in; // we'll emit 4 vertices on 2 primitives per mesh shader invocation layout(triangles, max_vertices = 4 * numMeshInvocationsX * numMeshInvocationsY, max_primitives = 2 * numMeshInvocationsX * numMeshInvocationsY) out; taskPayloadSharedEXT SharedData sharedData; // Example of a default output layout and location format: layout (location=3) out vec3 outColor[]; void main() { if ( gl_LocalInvocationIndex == 0 ) { // set the number of vertices and primitives to put out just once for the complete workgroup SetMeshOutputsEXT( 4 * numMeshInvocationsX * numMeshInvocationsY, 2 * numMeshInvocationsX * numMeshInvocationsY); } // determine 4 vertices by combining some global position and offset, as well as some local offset and size vec2 globalOffset = sharedData.offsets[gl_WorkGroupID.x]; vec2 localSize = sharedData.size / gl_WorkGroupSize.xy; vec2 localOffset = gl_LocalInvocationID.xy * localSize; vec2 v0 = sharedData.position + globalOffset + localOffset; vec2 v1 = v0 + vec2( localSize.x, 0.0f ); vec2 v2 = v0 + localSize; vec2 v3 = v0 + vec2( 0.0f, localSize.y ); uint vertexBaseIndex = 4 * gl_LocalInvocationIndex; gl_MeshVerticesEXT[vertexBaseIndex + 0].gl_Position = vec4( v0, 0.0f, 1.0f ); gl_MeshVerticesEXT[vertexBaseIndex + 1].gl_Position = vec4( v1, 0.0f, 1.0f ); gl_MeshVerticesEXT[vertexBaseIndex + 2].gl_Position = vec4( v2, 0.0f, 1.0f ); gl_MeshVerticesEXT[vertexBaseIndex + 3].gl_Position = vec4( v3, 0.0f, 1.0f ); uint primitiveBaseIndex = 2 * gl_LocalInvocationIndex; gl_PrimitiveTriangleIndicesEXT[primitiveBaseIndex + 0] = uvec3( vertexBaseIndex + 0, vertexBaseIndex + 1, vertexBaseIndex + 2 ); gl_PrimitiveTriangleIndicesEXT[primitiveBaseIndex + 1] = uvec3( vertexBaseIndex + 2, vertexBaseIndex + 3, vertexBaseIndex + 0 ); outColor[vertexBaseIndex + 0] = vec3( 1.0f, 0.0f, 0.0f ); outColor[vertexBaseIndex + 1] = vec3( 0.0f, 1.0f, 0.0f ); outColor[vertexBaseIndex + 2] = vec3( 0.0f, 0.0f, 1.0f ); outColor[vertexBaseIndex + 3] = vec3( 1.0f, 1.0f, 0.0f ); }