Login - Create Account
Bookmark and Share

Initialization problem

Login or Register to post new topics or replies
Sphinx.
Filter Optimizer

Posts: 1346
Filters: 38
I'm working on a filter with a rather heavy initialization section. In theory the initialization script part should execute one time (I'm testing with only CPU core), however I counted more than 60 executions :-S

Here is a dedicated test script that shows the problem (also attached, note it is unsafe due to the os.time() call):
Code

function prepare()
   do_initialize = true
   stamp = os.time()
   print("prepare ("..stamp..") ---------------------");
end;

function get_sample(x, y)
   if do_initialize then
      do_initialize = false
      print("initialize ("..stamp.."); x = " .. x ..", y = "..y);
   end
   return 0,0,0,0
end;


Here is the output (Filter Forge x86.log):

Code

prepare (1313930290) ---------------------
initialize (1313930290); x = 0,00083333333333333, y = 0,00083333333333333
initialize (1313930290); x = 0,12583333333333, y = 0,00083333333333333
initialize (1313930290); x = 0,25083333333333, y = 0,00083333333333333
initialize (1313930290); x = 0,37583333333333, y = 0,00083333333333333
initialize (1313930290); x = 0,50083333333333, y = 0,00083333333333333
initialize (1313930290); x = 0,62583333333333, y = 0,00083333333333333
initialize (1313930290); x = 0,75083333333333, y = 0,00083333333333333
initialize (1313930290); x = 0,87583333333333, y = 0,00083333333333333
initialize (1313930290); x = 0,00083333333333333, y = 0,12583333333333
initialize (1313930290); x = 0,12583333333333, y = 0,12583333333333
initialize (1313930290); x = 0,25083333333333, y = 0,12583333333333
initialize (1313930290); x = 0,37583333333333, y = 0,12583333333333
initialize (1313930290); x = 0,50083333333333, y = 0,12583333333333
initialize (1313930290); x = 0,62583333333333, y = 0,12583333333333
initialize (1313930290); x = 0,75083333333333, y = 0,12583333333333
initialize (1313930290); x = 0,87583333333333, y = 0,12583333333333
initialize (1313930290); x = 0,00083333333333333, y = 0,25083333333333
initialize (1313930290); x = 0,12583333333333, y = 0,25083333333333
initialize (1313930290); x = 0,25083333333333, y = 0,25083333333333
initialize (1313930290); x = 0,37583333333333, y = 0,25083333333333
initialize (1313930290); x = 0,50083333333333, y = 0,25083333333333
initialize (1313930290); x = 0,62583333333333, y = 0,25083333333333
initialize (1313930290); x = 0,75083333333333, y = 0,25083333333333
initialize (1313930290); x = 0,87583333333333, y = 0,25083333333333
initialize (1313930290); x = 0,00083333333333333, y = 0,37583333333333
initialize (1313930290); x = 0,12583333333333, y = 0,37583333333333
initialize (1313930290); x = 0,25083333333333, y = 0,37583333333333
initialize (1313930290); x = 0,37583333333333, y = 0,37583333333333
initialize (1313930290); x = 0,50083333333333, y = 0,37583333333333
initialize (1313930290); x = 0,62583333333333, y = 0,37583333333333
initialize (1313930290); x = 0,75083333333333, y = 0,37583333333333
initialize (1313930290); x = 0,87583333333333, y = 0,37583333333333
initialize (1313930290); x = 0,00083333333333333, y = 0,50083333333333
initialize (1313930290); x = 0,12583333333333, y = 0,50083333333333
initialize (1313930290); x = 0,25083333333333, y = 0,50083333333333
initialize (1313930290); x = 0,37583333333333, y = 0,50083333333333
initialize (1313930290); x = 0,50083333333333, y = 0,50083333333333
initialize (1313930290); x = 0,62583333333333, y = 0,50083333333333
initialize (1313930290); x = 0,75083333333333, y = 0,50083333333333
initialize (1313930290); x = 0,87583333333333, y = 0,50083333333333
initialize (1313930290); x = 0,00083333333333333, y = 0,62583333333333
initialize (1313930290); x = 0,12583333333333, y = 0,62583333333333
initialize (1313930290); x = 0,25083333333333, y = 0,62583333333333
initialize (1313930290); x = 0,37583333333333, y = 0,62583333333333
initialize (1313930290); x = 0,50083333333333, y = 0,62583333333333
initialize (1313930290); x = 0,62583333333333, y = 0,62583333333333
initialize (1313930290); x = 0,75083333333333, y = 0,62583333333333
initialize (1313930290); x = 0,87583333333333, y = 0,62583333333333
initialize (1313930290); x = 0,00083333333333333, y = 0,75083333333333
initialize (1313930290); x = 0,12583333333333, y = 0,75083333333333
initialize (1313930290); x = 0,25083333333333, y = 0,75083333333333
initialize (1313930290); x = 0,37583333333333, y = 0,75083333333333
initialize (1313930290); x = 0,50083333333333, y = 0,75083333333333
initialize (1313930290); x = 0,62583333333333, y = 0,75083333333333
initialize (1313930290); x = 0,75083333333333, y = 0,75083333333333
initialize (1313930290); x = 0,87583333333333, y = 0,75083333333333
initialize (1313930290); x = 0,00083333333333333, y = 0,87583333333333
initialize (1313930290); x = 0,12583333333333, y = 0,87583333333333
initialize (1313930290); x = 0,25083333333333, y = 0,87583333333333
initialize (1313930290); x = 0,37583333333333, y = 0,87583333333333
initialize (1313930290); x = 0,50083333333333, y = 0,87583333333333
initialize (1313930290); x = 0,62583333333333, y = 0,87583333333333
initialize (1313930290); x = 0,75083333333333, y = 0,87583333333333
initialize (1313930290); x = 0,87583333333333, y = 0,87583333333333


