Skip to content

Commit d3cfa1b

Browse files
vkconfig: Fix layer shame alidation caching
1 parent 7df1088 commit d3cfa1b

5 files changed

Lines changed: 94 additions & 30 deletions

File tree

vkconfig_core/configurator.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,7 +1143,12 @@ bool Configurator::Load() {
11431143
display.id.api_version = Version::NONE;
11441144
display.descriptor.enabled = json_descriptor_object.value("enabled").toBool();
11451145
display.descriptor.removed = json_descriptor_object.value("removed").toBool();
1146-
display.descriptor.validated = json_descriptor_object.value("validated").toBool();
1146+
display.descriptor.validated =
1147+
::GetLayerValidated(json_descriptor_object.value("validated").toString().toStdString().c_str());
1148+
if (json_descriptor_object.value("last_modified") != QJsonValue::Undefined) {
1149+
display.descriptor.last_modified =
1150+
json_descriptor_object.value("last_modified").toString().toStdString();
1151+
}
11471152
descriptors.push_back(display);
11481153
}
11491154

@@ -1379,10 +1384,10 @@ bool Configurator::Save() const {
13791384

13801385
QJsonObject json_descriptor;
13811386
json_descriptor.insert("key", jt->first.c_str());
1382-
json_descriptor.insert("validated", jt->second.descriptor.validated);
1387+
json_descriptor.insert("validated", ::GetToken(jt->second.descriptor.validated));
13831388
json_descriptor.insert("enabled", jt->second.descriptor.enabled);
13841389
json_descriptor.insert("removed", jt->second.descriptor.removed);
1385-
1390+
json_descriptor.insert("last_modified", jt->second.descriptor.last_modified.c_str());
13861391
json_layer_descriptors.append(json_descriptor);
13871392
}
13881393

vkconfig_core/layer.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,31 @@
4646
#include <string>
4747
#include <algorithm>
4848

49+
#include <array>
50+
#include <cstring>
51+
52+
const char* GetToken(LayerValidated status) {
53+
static const char* TOKENS[] = {
54+
"NONE", // LAYER_VALIDATE_NONE
55+
"PASS", // LAYER_VALIDATE_PASS
56+
"FAIL", // LAYER_VALIDATE_FAIL
57+
};
58+
static_assert(std::size(TOKENS) == LAYER_VALIDATE_COUNT);
59+
60+
return TOKENS[status];
61+
}
62+
63+
LayerValidated GetLayerValidated(const char* token) {
64+
for (int i = LAYER_VALIDATE_FIRST, l = LAYER_VALIDATE_LAST; i <= l; ++i) {
65+
const LayerValidated status = static_cast<LayerValidated>(i);
66+
if (std::strcmp(::GetToken(status), token) == 0) {
67+
return status;
68+
}
69+
}
70+
71+
return LAYER_VALIDATE_FIRST;
72+
}
73+
4974
Layer::Layer() : status(STATUS_STABLE), platforms(PLATFORM_DESKTOP_BIT) {}
5075

5176
Layer::Layer(const std::string& key) : key(key), status(STATUS_STABLE), platforms(PLATFORM_DESKTOP_BIT) {}

