D3D sharable 2D texture: Map Aux GpuVa and set renderCompressed if possible

Change-Id: I508965d07f456af74ecef6e980337f42f5967b43
This commit is contained in:
Dunajski, Bartosz 2018-01-25 15:10:07 +01:00 committed by sys_ocldev
parent 4ad96b75f5
commit 3532c6373f
18 changed files with 220 additions and 64 deletions

View File

@ -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

View File

@ -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);

View File

@ -178,9 +178,8 @@ template <typename GfxFamily>
void ImageHw<GfxFamily>::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);

View File

@ -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;

View File

@ -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) {
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) {

View File

@ -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;

View File

@ -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

View File

@ -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;

View File

@ -95,6 +95,10 @@ Image *D3DTexture<D3D>::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);
}

View File

@ -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<D3DTypesHelper::D3D10, D3DTypesHelper::D3D11> D3DTypes;
INSTANTIATE_TYPED_TEST_CASE_P(D3DSharingTests, D3DTests, D3DTypes);
template <typename T>
class D3DAuxTests : public D3DTests<T> {};
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<Image>(D3DTexture<TypeParam>::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<Image>(D3DTexture<TypeParam>::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<Image>(D3DTexture<TypeParam>::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<Image>(D3DTexture<TypeParam>::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

View File

@ -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>(Gmm::create(nullptr, 1, false));
auto mockResource = reinterpret_cast<MockGmmResourceInfo *>(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>(Gmm::create(nullptr, 1, false));
auto mockResource = reinterpret_cast<MockGmmResourceInfo *>(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);

View File

@ -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<NiceMock<MockGmmResourceInfo> *>(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<NiceMock<MockGmmResourceInfo> *>(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<Image>(Image2dHelper<>::create(context, &imgDesc));
image->setMcsSurfaceInfo(msi);
image->setMcsAllocation(mcsAlloc);
cl_mem memObj = image.get();
auto mockMcsGmmResInfo = reinterpret_cast<NiceMock<MockGmmResourceInfo> *>(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<const RENDER_SURFACE_STATE *>(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<uint32_t>(surfaceState->getNumberOfMultisamples()));
EXPECT_EQ(mcsAlloc->getGpuAddress(), surfaceState->getAuxiliarySurfaceBaseAddress());
}
HWTEST_F(ImageSetArgTest, clSetKernelArgImage1Dbuffer) {
typedef typename FamilyType::RENDER_SURFACE_STATE RENDER_SURFACE_STATE;

View File

@ -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<MockGmmResourceInfo *>(gmm->gmmResourceInfo.get());
mockGmmRes->setUnifiedAuxTranslationCapable();
EXPECT_FALSE(memoryManager.mapAuxGpuVA(allocation));
memoryManager.freeGraphicsMemory(allocation);
}
TEST(OsAgnosticMemoryManager, givenMemoryManagerWith64KBPagesDisabledWhenAllocateGraphicsMemoryForSVMIsCalledThen4KBGraphicsAllocationIsReturned) {
OsAgnosticMemoryManager memoryManager(false);
auto size = 4096u;

View File

@ -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

View File

@ -91,6 +91,8 @@ class MockGmmResourceInfo : public GmmResourceInfo {
void overrideReturnedRenderPitch(size_t newPitch) { rowPitch = newPitch; }
void setUnifiedAuxTranslationCapable();
protected:
MockGmmResourceInfo();

View File

@ -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<MockGmmResourceInfo *>(gmm->gmmResourceInfo.get());
mockGmmRes->setUnifiedAuxTranslationCapable();
EXPECT_FALSE(memoryManager->mapAuxGpuVA(allocation));
memoryManager->freeGraphicsMemory(allocation);
}
TEST_F(DrmMemoryManagerTest, given32BitAllocatorWithHeapAllocatorWhenLargerFragmentIsReusedThenOnlyUnmapSizeIsLargerWhileSizeStaysTheSame) {
DebugManagerStateRestore dbgFlagsKeeper;
//USERPTR + WAIT + CLOSE

View File

@ -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<FamilyType>());
WddmMemoryManager memoryManager(false, myWddm);
auto mockMngr = new NiceMock<MockGmmPageTableMngr>();
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(Gmm::create((void *)123, 4096u, false));
gmm->isRenderCompressed = true;

View File

@ -60,6 +60,19 @@ HWTEST_F(WddmTest, doubleCreation) {
delete wddmMock;
}
TEST_F(WddmTest, givenNullPageTableManagerWhenUpdateAuxTableCalledThenReturnFalse) {
auto wddmMock = std::make_unique<WddmMock>();
wddmMock->resetPageTableManager(nullptr);
EXPECT_EQ(nullptr, wddmMock->getPageTableManager());
auto gmm = std::unique_ptr<Gmm>(Gmm::create(nullptr, 1, false));
auto mockGmmRes = reinterpret_cast<MockGmmResourceInfo *>(gmm->gmmResourceInfo.get());
mockGmmRes->setUnifiedAuxTranslationCapable();
EXPECT_FALSE(wddmMock->updateAuxTable(1234u, gmm.get(), true));
}
TEST(WddmTestEnumAdapters, expectTrue) {
ADAPTER_INFO adpaterInfo;
const HardwareInfo hwInfo = *platformDevices[0];