diff --git a/runtime/gmm_helper/gmm_helper.cpp b/runtime/gmm_helper/gmm_helper.cpp index 8c3159d4c7..c0b6a2246a 100644 --- a/runtime/gmm_helper/gmm_helper.cpp +++ b/runtime/gmm_helper/gmm_helper.cpp @@ -394,6 +394,11 @@ uint8_t Gmm::resourceCopyBlt(void *sys, void *gpu, uint32_t pitch, uint32_t heig return this->gmmResourceInfo->cpuBlt(&gmmResourceCopyBLT); } +bool Gmm::unifiedAuxTranslationCapable() const { + auto gmmFlags = this->gmmResourceInfo->getResourceFlags(); + return gmmFlags->Gpu.CCS && gmmFlags->Gpu.UnifiedAuxSurface && gmmFlags->Info.RenderCompressed; +} + bool Gmm::useSimplifiedMocsTable = false; } // namespace OCLRT diff --git a/runtime/gmm_helper/gmm_helper.h b/runtime/gmm_helper/gmm_helper.h index a545d61cc9..1886fa64a5 100644 --- a/runtime/gmm_helper/gmm_helper.h +++ b/runtime/gmm_helper/gmm_helper.h @@ -86,6 +86,7 @@ class Gmm { uint32_t getRenderVAlignment(); static uint32_t getRenderAlignment(uint32_t alignment); void applyAuxFlags(ImageInfo &imgInfo, const HardwareInfo &hwInfo); + bool unifiedAuxTranslationCapable() const; uint32_t queryQPitch(GFXCORE_FAMILY gfxFamily, GMM_RESOURCE_TYPE resType); diff --git a/runtime/mem_obj/image.inl b/runtime/mem_obj/image.inl index bec9c5e00a..97583d1f1b 100644 --- a/runtime/mem_obj/image.inl +++ b/runtime/mem_obj/image.inl @@ -178,9 +178,8 @@ template void ImageHw::setAuxParamsForMultisamples(RENDER_SURFACE_STATE *surfaceState) { if (getMcsAllocation()) { auto mcsGmm = getMcsAllocation()->gmm; - auto gmmFlags = mcsGmm->gmmResourceInfo->getResourceFlags(); - if (gmmFlags->Gpu.CCS && gmmFlags->Gpu.UnifiedAuxSurface) { // Ignore MCS allocation when Color Control Surface is available + if (mcsGmm->unifiedAuxTranslationCapable()) { // Ignore MCS allocation when Color Control Surface is available setAuxParamsForCCS(surfaceState, mcsGmm); } else { surfaceState->setAuxiliarySurfaceMode((typename RENDER_SURFACE_STATE::AUXILIARY_SURFACE_MODE)1); diff --git a/runtime/memory_manager/memory_manager.h b/runtime/memory_manager/memory_manager.h index 1a9c6fbe55..3d2c736b5e 100644 --- a/runtime/memory_manager/memory_manager.h +++ b/runtime/memory_manager/memory_manager.h @@ -107,6 +107,8 @@ class MemoryManager { virtual GraphicsAllocation *createGraphicsAllocationFromNTHandle(void *handle) = 0; + virtual bool mapAuxGpuVA(GraphicsAllocation *graphicsAllocation) { return false; }; + virtual void *lockResource(GraphicsAllocation *graphicsAllocation) = 0; virtual void unlockResource(GraphicsAllocation *graphicsAllocation) = 0; diff --git a/runtime/os_interface/windows/wddm.cpp b/runtime/os_interface/windows/wddm.cpp index 2624f308ad..86742d1785 100644 --- a/runtime/os_interface/windows/wddm.cpp +++ b/runtime/os_interface/windows/wddm.cpp @@ -396,14 +396,10 @@ bool Wddm::mapGpuVirtualAddressImpl(Gmm *gmm, D3DKMT_HANDLE handle, void *cpuPtr return false; } - if (gmm && gmm->isRenderCompressed) { - GMM_DDI_UPDATEAUXTABLE ddiUpdateAuxTable = {}; - ddiUpdateAuxTable.BaseGpuVA = gpuPtr; - ddiUpdateAuxTable.BaseResInfo = gmm->gmmResourceInfo->peekHandle(); - ddiUpdateAuxTable.DoNotWait = true; - ddiUpdateAuxTable.Map = true; - return updateAuxTable(ddiUpdateAuxTable); + if (gmm->isRenderCompressed) { + return updateAuxTable(gpuPtr, gmm, true); } + return status == STATUS_SUCCESS; } @@ -889,8 +885,16 @@ void Wddm::initPageTableManagerRegisters(LinearStream &stream) { } } -bool Wddm::updateAuxTable(GMM_DDI_UPDATEAUXTABLE &ddiUpdateAuxTable) { - return pageTableManager->updateAuxTable(&ddiUpdateAuxTable) == GMM_STATUS::GMM_SUCCESS; +bool Wddm::updateAuxTable(D3DGPU_VIRTUAL_ADDRESS gpuVa, Gmm *gmm, bool map) { + if (pageTableManager.get()) { + GMM_DDI_UPDATEAUXTABLE ddiUpdateAuxTable = {}; + ddiUpdateAuxTable.BaseGpuVA = gpuVa; + ddiUpdateAuxTable.BaseResInfo = gmm->gmmResourceInfo->peekHandle(); + ddiUpdateAuxTable.DoNotWait = true; + ddiUpdateAuxTable.Map = map ? 1u : 0u; + return pageTableManager->updateAuxTable(&ddiUpdateAuxTable) == GMM_STATUS::GMM_SUCCESS; + } + return false; } void Wddm::resetPageTableManager(GmmPageTableMngr *newPageTableManager) { diff --git a/runtime/os_interface/windows/wddm.h b/runtime/os_interface/windows/wddm.h index fdd5a04d8a..8f416d19e6 100644 --- a/runtime/os_interface/windows/wddm.h +++ b/runtime/os_interface/windows/wddm.h @@ -181,7 +181,7 @@ class Wddm { void resetPageTableManager(GmmPageTableMngr *newPageTableManager); void initPageTableManagerRegisters(LinearStream &stream); - bool updateAuxTable(GMM_DDI_UPDATEAUXTABLE &ddiUpdateAuxTable); + bool updateAuxTable(D3DGPU_VIRTUAL_ADDRESS gpuVa, Gmm *gmm, bool map); protected: bool initialized; diff --git a/runtime/os_interface/windows/wddm_memory_manager.cpp b/runtime/os_interface/windows/wddm_memory_manager.cpp index 0c0b3db2e3..265100c7ad 100644 --- a/runtime/os_interface/windows/wddm_memory_manager.cpp +++ b/runtime/os_interface/windows/wddm_memory_manager.cpp @@ -276,7 +276,7 @@ void WddmMemoryManager::freeGraphicsMemoryImpl(GraphicsAllocation *gfxAllocation if (input->gmm) { if (input->gmm->isRenderCompressed) { - auto status = unmapAuxVA(input->gmm, input->gpuPtr); + auto status = wddm->updateAuxTable(input->gpuPtr, input->gmm, false); DEBUG_BREAK_IF(!status); } delete input->gmm; @@ -744,12 +744,7 @@ bool WddmMemoryManager::trimResidencyToBudget(uint64_t bytes) { return numberOfBytesToTrim == 0; } -bool WddmMemoryManager::unmapAuxVA(Gmm *gmm, D3DGPU_VIRTUAL_ADDRESS &gpuVA) { - GMM_DDI_UPDATEAUXTABLE ddiUpdateAuxTable = {}; - ddiUpdateAuxTable.BaseGpuVA = gpuVA; - ddiUpdateAuxTable.BaseResInfo = gmm->gmmResourceInfo->peekHandle(); - ddiUpdateAuxTable.DoNotWait = true; - ddiUpdateAuxTable.Map = false; - return wddm->updateAuxTable(ddiUpdateAuxTable); +bool WddmMemoryManager::mapAuxGpuVA(GraphicsAllocation *graphicsAllocation) { + return wddm->updateAuxTable(graphicsAllocation->getGpuAddress(), graphicsAllocation->gmm, true); } } // namespace OCLRT diff --git a/runtime/os_interface/windows/wddm_memory_manager.h b/runtime/os_interface/windows/wddm_memory_manager.h index 0bd50e255a..cf786837d0 100644 --- a/runtime/os_interface/windows/wddm_memory_manager.h +++ b/runtime/os_interface/windows/wddm_memory_manager.h @@ -83,6 +83,8 @@ class WddmMemoryManager : public MemoryManager { bool isMemoryBudgetExhausted() const override { return memoryBudgetExhausted; } + bool mapAuxGpuVA(GraphicsAllocation *graphicsAllocation) override; + protected: GraphicsAllocation *createAllocationFromHandle(osHandle handle, bool requireSpecificBitness, bool ntHandle); WddmAllocation *getTrimCandidateHead() { @@ -111,7 +113,6 @@ class WddmMemoryManager : public MemoryManager { uint64_t lastPeriodicTrimFenceValue = 0; uint32_t trimCandidatesCount = 0; bool memoryBudgetExhausted = false; - bool unmapAuxVA(Gmm *gmm, D3DGPU_VIRTUAL_ADDRESS &gpuVA); private: Wddm *wddm; diff --git a/runtime/sharings/d3d/d3d_texture.cpp b/runtime/sharings/d3d/d3d_texture.cpp index 782a218805..286d4cca57 100644 --- a/runtime/sharings/d3d/d3d_texture.cpp +++ b/runtime/sharings/d3d/d3d_texture.cpp @@ -95,6 +95,10 @@ Image *D3DTexture::create2d(Context *context, D3DTexture2d *d3dTexture, cl_ imgInfo.surfaceFormat = findSurfaceFormatInfo(alloc->gmm->gmmResourceInfo->getResourceFormat(), flags); } + if (alloc->gmm->unifiedAuxTranslationCapable() && sharedResource) { + alloc->gmm->isRenderCompressed = context->getMemoryManager()->mapAuxGpuVA(alloc); + } + return Image::createSharedImage(context, d3dTextureObj, mcsSurfaceInfo, alloc, nullptr, flags, imgInfo, __GMM_NO_CUBE_MAP, 0); } diff --git a/unit_tests/d3d_sharing/d3d_tests.cpp b/unit_tests/d3d_sharing/d3d_tests.cpp index a6d95cd7ea..48e9f0b3ce 100644 --- a/unit_tests/d3d_sharing/d3d_tests.cpp +++ b/unit_tests/d3d_sharing/d3d_tests.cpp @@ -81,8 +81,14 @@ class D3DTests : public PlatformFixture, public ::testing::Test { gmmOwnershipPassed = true; return alloc; } + bool mapAuxGpuVA(GraphicsAllocation *graphicsAllocation) override { + mapAuxGpuVACalled++; + return mapAuxGpuVaRetValue; + } Gmm *forceGmm = nullptr; bool gmmOwnershipPassed = false; + uint32_t mapAuxGpuVACalled = 0u; + bool mapAuxGpuVaRetValue = true; }; void setupMockGmm() { @@ -1280,4 +1286,76 @@ REGISTER_TYPED_TEST_CASE_P(D3DTests, typedef ::testing::Types D3DTypes; INSTANTIATE_TYPED_TEST_CASE_P(D3DSharingTests, D3DTests, D3DTypes); + +template +class D3DAuxTests : public D3DTests {}; +TYPED_TEST_CASE_P(D3DAuxTests); + +TYPED_TEST_P(D3DAuxTests, given2dSharableTextureWithUnifiedAuxFlagsWhenCreatingThenMapAuxTableAndSetAsRenderCompressed) { + this->mockSharingFcns->mockTexture2dDesc.MiscFlags = D3DResourceFlags::MISC_SHARED; + this->mockSharingFcns->mockTexture2dDesc.ArraySize = 4; + this->mockSharingFcns->mockTexture2dDesc.MipLevels = 4; + + mockGmmResInfo->setUnifiedAuxTranslationCapable(); + EXPECT_CALL(*this->mockSharingFcns, getTexture2dDesc(_, _)).Times(1).WillOnce(SetArgPointee<0>(this->mockSharingFcns->mockTexture2dDesc)); + + auto image = std::unique_ptr(D3DTexture::create2d(this->context, (D3DTexture2d *)&this->dummyD3DTexture, CL_MEM_READ_WRITE, 4, nullptr)); + ASSERT_NE(nullptr, image.get()); + + EXPECT_EQ(1u, mockMM.mapAuxGpuVACalled); + EXPECT_TRUE(gmm->isRenderCompressed); +} + +TYPED_TEST_P(D3DAuxTests, given2dSharableTextureWithUnifiedAuxFlagsWhenFailOnAuxMappingThenDontSetAsRenderCompressed) { + this->mockSharingFcns->mockTexture2dDesc.MiscFlags = D3DResourceFlags::MISC_SHARED; + this->mockSharingFcns->mockTexture2dDesc.ArraySize = 4; + this->mockSharingFcns->mockTexture2dDesc.MipLevels = 4; + + mockGmmResInfo->setUnifiedAuxTranslationCapable(); + EXPECT_CALL(*this->mockSharingFcns, getTexture2dDesc(_, _)).Times(1).WillOnce(SetArgPointee<0>(this->mockSharingFcns->mockTexture2dDesc)); + + mockMM.mapAuxGpuVaRetValue = false; + auto image = std::unique_ptr(D3DTexture::create2d(this->context, (D3DTexture2d *)&this->dummyD3DTexture, CL_MEM_READ_WRITE, 4, nullptr)); + ASSERT_NE(nullptr, image.get()); + + EXPECT_EQ(1u, mockMM.mapAuxGpuVACalled); + EXPECT_FALSE(gmm->isRenderCompressed); +} + +TYPED_TEST_P(D3DAuxTests, given2dSharableTextureWithoutUnifiedAuxFlagsWhenCreatingThenDontMapAuxTable) { + this->mockSharingFcns->mockTexture2dDesc.MiscFlags = D3DResourceFlags::MISC_SHARED; + this->mockSharingFcns->mockTexture2dDesc.ArraySize = 4; + this->mockSharingFcns->mockTexture2dDesc.MipLevels = 4; + + EXPECT_FALSE(gmm->unifiedAuxTranslationCapable()); + + EXPECT_CALL(*this->mockSharingFcns, getTexture2dDesc(_, _)).Times(1).WillOnce(SetArgPointee<0>(this->mockSharingFcns->mockTexture2dDesc)); + + auto image = std::unique_ptr(D3DTexture::create2d(this->context, (D3DTexture2d *)&this->dummyD3DTexture, CL_MEM_READ_WRITE, 4, nullptr)); + ASSERT_NE(nullptr, image.get()); + + EXPECT_EQ(0u, mockMM.mapAuxGpuVACalled); + EXPECT_FALSE(gmm->isRenderCompressed); +} + +TYPED_TEST_P(D3DAuxTests, given2dNonSharableTextureWithUnifiedAuxFlagsWhenCreatingThenDontMapAuxTable) { + mockGmmResInfo->setUnifiedAuxTranslationCapable(); + EXPECT_CALL(*this->mockSharingFcns, getTexture2dDesc(_, _)).Times(1).WillOnce(SetArgPointee<0>(this->mockSharingFcns->mockTexture2dDesc)); + + mockGmmResInfo->setUnifiedAuxTranslationCapable(); + auto image = std::unique_ptr(D3DTexture::create2d(this->context, (D3DTexture2d *)&this->dummyD3DTexture, CL_MEM_READ_WRITE, 1, nullptr)); + ASSERT_NE(nullptr, image.get()); + + EXPECT_EQ(0u, mockMM.mapAuxGpuVACalled); + EXPECT_FALSE(gmm->isRenderCompressed); +} + +REGISTER_TYPED_TEST_CASE_P(D3DAuxTests, + given2dSharableTextureWithUnifiedAuxFlagsWhenCreatingThenMapAuxTableAndSetAsRenderCompressed, + given2dSharableTextureWithUnifiedAuxFlagsWhenFailOnAuxMappingThenDontSetAsRenderCompressed, + given2dSharableTextureWithoutUnifiedAuxFlagsWhenCreatingThenDontMapAuxTable, + given2dNonSharableTextureWithUnifiedAuxFlagsWhenCreatingThenDontMapAuxTable); + +INSTANTIATE_TYPED_TEST_CASE_P(D3DSharingTests, D3DAuxTests, D3DTypes); + } // namespace OCLRT diff --git a/unit_tests/gmm_helper/gmm_helper_tests.cpp b/unit_tests/gmm_helper/gmm_helper_tests.cpp index 193b1a17cb..23a5c90980 100644 --- a/unit_tests/gmm_helper/gmm_helper_tests.cpp +++ b/unit_tests/gmm_helper/gmm_helper_tests.cpp @@ -561,6 +561,36 @@ TEST_F(GmmTests, copyResourceBlt) { EXPECT_TRUE(memcmp(&expectedCpuBlt, &requestedCpuBlt, sizeof(GMM_RES_COPY_BLT)) == 0); } +TEST(GmmTest, givenAllValidFlagsWhenAskedForUnifiedAuxTranslationCapabilityThenReturnTrue) { + auto gmm = std::unique_ptr(Gmm::create(nullptr, 1, false)); + auto mockResource = reinterpret_cast(gmm->gmmResourceInfo.get()); + + mockResource->setUnifiedAuxTranslationCapable(); + EXPECT_EQ(1u, mockResource->mockResourceCreateParams.Flags.Gpu.CCS); + EXPECT_EQ(1u, mockResource->mockResourceCreateParams.Flags.Gpu.UnifiedAuxSurface); + EXPECT_EQ(1u, mockResource->mockResourceCreateParams.Flags.Info.RenderCompressed); + + EXPECT_TRUE(gmm->unifiedAuxTranslationCapable()); +} + +TEST(GmmTest, givenInvalidFlagsSetWhenAskedForUnifiedAuxTranslationCapabilityThenReturnFalse) { + auto gmm = std::unique_ptr(Gmm::create(nullptr, 1, false)); + auto mockResource = reinterpret_cast(gmm->gmmResourceInfo.get()); + + mockResource->mockResourceCreateParams.Flags.Gpu.CCS = 0; + mockResource->mockResourceCreateParams.Flags.Gpu.UnifiedAuxSurface = 1; + mockResource->mockResourceCreateParams.Flags.Info.RenderCompressed = 1; + EXPECT_FALSE(gmm->unifiedAuxTranslationCapable()); // CCS == 0 + + mockResource->mockResourceCreateParams.Flags.Gpu.CCS = 1; + mockResource->mockResourceCreateParams.Flags.Gpu.UnifiedAuxSurface = 0; + EXPECT_FALSE(gmm->unifiedAuxTranslationCapable()); // UnifiedAuxSurface == 0 + + mockResource->mockResourceCreateParams.Flags.Gpu.UnifiedAuxSurface = 1; + mockResource->mockResourceCreateParams.Flags.Info.RenderCompressed = 0; + EXPECT_FALSE(gmm->unifiedAuxTranslationCapable()); // RenderCompressed == 0 +} + TEST(GmmSimplifiedCacheSelectionPolicy, givenGmmInSimplifiedCacheSelectionPolicyWhenItIsAskedForUncachedIndexThen0IsReturned) { Gmm::useSimplifiedMocsTable = true; auto index = Gmm::getMOCS(GMM_RESOURCE_USAGE_OCL_BUFFER_CACHELINE_MISALIGNED); diff --git a/unit_tests/mem_obj/image_set_arg_tests.cpp b/unit_tests/mem_obj/image_set_arg_tests.cpp index 3fb7d16edf..9dece18ec7 100644 --- a/unit_tests/mem_obj/image_set_arg_tests.cpp +++ b/unit_tests/mem_obj/image_set_arg_tests.cpp @@ -405,7 +405,7 @@ HWTEST_F(ImageSetArgTest, clSetKernelArgImage1Darray) { delete image1Darray; } -HWTEST_F(ImageSetArgTest, givenMcsAllocationWithoutCcsWhenSetArgIsCalledThenProgramAuxFieldsForMultisamples) { +HWTEST_F(ImageSetArgTest, givenMcsAllocationWhenSetArgIsCalledWithoutUnifiedAuxCapabilityThenProgramAuxFieldsForMultisamples) { typedef typename FamilyType::RENDER_SURFACE_STATE RENDER_SURFACE_STATE; McsSurfaceInfo msi = {10, 20, 3}; auto mcsAlloc = context->getMemoryManager()->allocateGraphicsMemory(4096); @@ -418,9 +418,7 @@ HWTEST_F(ImageSetArgTest, givenMcsAllocationWithoutCcsWhenSetArgIsCalledThenProg image->setMcsAllocation(mcsAlloc); cl_mem memObj = image; - auto mockMcsGmmResInfo = reinterpret_cast *>(mcsAlloc->gmm->gmmResourceInfo.get()); - EXPECT_EQ(0u, mockMcsGmmResInfo->getResourceFlags()->Gpu.CCS); - EXPECT_EQ(0u, mockMcsGmmResInfo->getResourceFlags()->Gpu.UnifiedAuxSurface); + EXPECT_FALSE(mcsAlloc->gmm->unifiedAuxTranslationCapable()); retVal = clSetKernelArg( pKernel, @@ -536,7 +534,7 @@ HWTEST_F(ImageSetArgTest, givenDepthFormatAndRenderCompressionWhenSetArgOnMultis EXPECT_EQ(0u, surfaceState->getAuxiliarySurfaceBaseAddress()); } -HWTEST_F(ImageSetArgTest, givenMcsAllocationWithCcsAndUnifiedAuxWhenSetArgIsCalledThenProgramAuxFieldsForCcs) { +HWTEST_F(ImageSetArgTest, givenMcsAllocationWhenSetArgIsCalledWithUnifiedAuxCapabilityThenProgramAuxFieldsForCcs) { typedef typename FamilyType::RENDER_SURFACE_STATE RENDER_SURFACE_STATE; McsSurfaceInfo msi = {10, 20, 3}; auto mcsAlloc = context->getMemoryManager()->allocateGraphicsMemory(4096); @@ -554,10 +552,8 @@ HWTEST_F(ImageSetArgTest, givenMcsAllocationWithCcsAndUnifiedAuxWhenSetArgIsCall uint64_t expectedAuxSurfaceOffset = 0x10000; auto mockMcsGmmResInfo = reinterpret_cast *>(mcsAlloc->gmm->gmmResourceInfo.get()); - mockMcsGmmResInfo->mockResourceCreateParams.Flags.Gpu.CCS = 1; - mockMcsGmmResInfo->mockResourceCreateParams.Flags.Gpu.UnifiedAuxSurface = 1; - EXPECT_EQ(1u, mockMcsGmmResInfo->getResourceFlags()->Gpu.CCS); - EXPECT_EQ(1u, mockMcsGmmResInfo->getResourceFlags()->Gpu.UnifiedAuxSurface); + mockMcsGmmResInfo->setUnifiedAuxTranslationCapable(); + EXPECT_TRUE(mcsAlloc->gmm->unifiedAuxTranslationCapable()); EXPECT_CALL(*mockMcsGmmResInfo, getRenderAuxPitchTiles()).Times(1).WillOnce(Return(expectedRenderAuxPitchTiles)); EXPECT_CALL(*mockMcsGmmResInfo, getAuxQPitch()).Times(1).WillOnce(Return(expectedAuxQPitch)); EXPECT_CALL(*mockMcsGmmResInfo, getUnifiedAuxSurfaceOffset(GMM_UNIFIED_AUX_TYPE::GMM_AUX_CCS)).Times(1).WillOnce(Return(expectedAuxSurfaceOffset)); @@ -574,40 +570,6 @@ HWTEST_F(ImageSetArgTest, givenMcsAllocationWithCcsAndUnifiedAuxWhenSetArgIsCall EXPECT_EQ(surfaceState->getSurfaceBaseAddress() + expectedAuxSurfaceOffset, surfaceState->getAuxiliarySurfaceBaseAddress()); } -HWTEST_F(ImageSetArgTest, givenMcsAllocationWithCcsAndWithoutUnifiedAuxWhenSetArgIsCalledThenProgramAuxFieldsForCcs) { - typedef typename FamilyType::RENDER_SURFACE_STATE RENDER_SURFACE_STATE; - McsSurfaceInfo msi = {10, 20, 3}; - auto mcsAlloc = context->getMemoryManager()->allocateGraphicsMemory(4096); - mcsAlloc->gmm = Gmm::create(nullptr, 1, false); - cl_image_desc imgDesc = Image2dDefaults::imageDesc; - imgDesc.num_samples = 8; - - auto image = std::unique_ptr(Image2dHelper<>::create(context, &imgDesc)); - image->setMcsSurfaceInfo(msi); - image->setMcsAllocation(mcsAlloc); - cl_mem memObj = image.get(); - - auto mockMcsGmmResInfo = reinterpret_cast *>(mcsAlloc->gmm->gmmResourceInfo.get()); - mockMcsGmmResInfo->mockResourceCreateParams.Flags.Gpu.CCS = 1; - mockMcsGmmResInfo->mockResourceCreateParams.Flags.Gpu.UnifiedAuxSurface = 0; - EXPECT_EQ(1u, mockMcsGmmResInfo->getResourceFlags()->Gpu.CCS); - EXPECT_EQ(0u, mockMcsGmmResInfo->getResourceFlags()->Gpu.UnifiedAuxSurface); - - retVal = clSetKernelArg(pKernel, 0, sizeof(memObj), &memObj); - ASSERT_EQ(CL_SUCCESS, retVal); - - auto surfaceState = reinterpret_cast(ptrOffset(pKernel->getSurfaceStateHeap(), - pKernelInfo->kernelArgInfo[0].offsetHeap)); - - EXPECT_TRUE(surfaceState->getMultisampledSurfaceStorageFormat() == - RENDER_SURFACE_STATE::MULTISAMPLED_SURFACE_STORAGE_FORMAT::MULTISAMPLED_SURFACE_STORAGE_FORMAT_MSS); - EXPECT_TRUE(surfaceState->getAuxiliarySurfaceMode() == (typename RENDER_SURFACE_STATE::AUXILIARY_SURFACE_MODE)1); - EXPECT_EQ(msi.pitch, surfaceState->getAuxiliarySurfacePitch()); - EXPECT_EQ(msi.qPitch, surfaceState->getAuxiliarySurfaceQpitch()); - EXPECT_EQ(msi.multisampleCount, static_cast(surfaceState->getNumberOfMultisamples())); - EXPECT_EQ(mcsAlloc->getGpuAddress(), surfaceState->getAuxiliarySurfaceBaseAddress()); -} - HWTEST_F(ImageSetArgTest, clSetKernelArgImage1Dbuffer) { typedef typename FamilyType::RENDER_SURFACE_STATE RENDER_SURFACE_STATE; diff --git a/unit_tests/memory_manager/memory_manager_tests.cpp b/unit_tests/memory_manager/memory_manager_tests.cpp index 608cc213ab..730156b092 100644 --- a/unit_tests/memory_manager/memory_manager_tests.cpp +++ b/unit_tests/memory_manager/memory_manager_tests.cpp @@ -735,6 +735,21 @@ TEST(OsAgnosticMemoryManager, givenDefaultMemoryManagerWhenAllocateGraphicsMemor memoryManager.freeGraphicsMemory(imageAllocation); } +TEST(OsAgnosticMemoryManager, givenDefaultMemoryManagerAndUnifiedAuxCapableAllocationWhenMappingThenReturnFalse) { + OsAgnosticMemoryManager memoryManager; + + auto gmm = Gmm::create(nullptr, 123, false); + auto allocation = memoryManager.allocateGraphicsMemory(123); + allocation->gmm = gmm; + + auto mockGmmRes = reinterpret_cast(gmm->gmmResourceInfo.get()); + mockGmmRes->setUnifiedAuxTranslationCapable(); + + EXPECT_FALSE(memoryManager.mapAuxGpuVA(allocation)); + + memoryManager.freeGraphicsMemory(allocation); +} + TEST(OsAgnosticMemoryManager, givenMemoryManagerWith64KBPagesDisabledWhenAllocateGraphicsMemoryForSVMIsCalledThen4KBGraphicsAllocationIsReturned) { OsAgnosticMemoryManager memoryManager(false); auto size = 4096u; diff --git a/unit_tests/mocks/mock_gmm_resource_info.cpp b/unit_tests/mocks/mock_gmm_resource_info.cpp index 964e42061c..45d8f91528 100644 --- a/unit_tests/mocks/mock_gmm_resource_info.cpp +++ b/unit_tests/mocks/mock_gmm_resource_info.cpp @@ -112,6 +112,12 @@ uint32_t MockGmmResourceInfo::getBitsPerPixel() { return (surfaceFormatInfo->PerChannelSizeInBytes << 3) * surfaceFormatInfo->NumChannels; } +void MockGmmResourceInfo::setUnifiedAuxTranslationCapable() { + mockResourceCreateParams.Flags.Gpu.CCS = 1; + mockResourceCreateParams.Flags.Gpu.UnifiedAuxSurface = 1; + mockResourceCreateParams.Flags.Info.RenderCompressed = 1; +} + MockGmmResourceInfo::MockGmmResourceInfo() {} MockGmmResourceInfo::~MockGmmResourceInfo() {} } // namespace OCLRT diff --git a/unit_tests/mocks/mock_gmm_resource_info.h b/unit_tests/mocks/mock_gmm_resource_info.h index 3ededd2321..b070c48a08 100644 --- a/unit_tests/mocks/mock_gmm_resource_info.h +++ b/unit_tests/mocks/mock_gmm_resource_info.h @@ -91,6 +91,8 @@ class MockGmmResourceInfo : public GmmResourceInfo { void overrideReturnedRenderPitch(size_t newPitch) { rowPitch = newPitch; } + void setUnifiedAuxTranslationCapable(); + protected: MockGmmResourceInfo(); 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 3f85909669..5c85811b18 100644 --- a/unit_tests/os_interface/linux/drm_memory_manager_tests.cpp +++ b/unit_tests/os_interface/linux/drm_memory_manager_tests.cpp @@ -1361,6 +1361,20 @@ TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenLockUnlockCalledThenDoNoth memoryManager->freeGraphicsMemory(allocation); } +TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerAndUnifiedAuxCapableAllocationWhenMappingThenReturnFalse) { + mock->ioctl_expected = 3; + auto gmm = Gmm::create(nullptr, 123, false); + auto allocation = memoryManager->allocateGraphicsMemory(123, 123); + allocation->gmm = gmm; + + auto mockGmmRes = reinterpret_cast(gmm->gmmResourceInfo.get()); + mockGmmRes->setUnifiedAuxTranslationCapable(); + + EXPECT_FALSE(memoryManager->mapAuxGpuVA(allocation)); + + memoryManager->freeGraphicsMemory(allocation); +} + TEST_F(DrmMemoryManagerTest, given32BitAllocatorWithHeapAllocatorWhenLargerFragmentIsReusedThenOnlyUnmapSizeIsLargerWhileSizeStaysTheSame) { DebugManagerStateRestore dbgFlagsKeeper; //USERPTR + WAIT + CLOSE 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 3d08fce573..2e6eecef53 100644 --- a/unit_tests/os_interface/windows/wddm_memory_manager_tests.cpp +++ b/unit_tests/os_interface/windows/wddm_memory_manager_tests.cpp @@ -1654,6 +1654,31 @@ TEST_F(MockWddmMemoryManagerTest, givenDisabledAsyncDeleterFlagWhenMemoryManager DebugManager.flags.EnableDeferredDeleter.set(defaultEnableDeferredDeleterFlag); } +HWTEST_F(MockWddmMemoryManagerTest, givenPageTableManagerWhenMapAuxGpuVaCalledThenUseWddmToMap) { + auto myWddm = new WddmMock(); + EXPECT_TRUE(myWddm->init()); + WddmMemoryManager memoryManager(false, myWddm); + + auto mockMngr = new NiceMock(); + myWddm->resetPageTableManager(mockMngr); + + auto allocation = memoryManager.allocateGraphicsMemory(4096); + + GMM_DDI_UPDATEAUXTABLE givenDdiUpdateAuxTable = {}; + GMM_DDI_UPDATEAUXTABLE expectedDdiUpdateAuxTable = {}; + expectedDdiUpdateAuxTable.BaseGpuVA = allocation->getGpuAddress(); + expectedDdiUpdateAuxTable.BaseResInfo = allocation->gmm->gmmResourceInfo->peekHandle(); + expectedDdiUpdateAuxTable.DoNotWait = true; + expectedDdiUpdateAuxTable.Map = true; + + EXPECT_CALL(*mockMngr, updateAuxTable(_)).Times(1).WillOnce(Invoke([&](const GMM_DDI_UPDATEAUXTABLE *arg) {givenDdiUpdateAuxTable = *arg; return GMM_SUCCESS; })); + + auto result = memoryManager.mapAuxGpuVA(allocation); + EXPECT_TRUE(result); + EXPECT_TRUE(memcmp(&expectedDdiUpdateAuxTable, &givenDdiUpdateAuxTable, sizeof(GMM_DDI_UPDATEAUXTABLE)) == 0); + memoryManager.freeGraphicsMemory(allocation); +} + HWTEST_F(MockWddmMemoryManagerTest, givenRenderCompressedAllocationWhenMappedGpuVaThenMapAuxVa) { std::unique_ptr gmm(Gmm::create((void *)123, 4096u, false)); gmm->isRenderCompressed = true; diff --git a/unit_tests/os_interface/windows/wddm_tests.cpp b/unit_tests/os_interface/windows/wddm_tests.cpp index 3023179d22..fc96d8d8d1 100644 --- a/unit_tests/os_interface/windows/wddm_tests.cpp +++ b/unit_tests/os_interface/windows/wddm_tests.cpp @@ -60,6 +60,19 @@ HWTEST_F(WddmTest, doubleCreation) { delete wddmMock; } +TEST_F(WddmTest, givenNullPageTableManagerWhenUpdateAuxTableCalledThenReturnFalse) { + auto wddmMock = std::make_unique(); + + wddmMock->resetPageTableManager(nullptr); + EXPECT_EQ(nullptr, wddmMock->getPageTableManager()); + + auto gmm = std::unique_ptr(Gmm::create(nullptr, 1, false)); + auto mockGmmRes = reinterpret_cast(gmm->gmmResourceInfo.get()); + mockGmmRes->setUnifiedAuxTranslationCapable(); + + EXPECT_FALSE(wddmMock->updateAuxTable(1234u, gmm.get(), true)); +} + TEST(WddmTestEnumAdapters, expectTrue) { ADAPTER_INFO adpaterInfo; const HardwareInfo hwInfo = *platformDevices[0];