Skip to main content
GameDev.net gamedev.net
🔒 Locked

Disable pixel shader

Started by donguow Jun 25, 2012 at 5:25 AM 14 replies 7.4k views
Original Post
donguow
donguow
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
donguow
donguow
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.
21st Century Moose
21st Century Moose
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.
Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls. 
donguow
donguow

What are you trying to achieve? Occlusion culling?

Nope. I just want to measure the processing time when pixel processing stage is disabled.
21st Century Moose
21st Century Moose
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.
Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls. 
japro
japro
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
21st Century Moose
21st Century Moose
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.
Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls. 
Yours3!f
Yours3!f
Nope. I just want to measure the processing time when pixel processing stage is disabled. [/quote]
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.
Aks9
Aks9

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

[quote name='donguow' timestamp='1340634594' post='4952666']
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.
[/quote]
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.
vNeeki
vNeeki
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();
}
}


? unsure.png
donguow
donguow


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

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.