[Added] Stipple (aka Dither) Shader

Moderator: Developers

Re: Stipple (aka Dither) Shader

Postby Rachael » Tue Aug 07, 2018 2:40 pm

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
Rachael
QZDoom + Webmaster
 
Joined: 13 Jan 2004

Re: Stipple (aka Dither) Shader

Postby Graf Zahl » Tue Aug 07, 2018 2:58 pm

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
Graf Zahl
Lead GZDoom Developer
 
Joined: 19 Jul 2003
Location: Germany

Re: Stipple (aka Dither) Shader

Postby Rachael » Tue Aug 07, 2018 3:32 pm

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.
User avatar
Rachael
QZDoom + Webmaster
 
Joined: 13 Jan 2004

Re: Stipple (aka Dither) Shader

Postby dpJudas » Tue Aug 07, 2018 3:40 pm

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.
dpJudas
 
 
 
Joined: 28 May 2016

Re: Stipple (aka Dither) Shader

Postby Rachael » Tue Aug 07, 2018 4:06 pm

I changed it to a #define, and pushed it, but still no speed difference. It's shit on the Intel.
User avatar
Rachael
QZDoom + Webmaster
 
Joined: 13 Jan 2004

Re: Stipple (aka Dither) Shader

Postby Pixel Eater » Tue Aug 07, 2018 5:18 pm

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!
User avatar
Pixel Eater
I sense evil I fear it here today, Like a bad dream that never goes away -MBerry
 
 
 
Joined: 02 Aug 2017
Location: In between the Moon and you, between the buried and me.

Re: Stipple (aka Dither) Shader

Postby dpJudas » Tue Aug 07, 2018 5:27 pm

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.
dpJudas
 
 
 
Joined: 28 May 2016

Re: Stipple (aka Dither) Shader

Postby Pixel Eater » Tue Aug 07, 2018 7:07 pm

In my case it's an Nvidia GeForce GT 755m 1024mb, which came built in to a late 2013 iMac.
User avatar
Pixel Eater
I sense evil I fear it here today, Like a bad dream that never goes away -MBerry
 
 
 
Joined: 02 Aug 2017
Location: In between the Moon and you, between the buried and me.

Re: Stipple (aka Dither) Shader

Postby Graf Zahl » Wed Aug 08, 2018 1:08 am

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 Developer
 
Joined: 19 Jul 2003
Location: Germany

Re: Stipple (aka Dither) Shader

Postby Graf Zahl » Wed Aug 08, 2018 1:28 am

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.
User avatar
Graf Zahl
Lead GZDoom Developer
 
Joined: 19 Jul 2003
Location: Germany

Re: Stipple (aka Dither) Shader

Postby _mental_ » Wed Aug 08, 2018 2:24 am

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.
_mental_
 
 
 
Joined: 07 Aug 2011

Re: Stipple (aka Dither) Shader

Postby Graf Zahl » Wed Aug 08, 2018 2:44 am

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.
User avatar
Graf Zahl
Lead GZDoom Developer
 
Joined: 19 Jul 2003
Location: Germany

Re: Stipple (aka Dither) Shader

Postby dpJudas » Wed Aug 08, 2018 4:37 am

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.
dpJudas
 
 
 
Joined: 28 May 2016

Re: Stipple (aka Dither) Shader

Postby Marisa Kirisame » Wed Aug 08, 2018 5:54 am

I get the same FPS with dither and without dither on my 1060. :S
User avatar
Marisa Kirisame
ZScript Magician
 
 
 
Joined: 08 Feb 2008
Location: Vigo, Galicia
Discord: Marisa Kirisame#4689
Twitch ID: magusmarisa

Re: Stipple (aka Dither) Shader

Postby Graf Zahl » Sun Aug 12, 2018 3:35 am

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.
User avatar
Graf Zahl
Lead GZDoom Developer
 
Joined: 19 Jul 2003
Location: Germany

PreviousNext

Return to Closed Feature Suggestions

Who is online

Users browsing this forum: No registered users and 2 guests