Jump to content

  • Log In with Google      Sign In   
  • Create Account


Depth pre-pass: does OpenGL still execute fragment shader if depth not written and color mask is GL_NONE?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
15 replies to this topic

#1 Prune   Members   -  Reputation: 216

Like
0Likes
Like

Posted 14 March 2014 - 02:27 PM

I set up for depth pre-pass as follows:

glEnable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE);
glDepthFunc(GL_LESS);
glClear(GL_DEPTH_BUFFER_BIT);
glFramebufferDrawBufferEXT(id, GL_NONE); // id is currently bound framebuffer object
glColorMaski(0, GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);

I'm not explicitly writing depth in the fragment shader. Should I then have a version of my shader program that has only a vertex shader and no fragment shader? I ask for efficiency reasons, since I don't know whether OpenGL can figure out from either the GL_NONE draw buffer or false color mask that it doesn't need to run the fragment shader. The downside of doing a separate shader program for the depth pre-pass is that I'd have to do it for every shader program that has a different vertex shader.


"But who prays for Satan? Who, in eighteen centuries, has had the common humanity to pray for the one sinner that needed it most?" --Mark Twain

~~~~~~~~~~~~~~~Looking for a high-performance, easy to use, and lightweight math library? http://www.cmldev.net/ (note: I'm not associated with that project; just a user)

Sponsor:

#2 dpadam450   Members   -  Reputation: 862

Like
-3Likes
Like

Posted 14 March 2014 - 04:45 PM

Kind of a useless question.

If it does execute: then keep your fragment shader as gl_FragColor = vec4(0,0,0,0);  OR you may not even need it. leaving a blank main() that returns immediately even though it is executed.

If it doesn't execute for GL_NONE: then keep the same stripped down fragment shader. It just wont run.....

I don't believe you can have a shader object without a vertex + pixel shader. Not sure though.



#3 3TATUK2   Members   -  Reputation: 729

Like
1Likes
Like

Posted 14 March 2014 - 05:02 PM

First off, you ask "if depth not written" - and then you use glDepthMask(GL_TRUE) - that's oxymoronic.

 

Secondly, for a final absolute determination... you can use a query object for samples passed.



#4 TheChubu   Crossbones+   -  Reputation: 3971

Like
-1Likes
Like

Posted 14 March 2014 - 05:05 PM

I think you can use the stencil buffer to mark what pixels you want to run fragment shaders on.


"I AM ZE EMPRAH OPENGL 3.3 THE CORE, I DEMAND FROM THEE ZE SHADERZ AND MATRIXEZ"

 

My journals: dustArtemis ECS framework and Making a Terrain Generator


#5 Prune   Members   -  Reputation: 216

Like
-1Likes
Like

Posted 14 March 2014 - 05:07 PM

Kind of a useless question.

If it does execute: then keep your fragment shader as gl_FragColor = vec4(0,0,0,0);  OR you may not even need it. leaving a blank main() that returns immediately even though it is executed.

If it doesn't execute for GL_NONE: then keep the same stripped down fragment shader. It just wont run.....

I don't believe you can have a shader object without a vertex + pixel shader. Not sure though.

 

Maybe you should read the question again, because you seem to have answered a different one.

 

> If it does execute...

> If it doesn't execute

 

That presumes the answer--which, if I knew, I wouldn't have asked here in the very title of my question, now, would have I? Do you have a problem with reading comprehension?

 

