Cycles/BI: Add a pixel size option for speeding up viewport rendering
authorLukas Stockner <lukas.stockner@freenet.de>
Mon, 14 Aug 2017 22:11:52 +0000 (00:11 +0200)
committerLukas Stockner <lukas.stockner@freenet.de>
Mon, 14 Aug 2017 23:22:40 +0000 (01:22 +0200)
This patch adds "Pixel Size" to the performance options, which allows to render
in a smaller resolution, which is especially useful for displays with high DPI.

Reviewers: Severin, dingto, sergey, brecht

Reviewed By: brecht

Subscribers: Severin, venomgfx, eyecandy, brecht

Differential Revision: https://developer.blender.org/D1619

13 files changed:
intern/cycles/blender/addon/ui.py
intern/cycles/blender/blender_sync.cpp
intern/cycles/render/session.cpp
intern/cycles/render/session.h
intern/cycles/render/tile.cpp
intern/cycles/render/tile.h
release/scripts/startup/bl_ui/properties_render.py
source/blender/blenkernel/BKE_scene.h
source/blender/blenkernel/intern/scene.c
source/blender/editors/render/render_internal.c
source/blender/makesdna/DNA_scene_types.h
source/blender/makesrna/intern/rna_render.c
source/blender/makesrna/intern/rna_scene.c

index debc8e76e54356443eecec91fe4e06b5afb4a8ef..d8c2bde0b027271896d68309cca4670b67559f2c 100644 (file)
@@ -402,6 +402,7 @@ class CyclesRender_PT_performance(CyclesButtonsPanel, Panel):
         col.prop(cscene, "debug_bvh_type", text="")
         col.separator()
         col.prop(cscene, "preview_start_resolution")
+        col.prop(rd, "preview_pixel_size", text="")
 
         col.separator()
 
index f5e8d0633bc80b909fc85b534339cb6807b32e4d..a858af253d45dc80bb5e723472ef2a5a35ecee42 100644 (file)
@@ -776,6 +776,7 @@ SessionParams BlenderSync::get_session_params(BL::RenderEngine& b_engine,
        }
 
        params.start_resolution = get_int(cscene, "preview_start_resolution");
+       params.pixel_size = b_engine.get_preview_pixel_size(b_scene);
 
        /* other parameters */
        if(b_scene.render().threads_mode() == BL::RenderSettings::threads_mode_FIXED)
@@ -796,6 +797,7 @@ SessionParams BlenderSync::get_session_params(BL::RenderEngine& b_engine,
                        params.progressive = false;
 
                params.start_resolution = INT_MAX;
+               params.pixel_size = 1;
        }
        else
                params.progressive = true;
