Tracing/QmlProfiler: Prepare for porting of shaders to Qt 6

This change touches up the shader handling code in Tracing and
QmlProfiler in order to pave the way for the pending porting of
the shaders to Qt 6.

- Use QSGGeometry::Attribute::createWithAttributeType instead of
  QSGGeometry::Attribute::create
- Undefine some fields that are unused in Qt 6
- Add a couple of comments to document the relation between C++
  variables and shader attributes
- Extract some code into functions

Change-Id: I0e7119484b6190a415a5c2d2a0bbd6465088cf19
Reviewed-by: Henning Gründl <henning.gruendl@qt.io>
This commit is contained in:
Alessandro Portale
2021-07-13 19:23:39 +02:00
parent f95d6c6009
commit 84a0170516
4 changed files with 71 additions and 64 deletions

View File

@@ -357,14 +357,22 @@ static qint64 endTime(const TimelineModel *model, const TimelineRenderState *par
const QSGGeometry::AttributeSet &OpaqueColoredPoint2DWithSize::attributes()
{
static QSGGeometry::Attribute data[] = {
QSGGeometry::Attribute::create(0, 2, QSGGeometry::FloatType, true),
QSGGeometry::Attribute::create(1, 2, QSGGeometry::FloatType),
QSGGeometry::Attribute::create(2, 1, QSGGeometry::FloatType),
QSGGeometry::Attribute::create(3, 4, QSGGeometry::UnsignedByteType)
static const QSGGeometry::Attribute data[] = {
// vec4 vertexCoord
QSGGeometry::Attribute::createWithAttributeType(0, 2, QSGGeometry::FloatType,
QSGGeometry::PositionAttribute),
// vec2 rectSize
QSGGeometry::Attribute::createWithAttributeType(1, 2, QSGGeometry::FloatType,
QSGGeometry::UnknownAttribute),
// float selectionId
QSGGeometry::Attribute::createWithAttributeType(2, 1, QSGGeometry::FloatType,
QSGGeometry::UnknownAttribute),
// vec4 vertexColor
QSGGeometry::Attribute::createWithAttributeType(3, 4, QSGGeometry::UnsignedByteType,
QSGGeometry::ColorAttribute),
};
static QSGGeometry::AttributeSet attrs = {
4,
static const QSGGeometry::AttributeSet attrs = {
sizeof(data) / sizeof(data[0]),
sizeof(OpaqueColoredPoint2DWithSize),
data
};
@@ -448,13 +456,13 @@ public:
private:
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
void initialize() override;
#endif // < Qt 6
int m_matrix_id;
int m_scale_id;
int m_selection_color_id;
int m_selected_item_id;
int m_z_range_id;
#endif // < Qt 6
};
TimelineItemsMaterialShader::TimelineItemsMaterialShader()
@@ -556,17 +564,12 @@ QSGMaterialType *TimelineItemsMaterial::type() const
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QSGMaterialShader *TimelineItemsMaterial::createShader() const
{
return new TimelineItemsMaterialShader;
}
#else // < Qt 6
QSGMaterialShader *TimelineItemsMaterial::createShader(
QSGRendererInterface::RenderMode renderMode) const
QSGMaterialShader *TimelineItemsMaterial::createShader(QSGRendererInterface::RenderMode) const
#endif // < Qt 6
{
Q_UNUSED(renderMode);
return new TimelineItemsMaterialShader;
}
#endif // < Qt 6
TimelineItemsRenderPassState::TimelineItemsRenderPassState(const TimelineModel *model) :
m_indexFrom(std::numeric_limits<int>::max()), m_indexTo(-1)

View File

@@ -48,7 +48,7 @@ public:
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QSGMaterialShader *createShader() const override;
#else
QSGMaterialShader *createShader(QSGRendererInterface::RenderMode renderMode) const override;
QSGMaterialShader *createShader(QSGRendererInterface::RenderMode) const override;
#endif // < Qt 6
private:
@@ -83,8 +83,10 @@ public:
static OpaqueColoredPoint2DWithSize *fromVertexData(QSGGeometry *geometry);
private:
float x, y, w, h, id;
unsigned char r, g, b, a;
float x, y; // vec4 vertexCoord
float w, h; // vec2 rectSize
float id; // float selectionId
unsigned char r, g, b, a; // vec4 vertexColor
void setCommon(const OpaqueColoredPoint2DWithSize *master);
void setLeft(const OpaqueColoredPoint2DWithSize *master);

View File

@@ -32,7 +32,8 @@
namespace Timeline {
struct Point2DWithDistanceFromTop {
float x, y, d;
float x, y; // vec4 vertexCoord
float d; // float distanceFromTop
void set(float nx, float ny, float nd);
};
@@ -43,7 +44,7 @@ public:
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QSGMaterialShader *createShader() const final;
#else // < Qt 6
QSGMaterialShader *createShader(QSGRendererInterface::RenderMode renderMode) const final;
QSGMaterialShader *createShader(QSGRendererInterface::RenderMode) const final;
#endif // < Qt 6
};
@@ -82,12 +83,16 @@ private:
const QSGGeometry::AttributeSet &NotesGeometry::point2DWithDistanceFromTop()
{
static QSGGeometry::Attribute data[] = {
QSGGeometry::Attribute::create(0, 2, QSGGeometry::FloatType, true),
QSGGeometry::Attribute::create(1, 1, QSGGeometry::FloatType),
static const QSGGeometry::Attribute data[] = {
// vec4 vertexCoord
QSGGeometry::Attribute::createWithAttributeType(0, 2, QSGGeometry::FloatType,
QSGGeometry::PositionAttribute),
// float distanceFromTop
QSGGeometry::Attribute::createWithAttributeType(1, 1, QSGGeometry::FloatType,
QSGGeometry::UnknownAttribute),
};
static QSGGeometry::AttributeSet attrs = {
2,
static const QSGGeometry::AttributeSet attrs = {
sizeof(data) / sizeof(data[0]),
sizeof(Point2DWithDistanceFromTop),
data
};
@@ -229,18 +234,17 @@ public:
QSGMaterial *oldEffect) override;
char const *const *attributeNames() const override;
#else // < Qt 6
bool updateUniformData(RenderState &state,
QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override;
bool updateUniformData(RenderState &state, QSGMaterial *, QSGMaterial *) override;
#endif // < Qt 6
private:
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
void initialize() override;
#endif // < Qt 6
int m_matrix_id;
int m_z_range_id;
int m_color_id;
#endif // < Qt 6
};
NotesMaterialShader::NotesMaterialShader()
@@ -255,20 +259,24 @@ NotesMaterialShader::NotesMaterialShader()
#endif // < Qt 6
}
static QColor notesColor()
{
return Utils::creatorTheme()
? Utils::creatorTheme()->color(Utils::Theme::Timeline_HighlightColor)
: QColor(255, 165, 0);
}
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
void NotesMaterialShader::updateState(const RenderState &state, QSGMaterial *, QSGMaterial *)
{
if (state.isMatrixDirty()) {
program()->setUniformValue(m_matrix_id, state.combinedMatrix());
program()->setUniformValue(m_z_range_id, GLfloat(1.0));
const QColor notesColor = Utils::creatorTheme()
? Utils::creatorTheme()->color(Utils::Theme::Timeline_HighlightColor)
: QColor(255, 165, 0);
program()->setUniformValue(m_color_id, notesColor);
program()->setUniformValue(m_color_id, notesColor());
}
}
#else // < Qt 6
bool NotesMaterialShader::updateUniformData(QSGMaterialShader::RenderState &state, QSGMaterial *, QSGMaterial *)
bool NotesMaterialShader::updateUniformData(RenderState &state, QSGMaterial *, QSGMaterial *)
{
if (state.isMatrixDirty()) {
}
@@ -299,16 +307,12 @@ QSGMaterialType *NotesMaterial::type() const
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QSGMaterialShader *NotesMaterial::createShader() const
{
return new NotesMaterialShader;
}
#else // < Qt 6
QSGMaterialShader *NotesMaterial::createShader(QSGRendererInterface::RenderMode renderMode) const
QSGMaterialShader *NotesMaterial::createShader(QSGRendererInterface::RenderMode) const
#endif // < Qt 6
{
Q_UNUSED(renderMode);
return new NotesMaterialShader;
}
#endif // < Qt 6
void Point2DWithDistanceFromTop::set(float nx, float ny, float nd)
{

View File

@@ -37,7 +37,7 @@ public:
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QSGMaterialShader *createShader() const override;
#else
QSGMaterialShader *createShader(QSGRendererInterface::RenderMode renderMode) const override;
QSGMaterialShader *createShader(QSGRendererInterface::RenderMode) const override;
#endif // < Qt 6
BindingLoopMaterial();
};
@@ -66,7 +66,8 @@ private:
};
struct Point2DWithOffset {
float x, y, x2, y2;
float x, y; // vec4 vertexCoord
float x2, y2; // vec2 postScaleOffset
void set(float nx, float ny, float nx2, float ny2);
};
@@ -199,12 +200,16 @@ Timeline::TimelineRenderPass::State *QmlProfilerBindingLoopsRenderPass::update(
const QSGGeometry::AttributeSet &BindlingLoopsGeometry::point2DWithOffset()
{
static QSGGeometry::Attribute data[] = {
QSGGeometry::Attribute::create(0, 2, QSGGeometry::FloatType, true),
QSGGeometry::Attribute::create(1, 2, QSGGeometry::FloatType),
static const QSGGeometry::Attribute data[] = {
// vec4 vertexCoord
QSGGeometry::Attribute::createWithAttributeType(0, 2, QSGGeometry::FloatType,
QSGGeometry::PositionAttribute),
// vec2 postScaleOffset
QSGGeometry::Attribute::createWithAttributeType(1, 2, QSGGeometry::FloatType,
QSGGeometry::UnknownAttribute),
};
static QSGGeometry::AttributeSet attrs = {
2,
static const QSGGeometry::AttributeSet attrs = {
sizeof(data) / sizeof(data[0]),
sizeof(Point2DWithOffset),
data
};
@@ -299,18 +304,17 @@ public:
QSGMaterial *oldEffect) override;
char const *const *attributeNames() const override;
#else // < Qt 6
bool updateUniformData(RenderState &state, QSGMaterial *newEffect,
QSGMaterial *oldEffect) override;
bool updateUniformData(RenderState &state, QSGMaterial *, QSGMaterial *) override;
#endif // < Qt 6
private:
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
void initialize() override;
#endif // < Qt 6
int m_matrix_id = 0;
int m_z_range_id = 0;
int m_color_id = 0;
#endif // < Qt 6
};
BindingLoopMaterialShader::BindingLoopMaterialShader()
@@ -327,25 +331,24 @@ BindingLoopMaterialShader::BindingLoopMaterialShader()
#endif // < Qt 6
}
static QColor bindingLoopsColor()
{
return Utils::creatorTheme()->color(Utils::Theme::Timeline_HighlightColor);
}
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
void BindingLoopMaterialShader::updateState(const RenderState &state, QSGMaterial *, QSGMaterial *)
{
if (state.isMatrixDirty()) {
program()->setUniformValue(m_matrix_id, state.combinedMatrix());
program()->setUniformValue(m_z_range_id, GLfloat(1.0));
program()->setUniformValue(
m_color_id,
Utils::creatorTheme()->color(Utils::Theme::Timeline_HighlightColor));
program()->setUniformValue(m_color_id, bindingLoopsColor());
}
}
#else // < Qt 6
bool BindingLoopMaterialShader::updateUniformData(RenderState &state,
QSGMaterial *newMaterial, QSGMaterial *)
bool BindingLoopMaterialShader::updateUniformData(RenderState &state, QSGMaterial *, QSGMaterial *)
{
// TODO: Make this work
if (state.isMatrixDirty()) {
BindingLoopMaterial *material = static_cast<BindingLoopMaterial *>(newMaterial);
}
return state.isMatrixDirty();
}
#endif // < Qt 6
@@ -378,17 +381,12 @@ QSGMaterialType *BindingLoopMaterial::type() const
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QSGMaterialShader *BindingLoopMaterial::createShader() const
{
return new BindingLoopMaterialShader;
}
#else // < Qt 6
QSGMaterialShader *BindingLoopMaterial::createShader(
QSGRendererInterface::RenderMode renderMode) const
QSGMaterialShader *BindingLoopMaterial::createShader(QSGRendererInterface::RenderMode) const
#endif // < Qt 6
{
Q_UNUSED(renderMode);
return new BindingLoopMaterialShader;
}
#endif // < Qt 6
void Point2DWithOffset::set(float nx, float ny, float nx2, float ny2)
{