Jump to content

  • Log In with Google      Sign In   
  • Create Account


Disable pixel shader


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 donguow   Members   -  Reputation: 173

Like
0Likes
Like

Posted 24 June 2012 - 11:25 PM

Hi guys,

For some reasons, I want to disable the pixel shader (fragment shader). It means that the hardware will throw fragments away right after they come out of the rasterization stage so that the fragments can't be able to get into the next stage (pixel shader).

I know that we can disable rasterization stage by enabling RASTERIZER_DISCARD, is there any similarity with pixel? or any trick to do that?

Thank in advance,
-D

Sponsor:

#2 larspensjo   Members   -  Reputation: 1526

Like
0Likes
Like

Posted 25 June 2012 - 07:08 AM

You can call glCullFace

(GL_FRONT_AND_BACK). That will cull all faces of triangles, sending none to the fragment shader.


Edited by larspensjo, 25 June 2012 - 07:08 AM.

Current project: Ephenation.
Sharing OpenGL experiences: http://ephenationopengl.blogspot.com/

#3 donguow   Members   -  Reputation: 173

Like
0Likes
Like

Posted 25 June 2012 - 07:21 AM

glCullFace won't let the data get into the rasterization stage, but in my case, I still want primitives to be processed at rasterization stage.

#4 japro   Members   -  Reputation: 887

Like
0Likes
Like

Posted 25 June 2012 - 07:23 AM

What are you trying to achieve? Occlusion culling?

#5 mhagain   Crossbones+   -  Reputation: 7328

Like
0Likes
Like

Posted 25 June 2012 - 07:28 AM

The general approach is to use glColorMask (GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE) but documentation I could find suggests that this just prevents the output colour from being written to the framebuffer - the shader will still run. Maybe your driver might be able to make an intelligent optimization, or maybe you can write a simple passthrough fragment shader for this purpose.

It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.


#6 donguow   Members   -  Reputation: 173

Like
0Likes
Like

Posted 25 June 2012 - 08:29 AM

What are you trying to achieve? Occlusion culling?

Nope. I just want to measure the processing time when pixel processing stage is disabled.

#7 mhagain   Crossbones+   -  Reputation: 7328

Like
0Likes
Like

Posted 25 June 2012 - 09:17 AM

I doubt you're going to get a meaningful measurement here. OpenGL API calls are asynchronous and operate in parallel with work on your CPU, so the calls you make with the PS disabled may not have even started executing on the GPU yet when you take your measurement.

It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.


#8 japro   Members   -  Reputation: 887

Like
0Likes
Like

Posted 25 June 2012 - 09:31 AM

You can use GL_TIME_ELAPSED queries tough. But i would also say trying to measure the vertex stage alone is not that useful since the measurement is totally synthetic and not relevant for real use cases. If anything just measure with a trivial fragment shader

#9 mhagain   Crossbones+   -  Reputation: 7328

Like
0Likes
Like

Posted 25 June 2012 - 10:29 AM

Any kind of query is going to need to stall the pipeline during readback though, which will skew the results. The best way is probably to set up a test case without the pixel shader (or with it disabled) and let it run for a few minutes - because transient conditions on your PC may also skew the results when measured over a short timescale. Compare that against the same case run with the full pixel shader and you should get a meaningful enough relative measurement.

Even that won't be 100% perfect though as in a real program there will be all kinds of other stuff going on - CPU/GPU concurrency and concurrency of pipeline stages may even mean that an apparently complex pixel shader can be had for free.

It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.


#10 japro   Members   -  Reputation: 887

Like
1Likes
Like

Posted 25 June 2012 - 11:25 AM

Any kind of query is going to need to stall the pipeline during readback though.

Only if you read back the result instantly, you can wait until it becomes available and read it back then.

#11 Yours3!f   Members   -  Reputation: 1248

Like
0Likes
Like

Posted 25 June 2012 - 02:03 PM

Nope. I just want to measure the processing time when pixel processing stage is disabled.

gDEBugger does this, you can check the GL_GREMEDY_frame_terminator, GL_GREMEDY_string_marker and GL_ARB_debug_output extensions. Also you may want to check out the gDEBugger docs.

Edited by Yours3!f, 25 June 2012 - 02:04 PM.


#12 Aks9   Members   -  Reputation: 756

Like
0Likes
Like

Posted 25 June 2012 - 05:04 PM

Nope. I just want to measure the processing time when pixel processing stage is disabled.


It sounds like you want to check whether your program is fragment shader bound.
In that case, just make ultra simple fragment shader and measure execution time.
Otherwise, glEnable(GL_RASTERIZER_DISCARD) is the way to disable fragment shaders execution.
Also, you could try to discard fragments in the fragment shader. It is, of course, meaningless, but maybe that will trigger some optimization in the drivers and totally eliminate FS.

#13 donguow   Members   -  Reputation: 173

Like
0Likes
Like

Posted 25 June 2012 - 08:18 PM


Nope. I just want to measure the processing time when pixel processing stage is disabled.


It sounds like you want to check whether your program is fragment shader bound.
In that case, just make ultra simple fragment shader and measure execution time.
Otherwise, glEnable(GL_RASTERIZER_DISCARD) is the way to disable fragment shaders execution.
Also, you could try to discard fragments in the fragment shader. It is, of course, meaningless, but maybe that will trigger some optimization in the drivers and totally eliminate FS.

I did use this way. This happens before rasterization stage. I am now testing with discarding fragments. This way, of course, is not perfectly correct but giving pixel shader as little work as possible seems not a bad idea though.

#14 vNeeki   Members   -  Reputation: 194

Like
0Likes
Like

Posted 26 June 2012 - 12:48 AM

I'm probably the worst GLSL programmer in the world , but why you don't try something like :

uniform int enabled;
void main ()
{
    if (enabled)
    {
	    RunMyPixelShaderTask();
    }
}

? Posted Image

#15 donguow   Members   -  Reputation: 173

Like
0Likes
Like

Posted 26 June 2012 - 02:18 AM

uniform int enabled;
void main ()
{
	if (enabled)
	{
		RunMyPixelShaderTask();
	}
}


It is possible to pass varying variables and attribute variables down to pixel shader but I don't think this works for functions. Anw, I still appreciate your idea
What I am doing now is as follows
void main ()
{
	 discard;
}
However, this, of course, can't give me accurate results.

Edited by donguow, 26 June 2012 - 02:19 AM.


#16 phantom   Moderators   -  Reputation: 6652

Like
1Likes
Like

Posted 26 June 2012 - 03:22 AM

As with your last thread on the subject the results are going to get are not going to be accurate; as I pointed out before ( http://www.gamedev.net/topic/626047-processing-time-at-vertex-shader/page__view__findpost__p__4947729 ) the only way you are going to get decent results is to the vendor supplied libraries or tools to time things.

More importantly; WHAT are you trying to do with this information?
Currently you are learning nothing useful what so ever...




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