summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaszlo Agocs <laszlo.agocs@qt.io>2019-08-10 21:01:06 +0200
committerLaszlo Agocs <laszlo.agocs@qt.io>2019-08-12 08:18:23 +0000
commit9a82c7f6e941698d351c553b2be0fe0a36921e36 (patch)
tree9701060e764c91367026c1ff4d74b93465423435
parent5ca17a8ea4c58860686eab3128e4fd580784284b (diff)
Make the _qt_order input location configurable
Change-Id: Id746ed3b6eefa7d4de3bff663c61c57a35052d1a Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
-rw-r--r--src/shadertools/qshaderbaker.cpp13
-rw-r--r--src/shadertools/qshaderbaker.h1
-rw-r--r--src/shadertools/qshaderbatchablerewriter.cpp8
-rw-r--r--src/shadertools/qshaderbatchablerewriter_p.h2
-rw-r--r--src/shadertools/qspirvcompiler.cpp8
-rw-r--r--src/shadertools/qspirvcompiler_p.h1
-rw-r--r--tools/qsb/qsb.cpp9
7 files changed, 36 insertions, 6 deletions
diff --git a/src/shadertools/qshaderbaker.cpp b/src/shadertools/qshaderbaker.cpp
index 11c3699..df30436 100644
--- a/src/shadertools/qshaderbaker.cpp
+++ b/src/shadertools/qshaderbaker.cpp
@@ -151,6 +151,7 @@ struct QShaderBakerPrivate
QVector<QShaderBaker::GeneratedShader> reqVersions;
QVector<QShader::Variant> variants;
QByteArray preamble;
+ int batchLoc = 7;
QSpirvCompiler compiler;
QString errorMessage;
};
@@ -313,6 +314,17 @@ void QShaderBaker::setPreamble(const QByteArray &preamble)
}
/*!
+ When generating a QShader::BatchableVertexShader variant, \a location
+ specifies the input location for the inserted vertex input. The value is by
+ default 7 and needs to be overridden only if the vertex shader already uses
+ input location 7.
+ */
+void QShaderBaker::setBatchableVertexShaderExtraInputLocation(int location)
+{
+ d->batchLoc = location;
+}
+
+/*!
Runs the compilation and translation process.
\return a QShader instance. To check if the process was successful,
@@ -347,6 +359,7 @@ QShader QShaderBaker::bake()
QByteArray batchableSpirv;
if (d->stage == QShader::VertexStage && d->variants.contains(QShader::BatchableVertexShader)) {
d->compiler.setFlags(QSpirvCompiler::RewriteToMakeBatchableForSG);
+ d->compiler.setSGBatchingVertexInputLocation(d->batchLoc);
batchableSpirv = d->compiler.compileToSpirv();
if (batchableSpirv.isEmpty()) {
d->errorMessage = d->compiler.errorMessage();
diff --git a/src/shadertools/qshaderbaker.h b/src/shadertools/qshaderbaker.h
index edac5fb..08a525c 100644
--- a/src/shadertools/qshaderbaker.h
+++ b/src/shadertools/qshaderbaker.h
@@ -65,6 +65,7 @@ public:
void setGeneratedShaderVariants(const QVector<QShader::Variant> &v);
void setPreamble(const QByteArray &preamble);
+ void setBatchableVertexShaderExtraInputLocation(int location);
QShader bake();
diff --git a/src/shadertools/qshaderbatchablerewriter.cpp b/src/shadertools/qshaderbatchablerewriter.cpp
index 72b369f..260a1dc 100644
--- a/src/shadertools/qshaderbatchablerewriter.cpp
+++ b/src/shadertools/qshaderbatchablerewriter.cpp
@@ -41,7 +41,7 @@
// This is a slightly modified version of qsgshaderrewriter.cpp from
// qtdeclarative/src/quick/scenegraph/coreapi. Here we insert an extra vertex
-// attribute (_qt_order) at location 7.
+// input (_qt_order) at the specified input location.
QT_BEGIN_NAMESPACE
@@ -164,7 +164,7 @@ Tokenizer::Token Tokenizer::next()
return Token_EOF;
}
-QByteArray addZAdjustment(const QByteArray &input)
+QByteArray addZAdjustment(const QByteArray &input, int vertexInputLocation)
{
Tokenizer tok;
tok.initialize(input);
@@ -188,7 +188,9 @@ QByteArray addZAdjustment(const QByteArray &input)
result.reserve(1024);
result += QByteArray::fromRawData(input.constData(), voidPos - input.constData());
- result += QByteArrayLiteral("layout(location = 7) in float _qt_order;\n");
+ result += QByteArrayLiteral("layout(location = ");
+ result += QByteArray::number(vertexInputLocation);
+ result += QByteArrayLiteral(") in float _qt_order;\n");
// Find first brace '{'
while (t != Tokenizer::Token_EOF && t != Tokenizer::Token_OpenBrace) t = tok.next();
diff --git a/src/shadertools/qshaderbatchablerewriter_p.h b/src/shadertools/qshaderbatchablerewriter_p.h
index 3ee8eca..b462cbb 100644
--- a/src/shadertools/qshaderbatchablerewriter_p.h
+++ b/src/shadertools/qshaderbatchablerewriter_p.h
@@ -56,7 +56,7 @@
QT_BEGIN_NAMESPACE
namespace QShaderBatchableRewriter {
-QByteArray addZAdjustment(const QByteArray &input);
+QByteArray addZAdjustment(const QByteArray &input, int vertexInputLocation);
}
QT_END_NAMESPACE
diff --git a/src/shadertools/qspirvcompiler.cpp b/src/shadertools/qspirvcompiler.cpp
index 0496c3a..e8f341e 100644
--- a/src/shadertools/qspirvcompiler.cpp
+++ b/src/shadertools/qspirvcompiler.cpp
@@ -163,6 +163,7 @@ struct QSpirvCompilerPrivate
EShLanguage stage = EShLangVertex;
QSpirvCompiler::Flags flags = 0;
QByteArray preamble;
+ int batchAttrLoc = 7;
QByteArray spirv;
QString log;
};
@@ -385,10 +386,15 @@ void QSpirvCompiler::setPreamble(const QByteArray &preamble)
d->preamble = preamble;
}
+void QSpirvCompiler::setSGBatchingVertexInputLocation(int location)
+{
+ d->batchAttrLoc = location;
+}
+
QByteArray QSpirvCompiler::compileToSpirv()
{
if (d->stage == EShLangVertex && d->flags.testFlag(RewriteToMakeBatchableForSG) && d->batchableSource.isEmpty())
- d->batchableSource = QShaderBatchableRewriter::addZAdjustment(d->source);
+ d->batchableSource = QShaderBatchableRewriter::addZAdjustment(d->source, d->batchAttrLoc);
return d->compile() ? d->spirv : QByteArray();
}
diff --git a/src/shadertools/qspirvcompiler_p.h b/src/shadertools/qspirvcompiler_p.h
index 4843f5d..63b5697 100644
--- a/src/shadertools/qspirvcompiler_p.h
+++ b/src/shadertools/qspirvcompiler_p.h
@@ -74,6 +74,7 @@ public:
void setSourceString(const QByteArray &sourceString, QShader::Stage stage, const QString &fileName = QString());
void setFlags(Flags flags);
void setPreamble(const QByteArray &preamble);
+ void setSGBatchingVertexInputLocation(int location);
QByteArray compileToSpirv();
QString errorMessage() const;
diff --git a/tools/qsb/qsb.cpp b/tools/qsb/qsb.cpp
index 28660a4..1288c94 100644
--- a/tools/qsb/qsb.cpp
+++ b/tools/qsb/qsb.cpp
@@ -292,6 +292,10 @@ int main(int argc, char **argv)
cmdLineParser.addPositionalArgument(QLatin1String("file"), QObject::tr("Vulkan GLSL source file to compile"), QObject::tr("file"));
QCommandLineOption batchableOption({ "b", "batchable" }, QObject::tr("Also generates rewritten vertex shader for Qt Quick scene graph batching."));
cmdLineParser.addOption(batchableOption);
+ QCommandLineOption batchLocOption("zorder-loc",
+ QObject::tr("The extra vertex input location when rewriting for batching. Defaults to 7."),
+ QObject::tr("location"));
+ cmdLineParser.addOption(batchLocOption);
QCommandLineOption glslOption({ "g", "glsl" },
QObject::tr("Comma separated list of GLSL versions to generate. (for example, \"100 es,120,330\")"),
QObject::tr("versions"));
@@ -358,8 +362,11 @@ int main(int argc, char **argv)
QVector<QShader::Variant> variants;
variants << QShader::StandardShader;
- if (cmdLineParser.isSet(batchableOption))
+ if (cmdLineParser.isSet(batchableOption)) {
variants << QShader::BatchableVertexShader;
+ if (cmdLineParser.isSet(batchLocOption))
+ baker.setBatchableVertexShaderExtraInputLocation(cmdLineParser.value(batchLocOption).toInt());
+ }
baker.setGeneratedShaderVariants(variants);