diff options
author | Sergey Sharybin <sergey@blender.org> | 2022-02-18 17:32:24 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey@blender.org> | 2022-02-18 17:32:24 +0300 |
commit | 303b566b10f9008f6608a3cce08dbac3c64b6b4a (patch) | |
tree | c0fe37b5ae98bcd2a76770bdaa705fda0ab1e531 /intern | |
parent | 40cddcd917a7de26a89908b82c6583ace8f76641 (diff) | |
parent | e4b7d52fe4fe3076f5f68ff575c200f5cf16e416 (diff) |
Merge branch 'blender-v3.1-release'
Diffstat (limited to 'intern')
-rw-r--r-- | intern/cycles/blender/session.cpp | 9 | ||||
-rw-r--r-- | intern/cycles/integrator/path_trace.cpp | 26 | ||||
-rw-r--r-- | intern/cycles/integrator/path_trace.h | 3 |
3 files changed, 28 insertions, 10 deletions
diff --git a/intern/cycles/blender/session.cpp b/intern/cycles/blender/session.cpp index 8917c703700..5e9066da5de 100644 --- a/intern/cycles/blender/session.cpp +++ b/intern/cycles/blender/session.cpp @@ -493,8 +493,13 @@ void BlenderSession::render_frame_finish() session->set_output_driver(nullptr); session->full_buffer_written_cb = function_null; - /* The display driver holds OpenGL resources which belong to an OpenGL context held by the render - * engine on Blender side. Force destruction of those resources. */ + /* The display driver is the source of drawing context for both drawing and possible graphics + * interop objects in the path trace. Once the frame is finished the OpenGL context might be + * freed form Blender side. Need to ensure that all GPU resources are freed prior to that + * point. + * Ideally would only do this when OpenGL context is actually destroyed, but there is no way to + * know when this happens (at least in the code at the time when this comment was written). + * The penalty of re-creating resources on every frame is unlikely to be noticed. */ display_driver_ = nullptr; session->set_display_driver(nullptr); diff --git a/intern/cycles/integrator/path_trace.cpp b/intern/cycles/integrator/path_trace.cpp index 220d4c9ffa2..eb12b0a6a11 100644 --- a/intern/cycles/integrator/path_trace.cpp +++ b/intern/cycles/integrator/path_trace.cpp @@ -54,14 +54,7 @@ PathTrace::PathTrace(Device *device, PathTrace::~PathTrace() { - /* Destroy any GPU resource which was used for graphics interop. - * Need to have access to the PathTraceDisplay as it is the only source of drawing context which - * is used for interop. */ - if (display_) { - for (auto &&path_trace_work : path_trace_works_) { - path_trace_work->destroy_gpu_resources(display_.get()); - } - } + destroy_gpu_resources(); } void PathTrace::load_kernels() @@ -559,6 +552,11 @@ void PathTrace::set_output_driver(unique_ptr<OutputDriver> driver) void PathTrace::set_display_driver(unique_ptr<DisplayDriver> driver) { + /* The display driver is the source of the drawing context which might be used by + * path trace works. Make sure there is no graphics interop using resources from + * the old display, as it might no longer be available after this call. */ + destroy_gpu_resources(); + if (driver) { display_ = make_unique<PathTraceDisplay>(move(driver)); } @@ -1075,6 +1073,18 @@ bool PathTrace::has_denoised_result() const return render_state_.has_denoised_result; } +void PathTrace::destroy_gpu_resources() +{ + /* Destroy any GPU resource which was used for graphics interop. + * Need to have access to the PathTraceDisplay as it is the only source of drawing context which + * is used for interop. */ + if (display_) { + for (auto &&path_trace_work : path_trace_works_) { + path_trace_work->destroy_gpu_resources(display_.get()); + } + } +} + /* -------------------------------------------------------------------- * Report generation. */ diff --git a/intern/cycles/integrator/path_trace.h b/intern/cycles/integrator/path_trace.h index 1be5ce847bc..a470a6e1402 100644 --- a/intern/cycles/integrator/path_trace.h +++ b/intern/cycles/integrator/path_trace.h @@ -226,6 +226,9 @@ class PathTrace { void progress_set_status(const string &status, const string &substatus = ""); + /* Destroy GPU resources (such as graphics interop) used by work. */ + void destroy_gpu_resources(); + /* Pointer to a device which is configured to be used for path tracing. If multiple devices * are configured this is a `MultiDevice`. */ Device *device_ = nullptr; |