Log in

View Full Version : Updated aWarpSharp version, with some new features


Pages : [1] 2 3 4

jpsdr
24th November 2017, 12:54
I've updated the aWarpSharp plugin, adding :
- New parameters for better tuning.
- Internal multi-threading.

This version works on all avs+ version, and on all 2.6.x versions.

Current version : 2.1.12

Sources are here (https://github.com/jpsdr/aWarpSharpMT).
Binaries are here (https://github.com/jpsdr/aWarpSharpMT/releases/download/2.1.12/aWarpSharpMT_v2_1_12.7z).

Version history
2.1.12 : Minor changes (more code refactory).
2.1.9 : Update to new AVS+ headers and fix awarp colorspace issue.
2.1.8 : Update to new AVS+ headers.
2.1.7 : Update on threadpool, no user limit (except memory).
2.1.6 : Fix on threadpool, using prefetch parameter created hang. Add negative prefetch for triming, read Multithreading.txt or Multithreading chapter here.
2.1.5 : Fix aSobel crash, fix on threadpool.
2.1.4 : Fix aWarp4 issues, update to new avisynth headers.
2.1.3 : Fix aWarp issue on 16 bits, update to new avisynth headers.
2.1.2 : Minor code change after threadpool update, fix in the number of threads.
2.1.0 : Update of the threadpool, add ThreadLevel parameter.
2.0.1 : Optimized CPU placement if SetAffinity=true for prefetch>1, SetAffinity back to default false.
2.0.0 : Add 16 bits support (thanks for pinterf's help), filter is MT_NICE.
1.0.4 : Fix aWarp/aWarp4 default settings.
1.0.3 : Fix (for good... :sly:) bug in aBlur x64 asm.
1.0.2 : Fix bug in aBlur x64 asm code, aWarp4 don't copy planes on some chroma modes (doc updated).
1.0.1 : Fix depthVC default value, fix depthC on aWarpSharp (thanks real.finder).
1.0.0 : First release.

==================================================================

The functions inside this plugin are :

aWarpSharp2(int thresh,int blur,int type,int depth,int chroma,int depthC,string "cplace",
int blurV,int depthV,int depthVC,int blurC,int blurVC,int threshC,
int threads,bool logicalCores,bool MaxPhysCore,bool SetAffinity,bool sleep,int prefetch,int ThreadLevel)

aSobel(int thresh,int chroma,int threshC,
int threads,bool logicalCores,bool MaxPhysCore,bool SetAffinity,bool sleep,int prefetch,int ThreadLevel)

aBlur(int blur,int type,int chroma,int blurV,int blurC,int blurVC,
int threads,bool logicalCores,bool MaxPhysCore,bool SetAffinity,bool sleep,int prefetch,int ThreadLevel)

aWarp(edge_mask_clip,int depth,int chroma,int depthC,string "cplace",int depthV,int depthVC,
int threads,bool logicalCores,bool MaxPhysCore,bool SetAffinity,bool sleep,int prefetch,int ThreadLevel)

aWarp4(edge_mask_clip,int depth,int chroma,int depthC,string "cplace",int depthV,int depthVC,
int threads,bool logicalCores,bool MaxPhysCore,bool SetAffinity,bool sleep,int prefetch,int ThreadLevel)


Parameters are exactly the same than the orignal aWarpSharp functions, and in the same order, so they are totaly
backward compatible.

Check the TXT file for a more complete description.
The new parameters are added at the end of all the parameters. They have been added to allow more tuning for processing, allowing separate values for horizontal and vertical, and different value for Y/C when not avaible originaly. The parameters are the following:

threshC: default thresh. Set the limit for edge detection on chroma planes.

blurV: Default blur. If blurV is different from blur, horizontal process will be
done only on blur passes, and vertical process will be done only on blurV passes.

blurC : Number of blur passes for the chroma, default (blur+1)/2 passes.

blurVC: Default blurC. If blurVC is different from blurC, horizontal process will be
done only on blurC passes, and vertical process will be done only on blurVC passes.

depthV: default depth. depth set the warping strength for horizontal, and depthV
set de warping strenght for vertical.

depthVC: default depthC. depthC set the warping strength for horizontal, and depthVC
set de warping strenght for vertical.

threads -

Controls how many threads will be used for processing. If set to 0, threads will
be set equal to the number of detected logical or physical cores,according logicalCores parameter.

Default: 0 (int)

logicalCores -

If threads is set to 0, it will specify if the number of threads will be the number
of logical CPU (true) or the number of physical cores (false). If your processor doesn't
have hyper-threading or threads<>0, this parameter has no effect.

Default: true (bool)

MaxPhysCore -

If true, the threads repartition will use the maximum of physical cores possible. If your
processor doesn't have hyper-threading or the SetAffinity parameter is set to false,
this parameter has no effect.

Default: true (bool)

SetAffinity -

If this parameter is set to true, the pool of threads will set each thread to a specific core,
according MaxPhysCore parameter. If set to false, it's leaved to the OS.

Default: true (bool)

sleep -
If this parameter is set to true, once the filter has finished one frame, the threads of the
threadpool will be suspended (instead of still running but waiting an event), and resume when
the next frame will be processed. If set to false, the threads of the threadpool are always
running and waiting for a start event even between frames.

Default: false (bool)

prefetch -
This parameter will allow to create more than one threadpool, to avoid mutual resources acces
lock/wait if "prefetch" is used in the avs script.
0 : Will set automaticaly to the prefetch value use in the script. Well... that's what i wanted
to do, but for now it's not possible for me to get this information when i need it, so, for
now, 0 will result in 1. For now, if you're using "prefetch" in your script, put the same
value on this parameter.

ThreadLevel -
This parameter will set the priority level of the threads created for the processing (internal
multithreading). No effect if threads=1.
1 : Idle level.
2 : Lowest level.
3 : Below level.
4 : Normal level.
5 : Above level.
6 : Highest level.
7 : Time critical level (WARNING !!! use this level at your own risk)

Default : 6

The logicalCores, MaxPhysCore, SetAffinity and sleep are parameters to specify how the pool of thread will be created and handled, allowing if necessary each people to tune according his configuration.

==================================================================

Multi-threading information

CPU example case : 4 cores with hyper-threading.

If you leave all the multi-threading parameters to their default value, it's set to be "optimal" when you're not using prefetch or if you are under standard avisynth, all the logical CPU will be used.
If you put SetAffinity to true it will allocate the threads on the CPU contiguously. Physical CPU 1 will have threads (0,1), ... physical CPU 4 will have threads (6,7), allowing optimal cache use. Make test to see what's best for you.

Now, if you are using prefetch on your script, things are different !
If you're using it with the max number of CPUs (8 in our exemple case), you still can make tests, but i would strongly advise to disable the internal multi-threading by using threads=1. In this case, there is no threadpool created, and all the other multi-threading related filter parameters have no effect, even prefetch.
If you're using prefetch on your script, with less than your CPU number, you may want to try to mix the external and internal mutli-threading, setting the internal multi-threading to a lower number of threads, and setting the prefetch parameter of the filter. This parameter will set the number of internal threadpool created, the best is to match the prefetch script value. If you don't set it (leave it to 1) or set a lower value than prefetch on your script, you'll have several instances (or GetFrame) created, but they'll not be running efficiently, because each instance (or GetFrame) will spend time waiting for a threadpool to be avaible, if not enough were created.
Unfortunately, as things are now, i have no way of knowing the prefetch value used in the avisynth script at the time i need the information, this is why you have to use the prefetch parameter in the filter.
In our CPU exemple case, you can have things like :

filter(...,threads=1)
prefetch(8)

or

filter(...,threads=2,prefetch=4)
prefetch(4)

or

filter(...,threads=4,prefetch=2)
prefetch(2)

or even

filter(...,threads=3,prefetch=4)
prefetch(4)

if you want to boost and go a little over your total CPU number.

Also, if your prefetch is not higher than your number of physical cores, you can try to put SetAffinity to true, but in that case, you have to set MaxPhysCore to false. The threads of each pool will be set on CPUs by steps.
For exemple, in our case :

filter(...,threads=2,prefetch=4,SetAffinity=true,MaxPhysCore=false)
prefetch(4)

Will create 4 pool of 2 threads, with the following :
pool[0] : threads(0 -> 1) on CPU 1.
pool[1] : threads(0 -> 1) on CPU 2.
pool[2] : threads(0 -> 1) on CPU 3.
pool[3] : threads(0 -> 1) on CPU 4.

filter(...,threads=4,prefetch=2,SetAffinity=true,MaxPhysCore=false)
prefetch(2)
Will create 2 pool of 4 threads, with the following :
pool[0] : threads(0 -> 1) on CPU 1.
pool[0] : threads(2 -> 3) on CPU 2.
pool[1] : threads(0 -> 1) on CPU 3.
pool[1] : threads(2 -> 3) on CPU 4.

Negative prefetch
The possibility to put negative prefecth to tune the prefetch parameter to optimal value has been added. The filter will throw an error if the number is not high enough to avoid waiting when requesting internal threadpool. For this to work properly, you have to put negative prefetch on ALL the filters of your script, and also ALL instances of the same filter.

Exemple :
filter(...,threads=2,prefetch=-2)
prefetch(2)
You'll see an error.

But with :
filter(...,threads=2,prefetch=-3)
prefetch(2)

You'll see no error, so the optimal is :
filter(...,threads=2,prefetch=3)
prefetch(2)

Once you've tune, put back a positive value.

real.finder
24th November 2017, 17:43
finally :thanks:

now this filter is very useful, even ablur can be used alone for Dot Crawl Removal, I did used in DDComb

and if you can added the others blur type (https://forum.doom9.org/showthread.php?p=1820161#post1820161) that was in original awarpsharp by Marc FD it will be more useful, aside form HBD in avs+

jpsdr
24th November 2017, 18:33
I don't know what they are, i need first the original code source. Where can i find it ?

real.finder
24th November 2017, 18:46
I don't know what they are, i need first the original code source. Where can i find it ?

you can ask prunedtree in IRC (rizon server) :rolleyes: same person that you asked about Debilinear

jpsdr
25th November 2017, 09:24
Yes, and you've already told me this... i just don't remember on what channel i can found him...:p

real.finder
25th November 2017, 15:59
Yes, and you've already told me this... i just don't remember on what channel i can found him...:p

in #darkhold and maybe others

jpsdr
26th November 2017, 12:05
Yes... Right, now i remember indeed... I'll try to get in touch with him.

Motenai Yoda
26th November 2017, 17:34
can you fix the awarp4 chroma bug?

real.finder
26th November 2017, 18:01
can you fix the awarp4 chroma bug?

what bug?

ryrynz
27th November 2017, 10:23
Does this now supersede Pinterf's version? ..Nevermind, readme clarified. :)

"Addition by pinterf on 20160623:
- AviSynth 2.6 interface, Avisynth+ header
- working x64 version
- minor cleanup"

jpsdr
27th November 2017, 10:31
now this filter is very useful, even ablur can be used alone for Dot Crawl Removal, I did used in DDComb


Isn't a threshold median filter more appropriate for this ? (If "Dot Crawl" is what i think, sometimes i'm not sure of the exact english technical version).

real.finder
27th November 2017, 14:44
Isn't a threshold median filter more appropriate for this ? (If "Dot Crawl" is what i think, sometimes i'm not sure of the exact english technical version).

median not work well with Dot Crawl (https://en.wikipedia.org/wiki/Dot_crawl) and it's slower

jpsdr
27th November 2017, 15:12
Ok, it wasn't what i thought, "dot" mislead me, so no surprise median is not adapted. Hard to remove, as it should have been done properly "before" either when demodulating chroma, or even more when creating the CVBS signal... :(

Motenai Yoda
27th November 2017, 22:52
what bug?

chroma values 2 5 6 are bugged as it doesn't scale back chroma/luma channels
maybe it can take them from last

real.finder
28th November 2017, 04:38
chroma values 2 5 6 are bugged as it doesn't scale back chroma/luma channels
maybe it can take them from last

yes, there are bug in chroma=6 or 5 or 2


ColorBars(pixel_type="yv12")
aWarp4(nnedi3_rpow2(rfactor=2).nnedi3_rpow2(rfactor=2), aSobel().aBlur(), depth=2,chroma=6)

jpsdr
28th November 2017, 09:37
Is it a bug i've introduced or was it also on the original ?

jpsdr
28th November 2017, 09:55
About original blur mode, i don't realy see the point as they are very similar from what i've understood taking a quick look. The hq mode is just the same of the R2, with just a little more accurate result, less rounding propagate errors. I'll explain. The actual version (both R2 and R6) uses pavgb function, wich compute the average of 8 bits data with the following formula : pavgb(A,B) = (A+B+1)>>1.
If you want to compute (A+2*B+C)/4 you can do the following :
A=pavgb(A,C)
result=pavgb(A,B)
But, you cumulate 2 successive pavgb and so rounding errors.
You can also do the followig :
Expand A,B,C on 16 bits, and compute (on 16bits) result=(A+2*B+C+2)>>2 and convert back to 8 bits.
This way, you have a little more accurate result.
Honestly don't see real interest of puting back the old hq blur mode, and as for the others, they are already implemented with the actual R2 and R6.

real.finder
28th November 2017, 18:20
Is it a bug i've introduced or was it also on the original ?

in original awarpsharp2 by SEt

About original blur mode, i don't realy see the point as they are very similar from what i've understood taking a quick look. The hq mode is just the same of the R2, with just a little more accurate result, less rounding propagate errors. I'll explain. The actual version (both R2 and R6) uses pavgb function, wich compute the average of 8 bits data with the following formula : pavgb(A,B) = (A+B+1)>>1.
If you want to compute (A+2*B+C)/4 you can do the following :
A=pavgb(A,C)
result=pavgb(A,B)
But, you cumulate 2 successive pavgb and so rounding errors.
You can also do the followig :
Expand A,B,C on 16 bits, and compute (on 16bits) result=(A+2*B+C+2)>>2 and convert back to 8 bits.
This way, you have a little more accurate result.
Honestly don't see real interest of puting back the old hq blur mode, and as for the others, they are already implemented with the actual R2 and R6.

there are big difference and superiority in original awarpsharp versus the new awarpsharp2

see here (https://forum.doom9.org/showthread.php?p=1687315#post1687315) and here (https://forum.doom9.org/showthread.php?p=1819947#post1819947)

and the hq is not only one, there are others (fast 1-pass is the default)

jpsdr
28th November 2017, 20:18
When i look at the code, the "fast 1-pass" is the actuel R6 with one pass...

real.finder
28th November 2017, 21:15
When i look at the code, the "fast 1-pass" is the actuel R6 with one pass...

why there are some notable difference then? bug in compatibility mapping for aWarpSharp parameters (http://avisynth.nl/index.php/AWarpsharp2/aWarpSharp)? and there are already one here (https://github.com/pinterf/aWarpSharp/issues/1)

ryrynz
28th November 2017, 21:17
Did anyone manage to get in touch with MarcFD for his original code if it's that much better? real.finder can you post screenshots for comparison?

real.finder
28th November 2017, 21:32
here we are

no filter
https://s18.postimg.cc/db14azh09/image.png

awarpsharp in awarpsharp2
https://s18.postimg.cc/bvzjme5o9/awarpsharp_in_awarpsharp2.png

awarpsharp in old awarpsharp
https://s18.postimg.cc/ai7wqjgjd/awarpsharp_in_old_awarpsharp.png

and according to SEt it should be same https://forum.doom9.org/showthread.php?p=1687695#post1687695

ryrynz
28th November 2017, 22:05
Thanks, I'm gonna have to go with awarp2 in this example, I can see the original awarp is a big sharper and thinner in some areas but awarp2 is sharper in some areas also.
The original awarp blows out the reds, Misato's shirt is worse (most noticeable around the arms) awarp2 is almost identical in appearance to the original frame as it should be.. you said chroma is better but that's simply not the case here.

real.finder
28th November 2017, 22:12
I'm gonna have to go with awarp2 in this example, I can see the original awarp is a big sharper and thinner in some areas but awarp2 is sharper in some areas also.
The original awarp blows out the reds, Misato's shirt is worse, awarp2 is almost identical in appearance to the original frame as it should be.. you said chroma is better but that's simply not the case here.

the original awarp is more clean and accurate, it not blows out the reds, it's just did the job with warp chroma to luma (Default behavior)

and aside from all that, awarpsharp2 has awarpsharp() for compatibility with old awarpsharp, it should be same (or at least with unnoticeable difference) regardless of whether they are better or worse

ryrynz
28th November 2017, 22:19
How is it accurate when it differs so much from the original frame? The reds are brighter than in the original frame and they shouldn't be. There's no win here for the original awarp.

real.finder
28th November 2017, 22:26
How is it accurate when it differs so much from the original frame? The reds are brighter than in the original frame and they shouldn't be. There's no win here for the original awarp.

not something unexpected here cuz it warp chroma with luma as I said

aside from chroma, you can see how it accurate without artifacts in the yellow text for example

ryrynz
28th November 2017, 22:38
The warping has stretched the very left side of the text but in other areas in the overlay it's more like the original frame, plus the overlay's appearance doesn't appear to match the effect on the lines in the actual
frame which is the more important part to be analyzing. I guess like anything awarpsharp2 could use a tweak or two but I'm still not seeing the original being more pleasing to me.

jpsdr, are you planning on tweaking this at all?

real.finder
28th November 2017, 23:11
so here another one that prove that old awarpsharp is better

https://s18.postimg.cc/rucuq99uh/warp2.png

https://s18.postimg.cc/u075k8xq1/old_warp.png (ignore the left line bug, it's know things since age and one reason that awarpsharp2 existing)

ColorBars(pixel_type="yv12")
info
aWarpSharp_aWarpSharp

ryrynz
29th November 2017, 01:47
Surely changing the depth parameter in awarp2 could provide a similar output?

real.finder
29th November 2017, 02:51
Surely changing the depth parameter in awarp2 could provide a similar output?

don't think so, the warp depth is same in both, I highly suspect the blur, maybe something else like aSobel but not the warp depth

real.finder
29th November 2017, 04:05
well, the chorma seems to have some bug in awarpsharp() in awarpsharp2, it's like using depthc=0, it should be depthc=depth/2 for 420, so:-

aWarp(aSobel(128).aBlur(2,0), depth=16,chroma=4, depthc=8)

this is the most close to original awarpsharp

but this made me learn something new, and it's I can use depthc=0 for chroma guide by luma :) I was think that depth=0 result will be always like unprocessed clip

edit1: well, no, it's not the same in Pinterf and older ver., as they seems to unwarp chroma if it guide by luma and depthc=0, awarpsharpmt is just use depth/2 for the depthVC (8 in this case)
SEt ver. (2012) work fine with the awarpshrp() in the awarpsharp2 dll, so the bug happened in 2015 one

edit2: also this lead us to another bug in the awarpsharpmt, and it's that depthVC default is not depthC as it should

aside form all thing, there are still there are some difference in both luma and chroma... not big but it's there

ryrynz
29th November 2017, 06:21
jpsdr, I can't for the life of me get awarp4 to work. If I just call awarpsharp() by itself it works fine.
No problems with Pinterf's version. Tried all versions, just get it crashing, plugin pack also crashes.

Ryzen on W10CU.

input4x = last.Spline64Resize(width*4, height*4, src_left=0.375, src_top=0.375)
edgemask = last.aSobel.ablur
aWarp4(input4x,edgemask,depth=2)

jpsdr
29th November 2017, 09:58
Did anyone manage to get in touch with MarcFD for his original code if it's that much better?
I've contacted him, and asked for the code, as i was asked to add the others blur modes.
I thought he would provide me the whole code, but he gave me only the blur part code. I've not asked him more, assuming he probably didn't want to give me the whole code...

ryrynz
29th November 2017, 10:01
Got nothing to lose, you might as well ask.

jpsdr
29th November 2017, 10:08
edit1: well, no, it's not the same in Pinterf and older ver., as they seems to unwarp chroma if it guide by luma and depthc=0, awarpsharpmt is just use depth/2 for the depthVC (8 in this case)
SEt ver. (2012) work fine with the awarpshrp() in the awarpsharp2 dll, so the bug happened in 2015 one

edit2: also this lead us to another bug in the awarpsharpmt, and it's that depthVC default is not depthC as it should

Oups... I thought i've fixed it, but depthCV is depthV as default instead of depth indeed...:( I'll fix it in a next release.
About edit1 : Do you meen the SEt version awarpsharp() is realy identical to original, but the versions afterward not anymore ?

jpsdr
29th November 2017, 10:12
jpsdr, I can't for the life of me get awarp4 to work

This code works for me. Does it for you ?

SetMemoryMax(64)
a=AVISource("Test.avi",False,"YV12").SetPlanarLegacyAlignment(True)
d=aSobel(a)
aWarp4(a.Spline36Resize(4*a.width,4*a.height),d)


Edit
Just tested this :

SetMemoryMax(64)
AVISource("Test.avi",False,"YV12").SetPlanarLegacyAlignment(True)
input4x = last.Spline64Resize(width*4, height*4, src_left=0.375, src_top=0.375)
edgemask = last.aSobel.ablur
aWarp4(input4x,edgemask,depth=2)

It works for me.

ryrynz
29th November 2017, 10:29
Tried the above but using ffdshow_source() and it crashes, it doesn't matter what MT mode I try whether I specify setmemorymax or not.
Tried W7 and XP releases for compatibility, I have the latest runtimes installed.

jpsdr
29th November 2017, 10:43
Ah... As i never use MT mode, i never thought of testing them... But strange, filters should report themselves as MT_MULTI_INSTANCE.
But if you use external multi-threading, in that case, maybe you should try adding threads=1 in the parameters.

ryrynz
29th November 2017, 11:07
Tried threads=1 on asobel, ablur and awarp4 with no success along with setting prefetch value accordingly.

jpsdr
29th November 2017, 11:52
Sorry... For now, no idea in that case. If you use AVISource and not ffdshow_source, does it crash ? Unfortunately, even if this is the issue, i would have no idea of the why...

real.finder
29th November 2017, 14:56
Oups... I thought i've fixed it, but depthCV is depthV as default instead of depth indeed...:( I'll fix it in a next release.
About edit1 : Do you meen the SEt version awarpsharp() is realy identical to original, but the versions afterward not anymore ?

SEt versions give output like aWarp(aSobel(128).aBlur(2,0), depth=16,chroma=4, depthc=8) the difference to versions afterward in chroma only (in 2015 when depthc added, in awarpsharp() seems it's always use depthc=0)

the luma (and chroma but luma is noted easly) small difference in all awarpsharp2 versions come from something else (blur maybe as I suspect)

jpsdr
29th November 2017, 16:37
If i understand properly, for now, what's trouble you more, is some chroma issue present in mine and pinterf version, but not in aWarpSharp_20120328 SEt version. Is that correct ?

real.finder
29th November 2017, 18:19
If i understand properly, for now, what's trouble you more, is some chroma issue present in mine and pinterf version, but not in aWarpSharp_20120328 SEt version. Is that correct ?

and in 2015 by cretindesalpes too

yes, it trouble more, and it should very easy to fix

jpsdr
29th November 2017, 20:20
Ok, at least it means :
- It's not me who introduced it.
- Checking the actual code vs the aWarpSharp_20120328 SEt version code, i should be able to find something.

TheFluff
29th November 2017, 21:04
you know, there is a vs port of this, with all the nice things already done, like all the asm rewritten to templated intrinsics, and it also supports high bitdepth
the entire thing is less lines of code than your x64 .asm file
so, to ask the question that needs to be asked, why on earth did you choose to base your version on the old garbage

jpsdr
30th November 2017, 09:44
Because... ;)

Maybe this will be done on a second time step, but for now, it's easier for me with this code to compare and check differences when i'm asked to "look like more the original version".

jpsdr
30th November 2017, 09:51
Tried all versions, just get it crashing, plugin pack also crashes.


Forgot to ask, just in case : On both x86 and x64 version ?

edcrfv94
30th November 2017, 11:20
so here another one that prove that old awarpsharp is better

https://s18.postimg.org/rucuq99uh/warp2.png

https://s18.postimg.org/u075k8xq1/old_warp.png (ignore the left line bug, it's know things since age and one reason that awarpsharp2 existing)

ColorBars(pixel_type="yv12")
info
aWarpSharp_aWarpSharp

Maybe you can try warpsharp is very good for animation.

ryrynz
30th November 2017, 13:16
Forgot to ask, just in case : On both x86 and x64 version ?

Haven't tried x86 version, if you really want me to test it I guess I could, I suspect it'll still not work. I think your internal multi-threading isn't entirely stable ^.^

jpsdr
30th November 2017, 13:53
Haven't tried x86 version, if you really want me to test it I guess I could
If you can test it, i would appreciate, to be sure. If threads=1 is not working, it's not the multi-threading, because in that case it's absolutely not used, that's why i've also asked you to make this test.