Debian Codegraph @

editor/export/shader_baker_export_plugin.h

raw symbols SCIP
1 /**************************************************************************/
2 /* shader_baker_export_plugin.h */
3 /**************************************************************************/
4 /* This file is part of: */
5 /* GODOT ENGINE */
6 /* https://godotengine.org */
7 /**************************************************************************/
8 /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9 /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10 /* */
11 /* Permission is hereby granted, free of charge, to any person obtaining */
12 /* a copy of this software and associated documentation files (the */
13 /* "Software"), to deal in the Software without restriction, including */
14 /* without limitation the rights to use, copy, modify, merge, publish, */
15 /* distribute, sublicense, and/or sell copies of the Software, and to */
16 /* permit persons to whom the Software is furnished to do so, subject to */
17 /* the following conditions: */
18 /* */
19 /* The above copyright notice and this permission notice shall be */
20 /* included in all copies or substantial portions of the Software. */
21 /* */
22 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26 /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27 /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29 /**************************************************************************/
30
31 #pragma once
32
33 #include "editor/export/editor_export_plugin.h"
34 #include "servers/rendering/renderer_rd/shader_rd.h"
35
36 class RenderingShaderContainerFormat;
37
38 class ShaderBakerExportPluginPlatform : public RefCounted {
39 GDCLASS(ShaderBakerExportPluginPlatform, RefCounted);
40
41 public:
42 virtual RenderingShaderContainerFormat *create_shader_container_format(const Ref<EditorExportPlatform> &p_platform, const Ref<EditorExportPreset> &p_preset) = 0;
43 virtual bool matches_driver(const String &p_driver) = 0;
44 virtual ~ShaderBakerExportPluginPlatform() {}
45 };
46
47 class ShaderBakerExportPlugin : public EditorExportPlugin {
48 GDSOFTCLASS(ShaderBakerExportPlugin, EditorExportPlugin);
49
50 protected:
51 struct WorkItem {
52 String cache_path;
53 String shader_name;
54 Vector<String> stage_sources;
55 Vector<uint64_t> dynamic_buffers;
56 int64_t variant = 0;
57 };
58
59 struct WorkResult {
60 // 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.
61 Vector<PackedByteArray> variant_data;
62 };
63
64 struct ShaderGroupItem {
65 String cache_path;
66 LocalVector<int> variants;
67 LocalVector<WorkerThreadPool::TaskID> variant_tasks;
68 };
69
70 String shader_cache_platform_name;
71 String shader_cache_renderer_name;
72 String shader_cache_export_path;
73 RBSet<String> shader_paths_processed;
74 HashMap<String, WorkResult> shader_work_results;
75 Mutex shader_work_results_mutex;
76 LocalVector<ShaderGroupItem> shader_group_items;
77 RenderingShaderContainerFormat *shader_container_format = nullptr;
78 String shader_container_driver;
79 Vector<Ref<ShaderBakerExportPluginPlatform>> platforms;
80 uint64_t customization_configuration_hash = 0;
81 uint32_t tasks_processed = 0;
82 uint32_t tasks_total = 0;
83 std::atomic<bool> tasks_cancelled;
84 BinaryMutex tasks_mutex;
85 ConditionVariable tasks_condition;
86
87 virtual String get_name() const override;
88 virtual bool _is_active(const Vector<String> &p_features) const;
89 virtual bool _initialize_container_format(const Ref<EditorExportPlatform> &p_platform, const Ref<EditorExportPreset> &p_preset);
90 virtual void _cleanup_container_format();
91 virtual bool _initialize_cache_directory();
92 virtual bool _begin_customize_resources(const Ref<EditorExportPlatform> &p_platform, const Vector<String> &p_features) override;
93 virtual bool _begin_customize_scenes(const Ref<EditorExportPlatform> &p_platform, const Vector<String> &p_features) override;
94 virtual void _end_customize_resources() override;
95 virtual Ref<Resource> _customize_resource(const Ref<Resource> &p_resource, const String &p_path) override;
96 virtual Node *_customize_scene(Node *p_root, const String &p_path) override;
97 virtual uint64_t _get_customization_configuration_hash() const override;
98 virtual void _customize_shader_version(ShaderRD *p_shader, RID p_version);
99 void _process_work_item(WorkItem p_work_item);
100
101 public:
102 ShaderBakerExportPlugin();
103 virtual ~ShaderBakerExportPlugin() override;
104 void add_platform(Ref<ShaderBakerExportPluginPlatform> p_platform);
105 void remove_platform(Ref<ShaderBakerExportPluginPlatform> p_platform);
106 };