Cleanup in WDDM files

Signed-off-by: Jaroslaw Chodor <jaroslaw.chodor@intel.com>
This commit is contained in:
Jaroslaw Chodor
2021-05-26 23:45:38 +02:00
committed by Compute-Runtime-Automation
parent 165194bf85
commit a77d2b1dde
17 changed files with 90 additions and 68 deletions

View File

@@ -107,7 +107,7 @@ add_definitions(
-DCL_USE_DEPRECATED_OPENCL_2_2_APIS
)
if(WIN32 OR WDDM_LINUX)
if(WIN32)
add_definitions(-D_CRT_SECURE_NO_WARNINGS -DWDDM_VERSION_NUMBER=23 -DNOMINMAX)
add_definitions(-DLEGACY_D3DAPI_VERSION=20)
endif()
@@ -321,7 +321,7 @@ if(NOT THIRD_PARTY_DIR)
endif()
message(STATUS "Third party dir: ${THIRD_PARTY_DIR}")
if(WIN32 OR WDDM_LINUX)
if(WIN32)
# get WDK location and version to use
if(NOT WDK_DIR)
if(IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/../wdk")
@@ -356,11 +356,6 @@ if(WIN32 OR WDDM_LINUX)
endif()
add_compile_options(-DCONST_FROM_WDK_10_0_18328_0=${CONST_FROM_WDK_10_0_18328_0})
set(WDK_INCLUDE_PATHS "")
if(WDDM_LINUX AND IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/../wsl")
get_filename_component(WSL_HEADERS "../wsl" ABSOLUTE)
list(APPEND WDK_INCLUDE_PATHS ${WSL_HEADERS})
endif()
list(APPEND WDK_INCLUDE_PATHS
"${WDK_DIR}/Include/${WindowsTargetPlatformVersion}/um"
"${WDK_DIR}/Include/${WindowsTargetPlatformVersion}/shared"
@@ -798,17 +793,14 @@ endif()
# Compiler warning flags
if(NOT MSVC)
if(NOT WDDM_LINUX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wempty-body")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wignored-qualifiers")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wtype-limits")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wuninitialized")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wextra -Wno-unused-parameter -Wno-missing-field-initializers")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Winvalid-pch")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-literal-suffix -Wno-error -w")
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wempty-body")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wignored-qualifiers")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wtype-limits")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wuninitialized")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wextra -Wno-unused-parameter -Wno-missing-field-initializers")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Winvalid-pch")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unknown-pragmas")
if("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang")
# clang only
@@ -832,9 +824,8 @@ if(NOT MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-noexcept-type") # Added for gtest
endif()
endif()
if(NOT WDDM_LINUX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
if(USE_SANITIZE_UB)
check_cxx_compiler_flag(-fsanitize=undefined COMPILER_SUPPORTS_UNDEFINED_BEHAVIOR_SANITIZER)
if(COMPILER_SUPPORTS_UNDEFINED_BEHAVIOR_SANITIZER)

View File

@@ -34,6 +34,7 @@ class WddmMock : public Wddm {
using Wddm::dedicatedVideoMemory;
using Wddm::device;
using Wddm::deviceRegistryPath;
using Wddm::enablePreemptionRegValue;
using Wddm::featureTable;
using Wddm::getSystemInfo;
using Wddm::gmmMemory;

View File

@@ -61,4 +61,16 @@ char *getenv(const char *variableName) {
}
} // namespace SysCalls
bool isShutdownInProgress() {
return false;
}
unsigned int getPid() {
return 0xABCEDF;
}
unsigned int readEnablePreemptionRegKey() {
return 1;
}
} // namespace NEO

View File

@@ -37,7 +37,6 @@ struct Wddm23TestsWithoutWddmInit : public ::testing::Test, GdiDllFixture {
wddm->featureTable->ftrWddmHwQueues = true;
wddmMockInterface = new WddmMockInterface23(*wddm);
wddm->wddmInterface.reset(wddmMockInterface);
wddm->registryReader.reset(new RegistryReaderMock());
}
void init() {

View File

@@ -559,7 +559,7 @@ TEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenCreateFromSharedHandleIs
memoryManager->freeGraphicsMemory(gpuAllocation);
}
TEST_F(WddmMemoryManagerSimpleTest, whenAllocationCreatedFromSharedHandleIsDestroyedThenNullAllocationHandleAndZeroAllocationCountArePassedTodestroyAllocation) {
TEST_F(WddmMemoryManagerSimpleTest, whenAllocationCreatedFromSharedHandleIsDestroyedThenDestroyAllocationFromGdiIsNotInvoked) {
gdi->getQueryResourceInfoArgOut().NumAllocations = 1;
std::unique_ptr<Gmm> gmm(new Gmm(rootDeviceEnvironment->getGmmClientContext(), nullptr, 0, 0, false));
@@ -579,9 +579,10 @@ TEST_F(WddmMemoryManagerSimpleTest, whenAllocationCreatedFromSharedHandleIsDestr
memoryManager->freeGraphicsMemory(allocation);
EXPECT_EQ(1u, memoryManager->freeGraphicsMemoryImplCalled);
gdi->getDestroyArg().AllocationCount = 7;
auto destroyArg = gdi->getDestroyArg();
EXPECT_EQ(nullptr, destroyArg.phAllocationList);
EXPECT_EQ(0, destroyArg.AllocationCount);
EXPECT_EQ(7, destroyArg.AllocationCount);
gdi->getDestroyArg().AllocationCount = 0;
}
TEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenCreateFromNTHandleIsCalledThenNonNullGraphicsAllocationIsReturned) {

View File

@@ -71,6 +71,7 @@ set(NEO_CORE_OS_INTERFACE_WINDOWS
${CMAKE_CURRENT_SOURCE_DIR}/wddm_memory_manager.cpp
${CMAKE_CURRENT_SOURCE_DIR}/wddm_memory_manager.h
${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}/wddm_memory_manager_allocate_in_device_pool.cpp
${CMAKE_CURRENT_SOURCE_DIR}/wddm/read_preemption_regkey.cpp
${CMAKE_CURRENT_SOURCE_DIR}/wddm/um_km_data_translator.cpp
${CMAKE_CURRENT_SOURCE_DIR}/wddm/um_km_data_translator.h
${CMAKE_CURRENT_SOURCE_DIR}/wddm${BRANCH_DIR_SUFFIX}/create_um_km_data_translator.cpp

View File

@@ -8,6 +8,7 @@
#pragma once
#include "shared/source/os_interface/driver_info.h"
#include "shared/source/utilities/debug_settings_reader.h"
#include <functional>
#include <memory>
@@ -15,8 +16,6 @@
namespace NEO {
class SettingsReader;
bool isCompatibleDriverStore(std::string &&deviceRegistryPath);
class DriverInfoWindows : public DriverInfo {

View File

@@ -7,13 +7,9 @@
#pragma once
#include "shared/source/os_interface/os_library.h"
#include "shared/source/os_interface/windows/d3dkmthk_wrapper.h"
#include "shared/source/os_interface/windows/os_inc.h"
#include "shared/source/os_interface/windows/thk_wrapper.h"
#include "shared/source/os_interface/windows/windows_wrapper.h"
#include <d3d9types.h>
#include <d3dkmthk.h>
#include <memory>
#include <string>

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2020 Intel Corporation
* Copyright (C) 2018-2021 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -9,6 +9,21 @@
namespace NEO {
unsigned int getPid() {
return GetCurrentProcessId();
}
bool isShutdownInProgress() {
auto handle = GetModuleHandleA("ntdll.dll");
if (!handle) {
return true;
}
auto RtlDllShutdownInProgress = reinterpret_cast<BOOLEAN(WINAPI *)()>(GetProcAddress(handle, "RtlDllShutdownInProgress"));
return RtlDllShutdownInProgress();
}
namespace SysCalls {
HANDLE createEvent(LPSECURITY_ATTRIBUTES lpEventAttributes, BOOL bManualReset, BOOL bInitialState, LPCSTR lpName) {

View File

@@ -7,11 +7,10 @@
#pragma once
#include "shared/source/helpers/options.h"
#include "shared/source/os_interface/windows/d3dkmthk_wrapper.h"
#include "shared/source/os_interface/windows/windows_wrapper.h"
#include "shared/source/utilities/api_intercept.h"
#include <d3dkmthk.h>
namespace NEO {
// Default template for GetID( ) for Thk function, causing compilation error !!
// Returns ID for specific ThkWrapper type

View File

@@ -5,6 +5,7 @@
*
*/
#define INITGUID
#include "shared/source/os_interface/windows/wddm/adapter_factory_dxcore.h"
#include "shared/source/helpers/debug_helpers.h"

View File

@@ -0,0 +1,18 @@
/*
* Copyright (C) 2021 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/os_interface/windows/debug_registry_reader.h"
#include "shared/source/os_interface/windows/wddm/wddm.h"
namespace NEO {
unsigned int readEnablePreemptionRegKey() {
auto registryReader = std::make_unique<RegistryReader>(false, "System\\CurrentControlSet\\Control\\GraphicsDrivers\\Scheduler");
return static_cast<unsigned int>(registryReader->getSetting("EnablePreemption", 1));
}
} // namespace NEO

View File

@@ -20,8 +20,8 @@
#include "shared/source/helpers/string.h"
#include "shared/source/helpers/windows/gmm_callbacks.h"
#include "shared/source/os_interface/hw_info_config.h"
#include "shared/source/os_interface/windows/debug_registry_reader.h"
#include "shared/source/os_interface/windows/driver_info_windows.h"
#include "shared/source/os_interface/windows/dxcore_wrapper.h"
#include "shared/source/os_interface/windows/gdi_interface.h"
#include "shared/source/os_interface/windows/kmdaf_listener.h"
#include "shared/source/os_interface/windows/os_context_win.h"
@@ -41,12 +41,6 @@
#include "gmm_client_context.h"
#include "gmm_memory.h"
// clang-format off
#include <initguid.h>
#include <dxcore.h>
#include <dxgi.h>
// clang-format on
namespace NEO {
extern Wddm::CreateDXGIFactoryFcn getCreateDxgiFactory();
extern Wddm::DXCoreCreateAdapterFactoryFcn getDXCoreCreateAdapterFactory();
@@ -69,7 +63,7 @@ Wddm::Wddm(std::unique_ptr<HwDeviceIdWddm> hwDeviceIdIn, RootDeviceEnvironment &
gfxPlatform.reset(new PLATFORM);
memset(gtSystemInfo.get(), 0, sizeof(*gtSystemInfo));
memset(gfxPlatform.get(), 0, sizeof(*gfxPlatform));
this->registryReader.reset(new RegistryReader(false, "System\\CurrentControlSet\\Control\\GraphicsDrivers\\Scheduler"));
this->enablePreemptionRegValue = NEO::readEnablePreemptionRegKey();
kmDafListener = std::unique_ptr<KmDafListener>(new KmDafListener);
temporaryResources = std::make_unique<WddmResidentAllocationsContainer>(this);
}
@@ -222,7 +216,7 @@ bool Wddm::createDevice(PreemptionMode preemptionMode) {
CreateDevice.hAdapter = getAdapter();
CreateDevice.Flags.LegacyMode = FALSE;
if (preemptionMode >= PreemptionMode::MidBatch) {
CreateDevice.Flags.DisableGpuTimeout = readEnablePreemptionRegKey();
CreateDevice.Flags.DisableGpuTimeout = getEnablePreemptionRegValue();
}
status = getGdi()->createDevice(&CreateDevice);
@@ -663,6 +657,9 @@ NTSTATUS Wddm::createAllocationsAndMapGpuVa(OsHandleStorage &osHandles) {
}
bool Wddm::destroyAllocations(const D3DKMT_HANDLE *handles, uint32_t allocationCount, D3DKMT_HANDLE resourceHandle) {
if ((0U == allocationCount) && (0U == resourceHandle)) {
return true;
}
NTSTATUS status = STATUS_SUCCESS;
D3DKMT_DESTROYALLOCATION2 DestroyAllocation = {0};
DEBUG_BREAK_IF(!(allocationCount <= 1 || resourceHandle == 0));
@@ -700,14 +697,14 @@ bool Wddm::openSharedHandle(D3DKMT_HANDLE handle, WddmAllocation *alloc) {
std::unique_ptr<char[]> allocPrivateData(new char[QueryResourceInfo.TotalPrivateDriverDataSize]);
std::unique_ptr<char[]> resPrivateData(new char[QueryResourceInfo.ResourcePrivateDriverDataSize]);
std::unique_ptr<char[]> resPrivateRuntimeData(new char[QueryResourceInfo.PrivateRuntimeDataSize]);
std::unique_ptr<D3DDDI_OPENALLOCATIONINFO[]> allocationInfo(new D3DDDI_OPENALLOCATIONINFO[QueryResourceInfo.NumAllocations]);
std::unique_ptr<D3DDDI_OPENALLOCATIONINFO2[]> allocationInfo(new D3DDDI_OPENALLOCATIONINFO2[QueryResourceInfo.NumAllocations]);
D3DKMT_OPENRESOURCE OpenResource = {0};
OpenResource.hDevice = device;
OpenResource.hGlobalShare = handle;
OpenResource.NumAllocations = QueryResourceInfo.NumAllocations;
OpenResource.pOpenAllocationInfo = allocationInfo.get();
OpenResource.pOpenAllocationInfo2 = allocationInfo.get();
OpenResource.pTotalPrivateDriverDataBuffer = allocPrivateData.get();
OpenResource.TotalPrivateDriverDataBufferSize = QueryResourceInfo.TotalPrivateDriverDataSize;
OpenResource.pResourcePrivateDriverData = resPrivateData.get();
@@ -815,7 +812,7 @@ bool Wddm::createContext(OsContextWin &osContext) {
PrivateData.IsProtectedProcess = FALSE;
PrivateData.IsDwm = FALSE;
PrivateData.ProcessID = GetCurrentProcessId();
PrivateData.ProcessID = NEO::getPid();
PrivateData.GpuVAContext = TRUE;
PrivateData.pHwContextId = &hwContextId;
PrivateData.IsMediaUsage = false;
@@ -828,7 +825,7 @@ bool Wddm::createContext(OsContextWin &osContext) {
CreateContext.Flags.HwQueueSupported = wddmInterface->hwQueuesSupported();
if (osContext.getPreemptionMode() >= PreemptionMode::MidBatch) {
CreateContext.Flags.DisableGpuTimeout = readEnablePreemptionRegKey();
CreateContext.Flags.DisableGpuTimeout = getEnablePreemptionRegValue();
}
UmKmDataTempStorage<CREATECONTEXT_PVTDATA> internalRepresentation;
@@ -903,8 +900,8 @@ void Wddm::getDeviceState() {
#endif
}
unsigned int Wddm::readEnablePreemptionRegKey() {
return static_cast<unsigned int>(registryReader->getSetting("EnablePreemption", 1));
unsigned int Wddm::getEnablePreemptionRegValue() {
return enablePreemptionRegValue;
}
bool Wddm::waitOnGPU(D3DKMT_HANDLE context) {
@@ -1003,14 +1000,7 @@ LUID Wddm::getAdapterLuid() const {
}
bool Wddm::isShutdownInProgress() {
auto handle = GetModuleHandleA("ntdll.dll");
if (!handle) {
return true;
}
auto RtlDllShutdownInProgress = reinterpret_cast<BOOLEAN(WINAPI *)()>(GetProcAddress(handle, "RtlDllShutdownInProgress"));
return RtlDllShutdownInProgress();
return NEO::isShutdownInProgress();
}
void Wddm::releaseReservedAddress(void *reservedAddress) {

View File

@@ -52,6 +52,10 @@ struct OsHandleStorage;
enum class HeapIndex : uint32_t;
unsigned int readEnablePreemptionRegKey();
unsigned int getPid();
bool isShutdownInProgress();
class Wddm : public DriverModel {
public:
static constexpr DriverModelType driverModelType = DriverModelType::WDDM;
@@ -146,8 +150,6 @@ class Wddm : public DriverModel {
return static_cast<uint32_t>(hwContextId);
}
std::unique_ptr<SettingsReader> registryReader;
uintptr_t getWddmMinAddress() const {
return this->minAddress;
}
@@ -155,7 +157,7 @@ class Wddm : public DriverModel {
return wddmInterface.get();
}
unsigned int readEnablePreemptionRegKey();
unsigned int getEnablePreemptionRegValue();
MOCKABLE_VIRTUAL uint64_t *getPagingFenceAddress() {
return pagingFenceAddress;
}
@@ -209,6 +211,7 @@ class Wddm : public DriverModel {
bool instrumentationEnabled = false;
std::string deviceRegistryPath;
RootDeviceEnvironment &rootDeviceEnvironment;
unsigned int enablePreemptionRegValue = 1;
unsigned long hwContextId = 0;
uintptr_t maximumApplicationAddress = 0;

View File

@@ -105,7 +105,7 @@ bool WddmInterface23::createHwQueue(OsContextWin &osContext) {
createHwQueue.hHwContext = osContext.getWddmContextHandle();
if (osContext.getPreemptionMode() >= PreemptionMode::MidBatch) {
createHwQueue.Flags.DisableGpuTimeout = wddm.readEnablePreemptionRegKey();
createHwQueue.Flags.DisableGpuTimeout = wddm.getEnablePreemptionRegValue();
}
auto status = wddm.getGdi()->createHwQueue(&createHwQueue);

View File

@@ -7,9 +7,7 @@
#pragma once
#include "shared/source/os_interface/windows/windows_wrapper.h"
#include <d3dkmthk.h>
#include "shared/source/os_interface/windows/d3dkmthk_wrapper.h"
#include <cstdint>

View File

@@ -36,9 +36,7 @@ class WddmPreemptionTests : public Test<WddmFixtureWithMockGdiDll> {
executionEnvironment->rootDeviceEnvironments[0]->osInterface->setDriverModel(std::unique_ptr<DriverModel>(wddm));
executionEnvironment->rootDeviceEnvironments[0]->memoryOperationsInterface = std::make_unique<WddmMemoryOperationsHandler>(wddm);
osInterface = executionEnvironment->rootDeviceEnvironments[0]->osInterface.get();
auto regReader = new RegistryReaderMock();
wddm->registryReader.reset(regReader);
regReader->forceRetValue = forceReturnPreemptionRegKeyValue;
wddm->enablePreemptionRegValue = forceReturnPreemptionRegKeyValue;
auto preemptionMode = PreemptionHelper::getDefaultPreemptionMode(hwInfoTest);
wddm->init();
hwInfo = executionEnvironment->rootDeviceEnvironments[0]->getHardwareInfo();