ACMX 2.139.0
Dual-Backend Real-Time GPU Video Synthesis
Loading...
Searching...
No Matches
acmxvk-source-manifest-test.cpp
Go to the documentation of this file.
2#include "shader-manifest.hpp"
3
4#include <QDir>
5#include <QFile>
6#include <QFileInfo>
7#include <QJsonArray>
8#include <QJsonDocument>
9#include <QJsonObject>
10#include <QTemporaryDir>
11#include <iostream>
12
13namespace {
14 bool write_file(const QString &path, const QByteArray &contents) {
15 if (!QDir().mkpath(QFileInfo(path).absolutePath()))
16 return false;
17 QFile file(path);
18 return file.open(QIODevice::WriteOnly) && file.write(contents) == contents.size();
19 }
20
21 QJsonObject read_manifest(const QString &path) {
22 QFile file(path);
23 if (!file.open(QIODevice::ReadOnly))
24 return {};
25 return QJsonDocument::fromJson(file.readAll()).object();
26 }
27} // namespace
28
29int main() {
30 QTemporaryDir temporary;
31 if (!temporary.isValid())
32 return 1;
33 const QString root = temporary.path();
34 if (!write_file(QDir(root).filePath(QStringLiteral("z.frag")), QByteArrayLiteral("#version 450\n")) || !write_file(QDir(root).filePath(QStringLiteral("a.frag")), QByteArrayLiteral("#define slider1 ext.custom_uniforms[5].x\n")) || !write_file(QDir(root).filePath(QStringLiteral("compute/fx.comp")), QByteArrayLiteral("#version 450\n"))) {
35 return 2;
36 }
37
39 QString error;
40 if (!acmx2::create_acmxvk_source_manifest(root, QString(), result, error)) {
41 std::cerr << error.toStdString() << '\n';
42 return 3;
43 }
44 if (result.fragmentCount != 2 || result.computeCount != 1 || result.customUniformCount != 27) {
45 return 4;
46 }
47
48 const QString manifestPath = QDir(root).filePath(QStringLiteral("library.json"));
49 QJsonObject manifest = read_manifest(manifestPath);
50 const QJsonArray shaders = manifest.value(QStringLiteral("shaders")).toArray();
51 if (manifest.value(QStringLiteral("backend")).toString() != QStringLiteral("acmxvk") || manifest.value(QStringLiteral("library_type")).toString() != QStringLiteral("source") || shaders.size() != 3 || shaders.at(0).toString() != QStringLiteral("a.frag") || shaders.at(2).toString() != QStringLiteral("compute/fx.comp")) {
52 return 5;
53 }
54
55 QJsonObject uniforms = manifest.value(QStringLiteral("custom_uniforms")).toObject();
56 QJsonObject slider = uniforms.value(QStringLiteral("slider1")).toObject();
57 slider.insert(QStringLiteral("value"), 0.75);
58 slider.insert(QStringLiteral("maximum"), 2.0);
59 uniforms.insert(QStringLiteral("slider1"), slider);
60 manifest.insert(QStringLiteral("custom_uniforms"), uniforms);
61 if (!write_file(manifestPath, QJsonDocument(manifest).toJson(QJsonDocument::Indented))) {
62 return 6;
63 }
64 if (!acmx2::create_acmxvk_source_manifest(root, QString(), result, error)) {
65 std::cerr << error.toStdString() << '\n';
66 return 7;
67 }
68 slider = read_manifest(manifestPath).value(QStringLiteral("custom_uniforms")).toObject().value(QStringLiteral("slider1")).toObject();
69 if (slider.value(QStringLiteral("slot")).toInt() != 20 || slider.value(QStringLiteral("value")).toDouble() != 0.75 || slider.value(QStringLiteral("maximum")).toDouble() != 2.0) {
70 return 8;
71 }
72
73 if (!acmx2::remove_shader_manifest_entry(root, QStringLiteral("z.frag"), error)) {
74 std::cerr << error.toStdString() << '\n';
75 return 9;
76 }
77 QStringList remainingShaders;
78 if (!acmx2::load_shader_manifest(root, remainingShaders, error) || remainingShaders.contains(QStringLiteral("z.frag"), Qt::CaseInsensitive) || !QFileInfo::exists(QDir(root).filePath(QStringLiteral("z.frag")))) {
79 return 10;
80 }
81 if (!write_file(QDir(root).filePath(QStringLiteral("new.frag")), QByteArrayLiteral("#version 450\n"))) {
82 return 11;
83 }
84 remainingShaders.append(QStringLiteral("new.frag"));
85 if (!acmx2::create_acmxvk_source_manifest_for_shaders(root, remainingShaders, QString(), result, error)) {
86 std::cerr << error.toStdString() << '\n';
87 return 12;
88 }
89 remainingShaders.clear();
90 if (!acmx2::load_shader_manifest(root, remainingShaders, error) || remainingShaders.contains(QStringLiteral("z.frag"), Qt::CaseInsensitive) || !remainingShaders.contains(QStringLiteral("new.frag"), Qt::CaseInsensitive)) {
91 return 13;
92 }
93
94 QList<acmx2::CustomUniformDefinition> customUniforms;
95 if (!acmx2::load_custom_uniforms(root, customUniforms, error) || customUniforms.size() != 27) {
96 return 14;
97 }
98 customUniforms.append({QStringLiteral("custom_knob"), 0.0, 2.0, 0.1, 1.0, 27});
99 if (!acmx2::write_custom_uniforms(root, customUniforms, error)) {
100 std::cerr << error.toStdString() << '\n';
101 return 15;
102 }
103 QJsonObject writtenUniforms = read_manifest(manifestPath).value(QStringLiteral("custom_uniforms")).toObject();
104 if (writtenUniforms.value(QStringLiteral("custom_knob")).toObject().value(QStringLiteral("slot")).toInt(-1) != 27) {
105 return 16;
106 }
107
108 customUniforms.removeLast();
109 if (!acmx2::write_custom_uniforms(root, customUniforms, error) || read_manifest(manifestPath).value(QStringLiteral("custom_uniforms")).toObject().contains(QStringLiteral("custom_knob"))) {
110 return 17;
111 }
112
113 while (customUniforms.size() < 65) {
114 const int slot = customUniforms.size();
115 customUniforms.append({QStringLiteral("extra_%1").arg(slot), 0.0, 1.0, 0.01, 0.0, slot});
116 }
117 if (acmx2::write_custom_uniforms(root, customUniforms, error) || !error.contains(QStringLiteral("at most 64"))) {
118 return 18;
119 }
120
121 QTemporaryDir runtimeDirectory;
122 if (!runtimeDirectory.isValid())
123 return 19;
124 QJsonObject runtimeManifest = read_manifest(manifestPath);
125 QJsonObject runtimeUniforms = runtimeManifest.value(QStringLiteral("custom_uniforms")).toObject();
126 QJsonObject runtimeSlider = runtimeUniforms.value(QStringLiteral("slider1")).toObject();
127 runtimeSlider.insert(QStringLiteral("value"), 0.75000000000001);
128 runtimeUniforms.insert(QStringLiteral("slider1"), runtimeSlider);
129 runtimeManifest.insert(QStringLiteral("custom_uniforms"), runtimeUniforms);
130 if (!write_file(QDir(runtimeDirectory.path()).filePath(QStringLiteral("library.json")), QJsonDocument(runtimeManifest).toJson(QJsonDocument::Indented))) {
131 return 20;
132 }
133 bool metadataMatches = false;
134 if (!acmx2::custom_uniform_metadata_matches(root, runtimeDirectory.path(), metadataMatches, error) || !metadataMatches) {
135 return 21;
136 }
137 runtimeSlider.insert(QStringLiteral("value"), 0.8);
138 runtimeUniforms.insert(QStringLiteral("slider1"), runtimeSlider);
139 runtimeManifest.insert(QStringLiteral("custom_uniforms"), runtimeUniforms);
140 if (!write_file(QDir(runtimeDirectory.path()).filePath(QStringLiteral("library.json")), QJsonDocument(runtimeManifest).toJson(QJsonDocument::Indented)) || !acmx2::custom_uniform_metadata_matches(root, runtimeDirectory.path(), metadataMatches, error) || metadataMatches) {
141 return 22;
142 }
143 return 0;
144}
int main(int argc, char **argv)
Application entry point.
bool custom_uniform_metadata_matches(const QString &leftDirectory, const QString &rightDirectory, bool &matches, QString &error)
Compare two manifests' custom-uniform ABI and numeric metadata.
bool create_acmxvk_source_manifest_for_shaders(const QString &rootDirectory, const QStringList &shaderFiles, const QString &outputPath, AcmxvkSourceManifestResult &result, QString &error)
Generate a source manifest from an explicit subset of files below root.
bool load_custom_uniforms(const QString &directory, QList< CustomUniformDefinition > &uniforms, QString &error)
Load custom float-uniform controls from library.json.
bool create_acmxvk_source_manifest(const QString &rootDirectory, const QString &outputPath, AcmxvkSourceManifestResult &result, QString &error)
Scan an ACMXVK source tree and atomically generate its library.json.
bool remove_shader_manifest_entry(const QString &directory, const QString &shader, QString &error)
Remove one shader from the preferred manifest, without deleting its file.
bool load_shader_manifest(const QString &directory, QStringList &shaders, QString &error)
Load shader filenames from the preferred manifest in a directory.
bool write_custom_uniforms(const QString &directory, const QList< CustomUniformDefinition > &uniforms, QString &error)
Rewrite custom float-uniform controls while preserving all other JSON fields.
bool write_file(const QString &path, const QByteArray &contents)
Optional JSON and legacy text shader-library manifests.