2022-05-10 10:06:48 +00:00
|
|
|
// Copyright (C) 2021 The Qt Company Ltd.
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2019-03-22 08:55:03 +00:00
|
|
|
|
2020-11-26 16:31:50 +00:00
|
|
|
#include <QTest>
|
2019-03-22 08:55:03 +00:00
|
|
|
#include <QFile>
|
2020-11-26 16:31:50 +00:00
|
|
|
#include <QBuffer>
|
|
|
|
|
2019-03-22 08:55:03 +00:00
|
|
|
#include <QtGui/private/qshaderdescription_p_p.h>
|
|
|
|
#include <QtGui/private/qshader_p_p.h>
|
|
|
|
|
|
|
|
class tst_QShader : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
private slots:
|
2020-05-01 13:07:12 +00:00
|
|
|
void serializeDeserialize();
|
2019-03-22 08:55:03 +00:00
|
|
|
void simpleCompileCheckResults();
|
|
|
|
void genVariants();
|
|
|
|
void shaderDescImplicitSharing();
|
|
|
|
void bakedShaderImplicitSharing();
|
2022-06-10 10:09:11 +00:00
|
|
|
void sortedKeys();
|
2019-10-28 15:37:57 +00:00
|
|
|
void mslResourceMapping();
|
|
|
|
void serializeShaderDesc();
|
2020-01-12 16:33:31 +00:00
|
|
|
void comparison();
|
|
|
|
void loadV4();
|
2021-01-11 14:11:16 +00:00
|
|
|
void manualShaderPackCreation();
|
rhi: Enable exposing separate image and sampler objects from the shader
Adds the following in a QShader/QShaderDescription:
- a list of separate images
- a list of separate samplers
- a list of "combined_sampler_uniform_name" -> [
separate_texture_binding, separate_sampler_binding ] mappings
(relevant for GLSL only)
On the QShader (and qsb/QShaderBaker) level not having separate image
(texture) and sampler objects exposed in the reflection info is not
entirely future proof. Right now we benefit strongly from the fact
that Vulkan/SPIR-V supports both combined and separate
images/samplers, while for HLSL and MSL SPIRV-Cross translates
combined image samplers to separate texture and sampler objects, but
it is not given that relying on combined image samplers will always be
possible in the long run; it is mostly a legacy OpenGL thing that just
happens to be supported in Vulkan/SPIR-V due to some benefits with
certain implementations/hw, but is not something present in any newer
APIs.
In addition, before this patch, attempting to run a shader with
separate textures and samplers through qsb will just fail for GLSL,
even though SPIRV-Cross does have the ability to generate a "fake"
combined sampler for each separate texture+sampler combination. Take
this into use. This also involves generating and exposing a
combined_name->[separate_texture_binding,separate_sampler_binding]
mapping table for GLSL, not unlike we have the native binding map for
HLSL and MSL. A user (such as, the GL backend of QRhi) would then use
this table to recognize what user-provided texture+sampler binding
point numbers correspond to which auto-generated sampler2Ds in the GL
program.
Take the following example:
layout(binding = 1) uniform texture2D sepTex;
layout(binding = 2) uniform sampler sepSampler;
layout(binding = 3) uniform sampler sepSampler2;
Inn the reflection info (QShaderDescription) this (assuming a
corresponding qtshadertools patch in place) now gives one entry in
separateImages() and two in separateSamplers(). Assuming sepTex is
used both with sepSampler and sepSampler2, the GLSL output and mapping
table from QShaderBaker will have two auto-generated sampler2Ds (and
no 'texture2D' or 'sampler').
One immediate benefit is that it is now possible to create a shader
that relies only on separate images and samplers, feed it into qsb,
generate all the possible targets, and then also feed the SPIR-V
binary into a tool or library such as Tint (e.g. to generate WGSL)
that canot deal with combined image samplers.
Change-Id: I9b19847ea5854837b45d3a23edc788c48502aa15
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
2021-12-18 21:21:31 +00:00
|
|
|
void loadV6WithSeparateImagesAndSamplers();
|
2022-08-18 10:43:23 +00:00
|
|
|
void loadV7();
|
2022-12-07 03:52:59 +00:00
|
|
|
void loadV8();
|
2019-03-22 08:55:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static QShader getShader(const QString &name)
|
|
|
|
{
|
|
|
|
QFile f(name);
|
|
|
|
if (f.open(QIODevice::ReadOnly))
|
|
|
|
return QShader::fromSerialized(f.readAll());
|
|
|
|
|
|
|
|
return QShader();
|
|
|
|
}
|
|
|
|
|
2020-05-01 13:07:12 +00:00
|
|
|
void tst_QShader::serializeDeserialize()
|
|
|
|
{
|
|
|
|
QShader s = getShader(QLatin1String(":/data/texture_all_v4.frag.qsb"));
|
|
|
|
QVERIFY(s.isValid());
|
|
|
|
|
|
|
|
QByteArray data = s.serialized();
|
|
|
|
QVERIFY(!data.isEmpty());
|
|
|
|
|
|
|
|
QShader s2;
|
|
|
|
QVERIFY(!s2.isValid());
|
|
|
|
QVERIFY(s != s2);
|
|
|
|
s2 = QShader::fromSerialized(data);
|
|
|
|
QVERIFY(s2.isValid());
|
|
|
|
QCOMPARE(s, s2);
|
|
|
|
}
|
|
|
|
|
2019-03-22 08:55:03 +00:00
|
|
|
void tst_QShader::simpleCompileCheckResults()
|
|
|
|
{
|
2020-07-29 15:59:55 +00:00
|
|
|
QShader s = getShader(QLatin1String(":/data/color_spirv_v5.vert.qsb"));
|
2019-03-22 08:55:03 +00:00
|
|
|
QVERIFY(s.isValid());
|
2020-07-29 15:59:55 +00:00
|
|
|
QCOMPARE(QShaderPrivate::get(&s)->qsbVersion, 5);
|
Port from container.count()/length() to size()
This is semantic patch using ClangTidyTransformator:
auto QtContainerClass = expr(hasType(namedDecl(hasAnyName(<classes>)))).bind(o)
makeRule(cxxMemberCallExpr(on(QtContainerClass),
callee(cxxMethodDecl(hasAnyName({"count", "length"),
parameterCountIs(0))))),
changeTo(cat(access(o, cat("size"), "()"))),
cat("use 'size()' instead of 'count()/length()'"))
a.k.a qt-port-to-std-compatible-api with config Scope: 'Container'.
<classes> are:
// sequential:
"QByteArray",
"QList",
"QQueue",
"QStack",
"QString",
"QVarLengthArray",
"QVector",
// associative:
"QHash",
"QMultiHash",
"QMap",
"QMultiMap",
"QSet",
// Qt has no QMultiSet
Change-Id: Ibe8837be96e8d30d1846881ecd65180c1bc459af
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2022-09-30 12:09:04 +00:00
|
|
|
QCOMPARE(s.availableShaders().size(), 1);
|
2019-03-22 08:55:03 +00:00
|
|
|
|
|
|
|
const QShaderCode shader = s.shader(QShaderKey(QShader::SpirvShader,
|
|
|
|
QShaderVersion(100)));
|
|
|
|
QVERIFY(!shader.shader().isEmpty());
|
|
|
|
QCOMPARE(shader.entryPoint(), QByteArrayLiteral("main"));
|
|
|
|
|
|
|
|
const QShaderDescription desc = s.description();
|
|
|
|
QVERIFY(desc.isValid());
|
Port from container.count()/length() to size()
This is semantic patch using ClangTidyTransformator:
auto QtContainerClass = expr(hasType(namedDecl(hasAnyName(<classes>)))).bind(o)
makeRule(cxxMemberCallExpr(on(QtContainerClass),
callee(cxxMethodDecl(hasAnyName({"count", "length"),
parameterCountIs(0))))),
changeTo(cat(access(o, cat("size"), "()"))),
cat("use 'size()' instead of 'count()/length()'"))
a.k.a qt-port-to-std-compatible-api with config Scope: 'Container'.
<classes> are:
// sequential:
"QByteArray",
"QList",
"QQueue",
"QStack",
"QString",
"QVarLengthArray",
"QVector",
// associative:
"QHash",
"QMultiHash",
"QMap",
"QMultiMap",
"QSet",
// Qt has no QMultiSet
Change-Id: Ibe8837be96e8d30d1846881ecd65180c1bc459af
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2022-09-30 12:09:04 +00:00
|
|
|
QCOMPARE(desc.inputVariables().size(), 2);
|
2019-03-22 08:55:03 +00:00
|
|
|
for (const QShaderDescription::InOutVariable &v : desc.inputVariables()) {
|
|
|
|
switch (v.location) {
|
|
|
|
case 0:
|
2020-05-27 10:34:29 +00:00
|
|
|
QCOMPARE(v.name, QByteArrayLiteral("position"));
|
2019-03-22 08:55:03 +00:00
|
|
|
QCOMPARE(v.type, QShaderDescription::Vec4);
|
|
|
|
break;
|
|
|
|
case 1:
|
2020-05-27 10:34:29 +00:00
|
|
|
QCOMPARE(v.name, QByteArrayLiteral("color"));
|
2019-03-22 08:55:03 +00:00
|
|
|
QCOMPARE(v.type, QShaderDescription::Vec3);
|
|
|
|
break;
|
|
|
|
default:
|
2021-06-11 12:38:24 +00:00
|
|
|
QFAIL(qPrintable(QStringLiteral("Bad location: %1").arg(v.location)));
|
2019-03-22 08:55:03 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
Port from container.count()/length() to size()
This is semantic patch using ClangTidyTransformator:
auto QtContainerClass = expr(hasType(namedDecl(hasAnyName(<classes>)))).bind(o)
makeRule(cxxMemberCallExpr(on(QtContainerClass),
callee(cxxMethodDecl(hasAnyName({"count", "length"),
parameterCountIs(0))))),
changeTo(cat(access(o, cat("size"), "()"))),
cat("use 'size()' instead of 'count()/length()'"))
a.k.a qt-port-to-std-compatible-api with config Scope: 'Container'.
<classes> are:
// sequential:
"QByteArray",
"QList",
"QQueue",
"QStack",
"QString",
"QVarLengthArray",
"QVector",
// associative:
"QHash",
"QMultiHash",
"QMap",
"QMultiMap",
"QSet",
// Qt has no QMultiSet
Change-Id: Ibe8837be96e8d30d1846881ecd65180c1bc459af
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2022-09-30 12:09:04 +00:00
|
|
|
QCOMPARE(desc.outputVariables().size(), 1);
|
2019-03-22 08:55:03 +00:00
|
|
|
for (const QShaderDescription::InOutVariable &v : desc.outputVariables()) {
|
|
|
|
switch (v.location) {
|
|
|
|
case 0:
|
2020-05-27 10:34:29 +00:00
|
|
|
QCOMPARE(v.name, QByteArrayLiteral("v_color"));
|
2019-03-22 08:55:03 +00:00
|
|
|
QCOMPARE(v.type, QShaderDescription::Vec3);
|
|
|
|
break;
|
|
|
|
default:
|
2021-06-11 12:38:24 +00:00
|
|
|
QFAIL(qPrintable(QStringLiteral("Bad location: %1").arg(v.location)));
|
2019-03-22 08:55:03 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
Port from container.count()/length() to size()
This is semantic patch using ClangTidyTransformator:
auto QtContainerClass = expr(hasType(namedDecl(hasAnyName(<classes>)))).bind(o)
makeRule(cxxMemberCallExpr(on(QtContainerClass),
callee(cxxMethodDecl(hasAnyName({"count", "length"),
parameterCountIs(0))))),
changeTo(cat(access(o, cat("size"), "()"))),
cat("use 'size()' instead of 'count()/length()'"))
a.k.a qt-port-to-std-compatible-api with config Scope: 'Container'.
<classes> are:
// sequential:
"QByteArray",
"QList",
"QQueue",
"QStack",
"QString",
"QVarLengthArray",
"QVector",
// associative:
"QHash",
"QMultiHash",
"QMap",
"QMultiMap",
"QSet",
// Qt has no QMultiSet
Change-Id: Ibe8837be96e8d30d1846881ecd65180c1bc459af
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2022-09-30 12:09:04 +00:00
|
|
|
QCOMPARE(desc.uniformBlocks().size(), 1);
|
2019-03-22 08:55:03 +00:00
|
|
|
const QShaderDescription::UniformBlock blk = desc.uniformBlocks().first();
|
2020-05-27 10:34:29 +00:00
|
|
|
QCOMPARE(blk.blockName, QByteArrayLiteral("buf"));
|
|
|
|
QCOMPARE(blk.structName, QByteArrayLiteral("ubuf"));
|
2019-03-22 08:55:03 +00:00
|
|
|
QCOMPARE(blk.size, 68);
|
|
|
|
QCOMPARE(blk.binding, 0);
|
|
|
|
QCOMPARE(blk.descriptorSet, 0);
|
Port from container.count()/length() to size()
This is semantic patch using ClangTidyTransformator:
auto QtContainerClass = expr(hasType(namedDecl(hasAnyName(<classes>)))).bind(o)
makeRule(cxxMemberCallExpr(on(QtContainerClass),
callee(cxxMethodDecl(hasAnyName({"count", "length"),
parameterCountIs(0))))),
changeTo(cat(access(o, cat("size"), "()"))),
cat("use 'size()' instead of 'count()/length()'"))
a.k.a qt-port-to-std-compatible-api with config Scope: 'Container'.
<classes> are:
// sequential:
"QByteArray",
"QList",
"QQueue",
"QStack",
"QString",
"QVarLengthArray",
"QVector",
// associative:
"QHash",
"QMultiHash",
"QMap",
"QMultiMap",
"QSet",
// Qt has no QMultiSet
Change-Id: Ibe8837be96e8d30d1846881ecd65180c1bc459af
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2022-09-30 12:09:04 +00:00
|
|
|
QCOMPARE(blk.members.size(), 2);
|
|
|
|
for (int i = 0; i < blk.members.size(); ++i) {
|
2019-03-22 08:55:03 +00:00
|
|
|
const QShaderDescription::BlockVariable v = blk.members[i];
|
|
|
|
switch (i) {
|
|
|
|
case 0:
|
|
|
|
QCOMPARE(v.offset, 0);
|
|
|
|
QCOMPARE(v.size, 64);
|
2020-05-27 10:34:29 +00:00
|
|
|
QCOMPARE(v.name, QByteArrayLiteral("mvp"));
|
2019-03-22 08:55:03 +00:00
|
|
|
QCOMPARE(v.type, QShaderDescription::Mat4);
|
|
|
|
QCOMPARE(v.matrixStride, 16);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
QCOMPARE(v.offset, 64);
|
|
|
|
QCOMPARE(v.size, 4);
|
2020-05-27 10:34:29 +00:00
|
|
|
QCOMPARE(v.name, QByteArrayLiteral("opacity"));
|
2019-03-22 08:55:03 +00:00
|
|
|
QCOMPARE(v.type, QShaderDescription::Float);
|
|
|
|
break;
|
|
|
|
default:
|
Port from container.count()/length() to size()
This is semantic patch using ClangTidyTransformator:
auto QtContainerClass = expr(hasType(namedDecl(hasAnyName(<classes>)))).bind(o)
makeRule(cxxMemberCallExpr(on(QtContainerClass),
callee(cxxMethodDecl(hasAnyName({"count", "length"),
parameterCountIs(0))))),
changeTo(cat(access(o, cat("size"), "()"))),
cat("use 'size()' instead of 'count()/length()'"))
a.k.a qt-port-to-std-compatible-api with config Scope: 'Container'.
<classes> are:
// sequential:
"QByteArray",
"QList",
"QQueue",
"QStack",
"QString",
"QVarLengthArray",
"QVector",
// associative:
"QHash",
"QMultiHash",
"QMap",
"QMultiMap",
"QSet",
// Qt has no QMultiSet
Change-Id: Ibe8837be96e8d30d1846881ecd65180c1bc459af
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2022-09-30 12:09:04 +00:00
|
|
|
QFAIL(qPrintable(QStringLiteral("Too many blocks: %1").arg(blk.members.size())));
|
2019-03-22 08:55:03 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QShader::genVariants()
|
|
|
|
{
|
2020-07-29 15:59:55 +00:00
|
|
|
QShader s = getShader(QLatin1String(":/data/color_all_v5.vert.qsb"));
|
2019-03-22 08:55:03 +00:00
|
|
|
// spirv, glsl 100, glsl 330, glsl 120, hlsl 50, msl 12
|
|
|
|
// + batchable variants
|
|
|
|
QVERIFY(s.isValid());
|
2020-07-29 15:59:55 +00:00
|
|
|
QCOMPARE(QShaderPrivate::get(&s)->qsbVersion, 5);
|
Port from container.count()/length() to size()
This is semantic patch using ClangTidyTransformator:
auto QtContainerClass = expr(hasType(namedDecl(hasAnyName(<classes>)))).bind(o)
makeRule(cxxMemberCallExpr(on(QtContainerClass),
callee(cxxMethodDecl(hasAnyName({"count", "length"),
parameterCountIs(0))))),
changeTo(cat(access(o, cat("size"), "()"))),
cat("use 'size()' instead of 'count()/length()'"))
a.k.a qt-port-to-std-compatible-api with config Scope: 'Container'.
<classes> are:
// sequential:
"QByteArray",
"QList",
"QQueue",
"QStack",
"QString",
"QVarLengthArray",
"QVector",
// associative:
"QHash",
"QMultiHash",
"QMap",
"QMultiMap",
"QSet",
// Qt has no QMultiSet
Change-Id: Ibe8837be96e8d30d1846881ecd65180c1bc459af
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2022-09-30 12:09:04 +00:00
|
|
|
QCOMPARE(s.availableShaders().size(), 2 * 6);
|
2019-03-22 08:55:03 +00:00
|
|
|
|
|
|
|
int batchableVariantCount = 0;
|
|
|
|
int batchableGlslVariantCount = 0;
|
|
|
|
for (const QShaderKey &key : s.availableShaders()) {
|
|
|
|
if (key.sourceVariant() == QShader::BatchableVertexShader) {
|
|
|
|
++batchableVariantCount;
|
|
|
|
if (key.source() == QShader::GlslShader) {
|
|
|
|
++batchableGlslVariantCount;
|
|
|
|
const QByteArray src = s.shader(key).shader();
|
|
|
|
QVERIFY(src.contains(QByteArrayLiteral("_qt_order * ")));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
QCOMPARE(batchableVariantCount, 6);
|
|
|
|
QCOMPARE(batchableGlslVariantCount, 3);
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QShader::shaderDescImplicitSharing()
|
|
|
|
{
|
2020-07-29 15:59:55 +00:00
|
|
|
QShader s = getShader(QLatin1String(":/data/color_spirv_v5.vert.qsb"));
|
2019-03-22 08:55:03 +00:00
|
|
|
QVERIFY(s.isValid());
|
2020-07-29 15:59:55 +00:00
|
|
|
QCOMPARE(QShaderPrivate::get(&s)->qsbVersion, 5);
|
Port from container.count()/length() to size()
This is semantic patch using ClangTidyTransformator:
auto QtContainerClass = expr(hasType(namedDecl(hasAnyName(<classes>)))).bind(o)
makeRule(cxxMemberCallExpr(on(QtContainerClass),
callee(cxxMethodDecl(hasAnyName({"count", "length"),
parameterCountIs(0))))),
changeTo(cat(access(o, cat("size"), "()"))),
cat("use 'size()' instead of 'count()/length()'"))
a.k.a qt-port-to-std-compatible-api with config Scope: 'Container'.
<classes> are:
// sequential:
"QByteArray",
"QList",
"QQueue",
"QStack",
"QString",
"QVarLengthArray",
"QVector",
// associative:
"QHash",
"QMultiHash",
"QMap",
"QMultiMap",
"QSet",
// Qt has no QMultiSet
Change-Id: Ibe8837be96e8d30d1846881ecd65180c1bc459af
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2022-09-30 12:09:04 +00:00
|
|
|
QCOMPARE(s.availableShaders().size(), 1);
|
2019-03-22 08:55:03 +00:00
|
|
|
QVERIFY(s.availableShaders().contains(QShaderKey(QShader::SpirvShader, QShaderVersion(100))));
|
|
|
|
|
|
|
|
QShaderDescription d0 = s.description();
|
|
|
|
QVERIFY(d0.isValid());
|
Port from container.count()/length() to size()
This is semantic patch using ClangTidyTransformator:
auto QtContainerClass = expr(hasType(namedDecl(hasAnyName(<classes>)))).bind(o)
makeRule(cxxMemberCallExpr(on(QtContainerClass),
callee(cxxMethodDecl(hasAnyName({"count", "length"),
parameterCountIs(0))))),
changeTo(cat(access(o, cat("size"), "()"))),
cat("use 'size()' instead of 'count()/length()'"))
a.k.a qt-port-to-std-compatible-api with config Scope: 'Container'.
<classes> are:
// sequential:
"QByteArray",
"QList",
"QQueue",
"QStack",
"QString",
"QVarLengthArray",
"QVector",
// associative:
"QHash",
"QMultiHash",
"QMap",
"QMultiMap",
"QSet",
// Qt has no QMultiSet
Change-Id: Ibe8837be96e8d30d1846881ecd65180c1bc459af
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2022-09-30 12:09:04 +00:00
|
|
|
QCOMPARE(d0.inputVariables().size(), 2);
|
|
|
|
QCOMPARE(d0.outputVariables().size(), 1);
|
|
|
|
QCOMPARE(d0.uniformBlocks().size(), 1);
|
2019-03-22 08:55:03 +00:00
|
|
|
|
|
|
|
QShaderDescription d1 = d0;
|
|
|
|
QVERIFY(QShaderDescriptionPrivate::get(&d0) == QShaderDescriptionPrivate::get(&d1));
|
Port from container.count()/length() to size()
This is semantic patch using ClangTidyTransformator:
auto QtContainerClass = expr(hasType(namedDecl(hasAnyName(<classes>)))).bind(o)
makeRule(cxxMemberCallExpr(on(QtContainerClass),
callee(cxxMethodDecl(hasAnyName({"count", "length"),
parameterCountIs(0))))),
changeTo(cat(access(o, cat("size"), "()"))),
cat("use 'size()' instead of 'count()/length()'"))
a.k.a qt-port-to-std-compatible-api with config Scope: 'Container'.
<classes> are:
// sequential:
"QByteArray",
"QList",
"QQueue",
"QStack",
"QString",
"QVarLengthArray",
"QVector",
// associative:
"QHash",
"QMultiHash",
"QMap",
"QMultiMap",
"QSet",
// Qt has no QMultiSet
Change-Id: Ibe8837be96e8d30d1846881ecd65180c1bc459af
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2022-09-30 12:09:04 +00:00
|
|
|
QCOMPARE(d0.inputVariables().size(), 2);
|
|
|
|
QCOMPARE(d0.outputVariables().size(), 1);
|
|
|
|
QCOMPARE(d0.uniformBlocks().size(), 1);
|
|
|
|
QCOMPARE(d1.inputVariables().size(), 2);
|
|
|
|
QCOMPARE(d1.outputVariables().size(), 1);
|
|
|
|
QCOMPARE(d1.uniformBlocks().size(), 1);
|
2019-10-28 15:37:57 +00:00
|
|
|
QCOMPARE(d0, d1);
|
2019-03-22 08:55:03 +00:00
|
|
|
|
|
|
|
d1.detach();
|
|
|
|
QVERIFY(QShaderDescriptionPrivate::get(&d0) != QShaderDescriptionPrivate::get(&d1));
|
Port from container.count()/length() to size()
This is semantic patch using ClangTidyTransformator:
auto QtContainerClass = expr(hasType(namedDecl(hasAnyName(<classes>)))).bind(o)
makeRule(cxxMemberCallExpr(on(QtContainerClass),
callee(cxxMethodDecl(hasAnyName({"count", "length"),
parameterCountIs(0))))),
changeTo(cat(access(o, cat("size"), "()"))),
cat("use 'size()' instead of 'count()/length()'"))
a.k.a qt-port-to-std-compatible-api with config Scope: 'Container'.
<classes> are:
// sequential:
"QByteArray",
"QList",
"QQueue",
"QStack",
"QString",
"QVarLengthArray",
"QVector",
// associative:
"QHash",
"QMultiHash",
"QMap",
"QMultiMap",
"QSet",
// Qt has no QMultiSet
Change-Id: Ibe8837be96e8d30d1846881ecd65180c1bc459af
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2022-09-30 12:09:04 +00:00
|
|
|
QCOMPARE(d0.inputVariables().size(), 2);
|
|
|
|
QCOMPARE(d0.outputVariables().size(), 1);
|
|
|
|
QCOMPARE(d0.uniformBlocks().size(), 1);
|
|
|
|
QCOMPARE(d1.inputVariables().size(), 2);
|
|
|
|
QCOMPARE(d1.outputVariables().size(), 1);
|
|
|
|
QCOMPARE(d1.uniformBlocks().size(), 1);
|
2019-10-28 15:37:57 +00:00
|
|
|
QCOMPARE(d0, d1);
|
|
|
|
|
|
|
|
d1 = QShaderDescription();
|
|
|
|
QVERIFY(d0 != d1);
|
2019-03-22 08:55:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QShader::bakedShaderImplicitSharing()
|
|
|
|
{
|
2020-07-29 15:59:55 +00:00
|
|
|
QShader s0 = getShader(QLatin1String(":/data/color_spirv_v5.vert.qsb"));
|
2019-03-22 08:55:03 +00:00
|
|
|
QVERIFY(s0.isValid());
|
2020-07-29 15:59:55 +00:00
|
|
|
QCOMPARE(QShaderPrivate::get(&s0)->qsbVersion, 5);
|
Port from container.count()/length() to size()
This is semantic patch using ClangTidyTransformator:
auto QtContainerClass = expr(hasType(namedDecl(hasAnyName(<classes>)))).bind(o)
makeRule(cxxMemberCallExpr(on(QtContainerClass),
callee(cxxMethodDecl(hasAnyName({"count", "length"),
parameterCountIs(0))))),
changeTo(cat(access(o, cat("size"), "()"))),
cat("use 'size()' instead of 'count()/length()'"))
a.k.a qt-port-to-std-compatible-api with config Scope: 'Container'.
<classes> are:
// sequential:
"QByteArray",
"QList",
"QQueue",
"QStack",
"QString",
"QVarLengthArray",
"QVector",
// associative:
"QHash",
"QMultiHash",
"QMap",
"QMultiMap",
"QSet",
// Qt has no QMultiSet
Change-Id: Ibe8837be96e8d30d1846881ecd65180c1bc459af
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2022-09-30 12:09:04 +00:00
|
|
|
QCOMPARE(s0.availableShaders().size(), 1);
|
2019-03-22 08:55:03 +00:00
|
|
|
QVERIFY(s0.availableShaders().contains(QShaderKey(QShader::SpirvShader, QShaderVersion(100))));
|
|
|
|
|
|
|
|
{
|
|
|
|
QShader s1 = s0;
|
|
|
|
QVERIFY(QShaderPrivate::get(&s0) == QShaderPrivate::get(&s1));
|
Port from container.count()/length() to size()
This is semantic patch using ClangTidyTransformator:
auto QtContainerClass = expr(hasType(namedDecl(hasAnyName(<classes>)))).bind(o)
makeRule(cxxMemberCallExpr(on(QtContainerClass),
callee(cxxMethodDecl(hasAnyName({"count", "length"),
parameterCountIs(0))))),
changeTo(cat(access(o, cat("size"), "()"))),
cat("use 'size()' instead of 'count()/length()'"))
a.k.a qt-port-to-std-compatible-api with config Scope: 'Container'.
<classes> are:
// sequential:
"QByteArray",
"QList",
"QQueue",
"QStack",
"QString",
"QVarLengthArray",
"QVector",
// associative:
"QHash",
"QMultiHash",
"QMap",
"QMultiMap",
"QSet",
// Qt has no QMultiSet
Change-Id: Ibe8837be96e8d30d1846881ecd65180c1bc459af
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2022-09-30 12:09:04 +00:00
|
|
|
QCOMPARE(s0.availableShaders().size(), 1);
|
2019-03-22 08:55:03 +00:00
|
|
|
QVERIFY(s0.availableShaders().contains(QShaderKey(QShader::SpirvShader, QShaderVersion(100))));
|
Port from container.count()/length() to size()
This is semantic patch using ClangTidyTransformator:
auto QtContainerClass = expr(hasType(namedDecl(hasAnyName(<classes>)))).bind(o)
makeRule(cxxMemberCallExpr(on(QtContainerClass),
callee(cxxMethodDecl(hasAnyName({"count", "length"),
parameterCountIs(0))))),
changeTo(cat(access(o, cat("size"), "()"))),
cat("use 'size()' instead of 'count()/length()'"))
a.k.a qt-port-to-std-compatible-api with config Scope: 'Container'.
<classes> are:
// sequential:
"QByteArray",
"QList",
"QQueue",
"QStack",
"QString",
"QVarLengthArray",
"QVector",
// associative:
"QHash",
"QMultiHash",
"QMap",
"QMultiMap",
"QSet",
// Qt has no QMultiSet
Change-Id: Ibe8837be96e8d30d1846881ecd65180c1bc459af
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2022-09-30 12:09:04 +00:00
|
|
|
QCOMPARE(s1.availableShaders().size(), 1);
|
2019-03-22 08:55:03 +00:00
|
|
|
QVERIFY(s1.availableShaders().contains(QShaderKey(QShader::SpirvShader, QShaderVersion(100))));
|
|
|
|
QCOMPARE(s0.stage(), s1.stage());
|
|
|
|
QCOMPARE(s0, s1);
|
|
|
|
|
|
|
|
s1.detach();
|
|
|
|
QVERIFY(QShaderPrivate::get(&s0) != QShaderPrivate::get(&s1));
|
Port from container.count()/length() to size()
This is semantic patch using ClangTidyTransformator:
auto QtContainerClass = expr(hasType(namedDecl(hasAnyName(<classes>)))).bind(o)
makeRule(cxxMemberCallExpr(on(QtContainerClass),
callee(cxxMethodDecl(hasAnyName({"count", "length"),
parameterCountIs(0))))),
changeTo(cat(access(o, cat("size"), "()"))),
cat("use 'size()' instead of 'count()/length()'"))
a.k.a qt-port-to-std-compatible-api with config Scope: 'Container'.
<classes> are:
// sequential:
"QByteArray",
"QList",
"QQueue",
"QStack",
"QString",
"QVarLengthArray",
"QVector",
// associative:
"QHash",
"QMultiHash",
"QMap",
"QMultiMap",
"QSet",
// Qt has no QMultiSet
Change-Id: Ibe8837be96e8d30d1846881ecd65180c1bc459af
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2022-09-30 12:09:04 +00:00
|
|
|
QCOMPARE(s0.availableShaders().size(), 1);
|
2019-03-22 08:55:03 +00:00
|
|
|
QVERIFY(s0.availableShaders().contains(QShaderKey(QShader::SpirvShader, QShaderVersion(100))));
|
Port from container.count()/length() to size()
This is semantic patch using ClangTidyTransformator:
auto QtContainerClass = expr(hasType(namedDecl(hasAnyName(<classes>)))).bind(o)
makeRule(cxxMemberCallExpr(on(QtContainerClass),
callee(cxxMethodDecl(hasAnyName({"count", "length"),
parameterCountIs(0))))),
changeTo(cat(access(o, cat("size"), "()"))),
cat("use 'size()' instead of 'count()/length()'"))
a.k.a qt-port-to-std-compatible-api with config Scope: 'Container'.
<classes> are:
// sequential:
"QByteArray",
"QList",
"QQueue",
"QStack",
"QString",
"QVarLengthArray",
"QVector",
// associative:
"QHash",
"QMultiHash",
"QMap",
"QMultiMap",
"QSet",
// Qt has no QMultiSet
Change-Id: Ibe8837be96e8d30d1846881ecd65180c1bc459af
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2022-09-30 12:09:04 +00:00
|
|
|
QCOMPARE(s1.availableShaders().size(), 1);
|
2019-03-22 08:55:03 +00:00
|
|
|
QVERIFY(s1.availableShaders().contains(QShaderKey(QShader::SpirvShader, QShaderVersion(100))));
|
|
|
|
QCOMPARE(s0.stage(), s1.stage());
|
|
|
|
QCOMPARE(s0, s1);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
QShader s1 = s0;
|
|
|
|
QVERIFY(QShaderPrivate::get(&s0) == QShaderPrivate::get(&s1));
|
|
|
|
QCOMPARE(s0.stage(), s1.stage());
|
|
|
|
|
|
|
|
s1.setStage(QShader::FragmentStage); // call a setter to trigger a detach
|
|
|
|
QVERIFY(QShaderPrivate::get(&s0) != QShaderPrivate::get(&s1));
|
Port from container.count()/length() to size()
This is semantic patch using ClangTidyTransformator:
auto QtContainerClass = expr(hasType(namedDecl(hasAnyName(<classes>)))).bind(o)
makeRule(cxxMemberCallExpr(on(QtContainerClass),
callee(cxxMethodDecl(hasAnyName({"count", "length"),
parameterCountIs(0))))),
changeTo(cat(access(o, cat("size"), "()"))),
cat("use 'size()' instead of 'count()/length()'"))
a.k.a qt-port-to-std-compatible-api with config Scope: 'Container'.
<classes> are:
// sequential:
"QByteArray",
"QList",
"QQueue",
"QStack",
"QString",
"QVarLengthArray",
"QVector",
// associative:
"QHash",
"QMultiHash",
"QMap",
"QMultiMap",
"QSet",
// Qt has no QMultiSet
Change-Id: Ibe8837be96e8d30d1846881ecd65180c1bc459af
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2022-09-30 12:09:04 +00:00
|
|
|
QCOMPARE(s0.availableShaders().size(), 1);
|
2019-03-22 08:55:03 +00:00
|
|
|
QVERIFY(s0.availableShaders().contains(QShaderKey(QShader::SpirvShader, QShaderVersion(100))));
|
Port from container.count()/length() to size()
This is semantic patch using ClangTidyTransformator:
auto QtContainerClass = expr(hasType(namedDecl(hasAnyName(<classes>)))).bind(o)
makeRule(cxxMemberCallExpr(on(QtContainerClass),
callee(cxxMethodDecl(hasAnyName({"count", "length"),
parameterCountIs(0))))),
changeTo(cat(access(o, cat("size"), "()"))),
cat("use 'size()' instead of 'count()/length()'"))
a.k.a qt-port-to-std-compatible-api with config Scope: 'Container'.
<classes> are:
// sequential:
"QByteArray",
"QList",
"QQueue",
"QStack",
"QString",
"QVarLengthArray",
"QVector",
// associative:
"QHash",
"QMultiHash",
"QMap",
"QMultiMap",
"QSet",
// Qt has no QMultiSet
Change-Id: Ibe8837be96e8d30d1846881ecd65180c1bc459af
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2022-09-30 12:09:04 +00:00
|
|
|
QCOMPARE(s1.availableShaders().size(), 1);
|
2019-03-22 08:55:03 +00:00
|
|
|
QVERIFY(s1.availableShaders().contains(QShaderKey(QShader::SpirvShader, QShaderVersion(100))));
|
|
|
|
QShaderDescription d0 = s0.description();
|
Port from container.count()/length() to size()
This is semantic patch using ClangTidyTransformator:
auto QtContainerClass = expr(hasType(namedDecl(hasAnyName(<classes>)))).bind(o)
makeRule(cxxMemberCallExpr(on(QtContainerClass),
callee(cxxMethodDecl(hasAnyName({"count", "length"),
parameterCountIs(0))))),
changeTo(cat(access(o, cat("size"), "()"))),
cat("use 'size()' instead of 'count()/length()'"))
a.k.a qt-port-to-std-compatible-api with config Scope: 'Container'.
<classes> are:
// sequential:
"QByteArray",
"QList",
"QQueue",
"QStack",
"QString",
"QVarLengthArray",
"QVector",
// associative:
"QHash",
"QMultiHash",
"QMap",
"QMultiMap",
"QSet",
// Qt has no QMultiSet
Change-Id: Ibe8837be96e8d30d1846881ecd65180c1bc459af
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2022-09-30 12:09:04 +00:00
|
|
|
QCOMPARE(d0.inputVariables().size(), 2);
|
|
|
|
QCOMPARE(d0.outputVariables().size(), 1);
|
|
|
|
QCOMPARE(d0.uniformBlocks().size(), 1);
|
2019-03-22 08:55:03 +00:00
|
|
|
QShaderDescription d1 = s1.description();
|
Port from container.count()/length() to size()
This is semantic patch using ClangTidyTransformator:
auto QtContainerClass = expr(hasType(namedDecl(hasAnyName(<classes>)))).bind(o)
makeRule(cxxMemberCallExpr(on(QtContainerClass),
callee(cxxMethodDecl(hasAnyName({"count", "length"),
parameterCountIs(0))))),
changeTo(cat(access(o, cat("size"), "()"))),
cat("use 'size()' instead of 'count()/length()'"))
a.k.a qt-port-to-std-compatible-api with config Scope: 'Container'.
<classes> are:
// sequential:
"QByteArray",
"QList",
"QQueue",
"QStack",
"QString",
"QVarLengthArray",
"QVector",
// associative:
"QHash",
"QMultiHash",
"QMap",
"QMultiMap",
"QSet",
// Qt has no QMultiSet
Change-Id: Ibe8837be96e8d30d1846881ecd65180c1bc459af
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2022-09-30 12:09:04 +00:00
|
|
|
QCOMPARE(d1.inputVariables().size(), 2);
|
|
|
|
QCOMPARE(d1.outputVariables().size(), 1);
|
|
|
|
QCOMPARE(d1.uniformBlocks().size(), 1);
|
2019-03-22 08:55:03 +00:00
|
|
|
QVERIFY(s0 != s1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-10 10:09:11 +00:00
|
|
|
void tst_QShader::sortedKeys()
|
|
|
|
{
|
|
|
|
QShader s = getShader(QLatin1String(":/data/texture_all_v4.frag.qsb"));
|
|
|
|
QVERIFY(s.isValid());
|
|
|
|
QList<QShaderKey> availableShaders = s.availableShaders();
|
Port from container.count()/length() to size()
This is semantic patch using ClangTidyTransformator:
auto QtContainerClass = expr(hasType(namedDecl(hasAnyName(<classes>)))).bind(o)
makeRule(cxxMemberCallExpr(on(QtContainerClass),
callee(cxxMethodDecl(hasAnyName({"count", "length"),
parameterCountIs(0))))),
changeTo(cat(access(o, cat("size"), "()"))),
cat("use 'size()' instead of 'count()/length()'"))
a.k.a qt-port-to-std-compatible-api with config Scope: 'Container'.
<classes> are:
// sequential:
"QByteArray",
"QList",
"QQueue",
"QStack",
"QString",
"QVarLengthArray",
"QVector",
// associative:
"QHash",
"QMultiHash",
"QMap",
"QMultiMap",
"QSet",
// Qt has no QMultiSet
Change-Id: Ibe8837be96e8d30d1846881ecd65180c1bc459af
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2022-09-30 12:09:04 +00:00
|
|
|
QCOMPARE(availableShaders.size(), 7);
|
2022-06-10 10:09:11 +00:00
|
|
|
std::sort(availableShaders.begin(), availableShaders.end());
|
|
|
|
QCOMPARE(availableShaders, s.availableShaders());
|
|
|
|
}
|
|
|
|
|
2019-10-28 15:37:57 +00:00
|
|
|
void tst_QShader::mslResourceMapping()
|
|
|
|
{
|
2020-07-29 15:59:55 +00:00
|
|
|
QShader s = getShader(QLatin1String(":/data/texture_all_v4.frag.qsb"));
|
2019-10-28 15:37:57 +00:00
|
|
|
QVERIFY(s.isValid());
|
2020-07-29 15:59:55 +00:00
|
|
|
QCOMPARE(QShaderPrivate::get(&s)->qsbVersion, 4);
|
2019-10-28 15:37:57 +00:00
|
|
|
|
2020-06-23 08:04:16 +00:00
|
|
|
const QList<QShaderKey> availableShaders = s.availableShaders();
|
Port from container.count()/length() to size()
This is semantic patch using ClangTidyTransformator:
auto QtContainerClass = expr(hasType(namedDecl(hasAnyName(<classes>)))).bind(o)
makeRule(cxxMemberCallExpr(on(QtContainerClass),
callee(cxxMethodDecl(hasAnyName({"count", "length"),
parameterCountIs(0))))),
changeTo(cat(access(o, cat("size"), "()"))),
cat("use 'size()' instead of 'count()/length()'"))
a.k.a qt-port-to-std-compatible-api with config Scope: 'Container'.
<classes> are:
// sequential:
"QByteArray",
"QList",
"QQueue",
"QStack",
"QString",
"QVarLengthArray",
"QVector",
// associative:
"QHash",
"QMultiHash",
"QMap",
"QMultiMap",
"QSet",
// Qt has no QMultiSet
Change-Id: Ibe8837be96e8d30d1846881ecd65180c1bc459af
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2022-09-30 12:09:04 +00:00
|
|
|
QCOMPARE(availableShaders.size(), 7);
|
2019-10-28 15:37:57 +00:00
|
|
|
QVERIFY(availableShaders.contains(QShaderKey(QShader::SpirvShader, QShaderVersion(100))));
|
|
|
|
QVERIFY(availableShaders.contains(QShaderKey(QShader::MslShader, QShaderVersion(12))));
|
|
|
|
QVERIFY(availableShaders.contains(QShaderKey(QShader::HlslShader, QShaderVersion(50))));
|
|
|
|
QVERIFY(availableShaders.contains(QShaderKey(QShader::GlslShader, QShaderVersion(100, QShaderVersion::GlslEs))));
|
|
|
|
QVERIFY(availableShaders.contains(QShaderKey(QShader::GlslShader, QShaderVersion(120))));
|
|
|
|
QVERIFY(availableShaders.contains(QShaderKey(QShader::GlslShader, QShaderVersion(150))));
|
|
|
|
QVERIFY(availableShaders.contains(QShaderKey(QShader::GlslShader, QShaderVersion(330))));
|
|
|
|
|
2021-12-21 15:04:30 +00:00
|
|
|
QShader::NativeResourceBindingMap resMap =
|
2019-10-28 15:37:57 +00:00
|
|
|
s.nativeResourceBindingMap(QShaderKey(QShader::GlslShader, QShaderVersion(330)));
|
2021-12-21 15:04:30 +00:00
|
|
|
QVERIFY(resMap.isEmpty());
|
2019-10-28 15:37:57 +00:00
|
|
|
|
|
|
|
// The Metal shader must come with a mapping table for binding points 0
|
|
|
|
// (uniform buffer) and 1 (combined image sampler mapped to a texture and
|
|
|
|
// sampler in the shader).
|
|
|
|
resMap = s.nativeResourceBindingMap(QShaderKey(QShader::MslShader, QShaderVersion(12)));
|
2021-12-21 15:04:30 +00:00
|
|
|
QVERIFY(!resMap.isEmpty());
|
2019-10-28 15:37:57 +00:00
|
|
|
|
Port from container::count() and length() to size() - V5
This is a semantic patch using ClangTidyTransformator as in
qtbase/df9d882d41b741fef7c5beeddb0abe9d904443d8, but extended to
handle typedefs and accesses through pointers, too:
const std::string o = "object";
auto hasTypeIgnoringPointer = [](auto type) { return anyOf(hasType(type), hasType(pointsTo(type))); };
auto derivedFromAnyOfClasses = [&](ArrayRef<StringRef> classes) {
auto exprOfDeclaredType = [&](auto decl) {
return expr(hasTypeIgnoringPointer(hasUnqualifiedDesugaredType(recordType(hasDeclaration(decl))))).bind(o);
};
return exprOfDeclaredType(cxxRecordDecl(isSameOrDerivedFrom(hasAnyName(classes))));
};
auto renameMethod = [&] (ArrayRef<StringRef> classes,
StringRef from, StringRef to) {
return makeRule(cxxMemberCallExpr(on(derivedFromAnyOfClasses(classes)),
callee(cxxMethodDecl(hasName(from), parameterCountIs(0)))),
changeTo(cat(access(o, cat(to)), "()")),
cat("use '", to, "' instead of '", from, "'"));
};
renameMethod(<classes>, "count", "size");
renameMethod(<classes>, "length", "size");
except that the on() matcher has been replaced by one that doesn't
ignoreParens().
a.k.a qt-port-to-std-compatible-api V5 with config Scope: 'Container'.
Added two NOLINTNEXTLINEs in tst_qbitarray and tst_qcontiguouscache,
to avoid porting calls that explicitly test count().
Change-Id: Icfb8808c2ff4a30187e9935a51cad26987451c22
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2022-09-30 12:09:04 +00:00
|
|
|
QCOMPARE(resMap.size(), 2);
|
2021-12-21 15:04:30 +00:00
|
|
|
QCOMPARE(resMap.value(0).first, 0); // mapped to native buffer index 0
|
|
|
|
QCOMPARE(resMap.value(1), qMakePair(0, 0)); // mapped to native texture index 0 and sampler index 0
|
2019-10-28 15:37:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QShader::serializeShaderDesc()
|
|
|
|
{
|
|
|
|
// default constructed QShaderDescription
|
|
|
|
{
|
|
|
|
QShaderDescription desc;
|
|
|
|
QVERIFY(!desc.isValid());
|
|
|
|
|
2020-01-12 16:33:31 +00:00
|
|
|
QByteArray data;
|
|
|
|
{
|
|
|
|
QBuffer buf(&data);
|
|
|
|
QDataStream ds(&buf);
|
|
|
|
QVERIFY(buf.open(QIODevice::WriteOnly));
|
2023-01-03 12:10:04 +00:00
|
|
|
desc.serialize(&ds, QShaderPrivate::QSB_VERSION);
|
2020-01-12 16:33:31 +00:00
|
|
|
}
|
2019-10-28 15:37:57 +00:00
|
|
|
QVERIFY(!data.isEmpty());
|
|
|
|
|
2020-01-12 16:33:31 +00:00
|
|
|
{
|
|
|
|
QBuffer buf(&data);
|
|
|
|
QDataStream ds(&buf);
|
|
|
|
QVERIFY(buf.open(QIODevice::ReadOnly));
|
2020-03-03 10:19:14 +00:00
|
|
|
QShaderDescription desc2 = QShaderDescription::deserialize(&ds, QShaderPrivate::QSB_VERSION);
|
2020-01-12 16:33:31 +00:00
|
|
|
QVERIFY(!desc2.isValid());
|
|
|
|
}
|
2019-10-28 15:37:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// a QShaderDescription with inputs, outputs, uniform block and combined image sampler
|
|
|
|
{
|
2020-01-12 16:33:31 +00:00
|
|
|
QShader s = getShader(QLatin1String(":/data/texture_all_v4.frag.qsb"));
|
2019-10-28 15:37:57 +00:00
|
|
|
QVERIFY(s.isValid());
|
|
|
|
const QShaderDescription desc = s.description();
|
|
|
|
QVERIFY(desc.isValid());
|
|
|
|
|
2020-01-12 16:33:31 +00:00
|
|
|
QByteArray data;
|
|
|
|
{
|
|
|
|
QBuffer buf(&data);
|
|
|
|
QDataStream ds(&buf);
|
|
|
|
QVERIFY(buf.open(QIODevice::WriteOnly));
|
2023-01-03 12:10:04 +00:00
|
|
|
desc.serialize(&ds, QShaderPrivate::QSB_VERSION);
|
2020-01-12 16:33:31 +00:00
|
|
|
}
|
2019-10-28 15:37:57 +00:00
|
|
|
QVERIFY(!data.isEmpty());
|
|
|
|
|
2020-01-13 15:45:28 +00:00
|
|
|
{
|
|
|
|
QShaderDescription desc2;
|
|
|
|
QVERIFY(!desc2.isValid());
|
|
|
|
QVERIFY(!(desc == desc2));
|
|
|
|
QVERIFY(desc != desc2);
|
|
|
|
}
|
2019-10-28 15:37:57 +00:00
|
|
|
|
2020-01-12 16:33:31 +00:00
|
|
|
{
|
|
|
|
QBuffer buf(&data);
|
|
|
|
QDataStream ds(&buf);
|
|
|
|
QVERIFY(buf.open(QIODevice::ReadOnly));
|
2020-03-03 10:19:14 +00:00
|
|
|
QShaderDescription desc2 = QShaderDescription::deserialize(&ds, QShaderPrivate::QSB_VERSION);
|
2020-01-12 16:33:31 +00:00
|
|
|
QVERIFY(desc2.isValid());
|
|
|
|
QCOMPARE(desc, desc2);
|
|
|
|
}
|
2019-10-28 15:37:57 +00:00
|
|
|
}
|
2020-01-12 16:33:31 +00:00
|
|
|
}
|
2019-10-28 15:37:57 +00:00
|
|
|
|
2020-01-12 16:33:31 +00:00
|
|
|
void tst_QShader::comparison()
|
|
|
|
{
|
2019-10-28 15:37:57 +00:00
|
|
|
// exercise QShader and QShaderDescription comparisons
|
|
|
|
{
|
2020-01-12 16:33:31 +00:00
|
|
|
QShader s1 = getShader(QLatin1String(":/data/texture_all_v4.frag.qsb"));
|
2019-10-28 15:37:57 +00:00
|
|
|
QVERIFY(s1.isValid());
|
2020-07-29 15:59:55 +00:00
|
|
|
QShader s2 = getShader(QLatin1String(":/data/color_all_v5.vert.qsb"));
|
2019-10-28 15:37:57 +00:00
|
|
|
QVERIFY(s2.isValid());
|
|
|
|
|
|
|
|
QVERIFY(s1.description().isValid());
|
|
|
|
QVERIFY(s2.description().isValid());
|
|
|
|
|
|
|
|
QVERIFY(s1 != s2);
|
|
|
|
QVERIFY(s1.description() != s2.description());
|
|
|
|
}
|
2020-01-12 16:33:31 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
QShader s1 = getShader(QLatin1String(":/data/texture_all_v4.frag.qsb"));
|
|
|
|
QVERIFY(s1.isValid());
|
|
|
|
QShader s2 = getShader(QLatin1String(":/data/texture_all_v4.frag.qsb"));
|
|
|
|
QVERIFY(s2.isValid());
|
|
|
|
|
|
|
|
QVERIFY(s1.description().isValid());
|
|
|
|
QVERIFY(s2.description().isValid());
|
|
|
|
|
|
|
|
QVERIFY(s1 == s2);
|
|
|
|
QVERIFY(s1.description() == s2.description());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QShader::loadV4()
|
|
|
|
{
|
|
|
|
// qsb version 4: QShaderDescription is serialized via QDataStream. Ensure the deserialized data is as expected.
|
|
|
|
QShader s = getShader(QLatin1String(":/data/texture_all_v4.frag.qsb"));
|
|
|
|
QVERIFY(s.isValid());
|
|
|
|
QCOMPARE(QShaderPrivate::get(&s)->qsbVersion, 4);
|
|
|
|
|
2020-06-23 08:04:16 +00:00
|
|
|
const QList<QShaderKey> availableShaders = s.availableShaders();
|
Port from container.count()/length() to size()
This is semantic patch using ClangTidyTransformator:
auto QtContainerClass = expr(hasType(namedDecl(hasAnyName(<classes>)))).bind(o)
makeRule(cxxMemberCallExpr(on(QtContainerClass),
callee(cxxMethodDecl(hasAnyName({"count", "length"),
parameterCountIs(0))))),
changeTo(cat(access(o, cat("size"), "()"))),
cat("use 'size()' instead of 'count()/length()'"))
a.k.a qt-port-to-std-compatible-api with config Scope: 'Container'.
<classes> are:
// sequential:
"QByteArray",
"QList",
"QQueue",
"QStack",
"QString",
"QVarLengthArray",
"QVector",
// associative:
"QHash",
"QMultiHash",
"QMap",
"QMultiMap",
"QSet",
// Qt has no QMultiSet
Change-Id: Ibe8837be96e8d30d1846881ecd65180c1bc459af
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2022-09-30 12:09:04 +00:00
|
|
|
QCOMPARE(availableShaders.size(), 7);
|
2020-01-12 16:33:31 +00:00
|
|
|
QVERIFY(availableShaders.contains(QShaderKey(QShader::SpirvShader, QShaderVersion(100))));
|
|
|
|
QVERIFY(availableShaders.contains(QShaderKey(QShader::MslShader, QShaderVersion(12))));
|
|
|
|
QVERIFY(availableShaders.contains(QShaderKey(QShader::HlslShader, QShaderVersion(50))));
|
|
|
|
QVERIFY(availableShaders.contains(QShaderKey(QShader::GlslShader, QShaderVersion(100, QShaderVersion::GlslEs))));
|
|
|
|
QVERIFY(availableShaders.contains(QShaderKey(QShader::GlslShader, QShaderVersion(120))));
|
|
|
|
QVERIFY(availableShaders.contains(QShaderKey(QShader::GlslShader, QShaderVersion(150))));
|
|
|
|
QVERIFY(availableShaders.contains(QShaderKey(QShader::GlslShader, QShaderVersion(330))));
|
|
|
|
|
|
|
|
const QShaderDescription desc = s.description();
|
|
|
|
QVERIFY(desc.isValid());
|
Port from container.count()/length() to size()
This is semantic patch using ClangTidyTransformator:
auto QtContainerClass = expr(hasType(namedDecl(hasAnyName(<classes>)))).bind(o)
makeRule(cxxMemberCallExpr(on(QtContainerClass),
callee(cxxMethodDecl(hasAnyName({"count", "length"),
parameterCountIs(0))))),
changeTo(cat(access(o, cat("size"), "()"))),
cat("use 'size()' instead of 'count()/length()'"))
a.k.a qt-port-to-std-compatible-api with config Scope: 'Container'.
<classes> are:
// sequential:
"QByteArray",
"QList",
"QQueue",
"QStack",
"QString",
"QVarLengthArray",
"QVector",
// associative:
"QHash",
"QMultiHash",
"QMap",
"QMultiMap",
"QSet",
// Qt has no QMultiSet
Change-Id: Ibe8837be96e8d30d1846881ecd65180c1bc459af
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2022-09-30 12:09:04 +00:00
|
|
|
QCOMPARE(desc.inputVariables().size(), 1);
|
2020-01-12 16:33:31 +00:00
|
|
|
for (const QShaderDescription::InOutVariable &v : desc.inputVariables()) {
|
|
|
|
switch (v.location) {
|
|
|
|
case 0:
|
2020-05-27 10:34:29 +00:00
|
|
|
QCOMPARE(v.name, QByteArrayLiteral("qt_TexCoord"));
|
2020-01-12 16:33:31 +00:00
|
|
|
QCOMPARE(v.type, QShaderDescription::Vec2);
|
|
|
|
break;
|
|
|
|
default:
|
2021-06-11 12:38:24 +00:00
|
|
|
QFAIL(qPrintable(QStringLiteral("Bad location: %1").arg(v.location)));
|
2020-01-12 16:33:31 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
Port from container.count()/length() to size()
This is semantic patch using ClangTidyTransformator:
auto QtContainerClass = expr(hasType(namedDecl(hasAnyName(<classes>)))).bind(o)
makeRule(cxxMemberCallExpr(on(QtContainerClass),
callee(cxxMethodDecl(hasAnyName({"count", "length"),
parameterCountIs(0))))),
changeTo(cat(access(o, cat("size"), "()"))),
cat("use 'size()' instead of 'count()/length()'"))
a.k.a qt-port-to-std-compatible-api with config Scope: 'Container'.
<classes> are:
// sequential:
"QByteArray",
"QList",
"QQueue",
"QStack",
"QString",
"QVarLengthArray",
"QVector",
// associative:
"QHash",
"QMultiHash",
"QMap",
"QMultiMap",
"QSet",
// Qt has no QMultiSet
Change-Id: Ibe8837be96e8d30d1846881ecd65180c1bc459af
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2022-09-30 12:09:04 +00:00
|
|
|
QCOMPARE(desc.outputVariables().size(), 1);
|
2020-01-12 16:33:31 +00:00
|
|
|
for (const QShaderDescription::InOutVariable &v : desc.outputVariables()) {
|
|
|
|
switch (v.location) {
|
|
|
|
case 0:
|
2020-05-27 10:34:29 +00:00
|
|
|
QCOMPARE(v.name, QByteArrayLiteral("fragColor"));
|
2020-01-12 16:33:31 +00:00
|
|
|
QCOMPARE(v.type, QShaderDescription::Vec4);
|
|
|
|
break;
|
|
|
|
default:
|
2021-06-11 12:38:24 +00:00
|
|
|
QFAIL(qPrintable(QStringLiteral("Bad location: %1").arg(v.location)));
|
2020-01-12 16:33:31 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
Port from container.count()/length() to size()
This is semantic patch using ClangTidyTransformator:
auto QtContainerClass = expr(hasType(namedDecl(hasAnyName(<classes>)))).bind(o)
makeRule(cxxMemberCallExpr(on(QtContainerClass),
callee(cxxMethodDecl(hasAnyName({"count", "length"),
parameterCountIs(0))))),
changeTo(cat(access(o, cat("size"), "()"))),
cat("use 'size()' instead of 'count()/length()'"))
a.k.a qt-port-to-std-compatible-api with config Scope: 'Container'.
<classes> are:
// sequential:
"QByteArray",
"QList",
"QQueue",
"QStack",
"QString",
"QVarLengthArray",
"QVector",
// associative:
"QHash",
"QMultiHash",
"QMap",
"QMultiMap",
"QSet",
// Qt has no QMultiSet
Change-Id: Ibe8837be96e8d30d1846881ecd65180c1bc459af
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2022-09-30 12:09:04 +00:00
|
|
|
QCOMPARE(desc.uniformBlocks().size(), 1);
|
2020-01-12 16:33:31 +00:00
|
|
|
const QShaderDescription::UniformBlock blk = desc.uniformBlocks().first();
|
2020-05-27 10:34:29 +00:00
|
|
|
QCOMPARE(blk.blockName, QByteArrayLiteral("buf"));
|
|
|
|
QCOMPARE(blk.structName, QByteArrayLiteral("ubuf"));
|
2020-01-12 16:33:31 +00:00
|
|
|
QCOMPARE(blk.size, 68);
|
|
|
|
QCOMPARE(blk.binding, 0);
|
|
|
|
QCOMPARE(blk.descriptorSet, 0);
|
Port from container.count()/length() to size()
This is semantic patch using ClangTidyTransformator:
auto QtContainerClass = expr(hasType(namedDecl(hasAnyName(<classes>)))).bind(o)
makeRule(cxxMemberCallExpr(on(QtContainerClass),
callee(cxxMethodDecl(hasAnyName({"count", "length"),
parameterCountIs(0))))),
changeTo(cat(access(o, cat("size"), "()"))),
cat("use 'size()' instead of 'count()/length()'"))
a.k.a qt-port-to-std-compatible-api with config Scope: 'Container'.
<classes> are:
// sequential:
"QByteArray",
"QList",
"QQueue",
"QStack",
"QString",
"QVarLengthArray",
"QVector",
// associative:
"QHash",
"QMultiHash",
"QMap",
"QMultiMap",
"QSet",
// Qt has no QMultiSet
Change-Id: Ibe8837be96e8d30d1846881ecd65180c1bc459af
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2022-09-30 12:09:04 +00:00
|
|
|
QCOMPARE(blk.members.size(), 2);
|
|
|
|
for (int i = 0; i < blk.members.size(); ++i) {
|
2020-01-12 16:33:31 +00:00
|
|
|
const QShaderDescription::BlockVariable v = blk.members[i];
|
|
|
|
switch (i) {
|
|
|
|
case 0:
|
|
|
|
QCOMPARE(v.offset, 0);
|
|
|
|
QCOMPARE(v.size, 64);
|
2020-05-27 10:34:29 +00:00
|
|
|
QCOMPARE(v.name, QByteArrayLiteral("qt_Matrix"));
|
2020-01-12 16:33:31 +00:00
|
|
|
QCOMPARE(v.type, QShaderDescription::Mat4);
|
|
|
|
QCOMPARE(v.matrixStride, 16);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
QCOMPARE(v.offset, 64);
|
|
|
|
QCOMPARE(v.size, 4);
|
2020-05-27 10:34:29 +00:00
|
|
|
QCOMPARE(v.name, QByteArrayLiteral("opacity"));
|
2020-01-12 16:33:31 +00:00
|
|
|
QCOMPARE(v.type, QShaderDescription::Float);
|
|
|
|
break;
|
|
|
|
default:
|
Port from container.count()/length() to size()
This is semantic patch using ClangTidyTransformator:
auto QtContainerClass = expr(hasType(namedDecl(hasAnyName(<classes>)))).bind(o)
makeRule(cxxMemberCallExpr(on(QtContainerClass),
callee(cxxMethodDecl(hasAnyName({"count", "length"),
parameterCountIs(0))))),
changeTo(cat(access(o, cat("size"), "()"))),
cat("use 'size()' instead of 'count()/length()'"))
a.k.a qt-port-to-std-compatible-api with config Scope: 'Container'.
<classes> are:
// sequential:
"QByteArray",
"QList",
"QQueue",
"QStack",
"QString",
"QVarLengthArray",
"QVector",
// associative:
"QHash",
"QMultiHash",
"QMap",
"QMultiMap",
"QSet",
// Qt has no QMultiSet
Change-Id: Ibe8837be96e8d30d1846881ecd65180c1bc459af
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2022-09-30 12:09:04 +00:00
|
|
|
QFAIL(qPrintable(QStringLiteral("Bad many blocks: %1").arg(blk.members.size())));
|
2020-01-12 16:33:31 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2019-10-28 15:37:57 +00:00
|
|
|
}
|
|
|
|
|
2021-01-11 14:11:16 +00:00
|
|
|
void tst_QShader::manualShaderPackCreation()
|
|
|
|
{
|
|
|
|
// Exercise manually building a QShader (instead of loading it from
|
|
|
|
// serialized form). Some Qt modules may do this, in particular when OpenGL
|
|
|
|
// and GLSL code that cannot be processed through the normal pipeline with
|
|
|
|
// Vulkan SPIR-V as the primary target.
|
|
|
|
|
|
|
|
static const char *FS =
|
|
|
|
"#extension GL_OES_EGL_image_external : require\n"
|
|
|
|
"varying vec2 v_texcoord;\n"
|
|
|
|
"struct buf {\n"
|
|
|
|
" mat4 qt_Matrix;\n"
|
|
|
|
" float qt_Opacity;\n"
|
|
|
|
"};\n"
|
|
|
|
"uniform buf ubuf;\n"
|
|
|
|
"uniform samplerExternalOES tex0;\n"
|
|
|
|
"void main()\n"
|
|
|
|
"{\n"
|
|
|
|
" gl_FragColor = ubuf.qt_Opacity * texture2D(tex0, v_texcoord);\n"
|
|
|
|
"}\n";
|
|
|
|
static const char *FS_GLES_PREAMBLE =
|
|
|
|
"precision highp float;\n";
|
|
|
|
// not necessarily sensible given the OES stuff but just for testing
|
|
|
|
static const char *FS_GL_PREAMBLE =
|
|
|
|
"#version 120\n";
|
|
|
|
QByteArray fs_gles = FS_GLES_PREAMBLE;
|
|
|
|
fs_gles += FS;
|
|
|
|
QByteArray fs_gl = FS_GL_PREAMBLE;
|
|
|
|
fs_gl += FS;
|
|
|
|
|
|
|
|
QShaderDescription desc;
|
|
|
|
QShaderDescriptionPrivate *descData = QShaderDescriptionPrivate::get(&desc);
|
|
|
|
QCOMPARE(descData->ref.loadRelaxed(), 1);
|
|
|
|
|
|
|
|
// Inputs
|
|
|
|
QShaderDescription::InOutVariable texCoordInput;
|
|
|
|
texCoordInput.name = "v_texcoord";
|
|
|
|
texCoordInput.type = QShaderDescription::Vec2;
|
|
|
|
texCoordInput.location = 0;
|
|
|
|
|
|
|
|
descData->inVars = {
|
|
|
|
texCoordInput
|
|
|
|
};
|
|
|
|
|
|
|
|
// Outputs (just here for completeness, not strictly needed with OpenGL, the
|
|
|
|
// OpenGL backend of QRhi does not care)
|
|
|
|
QShaderDescription::InOutVariable fragColorOutput;
|
|
|
|
texCoordInput.name = "gl_FragColor";
|
|
|
|
texCoordInput.type = QShaderDescription::Vec4;
|
|
|
|
texCoordInput.location = 0;
|
|
|
|
|
|
|
|
descData->outVars = {
|
|
|
|
fragColorOutput
|
|
|
|
};
|
|
|
|
|
|
|
|
// No real uniform blocks in GLSL shaders used with QRhi, but metadata-wise
|
|
|
|
// that's what the struct maps to in others shading languages.
|
|
|
|
QShaderDescription::BlockVariable matrixBlockVar;
|
|
|
|
matrixBlockVar.name = "qt_Matrix";
|
|
|
|
matrixBlockVar.type = QShaderDescription::Mat4;
|
|
|
|
matrixBlockVar.offset = 0;
|
|
|
|
matrixBlockVar.size = 64;
|
|
|
|
|
|
|
|
QShaderDescription::BlockVariable opacityBlockVar;
|
|
|
|
opacityBlockVar.name = "qt_Opacity";
|
|
|
|
opacityBlockVar.type = QShaderDescription::Float;
|
|
|
|
opacityBlockVar.offset = 64;
|
|
|
|
opacityBlockVar.size = 4;
|
|
|
|
|
|
|
|
QShaderDescription::UniformBlock ubufStruct;
|
|
|
|
ubufStruct.blockName = "buf";
|
|
|
|
ubufStruct.structName = "ubuf";
|
|
|
|
ubufStruct.size = 64 + 4;
|
|
|
|
ubufStruct.binding = 0;
|
|
|
|
ubufStruct.members = {
|
|
|
|
matrixBlockVar,
|
|
|
|
opacityBlockVar
|
|
|
|
};
|
|
|
|
|
|
|
|
descData->uniformBlocks = {
|
|
|
|
ubufStruct
|
|
|
|
};
|
|
|
|
|
|
|
|
// Samplers
|
|
|
|
QShaderDescription::InOutVariable samplerTex0;
|
|
|
|
samplerTex0.name = "tex0";
|
|
|
|
samplerTex0.type = QShaderDescription::SamplerExternalOES;
|
|
|
|
// the struct with the "uniform block" content should be binding 0, samplers can then use 1, 2, ...
|
|
|
|
samplerTex0.binding = 1;
|
|
|
|
|
|
|
|
descData->combinedImageSamplers = {
|
|
|
|
samplerTex0
|
|
|
|
};
|
|
|
|
|
|
|
|
// Now we have everything needed to construct a QShader suitable for OpenGL ES >=2.0 and OpenGL >=2.1
|
|
|
|
QShader shaderPack;
|
|
|
|
shaderPack.setStage(QShader::FragmentStage);
|
|
|
|
shaderPack.setDescription(desc);
|
|
|
|
shaderPack.setShader(QShaderKey(QShader::GlslShader, QShaderVersion(100, QShaderVersion::GlslEs)), QShaderCode(fs_gles));
|
|
|
|
shaderPack.setShader(QShaderKey(QShader::GlslShader, QShaderVersion(120)), QShaderCode(fs_gl));
|
|
|
|
|
|
|
|
// real world code would then pass the QShader to QSGMaterialShader::setShader() etc.
|
|
|
|
|
|
|
|
const QByteArray serialized = shaderPack.serialized();
|
|
|
|
QShader newShaderPack = QShader::fromSerialized(serialized);
|
Port from container.count()/length() to size()
This is semantic patch using ClangTidyTransformator:
auto QtContainerClass = expr(hasType(namedDecl(hasAnyName(<classes>)))).bind(o)
makeRule(cxxMemberCallExpr(on(QtContainerClass),
callee(cxxMethodDecl(hasAnyName({"count", "length"),
parameterCountIs(0))))),
changeTo(cat(access(o, cat("size"), "()"))),
cat("use 'size()' instead of 'count()/length()'"))
a.k.a qt-port-to-std-compatible-api with config Scope: 'Container'.
<classes> are:
// sequential:
"QByteArray",
"QList",
"QQueue",
"QStack",
"QString",
"QVarLengthArray",
"QVector",
// associative:
"QHash",
"QMultiHash",
"QMap",
"QMultiMap",
"QSet",
// Qt has no QMultiSet
Change-Id: Ibe8837be96e8d30d1846881ecd65180c1bc459af
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2022-09-30 12:09:04 +00:00
|
|
|
QCOMPARE(newShaderPack.availableShaders().size(), 2);
|
|
|
|
QCOMPARE(newShaderPack.description().inputVariables().size(), 1);
|
|
|
|
QCOMPARE(newShaderPack.description().outputVariables().size(), 1);
|
|
|
|
QCOMPARE(newShaderPack.description().uniformBlocks().size(), 1);
|
|
|
|
QCOMPARE(newShaderPack.description().combinedImageSamplers().size(), 1);
|
2021-01-11 14:11:16 +00:00
|
|
|
QCOMPARE(newShaderPack.shader(QShaderKey(QShader::GlslShader, QShaderVersion(100, QShaderVersion::GlslEs))).shader(), fs_gles);
|
|
|
|
QCOMPARE(newShaderPack.shader(QShaderKey(QShader::GlslShader, QShaderVersion(120))).shader(), fs_gl);
|
|
|
|
}
|
|
|
|
|
rhi: Enable exposing separate image and sampler objects from the shader
Adds the following in a QShader/QShaderDescription:
- a list of separate images
- a list of separate samplers
- a list of "combined_sampler_uniform_name" -> [
separate_texture_binding, separate_sampler_binding ] mappings
(relevant for GLSL only)
On the QShader (and qsb/QShaderBaker) level not having separate image
(texture) and sampler objects exposed in the reflection info is not
entirely future proof. Right now we benefit strongly from the fact
that Vulkan/SPIR-V supports both combined and separate
images/samplers, while for HLSL and MSL SPIRV-Cross translates
combined image samplers to separate texture and sampler objects, but
it is not given that relying on combined image samplers will always be
possible in the long run; it is mostly a legacy OpenGL thing that just
happens to be supported in Vulkan/SPIR-V due to some benefits with
certain implementations/hw, but is not something present in any newer
APIs.
In addition, before this patch, attempting to run a shader with
separate textures and samplers through qsb will just fail for GLSL,
even though SPIRV-Cross does have the ability to generate a "fake"
combined sampler for each separate texture+sampler combination. Take
this into use. This also involves generating and exposing a
combined_name->[separate_texture_binding,separate_sampler_binding]
mapping table for GLSL, not unlike we have the native binding map for
HLSL and MSL. A user (such as, the GL backend of QRhi) would then use
this table to recognize what user-provided texture+sampler binding
point numbers correspond to which auto-generated sampler2Ds in the GL
program.
Take the following example:
layout(binding = 1) uniform texture2D sepTex;
layout(binding = 2) uniform sampler sepSampler;
layout(binding = 3) uniform sampler sepSampler2;
Inn the reflection info (QShaderDescription) this (assuming a
corresponding qtshadertools patch in place) now gives one entry in
separateImages() and two in separateSamplers(). Assuming sepTex is
used both with sepSampler and sepSampler2, the GLSL output and mapping
table from QShaderBaker will have two auto-generated sampler2Ds (and
no 'texture2D' or 'sampler').
One immediate benefit is that it is now possible to create a shader
that relies only on separate images and samplers, feed it into qsb,
generate all the possible targets, and then also feed the SPIR-V
binary into a tool or library such as Tint (e.g. to generate WGSL)
that canot deal with combined image samplers.
Change-Id: I9b19847ea5854837b45d3a23edc788c48502aa15
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
2021-12-18 21:21:31 +00:00
|
|
|
void tst_QShader::loadV6WithSeparateImagesAndSamplers()
|
|
|
|
{
|
|
|
|
QShader s = getShader(QLatin1String(":/data/texture_sep_v6.frag.qsb"));
|
|
|
|
QVERIFY(s.isValid());
|
|
|
|
QCOMPARE(QShaderPrivate::get(&s)->qsbVersion, 6);
|
|
|
|
|
|
|
|
const QList<QShaderKey> availableShaders = s.availableShaders();
|
Port from container.count()/length() to size()
This is semantic patch using ClangTidyTransformator:
auto QtContainerClass = expr(hasType(namedDecl(hasAnyName(<classes>)))).bind(o)
makeRule(cxxMemberCallExpr(on(QtContainerClass),
callee(cxxMethodDecl(hasAnyName({"count", "length"),
parameterCountIs(0))))),
changeTo(cat(access(o, cat("size"), "()"))),
cat("use 'size()' instead of 'count()/length()'"))
a.k.a qt-port-to-std-compatible-api with config Scope: 'Container'.
<classes> are:
// sequential:
"QByteArray",
"QList",
"QQueue",
"QStack",
"QString",
"QVarLengthArray",
"QVector",
// associative:
"QHash",
"QMultiHash",
"QMap",
"QMultiMap",
"QSet",
// Qt has no QMultiSet
Change-Id: Ibe8837be96e8d30d1846881ecd65180c1bc459af
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2022-09-30 12:09:04 +00:00
|
|
|
QCOMPARE(availableShaders.size(), 6);
|
rhi: Enable exposing separate image and sampler objects from the shader
Adds the following in a QShader/QShaderDescription:
- a list of separate images
- a list of separate samplers
- a list of "combined_sampler_uniform_name" -> [
separate_texture_binding, separate_sampler_binding ] mappings
(relevant for GLSL only)
On the QShader (and qsb/QShaderBaker) level not having separate image
(texture) and sampler objects exposed in the reflection info is not
entirely future proof. Right now we benefit strongly from the fact
that Vulkan/SPIR-V supports both combined and separate
images/samplers, while for HLSL and MSL SPIRV-Cross translates
combined image samplers to separate texture and sampler objects, but
it is not given that relying on combined image samplers will always be
possible in the long run; it is mostly a legacy OpenGL thing that just
happens to be supported in Vulkan/SPIR-V due to some benefits with
certain implementations/hw, but is not something present in any newer
APIs.
In addition, before this patch, attempting to run a shader with
separate textures and samplers through qsb will just fail for GLSL,
even though SPIRV-Cross does have the ability to generate a "fake"
combined sampler for each separate texture+sampler combination. Take
this into use. This also involves generating and exposing a
combined_name->[separate_texture_binding,separate_sampler_binding]
mapping table for GLSL, not unlike we have the native binding map for
HLSL and MSL. A user (such as, the GL backend of QRhi) would then use
this table to recognize what user-provided texture+sampler binding
point numbers correspond to which auto-generated sampler2Ds in the GL
program.
Take the following example:
layout(binding = 1) uniform texture2D sepTex;
layout(binding = 2) uniform sampler sepSampler;
layout(binding = 3) uniform sampler sepSampler2;
Inn the reflection info (QShaderDescription) this (assuming a
corresponding qtshadertools patch in place) now gives one entry in
separateImages() and two in separateSamplers(). Assuming sepTex is
used both with sepSampler and sepSampler2, the GLSL output and mapping
table from QShaderBaker will have two auto-generated sampler2Ds (and
no 'texture2D' or 'sampler').
One immediate benefit is that it is now possible to create a shader
that relies only on separate images and samplers, feed it into qsb,
generate all the possible targets, and then also feed the SPIR-V
binary into a tool or library such as Tint (e.g. to generate WGSL)
that canot deal with combined image samplers.
Change-Id: I9b19847ea5854837b45d3a23edc788c48502aa15
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
2021-12-18 21:21:31 +00:00
|
|
|
QVERIFY(availableShaders.contains(QShaderKey(QShader::SpirvShader, QShaderVersion(100))));
|
|
|
|
QVERIFY(availableShaders.contains(QShaderKey(QShader::MslShader, QShaderVersion(12))));
|
|
|
|
QVERIFY(availableShaders.contains(QShaderKey(QShader::HlslShader, QShaderVersion(50))));
|
|
|
|
QVERIFY(availableShaders.contains(QShaderKey(QShader::GlslShader, QShaderVersion(100, QShaderVersion::GlslEs))));
|
|
|
|
QVERIFY(availableShaders.contains(QShaderKey(QShader::GlslShader, QShaderVersion(120))));
|
|
|
|
QVERIFY(availableShaders.contains(QShaderKey(QShader::GlslShader, QShaderVersion(150))));
|
|
|
|
|
2021-12-21 15:04:30 +00:00
|
|
|
QShader::NativeResourceBindingMap resMap =
|
rhi: Enable exposing separate image and sampler objects from the shader
Adds the following in a QShader/QShaderDescription:
- a list of separate images
- a list of separate samplers
- a list of "combined_sampler_uniform_name" -> [
separate_texture_binding, separate_sampler_binding ] mappings
(relevant for GLSL only)
On the QShader (and qsb/QShaderBaker) level not having separate image
(texture) and sampler objects exposed in the reflection info is not
entirely future proof. Right now we benefit strongly from the fact
that Vulkan/SPIR-V supports both combined and separate
images/samplers, while for HLSL and MSL SPIRV-Cross translates
combined image samplers to separate texture and sampler objects, but
it is not given that relying on combined image samplers will always be
possible in the long run; it is mostly a legacy OpenGL thing that just
happens to be supported in Vulkan/SPIR-V due to some benefits with
certain implementations/hw, but is not something present in any newer
APIs.
In addition, before this patch, attempting to run a shader with
separate textures and samplers through qsb will just fail for GLSL,
even though SPIRV-Cross does have the ability to generate a "fake"
combined sampler for each separate texture+sampler combination. Take
this into use. This also involves generating and exposing a
combined_name->[separate_texture_binding,separate_sampler_binding]
mapping table for GLSL, not unlike we have the native binding map for
HLSL and MSL. A user (such as, the GL backend of QRhi) would then use
this table to recognize what user-provided texture+sampler binding
point numbers correspond to which auto-generated sampler2Ds in the GL
program.
Take the following example:
layout(binding = 1) uniform texture2D sepTex;
layout(binding = 2) uniform sampler sepSampler;
layout(binding = 3) uniform sampler sepSampler2;
Inn the reflection info (QShaderDescription) this (assuming a
corresponding qtshadertools patch in place) now gives one entry in
separateImages() and two in separateSamplers(). Assuming sepTex is
used both with sepSampler and sepSampler2, the GLSL output and mapping
table from QShaderBaker will have two auto-generated sampler2Ds (and
no 'texture2D' or 'sampler').
One immediate benefit is that it is now possible to create a shader
that relies only on separate images and samplers, feed it into qsb,
generate all the possible targets, and then also feed the SPIR-V
binary into a tool or library such as Tint (e.g. to generate WGSL)
that canot deal with combined image samplers.
Change-Id: I9b19847ea5854837b45d3a23edc788c48502aa15
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
2021-12-18 21:21:31 +00:00
|
|
|
s.nativeResourceBindingMap(QShaderKey(QShader::HlslShader, QShaderVersion(50)));
|
Port from container::count() and length() to size() - V5
This is a semantic patch using ClangTidyTransformator as in
qtbase/df9d882d41b741fef7c5beeddb0abe9d904443d8, but extended to
handle typedefs and accesses through pointers, too:
const std::string o = "object";
auto hasTypeIgnoringPointer = [](auto type) { return anyOf(hasType(type), hasType(pointsTo(type))); };
auto derivedFromAnyOfClasses = [&](ArrayRef<StringRef> classes) {
auto exprOfDeclaredType = [&](auto decl) {
return expr(hasTypeIgnoringPointer(hasUnqualifiedDesugaredType(recordType(hasDeclaration(decl))))).bind(o);
};
return exprOfDeclaredType(cxxRecordDecl(isSameOrDerivedFrom(hasAnyName(classes))));
};
auto renameMethod = [&] (ArrayRef<StringRef> classes,
StringRef from, StringRef to) {
return makeRule(cxxMemberCallExpr(on(derivedFromAnyOfClasses(classes)),
callee(cxxMethodDecl(hasName(from), parameterCountIs(0)))),
changeTo(cat(access(o, cat(to)), "()")),
cat("use '", to, "' instead of '", from, "'"));
};
renameMethod(<classes>, "count", "size");
renameMethod(<classes>, "length", "size");
except that the on() matcher has been replaced by one that doesn't
ignoreParens().
a.k.a qt-port-to-std-compatible-api V5 with config Scope: 'Container'.
Added two NOLINTNEXTLINEs in tst_qbitarray and tst_qcontiguouscache,
to avoid porting calls that explicitly test count().
Change-Id: Icfb8808c2ff4a30187e9935a51cad26987451c22
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2022-09-30 12:09:04 +00:00
|
|
|
QVERIFY(resMap.size() == 4);
|
2021-12-21 15:04:30 +00:00
|
|
|
QVERIFY(s.separateToCombinedImageSamplerMappingList(QShaderKey(QShader::HlslShader, QShaderVersion(50))).isEmpty());
|
rhi: Enable exposing separate image and sampler objects from the shader
Adds the following in a QShader/QShaderDescription:
- a list of separate images
- a list of separate samplers
- a list of "combined_sampler_uniform_name" -> [
separate_texture_binding, separate_sampler_binding ] mappings
(relevant for GLSL only)
On the QShader (and qsb/QShaderBaker) level not having separate image
(texture) and sampler objects exposed in the reflection info is not
entirely future proof. Right now we benefit strongly from the fact
that Vulkan/SPIR-V supports both combined and separate
images/samplers, while for HLSL and MSL SPIRV-Cross translates
combined image samplers to separate texture and sampler objects, but
it is not given that relying on combined image samplers will always be
possible in the long run; it is mostly a legacy OpenGL thing that just
happens to be supported in Vulkan/SPIR-V due to some benefits with
certain implementations/hw, but is not something present in any newer
APIs.
In addition, before this patch, attempting to run a shader with
separate textures and samplers through qsb will just fail for GLSL,
even though SPIRV-Cross does have the ability to generate a "fake"
combined sampler for each separate texture+sampler combination. Take
this into use. This also involves generating and exposing a
combined_name->[separate_texture_binding,separate_sampler_binding]
mapping table for GLSL, not unlike we have the native binding map for
HLSL and MSL. A user (such as, the GL backend of QRhi) would then use
this table to recognize what user-provided texture+sampler binding
point numbers correspond to which auto-generated sampler2Ds in the GL
program.
Take the following example:
layout(binding = 1) uniform texture2D sepTex;
layout(binding = 2) uniform sampler sepSampler;
layout(binding = 3) uniform sampler sepSampler2;
Inn the reflection info (QShaderDescription) this (assuming a
corresponding qtshadertools patch in place) now gives one entry in
separateImages() and two in separateSamplers(). Assuming sepTex is
used both with sepSampler and sepSampler2, the GLSL output and mapping
table from QShaderBaker will have two auto-generated sampler2Ds (and
no 'texture2D' or 'sampler').
One immediate benefit is that it is now possible to create a shader
that relies only on separate images and samplers, feed it into qsb,
generate all the possible targets, and then also feed the SPIR-V
binary into a tool or library such as Tint (e.g. to generate WGSL)
that canot deal with combined image samplers.
Change-Id: I9b19847ea5854837b45d3a23edc788c48502aa15
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
2021-12-18 21:21:31 +00:00
|
|
|
resMap = s.nativeResourceBindingMap(QShaderKey(QShader::MslShader, QShaderVersion(12)));
|
Port from container::count() and length() to size() - V5
This is a semantic patch using ClangTidyTransformator as in
qtbase/df9d882d41b741fef7c5beeddb0abe9d904443d8, but extended to
handle typedefs and accesses through pointers, too:
const std::string o = "object";
auto hasTypeIgnoringPointer = [](auto type) { return anyOf(hasType(type), hasType(pointsTo(type))); };
auto derivedFromAnyOfClasses = [&](ArrayRef<StringRef> classes) {
auto exprOfDeclaredType = [&](auto decl) {
return expr(hasTypeIgnoringPointer(hasUnqualifiedDesugaredType(recordType(hasDeclaration(decl))))).bind(o);
};
return exprOfDeclaredType(cxxRecordDecl(isSameOrDerivedFrom(hasAnyName(classes))));
};
auto renameMethod = [&] (ArrayRef<StringRef> classes,
StringRef from, StringRef to) {
return makeRule(cxxMemberCallExpr(on(derivedFromAnyOfClasses(classes)),
callee(cxxMethodDecl(hasName(from), parameterCountIs(0)))),
changeTo(cat(access(o, cat(to)), "()")),
cat("use '", to, "' instead of '", from, "'"));
};
renameMethod(<classes>, "count", "size");
renameMethod(<classes>, "length", "size");
except that the on() matcher has been replaced by one that doesn't
ignoreParens().
a.k.a qt-port-to-std-compatible-api V5 with config Scope: 'Container'.
Added two NOLINTNEXTLINEs in tst_qbitarray and tst_qcontiguouscache,
to avoid porting calls that explicitly test count().
Change-Id: Icfb8808c2ff4a30187e9935a51cad26987451c22
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2022-09-30 12:09:04 +00:00
|
|
|
QVERIFY(resMap.size() == 4);
|
2021-12-21 15:04:30 +00:00
|
|
|
QVERIFY(s.separateToCombinedImageSamplerMappingList(QShaderKey(QShader::MslShader, QShaderVersion(12))).isEmpty());
|
rhi: Enable exposing separate image and sampler objects from the shader
Adds the following in a QShader/QShaderDescription:
- a list of separate images
- a list of separate samplers
- a list of "combined_sampler_uniform_name" -> [
separate_texture_binding, separate_sampler_binding ] mappings
(relevant for GLSL only)
On the QShader (and qsb/QShaderBaker) level not having separate image
(texture) and sampler objects exposed in the reflection info is not
entirely future proof. Right now we benefit strongly from the fact
that Vulkan/SPIR-V supports both combined and separate
images/samplers, while for HLSL and MSL SPIRV-Cross translates
combined image samplers to separate texture and sampler objects, but
it is not given that relying on combined image samplers will always be
possible in the long run; it is mostly a legacy OpenGL thing that just
happens to be supported in Vulkan/SPIR-V due to some benefits with
certain implementations/hw, but is not something present in any newer
APIs.
In addition, before this patch, attempting to run a shader with
separate textures and samplers through qsb will just fail for GLSL,
even though SPIRV-Cross does have the ability to generate a "fake"
combined sampler for each separate texture+sampler combination. Take
this into use. This also involves generating and exposing a
combined_name->[separate_texture_binding,separate_sampler_binding]
mapping table for GLSL, not unlike we have the native binding map for
HLSL and MSL. A user (such as, the GL backend of QRhi) would then use
this table to recognize what user-provided texture+sampler binding
point numbers correspond to which auto-generated sampler2Ds in the GL
program.
Take the following example:
layout(binding = 1) uniform texture2D sepTex;
layout(binding = 2) uniform sampler sepSampler;
layout(binding = 3) uniform sampler sepSampler2;
Inn the reflection info (QShaderDescription) this (assuming a
corresponding qtshadertools patch in place) now gives one entry in
separateImages() and two in separateSamplers(). Assuming sepTex is
used both with sepSampler and sepSampler2, the GLSL output and mapping
table from QShaderBaker will have two auto-generated sampler2Ds (and
no 'texture2D' or 'sampler').
One immediate benefit is that it is now possible to create a shader
that relies only on separate images and samplers, feed it into qsb,
generate all the possible targets, and then also feed the SPIR-V
binary into a tool or library such as Tint (e.g. to generate WGSL)
that canot deal with combined image samplers.
Change-Id: I9b19847ea5854837b45d3a23edc788c48502aa15
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
2021-12-18 21:21:31 +00:00
|
|
|
|
|
|
|
for (auto key : {
|
|
|
|
QShaderKey(QShader::GlslShader, QShaderVersion(100, QShaderVersion::GlslEs)),
|
|
|
|
QShaderKey(QShader::GlslShader, QShaderVersion(120)),
|
|
|
|
QShaderKey(QShader::GlslShader, QShaderVersion(150)) })
|
|
|
|
{
|
|
|
|
auto list = s.separateToCombinedImageSamplerMappingList(key);
|
Port from container::count() and length() to size() - V5
This is a semantic patch using ClangTidyTransformator as in
qtbase/df9d882d41b741fef7c5beeddb0abe9d904443d8, but extended to
handle typedefs and accesses through pointers, too:
const std::string o = "object";
auto hasTypeIgnoringPointer = [](auto type) { return anyOf(hasType(type), hasType(pointsTo(type))); };
auto derivedFromAnyOfClasses = [&](ArrayRef<StringRef> classes) {
auto exprOfDeclaredType = [&](auto decl) {
return expr(hasTypeIgnoringPointer(hasUnqualifiedDesugaredType(recordType(hasDeclaration(decl))))).bind(o);
};
return exprOfDeclaredType(cxxRecordDecl(isSameOrDerivedFrom(hasAnyName(classes))));
};
auto renameMethod = [&] (ArrayRef<StringRef> classes,
StringRef from, StringRef to) {
return makeRule(cxxMemberCallExpr(on(derivedFromAnyOfClasses(classes)),
callee(cxxMethodDecl(hasName(from), parameterCountIs(0)))),
changeTo(cat(access(o, cat(to)), "()")),
cat("use '", to, "' instead of '", from, "'"));
};
renameMethod(<classes>, "count", "size");
renameMethod(<classes>, "length", "size");
except that the on() matcher has been replaced by one that doesn't
ignoreParens().
a.k.a qt-port-to-std-compatible-api V5 with config Scope: 'Container'.
Added two NOLINTNEXTLINEs in tst_qbitarray and tst_qcontiguouscache,
to avoid porting calls that explicitly test count().
Change-Id: Icfb8808c2ff4a30187e9935a51cad26987451c22
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2022-09-30 12:09:04 +00:00
|
|
|
QCOMPARE(list.size(), 2);
|
rhi: Enable exposing separate image and sampler objects from the shader
Adds the following in a QShader/QShaderDescription:
- a list of separate images
- a list of separate samplers
- a list of "combined_sampler_uniform_name" -> [
separate_texture_binding, separate_sampler_binding ] mappings
(relevant for GLSL only)
On the QShader (and qsb/QShaderBaker) level not having separate image
(texture) and sampler objects exposed in the reflection info is not
entirely future proof. Right now we benefit strongly from the fact
that Vulkan/SPIR-V supports both combined and separate
images/samplers, while for HLSL and MSL SPIRV-Cross translates
combined image samplers to separate texture and sampler objects, but
it is not given that relying on combined image samplers will always be
possible in the long run; it is mostly a legacy OpenGL thing that just
happens to be supported in Vulkan/SPIR-V due to some benefits with
certain implementations/hw, but is not something present in any newer
APIs.
In addition, before this patch, attempting to run a shader with
separate textures and samplers through qsb will just fail for GLSL,
even though SPIRV-Cross does have the ability to generate a "fake"
combined sampler for each separate texture+sampler combination. Take
this into use. This also involves generating and exposing a
combined_name->[separate_texture_binding,separate_sampler_binding]
mapping table for GLSL, not unlike we have the native binding map for
HLSL and MSL. A user (such as, the GL backend of QRhi) would then use
this table to recognize what user-provided texture+sampler binding
point numbers correspond to which auto-generated sampler2Ds in the GL
program.
Take the following example:
layout(binding = 1) uniform texture2D sepTex;
layout(binding = 2) uniform sampler sepSampler;
layout(binding = 3) uniform sampler sepSampler2;
Inn the reflection info (QShaderDescription) this (assuming a
corresponding qtshadertools patch in place) now gives one entry in
separateImages() and two in separateSamplers(). Assuming sepTex is
used both with sepSampler and sepSampler2, the GLSL output and mapping
table from QShaderBaker will have two auto-generated sampler2Ds (and
no 'texture2D' or 'sampler').
One immediate benefit is that it is now possible to create a shader
that relies only on separate images and samplers, feed it into qsb,
generate all the possible targets, and then also feed the SPIR-V
binary into a tool or library such as Tint (e.g. to generate WGSL)
that canot deal with combined image samplers.
Change-Id: I9b19847ea5854837b45d3a23edc788c48502aa15
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
2021-12-18 21:21:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-18 10:43:23 +00:00
|
|
|
void tst_QShader::loadV7()
|
|
|
|
{
|
|
|
|
QShader vert = getShader(QLatin1String(":/data/metal_enabled_tessellation_v7.vert.qsb"));
|
|
|
|
QVERIFY(vert.isValid());
|
|
|
|
QCOMPARE(QShaderPrivate::get(&vert)->qsbVersion, 7);
|
Port from container.count()/length() to size()
This is semantic patch using ClangTidyTransformator:
auto QtContainerClass = expr(hasType(namedDecl(hasAnyName(<classes>)))).bind(o)
makeRule(cxxMemberCallExpr(on(QtContainerClass),
callee(cxxMethodDecl(hasAnyName({"count", "length"),
parameterCountIs(0))))),
changeTo(cat(access(o, cat("size"), "()"))),
cat("use 'size()' instead of 'count()/length()'"))
a.k.a qt-port-to-std-compatible-api with config Scope: 'Container'.
<classes> are:
// sequential:
"QByteArray",
"QList",
"QQueue",
"QStack",
"QString",
"QVarLengthArray",
"QVector",
// associative:
"QHash",
"QMultiHash",
"QMap",
"QMultiMap",
"QSet",
// Qt has no QMultiSet
Change-Id: Ibe8837be96e8d30d1846881ecd65180c1bc459af
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2022-09-30 12:09:04 +00:00
|
|
|
QCOMPARE(vert.availableShaders().size(), 8);
|
2022-08-18 10:43:23 +00:00
|
|
|
|
Port from container.count()/length() to size()
This is semantic patch using ClangTidyTransformator:
auto QtContainerClass = expr(hasType(namedDecl(hasAnyName(<classes>)))).bind(o)
makeRule(cxxMemberCallExpr(on(QtContainerClass),
callee(cxxMethodDecl(hasAnyName({"count", "length"),
parameterCountIs(0))))),
changeTo(cat(access(o, cat("size"), "()"))),
cat("use 'size()' instead of 'count()/length()'"))
a.k.a qt-port-to-std-compatible-api with config Scope: 'Container'.
<classes> are:
// sequential:
"QByteArray",
"QList",
"QQueue",
"QStack",
"QString",
"QVarLengthArray",
"QVector",
// associative:
"QHash",
"QMultiHash",
"QMap",
"QMultiMap",
"QSet",
// Qt has no QMultiSet
Change-Id: Ibe8837be96e8d30d1846881ecd65180c1bc459af
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2022-09-30 12:09:04 +00:00
|
|
|
QCOMPARE(vert.description().inputVariables().size(), 2);
|
|
|
|
QCOMPARE(vert.description().outputBuiltinVariables().size(), 1);
|
2022-08-18 10:43:23 +00:00
|
|
|
QCOMPARE(vert.description().outputBuiltinVariables()[0].type, QShaderDescription::PositionBuiltin);
|
Port from container.count()/length() to size()
This is semantic patch using ClangTidyTransformator:
auto QtContainerClass = expr(hasType(namedDecl(hasAnyName(<classes>)))).bind(o)
makeRule(cxxMemberCallExpr(on(QtContainerClass),
callee(cxxMethodDecl(hasAnyName({"count", "length"),
parameterCountIs(0))))),
changeTo(cat(access(o, cat("size"), "()"))),
cat("use 'size()' instead of 'count()/length()'"))
a.k.a qt-port-to-std-compatible-api with config Scope: 'Container'.
<classes> are:
// sequential:
"QByteArray",
"QList",
"QQueue",
"QStack",
"QString",
"QVarLengthArray",
"QVector",
// associative:
"QHash",
"QMultiHash",
"QMap",
"QMultiMap",
"QSet",
// Qt has no QMultiSet
Change-Id: Ibe8837be96e8d30d1846881ecd65180c1bc459af
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2022-09-30 12:09:04 +00:00
|
|
|
QCOMPARE(vert.description().outputVariables().size(), 1);
|
2022-08-18 10:43:23 +00:00
|
|
|
QCOMPARE(vert.description().outputVariables()[0].name, QByteArrayLiteral("v_color"));
|
|
|
|
|
|
|
|
QVERIFY(vert.availableShaders().contains(QShaderKey(QShader::MslShader, QShaderVersion(12))));
|
|
|
|
QVERIFY(!vert.shader(QShaderKey(QShader::MslShader, QShaderVersion(12), QShader::NonIndexedVertexAsComputeShader)).shader().isEmpty());
|
|
|
|
QVERIFY(!vert.shader(QShaderKey(QShader::MslShader, QShaderVersion(12), QShader::UInt16IndexedVertexAsComputeShader)).shader().isEmpty());
|
|
|
|
QVERIFY(!vert.shader(QShaderKey(QShader::MslShader, QShaderVersion(12), QShader::UInt32IndexedVertexAsComputeShader)).shader().isEmpty());
|
|
|
|
|
|
|
|
QShader tesc = getShader(QLatin1String(":/data/metal_enabled_tessellation_v7.tesc.qsb"));
|
|
|
|
QVERIFY(tesc.isValid());
|
|
|
|
QCOMPARE(QShaderPrivate::get(&tesc)->qsbVersion, 7);
|
Port from container.count()/length() to size()
This is semantic patch using ClangTidyTransformator:
auto QtContainerClass = expr(hasType(namedDecl(hasAnyName(<classes>)))).bind(o)
makeRule(cxxMemberCallExpr(on(QtContainerClass),
callee(cxxMethodDecl(hasAnyName({"count", "length"),
parameterCountIs(0))))),
changeTo(cat(access(o, cat("size"), "()"))),
cat("use 'size()' instead of 'count()/length()'"))
a.k.a qt-port-to-std-compatible-api with config Scope: 'Container'.
<classes> are:
// sequential:
"QByteArray",
"QList",
"QQueue",
"QStack",
"QString",
"QVarLengthArray",
"QVector",
// associative:
"QHash",
"QMultiHash",
"QMap",
"QMultiMap",
"QSet",
// Qt has no QMultiSet
Change-Id: Ibe8837be96e8d30d1846881ecd65180c1bc459af
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2022-09-30 12:09:04 +00:00
|
|
|
QCOMPARE(tesc.availableShaders().size(), 5);
|
2022-09-15 10:15:19 +00:00
|
|
|
QCOMPARE(tesc.description().tessellationOutputVertexCount(), 3u);
|
2022-08-18 10:43:23 +00:00
|
|
|
|
Port from container.count()/length() to size()
This is semantic patch using ClangTidyTransformator:
auto QtContainerClass = expr(hasType(namedDecl(hasAnyName(<classes>)))).bind(o)
makeRule(cxxMemberCallExpr(on(QtContainerClass),
callee(cxxMethodDecl(hasAnyName({"count", "length"),
parameterCountIs(0))))),
changeTo(cat(access(o, cat("size"), "()"))),
cat("use 'size()' instead of 'count()/length()'"))
a.k.a qt-port-to-std-compatible-api with config Scope: 'Container'.
<classes> are:
// sequential:
"QByteArray",
"QList",
"QQueue",
"QStack",
"QString",
"QVarLengthArray",
"QVector",
// associative:
"QHash",
"QMultiHash",
"QMap",
"QMultiMap",
"QSet",
// Qt has no QMultiSet
Change-Id: Ibe8837be96e8d30d1846881ecd65180c1bc459af
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2022-09-30 12:09:04 +00:00
|
|
|
QCOMPARE(tesc.description().inputBuiltinVariables().size(), 2);
|
|
|
|
QCOMPARE(tesc.description().outputBuiltinVariables().size(), 3);
|
2022-08-18 10:43:23 +00:00
|
|
|
// builtins must be sorted based on the type
|
|
|
|
QCOMPARE(tesc.description().inputBuiltinVariables()[0].type, QShaderDescription::PositionBuiltin);
|
|
|
|
QCOMPARE(tesc.description().inputBuiltinVariables()[1].type, QShaderDescription::InvocationIdBuiltin);
|
|
|
|
QCOMPARE(tesc.description().outputBuiltinVariables()[0].type, QShaderDescription::PositionBuiltin);
|
|
|
|
QCOMPARE(tesc.description().outputBuiltinVariables()[1].type, QShaderDescription::TessLevelOuterBuiltin);
|
|
|
|
QCOMPARE(tesc.description().outputBuiltinVariables()[2].type, QShaderDescription::TessLevelInnerBuiltin);
|
|
|
|
|
Port from container.count()/length() to size()
This is semantic patch using ClangTidyTransformator:
auto QtContainerClass = expr(hasType(namedDecl(hasAnyName(<classes>)))).bind(o)
makeRule(cxxMemberCallExpr(on(QtContainerClass),
callee(cxxMethodDecl(hasAnyName({"count", "length"),
parameterCountIs(0))))),
changeTo(cat(access(o, cat("size"), "()"))),
cat("use 'size()' instead of 'count()/length()'"))
a.k.a qt-port-to-std-compatible-api with config Scope: 'Container'.
<classes> are:
// sequential:
"QByteArray",
"QList",
"QQueue",
"QStack",
"QString",
"QVarLengthArray",
"QVector",
// associative:
"QHash",
"QMultiHash",
"QMap",
"QMultiMap",
"QSet",
// Qt has no QMultiSet
Change-Id: Ibe8837be96e8d30d1846881ecd65180c1bc459af
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2022-09-30 12:09:04 +00:00
|
|
|
QCOMPARE(tesc.description().outputVariables().size(), 3);
|
2022-08-18 10:43:23 +00:00
|
|
|
for (const QShaderDescription::InOutVariable &v : tesc.description().outputVariables()) {
|
|
|
|
switch (v.location) {
|
|
|
|
case 0:
|
|
|
|
QCOMPARE(v.name, QByteArrayLiteral("outColor"));
|
|
|
|
QCOMPARE(v.type, QShaderDescription::Vec3);
|
|
|
|
QCOMPARE(v.perPatch, false);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
QCOMPARE(v.name, QByteArrayLiteral("stuff"));
|
|
|
|
QCOMPARE(v.type, QShaderDescription::Vec3);
|
|
|
|
QCOMPARE(v.perPatch, true);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
QCOMPARE(v.name, QByteArrayLiteral("more_stuff"));
|
|
|
|
QCOMPARE(v.type, QShaderDescription::Float);
|
|
|
|
QCOMPARE(v.perPatch, true);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
QFAIL(qPrintable(QStringLiteral("Bad location: %1").arg(v.location)));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QVERIFY(!tesc.shader(QShaderKey(QShader::MslShader, QShaderVersion(12))).shader().isEmpty());
|
Port from container.count()/length() to size()
This is semantic patch using ClangTidyTransformator:
auto QtContainerClass = expr(hasType(namedDecl(hasAnyName(<classes>)))).bind(o)
makeRule(cxxMemberCallExpr(on(QtContainerClass),
callee(cxxMethodDecl(hasAnyName({"count", "length"),
parameterCountIs(0))))),
changeTo(cat(access(o, cat("size"), "()"))),
cat("use 'size()' instead of 'count()/length()'"))
a.k.a qt-port-to-std-compatible-api with config Scope: 'Container'.
<classes> are:
// sequential:
"QByteArray",
"QList",
"QQueue",
"QStack",
"QString",
"QVarLengthArray",
"QVector",
// associative:
"QHash",
"QMultiHash",
"QMap",
"QMultiMap",
"QSet",
// Qt has no QMultiSet
Change-Id: Ibe8837be96e8d30d1846881ecd65180c1bc459af
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2022-09-30 12:09:04 +00:00
|
|
|
QCOMPARE(tesc.nativeShaderInfo(QShaderKey(QShader::SpirvShader, QShaderVersion(100))).extraBufferBindings.size(), 0);
|
|
|
|
QCOMPARE(tesc.nativeShaderInfo(QShaderKey(QShader::MslShader, QShaderVersion(12))).extraBufferBindings.size(), 5);
|
2022-08-18 10:43:23 +00:00
|
|
|
|
|
|
|
QShader tese = getShader(QLatin1String(":/data/metal_enabled_tessellation_v7.tese.qsb"));
|
|
|
|
QVERIFY(tese.isValid());
|
|
|
|
QCOMPARE(QShaderPrivate::get(&tese)->qsbVersion, 7);
|
Port from container.count()/length() to size()
This is semantic patch using ClangTidyTransformator:
auto QtContainerClass = expr(hasType(namedDecl(hasAnyName(<classes>)))).bind(o)
makeRule(cxxMemberCallExpr(on(QtContainerClass),
callee(cxxMethodDecl(hasAnyName({"count", "length"),
parameterCountIs(0))))),
changeTo(cat(access(o, cat("size"), "()"))),
cat("use 'size()' instead of 'count()/length()'"))
a.k.a qt-port-to-std-compatible-api with config Scope: 'Container'.
<classes> are:
// sequential:
"QByteArray",
"QList",
"QQueue",
"QStack",
"QString",
"QVarLengthArray",
"QVector",
// associative:
"QHash",
"QMultiHash",
"QMap",
"QMultiMap",
"QSet",
// Qt has no QMultiSet
Change-Id: Ibe8837be96e8d30d1846881ecd65180c1bc459af
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2022-09-30 12:09:04 +00:00
|
|
|
QCOMPARE(tese.availableShaders().size(), 5);
|
2022-08-18 10:43:23 +00:00
|
|
|
QCOMPARE(tese.description().tessellationMode(), QShaderDescription::TrianglesTessellationMode);
|
|
|
|
QCOMPARE(tese.description().tessellationWindingOrder(), QShaderDescription::CcwTessellationWindingOrder);
|
|
|
|
QCOMPARE(tese.description().tessellationPartitioning(), QShaderDescription::FractionalOddTessellationPartitioning);
|
|
|
|
|
|
|
|
QCOMPARE(tese.description().inputBuiltinVariables()[0].type, QShaderDescription::PositionBuiltin);
|
|
|
|
QCOMPARE(tese.description().inputBuiltinVariables()[1].type, QShaderDescription::TessLevelOuterBuiltin);
|
|
|
|
QCOMPARE(tese.description().inputBuiltinVariables()[2].type, QShaderDescription::TessLevelInnerBuiltin);
|
|
|
|
QCOMPARE(tese.description().inputBuiltinVariables()[3].type, QShaderDescription::TessCoordBuiltin);
|
|
|
|
|
Port from container::count() and length() to size() - V5
This is a semantic patch using ClangTidyTransformator as in
qtbase/df9d882d41b741fef7c5beeddb0abe9d904443d8, but extended to
handle typedefs and accesses through pointers, too:
const std::string o = "object";
auto hasTypeIgnoringPointer = [](auto type) { return anyOf(hasType(type), hasType(pointsTo(type))); };
auto derivedFromAnyOfClasses = [&](ArrayRef<StringRef> classes) {
auto exprOfDeclaredType = [&](auto decl) {
return expr(hasTypeIgnoringPointer(hasUnqualifiedDesugaredType(recordType(hasDeclaration(decl))))).bind(o);
};
return exprOfDeclaredType(cxxRecordDecl(isSameOrDerivedFrom(hasAnyName(classes))));
};
auto renameMethod = [&] (ArrayRef<StringRef> classes,
StringRef from, StringRef to) {
return makeRule(cxxMemberCallExpr(on(derivedFromAnyOfClasses(classes)),
callee(cxxMethodDecl(hasName(from), parameterCountIs(0)))),
changeTo(cat(access(o, cat(to)), "()")),
cat("use '", to, "' instead of '", from, "'"));
};
renameMethod(<classes>, "count", "size");
renameMethod(<classes>, "length", "size");
except that the on() matcher has been replaced by one that doesn't
ignoreParens().
a.k.a qt-port-to-std-compatible-api V5 with config Scope: 'Container'.
Added two NOLINTNEXTLINEs in tst_qbitarray and tst_qcontiguouscache,
to avoid porting calls that explicitly test count().
Change-Id: Icfb8808c2ff4a30187e9935a51cad26987451c22
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2022-09-30 12:09:04 +00:00
|
|
|
QCOMPARE(tese.nativeResourceBindingMap(QShaderKey(QShader::MslShader, QShaderVersion(12))).size(), 1);
|
2022-08-18 10:43:23 +00:00
|
|
|
QCOMPARE(tese.nativeResourceBindingMap(QShaderKey(QShader::MslShader, QShaderVersion(12))).value(0), qMakePair(0, -1));
|
|
|
|
|
|
|
|
QShader frag = getShader(QLatin1String(":/data/metal_enabled_tessellation_v7.frag.qsb"));
|
|
|
|
QVERIFY(frag.isValid());
|
|
|
|
QCOMPARE(QShaderPrivate::get(&frag)->qsbVersion, 7);
|
|
|
|
}
|
|
|
|
|
2022-12-07 03:52:59 +00:00
|
|
|
void tst_QShader::loadV8()
|
|
|
|
{
|
|
|
|
QShader s = getShader(QLatin1String(":/data/storage_buffer_info_v8.comp.qsb"));
|
|
|
|
QVERIFY(s.isValid());
|
|
|
|
QCOMPARE(QShaderPrivate::get(&s)->qsbVersion, 8);
|
|
|
|
|
|
|
|
const QList<QShaderKey> availableShaders = s.availableShaders();
|
|
|
|
QCOMPARE(availableShaders.size(), 5);
|
|
|
|
QVERIFY(availableShaders.contains(QShaderKey(QShader::SpirvShader, QShaderVersion(100))));
|
|
|
|
QVERIFY(availableShaders.contains(QShaderKey(QShader::MslShader, QShaderVersion(12))));
|
|
|
|
QVERIFY(availableShaders.contains(QShaderKey(QShader::HlslShader, QShaderVersion(50))));
|
|
|
|
QVERIFY(availableShaders.contains(
|
|
|
|
QShaderKey(QShader::GlslShader, QShaderVersion(310, QShaderVersion::GlslEs))));
|
|
|
|
QVERIFY(availableShaders.contains(QShaderKey(QShader::GlslShader, QShaderVersion(430))));
|
|
|
|
|
|
|
|
QCOMPARE(s.description().storageBlocks().size(), 1);
|
|
|
|
QCOMPARE(s.description().storageBlocks().last().runtimeArrayStride, 4);
|
|
|
|
QCOMPARE(s.description().storageBlocks().last().qualifierFlags,
|
|
|
|
QShaderDescription::QualifierFlags(QShaderDescription::QualifierWriteOnly
|
|
|
|
| QShaderDescription::QualifierRestrict));
|
|
|
|
}
|
|
|
|
|
2019-03-22 08:55:03 +00:00
|
|
|
#include <tst_qshader.moc>
|
|
|
|
QTEST_MAIN(tst_QShader)
|