diff options
author | Nicolas Guichard <nicolas.guichard@kdab.com> | 2020-04-24 14:11:17 +0200 |
---|---|---|
committer | Nicolas Guichard <nicolas.guichard@kdab.com> | 2020-04-27 09:36:50 +0200 |
commit | 5e16aa067ac6a8b5f031ffcefc356777a0da34ad (patch) | |
tree | cdde252171520a8f11452cf05d78b8f45b9c8e5a | |
parent | 36ef85341aacd225839d58880d3f388f31e3100c (diff) | |
download | qt3d-5e16aa067ac6a8b5f031ffcefc356777a0da34ad.tar.gz |
QShaderGraph: disable edges connected to disabled nodesv5.15.0-rc2v5.15.0-rc1v5.15.05.15.0
This graph failed to generate statements with enabledLayers = {"0"}:
_edge0i__ function0 __edge0o__
/ \
input output
\_edge1i__ function1 __edge1o__/
with function0 and edge0o on layer "0" only
and function1 and edge1o on layer "1" only
and all other nodes and edges on all layers.
The issue was that when only layer "0" is enabled, edge1i didn't get
properly discarded and Kahn's algorithm didn't ever schedule input.
Task-number: QTBUG-83766
Change-Id: Idb8705d487c3748153e0c4b3330b9589e827139e
Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
-rw-r--r-- | src/render/shadergraph/qshadergraph.cpp | 22 | ||||
-rw-r--r-- | tests/auto/render/shadergraph/qshadergraph/tst_qshadergraph.cpp | 44 |
2 files changed, 56 insertions, 10 deletions
diff --git a/src/render/shadergraph/qshadergraph.cpp b/src/render/shadergraph/qshadergraph.cpp index c2f3c343e..285aff116 100644 --- a/src/render/shadergraph/qshadergraph.cpp +++ b/src/render/shadergraph/qshadergraph.cpp @@ -242,16 +242,6 @@ QVector<QShaderGraph::Statement> QShaderGraph::createStatements(const QStringLis return res; }(); - const QVector<Edge> enabledEdges = [this, intersectsEnabledLayers] { - auto res = QVector<Edge>(); - std::copy_if(m_edges.cbegin(), m_edges.cend(), - std::back_inserter(res), - [intersectsEnabledLayers] (const Edge &edge) { - return intersectsEnabledLayers(edge.layers); - }); - return res; - }(); - const QHash<QUuid, Statement> idHash = [enabledNodes] { auto nextVarId = 0; auto res = QHash<QUuid, Statement>(); @@ -260,6 +250,18 @@ QVector<QShaderGraph::Statement> QShaderGraph::createStatements(const QStringLis return res; }(); + const QVector<Edge> enabledEdges = [this, intersectsEnabledLayers, &idHash] { + auto res = QVector<Edge>(); + std::copy_if(m_edges.cbegin(), m_edges.cend(), + std::back_inserter(res), + [intersectsEnabledLayers, &idHash] (const Edge &edge) { + return intersectsEnabledLayers(edge.layers) + && idHash.contains(edge.sourceNodeUuid) + && idHash.contains(edge.targetNodeUuid); + }); + return res; + }(); + auto result = QVector<Statement>(); QVector<Edge> currentEdges = enabledEdges; QVector<QUuid> currentUuids = [enabledNodes, enabledEdges] { diff --git a/tests/auto/render/shadergraph/qshadergraph/tst_qshadergraph.cpp b/tests/auto/render/shadergraph/qshadergraph/tst_qshadergraph.cpp index 6336763f5..e21b57577 100644 --- a/tests/auto/render/shadergraph/qshadergraph/tst_qshadergraph.cpp +++ b/tests/auto/render/shadergraph/qshadergraph/tst_qshadergraph.cpp @@ -116,6 +116,7 @@ private slots: void shouldDealWithEdgesJumpingOverLayers(); void shouldGenerateDifferentStatementsDependingOnActiveLayers(); void shouldDealWithBranchesWithoutOutput(); + void shouldDiscardEdgesConnectedToDiscardedNodes(); }; void tst_QShaderGraph::shouldHaveEdgeDefaultState() @@ -816,6 +817,49 @@ void tst_QShaderGraph::shouldDealWithBranchesWithoutOutput() QCOMPARE(statements, expected); } +void tst_QShaderGraph::shouldDiscardEdgesConnectedToDiscardedNodes() +{ + // GIVEN + const auto input = createNode({ + createPort(QShaderNodePort::Output, "input") + }); + const auto output = createNode({ + createPort(QShaderNodePort::Input, "output") + }); + const auto function0 = createNode({ + createPort(QShaderNodePort::Input, "function0Input"), + createPort(QShaderNodePort::Output, "function0Output") + }, {"0"}); + const auto function1 = createNode({ + createPort(QShaderNodePort::Input, "function1Input"), + createPort(QShaderNodePort::Output, "function1Output") + }, {"1"}); + + const auto graph = [=] { + auto res = QShaderGraph(); + res.addNode(input); + res.addNode(function0); + res.addNode(function1); + res.addNode(output); + res.addEdge(createEdge(input.uuid(), "input", function0.uuid(), "function0Input", {"0"})); + res.addEdge(createEdge(input.uuid(), "input", function1.uuid(), "function1Input")); + res.addEdge(createEdge(function0.uuid(), "function0Output", output.uuid(), "output")); + res.addEdge(createEdge(function1.uuid(), "function1Output", output.uuid(), "output")); + return res; + }(); + + // WHEN + const auto statements = graph.createStatements({"0"}); + + // THEN + const auto expected = QVector<QShaderGraph::Statement>() + << createStatement(input, {}, {0}) + << createStatement(function0, {0}, {1}) + << createStatement(output, {1}, {}); + dumpStatementsIfNeeded(statements, expected); + QCOMPARE(statements, expected); +} + QTEST_MAIN(tst_QShaderGraph) #include "tst_qshadergraph.moc" |