Jump to content
  • Advertisement
Sign in to follow this  
Prune

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

This topic is 2040 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Advertisement

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites
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 ;)

Share this post


Link to post
Share on other sites

 

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".

Share this post


Link to post
Share on other sites

 

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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!