diff --git a/scripts/startup/bl_ui/space_node.py b/scripts/startup/bl_ui/space_node.py index 7fbf7c3e6a4..2b43822a73a 100644 --- a/scripts/startup/bl_ui/space_node.py +++ b/scripts/startup/bl_ui/space_node.py @@ -823,19 +823,19 @@ class NODE_PT_quality(bpy.types.Panel): layout.use_property_split = True layout.use_property_decorate = False + scene = context.scene + rd = scene.render + snode = context.space_data tree = snode.node_tree prefs = bpy.context.preferences - use_realtime = False col = layout.column() if prefs.experimental.use_experimental_compositors: - col.prop(tree, "execution_mode") - use_realtime = tree.execution_mode == 'REALTIME' - col.prop(tree, "precision") + col.prop(rd, "compositor_device", text="Device") + col.prop(rd, "compositor_precision", text="Precision") col = layout.column() - col.active = not use_realtime col.prop(tree, "use_viewer_border") col = layout.column() diff --git a/source/blender/blenkernel/BKE_blender_version.h b/source/blender/blenkernel/BKE_blender_version.h index 83a91b109f6..58a18a68ec6 100644 --- a/source/blender/blenkernel/BKE_blender_version.h +++ b/source/blender/blenkernel/BKE_blender_version.h @@ -29,7 +29,7 @@ extern "C" { /* Blender file format version. */ #define BLENDER_FILE_VERSION BLENDER_VERSION -#define BLENDER_FILE_SUBVERSION 32 +#define BLENDER_FILE_SUBVERSION 33 /* Minimum Blender version that supports reading file written with the current * version. Older Blender versions will test this and cancel loading the file, showing a warning to diff --git a/source/blender/blenloader/intern/versioning_400.cc b/source/blender/blenloader/intern/versioning_400.cc index a4cb092d82e..cbf5259d48b 100644 --- a/source/blender/blenloader/intern/versioning_400.cc +++ b/source/blender/blenloader/intern/versioning_400.cc @@ -3132,6 +3132,7 @@ void blo_do_versions_400(FileData *fd, Library * /*lib*/, Main *bmain) } if (!MAIN_VERSION_FILE_ATLEAST(bmain, 402, 3)) { + constexpr int NTREE_EXECUTION_MODE_CPU = 0; constexpr int NTREE_EXECUTION_MODE_FULL_FRAME = 1; constexpr int NTREE_COM_GROUPNODE_BUFFER = 1 << 3; @@ -3465,6 +3466,19 @@ void blo_do_versions_400(FileData *fd, Library * /*lib*/, Main *bmain) } } + if (!MAIN_VERSION_FILE_ATLEAST(bmain, 402, 33)) { + constexpr int NTREE_EXECUTION_MODE_GPU = 2; + + LISTBASE_FOREACH (Scene *, scene, &bmain->scenes) { + if (scene->nodetree) { + if (scene->nodetree->execution_mode == NTREE_EXECUTION_MODE_GPU) { + scene->r.compositor_device = SCE_COMPOSITOR_DEVICE_GPU; + } + scene->r.compositor_precision = scene->nodetree->precision; + } + } + } + /** * Always bump subversion in BKE_blender_version.h when adding versioning * code here, and wrap it inside a MAIN_VERSION_FILE_ATLEAST check. diff --git a/source/blender/compositor/intern/COM_compositor.cc b/source/blender/compositor/intern/COM_compositor.cc index cf630fdf15d..0b5c699883f 100644 --- a/source/blender/compositor/intern/COM_compositor.cc +++ b/source/blender/compositor/intern/COM_compositor.cc @@ -78,7 +78,7 @@ void COM_execute(Render *render, compositor_reset_node_tree_status(node_tree); if (U.experimental.use_full_frame_compositor && - node_tree->execution_mode == NTREE_EXECUTION_MODE_GPU) + scene->r.compositor_device == SCE_COMPOSITOR_DEVICE_GPU) { /* GPU compositor. */ RE_compositor_execute(*render, *scene, *render_data, *node_tree, view_name, render_context); diff --git a/source/blender/draw/engines/compositor/compositor_engine.cc b/source/blender/draw/engines/compositor/compositor_engine.cc index 6ac0bd0b25a..41ac23d8255 100644 --- a/source/blender/draw/engines/compositor/compositor_engine.cc +++ b/source/blender/draw/engines/compositor/compositor_engine.cc @@ -162,10 +162,10 @@ class Context : public realtime_compositor::Context { realtime_compositor::ResultPrecision get_precision() const override { - switch (get_node_tree().precision) { - case NODE_TREE_COMPOSITOR_PRECISION_AUTO: + switch (get_scene().r.compositor_precision) { + case SCE_COMPOSITOR_PRECISION_AUTO: return realtime_compositor::ResultPrecision::Half; - case NODE_TREE_COMPOSITOR_PRECISION_FULL: + case SCE_COMPOSITOR_PRECISION_FULL: return realtime_compositor::ResultPrecision::Full; } diff --git a/source/blender/editors/space_node/node_draw.cc b/source/blender/editors/space_node/node_draw.cc index 2d8668b8acd..6ed78708e78 100644 --- a/source/blender/editors/space_node/node_draw.cc +++ b/source/blender/editors/space_node/node_draw.cc @@ -4457,7 +4457,7 @@ static bool realtime_compositor_is_in_use(const bContext &context) } if (U.experimental.use_full_frame_compositor && - scene->nodetree->execution_mode == NTREE_EXECUTION_MODE_GPU) + scene->r.compositor_device == SCE_COMPOSITOR_DEVICE_GPU) { return true; } diff --git a/source/blender/editors/space_node/node_edit.cc b/source/blender/editors/space_node/node_edit.cc index 5952c4beff6..b4a6d351dce 100644 --- a/source/blender/editors/space_node/node_edit.cc +++ b/source/blender/editors/space_node/node_edit.cc @@ -349,7 +349,7 @@ static bool is_compositing_possible(const bContext *C) Scene *scene = CTX_data_scene(C); /* CPU compositor can always run. */ if (!U.experimental.use_full_frame_compositor || - scene->nodetree->execution_mode != NTREE_EXECUTION_MODE_GPU) + scene->r.compositor_device != SCE_COMPOSITOR_DEVICE_GPU) { return true; } diff --git a/source/blender/makesdna/DNA_node_types.h b/source/blender/makesdna/DNA_node_types.h index 13aed95de01..2810e184285 100644 --- a/source/blender/makesdna/DNA_node_types.h +++ b/source/blender/makesdna/DNA_node_types.h @@ -678,9 +678,9 @@ typedef struct bNodeTree { /** Tile size for compositor engine. */ int chunksize DNA_DEPRECATED; /** Execution mode to use for compositor engine. */ - int execution_mode; - /** Execution mode to use for compositor engine. */ - int precision; + int execution_mode DNA_DEPRECATED; + /** Precision used by the GPU execution of the compositor tree. */ + int precision DNA_DEPRECATED; /** #NodeGroupColorTag. */ int color_tag; @@ -842,18 +842,6 @@ enum { // NTREE_IS_LOCALIZED = 1 << 5, }; -/* tree->execution_mode */ -typedef enum eNodeTreeExecutionMode { - NTREE_EXECUTION_MODE_CPU = 0, - NTREE_EXECUTION_MODE_GPU = 2, -} eNodeTreeExecutionMode; - -/* tree->precision */ -typedef enum eNodeTreePrecision { - NODE_TREE_COMPOSITOR_PRECISION_AUTO = 0, - NODE_TREE_COMPOSITOR_PRECISION_FULL = 1, -} eNodeTreePrecision; - typedef enum eNodeTreeRuntimeFlag { /** There is a node that references an image with animation. */ NTREE_RUNTIME_FLAG_HAS_IMAGE_ANIMATION = 1 << 0, diff --git a/source/blender/makesdna/DNA_scene_types.h b/source/blender/makesdna/DNA_scene_types.h index cfcd0eade5d..1c0a05116bb 100644 --- a/source/blender/makesdna/DNA_scene_types.h +++ b/source/blender/makesdna/DNA_scene_types.h @@ -825,6 +825,12 @@ typedef struct RenderData { float motion_blur_shutter; int motion_blur_position; struct CurveMapping mblur_shutter_curve; + + /** Device to use for compositor engine. */ + int compositor_device; /* eCompositorDevice */ + + /** Precision used by the GPU execution of the compositor tree. */ + int compositor_precision; /* eCompositorPrecision */ } RenderData; /** #RenderData::quality_flag */ @@ -845,6 +851,18 @@ enum { SCE_MB_END = 2, }; +/** #RenderData::compositor_device */ +typedef enum eCompositorDevice { + SCE_COMPOSITOR_DEVICE_CPU = 0, + SCE_COMPOSITOR_DEVICE_GPU = 1, +} eCompositorDevice; + +/** #RenderData::compositor_precision */ +typedef enum eCompositorPrecision { + SCE_COMPOSITOR_PRECISION_AUTO = 0, + SCE_COMPOSITOR_PRECISION_FULL = 1, +} eCompositorPrecision; + /** \} */ /* -------------------------------------------------------------------- */ diff --git a/source/blender/makesrna/intern/rna_nodetree.cc b/source/blender/makesrna/intern/rna_nodetree.cc index 0a3de43d6ca..9cdece45edb 100644 --- a/source/blender/makesrna/intern/rna_nodetree.cc +++ b/source/blender/makesrna/intern/rna_nodetree.cc @@ -110,22 +110,6 @@ const EnumPropertyItem rna_enum_node_group_color_tag_items[] = { {0, nullptr, 0, nullptr, nullptr}, }; -static const EnumPropertyItem rna_enum_execution_mode_items[] = { - {NTREE_EXECUTION_MODE_CPU, "CPU", 0, "CPU", ""}, - {NTREE_EXECUTION_MODE_GPU, "GPU", 0, "GPU", ""}, - {0, nullptr, 0, nullptr, nullptr}, -}; - -static const EnumPropertyItem rna_enum_precision_items[] = { - {NODE_TREE_COMPOSITOR_PRECISION_AUTO, - "AUTO", - 0, - "Auto", - "Full precision for final renders, half precision otherwise"}, - {NODE_TREE_COMPOSITOR_PRECISION_FULL, "FULL", 0, "Full", "Full precision"}, - {0, nullptr, 0, nullptr, nullptr}, -}; - const EnumPropertyItem rna_enum_mapping_type_items[] = { {NODE_MAPPING_TYPE_POINT, "POINT", 0, "Point", "Transform a point"}, {NODE_MAPPING_TYPE_TEXTURE, @@ -10570,18 +10554,6 @@ static void rna_def_composite_nodetree(BlenderRNA *brna) RNA_def_struct_sdna(srna, "bNodeTree"); RNA_def_struct_ui_icon(srna, ICON_RENDERLAYERS); - prop = RNA_def_property(srna, "precision", PROP_ENUM, PROP_NONE); - RNA_def_property_enum_sdna(prop, nullptr, "precision"); - RNA_def_property_enum_items(prop, rna_enum_precision_items); - RNA_def_property_ui_text(prop, "Precision", "The precision of compositor intermediate result"); - RNA_def_property_update(prop, NC_NODE | ND_DISPLAY, "rna_NodeTree_update"); - - prop = RNA_def_property(srna, "execution_mode", PROP_ENUM, PROP_NONE); - RNA_def_property_enum_sdna(prop, nullptr, "execution_mode"); - RNA_def_property_enum_items(prop, rna_enum_execution_mode_items); - RNA_def_property_ui_text(prop, "Execution Mode", "Set how compositing is executed"); - RNA_def_property_update(prop, NC_NODE | ND_DISPLAY, "rna_NodeTree_update"); - prop = RNA_def_property(srna, "use_viewer_border", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, nullptr, "flag", NTREE_VIEWER_BORDER); RNA_def_property_ui_text( diff --git a/source/blender/makesrna/intern/rna_scene.cc b/source/blender/makesrna/intern/rna_scene.cc index a63c383c179..2d1b915086c 100644 --- a/source/blender/makesrna/intern/rna_scene.cc +++ b/source/blender/makesrna/intern/rna_scene.cc @@ -1831,6 +1831,18 @@ void rna_Scene_use_freestyle_update(Main * /*bmain*/, Scene * /*scene*/, Pointer } } +void rna_Scene_compositor_update(Main *bmain, Scene * /*scene*/, PointerRNA *ptr) +{ + Scene *scene = (Scene *)ptr->owner_id; + + if (scene->nodetree) { + bNodeTree *ntree = reinterpret_cast(scene->nodetree); + WM_main_add_notifier(NC_NODE | NA_EDITED, &ntree->id); + WM_main_add_notifier(NC_SCENE | ND_NODES, &ntree->id); + ED_node_tree_propagate_change(nullptr, bmain, ntree); + } +} + void rna_Scene_use_view_map_cache_update(Main * /*bmain*/, Scene * /*scene*/, PointerRNA * /*ptr*/) { # ifdef WITH_FREESTYLE @@ -6696,6 +6708,22 @@ static void rna_def_scene_render_data(BlenderRNA *brna) {0, nullptr, 0, nullptr, nullptr}, }; + static const EnumPropertyItem compositor_device_items[] = { + {SCE_COMPOSITOR_DEVICE_CPU, "CPU", 0, "CPU", ""}, + {SCE_COMPOSITOR_DEVICE_GPU, "GPU", 0, "GPU", ""}, + {0, nullptr, 0, nullptr, nullptr}, + }; + + static const EnumPropertyItem compositor_precision_items[] = { + {SCE_COMPOSITOR_PRECISION_AUTO, + "AUTO", + 0, + "Auto", + "Full precision for final renders, half precision otherwise"}, + {SCE_COMPOSITOR_PRECISION_FULL, "FULL", 0, "Full", "Full precision"}, + {0, nullptr, 0, nullptr, nullptr}, + }; + rna_def_scene_ffmpeg_settings(brna); srna = RNA_def_struct(brna, "RenderSettings", nullptr); @@ -7423,6 +7451,20 @@ static void rna_def_scene_render_data(BlenderRNA *brna) RNA_def_property_struct_type(prop, "BakeSettings"); RNA_def_property_ui_text(prop, "Bake Data", ""); + /* Compositor. */ + + prop = RNA_def_property(srna, "compositor_device", PROP_ENUM, PROP_NONE); + RNA_def_property_enum_items(prop, compositor_device_items); + RNA_def_property_ui_text(prop, "Compositor Device", "Set how compositing is executed"); + RNA_def_property_update(prop, NC_NODE | ND_DISPLAY, "rna_Scene_compositor_update"); + + prop = RNA_def_property(srna, "compositor_precision", PROP_ENUM, PROP_NONE); + RNA_def_property_enum_sdna(prop, nullptr, "compositor_precision"); + RNA_def_property_enum_items(prop, compositor_precision_items); + RNA_def_property_ui_text( + prop, "Compositor Precision", "The precision of compositor intermediate result"); + RNA_def_property_update(prop, NC_NODE | ND_DISPLAY, "rna_Scene_compositor_update"); + /* Nestled Data. */ /* *** Non-Animated *** */ RNA_define_animate_sdna(false); diff --git a/source/blender/render/intern/compositor.cc b/source/blender/render/intern/compositor.cc index 504d1af636a..66997c4e214 100644 --- a/source/blender/render/intern/compositor.cc +++ b/source/blender/render/intern/compositor.cc @@ -322,8 +322,8 @@ class Context : public realtime_compositor::Context { realtime_compositor::ResultPrecision get_precision() const override { - switch (input_data_.node_tree->precision) { - case NODE_TREE_COMPOSITOR_PRECISION_AUTO: + switch (input_data_.scene->r.compositor_precision) { + case SCE_COMPOSITOR_PRECISION_AUTO: /* Auto uses full precision for final renders and half procession otherwise. */ if (this->render_context()) { return realtime_compositor::ResultPrecision::Full; @@ -331,7 +331,7 @@ class Context : public realtime_compositor::Context { else { return realtime_compositor::ResultPrecision::Half; } - case NODE_TREE_COMPOSITOR_PRECISION_FULL: + case SCE_COMPOSITOR_PRECISION_FULL: return realtime_compositor::ResultPrecision::Full; } diff --git a/source/blender/render/intern/pipeline.cc b/source/blender/render/intern/pipeline.cc index c55407981d2..1a505b5349e 100644 --- a/source/blender/render/intern/pipeline.cc +++ b/source/blender/render/intern/pipeline.cc @@ -667,7 +667,7 @@ void RE_FreeUnusedGPUResources() /* Detect if scene is using GPU compositing, and if either a node editor is * showing the nodes, or an image editor is showing the render result or viewer. */ if (!(scene->use_nodes && scene->nodetree && - scene->nodetree->execution_mode == NTREE_EXECUTION_MODE_GPU)) + scene->r.compositor_device == SCE_COMPOSITOR_DEVICE_GPU)) { continue; } @@ -1693,7 +1693,7 @@ static bool is_compositing_possible_on_gpu(Scene *scene, ReportList *reports) { /* CPU compositor can always run. */ if (!U.experimental.use_full_frame_compositor || - scene->nodetree->execution_mode != NTREE_EXECUTION_MODE_GPU) + scene->r.compositor_device != SCE_COMPOSITOR_DEVICE_GPU) { return true; } diff --git a/tests/python/compositor_realtime_render_tests.py b/tests/python/compositor_realtime_render_tests.py index 2b187bb0ac7..c112616d201 100644 --- a/tests/python/compositor_realtime_render_tests.py +++ b/tests/python/compositor_realtime_render_tests.py @@ -17,7 +17,7 @@ except ImportError: ENABLE_REALTIME_COMPOSITOR_SCRIPT = "import bpy; " \ "bpy.context.preferences.experimental.use_experimental_compositors = True; " \ - "bpy.data.scenes[0].node_tree.execution_mode = 'GPU'" + "bpy.data.scenes[0].render.compositor_device = 'GPU'" def get_arguments(filepath, output_filepath):