summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorLaszlo Agocs <laszlo.agocs@qt.io>2019-04-29 11:56:27 +0200
committerLaszlo Agocs <laszlo.agocs@qt.io>2019-05-06 08:25:17 +0000
commit7fc3df67705ac4d3ca56a585a3a7a79b94ff12e6 (patch)
tree1ef190987fc7af57f850c80004d530c32877b75b /tools
parent0fde097e31e908b18db68f05e2122c5280d36304 (diff)
Add support for -D in qsb and preamble in QShaderBaker
Allow inserting a user provided string. glslang takes care of heavy lifting. For qsb this means compile time #define statements can now be generated by passing -DSOMETHING and -DSOMETHING=123 on the command line. Change-Id: Iddf276c3fa91e21780530aa2f54719325f404ba6 Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
Diffstat (limited to 'tools')
-rw-r--r--tools/qsb/qsb.cpp27
1 files changed, 23 insertions, 4 deletions
diff --git a/tools/qsb/qsb.cpp b/tools/qsb/qsb.cpp
index 66435c5..ea143f9 100644
--- a/tools/qsb/qsb.cpp
+++ b/tools/qsb/qsb.cpp
@@ -238,25 +238,27 @@ int main(int argc, char **argv)
cmdLineParser.addOption(batchableOption);
QCommandLineOption glslOption({ "g", "glsl" },
QObject::tr("Comma separated list of GLSL versions to generate. (for example, \"100 es,120,330\")"),
- QObject::tr("glsl"));
+ QObject::tr("versions"));
cmdLineParser.addOption(glslOption);
QCommandLineOption hlslOption({ "l", "hlsl" },
QObject::tr("Comma separated list of HLSL (Shader Model) versions to generate. F.ex. 50 is 5.0, 51 is 5.1."),
- QObject::tr("hlsl"));
+ QObject::tr("versions"));
cmdLineParser.addOption(hlslOption);
QCommandLineOption mslOption({ "m", "msl" },
QObject::tr("Comma separated list of Metal Shading Language versions to generate. F.ex. 12 is 1.2, 20 is 2.0."),
- QObject::tr("msl"));
+ QObject::tr("versions"));
cmdLineParser.addOption(mslOption);
QCommandLineOption outputOption({ "o", "output" },
QObject::tr("Output file for the baked shader pack."),
- QObject::tr("output"));
+ QObject::tr("filename"));
cmdLineParser.addOption(outputOption);
QCommandLineOption fxcOption({ "c", "fxc" }, QObject::tr("In combination with --hlsl invokes fxc to store DXBC instead of HLSL."));
cmdLineParser.addOption(fxcOption);
QCommandLineOption mtllibOption({ "t", "metallib" },
QObject::tr("In combination with --msl builds a Metal library with xcrun metal(lib) and stores that instead of the source."));
cmdLineParser.addOption(mtllibOption);
+ QCommandLineOption defineOption({ "D", "define" }, QObject::tr("Define macro"), QObject::tr("name[=value]"));
+ cmdLineParser.addOption(defineOption);
QCommandLineOption dumpOption({ "d", "dump" }, QObject::tr("Switches to dump mode. Input file is expected to be a baked shader pack."));
cmdLineParser.addOption(dumpOption);
@@ -340,6 +342,23 @@ int main(int argc, char **argv)
baker.setGeneratedShaders(genShaders);
+ if (cmdLineParser.isSet(defineOption)) {
+ QByteArray preamble;
+ const QStringList defines = cmdLineParser.values(defineOption);
+ for (const QString &def : defines) {
+ const QStringList defs = def.split(QLatin1Char('='), QString::SkipEmptyParts);
+ if (!defs.isEmpty()) {
+ preamble.append("#define");
+ for (const QString &s : defs) {
+ preamble.append(' ');
+ preamble.append(s.toUtf8());
+ }
+ preamble.append('\n');
+ }
+ }
+ baker.setPreamble(preamble);
+ }
+
QRhiShader bs = baker.bake();
if (!bs.isValid()) {
qWarning("Shader baking failed: %s", qPrintable(baker.errorMessage()));