summaryrefslogtreecommitdiffstats
path: root/tests/auto/gui/rhi
diff options
context:
space:
mode:
authorLaszlo Agocs <laszlo.agocs@qt.io>2019-03-22 09:55:03 +0100
committerLaszlo Agocs <laszlo.agocs@qt.io>2019-06-13 10:13:45 +0200
commit53599592e09edd215bfa1eaa7e6f3a9f3fc50ae6 (patch)
tree1083ec3a18030bb6f09de58b2fe0ac1cb8aedc0b /tests/auto/gui/rhi
parentc143161608ded130919006f151bf92c44a0991d0 (diff)
Introduce the Qt graphics abstraction as private QtGui helpers
Comes with backends for Vulkan, Metal, Direct3D 11.1, and OpenGL (ES). All APIs are private for now. Shader conditioning (i.e. generating a QRhiShader in memory or on disk from some shader source code) is done via the tools and APIs provided by qt-labs/qtshadertools. The OpenGL support follows the cross-platform tradition of requiring ES 2.0 only, while optionally using some (ES) 3.x features. It can operate in core profile contexts as well. Task-number: QTBUG-70287 Change-Id: I246f2e36d562e404012c05db2aa72487108aa7cc Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'tests/auto/gui/rhi')
-rw-r--r--tests/auto/gui/rhi/qrhi/data/texture.frag12
-rw-r--r--tests/auto/gui/rhi/qrhi/data/texture.vert18
-rw-r--r--tests/auto/gui/rhi/qrhi/qrhi.pro8
-rw-r--r--tests/auto/gui/rhi/qrhi/qrhi.qrc5
-rw-r--r--tests/auto/gui/rhi/qrhi/tst_qrhi.cpp246
-rw-r--r--tests/auto/gui/rhi/qshader/data/color.vert18
-rw-r--r--tests/auto/gui/rhi/qshader/data/color.vert.qsbbin0 -> 1847 bytes
-rw-r--r--tests/auto/gui/rhi/qshader/data/color_simple.vert.qsbbin0 -> 813 bytes
-rw-r--r--tests/auto/gui/rhi/qshader/qshader.pro8
-rw-r--r--tests/auto/gui/rhi/qshader/qshader.qrc5
-rw-r--r--tests/auto/gui/rhi/qshader/tst_qshader.cpp233
-rw-r--r--tests/auto/gui/rhi/rhi.pro4
12 files changed, 557 insertions, 0 deletions
diff --git a/tests/auto/gui/rhi/qrhi/data/texture.frag b/tests/auto/gui/rhi/qrhi/data/texture.frag
new file mode 100644
index 0000000000..e6021fe905
--- /dev/null
+++ b/tests/auto/gui/rhi/qrhi/data/texture.frag
@@ -0,0 +1,12 @@
+#version 440
+
+layout(location = 0) in vec2 v_texcoord;
+
+layout(location = 0) out vec4 fragColor;
+
+layout(binding = 1) uniform sampler2D tex;
+
+void main()
+{
+ fragColor = texture(tex, v_texcoord);
+}
diff --git a/tests/auto/gui/rhi/qrhi/data/texture.vert b/tests/auto/gui/rhi/qrhi/data/texture.vert
new file mode 100644
index 0000000000..de486cb772
--- /dev/null
+++ b/tests/auto/gui/rhi/qrhi/data/texture.vert
@@ -0,0 +1,18 @@
+#version 440
+
+layout(location = 0) in vec4 position;
+layout(location = 1) in vec2 texcoord;
+
+layout(location = 0) out vec2 v_texcoord;
+
+layout(std140, binding = 0) uniform buf {
+ mat4 mvp;
+} ubuf;
+
+out gl_PerVertex { vec4 gl_Position; };
+
+void main()
+{
+ v_texcoord = texcoord;
+ gl_Position = ubuf.mvp * position;
+}
diff --git a/tests/auto/gui/rhi/qrhi/qrhi.pro b/tests/auto/gui/rhi/qrhi/qrhi.pro
new file mode 100644
index 0000000000..58000ed514
--- /dev/null
+++ b/tests/auto/gui/rhi/qrhi/qrhi.pro
@@ -0,0 +1,8 @@
+TARGET = tst_qrhi
+CONFIG += testcase
+
+QT += testlib gui-private
+
+SOURCES += tst_qrhi.cpp
+
+RESOURCES += qrhi.qrc
diff --git a/tests/auto/gui/rhi/qrhi/qrhi.qrc b/tests/auto/gui/rhi/qrhi/qrhi.qrc
new file mode 100644
index 0000000000..f161d8aad6
--- /dev/null
+++ b/tests/auto/gui/rhi/qrhi/qrhi.qrc
@@ -0,0 +1,5 @@
+<RCC>
+ <qresource prefix="/">
+ <file>data</file>
+ </qresource>
+</RCC>
diff --git a/tests/auto/gui/rhi/qrhi/tst_qrhi.cpp b/tests/auto/gui/rhi/qrhi/tst_qrhi.cpp
new file mode 100644
index 0000000000..897613d525
--- /dev/null
+++ b/tests/auto/gui/rhi/qrhi/tst_qrhi.cpp
@@ -0,0 +1,246 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtTest/QtTest>
+#include <QThread>
+#include <QFile>
+#include <QOffscreenSurface>
+#include <QtGui/private/qrhi_p.h>
+#include <QtGui/private/qrhinull_p.h>
+
+#if QT_CONFIG(opengl)
+# include <QtGui/private/qrhigles2_p.h>
+# define TST_GL
+#endif
+
+#if QT_CONFIG(vulkan)
+# include <QVulkanInstance>
+# include <QtGui/private/qrhivulkan_p.h>
+# define TST_VK
+#endif
+
+#ifdef Q_OS_WIN
+#include <QtGui/private/qrhid3d11_p.h>
+# define TST_D3D11
+#endif
+
+#ifdef Q_OS_DARWIN
+# include <QtGui/private/qrhimetal_p.h>
+# define TST_MTL
+#endif
+
+Q_DECLARE_METATYPE(QRhi::Implementation)
+Q_DECLARE_METATYPE(QRhiInitParams *)
+
+class tst_QRhi : public QObject
+{
+ Q_OBJECT
+
+private slots:
+ void initTestCase();
+ void cleanupTestCase();
+
+ void create_data();
+ void create();
+
+private:
+ struct {
+ QRhiNullInitParams null;
+#ifdef TST_GL
+ QRhiGles2InitParams gl;
+#endif
+#ifdef TST_VK
+ QRhiVulkanInitParams vk;
+#endif
+#ifdef TST_D3D11
+ QRhiD3D11InitParams d3d;
+#endif
+#ifdef TST_MTL
+ QRhiMetalInitParams mtl;
+#endif
+ } initParams;
+
+#ifdef TST_VK
+ QVulkanInstance vulkanInstance;
+#endif
+ QOffscreenSurface *fallbackSurface = nullptr;
+};
+
+void tst_QRhi::initTestCase()
+{
+#ifdef TST_GL
+ fallbackSurface = QRhiGles2InitParams::newFallbackSurface();
+ initParams.gl.fallbackSurface = fallbackSurface;
+#endif
+
+#ifdef TST_VK
+ vulkanInstance.create();
+ initParams.vk.inst = &vulkanInstance;
+#endif
+}
+
+void tst_QRhi::cleanupTestCase()
+{
+#ifdef TST_VK
+ vulkanInstance.destroy();
+#endif
+
+ delete fallbackSurface;
+}
+
+void tst_QRhi::create_data()
+{
+ QTest::addColumn<QRhi::Implementation>("impl");
+ QTest::addColumn<QRhiInitParams *>("initParams");
+
+ QTest::newRow("Null") << QRhi::Null << static_cast<QRhiInitParams *>(&initParams.null);
+#ifdef TST_GL
+ QTest::newRow("OpenGL") << QRhi::OpenGLES2 << static_cast<QRhiInitParams *>(&initParams.gl);
+#endif
+#ifdef TST_VK
+ if (vulkanInstance.isValid())
+ QTest::newRow("Vulkan") << QRhi::Vulkan << static_cast<QRhiInitParams *>(&initParams.vk);
+#endif
+#ifdef TST_D3D11
+ QTest::newRow("Direct3D 11") << QRhi::D3D11 << static_cast<QRhiInitParams *>(&initParams.d3d);
+#endif
+#ifdef TST_MTL
+ QTest::newRow("Metal") << QRhi::Metal << static_cast<QRhiInitParams *>(&initParams.mtl);
+#endif
+}
+
+static int aligned(int v, int a)
+{
+ return (v + a - 1) & ~(a - 1);
+}
+
+void tst_QRhi::create()
+{
+ // Merely attempting to create a QRhi should survive, with an error when
+ // not supported. (of course, there is always a chance we encounter a crash
+ // due to some random graphics stack...)
+
+ QFETCH(QRhi::Implementation, impl);
+ QFETCH(QRhiInitParams *, initParams);
+
+ QScopedPointer<QRhi> rhi(QRhi::create(impl, initParams, QRhi::Flags(), nullptr));
+
+ if (rhi) {
+ QCOMPARE(rhi->backend(), impl);
+ QCOMPARE(rhi->thread(), QThread::currentThread());
+
+ int cleanupOk = 0;
+ QRhi *rhiPtr = rhi.data();
+ auto cleanupFunc = [rhiPtr, &cleanupOk](QRhi *dyingRhi) {
+ if (rhiPtr == dyingRhi)
+ cleanupOk += 1;
+ };
+ rhi->addCleanupCallback(cleanupFunc);
+ rhi->runCleanup();
+ QCOMPARE(cleanupOk, 1);
+ cleanupOk = 0;
+ rhi->addCleanupCallback(cleanupFunc);
+
+ QRhiResourceUpdateBatch *resUpd = rhi->nextResourceUpdateBatch();
+ QVERIFY(resUpd);
+ resUpd->release();
+
+ QVERIFY(!rhi->supportedSampleCounts().isEmpty());
+ QVERIFY(rhi->supportedSampleCounts().contains(1));
+
+ QVERIFY(rhi->ubufAlignment() > 0);
+ QCOMPARE(rhi->ubufAligned(123), aligned(123, rhi->ubufAlignment()));
+
+ QCOMPARE(rhi->mipLevelsForSize(QSize(512, 300)), 10);
+ QCOMPARE(rhi->sizeForMipLevel(0, QSize(512, 300)), QSize(512, 300));
+ QCOMPARE(rhi->sizeForMipLevel(1, QSize(512, 300)), QSize(256, 150));
+ QCOMPARE(rhi->sizeForMipLevel(2, QSize(512, 300)), QSize(128, 75));
+ QCOMPARE(rhi->sizeForMipLevel(9, QSize(512, 300)), QSize(1, 1));
+
+ const bool fbUp = rhi->isYUpInFramebuffer();
+ const bool ndcUp = rhi->isYUpInNDC();
+ const bool d0to1 = rhi->isClipDepthZeroToOne();
+ const QMatrix4x4 corrMat = rhi->clipSpaceCorrMatrix();
+ if (impl == QRhi::OpenGLES2) {
+ QVERIFY(fbUp);
+ QVERIFY(ndcUp);
+ QVERIFY(!d0to1);
+ QVERIFY(corrMat.isIdentity());
+ } else if (impl == QRhi::Vulkan) {
+ QVERIFY(!fbUp);
+ QVERIFY(!ndcUp);
+ QVERIFY(d0to1);
+ QVERIFY(!corrMat.isIdentity());
+ } else if (impl == QRhi::D3D11) {
+ QVERIFY(!fbUp);
+ QVERIFY(ndcUp);
+ QVERIFY(d0to1);
+ QVERIFY(!corrMat.isIdentity());
+ } else if (impl == QRhi::Metal) {
+ QVERIFY(!fbUp);
+ QVERIFY(ndcUp);
+ QVERIFY(d0to1);
+ QVERIFY(!corrMat.isIdentity());
+ }
+
+ const int texMin = rhi->resourceLimit(QRhi::TextureSizeMin);
+ const int texMax = rhi->resourceLimit(QRhi::TextureSizeMax);
+ const int maxAtt = rhi->resourceLimit(QRhi::MaxColorAttachments);
+ QVERIFY(texMin >= 1);
+ QVERIFY(texMax >= texMin);
+ QVERIFY(maxAtt >= 1);
+
+ QVERIFY(rhi->nativeHandles());
+ QVERIFY(rhi->profiler());
+
+ const QRhi::Feature features[] = {
+ QRhi::MultisampleTexture,
+ QRhi::MultisampleRenderBuffer,
+ QRhi::DebugMarkers,
+ QRhi::Timestamps,
+ QRhi::Instancing,
+ QRhi::CustomInstanceStepRate,
+ QRhi::PrimitiveRestart,
+ QRhi::NonDynamicUniformBuffers,
+ QRhi::NonFourAlignedEffectiveIndexBufferOffset,
+ QRhi::NPOTTextureRepeat,
+ QRhi::RedOrAlpha8IsRed,
+ QRhi::ElementIndexUint
+ };
+ for (size_t i = 0; i <sizeof(features) / sizeof(QRhi::Feature); ++i)
+ rhi->isFeatureSupported(features[i]);
+
+ QVERIFY(rhi->isTextureFormatSupported(QRhiTexture::RGBA8));
+
+ rhi.reset();
+ QCOMPARE(cleanupOk, 1);
+ }
+}
+
+#include <tst_qrhi.moc>
+QTEST_MAIN(tst_QRhi)
diff --git a/tests/auto/gui/rhi/qshader/data/color.vert b/tests/auto/gui/rhi/qshader/data/color.vert
new file mode 100644
index 0000000000..c92f71b9e1
--- /dev/null
+++ b/tests/auto/gui/rhi/qshader/data/color.vert
@@ -0,0 +1,18 @@
+#version 440
+
+layout(location = 0) in vec4 position;
+layout(location = 1) in vec3 color;
+layout(location = 0) out vec3 v_color;
+
+layout(std140, binding = 0) uniform buf {
+ mat4 mvp;
+ float opacity;
+} ubuf;
+
+out gl_PerVertex { vec4 gl_Position; };
+
+void main()
+{
+ v_color = color;
+ gl_Position = ubuf.mvp * position;
+}
diff --git a/tests/auto/gui/rhi/qshader/data/color.vert.qsb b/tests/auto/gui/rhi/qshader/data/color.vert.qsb
new file mode 100644
index 0000000000..7d02d823d2
--- /dev/null
+++ b/tests/auto/gui/rhi/qshader/data/color.vert.qsb
Binary files differ
diff --git a/tests/auto/gui/rhi/qshader/data/color_simple.vert.qsb b/tests/auto/gui/rhi/qshader/data/color_simple.vert.qsb
new file mode 100644
index 0000000000..c82ba7e8e7
--- /dev/null
+++ b/tests/auto/gui/rhi/qshader/data/color_simple.vert.qsb
Binary files differ
diff --git a/tests/auto/gui/rhi/qshader/qshader.pro b/tests/auto/gui/rhi/qshader/qshader.pro
new file mode 100644
index 0000000000..5d9ef8304d
--- /dev/null
+++ b/tests/auto/gui/rhi/qshader/qshader.pro
@@ -0,0 +1,8 @@
+TARGET = tst_qshader
+CONFIG += testcase
+
+QT += testlib gui-private
+
+SOURCES += tst_qshader.cpp
+
+RESOURCES += qshader.qrc
diff --git a/tests/auto/gui/rhi/qshader/qshader.qrc b/tests/auto/gui/rhi/qshader/qshader.qrc
new file mode 100644
index 0000000000..f161d8aad6
--- /dev/null
+++ b/tests/auto/gui/rhi/qshader/qshader.qrc
@@ -0,0 +1,5 @@
+<RCC>
+ <qresource prefix="/">
+ <file>data</file>
+ </qresource>
+</RCC>
diff --git a/tests/auto/gui/rhi/qshader/tst_qshader.cpp b/tests/auto/gui/rhi/qshader/tst_qshader.cpp
new file mode 100644
index 0000000000..21f0cc7895
--- /dev/null
+++ b/tests/auto/gui/rhi/qshader/tst_qshader.cpp
@@ -0,0 +1,233 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtTest/QtTest>
+#include <QFile>
+#include <QtGui/private/qshaderdescription_p_p.h>
+#include <QtGui/private/qshader_p_p.h>
+
+class tst_QShader : public QObject
+{
+ Q_OBJECT
+
+private slots:
+ void simpleCompileCheckResults();
+ void genVariants();
+ void shaderDescImplicitSharing();
+ void bakedShaderImplicitSharing();
+};
+
+static QShader getShader(const QString &name)
+{
+ QFile f(name);
+ if (f.open(QIODevice::ReadOnly))
+ return QShader::fromSerialized(f.readAll());
+
+ return QShader();
+}
+
+void tst_QShader::simpleCompileCheckResults()
+{
+ QShader s = getShader(QLatin1String(":/data/color_simple.vert.qsb"));
+ QVERIFY(s.isValid());
+ QCOMPARE(s.availableShaders().count(), 1);
+
+ 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());
+ QCOMPARE(desc.inputVariables().count(), 2);
+ for (const QShaderDescription::InOutVariable &v : desc.inputVariables()) {
+ switch (v.location) {
+ case 0:
+ QCOMPARE(v.name, QLatin1String("position"));
+ QCOMPARE(v.type, QShaderDescription::Vec4);
+ break;
+ case 1:
+ QCOMPARE(v.name, QLatin1String("color"));
+ QCOMPARE(v.type, QShaderDescription::Vec3);
+ break;
+ default:
+ QVERIFY(false);
+ break;
+ }
+ }
+ QCOMPARE(desc.outputVariables().count(), 1);
+ for (const QShaderDescription::InOutVariable &v : desc.outputVariables()) {
+ switch (v.location) {
+ case 0:
+ QCOMPARE(v.name, QLatin1String("v_color"));
+ QCOMPARE(v.type, QShaderDescription::Vec3);
+ break;
+ default:
+ QVERIFY(false);
+ break;
+ }
+ }
+ QCOMPARE(desc.uniformBlocks().count(), 1);
+ const QShaderDescription::UniformBlock blk = desc.uniformBlocks().first();
+ QCOMPARE(blk.blockName, QLatin1String("buf"));
+ QCOMPARE(blk.structName, QLatin1String("ubuf"));
+ QCOMPARE(blk.size, 68);
+ QCOMPARE(blk.binding, 0);
+ QCOMPARE(blk.descriptorSet, 0);
+ QCOMPARE(blk.members.count(), 2);
+ for (int i = 0; i < blk.members.count(); ++i) {
+ const QShaderDescription::BlockVariable v = blk.members[i];
+ switch (i) {
+ case 0:
+ QCOMPARE(v.offset, 0);
+ QCOMPARE(v.size, 64);
+ QCOMPARE(v.name, QLatin1String("mvp"));
+ QCOMPARE(v.type, QShaderDescription::Mat4);
+ QCOMPARE(v.matrixStride, 16);
+ break;
+ case 1:
+ QCOMPARE(v.offset, 64);
+ QCOMPARE(v.size, 4);
+ QCOMPARE(v.name, QLatin1String("opacity"));
+ QCOMPARE(v.type, QShaderDescription::Float);
+ break;
+ default:
+ QVERIFY(false);
+ break;
+ }
+ }
+}
+
+void tst_QShader::genVariants()
+{
+ QShader s = getShader(QLatin1String(":/data/color.vert.qsb"));
+ // spirv, glsl 100, glsl 330, glsl 120, hlsl 50, msl 12
+ // + batchable variants
+ QVERIFY(s.isValid());
+ QCOMPARE(s.availableShaders().count(), 2 * 6);
+
+ 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()
+{
+ QShader s = getShader(QLatin1String(":/data/color_simple.vert.qsb"));
+ QVERIFY(s.isValid());
+ QCOMPARE(s.availableShaders().count(), 1);
+ QVERIFY(s.availableShaders().contains(QShaderKey(QShader::SpirvShader, QShaderVersion(100))));
+
+ QShaderDescription d0 = s.description();
+ QVERIFY(d0.isValid());
+ QCOMPARE(d0.inputVariables().count(), 2);
+ QCOMPARE(d0.outputVariables().count(), 1);
+ QCOMPARE(d0.uniformBlocks().count(), 1);
+
+ QShaderDescription d1 = d0;
+ QVERIFY(QShaderDescriptionPrivate::get(&d0) == QShaderDescriptionPrivate::get(&d1));
+ QCOMPARE(d0.inputVariables().count(), 2);
+ QCOMPARE(d0.outputVariables().count(), 1);
+ QCOMPARE(d0.uniformBlocks().count(), 1);
+ QCOMPARE(d1.inputVariables().count(), 2);
+ QCOMPARE(d1.outputVariables().count(), 1);
+ QCOMPARE(d1.uniformBlocks().count(), 1);
+
+ d1.detach();
+ QVERIFY(QShaderDescriptionPrivate::get(&d0) != QShaderDescriptionPrivate::get(&d1));
+ QCOMPARE(d0.inputVariables().count(), 2);
+ QCOMPARE(d0.outputVariables().count(), 1);
+ QCOMPARE(d0.uniformBlocks().count(), 1);
+ QCOMPARE(d1.inputVariables().count(), 2);
+ QCOMPARE(d1.outputVariables().count(), 1);
+ QCOMPARE(d1.uniformBlocks().count(), 1);
+}
+
+void tst_QShader::bakedShaderImplicitSharing()
+{
+ QShader s0 = getShader(QLatin1String(":/data/color_simple.vert.qsb"));
+ QVERIFY(s0.isValid());
+ QCOMPARE(s0.availableShaders().count(), 1);
+ QVERIFY(s0.availableShaders().contains(QShaderKey(QShader::SpirvShader, QShaderVersion(100))));
+
+ {
+ QShader s1 = s0;
+ QVERIFY(QShaderPrivate::get(&s0) == QShaderPrivate::get(&s1));
+ QCOMPARE(s0.availableShaders().count(), 1);
+ QVERIFY(s0.availableShaders().contains(QShaderKey(QShader::SpirvShader, QShaderVersion(100))));
+ QCOMPARE(s1.availableShaders().count(), 1);
+ 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));
+ QCOMPARE(s0.availableShaders().count(), 1);
+ QVERIFY(s0.availableShaders().contains(QShaderKey(QShader::SpirvShader, QShaderVersion(100))));
+ QCOMPARE(s1.availableShaders().count(), 1);
+ 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));
+ QCOMPARE(s0.availableShaders().count(), 1);
+ QVERIFY(s0.availableShaders().contains(QShaderKey(QShader::SpirvShader, QShaderVersion(100))));
+ QCOMPARE(s1.availableShaders().count(), 1);
+ QVERIFY(s1.availableShaders().contains(QShaderKey(QShader::SpirvShader, QShaderVersion(100))));
+ QShaderDescription d0 = s0.description();
+ QCOMPARE(d0.inputVariables().count(), 2);
+ QCOMPARE(d0.outputVariables().count(), 1);
+ QCOMPARE(d0.uniformBlocks().count(), 1);
+ QShaderDescription d1 = s1.description();
+ QCOMPARE(d1.inputVariables().count(), 2);
+ QCOMPARE(d1.outputVariables().count(), 1);
+ QCOMPARE(d1.uniformBlocks().count(), 1);
+ QVERIFY(s0 != s1);
+ }
+}
+
+#include <tst_qshader.moc>
+QTEST_MAIN(tst_QShader)
diff --git a/tests/auto/gui/rhi/rhi.pro b/tests/auto/gui/rhi/rhi.pro
new file mode 100644
index 0000000000..cc548b7b8a
--- /dev/null
+++ b/tests/auto/gui/rhi/rhi.pro
@@ -0,0 +1,4 @@
+TEMPLATE=subdirs
+SUBDIRS= \
+ qshader \
+ qrhi