diff options
author | Alessandro Portale <alessandro.portale@qt.io> | 2021-07-27 18:37:35 +0200 |
---|---|---|
committer | Alessandro Portale <alessandro.portale@qt.io> | 2021-08-11 08:05:22 +0000 |
commit | 21cb0711c4d9bbd9d5d4b32899bf037dc8f1f4db (patch) | |
tree | 12b5d3aa88be31c3caa79b320238d4b73492d900 /src/plugins/qmlprofiler | |
parent | 84a017051693bab44a96f92fb4fd3f0c60264800 (diff) |
Tracing/QmlProfiler: Port shaders to Qt 6
For each shader in Tracing and QmlProfiler:
- Add a vert/frag variant in Vulkan style GLSL
- Include the shader via qt_add_shaders
- Implement RHI/Qt6-specific code for loading the shaders and for
updating the uniform buffer
- Set the material's QSGMaterial::CustomCompileStep flag to affect the z
value the same way as the Qt 5 code does
Building of Tracing, QmlProfiler, etc. with Qt 6 depends on the Qt
Shader tools being installed.
Fixes: QTCREATORBUG-20575
Change-Id: I9aba5a777da9a549da0cdd0a217dfcb346c72e58
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
Diffstat (limited to 'src/plugins/qmlprofiler')
-rw-r--r-- | src/plugins/qmlprofiler/CMakeLists.txt | 19 | ||||
-rw-r--r-- | src/plugins/qmlprofiler/qml/bindingloops_qt6.frag | 36 | ||||
-rw-r--r-- | src/plugins/qmlprofiler/qml/bindingloops_qt6.vert | 46 | ||||
-rw-r--r-- | src/plugins/qmlprofiler/qmlprofilerbindingloopsrenderpass.cpp | 23 |
4 files changed, 114 insertions, 10 deletions
diff --git a/src/plugins/qmlprofiler/CMakeLists.txt b/src/plugins/qmlprofiler/CMakeLists.txt index aee047a576d..e22bb1768f4 100644 --- a/src/plugins/qmlprofiler/CMakeLists.txt +++ b/src/plugins/qmlprofiler/CMakeLists.txt @@ -79,7 +79,10 @@ if(${Qt5_VERSION} VERSION_LESS "6.2.0") qml/qmlprofiler.qrc ) else() # < Qt 6.2 + find_package(Qt6 COMPONENTS ShaderTools QUIET) + add_qtc_plugin(QmlProfiler + CONDITION TARGET Tracing AND TARGET Qt6::ShaderTools DEPENDS QmlDebug QmlJS Tracing Qt5::QuickWidgets PLUGIN_DEPENDS Core Debugger ProjectExplorer QtSupport TextEditor SOURCES @@ -94,16 +97,20 @@ else() # < Qt 6.2 qml/QmlProfilerFlameGraphView.qml ) - set(QMLPROFILER_QML_RESOURCES - qml/bindingloops.frag - qml/bindingloops.vert - ) - - foreach(file IN LISTS QMLPROFILER_QML_FILES QMLPROFILER_QML_RESOURCES) + foreach(file IN LISTS QMLPROFILER_QML_FILES) get_filename_component(fileName "${file}" NAME) set_source_files_properties("${file}" PROPERTIES QT_RESOURCE_ALIAS "${fileName}") endforeach() + qt_add_shaders(QmlProfiler "res_qmlprofilershaders" + BATCHABLE + PREFIX + "/QtCreator/QmlProfiler" + FILES + qml/bindingloops_qt6.frag + qml/bindingloops_qt6.vert + ) + qt_add_qml_module(QmlProfiler URI "QtCreator.QmlProfiler" VERSION "1.0" diff --git a/src/plugins/qmlprofiler/qml/bindingloops_qt6.frag b/src/plugins/qmlprofiler/qml/bindingloops_qt6.frag new file mode 100644 index 00000000000..73e48b3c5de --- /dev/null +++ b/src/plugins/qmlprofiler/qml/bindingloops_qt6.frag @@ -0,0 +1,36 @@ +/**************************************************************************** +** +** Copyright (C) 2021 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt Creator. +** +** 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. +** +****************************************************************************/ + +#version 440 + +layout (location = 0) in vec4 color; + +layout (location = 0) out vec4 fragColor; + +void main() +{ + fragColor.rgb = color.rgb; + fragColor.a = 1.0; +} diff --git a/src/plugins/qmlprofiler/qml/bindingloops_qt6.vert b/src/plugins/qmlprofiler/qml/bindingloops_qt6.vert new file mode 100644 index 00000000000..da1f4279d1a --- /dev/null +++ b/src/plugins/qmlprofiler/qml/bindingloops_qt6.vert @@ -0,0 +1,46 @@ +/**************************************************************************** +** +** Copyright (C) 2021 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt Creator. +** +** 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. +** +****************************************************************************/ + +#version 440 + +layout (location = 0) in vec4 vertexCoord; +layout (location = 1) in vec2 postScaleOffset; + +layout (std140, binding = 0) uniform Block { + uniform mat4 matrix; + uniform vec4 bindingLoopsColor; +} block; + +layout (location = 0) out vec4 color; + +void main() +{ + gl_Position = block.matrix * vertexCoord; + gl_Position.x += postScaleOffset.x * 0.005; + gl_Position.y += postScaleOffset.y * 0.01; + gl_Position.z -= 0.1; + gl_Position.w = 1.0; + color = block.bindingLoopsColor; +} diff --git a/src/plugins/qmlprofiler/qmlprofilerbindingloopsrenderpass.cpp b/src/plugins/qmlprofiler/qmlprofilerbindingloopsrenderpass.cpp index 2d2f11fe110..edcc9d6361e 100644 --- a/src/plugins/qmlprofiler/qmlprofilerbindingloopsrenderpass.cpp +++ b/src/plugins/qmlprofiler/qmlprofilerbindingloopsrenderpass.cpp @@ -326,8 +326,8 @@ BindingLoopMaterialShader::BindingLoopMaterialShader() setShaderSourceFile(QOpenGLShader::Fragment, QStringLiteral(":/QtCreator/QmlProfiler/bindingloops.frag")); #else // < Qt 6 - setShaderFileName(VertexStage, ":/QtCreator/QmlProfiler/bindingloops.vert"); - setShaderFileName(FragmentStage, ":/QtCreator/QmlProfiler/bindingloops.frag"); + setShaderFileName(VertexStage, ":/QtCreator/QmlProfiler/bindingloops_qt6.vert.qsb"); + setShaderFileName(FragmentStage, ":/QtCreator/QmlProfiler/bindingloops_qt6.frag.qsb"); #endif // < Qt 6 } @@ -348,8 +348,20 @@ void BindingLoopMaterialShader::updateState(const RenderState &state, QSGMateria #else // < Qt 6 bool BindingLoopMaterialShader::updateUniformData(RenderState &state, QSGMaterial *, QSGMaterial *) { - // TODO: Make this work - return state.isMatrixDirty(); + QByteArray *buf = state.uniformData(); + + // mat4 matrix + if (state.isMatrixDirty()) { + const QMatrix4x4 m = state.combinedMatrix(); + memcpy(buf->data(), m.constData(), 64); + } + + // vec4 bindingLoopsColor + const QColor color = bindingLoopsColor(); + const float colorArray[] = { color.redF(), color.greenF(), color.blueF(), color.alphaF() }; + memcpy(buf->data() + 64, colorArray, 16); + + return true; } #endif // < Qt 6 @@ -371,6 +383,9 @@ void BindingLoopMaterialShader::initialize() BindingLoopMaterial::BindingLoopMaterial() { setFlag(QSGMaterial::Blending, false); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + setFlag(QSGMaterial::CustomCompileStep, true); +#endif // >= Qt 6 } QSGMaterialType *BindingLoopMaterial::type() const |