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

@@ -43,7 +43,10 @@ if(${Qt5_VERSION} VERSION_LESS "6.2.0")
qml/tracing.qrc qml/tracing.qrc
) )
else() # < Qt 6.2 else() # < Qt 6.2
find_package(Qt6 COMPONENTS ShaderTools QUIET)
add_qtc_library(Tracing add_qtc_library(Tracing
CONDITION TARGET Qt6::ShaderTools
FEATURE_INFO FEATURE_INFO
DEPENDS Utils Qt5::Qml Qt5::Quick DEPENDS Utils Qt5::Qml Qt5::Quick
PUBLIC_DEPENDS Qt5::Widgets PUBLIC_DEPENDS Qt5::Widgets
@@ -86,12 +89,8 @@ else() # < Qt 6.2
qml/ico_rangeselection@2x.png qml/ico_rangeselection@2x.png
qml/ico_selectionmode.png qml/ico_selectionmode.png
qml/ico_selectionmode@2x.png qml/ico_selectionmode@2x.png
qml/notes.frag
qml/notes.vert
qml/range_handle.png qml/range_handle.png
qml/range_handle@2.png qml/range_handle@2.png
qml/timelineitems.frag
qml/timelineitems.vert
) )
foreach(file IN LISTS TRACING_QML_FILES TRACING_QML_RESOURCES) foreach(file IN LISTS TRACING_QML_FILES TRACING_QML_RESOURCES)
@@ -99,6 +98,17 @@ else() # < Qt 6.2
set_source_files_properties("${file}" PROPERTIES QT_RESOURCE_ALIAS "${fileName}") set_source_files_properties("${file}" PROPERTIES QT_RESOURCE_ALIAS "${fileName}")
endforeach() endforeach()
qt_add_shaders(Tracing "res_tracingshaders"
BATCHABLE
PREFIX
"/QtCreator/Tracing"
FILES
qml/notes_qt6.vert
qml/notes_qt6.frag
qml/timelineitems_qt6.vert
qml/timelineitems_qt6.frag
)
qt_add_qml_module(Tracing qt_add_qml_module(Tracing
URI "QtCreator.Tracing" URI "QtCreator.Tracing"
VERSION "1.0" 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 = 1) in float d;
layout (location = 0) out vec4 fragColor;
void main()
{
fragColor = color * float(d < (2.0 / 3.0) || d > (5.0 / 6.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 float distanceFromTop;
layout (std140, binding = 0) uniform Block {
mat4 matrix;
vec4 notesColor;
} block;
layout (location = 0) out vec4 color;
layout (location = 1) out float d;
void main()
{
gl_Position = block.matrix * vertexCoord;
gl_Position.z -= 0.1;
gl_Position.w = 1.0;
color = block.notesColor;
d = distanceFromTop;
}

View File

@@ -0,0 +1,43 @@
/****************************************************************************
**
** 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 vec3 color;
layout (location = 1) in vec3 edgeColor;
layout (location = 2) in vec2 barycentric;
layout (location = 0) out vec4 fragColor;
void main()
{
lowp vec2 d = fwidth(barycentric) * 4.0;
lowp vec4 edge_closeness = step(vec4(d.x, d.y, d.x, d.y),
vec4(barycentric.x, barycentric.y, 1.0 - barycentric.x, 1.0 - barycentric.y));
lowp float total = min(min(edge_closeness[0], edge_closeness[1]),
min(edge_closeness[2], edge_closeness[3]));
fragColor.rgb = mix(edgeColor, color, total);
fragColor.a = 1.0;
}

View File

@@ -0,0 +1,63 @@
/****************************************************************************
**
** 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 rectSize;
layout (location = 2) in float selectionId;
layout (location = 3) in vec4 vertexColor;
layout (std140, binding = 0) uniform Block {
mat4 matrix;
vec2 scale;
vec4 selectionColor;
float selectedItem;
} block;
layout (location = 0) out vec3 color;
layout (location = 1) out vec3 edgeColor;
layout (location = 2) out vec2 barycentric;
void main()
{
gl_Position = block.matrix * vertexCoord;
// Make very narrow events somewhat wider so that they don't collapse into 0 pixels
float scaledWidth = block.scale.x * rectSize.x;
float shift = sign(rectSize.x) * max(0.0, 3.0 - abs(scaledWidth)) * 0.0005;
gl_Position.x += shift;
// Ditto for events with very small height
float scaledHeight = block.scale.y * rectSize.y;
gl_Position.y += float(rectSize.y > 0.0) * max(0.0, 3.0 - scaledHeight) * 0.003;
barycentric = vec2(rectSize.x > 0.0 ? 1.0 : 0.0, rectSize.y > 0.0 ? 1.0 : 0.0);
color = vertexColor.rgb;
float selected = min(abs(selectionId - block.selectedItem), 1.0);
edgeColor.rgb = mix(block.selectionColor.rgb, vertexColor.rgb, selected);
gl_Position.z += mix(0.0, (shift + 0.0015) / 10.0, selected);
gl_Position.w = 1.0;
}

View File

@@ -474,8 +474,8 @@ TimelineItemsMaterialShader::TimelineItemsMaterialShader()
setShaderSourceFile(QOpenGLShader::Fragment, setShaderSourceFile(QOpenGLShader::Fragment,
QStringLiteral(":/QtCreator/Tracing/timelineitems.frag")); QStringLiteral(":/QtCreator/Tracing/timelineitems.frag"));
#else // < Qt 6 #else // < Qt 6
setShaderFileName(VertexStage, ":/QtCreator/Tracing/timelineitems.vert"); setShaderFileName(VertexStage, ":/QtCreator/Tracing/timelineitems_qt6.vert.qsb");
setShaderFileName(FragmentStage, ":/QtCreator/Tracing/timelineitems.frag"); setShaderFileName(FragmentStage, ":/QtCreator/Tracing/timelineitems_qt6.frag.qsb");
#endif // < Qt 6 #endif // < Qt 6
} }
@@ -496,11 +496,29 @@ void TimelineItemsMaterialShader::updateState(const RenderState &state, QSGMater
bool TimelineItemsMaterialShader::updateUniformData(RenderState &state, bool TimelineItemsMaterialShader::updateUniformData(RenderState &state,
QSGMaterial *newMaterial, QSGMaterial *) QSGMaterial *newMaterial, QSGMaterial *)
{ {
// TODO: Make this work QByteArray *buf = state.uniformData();
auto material = static_cast<const TimelineItemsMaterial *>(newMaterial);
// mat4 matrix
if (state.isMatrixDirty()) { if (state.isMatrixDirty()) {
TimelineItemsMaterial *material = static_cast<TimelineItemsMaterial *>(newMaterial); const QMatrix4x4 m = state.combinedMatrix();
memcpy(buf->data(), m.constData(), 64);
} }
return state.isMatrixDirty();
// vec2 scale
const QVector2D scale = material->scale();
memcpy(buf->data() + 64, &scale, 8);
// vec4 selectionColor
const QColor color = material->selectionColor();
const float colorArray[] = { color.redF(), color.greenF(), color.blueF(), color.alphaF() };
memcpy(buf->data() + 80, colorArray, 16);
// float selectedItem
const float selectedItem = material->selectedItem();
memcpy(buf->data() + 96, &selectedItem, 4);
return true;
} }
#endif // < Qt 6 #endif // < Qt 6
@@ -524,6 +542,9 @@ void TimelineItemsMaterialShader::initialize()
TimelineItemsMaterial::TimelineItemsMaterial() : m_selectedItem(-1) TimelineItemsMaterial::TimelineItemsMaterial() : m_selectedItem(-1)
{ {
setFlag(QSGMaterial::Blending, false); setFlag(QSGMaterial::Blending, false);
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
setFlag(QSGMaterial::CustomCompileStep, true);
#endif // >= Qt 6
} }
QVector2D TimelineItemsMaterial::scale() const QVector2D TimelineItemsMaterial::scale() const

View File

@@ -178,6 +178,9 @@ TimelineNotesRenderPassState::TimelineNotesRenderPassState(int numExpandedRows)
m_nullGeometry(NotesGeometry::point2DWithDistanceFromTop(), 0) m_nullGeometry(NotesGeometry::point2DWithDistanceFromTop(), 0)
{ {
m_material.setFlag(QSGMaterial::Blending, true); m_material.setFlag(QSGMaterial::Blending, true);
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
m_material.setFlag(QSGMaterial::CustomCompileStep, true);
#endif // >= Qt 6
m_expandedRows.reserve(numExpandedRows); m_expandedRows.reserve(numExpandedRows);
for (int i = 0; i < numExpandedRows; ++i) for (int i = 0; i < numExpandedRows; ++i)
m_expandedRows << createNode(); m_expandedRows << createNode();
@@ -254,8 +257,8 @@ NotesMaterialShader::NotesMaterialShader()
setShaderSourceFile(QOpenGLShader::Vertex, QStringLiteral(":/QtCreator/Tracing/notes.vert")); setShaderSourceFile(QOpenGLShader::Vertex, QStringLiteral(":/QtCreator/Tracing/notes.vert"));
setShaderSourceFile(QOpenGLShader::Fragment, QStringLiteral(":/QtCreator/Tracing/notes.frag")); setShaderSourceFile(QOpenGLShader::Fragment, QStringLiteral(":/QtCreator/Tracing/notes.frag"));
#else // < Qt 6 #else // < Qt 6
setShaderFileName(VertexStage, ":/QtCreator/Tracing/notes.vert"); setShaderFileName(VertexStage, ":/QtCreator/Tracing/notes_qt6.vert.qsb");
setShaderFileName(FragmentStage, ":/QtCreator/Tracing/notes.frag"); setShaderFileName(FragmentStage, ":/QtCreator/Tracing/notes_qt6.frag.qsb");
#endif // < Qt 6 #endif // < Qt 6
} }
@@ -278,9 +281,20 @@ void NotesMaterialShader::updateState(const RenderState &state, QSGMaterial *, Q
#else // < Qt 6 #else // < Qt 6
bool NotesMaterialShader::updateUniformData(RenderState &state, QSGMaterial *, QSGMaterial *) bool NotesMaterialShader::updateUniformData(RenderState &state, QSGMaterial *, QSGMaterial *)
{ {
QByteArray *buf = state.uniformData();
// mat4 matrix
if (state.isMatrixDirty()) { if (state.isMatrixDirty()) {
const QMatrix4x4 m = state.combinedMatrix();
memcpy(buf->data(), m.constData(), 64);
} }
return state.isMatrixDirty();
// vec4 notesColor
const QColor color = notesColor();
const float colorArray[] = { color.redF(), color.greenF(), color.blueF(), color.alphaF() };
memcpy(buf->data() + 64, colorArray, 16);
return true;
} }
#endif // < Qt 6 #endif // < Qt 6

View File

@@ -49,6 +49,7 @@ if(${Qt5_VERSION} VERSION_LESS "6.2.0")
) )
else() # < Qt 6.2 else() # < Qt 6.2
add_qtc_plugin(PerfProfiler add_qtc_plugin(PerfProfiler
CONDITION TARGET Tracing
DEPENDS Tracing Qt5::QuickWidgets DEPENDS Tracing Qt5::QuickWidgets
PLUGIN_DEPENDS Core Debugger ProjectExplorer QtSupport PLUGIN_DEPENDS Core Debugger ProjectExplorer QtSupport
SOURCES SOURCES

View File

@@ -79,7 +79,10 @@ if(${Qt5_VERSION} VERSION_LESS "6.2.0")
qml/qmlprofiler.qrc qml/qmlprofiler.qrc
) )
else() # < Qt 6.2 else() # < Qt 6.2
find_package(Qt6 COMPONENTS ShaderTools QUIET)
add_qtc_plugin(QmlProfiler add_qtc_plugin(QmlProfiler
CONDITION TARGET Tracing AND TARGET Qt6::ShaderTools
DEPENDS QmlDebug QmlJS Tracing Qt5::QuickWidgets DEPENDS QmlDebug QmlJS Tracing Qt5::QuickWidgets
PLUGIN_DEPENDS Core Debugger ProjectExplorer QtSupport TextEditor PLUGIN_DEPENDS Core Debugger ProjectExplorer QtSupport TextEditor
SOURCES SOURCES
@@ -94,16 +97,20 @@ else() # < Qt 6.2
qml/QmlProfilerFlameGraphView.qml qml/QmlProfilerFlameGraphView.qml
) )
set(QMLPROFILER_QML_RESOURCES foreach(file IN LISTS QMLPROFILER_QML_FILES)
qml/bindingloops.frag
qml/bindingloops.vert
)
foreach(file IN LISTS QMLPROFILER_QML_FILES QMLPROFILER_QML_RESOURCES)
get_filename_component(fileName "${file}" NAME) get_filename_component(fileName "${file}" NAME)
set_source_files_properties("${file}" PROPERTIES QT_RESOURCE_ALIAS "${fileName}") set_source_files_properties("${file}" PROPERTIES QT_RESOURCE_ALIAS "${fileName}")
endforeach() 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 qt_add_qml_module(QmlProfiler
URI "QtCreator.QmlProfiler" URI "QtCreator.QmlProfiler"
VERSION "1.0" 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, setShaderSourceFile(QOpenGLShader::Fragment,
QStringLiteral(":/QtCreator/QmlProfiler/bindingloops.frag")); QStringLiteral(":/QtCreator/QmlProfiler/bindingloops.frag"));
#else // < Qt 6 #else // < Qt 6
setShaderFileName(VertexStage, ":/QtCreator/QmlProfiler/bindingloops.vert"); setShaderFileName(VertexStage, ":/QtCreator/QmlProfiler/bindingloops_qt6.vert.qsb");
setShaderFileName(FragmentStage, ":/QtCreator/QmlProfiler/bindingloops.frag"); setShaderFileName(FragmentStage, ":/QtCreator/QmlProfiler/bindingloops_qt6.frag.qsb");
#endif // < Qt 6 #endif // < Qt 6
} }
@@ -348,8 +348,20 @@ void BindingLoopMaterialShader::updateState(const RenderState &state, QSGMateria
#else // < Qt 6 #else // < Qt 6
bool BindingLoopMaterialShader::updateUniformData(RenderState &state, QSGMaterial *, QSGMaterial *) bool BindingLoopMaterialShader::updateUniformData(RenderState &state, QSGMaterial *, QSGMaterial *)
{ {
// TODO: Make this work QByteArray *buf = state.uniformData();
return state.isMatrixDirty();
// 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 #endif // < Qt 6
@@ -371,6 +383,9 @@ void BindingLoopMaterialShader::initialize()
BindingLoopMaterial::BindingLoopMaterial() BindingLoopMaterial::BindingLoopMaterial()
{ {
setFlag(QSGMaterial::Blending, false); setFlag(QSGMaterial::Blending, false);
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
setFlag(QSGMaterial::CustomCompileStep, true);
#endif // >= Qt 6
} }
QSGMaterialType *BindingLoopMaterial::type() const QSGMaterialType *BindingLoopMaterial::type() const