index ca3aefcb5e60d700879ec73ff07507d7be0e57bd..3798483aa9cab7701657aa880a7bb70f117b7e1d 100644 (file)
@@ -46,7 +46,7 @@ Session::Session(const SessionParams& params_)
 : params(params_),
   tile_manager(params.progressive, params.samples, params.tile_size, params.start_resolution,
        params.background == false || params.progressive_refine, params.background, params.tile_order,
-       max(params.device.multi_devices.size(), 1)),
+       max(params.device.multi_devices.size(), 1), params.pixel_size),
   stats()
 {
        device_use_gl = ((params.device.type != DEVICE_CPU) && !params.background);
index 9f8bb8c42fa9280914b31b5d45d45c30d6f92672..980eda0876de36a686cc8660f891a0bcb9c7a0db 100644 (file)
@@ -53,6 +53,7 @@ public:
        int2 tile_size;
        TileOrder tile_order;
        int start_resolution;
+       int pixel_size;
        int threads;
 
        bool display_buffer_linear;
@@ -81,6 +82,7 @@ public:
                samples = INT_MAX;
                tile_size = make_int2(64, 64);
                start_resolution = INT_MAX;
+               pixel_size = 1;
                threads = 0;
 
                use_denoising = false;
@@ -110,6 +112,7 @@ public:
                && experimental == params.experimental
                && tile_size == params.tile_size
                && start_resolution == params.start_resolution
+               && pixel_size == params.pixel_size
                && threads == params.threads
                && display_buffer_linear == params.display_buffer_linear
                && cancel_timeout == params.cancel_timeout
index 176a1f4f0f3f4eb6bba52b9bde33944d95d4df70..4f3479c52ae0c567f542da911c978e8511068836 100644 (file)
@@ -88,12 +88,14 @@ enum SpiralDirection {
 }  /* namespace */
 
 TileManager::TileManager(bool progressive_, int num_samples_, int2 tile_size_, int start_resolution_,
-                         bool preserve_tile_device_, bool background_, TileOrder tile_order_, int num_devices_)
+                         bool preserve_tile_device_, bool background_, TileOrder tile_order_,
+                         int num_devices_, int pixel_size_)
 {
        progressive = progressive_;
        tile_size = tile_size_;
        tile_order = tile_order_;
        start_resolution = start_resolution_;
+       pixel_size = pixel_size_;
        num_samples = num_samples_;
        num_devices = num_devices_;
        preserve_tile_device = preserve_tile_device_;
@@ -471,7 +473,7 @@ bool TileManager::done()
        int end_sample = (range_num_samples == -1)
                             ? num_samples
                             : range_start_sample + range_num_samples;
-       return (state.resolution_divider == 1) &&
+       return (state.resolution_divider == pixel_size) &&
               (state.sample+state.num_samples >= end_sample);
 }
 
@@ -480,9 +482,9 @@ bool TileManager::next()
        if(done())
                return false;
 
-       if(progressive && state.resolution_divider > 1) {
+       if(progressive && state.resolution_divider > pixel_size) {
                state.sample = 0;
-               state.resolution_divider /= 2;
+               state.resolution_divider = max(state.resolution_divider/2, pixel_size);
                state.num_samples = 1;
                set_tiles();
        }
@@ -496,7 +498,7 @@ bool TileManager::next()
                else
                        state.num_samples = range_num_samples;
 
-               state.resolution_divider = 1;
+               state.resolution_divider = pixel_size;
                set_tiles();
        }
 
index e39a8f0627ad4c04b742efd12d8df41e01caaf7e..4cd57b7b30c8a2e5f5fa3021805ce8d2d2ec53ba 100644 (file)
@@ -88,7 +88,7 @@ public:
        int num_samples;
 
        TileManager(bool progressive, int num_samples, int2 tile_size, int start_resolution,
-                   bool preserve_tile_device, bool background, TileOrder tile_order, int num_devices = 1);
+                   bool preserve_tile_device, bool background, TileOrder tile_order, int num_devices = 1, int pixel_size = 1);
        ~TileManager();
 
        void free_device();
@@ -122,6 +122,7 @@ protected:
        int2 tile_size;
        TileOrder tile_order;
        int start_resolution;
+       int pixel_size;
        int num_devices;
 
        /* in some cases it is important that the same tile will be returned for the same
index a7e8d9273ad969096431c1ccee8aa65cacf88ad6..98aa4057a6eaba217c6cc66127f5c5a7a938ece8 100644 (file)
@@ -275,6 +275,7 @@ class RENDER_PT_performance(RenderButtonsPanel, Panel):
 
         col.separator()
         col.prop(rd, "preview_start_resolution")
+        col.prop(rd, "preview_pixel_size", text="")
 
         col = split.column()
         col.label(text="Memory:")
index f1680b6ccbf755be294b249c24a6daeaec8d94c4..b7ecb85819ea40623167974f3942eeb3613afb83 100644 (file)
@@ -152,6 +152,8 @@ bool BKE_scene_check_rigidbody_active(const struct Scene *scene);
 int BKE_scene_num_threads(const struct Scene *scene);
 int BKE_render_num_threads(const struct RenderData *r);
 
+int BKE_render_preview_pixel_size(const struct RenderData *r);
+
 double BKE_scene_unit_scale(const struct UnitSettings *unit, const int unit_type, double value);
 
 /* multiview */
