diff options
Diffstat (limited to 'src/render/materialsystem')
-rw-r--r-- | src/render/materialsystem/material.cpp | 16 | ||||
-rw-r--r-- | src/render/materialsystem/prototypes/default.json | 160 | ||||
-rw-r--r-- | src/render/materialsystem/qeffect.cpp | 6 | ||||
-rw-r--r-- | src/render/materialsystem/qgraphicsapifilter.cpp | 22 | ||||
-rw-r--r-- | src/render/materialsystem/qgraphicsapifilter.h | 3 | ||||
-rw-r--r-- | src/render/materialsystem/qgraphicsapifilter_p.h | 2 | ||||
-rw-r--r-- | src/render/materialsystem/qmaterial.cpp | 3 | ||||
-rw-r--r-- | src/render/materialsystem/qrenderpass.cpp | 9 | ||||
-rw-r--r-- | src/render/materialsystem/qtechnique.cpp | 9 | ||||
-rw-r--r-- | src/render/materialsystem/shader.cpp | 2 | ||||
-rw-r--r-- | src/render/materialsystem/shader_p.h | 1 | ||||
-rw-r--r-- | src/render/materialsystem/shaderbuilder.cpp | 21 | ||||
-rw-r--r-- | src/render/materialsystem/shaderdata.cpp | 2 | ||||
-rw-r--r-- | src/render/materialsystem/shaderdata_p.h | 2 |
14 files changed, 231 insertions, 27 deletions
diff --git a/src/render/materialsystem/material.cpp b/src/render/materialsystem/material.cpp index 6fda17ccd..62dc0958a 100644 --- a/src/render/materialsystem/material.cpp +++ b/src/render/materialsystem/material.cpp @@ -76,19 +76,23 @@ void Material::syncFromFrontEnd(const QNode *frontEnd, bool firstTime) if (!node) return; + AbstractRenderer::BackendNodeDirtySet dirty = firstTime ? AbstractRenderer::MaterialDirty : static_cast<AbstractRenderer::BackendNodeDirtyFlag>(0); + auto parameters = qIdsForNodes(node->parameters()); std::sort(std::begin(parameters), std::end(parameters)); - if (m_parameterPack.parameters() != parameters) + if (m_parameterPack.parameters() != parameters) { m_parameterPack.setParameters(parameters); + dirty |= AbstractRenderer::AllDirty; + } const auto effectId = node->effect() ? node->effect()->id() : QNodeId{}; - if (effectId != m_effectUuid) + if (effectId != m_effectUuid) { m_effectUuid = effectId; + dirty |= AbstractRenderer::AllDirty; + } - if (firstTime) - markDirty(AbstractRenderer::MaterialDirty); - else - markDirty(AbstractRenderer::AllDirty); + if (dirty) + markDirty(dirty); } QVector<Qt3DCore::QNodeId> Material::parameters() const diff --git a/src/render/materialsystem/prototypes/default.json b/src/render/materialsystem/prototypes/default.json index 597de41c3..dfa51898f 100644 --- a/src/render/materialsystem/prototypes/default.json +++ b/src/render/materialsystem/prototypes/default.json @@ -32,6 +32,15 @@ }, "substitution": "$type $value = $name;", "headerSnippets": [ "$qualifier $type $name;" ] + }, + { + "format": { + "api": "RHI", + "major": 1, + "minor": 0 + }, + "substitution": "$type $value = $name;", + "headerSnippets": [ "add-input $qualifier $type $name" ] } ] }, @@ -62,6 +71,14 @@ "minor": 0 }, "substitution": "$type $value = $type($constant);" + }, + { + "format": { + "api": "RHI", + "major": 1, + "minor": 0 + }, + "substitution": "$type $value = $type($constant);" } ] }, @@ -102,6 +119,15 @@ }, "substitution": "vec4 $color = texture($name, $coord);", "headerSnippets": [ "uniform sampler2D $name;" ] + }, + { + "format": { + "api": "RHI", + "major": 1, + "minor": 0 + }, + "substitution": "vec4 $color = texture($name, $coord);", + "headerSnippets": [ "add-sampler sampler2D $name" ] } ] }, @@ -135,6 +161,15 @@ }, "substitution": "fragColor = $fragColor;", "headerSnippets": [ "out vec4 fragColor;" ] + }, + { + "format": { + "api": "RHI", + "major": 1, + "minor": 0 + }, + "substitution": "fragColor = $fragColor;", + "headerSnippets": [ "layout(location = 0) out vec4 fragColor;" ] } ] }, @@ -160,6 +195,15 @@ }, "substitution": "vec3 $eyePosition = eyePosition;", "headerSnippets": [ "uniform vec3 eyePosition;" ] + }, + { + "format": { + "api": "RHI", + "major": 1, + "minor": 0 + }, + "substitution": "vec3 $eyePosition = eyePosition;", + "headerSnippets": [ ] } ] }, @@ -185,6 +229,15 @@ }, "substitution": "float $time = time;", "headerSnippets": [ "uniform float time;" ] + }, + { + "format": { + "api": "RHI", + "major": 1, + "minor": 0 + }, + "substitution": "float $time = time;", + "headerSnippets": [ "add-uniform float time" ] } ] }, @@ -217,6 +270,14 @@ "minor": 0 }, "substitution": "$type $output = transpose($input);" + }, + { + "format": { + "api": "RHI", + "major": 1, + "minor": 0 + }, + "substitution": "$type $output = transpose($input);" } ] }, @@ -249,6 +310,14 @@ "minor": 0 }, "substitution": "$type $output = normalize($input);" + }, + { + "format": { + "api": "RHI", + "major": 1, + "minor": 0 + }, + "substitution": "$type $output = normalize($input);" } ] }, @@ -282,6 +351,14 @@ "minor": 0 }, "substitution": "$type $difference = $minuend - $subtrahend;" + }, + { + "format": { + "api": "RHI", + "major": 1, + "minor": 0 + }, + "substitution": "$type $difference = $minuend - $subtrahend;" } ] }, @@ -315,6 +392,14 @@ "minor": 0 }, "substitution": "$type $sum = $first + $second;" + }, + { + "format": { + "api": "RHI", + "major": 1, + "minor": 0 + }, + "substitution": "$type $sum = $first + $second;" } ] }, @@ -348,6 +433,14 @@ "minor": 0 }, "substitution": "$type $product = $first * $second;" + }, + { + "format": { + "api": "RHI", + "major": 1, + "minor": 0 + }, + "substitution": "$type $product = $first * $second;" } ] }, @@ -381,6 +474,14 @@ "minor": 0 }, "substitution": "$type $output = $input.$fields;" + }, + { + "format": { + "api": "RHI", + "major": 1, + "minor": 0 + }, + "substitution": "$type $output = $input.$fields;" } ] }, @@ -419,6 +520,15 @@ }, "substitution": "mat3 $matrix = calcWorldSpaceToTangentSpaceMatrix($worldNormal, $worldTangent);", "headerSnippets": [ "#pragma include :/shaders/gl3/coordinatesystems.inc" ] + }, + { + "format": { + "api": "RHI", + "major": 1, + "minor": 0 + }, + "substitution": "mat3 $matrix = calcWorldSpaceToTangentSpaceMatrix($worldNormal, $worldTangent);", + "headerSnippets": [ "#pragma include :/shaders/rhi/coordinatesystems.inc" ] } ] }, @@ -453,6 +563,15 @@ }, "substitution": "vec4 $outputColor = phongFunction($ambient, $diffuse, $specular, $shininess, $worldPosition, $worldView, $worldNormal);", "headerSnippets": [ "#pragma include :/shaders/gl3/phong.inc.frag" ] + }, + { + "format": { + "api": "RHI", + "major": 1, + "minor": 0 + }, + "substitution": "vec4 $outputColor = phongFunction($ambient, $diffuse, $specular, $shininess, $worldPosition, $worldView, $worldNormal);", + "headerSnippets": [ "#pragma include :/shaders/rhi/phong.inc.frag" ] } ] }, @@ -487,6 +606,15 @@ }, "substitution": "vec4 $outputColor = metalRoughFunction($baseColor, $metalness, $roughness, $ambientOcclusion, $worldPosition, $worldView, $worldNormal);", "headerSnippets": [ "#pragma include :/shaders/gl3/metalrough.inc.frag" ] + }, + { + "format": { + "api": "RHI", + "major": 1, + "minor": 0 + }, + "substitution": "vec4 $outputColor = metalRoughFunction($baseColor, $metalness, $roughness, $ambientOcclusion, $worldPosition, $worldView, $worldNormal);", + "headerSnippets": [ "#pragma include :/shaders/rhi/metalrough.inc.frag" ] } ] }, @@ -520,6 +648,14 @@ "minor": 0 }, "substitution": "$type $output = $type($first, $second);" + }, + { + "format": { + "api": "RHI", + "major": 1, + "minor": 0 + }, + "substitution": "$type $output = $type($first, $second);" } ] }, @@ -554,6 +690,14 @@ "minor": 0 }, "substitution": "$type $output = $type($first, $second, $third);" + }, + { + "format": { + "api": "RHI", + "major": 1, + "minor": 0 + }, + "substitution": "$type $output = $type($first, $second, $third);" } ] }, @@ -589,6 +733,14 @@ "minor": 0 }, "substitution": "$type $output = $type($first, $second, $third, $fourth);" + }, + { + "format": { + "api": "RHI", + "major": 1, + "minor": 0 + }, + "substitution": "$type $output = $type($first, $second, $third, $fourth);" } ] }, @@ -621,6 +773,14 @@ "minor": 0 }, "substitution": "$type $output = $type($input);" + }, + { + "format": { + "api": "RHI", + "major": 1, + "minor": 0 + }, + "substitution": "$type $output = $type($input);" } ] } diff --git a/src/render/materialsystem/qeffect.cpp b/src/render/materialsystem/qeffect.cpp index ad3dde8f7..0e950cee4 100644 --- a/src/render/materialsystem/qeffect.cpp +++ b/src/render/materialsystem/qeffect.cpp @@ -203,7 +203,8 @@ void QEffect::removeParameter(QParameter *parameter) { Q_D(QEffect); - d->m_parameters.removeOne(parameter); + if (!d->m_parameters.removeOne(parameter)) + return; // Remove bookkeeping connection d->unregisterDestructionHelper(parameter); d->update(); @@ -248,8 +249,9 @@ void QEffect::addTechnique(QTechnique *t) void QEffect::removeTechnique(QTechnique *t) { Q_D(QEffect); + if (!d->m_techniques.removeOne(t)) + return; d->update(); - d->m_techniques.removeOne(t); // Remove bookkeeping connection d->unregisterDestructionHelper(t); } diff --git a/src/render/materialsystem/qgraphicsapifilter.cpp b/src/render/materialsystem/qgraphicsapifilter.cpp index 9b5557930..e8b93de6e 100644 --- a/src/render/materialsystem/qgraphicsapifilter.cpp +++ b/src/render/materialsystem/qgraphicsapifilter.cpp @@ -53,6 +53,28 @@ GraphicsApiFilterData::GraphicsApiFilterData() , m_major(0) {} +QString GraphicsApiFilterData::toString() const +{ + QLatin1String api; + switch (m_api) { + case QGraphicsApiFilter::OpenGL: api = QLatin1String("OpenGL"); break; + case QGraphicsApiFilter::OpenGLES: api = QLatin1String("OpenGL"); break; + case QGraphicsApiFilter::Vulkan: api = QLatin1String("Vulkan"); break; + case QGraphicsApiFilter::DirectX: api = QLatin1String("DirectX"); break; + case QGraphicsApiFilter::RHI: api = QLatin1String("RHI"); break; + default: Q_UNREACHABLE(); + } + + QLatin1String profile; + switch (m_profile) { + case QGraphicsApiFilter::CoreProfile: profile = QLatin1String(" (Core Profile)"); break; + case QGraphicsApiFilter::CompatibilityProfile: profile = QLatin1String(" (Compatibility Profile)"); break; + default: break; + } + + return QString(QLatin1String("%1 %2.%3%4 (%5)").arg(api, QString::number(m_major), QString::number(m_minor), profile, m_vendor)); +} + bool GraphicsApiFilterData::operator ==(const GraphicsApiFilterData &other) const { // Check API diff --git a/src/render/materialsystem/qgraphicsapifilter.h b/src/render/materialsystem/qgraphicsapifilter.h index 337193673..80cfe026e 100644 --- a/src/render/materialsystem/qgraphicsapifilter.h +++ b/src/render/materialsystem/qgraphicsapifilter.h @@ -67,7 +67,8 @@ public: OpenGLES = QSurfaceFormat::OpenGLES, // 2 OpenGL = QSurfaceFormat::OpenGL, // 1 Vulkan = 3, // 3 - DirectX // 4 + DirectX, // 4 + RHI, // 5 }; Q_ENUM(Api) // LCOV_EXCL_LINE diff --git a/src/render/materialsystem/qgraphicsapifilter_p.h b/src/render/materialsystem/qgraphicsapifilter_p.h index 435451c27..52c489785 100644 --- a/src/render/materialsystem/qgraphicsapifilter_p.h +++ b/src/render/materialsystem/qgraphicsapifilter_p.h @@ -70,6 +70,8 @@ struct Q_3DRENDERSHARED_PRIVATE_EXPORT GraphicsApiFilterData QStringList m_extensions; QString m_vendor; + QString toString() const; + bool operator ==(const GraphicsApiFilterData &other) const; bool operator !=(const GraphicsApiFilterData &other) const; bool operator <(const GraphicsApiFilterData &other) const; diff --git a/src/render/materialsystem/qmaterial.cpp b/src/render/materialsystem/qmaterial.cpp index 9026e55f1..50fcd59be 100644 --- a/src/render/materialsystem/qmaterial.cpp +++ b/src/render/materialsystem/qmaterial.cpp @@ -283,8 +283,9 @@ void QMaterial::removeParameter(QParameter *parameter) { Q_ASSERT(parameter); Q_D(QMaterial); + if (!d->m_parameters.removeOne(parameter)) + return; d->update(); - d->m_parameters.removeOne(parameter); } /*! diff --git a/src/render/materialsystem/qrenderpass.cpp b/src/render/materialsystem/qrenderpass.cpp index 83a6e8255..40c9cb1cd 100644 --- a/src/render/materialsystem/qrenderpass.cpp +++ b/src/render/materialsystem/qrenderpass.cpp @@ -285,8 +285,9 @@ void QRenderPass::removeFilterKey(QFilterKey *filterKey) { Q_ASSERT(filterKey); Q_D(QRenderPass); + if (!d->m_filterKeyList.removeOne(filterKey)) + return; d->update(); - d->m_filterKeyList.removeOne(filterKey); // Remove bookkeeping connection d->unregisterDestructionHelper(filterKey); } @@ -333,8 +334,9 @@ void QRenderPass::removeRenderState(QRenderState *state) { Q_ASSERT(state); Q_D(QRenderPass); + if (!d->m_renderStates.removeOne(state)) + return; d->update(); - d->m_renderStates.removeOne(state); // Remove bookkeeping connection d->unregisterDestructionHelper(state); } @@ -380,8 +382,9 @@ void QRenderPass::removeParameter(QParameter *parameter) { Q_ASSERT(parameter); Q_D(QRenderPass); + if (!d->m_parameters.removeOne(parameter)) + return; d->update(); - d->m_parameters.removeOne(parameter); // Remove bookkeeping connection d->unregisterDestructionHelper(parameter); } diff --git a/src/render/materialsystem/qtechnique.cpp b/src/render/materialsystem/qtechnique.cpp index 088716fb9..eca8b88c6 100644 --- a/src/render/materialsystem/qtechnique.cpp +++ b/src/render/materialsystem/qtechnique.cpp @@ -269,8 +269,9 @@ void QTechnique::removeFilterKey(QFilterKey *filterKey) { Q_ASSERT(filterKey); Q_D(QTechnique); + if (!d->m_filterKeys.removeOne(filterKey)) + return; d->update(); - d->m_filterKeys.removeOne(filterKey); // Remove bookkeeping connection d->unregisterDestructionHelper(filterKey); } @@ -316,8 +317,9 @@ void QTechnique::removeParameter(QParameter *parameter) { Q_ASSERT(parameter); Q_D(QTechnique); + if (!d->m_parameters.removeOne(parameter)) + return; d->update(); - d->m_parameters.removeOne(parameter); // Remove bookkeeping connection d->unregisterDestructionHelper(parameter); } @@ -353,8 +355,9 @@ void QTechnique::removeRenderPass(QRenderPass *pass) { Q_ASSERT(pass); Q_D(QTechnique); + if (!d->m_renderPasses.removeOne(pass)) + return; d->update(); - d->m_renderPasses.removeOne(pass); // Remove bookkeeping connection d->unregisterDestructionHelper(pass); } diff --git a/src/render/materialsystem/shader.cpp b/src/render/materialsystem/shader.cpp index be7d0f1ea..ebdb4c64b 100644 --- a/src/render/materialsystem/shader.cpp +++ b/src/render/materialsystem/shader.cpp @@ -73,6 +73,7 @@ const int Shader::modelNormalMatrixNameId = StringToInt::lookupId(QLatin1String( const int Shader::modelViewNormalNameId = StringToInt::lookupId(QLatin1String("modelViewNormal")); const int Shader::viewportMatrixNameId = StringToInt::lookupId(QLatin1String("viewportMatrix")); const int Shader::inverseViewportMatrixNameId = StringToInt::lookupId(QLatin1String("inverseViewportMatrix")); +const int Shader::textureTransformMatrixNameId = StringToInt::lookupId(QLatin1String("textureTransformMatrix")); const int Shader::aspectRatioNameId = StringToInt::lookupId(QLatin1String("aspectRatio")); const int Shader::exposureNameId = StringToInt::lookupId(QLatin1String("exposure")); const int Shader::gammaNameId = StringToInt::lookupId(QLatin1String("gamma")); @@ -100,6 +101,7 @@ void Shader::cleanup() m_status = QShaderProgram::NotReady; m_format = QShaderProgram::GLSL; m_log.clear(); + m_requiresFrontendSync = false; m_dirty = false; } diff --git a/src/render/materialsystem/shader_p.h b/src/render/materialsystem/shader_p.h index 31603bcf7..0ac3227b7 100644 --- a/src/render/materialsystem/shader_p.h +++ b/src/render/materialsystem/shader_p.h @@ -86,6 +86,7 @@ public: static const int modelViewNormalNameId; static const int viewportMatrixNameId; static const int inverseViewportMatrixNameId; + static const int textureTransformMatrixNameId; static const int aspectRatioNameId; static const int exposureNameId; static const int gammaNameId; diff --git a/src/render/materialsystem/shaderbuilder.cpp b/src/render/materialsystem/shaderbuilder.cpp index 871b4cb4c..c7a2aa347 100644 --- a/src/render/materialsystem/shaderbuilder.cpp +++ b/src/render/materialsystem/shaderbuilder.cpp @@ -44,10 +44,10 @@ #include <Qt3DRender/private/qshaderprogram_p.h> #include <Qt3DCore/private/qurlhelper_p.h> -#include <QtGui/private/qshaderformat_p.h> -#include <QtGui/private/qshadergraphloader_p.h> -#include <QtGui/private/qshadergenerator_p.h> -#include <QtGui/private/qshadernodesloader_p.h> +#include <Qt3DRender/private/qshaderformat_p.h> +#include <Qt3DRender/private/qshadergraphloader_p.h> +#include <Qt3DRender/private/qshadergenerator_p.h> +#include <Qt3DRender/private/qshadernodesloader_p.h> #include <QFile> #include <QFileInfo> @@ -82,7 +82,7 @@ public: load(); } - QHash<QString, QShaderNode> prototypes() const + QHash<QString, Qt3DRender::QShaderNode> prototypes() const { return m_prototypes; } @@ -96,14 +96,14 @@ private: return; } - QShaderNodesLoader loader; + Qt3DRender::QShaderNodesLoader loader; loader.setDevice(&file); loader.load(); m_prototypes = loader.nodes(); } QString m_fileName; - QHash<QString, QShaderNode> m_prototypes; + QHash<QString, Qt3DRender::QShaderNode> m_prototypes; }; Q_GLOBAL_STATIC(GlobalShaderPrototypes, qt3dGlobalShaderPrototypes) @@ -232,6 +232,8 @@ void ShaderBuilder::generateCode(QShaderProgram::ShaderType type) auto format = QShaderFormat(); format.setApi(m_graphicsApi.m_api == QGraphicsApiFilter::OpenGLES ? QShaderFormat::OpenGLES + : m_graphicsApi.m_api == QGraphicsApiFilter::Vulkan ? QShaderFormat::VulkanFlavoredGLSL + : m_graphicsApi.m_api == QGraphicsApiFilter::RHI ? QShaderFormat::RHI : m_graphicsApi.m_profile == QGraphicsApiFilter::CoreProfile ? QShaderFormat::OpenGLCoreProfile : m_graphicsApi.m_profile == QGraphicsApiFilter::CompatibilityProfile ? QShaderFormat::OpenGLCompatibilityProfile : QShaderFormat::OpenGLNoProfile); @@ -244,7 +246,8 @@ void ShaderBuilder::generateCode(QShaderProgram::ShaderType type) generator.graph = graph; const auto code = generator.createShaderCode(m_enabledLayers); - m_codes.insert(type, QShaderProgramPrivate::deincludify(code, graphPath + QStringLiteral(".glsl"))); + const auto deincludified = QShaderProgramPrivate::deincludify(code, graphPath + QStringLiteral(".glsl")); + m_codes.insert(type, deincludified); m_dirtyTypes.remove(type); m_pendingUpdates.push_back({ peerId(), @@ -276,7 +279,7 @@ void ShaderBuilder::syncFromFrontEnd(const QNode *frontEnd, bool firstTime) markDirty(AbstractRenderer::ShadersDirty); } - static const QVector<std::pair<QShaderProgram::ShaderType, QUrl (QShaderProgramBuilder::*)() const>> shaderTypesToGetters = { + static const QVarLengthArray<std::pair<QShaderProgram::ShaderType, QUrl (QShaderProgramBuilder::*)() const>, 6> shaderTypesToGetters { {QShaderProgram::Vertex, &QShaderProgramBuilder::vertexShaderGraph}, {QShaderProgram::TessellationControl, &QShaderProgramBuilder::tessellationControlShaderGraph}, {QShaderProgram::TessellationEvaluation, &QShaderProgramBuilder::tessellationEvaluationShaderGraph}, diff --git a/src/render/materialsystem/shaderdata.cpp b/src/render/materialsystem/shaderdata.cpp index 44a41a240..6f113d592 100644 --- a/src/render/materialsystem/shaderdata.cpp +++ b/src/render/materialsystem/shaderdata.cpp @@ -160,7 +160,7 @@ ShaderData *ShaderData::lookupResource(QNodeId id) } // RenderCommand updater jobs -QVariant ShaderData::getTransformedProperty(const QString &name, const Matrix4x4 &viewMatrix) +QVariant ShaderData::getTransformedProperty(const QString &name, const Matrix4x4 &viewMatrix) const noexcept { // Note protecting m_worldMatrix at this point as we assume all world updates // have been performed when reaching this point diff --git a/src/render/materialsystem/shaderdata_p.h b/src/render/materialsystem/shaderdata_p.h index 6fe811566..a1491b328 100644 --- a/src/render/materialsystem/shaderdata_p.h +++ b/src/render/materialsystem/shaderdata_p.h @@ -89,7 +89,7 @@ public: // Called by FramePreparationJob void updateWorldTransform(const Matrix4x4 &worldMatrix); - QVariant getTransformedProperty(const QString &name, const Matrix4x4 &viewMatrix); + QVariant getTransformedProperty(const QString &name, const Matrix4x4 &viewMatrix) const noexcept; // Unit tests purposes only TransformType propertyTransformType(const QString &name) const; |