diff --git a/runtime/mem_obj/image.inl b/runtime/mem_obj/image.inl index e138a8f78a..36e3e74fb3 100644 --- a/runtime/mem_obj/image.inl +++ b/runtime/mem_obj/image.inl @@ -186,9 +186,7 @@ void ImageHw::setAuxSurfaceStateParams(RENDER_SURFACE_STATE *surfaceS } else if (isDepthFormat(imageFormat)) { surfaceState->setMultisampledSurfaceStorageFormat(RENDER_SURFACE_STATE::MULTISAMPLED_SURFACE_STORAGE_FORMAT::MULTISAMPLED_SURFACE_STORAGE_FORMAT_DEPTH_STENCIL); } - } - - if (gmm && gmm->isRenderCompressed) { + } else if (gmm && gmm->isRenderCompressed) { surfaceState->setAuxiliarySurfaceMode((typename RENDER_SURFACE_STATE::AUXILIARY_SURFACE_MODE)5); surfaceState->setAuxiliarySurfacePitch(std::max(gmm->gmmResourceInfo->getRenderAuxPitchTiles(), 1u)); surfaceState->setAuxiliarySurfaceQpitch(gmm->gmmResourceInfo->getAuxQPitch()); diff --git a/unit_tests/mem_obj/image_set_arg_tests.cpp b/unit_tests/mem_obj/image_set_arg_tests.cpp index 7e3ea50872..ac5da35e7c 100644 --- a/unit_tests/mem_obj/image_set_arg_tests.cpp +++ b/unit_tests/mem_obj/image_set_arg_tests.cpp @@ -474,6 +474,62 @@ HWTEST_F(ImageSetArgTest, givenDepthFormatWhenSetArgIsCalledThenProgramAuxFields delete image; } +HWTEST_F(ImageSetArgTest, givenMcsAllocationAndRenderCompressionWhenSetArgOnMultisampledImgIsCalledThenProgramAuxFieldsWithMcsParams) { + typedef typename FamilyType::RENDER_SURFACE_STATE RENDER_SURFACE_STATE; + McsSurfaceInfo msi = {10, 20, 3}; + auto mcsAlloc = context->getMemoryManager()->allocateGraphicsMemory(4096); + cl_image_desc imgDesc = Image2dDefaults::imageDesc; + imgDesc.num_samples = 8; + + auto image = std::unique_ptr(Image2dHelper<>::create(context, &imgDesc)); + image->getGraphicsAllocation()->gmm->isRenderCompressed = true; + image->setMcsSurfaceInfo(msi); + image->setMcsAllocation(mcsAlloc); + cl_mem memObj = image.get(); + + 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, givenDepthFormatAndRenderCompressionWhenSetArgOnMultisampledImgIsCalledThenDontProgramAuxFields) { + typedef typename FamilyType::RENDER_SURFACE_STATE RENDER_SURFACE_STATE; + McsSurfaceInfo msi = {0, 0, 3}; + cl_image_desc imgDesc = Image2dDefaults::imageDesc; + cl_image_format imgFormat = {CL_DEPTH, CL_FLOAT}; + imgDesc.num_samples = 8; + + auto image = std::unique_ptr(Image2dHelper<>::create(context, &imgDesc, &imgFormat)); + image->getGraphicsAllocation()->gmm->isRenderCompressed = true; + image->setMcsSurfaceInfo(msi); + cl_mem memObj = image.get(); + + 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(Image::isDepthFormat(image->getImageFormat())); + EXPECT_TRUE(surfaceState->getMultisampledSurfaceStorageFormat() == + RENDER_SURFACE_STATE::MULTISAMPLED_SURFACE_STORAGE_FORMAT::MULTISAMPLED_SURFACE_STORAGE_FORMAT_DEPTH_STENCIL); + EXPECT_TRUE(surfaceState->getAuxiliarySurfaceMode() == (typename RENDER_SURFACE_STATE::AUXILIARY_SURFACE_MODE)0); + EXPECT_EQ(1u, surfaceState->getAuxiliarySurfacePitch()); + EXPECT_EQ(0u, surfaceState->getAuxiliarySurfaceQpitch()); + EXPECT_EQ(msi.multisampleCount, static_cast(surfaceState->getNumberOfMultisamples())); + EXPECT_EQ(0u, surfaceState->getAuxiliarySurfaceBaseAddress()); +} + HWTEST_F(ImageSetArgTest, clSetKernelArgImage1Dbuffer) { typedef typename FamilyType::RENDER_SURFACE_STATE RENDER_SURFACE_STATE; diff --git a/unit_tests/mocks/mock_gmm_page_table_mngr.cpp b/unit_tests/mocks/mock_gmm_page_table_mngr.cpp index bc481ee893..3e503a7fea 100644 --- a/unit_tests/mocks/mock_gmm_page_table_mngr.cpp +++ b/unit_tests/mocks/mock_gmm_page_table_mngr.cpp @@ -25,7 +25,13 @@ #include "unit_tests/mocks/mock_gmm_page_table_mngr.h" namespace OCLRT { +using namespace ::testing; + GmmPageTableMngr *GmmPageTableMngr::create(GMM_DEVICE_CALLBACKS *deviceCb, unsigned int translationTableFlags, GMM_TRANSLATIONTABLE_CALLBACKS *translationTableCb) { - return new ::testing::NiceMock(deviceCb, translationTableFlags, translationTableCb); + auto pageTableMngr = new ::testing::NiceMock(deviceCb, translationTableFlags, translationTableCb); + ON_CALL(*pageTableMngr, initContextAuxTableRegister(_, _)).WillByDefault(Return(GMM_SUCCESS)); + ON_CALL(*pageTableMngr, initContextTRTableRegister(_, _)).WillByDefault(Return(GMM_SUCCESS)); + ON_CALL(*pageTableMngr, updateAuxTable(_)).WillByDefault(Return(GMM_SUCCESS)); + return pageTableMngr; } } // namespace OCLRT diff --git a/unit_tests/os_interface/windows/device_command_stream_tests.cpp b/unit_tests/os_interface/windows/device_command_stream_tests.cpp index dd82f0da78..c13eb79f3b 100644 --- a/unit_tests/os_interface/windows/device_command_stream_tests.cpp +++ b/unit_tests/os_interface/windows/device_command_stream_tests.cpp @@ -519,36 +519,43 @@ struct WddmCsrCompressionTests : WddmCommandStreamMockGdiTest { setCompressionEnabled(true); } + void createMockWddm() { + myMockWddm.reset(static_cast(Wddm::createWddm())); + } + HardwareInfo hwInfo = {}; + std::unique_ptr myMockWddm; }; HWTEST_F(WddmCsrCompressionTests, givenEnabledCompressionWhenInitializedThenCreatePagetableMngr) { - EXPECT_EQ(nullptr, mockWddm->getPageTableManager()); - MockWddmCsr mockWddmCsr(hwInfo, mockWddm); - ASSERT_NE(nullptr, mockWddm->getPageTableManager()); + createMockWddm(); + EXPECT_EQ(nullptr, myMockWddm->getPageTableManager()); + MockWddmCsr mockWddmCsr(hwInfo, myMockWddm.get()); + ASSERT_NE(nullptr, myMockWddm->getPageTableManager()); - auto mockMngr = reinterpret_cast(mockWddm->getPageTableManager()); + auto mockMngr = reinterpret_cast(myMockWddm->getPageTableManager()); GMM_DEVICE_CALLBACKS expectedDeviceCb = {}; GMM_TRANSLATIONTABLE_CALLBACKS expectedTTCallbacks = {}; unsigned int expectedFlags = (TT_TYPE::TRTT | TT_TYPE::AUXTT); + auto myGdi = myMockWddm->getGdi(); // clang-format off - expectedDeviceCb.Adapter = mockWddm->getAdapter(); - expectedDeviceCb.hDevice = mockWddm->getDevice(); - expectedDeviceCb.PagingQueue = mockWddm->getPagingQueue(); - expectedDeviceCb.PagingFence = mockWddm->getPagingQueueSyncObject(); + expectedDeviceCb.Adapter = myMockWddm->getAdapter(); + expectedDeviceCb.hDevice = myMockWddm->getDevice(); + expectedDeviceCb.PagingQueue = myMockWddm->getPagingQueue(); + expectedDeviceCb.PagingFence = myMockWddm->getPagingQueueSyncObject(); - expectedDeviceCb.pfnAllocate = gdi.createAllocation; - expectedDeviceCb.pfnDeallocate = gdi.destroyAllocation; - expectedDeviceCb.pfnMapGPUVA = gdi.mapGpuVirtualAddress; - expectedDeviceCb.pfnMakeResident = gdi.makeResident; - expectedDeviceCb.pfnEvict = gdi.evict; - expectedDeviceCb.pfnReserveGPUVA = gdi.reserveGpuVirtualAddress; - expectedDeviceCb.pfnUpdateGPUVA = gdi.updateGpuVirtualAddress; - expectedDeviceCb.pfnWaitFromCpu = gdi.waitForSynchronizationObjectFromCpu; - expectedDeviceCb.pfnLock = gdi.lock2; - expectedDeviceCb.pfnUnLock = gdi.unlock2; - expectedDeviceCb.pfnEscape = gdi.escape; + expectedDeviceCb.pfnAllocate = myGdi->createAllocation; + expectedDeviceCb.pfnDeallocate = myGdi->destroyAllocation; + expectedDeviceCb.pfnMapGPUVA = myGdi->mapGpuVirtualAddress; + expectedDeviceCb.pfnMakeResident = myGdi->makeResident; + expectedDeviceCb.pfnEvict = myGdi->evict; + expectedDeviceCb.pfnReserveGPUVA = myGdi->reserveGpuVirtualAddress; + expectedDeviceCb.pfnUpdateGPUVA = myGdi->updateGpuVirtualAddress; + expectedDeviceCb.pfnWaitFromCpu = myGdi->waitForSynchronizationObjectFromCpu; + expectedDeviceCb.pfnLock = myGdi->lock2; + expectedDeviceCb.pfnUnLock = myGdi->unlock2; + expectedDeviceCb.pfnEscape = myGdi->escape; expectedTTCallbacks.pfWriteL3Adr = TTCallbacks::writeL3Address; // clang-format on @@ -560,15 +567,17 @@ HWTEST_F(WddmCsrCompressionTests, givenEnabledCompressionWhenInitializedThenCrea HWTEST_F(WddmCsrCompressionTests, givenDisabledCompressionWhenInitializedThenDontCreatePagetableMngr) { setCompressionEnabled(false); - MockWddmCsr mockWddmCsr(hwInfo, mockWddm); - EXPECT_EQ(nullptr, mockWddm->getPageTableManager()); + createMockWddm(); + MockWddmCsr mockWddmCsr(hwInfo, myMockWddm.get()); + EXPECT_EQ(nullptr, myMockWddm->getPageTableManager()); } HWTEST_F(WddmCsrCompressionTests, givenEnabledCompressionWhenFlushingThenInitTranslationTableOnce) { - MockWddmCsr mockWddmCsr(hwInfo, mockWddm); + createMockWddm(); + MockWddmCsr mockWddmCsr(hwInfo, myMockWddm.get()); mockWddmCsr.overrideDispatchPolicy(CommandStreamReceiver::DispatchMode::BatchedDispatch); - auto mockMngr = reinterpret_cast(mockWddm->getPageTableManager()); + auto mockMngr = reinterpret_cast(myMockWddm->getPageTableManager()); mockWddmCsr.setMemoryManager(mm); mockWddmCsr.setTagAllocation(tagAllocation); @@ -577,7 +586,7 @@ HWTEST_F(WddmCsrCompressionTests, givenEnabledCompressionWhenFlushingThenInitTra auto graphicsAllocation = mm->allocateGraphicsMemory(1024, 4096); LinearStream cs(graphicsAllocation); - EXPECT_FALSE(mockWddm->peekIsPageTableManagerInitialized()); + EXPECT_FALSE(myMockWddm->peekIsPageTableManagerInitialized()); EXPECT_CALL(*mockMngr, initContextAuxTableRegister(&csrCS, GMM_ENGINE_TYPE::ENGINE_TYPE_RCS)).Times(1).WillOnce(Return(GMM_SUCCESS)); EXPECT_CALL(*mockMngr, initContextTRTableRegister(&csrCS, GMM_ENGINE_TYPE::ENGINE_TYPE_RCS)).Times(1).WillOnce(Return(GMM_SUCCESS)); @@ -585,7 +594,7 @@ HWTEST_F(WddmCsrCompressionTests, givenEnabledCompressionWhenFlushingThenInitTra DispatchFlags dispatchFlags; mockWddmCsr.flushTask(cs, 0u, cs, cs, cs, cs, 0u, dispatchFlags); - EXPECT_TRUE(mockWddm->peekIsPageTableManagerInitialized()); + EXPECT_TRUE(myMockWddm->peekIsPageTableManagerInitialized()); // flush again to check if PT manager was initialized once mockWddmCsr.flushTask(cs, 0u, cs, cs, cs, cs, 0u, dispatchFlags); @@ -595,10 +604,11 @@ HWTEST_F(WddmCsrCompressionTests, givenEnabledCompressionWhenFlushingThenInitTra HWTEST_F(WddmCsrCompressionTests, givenDisabledCompressionWhenFlushingThenDontInitTranslationTable) { setCompressionEnabled(false); - MockWddmCsr mockWddmCsr(hwInfo, mockWddm); + createMockWddm(); + MockWddmCsr mockWddmCsr(hwInfo, myMockWddm.get()); mockWddmCsr.overrideDispatchPolicy(CommandStreamReceiver::DispatchMode::BatchedDispatch); - EXPECT_EQ(nullptr, mockWddm->getPageTableManager()); + EXPECT_EQ(nullptr, myMockWddm->getPageTableManager()); mockWddmCsr.setMemoryManager(mm); mockWddmCsr.setTagAllocation(tagAllocation); @@ -606,12 +616,12 @@ HWTEST_F(WddmCsrCompressionTests, givenDisabledCompressionWhenFlushingThenDontIn auto graphicsAllocation = mm->allocateGraphicsMemory(1024, 4096); LinearStream cs(graphicsAllocation); - EXPECT_FALSE(mockWddm->peekIsPageTableManagerInitialized()); + EXPECT_FALSE(myMockWddm->peekIsPageTableManagerInitialized()); DispatchFlags dispatchFlags; mockWddmCsr.flushTask(cs, 0u, cs, cs, cs, cs, 0u, dispatchFlags); - EXPECT_FALSE(mockWddm->peekIsPageTableManagerInitialized()); + EXPECT_FALSE(myMockWddm->peekIsPageTableManagerInitialized()); mm->freeGraphicsMemory(graphicsAllocation); } 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 fe9d37ff2a..3d08fce573 100644 --- a/unit_tests/os_interface/windows/wddm_memory_manager_tests.cpp +++ b/unit_tests/os_interface/windows/wddm_memory_manager_tests.cpp @@ -32,6 +32,17 @@ using namespace OCLRT; using namespace ::testing; +void WddmMemoryManagerFixture::SetUp() { + MemoryManagementFixture::SetUp(); + WddmFixture::SetUp(); + ASSERT_NE(nullptr, wddm); + if (platformDevices[0]->capabilityTable.ftrCompression) { + GMM_DEVICE_CALLBACKS dummyDeviceCallbacks = {}; + GMM_TRANSLATIONTABLE_CALLBACKS dummyTTCallbacks = {}; + wddm->resetPageTableManager(GmmPageTableMngr::create(&dummyDeviceCallbacks, 0, &dummyTTCallbacks)); + } +} + TEST(WddmMemoryManagerAllocator32BitTest, allocator32BitIsCreatedWithCorrectBase) { WddmMock *wddm = static_cast(Wddm::createWddm()); uint64_t base = 0x56000; diff --git a/unit_tests/os_interface/windows/wddm_memory_manager_tests.h b/unit_tests/os_interface/windows/wddm_memory_manager_tests.h index 48f1054e57..096d202bbf 100644 --- a/unit_tests/os_interface/windows/wddm_memory_manager_tests.h +++ b/unit_tests/os_interface/windows/wddm_memory_manager_tests.h @@ -41,11 +41,7 @@ class WddmMemoryManagerFixture : public MemoryManagementFixture, public WddmFixt public: WddmMemoryManager *mm = nullptr; - virtual void SetUp() { - MemoryManagementFixture::SetUp(); - WddmFixture::SetUp(); - ASSERT_NE(nullptr, wddm); - } + virtual void SetUp(); template void SetUpMm() {