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/libs/tracing | |
parent | 84a017051693bab44a96f92fb4fd3f0c60264800 (diff) | |
download | qt-creator-21cb0711c4d9bbd9d5d4b32899bf037dc8f1f4db.tar.gz |
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/libs/tracing')
-rw-r--r-- | src/libs/tracing/CMakeLists.txt | 18 | ||||
-rw-r--r-- | src/libs/tracing/qml/notes_qt6.frag | 36 | ||||
-rw-r--r-- | src/libs/tracing/qml/notes_qt6.vert | 46 | ||||
-rw-r--r-- | src/libs/tracing/qml/timelineitems_qt6.frag | 43 | ||||
-rw-r--r-- | src/libs/tracing/qml/timelineitems_qt6.vert | 63 | ||||
-rw-r--r-- | src/libs/tracing/timelineitemsrenderpass.cpp | 31 | ||||
-rw-r--r-- | src/libs/tracing/timelinenotesrenderpass.cpp | 20 |
7 files changed, 245 insertions, 12 deletions
diff --git a/src/libs/tracing/CMakeLists.txt b/src/libs/tracing/CMakeLists.txt index d8970a7962..826e04426d 100644 --- a/src/libs/tracing/CMakeLists.txt +++ b/src/libs/tracing/CMakeLists.txt @@ -43,7 +43,10 @@ if(${Qt5_VERSION} VERSION_LESS "6.2.0") qml/tracing.qrc ) else() # < Qt 6.2 + find_package(Qt6 COMPONENTS ShaderTools QUIET) + add_qtc_library(Tracing + CONDITION TARGET Qt6::ShaderTools FEATURE_INFO DEPENDS Utils Qt5::Qml Qt5::Quick PUBLIC_DEPENDS Qt5::Widgets @@ -86,12 +89,8 @@ else() # < Qt 6.2 qml/ico_rangeselection@2x.png qml/ico_selectionmode.png qml/ico_selectionmode@2x.png - qml/notes.frag - qml/notes.vert qml/range_handle.png qml/range_handle@2.png - qml/timelineitems.frag - qml/timelineitems.vert ) 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}") 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 URI "QtCreator.Tracing" VERSION "1.0" diff --git a/src/libs/tracing/qml/notes_qt6.frag b/src/libs/tracing/qml/notes_qt6.frag new file mode 100644 index 0000000000..fb4ce9679b --- /dev/null +++ b/src/libs/tracing/qml/notes_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 = 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)); +} diff --git a/src/libs/tracing/qml/notes_qt6.vert b/src/libs/tracing/qml/notes_qt6.vert new file mode 100644 index 0000000000..440ea4fa1c --- /dev/null +++ b/src/libs/tracing/qml/notes_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 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; +} diff --git a/src/libs/tracing/qml/timelineitems_qt6.frag b/src/libs/tracing/qml/timelineitems_qt6.frag new file mode 100644 index 0000000000..ef59e543f0 --- /dev/null +++ b/src/libs/tracing/qml/timelineitems_qt6.frag @@ -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; +} diff --git a/src/libs/tracing/qml/timelineitems_qt6.vert b/src/libs/tracing/qml/timelineitems_qt6.vert new file mode 100644 index 0000000000..0327b9e91d --- /dev/null +++ b/src/libs/tracing/qml/timelineitems_qt6.vert @@ -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; +} diff --git a/src/libs/tracing/timelineitemsrenderpass.cpp b/src/libs/tracing/timelineitemsrenderpass.cpp index 344810d81d..8b0698c54c 100644 --- a/src/libs/tracing/timelineitemsrenderpass.cpp +++ b/src/libs/tracing/timelineitemsrenderpass.cpp @@ -474,8 +474,8 @@ TimelineItemsMaterialShader::TimelineItemsMaterialShader() setShaderSourceFile(QOpenGLShader::Fragment, QStringLiteral(":/QtCreator/Tracing/timelineitems.frag")); #else // < Qt 6 - setShaderFileName(VertexStage, ":/QtCreator/Tracing/timelineitems.vert"); - setShaderFileName(FragmentStage, ":/QtCreator/Tracing/timelineitems.frag"); + setShaderFileName(VertexStage, ":/QtCreator/Tracing/timelineitems_qt6.vert.qsb"); + setShaderFileName(FragmentStage, ":/QtCreator/Tracing/timelineitems_qt6.frag.qsb"); #endif // < Qt 6 } @@ -496,11 +496,29 @@ void TimelineItemsMaterialShader::updateState(const RenderState &state, QSGMater bool TimelineItemsMaterialShader::updateUniformData(RenderState &state, QSGMaterial *newMaterial, QSGMaterial *) { - // TODO: Make this work + QByteArray *buf = state.uniformData(); + auto material = static_cast<const TimelineItemsMaterial *>(newMaterial); + + // mat4 matrix 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 @@ -524,6 +542,9 @@ void TimelineItemsMaterialShader::initialize() TimelineItemsMaterial::TimelineItemsMaterial() : m_selectedItem(-1) { setFlag(QSGMaterial::Blending, false); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + setFlag(QSGMaterial::CustomCompileStep, true); +#endif // >= Qt 6 } QVector2D TimelineItemsMaterial::scale() const diff --git a/src/libs/tracing/timelinenotesrenderpass.cpp b/src/libs/tracing/timelinenotesrenderpass.cpp index e71366e74e..7eaefe9875 100644 --- a/src/libs/tracing/timelinenotesrenderpass.cpp +++ b/src/libs/tracing/timelinenotesrenderpass.cpp @@ -178,6 +178,9 @@ TimelineNotesRenderPassState::TimelineNotesRenderPassState(int numExpandedRows) m_nullGeometry(NotesGeometry::point2DWithDistanceFromTop(), 0) { 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); for (int i = 0; i < numExpandedRows; ++i) m_expandedRows << createNode(); @@ -254,8 +257,8 @@ NotesMaterialShader::NotesMaterialShader() setShaderSourceFile(QOpenGLShader::Vertex, QStringLiteral(":/QtCreator/Tracing/notes.vert")); setShaderSourceFile(QOpenGLShader::Fragment, QStringLiteral(":/QtCreator/Tracing/notes.frag")); #else // < Qt 6 - setShaderFileName(VertexStage, ":/QtCreator/Tracing/notes.vert"); - setShaderFileName(FragmentStage, ":/QtCreator/Tracing/notes.frag"); + setShaderFileName(VertexStage, ":/QtCreator/Tracing/notes_qt6.vert.qsb"); + setShaderFileName(FragmentStage, ":/QtCreator/Tracing/notes_qt6.frag.qsb"); #endif // < Qt 6 } @@ -278,9 +281,20 @@ void NotesMaterialShader::updateState(const RenderState &state, QSGMaterial *, Q #else // < Qt 6 bool NotesMaterialShader::updateUniformData(RenderState &state, QSGMaterial *, QSGMaterial *) { + QByteArray *buf = state.uniformData(); + + // mat4 matrix 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 |