Stipple (aka Dither) Shader

Moderator: GZDoom Developers

User avatar
Rachael
Posts: 13531
Joined: Tue Jan 13, 2004 1:31 pm
Preferred Pronouns: She/Her
Contact:

Re: Stipple (aka Dither) Shader

Post by Rachael »

I'm all for efficiency, but I can't wrap my head around the idea of texture access being more efficient than a static array, even on a GPU. With an array you need a maximum of one lookup to get the result, whereas for textures you have to calculate where you are in the texture (even if you're right on the nose), and calculate the neighboring pixels. That might be different if the lookup filter is set to GL_NEAREST but either way I have never noticed a speed difference even on older GPU's, between the two filter types.

I am well aware that GPU's ultimately execute instructions much differently than CPU's do, but they are still ultimately math processors at their core, and I really believe that they're pulling less weight with a simple memory offset lookup, rather than having to multiply out a 'float' with a texture access. I think dpJudas already very efficiently streamlined my code for specially GPU's by creating the matrix lookup in the first place.

If the concern is the matrix is being recreated every frame (or possibly even every pixel) - then yeah, it should be created somewhere else, but I don't know enough about GPU's or OpenGL to know if that's the case. I guess I kind of assume that it's being done at compile time since it's being created outside of a function.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49056
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: Stipple (aka Dither) Shader

Post by Graf Zahl »

I'd assume that shader compilers are smart enough to optimize this. This isn't Java where such fundamental things like static initialized arrays are just missing from the specs, leading to code that initializes them element by element.
User avatar
Rachael
Posts: 13531
Joined: Tue Jan 13, 2004 1:31 pm
Preferred Pronouns: She/Her
Contact:

Re: Stipple (aka Dither) Shader

Post by Rachael »

Well, the current implementation as-is does have some speed issues when I test it on an Intel HD4600. I ran GZDoom both without the shader and with the shader, and I got a smoother frame rate without it.

I hacked together a texture calculation using the screen itself as a texture, and it is indeed faster. I am not really quite sure the actual proper way to do it, though.

I guess I was wrong about it, but I have no idea why. Either way, I'll go ahead and make a texture out of the matrix.
dpJudas
 
 
Posts: 3037
Joined: Sat May 28, 2016 1:01 pm

Re: Stipple (aka Dither) Shader

Post by dpJudas »

I did not rule out the possibility texture sampling could be competitive to the array lookup mostly because texture sampling is so common that GPUs have special silicon and instructions dedicated for precisely this purpose. Especially very old GPUs were terrible at anything with integers in it. There a texture sampling could very well beat the array version as it could be done entirely with floating point instructions.

It is sort of like when you compare the performance between clamp(x, 0.0, 1.0) and max(x, 0.0). The clamp version is faster, especially on older hardware, because there's a dedicated saturate instruction. Same kind of thing can apply for texture stuff. But nowadays, with compute shaders and CUDA, I don't think a texture sampling can beat the static array unless the array is very large (won't fit into local workgroup memory). Even if it does still beat it, the speed difference would most likely be insignificant. The static array version is much easier to maintain and thus wins per default if all other things are in the same ballpark.

About the static array initialization, make sure you don't use that second static variable as input into the first one (change it to a define). I wouldn't put it past the dumbest compilers to then conclude it isn't a constant expression and have it initialize the table on each invocation.
User avatar
Rachael
Posts: 13531
Joined: Tue Jan 13, 2004 1:31 pm
Preferred Pronouns: She/Her
Contact:

Re: Stipple (aka Dither) Shader

Post by Rachael »

I changed it to a #define, and pushed it, but still no speed difference. It's shit on the Intel.
User avatar
Pixel Eater
 
 
Posts: 667
Joined: Wed Aug 02, 2017 12:31 am
Location: In between the Moon and you, between the buried and me.

Re: Stipple (aka Dither) Shader

Post by Pixel Eater »

Texture lookup was a lot faster when I ported the software fuzz into RetroSpectre. It went from ~50ms lag to ~2ms.
Looking forward to trying this shader out!
dpJudas
 
 
Posts: 3037
Joined: Sat May 28, 2016 1:01 pm

Re: Stipple (aka Dither) Shader

Post by dpJudas »

Okay so the conclusion here is that Intel can only do texture sampling fast. Why am I not surprised. Their hardware has always been shit and seems it is going to stay that way, too.
User avatar
Pixel Eater
 
 
Posts: 667
Joined: Wed Aug 02, 2017 12:31 am
Location: In between the Moon and you, between the buried and me.

Re: Stipple (aka Dither) Shader

Post by Pixel Eater »

In my case it's an Nvidia GeForce GT 755m 1024mb, which came built in to a late 2013 iMac.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49056
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: Stipple (aka Dither) Shader

Post by Graf Zahl »

Pixel Eater wrote:which came built in to a late 2013 iMac.

In that case the fault probably lies with Apple. Their GL implementation predates any sane standard for calculation intensive features.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49056
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: Stipple (aka Dither) Shader

Post by Graf Zahl »

Regarding the texture...

Great, that's another useless complication for Vulkan, considering how messy texture creation on Vulkan is, and this one not quite being that compatible to the standard formats of the texture manager. Is this only a problem on older Intels or on all of them? The mentioned HD 4600 is not quite the latest model.
_mental_
 
 
Posts: 3812
Joined: Sun Aug 07, 2011 4:32 am

Re: Stipple (aka Dither) Shader

Post by _mental_ »

So, this feature may have some performance issues (implementation dependent but still), and it's enabled by default and cannot be disabled, and it improves the picture in so subtle way that it's quite hard to notice the effect, right? Sorry if I'm missing something, but why?
It's OK to have an optional feature that unusable with particular hardware for some reason. In my opinion, however, this one is not that kind of feature and moreover it's not optional.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49056
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: Stipple (aka Dither) Shader

Post by Graf Zahl »

It's called "unfinished business" and definitely needs a switch.
To be honest, when it got merged to master by accident that should have been reverted ASAP.
dpJudas
 
 
Posts: 3037
Joined: Sat May 28, 2016 1:01 pm

Re: Stipple (aka Dither) Shader

Post by dpJudas »

Yeah, it will get a switch - no worries.

About the performance, I could actually measure a minor speed improvement even on my NV 980, so apparently all GPU's are teh suck when it comes to static arrays. Bit surprised about that, but hey, learn something every day. :)

About the texture format and Vulkan, the present shader is highly related to the postprocess system and the general swap chain. Postprocess already creates textures of various exotic formats and its texture management for Vulkan should be able to handle this texture as well. I don't utilize the general abstraction I created there yet mostly because I need to see exactly how our interaction with the swap chain ends up. Basically I don't think we will have to special handle the dither texture in the long run - whatever code we end up managing postprocess stuff should be able to handle it.
User avatar
Marisa the Magician
Posts: 3886
Joined: Fri Feb 08, 2008 9:15 am
Preferred Pronouns: She/Her
Operating System Version (Optional): (btw I use) Arch
Graphics Processor: nVidia with Vulkan support
Location: Vigo, Galicia
Contact:

Re: Stipple (aka Dither) Shader

Post by Marisa the Magician »

I get the same FPS with dither and without dither on my 1060. :S
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49056
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: Stipple (aka Dither) Shader

Post by Graf Zahl »

I'm wondering if using a uniform buffer for the dither table may be better than a texture. That should be the most straightforward way to provide raw data.
Post Reply

Return to “Closed Feature Suggestions [GZDoom]”