Question about shader optimization (rendertarget to 1x1 texture for data)

More
5 months 3 weeks ago - 5 months 3 weeks ago #1 by Daemonjax
So, I was reading this old thread:  reshade.me/forum/shader-presentation/230...ted-storybook-shader
... where crosire was describing a method to have a pixel shader pass run once per frame instead of once per pixel per frame :

Warning: Spoiler!


My questions: 

Is this simply because the rendertarget is 1x1 pixel (which would explain why multiple rendertargets require the pixel dimensions to be the same)?  So if we ONLY changed the texture to be 8x8 pixels, the shader would then run 64 times per frame (setting each pixel in the rendertarget to the same value)?  So I guess there's always a rendertarget even when it's not explicit in the technique declaration, and the default rendertarget is what exactly?  The next color buffer?

I'm always really paranoid on relying on compiller optimizations I don't fully understand.  I could imagine it being dumb and just run 1920*1080 times per frame, setting the same exact pixel in the 1x1 rendertarget to the same value and I'd be none the wiser.  Are there any gotchas to this approach?  

 
Last edit: 5 months 3 weeks ago by Daemonjax.

Please Log in or Create an account to join the conversation.

More
5 months 3 weeks ago #2 by Daemonjax
Or would I still need to include a

if (texcoord.x != 0.5 && texcoord.y != 0.5) discard;

?

 

Please Log in or Create an account to join the conversation.

More
5 months 6 days ago #3 by crosire
Your pixel shader is generally executed once for every pixel, so if you only have one pixel to render to (1x1 render target), it's only executed a single time (your if statement would have no effect, since it would never be hit). With a 8x8 render target it would run 64 times, yes (just keep in mind that it does run in parallel, not serialized, so big numbers here are not a problem).

There is always a render target, it's just that ReShade FX has syntactic sugar in that not explicitly setting a "RenderTarget" pass state will default to the back buffer (the buffer the game rendered the final image to).

Please Log in or Create an account to join the conversation.