From c59607b856f4349e71172b70ed7e2b9b3629e4b2 Mon Sep 17 00:00:00 2001 From: foreman Date: Tue, 8 Nov 2016 10:11:21 -0500 Subject: [PATCH] P4 to Git Change 1338072 by wchau@wchau_WIN_OCL_HSA on 2016/11/08 10:02:39 SWDEV-95007 - OpenCL on PAL - DVR Affected files ... ... //depot/stg/opencl/drivers/opencl/runtime/device/pal/paldevice.hpp#14 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/pal/paldevicegl.cpp#3 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palresource.cpp#18 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palresource.hpp#9 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palvirtual.cpp#37 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palvirtual.hpp#16 edit [ROCm/clr commit: 94bf561bd792c359ca9adebcf89912482548696c] --- .../rocclr/runtime/device/pal/paldevice.hpp | 7 ++- .../rocclr/runtime/device/pal/paldevicegl.cpp | 16 ++++- .../rocclr/runtime/device/pal/palresource.cpp | 10 +-- .../rocclr/runtime/device/pal/palresource.hpp | 3 +- .../rocclr/runtime/device/pal/palvirtual.cpp | 63 ++++++++++++++++--- .../rocclr/runtime/device/pal/palvirtual.hpp | 10 +++ 6 files changed, 94 insertions(+), 15 deletions(-) diff --git a/projects/clr/rocclr/runtime/device/pal/paldevice.hpp b/projects/clr/rocclr/runtime/device/pal/paldevice.hpp index ffb2e311fc..c205ca9b04 100644 --- a/projects/clr/rocclr/runtime/device/pal/paldevice.hpp +++ b/projects/clr/rocclr/runtime/device/pal/paldevice.hpp @@ -492,8 +492,11 @@ public: //! Interop for GL device bool initGLInteropPrivateExt(void* GLplatformContext, void* GLdeviceContext) const; bool glCanInterop(void* GLplatformContext, void* GLdeviceContext) const; - bool resGLAssociate(void* GLContext, uint name, uint type, - void** handle, void** mbResHandle, size_t* offset) const; + bool resGLAssociate(void* GLContext, uint name, uint type, void** handle, void** mbResHandle, size_t* offset +#ifdef ATI_OS_WIN + , Pal::DoppDesktopInfo& doppDesktopInfo +#endif + ) const; bool resGLAcquire(void* GLplatformContext, void* mbResHandle, uint type) const; bool resGLRelease(void* GLplatformContext, void* mbResHandle, uint type) const; bool resGLFree(void* GLplatformContext, void* mbResHandle, uint type) const; diff --git a/projects/clr/rocclr/runtime/device/pal/paldevicegl.cpp b/projects/clr/rocclr/runtime/device/pal/paldevicegl.cpp index f6567dbc6b..40378706b3 100644 --- a/projects/clr/rocclr/runtime/device/pal/paldevicegl.cpp +++ b/projects/clr/rocclr/runtime/device/pal/paldevicegl.cpp @@ -185,7 +185,11 @@ Device::resGLAssociate( uint type, void** handle, void** mbResHandle, - size_t* offset) const + size_t* offset +#ifdef ATI_OS_WIN + , Pal::DoppDesktopInfo& doppDesktopInfo +#endif + ) const { amd::ScopedLock lk(lockPAL()); @@ -218,6 +222,16 @@ Device::resGLAssociate( *handle = reinterpret_cast(hData.handle); *mbResHandle = reinterpret_cast(hData.mbResHandle); *offset = static_cast(hData.offset); +#ifdef ATI_OS_WIN + if (hData.isDoppDesktopTexture) { + doppDesktopInfo.gpuVirtAddr = hData.cardAddr; + doppDesktopInfo.vidPnSourceId = hData.vidpnSourceId; + } + else { + doppDesktopInfo.gpuVirtAddr = 0; + doppDesktopInfo.vidPnSourceId = 0; + } +#endif return status; } diff --git a/projects/clr/rocclr/runtime/device/pal/palresource.cpp b/projects/clr/rocclr/runtime/device/pal/palresource.cpp index cb9ce1ecb6..442ec6ed06 100644 --- a/projects/clr/rocclr/runtime/device/pal/palresource.cpp +++ b/projects/clr/rocclr/runtime/device/pal/palresource.cpp @@ -410,7 +410,7 @@ Resource::memTypeToHeap(Pal::GpuMemoryCreateInfo* createInfo) break; default: createInfo->heaps[0] = Pal::GpuHeapLocal; - break; + break; } } @@ -512,9 +512,11 @@ Resource::create(MemoryType memType, CreateParams* params) mipLevel = oglRes->mipLevel_; if (!dev().resGLAssociate(oglRes->glPlatformContext_, oglRes->handle_, - glType_, &openInfo.hExternalResource, &glInteropMbRes_, &offset_)) { + glType_, &openInfo.hExternalResource, &glInteropMbRes_, &offset_, + openInfo.doppDesktopInfo)) { return false; } + desc_.isDoppTexture_ = (openInfo.doppDesktopInfo.gpuVirtAddr != 0); } else { D3DInteropParams* d3dRes = reinterpret_cast(params); @@ -849,7 +851,7 @@ Resource::create(MemoryType memType, CreateParams* params) imgCreateInfo.fragments = 1; Pal::ImageTiling tiling = Pal::ImageTiling::Optimal; - if (((memoryType() == Persistent) && + if (((memoryType() == Persistent) && dev().settings().linearPersistentImage_) || (memoryType() == ImageBuffer)) { tiling = Pal::ImageTiling::Linear; @@ -1275,7 +1277,7 @@ Resource::partialMemCopyTo( if (((copyRegion.gpuMemoryRowPitch % 4) != 0) || // another DRM restriciton... SI has 4 pixels (copyRegion.gpuMemoryOffset % 4 != 0) || - (dev().settings().sdamPageFaultWar_ && + (dev().settings().sdamPageFaultWar_ && (copyRegion.imageOffset.x % dstResource.elementSize() != 0))) { result = false; } diff --git a/projects/clr/rocclr/runtime/device/pal/palresource.hpp b/projects/clr/rocclr/runtime/device/pal/palresource.hpp index f4343ec7e9..a49d63cecf 100644 --- a/projects/clr/rocclr/runtime/device/pal/palresource.hpp +++ b/projects/clr/rocclr/runtime/device/pal/palresource.hpp @@ -169,7 +169,7 @@ public: size_t height_; //!< Resource height size_t depth_; //!< Resource depth uint baseLevel_; //!< The base level for the view - uint mipLevels_; //!< Number of mip levels + uint mipLevels_; //!< Number of mip levels uint flags_; //!< Resource flags, used in creation size_t pitch_; //!< Resource pitch, valid if locked size_t slice_; //!< Resource slice, valid if locked @@ -185,6 +185,7 @@ public: uint SVMRes_ : 1; //!< SVM flag to the cal resource uint scratch_ : 1; //!< Scratch buffer uint isAllocExecute_ : 1; //!< SVM resource allocation attribute for shader\cmdbuf + uint isDoppTexture_ : 1; //!< PAL resource is for a DOPP desktop texture }; uint state_; }; diff --git a/projects/clr/rocclr/runtime/device/pal/palvirtual.cpp b/projects/clr/rocclr/runtime/device/pal/palvirtual.cpp index 407cccd3bf..fc8b368131 100644 --- a/projects/clr/rocclr/runtime/device/pal/palvirtual.cpp +++ b/projects/clr/rocclr/runtime/device/pal/palvirtual.cpp @@ -156,7 +156,7 @@ VirtualGPU::Queue::~Queue() void VirtualGPU::Queue::addCmdMemRef(Pal::IGpuMemory* iMem) -{ +{ auto it = memReferences_.find(iMem); if (it != memReferences_.end()) { it->second = (it->second & FirstMemoryReference) | cmdBufIdSlot_; @@ -174,6 +174,37 @@ VirtualGPU::Queue::removeCmdMemRef(Pal::IGpuMemory* iMem) } } +void +VirtualGPU::Queue::addCmdDoppRef(Pal::IGpuMemory* iMem, bool lastDoppCmd, bool pfpaDoppCmd) +{ + for (int i = 0; i < palDoppRefs_.size(); i++) { + if (palDoppRefs_[i].pGpuMemory == iMem) { + // If both LAST_DOPP_SUBMISSION and PFPA_DOPP_SUBMISSION VCOPs are requested, + // the LAST_DOPP_SUBMISSION is send as requsted by KMD + // + if (palDoppRefs_[i].flags.lastPfpaCmd == 1) { + return; // no need to override the last submission command + } + + if (lastDoppCmd) { + palDoppRefs_[i].flags.lastPfpaCmd = 1; + palDoppRefs_[i].flags.pfpa = 0; + } + else if (pfpaDoppCmd) { + palDoppRefs_[i].flags.pfpa = 1; + } + return; + } + } + + // this is the first reference of the DOPP desktop texture, add it in the vector + Pal::DoppRef doppRef = {}; + doppRef.flags.pfpa = pfpaDoppCmd ? 1 : 0; + doppRef.flags.lastPfpaCmd = lastDoppCmd ? 1 : 0; + doppRef.pGpuMemory = iMem; + palDoppRefs_.push_back(doppRef); +} + uint VirtualGPU::Queue::submit(bool forceFlush) { @@ -196,6 +227,7 @@ VirtualGPU::Queue::flush() LogError("PAL failed to finalize a command buffer!"); return false; } + // Add memory references for (auto it = memReferences_.begin(); it != memReferences_.end(); ++it) { if (it->second & FirstMemoryReference) { @@ -218,6 +250,8 @@ VirtualGPU::Queue::flush() submitInfo.cmdBufferCount = 1; submitInfo.ppCmdBuffers = &iCmdBuffs_[cmdBufIdSlot_]; submitInfo.pFence = iCmdFences_[cmdBufIdSlot_]; + submitInfo.doppRefCount = palDoppRefs_.size(); + submitInfo.pDoppRefs = palDoppRefs_.data(); // Submit command buffer to OS if (Pal::Result::Success != iQueue_->Submit(submitInfo)) { @@ -247,7 +281,7 @@ VirtualGPU::Queue::flush() // Make sure the slot isn't busy waifForFence(cmdBufIdSlot_); - // Progress retired TS + // Progress retired TS if ((cmdBufIdCurrent_ > MaxCmdBuffers) && (cmbBufIdRetired_ < (cmdBufIdCurrent_ - MaxCmdBuffers))) { cmbBufIdRetired_ = cmdBufIdCurrent_ - MaxCmdBuffers; @@ -272,6 +306,9 @@ VirtualGPU::Queue::flush() return false; } + // Clear dopp references + palDoppRefs_.resize(0); + palMems_.resize(0); // Remove old memory references for (auto it = memReferences_.begin(); it != memReferences_.end();) { @@ -299,7 +336,7 @@ VirtualGPU::Queue::waitForEvent(uint id) uint slotId = id % MaxCmdBuffers; bool result = waifForFence(slotId); - cmbBufIdRetired_ = id; + cmbBufIdRetired_ = id; return result; } @@ -318,7 +355,7 @@ VirtualGPU::Queue::isDone(uint id) if (Pal::Result::Success != iCmdFences_[id % MaxCmdBuffers]->GetStatus()) { return false; } - cmbBufIdRetired_ = id; + cmbBufIdRetired_ = id; return true; } @@ -384,7 +421,7 @@ VirtualGPU::MemoryDependency::validate( if (flushL1Cache) { // Flush cache gpu.flushCUCaches(); - + // Clear memory dependency state const static bool All = true; clear(!All); @@ -2019,6 +2056,11 @@ VirtualGPU::submitKernelInternal( // Add GSL handle to the memory list for VidMM for (uint i = 0; i < dispMemList.size(); ++i) { addVmMemory(dispMemList[i]); + if (dispMemList[i]->desc().isDoppTexture_) { + addDoppRef(dispMemList[i], + kernel.parameters().getExecNewVcop(), + kernel.parameters().getExecPfpaVcop()); + } } // HW Debug for the kernel? @@ -2312,9 +2354,9 @@ VirtualGPU::getGpuEvent(Pal::IGpuMemory* iMem) return &gpuEvents_[iMem]; } -void +void VirtualGPU::assignGpuEvent(Pal::IGpuMemory* iMem, GpuEvent gpuEvent) -{ +{ auto it = gpuEvents_.find(iMem); if (it != gpuEvents_.end()) { @@ -3089,6 +3131,13 @@ VirtualGPU::addVmMemory(const Memory* memory) return true; } +bool +VirtualGPU::addDoppRef(const Memory* memory, bool lastDoppCmd, bool pfpaDoppCmd) +{ + queues_[MainEngine]->addCmdDoppRef(memory->iMem(), lastDoppCmd, pfpaDoppCmd); + return true; +} + void VirtualGPU::profileEvent(EngineType engine, bool type) const { diff --git a/projects/clr/rocclr/runtime/device/pal/palvirtual.hpp b/projects/clr/rocclr/runtime/device/pal/palvirtual.hpp index 80f2b8ec9b..c41323ad5d 100644 --- a/projects/clr/rocclr/runtime/device/pal/palvirtual.hpp +++ b/projects/clr/rocclr/runtime/device/pal/palvirtual.hpp @@ -76,6 +76,8 @@ public: void addCmdMemRef(Pal::IGpuMemory* iMem); void removeCmdMemRef(Pal::IGpuMemory* iMem); + void addCmdDoppRef(Pal::IGpuMemory* iMem, bool lastDoppCmd, bool pfpaDoppCmd); + void addMemRef(Pal::IGpuMemory* iMem) const { Pal::GpuMemoryRef memRef = {}; @@ -141,6 +143,7 @@ public: Util::VirtualLinearAllocator vlAlloc_; std::vector palMemRefs_; std::vector palMems_; + std::vector palDoppRefs_; }; struct CommandBatch : public amd::HeapObject @@ -379,6 +382,13 @@ public: const Memory* memory //!< GPU memory object ); + //! Adds a dopp desktop texture reference + bool addDoppRef( + const Memory* memory, //!< GPU memory object + bool lastDoopCmd, //!< is the last submission for the pre-present primary + bool pfpaDoppCmd //!< is a submission for the pre-present primary + ); + //! Adds a stage write buffer into a list void addXferWrite(Memory& memory);