Issue with Multi-Viewport Rendering Using Mesh Shaders in OpenGL

Hello,

I am having trouble with rendering to multiple viewports using mesh shaders in OpenGL. Despite setting the gl_ViewportIndex for different primitives, only the first viewport receives the rendering, while the second viewport remains empty. Below is the shader code I am using

#version 460
#extension GL_NV_mesh_shader : enable
#extension GL_NV_viewport_array2 : enable

layout(local_size_x = 1) in;
layout(max_vertices = 6) out;
layout(max_primitives = 2) out;
layout(triangles) out;

const vec4 vertices1[3] = vec4[3](
    vec4(-0.5, -0.5, 0.0, 1.0),
    vec4( 0.5, -0.5, 0.0, 1.0),
    vec4( 0.0,  0.5, 0.0, 1.0)
);

const vec4 vertices2[3] = vec4[3](
    vec4( 0.5,  0.5, 0.0, 1.0),
    vec4(-0.5,  0.5, 0.0, 1.0),
    vec4( 0.0, -0.5, 0.0, 1.0)
);

void main() 
{
    // first primitive
    gl_MeshVerticesNV[0].gl_Position = vertices1[0];
    gl_MeshVerticesNV[1].gl_Position = vertices1[1];
    gl_MeshVerticesNV[2].gl_Position = vertices1[2];
    gl_PrimitiveIndicesNV[0] = 0;
    gl_PrimitiveIndicesNV[1] = 1;
    gl_PrimitiveIndicesNV[2] = 2;
    gl_MeshPrimitivesNV[0].gl_ViewportIndex = 0;

    // second primitive
    gl_MeshVerticesNV[3].gl_Position = vertices2[0];
    gl_MeshVerticesNV[4].gl_Position = vertices2[1];
    gl_MeshVerticesNV[5].gl_Position = vertices2[2];
    gl_PrimitiveIndicesNV[3] = 3;
    gl_PrimitiveIndicesNV[4] = 4;
    gl_PrimitiveIndicesNV[5] = 5;
    gl_MeshPrimitivesNV[1].gl_ViewportIndex = 1;

    gl_PrimitiveCountNV = 2;
}

The second viewport does not receive any rendering. What could be causing this issue? Am I missing something in the shader code?

Any guidance or suggestions would be greatly appreciated. Thank you!