Page MenuHome

Fix race condition between draw and render threads
ClosedPublic

Authored by Sergey Sharybin (sergey) on Sep 16 2021, 6:10 PM.

Details

Summary

Caused crashes like the one William was fixing in the D12498, or the
crash when rendering multiple view layers.

Need to guarantee that the render engine is not freed during drawing,
and that the external engine is not in the middle of re-allocation due
to update() which might cause session reset (happens in Cycles).

Had to introduce a separate lock. The reason for this comes from the
fact that we need to acquire the engine early on in the draw manager,
and release it only when drawing is done. However, some other engines
(like overlay) might be requesting ImBuf for the image space, so that
they know dimensions. Such acquisition is guarded by the resultmutex.
This means reusing resultmutex for the RenderEngine::draw() would
cause a recursive lock.

Not entirely happy with implicit release in the external engine code,
but not sure there is an existing way of making it explicit without
introducing new draw engine callback.

Diff Detail

Repository
rB Blender
Branch
cycles-x_draw (branched from master)
Build Status
Buildable 17064
Build 17064: arc lint + arc unit

Event Timeline

Sergey Sharybin (sergey) requested review of this revision.Sep 16 2021, 6:10 PM
Sergey Sharybin (sergey) created this revision.
Brecht Van Lommel (brecht) added inline comments.
source/blender/draw/engines/external/external_engine.c
514–518

I suggest return RE_engine_draw_acquire(re);

This revision is now accepted and ready to land.Sep 16 2021, 6:31 PM

I have verified this and it fixes my bug thanks :-) now I can get back to removing ray offsetting.

Updates for the comment form Brecht.

Should be minor no-functional change. I'll land the patch now.