diff options
Diffstat (limited to 'servers')
57 files changed, 587 insertions, 890 deletions
diff --git a/servers/audio/effects/eq.h b/servers/audio/effects/eq.h index 74280ee22e..d6293bf875 100644 --- a/servers/audio/effects/eq.h +++ b/servers/audio/effects/eq.h @@ -28,18 +28,12 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -// Author: reduzio@gmail.com (C) 2006 - #ifndef EQ_FILTER_H #define EQ_FILTER_H #include "core/templates/vector.h" #include "core/typedefs.h" -/** -@author Juan Linietsky -*/ - class EQ { public: enum Preset { @@ -105,4 +99,4 @@ inline void EQ::BandProcess::process_one(float &p_data) { history.b2 = history.b1; } -#endif +#endif // EQ_FILTER_H diff --git a/servers/audio/effects/reverb.h b/servers/audio/effects/reverb.h index fa06d262a3..ff59ab8d82 100644 --- a/servers/audio/effects/reverb.h +++ b/servers/audio/effects/reverb.h @@ -28,8 +28,6 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -// Author: Juan Linietsky <reduzio@gmail.com>, (C) 2006 - #ifndef REVERB_H #define REVERB_H @@ -120,4 +118,4 @@ public: ~Reverb(); }; -#endif +#endif // REVERB_H diff --git a/servers/camera/camera_feed.h b/servers/camera/camera_feed.h index ea66c5f947..e86605a89b 100644 --- a/servers/camera/camera_feed.h +++ b/servers/camera/camera_feed.h @@ -37,8 +37,6 @@ #include "servers/rendering_server.h" /** - @author Bastiaan Olij <mux213@gmail.com> - The camera server is a singleton object that gives access to the various camera feeds that can be used as the background for our environment. **/ @@ -111,4 +109,4 @@ public: VARIANT_ENUM_CAST(CameraFeed::FeedDataType); VARIANT_ENUM_CAST(CameraFeed::FeedPosition); -#endif /* !CAMERA_FEED_H */ +#endif // CAMERA_FEED_H diff --git a/servers/camera_server.h b/servers/camera_server.h index 893fdba912..b70938c34f 100644 --- a/servers/camera_server.h +++ b/servers/camera_server.h @@ -38,8 +38,6 @@ #include "core/variant/variant.h" /** - @author Bastiaan Olij <mux213@gmail.com> - The camera server is a singleton object that gives access to the various camera feeds that can be used as the background for our environment. **/ @@ -113,4 +111,4 @@ public: VARIANT_ENUM_CAST(CameraServer::FeedImage); -#endif /* CAMERA_SERVER_H */ +#endif // CAMERA_SERVER_H diff --git a/servers/display_server.cpp b/servers/display_server.cpp index 01f58e37eb..e9f15ab535 100644 --- a/servers/display_server.cpp +++ b/servers/display_server.cpp @@ -228,14 +228,6 @@ String DisplayServer::ime_get_text() const { ERR_FAIL_V_MSG(String(), "IME or NOTIFICATION_WM_IME_UPDATEnot supported by this display server."); } -void DisplayServer::console_set_visible(bool p_enabled) { - WARN_PRINT("Console window not supported by this display server."); -} - -bool DisplayServer::is_console_visible() const { - return false; -} - void DisplayServer::virtual_keyboard_show(const String &p_existing_text, const Rect2 &p_screen_rect, bool p_multiline, int p_max_length, int p_cursor_start, int p_cursor_end) { WARN_PRINT("Virtual keyboard not supported by this display server."); } @@ -446,9 +438,6 @@ void DisplayServer::_bind_methods() { ClassDB::bind_method(D_METHOD("ime_get_selection"), &DisplayServer::ime_get_selection); ClassDB::bind_method(D_METHOD("ime_get_text"), &DisplayServer::ime_get_text); - ClassDB::bind_method(D_METHOD("console_set_visible", "console_visible"), &DisplayServer::console_set_visible); - ClassDB::bind_method(D_METHOD("is_console_visible"), &DisplayServer::is_console_visible); - ClassDB::bind_method(D_METHOD("virtual_keyboard_show", "existing_text", "position", "multiline", "max_length", "cursor_start", "cursor_end"), &DisplayServer::virtual_keyboard_show, DEFVAL(Rect2i()), DEFVAL(false), DEFVAL(-1), DEFVAL(-1), DEFVAL(-1)); ClassDB::bind_method(D_METHOD("virtual_keyboard_hide"), &DisplayServer::virtual_keyboard_hide); @@ -493,7 +482,6 @@ void DisplayServer::_bind_methods() { BIND_ENUM_CONSTANT(FEATURE_CURSOR_SHAPE); BIND_ENUM_CONSTANT(FEATURE_CUSTOM_CURSOR_SHAPE); BIND_ENUM_CONSTANT(FEATURE_NATIVE_DIALOG); - BIND_ENUM_CONSTANT(FEATURE_CONSOLE_WINDOW); BIND_ENUM_CONSTANT(FEATURE_IME); BIND_ENUM_CONSTANT(FEATURE_WINDOW_TRANSPARENCY); BIND_ENUM_CONSTANT(FEATURE_HIDPI); diff --git a/servers/display_server.h b/servers/display_server.h index a84290be77..d896572b88 100644 --- a/servers/display_server.h +++ b/servers/display_server.h @@ -105,7 +105,6 @@ public: FEATURE_CURSOR_SHAPE, FEATURE_CUSTOM_CURSOR_SHAPE, FEATURE_NATIVE_DIALOG, - FEATURE_CONSOLE_WINDOW, FEATURE_IME, FEATURE_WINDOW_TRANSPARENCY, FEATURE_HIDPI, @@ -304,9 +303,6 @@ public: virtual Point2i ime_get_selection() const; virtual String ime_get_text() const; - virtual void console_set_visible(bool p_enabled); - virtual bool is_console_visible() const; - virtual void virtual_keyboard_show(const String &p_existing_text, const Rect2 &p_screen_rect = Rect2(), bool p_multiline = false, int p_max_length = -1, int p_cursor_start = -1, int p_cursor_end = -1); virtual void virtual_keyboard_hide(); diff --git a/servers/navigation_server_2d.cpp b/servers/navigation_server_2d.cpp index c4c10ebf3b..ee196673a3 100644 --- a/servers/navigation_server_2d.cpp +++ b/servers/navigation_server_2d.cpp @@ -29,14 +29,11 @@ /*************************************************************************/ #include "servers/navigation_server_2d.h" + #include "core/math/transform_2d.h" #include "core/math/transform_3d.h" #include "servers/navigation_server_3d.h" -/** - @author AndreaCatania -*/ - NavigationServer2D *NavigationServer2D::singleton = nullptr; #define FORWARD_0_C(FUNC_NAME) \ @@ -204,7 +201,7 @@ void NavigationServer2D::_bind_methods() { NavigationServer2D::NavigationServer2D() { singleton = this; ERR_FAIL_COND_MSG(!NavigationServer3D::get_singleton(), "The Navigation3D singleton should be initialized before the 2D one."); - NavigationServer3D::get_singleton()->connect("map_changed", callable_mp(this, &NavigationServer2D::_emit_map_changed)); + NavigationServer3D::get_singleton_mut()->connect("map_changed", callable_mp(this, &NavigationServer2D::_emit_map_changed)); } NavigationServer2D::~NavigationServer2D() { diff --git a/servers/navigation_server_2d.h b/servers/navigation_server_2d.h index 8ab479b8fd..7350eeb5b1 100644 --- a/servers/navigation_server_2d.h +++ b/servers/navigation_server_2d.h @@ -28,12 +28,8 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -/** - @author AndreaCatania -*/ - -#ifndef NAVIGATION_2D_SERVER_H -#define NAVIGATION_2D_SERVER_H +#ifndef NAVIGATION_SERVER_2D_H +#define NAVIGATION_SERVER_2D_H #include "core/object/class_db.h" #include "core/templates/rid.h" @@ -52,7 +48,7 @@ protected: public: /// Thread safe, can be used across many threads. - static NavigationServer2D *get_singleton() { return singleton; } + static const NavigationServer2D *get_singleton() { return singleton; } /// MUST be used in single thread! static NavigationServer2D *get_singleton_mut() { return singleton; } @@ -171,4 +167,4 @@ public: virtual ~NavigationServer2D(); }; -#endif +#endif // NAVIGATION_SERVER_2D_H diff --git a/servers/navigation_server_3d.cpp b/servers/navigation_server_3d.cpp index 03c75369a6..d18777869a 100644 --- a/servers/navigation_server_3d.cpp +++ b/servers/navigation_server_3d.cpp @@ -28,10 +28,6 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -/** - @author AndreaCatania -*/ - #include "navigation_server_3d.h" NavigationServer3D *NavigationServer3D::singleton = nullptr; @@ -84,7 +80,7 @@ void NavigationServer3D::_bind_methods() { ADD_SIGNAL(MethodInfo("map_changed", PropertyInfo(Variant::RID, "map"))); } -NavigationServer3D *NavigationServer3D::get_singleton() { +const NavigationServer3D *NavigationServer3D::get_singleton() { return singleton; } diff --git a/servers/navigation_server_3d.h b/servers/navigation_server_3d.h index c70d87ec16..0a75b07931 100644 --- a/servers/navigation_server_3d.h +++ b/servers/navigation_server_3d.h @@ -28,12 +28,8 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -/** - @author AndreaCatania -*/ - -#ifndef NAVIGATION_SERVER_H -#define NAVIGATION_SERVER_H +#ifndef NAVIGATION_SERVER_3D_H +#define NAVIGATION_SERVER_3D_H #include "core/object/class_db.h" #include "core/templates/rid.h" @@ -55,7 +51,7 @@ protected: public: /// Thread safe, can be used across many threads. - static NavigationServer3D *get_singleton(); + static const NavigationServer3D *get_singleton(); /// MUST be used in single thread! static NavigationServer3D *get_singleton_mut(); @@ -205,4 +201,4 @@ public: static NavigationServer3D *new_default_server(); }; -#endif +#endif // NAVIGATION_SERVER_3D_H diff --git a/servers/rendering/rasterizer_dummy.h b/servers/rendering/rasterizer_dummy.h index f02a01c97d..83da8388e4 100644 --- a/servers/rendering/rasterizer_dummy.h +++ b/servers/rendering/rasterizer_dummy.h @@ -120,7 +120,7 @@ public: void environment_set_ssil(RID p_env, bool p_enable, float p_radius, float p_intensity, float p_sharpness, float p_normal_rejection) override {} void environment_set_ssil_quality(RS::EnvironmentSSILQuality p_quality, bool p_half_size, float p_adaptive_target, int p_blur_passes, float p_fadeout_from, float p_fadeout_to) override {} - void environment_set_sdfgi(RID p_env, bool p_enable, RS::EnvironmentSDFGICascades p_cascades, float p_min_cell_size, RS::EnvironmentSDFGIYScale p_y_scale, bool p_use_occlusion, float p_bounce_feedback, bool p_read_sky, float p_energy, float p_normal_bias, float p_probe_bias) override {} + void environment_set_sdfgi(RID p_env, bool p_enable, int p_cascades, float p_min_cell_size, RS::EnvironmentSDFGIYScale p_y_scale, bool p_use_occlusion, float p_bounce_feedback, bool p_read_sky, float p_energy, float p_normal_bias, float p_probe_bias) override {} void environment_set_sdfgi_ray_count(RS::EnvironmentSDFGIRayCount p_ray_count) override {} void environment_set_sdfgi_frames_to_converge(RS::EnvironmentSDFGIFramesToConverge p_frames) override {} diff --git a/servers/rendering/renderer_canvas_cull.cpp b/servers/rendering/renderer_canvas_cull.cpp index 02af3c6eb9..418d2bc42e 100644 --- a/servers/rendering/renderer_canvas_cull.cpp +++ b/servers/rendering/renderer_canvas_cull.cpp @@ -261,6 +261,10 @@ void RendererCanvasCull::_cull_canvas_item(Item *p_canvas_item, const Transform2 if (ci->clip) { if (p_canvas_clip != nullptr) { ci->final_clip_rect = p_canvas_clip->final_clip_rect.intersection(global_rect); + if (ci->final_clip_rect == Rect2()) { + // Clip rects do not intersect, so don't draw this item. + return; + } } else { ci->final_clip_rect = global_rect; } @@ -1436,7 +1440,7 @@ void RendererCanvasCull::canvas_light_occluder_set_polygon(RID p_occluder, RID p ERR_FAIL_COND(!occluder); if (occluder->polygon.is_valid()) { - LightOccluderPolygon *occluder_poly = canvas_light_occluder_polygon_owner.get_or_null(p_polygon); + LightOccluderPolygon *occluder_poly = canvas_light_occluder_polygon_owner.get_or_null(occluder->polygon); if (occluder_poly) { occluder_poly->owners.erase(occluder); } diff --git a/servers/rendering/renderer_rd/effects_rd.cpp b/servers/rendering/renderer_rd/effects_rd.cpp index 4a19519995..4ab50782df 100644 --- a/servers/rendering/renderer_rd/effects_rd.cpp +++ b/servers/rendering/renderer_rd/effects_rd.cpp @@ -446,7 +446,7 @@ void EffectsRD::set_color(RID p_dest_texture, const Color &p_color, const Rect2i } void EffectsRD::gaussian_blur(RID p_source_rd_texture, RID p_texture, RID p_back_texture, const Rect2i &p_region, bool p_8bit_dst) { - ERR_FAIL_COND_MSG(!prefer_raster_effects, "Can't use the compute version of the gaussian blur with the mobile renderer."); + ERR_FAIL_COND_MSG(prefer_raster_effects, "Can't use the compute version of the gaussian blur with the mobile renderer."); memset(©.push_constant, 0, sizeof(CopyPushConstant)); diff --git a/servers/rendering/renderer_rd/effects_rd.h b/servers/rendering/renderer_rd/effects_rd.h index 747f2c8941..a3fb4db3df 100644 --- a/servers/rendering/renderer_rd/effects_rd.h +++ b/servers/rendering/renderer_rd/effects_rd.h @@ -728,7 +728,6 @@ private: uint8_t metallic_mask[4]; float projection[16]; - float prev_projection[16]; }; struct ScreenSpaceReflection { diff --git a/servers/rendering/renderer_rd/forward_clustered/render_forward_clustered.cpp b/servers/rendering/renderer_rd/forward_clustered/render_forward_clustered.cpp index cd7b2622ab..36604073cc 100644 --- a/servers/rendering/renderer_rd/forward_clustered/render_forward_clustered.cpp +++ b/servers/rendering/renderer_rd/forward_clustered/render_forward_clustered.cpp @@ -1795,12 +1795,14 @@ void RenderForwardClustered::_render_material(const Transform3D &p_cam_transform { RenderListParameters render_list_params(render_list[RENDER_LIST_SECONDARY].elements.ptr(), render_list[RENDER_LIST_SECONDARY].element_info.ptr(), render_list[RENDER_LIST_SECONDARY].elements.size(), true, pass_mode, true, false, rp_uniform_set); //regular forward for now - Vector<Color> clear; - clear.push_back(Color(0, 0, 0, 0)); - clear.push_back(Color(0, 0, 0, 0)); - clear.push_back(Color(0, 0, 0, 0)); - clear.push_back(Color(0, 0, 0, 0)); - clear.push_back(Color(0, 0, 0, 0)); + Vector<Color> clear = { + Color(0, 0, 0, 0), + Color(0, 0, 0, 0), + Color(0, 0, 0, 0), + Color(0, 0, 0, 0), + Color(0, 0, 0, 0) + }; + RD::DrawListID draw_list = RD::get_singleton()->draw_list_begin(p_framebuffer, RD::INITIAL_ACTION_CLEAR, RD::FINAL_ACTION_READ, RD::INITIAL_ACTION_CLEAR, RD::FINAL_ACTION_READ, clear, 1.0, 0, p_region); _render_list(draw_list, RD::get_singleton()->framebuffer_get_format(p_framebuffer), &render_list_params, 0, render_list_params.element_count); RD::get_singleton()->draw_list_end(); @@ -1839,12 +1841,13 @@ void RenderForwardClustered::_render_uv2(const PagedArray<GeometryInstance *> &p { RenderListParameters render_list_params(render_list[RENDER_LIST_SECONDARY].elements.ptr(), render_list[RENDER_LIST_SECONDARY].element_info.ptr(), render_list[RENDER_LIST_SECONDARY].elements.size(), true, pass_mode, true, false, rp_uniform_set, true); //regular forward for now - Vector<Color> clear; - clear.push_back(Color(0, 0, 0, 0)); - clear.push_back(Color(0, 0, 0, 0)); - clear.push_back(Color(0, 0, 0, 0)); - clear.push_back(Color(0, 0, 0, 0)); - clear.push_back(Color(0, 0, 0, 0)); + Vector<Color> clear = { + Color(0, 0, 0, 0), + Color(0, 0, 0, 0), + Color(0, 0, 0, 0), + Color(0, 0, 0, 0), + Color(0, 0, 0, 0) + }; RD::DrawListID draw_list = RD::get_singleton()->draw_list_begin(p_framebuffer, RD::INITIAL_ACTION_CLEAR, RD::FINAL_ACTION_READ, RD::INITIAL_ACTION_CLEAR, RD::FINAL_ACTION_READ, clear, 1.0, 0, p_region); const int uv_offset_count = 9; @@ -1901,11 +1904,12 @@ void RenderForwardClustered::_render_sdfgi(RID p_render_buffers, const Vector3i Vector3 half_extents = p_bounds.size * 0.5; Vector3 center = p_bounds.position + half_extents; - Vector<RID> sbs; - sbs.push_back(p_albedo_texture); - sbs.push_back(p_emission_texture); - sbs.push_back(p_emission_aniso_texture); - sbs.push_back(p_geom_facing_texture); + Vector<RID> sbs = { + p_albedo_texture, + p_emission_texture, + p_emission_aniso_texture, + p_geom_facing_texture + }; //print_line("re-render " + p_from + " - " + p_size + " bounds " + p_bounds); for (int i = 0; i < 3; i++) { diff --git a/servers/rendering/renderer_rd/forward_clustered/scene_shader_forward_clustered.cpp b/servers/rendering/renderer_rd/forward_clustered/scene_shader_forward_clustered.cpp index 942e78e1ff..a27ea75017 100644 --- a/servers/rendering/renderer_rd/forward_clustered/scene_shader_forward_clustered.cpp +++ b/servers/rendering/renderer_rd/forward_clustered/scene_shader_forward_clustered.cpp @@ -48,7 +48,7 @@ void SceneShaderForwardClustered::ShaderData::set_code(const String &p_code) { return; //just invalid, but no error } - ShaderCompilerRD::GeneratedCode gen_code; + ShaderCompiler::GeneratedCode gen_code; int blend_mode = BLEND_MODE_MIX; int depth_testi = DEPTH_TEST_ENABLED; @@ -79,10 +79,10 @@ void SceneShaderForwardClustered::ShaderData::set_code(const String &p_code) { int depth_drawi = DEPTH_DRAW_OPAQUE; - ShaderCompilerRD::IdentifierActions actions; - actions.entry_point_stages["vertex"] = ShaderCompilerRD::STAGE_VERTEX; - actions.entry_point_stages["fragment"] = ShaderCompilerRD::STAGE_FRAGMENT; - actions.entry_point_stages["light"] = ShaderCompilerRD::STAGE_FRAGMENT; + ShaderCompiler::IdentifierActions actions; + actions.entry_point_stages["vertex"] = ShaderCompiler::STAGE_VERTEX; + actions.entry_point_stages["fragment"] = ShaderCompiler::STAGE_FRAGMENT; + actions.entry_point_stages["light"] = ShaderCompiler::STAGE_FRAGMENT; actions.render_mode_values["blend_add"] = Pair<int *, int>(&blend_mode, BLEND_MODE_ADD); actions.render_mode_values["blend_mix"] = Pair<int *, int>(&blend_mode, BLEND_MODE_MIX); @@ -157,10 +157,10 @@ void SceneShaderForwardClustered::ShaderData::set_code(const String &p_code) { } print_line("\n**uniforms:\n" + gen_code.uniforms); - print_line("\n**vertex_globals:\n" + gen_code.stage_globals[ShaderCompilerRD::STAGE_VERTEX]); - print_line("\n**fragment_globals:\n" + gen_code.stage_globals[ShaderCompilerRD::STAGE_FRAGMENT]); + print_line("\n**vertex_globals:\n" + gen_code.stage_globals[ShaderCompiler::STAGE_VERTEX]); + print_line("\n**fragment_globals:\n" + gen_code.stage_globals[ShaderCompiler::STAGE_FRAGMENT]); #endif - shader_singleton->shader.version_set_code(version, gen_code.code, gen_code.uniforms, gen_code.stage_globals[ShaderCompilerRD::STAGE_VERTEX], gen_code.stage_globals[ShaderCompilerRD::STAGE_FRAGMENT], gen_code.defines); + shader_singleton->shader.version_set_code(version, gen_code.code, gen_code.uniforms, gen_code.stage_globals[ShaderCompiler::STAGE_VERTEX], gen_code.stage_globals[ShaderCompiler::STAGE_FRAGMENT], gen_code.defines); ERR_FAIL_COND(!shader_singleton->shader.version_is_valid(version)); ubo_size = gen_code.uniform_total_size; @@ -510,7 +510,7 @@ void SceneShaderForwardClustered::init(RendererStorageRD *p_storage, const Strin { //shader compiler - ShaderCompilerRD::DefaultIdentifierActions actions; + ShaderCompiler::DefaultIdentifierActions actions; actions.renames["WORLD_MATRIX"] = "world_matrix"; actions.renames["WORLD_NORMAL_MATRIX"] = "world_normal_matrix"; diff --git a/servers/rendering/renderer_rd/forward_clustered/scene_shader_forward_clustered.h b/servers/rendering/renderer_rd/forward_clustered/scene_shader_forward_clustered.h index 98448ce846..8e7bbad63e 100644 --- a/servers/rendering/renderer_rd/forward_clustered/scene_shader_forward_clustered.h +++ b/servers/rendering/renderer_rd/forward_clustered/scene_shader_forward_clustered.h @@ -129,7 +129,7 @@ public: String path; Map<StringName, ShaderLanguage::ShaderNode::Uniform> uniforms; - Vector<ShaderCompilerRD::GeneratedCode::Texture> texture_uniforms; + Vector<ShaderCompiler::GeneratedCode::Texture> texture_uniforms; Vector<uint32_t> ubo_offsets; uint32_t ubo_size; @@ -208,7 +208,7 @@ public: } SceneForwardClusteredShaderRD shader; - ShaderCompilerRD compiler; + ShaderCompiler compiler; RID default_shader; RID default_material; 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 8b2a60c487..b9c51f5461 100644 --- a/servers/rendering/renderer_rd/forward_mobile/render_forward_mobile.cpp +++ b/servers/rendering/renderer_rd/forward_mobile/render_forward_mobile.cpp @@ -1002,12 +1002,13 @@ void RenderForwardMobile::_render_material(const Transform3D &p_cam_transform, c { RenderListParameters render_list_params(render_list[RENDER_LIST_SECONDARY].elements.ptr(), render_list[RENDER_LIST_SECONDARY].element_info.ptr(), render_list[RENDER_LIST_SECONDARY].elements.size(), true, pass_mode, rp_uniform_set, 0); //regular forward for now - Vector<Color> clear; - clear.push_back(Color(0, 0, 0, 0)); - clear.push_back(Color(0, 0, 0, 0)); - clear.push_back(Color(0, 0, 0, 0)); - clear.push_back(Color(0, 0, 0, 0)); - clear.push_back(Color(0, 0, 0, 0)); + Vector<Color> clear = { + Color(0, 0, 0, 0), + Color(0, 0, 0, 0), + Color(0, 0, 0, 0), + Color(0, 0, 0, 0), + Color(0, 0, 0, 0) + }; RD::DrawListID draw_list = RD::get_singleton()->draw_list_begin(p_framebuffer, RD::INITIAL_ACTION_CLEAR, RD::FINAL_ACTION_READ, RD::INITIAL_ACTION_CLEAR, RD::FINAL_ACTION_READ, clear, 1.0, 0, p_region); _render_list(draw_list, RD::get_singleton()->framebuffer_get_format(p_framebuffer), &render_list_params, 0, render_list_params.element_count); RD::get_singleton()->draw_list_end(); @@ -1043,12 +1044,14 @@ void RenderForwardMobile::_render_uv2(const PagedArray<GeometryInstance *> &p_in { RenderListParameters render_list_params(render_list[RENDER_LIST_SECONDARY].elements.ptr(), render_list[RENDER_LIST_SECONDARY].element_info.ptr(), render_list[RENDER_LIST_SECONDARY].elements.size(), true, pass_mode, rp_uniform_set, true, 0); //regular forward for now - Vector<Color> clear; - clear.push_back(Color(0, 0, 0, 0)); - clear.push_back(Color(0, 0, 0, 0)); - clear.push_back(Color(0, 0, 0, 0)); - clear.push_back(Color(0, 0, 0, 0)); - clear.push_back(Color(0, 0, 0, 0)); + Vector<Color> clear = { + Color(0, 0, 0, 0), + Color(0, 0, 0, 0), + Color(0, 0, 0, 0), + Color(0, 0, 0, 0), + Color(0, 0, 0, 0) + }; + RD::DrawListID draw_list = RD::get_singleton()->draw_list_begin(p_framebuffer, RD::INITIAL_ACTION_CLEAR, RD::FINAL_ACTION_READ, RD::INITIAL_ACTION_CLEAR, RD::FINAL_ACTION_READ, clear, 1.0, 0, p_region); const int uv_offset_count = 9; diff --git a/servers/rendering/renderer_rd/forward_mobile/scene_shader_forward_mobile.cpp b/servers/rendering/renderer_rd/forward_mobile/scene_shader_forward_mobile.cpp index b0cc26340d..1613a307ec 100644 --- a/servers/rendering/renderer_rd/forward_mobile/scene_shader_forward_mobile.cpp +++ b/servers/rendering/renderer_rd/forward_mobile/scene_shader_forward_mobile.cpp @@ -51,7 +51,7 @@ void SceneShaderForwardMobile::ShaderData::set_code(const String &p_code) { return; //just invalid, but no error } - ShaderCompilerRD::GeneratedCode gen_code; + ShaderCompiler::GeneratedCode gen_code; int blend_mode = BLEND_MODE_MIX; int depth_testi = DEPTH_TEST_ENABLED; @@ -81,10 +81,10 @@ void SceneShaderForwardMobile::ShaderData::set_code(const String &p_code) { int depth_drawi = DEPTH_DRAW_OPAQUE; - ShaderCompilerRD::IdentifierActions actions; - actions.entry_point_stages["vertex"] = ShaderCompilerRD::STAGE_VERTEX; - actions.entry_point_stages["fragment"] = ShaderCompilerRD::STAGE_FRAGMENT; - actions.entry_point_stages["light"] = ShaderCompilerRD::STAGE_FRAGMENT; + ShaderCompiler::IdentifierActions actions; + actions.entry_point_stages["vertex"] = ShaderCompiler::STAGE_VERTEX; + actions.entry_point_stages["fragment"] = ShaderCompiler::STAGE_FRAGMENT; + actions.entry_point_stages["light"] = ShaderCompiler::STAGE_FRAGMENT; actions.render_mode_values["blend_add"] = Pair<int *, int>(&blend_mode, BLEND_MODE_ADD); actions.render_mode_values["blend_mix"] = Pair<int *, int>(&blend_mode, BLEND_MODE_MIX); @@ -159,11 +159,11 @@ void SceneShaderForwardMobile::ShaderData::set_code(const String &p_code) { } print_line("\n**uniforms:\n" + gen_code.uniforms); - print_line("\n**vertex_globals:\n" + gen_code.stage_globals[ShaderCompilerRD::STAGE_VERTEX]); - print_line("\n**fragment_globals:\n" + gen_code.stage_globals[ShaderCompilerRD::STAGE_FRAGMENT]); + print_line("\n**vertex_globals:\n" + gen_code.stage_globals[ShaderCompiler::STAGE_VERTEX]); + print_line("\n**fragment_globals:\n" + gen_code.stage_globals[ShaderCompiler::STAGE_FRAGMENT]); #endif - shader_singleton->shader.version_set_code(version, gen_code.code, gen_code.uniforms, gen_code.stage_globals[ShaderCompilerRD::STAGE_VERTEX], gen_code.stage_globals[ShaderCompilerRD::STAGE_FRAGMENT], gen_code.defines); + shader_singleton->shader.version_set_code(version, gen_code.code, gen_code.uniforms, gen_code.stage_globals[ShaderCompiler::STAGE_VERTEX], gen_code.stage_globals[ShaderCompiler::STAGE_FRAGMENT], gen_code.defines); ERR_FAIL_COND(!shader_singleton->shader.version_is_valid(version)); ubo_size = gen_code.uniform_total_size; @@ -498,7 +498,7 @@ void SceneShaderForwardMobile::init(RendererStorageRD *p_storage, const String p { //shader compiler - ShaderCompilerRD::DefaultIdentifierActions actions; + ShaderCompiler::DefaultIdentifierActions actions; actions.renames["WORLD_MATRIX"] = "world_matrix"; actions.renames["WORLD_NORMAL_MATRIX"] = "world_normal_matrix"; diff --git a/servers/rendering/renderer_rd/forward_mobile/scene_shader_forward_mobile.h b/servers/rendering/renderer_rd/forward_mobile/scene_shader_forward_mobile.h index 770f9bde3b..c136afd9f3 100644 --- a/servers/rendering/renderer_rd/forward_mobile/scene_shader_forward_mobile.h +++ b/servers/rendering/renderer_rd/forward_mobile/scene_shader_forward_mobile.h @@ -105,7 +105,7 @@ public: String path; Map<StringName, ShaderLanguage::ShaderNode::Uniform> uniforms; - Vector<ShaderCompilerRD::GeneratedCode::Texture> texture_uniforms; + Vector<ShaderCompiler::GeneratedCode::Texture> texture_uniforms; Vector<uint32_t> ubo_offsets; uint32_t ubo_size; @@ -184,7 +184,7 @@ public: } SceneForwardMobileShaderRD shader; - ShaderCompilerRD compiler; + ShaderCompiler compiler; RID default_shader; RID default_material; diff --git a/servers/rendering/renderer_rd/renderer_canvas_render_rd.cpp b/servers/rendering/renderer_rd/renderer_canvas_render_rd.cpp index da75c70cbb..7e188926e0 100644 --- a/servers/rendering/renderer_rd/renderer_canvas_render_rd.cpp +++ b/servers/rendering/renderer_rd/renderer_canvas_render_rd.cpp @@ -1957,15 +1957,15 @@ void RendererCanvasRenderRD::ShaderData::set_code(const String &p_code) { return; //just invalid, but no error } - ShaderCompilerRD::GeneratedCode gen_code; + ShaderCompiler::GeneratedCode gen_code; int blend_mode = BLEND_MODE_MIX; uses_screen_texture = false; - ShaderCompilerRD::IdentifierActions actions; - actions.entry_point_stages["vertex"] = ShaderCompilerRD::STAGE_VERTEX; - actions.entry_point_stages["fragment"] = ShaderCompilerRD::STAGE_FRAGMENT; - actions.entry_point_stages["light"] = ShaderCompilerRD::STAGE_FRAGMENT; + ShaderCompiler::IdentifierActions actions; + actions.entry_point_stages["vertex"] = ShaderCompiler::STAGE_VERTEX; + actions.entry_point_stages["fragment"] = ShaderCompiler::STAGE_FRAGMENT; + actions.entry_point_stages["light"] = ShaderCompiler::STAGE_FRAGMENT; actions.render_mode_values["blend_add"] = Pair<int *, int>(&blend_mode, BLEND_MODE_ADD); actions.render_mode_values["blend_mix"] = Pair<int *, int>(&blend_mode, BLEND_MODE_MIX); @@ -2002,7 +2002,7 @@ void RendererCanvasRenderRD::ShaderData::set_code(const String &p_code) { print_line("\n**fragment_code:\n" + gen_code.fragment); print_line("\n**light_code:\n" + gen_code.light); #endif - canvas_singleton->shader.canvas_shader.version_set_code(version, gen_code.code, gen_code.uniforms, gen_code.stage_globals[ShaderCompilerRD::STAGE_VERTEX], gen_code.stage_globals[ShaderCompilerRD::STAGE_FRAGMENT], gen_code.defines); + canvas_singleton->shader.canvas_shader.version_set_code(version, gen_code.code, gen_code.uniforms, gen_code.stage_globals[ShaderCompiler::STAGE_VERTEX], gen_code.stage_globals[ShaderCompiler::STAGE_FRAGMENT], gen_code.defines); ERR_FAIL_COND(!canvas_singleton->shader.canvas_shader.version_is_valid(version)); ubo_size = gen_code.uniform_total_size; @@ -2359,7 +2359,7 @@ RendererCanvasRenderRD::RendererCanvasRenderRD(RendererStorageRD *p_storage) { { //shader compiler - ShaderCompilerRD::DefaultIdentifierActions actions; + ShaderCompiler::DefaultIdentifierActions actions; actions.renames["VERTEX"] = "vertex"; actions.renames["LIGHT_VERTEX"] = "light_vertex"; diff --git a/servers/rendering/renderer_rd/renderer_canvas_render_rd.h b/servers/rendering/renderer_rd/renderer_canvas_render_rd.h index c9544a5239..b409264c9a 100644 --- a/servers/rendering/renderer_rd/renderer_canvas_render_rd.h +++ b/servers/rendering/renderer_rd/renderer_canvas_render_rd.h @@ -35,10 +35,10 @@ #include "servers/rendering/renderer_compositor.h" #include "servers/rendering/renderer_rd/pipeline_cache_rd.h" #include "servers/rendering/renderer_rd/renderer_storage_rd.h" -#include "servers/rendering/renderer_rd/shader_compiler_rd.h" #include "servers/rendering/renderer_rd/shaders/canvas.glsl.gen.h" #include "servers/rendering/renderer_rd/shaders/canvas_occlusion.glsl.gen.h" #include "servers/rendering/rendering_device.h" +#include "servers/rendering/shader_compiler.h" class RendererCanvasRenderRD : public RendererCanvasRender { RendererStorageRD *storage; @@ -148,7 +148,7 @@ class RendererCanvasRenderRD : public RendererCanvasRender { RID default_skeleton_uniform_buffer; RID default_skeleton_texture_buffer; - ShaderCompilerRD compiler; + ShaderCompiler compiler; } shader; struct ShaderData : public RendererStorageRD::ShaderData { @@ -167,7 +167,7 @@ class RendererCanvasRenderRD : public RendererCanvasRender { String path; Map<StringName, ShaderLanguage::ShaderNode::Uniform> uniforms; - Vector<ShaderCompilerRD::GeneratedCode::Texture> texture_uniforms; + Vector<ShaderCompiler::GeneratedCode::Texture> texture_uniforms; Vector<uint32_t> ubo_offsets; uint32_t ubo_size; diff --git a/servers/rendering/renderer_rd/renderer_scene_environment_rd.cpp b/servers/rendering/renderer_rd/renderer_scene_environment_rd.cpp index 7ea117ef33..0d0d7513d0 100644 --- a/servers/rendering/renderer_rd/renderer_scene_environment_rd.cpp +++ b/servers/rendering/renderer_rd/renderer_scene_environment_rd.cpp @@ -68,7 +68,7 @@ void RendererSceneEnvironmentRD::set_glow(bool p_enable, Vector<float> p_levels, glow_hdr_luminance_cap = p_hdr_luminance_cap; } -void RendererSceneEnvironmentRD::set_sdfgi(bool p_enable, RS::EnvironmentSDFGICascades p_cascades, float p_min_cell_size, RS::EnvironmentSDFGIYScale p_y_scale, bool p_use_occlusion, float p_bounce_feedback, bool p_read_sky, float p_energy, float p_normal_bias, float p_probe_bias) { +void RendererSceneEnvironmentRD::set_sdfgi(bool p_enable, int p_cascades, float p_min_cell_size, RS::EnvironmentSDFGIYScale p_y_scale, bool p_use_occlusion, float p_bounce_feedback, bool p_read_sky, float p_energy, float p_normal_bias, float p_probe_bias) { sdfgi_enabled = p_enable; sdfgi_cascades = p_cascades; sdfgi_min_cell_size = p_min_cell_size; diff --git a/servers/rendering/renderer_rd/renderer_scene_environment_rd.h b/servers/rendering/renderer_rd/renderer_scene_environment_rd.h index 9e36a61870..629d224b49 100644 --- a/servers/rendering/renderer_rd/renderer_scene_environment_rd.h +++ b/servers/rendering/renderer_rd/renderer_scene_environment_rd.h @@ -133,7 +133,7 @@ public: /// SDFGI bool sdfgi_enabled = false; - RS::EnvironmentSDFGICascades sdfgi_cascades; + int sdfgi_cascades = 6; float sdfgi_min_cell_size = 0.2; bool sdfgi_use_occlusion = false; float sdfgi_bounce_feedback = 0.0; @@ -155,7 +155,7 @@ public: void set_ambient_light(const Color &p_color, RS::EnvironmentAmbientSource p_ambient, float p_energy, float p_sky_contribution, RS::EnvironmentReflectionSource p_reflection_source); void set_tonemap(RS::EnvironmentToneMapper p_tone_mapper, float p_exposure, float p_white, bool p_auto_exposure, float p_min_luminance, float p_max_luminance, float p_auto_exp_speed, float p_auto_exp_scale); void set_glow(bool p_enable, Vector<float> p_levels, float p_intensity, float p_strength, float p_mix, float p_bloom_threshold, RS::EnvironmentGlowBlendMode p_blend_mode, float p_hdr_bleed_threshold, float p_hdr_bleed_scale, float p_hdr_luminance_cap); - void set_sdfgi(bool p_enable, RS::EnvironmentSDFGICascades p_cascades, float p_min_cell_size, RS::EnvironmentSDFGIYScale p_y_scale, bool p_use_occlusion, float p_bounce_feedback, bool p_read_sky, float p_energy, float p_normal_bias, float p_probe_bias); + void set_sdfgi(bool p_enable, int p_cascades, float p_min_cell_size, RS::EnvironmentSDFGIYScale p_y_scale, bool p_use_occlusion, float p_bounce_feedback, bool p_read_sky, float p_energy, float p_normal_bias, float p_probe_bias); void set_fog(bool p_enable, const Color &p_light_color, float p_light_energy, float p_sun_scatter, float p_density, float p_height, float p_height_density, float p_fog_aerial_perspective); void set_volumetric_fog(bool p_enable, float p_density, const Color &p_scatterin, const Color &p_emission, float p_emission_energy, float p_anisotropy, float p_length, float p_detail_spread, float p_gi_inject, bool p_temporal_reprojection, float p_temporal_reprojection_amount, float p_ambient_inject); void set_ssr(bool p_enable, int p_max_steps, float p_fade_int, float p_fade_out, float p_depth_tolerance); diff --git a/servers/rendering/renderer_rd/renderer_scene_gi_rd.cpp b/servers/rendering/renderer_rd/renderer_scene_gi_rd.cpp index 73cb088f6a..3069b1c379 100644 --- a/servers/rendering/renderer_rd/renderer_scene_gi_rd.cpp +++ b/servers/rendering/renderer_rd/renderer_scene_gi_rd.cpp @@ -42,14 +42,13 @@ const Vector3i RendererSceneGIRD::SDFGI::Cascade::DIRTY_ALL = Vector3i(0x7FFFFFF void RendererSceneGIRD::SDFGI::create(RendererSceneEnvironmentRD *p_env, const Vector3 &p_world_position, uint32_t p_requested_history_size, RendererSceneGIRD *p_gi) { storage = p_gi->storage; gi = p_gi; - cascade_mode = p_env->sdfgi_cascades; + num_cascades = p_env->sdfgi_cascades; min_cell_size = p_env->sdfgi_min_cell_size; uses_occlusion = p_env->sdfgi_use_occlusion; y_scale_mode = p_env->sdfgi_y_scale; static const float y_scale[3] = { 1.0, 1.5, 2.0 }; y_mult = y_scale[y_scale_mode]; - static const int cascasde_size[3] = { 4, 6, 8 }; - cascades.resize(cascasde_size[cascade_mode]); + cascades.resize(num_cascades); probe_axis_count = SDFGI::PROBE_DIVISOR + 1; solid_cell_ratio = gi->sdfgi_solid_cell_ratio; solid_cell_count = uint32_t(float(cascade_size * cascade_size * cascade_size) * solid_cell_ratio); @@ -716,7 +715,10 @@ void RendererSceneGIRD::SDFGI::create(RendererSceneEnvironmentRD *p_env, const V u.uniform_type = RD::UNIFORM_TYPE_IMAGE; u.binding = 13; RID parent_average; - if (i < cascades.size() - 1) { + if (cascades.size() == 1) { + // If there is only one SDFGI cascade, we can't use the previous cascade for blending. + parent_average = cascades[i].lightprobe_average_tex; + } else if (i < cascades.size() - 1) { parent_average = cascades[i + 1].lightprobe_average_tex; } else { parent_average = cascades[i - 1].lightprobe_average_tex; //to use something, but it won't be used diff --git a/servers/rendering/renderer_rd/renderer_scene_gi_rd.h b/servers/rendering/renderer_rd/renderer_scene_gi_rd.h index a407199d0a..5e55262798 100644 --- a/servers/rendering/renderer_rd/renderer_scene_gi_rd.h +++ b/servers/rendering/renderer_rd/renderer_scene_gi_rd.h @@ -495,7 +495,7 @@ public: float solid_cell_ratio = 0; uint32_t solid_cell_count = 0; - RS::EnvironmentSDFGICascades cascade_mode; + int num_cascades = 6; float min_cell_size = 0; uint32_t probe_axis_count = 0; //amount of probes per axis, this is an odd number because it encloses endpoints diff --git a/servers/rendering/renderer_rd/renderer_scene_render_rd.cpp b/servers/rendering/renderer_rd/renderer_scene_render_rd.cpp index 7af4f0e849..3a01c3377a 100644 --- a/servers/rendering/renderer_rd/renderer_scene_render_rd.cpp +++ b/servers/rendering/renderer_rd/renderer_scene_render_rd.cpp @@ -65,7 +65,7 @@ void RendererSceneRenderRD::sdfgi_update(RID p_render_buffers, RID p_environment static const uint32_t history_frames_to_converge[RS::ENV_SDFGI_CONVERGE_MAX] = { 5, 10, 15, 20, 25, 30 }; uint32_t requested_history_size = history_frames_to_converge[gi.sdfgi_frames_to_converge]; - if (rb->sdfgi && (rb->sdfgi->cascade_mode != env->sdfgi_cascades || rb->sdfgi->min_cell_size != env->sdfgi_min_cell_size || requested_history_size != rb->sdfgi->history_size || rb->sdfgi->uses_occlusion != env->sdfgi_use_occlusion || rb->sdfgi->y_scale_mode != env->sdfgi_y_scale)) { + if (rb->sdfgi && (rb->sdfgi->num_cascades != env->sdfgi_cascades || rb->sdfgi->min_cell_size != env->sdfgi_min_cell_size || requested_history_size != rb->sdfgi->history_size || rb->sdfgi->uses_occlusion != env->sdfgi_use_occlusion || rb->sdfgi->y_scale_mode != env->sdfgi_y_scale)) { //configuration changed, erase rb->sdfgi->erase(); memdelete(rb->sdfgi); @@ -303,7 +303,7 @@ void RendererSceneRenderRD::environment_glow_set_use_high_quality(bool p_enable) glow_high_quality = p_enable; } -void RendererSceneRenderRD::environment_set_sdfgi(RID p_env, bool p_enable, RS::EnvironmentSDFGICascades p_cascades, float p_min_cell_size, RS::EnvironmentSDFGIYScale p_y_scale, bool p_use_occlusion, float p_bounce_feedback, bool p_read_sky, float p_energy, float p_normal_bias, float p_probe_bias) { +void RendererSceneRenderRD::environment_set_sdfgi(RID p_env, bool p_enable, int p_cascades, float p_min_cell_size, RS::EnvironmentSDFGIYScale p_y_scale, bool p_use_occlusion, float p_bounce_feedback, bool p_read_sky, float p_energy, float p_normal_bias, float p_probe_bias) { RendererSceneEnvironmentRD *env = environment_owner.get_or_null(p_env); ERR_FAIL_COND(!env); @@ -545,11 +545,7 @@ Ref<Image> RendererSceneRenderRD::environment_bake_panorama(RID p_env, bool p_ba Ref<Image> panorama; panorama.instantiate(); panorama->create(p_size.width, p_size.height, false, Image::FORMAT_RGBAF); - for (int x = 0; x < p_size.width; x++) { - for (int y = 0; y < p_size.height; y++) { - panorama->set_pixel(x, y, panorama_color); - } - } + panorama->fill(panorama_color); return panorama; } @@ -3841,9 +3837,9 @@ void RendererSceneRenderRD::FogShaderData::set_code(const String &p_code) { return; //just invalid, but no error } - ShaderCompilerRD::GeneratedCode gen_code; - ShaderCompilerRD::IdentifierActions actions; - actions.entry_point_stages["fog"] = ShaderCompilerRD::STAGE_COMPUTE; + ShaderCompiler::GeneratedCode gen_code; + ShaderCompiler::IdentifierActions actions; + actions.entry_point_stages["fog"] = ShaderCompiler::STAGE_COMPUTE; uses_time = false; @@ -3860,7 +3856,7 @@ void RendererSceneRenderRD::FogShaderData::set_code(const String &p_code) { version = scene_singleton->volumetric_fog.shader.version_create(); } - scene_singleton->volumetric_fog.shader.version_set_compute_code(version, gen_code.code, gen_code.uniforms, gen_code.stage_globals[ShaderCompilerRD::STAGE_COMPUTE], gen_code.defines); + scene_singleton->volumetric_fog.shader.version_set_compute_code(version, gen_code.code, gen_code.uniforms, gen_code.stage_globals[ShaderCompiler::STAGE_COMPUTE], gen_code.defines); ERR_FAIL_COND(!scene_singleton->volumetric_fog.shader.version_is_valid(version)); ubo_size = gen_code.uniform_total_size; @@ -4015,6 +4011,9 @@ void RendererSceneRenderRD::_volumetric_fog_erase(RenderBuffers *rb) { RD::get_singleton()->free(rb->volumetric_fog->prev_light_density_map); RD::get_singleton()->free(rb->volumetric_fog->light_density_map); RD::get_singleton()->free(rb->volumetric_fog->fog_map); + RD::get_singleton()->free(rb->volumetric_fog->density_map); + RD::get_singleton()->free(rb->volumetric_fog->light_map); + RD::get_singleton()->free(rb->volumetric_fog->emissive_map); if (rb->volumetric_fog->fog_uniform_set.is_valid() && RD::get_singleton()->uniform_set_is_valid(rb->volumetric_fog->fog_uniform_set)) { RD::get_singleton()->free(rb->volumetric_fog->fog_uniform_set); @@ -5657,7 +5656,7 @@ void RendererSceneRenderRD::init() { } { - ShaderCompilerRD::DefaultIdentifierActions actions; + ShaderCompiler::DefaultIdentifierActions actions; actions.renames["TIME"] = "scene_params.time"; actions.renames["PI"] = _MKSTR(Math_PI); diff --git a/servers/rendering/renderer_rd/renderer_scene_render_rd.h b/servers/rendering/renderer_rd/renderer_scene_render_rd.h index b8a088d041..08e084f5cc 100644 --- a/servers/rendering/renderer_rd/renderer_scene_render_rd.h +++ b/servers/rendering/renderer_rd/renderer_scene_render_rd.h @@ -834,7 +834,7 @@ private: float transform[16]; }; - ShaderCompilerRD compiler; + ShaderCompiler compiler; VolumetricFogShaderRD shader; FogPushConstant push_constant; RID volume_ubo; @@ -917,7 +917,7 @@ private: RID pipeline; Map<StringName, ShaderLanguage::ShaderNode::Uniform> uniforms; - Vector<ShaderCompilerRD::GeneratedCode::Texture> texture_uniforms; + Vector<ShaderCompiler::GeneratedCode::Texture> texture_uniforms; Vector<uint32_t> ubo_offsets; uint32_t ubo_size; @@ -1093,7 +1093,7 @@ public: bool environment_is_ssr_enabled(RID p_env) const; bool environment_is_sdfgi_enabled(RID p_env) const; - virtual void environment_set_sdfgi(RID p_env, bool p_enable, RS::EnvironmentSDFGICascades p_cascades, float p_min_cell_size, RS::EnvironmentSDFGIYScale p_y_scale, bool p_use_occlusion, float p_bounce_feedback, bool p_read_sky, float p_energy, float p_normal_bias, float p_probe_bias) override; + virtual void environment_set_sdfgi(RID p_env, bool p_enable, int p_cascades, float p_min_cell_size, RS::EnvironmentSDFGIYScale p_y_scale, bool p_use_occlusion, float p_bounce_feedback, bool p_read_sky, float p_energy, float p_normal_bias, float p_probe_bias) override; virtual void environment_set_sdfgi_ray_count(RS::EnvironmentSDFGIRayCount p_ray_count) override; virtual void environment_set_sdfgi_frames_to_converge(RS::EnvironmentSDFGIFramesToConverge p_frames) override; virtual void environment_set_sdfgi_frames_to_update_light(RS::EnvironmentSDFGIFramesToUpdateLight p_update) override; diff --git a/servers/rendering/renderer_rd/renderer_scene_sky_rd.cpp b/servers/rendering/renderer_rd/renderer_scene_sky_rd.cpp index 8fb3c607fa..f0419b7907 100644 --- a/servers/rendering/renderer_rd/renderer_scene_sky_rd.cpp +++ b/servers/rendering/renderer_rd/renderer_scene_sky_rd.cpp @@ -50,9 +50,9 @@ void RendererSceneSkyRD::SkyShaderData::set_code(const String &p_code) { return; //just invalid, but no error } - ShaderCompilerRD::GeneratedCode gen_code; - ShaderCompilerRD::IdentifierActions actions; - actions.entry_point_stages["sky"] = ShaderCompilerRD::STAGE_FRAGMENT; + ShaderCompiler::GeneratedCode gen_code; + ShaderCompiler::IdentifierActions actions; + actions.entry_point_stages["sky"] = ShaderCompiler::STAGE_FRAGMENT; uses_time = false; uses_half_res = false; @@ -112,7 +112,7 @@ void RendererSceneSkyRD::SkyShaderData::set_code(const String &p_code) { print_line("\n**light_code:\n" + gen_code.light); #endif - scene_singleton->sky.sky_shader.shader.version_set_code(version, gen_code.code, gen_code.uniforms, gen_code.stage_globals[ShaderCompilerRD::STAGE_VERTEX], gen_code.stage_globals[ShaderCompilerRD::STAGE_FRAGMENT], gen_code.defines); + scene_singleton->sky.sky_shader.shader.version_set_code(version, gen_code.code, gen_code.uniforms, gen_code.stage_globals[ShaderCompiler::STAGE_VERTEX], gen_code.stage_globals[ShaderCompiler::STAGE_FRAGMENT], gen_code.defines); ERR_FAIL_COND(!scene_singleton->sky.sky_shader.shader.version_is_valid(version)); ubo_size = gen_code.uniform_total_size; @@ -807,7 +807,7 @@ void RendererSceneSkyRD::init(RendererStorageRD *p_storage) { storage->material_set_data_request_function(RendererStorageRD::SHADER_TYPE_SKY, _create_sky_material_funcs); { - ShaderCompilerRD::DefaultIdentifierActions actions; + ShaderCompiler::DefaultIdentifierActions actions; actions.renames["COLOR"] = "color"; actions.renames["ALPHA"] = "alpha"; diff --git a/servers/rendering/renderer_rd/renderer_scene_sky_rd.h b/servers/rendering/renderer_rd/renderer_scene_sky_rd.h index 1359cdec67..46d376e667 100644 --- a/servers/rendering/renderer_rd/renderer_scene_sky_rd.h +++ b/servers/rendering/renderer_rd/renderer_scene_sky_rd.h @@ -111,7 +111,7 @@ private: PipelineCacheRD pipelines[SKY_VERSION_MAX]; Map<StringName, ShaderLanguage::ShaderNode::Uniform> uniforms; - Vector<ShaderCompilerRD::GeneratedCode::Texture> texture_uniforms; + Vector<ShaderCompiler::GeneratedCode::Texture> texture_uniforms; Vector<uint32_t> ubo_offsets; uint32_t ubo_size; @@ -220,7 +220,7 @@ public: struct SkyShader { SkyShaderRD shader; - ShaderCompilerRD compiler; + ShaderCompiler compiler; RID default_shader; RID default_material; diff --git a/servers/rendering/renderer_rd/renderer_storage_rd.cpp b/servers/rendering/renderer_rd/renderer_storage_rd.cpp index 6cce51cfaf..19075fab86 100644 --- a/servers/rendering/renderer_rd/renderer_storage_rd.cpp +++ b/servers/rendering/renderer_rd/renderer_storage_rd.cpp @@ -324,75 +324,6 @@ Ref<Image> RendererStorageRD::_validate_texture_format(const Ref<Image> &p_image r_format.swizzle_b = RD::TEXTURE_SWIZZLE_B; r_format.swizzle_a = RD::TEXTURE_SWIZZLE_ONE; } break; //unsigned float bc6hu - case Image::FORMAT_PVRTC1_2: { - //this is not properly supported by MoltekVK it seems, so best to use ETC2 - if (RD::get_singleton()->texture_is_format_supported_for_usage(RD::DATA_FORMAT_PVRTC1_2BPP_UNORM_BLOCK_IMG, RD::TEXTURE_USAGE_SAMPLING_BIT | RD::TEXTURE_USAGE_CAN_UPDATE_BIT)) { - r_format.format = RD::DATA_FORMAT_PVRTC1_2BPP_UNORM_BLOCK_IMG; - r_format.format_srgb = RD::DATA_FORMAT_PVRTC1_2BPP_SRGB_BLOCK_IMG; - } else { - //not supported, reconvert - r_format.format = RD::DATA_FORMAT_R8G8B8A8_UNORM; - r_format.format_srgb = RD::DATA_FORMAT_R8G8B8A8_SRGB; - image->decompress(); - image->convert(Image::FORMAT_RGBA8); - } - r_format.swizzle_r = RD::TEXTURE_SWIZZLE_R; - r_format.swizzle_g = RD::TEXTURE_SWIZZLE_G; - r_format.swizzle_b = RD::TEXTURE_SWIZZLE_B; - r_format.swizzle_a = RD::TEXTURE_SWIZZLE_ONE; - - } break; //pvrtc - case Image::FORMAT_PVRTC1_2A: { - //this is not properly supported by MoltekVK it seems, so best to use ETC2 - if (RD::get_singleton()->texture_is_format_supported_for_usage(RD::DATA_FORMAT_PVRTC1_2BPP_UNORM_BLOCK_IMG, RD::TEXTURE_USAGE_SAMPLING_BIT | RD::TEXTURE_USAGE_CAN_UPDATE_BIT)) { - r_format.format = RD::DATA_FORMAT_PVRTC1_2BPP_UNORM_BLOCK_IMG; - r_format.format_srgb = RD::DATA_FORMAT_PVRTC1_2BPP_SRGB_BLOCK_IMG; - } else { - //not supported, reconvert - r_format.format = RD::DATA_FORMAT_R8G8B8A8_UNORM; - r_format.format_srgb = RD::DATA_FORMAT_R8G8B8A8_SRGB; - image->decompress(); - image->convert(Image::FORMAT_RGBA8); - } - r_format.swizzle_r = RD::TEXTURE_SWIZZLE_R; - r_format.swizzle_g = RD::TEXTURE_SWIZZLE_G; - r_format.swizzle_b = RD::TEXTURE_SWIZZLE_B; - r_format.swizzle_a = RD::TEXTURE_SWIZZLE_A; - } break; - case Image::FORMAT_PVRTC1_4: { - //this is not properly supported by MoltekVK it seems, so best to use ETC2 - if (RD::get_singleton()->texture_is_format_supported_for_usage(RD::DATA_FORMAT_PVRTC1_4BPP_UNORM_BLOCK_IMG, RD::TEXTURE_USAGE_SAMPLING_BIT | RD::TEXTURE_USAGE_CAN_UPDATE_BIT)) { - r_format.format = RD::DATA_FORMAT_PVRTC1_4BPP_UNORM_BLOCK_IMG; - r_format.format_srgb = RD::DATA_FORMAT_PVRTC1_4BPP_SRGB_BLOCK_IMG; - } else { - //not supported, reconvert - r_format.format = RD::DATA_FORMAT_R8G8B8A8_UNORM; - r_format.format_srgb = RD::DATA_FORMAT_R8G8B8A8_SRGB; - image->decompress(); - image->convert(Image::FORMAT_RGBA8); - } - r_format.swizzle_r = RD::TEXTURE_SWIZZLE_R; - r_format.swizzle_g = RD::TEXTURE_SWIZZLE_G; - r_format.swizzle_b = RD::TEXTURE_SWIZZLE_B; - r_format.swizzle_a = RD::TEXTURE_SWIZZLE_ONE; - } break; - case Image::FORMAT_PVRTC1_4A: { - //this is not properly supported by MoltekVK it seems, so best to use ETC2 - if (RD::get_singleton()->texture_is_format_supported_for_usage(RD::DATA_FORMAT_PVRTC1_4BPP_UNORM_BLOCK_IMG, RD::TEXTURE_USAGE_SAMPLING_BIT | RD::TEXTURE_USAGE_CAN_UPDATE_BIT)) { - r_format.format = RD::DATA_FORMAT_PVRTC1_4BPP_UNORM_BLOCK_IMG; - r_format.format_srgb = RD::DATA_FORMAT_PVRTC1_4BPP_SRGB_BLOCK_IMG; - } else { - //not supported, reconvert - r_format.format = RD::DATA_FORMAT_R8G8B8A8_UNORM; - r_format.format_srgb = RD::DATA_FORMAT_R8G8B8A8_SRGB; - image->decompress(); - image->convert(Image::FORMAT_RGBA8); - } - r_format.swizzle_r = RD::TEXTURE_SWIZZLE_R; - r_format.swizzle_g = RD::TEXTURE_SWIZZLE_G; - r_format.swizzle_b = RD::TEXTURE_SWIZZLE_B; - r_format.swizzle_a = RD::TEXTURE_SWIZZLE_A; - } break; case Image::FORMAT_ETC2_R11: { if (RD::get_singleton()->texture_is_format_supported_for_usage(RD::DATA_FORMAT_EAC_R11_UNORM_BLOCK, RD::TEXTURE_USAGE_SAMPLING_BIT | RD::TEXTURE_USAGE_CAN_UPDATE_BIT)) { r_format.format = RD::DATA_FORMAT_EAC_R11_UNORM_BLOCK; @@ -971,12 +902,7 @@ void RendererStorageRD::texture_2d_placeholder_initialize(RID p_texture) { Ref<Image> image; image.instantiate(); image->create(4, 4, false, Image::FORMAT_RGBA8); - - for (int i = 0; i < 4; i++) { - for (int j = 0; j < 4; j++) { - image->set_pixel(i, j, Color(1, 0, 1, 1)); - } - } + image->fill(Color(1, 0, 1, 1)); texture_2d_initialize(p_texture, image); } @@ -987,12 +913,7 @@ void RendererStorageRD::texture_2d_layered_placeholder_initialize(RID p_texture, Ref<Image> image; image.instantiate(); image->create(4, 4, false, Image::FORMAT_RGBA8); - - for (int i = 0; i < 4; i++) { - for (int j = 0; j < 4; j++) { - image->set_pixel(i, j, Color(1, 0, 1, 1)); - } - } + image->fill(Color(1, 0, 1, 1)); Vector<Ref<Image>> images; if (p_layered_type == RS::TEXTURE_LAYERED_2D_ARRAY) { @@ -1013,12 +934,7 @@ void RendererStorageRD::texture_3d_placeholder_initialize(RID p_texture) { Ref<Image> image; image.instantiate(); image->create(4, 4, false, Image::FORMAT_RGBA8); - - for (int i = 0; i < 4; i++) { - for (int j = 0; j < 4; j++) { - image->set_pixel(i, j, Color(1, 0, 1, 1)); - } - } + image->fill(Color(1, 0, 1, 1)); Vector<Ref<Image>> images; //cube @@ -1639,14 +1555,14 @@ void RendererStorageRD::material_initialize(RID p_rid) { } void RendererStorageRD::_material_queue_update(Material *material, bool p_uniform, bool p_texture) { + material->uniform_dirty = material->uniform_dirty || p_uniform; + material->texture_dirty = material->texture_dirty || p_texture; + if (material->update_element.in_list()) { return; } material_update_list.add(&material->update_element); - - material->uniform_dirty = material->uniform_dirty || p_uniform; - material->texture_dirty = material->texture_dirty || p_texture; } void RendererStorageRD::material_set_shader(RID p_material, RID p_shader) { @@ -2627,7 +2543,7 @@ void RendererStorageRD::MaterialData::update_uniform_buffer(const Map<StringName } if (E.value.scope == ShaderLanguage::ShaderNode::Uniform::SCOPE_INSTANCE) { - continue; //instance uniforms don't appear in the bufferr + continue; //instance uniforms don't appear in the buffer } if (E.value.scope == ShaderLanguage::ShaderNode::Uniform::SCOPE_GLOBAL) { @@ -2725,7 +2641,7 @@ RendererStorageRD::MaterialData::~MaterialData() { } } -void RendererStorageRD::MaterialData::update_textures(const Map<StringName, Variant> &p_parameters, const Map<StringName, Map<int, RID>> &p_default_textures, const Vector<ShaderCompilerRD::GeneratedCode::Texture> &p_texture_uniforms, RID *p_textures, bool p_use_linear_color) { +void RendererStorageRD::MaterialData::update_textures(const Map<StringName, Variant> &p_parameters, const Map<StringName, Map<int, RID>> &p_default_textures, const Vector<ShaderCompiler::GeneratedCode::Texture> &p_texture_uniforms, RID *p_textures, bool p_use_linear_color) { RendererStorageRD *singleton = (RendererStorageRD *)RendererStorage::base_singleton; #ifdef TOOLS_ENABLED Texture *roughness_detect_texture = nullptr; @@ -2951,7 +2867,7 @@ void RendererStorageRD::MaterialData::free_parameters_uniform_set(RID p_uniform_ } } -bool RendererStorageRD::MaterialData::update_parameters_uniform_set(const Map<StringName, Variant> &p_parameters, bool p_uniform_dirty, bool p_textures_dirty, const Map<StringName, ShaderLanguage::ShaderNode::Uniform> &p_uniforms, const uint32_t *p_uniform_offsets, const Vector<ShaderCompilerRD::GeneratedCode::Texture> &p_texture_uniforms, const Map<StringName, Map<int, RID>> &p_default_texture_params, uint32_t p_ubo_size, RID &uniform_set, RID p_shader, uint32_t p_shader_uniform_set, uint32_t p_barrier) { +bool RendererStorageRD::MaterialData::update_parameters_uniform_set(const Map<StringName, Variant> &p_parameters, bool p_uniform_dirty, bool p_textures_dirty, const Map<StringName, ShaderLanguage::ShaderNode::Uniform> &p_uniforms, const uint32_t *p_uniform_offsets, const Vector<ShaderCompiler::GeneratedCode::Texture> &p_texture_uniforms, const Map<StringName, Map<int, RID>> &p_default_texture_params, uint32_t p_ubo_size, RID &uniform_set, RID p_shader, uint32_t p_shader_uniform_set, uint32_t p_barrier) { if ((uint32_t)ubo_data.size() != p_ubo_size) { p_uniform_dirty = true; if (uniform_buffer.is_valid()) { @@ -5827,10 +5743,10 @@ void RendererStorageRD::ParticlesShaderData::set_code(const String &p_code) { return; //just invalid, but no error } - ShaderCompilerRD::GeneratedCode gen_code; - ShaderCompilerRD::IdentifierActions actions; - actions.entry_point_stages["start"] = ShaderCompilerRD::STAGE_COMPUTE; - actions.entry_point_stages["process"] = ShaderCompilerRD::STAGE_COMPUTE; + ShaderCompiler::GeneratedCode gen_code; + ShaderCompiler::IdentifierActions actions; + actions.entry_point_stages["start"] = ShaderCompiler::STAGE_COMPUTE; + actions.entry_point_stages["process"] = ShaderCompiler::STAGE_COMPUTE; /* uses_time = false; @@ -5852,7 +5768,7 @@ void RendererStorageRD::ParticlesShaderData::set_code(const String &p_code) { version = base_singleton->particles_shader.shader.version_create(); } - base_singleton->particles_shader.shader.version_set_compute_code(version, gen_code.code, gen_code.uniforms, gen_code.stage_globals[ShaderCompilerRD::STAGE_COMPUTE], gen_code.defines); + base_singleton->particles_shader.shader.version_set_compute_code(version, gen_code.code, gen_code.uniforms, gen_code.stage_globals[ShaderCompiler::STAGE_COMPUTE], gen_code.defines); ERR_FAIL_COND(!base_singleton->particles_shader.shader.version_is_valid(version)); ubo_size = gen_code.uniform_total_size; @@ -9299,10 +9215,6 @@ bool RendererStorageRD::has_os_feature(const String &p_feature) const { return true; } - if (p_feature == "pvrtc" && RD::get_singleton()->texture_is_format_supported_for_usage(RD::DATA_FORMAT_PVRTC1_2BPP_UNORM_BLOCK_IMG, RD::TEXTURE_USAGE_SAMPLING_BIT)) { - return true; - } - return false; } @@ -10031,7 +9943,7 @@ RendererStorageRD::RendererStorageRD() { material_set_data_request_function(RendererStorageRD::SHADER_TYPE_PARTICLES, _create_particles_material_funcs); { - ShaderCompilerRD::DefaultIdentifierActions actions; + ShaderCompiler::DefaultIdentifierActions actions; actions.renames["COLOR"] = "PARTICLE.color"; actions.renames["VELOCITY"] = "PARTICLE.velocity"; diff --git a/servers/rendering/renderer_rd/renderer_storage_rd.h b/servers/rendering/renderer_rd/renderer_storage_rd.h index cca61008c7..8c04274c3f 100644 --- a/servers/rendering/renderer_rd/renderer_storage_rd.h +++ b/servers/rendering/renderer_rd/renderer_storage_rd.h @@ -36,7 +36,6 @@ #include "core/templates/rid_owner.h" #include "servers/rendering/renderer_compositor.h" #include "servers/rendering/renderer_rd/effects_rd.h" -#include "servers/rendering/renderer_rd/shader_compiler_rd.h" #include "servers/rendering/renderer_rd/shaders/canvas_sdf.glsl.gen.h" #include "servers/rendering/renderer_rd/shaders/particles.glsl.gen.h" #include "servers/rendering/renderer_rd/shaders/particles_copy.glsl.gen.h" @@ -44,6 +43,7 @@ #include "servers/rendering/renderer_rd/shaders/voxel_gi_sdf.glsl.gen.h" #include "servers/rendering/renderer_scene_render.h" #include "servers/rendering/rendering_device.h" +#include "servers/rendering/shader_compiler.h" class RendererStorageRD : public RendererStorage { public: static _FORCE_INLINE_ void store_transform(const Transform3D &p_mtx, float *p_array) { @@ -152,7 +152,7 @@ public: struct MaterialData { void update_uniform_buffer(const Map<StringName, ShaderLanguage::ShaderNode::Uniform> &p_uniforms, const uint32_t *p_uniform_offsets, const Map<StringName, Variant> &p_parameters, uint8_t *p_buffer, uint32_t p_buffer_size, bool p_use_linear_color); - void update_textures(const Map<StringName, Variant> &p_parameters, const Map<StringName, Map<int, RID>> &p_default_textures, const Vector<ShaderCompilerRD::GeneratedCode::Texture> &p_texture_uniforms, RID *p_textures, bool p_use_linear_color); + void update_textures(const Map<StringName, Variant> &p_parameters, const Map<StringName, Map<int, RID>> &p_default_textures, const Vector<ShaderCompiler::GeneratedCode::Texture> &p_texture_uniforms, RID *p_textures, bool p_use_linear_color); virtual void set_render_priority(int p_priority) = 0; virtual void set_next_pass(RID p_pass) = 0; @@ -160,7 +160,7 @@ public: virtual ~MaterialData(); //to be used internally by update_parameters, in the most common configuration of material parameters - bool update_parameters_uniform_set(const Map<StringName, Variant> &p_parameters, bool p_uniform_dirty, bool p_textures_dirty, const Map<StringName, ShaderLanguage::ShaderNode::Uniform> &p_uniforms, const uint32_t *p_uniform_offsets, const Vector<ShaderCompilerRD::GeneratedCode::Texture> &p_texture_uniforms, const Map<StringName, Map<int, RID>> &p_default_texture_params, uint32_t p_ubo_size, RID &uniform_set, RID p_shader, uint32_t p_shader_uniform_set, uint32_t p_barrier = RD::BARRIER_MASK_ALL); + bool update_parameters_uniform_set(const Map<StringName, Variant> &p_parameters, bool p_uniform_dirty, bool p_textures_dirty, const Map<StringName, ShaderLanguage::ShaderNode::Uniform> &p_uniforms, const uint32_t *p_uniform_offsets, const Vector<ShaderCompiler::GeneratedCode::Texture> &p_texture_uniforms, const Map<StringName, Map<int, RID>> &p_default_texture_params, uint32_t p_ubo_size, RID &uniform_set, RID p_shader, uint32_t p_shader_uniform_set, uint32_t p_barrier = RD::BARRIER_MASK_ALL); void free_parameters_uniform_set(RID p_uniform_set); private: @@ -826,7 +826,7 @@ private: }; ParticlesShaderRD shader; - ShaderCompilerRD compiler; + ShaderCompiler compiler; RID default_shader; RID default_material; @@ -877,7 +877,7 @@ private: //PipelineCacheRD pipelines[SKY_VERSION_MAX]; Map<StringName, ShaderLanguage::ShaderNode::Uniform> uniforms; - Vector<ShaderCompilerRD::GeneratedCode::Texture> texture_uniforms; + Vector<ShaderCompiler::GeneratedCode::Texture> texture_uniforms; Vector<uint32_t> ubo_offsets; uint32_t ubo_size; diff --git a/servers/rendering/renderer_rd/shader_rd.h b/servers/rendering/renderer_rd/shader_rd.h index 06f78ab193..8e57f0d9af 100644 --- a/servers/rendering/renderer_rd/shader_rd.h +++ b/servers/rendering/renderer_rd/shader_rd.h @@ -40,11 +40,6 @@ #include "core/variant/variant.h" #include "servers/rendering_server.h" -#include <stdio.h> -/** - @author Juan Linietsky <reduzio@gmail.com> -*/ - class ShaderRD { //versions CharString general_defines; @@ -173,4 +168,4 @@ public: virtual ~ShaderRD(); }; -#endif +#endif // SHADER_RD_H diff --git a/servers/rendering/renderer_rd/shaders/scene_forward_clustered.glsl b/servers/rendering/renderer_rd/shaders/scene_forward_clustered.glsl index 608b76b108..97f7e0a6e6 100644 --- a/servers/rendering/renderer_rd/shaders/scene_forward_clustered.glsl +++ b/servers/rendering/renderer_rd/shaders/scene_forward_clustered.glsl @@ -575,7 +575,7 @@ void main() { uint instance_index = instance_index_interp; - //lay out everything, whathever is unused is optimized away anyway + //lay out everything, whatever is unused is optimized away anyway vec3 vertex = vertex_interp; vec3 view = -normalize(vertex_interp); vec3 albedo = vec3(1.0); diff --git a/servers/rendering/renderer_rd/shaders/scene_forward_mobile.glsl b/servers/rendering/renderer_rd/shaders/scene_forward_mobile.glsl index 9e3732fd2b..4d6a3b5864 100644 --- a/servers/rendering/renderer_rd/shaders/scene_forward_mobile.glsl +++ b/servers/rendering/renderer_rd/shaders/scene_forward_mobile.glsl @@ -581,7 +581,7 @@ void main() { discard; #endif - //lay out everything, whathever is unused is optimized away anyway + //lay out everything, whatever is unused is optimized away anyway vec3 vertex = vertex_interp; vec3 view = -normalize(vertex_interp); vec3 albedo = vec3(1.0); diff --git a/servers/rendering/renderer_rd/shaders/sdfgi_preprocess.glsl b/servers/rendering/renderer_rd/shaders/sdfgi_preprocess.glsl index 4d9fa85a74..f6ec249b5e 100644 --- a/servers/rendering/renderer_rd/shaders/sdfgi_preprocess.glsl +++ b/servers/rendering/renderer_rd/shaders/sdfgi_preprocess.glsl @@ -102,7 +102,7 @@ dispatch_data; struct ProcessVoxel { uint position; // xyz 7 bit packed, extra 11 bits for neighbors. - uint albedo; //rgb bits 0-15 albedo, bits 16-21 are normal bits (set if geometry exists toward that side), extra 11 bits for neibhbours + uint albedo; //rgb bits 0-15 albedo, bits 16-21 are normal bits (set if geometry exists toward that side), extra 11 bits for neighbours uint light; //rgbe8985 encoded total saved light, extra 2 bits for neighbours uint light_aniso; //55555 light anisotropy, extra 2 bits for neighbours //total neighbours: 26 @@ -135,7 +135,7 @@ dispatch_data; struct ProcessVoxel { uint position; // xyz 7 bit packed, extra 11 bits for neighbors. - uint albedo; //rgb bits 0-15 albedo, bits 16-21 are normal bits (set if geometry exists toward that side), extra 11 bits for neibhbours + uint albedo; //rgb bits 0-15 albedo, bits 16-21 are normal bits (set if geometry exists toward that side), extra 11 bits for neighbours uint light; //rgbe8985 encoded total saved light, extra 2 bits for neighbours uint light_aniso; //55555 light anisotropy, extra 2 bits for neighbours //total neighbours: 26 diff --git a/servers/rendering/renderer_scene.h b/servers/rendering/renderer_scene.h index 20ca49cd71..426d22f83e 100644 --- a/servers/rendering/renderer_scene.h +++ b/servers/rendering/renderer_scene.h @@ -149,7 +149,7 @@ public: virtual void environment_set_ssil(RID p_env, bool p_enable, float p_radius, float p_intensity, float p_sharpness, float p_normal_rejection) = 0; virtual void environment_set_ssil_quality(RS::EnvironmentSSILQuality p_quality, bool p_half_size, float p_adaptive_target, int p_blur_passes, float p_fadeout_from, float p_fadeout_to) = 0; - virtual void environment_set_sdfgi(RID p_env, bool p_enable, RS::EnvironmentSDFGICascades p_cascades, float p_min_cell_size, RS::EnvironmentSDFGIYScale p_y_scale, bool p_use_occlusion, float p_bounce_feedback, bool p_read_sky, float p_energy, float p_normal_bias, float p_probe_bias) = 0; + virtual void environment_set_sdfgi(RID p_env, bool p_enable, int p_cascades, float p_min_cell_size, RS::EnvironmentSDFGIYScale p_y_scale, bool p_use_occlusion, float p_bounce_feedback, bool p_read_sky, float p_energy, float p_normal_bias, float p_probe_bias) = 0; virtual void environment_set_sdfgi_ray_count(RS::EnvironmentSDFGIRayCount p_ray_count) = 0; virtual void environment_set_sdfgi_frames_to_converge(RS::EnvironmentSDFGIFramesToConverge p_frames) = 0; diff --git a/servers/rendering/renderer_scene_cull.h b/servers/rendering/renderer_scene_cull.h index 071d88233f..1e770ef66c 100644 --- a/servers/rendering/renderer_scene_cull.h +++ b/servers/rendering/renderer_scene_cull.h @@ -1127,7 +1127,7 @@ public: PASS2(environment_set_volumetric_fog_volume_size, int, int) PASS1(environment_set_volumetric_fog_filter_active, bool) - PASS11(environment_set_sdfgi, RID, bool, RS::EnvironmentSDFGICascades, float, RS::EnvironmentSDFGIYScale, bool, float, bool, float, float, float) + PASS11(environment_set_sdfgi, RID, bool, int, float, RS::EnvironmentSDFGIYScale, bool, float, bool, float, float, float) PASS1(environment_set_sdfgi_ray_count, RS::EnvironmentSDFGIRayCount) PASS1(environment_set_sdfgi_frames_to_converge, RS::EnvironmentSDFGIFramesToConverge) PASS1(environment_set_sdfgi_frames_to_update_light, RS::EnvironmentSDFGIFramesToUpdateLight) diff --git a/servers/rendering/renderer_scene_render.h b/servers/rendering/renderer_scene_render.h index f99d34d292..c34a46d166 100644 --- a/servers/rendering/renderer_scene_render.h +++ b/servers/rendering/renderer_scene_render.h @@ -140,7 +140,7 @@ public: virtual void environment_set_ssil(RID p_env, bool p_enable, float p_radius, float p_intensity, float p_sharpness, float p_normal_rejection) = 0; virtual void environment_set_ssil_quality(RS::EnvironmentSSILQuality p_quality, bool p_half_size, float p_adaptive_target, int p_blur_passes, float p_fadeout_from, float p_fadeout_to) = 0; - virtual void environment_set_sdfgi(RID p_env, bool p_enable, RS::EnvironmentSDFGICascades p_cascades, float p_min_cell_size, RS::EnvironmentSDFGIYScale p_y_scale, bool p_use_occlusion, float p_bounce_feedback, bool p_read_sky, float p_energy, float p_normal_bias, float p_probe_bias) = 0; + virtual void environment_set_sdfgi(RID p_env, bool p_enable, int p_cascades, float p_min_cell_size, RS::EnvironmentSDFGIYScale p_y_scale, bool p_use_occlusion, float p_bounce_feedback, bool p_read_sky, float p_energy, float p_normal_bias, float p_probe_bias) = 0; virtual void environment_set_sdfgi_ray_count(RS::EnvironmentSDFGIRayCount p_ray_count) = 0; virtual void environment_set_sdfgi_frames_to_converge(RS::EnvironmentSDFGIFramesToConverge p_frames) = 0; diff --git a/servers/rendering/renderer_viewport.cpp b/servers/rendering/renderer_viewport.cpp index 47934e7299..17a665922f 100644 --- a/servers/rendering/renderer_viewport.cpp +++ b/servers/rendering/renderer_viewport.cpp @@ -582,6 +582,21 @@ void RendererViewport::draw_viewports() { bool visible = vp->viewport_to_screen_rect != Rect2(); + if (vp->use_xr && xr_interface.is_valid()) { + visible = true; // XR viewport is always visible regardless of update mode, output is sent to HMD. + + // Override our size, make sure it matches our required size and is created as a stereo target + Size2 xr_size = xr_interface->get_render_target_size(); + + // Would have been nice if we could call viewport_set_size here, + // but alas that takes our RID and we now have our pointer, + // also we only check if view_count changes in render_target_set_size so we need to call that for this to reliably change + vp->occlusion_buffer_dirty = vp->occlusion_buffer_dirty || (vp->size != xr_size); + vp->size = xr_size; + uint32_t view_count = xr_interface->get_view_count(); + RSG::storage->render_target_set_size(vp->render_target, vp->size.x, vp->size.y, view_count); + } + if (vp->update_mode == RS::VIEWPORT_UPDATE_ALWAYS || vp->update_mode == RS::VIEWPORT_UPDATE_ONCE) { visible = true; } @@ -619,11 +634,6 @@ void RendererViewport::draw_viewports() { RSG::storage->render_target_set_as_unused(vp->render_target); if (vp->use_xr && xr_interface.is_valid()) { - // override our size, make sure it matches our required size and is created as a stereo target - vp->size = xr_interface->get_render_target_size(); - uint32_t view_count = xr_interface->get_view_count(); - RSG::storage->render_target_set_size(vp->render_target, vp->internal_size.x, vp->internal_size.y, view_count); - // check for an external texture destination (disabled for now, not yet supported) // RSG::storage->render_target_set_external_texture(vp->render_target, xr_interface->get_external_texture_for_eye(leftOrMono)); RSG::storage->render_target_set_external_texture(vp->render_target, 0); @@ -843,7 +853,7 @@ void RendererViewport::viewport_attach_to_screen(RID p_viewport, const Rect2 &p_ // if render_direct_to_screen was used, reset size and position if (RSG::rasterizer->is_low_end() && viewport->viewport_render_direct_to_screen) { RSG::storage->render_target_set_position(viewport->render_target, 0, 0); - RSG::storage->render_target_set_size(viewport->render_target, viewport->internal_size.x, viewport->internal_size.y, viewport->get_view_count()); + RSG::storage->render_target_set_size(viewport->render_target, viewport->size.x, viewport->size.y, viewport->get_view_count()); } viewport->viewport_to_screen_rect = Rect2(); diff --git a/servers/rendering/rendering_device.cpp b/servers/rendering/rendering_device.cpp index 88a8dfe694..46fb3c8537 100644 --- a/servers/rendering/rendering_device.cpp +++ b/servers/rendering/rendering_device.cpp @@ -729,14 +729,6 @@ void RenderingDevice::_bind_methods() { BIND_ENUM_CONSTANT(DATA_FORMAT_G16_B16_R16_3PLANE_422_UNORM); BIND_ENUM_CONSTANT(DATA_FORMAT_G16_B16R16_2PLANE_422_UNORM); BIND_ENUM_CONSTANT(DATA_FORMAT_G16_B16_R16_3PLANE_444_UNORM); - BIND_ENUM_CONSTANT(DATA_FORMAT_PVRTC1_2BPP_UNORM_BLOCK_IMG); - BIND_ENUM_CONSTANT(DATA_FORMAT_PVRTC1_4BPP_UNORM_BLOCK_IMG); - BIND_ENUM_CONSTANT(DATA_FORMAT_PVRTC2_2BPP_UNORM_BLOCK_IMG); - BIND_ENUM_CONSTANT(DATA_FORMAT_PVRTC2_4BPP_UNORM_BLOCK_IMG); - BIND_ENUM_CONSTANT(DATA_FORMAT_PVRTC1_2BPP_SRGB_BLOCK_IMG); - BIND_ENUM_CONSTANT(DATA_FORMAT_PVRTC1_4BPP_SRGB_BLOCK_IMG); - BIND_ENUM_CONSTANT(DATA_FORMAT_PVRTC2_2BPP_SRGB_BLOCK_IMG); - BIND_ENUM_CONSTANT(DATA_FORMAT_PVRTC2_4BPP_SRGB_BLOCK_IMG); BIND_ENUM_CONSTANT(DATA_FORMAT_MAX); BIND_ENUM_CONSTANT(TEXTURE_TYPE_1D); diff --git a/servers/rendering/rendering_device.h b/servers/rendering/rendering_device.h index 313c0e11b2..3e74741de0 100644 --- a/servers/rendering/rendering_device.h +++ b/servers/rendering/rendering_device.h @@ -392,14 +392,6 @@ public: DATA_FORMAT_G16_B16_R16_3PLANE_422_UNORM, DATA_FORMAT_G16_B16R16_2PLANE_422_UNORM, DATA_FORMAT_G16_B16_R16_3PLANE_444_UNORM, - DATA_FORMAT_PVRTC1_2BPP_UNORM_BLOCK_IMG, - DATA_FORMAT_PVRTC1_4BPP_UNORM_BLOCK_IMG, - DATA_FORMAT_PVRTC2_2BPP_UNORM_BLOCK_IMG, - DATA_FORMAT_PVRTC2_4BPP_UNORM_BLOCK_IMG, - DATA_FORMAT_PVRTC1_2BPP_SRGB_BLOCK_IMG, - DATA_FORMAT_PVRTC1_4BPP_SRGB_BLOCK_IMG, - DATA_FORMAT_PVRTC2_2BPP_SRGB_BLOCK_IMG, - DATA_FORMAT_PVRTC2_4BPP_SRGB_BLOCK_IMG, DATA_FORMAT_MAX }; diff --git a/servers/rendering/rendering_server_default.h b/servers/rendering/rendering_server_default.h index ead49f053c..ee684c69ed 100644 --- a/servers/rendering/rendering_server_default.h +++ b/servers/rendering/rendering_server_default.h @@ -643,7 +643,7 @@ public: FUNC2(environment_set_volumetric_fog_volume_size, int, int) FUNC1(environment_set_volumetric_fog_filter_active, bool) - FUNC11(environment_set_sdfgi, RID, bool, EnvironmentSDFGICascades, float, EnvironmentSDFGIYScale, bool, float, bool, float, float, float) + FUNC11(environment_set_sdfgi, RID, bool, int, float, EnvironmentSDFGIYScale, bool, float, bool, float, float, float) FUNC1(environment_set_sdfgi_ray_count, EnvironmentSDFGIRayCount) FUNC1(environment_set_sdfgi_frames_to_converge, EnvironmentSDFGIFramesToConverge) FUNC1(environment_set_sdfgi_frames_to_update_light, EnvironmentSDFGIFramesToUpdateLight) diff --git a/servers/rendering/renderer_rd/shader_compiler_rd.cpp b/servers/rendering/shader_compiler.cpp index 38ac00176f..78e81eac0b 100644 --- a/servers/rendering/renderer_rd/shader_compiler_rd.cpp +++ b/servers/rendering/shader_compiler.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* shader_compiler_rd.cpp */ +/* shader_compiler.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,11 +28,11 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "shader_compiler_rd.h" +#include "shader_compiler.h" #include "core/config/project_settings.h" #include "core/os/os.h" -#include "renderer_storage_rd.h" +#include "servers/rendering/shader_types.h" #include "servers/rendering_server.h" #define SL ShaderLanguage @@ -277,7 +277,7 @@ static String get_constant_text(SL::DataType p_type, const Vector<SL::ConstantNo } } -String ShaderCompilerRD::_get_sampler_name(ShaderLanguage::TextureFilter p_filter, ShaderLanguage::TextureRepeat p_repeat) { +String ShaderCompiler::_get_sampler_name(ShaderLanguage::TextureFilter p_filter, ShaderLanguage::TextureRepeat p_repeat) { if (p_filter == ShaderLanguage::FILTER_DEFAULT) { ERR_FAIL_COND_V(actions.default_filter == ShaderLanguage::FILTER_DEFAULT, String()); p_filter = actions.default_filter; @@ -289,7 +289,7 @@ String ShaderCompilerRD::_get_sampler_name(ShaderLanguage::TextureFilter p_filte return actions.sampler_array_name + "[" + itos(p_filter + (p_repeat == ShaderLanguage::REPEAT_ENABLE ? ShaderLanguage::FILTER_DEFAULT : 0)) + "]"; } -void ShaderCompilerRD::_dump_function_deps(const SL::ShaderNode *p_node, const StringName &p_for_func, const Map<StringName, String> &p_func_code, String &r_to_add, Set<StringName> &added) { +void ShaderCompiler::_dump_function_deps(const SL::ShaderNode *p_node, const StringName &p_for_func, const Map<StringName, String> &p_func_code, String &r_to_add, Set<StringName> &added) { int fidx = -1; for (int i = 0; i < p_node->functions.size(); i++) { @@ -435,7 +435,7 @@ static String _get_global_variable_from_type_and_index(const String &p_buffer, c } } -String ShaderCompilerRD::_dump_node_code(const SL::Node *p_node, int p_level, GeneratedCode &r_gen_code, IdentifierActions &p_actions, const DefaultIdentifierActions &p_default_actions, bool p_assigning, bool p_use_scope) { +String ShaderCompiler::_dump_node_code(const SL::Node *p_node, int p_level, GeneratedCode &r_gen_code, IdentifierActions &p_actions, const DefaultIdentifierActions &p_default_actions, bool p_assigning, bool p_use_scope) { String code; switch (p_node->type) { @@ -692,17 +692,36 @@ String ShaderCompilerRD::_dump_node_code(const SL::Node *p_node, int p_level, Ge vcode += _prestr(varying.precision, ShaderLanguage::is_float_type(varying.type)); vcode += _typestr(varying.type); vcode += " " + _mkid(varying_name); + uint32_t inc = 1U; + if (varying.array_size > 0) { + inc = (uint32_t)varying.array_size; + vcode += "["; vcode += itos(varying.array_size); vcode += "]"; } + + switch (varying.type) { + case SL::TYPE_MAT2: + inc *= 2U; + break; + case SL::TYPE_MAT3: + inc *= 3U; + break; + case SL::TYPE_MAT4: + inc *= 4U; + break; + default: + break; + } + vcode += ";\n"; r_gen_code.stage_globals[STAGE_VERTEX] += "layout(location=" + itos(index) + ") " + interp_mode + "out " + vcode; r_gen_code.stage_globals[STAGE_FRAGMENT] += "layout(location=" + itos(index) + ") " + interp_mode + "in " + vcode; - index++; + index += inc; } if (var_frag_to_light.size() > 0) { @@ -813,16 +832,49 @@ String ShaderCompilerRD::_dump_node_code(const SL::Node *p_node, int p_level, Ge } else { declaration += _prestr(vdnode->precision) + _typestr(vdnode->datatype); } + declaration += " "; for (int i = 0; i < vdnode->declarations.size(); i++) { + bool is_array = vdnode->declarations[i].size > 0; if (i > 0) { declaration += ","; - } else { - declaration += " "; } declaration += _mkid(vdnode->declarations[i].name); - if (vdnode->declarations[i].initializer) { - declaration += "="; - declaration += _dump_node_code(vdnode->declarations[i].initializer, p_level, r_gen_code, p_actions, p_default_actions, p_assigning); + if (is_array) { + declaration += "["; + if (vdnode->declarations[i].size_expression != nullptr) { + declaration += _dump_node_code(vdnode->declarations[i].size_expression, p_level, r_gen_code, p_actions, p_default_actions, p_assigning); + } else { + declaration += itos(vdnode->declarations[i].size); + } + declaration += "]"; + } + + if (!is_array || vdnode->declarations[i].single_expression) { + if (!vdnode->declarations[i].initializer.is_empty()) { + declaration += "="; + declaration += _dump_node_code(vdnode->declarations[i].initializer[0], p_level, r_gen_code, p_actions, p_default_actions, p_assigning); + } + } else { + int size = vdnode->declarations[i].initializer.size(); + if (size > 0) { + declaration += "="; + if (vdnode->datatype == SL::TYPE_STRUCT) { + declaration += _mkid(vdnode->struct_name); + } else { + declaration += _typestr(vdnode->datatype); + } + declaration += "["; + declaration += itos(size); + declaration += "]"; + declaration += "("; + for (int j = 0; j < size; j++) { + if (j > 0) { + declaration += ","; + } + declaration += _dump_node_code(vdnode->declarations[i].initializer[j], p_level, r_gen_code, p_actions, p_default_actions, p_assigning); + } + declaration += ")"; + } } } @@ -924,58 +976,6 @@ String ShaderCompilerRD::_dump_node_code(const SL::Node *p_node, int p_level, Ge } code += ")"; } break; - case SL::Node::TYPE_ARRAY_DECLARATION: { - SL::ArrayDeclarationNode *adnode = (SL::ArrayDeclarationNode *)p_node; - String declaration; - declaration += _constr(adnode->is_const); - if (adnode->datatype == SL::TYPE_STRUCT) { - declaration += _mkid(adnode->struct_name); - } else { - declaration += _prestr(adnode->precision) + _typestr(adnode->datatype); - } - for (int i = 0; i < adnode->declarations.size(); i++) { - if (i > 0) { - declaration += ","; - } else { - declaration += " "; - } - declaration += _mkid(adnode->declarations[i].name); - declaration += "["; - if (adnode->size_expression != nullptr) { - declaration += _dump_node_code(adnode->size_expression, p_level, r_gen_code, p_actions, p_default_actions, p_assigning); - } else { - declaration += itos(adnode->declarations[i].size); - } - declaration += "]"; - if (adnode->declarations[i].single_expression) { - declaration += "="; - declaration += _dump_node_code(adnode->declarations[i].initializer[0], p_level, r_gen_code, p_actions, p_default_actions, p_assigning); - } else { - int sz = adnode->declarations[i].initializer.size(); - if (sz > 0) { - declaration += "="; - if (adnode->datatype == SL::TYPE_STRUCT) { - declaration += _mkid(adnode->struct_name); - } else { - declaration += _typestr(adnode->datatype); - } - declaration += "["; - declaration += itos(sz); - declaration += "]"; - declaration += "("; - for (int j = 0; j < sz; j++) { - declaration += _dump_node_code(adnode->declarations[i].initializer[j], p_level, r_gen_code, p_actions, p_default_actions, p_assigning); - if (j != sz - 1) { - declaration += ", "; - } - } - declaration += ")"; - } - } - } - - code += declaration; - } break; case SL::Node::TYPE_ARRAY: { SL::ArrayNode *anode = (SL::ArrayNode *)p_node; bool use_fragment_varying = false; @@ -1332,12 +1332,12 @@ String ShaderCompilerRD::_dump_node_code(const SL::Node *p_node, int p_level, Ge return code; } -ShaderLanguage::DataType ShaderCompilerRD::_get_variable_type(const StringName &p_type) { - RS::GlobalVariableType gvt = ((RendererStorageRD *)(RendererStorage::base_singleton))->global_variable_get_type_internal(p_type); - return RS::global_variable_type_get_shader_datatype(gvt); +ShaderLanguage::DataType ShaderCompiler::_get_variable_type(const StringName &p_type) { + RS::GlobalVariableType gvt = RS::get_singleton()->global_variable_get_type(p_type); + return (ShaderLanguage::DataType)RS::global_variable_type_get_shader_datatype(gvt); } -Error ShaderCompilerRD::compile(RS::ShaderMode p_mode, const String &p_code, IdentifierActions *p_actions, const String &p_path, GeneratedCode &r_gen_code) { +Error ShaderCompiler::compile(RS::ShaderMode p_mode, const String &p_code, IdentifierActions *p_actions, const String &p_path, GeneratedCode &r_gen_code) { SL::ShaderCompileInfo info; info.functions = ShaderTypes::get_singleton()->get_functions(p_mode); info.render_modes = ShaderTypes::get_singleton()->get_modes(p_mode); @@ -1383,7 +1383,7 @@ Error ShaderCompilerRD::compile(RS::ShaderMode p_mode, const String &p_code, Ide return OK; } -void ShaderCompilerRD::initialize(DefaultIdentifierActions p_actions) { +void ShaderCompiler::initialize(DefaultIdentifierActions p_actions) { actions = p_actions; time_name = "TIME"; @@ -1405,7 +1405,7 @@ void ShaderCompilerRD::initialize(DefaultIdentifierActions p_actions) { texture_functions.insert("texelFetch"); } -ShaderCompilerRD::ShaderCompilerRD() { +ShaderCompiler::ShaderCompiler() { #if 0 /** SPATIAL SHADER **/ diff --git a/servers/rendering/renderer_rd/shader_compiler_rd.h b/servers/rendering/shader_compiler.h index 5670d881f6..8f0ee664ac 100644 --- a/servers/rendering/renderer_rd/shader_compiler_rd.h +++ b/servers/rendering/shader_compiler.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* shader_compiler_rd.h */ +/* shader_compiler.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,15 +28,14 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef SHADER_COMPILER_RD_H -#define SHADER_COMPILER_RD_H +#ifndef SHADER_COMPILER_H +#define SHADER_COMPILER_H #include "core/templates/pair.h" #include "servers/rendering/shader_language.h" -#include "servers/rendering/shader_types.h" #include "servers/rendering_server.h" -class ShaderCompilerRD { +class ShaderCompiler { public: enum Stage { STAGE_VERTEX, @@ -127,7 +126,7 @@ public: Error compile(RS::ShaderMode p_mode, const String &p_code, IdentifierActions *p_actions, const String &p_path, GeneratedCode &r_gen_code); void initialize(DefaultIdentifierActions p_actions); - ShaderCompilerRD(); + ShaderCompiler(); }; -#endif // SHADERCOMPILERRD_H +#endif // SHADER_COMPILER_H diff --git a/servers/rendering/shader_language.cpp b/servers/rendering/shader_language.cpp index 5d420ba48d..bb6cfd7b03 100644 --- a/servers/rendering/shader_language.cpp +++ b/servers/rendering/shader_language.cpp @@ -4309,101 +4309,73 @@ bool ShaderLanguage::_propagate_function_call_sampler_builtin_reference(StringNa ERR_FAIL_V(false); //bug? function not found } -ShaderLanguage::Node *ShaderLanguage::_parse_array_size(BlockNode *p_block, const FunctionInfo &p_function_info, int &r_array_size) { - int array_size = 0; - - Node *n = _parse_and_reduce_expression(p_block, p_function_info); - if (n) { - if (n->type == Node::TYPE_VARIABLE) { - VariableNode *vn = static_cast<VariableNode *>(n); - if (vn) { - ConstantNode::Value v; - DataType data_type; - bool is_const = false; - - _find_identifier(p_block, false, p_function_info, vn->name, &data_type, nullptr, &is_const, nullptr, nullptr, &v); - - if (is_const) { - if (data_type == TYPE_INT) { - int32_t value = v.sint; - if (value > 0) { - array_size = value; - } - } else if (data_type == TYPE_UINT) { - uint32_t value = v.uint; - if (value > 0U) { - array_size = value; - } - } - } - } - } else if (n->type == Node::TYPE_OPERATOR) { - _set_error("Array size expressions are not yet implemented."); - return nullptr; - } +Error ShaderLanguage::_parse_array_size(BlockNode *p_block, const FunctionInfo &p_function_info, bool p_forbid_unknown_size, Node **r_size_expression, int *r_array_size, bool *r_unknown_size) { + bool error = false; + if (r_array_size != nullptr && *r_array_size > 0) { + error = true; } - - r_array_size = array_size; - return n; -} - -Error ShaderLanguage::_parse_global_array_size(int &r_array_size, const FunctionInfo &p_function_info) { - if (r_array_size > 0) { - _set_error("Array size is already defined!"); - return ERR_PARSE_ERROR; + if (r_unknown_size != nullptr && *r_unknown_size) { + error = true; } - TkPos pos = _get_tkpos(); - Token tk = _get_token(); - - int array_size = 0; - - if (!tk.is_integer_constant() || ((int)tk.constant) <= 0) { - _set_tkpos(pos); - Node *n = _parse_array_size(nullptr, p_function_info, array_size); - if (!n) { - return ERR_PARSE_ERROR; - } - } else if (((int)tk.constant) > 0) { - array_size = (uint32_t)tk.constant; - } - - if (array_size <= 0) { - _set_error("Expected single integer constant > 0"); - return ERR_PARSE_ERROR; - } - - tk = _get_token(); - if (tk.type != TK_BRACKET_CLOSE) { - _set_error("Expected ']'"); + if (error) { + _set_error("Array size is already defined!"); return ERR_PARSE_ERROR; } - r_array_size = array_size; - return OK; -} - -Error ShaderLanguage::_parse_local_array_size(BlockNode *p_block, const FunctionInfo &p_function_info, Node *&r_size_expression, int &r_array_size, bool &r_is_unknown_size) { TkPos pos = _get_tkpos(); Token tk = _get_token(); if (tk.type == TK_BRACKET_CLOSE) { - r_is_unknown_size = true; + if (p_forbid_unknown_size) { + _set_error("Unknown array size is forbidden in that context!"); + return ERR_PARSE_ERROR; + } + if (r_unknown_size != nullptr) { + *r_unknown_size = true; + } } else { - int size = 0; + int array_size = 0; + if (!tk.is_integer_constant() || ((int)tk.constant) <= 0) { _set_tkpos(pos); - int array_size = 0; - Node *n = _parse_array_size(p_block, p_function_info, array_size); - if (!n) { - return ERR_PARSE_ERROR; + Node *n = _parse_and_reduce_expression(p_block, p_function_info); + if (n) { + if (n->type == Node::TYPE_VARIABLE) { + VariableNode *vn = static_cast<VariableNode *>(n); + if (vn) { + ConstantNode::Value v; + DataType data_type; + bool is_const = false; + + _find_identifier(p_block, false, p_function_info, vn->name, &data_type, nullptr, &is_const, nullptr, nullptr, &v); + + if (is_const) { + if (data_type == TYPE_INT) { + int32_t value = v.sint; + if (value > 0) { + array_size = value; + } + } else if (data_type == TYPE_UINT) { + uint32_t value = v.uint; + if (value > 0U) { + array_size = value; + } + } + } + } + } else if (n->type == Node::TYPE_OPERATOR) { + _set_error("Array size expressions are not yet implemented."); + return ERR_PARSE_ERROR; + } + if (r_size_expression != nullptr) { + *r_size_expression = n; + } } - size = array_size; - r_size_expression = n; } else if (((int)tk.constant) > 0) { - size = (uint32_t)tk.constant; + array_size = (uint32_t)tk.constant; } - if (size <= 0) { + if (array_size <= 0) { _set_error("Expected single integer constant > 0"); return ERR_PARSE_ERROR; } @@ -4414,9 +4386,10 @@ Error ShaderLanguage::_parse_local_array_size(BlockNode *p_block, const Function return ERR_PARSE_ERROR; } - r_array_size = size; + if (r_array_size != nullptr) { + *r_array_size = array_size; + } } - return OK; } @@ -4443,40 +4416,11 @@ ShaderLanguage::Node *ShaderLanguage::_parse_array_constructor(BlockNode *p_bloc } tk = _get_token(); if (tk.type == TK_BRACKET_OPEN) { - TkPos pos = _get_tkpos(); - tk = _get_token(); - if (tk.type == TK_BRACKET_CLOSE) { - undefined_size = true; - tk = _get_token(); - } else { - _set_tkpos(pos); - - Node *n = _parse_and_reduce_expression(p_block, p_function_info); - if (!n || n->type != Node::TYPE_CONSTANT || n->get_datatype() != TYPE_INT) { - _set_error("Expected single integer constant > 0"); - return nullptr; - } - - ConstantNode *cnode = (ConstantNode *)n; - if (cnode->values.size() == 1) { - array_size = cnode->values[0].sint; - if (array_size <= 0) { - _set_error("Expected single integer constant > 0"); - return nullptr; - } - } else { - _set_error("Expected single integer constant > 0"); - return nullptr; - } - - tk = _get_token(); - if (tk.type != TK_BRACKET_CLOSE) { - _set_error("Expected ']'"); - return nullptr; - } else { - tk = _get_token(); - } + Error error = _parse_array_size(p_block, p_function_info, false, nullptr, &array_size, &undefined_size); + if (error != OK) { + return nullptr; } + tk = _get_token(); } else { _set_error("Expected '['"); return nullptr; @@ -4572,40 +4516,15 @@ ShaderLanguage::Node *ShaderLanguage::_parse_array_constructor(BlockNode *p_bloc } tk = _get_token(); if (tk.type == TK_BRACKET_OPEN) { - TkPos pos = _get_tkpos(); - tk = _get_token(); - if (tk.type == TK_BRACKET_CLOSE) { + bool is_unknown_size = false; + Error error = _parse_array_size(p_block, p_function_info, false, nullptr, &array_size, &is_unknown_size); + if (error != OK) { + return nullptr; + } + if (is_unknown_size) { array_size = p_array_size; - tk = _get_token(); - } else { - _set_tkpos(pos); - - Node *n = _parse_and_reduce_expression(p_block, p_function_info); - if (!n || n->type != Node::TYPE_CONSTANT || n->get_datatype() != TYPE_INT) { - _set_error("Expected single integer constant > 0"); - return nullptr; - } - - ConstantNode *cnode = (ConstantNode *)n; - if (cnode->values.size() == 1) { - array_size = cnode->values[0].sint; - if (array_size <= 0) { - _set_error("Expected single integer constant > 0"); - return nullptr; - } - } else { - _set_error("Expected single integer constant > 0"); - return nullptr; - } - - tk = _get_token(); - if (tk.type != TK_BRACKET_CLOSE) { - _set_error("Expected ']'"); - return nullptr; - } else { - tk = _get_token(); - } } + tk = _get_token(); } else { _set_error("Expected '['"); return nullptr; @@ -6509,17 +6428,23 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const FunctionInfo &p_fun return ERR_PARSE_ERROR; } - Node *vardecl = nullptr; int array_size = 0; bool fixed_array_size = false; bool first = true; + VariableDeclarationNode *vdnode = alloc_node<VariableDeclarationNode>(); + vdnode->precision = precision; + if (is_struct) { + vdnode->struct_name = struct_name; + vdnode->datatype = TYPE_STRUCT; + } else { + vdnode->datatype = type; + }; + vdnode->is_const = is_const; + do { bool unknown_size = false; - Node *size_expr = nullptr; - - ArrayDeclarationNode *anode = nullptr; - ArrayDeclarationNode::Declaration adecl; + VariableDeclarationNode::Declaration decl; tk = _get_token(); @@ -6532,12 +6457,11 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const FunctionInfo &p_fun } if (tk.type == TK_BRACKET_OPEN) { - Error error = _parse_local_array_size(p_block, p_function_info, size_expr, array_size, unknown_size); + Error error = _parse_array_size(p_block, p_function_info, false, &decl.size_expression, &array_size, &unknown_size); if (error != OK) { return error; } - adecl.single_expression = false; - adecl.size = array_size; + decl.size = array_size; fixed_array_size = true; tk = _get_token(); @@ -6557,8 +6481,7 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const FunctionInfo &p_fun return ERR_PARSE_ERROR; } } - - adecl.name = name; + decl.name = name; #ifdef DEBUG_ENABLED if (check_warnings && HAS_WARNING(ShaderWarning::UNUSED_LOCAL_VARIABLE_FLAG)) { @@ -6584,50 +6507,24 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const FunctionInfo &p_fun tk = _get_token(); - bool is_array_decl = var.array_size > 0 || unknown_size; - if (tk.type == TK_BRACKET_OPEN) { - if (is_array_decl) { - _set_error("Array size is already defined!"); - return ERR_PARSE_ERROR; - } - if (RenderingServer::get_singleton()->is_low_end() && is_const) { _set_error("Local const arrays are supported only on high-end platform!"); return ERR_PARSE_ERROR; } - Error error = _parse_local_array_size(p_block, p_function_info, size_expr, var.array_size, unknown_size); + Error error = _parse_array_size(p_block, p_function_info, false, &decl.size_expression, &var.array_size, &unknown_size); if (error != OK) { return error; } - adecl.single_expression = false; - adecl.size = var.array_size; + decl.size = var.array_size; array_size = var.array_size; - is_array_decl = true; tk = _get_token(); } - if (is_array_decl) { - { - anode = alloc_node<ArrayDeclarationNode>(); - - if (is_struct) { - anode->struct_name = struct_name; - anode->datatype = TYPE_STRUCT; - } else { - anode->datatype = type; - } - - anode->precision = precision; - anode->is_const = is_const; - anode->size_expression = size_expr; - - vardecl = (Node *)anode; - } - + if (var.array_size > 0 || unknown_size) { bool full_def = false; if (tk.type == TK_OP_ASSIGN) { @@ -6648,7 +6545,7 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const FunctionInfo &p_fun return ERR_PARSE_ERROR; } else { if (unknown_size) { - adecl.size = n->get_array_size(); + decl.size = n->get_array_size(); var.array_size = n->get_array_size(); } @@ -6656,8 +6553,8 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const FunctionInfo &p_fun return ERR_PARSE_ERROR; } - adecl.single_expression = true; - adecl.initializer.push_back(n); + decl.single_expression = true; + decl.initializer.push_back(n); } tk = _get_token(); @@ -6702,40 +6599,15 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const FunctionInfo &p_fun tk = _get_token(); if (tk.type == TK_BRACKET_OPEN) { - TkPos pos2 = _get_tkpos(); - tk = _get_token(); - if (tk.type == TK_BRACKET_CLOSE) { + bool is_unknown_size = false; + Error error = _parse_array_size(p_block, p_function_info, false, nullptr, &array_size2, &is_unknown_size); + if (error != OK) { + return error; + } + if (is_unknown_size) { array_size2 = var.array_size; - tk = _get_token(); - } else { - _set_tkpos(pos2); - - Node *n = _parse_and_reduce_expression(p_block, p_function_info); - if (!n || n->type != Node::TYPE_CONSTANT || n->get_datatype() != TYPE_INT) { - _set_error("Expected single integer constant > 0"); - return ERR_PARSE_ERROR; - } - - ConstantNode *cnode = (ConstantNode *)n; - if (cnode->values.size() == 1) { - array_size2 = cnode->values[0].sint; - if (array_size2 <= 0) { - _set_error("Expected single integer constant > 0"); - return ERR_PARSE_ERROR; - } - } else { - _set_error("Expected single integer constant > 0"); - return ERR_PARSE_ERROR; - } - - tk = _get_token(); - if (tk.type != TK_BRACKET_CLOSE) { - _set_error("Expected ']'"); - return ERR_PARSE_ERROR; - } else { - tk = _get_token(); - } } + tk = _get_token(); } else { _set_error("Expected '['"); return ERR_PARSE_ERROR; @@ -6796,7 +6668,7 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const FunctionInfo &p_fun return ERR_PARSE_ERROR; } - if (anode->is_const && n->type == Node::TYPE_OPERATOR && ((OperatorNode *)n)->op == OP_CALL) { + if (is_const && n->type == Node::TYPE_OPERATOR && ((OperatorNode *)n)->op == OP_CALL) { _set_error("Expected constant expression"); return ERR_PARSE_ERROR; } @@ -6807,13 +6679,13 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const FunctionInfo &p_fun tk = _get_token(); if (tk.type == TK_COMMA) { - adecl.initializer.push_back(n); + decl.initializer.push_back(n); continue; } else if (!curly && tk.type == TK_PARENTHESIS_CLOSE) { - adecl.initializer.push_back(n); + decl.initializer.push_back(n); break; } else if (curly && tk.type == TK_CURLY_BRACKET_CLOSE) { - adecl.initializer.push_back(n); + decl.initializer.push_back(n); break; } else { if (curly) { @@ -6825,9 +6697,9 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const FunctionInfo &p_fun } } if (unknown_size) { - adecl.size = adecl.initializer.size(); - var.array_size = adecl.initializer.size(); - } else if (adecl.initializer.size() != var.array_size) { + decl.size = decl.initializer.size(); + var.array_size = decl.initializer.size(); + } else if (decl.initializer.size() != var.array_size) { _set_error("Array size mismatch"); return ERR_PARSE_ERROR; } @@ -6839,36 +6711,20 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const FunctionInfo &p_fun _set_error("Expected array initialization"); return ERR_PARSE_ERROR; } - if (anode->is_const) { + if (is_const) { _set_error("Expected initialization of constant"); return ERR_PARSE_ERROR; } } array_size = var.array_size; - anode->declarations.push_back(adecl); } else if (tk.type == TK_OP_ASSIGN) { - VariableDeclarationNode *node = alloc_node<VariableDeclarationNode>(); - if (is_struct) { - node->struct_name = struct_name; - node->datatype = TYPE_STRUCT; - } else { - node->datatype = type; - } - node->precision = precision; - node->is_const = is_const; - vardecl = (Node *)node; - - VariableDeclarationNode::Declaration decl; - decl.name = name; - decl.initializer = nullptr; - //variable created with assignment! must parse an expression Node *n = _parse_and_reduce_expression(p_block, p_function_info); if (!n) { return ERR_PARSE_ERROR; } - if (node->is_const && n->type == Node::TYPE_OPERATOR && ((OperatorNode *)n)->op == OP_CALL) { + if (is_const && n->type == Node::TYPE_OPERATOR && ((OperatorNode *)n)->op == OP_CALL) { OperatorNode *op = ((OperatorNode *)n); for (int i = 1; i < op->arguments.size(); i++) { if (!_check_node_constness(op->arguments[i])) { @@ -6877,7 +6733,6 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const FunctionInfo &p_fun } } } - decl.initializer = n; if (n->type == Node::TYPE_CONSTANT) { ConstantNode *const_node = static_cast<ConstantNode *>(n); @@ -6889,31 +6744,17 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const FunctionInfo &p_fun if (!_compare_datatypes(var.type, var.struct_name, var.array_size, n->get_datatype(), n->get_datatype_name(), n->get_array_size())) { return ERR_PARSE_ERROR; } + + decl.initializer.push_back(n); tk = _get_token(); - node->declarations.push_back(decl); } else { if (is_const) { _set_error("Expected initialization of constant"); return ERR_PARSE_ERROR; } - - VariableDeclarationNode *node = alloc_node<VariableDeclarationNode>(); - if (is_struct) { - node->struct_name = struct_name; - node->datatype = TYPE_STRUCT; - } else { - node->datatype = type; - } - node->precision = precision; - vardecl = (Node *)node; - - VariableDeclarationNode::Declaration decl; - decl.name = name; - decl.initializer = nullptr; - node->declarations.push_back(decl); } - p_block->statements.push_back(vardecl); + vdnode->declarations.push_back(decl); p_block->variables[name] = var; if (!fixed_array_size) { @@ -6932,6 +6773,8 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const FunctionInfo &p_fun return ERR_PARSE_ERROR; } } while (tk.type == TK_COMMA); //another variable + + p_block->statements.push_back((Node *)vdnode); } else if (tk.type == TK_CURLY_BRACKET_OPEN) { //a sub block, just because.. BlockNode *block = alloc_node<BlockNode>(); @@ -7563,17 +7406,13 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct return ERR_PARSE_ERROR; } - tk = _get_token(); + StringName shader_type_identifier; + _get_completable_identifier(nullptr, COMPLETION_SHADER_TYPE, shader_type_identifier); - if (tk.type != TK_IDENTIFIER) { + if (shader_type_identifier == StringName()) { _set_error("Expected identifier after 'shader_type', indicating type of shader. Valid types are: " + _get_shader_type_list(p_shader_types)); return ERR_PARSE_ERROR; } - - String shader_type_identifier; - - shader_type_identifier = tk.text; - if (!p_shader_types.has(shader_type_identifier)) { _set_error("Invalid shader type. Valid types are: " + _get_shader_type_list(p_shader_types)); return ERR_PARSE_ERROR; @@ -7596,8 +7435,16 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct #ifdef DEBUG_ENABLED int uniform_buffer_size = 0; int max_uniform_buffer_size = 0; - if (RenderingDevice::get_singleton()) { - max_uniform_buffer_size = RenderingDevice::get_singleton()->limit_get(RenderingDevice::LIMIT_MAX_UNIFORM_BUFFER_SIZE); + int uniform_buffer_exceeded_line = -1; + + bool check_device_limit_warnings = false; + { + RenderingDevice *device = RenderingDevice::get_singleton(); + if (device != nullptr) { + check_device_limit_warnings = check_warnings && HAS_WARNING(ShaderWarning::DEVICE_LIMIT_EXCEEDED_FLAG); + + max_uniform_buffer_size = device->limit_get(RenderingDevice::LIMIT_MAX_UNIFORM_BUFFER_SIZE); + } } #endif // DEBUG_ENABLED ShaderNode::Uniform::Scope uniform_scope = ShaderNode::Uniform::SCOPE_LOCAL; @@ -7760,7 +7607,7 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct } if (tk.type == TK_BRACKET_OPEN) { - Error error = _parse_global_array_size(array_size, constants); + Error error = _parse_array_size(nullptr, constants, true, nullptr, &array_size, nullptr); if (error != OK) { return error; } @@ -7789,7 +7636,7 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct tk = _get_token(); if (tk.type == TK_BRACKET_OPEN) { - Error error = _parse_global_array_size(member->array_size, constants); + Error error = _parse_array_size(nullptr, constants, true, nullptr, &member->array_size, nullptr); if (error != OK) { return error; } @@ -7921,7 +7768,7 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct } if (tk.type == TK_BRACKET_OPEN) { - Error error = _parse_global_array_size(array_size, constants); + Error error = _parse_array_size(nullptr, constants, true, nullptr, &array_size, nullptr); if (error != OK) { return error; } @@ -7969,7 +7816,7 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct tk = _get_token(); if (tk.type == TK_BRACKET_OPEN) { - Error error = _parse_global_array_size(uniform2.array_size, constants); + Error error = _parse_array_size(nullptr, constants, true, nullptr, &uniform2.array_size, nullptr); if (error != OK) { return error; } @@ -8001,15 +7848,21 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct if (uniform_scope != ShaderNode::Uniform::SCOPE_INSTANCE) { uniform2.order = uniforms++; #ifdef DEBUG_ENABLED - if (uniform2.array_size > 0) { - int size = get_datatype_size(uniform2.type) * uniform2.array_size; - int m = (16 * uniform2.array_size); - if ((size % m) != 0U) { - size += m - (size % m); + if (check_device_limit_warnings) { + if (uniform2.array_size > 0) { + int size = get_datatype_size(uniform2.type) * uniform2.array_size; + int m = (16 * uniform2.array_size); + if ((size % m) != 0U) { + size += m - (size % m); + } + uniform_buffer_size += size; + } else { + uniform_buffer_size += get_datatype_size(uniform2.type); + } + + if (uniform_buffer_exceeded_line == -1 && uniform_buffer_size > max_uniform_buffer_size) { + uniform_buffer_exceeded_line = tk_line; } - uniform_buffer_size += size; - } else { - uniform_buffer_size += get_datatype_size(uniform2.type); } #endif // DEBUG_ENABLED } @@ -8298,29 +8151,11 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct } if (tk.type == TK_BRACKET_OPEN) { - if (array_size > 0) { - _set_error("Array size is already defined!"); - return ERR_PARSE_ERROR; + Error error = _parse_array_size(nullptr, constants, true, nullptr, &varying.array_size, nullptr); + if (error != OK) { + return error; } tk = _get_token(); - if (tk.is_integer_constant() && tk.constant > 0) { - varying.array_size = (int)tk.constant; - - tk = _get_token(); - if (tk.type == TK_BRACKET_CLOSE) { - tk = _get_token(); - if (tk.type != TK_SEMICOLON) { - _set_error("Expected ';'"); - return ERR_PARSE_ERROR; - } - } else { - _set_error("Expected ']'"); - return ERR_PARSE_ERROR; - } - } else { - _set_error("Expected integer constant > 0"); - return ERR_PARSE_ERROR; - } } shader->varyings[name] = varying; @@ -8332,6 +8167,10 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct } } break; + case TK_SHADER_TYPE: { + _set_error("Shader type is already defined."); + return ERR_PARSE_ERROR; + } break; default: { //function or constant variable @@ -8381,36 +8220,18 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct tk = _get_token(); bool unknown_size = false; + bool fixed_array_size = false; if (tk.type == TK_BRACKET_OPEN) { if (is_constant && RenderingServer::get_singleton()->is_low_end()) { _set_error("Global const arrays are only supported on high-end platform!"); return ERR_PARSE_ERROR; } - bool error = false; - tk = _get_token(); - - if (tk.is_integer_constant()) { - array_size = (int)tk.constant; - if (array_size > 0) { - tk = _get_token(); - if (tk.type != TK_BRACKET_CLOSE) { - _set_error("Expected ']'"); - return ERR_PARSE_ERROR; - } - } else { - error = true; - } - } else if (tk.type == TK_BRACKET_CLOSE) { - unknown_size = true; - } else { - error = true; - } - if (error) { - _set_error("Expected integer constant > 0 or ']'"); - return ERR_PARSE_ERROR; + Error error = _parse_array_size(nullptr, constants, !is_constant, nullptr, &array_size, &unknown_size); + if (error != OK) { + return error; } - + fixed_array_size = true; prev_pos = _get_tkpos(); } @@ -8440,7 +8261,6 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct } //variable - bool first = true; while (true) { ShaderNode::Constant constant; constant.name = name; @@ -8448,34 +8268,18 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct constant.type_str = struct_name; constant.precision = precision; constant.initializer = nullptr; - constant.array_size = (first ? array_size : 0); - first = false; + constant.array_size = array_size; if (tk.type == TK_BRACKET_OPEN) { if (RenderingServer::get_singleton()->is_low_end()) { _set_error("Global const arrays are only supported on high-end platform!"); return ERR_PARSE_ERROR; } - if (constant.array_size > 0 || unknown_size) { - _set_error("Array size is already defined!"); - return ERR_PARSE_ERROR; + Error error = _parse_array_size(nullptr, constants, false, nullptr, &constant.array_size, &unknown_size); + if (error != OK) { + return error; } tk = _get_token(); - if (tk.type == TK_BRACKET_CLOSE) { - unknown_size = true; - tk = _get_token(); - } else if (tk.is_integer_constant() && ((int)tk.constant) > 0) { - constant.array_size = (int)tk.constant; - tk = _get_token(); - if (tk.type != TK_BRACKET_CLOSE) { - _set_error("Expected ']'"); - return ERR_PARSE_ERROR; - } - tk = _get_token(); - } else { - _set_error("Expected integer constant > 0 or ']'"); - return ERR_PARSE_ERROR; - } } if (tk.type == TK_OP_ASSIGN) { @@ -8487,7 +8291,7 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct if (constant.array_size > 0 || unknown_size) { bool full_def = false; - ArrayDeclarationNode::Declaration decl; + VariableDeclarationNode::Declaration decl; decl.name = name; decl.size = constant.array_size; @@ -8526,43 +8330,18 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct } int array_size2 = 0; - tk = _get_token(); + if (tk.type == TK_BRACKET_OPEN) { - prev_pos = _get_tkpos(); - tk = _get_token(); - if (tk.type == TK_BRACKET_CLOSE) { + bool is_unknown_size = false; + Error error = _parse_array_size(nullptr, constants, false, nullptr, &array_size2, &is_unknown_size); + if (error != OK) { + return error; + } + if (is_unknown_size) { array_size2 = constant.array_size; - tk = _get_token(); - } else { - _set_tkpos(prev_pos); - - Node *n = _parse_and_reduce_expression(nullptr, constants); - if (!n || n->type != Node::TYPE_CONSTANT || n->get_datatype() != TYPE_INT) { - _set_error("Expected single integer constant > 0"); - return ERR_PARSE_ERROR; - } - - ConstantNode *cnode = (ConstantNode *)n; - if (cnode->values.size() == 1) { - array_size2 = cnode->values[0].sint; - if (array_size2 <= 0) { - _set_error("Expected single integer constant > 0"); - return ERR_PARSE_ERROR; - } - } else { - _set_error("Expected single integer constant > 0"); - return ERR_PARSE_ERROR; - } - - tk = _get_token(); - if (tk.type != TK_BRACKET_CLOSE) { - _set_error("Expected ']"); - return ERR_PARSE_ERROR; - } else { - tk = _get_token(); - } } + tk = _get_token(); } else { _set_error("Expected '["); return ERR_PARSE_ERROR; @@ -8660,6 +8439,8 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct } } + array_size = constant.array_size; + ConstantNode *expr = memnew(ConstantNode); expr->datatype = constant.type; @@ -8732,6 +8513,11 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct tk = _get_token(); + if (!fixed_array_size) { + array_size = 0; + } + unknown_size = false; + } else if (tk.type == TK_SEMICOLON) { break; } else { @@ -8760,6 +8546,13 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct } } + for (int i = 0; i < shader->functions.size(); i++) { + if (!shader->functions[i].callable && shader->functions[i].name == name) { + _set_error("Redefinition of '" + String(name) + "'"); + return ERR_PARSE_ERROR; + } + } + ShaderNode::Function function; function.callable = !p_functions.has(name); @@ -8881,27 +8674,9 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct tk = _get_token(); if (tk.type == TK_BRACKET_OPEN) { - bool error = false; - tk = _get_token(); - - if (tk.is_integer_constant()) { - arg_array_size = (int)tk.constant; - - if (arg_array_size > 0) { - tk = _get_token(); - if (tk.type != TK_BRACKET_CLOSE) { - _set_error("Expected ']'"); - return ERR_PARSE_ERROR; - } - } else { - error = true; - } - } else { - error = true; - } - if (error) { - _set_error("Expected integer constant > 0"); - return ERR_PARSE_ERROR; + Error error = _parse_array_size(nullptr, constants, true, nullptr, &arg_array_size, nullptr); + if (error != OK) { + return error; } tk = _get_token(); } @@ -8939,32 +8714,9 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct tk = _get_token(); if (tk.type == TK_BRACKET_OPEN) { - if (arg_array_size > 0) { - _set_error("Array size is already defined!"); - return ERR_PARSE_ERROR; - } - bool error = false; - tk = _get_token(); - - if (tk.is_integer_constant()) { - arg_array_size = (int)tk.constant; - - if (arg_array_size > 0) { - tk = _get_token(); - if (tk.type != TK_BRACKET_CLOSE) { - _set_error("Expected ']'"); - return ERR_PARSE_ERROR; - } - } else { - error = true; - } - } else { - error = true; - } - - if (error) { - _set_error("Expected integer constant > 0"); - return ERR_PARSE_ERROR; + Error error = _parse_array_size(nullptr, constants, true, nullptr, &arg_array_size, nullptr); + if (error != OK) { + return error; } tk = _get_token(); } @@ -9022,11 +8774,8 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct } #ifdef DEBUG_ENABLED - if (HAS_WARNING(ShaderWarning::DEVICE_LIMIT_EXCEEDED) && (uniform_buffer_size > max_uniform_buffer_size)) { - Vector<Variant> args; - args.push_back(uniform_buffer_size); - args.push_back(max_uniform_buffer_size); - _add_global_warning(ShaderWarning::DEVICE_LIMIT_EXCEEDED, "uniform buffer", args); + if (check_device_limit_warnings && uniform_buffer_exceeded_line != -1) { + _add_warning(ShaderWarning::DEVICE_LIMIT_EXCEEDED, uniform_buffer_exceeded_line, "uniform buffer", { uniform_buffer_size, max_uniform_buffer_size }); } #endif // DEBUG_ENABLED return OK; @@ -9249,6 +8998,13 @@ Error ShaderLanguage::complete(const String &p_code, const ShaderCompileInfo &p_ //do nothing return OK; } break; + case COMPLETION_SHADER_TYPE: { + for (const String &shader_type : p_info.shader_types) { + ScriptCodeCompletionOption option(shader_type, ScriptCodeCompletionOption::KIND_PLAIN_TEXT); + r_options->push_back(option); + } + return OK; + } break; case COMPLETION_RENDER_MODE: { for (int i = 0; i < p_info.render_modes.size(); i++) { const ModeInfo &info = p_info.render_modes[i]; @@ -9264,7 +9020,7 @@ Error ShaderLanguage::complete(const String &p_code, const ShaderCompileInfo &p_ if (!found) { for (int j = 0; j < info.options.size(); j++) { - ScriptCodeCompletionOption option(String(info.name) + "_" + String(info.options[j]), ScriptCodeCompletionOption::KIND_ENUM); + ScriptCodeCompletionOption option(String(info.name) + "_" + String(info.options[j]), ScriptCodeCompletionOption::KIND_PLAIN_TEXT); r_options->push_back(option); } } @@ -9272,7 +9028,7 @@ Error ShaderLanguage::complete(const String &p_code, const ShaderCompileInfo &p_ const String name = String(info.name); if (!shader->render_modes.has(name)) { - ScriptCodeCompletionOption option(name, ScriptCodeCompletionOption::KIND_ENUM); + ScriptCodeCompletionOption option(name, ScriptCodeCompletionOption::KIND_PLAIN_TEXT); r_options->push_back(option); } } @@ -9358,6 +9114,9 @@ Error ShaderLanguage::complete(const String &p_code, const ShaderCompileInfo &p_ } } + for (const KeyValue<StringName, ShaderNode::Constant> &E : shader->constants) { + matches.insert(E.key, ScriptCodeCompletionOption::KIND_CONSTANT); + } for (const KeyValue<StringName, ShaderNode::Varying> &E : shader->varyings) { matches.insert(E.key, ScriptCodeCompletionOption::KIND_VARIABLE); } diff --git a/servers/rendering/shader_language.h b/servers/rendering/shader_language.h index b9c2d4b33c..c619934182 100644 --- a/servers/rendering/shader_language.h +++ b/servers/rendering/shader_language.h @@ -362,7 +362,6 @@ public: TYPE_CONTROL_FLOW, TYPE_MEMBER, TYPE_ARRAY, - TYPE_ARRAY_DECLARATION, TYPE_ARRAY_CONSTRUCT, TYPE_STRUCT, }; @@ -428,7 +427,10 @@ public: struct Declaration { StringName name; - Node *initializer; + uint32_t size = 0U; + Node *size_expression = nullptr; + Vector<Node *> initializer; + bool single_expression = false; }; Vector<Declaration> declarations; @@ -471,27 +473,6 @@ public: Node(TYPE_ARRAY_CONSTRUCT) {} }; - struct ArrayDeclarationNode : public Node { - DataPrecision precision = PRECISION_DEFAULT; - DataType datatype = TYPE_VOID; - String struct_name; - bool is_const = false; - Node *size_expression = nullptr; - - struct Declaration { - StringName name; - uint32_t size; - Vector<Node *> initializer; - bool single_expression; - }; - Vector<Declaration> declarations; - - virtual DataType get_datatype() const override { return datatype; } - - ArrayDeclarationNode() : - Node(TYPE_ARRAY_DECLARATION) {} - }; - struct ConstantNode : public Node { DataType datatype = TYPE_VOID; String struct_name = ""; @@ -505,7 +486,7 @@ public: }; Vector<Value> values; - Vector<ArrayDeclarationNode::Declaration> array_declarations; + Vector<VariableDeclarationNode::Declaration> array_declarations; virtual DataType get_datatype() const override { return datatype; } virtual String get_datatype_name() const override { return struct_name; } @@ -742,6 +723,7 @@ public: enum CompletionType { COMPLETION_NONE, + COMPLETION_SHADER_TYPE, COMPLETION_RENDER_MODE, COMPLETION_MAIN_FUNCTION, COMPLETION_IDENTIFIER, @@ -1044,11 +1026,8 @@ private: bool _validate_varying_assign(ShaderNode::Varying &p_varying, String *r_message); bool _check_node_constness(const Node *p_node) const; - Node *_parse_array_size(BlockNode *p_block, const FunctionInfo &p_function_info, int &r_array_size); - Error _parse_global_array_size(int &r_array_size, const FunctionInfo &p_function_info); - Error _parse_local_array_size(BlockNode *p_block, const FunctionInfo &p_function_info, Node *&r_size_expression, int &r_array_size, bool &r_is_unknown_size); - Node *_parse_expression(BlockNode *p_block, const FunctionInfo &p_function_info); + Error _parse_array_size(BlockNode *p_block, const FunctionInfo &p_function_info, bool p_forbid_unknown_size, Node **r_size_expression, int *r_array_size, bool *r_unknown_size); Node *_parse_array_constructor(BlockNode *p_block, const FunctionInfo &p_function_info); Node *_parse_array_constructor(BlockNode *p_block, const FunctionInfo &p_function_info, DataType p_type, const StringName &p_struct_name, int p_array_size); ShaderLanguage::Node *_reduce_expression(BlockNode *p_block, ShaderLanguage::Node *p_node); diff --git a/servers/rendering_server.cpp b/servers/rendering_server.cpp index 1db9593473..863aae6e4c 100644 --- a/servers/rendering_server.cpp +++ b/servers/rendering_server.cpp @@ -32,6 +32,7 @@ #include "core/config/project_settings.h" #include "servers/rendering/rendering_server_globals.h" +#include "servers/rendering/shader_language.h" RenderingServer *RenderingServer::singleton = nullptr; RenderingServer *(*RenderingServer::create_func)() = nullptr; @@ -1411,7 +1412,7 @@ Array RenderingServer::_mesh_surface_get_skeleton_aabb_bind(RID p_mesh, int p_su } #endif -ShaderLanguage::DataType RenderingServer::global_variable_type_get_shader_datatype(GlobalVariableType p_type) { +int RenderingServer::global_variable_type_get_shader_datatype(GlobalVariableType p_type) { switch (p_type) { case RS::GLOBAL_VAR_TYPE_BOOL: return ShaderLanguage::TYPE_BOOL; @@ -2000,6 +2001,10 @@ void RenderingServer::_bind_methods() { BIND_ENUM_CONSTANT(DECAL_FILTER_LINEAR_MIPMAPS); BIND_ENUM_CONSTANT(DECAL_FILTER_LINEAR_MIPMAPS_ANISOTROPIC); + /* GI API (affects VoxelGI and SDFGI) */ + + ClassDB::bind_method(D_METHOD("gi_set_use_half_resolution", "half_resolution"), &RenderingServer::gi_set_use_half_resolution); + /* VOXEL GI API */ ClassDB::bind_method(D_METHOD("voxel_gi_create"), &RenderingServer::voxel_gi_create); @@ -2325,6 +2330,7 @@ void RenderingServer::_bind_methods() { ClassDB::bind_method(D_METHOD("environment_glow_set_use_high_quality", "enable"), &RenderingServer::environment_glow_set_use_high_quality); ClassDB::bind_method(D_METHOD("environment_set_ssr_roughness_quality", "quality"), &RenderingServer::environment_set_ssr_roughness_quality); ClassDB::bind_method(D_METHOD("environment_set_ssao_quality", "quality", "half_size", "adaptive_target", "blur_passes", "fadeout_from", "fadeout_to"), &RenderingServer::environment_set_ssao_quality); + ClassDB::bind_method(D_METHOD("environment_set_ssil_quality", "quality", "half_size", "adaptive_target", "blur_passes", "fadeout_from", "fadeout_to"), &RenderingServer::environment_set_ssil_quality); ClassDB::bind_method(D_METHOD("environment_set_sdfgi_ray_count", "ray_count"), &RenderingServer::environment_set_sdfgi_ray_count); ClassDB::bind_method(D_METHOD("environment_set_sdfgi_frames_to_converge", "frames"), &RenderingServer::environment_set_sdfgi_frames_to_converge); ClassDB::bind_method(D_METHOD("environment_set_sdfgi_frames_to_update_light", "frames"), &RenderingServer::environment_set_sdfgi_frames_to_update_light); @@ -2376,9 +2382,11 @@ void RenderingServer::_bind_methods() { BIND_ENUM_CONSTANT(ENV_SSAO_QUALITY_HIGH); BIND_ENUM_CONSTANT(ENV_SSAO_QUALITY_ULTRA); - BIND_ENUM_CONSTANT(ENV_SDFGI_CASCADES_4); - BIND_ENUM_CONSTANT(ENV_SDFGI_CASCADES_6); - BIND_ENUM_CONSTANT(ENV_SDFGI_CASCADES_8); + BIND_ENUM_CONSTANT(ENV_SSIL_QUALITY_VERY_LOW); + BIND_ENUM_CONSTANT(ENV_SSIL_QUALITY_LOW); + BIND_ENUM_CONSTANT(ENV_SSIL_QUALITY_MEDIUM); + BIND_ENUM_CONSTANT(ENV_SSIL_QUALITY_HIGH); + BIND_ENUM_CONSTANT(ENV_SSIL_QUALITY_ULTRA); BIND_ENUM_CONSTANT(ENV_SDFGI_Y_SCALE_DISABLED); BIND_ENUM_CONSTANT(ENV_SDFGI_Y_SCALE_75_PERCENT); @@ -2810,7 +2818,6 @@ RenderingServer::RenderingServer() { GLOBAL_DEF_RST("rendering/textures/vram_compression/import_s3tc", true); GLOBAL_DEF_RST("rendering/textures/vram_compression/import_etc", false); GLOBAL_DEF_RST("rendering/textures/vram_compression/import_etc2", true); - GLOBAL_DEF_RST("rendering/textures/vram_compression/import_pvrtc", false); GLOBAL_DEF("rendering/textures/lossless_compression/force_png", false); GLOBAL_DEF("rendering/textures/lossless_compression/webp_compression_level", 2); diff --git a/servers/rendering_server.h b/servers/rendering_server.h index d36784dbab..945fd052c6 100644 --- a/servers/rendering_server.h +++ b/servers/rendering_server.h @@ -41,7 +41,6 @@ #include "servers/display_server.h" #include "servers/rendering/renderer_thread_pool.h" #include "servers/rendering/rendering_device.h" -#include "servers/rendering/shader_language.h" class RenderingServer : public Object { GDCLASS(RenderingServer, Object); @@ -1042,19 +1041,13 @@ public: virtual void environment_set_ssil_quality(EnvironmentSSILQuality p_quality, bool p_half_size, float p_adaptive_target, int p_blur_passes, float p_fadeout_from, float p_fadeout_to) = 0; - enum EnvironmentSDFGICascades { - ENV_SDFGI_CASCADES_4, - ENV_SDFGI_CASCADES_6, - ENV_SDFGI_CASCADES_8, - }; - enum EnvironmentSDFGIYScale { ENV_SDFGI_Y_SCALE_DISABLED, ENV_SDFGI_Y_SCALE_75_PERCENT, ENV_SDFGI_Y_SCALE_50_PERCENT }; - virtual void environment_set_sdfgi(RID p_env, bool p_enable, EnvironmentSDFGICascades p_cascades, float p_min_cell_size, EnvironmentSDFGIYScale p_y_scale, bool p_use_occlusion, float p_bounce_feedback, bool p_read_sky, float p_energy, float p_normal_bias, float p_probe_bias) = 0; + virtual void environment_set_sdfgi(RID p_env, bool p_enable, int p_cascades, float p_min_cell_size, EnvironmentSDFGIYScale p_y_scale, bool p_use_occlusion, float p_bounce_feedback, bool p_read_sky, float p_energy, float p_normal_bias, float p_probe_bias) = 0; enum EnvironmentSDFGIRayCount { ENV_SDFGI_RAY_COUNT_4, @@ -1456,7 +1449,7 @@ public: virtual void global_variables_load_settings(bool p_load_textures) = 0; virtual void global_variables_clear() = 0; - static ShaderLanguage::DataType global_variable_type_get_shader_datatype(GlobalVariableType p_type); + static int global_variable_type_get_shader_datatype(GlobalVariableType p_type); /* FREE */ @@ -1608,7 +1601,7 @@ VARIANT_ENUM_CAST(RenderingServer::EnvironmentGlowBlendMode); VARIANT_ENUM_CAST(RenderingServer::EnvironmentToneMapper); VARIANT_ENUM_CAST(RenderingServer::EnvironmentSSRRoughnessQuality); VARIANT_ENUM_CAST(RenderingServer::EnvironmentSSAOQuality); -VARIANT_ENUM_CAST(RenderingServer::EnvironmentSDFGICascades); +VARIANT_ENUM_CAST(RenderingServer::EnvironmentSSILQuality); VARIANT_ENUM_CAST(RenderingServer::EnvironmentSDFGIFramesToConverge); VARIANT_ENUM_CAST(RenderingServer::EnvironmentSDFGIRayCount); VARIANT_ENUM_CAST(RenderingServer::EnvironmentSDFGIFramesToUpdateLight); diff --git a/servers/text/text_server_extension.cpp b/servers/text/text_server_extension.cpp index 2b0510680e..d7e7960496 100644 --- a/servers/text/text_server_extension.cpp +++ b/servers/text/text_server_extension.cpp @@ -174,6 +174,9 @@ void TextServerExtension::_bind_methods() { GDVIRTUAL_BIND(_font_remove_script_support_override, "font_rid", "script"); GDVIRTUAL_BIND(_font_get_script_support_overrides, "font_rid"); + GDVIRTUAL_BIND(_font_set_opentype_feature_overrides, "font_rid", "overrides"); + GDVIRTUAL_BIND(_font_get_opentype_feature_overrides, "font_rid"); + GDVIRTUAL_BIND(_font_supported_feature_list, "font_rid"); GDVIRTUAL_BIND(_font_supported_variation_list, "font_rid"); @@ -191,6 +194,7 @@ void TextServerExtension::_bind_methods() { GDVIRTUAL_BIND(_shaped_text_set_direction, "shaped", "direction"); GDVIRTUAL_BIND(_shaped_text_get_direction, "shaped"); + GDVIRTUAL_BIND(_shaped_text_get_inferred_direction, "shaped"); GDVIRTUAL_BIND(_shaped_text_set_bidi_override, "shaped", "override"); @@ -267,6 +271,9 @@ void TextServerExtension::_bind_methods() { GDVIRTUAL_BIND(_format_number, "string", "language"); GDVIRTUAL_BIND(_parse_number, "string", "language"); GDVIRTUAL_BIND(_percent_sign, "language"); + + GDVIRTUAL_BIND(_string_to_upper, "string", "language"); + GDVIRTUAL_BIND(_string_to_lower, "string", "language"); } bool TextServerExtension::has_feature(Feature p_feature) const { @@ -869,6 +876,18 @@ Vector<String> TextServerExtension::font_get_script_support_overrides(RID p_font return Vector<String>(); } +void TextServerExtension::font_set_opentype_feature_overrides(RID p_font_rid, const Dictionary &p_overrides) { + GDVIRTUAL_CALL(_font_set_opentype_feature_overrides, p_font_rid, p_overrides); +} + +Dictionary TextServerExtension::font_get_opentype_feature_overrides(RID p_font_rid) const { + Dictionary ret; + if (GDVIRTUAL_CALL(_font_get_opentype_feature_overrides, p_font_rid, ret)) { + return ret; + } + return Dictionary(); +} + Dictionary TextServerExtension::font_supported_feature_list(RID p_font_rid) const { Dictionary ret; if (GDVIRTUAL_CALL(_font_supported_feature_list, p_font_rid, ret)) { @@ -939,6 +958,14 @@ TextServer::Direction TextServerExtension::shaped_text_get_direction(RID p_shape return TextServer::Direction::DIRECTION_AUTO; } +TextServer::Direction TextServerExtension::shaped_text_get_inferred_direction(RID p_shaped) const { + int ret; + if (GDVIRTUAL_CALL(_shaped_text_get_inferred_direction, p_shaped, ret)) { + return (TextServer::Direction)ret; + } + return TextServer::Direction::DIRECTION_LTR; +} + void TextServerExtension::shaped_text_set_orientation(RID p_shaped, TextServer::Orientation p_orientation) { GDVIRTUAL_CALL(_shaped_text_set_orientation, p_shaped, p_orientation); } @@ -1341,6 +1368,22 @@ String TextServerExtension::percent_sign(const String &p_language) const { return TextServer::percent_sign(p_language); } +String TextServerExtension::string_to_upper(const String &p_string, const String &p_language) const { + String ret; + if (GDVIRTUAL_CALL(_string_to_upper, p_string, p_language, ret)) { + return ret; + } + return p_string; +} + +String TextServerExtension::string_to_lower(const String &p_string, const String &p_language) const { + String ret; + if (GDVIRTUAL_CALL(_string_to_lower, p_string, p_language, ret)) { + return ret; + } + return p_string; +} + TextServerExtension::TextServerExtension() { //NOP } diff --git a/servers/text/text_server_extension.h b/servers/text/text_server_extension.h index 5c97401118..6e203f22ee 100644 --- a/servers/text/text_server_extension.h +++ b/servers/text/text_server_extension.h @@ -285,6 +285,11 @@ public: GDVIRTUAL2(_font_remove_script_support_override, RID, const String &); GDVIRTUAL1R(Vector<String>, _font_get_script_support_overrides, RID); + virtual void font_set_opentype_feature_overrides(RID p_font_rid, const Dictionary &p_overrides) override; + virtual Dictionary font_get_opentype_feature_overrides(RID p_font_rid) const override; + GDVIRTUAL2(_font_set_opentype_feature_overrides, RID, const Dictionary &); + GDVIRTUAL1RC(Dictionary, _font_get_opentype_feature_overrides, RID); + virtual Dictionary font_supported_feature_list(RID p_font_rid) const override; virtual Dictionary font_supported_variation_list(RID p_font_rid) const override; GDVIRTUAL1RC(Dictionary, _font_supported_feature_list, RID); @@ -310,8 +315,10 @@ public: virtual void shaped_text_set_direction(RID p_shaped, Direction p_direction = DIRECTION_AUTO) override; virtual Direction shaped_text_get_direction(RID p_shaped) const override; + virtual Direction shaped_text_get_inferred_direction(RID p_shaped) const override; GDVIRTUAL2(_shaped_text_set_direction, RID, Direction); GDVIRTUAL1RC(/*Direction*/ int, _shaped_text_get_direction, RID); + GDVIRTUAL1RC(/*Direction*/ int, _shaped_text_get_inferred_direction, RID); virtual void shaped_text_set_bidi_override(RID p_shaped, const Array &p_override) override; GDVIRTUAL2(_shaped_text_set_bidi_override, RID, const Array &); @@ -442,6 +449,11 @@ public: GDVIRTUAL2RC(String, _parse_number, const String &, const String &); GDVIRTUAL1RC(String, _percent_sign, const String &); + virtual String string_to_upper(const String &p_string, const String &p_language = "") const override; + virtual String string_to_lower(const String &p_string, const String &p_language = "") const override; + GDVIRTUAL2RC(String, _string_to_upper, const String &, const String &); + GDVIRTUAL2RC(String, _string_to_lower, const String &, const String &); + TextServerExtension(); ~TextServerExtension(); }; diff --git a/servers/text_server.cpp b/servers/text_server.cpp index d547bcc75e..17840584ee 100644 --- a/servers/text_server.cpp +++ b/servers/text_server.cpp @@ -327,6 +327,9 @@ void TextServer::_bind_methods() { ClassDB::bind_method(D_METHOD("font_remove_script_support_override", "font_rid", "script"), &TextServer::font_remove_script_support_override); ClassDB::bind_method(D_METHOD("font_get_script_support_overrides", "font_rid"), &TextServer::font_get_script_support_overrides); + ClassDB::bind_method(D_METHOD("font_set_opentype_feature_overrides", "font_rid", "overrides"), &TextServer::font_set_opentype_feature_overrides); + ClassDB::bind_method(D_METHOD("font_get_opentype_feature_overrides", "font_rid"), &TextServer::font_get_opentype_feature_overrides); + ClassDB::bind_method(D_METHOD("font_supported_feature_list", "font_rid"), &TextServer::font_supported_feature_list); ClassDB::bind_method(D_METHOD("font_supported_variation_list", "font_rid"), &TextServer::font_supported_variation_list); @@ -344,6 +347,7 @@ void TextServer::_bind_methods() { ClassDB::bind_method(D_METHOD("shaped_text_set_direction", "shaped", "direction"), &TextServer::shaped_text_set_direction, DEFVAL(DIRECTION_AUTO)); ClassDB::bind_method(D_METHOD("shaped_text_get_direction", "shaped"), &TextServer::shaped_text_get_direction); + ClassDB::bind_method(D_METHOD("shaped_text_get_inferred_direction", "shaped"), &TextServer::shaped_text_get_inferred_direction); ClassDB::bind_method(D_METHOD("shaped_text_set_bidi_override", "shaped", "override"), &TextServer::shaped_text_set_bidi_override); @@ -418,6 +422,9 @@ void TextServer::_bind_methods() { ClassDB::bind_method(D_METHOD("strip_diacritics", "string"), &TextServer::strip_diacritics); + ClassDB::bind_method(D_METHOD("string_to_upper", "string", "language"), &TextServer::string_to_upper, DEFVAL("")); + ClassDB::bind_method(D_METHOD("string_to_lower", "string", "language"), &TextServer::string_to_lower, DEFVAL("")); + /* Direction */ BIND_ENUM_CONSTANT(DIRECTION_AUTO); BIND_ENUM_CONSTANT(DIRECTION_LTR); @@ -476,6 +483,7 @@ void TextServer::_bind_methods() { BIND_ENUM_CONSTANT(FEATURE_BREAK_ITERATORS); BIND_ENUM_CONSTANT(FEATURE_FONT_SYSTEM); BIND_ENUM_CONSTANT(FEATURE_FONT_VARIABLE); + BIND_ENUM_CONSTANT(FEATURE_CONTEXT_SENSITIVE_CASE_CONVERSION); BIND_ENUM_CONSTANT(FEATURE_USE_SUPPORT_DATA); /* FT Contour Point Types */ @@ -989,9 +997,9 @@ Vector<Vector2> TextServer::shaped_text_get_selection(RID p_shaped, int p_start, } real_t char_adv = advance / (real_t)(glyphs[i].end - glyphs[i].start); if ((glyphs[i].flags & GRAPHEME_IS_RTL) == GRAPHEME_IS_RTL) { - ranges.push_back(Vector2(off, off + char_adv * (start - glyphs[i].start))); + ranges.push_back(Vector2(off, off + char_adv * (glyphs[i].end - start))); } else { - ranges.push_back(Vector2(off + char_adv * (glyphs[i].end - start), off + advance)); + ranges.push_back(Vector2(off + char_adv * (start - glyphs[i].start), off + advance)); } } // Selection range is within grapheme. @@ -1099,6 +1107,31 @@ int TextServer::shaped_text_hit_test_position(RID p_shaped, float p_coords) cons return glyphs[i].start; } } + // Ligature, handle mid-grapheme hit. + if (p_coords >= off && p_coords < off + advance && glyphs[i].end > glyphs[i].start + 1) { + int cnt = glyphs[i].end - glyphs[i].start; + real_t char_adv = advance / (real_t)(cnt); + real_t sub_off = off; + for (int j = 0; j < cnt; j++) { + // Place caret to the left of clicked sub-grapheme. + if (p_coords >= sub_off && p_coords < sub_off + char_adv / 2) { + if ((glyphs[i].flags & GRAPHEME_IS_RTL) == GRAPHEME_IS_RTL) { + return glyphs[i].end - j; + } else { + return glyphs[i].start + j; + } + } + // Place caret to the right of clicked sub-grapheme. + if (p_coords >= sub_off + char_adv / 2 && p_coords < sub_off + char_adv) { + if ((glyphs[i].flags & GRAPHEME_IS_RTL) == GRAPHEME_IS_RTL) { + return glyphs[i].start + (cnt - 1) - j; + } else { + return glyphs[i].end - (cnt - 1) + j; + } + } + sub_off += char_adv; + } + } // Place caret to the left of clicked grapheme. if (p_coords >= off && p_coords < off + advance / 2) { if ((glyphs[i].flags & GRAPHEME_IS_RTL) == GRAPHEME_IS_RTL) { @@ -1196,6 +1229,17 @@ void TextServer::shaped_text_draw(RID p_shaped, RID p_canvas, const Vector2 &p_p } // Draw at the baseline. for (int i = 0; i < v_size; i++) { + if (trim_pos >= 0) { + if (rtl) { + if (i < trim_pos) { + continue; + } + } else { + if (i >= trim_pos) { + break; + } + } + } for (int j = 0; j < glyphs[i].repeat; j++) { if (p_clip_r > 0) { // Clip right / bottom. @@ -1223,17 +1267,6 @@ void TextServer::shaped_text_draw(RID p_shaped, RID p_canvas, const Vector2 &p_p } } } - if (trim_pos >= 0) { - if (rtl) { - if (i < trim_pos && (glyphs[j].flags & TextServer::GRAPHEME_IS_VIRTUAL) != TextServer::GRAPHEME_IS_VIRTUAL) { - continue; - } - } else { - if (i >= trim_pos && (glyphs[j].flags & TextServer::GRAPHEME_IS_VIRTUAL) != TextServer::GRAPHEME_IS_VIRTUAL) { - break; - } - } - } if (glyphs[i].font_rid != RID()) { font_draw_glyph(glyphs[i].font_rid, p_canvas, glyphs[i].font_size, ofs + Vector2(glyphs[i].x_off, glyphs[i].y_off), glyphs[i].index, p_color); @@ -1265,7 +1298,7 @@ void TextServer::shaped_text_draw(RID p_shaped, RID p_canvas, const Vector2 &p_p void TextServer::shaped_text_draw_outline(RID p_shaped, RID p_canvas, const Vector2 &p_pos, float p_clip_l, float p_clip_r, int p_outline_size, const Color &p_color) const { TextServer::Orientation orientation = shaped_text_get_orientation(p_shaped); - bool rtl = (shaped_text_get_direction(p_shaped) == DIRECTION_RTL); + bool rtl = (shaped_text_get_inferred_direction(p_shaped) == DIRECTION_RTL); int ellipsis_pos = shaped_text_get_ellipsis_pos(p_shaped); int trim_pos = shaped_text_get_trim_pos(p_shaped); @@ -1291,6 +1324,17 @@ void TextServer::shaped_text_draw_outline(RID p_shaped, RID p_canvas, const Vect } // Draw at the baseline. for (int i = 0; i < v_size; i++) { + if (trim_pos >= 0) { + if (rtl) { + if (i < trim_pos) { + continue; + } + } else { + if (i >= trim_pos) { + break; + } + } + } for (int j = 0; j < glyphs[i].repeat; j++) { if (p_clip_r > 0) { // Clip right / bottom. @@ -1318,17 +1362,6 @@ void TextServer::shaped_text_draw_outline(RID p_shaped, RID p_canvas, const Vect } } } - if (trim_pos >= 0) { - if (rtl) { - if (i < trim_pos) { - continue; - } - } else { - if (i >= trim_pos && (glyphs[j].flags & TextServer::GRAPHEME_IS_VIRTUAL) != TextServer::GRAPHEME_IS_VIRTUAL) { - break; - } - } - } if (glyphs[i].font_rid != RID()) { font_draw_glyph_outline(glyphs[i].font_rid, p_canvas, glyphs[i].font_size, p_outline_size, ofs + Vector2(glyphs[i].x_off, glyphs[i].y_off), glyphs[i].index, p_color); } diff --git a/servers/text_server.h b/servers/text_server.h index e9c5248866..599cc3afd0 100644 --- a/servers/text_server.h +++ b/servers/text_server.h @@ -109,7 +109,8 @@ public: FEATURE_BREAK_ITERATORS = 1 << 4, FEATURE_FONT_SYSTEM = 1 << 5, FEATURE_FONT_VARIABLE = 1 << 6, - FEATURE_USE_SUPPORT_DATA = 1 << 7 + FEATURE_CONTEXT_SENSITIVE_CASE_CONVERSION = 1 << 7, + FEATURE_USE_SUPPORT_DATA = 1 << 8, }; enum ContourPointTag { @@ -350,6 +351,9 @@ public: virtual void font_remove_script_support_override(RID p_font_rid, const String &p_script) = 0; virtual Vector<String> font_get_script_support_overrides(RID p_font_rid) = 0; + virtual void font_set_opentype_feature_overrides(RID p_font_rid, const Dictionary &p_overrides) = 0; + virtual Dictionary font_get_opentype_feature_overrides(RID p_font_rid) const = 0; + virtual Dictionary font_supported_feature_list(RID p_font_rid) const = 0; virtual Dictionary font_supported_variation_list(RID p_font_rid) const = 0; @@ -367,6 +371,7 @@ public: virtual void shaped_text_set_direction(RID p_shaped, Direction p_direction = DIRECTION_AUTO) = 0; virtual Direction shaped_text_get_direction(RID p_shaped) const = 0; + virtual Direction shaped_text_get_inferred_direction(RID p_shaped) const = 0; virtual void shaped_text_set_bidi_override(RID p_shaped, const Array &p_override) = 0; @@ -453,6 +458,10 @@ public: virtual String strip_diacritics(const String &p_string) const; + // Other string operations. + virtual String string_to_upper(const String &p_string, const String &p_language = "") const = 0; + virtual String string_to_lower(const String &p_string, const String &p_language = "") const = 0; + TextServer(); ~TextServer(); }; diff --git a/servers/xr/xr_interface.h b/servers/xr/xr_interface.h index 03563026c8..aee98f8fee 100644 --- a/servers/xr/xr_interface.h +++ b/servers/xr/xr_interface.h @@ -39,8 +39,6 @@ struct BlitToScreen; /** - @author Bastiaan Olij <mux213@gmail.com> - The XR interface is a template class on top of which we build interface to different AR, VR and tracking SDKs. The idea is that we subclass this class, implement the logic, and then instantiate a singleton of each interface when Godot starts. These instances do not initialize themselves but register themselves with the AR/VR server. @@ -138,4 +136,4 @@ VARIANT_ENUM_CAST(XRInterface::Capabilities); VARIANT_ENUM_CAST(XRInterface::TrackingStatus); VARIANT_ENUM_CAST(XRInterface::PlayAreaMode); -#endif // !XR_INTERFACE_H +#endif // XR_INTERFACE_H diff --git a/servers/xr/xr_pose.cpp b/servers/xr/xr_pose.cpp index ab6eb042c9..0862fefef5 100644 --- a/servers/xr/xr_pose.cpp +++ b/servers/xr/xr_pose.cpp @@ -35,7 +35,7 @@ void XRPose::_bind_methods() { ClassDB::bind_method(D_METHOD("set_has_tracking_data", "has_tracking_data"), &XRPose::set_has_tracking_data); ClassDB::bind_method(D_METHOD("get_has_tracking_data"), &XRPose::get_has_tracking_data); - ADD_PROPERTY(PropertyInfo(Variant::STRING, "has_tracking_data"), "set_has_tracking_data", "get_has_tracking_data"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "has_tracking_data"), "set_has_tracking_data", "get_has_tracking_data"); ClassDB::bind_method(D_METHOD("set_name", "name"), &XRPose::set_name); ClassDB::bind_method(D_METHOD("get_name"), &XRPose::get_name); diff --git a/servers/xr/xr_positional_tracker.h b/servers/xr/xr_positional_tracker.h index 895bcab215..2bcbf2c018 100644 --- a/servers/xr/xr_positional_tracker.h +++ b/servers/xr/xr_positional_tracker.h @@ -37,8 +37,6 @@ #include "servers/xr_server.h" /** - @author Bastiaan Olij <mux213@gmail.com> - The positional tracker object as an object that represents the position and orientation of a tracked object like a controller or headset. An AR/VR Interface will registered the trackers it manages with our AR/VR server and update its position and orientation. This is where potentially additional AR/VR interfaces may be active as there are AR/VR SDKs that solely deal with positional tracking. @@ -99,4 +97,4 @@ public: VARIANT_ENUM_CAST(XRPositionalTracker::TrackerHand); -#endif +#endif // XR_POSITIONAL_TRACKER_H diff --git a/servers/xr_server.h b/servers/xr_server.h index 824a42ed31..a820634bd9 100644 --- a/servers/xr_server.h +++ b/servers/xr_server.h @@ -41,8 +41,6 @@ class XRInterface; class XRPositionalTracker; /** - @author Bastiaan Olij <mux213@gmail.com> - The XR server is a singleton object that gives access to the various objects and SDKs that are available on the system. Because there can be multiple SDKs active this is exposed as an array @@ -193,4 +191,4 @@ public: VARIANT_ENUM_CAST(XRServer::TrackerType); VARIANT_ENUM_CAST(XRServer::RotationMode); -#endif +#endif // XR_SERVER_H |