|
8 | 8 | #include "runtime/command_stream/command_stream_receiver_hw.h" |
9 | 9 | #include "runtime/command_stream/experimental_command_buffer.h" |
10 | 10 | #include "runtime/command_stream/linear_stream.h" |
| 11 | +#include "runtime/command_stream/scratch_space_controller_base.h" |
11 | 12 | #include "runtime/device/device.h" |
12 | 13 | #include "runtime/event/event.h" |
13 | 14 | #include "runtime/gtpin/gtpin_notify.h" |
@@ -51,6 +52,7 @@ CommandStreamReceiverHw<GfxFamily>::CommandStreamReceiverHw(const HardwareInfo & |
51 | 52 | if (DebugManager.flags.EnableTimestampPacket.get() != -1) { |
52 | 53 | timestampPacketWriteEnabled = !!DebugManager.flags.EnableTimestampPacket.get(); |
53 | 54 | } |
| 55 | + createScratchSpaceController(hwInfoIn); |
54 | 56 | } |
55 | 57 |
|
56 | 58 | template <typename GfxFamily> |
@@ -237,22 +239,21 @@ CompletionStamp CommandStreamReceiverHw<GfxFamily>::flushTask( |
237 | 239 | csrSizeRequestFlags.numGrfRequiredChanged = this->lastSentNumGrfRequired != dispatchFlags.numGrfRequired; |
238 | 240 | csrSizeRequestFlags.specialPipelineSelectModeChanged = this->lastSpecialPipelineSelectMode != dispatchFlags.specialPipelineSelectMode; |
239 | 241 |
|
240 | | - size_t requiredScratchSizeInBytes = requiredScratchSize * device.getDeviceInfo().computeUnitsUsedForScratch; |
241 | | - |
242 | 242 | auto force32BitAllocations = getMemoryManager()->peekForce32BitAllocations(); |
243 | | - |
244 | 243 | bool stateBaseAddressDirty = false; |
245 | 244 |
|
246 | | - if (requiredScratchSize && (!scratchAllocation || scratchAllocation->getUnderlyingBufferSize() < requiredScratchSizeInBytes)) { |
247 | | - if (scratchAllocation) { |
248 | | - scratchAllocation->updateTaskCount(this->taskCount, this->deviceIndex); |
249 | | - internalAllocationStorage->storeAllocation(std::unique_ptr<GraphicsAllocation>(scratchAllocation), TEMPORARY_ALLOCATION); |
250 | | - } |
251 | | - createScratchSpaceAllocation(requiredScratchSizeInBytes); |
252 | | - overrideMediaVFEStateDirty(true); |
253 | | - if (is64bit && !force32BitAllocations) { |
254 | | - stateBaseAddressDirty = true; |
| 245 | + bool checkVfeStateDirty = false; |
| 246 | + if (requiredScratchSize) { |
| 247 | + scratchSpaceController->setRequiredScratchSpace(ssh.getCpuBase(), |
| 248 | + requiredScratchSize, |
| 249 | + this->taskCount, |
| 250 | + this->deviceIndex, |
| 251 | + stateBaseAddressDirty, |
| 252 | + checkVfeStateDirty); |
| 253 | + if (checkVfeStateDirty) { |
| 254 | + overrideMediaVFEStateDirty(true); |
255 | 255 | } |
| 256 | + makeResident(*scratchSpaceController->getScratchSpaceAllocation()); |
256 | 257 | } |
257 | 258 |
|
258 | 259 | auto &commandStreamCSR = this->getCS(getRequiredCmdStreamSizeAligned(dispatchFlags, device)); |
@@ -308,8 +309,8 @@ CompletionStamp CommandStreamReceiverHw<GfxFamily>::flushTask( |
308 | 309 |
|
309 | 310 | uint64_t newGSHbase = 0; |
310 | 311 | GSBAFor32BitProgrammed = false; |
311 | | - if (is64bit && scratchAllocation && !force32BitAllocations) { |
312 | | - newGSHbase = (uint64_t)scratchAllocation->getUnderlyingBuffer() - PreambleHelper<GfxFamily>::getScratchSpaceOffsetFor64bit(); |
| 312 | + if (is64bit && scratchSpaceController->getScratchSpaceAllocation() && !force32BitAllocations) { |
| 313 | + newGSHbase = scratchSpaceController->calculateNewGSH(); |
313 | 314 | } else if (is64bit && force32BitAllocations && dispatchFlags.GSBA32BitRequired) { |
314 | 315 | newGSHbase = getMemoryManager()->allocator32Bit->getBase(); |
315 | 316 | GSBAFor32BitProgrammed = true; |
@@ -381,9 +382,6 @@ CompletionStamp CommandStreamReceiverHw<GfxFamily>::flushTask( |
381 | 382 |
|
382 | 383 | this->makeResident(*tagAllocation); |
383 | 384 |
|
384 | | - if (requiredScratchSize) |
385 | | - makeResident(*scratchAllocation); |
386 | | - |
387 | 385 | if (preemptionCsrAllocation) |
388 | 386 | makeResident(*preemptionCsrAllocation); |
389 | 387 |
|
@@ -608,22 +606,6 @@ void CommandStreamReceiverHw<GfxFamily>::addPipeControl(LinearStream &commandStr |
608 | 606 | } |
609 | 607 | } |
610 | 608 |
|
611 | | -template <typename GfxFamily> |
612 | | -uint64_t CommandStreamReceiverHw<GfxFamily>::getScratchPatchAddress() { |
613 | | - //for 32 bit scratch space pointer is being programmed in Media VFE State and is relative to 0 as General State Base Address |
614 | | - //for 64 bit, scratch space pointer is being programmed as "General State Base Address - scratchSpaceOffsetFor64bit" |
615 | | - // and "0 + scratchSpaceOffsetFor64bit" is being programmed in Media VFE state |
616 | | - |
617 | | - uint64_t scratchAddress = 0; |
618 | | - if (requiredScratchSize) { |
619 | | - scratchAddress = scratchAllocation->getGpuAddressToPatch(); |
620 | | - if (is64bit && !getMemoryManager()->peekForce32BitAllocations()) { |
621 | | - //this is to avoid scractch allocation offset "0" |
622 | | - scratchAddress = PreambleHelper<GfxFamily>::getScratchSpaceOffsetFor64bit(); |
623 | | - } |
624 | | - } |
625 | | - return scratchAddress; |
626 | | -} |
627 | 609 | template <typename GfxFamily> |
628 | 610 | size_t CommandStreamReceiverHw<GfxFamily>::getRequiredCmdStreamSizeAligned(const DispatchFlags &dispatchFlags, Device &device) { |
629 | 611 | size_t size = getRequiredCmdStreamSize(dispatchFlags, device); |
@@ -821,7 +803,12 @@ void CommandStreamReceiverHw<GfxFamily>::handleEventsTimestampPacketTags(LinearS |
821 | 803 | } |
822 | 804 |
|
823 | 805 | template <typename GfxFamily> |
824 | | -void CommandStreamReceiverHw<GfxFamily>::createScratchSpaceAllocation(size_t requiredScratchSizeInBytes) { |
825 | | - scratchAllocation = getMemoryManager()->allocateGraphicsMemoryInPreferredPool(AllocationFlags(true), 0, nullptr, requiredScratchSizeInBytes, GraphicsAllocation::AllocationType::SCRATCH_SURFACE); |
| 806 | +void CommandStreamReceiverHw<GfxFamily>::createScratchSpaceController(const HardwareInfo &hwInfoIn) { |
| 807 | + scratchSpaceController = std::make_unique<ScratchSpaceControllerBase>(hwInfoIn, executionEnvironment, *internalAllocationStorage.get()); |
| 808 | +} |
| 809 | + |
| 810 | +template <typename GfxFamily> |
| 811 | +uint64_t CommandStreamReceiverHw<GfxFamily>::getScratchPatchAddress() { |
| 812 | + return scratchSpaceController->getScratchPatchAddress(); |
826 | 813 | } |
827 | 814 | } // namespace OCLRT |
0 commit comments