3030#include " runtime/gmm_helper/page_table_mngr.h"
3131#include " runtime/os_interface/windows/wddm/wddm.h"
3232#include " runtime/os_interface/hw_info_config.h"
33+ #include " runtime/os_interface/windows/os_context_win.h"
3334#include " runtime/os_interface/windows/wddm_allocation.h"
3435#include " runtime/os_interface/windows/registry_reader.h"
3536#include " runtime/helpers/debug_helpers.h"
@@ -54,16 +55,7 @@ Wddm::GetSystemInfoFcn Wddm::getSystemInfo = getGetSystemInfo();
5455Wddm::VirtualAllocFcn Wddm::virtualAllocFnc = getVirtualAlloc();
5556Wddm::VirtualFreeFcn Wddm::virtualFreeFnc = getVirtualFree();
5657
57- Wddm::Wddm () : initialized(false ),
58- adapter (0 ),
59- context(0 ),
60- device(0 ),
61- pagingQueue(0 ),
62- pagingQueueSyncObject(0 ),
63- pagingFenceAddress(nullptr ),
64- currentPagingFenceValue(0 ),
65- hwContextId(0 ),
66- trimCallbackHandle(nullptr ) {
58+ Wddm::Wddm () {
6759 featureTable.reset (new FeatureTable ());
6860 waTable.reset (new WorkaroundTable ());
6961 gtSystemInfo.reset (new GT_SYSTEM_INFO);
@@ -74,17 +66,12 @@ Wddm::Wddm() : initialized(false),
7466 registryReader.reset (new RegistryReader (" System\\ CurrentControlSet\\ Control\\ GraphicsDrivers\\ Scheduler" ));
7567 adapterLuid.HighPart = 0 ;
7668 adapterLuid.LowPart = 0 ;
77- maximumApplicationAddress = 0 ;
78- node = GPUNODE_3D;
79- preemptionMode = PreemptionMode::Disabled;
80- minAddress = 0 ;
8169 kmDafListener = std::unique_ptr<KmDafListener>(new KmDafListener);
8270 gdi = std::unique_ptr<Gdi>(new Gdi ());
8371}
8472
8573Wddm::~Wddm () {
8674 resetPageTableManager (nullptr );
87- destroyContext (context);
8875 destroyPagingQueue ();
8976 destroyDevice ();
9077 closeAdapter ();
@@ -684,7 +671,7 @@ void Wddm::kmDafLock(WddmAllocation *wddmAllocation) {
684671 kmDafListener->notifyLock (featureTable->ftrKmdDaf , adapter, device, wddmAllocation->handle , 0 , gdi->escape );
685672}
686673
687- bool Wddm::createContext () {
674+ bool Wddm::createContext (D3DKMT_HANDLE &context ) {
688675 NTSTATUS status = STATUS_UNSUCCESSFUL;
689676 D3DKMT_CREATECONTEXTVIRTUAL CreateContext = {0 };
690677 CREATECONTEXT_PVTDATA PrivateData = {{0 }};
@@ -730,15 +717,15 @@ bool Wddm::destroyContext(D3DKMT_HANDLE context) {
730717
731718bool Wddm::submit (uint64_t commandBuffer, size_t size, void *commandHeader) {
732719 bool status = false ;
733- if (currentPagingFenceValue > *pagingFenceAddress && !waitOnGPU ()) {
720+ if (currentPagingFenceValue > *pagingFenceAddress && !waitOnGPU (osContext-> getContext () )) {
734721 return false ;
735722 }
736- DBG_LOG (ResidencyDebugEnable, " Residency:" , __FUNCTION__, " currentFenceValue =" , monitoredFence .currentFenceValue );
723+ DBG_LOG (ResidencyDebugEnable, " Residency:" , __FUNCTION__, " currentFenceValue =" , osContext-> getMonitoredFence () .currentFenceValue );
737724
738- status = wddmInterface->submit (commandBuffer, size, commandHeader);
725+ status = wddmInterface->submit (commandBuffer, size, commandHeader, *osContext );
739726 if (status) {
740- monitoredFence .lastSubmittedFence = monitoredFence .currentFenceValue ;
741- monitoredFence .currentFenceValue ++;
727+ osContext-> getMonitoredFence () .lastSubmittedFence = osContext-> getMonitoredFence () .currentFenceValue ;
728+ osContext-> getMonitoredFence () .currentFenceValue ++;
742729 }
743730 getDeviceState ();
744731 UNRECOVERABLE_IF (!status);
@@ -764,9 +751,9 @@ void Wddm::getDeviceState() {
764751}
765752
766753void Wddm::handleCompletion () {
767- if (monitoredFence .cpuAddress ) {
768- auto *currentTag = monitoredFence .cpuAddress ;
769- while (*currentTag < monitoredFence .currentFenceValue - 1 )
754+ if (osContext-> getMonitoredFence () .cpuAddress ) {
755+ auto *currentTag = osContext-> getMonitoredFence () .cpuAddress ;
756+ while (*currentTag < osContext-> getMonitoredFence () .currentFenceValue - 1 )
770757 ;
771758 }
772759}
@@ -775,7 +762,7 @@ unsigned int Wddm::readEnablePreemptionRegKey() {
775762 return static_cast <unsigned int >(registryReader->getSetting (" EnablePreemption" , 1 ));
776763}
777764
778- bool Wddm::waitOnGPU () {
765+ bool Wddm::waitOnGPU (D3DKMT_HANDLE context ) {
779766 D3DKMT_WAITFORSYNCHRONIZATIONOBJECTFROMGPU WaitOnGPU = {0 };
780767
781768 WaitOnGPU.hContext = context;
@@ -792,10 +779,10 @@ bool Wddm::waitOnGPU() {
792779bool Wddm::waitFromCpu (uint64_t lastFenceValue) {
793780 NTSTATUS status = STATUS_SUCCESS;
794781
795- if (lastFenceValue > *monitoredFence .cpuAddress ) {
782+ if (lastFenceValue > *osContext-> getMonitoredFence () .cpuAddress ) {
796783 D3DKMT_WAITFORSYNCHRONIZATIONOBJECTFROMCPU waitFromCpu = {0 };
797784 waitFromCpu.ObjectCount = 1 ;
798- waitFromCpu.ObjectHandleArray = &monitoredFence .fenceHandle ;
785+ waitFromCpu.ObjectHandleArray = &osContext-> getMonitoredFence () .fenceHandle ;
799786 waitFromCpu.FenceValueArray = &lastFenceValue;
800787 waitFromCpu.hDevice = device;
801788 waitFromCpu.hAsyncEvent = NULL ;
@@ -901,12 +888,9 @@ void *Wddm::virtualAlloc(void *inPtr, size_t size, unsigned long flags, unsigned
901888int Wddm::virtualFree (void *ptr, size_t size, unsigned long flags) {
902889 return virtualFreeFnc (ptr, size, flags);
903890}
891+ MonitoredFence &Wddm::getMonitoredFence () { return osContext->getMonitoredFence (); }
904892
905- void Wddm::resetMonitoredFenceParams (D3DKMT_HANDLE &handle, uint64_t *cpuAddress, D3DGPU_VIRTUAL_ADDRESS &gpuAddress) {
906- monitoredFence.lastSubmittedFence = 0 ;
907- monitoredFence.currentFenceValue = 1 ;
908- monitoredFence.fenceHandle = handle;
909- monitoredFence.cpuAddress = cpuAddress;
910- monitoredFence.gpuAddress = gpuAddress;
893+ D3DKMT_HANDLE Wddm::getOsDeviceContext () const {
894+ return osContext->getContext ();
911895}
912896} // namespace OCLRT
0 commit comments