I specifically asked about efficiency. I need to know which case it is, so I can determine whether to do the work of making additional shader programs that have the no fragment shader (or have a main() that doesn't do anything--which of those latter two is NOT my question and obviously I can easily check). What you wrote, instead, was what to do in either case--which I already knew. GG


Edited by Prune, 14 March 2014 - 05:08 PM.

"But who prays for Satan? Who, in eighteen centuries, has had the common humanity to pray for the one sinner that needed it most?" --Mark Twain

~~~~~~~~~~~~~~~Looking for a high-performance, easy to use, and lightweight math library? http://www.cmldev.net/ (note: I'm not associated with that project; just a user)

#6 Prune   Members   -  Reputation: 216

Like
1Likes
Like

Posted 14 March 2014 - 05:10 PM

First off, you ask "if depth not written" - and then you use glDepthMask(GL_TRUE) - that's oxymoronic.

 

Secondly, for a final absolute determination... you can use a query object for samples passed.

I mean not written explicitly in the fragment shader by assigning to gl_FragDepth.


"But who prays for Satan? Who, in eighteen centuries, has had the common humanity to pray for the one sinner that needed it most?" --Mark Twain

~~~~~~~~~~~~~~~Looking for a high-performance, easy to use, and lightweight math library? http://www.cmldev.net/ (note: I'm not associated with that project; just a user)

#7 samoth   Crossbones+   -  Reputation: 4656

Like
1Likes
Like

Posted 14 March 2014 - 05:14 PM

Impossible to tell for sure, but probably yes.

 

In theory, the fragment shader should run, since whether or not you enable writing out fragments using glColorMaski doesn't matter for the shader. Masking happens after execution of the fragment shader, and it is also orthogonal (in times of atomic ops and shader load/store, a shader can have side effects even if not outputting any depth or color values to fragments).

 

In practice, who knows. The driver might simply realize that nothing happens (depth is not written in the shader, and color is masked out) and not execute the shader at all. If your application has a noticeable market share, the IHV might even come up with a driver profile for your application which enables that optimization only for your application.

 

First off, you ask "if depth not written" - and then you use glDepthMask(GL_TRUE) - that's oxymoronic.
The meaning is (at least I'd guess so) that depth is written as the interpolated vertex depth, and not calculated by the fragment shader.

Edited by samoth, 14 March 2014 - 05:19 PM.


#8 Hodgman   Moderators   -  Reputation: 28605

Like
4Likes
Like

Posted 14 March 2014 - 05:23 PM

If you don't bind a shader, then the fixed function pipeline will take over ;)

I think in these cases you just have to trust that the driver will be smart enough to optimize for the case where there's no colour-target bound and/or the colour-write mask is all 0's.

Btw, if you did write to gl_FragDepth in your shader, you'd likely be disabling Hi-Z/early-Z optimizations, defeating the purpose of a depth-pre-pass ;)

#9 Prune   Members   -  Reputation: 216

Like
0Likes
Like

Posted 14 March 2014 - 05:28 PM

 

Impossible to tell for sure, but probably yes.

 

In theory, the fragment shader should run, since whether or not you enable writing out fragments using glColorMaski doesn't matter for the shader. Masking happens after execution of the fragment shader, and it is also orthogonal (in times of atomic ops and shader load/store, a shader can have side effects even if not outputting any depth or color values to fragments).

 

In practice, who knows. The driver might simply realize that nothing happens (depth is not written in the shader, and color is masked out) and not execute the shader at all. If your application has a noticeable market share, the IHV might even come up with a driver profile for your application which enables that optimization only for your application.

 

 

 

First off, you ask "if depth not written" - and then you use glDepthMask(GL_TRUE) - that's oxymoronic.
The meaning is (at least I'd guess so) that depth is written as the interpolated vertex depth, and not calculated by the fragment shader.

 

Thanks. And yes, that's what I meant with "depth not written".


"But who prays for Satan? Who, in eighteen centuries, has had the common humanity to pray for the one sinner that needed it most?" --Mark Twain

~~~~~~~~~~~~~~~Looking for a high-performance, easy to use, and lightweight math library? http://www.cmldev.net/ (note: I'm not associated with that project; just a user)

#10 dpadam450   Members   -  Reputation: 862

Like
-3Likes
Like

Posted 14 March 2014 - 05:44 PM

 

does OpenGL still execute fragment shader if depth not written and color mask is GL_NONE?

 

And what exactly did I say......... I will add you to the list of people I choose not to help, which will be 1 person for the last 8 years I've been on here.

I gave you some logical thinking which is: who cares. If the GPU does or doesn't run the pixel shader, then whatever shader you have bound wont run anyway (Even if its 1 million executions). If the contrary to that is it does run, then give it the simplest shader possible. Same result, and you don't even need to know the answer to your question................because it doesn't matter. Its either going to execute your 0 or 1 instruction pixel shader or not. Its out of your control, but if you assume it has to run a pixel shader, then you are safe. NOT TO MENTION it could be vendor/card specific under the hood to decide to use the pixel shader or not.

How hard is if for you to write a pixel shader that does 20 texture fetches with glDrawBuffers(GL_NONE) and see if your performance is horrible.....well then its running your pixel shader......

 

Do you have a problem with reading comprehension?

When people (who work in the industry already) reply to you and give you a decent answer and tell them they are too stupid that they can't even read your question, so they shouldn't help you.....


Edited by dpadam450, 14 March 2014 - 05:51 PM.


#11 CoffeeandCode   Members   -  Reputation: 174

Like
0Likes
Like

Posted 14 March 2014 - 06:29 PM

Instead of answering the question (because I don't know) I'll just suggest you use `glDrawBuffer(GL_NONE)` to explicitly tell it not to draw to a color buffer. I dont use a fragment shader with this setting and Everything runs great.

#12 3TATUK2   Members   -  Reputation: 729

Like
-1Likes
Like

Posted 14 March 2014 - 10:47 PM

glStencilFunc(GL_NEVER,0,0);

glEnable(GL_STENCIL_TEST);



#13 JohnnyCode   Members   -  Reputation: 199

Like
0Likes
Like

Posted 15 March 2014 - 12:29 AM

as Hodge man said, in case you alter gl_FragCoord, pixel function is run even if zfail occurs. In case you dont, rendering z prepass will mean writing to depth buffer, so pixel function will run if z passes. If you have an extensive instruction you do not wish to run in it computing colors, use a another program with rather empty pixel function, I do not see a big problem setting a program once a frame to generate zprepass. I gess that only in case of colormask false, depthmask false and stencil mask false will driver not perform pixel function, but that would mean not performing actual draw call, what is not a case of depth writing zprepass.



#14 Ohforf sake   Members   -  Reputation: 1688

Like
1Likes
Like

Posted 15 March 2014 - 04:59 AM

Should I then have a version of my shader program that has only a vertex shader and no fragment shader? [...] The downside of doing a separate shader program for the depth pre-pass is that I'd have to do it for every shader program that has a different vertex shader.


I think you should be able to reuse the shaders for the shadow map generation, so you don't need an additional version (or rather, you need it anyways for the shadows).

As to whether or not you should use seperate versions in the first place: I don't have actual numbers, but a vertex program reads a lot of attributes (texture coordinates, normals, tangents, ...) that you don't need for shadow maps/z pre pass. The driver might be able to detect, that the fragment program can be disabled, and that it doesn't need the interpolants for those attributes, but my guess is that it won't recompile the vertex program to strip out all the unnecessary attribute reading and (possibly) transforming.
Also, most shaders only vary in the fragment part and using a seperate shader for shadow map/z pre pass should allow the renderer to issue less shader program changes or even merge entire draw calls.
So I would expect to see a performance speedup from seperate shader versions, but again: I don't have any real numbers to prove it.

#15 Ohforf sake   Members   -  Reputation: 1688

Like
0Likes
Like

Posted 15 March 2014 - 05:48 AM

[...] Same result, and you don't even need to know the answer to your question................because it doesn't matter. Its either going to execute your 0 or 1 instruction pixel shader or not.


Actually I seem to recall that a certain widely used GPU could render at twice it's normal speed when fragment programs were explicitely disabled. On that GPU, the 0 or 1 instruction pixel shader would slow down rendering to half the possible speed.

#16 samoth   Crossbones+   -  Reputation: 4656

Like
0Likes
Like

Posted 15 March 2014 - 08:23 AM

Actually I seem to recall that a certain widely used GPU could render at twice it's normal speed when fragment programs were explicitely disabled. On that GPU, the 0 or 1 instruction pixel shader would slow down rendering to half the possible speed.

That was nVidia GPUS, a long time ago (like... Geforce 8 or so, possibly even Geforce 6).

 

 

In general, that same thing is of course still true, but not as such a clear-cut 1:2 thing. The time it takes to complete a frame is the time it takes to process the vertices and run other gimmicks such as geo shader or tesselation, and then shade fragments, and finally push the output trough ROPs.

 

While ALU (that is, shaders) has gone up tremendously, ROP is more or less the same as it was 5 or 10 years ago, so this matters a lot more.

 

Depending on how the ROPs work on a partiuclar card (ALU is nowadays scalar, so processing 4 values isn't the same as processing 1 value any more, it might be similar for ROPs, or very different -- I can't tell), it may make virtually no difference at all, or a huge difference. Imagine that a ROP can pass a 4-vector plus depth plus stencil (6 values total) during one clock cycle, or 6 depth-only values (also 6 values total). Or, imagine that it processes one output pixel with up to 16 (or any other number) values.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS