Skip to content

Commit b5e5aef

Browse files
vkconfig: Fix mix layer and icd manifest
1 parent 9be945a commit b5e5aef

11 files changed

Lines changed: 505 additions & 346 deletions

File tree

vkconfig_core/layer.cpp

Lines changed: 129 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
#include "util.h"
3434
#include "path.h"
3535
#include "json.h"
36-
#include "json_validator.h"
3736
#include "is_dll_32.h"
3837
#include "configurator.h"
3938

@@ -42,23 +41,11 @@
4241
#include <QMessageBox>
4342
#include <QJsonArray>
4443
#include <QCheckBox>
45-
#include <QDesktopServices>
46-
#include <QFileDialog>
4744

4845
#include <cassert>
4946
#include <string>
5047
#include <algorithm>
5148

52-
bool Found(const std::vector<Path>& data, const Path& path) {
53-
for (std::size_t i = 0, n = data.size(); i < n; ++i) {
54-
if (data[i] == path) {
55-
return true;
56-
}
57-
}
58-
59-
return false;
60-
}
61-
6249
Layer::Layer() : status(STATUS_STABLE), platforms(PLATFORM_DESKTOP_BIT) {}
6350

6451
Layer::Layer(const std::string& key) : key(key), status(STATUS_STABLE), platforms(PLATFORM_DESKTOP_BIT) {}
@@ -73,6 +60,14 @@ Layer::Layer(const std::string& key, const Version& file_format_version, const V
7360
status(STATUS_STABLE),
7461
platforms(PLATFORM_DESKTOP_BIT) {}
7562

63+
LayerId Layer::GetId() const {
64+
LayerId id;
65+
id.manifest_path = this->manifest_path;
66+
id.key = this->key;
67+
id.api_version = this->api_version;
68+
return id;
69+
}
70+
7671
bool Layer::IsValid() const {
7772
return file_format_version != Version::NONE && !key.empty() && !binary_path.Empty() && api_version != Version::NONE &&
7873
!implementation_version.empty();
@@ -176,71 +171,7 @@ void Layer::FillPresetSettings(SettingDataSet& settings_data, const std::vector<
176171
}
177172
}
178173

179-
LayerLoadStatus Layer::Load(const Path& full_path_to_file, LayerType type, bool request_validate_manifest,
180-
ConfiguratorMode configurator_mode) {
181-
this->type = type; // Set layer type, no way to know this from the json file
182-
183-
if (full_path_to_file.Empty()) {
184-
return LAYER_LOAD_IGNORED;
185-
}
186-
187-
QFile file(full_path_to_file.AbsolutePath().c_str());
188-
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
189-
return LAYER_LOAD_FAILED;
190-
}
191-
192-
QString json_text = file.readAll();
193-
file.close();
194-
195-
this->manifest_path = full_path_to_file;
196-
this->last_modified = full_path_to_file.LastModified();
197-
198-
// Convert the text to a JSON document & validate it.
199-
// It does need to be a valid json formatted file.
200-
QJsonParseError json_parse_error;
201-
const QJsonDocument& json_document = QJsonDocument::fromJson(json_text.toUtf8(), &json_parse_error);
202-
if (json_parse_error.error != QJsonParseError::NoError) {
203-
return LAYER_LOAD_FAILED;
204-
}
205-
206-
// Make sure it's not empty
207-
if (json_document.isNull() || json_document.isEmpty()) {
208-
return LAYER_LOAD_FAILED;
209-
}
210-
211-
// First check it's a layer manifest, ignore otherwise.
212-
const QJsonObject& json_root_object = json_document.object();
213-
if (json_root_object.value("file_format_version") == QJsonValue::Undefined) {
214-
return LAYER_LOAD_IGNORED; // Not a layer JSON file
215-
}
216-
if (json_root_object.value("layer") == QJsonValue::Undefined) {
217-
return LAYER_LOAD_IGNORED; // Not a layer JSON file
218-
}
219-
220-
this->file_format_version = ReadVersionValue(json_root_object, "file_format_version");
221-
if (this->file_format_version.GetMajor() > 1) {
222-
switch (configurator_mode) {
223-
default: {
224-
} break;
225-
case CONFIGURATOR_MODE_GUI: {
226-
QMessageBox alert;
227-
alert.setWindowTitle("Failed to load a layer manifest...");
228-
alert.setText(format("Unsupported layer file format: %s.", this->file_format_version.str().c_str()).c_str());
229-
alert.setInformativeText(
230-
format("The %s layer is being ignored.", full_path_to_file.AbsolutePath().c_str()).c_str());
231-
alert.setIcon(QMessageBox::Critical);
232-
alert.exec();
233-
} break;
234-
case CONFIGURATOR_MODE_CMD: {
235-
fprintf(stderr, "vkconfig: [ERROR] Unsupported layer file format: %s\n", this->file_format_version.str().c_str());
236-
fprintf(stderr, "\n (%s layer is ignored\n)", full_path_to_file.AbsolutePath().c_str());
237-
} break;
238-
}
239-
return LAYER_LOAD_INVALID;
240-
}
241-
242-
const QJsonObject& json_layer_object = ReadObject(json_root_object, "layer");
243-
174+
LayerLoadStatus Layer::Load(const QJsonObject& json_layer_object) {
244175
this->key = ReadStringValue(json_layer_object, "name");
245176

246177
if (this->key == "VK_LAYER_LUNARG_override" || !(this->key.rfind("VK_", 0) == 0)) {
@@ -249,50 +180,6 @@ LayerLoadStatus Layer::Load(const Path& full_path_to_file, LayerType type, bool
249180

250181
this->api_version = ReadVersionValue(json_layer_object, "api_version");
251182

252-
JsonValidator validator;
253-
254-
const bool is_valid = request_validate_manifest ? validator.Check(json_text) : true;
255-
256-
if (!is_valid) {
257-
switch (configurator_mode) {
258-
default: {
259-
} break;
260-
case CONFIGURATOR_MODE_GUI: {
261-
QMessageBox alert;
262-
alert.setWindowTitle("Failed to load a layer manifest...");
263-
alert.setText(format("%s is not a valid layer file", full_path_to_file.AbsolutePath().c_str()).c_str());
264-
alert.setInformativeText("Do you want to save the validation log?");
265-
alert.setIcon(QMessageBox::Critical);
266-
alert.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
267-
alert.setDefaultButton(QMessageBox::Yes);
268-
int result = alert.exec();
269-
if (result == QMessageBox::Yes) {
270-
const QString& selected_path = QFileDialog::getSaveFileName(
271-
nullptr, format("Export %s validation log", full_path_to_file.AbsolutePath().c_str()).c_str(),
272-
(AbsolutePath(Path::HOME) + "/" + full_path_to_file.Basename() + "_log.txt").c_str(), "Log(*.txt)");
273-
QFile log_file(selected_path);
274-
const bool result = log_file.open(QIODevice::WriteOnly | QIODevice::Text);
275-
if (result) {
276-
QDesktopServices::openUrl(QUrl::fromLocalFile(selected_path));
277-
log_file.write(validator.message.toStdString().c_str());
278-
log_file.close();
279-
} else {
280-
QMessageBox alert;
281-
alert.setWindowTitle("Failed to save layer manifest log...");
282-
alert.setText(format("Couldn't not open %s file...", selected_path.toStdString().c_str()).c_str());
283-
alert.setIcon(QMessageBox::Critical);
284-
alert.exec();
285-
}
286-
}
287-
} break;
288-
case CONFIGURATOR_MODE_CMD: {
289-
fprintf(stderr, "vkconfig: [ERROR] Couldn't validate layer file: %s\n", full_path_to_file.AbsolutePath().c_str());
290-
fprintf(stderr, "\n%s\n)", validator.message.toStdString().c_str());
291-
} break;
292-
}
293-
return LAYER_LOAD_INVALID;
294-
}
295-
296183
const QJsonValue& json_library_path_value = json_layer_object.value("library_path");
297184
if (json_library_path_value != QJsonValue::Undefined) {
298185
this->binary_path = json_library_path_value.toString().toStdString();
@@ -301,7 +188,7 @@ LayerLoadStatus Layer::Load(const Path& full_path_to_file, LayerType type, bool
301188
const Path& binary = this->manifest_path.AbsoluteDir() + "/" + this->binary_path.AbsolutePath();
302189
if (::IsDLL32Bit(binary.AbsolutePath())) {
303190
this->is_32bits = true;
304-
return LAYER_LOAD_INVALID;
191+
return LAYER_LOAD_IGNORED;
305192
}
306193

307194
if (json_layer_object.value("prefix") != QJsonValue::Undefined) {
@@ -390,9 +277,127 @@ LayerLoadStatus Layer::Load(const Path& full_path_to_file, LayerType type, bool
390277
}
391278
}
392279

393-
return this->IsValid() ? LAYER_LOAD_ADDED : LAYER_LOAD_INVALID; // Not all JSON file are layer JSON valid
280+
return this->IsValid() ? LAYER_LOAD_ADDED : LAYER_LOAD_INVALID;
394281
}
395282

283+
/*
284+
LayerLoadStatus Layer::Load(const Path& full_path_to_file, LayerType type, ConfiguratorMode configurator_mode) {
285+
this->type = type; // Set layer type, no way to know this from the json file
286+
287+
if (full_path_to_file.Empty()) {
288+
return LAYER_LOAD_IGNORED;
289+
}
290+
291+
QFile file(full_path_to_file.AbsolutePath().c_str());
292+
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
293+
return LAYER_LOAD_FAILED;
294+
}
295+
296+
QString json_text = file.readAll();
297+
file.close();
298+
299+
this->manifest_path = full_path_to_file;
300+
this->last_modified = full_path_to_file.LastModified();
301+
302+
// Convert the text to a JSON document & validate it.
303+
// It does need to be a valid json formatted file.
304+
QJsonParseError json_parse_error;
305+
const QJsonDocument& json_document = QJsonDocument::fromJson(json_text.toUtf8(), &json_parse_error);
306+
if (json_parse_error.error != QJsonParseError::NoError) {
307+
return LAYER_LOAD_FAILED;
308+
}
309+
310+
// Make sure it's not empty
311+
if (json_document.isNull() || json_document.isEmpty()) {
312+
return LAYER_LOAD_FAILED;
313+
}
314+
315+
// First check it's a layer manifest, ignore otherwise.
316+
const QJsonObject& json_root_object = json_document.object();
317+
if (json_root_object.value("file_format_version") == QJsonValue::Undefined) {
318+
return LAYER_LOAD_IGNORED; // Not a layer JSON file
319+
}
320+
if (json_root_object.value("layer") == QJsonValue::Undefined && json_root_object.value("layers") == QJsonValue::Undefined) {
321+
return LAYER_LOAD_IGNORED; // Not a layer JSON file
322+
}
323+
324+
this->file_format_version = ReadVersionValue(json_root_object, "file_format_version");
325+
if (this->file_format_version.GetMajor() > 1) {
326+
switch (configurator_mode) {
327+
default: {
328+
} break;
329+
case CONFIGURATOR_MODE_GUI: {
330+
QMessageBox alert;
331+
alert.setWindowTitle("Failed to load a layer manifest...");
332+
alert.setText(format("Unsupported layer file format: %s.", this->file_format_version.str().c_str()).c_str());
333+
alert.setInformativeText(
334+
format("The %s layer is being ignored.", full_path_to_file.AbsolutePath().c_str()).c_str());
335+
alert.setIcon(QMessageBox::Critical);
336+
alert.exec();
337+
} break;
338+
case CONFIGURATOR_MODE_CMD: {
339+
fprintf(stderr, "vkconfig: [ERROR] Unsupported layer file format: %s\n", this->file_format_version.str().c_str());
340+
fprintf(stderr, "\n (%s layer is ignored\n)", full_path_to_file.AbsolutePath().c_str());
341+
} break;
342+
}
343+
return LAYER_LOAD_INVALID;
344+
}
345+
346+
JsonValidator validator;
347+
348+
const bool is_valid = request_validate_manifest ? validator.Check(json_text) : true;
349+
if (!is_valid) {
350+
switch (configurator_mode) {
351+
default: {
352+
} break;
353+
case CONFIGURATOR_MODE_GUI: {
354+
QMessageBox alert;
355+
alert.setWindowTitle("Failed to load a layer manifest...");
356+
alert.setText(format("%s is not a valid layer file", full_path_to_file.AbsolutePath().c_str()).c_str());
357+
alert.setInformativeText("Do you want to save the validation log?");
358+
alert.setIcon(QMessageBox::Critical);
359+
alert.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
360+
alert.setDefaultButton(QMessageBox::Yes);
361+
int result = alert.exec();
362+
if (result == QMessageBox::Yes) {
363+
const QString& selected_path = QFileDialog::getSaveFileName(
364+
nullptr, format("Export %s validation log", full_path_to_file.AbsolutePath().c_str()).c_str(),
365+
(AbsolutePath(Path::HOME) + "/" + full_path_to_file.Basename() + "_log.txt").c_str(), "Log(*.txt)");
366+
QFile log_file(selected_path);
367+
const bool result = log_file.open(QIODevice::WriteOnly | QIODevice::Text);
368+
if (result) {
369+
QDesktopServices::openUrl(QUrl::fromLocalFile(selected_path));
370+
log_file.write(validator.message.toStdString().c_str());
371+
log_file.close();
372+
} else {
373+
QMessageBox alert;
374+
alert.setWindowTitle("Failed to save layer manifest log...");
375+
alert.setText(format("Couldn't not open %s file...", selected_path.toStdString().c_str()).c_str());
376+
alert.setIcon(QMessageBox::Critical);
377+
alert.exec();
378+
}
379+
}
380+
} break;
381+
case CONFIGURATOR_MODE_CMD: {
382+
fprintf(stderr, "vkconfig: [ERROR] Couldn't validate layer file: %s\n", full_path_to_file.AbsolutePath().c_str());
383+
fprintf(stderr, "\n%s\n)", validator.message.toStdString().c_str());
384+
} break;
385+
}
386+
return LAYER_LOAD_INVALID;
387+
}
388+
389+
if (json_root_object.value("layers") == QJsonValue::Undefined) {
390+
const QJsonArray& json_layers_array = json_root_object.value("layers").toArray();
391+
for (int i = 0, n = json_layers_array.size(); i < n; ++i) {
392+
const QJsonObject& json_layer_object = json_layers_array[i].toObject();
393+
return this->LoadLayer(json_layer_object);
394+
}
395+
} else {
396+
const QJsonObject& json_layer_object = ReadObject(json_root_object, "layer");
397+
return this->LoadLayer(json_layer_object);
398+
}
399+
}
400+
*/
396401
bool operator<(const Layer& layer_a, const Layer& layer_b) {
397402
if (layer_a.key == layer_b.key) {
398403
return layer_a.api_version < layer_b.api_version;

vkconfig_core/layer.h

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,34 +36,32 @@
3636
#include <vector>
3737
#include <string>
3838

39-
struct LayerDescriptor {
40-
LayerType type = LAYER_TYPE_EXPLICIT;
41-
std::string last_modified;
42-
bool validated = false;
43-
bool enabled = true;
44-
bool added = false;
45-
};
46-
47-
bool Found(const std::vector<Path>& data, const Path& path);
48-
4939
enum LayerLoadStatus {
5040
LAYER_LOAD_ADDED = 0,
5141
LAYER_LOAD_RELOADED,
5242
LAYER_LOAD_UNMODIFIED,
53-
LAYER_LOAD_FAILED,
5443
LAYER_LOAD_INVALID,
5544
LAYER_LOAD_IGNORED,
5645

5746
LAYER_LOAD_FIRST = LAYER_LOAD_ADDED,
5847
LAYER_LOAD_LAST = LAYER_LOAD_IGNORED,
5948
};
6049

61-
inline bool IsEnabled(LayerLoadStatus status) {
62-
return !(status == LAYER_LOAD_FAILED || status == LAYER_LOAD_INVALID || status == LAYER_LOAD_IGNORED);
63-
}
64-
6550
enum { LAYER_LOAD_COUNT = LAYER_LOAD_LAST - LAYER_LOAD_FIRST + 1 };
6651

52+
struct LayerId {
53+
Path manifest_path;
54+
std::string key;
55+
Version api_version;
56+
};
57+
58+
struct LayerDescriptor {
59+
bool validated = false;
60+
bool enabled = true;
61+
bool added = false;
62+
bool removed = false;
63+
};
64+
6765
class Layer {
6866
public:
6967
enum { NO_PRESET = -1, DEFAULT_PRESET = 0 };
@@ -73,6 +71,8 @@ class Layer {
7371
Layer(const std::string& key, const Version& file_format_version, const Version& api_version,
7472
const std::string& implementation_version, const std::string& library_path);
7573

74+
LayerId GetId() const;
75+
7676
bool IsValid() const;
7777

7878
LayerControl GetActualControl() const;
@@ -113,8 +113,9 @@ class Layer {
113113
std::vector<SettingMeta*> settings;
114114
std::vector<LayerPreset> presets;
115115

116-
LayerLoadStatus Load(const Path& full_path_to_file, LayerType type, bool request_validate_manifest,
117-
ConfiguratorMode configurator_mode);
116+
LayerLoadStatus Load(const QJsonObject& json_layer_object);
117+
118+
LayerDescriptor descriptor;
118119

119120
private:
120121
Layer& operator=(const Layer&) = delete;

0 commit comments

Comments
 (0)