Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

Domains: forum.doom9.org / forum.doom9.net / forum.doom9.se

 

Go Back   Doom9's Forum > Capturing and Editing Video > Avisynth Development

Reply
 
Thread Tools Search this Thread
Old 19th April 2005, 08:02   #1  |  Link
kassandro
Registered User
 
Join Date: May 2003
Location: Germany
Posts: 502
MakeWritable and hidden bitblts

Does env->MakeWritable(&df) trigger an internal bitblt, if the Avisynths cache is enabled and can this bitblt be avoided if child->SetCacheHints(CACHE_NOTHING, 0) is called in the filter contructor?
kassandro is offline   Reply With Quote
Old 19th April 2005, 15:34   #2  |  Link
esby
Registered User
 
esby's Avatar
 
Join Date: Oct 2001
Location: france
Posts: 521
src/core/avisynth.cpp
Code:
bool ScriptEnvironment::MakeWritable(PVideoFrame* pvf) {
  const PVideoFrame& vf = *pvf;
  // If the frame is already writable, do nothing.
  if (vf->IsWritable()) {
    return false;
  }

  // Otherwise, allocate a new frame (using NewVideoFrame) and
  // copy the data into it.  Then modify the passed PVideoFrame
  // to point to the new buffer.
    const int row_size = vf->GetRowSize();
    const int height = vf->GetHeight();
    PVideoFrame dst;
    if (vf->GetPitch(PLANAR_U)) {  // we have no videoinfo, so we can only assume that it is Planar
      dst = NewPlanarVideoFrame(row_size, height, FRAME_ALIGN,false);  // Always V first on internal images
    } else {
      dst = NewVideoFrame(row_size, height, FRAME_ALIGN);
    }
    BitBlt(dst->GetWritePtr(), dst->GetPitch(), vf->GetReadPtr(), vf->GetPitch(), row_size, height);
    // Blit More planes (pitch, rowsize and height should be 0, if none is present)
    BitBlt(dst->GetWritePtr(PLANAR_V), dst->GetPitch(PLANAR_V), vf->GetReadPtr(PLANAR_V), vf->GetPitch(PLANAR_V), vf->GetRowSi
ze(PLANAR_V), vf->GetHeight(PLANAR_V));
    BitBlt(dst->GetWritePtr(PLANAR_U), dst->GetPitch(PLANAR_U), vf->GetReadPtr(PLANAR_U), vf->GetPitch(PLANAR_U), vf->GetRowSi
ze(PLANAR_U), vf->GetHeight(PLANAR_U));

    *pvf = dst;
    return true;
}
So obviously a bitblt() is triggered, except if the frame is already writable, meaning it has been created and cached and/or reused.

But I guess that for what you are asking, the setCache() does not avoid to trigger any bitblt() code, as you still need to create a frame.

So what do you want to do exactly?

esby
__________________
http://esby.free.fr/
esby is offline   Reply With Quote
Old 24th April 2005, 18:04   #3  |  Link
kassandro
Registered User
 
Join Date: May 2003
Location: Germany
Posts: 502
Thanks for the (disappointing) information. I think that Avisynth could be smarter. If the cache is disabled with child->SetCacheHints(CACHE_NOTHING, 0), then it should be clear that the frame is not requested again. Thus there is no need to keep a copy in this case.
kassandro is offline   Reply With Quote
Old 24th April 2005, 18:12   #4  |  Link
sh0dan
Retired AviSynth Dev ;)
 
sh0dan's Avatar
 
Join Date: Nov 2001
Location: Dark Side of the Moon
Posts: 3,480
...but other filters may have the same input, thus requiering a writeable frame. Consider this script:

v=avisource()
a=yourfilter(v)
b=anotherfilter(v)

return overlay(a,b)

Both yourfilter() and antherfiler() will request the same frame from the source. If both make them writable a bitblit is inavoidable.
__________________
Regards, sh0dan // VoxPod
sh0dan is offline   Reply With Quote
Old 25th April 2005, 07:28   #5  |  Link
kassandro
Registered User
 
Join Date: May 2003
Location: Germany
Posts: 502
Quote:
Originally posted by sh0dan
...but other filters may have the same input, thus requiering a writeable frame. Consider this script:

v=avisource()
a=yourfilter(v)
b=anotherfilter(v)

return overlay(a,b)

Both yourfilter() and antherfiler() will request the same frame from the source. If both make them writable a bitblit is inavoidable.
Good argument. On the other hand, if "yourfilter" uses child->SetCacheHints(CACHE_RANGE, 1) and 1 is too tight for "anotherfilter", then we have the same problem: a frame has to be processed twice. Cache hints are bad, if frames are requested from more than one filter. The Avisynth script parser, could control this, but this would add unpleasant complexity. I would suggest the following: if a clip receives more than one cache hint, it should ignore all the cache hints and persue the default strategy "cache as much as you can" (or a smarter variant). As a consequence, any filter should issue cache hints to clips, which it wants to use. If a filter doesn't do this, it shouldn't wonder about poor performance. Then, if child->SetCacheHints(CACHE_NOTHING, 0) is the only cache hint, MakeWritable should not make bitblt. If there is a chain of such filters, then we could not only save bitblts, but even could keep the frame throughout the processing in the L2 cache, if it is large enough, say 1 or 2 MB.
kassandro is offline   Reply With Quote
Old 25th April 2005, 20:45   #6  |  Link
Bidoche
Avisynth 3.0 Developer
 
Join Date: Jan 2002
Location: France
Posts: 639
Quote:
Originally posted by kassandro
The Avisynth script parser, could control this, but this would add unpleasant complexity. I would suggest the following: if a clip receives more than one cache hint, it should ignore all the cache hints and persue the default strategy "cache as much as you can" (or a smarter variant).
I took that into account when designing 3.0 Cache : It use an adaptive heuristic, ie it detects missed cache opportunities to adapt cache size.
Bidoche is offline   Reply With Quote
Old 27th April 2005, 08:28   #7  |  Link
kassandro
Registered User
 
Join Date: May 2003
Location: Germany
Posts: 502
Quote:
Originally posted by Bidoche
I took that into account when designing 3.0 Cache : It use an adaptive heuristic, ie it detects missed cache opportunities to adapt cache size.
The adapative heuristic, is it adaptive enough, such that makewritable is without a bitblt, if a frame is requested only once?

Last edited by kassandro; 27th April 2005 at 09:10.
kassandro is offline   Reply With Quote
Old 27th April 2005, 23:51   #8  |  Link
Bidoche
Avisynth 3.0 Developer
 
Join Date: Jan 2002
Location: France
Posts: 639
Quote:
Originally posted by kassandro
The adaptive heuristic, is it adaptive enough, such that makewritable is without a bitblt, if a frame is requested only once?
All Caches start with caching nothing, and it only grows if the cache detects it is missing opportunities.

So in your case, cache sizes never grow, and MakeWritable will never blit.
(though there is no more MakeWritable, it is implicitly done for you)

Last edited by Bidoche; 28th April 2005 at 12:48.
Bidoche is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 19:43.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.