diff options
author | RĂ©mi Verschelde <remi@verschelde.fr> | 2021-08-11 15:19:11 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-11 15:19:11 +0200 |
commit | 62047e4e4848e511a5f4e0aa84bc4f512f075f8d (patch) | |
tree | 71333e70a1f14cf19178e84481daa2d3c51882ed /servers | |
parent | a57d420224e1d2ac40281e81e1300184a8ce9902 (diff) | |
parent | ca117910da682fbff6b8d75aef5c958049d25e44 (diff) |
Merge pull request #51486 from reduz/fixes-to-mobile-renderer
Fixes and optimizations to mobile renderer
Diffstat (limited to 'servers')
5 files changed, 51 insertions, 46 deletions
diff --git a/servers/rendering/renderer_rd/forward_mobile/render_forward_mobile.cpp b/servers/rendering/renderer_rd/forward_mobile/render_forward_mobile.cpp index dea2975660..f810ae2454 100644 --- a/servers/rendering/renderer_rd/forward_mobile/render_forward_mobile.cpp +++ b/servers/rendering/renderer_rd/forward_mobile/render_forward_mobile.cpp @@ -519,7 +519,7 @@ void RenderForwardMobile::_render_scene(RenderDataRD *p_render_data, const Color using_subpass_post_process = false; } - if (scene_state.used_screen_texture || scene_state.used_depth_texture) { + if (using_ssr || using_sss || scene_state.used_screen_texture || scene_state.used_depth_texture) { // can't use our last two subpasses using_subpass_transparent = false; using_subpass_post_process = false; @@ -679,17 +679,20 @@ void RenderForwardMobile::_render_scene(RenderDataRD *p_render_data, const Color _setup_environment(p_render_data, p_render_data->reflection_probe.is_valid(), screen_size, !p_render_data->reflection_probe.is_valid(), p_default_bg_color, p_render_data->render_buffers.is_valid()); - RENDER_TIMESTAMP("Render Opaque Subpass"); + if (using_subpass_transparent && using_subpass_post_process) { + RENDER_TIMESTAMP("Render Opaque + Transparent + Tonemap"); + } else if (using_subpass_transparent) { + RENDER_TIMESTAMP("Render Opaque + Transparent"); + } else { + RENDER_TIMESTAMP("Render Opaque"); + } RID rp_uniform_set = _setup_render_pass_uniform_set(RENDER_LIST_OPAQUE, p_render_data, radiance_texture, true); - bool can_continue_color = !scene_state.used_screen_texture && !using_ssr && !using_sss; - bool can_continue_depth = !scene_state.used_depth_texture && !using_ssr && !using_sss; + bool can_continue_color = !using_subpass_transparent && !scene_state.used_screen_texture && !using_ssr && !using_sss; + bool can_continue_depth = !using_subpass_transparent && !scene_state.used_depth_texture && !using_ssr && !using_sss; { - bool will_continue_color = (can_continue_color || draw_sky || draw_sky_fog_only); - bool will_continue_depth = (can_continue_depth || draw_sky || draw_sky_fog_only); - // regular forward for now Vector<Color> c; c.push_back(clear_color.to_linear()); // our render buffer @@ -709,11 +712,11 @@ void RenderForwardMobile::_render_scene(RenderDataRD *p_render_data, const Color // secondary command buffers need more testing at this time //multi threaded thread_draw_lists.resize(RendererThreadPool::singleton->thread_work_pool.get_thread_count()); - RD::get_singleton()->draw_list_begin_split(framebuffer, thread_draw_lists.size(), thread_draw_lists.ptr(), keep_color ? RD::INITIAL_ACTION_KEEP : RD::INITIAL_ACTION_CLEAR, will_continue_color ? RD::FINAL_ACTION_CONTINUE : RD::FINAL_ACTION_READ, RD::INITIAL_ACTION_CLEAR, will_continue_depth ? RD::FINAL_ACTION_CONTINUE : RD::FINAL_ACTION_READ, c, 1.0, 0); + RD::get_singleton()->draw_list_begin_split(framebuffer, thread_draw_lists.size(), thread_draw_lists.ptr(), keep_color ? RD::INITIAL_ACTION_KEEP : RD::INITIAL_ACTION_CLEAR, can_continue_color ? RD::FINAL_ACTION_CONTINUE : RD::FINAL_ACTION_READ, RD::INITIAL_ACTION_CLEAR, can_continue_depth ? RD::FINAL_ACTION_CONTINUE : RD::FINAL_ACTION_READ, c, 1.0, 0); RendererThreadPool::singleton->thread_work_pool.do_work(thread_draw_lists.size(), this, &RenderForwardMobile::_render_list_thread_function, &render_list_params); } else { //single threaded - RD::DrawListID draw_list = RD::get_singleton()->draw_list_begin(framebuffer, keep_color ? RD::INITIAL_ACTION_KEEP : RD::INITIAL_ACTION_CLEAR, will_continue_color ? RD::FINAL_ACTION_CONTINUE : RD::FINAL_ACTION_READ, RD::INITIAL_ACTION_CLEAR, will_continue_depth ? RD::FINAL_ACTION_CONTINUE : RD::FINAL_ACTION_READ, c, 1.0, 0); + RD::DrawListID draw_list = RD::get_singleton()->draw_list_begin(framebuffer, keep_color ? RD::INITIAL_ACTION_KEEP : RD::INITIAL_ACTION_CLEAR, can_continue_color ? RD::FINAL_ACTION_CONTINUE : RD::FINAL_ACTION_READ, RD::INITIAL_ACTION_CLEAR, can_continue_depth ? RD::FINAL_ACTION_CONTINUE : RD::FINAL_ACTION_READ, c, 1.0, 0); _render_list(draw_list, fb_format, &render_list_params, 0, render_list_params.element_count); } } @@ -721,8 +724,6 @@ void RenderForwardMobile::_render_scene(RenderDataRD *p_render_data, const Color RD::get_singleton()->draw_command_end_label(); //Render Opaque Subpass if (draw_sky || draw_sky_fog_only) { - RENDER_TIMESTAMP("Render Sky Subpass"); - RD::get_singleton()->draw_command_begin_label("Draw Sky Subpass"); RD::DrawListID draw_list = RD::get_singleton()->draw_list_switch_to_next_pass(); @@ -752,7 +753,6 @@ void RenderForwardMobile::_render_scene(RenderDataRD *p_render_data, const Color } // transparent pass - RENDER_TIMESTAMP("Render Transparent Subpass"); RD::get_singleton()->draw_command_begin_label("Render Transparent Subpass"); @@ -789,6 +789,8 @@ void RenderForwardMobile::_render_scene(RenderDataRD *p_render_data, const Color RD::get_singleton()->draw_list_end(RD::BARRIER_MASK_ALL); } else { + RENDER_TIMESTAMP("Render Transparent"); + framebuffer = render_buffer->color_fbs[FB_CONFIG_ONE_PASS]; // this may be needed if we re-introduced steps that change info, not sure which do so in the previous implementation diff --git a/servers/rendering/renderer_rd/renderer_scene_render_rd.cpp b/servers/rendering/renderer_rd/renderer_scene_render_rd.cpp index 5b734fc603..fd797b1cab 100644 --- a/servers/rendering/renderer_rd/renderer_scene_render_rd.cpp +++ b/servers/rendering/renderer_rd/renderer_scene_render_rd.cpp @@ -2010,7 +2010,6 @@ void RendererSceneRenderRD::_post_process_subpass(RID p_source_texture, RID p_fr bool can_use_effects = rb->width >= 8 && rb->height >= 8; - RENDER_TIMESTAMP("Tonemap"); RD::DrawListID draw_list = RD::get_singleton()->draw_list_switch_to_next_pass(); EffectsRD::TonemapSettings tonemap; diff --git a/servers/rendering/renderer_rd/shaders/light_data_inc.glsl b/servers/rendering/renderer_rd/shaders/light_data_inc.glsl index 2fce258cff..9155216d7e 100644 --- a/servers/rendering/renderer_rd/shaders/light_data_inc.glsl +++ b/servers/rendering/renderer_rd/shaders/light_data_inc.glsl @@ -3,7 +3,7 @@ #define LIGHT_BAKE_STATIC 2 struct LightData { //this structure needs to be as packed as possible - vec3 position; + highp vec3 position; float inv_radius; vec3 direction; @@ -17,8 +17,8 @@ struct LightData { //this structure needs to be as packed as possible float specular_amount; bool shadow_enabled; - vec4 atlas_rect; // rect in the shadow atlas - mat4 shadow_matrix; + highp vec4 atlas_rect; // rect in the shadow atlas + highp mat4 shadow_matrix; float shadow_bias; float shadow_normal_bias; float transmittance_bias; @@ -27,7 +27,7 @@ struct LightData { //this structure needs to be as packed as possible uint mask; float shadow_volumetric_fog_fade; uint bake_mode; - vec4 projector_rect; //projector rect in srgb decal atlas + highp vec4 projector_rect; //projector rect in srgb decal atlas }; #define REFLECTION_AMBIENT_DISABLED 0 @@ -69,13 +69,13 @@ struct DirectionalLightData { vec4 shadow_bias; vec4 shadow_normal_bias; vec4 shadow_transmittance_bias; - vec4 shadow_z_range; - vec4 shadow_range_begin; + highp vec4 shadow_z_range; + highp vec4 shadow_range_begin; vec4 shadow_split_offsets; - mat4 shadow_matrix1; - mat4 shadow_matrix2; - mat4 shadow_matrix3; - mat4 shadow_matrix4; + highp mat4 shadow_matrix1; + highp mat4 shadow_matrix2; + highp mat4 shadow_matrix3; + highp mat4 shadow_matrix4; vec4 shadow_color1; vec4 shadow_color2; vec4 shadow_color3; diff --git a/servers/rendering/renderer_rd/shaders/scene_forward_mobile.glsl b/servers/rendering/renderer_rd/shaders/scene_forward_mobile.glsl index 681656e1d5..2babe92c1c 100644 --- a/servers/rendering/renderer_rd/shaders/scene_forward_mobile.glsl +++ b/servers/rendering/renderer_rd/shaders/scene_forward_mobile.glsl @@ -59,27 +59,27 @@ layout(location = 11) in vec4 weight_attrib; /* Varyings */ -layout(location = 0) out vec3 vertex_interp; +layout(location = 0) highp out vec3 vertex_interp; #ifdef NORMAL_USED -layout(location = 1) out vec3 normal_interp; +layout(location = 1) mediump out vec3 normal_interp; #endif #if defined(COLOR_USED) -layout(location = 2) out vec4 color_interp; +layout(location = 2) mediump out vec4 color_interp; #endif #ifdef UV_USED -layout(location = 3) out vec2 uv_interp; +layout(location = 3) mediump out vec2 uv_interp; #endif #if defined(UV2_USED) || defined(USE_LIGHTMAP) -layout(location = 4) out vec2 uv2_interp; +layout(location = 4) mediump out vec2 uv2_interp; #endif #if defined(TANGENT_USED) || defined(NORMAL_MAP_USED) || defined(LIGHT_ANISOTROPY_USED) -layout(location = 5) out vec3 tangent_interp; -layout(location = 6) out vec3 binormal_interp; +layout(location = 5) mediump out vec3 tangent_interp; +layout(location = 6) mediump out vec3 binormal_interp; #endif #ifdef MATERIAL_UNIFORMS_USED @@ -370,6 +370,10 @@ void main() { #VERSION_DEFINES +//use medium precision for floats on mobile. + +precision mediump float; + /* Specialization Constants */ /* Specialization Constants (Toggles) */ @@ -395,32 +399,32 @@ layout(constant_id = 11) const bool sc_projector_use_mipmaps = true; /* Varyings */ -layout(location = 0) in vec3 vertex_interp; +layout(location = 0) highp in vec3 vertex_interp; #ifdef NORMAL_USED -layout(location = 1) in vec3 normal_interp; +layout(location = 1) mediump in vec3 normal_interp; #endif #if defined(COLOR_USED) -layout(location = 2) in vec4 color_interp; +layout(location = 2) mediump in vec4 color_interp; #endif #ifdef UV_USED -layout(location = 3) in vec2 uv_interp; +layout(location = 3) mediump in vec2 uv_interp; #endif #if defined(UV2_USED) || defined(USE_LIGHTMAP) -layout(location = 4) in vec2 uv2_interp; +layout(location = 4) mediump in vec2 uv2_interp; #endif #if defined(TANGENT_USED) || defined(NORMAL_MAP_USED) || defined(LIGHT_ANISOTROPY_USED) -layout(location = 5) in vec3 tangent_interp; -layout(location = 6) in vec3 binormal_interp; +layout(location = 5) mediump in vec3 tangent_interp; +layout(location = 6) mediump in vec3 binormal_interp; #endif #ifdef MODE_DUAL_PARABOLOID -layout(location = 8) in float dp_clip; +layout(location = 8) highp in float dp_clip; #endif diff --git a/servers/rendering/renderer_rd/shaders/scene_forward_mobile_inc.glsl b/servers/rendering/renderer_rd/shaders/scene_forward_mobile_inc.glsl index d9682d7b23..f1e554d01c 100644 --- a/servers/rendering/renderer_rd/shaders/scene_forward_mobile_inc.glsl +++ b/servers/rendering/renderer_rd/shaders/scene_forward_mobile_inc.glsl @@ -16,12 +16,12 @@ /* don't exceed 128 bytes!! */ /* put instance data into our push content, not a array */ layout(push_constant, binding = 0, std430) uniform DrawCall { - mat4 transform; // 64 - 64 + highp mat4 transform; // 64 - 64 uint flags; // 04 - 68 uint instance_uniforms_ofs; //base offset in global buffer for instance variables // 04 - 72 uint gi_offset; //GI information when using lightmapping (VCT or lightmap index) // 04 - 76 uint layer_mask; // 04 - 80 - vec4 lightmap_uv_scale; // 16 - 96 doubles as uv_offset when needed + highp vec4 lightmap_uv_scale; // 16 - 96 doubles as uv_offset when needed uvec2 reflection_probes; // 08 - 104 uvec2 omni_lights; // 08 - 112 @@ -126,14 +126,14 @@ global_variables; /* Set 1: Render Pass (changes per render pass) */ layout(set = 1, binding = 0, std140) uniform SceneData { - mat4 projection_matrix; - mat4 inv_projection_matrix; - mat4 camera_matrix; - mat4 inv_camera_matrix; + highp mat4 projection_matrix; + highp mat4 inv_projection_matrix; + highp mat4 camera_matrix; + highp mat4 inv_camera_matrix; // only used for multiview - mat4 projection_matrix_view[MAX_VIEWS]; - mat4 inv_projection_matrix_view[MAX_VIEWS]; + highp mat4 projection_matrix_view[MAX_VIEWS]; + highp mat4 inv_projection_matrix_view[MAX_VIEWS]; vec2 viewport_size; vec2 screen_pixel_size; |