Use consistent ordering in QShader
Fixes: QTBUG-101923 Change-Id: I62df3eba773350e47ed650acb00bc42b3ce6a899 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Andy Nichols <andy.nichols@qt.io>bb10
parent
992a318d39
commit
9dced35b41
|
|
@ -563,6 +563,22 @@ size_t qHash(const QShaderVersion &s, size_t seed) noexcept
|
|||
}
|
||||
#endif
|
||||
|
||||
/*!
|
||||
Establishes a sorting order between the two QShaderVersion \a lhs and \a rhs.
|
||||
|
||||
\relates QShaderVersion
|
||||
*/
|
||||
bool operator<(const QShaderVersion &lhs, const QShaderVersion &rhs) noexcept
|
||||
{
|
||||
if (lhs.version() < rhs.version())
|
||||
return true;
|
||||
|
||||
if (lhs.version() == rhs.version())
|
||||
return int(lhs.flags()) < int(rhs.flags());
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/*!
|
||||
\internal
|
||||
\fn bool operator!=(const QShaderVersion &lhs, const QShaderVersion &rhs)
|
||||
|
|
@ -584,6 +600,28 @@ bool operator==(const QShaderKey &lhs, const QShaderKey &rhs) noexcept
|
|||
&& lhs.sourceVariant() == rhs.sourceVariant();
|
||||
}
|
||||
|
||||
/*!
|
||||
Establishes a sorting order between the two keys \a lhs and \a rhs.
|
||||
|
||||
\relates QShaderKey
|
||||
*/
|
||||
bool operator<(const QShaderKey &lhs, const QShaderKey &rhs) noexcept
|
||||
{
|
||||
if (int(lhs.source()) < int(rhs.source()))
|
||||
return true;
|
||||
|
||||
if (int(lhs.source()) == int(rhs.source())) {
|
||||
if (lhs.sourceVersion() < rhs.sourceVersion())
|
||||
return true;
|
||||
if (lhs.sourceVersion() == rhs.sourceVersion()) {
|
||||
if (int(lhs.sourceVariant()) < int(rhs.sourceVariant()))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/*!
|
||||
\internal
|
||||
\fn bool operator!=(const QShaderKey &lhs, const QShaderKey &rhs)
|
||||
|
|
|
|||
|
|
@ -187,7 +187,9 @@ inline bool operator!=(const QShader &lhs, const QShader &rhs) noexcept
|
|||
}
|
||||
|
||||
Q_GUI_EXPORT bool operator==(const QShaderVersion &lhs, const QShaderVersion &rhs) noexcept;
|
||||
Q_GUI_EXPORT bool operator<(const QShaderVersion &lhs, const QShaderVersion &rhs) noexcept;
|
||||
Q_GUI_EXPORT bool operator==(const QShaderKey &lhs, const QShaderKey &rhs) noexcept;
|
||||
Q_GUI_EXPORT bool operator<(const QShaderKey &lhs, const QShaderKey &rhs) noexcept;
|
||||
Q_GUI_EXPORT bool operator==(const QShaderCode &lhs, const QShaderCode &rhs) noexcept;
|
||||
|
||||
inline bool operator!=(const QShaderVersion &lhs, const QShaderVersion &rhs) noexcept
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@
|
|||
|
||||
#include "qshader_p.h"
|
||||
#include <QtCore/QAtomicInt>
|
||||
#include <QtCore/QHash>
|
||||
#include <QtCore/QMap>
|
||||
#include <QtCore/QDebug>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
|
@ -54,9 +54,10 @@ struct Q_GUI_EXPORT QShaderPrivate
|
|||
int qsbVersion = QSB_VERSION;
|
||||
QShader::Stage stage = QShader::VertexStage;
|
||||
QShaderDescription desc;
|
||||
QHash<QShaderKey, QShaderCode> shaders;
|
||||
QHash<QShaderKey, QShader::NativeResourceBindingMap> bindings;
|
||||
QHash<QShaderKey, QShader::SeparateToCombinedImageSamplerMappingList> combinedImageMap;
|
||||
// QMap not QHash because we need to be able to iterate based on sorted keys
|
||||
QMap<QShaderKey, QShaderCode> shaders;
|
||||
QMap<QShaderKey, QShader::NativeResourceBindingMap> bindings;
|
||||
QMap<QShaderKey, QShader::SeparateToCombinedImageSamplerMappingList> combinedImageMap;
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ private slots:
|
|||
void genVariants();
|
||||
void shaderDescImplicitSharing();
|
||||
void bakedShaderImplicitSharing();
|
||||
void sortedKeys();
|
||||
void mslResourceMapping();
|
||||
void serializeShaderDesc();
|
||||
void comparison();
|
||||
|
|
@ -238,6 +239,16 @@ void tst_QShader::bakedShaderImplicitSharing()
|
|||
}
|
||||
}
|
||||
|
||||
void tst_QShader::sortedKeys()
|
||||
{
|
||||
QShader s = getShader(QLatin1String(":/data/texture_all_v4.frag.qsb"));
|
||||
QVERIFY(s.isValid());
|
||||
QList<QShaderKey> availableShaders = s.availableShaders();
|
||||
QCOMPARE(availableShaders.count(), 7);
|
||||
std::sort(availableShaders.begin(), availableShaders.end());
|
||||
QCOMPARE(availableShaders, s.availableShaders());
|
||||
}
|
||||
|
||||
void tst_QShader::mslResourceMapping()
|
||||
{
|
||||
QShader s = getShader(QLatin1String(":/data/texture_all_v4.frag.qsb"));
|
||||
|
|
|
|||
Loading…
Reference in New Issue