CUDASynth

These CUDA filters are packaged into DGDecodeNV, which is part of DGDecNV.
User avatar
Rocky
Posts: 3631
Joined: Fri Sep 06, 2019 12:57 pm

CUDASynth

Post by Rocky »

hydra3333 wrote:
Mon Apr 01, 2024 1:07 am
Wondering, the original video author may have intended for some type of shade graduation left to right to remain apparent, perhaps a squirrely monster lurks in the shadows or something, and my tired old eyes don't quite perceive the result like that or I didn't properly discern your intent.
Sure, it depends on the use case. Think of it as the two extremes of possible processing of that image. There is this thing called lerping that allows you to generate any intermediate between the two extremes:

https://stackoverflow.com/questions/198 ... using-lerp
I guess you are saying that's doable and depends on some parameters (curves?) one specifies in the call. I must read the documentation you provided in the release.
You could use lerping to make an acceptable intermediate. But if you are not interested in spatially equalizing things at all, then you wouldn't use a windowed filter.
Would it be possible to post the clip with the stones, for us to play with?
The original is an image that you can turn into a clip with ImageSource() or directly in VirtualDub. Right click and 'Save image as ...' on the stones image here:

https://www.rationalqm.us/winhistogram.html

Note that this filter's 'Strength' parameter just controls a lerping of the original and fully filtered outputs.

Hope you had a cracker of an Easter, m8!
User avatar
hydra3333
Posts: 408
Joined: Wed Oct 06, 2010 3:34 am
Contact:

CUDASynth

Post by hydra3333 »

Rocky wrote:
Mon Apr 01, 2024 1:47 pm
Hope you had a cracker of an Easter, m8!
And you ! :D
Cheers
Rocky wrote:
Mon Apr 01, 2024 1:37 pm
You'd start with some other source filter, then add the proposed DGFilters() filter.
...

here are two advantages: 1) different source filters could be used (while retaining the advantages of CUDASynth), and 2) I wouldn't have to individually implement standalone filters; I'd just have the one do-it-all DGFilters().
Yes, that seemed like a beaut concept.
I gather ?vapoursynth author? seems to be developing https://github.com/vapoursynth/bestsource which I guess some may consider using for odd formats or perhaps "real" vfr->cfr if required, so that approach would be great.
I really do like it here.
User avatar
Rocky
Posts: 3631
Joined: Fri Sep 06, 2019 12:57 pm

CUDASynth

Post by Rocky »

For sure. Bit of chutzpah there to name your tool "BestTool" but perhaps it's a bit of tongue-in-cheek. Wasn't that Ron Jeremy's trademark? ;)

So yeah, and it won't be hard to implement. Just make an alias DGFilters for DGSource and have it pass a null dgi string. Then, in GetFrame, if the dgi was null, instead of doing source filter stuff we do normal filter stuff plus uploading/downloading the frame at the start and end of the chain. Then the rest of the code doesn't know or care whether it's DGSource or DGFilters. Let's see. After that initial implementation, we'll have greatly reduced development/testing/maintenance going forward.

Off to make a DGMPGDec release...
User avatar
Rocky
Posts: 3631
Joined: Fri Sep 06, 2019 12:57 pm

CUDASynth

Post by Rocky »

I got rid of my own points file format and replaced it with the GIMP curve file format. GIMP is free so it's ideal to create and export curve files. I'll need a ranges file, though, to do frame ranges.
User avatar
Rocky
Posts: 3631
Joined: Fri Sep 06, 2019 12:57 pm

CUDASynth

Post by Rocky »

My solution is working great for the luma curve but there are issues with color. Now be aware that since this is going into DGSource() it must and only accepts YUV (aka YCbCr). So I thought, erm, all I have to do is convert to RGB, apply the RGB curves and convert back to YUV. What's the big deal? Well, the deal is that, believe it or not, not all legal YUV values generate legal RGB. I saw some colors producing RGB values of up to -10 (for 8-bit). Yes, negative! OK, no problemo, just clip to 0-255. That's easy but the result is horrible. Ya know, people don't just clip for HDR to SDR tone mapping, and for good reason.

Hmm, I thought, Vapoursynth-Curve accepts both YUV and RGB, let's see what they do. Oy, ya know what they do? When the input is YUV, the 'red' curve controls Y, the 'green' controls U, and the 'blue' controls V. Yuck. Nobody in their right mind would want or be able to intuitively tweak U and V directly. We want to do things like up the redness a little, so we have to act in RGB space.

But fear not, I have some ideas to make the scheme work. I want to do some experiments before describing them, because they could be stupid and I don't want to :oops: myself. But let's see.
User avatar
Rocky
Posts: 3631
Joined: Fri Sep 06, 2019 12:57 pm

CUDASynth

Post by Rocky »

Hehe, good day at the office. I discovered that it wasn't the RGB clipping that caused the horrible result. It was a widdle oversight in my code. Now the concept of YUV->RGB->apply curves->YUV is working great. So it's onward and upward! Still need to implement:

* specification of matrix 601/709/2020 [DONE]
* 16-bit support [DONE]
* allow drawing of master (Y), r, g, or b curves [DONE]
* presets
* frame ranges
* port to CUDASynth framework

