diff options
author | Laszlo Agocs <laszlo.agocs@qt.io> | 2022-01-12 10:03:49 +0100 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2022-01-17 10:15:13 +0000 |
commit | 345e6432be0b3f05ba4db1caee2e685608a42953 (patch) | |
tree | 182f29f02e4084ec2ad72ed444f13ec1014ccb1c /tests | |
parent | 36009c8eece8b016601c01f5654b00f6430f1b7e (diff) |
ShaderEffect: Make uniform setting safer
...to better match the Qt 5 behavior. For example, trying to assign a
Qt.point() to a vec3 works in Qt 5, setting the 3rd component to 0,
because it just does a blind call to glUniform2fv. In Qt 6 this was not
done initially, and the data copy is based on the value's size, so
one either gets an assert in debug builds, and perhaps a crash or some
strange behavior in the shader in release. Make this safer.
The handling of QTransform->mat3 was broken as well, although it is
unlikely anyone ever used that in practice. Fix it so that we properly
map the 9 floats to the 4-float-per-column layout.
Change-Id: Ia4a24bff0e54d94ddb2f5db276f0ed0a2cde0efd
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
(cherry picked from commit c4f49a9e1f2c5a7819495f567f5ffe32d0eb468b)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/quick/qquickshadereffect/CMakeLists.txt | 3 | ||||
-rw-r--r-- | tests/auto/quick/qquickshadereffect/data/+qsb/testprop.frag | bin | 0 -> 1842 bytes | |||
-rw-r--r-- | tests/auto/quick/qquickshadereffect/data/compile.bat | 2 | ||||
-rw-r--r-- | tests/auto/quick/qquickshadereffect/data/testProperties.qml | 73 | ||||
-rw-r--r-- | tests/auto/quick/qquickshadereffect/data/testprop.frag | 28 | ||||
-rw-r--r-- | tests/auto/quick/qquickshadereffect/tst_qquickshadereffect.cpp | 11 |
6 files changed, 117 insertions, 0 deletions
diff --git a/tests/auto/quick/qquickshadereffect/CMakeLists.txt b/tests/auto/quick/qquickshadereffect/CMakeLists.txt index 100890ff5b..f8980d406d 100644 --- a/tests/auto/quick/qquickshadereffect/CMakeLists.txt +++ b/tests/auto/quick/qquickshadereffect/CMakeLists.txt @@ -21,6 +21,7 @@ set(resources_resource_files "data/+qsb/red.frag" "data/+qsb/test.frag" "data/+qsb/test.vert" + "data/+qsb/testprop.frag" "data/MyIcon.qml" "data/connections.qml" "data/deleteShaderEffectSource.qml" @@ -32,6 +33,8 @@ set(resources_resource_files "data/test.frag" "data/test.vert" "data/twoImagesOneShaderEffect.qml" + "data/testprop.frag" + "data/testProperties.qml" ) qt_internal_add_resource(tst_qquickshadereffect "resources" diff --git a/tests/auto/quick/qquickshadereffect/data/+qsb/testprop.frag b/tests/auto/quick/qquickshadereffect/data/+qsb/testprop.frag Binary files differnew file mode 100644 index 0000000000..97d2430699 --- /dev/null +++ b/tests/auto/quick/qquickshadereffect/data/+qsb/testprop.frag diff --git a/tests/auto/quick/qquickshadereffect/data/compile.bat b/tests/auto/quick/qquickshadereffect/data/compile.bat index 6b276aea69..112acfb1c0 100644 --- a/tests/auto/quick/qquickshadereffect/data/compile.bat +++ b/tests/auto/quick/qquickshadereffect/data/compile.bat @@ -2,3 +2,5 @@ qsb -b --glsl "150,120,100 es" --hlsl 50 --msl 12 -o +qsb/test.vert test_rhi.ver qsb --glsl "150,120,100 es" --hlsl 50 --msl 12 -o +qsb/red.frag red_rhi.frag qsb --glsl "150,120,100 es" --hlsl 50 --msl 12 -o +qsb/test.frag test_rhi.frag + +qsb --glsl "150,120,100 es" --hlsl 50 --msl 12 -o +qsb/testprop.frag testprop.frag diff --git a/tests/auto/quick/qquickshadereffect/data/testProperties.qml b/tests/auto/quick/qquickshadereffect/data/testProperties.qml new file mode 100644 index 0000000000..0f056d69c1 --- /dev/null +++ b/tests/auto/quick/qquickshadereffect/data/testProperties.qml @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** Copyright (C) 2022 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$ +** +****************************************************************************/ + +import QtQuick + +Item { + id: root + width: 640 + height: 480 + + property bool finished + + Rectangle { + id: rect + color: "red" + width: 300 + height: 300 + Text { + text: "Hello world" + anchors.centerIn: parent + color: "#00FF00" + } + layer.enabled: true + layer.effect: ShaderEffect { + objectName: "shaderEffect" + fragmentShader: "qrc:/data/testprop.frag" + + // This is intended to exercise the uniform data copy logic in + // QSGRhiShaderEffectMaterialShader::updateUniformData() to see if + // the undocumented combinations for passing in a vector with more + // components than the shader variable works, and no assertions or + // crashes occur. + + property variant aVec4: Qt.point(0.1, 0.0) // third and fourth are 0 + property variant aVec3: Qt.point(0.1, 0.5) // third will be 0 + property variant aVec2: Qt.vector4d(0.1, 0.5, 1.0, 1.0) // only first two are used + property real f: 0.0 + property variant aFloat: Qt.size(0.1 + f, 0.1) // only first is used + + NumberAnimation on f { + from: 0.0 + to: 1.0 + duration: 1000 + onFinished: root.finished = true + } + } + } +} diff --git a/tests/auto/quick/qquickshadereffect/data/testprop.frag b/tests/auto/quick/qquickshadereffect/data/testprop.frag new file mode 100644 index 0000000000..86f007bcb4 --- /dev/null +++ b/tests/auto/quick/qquickshadereffect/data/testprop.frag @@ -0,0 +1,28 @@ +#version 440 + +layout(location = 0) in vec2 qt_TexCoord0; +layout(location = 0) out vec4 fragColor; + +layout(binding = 1) uniform sampler2D source; + +layout(std140, binding = 0) uniform buf { + mat4 qt_Matrix; + float qt_Opacity; + vec4 aVec4; + vec3 aVec3; + vec2 aVec2; + float aFloat; +}; + +void main() +{ + vec4 c = texture(source, qt_TexCoord0); + vec4 v = aVec4; + v.rgb += aVec3; + v.rg += aVec2; + v.r += aFloat; + c *= v; + if (c.a == 0.0) + c.a = 1.0; + fragColor = c * qt_Opacity; +} diff --git a/tests/auto/quick/qquickshadereffect/tst_qquickshadereffect.cpp b/tests/auto/quick/qquickshadereffect/tst_qquickshadereffect.cpp index 176001b599..c7619ab73c 100644 --- a/tests/auto/quick/qquickshadereffect/tst_qquickshadereffect.cpp +++ b/tests/auto/quick/qquickshadereffect/tst_qquickshadereffect.cpp @@ -90,6 +90,7 @@ private slots: void withoutQmlEngine(); void hideParent(); + void testPropertyMappings(); private: enum PresenceFlags { @@ -199,6 +200,16 @@ void tst_qquickshadereffect::hideParent() QTRY_VERIFY(view->rootObject()->property("finished").toBool()); } +void tst_qquickshadereffect::testPropertyMappings() +{ + QScopedPointer<QQuickView> view(new QQuickView); + view->setSource(QUrl(QStringLiteral("qrc:/data/testProperties.qml"))); + QCOMPARE(view->status(), QQuickView::Ready); + view->show(); + QVERIFY(QTest::qWaitForWindowExposed(view.data())); + QTRY_VERIFY(view->rootObject()->property("finished").toBool()); +} + QTEST_MAIN(tst_qquickshadereffect) #include "tst_qquickshadereffect.moc" |