@@ -37,9 +37,9 @@ AUBCommandStreamReceiverHw<GfxFamily>::AUBCommandStreamReceiverHw(const Hardware
3737 : BaseClass(hwInfoIn),
3838 stream (std::unique_ptr<AUBCommandStreamReceiver::AubFileStream>(new AUBCommandStreamReceiver::AubFileStream())),
3939 standalone(standalone) {
40- this ->dispatchMode = CommandStreamReceiver:: DispatchMode::BatchedDispatch;
40+ this ->dispatchMode = DispatchMode::BatchedDispatch;
4141 if (DebugManager.flags .CsrDispatchMode .get ()) {
42- this ->dispatchMode = (CommandStreamReceiver:: DispatchMode)DebugManager.flags .CsrDispatchMode .get ();
42+ this ->dispatchMode = (DispatchMode)DebugManager.flags .CsrDispatchMode .get ();
4343 }
4444 for (auto &engineInfo : engineInfoTable) {
4545 engineInfo.pLRCA = nullptr ;
@@ -221,8 +221,8 @@ FlushStamp AUBCommandStreamReceiverHw<GfxFamily>::flush(BatchBuffer &batchBuffer
221221 auto sizeBatchBuffer = currentOffset - batchBuffer.startOffset ;
222222
223223 std::unique_ptr<void , std::function<void (void *)>> flatBatchBuffer (nullptr , [&](void *ptr) { this ->getMemoryManager ()->alignedFreeWrapper (ptr); });
224- if (DebugManager.flags .FlattenBatchBufferForAUBDump .get () && ( this -> dispatchMode == CommandStreamReceiver::DispatchMode::ImmediateDispatch) ) {
225- flatBatchBuffer.reset (flattenBatchBuffer (batchBuffer, sizeBatchBuffer));
224+ if (DebugManager.flags .FlattenBatchBufferForAUBDump .get ()) {
225+ flatBatchBuffer.reset (this -> flatBatchBufferHelper -> flattenBatchBuffer (batchBuffer, sizeBatchBuffer, this -> dispatchMode ));
226226 if (flatBatchBuffer.get () != nullptr ) {
227227 pBatchBuffer = flatBatchBuffer.get ();
228228 }
@@ -248,7 +248,7 @@ FlushStamp AUBCommandStreamReceiverHw<GfxFamily>::flush(BatchBuffer &batchBuffer
248248 }
249249
250250 if (this ->standalone ) {
251- if (this ->dispatchMode == CommandStreamReceiver:: DispatchMode::ImmediateDispatch) {
251+ if (this ->dispatchMode == DispatchMode::ImmediateDispatch) {
252252 if (!DebugManager.flags .FlattenBatchBufferForAUBDump .get ()) {
253253 makeResident (*batchBuffer.commandBufferAllocation );
254254 }
@@ -259,6 +259,7 @@ FlushStamp AUBCommandStreamReceiverHw<GfxFamily>::flush(BatchBuffer &batchBuffer
259259 processResidency (allocationsForResidency);
260260 }
261261 if (DebugManager.flags .AddPatchInfoCommentsForAUBDump .get ()) {
262+ addGUCStartMessage (static_cast <uint64_t >(reinterpret_cast <std::uintptr_t >(pBatchBuffer)), engineType);
262263 addPatchInfoComments ();
263264 }
264265
@@ -387,32 +388,13 @@ FlushStamp AUBCommandStreamReceiverHw<GfxFamily>::flush(BatchBuffer &batchBuffer
387388 return 0 ;
388389}
389390
390- template <typename GfxFamily>
391- void *AUBCommandStreamReceiverHw<GfxFamily>::flattenBatchBuffer(BatchBuffer &batchBuffer, size_t &sizeBatchBuffer) {
392- void *flatBatchBuffer = nullptr ;
393-
394- if (batchBuffer.chainedBatchBuffer ) {
395- batchBuffer.chainedBatchBuffer ->setTypeAubNonWritable ();
396- auto sizeMainBatchBuffer = batchBuffer.chainedBatchBufferStartOffset - batchBuffer.startOffset ;
397- auto flatBatchBufferSize = alignUp (sizeMainBatchBuffer + batchBuffer.chainedBatchBuffer ->getUnderlyingBufferSize (), MemoryConstants::pageSize);
398- flatBatchBuffer = this ->getMemoryManager ()->alignedMallocWrapper (flatBatchBufferSize, MemoryConstants::pageSize);
399- UNRECOVERABLE_IF (flatBatchBuffer == nullptr );
400- // Copy FLB
401- memcpy_s (flatBatchBuffer, sizeMainBatchBuffer, ptrOffset (batchBuffer.commandBufferAllocation ->getUnderlyingBuffer (), batchBuffer.startOffset ), sizeMainBatchBuffer);
402- // Copy SLB
403- memcpy_s (ptrOffset (flatBatchBuffer, sizeMainBatchBuffer), batchBuffer.chainedBatchBuffer ->getUnderlyingBufferSize (), batchBuffer.chainedBatchBuffer ->getUnderlyingBuffer (), batchBuffer.chainedBatchBuffer ->getUnderlyingBufferSize ());
404- sizeBatchBuffer = flatBatchBufferSize;
405- }
406- return flatBatchBuffer;
407- }
408-
409391template <typename GfxFamily>
410392bool AUBCommandStreamReceiverHw<GfxFamily>::addPatchInfoComments() {
411393 std::map<uint64_t , uint64_t > allocationsMap;
412394
413395 std::ostringstream str;
414396 str << " PatchInfoData" << std::endl;
415- for (auto &patchInfoData : this ->patchInfoCollection ) {
397+ for (auto &patchInfoData : this ->flatBatchBufferHelper -> getPatchInfoCollection () ) {
416398 str << std::hex << patchInfoData.sourceAllocation << " ;" ;
417399 str << std::hex << patchInfoData.sourceAllocationOffset << " ;" ;
418400 str << std::hex << patchInfoData.sourceType << " ;" ;
@@ -432,7 +414,7 @@ bool AUBCommandStreamReceiverHw<GfxFamily>::addPatchInfoComments() {
432414 }
433415 }
434416 bool result = stream->addComment (str.str ().c_str ());
435- this ->patchInfoCollection .clear ();
417+ this ->flatBatchBufferHelper -> getPatchInfoCollection () .clear ();
436418 if (!result) {
437419 return false ;
438420 }
@@ -547,8 +529,41 @@ void AUBCommandStreamReceiverHw<GfxFamily>::addContextToken() {
547529}
548530
549531template <typename GfxFamily>
550- bool AUBCommandStreamReceiverHw<GfxFamily>::setPatchInfoData(PatchInfoData &data) {
551- patchInfoCollection.push_back (data);
552- return true ;
532+ void AUBCommandStreamReceiverHw<GfxFamily>::addGUCStartMessage(uint64_t batchBufferAddress, EngineType engineType) {
533+ typedef typename GfxFamily::MI_BATCH_BUFFER_START MI_BATCH_BUFFER_START;
534+
535+ auto bufferSize = sizeof (uint32_t ) + sizeof (MI_BATCH_BUFFER_START);
536+
537+ std::unique_ptr<void , std::function<void (void *)>> buffer (this ->getMemoryManager ()->alignedMallocWrapper (bufferSize, MemoryConstants::pageSize), [&](void *ptr) { this ->getMemoryManager ()->alignedFreeWrapper (ptr); });
538+ LinearStream linearStream (buffer.get (), bufferSize);
539+
540+ uint32_t *header = static_cast <uint32_t *>(linearStream.getSpace (sizeof (uint32_t )));
541+ *header = getGUCWorkQueueItemHeader (engineType);
542+
543+ MI_BATCH_BUFFER_START *miBatchBufferStart = linearStream.getSpaceForCmd <MI_BATCH_BUFFER_START>();
544+ DEBUG_BREAK_IF (bufferSize != linearStream.getUsed ());
545+ miBatchBufferStart->init ();
546+ miBatchBufferStart->setBatchBufferStartAddressGraphicsaddress472 (AUB::ptrToPPGTT (buffer.get ()));
547+ miBatchBufferStart->setAddressSpaceIndicator (MI_BATCH_BUFFER_START::ADDRESS_SPACE_INDICATOR_PPGTT);
548+
549+ auto physBufferAddres = ppgtt.map (reinterpret_cast <uintptr_t >(buffer.get ()), bufferSize);
550+ AUB::reserveAddressPPGTT (*stream, reinterpret_cast <uintptr_t >(buffer.get ()), bufferSize, physBufferAddres);
551+
552+ AUB::addMemoryWrite (
553+ *stream,
554+ physBufferAddres,
555+ buffer.get (),
556+ bufferSize,
557+ AubMemDump::AddressSpaceValues::TraceNonlocal);
558+
559+ PatchInfoData patchInfoData (batchBufferAddress, 0u , PatchInfoAllocationType::Default, reinterpret_cast <uintptr_t >(buffer.get ()), sizeof (uint32_t ) + sizeof (MI_BATCH_BUFFER_START) - sizeof (uint64_t ), PatchInfoAllocationType::GUCStartMessage);
560+ this ->flatBatchBufferHelper ->setPatchInfoData (patchInfoData);
553561}
562+
563+ template <typename GfxFamily>
564+ uint32_t AUBCommandStreamReceiverHw<GfxFamily>::getGUCWorkQueueItemHeader(EngineType engineType) {
565+ uint32_t GUCWorkQueueItemHeader = 0x00030001 ;
566+ return GUCWorkQueueItemHeader;
567+ }
568+
554569} // namespace OCLRT
0 commit comments