سؤال

I have a program which renders first to a texture, then pass the texture to the compute shader for processing, then renders the output result to the screen via a textured full screen quad.

I've read in the nVidia's programming guide for compute shaders that every time you dispatch a compute shader, it initiates a GPU device context switch, which should not be done quite often.

I'm very confused right now. The way I see it, in my rendering pipeline the GPU switches contexts twice. Right? Once during the first dispatch call, the next time when I render my full screen quad normally.

If this is correct, then I can avoid one switch by reorganizing my code like this. First, render to a texture. Second, do the processing on the compute shader. Then, IN THE NEXT FRAME, render the result, then (still in the next frame) render all updates to texture, do processing on compute shader... So basically every start of the frame I render the results of the last frame (the first frame will be an exception). Then there will only be one context switch, right?

But then the GPU will still have to do a context switch between the frames, right? So the two versions of my rendering pipeline all have two context switches. There would be no difference in performance. Am I correct?

Any help would be appreciated.

هل كانت مفيدة؟

المحلول

Context switch introduces a small hit, but in your case it would be pretty negligible, so you can safely switch between compute and render pipeline several times in the same frame without having to worry about it.

In lot of modern games there's more than 2 switches in the same pipeline (graphics pipeline for render, compute shader for light, pixelshader for fxaa...) and they still run fine.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top