Commit Graph

2112 Commits

Author SHA1 Message Date
5be97aba95 Recent spinlock commit made scheduling unsafe for threading
Namely, it caused nodes be adding to the pool multiple times.

Returned spin back, but use it only in cases node valency is
zero. So now valency is decreasing without any locks, then
if it's zero spin lock happens, node color (which indicates
whether node is scheduled or not) happens. Actual new task
creation happens outside of locks.

This might sound a bit complicated, but it's straightforward
code which is free from any thread synchronization latency.
2013-08-14 09:24:15 +00:00
3c9c5b42cb Merging r58778 through r59080 from trunk into soc-2013-depsgraph_mt 2013-08-12 09:35:16 +00:00
0395b8eee8 border render with cycles had 1 pixel offset on the top-right edge of the image, issue was caused by wmSubWindowScissorSet adding 1 to the ar->drawrct, now only add the padding when drawing the entire area 2013-08-05 04:52:27 +00:00
c847198a7b Use one global task scheduler for all the tasks
Instead of allocating scheduler and starting threads
on every object_update call make it so scheduler is
global and threads are always ready to run.

This was we could avoid quite hacky thing which is
counting how much objects need to be updated before
starting threaded update.

It'll also allow using the same scheduler to do all
sorts of tasks, not only objects update in the same
scheduler. This is nice from load balancing point of
view.

Couple of changes were needed to be done in task
scheduler itself:

- Free tas before sending notifier.
- Free TaskThread structures outside from thread.

This is needed to make it possible use begin/end
threaded malloc from the main thread before/after
running the pool. Without this change it was possible
that allocation will switch to non-thread mode while
thread is freeing the task.

This required storing TaskThread array in Scheduler,
but it's not so much bad actually, since it also
reduces memory overhead caused by per-thread allocation.
2013-07-31 21:55:36 +00:00
86cb81abb9 Merging r58756 through r58777 from trunk into soc-2013-depsgraph_mt 2013-07-31 20:49:39 +00:00
43ab02db14 code cleanup: remove redundant NULL checks 2013-07-31 09:18:40 +00:00
24b0f8247f Merging r58701 through r58746 from trunk into soc-2013-depsgraph_mt 2013-07-30 19:05:29 +00:00
29f8dfd37a BGE: Adding vsync control. Users can enable vsync, disable vsync, or use adaptive vsync via UI options in the render properties, or by using the new Python method bge.render.setVsync(). Win32 and X11 support are done via EXT_swap_control. Support for using EXT_swap_control on OS X still needs to be added to Ghost. 2013-07-29 22:31:32 +00:00
02608d257a add api call for initializing events from the windows eventstate. 2013-07-29 08:29:04 +00:00
51dab0e0ef Merging r58475 through r58700 from trunk into soc-2013-depsgraph_mt 2013-07-29 02:49:36 +00:00
fc4a777511 use '_exec' suffix for operator execute callbacks, also picky change to sizeof() use in BLI_array.h 2013-07-28 17:06:31 +00:00
9b16b105f1 avoid calling context functions when direct access is possible. 2013-07-23 18:30:06 +00:00
3ff3d1bc0f replace use of strcat() where the string offset is known.
also correct bad logic with converting a textblock to 3d-text, bytes-vs-number of chars wasn't handled right.
2013-07-23 12:49:30 +00:00
44a43ead67 Merging r58464 through r58474 from trunk into soc-2013-depsgraph_mt 2013-07-21 14:35:33 +00:00
7db1d6556d code cleanup: add break statements in switch ()'s, (even at the last case). 2013-07-21 08:16:37 +00:00
2d7a425381 Merging r58362 through r58463 from trunk into soc-2013-depsgraph_mt 2013-07-21 08:14:59 +00:00
a2492e0603 style cleanup: braces/indentation 2013-07-19 16:44:17 +00:00
397da50002 style cleanup: switch statements, include break statements within braces & indent.
also indent case's within the switch (we already did both of these almost everywhere)
2013-07-19 15:23:42 +00:00
fea5af0d88 code cleanup: replace wm_macro_modal inline search for BLI_findptr. 2013-07-19 10:39:55 +00:00
d44fb5bd8b Merging r58196 through r58265 from trunk into soc-2013-depsgraph_mt 2013-07-15 11:25:56 +00:00
bf77d35f69 fix for bad lengths being passed to string functions. 2013-07-15 05:11:14 +00:00
0ea078ad03 fix for 2 bugs in animation playback
- reading bmp images was failing (needed to increase the size of the header to 64 bytes)
- the dnd image was being incorrectly checked (was always returning true even when none was used).
2013-07-13 12:58:00 +00:00
643d709d14 Merging r58073 through r58111 from trunk into soc-2013-depsgraph_mt 2013-07-09 08:44:06 +00:00
3ce280e825 Fix #35960, #36044: blender internal viewport rendering crash while editing data.
Now the viewport rendering thread will lock the main thread while it is exporting
objects to render data. This is not ideal if you have big scenes that might block
the UI, but Cycles does the same, and it's fairly quick because the same evaluated
mesh can be used as for viewport drawing. It's the only way to get things stable
until the thread safe dependency graph is here.

