mirror of
https://github.com/intel/compute-runtime.git
synced 2025-12-20 08:53:55 +08:00
[1/n] Move different wddm functions to dedicated helper.
- This is first phase of moving wddm specific internals to Wddm Interface helper - Instead of having 2 different wddm classes driver will route interface specific functions to dedicated helper - Helper will be initialized when interface version will be known, therefore we would not need to initialize wddm multiple times Change-Id: Ic71788ccb2f8a71bf2f3f3c2a04117f16417d85e
This commit is contained in:
committed by
sys_ocldev
parent
95e28faca0
commit
d51c7ccdd4
@@ -73,6 +73,8 @@ set(RUNTIME_SRCS_OS_INTERFACE_WINDOWS
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/wddm/wddm.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/wddm/wddm.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/wddm/wddm.inl
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/wddm/wddm_interface.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/wddm/wddm_interface.cpp
|
||||
)
|
||||
|
||||
if(WIN32)
|
||||
|
||||
@@ -80,9 +80,11 @@ Wddm::Wddm() : initialized(false),
|
||||
minAddress = 0;
|
||||
kmDafListener = std::unique_ptr<KmDafListener>(new KmDafListener);
|
||||
gdi = std::unique_ptr<Gdi>(new Gdi());
|
||||
wddmInterface = std::make_unique<WddmInterface20>(*this);
|
||||
}
|
||||
|
||||
Wddm::~Wddm() {
|
||||
wddmInterface->destroyHwQueue();
|
||||
resetPageTableManager(nullptr);
|
||||
destroyContext(context);
|
||||
destroyPagingQueue();
|
||||
@@ -213,25 +215,6 @@ bool Wddm::destroyDevice() {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Wddm::createMonitoredFence() {
|
||||
NTSTATUS Status;
|
||||
D3DKMT_CREATESYNCHRONIZATIONOBJECT2 CreateSynchronizationObject = {0};
|
||||
DEBUG_BREAK_IF(!device);
|
||||
CreateSynchronizationObject.hDevice = device;
|
||||
CreateSynchronizationObject.Info.Type = D3DDDI_MONITORED_FENCE;
|
||||
CreateSynchronizationObject.Info.MonitoredFence.InitialFenceValue = 0;
|
||||
|
||||
Status = gdi->createSynchronizationObject2(&CreateSynchronizationObject);
|
||||
|
||||
DEBUG_BREAK_IF(STATUS_SUCCESS != Status);
|
||||
|
||||
resetMonitoredFenceParams(CreateSynchronizationObject.hSyncObject,
|
||||
reinterpret_cast<uint64_t *>(CreateSynchronizationObject.Info.MonitoredFence.FenceValueCPUVirtualAddress),
|
||||
CreateSynchronizationObject.Info.MonitoredFence.FenceValueGPUVirtualAddress);
|
||||
|
||||
return Status == STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
bool Wddm::closeAdapter() {
|
||||
NTSTATUS status = STATUS_UNSUCCESSFUL;
|
||||
D3DKMT_CLOSEADAPTER CloseAdapter = {0};
|
||||
@@ -718,7 +701,7 @@ bool Wddm::createContext() {
|
||||
|
||||
CreateContext.EngineAffinity = 0;
|
||||
CreateContext.Flags.NullRendering = static_cast<UINT>(DebugManager.flags.EnableNullHardware.get());
|
||||
CreateContext.Flags.HwQueueSupported = hwQueuesSupported();
|
||||
CreateContext.Flags.HwQueueSupported = wddmInterface->hwQueuesSupported();
|
||||
|
||||
if (preemptionMode >= PreemptionMode::MidBatch) {
|
||||
CreateContext.Flags.DisableGpuTimeout = readEnablePreemptionRegKey();
|
||||
@@ -748,46 +731,21 @@ bool Wddm::destroyContext(D3DKMT_HANDLE context) {
|
||||
}
|
||||
|
||||
bool Wddm::submit(uint64_t commandBuffer, size_t size, void *commandHeader) {
|
||||
D3DKMT_SUBMITCOMMAND SubmitCommand = {0};
|
||||
NTSTATUS status = STATUS_SUCCESS;
|
||||
bool success = true;
|
||||
|
||||
SubmitCommand.Commands = commandBuffer;
|
||||
SubmitCommand.CommandLength = static_cast<UINT>(size);
|
||||
SubmitCommand.BroadcastContextCount = 1;
|
||||
SubmitCommand.BroadcastContext[0] = context;
|
||||
SubmitCommand.Flags.NullRendering = (UINT)DebugManager.flags.EnableNullHardware.get();
|
||||
|
||||
COMMAND_BUFFER_HEADER *pHeader = reinterpret_cast<COMMAND_BUFFER_HEADER *>(commandHeader);
|
||||
|
||||
pHeader->MonitorFenceVA = monitoredFence.gpuAddress;
|
||||
pHeader->MonitorFenceValue = monitoredFence.currentFenceValue;
|
||||
|
||||
// Note: Private data should be the CPU VA Address
|
||||
SubmitCommand.pPrivateDriverData = commandHeader;
|
||||
SubmitCommand.PrivateDriverDataSize = sizeof(COMMAND_BUFFER_HEADER);
|
||||
|
||||
if (currentPagingFenceValue > *pagingFenceAddress) {
|
||||
success = waitOnGPU();
|
||||
bool status = false;
|
||||
if (currentPagingFenceValue > *pagingFenceAddress && !waitOnGPU()) {
|
||||
return false;
|
||||
}
|
||||
DBG_LOG(ResidencyDebugEnable, "Residency:", __FUNCTION__, "currentFenceValue =", monitoredFence.currentFenceValue);
|
||||
|
||||
if (success) {
|
||||
|
||||
DBG_LOG(ResidencyDebugEnable, "Residency:", __FUNCTION__, "currentFenceValue =", monitoredFence.currentFenceValue);
|
||||
|
||||
status = gdi->submitCommand(&SubmitCommand);
|
||||
if (STATUS_SUCCESS != status) {
|
||||
success = false;
|
||||
} else {
|
||||
monitoredFence.lastSubmittedFence = monitoredFence.currentFenceValue;
|
||||
monitoredFence.currentFenceValue++;
|
||||
}
|
||||
status = wddmInterface->submit(commandBuffer, size, commandHeader);
|
||||
if (status) {
|
||||
monitoredFence.lastSubmittedFence = monitoredFence.currentFenceValue;
|
||||
monitoredFence.currentFenceValue++;
|
||||
}
|
||||
|
||||
getDeviceState();
|
||||
UNRECOVERABLE_IF(!success);
|
||||
UNRECOVERABLE_IF(!status);
|
||||
|
||||
return success;
|
||||
return status;
|
||||
}
|
||||
|
||||
void Wddm::getDeviceState() {
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#pragma once
|
||||
#include "runtime/os_interface/windows/windows_wrapper.h"
|
||||
#include "runtime/os_interface/windows/windows_defs.h"
|
||||
#include "runtime/os_interface/windows/wddm/wddm_interface.h"
|
||||
#include "umKmInc/sharedata.h"
|
||||
#include "runtime/helpers/debug_helpers.h"
|
||||
#include <d3d9types.h>
|
||||
@@ -71,7 +72,6 @@ class Wddm {
|
||||
bool mapGpuVirtualAddress(WddmAllocation *allocation, void *cpuPtr, bool allocation32bit, bool use64kbPages, bool useHeap1);
|
||||
bool mapGpuVirtualAddress(AllocationStorageData *allocationStorageData, bool allocation32bit, bool use64kbPages);
|
||||
MOCKABLE_VIRTUAL bool createContext();
|
||||
virtual bool createHwQueue() { return false; }
|
||||
MOCKABLE_VIRTUAL bool freeGpuVirtualAddres(D3DGPU_VIRTUAL_ADDRESS &gpuPtr, uint64_t size);
|
||||
MOCKABLE_VIRTUAL NTSTATUS createAllocation(WddmAllocation *alloc);
|
||||
MOCKABLE_VIRTUAL bool createAllocation64k(WddmAllocation *alloc);
|
||||
@@ -165,6 +165,9 @@ class Wddm {
|
||||
return context;
|
||||
}
|
||||
|
||||
unsigned int readEnablePreemptionRegKey();
|
||||
void resetMonitoredFenceParams(D3DKMT_HANDLE &handle, uint64_t *cpuAddress, D3DGPU_VIRTUAL_ADDRESS &gpuAddress);
|
||||
|
||||
protected:
|
||||
bool initialized;
|
||||
std::unique_ptr<Gdi> gdi;
|
||||
@@ -207,12 +210,8 @@ class Wddm {
|
||||
bool destroyPagingQueue();
|
||||
bool destroyDevice();
|
||||
bool closeAdapter();
|
||||
virtual bool createMonitoredFence();
|
||||
void getDeviceState();
|
||||
void handleCompletion();
|
||||
unsigned int readEnablePreemptionRegKey();
|
||||
void resetMonitoredFenceParams(D3DKMT_HANDLE &handle, uint64_t *cpuAddress, D3DGPU_VIRTUAL_ADDRESS &gpuAddress);
|
||||
virtual const bool hwQueuesSupported() const { return false; }
|
||||
|
||||
static CreateDXGIFactoryFcn createDxgiFactory;
|
||||
static GetSystemInfoFcn getSystemInfo;
|
||||
@@ -222,6 +221,7 @@ class Wddm {
|
||||
std::unique_ptr<GmmPageTableMngr> pageTableManager;
|
||||
|
||||
std::unique_ptr<KmDafListener> kmDafListener;
|
||||
std::unique_ptr<WddmInterface> wddmInterface;
|
||||
};
|
||||
|
||||
using Wddm20 = Wddm;
|
||||
|
||||
@@ -61,10 +61,10 @@ bool Wddm::init() {
|
||||
if (!createContext()) {
|
||||
return false;
|
||||
}
|
||||
if (hwQueuesSupported() && !createHwQueue()) {
|
||||
if (wddmInterface->hwQueuesSupported() && !wddmInterface->createHwQueue(preemptionMode)) {
|
||||
return false;
|
||||
}
|
||||
if (!createMonitoredFence()) {
|
||||
if (!wddmInterface->createMonitoredFence()) {
|
||||
return false;
|
||||
}
|
||||
initialized = true;
|
||||
|
||||
@@ -24,75 +24,7 @@
|
||||
#include "runtime/os_interface/windows/wddm/wddm23.h"
|
||||
|
||||
namespace OCLRT {
|
||||
Wddm23::Wddm23() : Wddm20() {}
|
||||
|
||||
Wddm23::~Wddm23() {
|
||||
destroyHwQueue();
|
||||
}
|
||||
|
||||
bool Wddm23::createHwQueue() {
|
||||
D3DKMT_CREATEHWQUEUE createHwQueue = {};
|
||||
|
||||
if (!gdi->setupHwQueueProcAddresses()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
createHwQueue.hHwContext = context;
|
||||
if (preemptionMode >= PreemptionMode::MidBatch) {
|
||||
createHwQueue.Flags.DisableGpuTimeout = readEnablePreemptionRegKey();
|
||||
}
|
||||
|
||||
auto status = gdi->createHwQueue(&createHwQueue);
|
||||
UNRECOVERABLE_IF(status != STATUS_SUCCESS);
|
||||
hwQueueHandle = createHwQueue.hHwQueue;
|
||||
|
||||
resetMonitoredFenceParams(createHwQueue.hHwQueueProgressFence,
|
||||
reinterpret_cast<uint64_t *>(createHwQueue.HwQueueProgressFenceCPUVirtualAddress),
|
||||
createHwQueue.HwQueueProgressFenceGPUVirtualAddress);
|
||||
|
||||
return status == STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
void Wddm23::destroyHwQueue() {
|
||||
if (hwQueueHandle) {
|
||||
D3DKMT_DESTROYHWQUEUE destroyHwQueue = {};
|
||||
destroyHwQueue.hHwQueue = hwQueueHandle;
|
||||
|
||||
auto status = gdi->destroyHwQueue(&destroyHwQueue);
|
||||
DEBUG_BREAK_IF(status != STATUS_SUCCESS);
|
||||
}
|
||||
}
|
||||
|
||||
bool Wddm23::submit(uint64_t commandBuffer, size_t size, void *commandHeader) {
|
||||
D3DKMT_SUBMITCOMMANDTOHWQUEUE submitCommand = {};
|
||||
submitCommand.hHwQueue = hwQueueHandle;
|
||||
submitCommand.HwQueueProgressFenceId = monitoredFence.fenceHandle;
|
||||
submitCommand.CommandBuffer = commandBuffer;
|
||||
submitCommand.CommandLength = static_cast<UINT>(size);
|
||||
|
||||
COMMAND_BUFFER_HEADER *pHeader = reinterpret_cast<COMMAND_BUFFER_HEADER *>(commandHeader);
|
||||
pHeader->MonitorFenceVA = monitoredFence.gpuAddress;
|
||||
pHeader->MonitorFenceValue = monitoredFence.currentFenceValue;
|
||||
|
||||
submitCommand.pPrivateDriverData = commandHeader;
|
||||
submitCommand.PrivateDriverDataSize = sizeof(COMMAND_BUFFER_HEADER);
|
||||
|
||||
if (currentPagingFenceValue > *pagingFenceAddress && !waitOnGPU()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
DBG_LOG(ResidencyDebugEnable, "Residency:", __FUNCTION__, "currentFenceValue =", monitoredFence.currentFenceValue);
|
||||
|
||||
auto status = gdi->submitCommandToHwQueue(&submitCommand);
|
||||
UNRECOVERABLE_IF(status != STATUS_SUCCESS);
|
||||
|
||||
if (STATUS_SUCCESS == status) {
|
||||
monitoredFence.lastSubmittedFence = monitoredFence.currentFenceValue;
|
||||
monitoredFence.currentFenceValue++;
|
||||
}
|
||||
|
||||
getDeviceState();
|
||||
|
||||
return status == STATUS_SUCCESS;
|
||||
Wddm23::Wddm23() : Wddm20() {
|
||||
wddmInterface = std::make_unique<WddmInterface23>(*this);
|
||||
}
|
||||
} // namespace OCLRT
|
||||
|
||||
@@ -28,13 +28,7 @@ class Wddm23 : public Wddm20 {
|
||||
protected:
|
||||
friend Wddm20;
|
||||
Wddm23();
|
||||
~Wddm23();
|
||||
|
||||
bool createHwQueue() override;
|
||||
void destroyHwQueue();
|
||||
bool createMonitoredFence() override { return true; }
|
||||
const bool hwQueuesSupported() const override { return true; }
|
||||
bool submit(uint64_t commandBuffer, size_t size, void *commandHeader) override;
|
||||
~Wddm23() = default;
|
||||
|
||||
D3DKMT_HANDLE hwQueueHandle = 0;
|
||||
};
|
||||
|
||||
141
runtime/os_interface/windows/wddm/wddm_interface.cpp
Normal file
141
runtime/os_interface/windows/wddm/wddm_interface.cpp
Normal file
@@ -0,0 +1,141 @@
|
||||
/*
|
||||
* Copyright (c) 2018, Intel Corporation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included
|
||||
* in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
* OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "runtime/os_interface/windows/gdi_interface.h"
|
||||
#include "runtime/os_interface/windows/wddm/wddm_interface.h"
|
||||
#include "runtime/os_interface/windows/wddm/wddm.h"
|
||||
|
||||
bool OCLRT::WddmInterface20::createHwQueue(PreemptionMode preemptionMode) {
|
||||
return false;
|
||||
}
|
||||
|
||||
void OCLRT::WddmInterface20::destroyHwQueue() {
|
||||
}
|
||||
|
||||
bool OCLRT::WddmInterface20::createMonitoredFence() {
|
||||
NTSTATUS Status;
|
||||
D3DKMT_CREATESYNCHRONIZATIONOBJECT2 CreateSynchronizationObject = {0};
|
||||
CreateSynchronizationObject.hDevice = wddm.getDevice();
|
||||
CreateSynchronizationObject.Info.Type = D3DDDI_MONITORED_FENCE;
|
||||
CreateSynchronizationObject.Info.MonitoredFence.InitialFenceValue = 0;
|
||||
|
||||
Status = wddm.getGdi()->createSynchronizationObject2(&CreateSynchronizationObject);
|
||||
|
||||
DEBUG_BREAK_IF(STATUS_SUCCESS != Status);
|
||||
|
||||
wddm.resetMonitoredFenceParams(CreateSynchronizationObject.hSyncObject,
|
||||
reinterpret_cast<uint64_t *>(CreateSynchronizationObject.Info.MonitoredFence.FenceValueCPUVirtualAddress),
|
||||
CreateSynchronizationObject.Info.MonitoredFence.FenceValueGPUVirtualAddress);
|
||||
|
||||
return Status == STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
const bool OCLRT::WddmInterface20::hwQueuesSupported() {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool OCLRT::WddmInterface20::submit(uint64_t commandBuffer, size_t size, void *commandHeader) {
|
||||
D3DKMT_SUBMITCOMMAND SubmitCommand = {0};
|
||||
NTSTATUS status = STATUS_SUCCESS;
|
||||
|
||||
auto monitoredFence = wddm.getMonitoredFence();
|
||||
SubmitCommand.Commands = commandBuffer;
|
||||
SubmitCommand.CommandLength = static_cast<UINT>(size);
|
||||
SubmitCommand.BroadcastContextCount = 1;
|
||||
SubmitCommand.BroadcastContext[0] = wddm.getOsDeviceContext();
|
||||
SubmitCommand.Flags.NullRendering = (UINT)DebugManager.flags.EnableNullHardware.get();
|
||||
|
||||
COMMAND_BUFFER_HEADER *pHeader = reinterpret_cast<COMMAND_BUFFER_HEADER *>(commandHeader);
|
||||
|
||||
pHeader->MonitorFenceVA = monitoredFence.gpuAddress;
|
||||
pHeader->MonitorFenceValue = monitoredFence.currentFenceValue;
|
||||
|
||||
// Note: Private data should be the CPU VA Address
|
||||
SubmitCommand.pPrivateDriverData = commandHeader;
|
||||
SubmitCommand.PrivateDriverDataSize = sizeof(COMMAND_BUFFER_HEADER);
|
||||
|
||||
status = wddm.getGdi()->submitCommand(&SubmitCommand);
|
||||
|
||||
return STATUS_SUCCESS == status;
|
||||
}
|
||||
|
||||
bool OCLRT::WddmInterface23::createHwQueue(PreemptionMode preemptionMode) {
|
||||
D3DKMT_CREATEHWQUEUE createHwQueue = {};
|
||||
|
||||
if (!wddm.getGdi()->setupHwQueueProcAddresses()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
createHwQueue.hHwContext = wddm.getOsDeviceContext();
|
||||
if (preemptionMode >= PreemptionMode::MidBatch) {
|
||||
createHwQueue.Flags.DisableGpuTimeout = wddm.readEnablePreemptionRegKey();
|
||||
}
|
||||
|
||||
auto status = wddm.getGdi()->createHwQueue(&createHwQueue);
|
||||
UNRECOVERABLE_IF(status != STATUS_SUCCESS);
|
||||
hwQueueHandle = createHwQueue.hHwQueue;
|
||||
|
||||
wddm.resetMonitoredFenceParams(createHwQueue.hHwQueueProgressFence,
|
||||
reinterpret_cast<uint64_t *>(createHwQueue.HwQueueProgressFenceCPUVirtualAddress),
|
||||
createHwQueue.HwQueueProgressFenceGPUVirtualAddress);
|
||||
|
||||
return status == STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
void OCLRT::WddmInterface23::destroyHwQueue() {
|
||||
if (hwQueueHandle) {
|
||||
D3DKMT_DESTROYHWQUEUE destroyHwQueue = {};
|
||||
destroyHwQueue.hHwQueue = hwQueueHandle;
|
||||
|
||||
auto status = wddm.getGdi()->destroyHwQueue(&destroyHwQueue);
|
||||
DEBUG_BREAK_IF(status != STATUS_SUCCESS);
|
||||
}
|
||||
}
|
||||
|
||||
bool OCLRT::WddmInterface23::createMonitoredFence() {
|
||||
return true;
|
||||
}
|
||||
|
||||
const bool OCLRT::WddmInterface23::hwQueuesSupported() {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool OCLRT::WddmInterface23::submit(uint64_t commandBuffer, size_t size, void *commandHeader) {
|
||||
auto monitoredFence = wddm.getMonitoredFence();
|
||||
|
||||
D3DKMT_SUBMITCOMMANDTOHWQUEUE submitCommand = {};
|
||||
submitCommand.hHwQueue = hwQueueHandle;
|
||||
submitCommand.HwQueueProgressFenceId = monitoredFence.fenceHandle;
|
||||
submitCommand.CommandBuffer = commandBuffer;
|
||||
submitCommand.CommandLength = static_cast<UINT>(size);
|
||||
|
||||
COMMAND_BUFFER_HEADER *pHeader = reinterpret_cast<COMMAND_BUFFER_HEADER *>(commandHeader);
|
||||
pHeader->MonitorFenceVA = monitoredFence.gpuAddress;
|
||||
pHeader->MonitorFenceValue = monitoredFence.currentFenceValue;
|
||||
|
||||
submitCommand.pPrivateDriverData = commandHeader;
|
||||
submitCommand.PrivateDriverDataSize = sizeof(COMMAND_BUFFER_HEADER);
|
||||
|
||||
auto status = wddm.getGdi()->submitCommandToHwQueue(&submitCommand);
|
||||
UNRECOVERABLE_IF(status != STATUS_SUCCESS);
|
||||
return status == STATUS_SUCCESS;
|
||||
}
|
||||
61
runtime/os_interface/windows/wddm/wddm_interface.h
Normal file
61
runtime/os_interface/windows/wddm/wddm_interface.h
Normal file
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (c) 2018, Intel Corporation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included
|
||||
* in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
* OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
#include "runtime/helpers/hw_info.h"
|
||||
|
||||
namespace OCLRT {
|
||||
class Gdi;
|
||||
class Wddm;
|
||||
class WddmInterface {
|
||||
public:
|
||||
WddmInterface(Wddm &wddm) : wddm(wddm){};
|
||||
WddmInterface() = delete;
|
||||
virtual bool createHwQueue(PreemptionMode preemptionMode) = 0;
|
||||
virtual void destroyHwQueue() = 0;
|
||||
virtual bool createMonitoredFence() = 0;
|
||||
virtual const bool hwQueuesSupported() = 0;
|
||||
virtual bool submit(uint64_t commandBuffer, size_t size, void *commandHeader) = 0;
|
||||
Wddm &wddm;
|
||||
};
|
||||
|
||||
class WddmInterface20 : public WddmInterface {
|
||||
public:
|
||||
using WddmInterface::WddmInterface;
|
||||
bool createHwQueue(PreemptionMode preemptionMode) override;
|
||||
void destroyHwQueue() override;
|
||||
bool createMonitoredFence() override;
|
||||
const bool hwQueuesSupported() override;
|
||||
bool submit(uint64_t commandBuffer, size_t size, void *commandHeader) override;
|
||||
};
|
||||
|
||||
class WddmInterface23 : public WddmInterface {
|
||||
public:
|
||||
using WddmInterface::WddmInterface;
|
||||
bool createHwQueue(PreemptionMode preemptionMode) override;
|
||||
void destroyHwQueue() override;
|
||||
bool createMonitoredFence() override;
|
||||
const bool hwQueuesSupported() override;
|
||||
bool submit(uint64_t commandBuffer, size_t size, void *commandHeader) override;
|
||||
D3DKMT_HANDLE hwQueueHandle = 0;
|
||||
};
|
||||
} // namespace OCLRT
|
||||
@@ -126,11 +126,6 @@ bool WddmMock::createContext() {
|
||||
return createContextResult.success = Wddm::createContext();
|
||||
}
|
||||
|
||||
bool WddmMock::createHwQueue() {
|
||||
createHwQueueResult.called++;
|
||||
return createHwQueueResult.success = Wddm::createHwQueue();
|
||||
}
|
||||
|
||||
bool WddmMock::destroyContext(D3DKMT_HANDLE context) {
|
||||
destroyContextResult.called++;
|
||||
return destroyContextResult.success = Wddm::destroyContext(context);
|
||||
@@ -260,10 +255,10 @@ bool WddmMock::initializeWithoutConfiguringAddressSpace() {
|
||||
if (!createContext()) {
|
||||
return false;
|
||||
}
|
||||
if (hwQueuesSupported() && !createHwQueue()) {
|
||||
if (wddmInterface->hwQueuesSupported() && !wddmInterface->createHwQueue(preemptionMode)) {
|
||||
return false;
|
||||
}
|
||||
if (!createMonitoredFence()) {
|
||||
if (!wddmInterface->createMonitoredFence()) {
|
||||
return false;
|
||||
}
|
||||
initialized = true;
|
||||
|
||||
@@ -51,14 +51,13 @@ class WddmMock : public Wddm20 {
|
||||
public:
|
||||
using Wddm::adapter;
|
||||
using Wddm::context;
|
||||
using Wddm::createHwQueue;
|
||||
using Wddm::createMonitoredFence;
|
||||
using Wddm::device;
|
||||
using Wddm::gdi;
|
||||
using Wddm::getSystemInfo;
|
||||
using Wddm::gmmMemory;
|
||||
using Wddm::hwQueuesSupported;
|
||||
using Wddm::pagingQueue;
|
||||
using Wddm::preemptionMode;
|
||||
using Wddm::wddmInterface;
|
||||
|
||||
WddmMock() : Wddm20(){};
|
||||
~WddmMock();
|
||||
@@ -73,7 +72,6 @@ class WddmMock : public Wddm20 {
|
||||
bool destroyAllocation(WddmAllocation *alloc);
|
||||
bool openSharedHandle(D3DKMT_HANDLE handle, WddmAllocation *alloc) override;
|
||||
bool createContext() override;
|
||||
bool createHwQueue() override;
|
||||
bool destroyContext(D3DKMT_HANDLE context) override;
|
||||
bool queryAdapterInfo() override;
|
||||
bool submit(uint64_t commandBuffer, size_t size, void *commandHeader) override;
|
||||
@@ -125,7 +123,6 @@ class WddmMock : public Wddm20 {
|
||||
WddmMockHelpers::CallResult waitFromCpuResult;
|
||||
WddmMockHelpers::CallResult releaseReservedAddressResult;
|
||||
WddmMockHelpers::CallResult reserveValidAddressRangeResult;
|
||||
WddmMockHelpers::CallResult createHwQueueResult;
|
||||
|
||||
NTSTATUS createAllocationStatus;
|
||||
bool mapGpuVaStatus;
|
||||
|
||||
@@ -27,14 +27,12 @@
|
||||
namespace OCLRT {
|
||||
class WddmMock23 : public Wddm23 {
|
||||
public:
|
||||
using Wddm::preemptionMode;
|
||||
using Wddm::wddmInterface;
|
||||
using Wddm23::context;
|
||||
using Wddm23::createHwQueue;
|
||||
using Wddm23::createMonitoredFence;
|
||||
using Wddm23::currentPagingFenceValue;
|
||||
using Wddm23::destroyHwQueue;
|
||||
using Wddm23::gdi;
|
||||
using Wddm23::hwQueueHandle;
|
||||
using Wddm23::hwQueuesSupported;
|
||||
using Wddm23::pagingFenceAddress;
|
||||
using Wddm23::submit;
|
||||
|
||||
@@ -45,13 +43,21 @@ class WddmMock23 : public Wddm23 {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool createHwQueue() override {
|
||||
uint32_t waitOnGPUCalled = 0;
|
||||
uint32_t createHwQueueCalled = 0;
|
||||
bool createHwQueueResult = false;
|
||||
};
|
||||
|
||||
class WddmMockInterface23 : public WddmInterface23 {
|
||||
public:
|
||||
using WddmInterface23::WddmInterface23;
|
||||
|
||||
bool createHwQueue(PreemptionMode preemptionMode) override {
|
||||
createHwQueueCalled++;
|
||||
createHwQueueResult = forceCreateHwQueueFail ? false : Wddm23::createHwQueue();
|
||||
createHwQueueResult = forceCreateHwQueueFail ? false : WddmInterface23::createHwQueue(preemptionMode);
|
||||
return createHwQueueResult;
|
||||
}
|
||||
|
||||
uint32_t waitOnGPUCalled = 0;
|
||||
uint32_t createHwQueueCalled = 0;
|
||||
bool forceCreateHwQueueFail = false;
|
||||
bool createHwQueueResult = false;
|
||||
|
||||
@@ -676,17 +676,12 @@ HWTEST_F(Wddm20WithMockGdiDllTests, givenUseNoRingFlushesKmdModeDebugFlagToTrueW
|
||||
|
||||
HWTEST_F(Wddm20WithMockGdiDllTests, whenCreateContextIsCalledThenDisableHwQueues) {
|
||||
wddm->init<FamilyType>();
|
||||
EXPECT_FALSE(wddm->hwQueuesSupported());
|
||||
EXPECT_FALSE(wddm->wddmInterface->hwQueuesSupported());
|
||||
EXPECT_EQ(0u, getCreateContextDataFcn()->Flags.HwQueueSupported);
|
||||
}
|
||||
|
||||
TEST_F(Wddm20Tests, whenCreateHwQueueIsCalledThenAlwaysReturnFalse) {
|
||||
EXPECT_FALSE(wddm->createHwQueue());
|
||||
}
|
||||
|
||||
HWTEST_F(Wddm20Tests, whenInitCalledThenDontCallToCreateHwQueue) {
|
||||
wddm->init<FamilyType>();
|
||||
EXPECT_EQ(0u, wddm->createHwQueueResult.called);
|
||||
EXPECT_FALSE(wddm->wddmInterface->createHwQueue(wddm->preemptionMode));
|
||||
}
|
||||
|
||||
HWTEST_F(Wddm20Tests, whenWddmIsInitializedThenGdiDoesntHaveHwQueueDDIs) {
|
||||
@@ -898,7 +893,7 @@ HWTEST_F(Wddm20Tests, createMonitoredFenceIsInitializedWithFenceValueZeroAndCurr
|
||||
|
||||
gdi->getCreateSynchronizationObject2Arg().Info.MonitoredFence.InitialFenceValue = 300;
|
||||
|
||||
wddm->createMonitoredFence();
|
||||
wddm->wddmInterface->createMonitoredFence();
|
||||
|
||||
EXPECT_EQ(0u, gdi->getCreateSynchronizationObject2Arg().Info.MonitoredFence.InitialFenceValue);
|
||||
EXPECT_EQ(1u, wddm->getMonitoredFence().currentFenceValue);
|
||||
|
||||
@@ -35,6 +35,8 @@ struct Wddm23Tests : public ::testing::Test, GdiDllFixture, public GmmEnvironmen
|
||||
GmmEnvironmentFixture::SetUp();
|
||||
GdiDllFixture::SetUp();
|
||||
wddm.reset(static_cast<WddmMock23 *>(Wddm::createWddm(WddmInterfaceVersion::Wddm23)));
|
||||
wddmMockInterface = new WddmMockInterface23(*wddm);
|
||||
wddm->wddmInterface.reset(wddmMockInterface);
|
||||
wddm->registryReader.reset(new RegistryReaderMock());
|
||||
}
|
||||
|
||||
@@ -44,10 +46,11 @@ struct Wddm23Tests : public ::testing::Test, GdiDllFixture, public GmmEnvironmen
|
||||
}
|
||||
|
||||
std::unique_ptr<WddmMock23> wddm;
|
||||
WddmMockInterface23 *wddmMockInterface = nullptr;
|
||||
};
|
||||
|
||||
TEST_F(Wddm23Tests, whenCreateMonitoredFenceCalledThenDoNothing) {
|
||||
EXPECT_TRUE(wddm->createMonitoredFence());
|
||||
EXPECT_TRUE(wddm->wddmInterface->createMonitoredFence());
|
||||
EXPECT_TRUE(nullptr == wddm->getMonitoredFence().cpuAddress);
|
||||
EXPECT_EQ(0u, wddm->getMonitoredFence().currentFenceValue);
|
||||
EXPECT_EQ(static_cast<D3DKMT_HANDLE>(0), wddm->getMonitoredFence().fenceHandle);
|
||||
@@ -57,7 +60,7 @@ TEST_F(Wddm23Tests, whenCreateMonitoredFenceCalledThenDoNothing) {
|
||||
|
||||
HWTEST_F(Wddm23Tests, whenCreateContextIsCalledThenEnableHwQueues) {
|
||||
wddm->init<FamilyType>();
|
||||
EXPECT_TRUE(wddm->hwQueuesSupported());
|
||||
EXPECT_TRUE(wddm->wddmInterface->hwQueuesSupported());
|
||||
EXPECT_EQ(1u, getCreateContextDataFcn()->Flags.HwQueueSupported);
|
||||
}
|
||||
|
||||
@@ -65,7 +68,7 @@ TEST_F(Wddm23Tests, whenCreateHwQueueIsCalledThenSetAllRequiredFieldsAndMonitore
|
||||
EXPECT_EQ(0u, wddm->hwQueueHandle);
|
||||
wddm->context = 1;
|
||||
|
||||
wddm->createHwQueue();
|
||||
wddm->wddmInterface->createHwQueue(wddm->preemptionMode);
|
||||
|
||||
EXPECT_EQ(wddm->context, getCreateHwQueueDataFcn()->hHwContext);
|
||||
EXPECT_EQ(0u, getCreateHwQueueDataFcn()->PrivateDriverDataSize);
|
||||
@@ -80,29 +83,29 @@ TEST_F(Wddm23Tests, whenCreateHwQueueIsCalledThenSetAllRequiredFieldsAndMonitore
|
||||
|
||||
TEST_F(Wddm23Tests, givenPreemptionModeWhenCreateHwQueueCalledThenSetGpuTimeoutIfEnabled) {
|
||||
wddm->setPreemptionMode(PreemptionMode::Disabled);
|
||||
wddm->createHwQueue();
|
||||
wddm->wddmInterface->createHwQueue(wddm->preemptionMode);
|
||||
EXPECT_EQ(0u, getCreateHwQueueDataFcn()->Flags.DisableGpuTimeout);
|
||||
|
||||
wddm->setPreemptionMode(PreemptionMode::MidBatch);
|
||||
wddm->createHwQueue();
|
||||
wddm->wddmInterface->createHwQueue(wddm->preemptionMode);
|
||||
EXPECT_EQ(1u, getCreateHwQueueDataFcn()->Flags.DisableGpuTimeout);
|
||||
}
|
||||
|
||||
HWTEST_F(Wddm23Tests, whenDestroyHwQueueCalledThenPassExistingHandle) {
|
||||
wddm->init<FamilyType>();
|
||||
wddm->hwQueueHandle = 123;
|
||||
wddm->destroyHwQueue();
|
||||
EXPECT_EQ(wddm->hwQueueHandle, getDestroyHwQueueDataFcn()->hHwQueue);
|
||||
wddmMockInterface->hwQueueHandle = 123;
|
||||
wddm->wddmInterface->destroyHwQueue();
|
||||
EXPECT_EQ(wddmMockInterface->hwQueueHandle, getDestroyHwQueueDataFcn()->hHwQueue);
|
||||
|
||||
wddm->hwQueueHandle = 0;
|
||||
wddm->destroyHwQueue();
|
||||
EXPECT_NE(wddm->hwQueueHandle, getDestroyHwQueueDataFcn()->hHwQueue); // gdi not called when 0
|
||||
wddmMockInterface->hwQueueHandle = 0;
|
||||
wddm->wddmInterface->destroyHwQueue();
|
||||
EXPECT_NE(wddmMockInterface->hwQueueHandle, getDestroyHwQueueDataFcn()->hHwQueue); // gdi not called when 0
|
||||
}
|
||||
|
||||
HWTEST_F(Wddm23Tests, whenObjectIsDestructedThenDestroyHwQueue) {
|
||||
wddm->init<FamilyType>();
|
||||
D3DKMT_HANDLE hwQueue = 123;
|
||||
wddm->hwQueueHandle = hwQueue;
|
||||
wddmMockInterface->hwQueueHandle = hwQueue;
|
||||
wddm.reset(nullptr);
|
||||
EXPECT_EQ(hwQueue, getDestroyHwQueueDataFcn()->hHwQueue);
|
||||
}
|
||||
@@ -120,7 +123,7 @@ HWTEST_F(Wddm23Tests, givenCmdBufferWhenSubmitCalledThenSetAllRequiredFiledsAndU
|
||||
|
||||
EXPECT_EQ(cmdBufferAddress, getSubmitCommandToHwQueueDataFcn()->CommandBuffer);
|
||||
EXPECT_EQ(static_cast<UINT>(cmdSize), getSubmitCommandToHwQueueDataFcn()->CommandLength);
|
||||
EXPECT_EQ(wddm->hwQueueHandle, getSubmitCommandToHwQueueDataFcn()->hHwQueue);
|
||||
EXPECT_EQ(wddmMockInterface->hwQueueHandle, getSubmitCommandToHwQueueDataFcn()->hHwQueue);
|
||||
EXPECT_EQ(wddm->getMonitoredFence().fenceHandle, getSubmitCommandToHwQueueDataFcn()->HwQueueProgressFenceId);
|
||||
EXPECT_EQ(&cmdBufferHeader, getSubmitCommandToHwQueueDataFcn()->pPrivateDriverData);
|
||||
EXPECT_EQ(static_cast<UINT>(sizeof(COMMAND_BUFFER_HEADER)), getSubmitCommandToHwQueueDataFcn()->PrivateDriverDataSize);
|
||||
@@ -153,7 +156,7 @@ HWTEST_F(Wddm23Tests, whenInitCalledThenInitializeNewGdiDDIsAndCallToCreateHwQue
|
||||
EXPECT_EQ(nullptr, wddm->gdi->submitCommandToHwQueue.mFunc);
|
||||
|
||||
EXPECT_TRUE(wddm->init<FamilyType>());
|
||||
EXPECT_EQ(1u, wddm->createHwQueueCalled);
|
||||
EXPECT_EQ(1u, wddmMockInterface->createHwQueueCalled);
|
||||
|
||||
EXPECT_NE(nullptr, wddm->gdi->createHwQueue.mFunc);
|
||||
EXPECT_NE(nullptr, wddm->gdi->destroyHwQueue.mFunc);
|
||||
@@ -161,7 +164,7 @@ HWTEST_F(Wddm23Tests, whenInitCalledThenInitializeNewGdiDDIsAndCallToCreateHwQue
|
||||
}
|
||||
|
||||
HWTEST_F(Wddm23Tests, whenCreateHwQueueFailedThenReturnFalseFromInit) {
|
||||
wddm->forceCreateHwQueueFail = true;
|
||||
wddmMockInterface->forceCreateHwQueueFail = true;
|
||||
EXPECT_FALSE(wddm->init<FamilyType>());
|
||||
}
|
||||
|
||||
@@ -171,9 +174,9 @@ HWTEST_F(Wddm23Tests, givenFailureOnGdiInitializationWhenCreatingHwQueueThenRetu
|
||||
return false;
|
||||
}
|
||||
};
|
||||
wddm->gdi.reset(new MyMockGdi());
|
||||
|
||||
auto myMockGdi = new MyMockGdi();
|
||||
wddm->gdi.reset(myMockGdi);
|
||||
EXPECT_FALSE(wddm->init<FamilyType>());
|
||||
EXPECT_EQ(1u, wddm->createHwQueueCalled);
|
||||
EXPECT_FALSE(wddm->createHwQueueResult);
|
||||
EXPECT_EQ(1u, wddmMockInterface->createHwQueueCalled);
|
||||
EXPECT_FALSE(wddmMockInterface->createHwQueueResult);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user