View Full Version : ViewFields2.5: BitBlt vs memcpy: Which is better?
scmccarthy
10th January 2003, 02:38
Since recompiling ViewFields for AviSynth 2.5 is so easy, the more interesting question is my substituting BitBlt for memcpy will improve speed.
This thread has the other purpose of asking Simon Walters if I can offer AviSynth 2.5 versions of his filters. This is the only way I can reach him. Simon and I share a preference for the c programming language, so his filters are the easiest for me to deal with.
There are three versions of ViewFields and UnViewFields. One that simpy recompiles the original, then substituting BitBlt for memcpy, and then making it work in the YV12 color space. I like ViewFields because I think it works faster than chaining SeparateFields and StackFrames together. UnViewFields() is untested; the two are so similiar that if one works so does the other.
I include my ConvertYV12ToYUY2() filter to make it easier to test the YUY2 versions of ViewFields(). I prefer my filter because it has a smaller, sharper chroma interpolating filter. All these filters are simple and fast enough not to need assembler optimizations.
cdll.bat reveals what kind of programming development environment I am using. My primary defense is that it is free!
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore98/html/_core_linker_reference.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore98/html/_core_linker_reference.asp
The above links are to the compiler and linker options reference at MSDN respectively.
Let me explain chroma interpolation one more time?
nevermind, it is too long
I chose a kernel that is close to the powers of three, but adds up to a power of 2:
(*128): 4, 28, 84, 12
4x3=12;28x3=84. It is based on a weighted average theory and does not try to smooth at all, only making sure that the chroma is sited properly. Subjectively, it looks better to me for being sharper.
As far as I know, AviSynth still always assumes framebased. ConvertYV12ToYUY2_fieldbased() has both framebased and fieldbased interpolation code in it using all different kernels than the one above, but it always assumes fieldbased because of the following:
ConvertYV12ToYUY2(PClip _child) : GenericVideoFilter(_child) {
vi.pixel_type = VideoInfo::CS_YUY2;
vi.image_type = VideoInfo::IT_FIELDBASED;
child->SetCacheHints(CACHE_NOTHING,0);
}
Commenting out the vi.image_type line would turn it into a framebased filter using the classic (*256): 3, -16, 67, 227, -32, 7 kernel. Well, then you can precede it with the AssumeFieldBased() filter in the script to get it back to its fieldbased code.
I should put this into a help file, shouldn't I?
My guess is that BitBlt is faster than memcpy, no? I want that to be the central point of this thread. At least don't miss it for everything else.
Stephen
scmccarthy
10th January 2003, 08:21
I thought about it and realized that ViewFieldsYV12 would only work properly on true interlaced frames. Also ConvertYV12ToYUY2 should not be used after ViewFieldsYV12 unless it is an interlaced frame. I included it in order to use the other versions of ViewFields.
Stephen
Si
10th January 2003, 09:12
Stephen - I replied to the PM you sent me - you obviously didn't get it :(
No problem in recompiling/improving any of my filters -I'm just waiting for Avisynth 2.5 to get to beta before trying out any re-compiling for YV12.
And my filters will never be fast because I've never found an idiots guide to assembler/MMX just using MS VC++.
regards
Simon
PS Could I have a copy of your source please?
sh0dan
10th January 2003, 09:50
* ImageType.
Use vi.SetFieldBased(true/false) to set the image type - much easier, and cleaner code.
* BitBlt vs. memcpy. When dealing with more than one line BitBlt is always faster. When copying a single line this may not always be true. (Depends on whether you read from the line shortly after - if you do, memcpy will be faster).
I honestly don't understand much of the rest of the post :confused:
scmccarthy
10th January 2003, 16:13
@siwalters
No problem in recompiling/improving any of my filters -I'm just waiting for Avisynth 2.5 to get to beta before trying out any re-compiling for YV12.
I think of it as beta now, especially with the AvisynthPluginInit2 out of the way. Initially, definitely alpha, but by December it felt like beta to me. Don't get me wrong, I know officially it is still alpha and sh0dan still has the freedom to experiment with it if he has to.
There is supposed to me an attachment with my post, but here is a software only version of that:
@sh0dan
I honestly don't understand much of the rest of the post
Well, I know I need to make my posts a lot shorter and to the point.
That is why I ended on the point I wanted you to respond to. To me the following two lines are parallel and must be equally valid:
vi.pixel_type = VideoInfo::CS_YUY2;
vi.image_type = VideoInfo::IT_FIELDBASED;
You use the first in the internal conversion filters. I figured out how to use the image_type enum just by studying avisynth.h If SetFieldBased(true) is really better, maybe we need a SetColorSpace(YUY2) filter as well?
Stephen
sh0dan
10th January 2003, 16:35
Originally posted by scmccarthy
@siwalters
I think of it as beta now, especially with the AvisynthPluginInit2 out of the way. Initially, definitely alpha, but by December it felt like beta to me. Don't get me wrong, I know officially it is still alpha and sh0dan still has the freedom to experiment with it if he has to.
The only this missing is for me to personally make an official beta is:
* Cache implementation - Bidoche seems to be working on it, but it doesn't compile yet - waiting for an activated version that tests out to work.
* Confirmation that the most important filters are using AvisynthPluginInit2.
2.5 seems as stable as 2.0 by now, and the interface is not going to change.
You use the first in the internal conversion filters. I figured out how to use the image_type enum just by studying avisynth.h If SetFieldBased(true) is really better, maybe we need a SetColorSpace(YUY2) filter as well?
It's for easier future compatibility - and making the code more readable. No technical reasons, however.
Where did you find this - I thought I had removed all direct references. source.cpp and convert.cpp doesn't contain any...? Could you point me to it?
trbarry
10th January 2003, 16:48
Use vi.SetFieldBased(true/false) to set the image type - much easier, and cleaner code.
I didn't know about this one. Is this (vi.SetFieldBased(false)) what we should be doing after deinterlacing/IVTC to tell subsequent Avisynth color conversions to treat it as progressive?
- Tom
sh0dan
10th January 2003, 16:50
Yes - it might help filters sensitive to this. (weave / converttoyuy2, etc).
trbarry
10th January 2003, 16:53
Shodan -
Thanks. I'd asked about this (for any function) a couple months ago and even had something else similar in TomsMoComp at first but removed it.
- Tom
Bidoche
10th January 2003, 16:55
My code doesn't compile ?
I thought I got it to work, but only the unit, since I still cannot build the whole dll :'(
Anyway, I have done only a simple implementation for now, I would like to make it able to serve multiple top filters by adding a 'client' parameter (with a default so it won't break the API) in GetFrame and SetCacheHints.
scmccarthy
10th January 2003, 17:01
@sh0dan
It's for easier future compatibility - and making the code more readable. No technical reasons, however.
ChromaShift12 uses vi.IsYUY2(), making it compile without modification(except the Init2). I suppose that makes it more compatible.
Where did you find this - I thought I had removed all direct references. source.cpp and convert.cpp doesn't contain any...? Could you point me to it?
The sources from October 28, 2002 is still the only one I can find. I still use it to give me pointers on how to write my own filters. The following is from convert.cpp:
ConvertToYV12::ConvertToYV12(PClip _child, IScriptEnvironment* env)
: GenericVideoFilter(_child)
{
if (vi.width & 4)
env->ThrowError("ConvertToYV12: image width must be multiple of 4");
if (vi.height & 4)
env->ThrowError("ConvertToYV12: image height must be multiple of 4");
vi.pixel_type = VideoInfo::CS_YV12;
}
Maybe you misupderstood me. I learned how to use image_type by paralleling it with how I use pixel_type in ConvertYV12ToYUY2_fieldbased.cpp.
This is my chance to suggest you put a newer version of the sources on the AviSynth 2.5 alpha download page.
Stephen
sh0dan
10th January 2003, 17:02
@Bidoche: Check PM. I guess the optional client it a nice solution, if it doesn't break anything. The filters that needs to be modified would also have to implement the setcachehints anyway.
When I use the code you put in I get a linker error - I mailed it to you through sourceforge.
How will the default cache behaviour be? Cache the last 'x' frames requested?
What's the problem comiling the code?
(Shouldn't we find the old "Implementing cache hints" thread again, and continue there?)
scmccarthy
11th January 2003, 17:20
@sh0dan
Where did you find this - I thought I had removed all direct references. source.cpp and convert.cpp doesn't contain any...? Could you point me to it?
I still want to know what you think of this.
You could be referring to two things; and I have two different answers depending on what you mean.
1) You mean that 'vi.pixel_type = VideoInfo::CS_YV12;' is no longer in the convert.cpp sources. If that were true, then it has been a long time since you have looked at the 281002 dated sources, so why continue to post it along with the newest dll and header on the AviSynth 2.5 alpha page? Why not zip up a newer version of the sources?
2) O.K., you don't mean the above, so you must be asking where vi.image_type is in convert.cpp. Well, it's not, I figured it out on my own as a parallel contruction of the way you use vi.pixel_type. In that case my comment it that referring directly to the image_type enum values must be as valid and safe as referring directly to pixel_type enum values. If that is more compatible, then why not create a method to set the colorspace that would also be compatible for future versions as well?
Acually, my true programming philosophy is never give me more than one way to do anything. SetFieldBased is just an alternate way of doing something I already know how to do.
Oops, I just noticed that vi.image_type is new since the avisynth_src_281002 sources. SetFieldBased used to use pixel_type:
if (isfieldbased) pixel_type|=CS_FIELDBASED;
else pixel_type&=~CS_FIELDBASED;
I use the newest avisynth header in lieu of a tutorial to give me pointers on how to make a filter. Anyway, I would switch, if the absence of SetColorSpace didn't suggest to me that SetFieldBased is also unnecessary.
Stephen
scmccarthy
11th January 2003, 17:23
@siwalters
I replied to the PM you sent me
What's a PM?
Have you tried to compile it? What do you think of the sources?
Stephen
neuron2
11th January 2003, 17:47
Originally posted by scmccarthy
What's a PM?LOL! :D
[Private Message]
Si
12th January 2003, 00:46
@scmccarthy
I haven't tried compiling them as since I'm just a programming camp follower, I'm waiting for the big boys to declare 2.5 beta before I join in the game :)
regards
Simon
scmccarthy
12th January 2003, 01:19
@siwalters
I started immediately in hopes that by the time the beta is released, I'd have some useful programming experience under my belt.
Stephen
scmccarthy
12th January 2003, 01:27
HAHA, sh0dan took the hint!
New version of the 2.5 sources are on the main AviSynth 2.5 alpha page!
Stephen
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.