This adds a mechanism to the job system for jobs to lock the main thread, using a
new 'ticket mutex lock' which is a mutex lock that gives priority to the first
thread that tries to lock the mutex.

Still to solve: undo/redo crashes.
2013-07-08 17:56:51 +00:00
8097e9d235 Merging r57989 through r58072 from trunk into soc-2013-depsgraph_mt 2013-07-08 11:29:08 +00:00
8a388a7bef fix [#36043] Missing Tooltip for Excluded Paths field of Auto Run Python Scripts in User Preferences -> File
also select more/less were flipped for mesh menu compared to everywhere else.
2013-07-08 07:40:32 +00:00
6fb6087c68 correct bad use of bool for cursor arg. 2013-07-04 18:58:00 +00:00
5f8d67b055 Merging r57962 through r57988 from trunk into soc-2013-depsgraph_mt 2013-07-04 09:23:21 +00:00
42f6136da8 Fix #35991: show warning message to when trying to edit driven values in number buttons. 2013-07-03 20:37:07 +00:00
76b3f6edcc Fix #35933: setting shortcut keys in object mode menu didn't work correct. 2013-07-03 17:11:33 +00:00
06e2d967ae Simplify debug print macro in WM even system 2013-07-02 19:22:49 +00:00
8c67e9d799 Merging r57925 through r57933 from trunk into soc-2013-depsgraph_mt 2013-07-02 19:18:10 +00:00
418011907c remove nan copyrights from code added since blender become opensource (copy paste errors), also remove BKE_script.h 2013-07-02 10:14:59 +00:00
311d4e15ec Merging r57897 through r57924 from trunk into soc-2013-depsgraph_mt 2013-07-02 06:40:05 +00:00
83411dab07 fix for crash in demo-mode, caused by r51702 2013-07-02 05:54:28 +00:00
ded22d7060 Replace stupid static balancing with task-based one
Initially i wanted to have some really simple and basic
threading scheduler and wrote one based on traversing
depsgraph in advance. But it ended up in some issues with
the single-pass traverse i did which didn't gather all
the dependencies actually.

That was for sure solvable, but it ended up in a bit of
time consuming thing and with huge help of Brecht's
patch it was faster just to write proper balancing.

But it's again really basic thing, which could be
easily changed depending on feedback and design decisions
from Joshua,

So for now it works in the following way:

- Currently DagNode is used for threaded evaluaiton,
  meaning traversing actually happens for DagNodes.

  This is easier than converting DAG to a graph where
  only objects are stored, but required adding one int
  field to DagNode for faster runtime checks.

  We could change this later when it'll be clear how
  and where we'll store evaluation data, but for now
  it work pretty ok.

- The new field is called "valency" and it's basically
  number of node parents which needs to be evaluated
  before the node itself could be evaluated.

- Nodes' valency is getting initialized before threading,
  and when node finished to update valency of it's childs
  is getting decreased by one. And if it happens so
  child's valency became zero, it's adding to task pool.

- There's thread lock around valency update, it'll be
  replaced with spinlock in nearest future.

- Another update runtime data is node color. White nodes
  represents objects, gray one non-objects.

  Currently it's needed to distinguish whether we need to
  call object_handle_update on node->ob or not. In the
  future it could be replaced with node->type to support
  granularity, meaning we then could update object data
  separately from object itself.

- Needed to add some public depsgraph functions to make
  it possible to traverse depsgraph without including
  depsgraph private header to other files.

This change doesn't make code anyhow more stable, but
solves update order issues noticed while working on
fixing underlying bugs.

Threaded update is still ifdef-ed for until curves and
armatures are considered thread-safe, which is next
step to be done.
2013-07-01 21:23:25 +00:00
16efede680 Merging r57816 through r57896 from trunk into soc-2013-depsgraph_mt 2013-07-01 09:07:21 +00:00
11972c0d82 Towards threaded object update
This commit contains changes related on running function
BKE_object_handle_update_ex from multiple threads in order
to increase scene update time when having multiple
independent groups of objects.

Currently this required changes to two areas:

- scene.c, where scene_update_tagged_recursive is now using
  threads for updating the object

  There're some tricks to prevent threads from being spawned
  when it's not needed:

  * Threading will only happen if there're more than one CPU
    core.

  * Threading will happen only if there're more than single
    object which needed to be updated.

  There's currently one crappy part of the change: which is
  freeing object caches (derivedFinal, derivedDeform and so)
  from main thread. This is so because in case VBO are used
  freeing DM is not thread safe. This is because DrawObject
  used global array. Would look into possibility of making
  that code safe later.

  There're also currently some ifdef-ed debug-only code, which
  helps a lot troubleshooting whether everything is working
  fine. This code looks a bit ugly now, will either drop it
  later or make it more cleat.

  And one more thing: threaded update is CURRENTLY DISABLED.
  This is because of some thread-unsafe issues discovered
  while was working on this patch. Namely:

  * I have once a crash in Curve module. Wasn't been able
    to reproduce the crash, but could thing about some
    unsafe code there.

  * Virtual modifier list is not thread-safe (it uses static
    variables).

  * Armature modifier is also doesn't seem to be thread safe
    because of storing some temporary runtime data in actual
    armature.

  All this issues are to be solved next.

- depsgraph.c, where i've added a function which gives list
  of groups, each group contains objects and dependency is
  only allowed between objects inside one group.

  This is needed to make scheduling of objects easier, which
  means update threads will operate on groups, and will handle
  objects one-by-one inside group. Different threads will
  operate on different groups.

  Currently such groups will be generated on every update.
  Actually, on every run of scene_update_objects_threaded which
  only happens if there're objects marked for update. In the
  future we could consider storing such groups in graph itself,
  which will help saving CPU power on building such groups.
  But this is something to be discussed with Joshua first.

P.S. If you really want to test threaded update, you'll
     need to replace:

       #undef USE_THREADED_UPDATE

     with:

       #define USE_THREADED_UPDATE
2013-06-28 21:58:56 +00:00
f934825a4e Allow some operators when interface is locked
Now it's possible to mark operator as safe to be used
in locked interface mode by adding OPTYPE_ALLOW_LOCKED
bit to operator template flags.

This bit is completely handled by wm_evem_system, not
with operator run routines, so it's still possible to
run operators from drivers and handlers.

Currently allowed image editor navigation and zooming.
2013-06-28 21:58:52 +00:00
02483146ee Code cleanup: replace bunch of ifdef+if(do_debug_handler) with
a macro which checks all the stuff and keeps code easy to follow.
2013-06-28 21:58:48 +00:00
5d413b523a fix for crash when setting the cursor in background mode. 2013-06-28 16:37:39 +00:00
4d5fffa1a9 Fix #35809: dragging a non-active node in the node editor did not work reliably.
Disabled timer events from the properties editor were cancelling gestures.
2013-06-27 15:07:27 +00:00
ee85587a43 Blender 2.68 Release maintenance:
* Update readme and release-log links to 2.68.
2013-06-27 11:30:53 +00:00
f7216eda79 Merging r57729 through r57815 from trunk into soc-2013-depsgraph_mt 2013-06-27 09:07:19 +00:00
fad1da062d correct typos in comments. 2013-06-25 22:58:23 +00:00
6268434eee Fix part of #35859: lib linking errors were not shown when opening files through open recent. 2013-06-25 13:39:51 +00:00
c4e88dd908 Experimental feature to lock the interface while rendering
Added function called WM_set_locked_interface which does
two things:

- Prevents event queue from being handled, so no operators
  or values are even possible to run or change. This prevents
  any kind of "destructive" action performed from user while
  rendering.

- Locks interface refresh for regions which does have lock
  set to truth in their template. Currently it's just a 3D
  viewport, but in the future more regions could be considered
  unsafe, or we could want to lock different parts of
  interface when doing different jobs.

  This is needed because 3D viewport could be using or changing
  the same data as renderer currently uses, leading to threading
  conflict.

Notifiers are still allowed to handle, so render progress is
seen on the screen, but would need to doublecheck on this, in
terms some notifiers could be changing the data.

For now interface locking happens for render job only in case
"Lock Interface" checkbox is enabled.

Currently this option would only make rendering thread-safe, but
in the future more benefits are possible to gain from it. Namely,
if we'll make renderer using it's own graph, this option would
allow to free memory used by 3D viewport graph, which would help
keeping memory usage low (or even would allow renderer not to
copy anything in this case).

Initially thought this change will also allow to free DMs used
by viewport, but we couldn't actually do this. This is because
of modifiers which uses other objects (like boolean), They're
in fact using viewport DM. This is bad because of few reasons.

We currently need to have viewport DM when rendering.
And for sure even in background render viewport DMs are being
calculated. This sounds like 2x computing is needed: one is for
viewport DM and one is for RenderDM.

If we'll have local graphs, we'll be able to compute RenderDMs
only and store them in graph. This would require a bit more of
the memory, but would solve current issues with viewport DM
used for modifiers operands while rendering and it should give
quite noticeable speedup.

Other tools like backing would also benefit of this option,
but rather get approval of current way of locking first.
2013-06-25 09:04:42 +00:00
02fbfa5c70 Fix unnecessary 3D viewport redraws in various cases, in particular when editing
node materials.

Area and region listener callbacks now get the screen and area pointers passed, so
they can do more fine grained checks to see if redraw is really needed, for example
depending on the 3D view drawtype.
2013-06-24 22:41:33 +00:00
2df82a2a2b Code cleanup: fix some vs2012 compiler warnings 2013-06-21 12:33:19 +00:00
033089d286 Usability:
For users without middle-mouse buttons, they can now use Circle and Border
deselect by holding SHIFT. Middle mouse still works too.
2013-06-19 15:20:50 +00:00