@@ -302,6 +302,14 @@ vk::ResourceAccess GetStencilAccess(const gl::DepthStencilState &dsState)
302302 // Simplify this check by returning write instead of checking the mask.
303303 return vk::ResourceAccess::Write;
304304}
305+
306+ #if defined(ANGLE_ENABLE_DEBUG_TRACE)
307+ # define ANGLE_WRITE_EVENT_LOG (context, commandBuffer ) writeEventLog(context, commandBuffer)
308+ # define ANGLE_END_EVENT_LOG (commandBuffer ) commandBuffer->endDebugUtilsLabelEXT ()
309+ #else
310+ # define ANGLE_WRITE_EVENT_LOG (context, commandBuffer )
311+ # define ANGLE_END_EVENT_LOG (commandBuffer )
312+ #endif
305313} // anonymous namespace
306314
307315ANGLE_INLINE void ContextVk::flushDescriptorSetUpdates ()
@@ -1077,6 +1085,8 @@ angle::Result ContextVk::setupDraw(const gl::Context *context,
10771085 if (dirtyBits.none ())
10781086 return angle::Result::Continue;
10791087
1088+ ANGLE_WRITE_EVENT_LOG (context, *commandBufferOut);
1089+
10801090 // Flush any relevant dirty bits.
10811091 for (size_t dirtyBit : dirtyBits)
10821092 {
@@ -1282,6 +1292,7 @@ angle::Result ContextVk::setupDispatch(const gl::Context *context,
12821292 // The following ensures prior commands are flushed before we start processing dirty bits.
12831293 ANGLE_TRY (flushCommandsAndEndRenderPass ());
12841294 *commandBufferOut = &mOutsideRenderPassCommands ->getCommandBuffer ();
1295+ ANGLE_WRITE_EVENT_LOG (context, *commandBufferOut);
12851296
12861297 // Create a local object to ensure we flush the descriptor updates to device when we leave this
12871298 // function
@@ -2087,7 +2098,7 @@ angle::Result ContextVk::drawArrays(const gl::Context *context,
20872098 nullptr , mNonIndexedDirtyBitsMask , &commandBuffer));
20882099 commandBuffer->draw (clampedVertexCount, first);
20892100 }
2090-
2101+ ANGLE_END_EVENT_LOG (commandBuffer);
20912102 return angle::Result::Continue;
20922103}
20932104
@@ -2107,12 +2118,15 @@ angle::Result ContextVk::drawArraysInstanced(const gl::Context *context,
21072118 gl::DrawElementsType::InvalidEnum, nullptr , &commandBuffer,
21082119 &numIndices));
21092120 commandBuffer->drawIndexedInstanced (numIndices, instances);
2110- return angle::Result::Continue;
21112121 }
2112-
2113- ANGLE_TRY (setupDraw (context, mode, first, count, instances, gl::DrawElementsType::InvalidEnum,
2114- nullptr , mNonIndexedDirtyBitsMask , &commandBuffer));
2115- commandBuffer->drawInstanced (gl::GetClampedVertexCount<uint32_t >(count), instances, first);
2122+ else
2123+ {
2124+ ANGLE_TRY (setupDraw (context, mode, first, count, instances,
2125+ gl::DrawElementsType::InvalidEnum, nullptr , mNonIndexedDirtyBitsMask ,
2126+ &commandBuffer));
2127+ commandBuffer->drawInstanced (gl::GetClampedVertexCount<uint32_t >(count), instances, first);
2128+ }
2129+ ANGLE_END_EVENT_LOG (commandBuffer);
21162130 return angle::Result::Continue;
21172131}
21182132
@@ -2134,13 +2148,16 @@ angle::Result ContextVk::drawArraysInstancedBaseInstance(const gl::Context *cont
21342148 &numIndices));
21352149 commandBuffer->drawIndexedInstancedBaseVertexBaseInstance (numIndices, instances, 0 , 0 ,
21362150 baseInstance);
2137- return angle::Result::Continue;
21382151 }
2139-
2140- ANGLE_TRY (setupDraw (context, mode, first, count, instances, gl::DrawElementsType::InvalidEnum,
2141- nullptr , mNonIndexedDirtyBitsMask , &commandBuffer));
2142- commandBuffer->drawInstancedBaseInstance (gl::GetClampedVertexCount<uint32_t >(count), instances,
2143- first, baseInstance);
2152+ else
2153+ {
2154+ ANGLE_TRY (setupDraw (context, mode, first, count, instances,
2155+ gl::DrawElementsType::InvalidEnum, nullptr , mNonIndexedDirtyBitsMask ,
2156+ &commandBuffer));
2157+ commandBuffer->drawInstancedBaseInstance (gl::GetClampedVertexCount<uint32_t >(count),
2158+ instances, first, baseInstance);
2159+ }
2160+ ANGLE_END_EVENT_LOG (commandBuffer);
21442161 return angle::Result::Continue;
21452162}
21462163
@@ -2163,7 +2180,7 @@ angle::Result ContextVk::drawElements(const gl::Context *context,
21632180 ANGLE_TRY (setupIndexedDraw (context, mode, count, 1 , type, indices, &commandBuffer));
21642181 commandBuffer->drawIndexed (count);
21652182 }
2166-
2183+ ANGLE_END_EVENT_LOG (commandBuffer);
21672184 return angle::Result::Continue;
21682185}
21692186
@@ -2187,7 +2204,7 @@ angle::Result ContextVk::drawElementsBaseVertex(const gl::Context *context,
21872204 ANGLE_TRY (setupIndexedDraw (context, mode, count, 1 , type, indices, &commandBuffer));
21882205 commandBuffer->drawIndexedBaseVertex (count, baseVertex);
21892206 }
2190-
2207+ ANGLE_END_EVENT_LOG (commandBuffer);
21912208 return angle::Result::Continue;
21922209}
21932210
@@ -2213,6 +2230,7 @@ angle::Result ContextVk::drawElementsInstanced(const gl::Context *context,
22132230 }
22142231
22152232 commandBuffer->drawIndexedInstanced (count, instances);
2233+ ANGLE_END_EVENT_LOG (commandBuffer);
22162234 return angle::Result::Continue;
22172235}
22182236
@@ -2239,6 +2257,7 @@ angle::Result ContextVk::drawElementsInstancedBaseVertex(const gl::Context *cont
22392257 }
22402258
22412259 commandBuffer->drawIndexedInstancedBaseVertex (count, instances, baseVertex);
2260+ ANGLE_END_EVENT_LOG (commandBuffer);
22422261 return angle::Result::Continue;
22432262}
22442263
@@ -2260,12 +2279,14 @@ angle::Result ContextVk::drawElementsInstancedBaseVertexBaseInstance(const gl::C
22602279 setupLineLoopDraw (context, mode, 0 , count, type, indices, &commandBuffer, &indexCount));
22612280 commandBuffer->drawIndexedInstancedBaseVertexBaseInstance (indexCount, instances, 0 ,
22622281 baseVertex, baseInstance);
2263- return angle::Result::Continue;
22642282 }
2265-
2266- ANGLE_TRY (setupIndexedDraw (context, mode, count, instances, type, indices, &commandBuffer));
2267- commandBuffer->drawIndexedInstancedBaseVertexBaseInstance (count, instances, 0 , baseVertex,
2268- baseInstance);
2283+ else
2284+ {
2285+ ANGLE_TRY (setupIndexedDraw (context, mode, count, instances, type, indices, &commandBuffer));
2286+ commandBuffer->drawIndexedInstancedBaseVertexBaseInstance (count, instances, 0 , baseVertex,
2287+ baseInstance);
2288+ }
2289+ ANGLE_END_EVENT_LOG (commandBuffer);
22692290 return angle::Result::Continue;
22702291}
22712292
@@ -2339,13 +2360,16 @@ angle::Result ContextVk::drawArraysIndirect(const gl::Context *context,
23392360 &dstIndirectBuf, &dstIndirectBufOffset));
23402361
23412362 commandBuffer->drawIndexedIndirect (dstIndirectBuf->getBuffer (), dstIndirectBufOffset, 1 , 0 );
2342- return angle::Result::Continue;
23432363 }
2364+ else
2365+ {
2366+ ANGLE_TRY (setupIndirectDraw (context, mode, mNonIndexedDirtyBitsMask , currentIndirectBuf,
2367+ currentIndirectBufOffset, &commandBuffer));
23442368
2345- ANGLE_TRY ( setupIndirectDraw (context, mode, mNonIndexedDirtyBitsMask , currentIndirectBuf ,
2346- currentIndirectBufOffset, &commandBuffer) );
2347-
2348- commandBuffer-> drawIndirect (currentIndirectBuf-> getBuffer (), currentIndirectBufOffset, 1 , 0 );
2369+ commandBuffer-> drawIndirect (currentIndirectBuf-> getBuffer (), currentIndirectBufOffset, 1 ,
2370+ 0 );
2371+ }
2372+ ANGLE_END_EVENT_LOG (commandBuffer );
23492373 return angle::Result::Continue;
23502374}
23512375
@@ -2420,6 +2444,7 @@ angle::Result ContextVk::drawElementsIndirect(const gl::Context *context,
24202444
24212445 commandBuffer->drawIndexedIndirect (currentIndirectBuf->getBuffer (), currentIndirectBufOffset, 1 ,
24222446 0 );
2447+ ANGLE_END_EVENT_LOG (commandBuffer);
24232448 return angle::Result::Continue;
24242449}
24252450
@@ -2617,6 +2642,56 @@ angle::Result ContextVk::popDebugGroup(const gl::Context *context)
26172642 return angle::Result::Continue;
26182643}
26192644
2645+ void ContextVk::writeEventLog (const gl::Context *context, vk::CommandBuffer *commandBuffer)
2646+ {
2647+ if (mEventLog .empty ())
2648+ {
2649+ return ;
2650+ }
2651+
2652+ // Insert OpenGL ES commands into debug label. We create a 3-level cascade here for
2653+ // OpenGL-ES-first debugging in AGI. Here's the general outline of commands:
2654+ // -glDrawCommand
2655+ // --vkCmdBeginDebugUtilsLabelEXT() #1 for "glDrawCommand"
2656+ // --OpenGL ES Commands
2657+ // ---vkCmdBeginDebugUtilsLabelEXT() #2 for "OpenGL ES Commands"
2658+ // ---Individual OpenGL ES Commands leading up to glDrawCommand
2659+ // ----vkCmdBeginDebugUtilsLabelEXT() #3 for each individual OpenGL ES Command
2660+ // ----vkCmdEndDebugUtilsLabelEXT() #3 for each individual OpenGL ES Command
2661+ // ----...More Individual OGL Commands...
2662+ // ----Final Individual OGL command will be the same glDrawCommand shown in #1 above
2663+ // ---vkCmdEndDebugUtilsLabelEXT() #2 for "OpenGL ES Commands"
2664+ // --VK SetupDraw & Draw-related commands will be embedded here under glDraw #1
2665+ // --vkCmdEndDebugUtilsLabelEXT() #1 is called after each vkDraw* or vkDispatch* call
2666+ VkDebugUtilsLabelEXT label = {VK_STRUCTURE_TYPE_DEBUG_UTILS_LABEL_EXT,
2667+ nullptr ,
2668+ mEventLog .back ().c_str (),
2669+ {0 .0f , 0 .0f , 0 .0f , 0 .0f }};
2670+ // This is #1 from comment above
2671+ commandBuffer->beginDebugUtilsLabelEXT (label);
2672+ std::string oglCmds = " OpenGL ES Commands" ;
2673+ label.pLabelName = oglCmds.c_str ();
2674+ // This is #2 from comment above
2675+ commandBuffer->beginDebugUtilsLabelEXT (label);
2676+ for (uint32_t i = 0 ; i < mEventLog .size (); ++i)
2677+ {
2678+ label.pLabelName = mEventLog [i].c_str ();
2679+ // NOTE: We have to use a begin/end pair here because AGI does not promote the
2680+ // pLabelName from an insertDebugUtilsLabelEXT() call to the Commands panel.
2681+ // Internal bug b/169243237 is tracking this and once the insert* call shows the
2682+ // pLabelName similar to begin* call, we can switch these to insert* calls instead.
2683+ // This is #3 from comment above.
2684+ // TODO(ianelliott): Transfer the bug to a publicly-visible bug.
2685+ commandBuffer->beginDebugUtilsLabelEXT (label);
2686+ commandBuffer->endDebugUtilsLabelEXT ();
2687+ }
2688+ commandBuffer->endDebugUtilsLabelEXT ();
2689+ // The final end* call for #1 above is made in the ContextVk::draw* or
2690+ // ContextVk::dispatch* function calls.
2691+
2692+ mEventLog .clear ();
2693+ }
2694+
26202695bool ContextVk::isViewportFlipEnabledForDrawFBO () const
26212696{
26222697 return mFlipViewportForDrawFramebuffer && mFlipYForCurrentSurface ;
@@ -3578,6 +3653,8 @@ angle::Result ContextVk::dispatchCompute(const gl::Context *context,
35783653
35793654 commandBuffer->dispatch (numGroupsX, numGroupsY, numGroupsZ);
35803655
3656+ ANGLE_END_EVENT_LOG (commandBuffer);
3657+
35813658 return angle::Result::Continue;
35823659}
35833660
@@ -3593,6 +3670,8 @@ angle::Result ContextVk::dispatchComputeIndirect(const gl::Context *context, GLi
35933670
35943671 commandBuffer->dispatchIndirect (buffer.getBuffer (), indirect);
35953672
3673+ ANGLE_END_EVENT_LOG (commandBuffer);
3674+
35963675 return angle::Result::Continue;
35973676}
35983677
0 commit comments