OpenGL `smooth` interpolation seemingly producing different results than `flat` interpolation when all vertices have the same value

geometry shader:

#version 460 core

layout (points) in;
layout (triangle_strip, max_vertices=4) out;

in vec3 coords_[];
smooth out vec3 coords;

const float offset = .2f;

void main() {
	gl_Position = gl_in[0].gl_Position + vec4(-offset, offset, 0.f, 0.f);
	coords = coords_[0];
	EmitVertex();

	gl_Position = gl_in[0].gl_Position + vec4(-offset, -offset, 0.f, 0.f);
	coords = coords_[0];
	EmitVertex();

	gl_Position = gl_in[0].gl_Position + vec4(offset, offset, 0.f, 0.f);
	coords = coords_[0];
	EmitVertex();

	gl_Position = gl_in[0].gl_Position + vec4(offset, -offset, 0.f, 0.f);
	coords = coords_[0];
	EmitVertex();


	EndPrimitive();
}

fragment shader:

#version 460 core

smooth in vec3 coords;

out vec4 frag_color;

uniform sampler3D array;

void main() {
	float col = texelFetch(array, ivec3(coords), 0).r;
	frag_color = vec4(col, col, col, 1.f);
}

This produces wrong values, most likely wrong coords values, as this persists even when changing texelFetch to a different function like texture. changing the interpolation form smooth to flat or noperspective fixes the problem. This is weird, because all 4 vertices from the geometry shader should have the same coords value, thus changing the interpolation used should have no effect. This does not happen on other OpenGL implementations (though I’ve only tested Intel Mesa, as that’s the only other GPU I have).

This only happens for curtain view matrices (try varying the z coordinate of camera_pos on line 121 of the provided code). for example, 5.333f and 5.666f produce the bug, but 5.5f and 5.0f don’t.

It happens for any array_size (line 67) >= 2. It does not happen when all the values in the array are the same.

wrong result (with smooth interpolation):

correct result (with flat or noperspective interpolation or on a different GPU):

I’ve provided a minimal reproducer in bug.zip. you can compile it with gcc -I cglm/include/ -I glad/include/ -lm -lglfw -lGL -o bug glad/src/gl.c bug.c and run it with ./bug. You will need to have GLFW installed on the system to compile and run it, cglm and glad are included in the zip file directly.

The provided code does not do any error checking, however, i also have more complete code with proper error checking and an OpenGL debug context, and nothing is being reported.

bug.zip (310.6 KB)

When trying to capture this in RenderDoc, the bug is not present on the capture:

when capturing (bug present):

when captured (bug not present):

system information

PC: ThinkPad P1 Gen 4i

distro: Fedora 44

DE: GNOME

windowing system: Wayland

GPU: NVIDIA RTX A2000 Mobile

driver version: 610.57.04