Sherman has been busy on his radios. He just finished a nice Zenith H723Z2 AM/FM radio. It gets MeTV FM real good so mission accomplished. A Zenith X337 AM/FM is arriving shortly. That is the last manufactured Zenith tube AM/FM radio. And BTW, Zenith was headquartered right here in Chi-town. We already have a wooden and a bakelite AM/FM. The X337 is wooden but with a plastic front, call it a hybrid. It's supposed to have audio on a par with the big German sets. We'll see.
User avatar
hydra3333
Posts: 408
Joined: Wed Oct 06, 2010 3:34 am
Contact:

CUDASynth

Post by hydra3333 »

Nice job, on both fronts.
Thank you very much.
I really do like it here.
User avatar
Rocky
Posts: 3631
Joined: Fri Sep 06, 2019 12:57 pm

CUDASynth

Post by Rocky »

OK, matrices, 16-bit, and drawing are done. I'll probably do the CUDASynth stuff before presets and frame ranges.

But first, I have noticed that GIMP's curve drawing is not just a simple cubic/hermite spline. It's some kind of tensioned piecewise linear thing. I could check the source code but I found something interesting called Chaikin's algorithm:

https://www.cs.unc.edu/~dm/UNC/COMP258/ ... orithm.pdf

I'm going to implement that, but instead of the 25/75% locations I'll use 10/90% to stay closer to the polyline. Probably 2 or 3 iterations will be enough. I don't like the typical splines because they can deviate too much from the polyline defined by the configured points. Splines can be unstable/unpredictable in some cases, too. This approach will be pretty close to what GIMP does, so the GIMP GUI will be useful for setting up curves for our filter.

Technical note: Chaikin's algorithm with the 25/75% positions is equivalent to a quadratic uniform B-spline curve when the number of iterations is large. We'll use 10/90% to cling to the polyline a little tighter. We don't mind linear segments because it's only the vertices that can cause banding. But we eliminate that by smoothing out the vertices.

https://www.cs.unc.edu/~dm/UNC/COMP258/ ... nement.pdf
User avatar
Rocky
Posts: 3631
Joined: Fri Sep 06, 2019 12:57 pm

CUDASynth

Post by Rocky »

I added a mode "slinear" that does Chaikin 10/90% with 2 iterations and it looks great, if I do say so myself. ;)

So we have linear, slinear, cubic, and hermite. Maybe for fun I'll see what GIMP is doing.

EDIT: GIMP uses a cubic bezier. The code is complex so currently I don't see the need to match that precisely.

https://blog.maximeheckel.com/posts/cub ... to-motion/
User avatar
Rocky
Posts: 3631
Joined: Fri Sep 06, 2019 12:57 pm

CUDASynth

Post by Rocky »

I've started CUDA-izing it.

But right now it's time-out for the final round of the chess world championship candidates tournament. It's gonna be either the Indian Gukesh, the Russian Nepomniatchi, or one of the Americans Nakamura or Caruana. I'll go out on a limb (not really so risky for a squirrel!) and predict that Gukesh wins it.
User avatar
Rocky
Posts: 3631
Joined: Fri Sep 06, 2019 12:57 pm

CUDASynth

Post by Rocky »

Congrats to Gukesh! India versus China will be an epic encounter.
User avatar
Rocky
Posts: 3631
Joined: Fri Sep 06, 2019 12:57 pm

CUDASynth

Post by Rocky »

Sorry guys, I'm kinda fixated on getting the Curves filter done. Don't worry, I'll get to the other stuff in good time.

So, OK, I have the framework done (JIT, upload tables to GPU, etc.) and luma working in CUDA. I have to implement chroma and Vapoursynth. It's going to be blazingly fast compared to (say) Vapoursynth-Curve, especially for UHD. When that's done I'll make a test release and then we move on to automaticity, presets, and frame ranges.

Also, I've been helping Sherman with his Zenith X337 radio. He's doing electrical and I'm doing cosmetics.
User avatar
Rocky
Posts: 3631
Joined: Fri Sep 06, 2019 12:57 pm

CUDASynth

Post by Rocky »

Chroma is working. On to Vapoursynth.
User avatar
Sherman
Posts: 580
Joined: Mon Jan 06, 2020 10:19 pm

CUDASynth

Post by Sherman »

Sorry, Rocky, I tried to hand rub it but it's been very cold and humid so it wasn't ready for that. What now?
Sherman Peabody
Director of Linux Development
User avatar
Rocky
Posts: 3631
Joined: Fri Sep 06, 2019 12:57 pm

CUDASynth

Post by Rocky »

Just leave it alone for 72 hours. Then we'll hit it with some 0000 steel wool and put on a second light coat of poly. After that, DO NOT TOUCH it for a whole week. Then some furniture wax and buffing. I like that pecan stain. Great job on the electrical. It sounds amazing.
User avatar
Sherman
Posts: 580
Joined: Mon Jan 06, 2020 10:19 pm

CUDASynth

Post by Sherman »

Thanks, Rocky, you're the squirrel!
Sherman Peabody
Director of Linux Development
Post Reply