1616#include " runtime/command_stream/aub_command_stream_receiver.h"
1717#include " runtime/command_stream/command_stream_receiver_with_aub_dump.h"
1818#include " runtime/execution_environment/execution_environment.h"
19+ #include " runtime/helpers/dispatch_info.h"
1920#include " runtime/helpers/hardware_context_controller.h"
2021#include " runtime/helpers/hw_helper.h"
2122#include " runtime/memory_manager/memory_banks.h"
@@ -156,9 +157,21 @@ CommandStreamReceiver *TbxCommandStreamReceiverHw<GfxFamily>::create(const std::
156157 executionEnvironment.initAubCenter (localMemoryEnabled, fullName, CommandStreamReceiverType::CSR_TBX_WITH_AUB);
157158
158159 csr = new CommandStreamReceiverWithAUBDump<TbxCommandStreamReceiverHw<GfxFamily>>(baseName, executionEnvironment);
160+
161+ auto aubCenter = executionEnvironment.aubCenter .get ();
162+ UNRECOVERABLE_IF (nullptr == aubCenter);
163+
164+ auto subCaptureCommon = aubCenter->getSubCaptureCommon ();
165+ UNRECOVERABLE_IF (nullptr == subCaptureCommon);
166+
167+ if (subCaptureCommon->subCaptureMode > AubSubCaptureManager::SubCaptureMode::Off) {
168+ csr->subCaptureManager = std::make_unique<AubSubCaptureManager>(fullName, *subCaptureCommon);
169+ }
170+
159171 if (csr->aubManager ) {
160172 if (!csr->aubManager ->isOpen ()) {
161- csr->aubManager ->open (fullName);
173+ MultiDispatchInfo dispatchInfo;
174+ csr->aubManager ->open (csr->subCaptureManager ? csr->subCaptureManager ->getSubCaptureFileName (dispatchInfo) : fullName);
162175 UNRECOVERABLE_IF (!csr->aubManager ->isOpen ());
163176 }
164177 }
@@ -179,6 +192,12 @@ CommandStreamReceiver *TbxCommandStreamReceiverHw<GfxFamily>::create(const std::
179192
180193template <typename GfxFamily>
181194FlushStamp TbxCommandStreamReceiverHw<GfxFamily>::flush(BatchBuffer &batchBuffer, ResidencyContainer &allocationsForResidency) {
195+ if (subCaptureManager) {
196+ if (aubManager) {
197+ aubManager->pause (false );
198+ }
199+ }
200+
182201 initializeEngine ();
183202
184203 // Write our batch buffer
@@ -196,7 +215,19 @@ FlushStamp TbxCommandStreamReceiverHw<GfxFamily>::flush(BatchBuffer &batchBuffer
196215 // Write allocations for residency
197216 processResidency (allocationsForResidency);
198217
218+ if (subCaptureManager && !subCaptureManager->isSubCaptureEnabled ()) {
219+ if (aubManager) {
220+ aubManager->pause (true );
221+ }
222+ }
223+
199224 submitBatchBuffer (batchBufferGpuAddress, pBatchBuffer, sizeBatchBuffer, this ->getMemoryBank (batchBuffer.commandBufferAllocation ), this ->getPPGTTAdditionalBits (batchBuffer.commandBufferAllocation ));
225+
226+ if (subCaptureManager) {
227+ pollForCompletion ();
228+ subCaptureManager->disableSubCapture ();
229+ }
230+
200231 return 0 ;
201232}
202233
@@ -412,12 +443,17 @@ void TbxCommandStreamReceiverHw<GfxFamily>::processEviction() {
412443template <typename GfxFamily>
413444void TbxCommandStreamReceiverHw<GfxFamily>::processResidency(const ResidencyContainer &allocationsForResidency) {
414445 for (auto &gfxAllocation : allocationsForResidency) {
446+ if (dumpTbxNonWritable) {
447+ this ->setTbxWritable (true , *gfxAllocation);
448+ }
415449 if (!writeMemory (*gfxAllocation)) {
416450 DEBUG_BREAK_IF (!((gfxAllocation->getUnderlyingBufferSize () == 0 ) ||
417451 !this ->isTbxWritable (*gfxAllocation)));
418452 }
419453 gfxAllocation->updateResidencyTaskCount (this ->taskCount + 1 , this ->osContext ->getContextId ());
420454 }
455+
456+ dumpTbxNonWritable = false ;
421457}
422458
423459template <typename GfxFamily>
@@ -450,4 +486,17 @@ template <typename GfxFamily>
450486bool TbxCommandStreamReceiverHw<GfxFamily>::getpollNotEqualValueForPollForCompletion() const {
451487 return false ;
452488}
489+
490+ template <typename GfxFamily>
491+ AubSubCaptureStatus TbxCommandStreamReceiverHw<GfxFamily>::checkAndActivateAubSubCapture(const MultiDispatchInfo &dispatchInfo) {
492+ if (!subCaptureManager) {
493+ return {false , false };
494+ }
495+
496+ auto status = subCaptureManager->checkAndActivateSubCapture (dispatchInfo);
497+ if (status.isActive && !status.wasActiveInPreviousEnqueue ) {
498+ dumpTbxNonWritable = true ;
499+ }
500+ return status;
501+ }
453502} // namespace NEO
0 commit comments