Variable "do_initialize" should remain false, but for some reason it doesn't. "Prepare" is only executed once, so what the h*** is going on here? Is this related to the rendering "tiles"?

Ini Test.ffxml
Njyldgarkn sample cache!
  Details E-Mail
Sphinx.
Filter Optimizer

Posts: 1346
Filters: 38
This is very annoying :-S I can't prepare the script in function Prepare because get_sample calls are not allowed (I need to analyze multiple image inputs to get average color of the inputs).

So I'm left with the option to analyze the images in the main get_sample function (with a similar initialization setup as described above). But the extreme overhead caused by the multiple executions (as described above) makes it practically unusable.. smile:evil:

We really need a middle way here: some sort of initialization function that allows get_sample calls and can produce data that is shared in all threads/tiles..

FF programmers.. any comments?
Njyldgarkn sample cache!
  Details E-Mail
Igor Lorents
Filter Forge, Inc.
Posts: 39
Sphinx, thank you for reporting the issue.

The problem seems to be in our architecture. Changes you've made in the Global table which contains definition for all global variables after the first initialization (which is made by calling the prepare() routine) do not propagate properly.
That's why your initialization code in get_sample() function executes each time when the new rendering block is started.
The problem should still persist even if you use single-threaded rendering, and your test sample illustrates it very well.

So, this issue seems to be a pretty large piece of work, and unfortunately I won't have time for it until the release of version 3.0.

Sorry for the inconvenience.
  Details E-Mail
Sphinx.
Filter Optimizer

Posts: 1346
Filters: 38
I see - after Prepare has been called you assume the global table is not changed and simply copy the table...

Could you possibly add some sort of "super global" table that works across tiles, or allow get_sample calls in prepare?
Njyldgarkn sample cache!
  Details E-Mail
Igor Lorents
Filter Forge, Inc.
Posts: 39
Quote
Could you possibly add some sort of "super global" table that works across tiles, or allow get_sample calls in prepare?


Unfortunately no, because the behavior of the suggested "super global" table is absolutely equal to the intended behavior of the global table. We'll just have to implement it properly smile:)
  Details E-Mail
Sphinx.
Filter Optimizer

Posts: 1346
Filters: 38
Sigh... well, that "bug" along with the darn unpersist error blocks several of my projects. Patience..

Thanks for the explanation anyways.
Njyldgarkn sample cache!
  Details E-Mail
Sphinx.
Filter Optimizer

Posts: 1346
Filters: 38
Alright, FF3 released - time to bring this up again smile:-)

The problem still persists:

Global variables are not truly global, but only "global" inside a given rendering block. This will ruin smart logic such as initialization regions.

A typical scenario: collect a set of samples and use their properties to determine global filtering (e.g. auto levels). This initial sample collection is only necessary to do once.
Njyldgarkn sample cache!
  Details E-Mail

Join Our Community!

Filter Forge has a thriving, vibrant, knowledgeable user community. Feel free to join us and have fun!

15,510 Registered Users
+7 new last day!

113,387 Posts
+55 new last day!

10,191 Topics
+10 new last day!

Online Users Last 5 minutes:

5 unregistered users.

Recent Wiki Edits:

Follow filterforge on Twitter