diff --git a/CMakeLists.txt b/CMakeLists.txt index 5e01110eb2..80e5401040 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -501,6 +501,7 @@ include_directories(${IGDRCL_BUILD_DIR}) include_directories(${IGDRCL_SOURCE_DIR}/runtime/sku_info/definitions${BRANCH_DIR_SUFFIX}) include_directories(${IGDRCL_SOURCE_DIR}/runtime/gen_common/reg_configs${BRANCH_DIR_SUFFIX}) include_directories(${IGDRCL_SOURCE_DIR}/runtime/gmm_helper/${BRANCH_DIR_SUFFIX}) +include_directories(${IGDRCL_SOURCE_DIR}/runtime/gmm_helper/client_context${BRANCH_DIR_SUFFIX}) set(HW_SRC_INCLUDE_PATH ${IGDRCL_SOURCE_DIR}/runtime/gen_common) diff --git a/runtime/gmm_helper/CMakeLists.txt b/runtime/gmm_helper/CMakeLists.txt index 99f9f3da56..d495f7431e 100644 --- a/runtime/gmm_helper/CMakeLists.txt +++ b/runtime/gmm_helper/CMakeLists.txt @@ -20,6 +20,10 @@ set(RUNTIME_SRCS_GMM_HELPER_BASE ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt + ${CMAKE_CURRENT_SOURCE_DIR}/client_context/gmm_client_context_base.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/client_context/gmm_client_context_base.h + ${CMAKE_CURRENT_SOURCE_DIR}/client_context${BRANCH_DIR_SUFFIX}/gmm_client_context.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/client_context${BRANCH_DIR_SUFFIX}/gmm_client_context.h ${CMAKE_CURRENT_SOURCE_DIR}/gmm_helper.cpp ${CMAKE_CURRENT_SOURCE_DIR}/gmm_helper.h ${CMAKE_CURRENT_SOURCE_DIR}/gmm_lib.h diff --git a/runtime/gmm_helper/client_context/gmm_client_context.cpp b/runtime/gmm_helper/client_context/gmm_client_context.cpp new file mode 100644 index 0000000000..d08efe30f1 --- /dev/null +++ b/runtime/gmm_helper/client_context/gmm_client_context.cpp @@ -0,0 +1,27 @@ +/* +* 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 "gmm_client_context.h" + +namespace OCLRT { +GmmClientContext::GmmClientContext(GMM_CLIENT clientType) : GmmClientContextBase(clientType){}; +} // namespace OCLRT diff --git a/runtime/gmm_helper/client_context/gmm_client_context.h b/runtime/gmm_helper/client_context/gmm_client_context.h new file mode 100644 index 0000000000..86ca5d0066 --- /dev/null +++ b/runtime/gmm_helper/client_context/gmm_client_context.h @@ -0,0 +1,31 @@ +/* +* 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 "runtime/gmm_helper/client_context/gmm_client_context_base.h" + +namespace OCLRT { +class GmmClientContext : public GmmClientContextBase { + public: + GmmClientContext(GMM_CLIENT clientType); +}; +} // namespace OCLRT diff --git a/runtime/gmm_helper/client_context/gmm_client_context_base.cpp b/runtime/gmm_helper/client_context/gmm_client_context_base.cpp new file mode 100644 index 0000000000..560378a13e --- /dev/null +++ b/runtime/gmm_helper/client_context/gmm_client_context_base.cpp @@ -0,0 +1,52 @@ +/* +* 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/gmm_helper/client_context/gmm_client_context_base.h" + +namespace OCLRT { +GmmClientContextBase::GmmClientContextBase(GMM_CLIENT clientType) { + clientContext = Gmm::createClientContextFunc(clientType); +} +GmmClientContextBase::~GmmClientContextBase() { + Gmm::deleteClientContextFunc(clientContext); +}; + +MEMORY_OBJECT_CONTROL_STATE GmmClientContextBase::cachePolicyGetMemoryObject(GMM_RESOURCE_INFO *pResInfo, GMM_RESOURCE_USAGE_TYPE usage) { + return clientContext->CachePolicyGetMemoryObject(pResInfo, usage); +} + +GMM_RESOURCE_INFO *GmmClientContextBase::createResInfoObject(GMM_RESCREATE_PARAMS *pCreateParams) { + return clientContext->CreateResInfoObject(pCreateParams); +} + +GMM_RESOURCE_INFO *GmmClientContextBase::copyResInfoObject(GMM_RESOURCE_INFO *pSrcRes) { + return clientContext->CopyResInfoObject(pSrcRes); +} + +void GmmClientContextBase::destroyResInfoObject(GMM_RESOURCE_INFO *pResInfo) { + return clientContext->DestroyResInfoObject(pResInfo); +} + +GMM_CLIENT_CONTEXT *GmmClientContextBase::getHandle() const { + return clientContext; +} +} // namespace OCLRT diff --git a/runtime/gmm_helper/client_context/gmm_client_context_base.h b/runtime/gmm_helper/client_context/gmm_client_context_base.h new file mode 100644 index 0000000000..bbba2bd842 --- /dev/null +++ b/runtime/gmm_helper/client_context/gmm_client_context_base.h @@ -0,0 +1,48 @@ +/* +* 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 "runtime/gmm_helper/gmm_helper.h" +#include "runtime/gmm_helper/gmm_lib.h" +#include + +namespace OCLRT { +class GmmClientContext; +class GmmClientContextBase { + public: + virtual ~GmmClientContextBase(); + + MOCKABLE_VIRTUAL MEMORY_OBJECT_CONTROL_STATE cachePolicyGetMemoryObject(GMM_RESOURCE_INFO *pResInfo, GMM_RESOURCE_USAGE_TYPE usage); + MOCKABLE_VIRTUAL GMM_RESOURCE_INFO *createResInfoObject(GMM_RESCREATE_PARAMS *pCreateParams); + MOCKABLE_VIRTUAL GMM_RESOURCE_INFO *copyResInfoObject(GMM_RESOURCE_INFO *pSrcRes); + MOCKABLE_VIRTUAL void destroyResInfoObject(GMM_RESOURCE_INFO *pResInfo); + GMM_CLIENT_CONTEXT *getHandle() const; + template + static std::unique_ptr create(GMM_CLIENT clientType) { + return std::unique_ptr(new T(clientType)); + } + + protected: + GMM_CLIENT_CONTEXT *clientContext; + GmmClientContextBase(GMM_CLIENT clientType); +}; +} // namespace OCLRT diff --git a/runtime/gmm_helper/gmm_helper.cpp b/runtime/gmm_helper/gmm_helper.cpp index 7a126b490c..3ab1a7adec 100644 --- a/runtime/gmm_helper/gmm_helper.cpp +++ b/runtime/gmm_helper/gmm_helper.cpp @@ -20,6 +20,7 @@ * OTHER DEALINGS IN THE SOFTWARE. */ +#include "gmm_client_context.h" #include "runtime/gmm_helper/gmm_helper.h" #include "runtime/gmm_helper/resource_info.h" #include "runtime/helpers/get_info.h" @@ -54,15 +55,14 @@ bool Gmm::initContext(const PLATFORM *pPlatform, } bool success = GMM_SUCCESS == initGlobalContextFunc(*pPlatform, &gmmFtrTable, &gmmWaTable, pGtSysInfo, GMM_CLIENT::GMM_OCL_VISTA); UNRECOVERABLE_IF(!success); - Gmm::gmmClientContext = createClientContextFunc(GMM_CLIENT::GMM_OCL_VISTA); + Gmm::gmmClientContext = Gmm::createGmmContextWrapperFunc(GMM_CLIENT::GMM_OCL_VISTA); } return Gmm::gmmClientContext != nullptr; } void Gmm::destroyContext() { if (Gmm::gmmClientContext) { - deleteClientContextFunc(Gmm::gmmClientContext); - Gmm::gmmClientContext = nullptr; + Gmm::gmmClientContext.reset(nullptr); destroyGlobalContextFunc(); } } @@ -76,7 +76,7 @@ uint32_t Gmm::getMOCS(uint32_t type) { } } - MEMORY_OBJECT_CONTROL_STATE mocs = Gmm::gmmClientContext->CachePolicyGetMemoryObject(nullptr, static_cast(type)); + MEMORY_OBJECT_CONTROL_STATE mocs = Gmm::gmmClientContext->cachePolicyGetMemoryObject(nullptr, static_cast(type)); return static_cast(mocs.DwordValue); } @@ -392,8 +392,11 @@ bool Gmm::unifiedAuxTranslationCapable() const { return gmmFlags->Gpu.CCS && gmmFlags->Gpu.UnifiedAuxSurface && gmmFlags->Info.RenderCompressed; } +Gmm::~Gmm() {} + +std::unique_ptr (*Gmm::createGmmContextWrapperFunc)(GMM_CLIENT) = GmmClientContextBase::create; bool Gmm::useSimplifiedMocsTable = false; -GMM_CLIENT_CONTEXT *Gmm::gmmClientContext = nullptr; +std::unique_ptr Gmm::gmmClientContext = nullptr; bool Gmm::isLoaded = false; } // namespace OCLRT diff --git a/runtime/gmm_helper/gmm_helper.h b/runtime/gmm_helper/gmm_helper.h index ea520f23ac..ca1b8e93eb 100644 --- a/runtime/gmm_helper/gmm_helper.h +++ b/runtime/gmm_helper/gmm_helper.h @@ -34,6 +34,7 @@ struct WorkaroundTable; struct ImageInfo; class GraphicsAllocation; class GmmResourceInfo; +class GmmClientContext; enum OCLPlane { NO_PLANE = 0, @@ -50,7 +51,7 @@ class Gmm { public: static const uint32_t maxPossiblePitch = 2147483648; - virtual ~Gmm() = default; + virtual ~Gmm(); void create(); static Gmm *create(const void *alignedPtr, size_t alignedSize, bool uncacheable); @@ -96,10 +97,11 @@ class Gmm { static decltype(&GmmDestroyGlobalContext) destroyGlobalContextFunc; static decltype(&GmmCreateClientContext) createClientContextFunc; static decltype(&GmmDeleteClientContext) deleteClientContextFunc; + static std::unique_ptr (*createGmmContextWrapperFunc)(GMM_CLIENT); bool isRenderCompressed = false; static bool useSimplifiedMocsTable; - static GMM_CLIENT_CONTEXT *gmmClientContext; + static std::unique_ptr gmmClientContext; static bool isLoaded; }; } // namespace OCLRT diff --git a/runtime/gmm_helper/gmm_memory_base.cpp b/runtime/gmm_helper/gmm_memory_base.cpp index 8dffff562a..a5d62f4fda 100644 --- a/runtime/gmm_helper/gmm_memory_base.cpp +++ b/runtime/gmm_helper/gmm_memory_base.cpp @@ -20,6 +20,7 @@ * OTHER DEALINGS IN THE SOFTWARE. */ +#include "gmm_client_context.h" #include "runtime/gmm_helper/gmm_memory_base.h" #include "runtime/gmm_helper/gmm_helper.h" @@ -33,7 +34,7 @@ bool GmmMemoryBase::configureDeviceAddressSpace(GMM_ESCAPE_HANDLE hAdapter, BOOLEAN BDWL3Coherency, GMM_GFX_SIZE_T SizeOverride, GMM_GFX_SIZE_T SlmGfxSpaceReserve) { - return Gmm::gmmClientContext->ConfigureDeviceAddressSpace( + return clientContext->ConfigureDeviceAddressSpace( {hAdapter}, {hDevice}, {pfnEscape}, @@ -46,7 +47,10 @@ bool GmmMemoryBase::configureDeviceAddressSpace(GMM_ESCAPE_HANDLE hAdapter, } uintptr_t GmmMemoryBase::getInternalGpuVaRangeLimit() { - return static_cast(Gmm::gmmClientContext->GetInternalGpuVaRangeLimit()); + return static_cast(clientContext->GetInternalGpuVaRangeLimit()); +} +GmmMemoryBase::GmmMemoryBase() { + clientContext = Gmm::gmmClientContext->getHandle(); } }; // namespace OCLRT diff --git a/runtime/gmm_helper/gmm_memory_base.h b/runtime/gmm_helper/gmm_memory_base.h index dac1603863..46826b9e46 100644 --- a/runtime/gmm_helper/gmm_memory_base.h +++ b/runtime/gmm_helper/gmm_memory_base.h @@ -42,6 +42,7 @@ class GmmMemoryBase { MOCKABLE_VIRTUAL uintptr_t getInternalGpuVaRangeLimit(); protected: - GmmMemoryBase() = default; + GMM_CLIENT_CONTEXT *clientContext = nullptr; + GmmMemoryBase(); }; } // namespace OCLRT diff --git a/runtime/gmm_helper/gmm_utils.cpp b/runtime/gmm_helper/gmm_utils.cpp index e6fb4d6ea9..046e771e37 100644 --- a/runtime/gmm_helper/gmm_utils.cpp +++ b/runtime/gmm_helper/gmm_utils.cpp @@ -24,5 +24,7 @@ #include "runtime/helpers/hw_info.h" #include "runtime/helpers/surface_formats.h" -void OCLRT::Gmm::applyAuxFlags(ImageInfo &imgInfo, const HardwareInfo &hwInfo) { +namespace OCLRT { +void Gmm::applyAuxFlags(ImageInfo &imgInfo, const HardwareInfo &hwInfo) { } +} // namespace OCLRT diff --git a/runtime/gmm_helper/page_table_mngr.h b/runtime/gmm_helper/page_table_mngr.h index 28822da01c..1bbbb1484f 100644 --- a/runtime/gmm_helper/page_table_mngr.h +++ b/runtime/gmm_helper/page_table_mngr.h @@ -28,7 +28,7 @@ namespace OCLRT { class GmmPageTableMngr { public: - MOCKABLE_VIRTUAL ~GmmPageTableMngr() = default; + MOCKABLE_VIRTUAL ~GmmPageTableMngr(); static GmmPageTableMngr *create(GMM_DEVICE_CALLBACKS_INT *deviceCb, unsigned int translationTableFlags, GMM_TRANSLATIONTABLE_CALLBACKS *translationTableCb); @@ -45,13 +45,12 @@ class GmmPageTableMngr { } protected: - static void customDeleter(GMM_PAGETABLE_MGR *gmmPageTableManager); - using UniquePtrType = std::unique_ptr>; + GMM_CLIENT_CONTEXT *clientContext = nullptr; GmmPageTableMngr() = default; GmmPageTableMngr(GMM_DEVICE_CALLBACKS_INT *deviceCb, unsigned int translationTableFlags, GMM_TRANSLATIONTABLE_CALLBACKS *translationTableCb); - UniquePtrType pageTableManager; + GMM_PAGETABLE_MGR *pageTableManager = nullptr; }; } // namespace OCLRT diff --git a/runtime/gmm_helper/page_table_mngr_impl.cpp b/runtime/gmm_helper/page_table_mngr_impl.cpp index 134d8c2964..5930ff034e 100644 --- a/runtime/gmm_helper/page_table_mngr_impl.cpp +++ b/runtime/gmm_helper/page_table_mngr_impl.cpp @@ -20,17 +20,20 @@ * OTHER DEALINGS IN THE SOFTWARE. */ +#include "gmm_client_context.h" #include "runtime/gmm_helper/gmm_helper.h" #include "runtime/gmm_helper/page_table_mngr.h" namespace OCLRT { -void GmmPageTableMngr::customDeleter(GMM_PAGETABLE_MGR *gmmPageTableManager) { - Gmm::gmmClientContext->DestroyPageTblMgrObject(gmmPageTableManager); +GmmPageTableMngr::~GmmPageTableMngr() { + if (clientContext) { + clientContext->DestroyPageTblMgrObject(pageTableManager); + } } GmmPageTableMngr::GmmPageTableMngr(GMM_DEVICE_CALLBACKS_INT *deviceCb, unsigned int translationTableFlags, GMM_TRANSLATIONTABLE_CALLBACKS *translationTableCb) { - auto pageTableMngrPtr = Gmm::gmmClientContext->CreatePageTblMgrObject(deviceCb, translationTableCb, translationTableFlags); - this->pageTableManager = UniquePtrType(pageTableMngrPtr, GmmPageTableMngr::customDeleter); + clientContext = Gmm::gmmClientContext->getHandle(); + pageTableManager = clientContext->CreatePageTblMgrObject(deviceCb, translationTableCb, translationTableFlags); } } // namespace OCLRT diff --git a/runtime/gmm_helper/resource_info_impl.cpp b/runtime/gmm_helper/resource_info_impl.cpp index 0c43ed7263..eff76e3b4c 100644 --- a/runtime/gmm_helper/resource_info_impl.cpp +++ b/runtime/gmm_helper/resource_info_impl.cpp @@ -20,21 +20,22 @@ * OTHER DEALINGS IN THE SOFTWARE. */ +#include "gmm_client_context.h" #include "runtime/gmm_helper/resource_info.h" #include "runtime/gmm_helper/gmm_helper.h" namespace OCLRT { void GmmResourceInfo::customDeleter(GMM_RESOURCE_INFO *gmmResourceInfo) { - Gmm::gmmClientContext->DestroyResInfoObject(gmmResourceInfo); + Gmm::gmmClientContext->destroyResInfoObject(gmmResourceInfo); } GmmResourceInfo::GmmResourceInfo(GMM_RESCREATE_PARAMS *resourceCreateParams) { - auto resourceInfoPtr = Gmm::gmmClientContext->CreateResInfoObject(resourceCreateParams); + auto resourceInfoPtr = Gmm::gmmClientContext->createResInfoObject(resourceCreateParams); this->resourceInfo = UniquePtrType(resourceInfoPtr, GmmResourceInfo::customDeleter); } GmmResourceInfo::GmmResourceInfo(GMM_RESOURCE_INFO *inputGmmResourceInfo) { - auto resourceInfoPtr = Gmm::gmmClientContext->CopyResInfoObject(inputGmmResourceInfo); + auto resourceInfoPtr = Gmm::gmmClientContext->copyResInfoObject(inputGmmResourceInfo); this->resourceInfo = UniquePtrType(resourceInfoPtr, GmmResourceInfo::customDeleter); } diff --git a/unit_tests/gmm_helper/gmm_helper_tests.cpp b/unit_tests/gmm_helper/gmm_helper_tests.cpp index 52aa071052..858aa3682a 100644 --- a/unit_tests/gmm_helper/gmm_helper_tests.cpp +++ b/unit_tests/gmm_helper/gmm_helper_tests.cpp @@ -20,6 +20,7 @@ * OTHER DEALINGS IN THE SOFTWARE. */ +#include "gmm_client_context.h" #include "gtest/gtest.h" #include "igfxfmid.h" #include "runtime/helpers/hw_info.h" @@ -601,11 +602,13 @@ TEST(GmmTest, givenInvalidFlagsSetWhenAskedForUnifiedAuxTranslationCapabilityThe TEST(GmmTest, whenContextIsInitializedMultipleTimesThenDontOverride) { const HardwareInfo *hwinfo = *platformDevices; EXPECT_TRUE(Gmm::initContext(hwinfo->pPlatform, hwinfo->pSkuTable, hwinfo->pWaTable, hwinfo->pSysInfo)); - auto currentClientContext = Gmm::gmmClientContext; + auto currentClientContext = Gmm::gmmClientContext.get(); + auto currentClientContextHandle = Gmm::gmmClientContext->getHandle(); EXPECT_TRUE(Gmm::initContext(hwinfo->pPlatform, hwinfo->pSkuTable, hwinfo->pWaTable, hwinfo->pSysInfo)); - EXPECT_EQ(currentClientContext, Gmm::gmmClientContext); + EXPECT_EQ(currentClientContext, Gmm::gmmClientContext.get()); + EXPECT_EQ(currentClientContextHandle, Gmm::gmmClientContext->getHandle()); } TEST(GmmTest, whenContextIsDestroyedMultimpleTimesThenDontCrash) { diff --git a/unit_tests/main.cpp b/unit_tests/main.cpp index fd96944810..b40a72ed3d 100644 --- a/unit_tests/main.cpp +++ b/unit_tests/main.cpp @@ -32,6 +32,7 @@ #include "runtime/gmm_helper/resource_info.h" #include "runtime/os_interface/debug_settings_manager.h" #include "lib_names.h" +#include "mock_gmm_client_context.h" #include "gmock/gmock.h" #include #include @@ -420,6 +421,8 @@ int main(int argc, char **argv) { SetUnhandledExceptionFilter(&UltExceptionFilter); if (!useMockGmm) { Os::gmmDllName = GMM_LIBRARY_NAME; + } else { + Gmm::createGmmContextWrapperFunc = GmmClientContextBase::create; } #endif initializeTestHelpers(); diff --git a/unit_tests/mock_gmm/CMakeLists.txt b/unit_tests/mock_gmm/CMakeLists.txt index 7bd96606e0..7e958e3e9f 100644 --- a/unit_tests/mock_gmm/CMakeLists.txt +++ b/unit_tests/mock_gmm/CMakeLists.txt @@ -26,8 +26,7 @@ if(NOT USE_STATIC_GMM) set(IGDRCL_SRCS_tests_mock_gmm ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt ${CMAKE_CURRENT_SOURCE_DIR}/mock_gmm.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/mock_gmm.h - ${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}/init_platform.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/mock_gmm.def ) add_library(${target_name} EXCLUDE_FROM_ALL SHARED ${IGDRCL_SRCS_tests_mock_gmm}) @@ -46,7 +45,7 @@ if(NOT USE_STATIC_GMM) create_project_source_tree(${target_name}) set_target_properties(${target_name} PROPERTIES FOLDER "test mocks") - target_compile_definitions(${target_name} PUBLIC GMM_LIB_DLL GMM_LIB_DLL_EXPORTS) + target_compile_definitions(${target_name} PUBLIC) if(NOT USE_STATIC_GMM) add_dependencies(unit_tests ${target_name}) endif() diff --git a/unit_tests/mock_gmm/init_platform.cpp b/unit_tests/mock_gmm/init_platform.cpp deleted file mode 100644 index e3d63fb077..0000000000 --- a/unit_tests/mock_gmm/init_platform.cpp +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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 "mock_gmm.h" - -void initPlatform(GMM_PLATFORM_INFO *platform) {} diff --git a/unit_tests/mock_gmm/mock_gmm.cpp b/unit_tests/mock_gmm/mock_gmm.cpp index e44284bc56..0ec199f334 100644 --- a/unit_tests/mock_gmm/mock_gmm.cpp +++ b/unit_tests/mock_gmm/mock_gmm.cpp @@ -20,26 +20,19 @@ * OTHER DEALINGS IN THE SOFTWARE. */ -#include "mock_gmm.h" - -GMM_GLOBAL_CONTEXT *pGmmGlobalContext; -GMM_PLATFORM_INFO *pGlobalPlatformInfo = nullptr; +#include "GmmLib.h" GMM_CLIENT_CONTEXT *GMM_STDCALL createClientContext(GMM_CLIENT ClientType) { - return new GMM_CLIENT_CONTEXT(ClientType); + return reinterpret_cast(0x1); } void GMM_STDCALL deleteClientContext(GMM_CLIENT_CONTEXT *pGmmClientContext) { - delete pGmmClientContext; } void GMM_STDCALL destroySingletonContext(void) { - delete pGlobalPlatformInfo; } GMM_STATUS GMM_STDCALL createSingletonContext(const PLATFORM Platform, const SKU_FEATURE_TABLE *pSkuTable, const WA_TABLE *pWaTable, const GT_SYSTEM_INFO *pGtSysInfo) { - pGlobalPlatformInfo = new GMM_PLATFORM_INFO; - initPlatform(pGlobalPlatformInfo); return GMM_SUCCESS; } GMM_STATUS GMM_STDCALL OpenGmm(GmmExportEntries *pm_GmmFuncs) { @@ -48,573 +41,4 @@ GMM_STATUS GMM_STDCALL OpenGmm(GmmExportEntries *pm_GmmFuncs) { pm_GmmFuncs->pfnDeleteClientContext = &deleteClientContext; pm_GmmFuncs->pfnDestroySingletonContext = &destroySingletonContext; return GMM_SUCCESS; -} - -namespace GmmLib { -MEMORY_OBJECT_CONTROL_STATE GmmClientContext::CachePolicyGetMemoryObject(GMM_RESOURCE_INFO *pResInfo, GMM_RESOURCE_USAGE_TYPE Usage) { - return {}; -} -GmmClientContext::GmmClientContext(GMM_CLIENT ClientType) { -} -GmmClientContext::~GmmClientContext() { -} - -GMM_PTE_CACHE_CONTROL_BITS GMM_STDCALL GmmClientContext::CachePolicyGetPteType(GMM_RESOURCE_USAGE_TYPE Usage) { - return {}; -} - -MEMORY_OBJECT_CONTROL_STATE GMM_STDCALL GmmClientContext::CachePolicyGetOriginalMemoryObject(GMM_RESOURCE_INFO *pResInfo) { - return {}; -} - -uint8_t GMM_STDCALL GmmClientContext::CachePolicyIsUsagePTECached(GMM_RESOURCE_USAGE_TYPE Usage) { - return 0; -} - -uint32_t GMM_STDCALL GmmClientContext::CachePolicyGetMaxMocsIndex() { - return 0; -} - -uint32_t GMM_STDCALL GmmClientContext::CachePolicyGetMaxL1HdcMocsIndex() { - return 0; -} - -uint32_t GMM_STDCALL GmmClientContext::CachePolicyGetMaxSpecialMocsIndex(void) { - return 0; -} - -const GMM_CACHE_POLICY_ELEMENT *GMM_STDCALL GmmClientContext::GetCachePolicyUsage() { - return nullptr; -} - -void GMM_STDCALL GmmClientContext::GetCacheSizes(GMM_CACHE_SIZES *pCacheSizes) { - return; -} - -uint8_t GMM_STDCALL GmmClientContext::GetUseGlobalGtt(GMM_HW_COMMAND_STREAMER cs, - GMM_HW_COMMAND Command, - D3DDDI_PATCHLOCATIONLIST_DRIVERID *pDriverId) { - return 0; -} -GMM_CACHE_POLICY_ELEMENT GMM_STDCALL GmmClientContext::GetCachePolicyElement(GMM_RESOURCE_USAGE_TYPE Usage) { - return {}; -} - -GMM_CACHE_POLICY_TBL_ELEMENT GMM_STDCALL GmmClientContext::GetCachePolicyTlbElement(uint32_t MocsIdx) { - return {}; -} - -GMM_PLATFORM_INFO &GMM_STDCALL GmmClientContext::GetPlatformInfo() { - return *pGlobalPlatformInfo; -} - -uint8_t GMM_STDCALL GmmClientContext::IsPlanar(GMM_RESOURCE_FORMAT Format) { - return 0; -} - -uint8_t GMM_STDCALL GmmClientContext::IsP0xx(GMM_RESOURCE_FORMAT Format) { - return 0; -} - -uint8_t GMM_STDCALL GmmClientContext::IsUVPacked(GMM_RESOURCE_FORMAT Format) { - return 0; -} - -uint8_t GMM_STDCALL GmmClientContext::IsCompressed(GMM_RESOURCE_FORMAT Format) { - return 0; -} - -uint8_t GMM_STDCALL GmmClientContext::IsYUVPacked(GMM_RESOURCE_FORMAT Format) { - return 0; -} - -GMM_STATUS GMM_STDCALL GmmClientContext::GetLogicalTileShape(uint32_t TileMode, - uint32_t *pWidthInBytes, - uint32_t *pHeight, - uint32_t *pDepth) { - return GMM_SUCCESS; -} - -GMM_RESOURCE_INFO *GMM_STDCALL GmmClientContext::CreateResInfoObject(GMM_RESCREATE_PARAMS *pCreateParams) { - return new GMM_RESOURCE_INFO; -} - -GMM_RESOURCE_INFO *GMM_STDCALL GmmClientContext::CopyResInfoObject(GMM_RESOURCE_INFO *pSrcRes) { - return new GMM_RESOURCE_INFO; -} - -void GMM_STDCALL GmmClientContext::ResMemcpy(void *pDst, void *pSrc) { -} - -void GMM_STDCALL GmmClientContext::DestroyResInfoObject(GMM_RESOURCE_INFO *pResInfo) { - delete pResInfo; -} - -GMM_PAGETABLE_MGR *GMM_STDCALL GmmClientContext::CreatePageTblMgrObject( - GMM_DEVICE_CALLBACKS *pDevCb, - GMM_TRANSLATIONTABLE_CALLBACKS *pTTCB, - uint32_t TTFlags) { - return nullptr; -} - -GMM_PAGETABLE_MGR *GMM_STDCALL GmmClientContext::CreatePageTblMgrObject( - GMM_DEVICE_CALLBACKS_INT *pDevCb, - GMM_TRANSLATIONTABLE_CALLBACKS *pTTCB, - uint32_t TTFlags) { - return nullptr; -} - -void GMM_STDCALL GmmClientContext::DestroyPageTblMgrObject(GMM_PAGETABLE_MGR *pPageTableMgr) { -} -GMM_RESOURCE_INFO *GMM_STDCALL GmmClientContext::CreateResInfoObject(GMM_RESCREATE_PARAMS *pCreateParams, - GmmClientAllocationCallbacks *pAllocCbs) { - return nullptr; -} - -void GMM_STDCALL GmmClientContext::DestroyResInfoObject(GMM_RESOURCE_INFO *pResInfo, - GmmClientAllocationCallbacks *pAllocCbs) { -} - -GMM_PAGETABLE_MGR *GMM_STDCALL GmmClientContext::CreatePageTblMgrObject( - GMM_DEVICE_CALLBACKS_INT *pDevCb, - GMM_TRANSLATIONTABLE_CALLBACKS *pTTCB, - uint32_t TTFlags, - GmmClientAllocationCallbacks *pAllocCbs) { - return nullptr; -} - -void GMM_STDCALL GmmClientContext::DestroyPageTblMgrObject(GMM_PAGETABLE_MGR *pPageTableMgr, - GmmClientAllocationCallbacks *pAllocCbs) { -} - -extern "C" GMM_CLIENT_CONTEXT *GMM_STDCALL GmmCreateClientContext(GMM_CLIENT ClientType) { - return nullptr; -} - -extern "C" void GMM_STDCALL GmmDeleteClientContext(GMM_CLIENT_CONTEXT *pGmmClientContext) { -} - -uint8_t GMM_STDCALL GmmClientContext::ConfigureDeviceAddressSpace(GMM_ESCAPE_HANDLE_EXT hAdapter, - GMM_ESCAPE_HANDLE_EXT hDevice, - GMM_ESCAPE_FUNC_TYPE_EXT pfnEscape, - GMM_GFX_SIZE_T SvmSize, - uint8_t FaultableSvm, - uint8_t SparseReady, - uint8_t BDWL3Coherency, - GMM_GFX_SIZE_T SizeOverride, - GMM_GFX_SIZE_T SlmGfxSpaceReserve) { - return 0; -} - -uint32_t GmmClientContext::GetSetProcessGfxPartition(GMM_ESCAPE_HANDLE_EXT hAdapter, - GMM_ESCAPE_HANDLE_EXT hDevice, - GMM_GFX_PARTITIONING *pProcessGfxPart, - uint8_t Get, - GMM_ESCAPE_FUNC_TYPE_EXT pfnEscape) { - - return 0; -} - -GMM_GFX_PARTITIONING GMM_STDCALL GmmClientContext::OverrideGfxPartition(GMM_GFX_PARTITIONING *GfxPartition, - GMM_ESCAPE_HANDLE_EXT hAdapter, - GMM_ESCAPE_HANDLE_EXT hDevice, - GMM_ESCAPE_FUNC_TYPE_EXT pfnEscape) { - return {}; -} - -uint8_t GMM_STDCALL GmmClientContext::EnhancedBufferMap(GMM_ESCAPE_HANDLE_EXT hAdapter, - GMM_ESCAPE_HANDLE_EXT hDevice, - GMM_ESCAPE_FUNC_TYPE_EXT pfnEscape, - D3DKMT_HANDLE hOriginalAllocation, - GMM_ENHANCED_BUFFER_INFO *pEnhancedBufferInfo[GMM_MAX_DISPLAYS]) { - return 0; -} - -GMM_GFX_ADDRESS GMM_STDCALL GmmClientContext::GetHeap32Base(GMM_ESCAPE_HANDLE_EXT hAdapter, - GMM_ESCAPE_HANDLE_EXT hDevice, - uint32_t *pHeapSize, - GMM_ESCAPE_FUNC_TYPE_EXT pfnEscape) { - - return {}; -} - -GMM_GFX_ADDRESS GMM_STDCALL GmmClientContext::GetTrashPageGfxAddress(GMM_ESCAPE_HANDLE_EXT hAdapter, - GMM_ESCAPE_HANDLE_EXT hDevice, - GMM_ESCAPE_FUNC_TYPE_EXT pfnEscape) { - return {}; -} - -GMM_HEAP *GMM_STDCALL GmmClientContext::UmSetupHeap(GMM_ESCAPE_HANDLE_EXT hAdapter, - GMM_ESCAPE_HANDLE_EXT hDevice, - GMM_GFX_ADDRESS GfxAddress, - GMM_GFX_SIZE_T Size, - uint32_t Flags, - GMM_ESCAPE_FUNC_TYPE_EXT pfnEscape) { - - return nullptr; -} - -GMM_STATUS GMM_STDCALL GmmClientContext::UmDestroypHeap(GMM_ESCAPE_HANDLE_EXT hAdapter, - GMM_ESCAPE_HANDLE_EXT hDevice, - GMM_HEAP **pHeapObj, - GMM_ESCAPE_FUNC_TYPE_EXT pfnEscape) { - return GMM_SUCCESS; -} - -GMM_GFX_ADDRESS GMM_STDCALL GmmClientContext::AllocateHeapVA(GMM_HEAP *pHeapObj, - GMM_GFX_SIZE_T AllocSize) { - - return {}; -} - -GMM_STATUS GMM_STDCALL GmmClientContext::FreeHeapVA(GMM_HEAP *pHeapObj, - GMM_GFX_ADDRESS AllocVA, - GMM_GFX_SIZE_T AllocSize) { - return GMM_SUCCESS; -} - -void *GmmClientContext::__GetSharedHeapObject(GMM_ESCAPE_HANDLE_EXT hAdapter, - GMM_ESCAPE_HANDLE_EXT hDevice, - GMM_ESCAPE_FUNC_TYPE_EXT pfnEscape) { - return nullptr; -} - -uint32_t GmmClientContext::__SetSharedHeapObject(GMM_ESCAPE_HANDLE_EXT hAdapter, - GMM_ESCAPE_HANDLE_EXT hDevice, - void **pHeapObj, - GMM_ESCAPE_FUNC_TYPE_EXT pfnEscape) { - return 0; -} - -GMM_GFX_ADDRESS GMM_STDCALL GmmClientContext::GetSLMaddressRange(GMM_ESCAPE_HANDLE_EXT hAdapter, - GMM_ESCAPE_HANDLE_EXT hDevice, - GMM_GFX_SIZE_T Size, - GMM_ESCAPE_FUNC_TYPE_EXT pfnEscape) { - return {}; -} - -uint8_t GMM_STDCALL GmmClientContext::ResDestroySvmAllocation(GMM_ESCAPE_HANDLE_EXT hAdapter, - GMM_ESCAPE_HANDLE_EXT hDevice, - D3DKMT_HANDLE hAllocation, - GMM_ESCAPE_FUNC_TYPE_EXT pfnEscape) { - return 0; -} - -void GMM_STDCALL GmmClientContext::GetD3dSwizzlePattern(const SWIZZLE_DESCRIPTOR *pGmmSwizzle, - uint8_t MSAA, - D3DWDDM2_0DDI_SWIZZLE_PATTERN_DESC *pD3dSwizzle) { -} - -void GMM_STDCALL GmmClientContext::GetD3dSwizzlePattern(const SWIZZLE_DESCRIPTOR *pGmmSwizzle, - uint8_t MSAA, - D3DWDDM2_2DDI_SWIZZLE_PATTERN_DESC *pD3dSwizzle) { -} - -void GMM_STDCALL GmmClientContext::GetD3dSwizzlePattern(const SWIZZLE_DESCRIPTOR *pGmmSwizzle, - uint8_t MSAA, - D3D12DDI_SWIZZLE_PATTERN_DESC_0022 *pD3dSwizzle) { -} - -void GMM_STDCALL GmmClientContext::GetD3dSwizzlePattern(const SWIZZLE_DESCRIPTOR *pGmmSwizzle, - uint8_t MSAA, - D3D12DDI_SWIZZLE_PATTERN_DESC_0004 *pD3dSwizzle) { -} - -GMM_GFX_ADDRESS GMM_STDCALL GmmClientContext::PigmsReserveGpuVA(GMM_ESCAPE_HANDLE_EXT hAdapter, - GMM_ESCAPE_HANDLE_EXT hDevice, - GMM_GFX_SIZE_T Size, - GMM_ESCAPE_FUNC_TYPE_EXT pfnEscape) { - return 0; -} - -uint8_t GMM_STDCALL GmmClientContext::PigmsMapGpuVA(GMM_ESCAPE_HANDLE_EXT hAdapter, - GMM_ESCAPE_HANDLE_EXT hDevice, - GMM_GFX_ADDRESS GfxAddress, - D3DKMT_HANDLE hAllocation, - GMM_RESOURCE_INFO *pGmmResInfo, - GMM_ESCAPE_FUNC_TYPE_EXT pfnEscape) { - return 0; -} - -uint8_t GMM_STDCALL GmmClientContext::PigmsFreeGpuVa(GMM_ESCAPE_HANDLE_EXT hAdapter, - GMM_ESCAPE_HANDLE_EXT hDevice, - GMM_GFX_ADDRESS GfxAddress, - GMM_GFX_SIZE_T Size, - GMM_ESCAPE_FUNC_TYPE_EXT pfnEscape) { - return 0; -} - -GMM_STATUS GMM_STDCALL GmmClientContext::ResUpdateAfterSharedOpen(HANDLE hAdapter, - HANDLE hDevice, - D3DKMT_HANDLE hAllocation, - GMM_RESOURCE_INFO *pGmmResInfo, - GMM_ESCAPE_FUNC_TYPE_EXT pfnEscape) { - return GMM_SUCCESS; -} - -uint8_t GMM_STDCALL GmmClientContext::CreateTiledResource(GMM_HANDLE_EXT hAdapter, - GMM_HANDLE_EXT hDevice, - GMM_UMD_SYNCCONTEXT *pUmdContext, - GMM_TRANSLATIONTABLE_CALLBACKS *pTrTtCallbacks, - GMM_RESOURCE_INFO *pGmmResource, - GMM_ESCAPE_FUNC_TYPE_EXT pfnEscape, - uint32_t NullHw) { - return 0; -} - -uint8_t GMM_STDCALL GmmClientContext::DestroyTiledResource(GMM_HANDLE_EXT hAdapter, - GMM_HANDLE_EXT hDevice, - GMM_UMD_SYNCCONTEXT *pUmdContext, - GMM_TRANSLATIONTABLE_CALLBACKS *pTrTtCallbacks, - GMM_RESOURCE_INFO *pGmmResource, - GMM_ESCAPE_FUNC_TYPE_EXT pfnEscape, - uint32_t NullHw) { - return 0; -} - -GMM_STATUS GMM_STDCALL GmmClientContext::UpdateTiledResourceMapping(GMM_HANDLE_EXT hAdapter, - GMM_HANDLE_EXT hDevice, - GMM_UPDATE_TILE_MAPPINGS_INT Mappings, - uint8_t UseWDDM20, - GMM_UMD_SYNCCONTEXT *pUmdContext, - GMM_TRANSLATIONTABLE_CALLBACKS *CmdBufCallbacks, - GMM_ESCAPE_FUNC_TYPE_EXT pfnEscape, - GMM_DEVICE_CALLBACKS_INT *DeviceCallbacks, - uint32_t NullHw, - uint8_t NewPool) { - return GMM_SUCCESS; -} - -GMM_STATUS GMM_STDCALL GmmClientContext::UpdateSparseResourceOpaqueMapping(GMM_HANDLE_EXT hAdapter, - GMM_HANDLE_EXT hDevice, - GMM_UMD_SYNCCONTEXT *pUmdContext, - GMM_TRANSLATIONTABLE_CALLBACKS *CmdBufCallbacks, - GMM_ESCAPE_FUNC_TYPE_EXT pfnEscape, - uint8_t UseWDDM20, - uint32_t NumMappings, - GMM_UPDATE_SPARSE_RESOURCE_OPAQUE_MAPPINGS *pMappings) { - return GMM_SUCCESS; -} - -GMM_STATUS GMM_STDCALL GmmClientContext::CopyTileMappings(GMM_HANDLE_EXT hAdapter, - GMM_HANDLE_EXT hDevice, - GMM_COPY_TILE_MAPPINGS_INT Mappings, - uint8_t UseWDDM20, - GMM_UMD_SYNCCONTEXT *pUmdContext, - GMM_TRANSLATIONTABLE_CALLBACKS *CmdBufCallbacks, - GMM_ESCAPE_FUNC_TYPE_EXT pfnEscape, - GMM_DEVICE_CALLBACKS_INT *DeviceCallbacks, - uint32_t NullHw, - uint8_t CheckTilePoolAllocs) { - return GMM_SUCCESS; -} - -uint64_t GMM_STDCALL GmmClientContext::GetInternalGpuVaRangeLimit() { - return 0; -} - -bool GmmResourceInfoCommon::IsPresentableformat() { - return false; -} -void GmmResourceInfoCommon::GetGenericRestrictions(__GMM_BUFFER_TYPE *pBuff) { -} -__GMM_BUFFER_TYPE *GmmResourceInfoCommon::GetBestRestrictions(__GMM_BUFFER_TYPE *pFirstBuffer, const __GMM_BUFFER_TYPE *pSecondBuffer) { - return nullptr; -} -bool GmmResourceInfoCommon::CopyClientParams(GMM_RESCREATE_PARAMS &CreateParams) { - return false; -} -bool GmmResourceInfoCommon::RedescribePlanes() { - return false; -} -bool GmmResourceInfoCommon::ReAdjustPlaneProperties(bool IsAuxSurf) { - return false; -} - -const GMM_PLATFORM_INFO &GmmResourceInfoCommon::GetPlatformInfo() { - return *pGlobalPlatformInfo; -} -GMM_STATUS GMM_STDCALL GmmResourceInfoCommon::Create(Context &GmmLibContext, GMM_RESCREATE_PARAMS &CreateParams) { - return GMM_SUCCESS; -} -uint8_t GMM_STDCALL GmmResourceInfoCommon::ValidateParams() { - return 0; -} -GMM_STATUS GMM_STDCALL GmmResourceInfoCommon::Create(GMM_RESCREATE_PARAMS &CreateParams) { - - return GMM_SUCCESS; -} -void GMM_STDCALL GmmResourceInfoCommon::GetRestrictions(__GMM_BUFFER_TYPE &Restrictions) { -} -uint32_t GMM_STDCALL GmmResourceInfoCommon::GetPaddedWidth(uint32_t MipLevel) { - return 0; -} -uint32_t GMM_STDCALL GmmResourceInfoCommon::GetPaddedHeight(uint32_t MipLevel) { - return 0; -} -uint32_t GMM_STDCALL GmmResourceInfoCommon::GetPaddedPitch(uint32_t MipLevel) { - return 0; -} -uint32_t GMM_STDCALL GmmResourceInfoCommon::GetQPitch() { - return 0; -} -GMM_STATUS GMM_STDCALL GmmResourceInfoCommon::GetOffset(GMM_REQ_OFFSET_INFO &ReqInfo) { - - return GMM_SUCCESS; -} -uint8_t GMM_STDCALL GmmResourceInfoCommon::CpuBlt(GMM_RES_COPY_BLT *pBlt) { - return 0; -} -uint8_t GMM_STDCALL GmmResourceInfoCommon::GetMappingSpanDesc(GMM_GET_MAPPING *pMapping) { - return 0; -} -uint8_t GMM_STDCALL GmmResourceInfoCommon::Is64KBPageSuitable() { - return 0; -} -void GMM_STDCALL GmmResourceInfoCommon::GetTiledResourceMipPacking(uint32_t *pNumPackedMips, - uint32_t *pNumTilesForPackedMips) {} -uint32_t GMM_STDCALL GmmResourceInfoCommon::GetPackedMipTailStartLod() { - return 0; -} -bool GMM_STDCALL GmmResourceInfoCommon::IsMipRCCAligned(uint8_t &MisAlignedLod) { - return false; -} -uint8_t GMM_STDCALL GmmResourceInfoCommon::GetDisplayFastClearSupport() { - return 0; -} -uint8_t GMM_STDCALL GmmResourceInfoCommon::GetDisplayCompressionSupport() { - return 0; -} -uint32_t GMM_STDCALL GmmResourceInfoCommon::GetCompressionBlockWidth() { - return 0; -} -uint32_t GMM_STDCALL GmmResourceInfoCommon::GetCompressionBlockHeight() { - return 0; -} -uint32_t GMM_STDCALL GmmResourceInfoCommon::GetCompressionBlockDepth() { - return 0; -} -uint8_t GMM_STDCALL GmmResourceInfoCommon::IsArraySpacingSingleLod() { - return 0; -} -uint8_t GMM_STDCALL GmmResourceInfoCommon::IsASTC() { - return 0; -} -MEMORY_OBJECT_CONTROL_STATE GMM_STDCALL GmmResourceInfoCommon::GetMOCS() { - return {}; -} -uint32_t GMM_STDCALL GmmResourceInfoCommon::GetStdTilingModeExtSurfaceState() { - return 0; -} -GMM_SURFACESTATE_FORMAT GMM_STDCALL GmmResourceInfoCommon::GetResourceFormatSurfaceState() { - return {}; -} -GMM_GFX_SIZE_T GMM_STDCALL GmmResourceInfoCommon::GetMipWidth(uint32_t MipLevel) { - return {}; -} -uint32_t GMM_STDCALL GmmResourceInfoCommon::GetMipHeight(uint32_t MipLevel) { - return 0; -} -uint32_t GMM_STDCALL GmmResourceInfoCommon::GetMipDepth(uint32_t MipLevel) { - return 0; -} -GMM_STATUS GMM_STDCALL GmmResourceInfoWin::GetOffsetFor64KBTiles(GMM_REQ_OFFSET_INFO &ReqInfo) { - return GMM_SUCCESS; -} -uint8_t GMM_STDCALL GmmResourceInfoWin::ApplyExistingSysMem(void *pExistingSysMem, GMM_GFX_SIZE_T ExistingSysMemSize) { - return 0; -} -uint8_t GMM_STDCALL GmmResourceInfoWin::IsPredictedGlobalAliasingParticipant() { - return 0; -} -uint8_t GMM_STDCALL GmmResourceInfoWin::IsSurfaceFaultable() { - return 0; -} -uint32_t GMM_STDCALL GmmResourceInfoWin::GetRenderPitchIn64KBTiles() { - return 0; -} -uint8_t GMM_STDCALL GmmResourceInfoWin::UpdateCacheability(GMM_ESCAPE_HANDLE_EXT hAdapter, - GMM_ESCAPE_HANDLE_EXT hDevice, - D3DKMT_HANDLE hAllocation, - GMM_GPU_CACHE_SETTINGS &CacheSettings, - GMM_ESCAPE_FUNC_TYPE_EXT pfnEscape) { - return 0; -} -uint8_t GMM_STDCALL GmmResourceInfoWin::Alias32bit(GMM_ESCAPE_HANDLE_EXT hAdapter, - GMM_ESCAPE_HANDLE_EXT hDevice, - D3DKMT_HANDLE hAllocation, - uint32_t Size, - uint32_t *pAliasAddress, - GMM_ESCAPE_FUNC_TYPE_EXT pfnEscape) { - return 0; -} -uint8_t GMM_STDCALL GmmResourceInfoWin::KmdGetSetHardwareProtection(GMM_ESCAPE_HANDLE_EXT hAdapter, - GMM_ESCAPE_HANDLE_EXT hDevice, - D3DKMT_HANDLE hAllocation, - uint8_t SetIsEncrypted, - uint8_t *pGetIsEncrypted, - GMM_ESCAPE_FUNC_TYPE_EXT pfnEscape) { - return 0; -} - -uint8_t GMM_STDCALL GmmResourceInfoWin::KmdSetPavpStoutOrIsolatedEncryptionForDisplay(GMM_ESCAPE_HANDLE_EXT hAdapter, - GMM_ESCAPE_HANDLE_EXT hDevice, - D3DKMT_HANDLE hAllocation, - uint8_t bPavpModeIsStoutOrIsolatedDecode, - uint32_t uiPavpSessionId, - GMM_ESCAPE_FUNC_TYPE_EXT pfnEscape) { - return 0; -} - -uint32_t GMM_STDCALL GmmResourceInfoWin::KmdGetSetCpSurfTag(GMM_ESCAPE_HANDLE_EXT hAdapter, - GMM_ESCAPE_HANDLE_EXT hDevice, - D3DKMT_HANDLE hAllocation, - uint8_t IsSet, - uint32_t CpTag, - GMM_ESCAPE_FUNC_TYPE_EXT pfnEscape) { - return 0; -} -bool GmmResourceInfoWin::CopyClientParams(GMM_RESCREATE_PARAMS &CreateParams) { - return false; -} -GMM_GFX_ADDRESS GmmPageTableMgr::GetTRL3TableAddr() { - return {}; -} -GMM_GFX_ADDRESS GmmPageTableMgr::GetAuxL3TableAddr() { - return {}; -} -GMM_STATUS GmmPageTableMgr::InitContextAuxTableRegister(HANDLE initialBBHandle, GMM_ENGINE_TYPE engType) { - return GMM_SUCCESS; -} -GMM_STATUS GmmPageTableMgr::InitContextTRTableRegister(HANDLE initialBBHandle, GMM_ENGINE_TYPE engType) { - return GMM_SUCCESS; -} -void GmmPageTableMgr::InitGpuBBQueueCallbacks(GMM_TRANSLATIONTABLE_CALLBACKS *TTCB) {} - -HRESULT GmmPageTableMgr::ReserveTRGpuVirtualAddress(GMM_UMD_SYNCCONTEXT *, D3DDDI_RESERVEGPUVIRTUALADDRESS *, uint8_t DoNotWait) { - return 0; -} - -HRESULT GmmPageTableMgr::MapTRGpuVirtualAddress(GMM_MAPTRGPUVIRTUALADDRESS *ReserveGpuVa, uint8_t DoNotWait) { - return 0; -} -HRESULT GmmPageTableMgr::UpdateTRGpuVirtualAddress(GMM_UMD_SYNCCONTEXT **, const GMM_UPDATETRGPUVIRTUALADDRESS_INT *, uint8_t DoNotWait) { - return 0; -} -HRESULT GmmPageTableMgr::FreeTRGpuVirtualAddress(GMM_UMD_SYNCCONTEXT *, const GMM_DDI_FREEGPUVIRTUALADDRSS_INT *, uint8_t DoNotWait) { - return 0; -} -GMM_STATUS GmmPageTableMgr::UpdateAuxTable(const GMM_DDI_UPDATEAUXTABLE *) { - return GMM_SUCCESS; -} -void GmmPageTableMgr::EvictPageTablePool(D3DKMT_HANDLE *BBQHandles, int NumBBFenceObj) {} -void GmmPageTableMgr::__ReleaseUnusedPool(GMM_UMD_SYNCCONTEXT *UmdContext) {} -GMM_PAGETABLEPool *GmmPageTableMgr::__GetFreePoolNode(uint32_t *FreePoolNodeIdx, POOL_TYPE PoolType) { return nullptr; } -GmmPageTableMgr::~GmmPageTableMgr() {} -} // namespace GmmLib -uint8_t GMM_STDCALL GmmIsPlanar(GMM_RESOURCE_FORMAT Format) { - return 0; -} -const GMM_PLATFORM_INFO *GMM_STDCALL GmmGetPlatformInfo(GMM_GLOBAL_CONTEXT *pGmmLibContext) { - return nullptr; -} +} \ No newline at end of file diff --git a/unit_tests/mock_gmm/mock_gmm.def b/unit_tests/mock_gmm/mock_gmm.def new file mode 100644 index 0000000000..fa8bd1dc70 --- /dev/null +++ b/unit_tests/mock_gmm/mock_gmm.def @@ -0,0 +1,23 @@ +; 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. + +LIBRARY "mock_gmm" +EXPORTS +OpenGmm \ No newline at end of file diff --git a/unit_tests/mock_gmm/mock_gmm.h b/unit_tests/mock_gmm/mock_gmm.h deleted file mode 100644 index 7247eae557..0000000000 --- a/unit_tests/mock_gmm/mock_gmm.h +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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 "GmmLib.h" - -void initPlatform(GMM_PLATFORM_INFO *platform); diff --git a/unit_tests/mocks/CMakeLists.txt b/unit_tests/mocks/CMakeLists.txt index 1b2d62b9cc..a4ba5350fa 100644 --- a/unit_tests/mocks/CMakeLists.txt +++ b/unit_tests/mocks/CMakeLists.txt @@ -44,10 +44,14 @@ set(IGDRCL_SRCS_tests_mocks ${CMAKE_CURRENT_SOURCE_DIR}/mock_device.h ${CMAKE_CURRENT_SOURCE_DIR}/mock_event.h ${CMAKE_CURRENT_SOURCE_DIR}/mock_gmm.h + ${CMAKE_CURRENT_SOURCE_DIR}/mock_gmm_client_context_base.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/mock_gmm_client_context_base.h ${CMAKE_CURRENT_SOURCE_DIR}/mock_gmm_resource_info.h ${CMAKE_CURRENT_SOURCE_DIR}/mock_gmm_resource_info.cpp ${CMAKE_CURRENT_SOURCE_DIR}/mock_graphics_allocation.h ${CMAKE_CURRENT_SOURCE_DIR}${IGDRCL__INSTRUMENTATION_DIR_SUFFIX}/mock_instrumentation.cpp + ${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}/mock_gmm_client_context.cpp + ${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}/mock_gmm_client_context.h ${CMAKE_CURRENT_SOURCE_DIR}/mock_image.h ${CMAKE_CURRENT_SOURCE_DIR}/mock_kernel.cpp ${CMAKE_CURRENT_SOURCE_DIR}/mock_kernel.h diff --git a/unit_tests/mocks/mock_gmm_client_context.cpp b/unit_tests/mocks/mock_gmm_client_context.cpp new file mode 100644 index 0000000000..ab93bc9d51 --- /dev/null +++ b/unit_tests/mocks/mock_gmm_client_context.cpp @@ -0,0 +1,28 @@ +/* +* 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 "mock_gmm_client_context.h" + +namespace OCLRT { +MockGmmClientContext::MockGmmClientContext(GMM_CLIENT clientType) : MockGmmClientContextBase(clientType) { +} +} // namespace OCLRT diff --git a/unit_tests/mocks/mock_gmm_client_context.h b/unit_tests/mocks/mock_gmm_client_context.h new file mode 100644 index 0000000000..a7ca0d0a5a --- /dev/null +++ b/unit_tests/mocks/mock_gmm_client_context.h @@ -0,0 +1,31 @@ +/* +* 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 "unit_tests/mocks/mock_gmm_client_context_base.h" + +namespace OCLRT { +class MockGmmClientContext : public MockGmmClientContextBase { + public: + MockGmmClientContext(GMM_CLIENT clientType); +}; +} // namespace OCLRT diff --git a/unit_tests/mocks/mock_gmm_client_context_base.cpp b/unit_tests/mocks/mock_gmm_client_context_base.cpp new file mode 100644 index 0000000000..5b886aeecf --- /dev/null +++ b/unit_tests/mocks/mock_gmm_client_context_base.cpp @@ -0,0 +1,44 @@ +/* +* 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 "unit_tests/mocks/mock_gmm_client_context.h" + +namespace OCLRT { +MockGmmClientContextBase::MockGmmClientContextBase(GMM_CLIENT clientType) : GmmClientContext(clientType) { +} + +MEMORY_OBJECT_CONTROL_STATE MockGmmClientContextBase::cachePolicyGetMemoryObject(GMM_RESOURCE_INFO *pResInfo, GMM_RESOURCE_USAGE_TYPE usage) { + return {}; +} + +GMM_RESOURCE_INFO *MockGmmClientContextBase::createResInfoObject(GMM_RESCREATE_PARAMS *pCreateParams) { + return reinterpret_cast(new char[1]); +} + +GMM_RESOURCE_INFO *MockGmmClientContextBase::copyResInfoObject(GMM_RESOURCE_INFO *pSrcRes) { + return reinterpret_cast(new char[1]); +} + +void MockGmmClientContextBase::destroyResInfoObject(GMM_RESOURCE_INFO *pResInfo) { + delete[] reinterpret_cast(pResInfo); +} +} // namespace OCLRT diff --git a/unit_tests/mocks/mock_gmm_client_context_base.h b/unit_tests/mocks/mock_gmm_client_context_base.h new file mode 100644 index 0000000000..8ae1f1406b --- /dev/null +++ b/unit_tests/mocks/mock_gmm_client_context_base.h @@ -0,0 +1,37 @@ +/* +* 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 "gmm_client_context.h" + +namespace OCLRT { +class MockGmmClientContextBase : public GmmClientContext { + public: + MEMORY_OBJECT_CONTROL_STATE cachePolicyGetMemoryObject(GMM_RESOURCE_INFO *pResInfo, GMM_RESOURCE_USAGE_TYPE usage) override; + GMM_RESOURCE_INFO *createResInfoObject(GMM_RESCREATE_PARAMS *pCreateParams) override; + GMM_RESOURCE_INFO *copyResInfoObject(GMM_RESOURCE_INFO *pSrcRes) override; + void destroyResInfoObject(GMM_RESOURCE_INFO *pResInfo) override; + + protected: + MockGmmClientContextBase(GMM_CLIENT clientType); +}; +} // namespace OCLRT