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>
This commit is contained in:
Alessandro Portale
2021-07-27 18:37:35 +02:00
parent 84a0170516
commit 21cb0711c4
12 changed files with 360 additions and 22 deletions

View File

@@ -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"

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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