Render: Make GPU compositor a BaseRender method #110696

Merged
Sergey Sharybin merged 1 commits from Sergey/blender:render_pipeline into main 2023-08-02 10:30:33 +02:00
3 changed files with 62 additions and 22 deletions

View File

@ -431,6 +431,34 @@ class RealtimeCompositor {
} // namespace blender::render
void Render::compositor_execute(const Scene &scene,
const RenderData &render_data,
const bNodeTree &node_tree,
const bool use_file_output,
const char *view_name)
{
std::unique_lock lock(gpu_compositor_mutex);
blender::render::ContextInputData input_data(
scene, render_data, node_tree, use_file_output, view_name);
if (gpu_compositor == nullptr) {
gpu_compositor = new blender::render::RealtimeCompositor(*this, input_data);
}
gpu_compositor->execute(input_data);
}
void Render::compositor_free()
{
std::unique_lock lock(gpu_compositor_mutex);
if (gpu_compositor != nullptr) {
delete gpu_compositor;
gpu_compositor = nullptr;
}
}
void RE_compositor_execute(Render &render,
const Scene &scene,
const RenderData &render_data,
@ -438,26 +466,10 @@ void RE_compositor_execute(Render &render,
const bool use_file_output,
const char *view_name)
{
BLI_mutex_lock(&render.gpu_compositor_mutex);
blender::render::ContextInputData input_data(
scene, render_data, node_tree, use_file_output, view_name);
if (render.gpu_compositor == nullptr) {
render.gpu_compositor = new blender::render::RealtimeCompositor(render, input_data);
}
render.gpu_compositor->execute(input_data);
BLI_mutex_unlock(&render.gpu_compositor_mutex);
render.compositor_execute(scene, render_data, node_tree, use_file_output, view_name);
}
void RE_compositor_free(Render &render)
{
BLI_mutex_lock(&render.gpu_compositor_mutex);
if (render.gpu_compositor) {
delete render.gpu_compositor;
render.gpu_compositor = nullptr;
}
BLI_mutex_unlock(&render.gpu_compositor_mutex);
render.compositor_free();
}

View File

@ -36,8 +36,6 @@ Render::~Render()
RE_blender_gpu_context_free(this);
RE_system_gpu_context_free(this);
BLI_mutex_end(&gpu_compositor_mutex);
BKE_curvemapping_free_data(&r.mblur_shutter_curve);
render_result_free(pushedresult);

View File

@ -12,6 +12,8 @@
/* exposed internal in render module only! */
/* ------------------------------------------------------------------------- */
#include <mutex>
#include "DNA_scene_types.h"
#include "BLI_threads.h"
@ -21,12 +23,14 @@
#include "tile_highlight.h"
struct bNodeTree;
struct Depsgraph;
struct GSet;
struct Main;
struct Object;
struct RenderEngine;
struct ReportList;
struct Scene;
struct BaseRender {
BaseRender() = default;
@ -37,6 +41,14 @@ struct BaseRender {
* highlight. */
virtual blender::render::TilesHighlight *get_tile_highlight() = 0;
/* GPU/realtime compositor. */
virtual void compositor_execute(const Scene &scene,
const RenderData &render_data,
const bNodeTree &node_tree,
const bool use_file_output,
const char *view_name) = 0;
virtual void compositor_free() = 0;
/* Result of rendering */
RenderResult *result = nullptr;
@ -57,6 +69,15 @@ struct ViewRender : public BaseRender {
{
return nullptr;
}
void compositor_execute(const Scene & /*scene*/,
const RenderData & /*render_data*/,
const bNodeTree & /*node_tree*/,
const bool /*use_file_output*/,
const char * /*view_name*/) override
{
}
void compositor_free() override {}
};
/* Controls state of render, everything that's read-only during render stage */
@ -71,6 +92,13 @@ struct Render : public BaseRender {
return &tile_highlight;
}
void compositor_execute(const Scene &scene,
const RenderData &render_data,
const bNodeTree &node_tree,
const bool use_file_output,
const char *view_name) override;
void compositor_free() override;
char name[RE_MAXNAME] = "";
int slot = 0;
@ -116,9 +144,11 @@ struct Render : public BaseRender {
struct Depsgraph *pipeline_depsgraph = nullptr;
Scene *pipeline_scene_eval = nullptr;
/* Realtime GPU Compositor. */
/* Realtime GPU Compositor.
* NOTE: Use bare pointer instead of smart pointer because the RealtimeCompositor is a fully
* opaque type. */
blender::render::RealtimeCompositor *gpu_compositor = nullptr;
ThreadMutex gpu_compositor_mutex = BLI_MUTEX_INITIALIZER;
std::mutex gpu_compositor_mutex;
/* callbacks */
void (*display_init)(void *handle, RenderResult *rr) = nullptr;