-
Notifications
You must be signed in to change notification settings - Fork 72
Expand file tree
/
Copy pathgen_profiles_layer.py
More file actions
5715 lines (5092 loc) · 295 KB
/
gen_profiles_layer.py
File metadata and controls
5715 lines (5092 loc) · 295 KB
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
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/python3
#
# Copyright (c) 2021-2026 LunarG, Inc.
# Copyright (c) 2023-2024 RasterGrid Kft.
#
# Licensed under the Apache License, Version 2.0 (the "License")
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Authors:
# - Ziga Markus <ziga@lunarg.com>
# - Christophe Riccio <christophe@lunarg.com>
import gen_profiles_solution
import argparse
from typing import OrderedDict
COPYRIGHT_HEADER = '''
/*
* Copyright (C) 2015-2024 Valve Corporation
* Copyright (C) 2015-2024 LunarG, Inc.
* Copyright (C) 2023-2024 RasterGrid Kft.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Authors:
* - Ziga Markus <ziga@lunarg.com>
* - Christophe Riccio <christophe@lunarg.com>
* - Mark Lobodzinski <mark@lunarg.com>
* - Mike Weiblen
* - Arda Coskunses
* - Jeremy Kniager
* This file is ***GENERATED***. Do Not Edit.
* See scripts/gen_profiles_layer.py for modifications.
*/
'''
DESCRIPTION_HEADER = '''
/*
* layer/profiles.cpp - The VK_LAYER_KHRONOS_profiles layer.
* This Profiles layer simulates a device by loading a JSON configuration file to override values that would normally be returned
* from a Vulkan implementation. Configuration files must validate with the Profiles schema; this layer does not redundantly
* check for configuration errors that would be caught by schema validation.
*
* References (several documents are also included in the LunarG Vulkan SDK, see [SDK]):
* [SPEC] https://www.khronos.org/registry/vulkan/specs/1.0-extensions/html/vkspec.html
* [SDK] https://vulkan.lunarg.com/sdk/home
* [LALI] https://github.com/KhronosGroup/Vulkan-Loader/blob/main/loader/LoaderAndLayerInterface.md
*
* Misc notes:
* This code generally follows the spirit of the Google C++ styleguide, while accommodating conventions of the Vulkan styleguide.
* https://google.github.io/styleguide/cppguide.html
* https://www.khronos.org/registry/vulkan/specs/1.1/styleguide.html
*/
'''
INCLUDES_HEADER = '''
#include "profiles.h"
#include "profiles_util.h"
#include "profiles_json.h"
#include "profiles_settings.h"
#include <algorithm>
#include <filesystem>
#include <functional>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <optional>
namespace fs = std::filesystem;
'''
GLOBAL_CONSTANTS = '''
// Global constants //////////////////////////////////////////////////////////////////////////////////////////////////////////////
// For new features/functionality, increment the minor level and reset patch level to zero.
// For any changes, at least increment the patch level. See https://semver.org/
// When updating the version, be sure to make corresponding changes to the layer manifest file at
// layer/VkLayer_khronos_profiles.json.in
const uint32_t kVersionProfilesMajor = 1;
const uint32_t kVersionProfilesMinor = 3;
const uint32_t kVersionProfilesPatch = 0;
const uint32_t kVersionProfilesImplementation =
VK_MAKE_VERSION(kVersionProfilesMajor, kVersionProfilesMinor, kVersionProfilesPatch);
static const char *SCHEMA_URI_BASE = "https://schema.khronos.org/vulkan/profiles-";
// Properties of this layer:
const VkLayerProperties kLayerProperties[] = {{
kLayerName, // layerName
VK_MAKE_VERSION(1, 0, 68), // specVersion (clamped to final 1.0 spec version)
kVersionProfilesImplementation, // implementationVersion
"Khronos Profiles layer" // description
}};
const uint32_t kLayerPropertiesCount = (sizeof(kLayerProperties) / sizeof(kLayerProperties[0]));
// Instance extensions that this layer provides:
const VkExtensionProperties kInstanceExtensionProperties[] = {
VkExtensionProperties{VK_EXT_LAYER_SETTINGS_EXTENSION_NAME, VK_EXT_LAYER_SETTINGS_SPEC_VERSION}};
const uint32_t kInstanceExtensionPropertiesCount = static_cast<uint32_t>(std::size(kInstanceExtensionProperties));
// Device extensions that this layer provides:
const std::array<VkExtensionProperties, 2> kDeviceExtensionProperties = {
{{VK_EXT_TOOLING_INFO_EXTENSION_NAME, VK_EXT_TOOLING_INFO_SPEC_VERSION},
{VK_KHR_PORTABILITY_SUBSET_EXTENSION_NAME, VK_KHR_PORTABILITY_SUBSET_SPEC_VERSION}}};
const uint32_t kDeviceExtensionPropertiesCount = static_cast<uint32_t>(kDeviceExtensionProperties.size());
'''
GLOBAL_VARS = '''
// Global variables //////////////////////////////////////////////////////////////////////////////////////////////////////////////
uint32_t requested_version = 0;
bool device_has_astc_hdr = false;
bool device_has_astc = false;
bool device_has_etc2 = false;
bool device_has_bc = false;
bool device_has_pvrtc = false;
std::recursive_mutex global_lock; // Enforce thread-safety for this layer.
'''
PHYSICAL_DEVICE_DATA_BEGIN = '''
// PhysicalDeviceData : creates and manages the simulated device configurations //////////////////////////////////////////////////
class PhysicalDeviceData {
public:
// Create a new PDD element during vkCreateInstance(), and preserve in map, indexed by physical_device.
static PhysicalDeviceData &Create(VkPhysicalDevice pd, VkInstance instance) {
assert(pd != VK_NULL_HANDLE);
assert(instance != VK_NULL_HANDLE);
assert(!Find(pd)); // Verify this instance does not already exist.
const auto result = map().emplace(pd, instance);
assert(result.second); // true=insertion, false=replacement
auto iter = result.first;
PhysicalDeviceData *pdd = &iter->second;
assert(Find(pd) == pdd); // Verify we get the same instance we just inserted.
return *pdd;
}
static void Destroy(const VkPhysicalDevice pd) {
map().erase(pd);
}
// Find a PDD from our map, or nullptr if doesn't exist.
static PhysicalDeviceData *Find(VkPhysicalDevice pd) {
const auto iter = map().find(pd);
return (iter != map().end()) ? &iter->second : nullptr;
}
static bool HasExtension(PhysicalDeviceData *pdd, const char *extension_name) {
return pdd->device_extensions_.count(extension_name) > 0;
}
static bool HasSimulatedExtension(VkPhysicalDevice pd, const char *extension_name) {
return HasSimulatedExtension(Find(pd), extension_name);
}
static bool HasSimulatedExtension(PhysicalDeviceData *pdd, const char *extension_name) {
return pdd->simulation_extensions_.count(extension_name) > 0;
}
static bool HasSimulatedOrRealExtension(VkPhysicalDevice pd, const char *extension_name) {
return HasSimulatedOrRealExtension(Find(pd), extension_name);
}
static bool HasSimulatedOrRealExtension(PhysicalDeviceData *pdd, const char *extension_name) {
return HasSimulatedExtension(pdd, extension_name) || HasExtension(pdd, extension_name);
}
uint32_t GetEffectiveVersion() {
return requested_version < physical_device_properties_.apiVersion ? requested_version
: physical_device_properties_.apiVersion;
}
VkInstance instance() const { return instance_; }
MapOfVkExtensionProperties device_extensions_{};
MapOfVkFormatProperties device_formats_{};
MapOfVkFormatProperties3 device_formats_3_{};
ArrayOfVkQueueFamilyProperties device_queue_family_properties_{};
SetOfVideoProfiles set_of_device_video_profiles_{};
MapOfVkExtensionProperties simulation_extensions_{};
VkPhysicalDeviceProperties physical_device_properties_{};
VkPhysicalDeviceFeatures physical_device_features_{};
VkPhysicalDeviceMemoryProperties physical_device_memory_properties_{};
VkPhysicalDeviceToolProperties physical_device_tool_properties_{};
VkSurfaceCapabilitiesKHR surface_capabilities_{};
MapOfVkFormatProperties map_of_format_properties_{};
MapOfVkFormatProperties3 map_of_format_properties_3_{};
MapOfVkExtensionProperties map_of_extension_properties_{};
ArrayOfVkQueueFamilyProperties arrayof_queue_family_properties_{};
SetOfVideoProfiles set_of_video_profiles_{};
// Space for array queries:
//
// - From VkPhysicalDeviceHostImageCopyPropertiesEXT
std::vector<VkImageLayout> pCopySrcLayouts_;
std::vector<VkImageLayout> pCopyDstLayouts_;
bool vulkan_1_1_properties_written_;
bool vulkan_1_2_properties_written_;
bool vulkan_1_3_properties_written_;
bool vulkan_1_4_properties_written_;
bool vulkan_1_1_features_written_;
bool vulkan_1_2_features_written_;
bool vulkan_1_3_features_written_;
bool vulkan_1_4_features_written_;
'''
PHYSICAL_DEVICE_DATA_CONSTRUCTOR_BEGIN = '''
PhysicalDeviceData(VkInstance instance) : instance_(instance) {
physical_device_properties_ = {};
physical_device_features_ = {};
physical_device_memory_properties_ = {};
surface_capabilities_ = {};
vulkan_1_1_properties_written_ = false;
vulkan_1_2_properties_written_ = false;
vulkan_1_3_properties_written_ = false;
vulkan_1_4_properties_written_ = false;
vulkan_1_1_features_written_ = false;
vulkan_1_2_features_written_ = false;
vulkan_1_3_features_written_ = false;
vulkan_1_4_features_written_ = false;
'''
PHYSICAL_DEVICE_DATA_END = ''' }
PhysicalDeviceData(const PhysicalDeviceData &) = delete;
PhysicalDeviceData &operator=(const PhysicalDeviceData &) = delete;
private:
const VkInstance instance_;
typedef std::unordered_map<VkPhysicalDevice, PhysicalDeviceData> Map;
static Map& map() {
static Map map_;
return map_;
}
};
'''
JSON_LOADER_BEGIN = '''
// Loader for Profiles JSON configuration files ////////////////////////////////////////////////////////////////////////////////////
class JsonLoader {
public:
JsonLoader()
: layer_settings{},
pdd_(nullptr),
profile_api_version_(0),
excluded_extensions_(),
excluded_formats_()
{}
JsonLoader(const JsonLoader &) = delete;
JsonLoader &operator=(const JsonLoader &rhs) = delete;
static JsonLoader &Create() {
VkInstance temporary = VK_NULL_HANDLE;
const auto result = profile_map().emplace(std::piecewise_construct, std::make_tuple(temporary), std::make_tuple());
assert(result.second); // true=insertion, false=replacement
auto iter = result.first;
JsonLoader *profile = &iter->second;
return *profile;
}
static void Store(VkInstance instance) {
auto nh = profile_map().extract(VK_NULL_HANDLE);
nh.key() = instance;
profile_map().insert(std::move(nh));
}
static JsonLoader *Find(VkInstance instance) {
const auto iter = profile_map().find(instance);
return (iter != profile_map().end()) ? &iter->second : nullptr;
}
static void Destroy(VkInstance instance) {
profile_map().erase(instance);
}
void LogFoundProfiles();
const Json::Value& FindRootFromProfileName(const std::string& profile_name) const;
VkResult LoadProfilesDatabase();
VkResult LoadFile(const std::string& filename);
void ReadProfileApiVersion();
VkResult LoadDevice(const char* device_name, PhysicalDeviceData *pdd);
VkResult ReadProfile(const char* device_name, const Json::Value& root, const std::vector<std::vector<std::string>> &capabilities, bool requested_profile, bool enable_warnings);
uint32_t GetProfileApiVersion() const { return profile_api_version_; }
void CollectProfiles(const std::string& profile_name, std::vector<std::string>& results) const;
ProfileLayerSettings layer_settings;
private:
PhysicalDeviceData *pdd_;
std::map<std::string, Json::Value> profiles_file_roots_;
std::uint32_t profile_api_version_;
std::vector<std::string> excluded_extensions_;
std::vector<std::string> excluded_formats_;
struct Extension {
std::string name;
int specVersion;
};
enum ExtensionSupport {
UNSUPPORTED,
EXCLUDED,
SUPPORTED,
};
bool WarnDuplicatedFeature(const Json::Value &parent);
bool WarnDuplicatedProperty(const Json::Value &parent);
bool GetFeature(const char *device_name, bool requested_profile, const Json::Value &features, const std::string &name);
bool GetProperty(const char *device_name, bool requested_profile, const Json::Value &props, const std::string &name);
bool GetFormat(const char *device_name, bool requested_profile, const Json::Value &formats, const std::string &format_name, MapOfVkFormatProperties *dest,
MapOfVkFormatProperties3 *dest3);
bool CheckVersionSupport(uint32_t version, const std::string &name);
ExtensionSupport CheckExtensionSupport(const char *extension, const std::string &name);
bool valid(ExtensionSupport support);
bool GetQueueFamilyProperties(const char* device_name, const Json::Value &qf_props, QueueFamilyProperties *dest);
bool OrderQueueFamilyProperties(ArrayOfVkQueueFamilyProperties *qfp);
void AddPromotedExtensions(uint32_t api_level);
'''
JSON_LOADER_END = '''
typedef std::unordered_map<VkInstance, JsonLoader> ProfileMap;
static ProfileMap& profile_map() {
static ProfileMap profile_map_;
return profile_map_;
}
};
'''
WARN_FUNCTIONS = '''
static bool WarnIfNotEqualFloat(ProfileLayerSettings *layer_settings, bool enable_warnings, const char* device_name, const char *cap_name, const float new_value, const float old_value, const bool not_modifiable) {
if (std::abs(new_value - old_value) > 0.0001f) {
if (enable_warnings) {
if (not_modifiable) {
LogMessage(layer_settings, DEBUG_REPORT_WARNING_BIT,
"'%s' is not modifiable but the profile value (%3.2f) is different from the device (%s) value (%3.2f)\\n", cap_name, new_value, device_name, old_value);
} else {
LogMessage(layer_settings, DEBUG_REPORT_WARNING_BIT,
"'%s' profile value (%3.2f) is different from the device (%s) supported value (%3.2f)\\n", cap_name, new_value, device_name, old_value);
}
}
return true;
}
return false;
}
static bool WarnIfNotEqualBool(ProfileLayerSettings *layer_settings, bool enable_warnings, const char* device_name, const char *cap_name, const bool new_value, const bool old_value, const bool not_modifiable) {
if (new_value != old_value) {
if (enable_warnings) {
if (not_modifiable) {
LogMessage(layer_settings, DEBUG_REPORT_WARNING_BIT,
"'%s' is not modifiable but the profile value (%s) is different from the device (%s) value (%s)\\n", cap_name, new_value ? "true" : "false", device_name, old_value ? "true" : "false");
} else if (new_value) {
LogMessage(layer_settings, DEBUG_REPORT_WARNING_BIT,
"'%s' profile value is enabled in the profile, but the device (%s) does not support it\\n", cap_name, device_name);
}
}
return true;
}
return false;
}
static bool WarnIfNotEqualEnum(ProfileLayerSettings *layer_settings, bool enable_warnings, const char* device_name, const char *cap_name, const uint32_t new_value, const uint32_t old_value, const bool not_modifiable) {
if (new_value != old_value) {
if (enable_warnings) {
if (not_modifiable) {
LogMessage(layer_settings, DEBUG_REPORT_WARNING_BIT,
"'%s' is not modifiable but the profile value (%" PRIu32 ") is different from the device (%s) value (%" PRIu32 ")\\n", cap_name, new_value, device_name, old_value);
} else {
LogMessage(layer_settings, DEBUG_REPORT_WARNING_BIT,
"'%s' profile value (%" PRIu32 ") is different from the device (%s) value (%" PRIu32 ")\\n", cap_name, new_value, device_name, old_value);
}
}
return true;
}
return false;
}
static bool WarnIfNotEqual(ProfileLayerSettings *layer_settings, bool enable_warnings, const char* device_name, const char *cap_name, const uint32_t new_value, const uint32_t old_value, const bool not_modifiable) {
if (new_value != old_value) {
if (enable_warnings) {
if (not_modifiable) {
LogMessage(layer_settings, DEBUG_REPORT_WARNING_BIT,
"'%s' is not modifiable but the profile value (%" PRIu32 ") is different from the device (%s) value (%" PRIu32 ")\\n", cap_name, new_value, device_name, old_value);
} else {
LogMessage(layer_settings, DEBUG_REPORT_WARNING_BIT,
"'%s' profile value (%" PRIu32 ") is different from the device (%s) value (%" PRIu32 ")\\n", cap_name, new_value, device_name, old_value);
}
}
return true;
}
return false;
}
static bool WarnIfNotEqual32u(ProfileLayerSettings *layer_settings, bool enable_warnings, const char* device_name, const char *cap_name, const uint32_t new_value, const uint32_t old_value, const bool not_modifiable) {
if (new_value != old_value) {
if (enable_warnings) {
if (not_modifiable) {
LogMessage(layer_settings, DEBUG_REPORT_WARNING_BIT,
"'%s' is not modifiable but the profile value (%" PRIu32 ") is different from the device (%s) value (%" PRIu32 ")\\n", cap_name, new_value, device_name, old_value);
} else {
LogMessage(layer_settings, DEBUG_REPORT_WARNING_BIT,
"'%s' profile value (%" PRIu32 ") is different from the device (%s) value (%" PRIu32 ")\\n", cap_name, new_value, device_name, old_value);
}
}
return true;
}
return false;
}
static bool WarnIfNotEqual(ProfileLayerSettings *layer_settings, bool enable_warnings, const char* device_name, const char *cap_name, const int32_t new_value, const int32_t old_value, const bool not_modifiable) {
if (new_value != old_value) {
if (enable_warnings) {
if (not_modifiable) {
LogMessage(layer_settings, DEBUG_REPORT_WARNING_BIT,
"'%s' is not modifiable but the profile value (%" PRIi32 ") is different from the device (%s) value (%" PRIi32 ")\\n", cap_name, new_value, device_name, old_value);
} else {
LogMessage(layer_settings, DEBUG_REPORT_WARNING_BIT,
"'%s' profile value (%" PRIi32 ") is different from the device (%s) value (%" PRIi32 ")\\n", cap_name, new_value, device_name, old_value);
}
}
return true;
}
return false;
}
static bool WarnIfNotEqual64u(ProfileLayerSettings *layer_settings, bool enable_warnings, const char* device_name, const char *cap_name, const uint64_t new_value, const uint64_t old_value, const bool not_modifiable) {
if (new_value != old_value) {
if (enable_warnings) {
if (not_modifiable) {
LogMessage(layer_settings, DEBUG_REPORT_WARNING_BIT,
"'%s' is not modifiable but the profile value (%" PRIu64 ") is different from the device (%s) value (%" PRIu64 ")\\n", cap_name, new_value, device_name, old_value);
} else {
LogMessage(layer_settings, DEBUG_REPORT_WARNING_BIT,
"'%s' profile value (%" PRIu64 ") is different from the device (%s) value (%" PRIu64 ")\\n", cap_name, new_value, device_name, old_value);
}
}
return true;
}
return false;
}
static bool WarnIfNotEquali64(ProfileLayerSettings *layer_settings, bool enable_warnings, const char* device_name, const char *cap_name, const int64_t new_value, const int64_t old_value, const bool not_modifiable) {
if (new_value != old_value) {
if (enable_warnings) {
if (not_modifiable) {
LogMessage(layer_settings, DEBUG_REPORT_WARNING_BIT,
"'%s' is not modifiable but the profile value (%" PRIi64 ") is different from the device (%s) value (%" PRIi64 ")\\n", cap_name, new_value, device_name, old_value);
} else {
LogMessage(layer_settings, DEBUG_REPORT_WARNING_BIT,
"'%s' profile value (%" PRIi64 ") is different from the device (%s) value (%" PRIi64 ")\\n", cap_name, new_value, device_name, old_value);
}
}
return true;
}
return false;
}
static bool WarnIfNotEqualSizet(ProfileLayerSettings *layer_settings, bool enable_warnings, const char* device_name, const char *cap_name, const size_t new_value, const size_t old_value, const bool not_modifiable) {
if (new_value != old_value) {
if (enable_warnings) {
if (not_modifiable) {
LogMessage(layer_settings, DEBUG_REPORT_WARNING_BIT,
"'%s' is not modifiable but the profile value (%" PRIuLEAST64 ") is different from the device (%s) value (%" PRIuLEAST64 ")\\n", cap_name, new_value, device_name, old_value);
} else {
LogMessage(layer_settings, DEBUG_REPORT_WARNING_BIT,
"'%s' profile value (%" PRIuLEAST64 ") is different from the device (%s) value (%" PRIuLEAST64 ")\\n", cap_name, new_value, device_name, old_value);
}
}
return true;
}
return false;
}
static bool WarnIfMissingBit(ProfileLayerSettings *layer_settings, bool enable_warnings, const char* device_name, const char *cap_name, const uint64_t new_value, const uint64_t old_value, const bool not_modifiable) {
if ((old_value | new_value) != old_value) {
if (enable_warnings) {
if (not_modifiable) {
LogMessage(layer_settings, DEBUG_REPORT_WARNING_BIT,
"'%s' is not modifiable but the profile value (%" PRIu64 ") is different from the device (%s) value (%" PRIu64 ")\\n", cap_name, new_value, device_name, old_value);
} else {
LogMessage(layer_settings, DEBUG_REPORT_WARNING_BIT,
"'%s' profile value (%" PRIu64 ") has bits set that the device (%s) value (%" PRIu64 ") does not\\n", cap_name, new_value, device_name, old_value);
}
}
return true;
}
return false;
}
static bool WarnIfGreater(ProfileLayerSettings *layer_settings, bool enable_warnings, const char* device_name, const char *cap_name, const uint64_t new_value, const uint64_t old_value, const bool not_modifiable) {
(void)not_modifiable;
if (new_value > old_value) {
if (enable_warnings) {
LogMessage(layer_settings, DEBUG_REPORT_WARNING_BIT,
"'%s' profile value (%" PRIu64 ") is greater than device (%s) value (%" PRIu64 ")\\n", cap_name, new_value, device_name, old_value);
}
return true;
}
return false;
}
static bool WarnIfGreaterSizet(ProfileLayerSettings *layer_settings, bool enable_warnings, const char* device_name, const char *cap_name, const size_t new_value, const size_t old_value, const bool not_modifiable) {
(void)not_modifiable;
if (new_value > old_value) {
if (enable_warnings) {
LogMessage(layer_settings, DEBUG_REPORT_WARNING_BIT,
"'%s' profile value (%" PRIuLEAST64 ") is greater than device (%s) value (%" PRIuLEAST64 ")\\n", cap_name, new_value, device_name, old_value);
}
return true;
}
return false;
}
static bool WarnIfGreaterFloat(ProfileLayerSettings *layer_settings, bool enable_warnings, const char* device_name, const char *cap_name, const float new_value, const float old_value, const bool not_modifiable) {
(void)not_modifiable;
if (new_value > old_value) {
if (enable_warnings) {
LogMessage(layer_settings, DEBUG_REPORT_WARNING_BIT,
"'%s' profile value (%3.2f) is greater than device (%s) value (%3.2f)\\n", cap_name, new_value, device_name, old_value);
}
return true;
}
return false;
}
static bool WarnIfLesser(ProfileLayerSettings *layer_settings, bool enable_warnings, const char* device_name, const char *cap_name, const uint64_t new_value, const uint64_t old_value, const bool not_modifiable) {
(void)not_modifiable;
if (new_value < old_value) {
if (enable_warnings) {
LogMessage(layer_settings, DEBUG_REPORT_WARNING_BIT,
"'%s' profile value (%" PRIu64 ") is lesser than device (%s) value (%" PRIu64 ")\\n", cap_name, new_value, device_name, old_value);
}
return true;
}
return false;
}
static bool WarnIfLesserSizet(ProfileLayerSettings *layer_settings, bool enable_warnings, const char* device_name, const char *cap_name, const size_t new_value, const size_t old_value, const bool not_modifiable) {
(void)not_modifiable;
if (new_value < old_value) {
if (enable_warnings) {
LogMessage(layer_settings, DEBUG_REPORT_WARNING_BIT,
"'%s' profile value (%" PRIuLEAST64 ") is lesser than device (%s) value (%" PRIuLEAST64 ")\\n", cap_name, new_value, device_name, old_value);
}
return true;
}
return false;
}
static bool WarnIfLesserFloat(ProfileLayerSettings *layer_settings, bool enable_warnings, const char* device_name, const char *cap_name, const float new_value, const float old_value, const bool not_modifiable) {
(void)not_modifiable;
if (new_value < old_value) {
if (enable_warnings) {
LogMessage(layer_settings, DEBUG_REPORT_WARNING_BIT,
"'%s' profile value (%3.2f) is lesser than device (%s) value (%3.2f)\\n", cap_name, new_value, device_name, old_value);
}
return true;
}
return false;
}
'''
GET_VALUE_FUNCTIONS = '''
bool GetValue(const char* device_name, const Json::Value &parent, const std::string &member, const char *name, float *dest, bool not_modifiable, bool requested_profile,
std::function<bool(ProfileLayerSettings *, bool, const char *, const char *, float, float, bool)> warn_func = nullptr) {
if (member != name) {
return true;
}
// If the value is not modifiable and we don't warn, we can return immediately, we will use the native value
if (not_modifiable && warn_func == nullptr) {
return true;
}
const Json::Value value = parent[name];
if (!value.isDouble()) {
return true;
}
bool valid = true;
const float new_value = value.asFloat();
if (warn_func) {
if (warn_func(&layer_settings, requested_profile, device_name, name, new_value, *dest, not_modifiable)) {
valid = false;
}
}
if (!not_modifiable) {
*dest = new_value;
}
return valid;
}
bool GetValue(const char* device_name, const Json::Value &parent, const std::string &member, const char *name, uint8_t *dest, bool not_modifiable, bool requested_profile,
std::function<bool(ProfileLayerSettings *, bool, const char *, const char *, uint8_t, uint8_t, bool)> warn_func = nullptr) {
if (member != name) {
return true;
}
// If the value is not modifiable and we don't warn, we can return immediately, we will use the native value
if (not_modifiable && warn_func == nullptr) {
return true;
}
const Json::Value value = parent[name];
bool valid = true;
if (value.isBool()) {
const bool new_value = value.asBool();
if (warn_func) {
if (warn_func(&layer_settings, requested_profile, device_name, name, new_value, *dest, not_modifiable)) {
valid = false;
}
}
*dest = static_cast<uint8_t>(new_value);
} else if (value.isArray()) {
uint64_t sum_bits = 0;
for (const auto &entry : value) {
if (entry.isString()) {
sum_bits |= VkStringToUint64(entry.asString());
}
}
if (!not_modifiable) {
*dest = static_cast<uint8_t>(sum_bits);
}
} else if (value.isUInt()) {
const uint8_t new_value = static_cast<uint8_t>(value.asUInt());
if (warn_func) {
if (warn_func(&layer_settings, requested_profile, device_name, name, new_value, *dest, not_modifiable)) {
valid = false;
}
}
if (!not_modifiable) {
*dest = static_cast<uint8_t>(new_value);
}
}
return valid;
}
bool GetValue(const char* device_name, const Json::Value &parent, const std::string &member, const char *name, int32_t *dest, bool not_modifiable, bool requested_profile,
std::function<bool(ProfileLayerSettings *, bool, const char *, const char *, int32_t, int32_t, bool)> warn_func = nullptr) {
if (member != name) {
return true;
}
// If the value is not modifiable and we don't warn, we can return immediately, we will use the native value
if (not_modifiable && warn_func == nullptr) {
return true;
}
const Json::Value value = parent[name];
if (!value.isInt()) {
return true;
}
bool valid = true;
const int32_t new_value = value.asInt();
if (warn_func) {
if (warn_func(&layer_settings, requested_profile, device_name, name, new_value, *dest, not_modifiable)) {
valid = false;
}
}
if (!not_modifiable) {
*dest = new_value;
}
return valid;
}
bool GetValue(const char* device_name, const Json::Value &parent, const std::string &member, const char *name, int64_t *dest, bool not_modifiable, bool requested_profile,
std::function<bool(ProfileLayerSettings *, bool, const char *, const char *, int64_t, int64_t, bool)> warn_func = nullptr) {
if (member != name) {
return true;
}
// If the value is not modifiable and we don't warn, we can return immediately, we will use the native value
if (not_modifiable && warn_func == nullptr) {
return true;
}
const Json::Value value = parent[name];
if (!value.isInt64()) {
return true;
}
bool valid = true;
const int64_t new_value = value.asInt64();
if (warn_func) {
if (warn_func(&layer_settings, requested_profile, device_name, name, new_value, *dest, not_modifiable)) {
valid = false;
}
}
if (!not_modifiable) {
*dest = new_value;
}
return valid;
}
bool GetValue(const char* device_name, const Json::Value &parent, const std::string &member, const char *name, uint32_t *dest, bool not_modifiable, bool requested_profile,
std::function<bool(ProfileLayerSettings *, bool, const char *, const char *, uint32_t, uint32_t, bool)> warn_func = nullptr) {
if (member != name) {
return true;
}
// If the value is not modifiable and we don't warn, we can return immediately, we will use the native value
if (not_modifiable && warn_func == nullptr) {
return true;
}
const Json::Value value = parent[name];
bool valid = true;
if (value.isBool()) {
const bool new_value = value.asBool();
if (warn_func) {
if (warn_func(&layer_settings, requested_profile, device_name, name, new_value, *dest, not_modifiable)) {
valid = false;
}
}
if (!not_modifiable) {
*dest = static_cast<uint32_t>(new_value);
}
} else if (value.isArray()) {
uint64_t sum_bits = 0;
for (const auto &entry : value) {
if (entry.isString()) {
sum_bits |= VkStringToUint64(entry.asString());
}
}
if (!not_modifiable) {
*dest = static_cast<uint32_t>(sum_bits);
}
} else if (value.isUInt()) {
const uint32_t new_value = value.asUInt();
if (warn_func) {
if (warn_func(&layer_settings, requested_profile, device_name, name, new_value, *dest, not_modifiable)) {
valid = false;
}
}
if (!not_modifiable) {
*dest = new_value;
}
}
return valid;
}
bool GetValue(const char* device_name, const Json::Value &parent, const std::string &member, const char *name, uint64_t *dest, bool not_modifiable, bool requested_profile,
std::function<bool(ProfileLayerSettings *, bool, const char *, const char *, uint64_t, uint64_t, bool)> warn_func = nullptr) {
if (member != name) {
return true;
}
// If the value is not modifiable and we don't warn, we can return immediately, we will use the native value
if (not_modifiable && warn_func == nullptr) {
return true;
}
const Json::Value value = parent[name];
if (!value.isUInt64()) {
return true;
}
bool valid = true;
const uint64_t new_value = value.asUInt64();
if (warn_func) {
if (warn_func(&layer_settings, requested_profile, device_name, name, new_value, *dest, not_modifiable)) {
valid = false;
}
}
if (!not_modifiable) {
*dest = new_value;
}
return valid;
}
bool GetValue(const char* device_name, const Json::Value &pparent, const std::string &member, const char *name, VkExtent2D *dest, bool not_modifiable, bool requested_profile,
std::function<bool(ProfileLayerSettings *, bool, const char *, const char *, uint32_t, uint32_t, bool)> warn_func = nullptr) {
if (member != name) {
return true;
}
// If the value is not modifiable and we don't warn, we can return immediately, we will use the native value
if (not_modifiable && warn_func == nullptr) {
return true;
}
const Json::Value parent = pparent[name];
if (parent.type() != Json::objectValue) {
return true;
}
bool valid = true;
for (const auto &prop : parent.getMemberNames()) {
GET_VALUE_WARN(prop, width, not_modifiable, requested_profile, warn_func);
GET_VALUE_WARN(prop, height, not_modifiable, requested_profile, warn_func);
}
return valid;
}
bool GetValue(const char* device_name, const Json::Value &pparent, const std::string &member, const char *name, VkExtent3D *dest, bool not_modifiable, bool requested_profile,
std::function<bool(ProfileLayerSettings *, bool, const char *, const char *, uint32_t, uint32_t, bool)> warn_func = nullptr) {
if (member != name) {
return true;
}
// If the value is not modifiable and we don't warn, we can return immediately, we will use the native value
if (not_modifiable && warn_func == nullptr) {
return true;
}
const Json::Value parent = pparent[name];
if (parent.type() != Json::objectValue) {
return true;
}
bool valid = true;
for (const auto &prop : parent.getMemberNames()) {
GET_VALUE_WARN(prop, width, not_modifiable, requested_profile, warn_func);
GET_VALUE_WARN(prop, height, not_modifiable, requested_profile, warn_func);
GET_VALUE_WARN(prop, depth, not_modifiable, requested_profile, warn_func);
}
return valid;
}
bool GetValueSizet(const char* device_name, const Json::Value &parent, const std::string &member, const char *name, size_t *dest, bool not_modifiable, bool requested_profile,
std::function<bool(ProfileLayerSettings *, bool, const char *, const char *, size_t, size_t, bool)> warn_func = nullptr) {
if (member != name) {
return true;
}
// If the value is not modifiable and we don't warn, we can return immediately, we will use the native value
if (not_modifiable && warn_func == nullptr) {
return true;
}
const Json::Value value = parent[name];
bool valid = true;
if (value.isUInt()) {
const size_t new_value = value.asUInt();
if (warn_func) {
if (warn_func(&layer_settings, requested_profile, device_name, name, new_value, *dest, not_modifiable)) {
valid = false;
}
}
if (!not_modifiable) {
*dest = new_value;
}
}
return valid;
}
template <typename T> // for Vulkan enum types
bool GetValueFlag(const char* device_name, const Json::Value &parent, const std::string &member, const char *name, T *dest, bool not_modifiable, bool requested_profile,
std::function<bool(ProfileLayerSettings *, bool, const char *, const char *, T, T, bool)> warn_func = nullptr) {
if (member != name) {
return true;
}
// If the value is not modifiable and we don't warn, we can return immediately, we will use the native value
if (not_modifiable && warn_func == nullptr) {
return true;
}
const Json::Value value = parent[name];
bool valid = true;
uint64_t new_value = 0;
if (value.isArray()) {
for (const auto &entry : value) {
if (entry.isString()) {
new_value |= VkStringToUint64(entry.asString());
}
}
}
if (WarnIfMissingBit(&layer_settings, requested_profile, device_name, name, new_value, static_cast<uint64_t>(*dest), not_modifiable)) {
valid = false;
}
if (!not_modifiable) {
*dest = static_cast<T>(new_value);
}
return valid;
}
template <typename T> // for Vulkan enum types
bool GetValueEnum(const char* device_name, const Json::Value &parent, const std::string &member, const char *name, T *dest, bool not_modifiable, bool requested_profile,
std::function<bool(ProfileLayerSettings *, bool, const char *, const char *, uint32_t, uint32_t, bool)> warn_func = nullptr) {
if (member != name) {
return true;
}
// If the value is not modifiable and we don't warn, we can return immediately, we will use the native value
if (not_modifiable && warn_func == nullptr) {
return true;
}
const Json::Value value = parent[name];
bool valid = true;
uint32_t new_value = 0;
if (value.isString()) {
new_value = static_cast<T>(VkStringToUint64(value.asString()));
}
if (warn_func) {
if (warn_func(&layer_settings, requested_profile, device_name, name, new_value, *dest, not_modifiable)) {
valid = false;
}
} else {
if (WarnIfNotEqualEnum(&layer_settings, requested_profile, device_name, name, new_value, *dest, not_modifiable)) {
valid = false;
}
}
if (!not_modifiable) {
*dest = static_cast<T>(new_value);
}
return valid;
}
int GetArray(const char* device_name, const Json::Value &parent, const std::string &member, const char *name, uint8_t *dest, bool not_modifiable) {
(void)device_name;
if (member != name) {
return -1;
}
const Json::Value value = parent[name];
if (value.type() != Json::arrayValue) {
return -1;
}
const int count = static_cast<int>(value.size());
if (!not_modifiable) {
for (int i = 0; i < count; ++i) {
dest[i] = static_cast<uint8_t>(value[i].asUInt());
}
}
return count;
}
int GetArray(const char* device_name, const Json::Value &parent, const std::string &member, const char *name, uint32_t *dest, bool not_modifiable) {
(void)device_name;
if (member != name) {
return -1;
}
const Json::Value value = parent[name];
if (value.type() != Json::arrayValue) {
return -1;
}
const int count = static_cast<int>(value.size());
if (!not_modifiable) {
for (int i = 0; i < count; ++i) {
dest[i] = static_cast<uint32_t>(value[i].asUInt());
}
}
return count;
}
int GetArray(const char* device_name, const Json::Value &parent, const std::string &member, const char *name, float *dest, bool not_modifiable) {
(void)device_name;
if (member != name) {
return -1;
}
const Json::Value value = parent[name];
if (value.type() != Json::arrayValue) {
return -1;
}
const int count = static_cast<int>(value.size());
if (!not_modifiable) {
for (int i = 0; i < count; ++i) {
dest[i] = value[i].asFloat();
}
}
return count;