Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/editor/export/shader_baker_export_plugin.h
9903 views
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
#include "servers/rendering/rendering_shader_container.h"
36
37
class ShaderBakerExportPluginPlatform : public RefCounted {
38
GDCLASS(ShaderBakerExportPluginPlatform, RefCounted);
39
40
public:
41
virtual RenderingShaderContainerFormat *create_shader_container_format(const Ref<EditorExportPlatform> &p_platform) = 0;
42
virtual bool matches_driver(const String &p_driver) = 0;
43
virtual ~ShaderBakerExportPluginPlatform() {}
44
};
45
46
class ShaderBakerExportPlugin : public EditorExportPlugin {
47
protected:
48
struct WorkItem {
49
String cache_path;
50
String shader_name;
51
Vector<String> stage_sources;
52
int64_t variant = 0;
53
};
54
55
struct WorkResult {
56
// 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.
57
Vector<PackedByteArray> variant_data;
58
};
59
60
struct ShaderGroupItem {
61
String cache_path;
62
LocalVector<int> variants;
63
LocalVector<WorkerThreadPool::TaskID> variant_tasks;
64
};
65
66
String shader_cache_platform_name;
67
String shader_cache_renderer_name;
68
String shader_cache_export_path;
69
RBSet<String> shader_paths_processed;
70
HashMap<String, WorkResult> shader_work_results;
71
Mutex shader_work_results_mutex;
72
LocalVector<ShaderGroupItem> shader_group_items;
73
RenderingShaderContainerFormat *shader_container_format = nullptr;
74
String shader_container_driver;
75
Vector<Ref<ShaderBakerExportPluginPlatform>> platforms;
76
uint64_t customization_configuration_hash = 0;
77
uint32_t tasks_processed = 0;
78
uint32_t tasks_total = 0;
79
std::atomic<bool> tasks_cancelled;
80
BinaryMutex tasks_mutex;
81
ConditionVariable tasks_condition;
82
83
virtual String get_name() const override;
84
virtual bool _is_active(const Vector<String> &p_features) const;
85
virtual bool _initialize_container_format(const Ref<EditorExportPlatform> &p_platform, const Vector<String> &p_features);
86
virtual void _cleanup_container_format();
87
virtual bool _initialize_cache_directory();
88
virtual bool _begin_customize_resources(const Ref<EditorExportPlatform> &p_platform, const Vector<String> &p_features) override;
89
virtual bool _begin_customize_scenes(const Ref<EditorExportPlatform> &p_platform, const Vector<String> &p_features) override;
90
virtual void _end_customize_resources() override;
91
virtual Ref<Resource> _customize_resource(const Ref<Resource> &p_resource, const String &p_path) override;
92
virtual Node *_customize_scene(Node *p_root, const String &p_path) override;
93
virtual uint64_t _get_customization_configuration_hash() const override;
94
virtual void _customize_shader_version(ShaderRD *p_shader, RID p_version);
95
void _process_work_item(WorkItem p_work_item);
96
97
public:
98
ShaderBakerExportPlugin();
99
virtual ~ShaderBakerExportPlugin() override;
100
void add_platform(Ref<ShaderBakerExportPluginPlatform> p_platform);
101
void remove_platform(Ref<ShaderBakerExportPluginPlatform> p_platform);
102
};
103
104