Skip to content

Commit 8cd2d36

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

13 files changed

Lines changed: 527 additions & 364 deletions

vkconfig_cmd/main_layers.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ static int RunLayersPath(Configurator& configurator, const CommandLine& command_
9292
const std::set<LayerDisplay>& layer_display_list = configurator.layers.BuildLayerDisplayList();
9393

9494
for (auto it = layer_display_list.begin(), end = layer_display_list.end(); it != end; ++it) {
95-
const Layer* layer = configurator.layers.FindFromManifest(it->manifest_path, true);
95+
const Layer* layer = configurator.layers.FindFromManifest(it->id.manifest_path, true);
9696
if (layer == nullptr) {
9797
continue;
9898
}

vkconfig_core/layer.cpp

Lines changed: 128 additions & 133 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,36 +41,22 @@
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) {}
6552

66-
Layer::Layer(const std::string& key, const Version& file_format_version, const Version& api_version,
67-
const std::string& implementation_version, const std::string& library_path)
68-
: key(key),
69-
file_format_version(file_format_version),
70-
binary_path(library_path),
71-
api_version(api_version),
72-
implementation_version(implementation_version),
73-
status(STATUS_STABLE),
74-
platforms(PLATFORM_DESKTOP_BIT) {}
53+
LayerId Layer::GetId() const {
54+
LayerId id;
55+
id.manifest_path = this->manifest_path;
56+
id.key = this->key;
57+
id.api_version = this->api_version;
58+
return id;
59+
}
7560

7661
bool Layer::IsValid() const {
7762
return file_format_version != Version::NONE && !key.empty() && !binary_path.Empty() && api_version != Version::NONE &&
@@ -176,71 +161,7 @@ void Layer::FillPresetSettings(SettingDataSet& settings_data, const std::vector<
176161
}
177162
}
178163

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-
164+
LayerLoadStatus Layer::Load(const QJsonObject& json_layer_object) {
244165
this->key = ReadStringValue(json_layer_object, "name");
245166

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

250171
this->api_version = ReadVersionValue(json_layer_object, "api_version");
251172

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-
296173
const QJsonValue& json_library_path_value = json_layer_object.value("library_path");
297174
if (json_library_path_value != QJsonValue::Undefined) {
298175
this->binary_path = json_library_path_value.toString().toStdString();
@@ -301,7 +178,7 @@ LayerLoadStatus Layer::Load(const Path& full_path_to_file, LayerType type, bool
301178
const Path& binary = this->manifest_path.AbsoluteDir() + "/" + this->binary_path.AbsolutePath();
302179
if (::IsDLL32Bit(binary.AbsolutePath())) {
303180
this->is_32bits = true;
304-
return LAYER_LOAD_INVALID;
181+
return LAYER_LOAD_IGNORED;
305182
}
306183

307184
if (json_layer_object.value("prefix") != QJsonValue::Undefined) {
@@ -390,9 +267,127 @@ LayerLoadStatus Layer::Load(const Path& full_path_to_file, LayerType type, bool
390267
}
391268
}
392269

393-
return this->IsValid() ? LAYER_LOAD_ADDED : LAYER_LOAD_INVALID; // Not all JSON file are layer JSON valid
270+
return this->IsValid() ? LAYER_LOAD_ADDED : LAYER_LOAD_INVALID;
394271
}
395272

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

vkconfig_core/layer.h

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -36,42 +36,40 @@
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 };
7068

7169
Layer();
7270
Layer(const std::string& key);
73-
Layer(const std::string& key, const Version& file_format_version, const Version& api_version,
74-
const std::string& implementation_version, const std::string& library_path);
71+
72+
LayerId GetId() const;
7573

7674
bool IsValid() const;
7775

@@ -113,8 +111,9 @@ class Layer {
113111
std::vector<SettingMeta*> settings;
114112
std::vector<LayerPreset> presets;
115113

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

119118
private:
120119
Layer& operator=(const Layer&) = delete;

0 commit comments

Comments
 (0)