This repository has been archived by the owner on Jun 17, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgit.patch
402 lines (385 loc) · 33.1 KB
/
git.patch
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
diff --git a/CMakeLists.txt b/CMakeLists.txt
index bfc3a66..10b3401 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -47,10 +47,18 @@ add_definitions(-DVK_SPEC="${vk_spec}")
if (NOT DEFINED VULKAN_HPP_PATH)
set(VULKAN_HPP_PATH "${CMAKE_CURRENT_SOURCE_DIR}/vulkan")
+ set(VULKAN_HPP_INT_PATH "${VULKAN_HPP_PATH}/internal/")
+ set(VULKAN_HPP_INT_STRUCTS_PATH "${VULKAN_HPP_PATH}/internal/struct/")
+ set(VULKAN_HPP_INT_CMDS_PATH "${VULKAN_HPP_PATH}/internal/cmds/")
endif()
-file(TO_NATIVE_PATH ${VULKAN_HPP_PATH}/vulkan.hpp vulkan_hpp)
-string(REPLACE "\\" "\\\\" vulkan_hpp ${vulkan_hpp})
-add_definitions(-DVULKAN_HPP_FILE="${vulkan_hpp}")
+string(REPLACE "\\" "\\\\" VULKAN_HPP_PATH ${VULKAN_HPP_PATH})
+file(MAKE_DIRECTORY ${VULKAN_HPP_INT_PATH})
+string(REPLACE "\\" "\\\\" VULKAN_HPP_INT_PATH ${VULKAN_HPP_INT_PATH})
+file(MAKE_DIRECTORY ${VULKAN_HPP_INT_STRUCTS_PATH})
+string(REPLACE "\\" "\\\\" VULKAN_HPP_INT_STRUCTS_PATH ${VULKAN_HPP_INT_STRUCTS_PATH})
+file(MAKE_DIRECTORY ${VULKAN_HPP_INT_CMDS_PATH})
+string(REPLACE "\\" "\\\\" VULKAN_HPP_INT_CMDS_PATH ${VULKAN_HPP_INT_CMDS_PATH})
+add_definitions(-DVULKAN_HPP_PATH="${VULKAN_HPP_PATH}" -DVULKAN_HPP_INT_PATH="${VULKAN_HPP_INT_PATH}" -DVULKAN_HPP_INT_STRUCTS_PATH="${VULKAN_HPP_INT_STRUCTS_PATH}" -DVULKAN_HPP_INT_CMDS_PATH="${VULKAN_HPP_INT_CMDS_PATH}")
include_directories(${VULKAN_HPP_PATH})
diff --git a/VulkanHppGenerator.cpp b/VulkanHppGenerator.cpp
index 49be868..09c641c 100644
--- a/VulkanHppGenerator.cpp
+++ b/VulkanHppGenerator.cpp
@@ -20,6 +20,7 @@
#include <exception>
#include <regex>
#include <iterator>
+#include <unordered_map>
#include "VulkanHppGenerator.hpp"
void appendArgumentCount(std::string & str, size_t vectorIndex, std::string const& vectorName, std::string const& counterName, size_t returnParamIndex, size_t templateParamIndex, bool twoStep, bool singular);
@@ -2607,23 +2608,26 @@ void VulkanHppGenerator::appendHandles(std::string & str) const
}
}
-void VulkanHppGenerator::appendHandlesCommandDefintions(std::string & str) const
+std::unordered_map<std::string, std::string> VulkanHppGenerator::getHandlesCommandDefintions() const
{
+ std::unordered_map<std::string, std::string> map;
for (auto const& handle : m_handles)
{
+ auto& mapString = map[handle.first.empty() ? "Vk" : handle.first];
+
// finally the commands, that are member functions of this handle
for (auto const& command : handle.second.commands)
{
std::string commandName = determineCommandName(command.first, command.second.params[0].type.type);
std::string strippedName = startLowerCase(stripPrefix(command.first, "vk"));
- str += "\n";
- appendPlatformEnter(str, !command.second.aliases.empty(), command.second.platform);
- appendCommand(str, " ", commandName, command, true);
+ mapString += "\n";
+ appendPlatformEnter(mapString, !command.second.aliases.empty(), command.second.platform);
+ appendCommand(mapString, " ", commandName, command, true);
for (auto const& alias : command.second.aliases)
{
- str += "\n";
- appendCommand(str, " ", determineCommandName(alias, command.second.params[0].type.type), command, true);
+ mapString += "\n";
+ appendCommand(mapString, " ", determineCommandName(alias, command.second.params[0].type.type), command, true);
}
// special handling for destroy functions
@@ -2635,21 +2639,21 @@ void VulkanHppGenerator::appendHandlesCommandDefintions(std::string & str) const
assert(handleIt != m_handles.end());
if (!handleIt->second.alias.empty())
{
- appendPlatformLeave(str, !command.second.aliases.empty(), command.second.platform);
+ appendPlatformLeave(mapString, !command.second.aliases.empty(), command.second.platform);
platformLeft = true;
}
commandName = (command.first.substr(2, 7) == "Destroy") ? "destroy" : "free";
- str += "\n";
- appendCommand(str, " ", commandName, command, true);
+ mapString += "\n";
+ appendCommand(mapString, " ", commandName, command, true);
}
if (!platformLeft)
{
- appendPlatformLeave(str, !command.second.aliases.empty(), command.second.platform);
+ appendPlatformLeave(mapString, !command.second.aliases.empty(), command.second.platform);
}
}
}
- str += "\n";
+ return map;
}
// Intended only for `enum class Result`!
@@ -3031,13 +3035,41 @@ void VulkanHppGenerator::appendStructMembers(std::string & str, std::pair<std::s
}
}
-void VulkanHppGenerator::appendStructs(std::string & str) const
+std::vector<std::pair<std::string, std::string>> VulkanHppGenerator::getStructs() const
{
std::set<std::string> listedStructures;
+ std::unordered_map<std::string, std::string> map;
+ std::unordered_map<std::string, std::vector<std::string>> mapInclude;
for (auto const& structure : m_structures)
{
- appendStruct(str, structure, listedStructures);
+ auto name = structure.first;
+ for (size_t len = 3; len < name.length(); len++) {
+ if (!std::isupper(name.at(len)))
+ continue;
+ else {
+ if(name.length() != (len+1) && std::isdigit(name.at(len+1)))
+ len++;
+ else if (std::isdigit(name.at(len-1)) && !std::isdigit(name.at(len-2)))
+ len--;
+ name = name.substr(0, len);
+ break;
+ }
+ }
+ auto& includes = mapInclude[name];
+ for(auto& item : map)
+ if(std::find(includes.begin(), includes.end(), item.first) == includes.end())
+ includes.push_back(item.first);
+ appendStruct(map[name], structure, listedStructures);
+ }
+ std::vector<std::pair<std::string, std::string>> vtr;
+ for(auto& item : map) {
+ std::string includeString{};
+ for(auto& include : mapInclude.at(item.first))
+ includeString += "#include \"" + include + ".hpp\"\n";
+ item.second = includeString + "\nnamespace VULKAN_HPP_NAMESPACE\n{" + item.second + "} // namespace VULKAN_HPP_NAMESPACE\n";
+ vtr.push_back(item);
}
+ return vtr;
}
void VulkanHppGenerator::appendStructSetter(std::string & str, std::string const& structureName, MemberData const& memberData) const
@@ -6522,8 +6554,7 @@ static const std::string constExpressionArrayCopy = R"(
)";
static const std::string includes = R"(
-#ifndef VULKAN_HPP
-#define VULKAN_HPP
+#pragma once
#include <algorithm>
#include <array>
@@ -6725,7 +6756,7 @@ namespace std
std::string filename = (argc == 1) ? VK_SPEC : argv[1];
std::cout << "Loading vk.xml from " << filename << std::endl;
- std::cout << "Writing vulkan.hpp to " << VULKAN_HPP_FILE << std::endl;
+ std::cout << "Writing vulkan headers to " << VULKAN_HPP_PATH << std::endl;
tinyxml2::XMLError error = doc.LoadFile(filename.c_str());
if (error != tinyxml2::XML_SUCCESS)
@@ -6736,61 +6767,179 @@ namespace std
VulkanHppGenerator generator(doc);
- std::string str;
+ std::string base, dispatch, objects, enums, exceptions_, bitmasks, forward, handles, structs, commands, dynamicDispatch;
+
static const size_t estimatedLength = 4 * 1024 * 1024;
- str.reserve(estimatedLength);
- str += generator.getVulkanLicenseHeader()
- + includes
- + "\n";
- appendVersionCheck(str, generator.getVersion());
- appendTypesafeStuff(str, generator.getTypesafeCheck());
- str += defines
- + "\n"
- + "namespace VULKAN_HPP_NAMESPACE\n"
- + "{\n"
+ base.reserve(estimatedLength);
+ dispatch.reserve(estimatedLength);
+ objects.reserve(estimatedLength);
+ enums.reserve(estimatedLength);
+ bitmasks.reserve(estimatedLength);
+ exceptions_.reserve(estimatedLength);
+ forward.reserve(estimatedLength);
+ handles.reserve(estimatedLength);
+ structs.reserve(estimatedLength);
+ commands.reserve(estimatedLength);
+ dynamicDispatch.reserve(estimatedLength);
+
+
+ base += generator.getVulkanLicenseHeader() + includes + "\n";
+ appendVersionCheck(base, generator.getVersion());
+ appendTypesafeStuff(base, generator.getTypesafeCheck());
+ base += defines + "\nnamespace VULKAN_HPP_NAMESPACE\n{\n"
+ classArrayProxy
+ classFlags
+ classOptional
+ classStructureChain
+ classUniqueHandle;
- generator.appendDispatchLoaderStatic(str);
- generator.appendDispatchLoaderDefault(str);
- str += classObjectDestroy
+ base += "} // namespace VULKAN_HPP_NAMESPACE\n";
+
+
+ dispatch += generator.getVulkanLicenseHeader() + "\n#pragma once\n\n#include \"base.hpp\"\n\nnamespace VULKAN_HPP_NAMESPACE\n{\n";
+ generator.appendDispatchLoaderDefault(dispatch);
+ generator.appendDispatchLoaderStatic(dispatch);
+ dispatch += "} // namespace VULKAN_HPP_NAMESPACE\n";
+
+
+ objects += generator.getVulkanLicenseHeader() + "\n#pragma once\n\n#include \"dispatch.hpp\"\n\nnamespace VULKAN_HPP_NAMESPACE\n{\n"
+ + classObjectDestroy
+ classObjectFree
+ classPoolFree
+ constExpressionArrayCopy
+ "\n";
- generator.appendBaseTypes(str);
- generator.appendEnums(str);
- str += typeTraits;
- generator.appendBitmasks(str);
- str += "} // namespace VULKAN_HPP_NAMESPACE\n"
- + is_error_code_enum
- + "\n"
- + "namespace VULKAN_HPP_NAMESPACE\n"
- + "{\n"
- + "#ifndef VULKAN_HPP_NO_EXCEPTIONS"
- + exceptions;
- generator.appendResultExceptions(str);
- generator.appendThrowExceptions(str);
- str += "#endif\n"
- + structResultValue;
- generator.appendForwardDeclarations(str);
- generator.appendHandles(str);
- generator.appendStructs(str);
- generator.appendHandlesCommandDefintions(str);
- generator.appendStructureChainValidation(str);
- generator.appendDispatchLoaderDynamic(str);
- str += "} // namespace VULKAN_HPP_NAMESPACE\n"
- "#endif\n";
-
- assert(str.length() < estimatedLength);
- cleanup(str);
-
- std::ofstream ofs(VULKAN_HPP_FILE);
- assert(!ofs.fail());
- ofs << str;
- ofs.close();
+ generator.appendBaseTypes(objects);
+ objects += "} // namespace VULKAN_HPP_NAMESPACE\n";
+
+
+ enums += generator.getVulkanLicenseHeader() + "\n#pragma once\n\n#include \"objects.hpp\"\n\nnamespace VULKAN_HPP_NAMESPACE\n{\n";
+ generator.appendEnums(enums);
+ enums += typeTraits + "\n} // namespace VULKAN_HPP_NAMESPACE\n";
+
+
+ bitmasks += generator.getVulkanLicenseHeader() + "\n#pragma once\n\n#include \"enums.hpp\"\n\nnamespace VULKAN_HPP_NAMESPACE\n{\n";
+ generator.appendBitmasks(bitmasks);
+ bitmasks += "} // namespace VULKAN_HPP_NAMESPACE\n";
+
+
+ exceptions_ += generator.getVulkanLicenseHeader() + "\n#pragma once\n\n#include \"bitmasks.hpp\"\n\n" + is_error_code_enum + "\n\nnamespace VULKAN_HPP_NAMESPACE\n{\n#ifndef VULKAN_HPP_NO_EXCEPTIONS" + exceptions;
+ generator.appendResultExceptions(exceptions_);
+ generator.appendThrowExceptions(exceptions_);
+ exceptions_ += "#endif\n" + structResultValue + "} // namespace VULKAN_HPP_NAMESPACE\n";
+
+ forward += generator.getVulkanLicenseHeader() + "\n#pragma once\n\n#include \"exceptions.hpp\"\n\nnamespace VULKAN_HPP_NAMESPACE\n{\n";
+ generator.appendForwardDeclarations(forward);
+ forward += "} // namespace VULKAN_HPP_NAMESPACE\n";
+
+
+ handles += generator.getVulkanLicenseHeader() + "\n#pragma once\n\n#include \"forward.hpp\"\n\nnamespace VULKAN_HPP_NAMESPACE\n{\n";
+ generator.appendHandles(handles);
+ handles += "} // namespace VULKAN_HPP_NAMESPACE\n";
+
+
+ auto genStructs = generator.getStructs();
+ structs = generator.getVulkanLicenseHeader() + "\n#pragma once\n\n";
+
+
+ auto genCmds = generator.getHandlesCommandDefintions();
+ commands += generator.getVulkanLicenseHeader() + "\n#pragma once\n\n";
+
+
+ dynamicDispatch += generator.getVulkanLicenseHeader() + "\n#pragma once\n\n#include \"commands.hpp\"\n\nnamespace VULKAN_HPP_NAMESPACE\n{\n";
+ generator.appendStructureChainValidation(dynamicDispatch);
+ generator.appendDispatchLoaderDynamic(dynamicDispatch);
+ dynamicDispatch += "} // namespace VULKAN_HPP_NAMESPACE\n";
+
+
+ cleanup(base);
+ cleanup(objects);
+ cleanup(dispatch);
+ cleanup(structs);
+ cleanup(enums);
+ cleanup(bitmasks);
+ cleanup(exceptions_);
+ cleanup(forward);
+ cleanup(handles);
+ cleanup(commands);
+ cleanup(dynamicDispatch);
+
+
+ std::ofstream baseStream(VULKAN_HPP_INT_PATH"/base.hpp");
+ assert(!baseStream.fail());
+ baseStream << base;
+ baseStream.close();
+
+ std::ofstream objectsStream(VULKAN_HPP_INT_PATH "/objects.hpp");
+ assert(!objectsStream.fail());
+ objectsStream << objects;
+ objectsStream.close();
+
+ std::ofstream dispatchStream(VULKAN_HPP_INT_PATH "/dispatch.hpp");
+ assert(!dispatchStream.fail());
+ dispatchStream << dispatch;
+ dispatchStream.close();
+
+ std::ofstream enumsStream(VULKAN_HPP_INT_PATH "/enums.hpp");
+ assert(!enumsStream.fail());
+ enumsStream << enums;
+ enumsStream.close();
+
+ std::ofstream bitmasksStream(VULKAN_HPP_INT_PATH "/bitmasks.hpp");
+ assert(!bitmasksStream.fail());
+ bitmasksStream << bitmasks;
+ bitmasksStream.close();
+
+ std::ofstream exceptionsStream(VULKAN_HPP_INT_PATH "/exceptions.hpp");
+ assert(!exceptionsStream.fail());
+ exceptionsStream << exceptions_;
+ exceptionsStream.close();
+
+ std::ofstream forwardStream(VULKAN_HPP_INT_PATH "/forward.hpp");
+ assert(!forwardStream.fail());
+ forwardStream << forward;
+ forwardStream.close();
+
+ std::ofstream handlesStream(VULKAN_HPP_INT_PATH "/handles.hpp");
+ assert(!handlesStream.fail());
+ handlesStream << handles;
+ handlesStream.close();
+
+ for (auto& genStruct : genStructs) {
+ auto path = VULKAN_HPP_INT_STRUCTS_PATH + genStruct.first + ".hpp";
+ std::ofstream typeStream(VULKAN_HPP_INT_STRUCTS_PATH + genStruct.first + ".hpp");
+ cleanup(genStruct.second);
+ typeStream << generator.getVulkanLicenseHeader() << "\n#pragma once\n\n#include \"../handles.hpp\"\n" << genStruct.second;
+ typeStream.close();
+ structs += "#include \"struct/" + genStruct.first + ".hpp" + "\"\n";
+ }
+
+ std::ofstream structsStream(VULKAN_HPP_INT_PATH "/structs.hpp");
+ assert(!structsStream.fail());
+ structsStream << structs;
+ structsStream.close();
+
+ for (auto& genCmd : genCmds) {
+ auto path = VULKAN_HPP_INT_CMDS_PATH + genCmd.first + ".hpp";
+ std::ofstream typeStream(VULKAN_HPP_INT_CMDS_PATH + genCmd.first + ".hpp");
+ cleanup(genCmd.second);
+ typeStream << generator.getVulkanLicenseHeader() << "\n#pragma once\n\n#include \"../structs.hpp\"\n\nnamespace VULKAN_HPP_NAMESPACE\n{\n" << genCmd.second << "} // namespace VULKAN_HPP_NAMESPACE\n";
+ typeStream.close();
+ commands += "#include \"cmds/" + genCmd.first + ".hpp" + "\"\n";
+ }
+
+ std::ofstream commandsStream(VULKAN_HPP_INT_PATH "/commands.hpp");
+ assert(!commandsStream.fail());
+ commandsStream << commands;
+ commandsStream.close();
+
+ std::ofstream dynamicDispatchStream(VULKAN_HPP_INT_PATH "/dynamicDispatch.hpp");
+ assert(!dynamicDispatchStream.fail());
+ dynamicDispatchStream << dynamicDispatch;
+ dynamicDispatchStream.close();
+
+ std::ofstream mainStream(VULKAN_HPP_PATH "/vulkan.hpp");
+ assert(!mainStream.fail());
+ mainStream << "#pragma once\n\n#include \"internal/dynamicDispatch.hpp\"\n";
+ mainStream.close();
}
catch (std::exception const& e)
{
diff --git a/VulkanHppGenerator.hpp b/VulkanHppGenerator.hpp
index d335967..43db9f9 100644
--- a/VulkanHppGenerator.hpp
+++ b/VulkanHppGenerator.hpp
@@ -33,9 +33,9 @@ class VulkanHppGenerator
void appendEnums(std::string & str) const;
void appendForwardDeclarations(std::string & str) const;
void appendHandles(std::string & str) const;
- void appendHandlesCommandDefintions(std::string & str) const;
+ std::unordered_map<std::string, std::string> getHandlesCommandDefintions() const;
void appendResultExceptions(std::string & str) const;
- void appendStructs(std::string & str) const;
+ std::vector<std::pair<std::string, std::string>> getStructs() const;
void appendStructureChainValidation(std::string & str);
void appendThrowExceptions(std::string & str) const;
std::string const& getTypesafeCheck() const;