🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

GLSL using "return"

Started by
3 comments, last by Tommato 3 years, 10 months ago

Hi All

I'm using glBegin(End)TransformFeedback API and in geometry shader writting a buffer

out block {

 vec4 Color;

} Out;

void main()

{
  ...
  Out.Color = vec4(..);
  ...
}

If I avoid to use “return” in main, then all is going as expected, the buffer has correct size and filled with data I wrote. However with return in main the buffer size = count of all primitives passed in glDrawElements and all values are 1.0. So my questions are:

  • is this a bug or limitation or hidden feature?
  • where can I read about it or, better yet, about cases like this one? It would be a pain if happened on remote user's machine I can't debug

Thx

Advertisement

Calling return will end processing of the function, further writes to output, which happen asynchronously at a distance in the single draw call/invoking stage of the shader, may not happen.

From the GLSL docs (https://www.khronos.org/opengl/wiki/Core_Language_(GLSL))

Using discard is different from return from main. Executing return still means that the values written to the shader outputs will be used by the rest of the pipeline. Executing discard means that they will not. Also, returning before writing outputs to all of the outputs yields undefined behavior for the unwritten outputs, whereas discard has defined behavior for unwritten outputs.

So could it be that you are not writing to all outputs before return is called, which for some reason might work on most PCs but get you those issues on other PCs? (thats pretty much what undefined behaviour means)

Thx for your replies

I understand the returning before writing something as glFragColor (for example) = UB, But I see no any UB with geometry shader that solves itself should a primitive be emitted or not. And what's wrong to use “return” in last case?

About “this/that machine/card”, this prob appeared on main, (OpenGL 4.1, INTEL-12.4.7) can it be with other hardware - don't know,

This topic is closed to new replies.

Advertisement