Allow to allocate shareable graphics allocation

Change-Id: I284b03b001e5b67c344d46f34048803ef9a57314
Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
This commit is contained in:
Mateusz Jablonski
2018-12-20 07:43:57 +00:00
committed by sys_ocldev
parent f6757c02a4
commit 1e011f9a08
11 changed files with 93 additions and 19 deletions

View File

@@ -377,3 +377,31 @@ TEST(MemoryManagerTest, givenTimestampTagBufferTypeWhenGetAllocationDataIsCalled
MockMemoryManager::getAllocationData(allocData, {1, GraphicsAllocation::AllocationType::TIMESTAMP_TAG_BUFFER}, 0, nullptr);
EXPECT_TRUE(allocData.flags.useSystemMemory);
}
TEST(MemoryManagerTest, givenAllocationPropertiesWithShareableFlagEnabledWhenAllocateMemoryThenAllocationIsShareable) {
MockMemoryManager memoryManager(false);
AllocationProperties properties{MemoryConstants::pageSize, GraphicsAllocation::AllocationType::BUFFER};
properties.flags.shareable = true;
AllocationData allocData;
MockMemoryManager::getAllocationData(allocData, properties, 0, nullptr);
EXPECT_TRUE(allocData.flags.shareable);
auto allocation = memoryManager.allocateGraphicsMemoryWithProperties(properties);
EXPECT_TRUE(allocation->isShareable());
memoryManager.freeGraphicsMemory(allocation);
}
TEST(MemoryManagerTest, givenAllocationPropertiesWithShareableFlagDisabledWhenAllocateMemoryThenAllocationIsNotShareable) {
MockMemoryManager memoryManager(false);
AllocationProperties properties{MemoryConstants::pageSize, GraphicsAllocation::AllocationType::BUFFER};
properties.flags.shareable = false;
AllocationData allocData;
MockMemoryManager::getAllocationData(allocData, properties, 0, nullptr);
EXPECT_FALSE(allocData.flags.shareable);
auto allocation = memoryManager.allocateGraphicsMemoryWithProperties(properties);
EXPECT_FALSE(allocation->isShareable());
memoryManager.freeGraphicsMemory(allocation);
}

View File

@@ -30,7 +30,9 @@ void *MockMemoryManager::allocateSystemMemory(size_t size, size_t alignment) {
}
GraphicsAllocation *MockMemoryManager::allocateGraphicsMemoryWithProperties(const AllocationProperties &properties) {
return OsAgnosticMemoryManager::allocateGraphicsMemoryWithProperties({redundancyRatio * properties.size, properties.allocationType});
AllocationProperties adjustedProperties(properties);
adjustedProperties.size = redundancyRatio * properties.size;
return OsAgnosticMemoryManager::allocateGraphicsMemoryWithProperties(adjustedProperties);
}
GraphicsAllocation *MockMemoryManager::allocateGraphicsMemoryForImage(ImageInfo &imgInfo, const void *hostPtr) {

View File

@@ -651,6 +651,26 @@ TEST_F(DrmMemoryManagerTest, GivenNoInputsWhenOsHandleIsCreatedThenAllBoHandlesA
EXPECT_EQ(nullptr, boHandle2->bo);
}
TEST_F(DrmMemoryManagerTest, givenAllocationPropertiesWithShareableFlagEnabledWhenAllocateMemoryThenAllocationIsShareable) {
mock->ioctl_expected.total = -1;
AllocationProperties properties{MemoryConstants::pageSize, GraphicsAllocation::AllocationType::BUFFER};
properties.flags.shareable = true;
auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(properties);
EXPECT_TRUE(allocation->isShareable());
memoryManager->freeGraphicsMemory(allocation);
}
TEST_F(DrmMemoryManagerTest, givenAllocationPropertiesWithShareableFlagDisabledWhenAllocateMemoryThenAllocationIsNotShareable) {
mock->ioctl_expected.total = -1;
AllocationProperties properties{MemoryConstants::pageSize, GraphicsAllocation::AllocationType::BUFFER};
properties.flags.shareable = false;
auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(properties);
EXPECT_FALSE(allocation->isShareable());
memoryManager->freeGraphicsMemory(allocation);
}
TEST_F(DrmMemoryManagerTest, GivenPointerAndSizeWhenAskedToCreateGrahicsAllocationThenGraphicsAllocationIsCreated) {
OsHandleStorage handleStorage;
auto ptr = reinterpret_cast<void *>(0x1000);

View File

@@ -228,6 +228,24 @@ TEST_F(WddmMemoryManagerTest, givenDefaultWddmMemoryManagerWhenAskedForVirtualPa
EXPECT_FALSE(memoryManager->peekVirtualPaddingSupport());
}
TEST_F(WddmMemoryManagerTest, givenAllocationPropertiesWithShareableFlagEnabledWhenAllocateMemoryThenAllocationIsShareable) {
AllocationProperties properties{MemoryConstants::pageSize, GraphicsAllocation::AllocationType::BUFFER};
properties.flags.shareable = true;
auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(properties);
EXPECT_TRUE(allocation->isShareable());
memoryManager->freeGraphicsMemory(allocation);
}
TEST_F(WddmMemoryManagerTest, givenAllocationPropertiesWithShareableFlagDisabledWhenAllocateMemoryThenAllocationIsNotShareable) {
AllocationProperties properties{MemoryConstants::pageSize, GraphicsAllocation::AllocationType::BUFFER};
properties.flags.shareable = false;
auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(properties);
EXPECT_FALSE(allocation->isShareable());
memoryManager->freeGraphicsMemory(allocation);
}
TEST_F(WddmMemoryManagerTest, GivenGraphicsAllocationWhenAddAndRemoveAllocationToHostPtrManagerThenfragmentHasCorrectValues) {
void *cpuPtr = (void *)0x30000;
size_t size = 0x1000;