| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 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 |
|
| 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 |
}; |