Graphics
Intel® graphics drivers and software, compatibility, troubleshooting, performance, and optimization
22647 Discussions

Crash on write to GL_NONE attachment

szamil
Beginner
370 Views

When my OpenGL app renders multiple textures, it crashes if I try to discard the output by setting GL_NONE in glDrawBuffers.

Is that a bug or there is a specification I am not aware of? NVidia works fine. 

Example code below (C#):

GL.DrawBuffers(5, new[] {
      DrawBuffersEnum.None,
      DrawBuffersEnum.ColorAttachment5,
      DrawBuffersEnum.ColorAttachment1,
      DrawBuffersEnum.None,
      DrawBuffersEnum.None,
  });

shader:

#version 430 core
layout(location = 0) out vec4 outColor1;
layout(location = 1) out vec4 outFront;
layout(location = 2) out vec4 outBack;
layout(location = 3) out vec4 outColor2;
layout(location = 4) out vec4 outNormal;

void main(void)
{
	outColor1 = vec4(0, 1.0, 0, 1.0); // will crash silently
}

 

0 Kudos
2 Replies
jbruceyu
New Contributor I
293 Views

...attempting to write to an output in the fragment shader while the corresponding draw buffer is set to GL_NONE i.e., explicitly discarding output can lead to undefined behavior, depending on the GPU driver and platform. According to the OpenGL specification, if a shader writes to a location that is not backed by an active draw buffer e.g., GL_NONE, the behavior is undefined unless the shader explicitly disables that output. While some drivers, like NVIDIA’s, may tolerate this or silently ignore the write, others (including Intel’s driver stack) may crash or behave unpredictably, which seems to be what you're experiencing here.

To ensure cross-vendor compatibility and avoid undefined behavior, you should only write to fragment shader outputs that are actively bound viaglDrawBuffers. For outputs that are not active, you have two safe options:

  1. Don’t write to those outputs at all in the shader, or

  2. Use preprocessor directives or dynamic branching to conditionally write based on your output configuration.

Example workaround:

glsl
layout(location = 0) out vec4 outColor1; void main(void) { // Only write if outColor1 is actively bound (logic handled on CPU side) #ifdef ENABLE_COLOR1 outColor1 = vec4(0, 1.0, 0, 1.0); #endif }

NVIDIA’s drivers tend to be more lenient in allowing undefined or non-standard behavior. However, relying on this can create portability issues, especially across Intel and AMD drivers, or on platforms strictly following OpenGL specifications.

 

hope it helps,

0 Kudos
szamil
Beginner
263 Views

Can you provide sources for that or is it chatgpt?

 

The preprocessor option will require my to recompile the shader. 

 

0 Kudos
Reply