vkconfig_core/layer.h

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,30 @@ enum LayerLoadStatus {
4949

5050
enum { LAYER_LOAD_COUNT = LAYER_LOAD_LAST - LAYER_LOAD_FIRST + 1 };
5151

52+
enum LayerValidated {
53+
LAYER_VALIDATE_NONE = 0,
54+
LAYER_VALIDATE_PASS,
55+
LAYER_VALIDATE_FAIL,
56+
57+
LAYER_VALIDATE_FIRST = LAYER_VALIDATE_NONE,
58+
LAYER_VALIDATE_LAST = LAYER_VALIDATE_FAIL,
59+
};
60+
61+
enum { LAYER_VALIDATE_COUNT = LAYER_VALIDATE_LAST - LAYER_VALIDATE_FIRST + 1 };
62+
63+
const char* GetToken(LayerValidated status);
64+
65+
LayerValidated GetLayerValidated(const char* token);
66+
5267
struct LayerId {
5368
Path manifest_path;
5469
std::string key;
5570
Version api_version;
5671
};
5772

5873
struct LayerDescriptor {
59-
bool validated = false;
74+
std::string last_modified;
75+
LayerValidated validated = LAYER_VALIDATE_NONE;
6076
bool enabled = true;
6177
bool removed = false;
6278
bool recent = false;
@@ -94,7 +110,7 @@ class Layer {
94110
Path binary_path;
95111
Version api_version;
96112
std::string implementation_version;
97-
std::string last_modified;
113+
// std::string last_modified;
98114
StatusType status;
99115
std::string description;
100116
std::string introduction;

vkconfig_core/layer_manager.cpp

Lines changed: 40 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ bool LayerManager::Load(const QJsonObject &json_root_object, ConfiguratorMode co
175175
LayerDisplay layer;
176176
layer.id.manifest_path = json_layers_found_keys[i].toStdString();
177177
layer.descriptor.enabled = !json_status_object.value("disabled").toBool();
178-
layer.descriptor.validated = json_status_object.value("validated").toBool();
178+
layer.descriptor.validated = LAYER_VALIDATE_NONE;
179179

180180
std::vector<LayerDisplay> layers;
181181
layers.push_back(layer);
@@ -391,7 +391,7 @@ const Layer *LayerManager::FindLastModified(const std::string &layer_name, const
391391
}
392392

393393
if (result != nullptr) {
394-
if (result->last_modified > this->available_layers[i].last_modified) {
394+
if (result->descriptor.last_modified > this->available_layers[i].descriptor.last_modified) {
395395
continue;
396396
}
397397
}
@@ -497,10 +497,10 @@ void LayerManager::LoadAllInstalledLayers(ConfiguratorMode configurator_mode) {
497497
}
498498
}
499499

500-
this->ApplyLayerDescriptor();
500+
// this->ApplyLayerDescriptor();
501501
}
502502

503-
bool LayerManager::Validate(const Path &layer_path, QString json_text, ConfiguratorMode configurator_mode) const {
503+
LayerValidated LayerManager::Validate(const Path &layer_path, QString json_text, ConfiguratorMode configurator_mode) const {
504504
JsonValidator validator;
505505
bool result = validator.Check(json_text);
506506

@@ -543,13 +543,25 @@ bool LayerManager::Validate(const Path &layer_path, QString json_text, Configura
543543
}
544544
}
545545

546-
return result;
546+
return result ? LAYER_VALIDATE_PASS : LAYER_VALIDATE_FAIL;
547547
}
548548

549-
LayerLoadStatus LayerManager::LoadLayers(const Path &layer_path, LayerType type, ConfiguratorMode configurator_mode) {
550-
const std::string &last_modified = layer_path.LastModified();
551-
LayerDescriptor descriptor;
549+
LayerDescriptor LayerManager::GetDescriptor(const Path &layer_path, const std::string &layer_key) const {
550+
auto it = layer_init.find(layer_path);
551+
if (it != layer_init.end()) {
552+
const std::vector<LayerDisplay> &data = it->second;
553+
for (std::size_t i = 0, n = data.size(); i < n; ++i) {
554+
const LayerDisplay &display = data[i];
555+
if (display.id.key == layer_key) {
556+
return display.descriptor;
557+
}
558+
}
559+
}
560+
561+
return LayerDescriptor();
562+
}
552563

564+
LayerLoadStatus LayerManager::LoadLayers(const Path &layer_path, LayerType type, ConfiguratorMode configurator_mode) {
553565
QFile file(layer_path.AbsolutePath().c_str());
554566
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
555567
assert(0);
@@ -579,6 +591,7 @@ LayerLoadStatus LayerManager::LoadLayers(const Path &layer_path, LayerType type,
579591
}
580592

581593
LayerLoadStatus status = LAYER_LOAD_ADDED;
594+
const std::string &last_modified = layer_path.LastModified();
582595

583596
if (json_root_object.value("layers") != QJsonValue::Undefined) {
584597
const QJsonArray &json_layers_array = json_root_object.value("layers").toArray();
@@ -589,32 +602,37 @@ LayerLoadStatus LayerManager::LoadLayers(const Path &layer_path, LayerType type,
589602
std::string key = ReadStringValue(json_layer_object, "name");
590603

591604
if (key == "VK_LAYER_LUNARG_override" || !(key.rfind("VK_", 0) == 0)) {
592-
return LAYER_LOAD_IGNORED;
605+
status = LAYER_LOAD_IGNORED;
606+
continue;
593607
}
594-
}
595608

596-
if (this->validate_manifests) {
597-
descriptor.validated = this->Validate(layer_path, json_text, configurator_mode);
598-
}
609+
LayerDescriptor descriptor = this->GetDescriptor(layer_path, key);
599610

600-
for (int i = 0, n = json_layers_array.size(); i < n; ++i) {
601-
const QJsonObject &json_layer_object = json_layers_array[i].toObject();
602-
status = this->LoadLayer(json_layer_object, layer_path, type, last_modified, file_format_version, descriptor);
611+
if (this->validate_manifests && (descriptor.last_modified != last_modified) || !descriptor.validated) {
612+
descriptor.validated = this->Validate(layer_path, json_text, configurator_mode);
613+
descriptor.last_modified = last_modified;
614+
}
615+
616+
status = this->LoadLayer(json_layer_object, layer_path, type, file_format_version, descriptor);
603617
}
604618
} else if (json_root_object.value("layer") != QJsonValue::Undefined) {
605619
const QJsonObject &json_layer_object = json_root_object.value("layer").toObject();
606620

607-
std::string key = ReadStringValue(json_layer_object, "name");
621+
std::string layer_key = ReadStringValue(json_layer_object, "name");
608622

609-
if (key == "VK_LAYER_LUNARG_override" || !(key.rfind("VK_", 0) == 0)) {
623+
if (layer_key == "VK_LAYER_LUNARG_override" || !(layer_key.rfind("VK_", 0) == 0)) {
610624
return LAYER_LOAD_IGNORED;
611625
}
612626

613-
if (this->validate_manifests) {
627+
LayerDescriptor descriptor = this->GetDescriptor(layer_path, layer_key);
628+
629+
if (this->validate_manifests &&
630+
(descriptor.last_modified != last_modified || descriptor.validated == LAYER_VALIDATE_NONE)) {
614631
descriptor.validated = this->Validate(layer_path, json_text, configurator_mode);
632+
descriptor.last_modified = last_modified;
615633
}
616634

617-
status = this->LoadLayer(json_layer_object, layer_path, type, last_modified, file_format_version, descriptor);
635+
status = this->LoadLayer(json_layer_object, layer_path, type, file_format_version, descriptor);
618636
} else {
619637
assert(0);
620638
}
@@ -623,11 +641,10 @@ LayerLoadStatus LayerManager::LoadLayers(const Path &layer_path, LayerType type,
623641
}
624642

625643
LayerLoadStatus LayerManager::LoadLayer(const QJsonObject &json_layer_object, const Path &layer_path, LayerType type,
626-
const std::string &last_modified, Version file_format_version, LayerDescriptor descriptor) {
644+
Version file_format_version, LayerDescriptor descriptor) {
627645
Layer layer;
628646
layer.type = type;
629647
layer.manifest_path = layer_path;
630-
layer.last_modified = last_modified;
631648
layer.file_format_version = file_format_version;
632649
layer.descriptor = descriptor;
633650

@@ -641,7 +658,7 @@ LayerLoadStatus LayerManager::LoadLayer(const QJsonObject &json_layer_object, co
641658
if (duplicated_layer->descriptor.removed) {
642659
duplicated_layer->descriptor.removed = false;
643660
duplicated_layer->descriptor.enabled = true;
644-
} else if (duplicated_layer->last_modified != layer.last_modified) {
661+
} else if (duplicated_layer->descriptor.last_modified != layer.descriptor.last_modified) {
645662
// Reload when the manifest was updated
646663
LayerLoadStatus reloaded_status = duplicated_layer->Load(json_layer_object);
647664
status = reloaded_status == LAYER_LOAD_ADDED ? LAYER_LOAD_RELOADED : reloaded_status;

vkconfig_core/layer_manager.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ class LayerManager : public Serialize {
6969
std::set<LayerDisplay> BuildLayerDisplayList() const;
7070
std::map<Path, std::map<std::string, LayerDisplay>> BuildLayerStoreList() const;
7171
std::vector<Path> BuildLayerPaths() const;
72+
LayerDescriptor GetDescriptor(const Path& layer_path, const std::string& layer_key) const;
7273

7374
std::vector<std::string> GatherLayerNames() const;
7475

@@ -83,10 +84,10 @@ class LayerManager : public Serialize {
8384
}
8485

8586
private:
86-
bool Validate(const Path& layer_path, QString json_text, ConfiguratorMode configurator_mode) const;
87+
LayerValidated Validate(const Path& layer_path, QString json_text, ConfiguratorMode configurator_mode) const;
8788

8889
LayerLoadStatus LoadLayer(const QJsonObject& json_layer_object, const Path& layer_path, LayerType type,
89-
const std::string& last_modified, Version file_format_version, LayerDescriptor descriptor);
90+
Version file_format_version, LayerDescriptor descriptor);
9091

9192
void ApplyLayerDescriptor();
9293

0 commit comments

Comments
 (0)