From c7d18dec70127841db302817b35611f1ee75e3e1 Mon Sep 17 00:00:00 2001 From: lawnjelly Date: Tue, 26 May 2020 14:24:48 +0100 Subject: [PATCH] Rename batching project settings in preparation for GLES3 As it now seems like we will soon have GLES3 batching working using the same intermediate layer as GLES2, it makes more sense to reuse the same batching settings for both renderers rather than duplicate project settings for GLES2 and GLES3. --- doc/classes/ProjectSettings.xml | 56 +++++++++++------------ drivers/gles2/rasterizer_canvas_gles2.cpp | 27 ++++++----- servers/visual_server.cpp | 38 +++++++-------- 3 files changed, 63 insertions(+), 58 deletions(-) diff --git a/doc/classes/ProjectSettings.xml b/doc/classes/ProjectSettings.xml index a9632e4b21dc..3960c22e53a4 100644 --- a/doc/classes/ProjectSettings.xml +++ b/doc/classes/ProjectSettings.xml @@ -970,47 +970,47 @@ Fix to improve physics jitter, specially on monitors where refresh rate is different than the physics FPS. [b]Note:[/b] This property is only read when the project starts. To change the physics FPS at runtime, set [member Engine.physics_jitter_fix] instead. - - Default background clear color. Overridable per [Viewport] using its [Environment]. See [member Environment.background_mode] and [member Environment.background_color] in particular. To change this default color programmatically, use [method VisualServer.set_default_clear_color]. + + When batching is on, this regularly prints a frame diagnosis log. Note that this will degrade performance. - - [Environment] that will be used as a fallback environment in case a scene does not specify its own environment. The default environment is loaded in at scene load time regardless of whether you have set an environment or not. If you do not rely on the fallback environment, it is best to delete [code]default_env.tres[/code], or to specify a different default environment here. + + [b]Experimental[/b] For regression testing against the old renderer. If this is switched on, and [code]use_batching[/code] is set, the renderer will swap alternately between using the old renderer, and the batched renderer, on each frame. This makes it easy to identify visual differences. Performance will be degraded. - - Size of buffer reserved for batched vertices. Larger size enables larger batches, but there are diminishing returns for the memory used. + + Lights have the potential to prevent joining items, and break many of the performance benefits of batching. This setting enables some complex logic to allow joining items if their lighting is similar, and overlap tests pass. This can significantly improve performance in some games. Set to 0 to switch off. With large values the cost of overlap tests may lead to diminishing returns. - - Including color in the vertex format has a cost, however, not including color prevents batching across color changes. This threshold determines the ratio of [code]number of vertex color changes / total number of vertices[/code] above which vertices will be translated to colored format. A value of 0 will always use colored vertices, 1 will never use colored vertices. + + Sets the proportion of the total screen area (in pixels) that must be saved by a scissor operation in order to activate light scissoring. This can prevent parts of items being rendered outside the light area. Lower values scissor more aggressively. A value of 1 scissors none of the items, a value of 0 scissors every item. The power of 4 of the value is used, in order to emphasize the lower range, and multiplied by the total screen area in pixels to give the threshold. This can reduce fill rate requirements in scenes with a lot of lighting. - - In certain circumstances, the batcher can reorder items in order to better join them. This may result in better performance. An overlap test is needed however for each item lookahead, so there is a trade off, with diminishing returns. If you are getting no benefit, setting this to 0 will switch it off. + + Enabling this setting uses the legacy method to draw batches containing only one rect. The legacy method is faster (approx twice as fast), but can cause flicker on some systems. In order to directly compare performance with the non-batching renderer you can set this to true, but it is recommended to turn this off unless you can guarantee your target hardware will work with this method. - - Lights have the potential to prevent joining items, and break many of the performance benefits of batching. This setting enables some complex logic to allow joining items if their lighting is similar, and overlap tests pass. This can significantly improve performance in some games. Set to 0 to switch off. With large values the cost of overlap tests may lead to diminishing returns. + + Turns batching on and off. Batching increases performance by reducing the amount of graphics API drawcalls. - - Sets the proportion of the screen area that must be saved by a scissor operation in order to activate light scissoring. This can prevent parts of items being rendered outside the light area. Lower values scissor more aggressively. A value of 1 scissors none of the items, a value of 0 scissors every item. This can reduce fill rate requirements in scenes with a lot of lighting. + + Switches on batching within the editor. - - Sets the number of commands to lookahead to determine whether to batch render items. A value of 1 can join items consisting of single commands, 0 turns off joining. Higher values are in theory more likely to join, however this has diminishing returns and has a runtime cost so a small value is recommended. + + Size of buffer reserved for batched vertices. Larger size enables larger batches, but there are diminishing returns for the memory used. This should only have a minor effect on performance. - - Enabling this uses the legacy method to draw single rects, which is faster, but can cause flicker on some systems. This is best disabled unless crucial for performance. + + Including color in the vertex format has a cost, however, not including color prevents batching across color changes. This threshold determines the ratio of [code]number of vertex color changes / total number of vertices[/code] above which vertices will be translated to colored format. A value of 0 will always use colored vertices, 1 will never use colored vertices. - - Turns batching on and off. Batching increases performance by reducing the amount of graphics API drawcalls. + + In certain circumstances, the batcher can reorder items in order to better join them. This may result in better performance. An overlap test is needed however for each item lookahead, so there is a trade off, with diminishing returns. If you are getting no benefit, setting this to 0 will switch it off. - - When batching is on, this regularly prints a frame diagnosis log. Note that this will degrade performance. + + Sets the number of commands to lookahead to determine whether to batch render items. A value of 1 can join items consisting of single commands, 0 turns off joining. Higher values are in theory more likely to join, however this has diminishing returns and has a runtime cost so a small value is recommended. - - The use of half-float vertex compression may be producing rendering errors on some platforms (especially iOS). These have been seen particularly in particles. Disabling half-float may resolve these problems. + + Default background clear color. Overridable per [Viewport] using its [Environment]. See [member Environment.background_mode] and [member Environment.background_color] in particular. To change this default color programmatically, use [method VisualServer.set_default_clear_color]. - - [b]Experimental[/b] For regression testing against the old renderer. If this is switched on, and [code]use_batching[/code] is set, the renderer will swap alternately between using the old renderer, and the batched renderer, on each frame. This makes it easy to identify visual differences. Performance will be degraded. + + [Environment] that will be used as a fallback environment in case a scene does not specify its own environment. The default environment is loaded in at scene load time regardless of whether you have set an environment or not. If you do not rely on the fallback environment, it is best to delete [code]default_env.tres[/code], or to specify a different default environment here. - - [b]Experimental[/b] Switches on batching within the editor. Use with caution - note that if your editor does not render correctly you may need to edit your [code]project.godot[/code] and remove the use_batching_in_editor setting manually. + + The use of half-float vertex compression may be producing rendering errors on some platforms (especially iOS). These have been seen particularly in particles. Disabling half-float may resolve these problems. Max buffer size for blend shapes. Any blend shape bigger than this will not work. diff --git a/drivers/gles2/rasterizer_canvas_gles2.cpp b/drivers/gles2/rasterizer_canvas_gles2.cpp index 5735ba3af00e..b5ea3c993f9c 100644 --- a/drivers/gles2/rasterizer_canvas_gles2.cpp +++ b/drivers/gles2/rasterizer_canvas_gles2.cpp @@ -3339,30 +3339,35 @@ void RasterizerCanvasGLES2::_calculate_scissor_threshold_area() { void RasterizerCanvasGLES2::initialize() { RasterizerCanvasBaseGLES2::initialize(); - bdata.settings_use_batching = GLOBAL_GET("rendering/gles2/batching/use_batching"); - bdata.settings_max_join_item_commands = GLOBAL_GET("rendering/gles2/batching/max_join_item_commands"); - bdata.settings_colored_vertex_format_threshold = GLOBAL_GET("rendering/gles2/batching/colored_vertex_format_threshold"); - bdata.settings_item_reordering_lookahead = GLOBAL_GET("rendering/gles2/batching/item_reordering_lookahead"); - bdata.settings_light_max_join_items = GLOBAL_GET("rendering/gles2/batching/light_max_join_items"); - bdata.settings_use_single_rect_fallback = GLOBAL_GET("rendering/gles2/batching/single_rect_fallback"); + bdata.settings_use_batching = GLOBAL_GET("rendering/batching/options/use_batching"); + bdata.settings_max_join_item_commands = GLOBAL_GET("rendering/batching/parameters/max_join_item_commands"); + bdata.settings_colored_vertex_format_threshold = GLOBAL_GET("rendering/batching/parameters/colored_vertex_format_threshold"); + bdata.settings_item_reordering_lookahead = GLOBAL_GET("rendering/batching/parameters/item_reordering_lookahead"); + bdata.settings_light_max_join_items = GLOBAL_GET("rendering/batching/lights/max_join_items"); + bdata.settings_use_single_rect_fallback = GLOBAL_GET("rendering/batching/options/single_rect_fallback"); // we can use the threshold to determine whether to turn scissoring off or on - bdata.settings_scissor_threshold = GLOBAL_GET("rendering/gles2/batching/light_scissor_area_threshold"); + bdata.settings_scissor_threshold = GLOBAL_GET("rendering/batching/lights/scissor_area_threshold"); if (bdata.settings_scissor_threshold > 0.999f) { bdata.settings_scissor_lights = false; } else { bdata.settings_scissor_lights = true; + + // apply power of 4 relationship for the area, as most of the important changes + // will be happening at low values of scissor threshold + bdata.settings_scissor_threshold *= bdata.settings_scissor_threshold; + bdata.settings_scissor_threshold *= bdata.settings_scissor_threshold; } // The sweet spot on my desktop for cache is actually smaller than the max, and this // is the default. This saves memory too so we will use it for now, needs testing to see whether this varies according // to device / platform. - bdata.settings_batch_buffer_num_verts = GLOBAL_GET("rendering/gles2/batching/batch_buffer_size"); + bdata.settings_batch_buffer_num_verts = GLOBAL_GET("rendering/batching/parameters/batch_buffer_size"); // override the use_batching setting in the editor // (note that if the editor can't start, you can't change the use_batching project setting!) if (Engine::get_singleton()->is_editor_hint()) { - bool use_in_editor = GLOBAL_GET("rendering/gles2/debug/use_batching_in_editor"); + bool use_in_editor = GLOBAL_GET("rendering/batching/options/use_batching_in_editor"); bdata.settings_use_batching = use_in_editor; // fix some settings in the editor, as the performance not worth the risk @@ -3383,7 +3388,7 @@ void RasterizerCanvasGLES2::initialize() { // This should not be used except during development. // make a note of the original choice in case we are flashing on and off the batching bdata.settings_use_batching_original_choice = bdata.settings_use_batching; - bdata.settings_flash_batching = GLOBAL_GET("rendering/gles2/debug/flash_batching"); + bdata.settings_flash_batching = GLOBAL_GET("rendering/batching/debug/flash_batching"); if (!bdata.settings_use_batching) { // no flash when batching turned off bdata.settings_flash_batching = false; @@ -3392,7 +3397,7 @@ void RasterizerCanvasGLES2::initialize() { // frame diagnosis. print out the batches every nth frame bdata.settings_diagnose_frame = false; if (!Engine::get_singleton()->is_editor_hint() && bdata.settings_use_batching) { - bdata.settings_diagnose_frame = GLOBAL_GET("rendering/gles2/debug/diagnose_frame"); + bdata.settings_diagnose_frame = GLOBAL_GET("rendering/batching/debug/diagnose_frame"); } // the maximum num quads in a batch is limited by GLES2. We can have only 16 bit indices, diff --git a/servers/visual_server.cpp b/servers/visual_server.cpp index 444131f8531b..e9d7793ae20c 100644 --- a/servers/visual_server.cpp +++ b/servers/visual_server.cpp @@ -2419,25 +2419,25 @@ VisualServer::VisualServer() { GLOBAL_DEF("rendering/quality/filters/use_nearest_mipmap_filter", false); - GLOBAL_DEF("rendering/gles2/batching/use_batching", true); - GLOBAL_DEF("rendering/gles2/batching/max_join_item_commands", 16); - GLOBAL_DEF("rendering/gles2/batching/colored_vertex_format_threshold", 0.25f); - GLOBAL_DEF("rendering/gles2/batching/light_scissor_area_threshold", 1.0f); - GLOBAL_DEF("rendering/gles2/batching/light_max_join_items", 32); - GLOBAL_DEF("rendering/gles2/batching/batch_buffer_size", 16384); - GLOBAL_DEF("rendering/gles2/batching/item_reordering_lookahead", 4); - GLOBAL_DEF("rendering/gles2/batching/single_rect_fallback", false); - GLOBAL_DEF("rendering/gles2/debug/flash_batching", false); - GLOBAL_DEF("rendering/gles2/debug/diagnose_frame", false); - GLOBAL_DEF_RST("rendering/gles2/debug/use_batching_in_editor", true); - GLOBAL_DEF("rendering/gles2/debug/disable_half_float", false); - - ProjectSettings::get_singleton()->set_custom_property_info("rendering/gles2/batching/max_join_item_commands", PropertyInfo(Variant::INT, "rendering/gles2/batching/max_join_item_commands", PROPERTY_HINT_RANGE, "0,65535")); - ProjectSettings::get_singleton()->set_custom_property_info("rendering/gles2/batching/colored_vertex_format_threshold", PropertyInfo(Variant::REAL, "rendering/gles2/batching/colored_vertex_format_threshold", PROPERTY_HINT_RANGE, "0.0,1.0,0.01")); - ProjectSettings::get_singleton()->set_custom_property_info("rendering/gles2/batching/batch_buffer_size", PropertyInfo(Variant::INT, "rendering/gles2/batching/batch_buffer_size", PROPERTY_HINT_RANGE, "1024,65535,1024")); - ProjectSettings::get_singleton()->set_custom_property_info("rendering/gles2/batching/light_scissor_area_threshold", PropertyInfo(Variant::REAL, "rendering/gles2/batching/light_scissor_area_threshold", PROPERTY_HINT_RANGE, "0.0,1.0")); - ProjectSettings::get_singleton()->set_custom_property_info("rendering/gles2/batching/light_max_join_items", PropertyInfo(Variant::INT, "rendering/gles2/batching/light_max_join_items", PROPERTY_HINT_RANGE, "0,512")); - ProjectSettings::get_singleton()->set_custom_property_info("rendering/gles2/batching/item_reordering_lookahead", PropertyInfo(Variant::INT, "rendering/gles2/batching/item_reordering_lookahead", PROPERTY_HINT_RANGE, "0,256")); + GLOBAL_DEF("rendering/batching/options/use_batching", true); + GLOBAL_DEF_RST("rendering/batching/options/use_batching_in_editor", true); + GLOBAL_DEF("rendering/batching/options/single_rect_fallback", false); + GLOBAL_DEF("rendering/batching/parameters/max_join_item_commands", 16); + GLOBAL_DEF("rendering/batching/parameters/colored_vertex_format_threshold", 0.25f); + GLOBAL_DEF("rendering/batching/lights/scissor_area_threshold", 1.0f); + GLOBAL_DEF("rendering/batching/lights/max_join_items", 32); + GLOBAL_DEF("rendering/batching/parameters/batch_buffer_size", 16384); + GLOBAL_DEF("rendering/batching/parameters/item_reordering_lookahead", 4); + GLOBAL_DEF("rendering/batching/debug/flash_batching", false); + GLOBAL_DEF("rendering/batching/debug/diagnose_frame", false); + GLOBAL_DEF("rendering/gles2/compatibility/disable_half_float", false); + + ProjectSettings::get_singleton()->set_custom_property_info("rendering/batching/parameters/max_join_item_commands", PropertyInfo(Variant::INT, "rendering/batching/parameters/max_join_item_commands", PROPERTY_HINT_RANGE, "0,65535")); + ProjectSettings::get_singleton()->set_custom_property_info("rendering/batching/parameters/colored_vertex_format_threshold", PropertyInfo(Variant::REAL, "rendering/batching/parameters/colored_vertex_format_threshold", PROPERTY_HINT_RANGE, "0.0,1.0,0.01")); + ProjectSettings::get_singleton()->set_custom_property_info("rendering/batching/parameters/batch_buffer_size", PropertyInfo(Variant::INT, "rendering/batching/parameters/batch_buffer_size", PROPERTY_HINT_RANGE, "1024,65535,1024")); + ProjectSettings::get_singleton()->set_custom_property_info("rendering/batching/lights/scissor_area_threshold", PropertyInfo(Variant::REAL, "rendering/batching/lights/scissor_area_threshold", PROPERTY_HINT_RANGE, "0.0,1.0")); + ProjectSettings::get_singleton()->set_custom_property_info("rendering/batching/lights/max_join_items", PropertyInfo(Variant::INT, "rendering/batching/lights/max_join_items", PROPERTY_HINT_RANGE, "0,512")); + ProjectSettings::get_singleton()->set_custom_property_info("rendering/batching/parameters/item_reordering_lookahead", PropertyInfo(Variant::INT, "rendering/batching/parameters/item_reordering_lookahead", PROPERTY_HINT_RANGE, "0,256")); } VisualServer::~VisualServer() {