@@ -864,14 +864,16 @@ COpenGLCommandBuffer::~COpenGLCommandBuffer()
864
864
{
865
865
auto & c = cmd.get <impl::ECT_BEGIN_RENDERPASS>();
866
866
auto framebuf = core::smart_refctd_ptr_static_cast<const COpenGLFramebuffer>(c.renderpassBegin .framebuffer );
867
-
867
+
868
868
ctxlocal->nextState .framebuffer .hash = framebuf->getHashValue ();
869
869
ctxlocal->nextState .framebuffer .fbo = std::move (framebuf);
870
870
ctxlocal->flushStateGraphics (gl, SOpenGLContextLocalCache::GSB_FRAMEBUFFER, ctxid);
871
871
872
872
GLuint fbo = ctxlocal->currentState .framebuffer .GLname ;
873
873
if (fbo)
874
874
beginRenderpass_clearAttachments (gl, ctxlocal, ctxid, c.renderpassBegin , fbo, m_logger.getOptRawPtr ());
875
+
876
+ currentlyRecordingRenderPass = c.renderpassBegin .renderpass .get ();
875
877
}
876
878
break ;
877
879
case impl::ECT_NEXT_SUBPASS:
@@ -887,6 +889,7 @@ COpenGLCommandBuffer::~COpenGLCommandBuffer()
887
889
ctxlocal->nextState .framebuffer .hash = SOpenGLState::NULL_FBO_HASH;
888
890
ctxlocal->nextState .framebuffer .GLname = 0u ;
889
891
ctxlocal->nextState .framebuffer .fbo = nullptr ;
892
+ currentlyRecordingRenderPass = nullptr ;
890
893
}
891
894
break ;
892
895
case impl::ECT_SET_DEVICE_MASK:
@@ -928,10 +931,18 @@ COpenGLCommandBuffer::~COpenGLCommandBuffer()
928
931
auto & c = cmd.get <impl::ECT_BEGIN_QUERY>();
929
932
const COpenGLQueryPool* qp = static_cast <const COpenGLQueryPool*>(c.queryPool .get ());
930
933
auto currentQuery = core::bitflag (qp->getCreationParameters ().queryType );
931
- if (!queriesUsed .hasValue (currentQuery))
934
+ if (!queriesActive .hasValue (currentQuery))
932
935
{
933
936
qp->beginQuery (gl, ctxid, c.query , c.flags .value );
934
- queriesUsed |= currentQuery;
937
+ queriesActive |= currentQuery;
938
+
939
+ uint32_t queryTypeIndex = std::log2<uint32_t >(currentQuery.value );
940
+ currentlyRecordingQueries[queryTypeIndex] = std::make_tuple (
941
+ qp,
942
+ c.query ,
943
+ currentlyRecordingRenderPass,
944
+ 0u
945
+ );
935
946
}
936
947
else
937
948
{
@@ -941,12 +952,36 @@ COpenGLCommandBuffer::~COpenGLCommandBuffer()
941
952
break ;
942
953
case impl::ECT_END_QUERY:
943
954
{
944
- // TODO: set last queue to use
945
955
auto & c = cmd.get <impl::ECT_END_QUERY>();
946
956
const COpenGLQueryPool* qp = static_cast <const COpenGLQueryPool*>(c.queryPool .get ());
947
957
auto currentQuery = core::bitflag (qp->getCreationParameters ().queryType );
948
- qp->endQuery (gl, ctxid, c.query );
949
- queriesUsed &= ~currentQuery;
958
+ if (queriesActive.hasValue (currentQuery))
959
+ {
960
+ uint32_t queryTypeIndex = std::log2<uint32_t >(currentQuery.value );
961
+ IQueryPool const * currentQueryPool = std::get<0 >(currentlyRecordingQueries[queryTypeIndex]);
962
+ uint32_t currentQueryIndex = std::get<1 >(currentlyRecordingQueries[queryTypeIndex]);
963
+ renderpass_t const * currentQueryRenderpass = std::get<2 >(currentlyRecordingQueries[queryTypeIndex]);
964
+ uint32_t currentQuerySubpassIndex = std::get<3 >(currentlyRecordingQueries[queryTypeIndex]);
965
+
966
+ if (currentQueryPool != c.queryPool .get () || currentQueryIndex != c.query )
967
+ {
968
+ assert (false ); // You must end the same query you began for every query type.
969
+ break ;
970
+ }
971
+ if (currentQueryRenderpass != currentlyRecordingRenderPass)
972
+ {
973
+ assert (false ); // Query either starts and ends in the same subpass or starts and ends entirely outside a renderpass
974
+ break ;
975
+ }
976
+
977
+ // currentlyRecordingQuery assert tuple -> same query index and query pool -> same renderpass
978
+ qp->endQuery (gl, ctxid, c.query );
979
+ queriesActive &= ~currentQuery;
980
+ }
981
+ else
982
+ {
983
+ assert (false ); // QueryType was not active to end.
984
+ }
950
985
}
951
986
break ;
952
987
case impl::ECT_COPY_QUERY_POOL_RESULTS:
@@ -1259,7 +1294,12 @@ COpenGLCommandBuffer::~COpenGLCommandBuffer()
1259
1294
case impl::ECT_EXECUTE_COMMANDS:
1260
1295
{
1261
1296
auto & c = cmd.get <impl::ECT_EXECUTE_COMMANDS>();
1262
-
1297
+ auto inheritanceInfo = c.cmdbuf ->getCachedInheritanceInfo ();
1298
+ if (queriesActive.hasValue (IQueryPool::EQT_OCCLUSION))
1299
+ {
1300
+ // For a secondary command buffer to be executed while a query is active, it must set the occlusionQueryEnable, queryFlags, and/or pipelineStatistics members of InheritanceInfo to conservative values
1301
+ assert (inheritanceInfo.occlusionQueryEnable );
1302
+ }
1263
1303
static_cast <COpenGLCommandBuffer*>(c.cmdbuf .get ())->executeAll (gl, ctxlocal, ctxid);
1264
1304
}
1265
1305
break ;
0 commit comments