diff --git a/runtime/gmm_helper/gmm.cpp b/runtime/gmm_helper/gmm.cpp index d3369b8527..33a4b76d65 100644 --- a/runtime/gmm_helper/gmm.cpp +++ b/runtime/gmm_helper/gmm.cpp @@ -30,15 +30,46 @@ #include "runtime/helpers/hw_info.h" namespace OCLRT { -void Gmm::create() { +Gmm::Gmm(const void *alignedPtr, size_t alignedSize, bool uncacheable) { + resourceParams.Type = RESOURCE_BUFFER; + resourceParams.Format = GMM_FORMAT_GENERIC_8BIT; + resourceParams.BaseWidth = static_cast(alignedSize); + resourceParams.BaseHeight = 1; + resourceParams.Depth = 1; + if (!uncacheable) { + resourceParams.Usage = GMM_RESOURCE_USAGE_OCL_BUFFER; + } else { + resourceParams.Usage = GMM_RESOURCE_USAGE_OCL_BUFFER_CSR_UC; + } + resourceParams.Flags.Info.Linear = 1; + resourceParams.Flags.Info.Cacheable = 1; + resourceParams.Flags.Gpu.Texture = 1; + + if (alignedPtr) { + resourceParams.Flags.Info.ExistingSysMem = 1; + resourceParams.pExistingSysMem = reinterpret_cast(alignedPtr); + resourceParams.ExistingSysMemSize = alignedSize; + } + if (resourceParams.BaseWidth >= GmmHelper::maxPossiblePitch) { resourceParams.Flags.Gpu.NoRestriction = 1; } + applyAuxFlagsForBuffer(false); + gmmResourceInfo.reset(GmmResourceInfo::create(&resourceParams)); } +Gmm::Gmm(GMM_RESOURCE_INFO *inputGmm) { + gmmResourceInfo.reset(GmmResourceInfo::create(inputGmm)); +} + +Gmm::Gmm(ImageInfo &inputOutputImgInfo) { + queryImageParams(inputOutputImgInfo); +} + void Gmm::queryImageParams(ImageInfo &imgInfo) { + this->resourceParams = {}; uint32_t imageWidth = static_cast(imgInfo.imgDesc->image_width); uint32_t imageHeight = 1; uint32_t imageDepth = 1; @@ -90,7 +121,7 @@ void Gmm::queryImageParams(ImageInfo &imgInfo) { this->resourceParams.Flags.Info.AllowVirtualPadding = true; } - applyAuxFlags(imgInfo); + applyAuxFlagsForImage(imgInfo); this->gmmResourceInfo.reset(GmmResourceInfo::create(&this->resourceParams)); @@ -144,7 +175,6 @@ void Gmm::queryImageParams(ImageInfo &imgInfo) { } imgInfo.qPitch = queryQPitch(this->resourceParams.Type); - return; } uint32_t Gmm::queryQPitch(GMM_RESOURCE_TYPE resType) { diff --git a/runtime/gmm_helper/gmm.h b/runtime/gmm_helper/gmm.h index d094b06511..4917cebe20 100644 --- a/runtime/gmm_helper/gmm.h +++ b/runtime/gmm_helper/gmm.h @@ -36,14 +36,18 @@ class GmmResourceInfo; class Gmm { public: virtual ~Gmm() = default; + Gmm() = delete; + Gmm(ImageInfo &inputOutputImgInfo); + Gmm(const void *alignedPtr, size_t alignedSize, bool uncacheable); + Gmm(GMM_RESOURCE_INFO *inputGmm); - void create(); - void queryImageParams(ImageInfo &imgInfo); + void queryImageParams(ImageInfo &inputOutputImgInfo); uint32_t getRenderHAlignment(); uint32_t getRenderVAlignment(); - void applyAuxFlags(ImageInfo &imgInfo); + void applyAuxFlagsForImage(ImageInfo &imgInfo); + void applyAuxFlagsForBuffer(bool preferRenderCompression); bool unifiedAuxTranslationCapable() const; uint32_t queryQPitch(GMM_RESOURCE_TYPE resType); diff --git a/runtime/gmm_helper/gmm_helper.cpp b/runtime/gmm_helper/gmm_helper.cpp index 70fa8d803c..e022633a3d 100644 --- a/runtime/gmm_helper/gmm_helper.cpp +++ b/runtime/gmm_helper/gmm_helper.cpp @@ -73,46 +73,6 @@ uint32_t GmmHelper::getMOCS(uint32_t type) { return static_cast(mocs.DwordValue); } -Gmm *GmmHelper::create(const void *alignedPtr, size_t alignedSize, bool uncacheable) { - auto gmm = new Gmm(); - - gmm->resourceParams.Type = RESOURCE_BUFFER; - gmm->resourceParams.Format = GMM_FORMAT_GENERIC_8BIT; - gmm->resourceParams.BaseWidth = (uint32_t)alignedSize; - gmm->resourceParams.BaseHeight = 1; - gmm->resourceParams.Depth = 1; - if (!uncacheable) { - gmm->resourceParams.Usage = GMM_RESOURCE_USAGE_OCL_BUFFER; - } else { - gmm->resourceParams.Usage = GMM_RESOURCE_USAGE_OCL_BUFFER_CSR_UC; - } - gmm->resourceParams.Flags.Info.Linear = 1; - gmm->resourceParams.Flags.Info.Cacheable = 1; - gmm->resourceParams.Flags.Gpu.Texture = 1; - - if (alignedPtr != nullptr) { - gmm->resourceParams.Flags.Info.ExistingSysMem = 1; - gmm->resourceParams.pExistingSysMem = reinterpret_cast(alignedPtr); - gmm->resourceParams.ExistingSysMemSize = alignedSize; - } - - gmm->create(); - - return gmm; -} - -Gmm *GmmHelper::create(GMM_RESOURCE_INFO *inputGmm) { - auto gmm = new Gmm(); - gmm->gmmResourceInfo.reset(GmmResourceInfo::create(inputGmm)); - return gmm; -} - -Gmm *GmmHelper::createGmmAndQueryImgParams(ImageInfo &imgInfo) { - Gmm *gmm = new Gmm(); - gmm->queryImageParams(imgInfo); - return gmm; -} - void GmmHelper::queryImgFromBufferParams(ImageInfo &imgInfo, GraphicsAllocation *gfxAlloc) { // 1D or 2D from buffer if (imgInfo.imgDesc->image_row_pitch > 0) { diff --git a/runtime/gmm_helper/gmm_helper.h b/runtime/gmm_helper/gmm_helper.h index 7f75b507c0..1ae2d993d4 100644 --- a/runtime/gmm_helper/gmm_helper.h +++ b/runtime/gmm_helper/gmm_helper.h @@ -43,10 +43,6 @@ class GmmHelper { static constexpr uint32_t cacheEnabledIndex = 4; static constexpr uint32_t maxPossiblePitch = 2147483648; - static Gmm *createGmmAndQueryImgParams(ImageInfo &imgInfo); - static Gmm *create(const void *alignedPtr, size_t alignedSize, bool uncacheable); - static Gmm *create(GMM_RESOURCE_INFO *inputGmm); - static void loadLib(); static bool initContext(const PLATFORM *pPlatform, const FeatureTable *pSkuTable, const WorkaroundTable *pWaTable, const GT_SYSTEM_INFO *pGtSysInfo); static void destroyContext(); diff --git a/runtime/gmm_helper/gmm_utils.cpp b/runtime/gmm_helper/gmm_utils.cpp index 50fe67f0f5..72f5accf7f 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) { -} +using namespace OCLRT; + +void Gmm::applyAuxFlagsForImage(ImageInfo &imgInfo) {} +void Gmm::applyAuxFlagsForBuffer(bool preferRenderCompression) {} diff --git a/runtime/mem_obj/image.cpp b/runtime/mem_obj/image.cpp index 79f15e58bb..dfe3eb824d 100644 --- a/runtime/mem_obj/image.cpp +++ b/runtime/mem_obj/image.cpp @@ -213,7 +213,7 @@ Image *Image::create(Context *context, if (memoryManager->peekVirtualPaddingSupport() && (imageDesc->image_type == CL_MEM_OBJECT_IMAGE2D)) { // Retrieve sizes from GMM and apply virtual padding if buffer storage is not big enough auto queryGmmImgInfo(imgInfo); - std::unique_ptr gmm(GmmHelper::createGmmAndQueryImgParams(queryGmmImgInfo)); + std::unique_ptr gmm(new Gmm(queryGmmImgInfo)); auto gmmAllocationSize = gmm->gmmResourceInfo->getSizeAllocation(); if (gmmAllocationSize > memory->getUnderlyingBufferSize()) { memory = memoryManager->createGraphicsAllocationWithPadding(memory, gmmAllocationSize); @@ -224,8 +224,7 @@ Image *Image::create(Context *context, memory->gmm->queryImageParams(imgInfo); isTilingAllowed = parentImage->allowTiling(); } else { - gmm = new Gmm(); - gmm->queryImageParams(imgInfo); + gmm = new Gmm(imgInfo); errcodeRet = CL_OUT_OF_HOST_MEMORY; if (flags & CL_MEM_USE_HOST_PTR) { @@ -656,10 +655,7 @@ cl_int Image::getImageParams(Context *context, imgInfo.imgDesc = &imageDescriptor; imgInfo.surfaceFormat = surfaceFormat; - Gmm *gmm = nullptr; - gmm = new Gmm(); - gmm->queryImageParams(imgInfo); - delete gmm; + std::unique_ptr gmm(new Gmm(imgInfo)); // query imgInfo *imageRowPitch = imgInfo.rowPitch; *imageSlicePitch = imgInfo.slicePitch; diff --git a/runtime/os_interface/windows/wddm/wddm.cpp b/runtime/os_interface/windows/wddm/wddm.cpp index e362b1ce22..b231768169 100644 --- a/runtime/os_interface/windows/wddm/wddm.cpp +++ b/runtime/os_interface/windows/wddm/wddm.cpp @@ -633,7 +633,8 @@ bool Wddm::openSharedHandle(D3DKMT_HANDLE handle, WddmAllocation *alloc) { alloc->handle = allocationInfo[0].hAllocation; alloc->resourceHandle = OpenResource.hResource; - alloc->gmm = GmmHelper::create((PGMM_RESOURCE_INFO)(allocationInfo[0].pPrivateDriverData)); + auto resourceInfo = const_cast(allocationInfo[0].pPrivateDriverData); + alloc->gmm = new Gmm(static_cast(resourceInfo)); return true; } @@ -669,7 +670,8 @@ bool Wddm::openNTHandle(HANDLE handle, WddmAllocation *alloc) { alloc->handle = allocationInfo2[0].hAllocation; alloc->resourceHandle = openResourceFromNtHandle.hResource; - alloc->gmm = GmmHelper::create((PGMM_RESOURCE_INFO)(allocationInfo2[0].pPrivateDriverData)); + auto resourceInfo = const_cast(allocationInfo2[0].pPrivateDriverData); + alloc->gmm = new Gmm(static_cast(resourceInfo)); return true; } diff --git a/runtime/os_interface/windows/wddm_memory_manager.cpp b/runtime/os_interface/windows/wddm_memory_manager.cpp index 0463615fa9..02dc7fd89c 100644 --- a/runtime/os_interface/windows/wddm_memory_manager.cpp +++ b/runtime/os_interface/windows/wddm_memory_manager.cpp @@ -81,7 +81,7 @@ GraphicsAllocation *WddmMemoryManager::allocateGraphicsMemory64kb(size_t size, s auto wddmAllocation = new WddmAllocation(nullptr, sizeAligned, nullptr, sizeAligned, nullptr); - gmm = GmmHelper::create(nullptr, sizeAligned, false); + gmm = new Gmm(nullptr, sizeAligned, false); wddmAllocation->gmm = gmm; if (!wddm->createAllocation64k(wddmAllocation)) { @@ -115,7 +115,7 @@ GraphicsAllocation *WddmMemoryManager::allocateGraphicsMemory(size_t size, size_ auto wddmAllocation = new WddmAllocation(pSysMem, sizeAligned, pSysMem, sizeAligned, nullptr); wddmAllocation->cpuPtrAllocated = true; - gmm = GmmHelper::create(pSysMem, sizeAligned, uncacheable); + gmm = new Gmm(pSysMem, sizeAligned, uncacheable); wddmAllocation->gmm = gmm; @@ -150,7 +150,7 @@ GraphicsAllocation *WddmMemoryManager::allocateGraphicsMemory(size_t size, const auto allocation = new WddmAllocation(ptr, size, ptrAligned, sizeAligned, reserve); allocation->allocationOffset = offset; - Gmm *gmm = GmmHelper::create(ptrAligned, sizeAligned, false); + Gmm *gmm = new Gmm(ptrAligned, sizeAligned, false); allocation->gmm = gmm; if (createWddmAllocation(allocation, AllocationOrigin::EXTERNAL_ALLOCATION)) { return allocation; @@ -189,7 +189,7 @@ GraphicsAllocation *WddmMemoryManager::allocate32BitGraphicsMemory(size_t size, wddmAllocation->is32BitAllocation = true; wddmAllocation->allocationOffset = offset; - gmm = GmmHelper::create(ptrAligned, sizeAligned, false); + gmm = new Gmm(ptrAligned, sizeAligned, false); wddmAllocation->gmm = gmm; if (!createWddmAllocation(wddmAllocation, allocationOrigin)) { @@ -364,7 +364,7 @@ MemoryManager::AllocationStatus WddmMemoryManager::populateOsHandles(OsHandleSto handleStorage.fragmentStorageData[i].osHandleStorage = new OsHandle(); handleStorage.fragmentStorageData[i].residency = new ResidencyData(); - handleStorage.fragmentStorageData[i].osHandleStorage->gmm = GmmHelper::create(handleStorage.fragmentStorageData[i].cpuPtr, handleStorage.fragmentStorageData[i].fragmentSize, false); + handleStorage.fragmentStorageData[i].osHandleStorage->gmm = new Gmm(handleStorage.fragmentStorageData[i].cpuPtr, handleStorage.fragmentStorageData[i].fragmentSize, false); allocatedFragmentIndexes[allocatedFragmentsCounter] = i; allocatedFragmentsCounter++; } diff --git a/runtime/sharings/d3d/d3d_surface.cpp b/runtime/sharings/d3d/d3d_surface.cpp index ca8ffdd2f9..a61aa3a30d 100644 --- a/runtime/sharings/d3d/d3d_surface.cpp +++ b/runtime/sharings/d3d/d3d_surface.cpp @@ -102,7 +102,7 @@ Image *D3DSurface::create(Context *context, cl_dx9_surface_info_khr *surfaceInfo imgDesc.image_width /= 2; imgDesc.image_height /= 2; } - Gmm *gmm = GmmHelper::createGmmAndQueryImgParams(imgInfo); + Gmm *gmm = new Gmm(imgInfo); imgDesc.image_row_pitch = imgInfo.rowPitch; imgDesc.image_slice_pitch = imgInfo.slicePitch; diff --git a/runtime/sharings/va/va_surface.cpp b/runtime/sharings/va/va_surface.cpp index 1f6d4a3b1c..40e561b8fb 100644 --- a/runtime/sharings/va/va_surface.cpp +++ b/runtime/sharings/va/va_surface.cpp @@ -74,7 +74,7 @@ Image *VASurface::createSharedVaSurface(Context *context, VASharingFunctions *sh auto alloc = memoryManager->createGraphicsAllocationFromSharedHandle(sharedHandle, false, true); - Gmm *gmm = GmmHelper::createGmmAndQueryImgParams(imgInfo); + Gmm *gmm = new Gmm(imgInfo); DEBUG_BREAK_IF(alloc->gmm != nullptr); alloc->gmm = gmm; diff --git a/unit_tests/gmm_helper/gmm_helper_tests.cpp b/unit_tests/gmm_helper/gmm_helper_tests.cpp index 58af171aa6..148f974c89 100644 --- a/unit_tests/gmm_helper/gmm_helper_tests.cpp +++ b/unit_tests/gmm_helper/gmm_helper_tests.cpp @@ -40,7 +40,7 @@ class GmmTests : public ::testing::Test { TEST_F(GmmTests, resourceCreation) { std::unique_ptr mm(new OsAgnosticMemoryManager); void *pSysMem = mm->allocateSystemMemory(4096, 4096); - std::unique_ptr gmm(GmmHelper::create(pSysMem, 4096, false)); + std::unique_ptr gmm(new Gmm(pSysMem, 4096, false)); ASSERT_TRUE(gmm->gmmResourceInfo.get() != nullptr); @@ -55,7 +55,7 @@ TEST_F(GmmTests, resourceCreationUncacheable) { std::unique_ptr mm(new OsAgnosticMemoryManager); void *pSysMem = mm->allocateSystemMemory(4096, 4096); - std::unique_ptr gmm(GmmHelper::create(pSysMem, 4096, true)); + std::unique_ptr gmm(new Gmm(pSysMem, 4096, true)); ASSERT_TRUE(gmm->gmmResourceInfo.get() != nullptr); @@ -71,7 +71,7 @@ TEST_F(GmmTests, resourceCleanupOnDelete) { std::unique_ptr mm(new OsAgnosticMemoryManager); void *pSysMem = mm->allocateSystemMemory(4096, 4096); - std::unique_ptr gmm(GmmHelper::create(pSysMem, 4096, false)); + std::unique_ptr gmm(new Gmm(pSysMem, 4096, false)); ASSERT_TRUE(gmm->gmmResourceInfo.get() != nullptr); @@ -84,7 +84,7 @@ TEST_F(GmmTests, GivenBufferSizeLargerThenMaxPitchWhenAskedForGmmCreationThenGMM MemoryManager *mm = new OsAgnosticMemoryManager; void *pSysMem = mm->allocateSystemMemory(4096, 4096); - auto gmmRes = GmmHelper::create(pSysMem, maxSize, false); + auto gmmRes = new Gmm(pSysMem, maxSize, false); ASSERT_TRUE(gmmRes->gmmResourceInfo.get() != nullptr); @@ -97,8 +97,8 @@ TEST_F(GmmTests, GivenBufferSizeLargerThenMaxPitchWhenAskedForGmmCreationThenGMM TEST_F(GmmTests, givenGmmCreatedFromExistingGmmThenHelperDoesNotReleaseParentGmm) { auto size = 4096u; void *incomingPtr = (void *)0x1000; - auto gmmRes = GmmHelper::create(incomingPtr, size, false); - auto gmmRes2 = GmmHelper::create(gmmRes->gmmResourceInfo->peekHandle()); + auto gmmRes = new Gmm(incomingPtr, size, false); + auto gmmRes2 = new Gmm(gmmRes->gmmResourceInfo->peekHandle()); //copy is being made EXPECT_NE(gmmRes2->gmmResourceInfo->peekHandle(), gmmRes->gmmResourceInfo->peekHandle()); @@ -570,7 +570,7 @@ TEST_F(GmmTests, copyResourceBlt) { } TEST(GmmTest, givenAllValidFlagsWhenAskedForUnifiedAuxTranslationCapabilityThenReturnTrue) { - auto gmm = std::unique_ptr(GmmHelper::create(nullptr, 1, false)); + auto gmm = std::unique_ptr(new Gmm(nullptr, 1, false)); auto mockResource = reinterpret_cast(gmm->gmmResourceInfo.get()); mockResource->setUnifiedAuxTranslationCapable(); @@ -582,7 +582,7 @@ TEST(GmmTest, givenAllValidFlagsWhenAskedForUnifiedAuxTranslationCapabilityThenR } TEST(GmmTest, givenInvalidFlagsSetWhenAskedForUnifiedAuxTranslationCapabilityThenReturnFalse) { - auto gmm = std::unique_ptr(GmmHelper::create(nullptr, 1, false)); + auto gmm = std::unique_ptr(new Gmm(nullptr, 1, false)); auto mockResource = reinterpret_cast(gmm->gmmResourceInfo.get()); mockResource->mockResourceCreateParams.Flags.Gpu.CCS = 0; diff --git a/unit_tests/helpers/mipmap_tests.cpp b/unit_tests/helpers/mipmap_tests.cpp index cd8b6a176f..a19cbde5b1 100644 --- a/unit_tests/helpers/mipmap_tests.cpp +++ b/unit_tests/helpers/mipmap_tests.cpp @@ -111,15 +111,16 @@ struct MockMipMapGmmResourceInfo : GmmResourceInfo { }; struct MockImage : MockImageBase { - MockGmm mockGmm; + std::unique_ptr mockGmm; MockImage() : MockImageBase() { - graphicsAllocation->gmm = &mockGmm; - mockGmm.gmmResourceInfo.reset(new MockMipMapGmmResourceInfo()); + mockGmm.reset(new Gmm(nullptr, 0, false)); + graphicsAllocation->gmm = mockGmm.get(); + mockGmm->gmmResourceInfo.reset(new MockMipMapGmmResourceInfo()); } MockMipMapGmmResourceInfo *getResourceInfo() { - return static_cast(mockGmm.gmmResourceInfo.get()); + return static_cast(mockGmm->gmmResourceInfo.get()); } }; diff --git a/unit_tests/mem_obj/image_set_arg_tests.cpp b/unit_tests/mem_obj/image_set_arg_tests.cpp index b1f259a801..d237a05a02 100644 --- a/unit_tests/mem_obj/image_set_arg_tests.cpp +++ b/unit_tests/mem_obj/image_set_arg_tests.cpp @@ -417,7 +417,7 @@ HWTEST_F(ImageSetArgTest, givenMcsAllocationWhenSetArgIsCalledWithoutUnifiedAuxC typedef typename FamilyType::RENDER_SURFACE_STATE RENDER_SURFACE_STATE; McsSurfaceInfo msi = {10, 20, 3}; auto mcsAlloc = context->getMemoryManager()->allocateGraphicsMemory(4096); - mcsAlloc->gmm = GmmHelper::create(nullptr, 1, false); + mcsAlloc->gmm = new Gmm(nullptr, 1, false); cl_image_desc imgDesc = Image2dDefaults::imageDesc; imgDesc.num_samples = 8; @@ -514,7 +514,7 @@ HWTEST_F(ImageSetArgTest, givenMcsAllocationAndRenderCompressionWhenSetArgOnMult typedef typename FamilyType::RENDER_SURFACE_STATE RENDER_SURFACE_STATE; McsSurfaceInfo msi = {10, 20, 3}; auto mcsAlloc = context->getMemoryManager()->allocateGraphicsMemory(4096); - mcsAlloc->gmm = GmmHelper::create(nullptr, 1, false); + mcsAlloc->gmm = new Gmm(nullptr, 1, false); cl_image_desc imgDesc = Image2dDefaults::imageDesc; imgDesc.num_samples = 8; @@ -571,7 +571,7 @@ HWTEST_F(ImageSetArgTest, givenMcsAllocationWhenSetArgIsCalledWithUnifiedAuxCapa typedef typename FamilyType::RENDER_SURFACE_STATE RENDER_SURFACE_STATE; McsSurfaceInfo msi = {10, 20, 3}; auto mcsAlloc = context->getMemoryManager()->allocateGraphicsMemory(4096); - mcsAlloc->gmm = GmmHelper::create(nullptr, 1, false); + mcsAlloc->gmm = new Gmm(nullptr, 1, false); cl_image_desc imgDesc = Image2dDefaults::imageDesc; imgDesc.num_samples = 8; diff --git a/unit_tests/memory_manager/memory_manager_tests.cpp b/unit_tests/memory_manager/memory_manager_tests.cpp index 00f491f48d..73014f2784 100644 --- a/unit_tests/memory_manager/memory_manager_tests.cpp +++ b/unit_tests/memory_manager/memory_manager_tests.cpp @@ -834,7 +834,7 @@ TEST(OsAgnosticMemoryManager, givenDefaultMemoryManagerWhenAllocateGraphicsMemor TEST(OsAgnosticMemoryManager, givenDefaultMemoryManagerAndUnifiedAuxCapableAllocationWhenMappingThenReturnFalse) { OsAgnosticMemoryManager memoryManager; - auto gmm = GmmHelper::create(nullptr, 123, false); + auto gmm = new Gmm(nullptr, 123, false); auto allocation = memoryManager.allocateGraphicsMemory(123); allocation->gmm = gmm; @@ -1215,7 +1215,7 @@ TEST(OsAgnosticMemoryManager, givenDefaultOsAgnosticMemoryManagerWhenItIsQueried } TEST_F(MemoryAllocatorTest, GivenSizeWhenGmmIsCreatedThenSuccess) { - Gmm *gmm = GmmHelper::create(nullptr, 65536, false); + Gmm *gmm = new Gmm(nullptr, 65536, false); EXPECT_NE(nullptr, gmm); delete gmm; } diff --git a/unit_tests/mocks/mock_gmm.h b/unit_tests/mocks/mock_gmm.h index c86f2ccfbd..2789e6711c 100644 --- a/unit_tests/mocks/mock_gmm.h +++ b/unit_tests/mocks/mock_gmm.h @@ -36,7 +36,7 @@ static SurfaceFormatInfo mockSurfaceFormat; class MockGmm : public Gmm { public: static std::unique_ptr queryImgParams(ImageInfo &imgInfo) { - return std::unique_ptr(GmmHelper::createGmmAndQueryImgParams(imgInfo)); + return std::unique_ptr(new Gmm(imgInfo)); } static ImageInfo initImgInfo(cl_image_desc &imgDesc, int baseMipLevel, const SurfaceFormatInfo *surfaceFormat) { diff --git a/unit_tests/os_interface/linux/drm_memory_manager_tests.cpp b/unit_tests/os_interface/linux/drm_memory_manager_tests.cpp index dba807f954..32afe30f33 100644 --- a/unit_tests/os_interface/linux/drm_memory_manager_tests.cpp +++ b/unit_tests/os_interface/linux/drm_memory_manager_tests.cpp @@ -1858,7 +1858,7 @@ TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerAndUnifiedAuxCapableAllocation mock->ioctl_expected.gemWait = 1; mock->ioctl_expected.gemClose = 1; - auto gmm = GmmHelper::create(nullptr, 123, false); + auto gmm = new Gmm(nullptr, 123, false); auto allocation = memoryManager->allocateGraphicsMemory(123, 123); allocation->gmm = gmm; diff --git a/unit_tests/os_interface/windows/wddm20_tests.cpp b/unit_tests/os_interface/windows/wddm20_tests.cpp index 8080be49a1..b07a1cce07 100644 --- a/unit_tests/os_interface/windows/wddm20_tests.cpp +++ b/unit_tests/os_interface/windows/wddm20_tests.cpp @@ -47,28 +47,9 @@ namespace GmmHelperFunctions { Gmm *getGmm(void *ptr, size_t size) { size_t alignedSize = alignSizeWholePage(ptr, size); void *alignedPtr = alignUp(ptr, 4096); - Gmm *gmm = new Gmm; - - gmm->resourceParams.Type = RESOURCE_BUFFER; - gmm->resourceParams.Format = GMM_FORMAT_GENERIC_8BIT; - gmm->resourceParams.BaseWidth = (uint32_t)alignedSize; - gmm->resourceParams.BaseHeight = 1; - gmm->resourceParams.Depth = 1; - gmm->resourceParams.Usage = GMM_RESOURCE_USAGE_OCL_BUFFER; - - gmm->resourceParams.pExistingSysMem = reinterpret_cast(alignedPtr); - gmm->resourceParams.ExistingSysMemSize = alignedSize; - gmm->resourceParams.BaseAlignment = 0; - - gmm->resourceParams.Flags.Info.ExistingSysMem = 1; - gmm->resourceParams.Flags.Info.Linear = 1; - gmm->resourceParams.Flags.Info.Cacheable = 1; - gmm->resourceParams.Flags.Gpu.Texture = 1; - - gmm->create(); + Gmm *gmm = new Gmm(alignedPtr, alignedSize, false); EXPECT_NE(gmm->gmmResourceInfo.get(), nullptr); - return gmm; } } // namespace GmmHelperFunctions @@ -107,7 +88,7 @@ TEST_F(Wddm20Tests, givenNullPageTableManagerWhenUpdateAuxTableCalledThenReturnF wddm->resetPageTableManager(nullptr); EXPECT_EQ(nullptr, wddm->getPageTableManager()); - auto gmm = std::unique_ptr(GmmHelper::create(nullptr, 1, false)); + auto gmm = std::unique_ptr(new Gmm(nullptr, 1, false)); auto mockGmmRes = reinterpret_cast(gmm->gmmResourceInfo.get()); mockGmmRes->setUnifiedAuxTranslationCapable(); @@ -468,7 +449,7 @@ TEST_F(Wddm20Tests, GetCpuGpuTime) { HWTEST_F(Wddm20WithMockGdiDllTests, givenSharedHandleWhenCreateGraphicsAllocationFromSharedHandleIsCalledThenGraphicsAllocationWithSharedPropertiesIsCreated) { void *pSysMem = (void *)0x1000; - std::unique_ptr gmm(GmmHelper::create(pSysMem, 4096u, false)); + std::unique_ptr gmm(new Gmm(pSysMem, 4096u, false)); auto status = setSizesFcn(gmm->gmmResourceInfo.get(), 1u, 1024u, 1u); EXPECT_EQ(0u, status); @@ -506,7 +487,7 @@ HWTEST_F(Wddm20WithMockGdiDllTests, givenSharedHandleWhenCreateGraphicsAllocatio HWTEST_F(Wddm20WithMockGdiDllTests, givenSharedHandleWhenCreateGraphicsAllocationFromSharedHandleIsCalledThenMapGpuVaWithCpuPtrDepensOnBitness) { void *pSysMem = (void *)0x1000; - std::unique_ptr gmm(GmmHelper::create(pSysMem, 4096u, false)); + std::unique_ptr gmm(new Gmm(pSysMem, 4096u, false)); auto status = setSizesFcn(gmm->gmmResourceInfo.get(), 1u, 1024u, 1u); EXPECT_EQ(0u, status); diff --git a/unit_tests/os_interface/windows/wddm_kmdaf_listener_tests.cpp b/unit_tests/os_interface/windows/wddm_kmdaf_listener_tests.cpp index 48eddb0ee9..8274d409f1 100644 --- a/unit_tests/os_interface/windows/wddm_kmdaf_listener_tests.cpp +++ b/unit_tests/os_interface/windows/wddm_kmdaf_listener_tests.cpp @@ -95,7 +95,7 @@ HWTEST_F(WddmKmDafListenerTest, givenWddmWhenUnlockResourceIsCalledThenKmDafList HWTEST_F(WddmKmDafListenerTest, givenWddmWhenMapGpuVirtualAddressIsCalledThenKmDafListenerNotifyMapGpuVAIsFedWithCorrectParams) { WddmAllocation allocation((void *)0x23000, 0x1000, nullptr); allocation.handle = ALLOCATION_HANDLE; - auto gmm = std::unique_ptr(GmmHelper::create(nullptr, 1, false)); + auto gmm = std::unique_ptr(new Gmm(nullptr, 1, false)); allocation.gmm = gmm.get(); wddmWithKmDafMock->mapGpuVirtualAddressImpl(allocation.gmm, allocation.handle, allocation.getUnderlyingBuffer(), allocation.getUnderlyingBufferSize(), allocation.gpuPtr, false, false, false); @@ -150,7 +150,7 @@ HWTEST_F(WddmKmDafListenerTest, givenWddmWhenEvictIsCalledThenKmDafListenerNotif HWTEST_F(WddmKmDafListenerTest, givenWddmWhenCreateAllocationIsCalledThenKmDafListenerNotifyWriteTargetIsFedWithCorrectParams) { WddmAllocation allocation((void *)0x23000, 0x1000, nullptr); - auto gmm = std::unique_ptr(GmmHelper::create(nullptr, 1, false)); + auto gmm = std::unique_ptr(new Gmm(nullptr, 1, false)); allocation.gmm = gmm.get(); wddmWithKmDafMock->createAllocation(&allocation); @@ -164,7 +164,7 @@ HWTEST_F(WddmKmDafListenerTest, givenWddmWhenCreateAllocationIsCalledThenKmDafLi HWTEST_F(WddmKmDafListenerTest, givenWddmWhenCreateAllocation64IsCalledThenKmDafListenerNotifyWriteTargetIsFedWithCorrectParams) { WddmAllocation allocation((void *)0x23000, 0x1000, nullptr); - auto gmm = std::unique_ptr(GmmHelper::create(nullptr, 1, false)); + auto gmm = std::unique_ptr(new Gmm(nullptr, 1, false)); allocation.gmm = gmm.get(); wddmWithKmDafMock->createAllocation64k(&allocation); @@ -179,7 +179,7 @@ HWTEST_F(WddmKmDafListenerTest, givenWddmWhenCreateAllocation64IsCalledThenKmDaf HWTEST_F(WddmKmDafListenerTest, givenWddmWhenCreateAllocationsAndMapGpuVaIsCalledThenKmDafListenerNotifyWriteTargetAndMapGpuVAIsFedWithCorrectParams) { OsHandleStorage storage; OsHandle osHandle = {0}; - auto gmm = std::unique_ptr(GmmHelper::create(nullptr, 1, false)); + auto gmm = std::unique_ptr(new Gmm(nullptr, 1, false)); storage.fragmentStorageData[0].osHandleStorage = &osHandle; storage.fragmentStorageData[0].fragmentSize = 100; storage.fragmentStorageData[0].osHandleStorage->gmm = gmm.get(); diff --git a/unit_tests/os_interface/windows/wddm_memory_manager_tests.cpp b/unit_tests/os_interface/windows/wddm_memory_manager_tests.cpp index a309415771..b526c9a939 100644 --- a/unit_tests/os_interface/windows/wddm_memory_manager_tests.cpp +++ b/unit_tests/os_interface/windows/wddm_memory_manager_tests.cpp @@ -152,7 +152,7 @@ HWTEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenCreateFromSharedHandle auto size = 4096u; void *pSysMem = reinterpret_cast(0x1000); - std::unique_ptr gmm(GmmHelper::create(pSysMem, 4096u, false)); + std::unique_ptr gmm(new Gmm(pSysMem, 4096u, false)); auto status = setSizesFcn(gmm->gmmResourceInfo.get(), 1u, 1024u, 1u); auto *gpuAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(osHandle, false, false); @@ -169,7 +169,7 @@ HWTEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenCreateFromNTHandleIsCa auto size = 4096u; void *pSysMem = reinterpret_cast(0x1000); - std::unique_ptr gmm(GmmHelper::create(pSysMem, 4096u, false)); + std::unique_ptr gmm(new Gmm(pSysMem, 4096u, false)); auto status = setSizesFcn(gmm->gmmResourceInfo.get(), 1u, 1024u, 1u); auto *gpuAllocation = memoryManager->createGraphicsAllocationFromNTHandle(reinterpret_cast(1)); @@ -203,7 +203,7 @@ HWTEST_F(WddmMemoryManagerTest, createAllocationFromSharedHandleReturns32BitAllo auto size = 4096u; void *pSysMem = reinterpret_cast(0x1000); - std::unique_ptr gmm(GmmHelper::create(pSysMem, 4096u, false)); + std::unique_ptr gmm(new Gmm(pSysMem, 4096u, false)); auto status = setSizesFcn(gmm->gmmResourceInfo.get(), 1u, 1024u, 1u); memoryManager->setForce32BitAllocations(true); @@ -226,7 +226,7 @@ HWTEST_F(WddmMemoryManagerTest, createAllocationFromSharedHandleDoesNotReturn32B auto size = 4096u; void *pSysMem = reinterpret_cast(0x1000); - std::unique_ptr gmm(GmmHelper::create(pSysMem, 4096u, false)); + std::unique_ptr gmm(new Gmm(pSysMem, 4096u, false)); auto status = setSizesFcn(gmm->gmmResourceInfo.get(), 1u, 1024u, 1u); memoryManager->setForce32BitAllocations(true); @@ -249,7 +249,7 @@ HWTEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenFreeAllocFromSharedHan auto size = 4096u; void *pSysMem = reinterpret_cast(0x1000); - std::unique_ptr gmm(GmmHelper::create(pSysMem, 4096u, false)); + std::unique_ptr gmm(new Gmm(pSysMem, 4096u, false)); auto status = setSizesFcn(gmm->gmmResourceInfo.get(), 1u, 1024u, 1u); auto gpuAllocation = (WddmAllocation *)memoryManager->createGraphicsAllocationFromSharedHandle(osHandle, false, false); @@ -271,7 +271,7 @@ HWTEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerSizeZeroWhenCreateFromShar auto size = 4096u; void *pSysMem = reinterpret_cast(0x1000); - std::unique_ptr gmm(GmmHelper::create(pSysMem, size, false)); + std::unique_ptr gmm(new Gmm(pSysMem, size, false)); auto status = setSizesFcn(gmm->gmmResourceInfo.get(), 1u, 1024u, 1u); auto *gpuAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(osHandle, false, false); @@ -286,7 +286,7 @@ HWTEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenCreateFromSharedHandle auto size = 4096u; void *pSysMem = reinterpret_cast(0x1000); - std::unique_ptr gmm(GmmHelper::create(pSysMem, size, false)); + std::unique_ptr gmm(new Gmm(pSysMem, size, false)); auto status = setSizesFcn(gmm->gmmResourceInfo.get(), 1u, 1024u, 1u); wddm->failOpenSharedHandle = true; @@ -615,7 +615,7 @@ HWTEST_F(WddmMemoryManagerTest, GivenThreeOsHandlesWhenAskedForDestroyAllocation storage.fragmentStorageData[0].osHandleStorage->handle = ALLOCATION_HANDLE; storage.fragmentStorageData[0].freeTheFragment = true; - storage.fragmentStorageData[0].osHandleStorage->gmm = GmmHelper::create(pSysMem, 4096u, false); + storage.fragmentStorageData[0].osHandleStorage->gmm = new Gmm(pSysMem, 4096u, false); storage.fragmentStorageData[1].osHandleStorage = new OsHandle; storage.fragmentStorageData[1].osHandleStorage->handle = ALLOCATION_HANDLE; @@ -626,7 +626,7 @@ HWTEST_F(WddmMemoryManagerTest, GivenThreeOsHandlesWhenAskedForDestroyAllocation storage.fragmentStorageData[2].osHandleStorage = new OsHandle; storage.fragmentStorageData[2].osHandleStorage->handle = ALLOCATION_HANDLE; storage.fragmentStorageData[2].freeTheFragment = true; - storage.fragmentStorageData[2].osHandleStorage->gmm = GmmHelper::create(pSysMem, 4096u, false); + storage.fragmentStorageData[2].osHandleStorage->gmm = new Gmm(pSysMem, 4096u, false); storage.fragmentStorageData[2].residency = new ResidencyData; memoryManager->cleanOsHandles(storage); @@ -676,7 +676,7 @@ HWTEST_F(WddmMemoryManagerTest, givenManagerWithDisabledDeferredDeleterWhenMapGp SetUpMm(); void *ptr = reinterpret_cast(0x1000); size_t size = 0x1000; - std::unique_ptr gmm(GmmHelper::create(ptr, size, false)); + std::unique_ptr gmm(new Gmm(ptr, size, false)); memoryManager->setDeferredDeleter(nullptr); setMapGpuVaFailConfigFcn(0, 1); @@ -691,7 +691,7 @@ HWTEST_F(WddmMemoryManagerTest, givenManagerWithEnabledDeferredDeleterWhenFirstM SetUpMm(); void *ptr = reinterpret_cast(0x1000); size_t size = 0x1000; - std::unique_ptr gmm(GmmHelper::create(ptr, size, false)); + std::unique_ptr gmm(new Gmm(ptr, size, false)); MockDeferredDeleter *deleter = new MockDeferredDeleter; memoryManager->setDeferredDeleter(deleter); @@ -709,7 +709,7 @@ HWTEST_F(WddmMemoryManagerTest, givenManagerWithEnabledDeferredDeleterWhenFirstA SetUpMm(); void *ptr = reinterpret_cast(0x1000); size_t size = 0x1000; - std::unique_ptr gmm(GmmHelper::create(ptr, size, false)); + std::unique_ptr gmm(new Gmm(ptr, size, false)); MockDeferredDeleter *deleter = new MockDeferredDeleter; memoryManager->setDeferredDeleter(deleter); @@ -1587,7 +1587,7 @@ HWTEST_F(BufferWithWddmMemory, givenFragmentsThatAreNotInOrderWhenGraphicsAlloca handleStorage.fragmentStorageData[0].osHandleStorage = new OsHandle(); handleStorage.fragmentStorageData[0].residency = new ResidencyData(); handleStorage.fragmentStorageData[0].freeTheFragment = true; - handleStorage.fragmentStorageData[0].osHandleStorage->gmm = new MockGmm(); + handleStorage.fragmentStorageData[0].osHandleStorage->gmm = new Gmm(ptr, size, false); handleStorage.fragmentCount = 1; FragmentStorage fragment = {}; @@ -1619,7 +1619,7 @@ HWTEST_F(BufferWithWddmMemory, givenFragmentsThatAreNotInOrderWhenGraphicsAlloca handleStorage.fragmentStorageData[0].osHandleStorage = new OsHandle(); handleStorage.fragmentStorageData[0].residency = new ResidencyData(); handleStorage.fragmentStorageData[0].freeTheFragment = true; - handleStorage.fragmentStorageData[0].osHandleStorage->gmm = new MockGmm(); + handleStorage.fragmentStorageData[0].osHandleStorage->gmm = new Gmm(ptr, size, false); handleStorage.fragmentCount = 1; FragmentStorage fragment = {}; @@ -2021,7 +2021,7 @@ HWTEST_F(MockWddmMemoryManagerTest, givenPageTableManagerWhenMapAuxGpuVaCalledTh } HWTEST_F(MockWddmMemoryManagerTest, givenRenderCompressedAllocationWhenMappedGpuVaThenMapAuxVa) { - std::unique_ptr gmm(GmmHelper::create(reinterpret_cast(123), 4096u, false)); + std::unique_ptr gmm(new Gmm(reinterpret_cast(123), 4096u, false)); gmm->isRenderCompressed = true; D3DGPU_VIRTUAL_ADDRESS gpuVa = 0; WddmMock wddm; @@ -2089,7 +2089,7 @@ HWTEST_F(MockWddmMemoryManagerTest, givenNonRenderCompressedAllocationWhenReleas } HWTEST_F(MockWddmMemoryManagerTest, givenNonRenderCompressedAllocationWhenMappedGpuVaThenDontMapAuxVa) { - std::unique_ptr gmm(GmmHelper::create(reinterpret_cast(123), 4096u, false)); + std::unique_ptr gmm(new Gmm(reinterpret_cast(123), 4096u, false)); gmm->isRenderCompressed = false; D3DGPU_VIRTUAL_ADDRESS gpuVa = 0; WddmMock wddm; @@ -2105,7 +2105,7 @@ HWTEST_F(MockWddmMemoryManagerTest, givenNonRenderCompressedAllocationWhenMapped } HWTEST_F(MockWddmMemoryManagerTest, givenFailingAllocationWhenMappedGpuVaThenReturnFalse) { - std::unique_ptr gmm(GmmHelper::create(reinterpret_cast(123), 4096u, false)); + std::unique_ptr gmm(new Gmm(reinterpret_cast(123), 4096u, false)); gmm->isRenderCompressed = false; D3DGPU_VIRTUAL_ADDRESS gpuVa = 0; WddmMock wddm; @@ -2124,7 +2124,7 @@ HWTEST_F(MockWddmMemoryManagerTest, givenRenderCompressedFlagSetWhenInternalIsUn auto mockMngr = new NiceMock(); wddm->resetPageTableManager(mockMngr); - auto myGmm = GmmHelper::create(reinterpret_cast(123), 4096u, false); + auto myGmm = new Gmm(reinterpret_cast(123), 4096u, false); myGmm->isRenderCompressed = false; myGmm->gmmResourceInfo->getResourceFlags()->Info.RenderCompressed = 1;