/**************************************************************************/ /* shader_baker_export_plugin.h */ /**************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ /* https://godotengine.org */ /**************************************************************************/ /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ /* "Software"), to deal in the Software without restriction, including */ /* without limitation the rights to use, copy, modify, merge, publish, */ /* distribute, sublicense, and/or sell copies of the Software, and to */ /* permit persons to whom the Software is furnished to do so, subject to */ /* the following conditions: */ /* */ /* The above copyright notice and this permission notice shall be */ /* included in all copies or substantial portions of the Software. */ /* */ /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /**************************************************************************/ #pragma once #include "editor/export/editor_export_plugin.h" #include "servers/rendering/renderer_rd/shader_rd.h" #include "servers/rendering/rendering_shader_container.h" class ShaderBakerExportPluginPlatform : public RefCounted { GDCLASS(ShaderBakerExportPluginPlatform, RefCounted); public: virtual RenderingShaderContainerFormat *create_shader_container_format(const Ref &p_platform, const Ref &p_preset) = 0; virtual bool matches_driver(const String &p_driver) = 0; virtual ~ShaderBakerExportPluginPlatform() {} }; class ShaderBakerExportPlugin : public EditorExportPlugin { protected: struct WorkItem { String cache_path; String shader_name; Vector stage_sources; int64_t variant = 0; }; struct WorkResult { // Since this result is per group, this vector will have gaps in the data it covers as the indices must stay relative to all variants. Vector variant_data; }; struct ShaderGroupItem { String cache_path; LocalVector variants; LocalVector variant_tasks; }; String shader_cache_platform_name; String shader_cache_renderer_name; String shader_cache_export_path; RBSet shader_paths_processed; HashMap shader_work_results; Mutex shader_work_results_mutex; LocalVector shader_group_items; RenderingShaderContainerFormat *shader_container_format = nullptr; String shader_container_driver; Vector> platforms; uint64_t customization_configuration_hash = 0; uint32_t tasks_processed = 0; uint32_t tasks_total = 0; std::atomic tasks_cancelled; BinaryMutex tasks_mutex; ConditionVariable tasks_condition; virtual String get_name() const override; virtual bool _is_active(const Vector &p_features) const; virtual bool _initialize_container_format(const Ref &p_platform, const Vector &p_features, const Ref &p_preset); virtual void _cleanup_container_format(); virtual bool _initialize_cache_directory(); virtual bool _begin_customize_resources(const Ref &p_platform, const Vector &p_features) override; virtual bool _begin_customize_scenes(const Ref &p_platform, const Vector &p_features) override; virtual void _end_customize_resources() override; virtual Ref _customize_resource(const Ref &p_resource, const String &p_path) override; virtual Node *_customize_scene(Node *p_root, const String &p_path) override; virtual uint64_t _get_customization_configuration_hash() const override; virtual void _customize_shader_version(ShaderRD *p_shader, RID p_version); void _process_work_item(WorkItem p_work_item); public: ShaderBakerExportPlugin(); virtual ~ShaderBakerExportPlugin() override; void add_platform(Ref p_platform); void remove_platform(Ref p_platform); };