index b7fc6e70e658debddda68e91d71ec875146a5e60..b8ad54dc533558f58dce58d83d50e1767a8f204d 100644 (file)
@@ -2411,6 +2411,14 @@ int BKE_scene_num_threads(const Scene *scene)
        return BKE_render_num_threads(&scene->r);
 }
 
+int BKE_render_preview_pixel_size(const RenderData *r)
+{
+       if (r->preview_pixel_size == 0) {
+               return (U.pixelsize > 1.5f)? 2 : 1;
+       }
+       return r->preview_pixel_size;
+}
+
 /* Apply the needed correction factor to value, based on unit_type (only length-related are affected currently)
  * and unit->scale_length.
  */
index 9d98a3676ac156e5aacda3d35415626eedcb2417..da14e72f887ef370dace58907bda16fd691999b1 100644 (file)
@@ -1171,7 +1171,7 @@ static void render_update_resolution(Render *re, const RenderPreview *rp,
        }
 
        if (rp->has_freestyle) {
-               if (rp->resolution_divider == 1) {
+               if (rp->resolution_divider == BKE_render_preview_pixel_size(&rp->scene->r)) {
                        RE_ChangeModeFlag(re, R_EDGE_FRS, false);
                }
                else {
@@ -1312,11 +1312,12 @@ static void render_view3d_startjob(void *customdata, short *stop, short *do_upda
                RE_updateRenderInstances(re, ob_inst_update_flag);
 
                for (;;) {
+                       int pixel_size = BKE_render_preview_pixel_size(&rp->scene->r);
                        if (first_time == false) {
                                if (restore)
                                        RE_DataBase_IncrementalView(re, rp->viewmat, 1);
 
-                               rp->resolution_divider /= 2;
+                               rp->resolution_divider = MAX2(rp->resolution_divider/2, pixel_size);
                                *do_update = 1;
 
                                render_update_resolution(re, rp, use_border, &cliprct);
@@ -1333,7 +1334,7 @@ static void render_view3d_startjob(void *customdata, short *stop, short *do_upda
 
                        first_time = false;
 
-                       if (*stop || rp->resolution_divider == 1) {
+                       if (*stop || rp->resolution_divider == pixel_size) {
                                break;
                        }
                }
@@ -1435,7 +1436,7 @@ static void render_view3d_do(RenderEngine *engine, const bContext *C)
        Scene *scene = CTX_data_scene(C);
        ARegion *ar = CTX_wm_region(C);
        int width = ar->winx, height = ar->winy;
-       int divider = 1;
+       int divider = BKE_render_preview_pixel_size(&scene->r);
        int resolution_threshold = scene->r.preview_start_resolution *
                                   scene->r.preview_start_resolution;
 
index 2bca55655530f981e9a7f6f68922416afde1c2d0..de516dc0f1fa2b626b39acc365dc18fa9e7c1b8a 100644 (file)
@@ -790,14 +790,13 @@ typedef struct RenderData {
        struct BakeData bake;
 
        int preview_start_resolution;
+       short preview_pixel_size;
 
        /* Type of the debug pass to use.
         * Only used when built with debug passes support.
         */
        short debug_pass_type;
 
-       short pad;
-
        /* MultiView */
        ListBase views;  /* SceneRenderView */
        short actview;
index c30765d88574f3b2581201abd5ddefe5bcc42bc8..a66c160ed1a3ebbb9491891db8098d45f6e5edb8 100644 (file)
@@ -33,6 +33,8 @@
 #include "BLI_utildefines.h"
 #include "BLI_path_util.h"
 
+#include "BKE_scene.h"
+
 #include "RNA_define.h"
 #include "RNA_enum_types.h"
 
@@ -123,6 +125,11 @@ static int engine_support_display_space_shader(RenderEngine *UNUSED(engine), Sce
        return IMB_colormanagement_support_glsl_draw(&scene->view_settings);
 }
 
+static int engine_get_preview_pixel_size(RenderEngine *UNUSED(engine), Scene *scene)
+{
+       return BKE_render_preview_pixel_size(&scene->r);
+}
+
 static void engine_bind_display_space_shader(RenderEngine *UNUSED(engine), Scene *scene)
 {
        IMB_colormanagement_setup_glsl_draw(&scene->view_settings,
@@ -647,6 +654,13 @@ static void rna_def_render_engine(BlenderRNA *brna)
        parm = RNA_def_boolean(func, "supported", 0, "Supported", "");
        RNA_def_function_return(func, parm);
 
+       func = RNA_def_function(srna, "get_preview_pixel_size", "engine_get_preview_pixel_size");
+       RNA_def_function_ui_description(func, "Get the pixel size that should be used for preview rendering");
+       parm = RNA_def_pointer(func, "scene", "Scene", "", "");
+       RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
+       parm = RNA_def_int(func, "pixel_size", 0, 1, 8, "Pixel Size", "", 1, 8);
+       RNA_def_function_return(func, parm);
+
        RNA_define_verify_sdna(0);
 
        prop = RNA_def_property(srna, "is_animation", PROP_BOOLEAN, PROP_NONE);
index 2722f8759b82d8d202e5c0f40862180fa598a0d4..71350edeb9477c9fe42dec8d3bb102990675acd4 100644 (file)
@@ -1846,6 +1846,13 @@ static void rna_Scene_simplify_update(Main *bmain, Scene *UNUSED(scene), Pointer
                rna_Scene_use_simplify_update(bmain, sce, ptr);
 }
 
+static void rna_SceneRenderData_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
+{
+       Scene *sce = ptr->id.data;
+
+       DAG_id_tag_update(&sce->id, 0);
+}
+
 static void rna_Scene_use_persistent_data_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
 {
        Scene *sce = ptr->id.data;
@@ -5895,6 +5902,15 @@ static void rna_def_scene_render_data(BlenderRNA *brna)
                {0, NULL, 0, NULL, NULL}
        };
        
+       static EnumPropertyItem pixel_size_items[] = {
+               {0, "AUTO", 0, "Automatic", "Automatic pixel size, depends on the UI scale"},
+               {1, "1", 0, "1x", "Render at full resolution"},
+               {2, "2", 0, "2x", "Render at 50% resolution"},
+               {4, "4", 0, "4x", "Render at 25% resolution"},
+               {8, "8", 0, "8x", "Render at 12.5% resolution"},
+               {0, NULL, 0, NULL, NULL}
+       };
+
        static EnumPropertyItem octree_resolution_items[] = {
                {64, "64", 0, "64", ""},
                {128, "128", 0, "128", ""},
@@ -6018,6 +6034,12 @@ static void rna_def_scene_render_data(BlenderRNA *brna)
                                                           "progressively increasing it to the full viewport size");
        RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, NULL);
 
+       prop = RNA_def_property(srna, "preview_pixel_size", PROP_ENUM, PROP_NONE);
+       RNA_def_property_enum_sdna(prop, NULL, "preview_pixel_size");
+       RNA_def_property_enum_items(prop, pixel_size_items);
+       RNA_def_property_ui_text(prop, "Pixel Size", "Pixel size for viewport rendering");
+       RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_SceneRenderData_update");
+
        prop = RNA_def_property(srna, "pixel_aspect_x", PROP_FLOAT, PROP_NONE);
        RNA_def_property_float_sdna(prop, NULL, "xasp");
        RNA_def_property_flag(prop, PROP_PROPORTIONAL);