From 47dbe359bfb7636c1259f3724fe3e3eea75f6267 Mon Sep 17 00:00:00 2001 From: Zbigniew Zdanowicz Date: Thu, 2 Dec 2021 14:17:45 +0000 Subject: [PATCH] Add command encoder for store data command Related-To: NEO-6262 Signed-off-by: Zbigniew Zdanowicz --- level_zero/core/source/cmdlist/cmdlist_hw.inl | 14 ++- .../core/source/debugger/debugger_l0.inl | 94 ++++++++----------- .../command_container/command_encoder.h | 22 +++++ .../command_container/command_encoder.inl | 16 ++++ .../command_encoder_bdw_and_later.inl | 20 ++++ .../command_encoder_xehp_and_later.inl | 22 +++++ .../dispatchers/dispatcher.inl | 20 ++-- shared/source/gen11/command_encoder_gen11.cpp | 1 + .../gen12lp/command_encoder_gen12lp.cpp | 1 + shared/source/gen8/command_encoder_gen8.cpp | 1 + shared/source/gen9/command_encoder_gen9.cpp | 1 + .../helpers/flat_batch_buffer_helper_hw.inl | 35 ++++--- .../source/utilities/software_tags_manager.h | 34 +++---- .../xe_hp_core/command_encoder_xe_hp_core.cpp | 1 + .../command_encoder_xe_hpg_core.cpp | 1 + .../command_encoder_tests_xehp_and_later.cpp | 47 ++++++++++ .../encoders/test_command_encoder.cpp | 63 +++++++++++++ 17 files changed, 284 insertions(+), 109 deletions(-) diff --git a/level_zero/core/source/cmdlist/cmdlist_hw.inl b/level_zero/core/source/cmdlist/cmdlist_hw.inl index da0f2f4844..27dc4d0b06 100644 --- a/level_zero/core/source/cmdlist/cmdlist_hw.inl +++ b/level_zero/core/source/cmdlist/cmdlist_hw.inl @@ -1829,14 +1829,12 @@ ze_result_t CommandListCoreFamily::appendSignalEvent(ze_event_han commandContainer.getDevice()->getHardwareInfo(), args); } else { - using MI_STORE_DATA_IMM = typename GfxFamily::MI_STORE_DATA_IMM; - MI_STORE_DATA_IMM storeDataImmediate = GfxFamily::cmdInitStoreDataImm; - storeDataImmediate.setAddress(ptrOffset(baseAddr, eventSignalOffset)); - storeDataImmediate.setStoreQword(false); - storeDataImmediate.setDwordLength(MI_STORE_DATA_IMM::DWORD_LENGTH::DWORD_LENGTH_STORE_DWORD); - storeDataImmediate.setDataDword0(Event::STATE_SIGNALED); - auto buffer = commandContainer.getCommandStream()->template getSpaceForCmd(); - *buffer = storeDataImmediate; + NEO::EncodeStoreMemory::programStoreDataImm(*commandContainer.getCommandStream(), + ptrOffset(baseAddr, eventSignalOffset), + Event::STATE_SIGNALED, + 0u, + false, + false); } } diff --git a/level_zero/core/source/debugger/debugger_l0.inl b/level_zero/core/source/debugger/debugger_l0.inl index 28fc3dab80..63592ea84c 100644 --- a/level_zero/core/source/debugger/debugger_l0.inl +++ b/level_zero/core/source/debugger/debugger_l0.inl @@ -5,6 +5,7 @@ * */ +#include "shared/source/command_container/command_encoder.h" #include "shared/source/command_stream/linear_stream.h" #include "shared/source/debug_settings/debug_settings_manager.h" #include "shared/source/gmm_helper/gmm_helper.h" @@ -17,12 +18,11 @@ namespace L0 { template size_t DebuggerL0Hw::getSbaTrackingCommandsSize(size_t trackedAddressCount) { - return trackedAddressCount * sizeof(typename GfxFamily::MI_STORE_DATA_IMM); + return trackedAddressCount * NEO::EncodeStoreMemory::getStoreDataImmSize(); } template void DebuggerL0Hw::programSbaTrackingCommands(NEO::LinearStream &cmdStream, const SbaAddresses &sba) { - using MI_STORE_DATA_IMM = typename GfxFamily::MI_STORE_DATA_IMM; auto gpuAddress = NEO::GmmHelper::decanonize(sbaTrackingGpuVa.address); PRINT_DEBUGGER_INFO_LOG("Debugger: SBA stored ssh = %" SCNx64 @@ -35,70 +35,52 @@ void DebuggerL0Hw::programSbaTrackingCommands(NEO::LinearStream &cmdS sba.IndirectObjectBaseAddress, sba.InstructionBaseAddress, sba.BindlessSurfaceStateBaseAddress); if (sba.GeneralStateBaseAddress) { - MI_STORE_DATA_IMM storeDataImmediate = GfxFamily::cmdInitStoreDataImm; - storeDataImmediate.setAddress(gpuAddress + offsetof(SbaTrackedAddresses, GeneralStateBaseAddress)); - storeDataImmediate.setStoreQword(true); - storeDataImmediate.setDwordLength(MI_STORE_DATA_IMM::DWORD_LENGTH::DWORD_LENGTH_STORE_QWORD); - storeDataImmediate.setDataDword0(static_cast(sba.GeneralStateBaseAddress & 0x0000FFFFFFFFULL)); - storeDataImmediate.setDataDword1(static_cast(sba.GeneralStateBaseAddress >> 32)); - - auto storeDataImmediateSpace = cmdStream.getSpaceForCmd(); - *storeDataImmediateSpace = storeDataImmediate; + NEO::EncodeStoreMemory::programStoreDataImm(cmdStream, + gpuAddress + offsetof(SbaTrackedAddresses, GeneralStateBaseAddress), + static_cast(sba.GeneralStateBaseAddress & 0x0000FFFFFFFFULL), + static_cast(sba.GeneralStateBaseAddress >> 32), + true, + false); } if (sba.SurfaceStateBaseAddress) { - MI_STORE_DATA_IMM storeDataImmediate = GfxFamily::cmdInitStoreDataImm; - storeDataImmediate.setAddress(gpuAddress + offsetof(SbaTrackedAddresses, SurfaceStateBaseAddress)); - storeDataImmediate.setStoreQword(true); - storeDataImmediate.setDwordLength(MI_STORE_DATA_IMM::DWORD_LENGTH::DWORD_LENGTH_STORE_QWORD); - storeDataImmediate.setDataDword0(static_cast(sba.SurfaceStateBaseAddress & 0x0000FFFFFFFFULL)); - storeDataImmediate.setDataDword1(static_cast(sba.SurfaceStateBaseAddress >> 32)); - - auto storeDataImmediateSpace = cmdStream.getSpaceForCmd(); - *storeDataImmediateSpace = storeDataImmediate; + NEO::EncodeStoreMemory::programStoreDataImm(cmdStream, + gpuAddress + offsetof(SbaTrackedAddresses, SurfaceStateBaseAddress), + static_cast(sba.SurfaceStateBaseAddress & 0x0000FFFFFFFFULL), + static_cast(sba.SurfaceStateBaseAddress >> 32), + true, + false); } if (sba.DynamicStateBaseAddress) { - MI_STORE_DATA_IMM storeDataImmediate = GfxFamily::cmdInitStoreDataImm; - storeDataImmediate.setAddress(gpuAddress + offsetof(SbaTrackedAddresses, DynamicStateBaseAddress)); - storeDataImmediate.setStoreQword(true); - storeDataImmediate.setDwordLength(MI_STORE_DATA_IMM::DWORD_LENGTH::DWORD_LENGTH_STORE_QWORD); - storeDataImmediate.setDataDword0(static_cast(sba.DynamicStateBaseAddress & 0x0000FFFFFFFFULL)); - storeDataImmediate.setDataDword1(static_cast(sba.DynamicStateBaseAddress >> 32)); - - auto storeDataImmediateSpace = cmdStream.getSpaceForCmd(); - *storeDataImmediateSpace = storeDataImmediate; + NEO::EncodeStoreMemory::programStoreDataImm(cmdStream, + gpuAddress + offsetof(SbaTrackedAddresses, DynamicStateBaseAddress), + static_cast(sba.DynamicStateBaseAddress & 0x0000FFFFFFFFULL), + static_cast(sba.DynamicStateBaseAddress >> 32), + true, + false); } if (sba.IndirectObjectBaseAddress) { - MI_STORE_DATA_IMM storeDataImmediate = GfxFamily::cmdInitStoreDataImm; - storeDataImmediate.setAddress(gpuAddress + offsetof(SbaTrackedAddresses, IndirectObjectBaseAddress)); - storeDataImmediate.setStoreQword(true); - storeDataImmediate.setDwordLength(MI_STORE_DATA_IMM::DWORD_LENGTH::DWORD_LENGTH_STORE_QWORD); - storeDataImmediate.setDataDword0(static_cast(sba.IndirectObjectBaseAddress & 0x0000FFFFFFFFULL)); - storeDataImmediate.setDataDword1(static_cast(sba.IndirectObjectBaseAddress >> 32)); - - auto storeDataImmediateSpace = cmdStream.getSpaceForCmd(); - *storeDataImmediateSpace = storeDataImmediate; + NEO::EncodeStoreMemory::programStoreDataImm(cmdStream, + gpuAddress + offsetof(SbaTrackedAddresses, IndirectObjectBaseAddress), + static_cast(sba.IndirectObjectBaseAddress & 0x0000FFFFFFFFULL), + static_cast(sba.IndirectObjectBaseAddress >> 32), + true, + false); } if (sba.InstructionBaseAddress) { - MI_STORE_DATA_IMM storeDataImmediate = GfxFamily::cmdInitStoreDataImm; - storeDataImmediate.setAddress(gpuAddress + offsetof(SbaTrackedAddresses, InstructionBaseAddress)); - storeDataImmediate.setStoreQword(true); - storeDataImmediate.setDwordLength(MI_STORE_DATA_IMM::DWORD_LENGTH::DWORD_LENGTH_STORE_QWORD); - storeDataImmediate.setDataDword0(static_cast(sba.InstructionBaseAddress & 0x0000FFFFFFFFULL)); - storeDataImmediate.setDataDword1(static_cast(sba.InstructionBaseAddress >> 32)); - - auto storeDataImmediateSpace = cmdStream.getSpaceForCmd(); - *storeDataImmediateSpace = storeDataImmediate; + NEO::EncodeStoreMemory::programStoreDataImm(cmdStream, + gpuAddress + offsetof(SbaTrackedAddresses, InstructionBaseAddress), + static_cast(sba.InstructionBaseAddress & 0x0000FFFFFFFFULL), + static_cast(sba.InstructionBaseAddress >> 32), + true, + false); } if (sba.BindlessSurfaceStateBaseAddress) { - MI_STORE_DATA_IMM storeDataImmediate = GfxFamily::cmdInitStoreDataImm; - storeDataImmediate.setAddress(gpuAddress + offsetof(SbaTrackedAddresses, BindlessSurfaceStateBaseAddress)); - storeDataImmediate.setStoreQword(true); - storeDataImmediate.setDwordLength(MI_STORE_DATA_IMM::DWORD_LENGTH::DWORD_LENGTH_STORE_QWORD); - storeDataImmediate.setDataDword0(static_cast(sba.BindlessSurfaceStateBaseAddress & 0x0000FFFFFFFFULL)); - storeDataImmediate.setDataDword1(static_cast(sba.BindlessSurfaceStateBaseAddress >> 32)); - - auto storeDataImmediateSpace = cmdStream.getSpaceForCmd(); - *storeDataImmediateSpace = storeDataImmediate; + NEO::EncodeStoreMemory::programStoreDataImm(cmdStream, + gpuAddress + offsetof(SbaTrackedAddresses, BindlessSurfaceStateBaseAddress), + static_cast(sba.BindlessSurfaceStateBaseAddress & 0x0000FFFFFFFFULL), + static_cast(sba.BindlessSurfaceStateBaseAddress >> 32), + true, + false); } } diff --git a/shared/source/command_container/command_encoder.h b/shared/source/command_container/command_encoder.h index 4e12ed27da..c2f644da98 100644 --- a/shared/source/command_container/command_encoder.h +++ b/shared/source/command_container/command_encoder.h @@ -391,4 +391,26 @@ struct EncodeNoop { static void emitNoop(LinearStream &commandStream, size_t bytesToUpdate); }; +template +struct EncodeStoreMemory { + using MI_STORE_DATA_IMM = typename GfxFamily::MI_STORE_DATA_IMM; + static void programStoreDataImm(LinearStream &commandStream, + uint64_t gpuAddress, + uint32_t dataDword0, + uint32_t dataDword1, + bool storeQword, + bool workloadPartitionOffset); + + static void programStoreDataImm(MI_STORE_DATA_IMM *cmdBuffer, + uint64_t gpuAddress, + uint32_t dataDword0, + uint32_t dataDword1, + bool storeQword, + bool workloadPartitionOffset); + + static size_t getStoreDataImmSize() { + return sizeof(MI_STORE_DATA_IMM); + } +}; + } // namespace NEO diff --git a/shared/source/command_container/command_encoder.inl b/shared/source/command_container/command_encoder.inl index ac5727aa4a..0bface89d9 100644 --- a/shared/source/command_container/command_encoder.inl +++ b/shared/source/command_container/command_encoder.inl @@ -841,4 +841,20 @@ inline void EncodeNoop::emitNoop(LinearStream &commandStream, size_t byt } } +template +inline void EncodeStoreMemory::programStoreDataImm(LinearStream &commandStream, + uint64_t gpuAddress, + uint32_t dataDword0, + uint32_t dataDword1, + bool storeQword, + bool workloadPartitionOffset) { + auto miStoreDataImmBuffer = commandStream.getSpaceForCmd(); + EncodeStoreMemory::programStoreDataImm(miStoreDataImmBuffer, + gpuAddress, + dataDword0, + dataDword1, + storeQword, + workloadPartitionOffset); +} + } // namespace NEO diff --git a/shared/source/command_container/command_encoder_bdw_and_later.inl b/shared/source/command_container/command_encoder_bdw_and_later.inl index af5650befc..c53f48afc5 100644 --- a/shared/source/command_container/command_encoder_bdw_and_later.inl +++ b/shared/source/command_container/command_encoder_bdw_and_later.inl @@ -484,4 +484,24 @@ template void EncodeEnableRayTracing::programEnableRayTracing(LinearStream &commandStream, GraphicsAllocation &backBuffer) { } +template +inline void EncodeStoreMemory::programStoreDataImm(MI_STORE_DATA_IMM *cmdBuffer, + uint64_t gpuAddress, + uint32_t dataDword0, + uint32_t dataDword1, + bool storeQword, + bool workloadPartitionOffset) { + MI_STORE_DATA_IMM storeDataImmediate = Family::cmdInitStoreDataImm; + storeDataImmediate.setAddress(gpuAddress); + storeDataImmediate.setStoreQword(storeQword); + storeDataImmediate.setDataDword0(dataDword0); + if (storeQword) { + storeDataImmediate.setDataDword1(dataDword1); + storeDataImmediate.setDwordLength(MI_STORE_DATA_IMM::DWORD_LENGTH::DWORD_LENGTH_STORE_QWORD); + } else { + storeDataImmediate.setDwordLength(MI_STORE_DATA_IMM::DWORD_LENGTH::DWORD_LENGTH_STORE_DWORD); + } + *cmdBuffer = storeDataImmediate; +} + } // namespace NEO diff --git a/shared/source/command_container/command_encoder_xehp_and_later.inl b/shared/source/command_container/command_encoder_xehp_and_later.inl index f2b43164e0..658ea8d698 100644 --- a/shared/source/command_container/command_encoder_xehp_and_later.inl +++ b/shared/source/command_container/command_encoder_xehp_and_later.inl @@ -704,4 +704,26 @@ template inline size_t EncodeWA::getAdditionalPipelineSelectSize(Device &device) { return 0u; } + +template +inline void EncodeStoreMemory::programStoreDataImm(MI_STORE_DATA_IMM *cmdBuffer, + uint64_t gpuAddress, + uint32_t dataDword0, + uint32_t dataDword1, + bool storeQword, + bool workloadPartitionOffset) { + MI_STORE_DATA_IMM storeDataImmediate = Family::cmdInitStoreDataImm; + storeDataImmediate.setAddress(gpuAddress); + storeDataImmediate.setStoreQword(storeQword); + storeDataImmediate.setDataDword0(dataDword0); + if (storeQword) { + storeDataImmediate.setDataDword1(dataDword1); + storeDataImmediate.setDwordLength(MI_STORE_DATA_IMM::DWORD_LENGTH::DWORD_LENGTH_STORE_QWORD); + } else { + storeDataImmediate.setDwordLength(MI_STORE_DATA_IMM::DWORD_LENGTH::DWORD_LENGTH_STORE_DWORD); + } + storeDataImmediate.setWorkloadPartitionIdOffsetEnable(workloadPartitionOffset); + *cmdBuffer = storeDataImmediate; +} + } // namespace NEO diff --git a/shared/source/direct_submission/dispatchers/dispatcher.inl b/shared/source/direct_submission/dispatchers/dispatcher.inl index 4cc2d6e675..543a60fc05 100644 --- a/shared/source/direct_submission/dispatchers/dispatcher.inl +++ b/shared/source/direct_submission/dispatchers/dispatcher.inl @@ -1,10 +1,11 @@ /* - * Copyright (C) 2020 Intel Corporation + * Copyright (C) 2020-2021 Intel Corporation * * SPDX-License-Identifier: MIT * */ +#include "shared/source/command_container/command_encoder.h" #include "shared/source/command_stream/linear_stream.h" #include "shared/source/direct_submission/dispatchers/dispatcher.h" @@ -48,20 +49,17 @@ inline size_t Dispatcher::getSizeStopCommandBuffer() { template inline void Dispatcher::dispatchStoreDwordCommand(LinearStream &cmdBuffer, uint64_t gpuVa, uint32_t value) { - using MI_STORE_DATA_IMM = typename GfxFamily::MI_STORE_DATA_IMM; - - MI_STORE_DATA_IMM cmd = GfxFamily::cmdInitStoreDataImm; - cmd.setAddress(gpuVa); - cmd.setDataDword0(value); - - auto storeDataImmediate = cmdBuffer.getSpaceForCmd(); - *storeDataImmediate = cmd; + EncodeStoreMemory::programStoreDataImm(cmdBuffer, + gpuVa, + value, + 0, + false, + false); } template inline size_t Dispatcher::getSizeStoreDwordCommand() { - using MI_STORE_DATA_IMM = typename GfxFamily::MI_STORE_DATA_IMM; - return sizeof(MI_STORE_DATA_IMM); + return EncodeStoreMemory::getStoreDataImmSize(); } } // namespace NEO diff --git a/shared/source/gen11/command_encoder_gen11.cpp b/shared/source/gen11/command_encoder_gen11.cpp index 3f9fff2d36..eebdc9dd61 100644 --- a/shared/source/gen11/command_encoder_gen11.cpp +++ b/shared/source/gen11/command_encoder_gen11.cpp @@ -59,4 +59,5 @@ template struct EncodeMiArbCheck; template struct EncodeComputeMode; template struct EncodeEnableRayTracing; template struct EncodeNoop; +template struct EncodeStoreMemory; } // namespace NEO diff --git a/shared/source/gen12lp/command_encoder_gen12lp.cpp b/shared/source/gen12lp/command_encoder_gen12lp.cpp index 4e6a2d8d7e..999ce8f4d8 100644 --- a/shared/source/gen12lp/command_encoder_gen12lp.cpp +++ b/shared/source/gen12lp/command_encoder_gen12lp.cpp @@ -116,4 +116,5 @@ template struct EncodeMiArbCheck; template struct EncodeComputeMode; template struct EncodeEnableRayTracing; template struct EncodeNoop; +template struct EncodeStoreMemory; } // namespace NEO diff --git a/shared/source/gen8/command_encoder_gen8.cpp b/shared/source/gen8/command_encoder_gen8.cpp index f59caf07b8..9ba956ed85 100644 --- a/shared/source/gen8/command_encoder_gen8.cpp +++ b/shared/source/gen8/command_encoder_gen8.cpp @@ -53,4 +53,5 @@ template struct EncodeMiArbCheck; template struct EncodeComputeMode; template struct EncodeEnableRayTracing; template struct EncodeNoop; +template struct EncodeStoreMemory; } // namespace NEO diff --git a/shared/source/gen9/command_encoder_gen9.cpp b/shared/source/gen9/command_encoder_gen9.cpp index f76669b3db..9a2ea65ee5 100644 --- a/shared/source/gen9/command_encoder_gen9.cpp +++ b/shared/source/gen9/command_encoder_gen9.cpp @@ -53,4 +53,5 @@ template struct EncodeMiArbCheck; template struct EncodeComputeMode; template struct EncodeEnableRayTracing; template struct EncodeNoop; +template struct EncodeStoreMemory; } // namespace NEO diff --git a/shared/source/helpers/flat_batch_buffer_helper_hw.inl b/shared/source/helpers/flat_batch_buffer_helper_hw.inl index b4260b351b..f7d3eb58ea 100644 --- a/shared/source/helpers/flat_batch_buffer_helper_hw.inl +++ b/shared/source/helpers/flat_batch_buffer_helper_hw.inl @@ -5,6 +5,7 @@ * */ +#include "shared/source/command_container/command_encoder.h" #include "shared/source/command_stream/command_stream_receiver.h" #include "shared/source/helpers/flat_batch_buffer_helper_hw.h" #include "shared/source/helpers/hw_helper.h" @@ -145,12 +146,10 @@ GraphicsAllocation *FlatBatchBufferHelperHw::flattenBatchBuffer(uint3 template char *FlatBatchBufferHelperHw::getIndirectPatchCommands(size_t &indirectPatchCommandsSize, std::vector &indirectPatchInfo) { - typedef typename GfxFamily::MI_STORE_DATA_IMM MI_STORE_DATA_IMM; - indirectPatchCommandsSize = 0; for (auto &patchInfoData : patchInfoCollection) { if (patchInfoData.requiresIndirectPatching()) { - indirectPatchCommandsSize += sizeof(MI_STORE_DATA_IMM); + indirectPatchCommandsSize += EncodeStoreMemory::getStoreDataImmSize(); } } @@ -163,20 +162,28 @@ char *FlatBatchBufferHelperHw::getIndirectPatchCommands(size_t &indir for (auto &patchInfoData : patchInfoCopy) { if (patchInfoData.requiresIndirectPatching()) { bool is32BitAddress = patchInfoData.patchAddressSize == sizeof(uint32_t); - auto storeDataImmediateSpace = indirectPatchCommandStream.getSpaceForCmd(); - auto storeDataImmediate = GfxFamily::cmdInitStoreDataImm; - storeDataImmediate.setAddress(patchInfoData.targetAllocation + patchInfoData.targetAllocationOffset); - storeDataImmediate.setStoreQword(!is32BitAddress); - storeDataImmediate.setDwordLength(is32BitAddress ? MI_STORE_DATA_IMM::DWORD_LENGTH::DWORD_LENGTH_STORE_DWORD : MI_STORE_DATA_IMM::DWORD_LENGTH::DWORD_LENGTH_STORE_QWORD); - storeDataImmediate.setDataDword0(static_cast((patchInfoData.sourceAllocation + patchInfoData.sourceAllocationOffset) & 0x0000FFFFFFFFULL)); - storeDataImmediate.setDataDword1(static_cast((patchInfoData.sourceAllocation + patchInfoData.sourceAllocationOffset) >> 32)); - *storeDataImmediateSpace = storeDataImmediate; + EncodeStoreMemory::programStoreDataImm(indirectPatchCommandStream, + patchInfoData.targetAllocation + patchInfoData.targetAllocationOffset, + static_cast((patchInfoData.sourceAllocation + patchInfoData.sourceAllocationOffset) & 0x0000FFFFFFFFULL), + static_cast((patchInfoData.sourceAllocation + patchInfoData.sourceAllocationOffset) >> 32), + !is32BitAddress, + false); - PatchInfoData patchInfoForAddress(patchInfoData.targetAllocation, patchInfoData.targetAllocationOffset, patchInfoData.targetType, 0u, stiCommandOffset + sizeof(MI_STORE_DATA_IMM) - 2 * sizeof(uint64_t), PatchInfoAllocationType::Default); - PatchInfoData patchInfoForValue(patchInfoData.sourceAllocation, patchInfoData.sourceAllocationOffset, patchInfoData.sourceType, 0u, stiCommandOffset + sizeof(MI_STORE_DATA_IMM) - sizeof(uint64_t), PatchInfoAllocationType::Default); + PatchInfoData patchInfoForAddress(patchInfoData.targetAllocation, + patchInfoData.targetAllocationOffset, + patchInfoData.targetType, + 0u, + stiCommandOffset + EncodeStoreMemory::getStoreDataImmSize() - 2 * sizeof(uint64_t), + PatchInfoAllocationType::Default); + PatchInfoData patchInfoForValue(patchInfoData.sourceAllocation, + patchInfoData.sourceAllocationOffset, + patchInfoData.sourceType, + 0u, + stiCommandOffset + EncodeStoreMemory::getStoreDataImmSize() - sizeof(uint64_t), + PatchInfoAllocationType::Default); indirectPatchInfo.push_back(patchInfoForAddress); indirectPatchInfo.push_back(patchInfoForValue); - stiCommandOffset += sizeof(MI_STORE_DATA_IMM); + stiCommandOffset += EncodeStoreMemory::getStoreDataImmSize(); } else { patchInfoCollection.push_back(patchInfoData); } diff --git a/shared/source/utilities/software_tags_manager.h b/shared/source/utilities/software_tags_manager.h index 659a6d5563..8a95243af2 100644 --- a/shared/source/utilities/software_tags_manager.h +++ b/shared/source/utilities/software_tags_manager.h @@ -6,6 +6,7 @@ */ #pragma once +#include "shared/source/command_container/command_encoder.h" #include "shared/source/debug_settings/debug_settings_manager.h" #include "shared/source/memory_manager/memory_manager.h" #include "shared/source/utilities/software_tags.h" @@ -56,32 +57,26 @@ class SWTagsManager { template void SWTagsManager::insertBXMLHeapAddress(LinearStream &cmdStream) { - using MI_STORE_DATA_IMM = typename GfxFamily::MI_STORE_DATA_IMM; - auto ptr = reinterpret_cast(memoryManager->lockResource(bxmlHeap)); - MI_STORE_DATA_IMM storeDataImm = GfxFamily::cmdInitStoreDataImm; - storeDataImm.setAddress(bxmlHeap->getGpuAddress()); - storeDataImm.setDwordLength(MI_STORE_DATA_IMM::DWORD_LENGTH::DWORD_LENGTH_STORE_DWORD); - storeDataImm.setDataDword0(ptr->magicNumber); + EncodeStoreMemory::programStoreDataImm(cmdStream, + bxmlHeap->getGpuAddress(), + ptr->magicNumber, + 0, + false, + false); memoryManager->unlockResource(bxmlHeap); - - auto sdiSpace = cmdStream.getSpaceForCmd(); - *sdiSpace = storeDataImm; } template void SWTagsManager::insertSWTagHeapAddress(LinearStream &cmdStream) { - using MI_STORE_DATA_IMM = typename GfxFamily::MI_STORE_DATA_IMM; - auto ptr = reinterpret_cast(memoryManager->lockResource(tagHeap)); - MI_STORE_DATA_IMM storeDataImm = GfxFamily::cmdInitStoreDataImm; - storeDataImm.setAddress(tagHeap->getGpuAddress()); - storeDataImm.setDwordLength(MI_STORE_DATA_IMM::DWORD_LENGTH::DWORD_LENGTH_STORE_DWORD); - storeDataImm.setDataDword0(ptr->magicNumber); + EncodeStoreMemory::programStoreDataImm(cmdStream, + tagHeap->getGpuAddress(), + ptr->magicNumber, + 0, + false, + false); memoryManager->unlockResource(tagHeap); - - auto sdiSpace = cmdStream.getSpaceForCmd(); - *sdiSpace = storeDataImm; } template @@ -115,10 +110,9 @@ void SWTagsManager::insertTag(LinearStream &cmdStream, Device &device, Params... template size_t SWTagsManager::estimateSpaceForSWTags() { - using MI_STORE_DATA_IMM = typename GfxFamily::MI_STORE_DATA_IMM; using MI_NOOP = typename GfxFamily::MI_NOOP; - return 2 * sizeof(MI_STORE_DATA_IMM) + 2 * MAX_TAG_COUNT * sizeof(MI_NOOP); + return 2 * EncodeStoreMemory::getStoreDataImmSize() + 2 * MAX_TAG_COUNT * sizeof(MI_NOOP); } } // namespace NEO diff --git a/shared/source/xe_hp_core/command_encoder_xe_hp_core.cpp b/shared/source/xe_hp_core/command_encoder_xe_hp_core.cpp index 6875a40c03..c352bc427b 100644 --- a/shared/source/xe_hp_core/command_encoder_xe_hp_core.cpp +++ b/shared/source/xe_hp_core/command_encoder_xe_hp_core.cpp @@ -72,4 +72,5 @@ template struct EncodeMiArbCheck; template struct EncodeWA; template struct EncodeEnableRayTracing; template struct EncodeNoop; +template struct EncodeStoreMemory; } // namespace NEO diff --git a/shared/source/xe_hpg_core/command_encoder_xe_hpg_core.cpp b/shared/source/xe_hpg_core/command_encoder_xe_hpg_core.cpp index f961dfa49e..c8eded3ca3 100644 --- a/shared/source/xe_hpg_core/command_encoder_xe_hpg_core.cpp +++ b/shared/source/xe_hpg_core/command_encoder_xe_hpg_core.cpp @@ -188,4 +188,5 @@ template struct EncodeMiArbCheck; template struct EncodeWA; template struct EncodeEnableRayTracing; template struct EncodeNoop; +template struct EncodeStoreMemory; } // namespace NEO diff --git a/shared/test/unit_test/encoders/command_encoder_tests_xehp_and_later.cpp b/shared/test/unit_test/encoders/command_encoder_tests_xehp_and_later.cpp index bb25926e72..4e127e5407 100644 --- a/shared/test/unit_test/encoders/command_encoder_tests_xehp_and_later.cpp +++ b/shared/test/unit_test/encoders/command_encoder_tests_xehp_and_later.cpp @@ -6,6 +6,7 @@ */ #include "shared/source/command_container/command_encoder.h" +#include "shared/test/common/cmd_parse/gen_cmd_parse.h" #include "shared/test/common/fixtures/device_fixture.h" #include "shared/test/common/mocks/mock_device.h" @@ -49,3 +50,49 @@ HWTEST2_F(XeHPAndLaterCommandEncoderTest, givenCommandContainerWithDirtyHeapWhen size_t size = EncodeStateBaseAddress::getRequiredSizeForStateBaseAddress(*pDevice, container); EXPECT_EQ(size, 104ul); } + +HWCMDTEST_F(IGFX_XE_HP_CORE, XeHPAndLaterHardwareCommandsTest, givenPartitionArgumentFalseWhenAddingStoreDataImmThenExpectCommandFlagFalse) { + using MI_STORE_DATA_IMM = typename FamilyType::MI_STORE_DATA_IMM; + + uint64_t gpuAddress = 0xFF0000; + uint32_t dword0 = 0x123; + uint32_t dword1 = 0x456; + + constexpr size_t bufferSize = 64; + uint8_t buffer[bufferSize]; + LinearStream cmdStream(buffer, bufferSize); + + EncodeStoreMemory::programStoreDataImm(cmdStream, + gpuAddress, + dword0, + dword1, + false, + false); + + auto storeDataImm = genCmdCast(buffer); + ASSERT_NE(nullptr, storeDataImm); + EXPECT_FALSE(storeDataImm->getWorkloadPartitionIdOffsetEnable()); +} + +HWCMDTEST_F(IGFX_XE_HP_CORE, XeHPAndLaterHardwareCommandsTest, givenPartitionArgumentTrueWhenAddingStoreDataImmThenExpectCommandFlagTrue) { + using MI_STORE_DATA_IMM = typename FamilyType::MI_STORE_DATA_IMM; + + uint64_t gpuAddress = 0xFF0000; + uint32_t dword0 = 0x123; + uint32_t dword1 = 0x456; + + constexpr size_t bufferSize = 64; + uint8_t buffer[bufferSize]; + LinearStream cmdStream(buffer, bufferSize); + + EncodeStoreMemory::programStoreDataImm(cmdStream, + gpuAddress, + dword0, + dword1, + false, + true); + + auto storeDataImm = genCmdCast(buffer); + ASSERT_NE(nullptr, storeDataImm); + EXPECT_TRUE(storeDataImm->getWorkloadPartitionIdOffsetEnable()); +} diff --git a/shared/test/unit_test/encoders/test_command_encoder.cpp b/shared/test/unit_test/encoders/test_command_encoder.cpp index 09860d27a1..cf4d9d95df 100644 --- a/shared/test/unit_test/encoders/test_command_encoder.cpp +++ b/shared/test/unit_test/encoders/test_command_encoder.cpp @@ -6,6 +6,7 @@ */ #include "shared/source/command_container/cmdcontainer.h" +#include "shared/test/common/cmd_parse/gen_cmd_parse.h" #include "shared/test/common/fixtures/device_fixture.h" #include "test.h" @@ -62,3 +63,65 @@ HWTEST2_F(CommandEncoderTest, givenICLLPWhenGettingRequiredSizeForStateBaseAddre size_t size = EncodeStateBaseAddress::getRequiredSizeForStateBaseAddress(*pDevice, container); EXPECT_EQ(size, 88ul); } + +HWTEST_F(CommandEncoderTest, GivenDwordStoreWhenAddingStoreDataImmThenExpectDwordProgramming) { + using MI_STORE_DATA_IMM = typename FamilyType::MI_STORE_DATA_IMM; + size_t size = EncodeStoreMemory::getStoreDataImmSize(); + EXPECT_EQ(sizeof(MI_STORE_DATA_IMM), size); + + uint64_t gpuAddress = 0xFF0000; + uint32_t dword0 = 0x123; + uint32_t dword1 = 0x456; + + constexpr size_t bufferSize = 64; + uint8_t buffer[bufferSize]; + LinearStream cmdStream(buffer, bufferSize); + + EncodeStoreMemory::programStoreDataImm(cmdStream, + gpuAddress, + dword0, + dword1, + false, + false); + size_t usedAfter = cmdStream.getUsed(); + EXPECT_EQ(size, usedAfter); + + auto storeDataImm = genCmdCast(buffer); + ASSERT_NE(nullptr, storeDataImm); + EXPECT_EQ(gpuAddress, storeDataImm->getAddress()); + EXPECT_EQ(dword0, storeDataImm->getDataDword0()); + EXPECT_EQ(0u, storeDataImm->getDataDword1()); + EXPECT_FALSE(storeDataImm->getStoreQword()); + EXPECT_EQ(MI_STORE_DATA_IMM::DWORD_LENGTH::DWORD_LENGTH_STORE_DWORD, storeDataImm->getDwordLength()); +} + +HWTEST_F(CommandEncoderTest, GivenQwordStoreWhenAddingStoreDataImmThenExpectQwordProgramming) { + using MI_STORE_DATA_IMM = typename FamilyType::MI_STORE_DATA_IMM; + size_t size = EncodeStoreMemory::getStoreDataImmSize(); + EXPECT_EQ(sizeof(MI_STORE_DATA_IMM), size); + + uint64_t gpuAddress = 0xFF0000; + uint32_t dword0 = 0x123; + uint32_t dword1 = 0x456; + + constexpr size_t bufferSize = 64; + uint8_t buffer[bufferSize]; + LinearStream cmdStream(buffer, bufferSize); + + EncodeStoreMemory::programStoreDataImm(cmdStream, + gpuAddress, + dword0, + dword1, + true, + false); + size_t usedAfter = cmdStream.getUsed(); + EXPECT_EQ(size, usedAfter); + + auto storeDataImm = genCmdCast(buffer); + ASSERT_NE(nullptr, storeDataImm); + EXPECT_EQ(gpuAddress, storeDataImm->getAddress()); + EXPECT_EQ(dword0, storeDataImm->getDataDword0()); + EXPECT_EQ(dword1, storeDataImm->getDataDword1()); + EXPECT_TRUE(storeDataImm->getStoreQword()); + EXPECT_EQ(MI_STORE_DATA_IMM::DWORD_LENGTH::DWORD_LENGTH_STORE_QWORD, storeDataImm->getDwordLength()); +}