Propagate AllocationFlags and deviceIndex to GraphicsAllocation

- adjust AllocationData interface

Change-Id: I3754585011d34b747fe23836f754fba8e711c9ff
This commit is contained in:
Hoppe, Mateusz
2018-09-20 21:07:50 -07:00
committed by sys_ocldev
parent 94c53f0777
commit e8b6f11cad
4 changed files with 83 additions and 27 deletions

View File

@@ -20,8 +20,8 @@ class MemoryManagerGetAlloctionDataTest : public testing::TestWithParam<Graphics
TEST(MemoryManagerGetAlloctionDataTest, givenHostMemoryAllocationTypeAndAllocateMemoryFlagAndNullptrWhenAllocationDataIsQueriedThenCorrectFlagsAndSizeAreSet) {
AllocationData allocData;
MockMemoryManager::getAllocationData(allocData, true, nullptr, 10, GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY);
AllocationFlags flags(true);
MockMemoryManager::getAllocationData(allocData, flags, 0, nullptr, 10, GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY);
EXPECT_TRUE(allocData.flags.mustBeZeroCopy);
EXPECT_TRUE(allocData.flags.useSystemMemory);
@@ -31,8 +31,9 @@ TEST(MemoryManagerGetAlloctionDataTest, givenHostMemoryAllocationTypeAndAllocate
TEST(MemoryManagerGetAlloctionDataTest, givenNonHostMemoryAllocatoinTypeWhenAllocationDataIsQueriedThenMustBeZeroCopyAndUseSystemMemoryFlagsAreNotSet) {
AllocationData allocData;
AllocationFlags flags(true);
MockMemoryManager::getAllocationData(allocData, true, nullptr, 10, GraphicsAllocation::AllocationType::BUFFER);
MockMemoryManager::getAllocationData(allocData, flags, 0, nullptr, 10, GraphicsAllocation::AllocationType::BUFFER);
EXPECT_FALSE(allocData.flags.mustBeZeroCopy);
EXPECT_FALSE(allocData.flags.useSystemMemory);
@@ -43,7 +44,9 @@ TEST(MemoryManagerGetAlloctionDataTest, givenNonHostMemoryAllocatoinTypeWhenAllo
TEST(MemoryManagerGetAlloctionDataTest, givenAllocateMemoryFlagTrueWhenHostPtrIsNotNullThenAllocationDataHasHostPtrNulled) {
AllocationData allocData;
char memory = 0;
MockMemoryManager::getAllocationData(allocData, true, &memory, sizeof(memory), GraphicsAllocation::AllocationType::BUFFER);
AllocationFlags flags(true);
MockMemoryManager::getAllocationData(allocData, flags, 0, &memory, sizeof(memory), GraphicsAllocation::AllocationType::BUFFER);
EXPECT_EQ(sizeof(memory), allocData.size);
EXPECT_EQ(nullptr, allocData.hostPtr);
@@ -51,32 +54,56 @@ TEST(MemoryManagerGetAlloctionDataTest, givenAllocateMemoryFlagTrueWhenHostPtrIs
TEST(MemoryManagerGetAlloctionDataTest, givenBufferTypeWhenAllocationDataIsQueriedThenForcePinFlagIsSet) {
AllocationData allocData;
MockMemoryManager::getAllocationData(allocData, true, nullptr, 10, GraphicsAllocation::AllocationType::BUFFER);
AllocationFlags flags(true);
MockMemoryManager::getAllocationData(allocData, flags, 0, nullptr, 10, GraphicsAllocation::AllocationType::BUFFER);
EXPECT_TRUE(allocData.flags.forcePin);
}
TEST(MemoryManagerGetAlloctionDataTest, givenBufferHostMemoryTypeWhenAllocationDataIsQueriedThenForcePinFlagIsSet) {
AllocationData allocData;
MockMemoryManager::getAllocationData(allocData, true, nullptr, 10, GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY);
AllocationFlags flags(true);
MockMemoryManager::getAllocationData(allocData, flags, 0, nullptr, 10, GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY);
EXPECT_TRUE(allocData.flags.forcePin);
}
TEST(MemoryManagerGetAlloctionDataTest, givenBufferCompressedTypeWhenAllocationDataIsQueriedThenForcePinFlagIsSet) {
AllocationData allocData;
MockMemoryManager::getAllocationData(allocData, true, nullptr, 10, GraphicsAllocation::AllocationType::BUFFER_COMPRESSED);
AllocationFlags flags(true);
MockMemoryManager::getAllocationData(allocData, flags, 0, nullptr, 10, GraphicsAllocation::AllocationType::BUFFER_COMPRESSED);
EXPECT_TRUE(allocData.flags.forcePin);
}
TEST(MemoryManagerGetAlloctionDataTest, givenDefaultAllocationFlagsWhenAllocationDataIsQueriedThenAllocateMemoryIsFalse) {
AllocationData allocData;
AllocationFlags flags;
char memory;
MockMemoryManager::getAllocationData(allocData, flags, 0, &memory, sizeof(memory), GraphicsAllocation::AllocationType::BUFFER_COMPRESSED);
EXPECT_FALSE(allocData.flags.allocateMemory);
}
TEST(MemoryManagerGetAlloctionDataTest, givenSpecificDeviceWhenAllocationDataIsQueriedThenDeviceIsPropagatedToAllocationData) {
AllocationData allocData;
AllocationFlags flags(true);
MockMemoryManager::getAllocationData(allocData, flags, 3u, nullptr, 10, GraphicsAllocation::AllocationType::BUFFER_COMPRESSED);
EXPECT_EQ(3u, allocData.deviceIndex);
}
typedef MemoryManagerGetAlloctionDataTest MemoryManagerGetAlloctionData32BitAnd64kbPagesAllowedTest;
TEST_P(MemoryManagerGetAlloctionData32BitAnd64kbPagesAllowedTest, givenAllocationTypesWith32BitAnd64kbPagesAllowedWhenAllocationDataIsQueriedThenProperFlagsAreSet) {
AllocationData allocData;
AllocationFlags flags(true);
auto allocType = GetParam();
MockMemoryManager::getAllocationData(allocData, true, nullptr, 10, allocType);
MockMemoryManager::getAllocationData(allocData, flags, 0, nullptr, 10, allocType);
EXPECT_TRUE(allocData.flags.allow32Bit);
EXPECT_TRUE(allocData.flags.allow64kbPages);
@@ -86,7 +113,9 @@ TEST_P(MemoryManagerGetAlloctionData32BitAnd64kbPagesAllowedTest, givenAllocatio
TEST_P(MemoryManagerGetAlloctionData32BitAnd64kbPagesAllowedTest, given64kbAllowedAllocationTypeWhenAllocatingThenPreferRenderCompressionOnlyForSpecificTypes) {
auto allocType = GetParam();
AllocationData allocData;
MockMemoryManager::getAllocationData(allocData, true, nullptr, 10, allocType);
AllocationFlags flags(true);
MockMemoryManager::getAllocationData(allocData, flags, 0, nullptr, 10, allocType);
bool bufferCompressedType = (allocType == GraphicsAllocation::AllocationType::BUFFER_COMPRESSED);
EXPECT_TRUE(allocData.flags.allow64kbPages);
@@ -103,9 +132,10 @@ typedef MemoryManagerGetAlloctionDataTest MemoryManagerGetAlloctionData32BitAnd6
TEST_P(MemoryManagerGetAlloctionData32BitAnd64kbPagesNotAllowedTest, givenAllocationTypesWith32BitAnd64kbPagesDisallowedWhenAllocationDataIsQueriedThenFlagsAreNotSet) {
AllocationData allocData;
AllocationFlags flags(true);
auto allocType = GetParam();
MockMemoryManager::getAllocationData(allocData, true, nullptr, 10, allocType);
MockMemoryManager::getAllocationData(allocData, flags, 0, nullptr, 10, allocType);
EXPECT_FALSE(allocData.flags.allow32Bit);
EXPECT_FALSE(allocData.flags.allow64kbPages);
@@ -142,7 +172,9 @@ TEST(MemoryManagerTest, givenForced32BitSetWhenGraphicsMemoryFor32BitAllowedType
memoryManager.setForce32BitAllocations(true);
AllocationData allocData;
MockMemoryManager::getAllocationData(allocData, true, nullptr, 10, GraphicsAllocation::AllocationType::BUFFER);
AllocationFlags flags(true);
MockMemoryManager::getAllocationData(allocData, flags, 0, nullptr, 10, GraphicsAllocation::AllocationType::BUFFER);
auto allocation = memoryManager.allocateGraphicsMemory(allocData);
ASSERT_NE(nullptr, allocation);
@@ -162,7 +194,9 @@ TEST(MemoryManagerTest, givenForced32BitEnabledWhenGraphicsMemoryWihtoutAllow32B
memoryManager.setForce32BitAllocations(true);
AllocationData allocData;
MockMemoryManager::getAllocationData(allocData, true, nullptr, 10, GraphicsAllocation::AllocationType::BUFFER);
AllocationFlags flags(true);
MockMemoryManager::getAllocationData(allocData, flags, 0, nullptr, 10, GraphicsAllocation::AllocationType::BUFFER);
allocData.flags.allow32Bit = false;
auto allocation = memoryManager.allocateGraphicsMemory(allocData);
@@ -177,7 +211,9 @@ TEST(MemoryManagerTest, givenForced32BitDisabledWhenGraphicsMemoryWith32BitFlagF
memoryManager.setForce32BitAllocations(false);
AllocationData allocData;
MockMemoryManager::getAllocationData(allocData, true, nullptr, 10, GraphicsAllocation::AllocationType::BUFFER);
AllocationFlags flags(true);
MockMemoryManager::getAllocationData(allocData, flags, 0, nullptr, 10, GraphicsAllocation::AllocationType::BUFFER);
auto allocation = memoryManager.allocateGraphicsMemory(allocData);
ASSERT_NE(nullptr, allocation);
@@ -189,7 +225,9 @@ TEST(MemoryManagerTest, givenForced32BitDisabledWhenGraphicsMemoryWith32BitFlagF
TEST(MemoryManagerTest, givenEnabled64kbPagesWhenGraphicsMemoryMustBeHostMemoryAndIsAllocatedWithNullptrForBufferThen64kbAllocationIsReturned) {
OsAgnosticMemoryManager memoryManager(true, false);
AllocationData allocData;
MockMemoryManager::getAllocationData(allocData, true, nullptr, 10, GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY);
AllocationFlags flags(true);
MockMemoryManager::getAllocationData(allocData, flags, 0, nullptr, 10, GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY);
auto allocation = memoryManager.allocateGraphicsMemory(allocData);
ASSERT_NE(nullptr, allocation);
@@ -204,7 +242,9 @@ TEST(MemoryManagerTest, givenEnabled64kbPagesWhenGraphicsMemoryMustBeHostMemoryA
TEST(MemoryManagerTest, givenEnabled64kbPagesWhenGraphicsMemoryWithoutAllow64kbPagesFlagsIsAllocatedThenNon64kbAllocationIsReturned) {
MockMemoryManager memoryManager(true);
AllocationData allocData;
MockMemoryManager::getAllocationData(allocData, true, nullptr, 10, GraphicsAllocation::AllocationType::BUFFER);
AllocationFlags flags(true);
MockMemoryManager::getAllocationData(allocData, flags, 0, nullptr, 10, GraphicsAllocation::AllocationType::BUFFER);
allocData.flags.allow64kbPages = false;
auto allocation = memoryManager.allocateGraphicsMemory(allocData);
@@ -218,7 +258,9 @@ TEST(MemoryManagerTest, givenEnabled64kbPagesWhenGraphicsMemoryWithoutAllow64kbP
TEST(MemoryManagerTest, givenDisabled64kbPagesWhenGraphicsMemoryMustBeHostMemoryAndIsAllocatedWithNullptrForBufferThenNon64kbAllocationIsReturned) {
MockMemoryManager memoryManager(false);
AllocationData allocData;
MockMemoryManager::getAllocationData(allocData, true, nullptr, 10, GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY);
AllocationFlags flags(true);
MockMemoryManager::getAllocationData(allocData, flags, 0, nullptr, 10, GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY);
auto allocation = memoryManager.allocateGraphicsMemory(allocData);
ASSERT_NE(nullptr, allocation);
@@ -234,7 +276,9 @@ TEST(MemoryManagerTest, givenForced32BitAndEnabled64kbPagesWhenGraphicsMemoryMus
memoryManager.setForce32BitAllocations(true);
AllocationData allocData;
MockMemoryManager::getAllocationData(allocData, true, nullptr, 10, GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY);
AllocationFlags flags(true);
MockMemoryManager::getAllocationData(allocData, flags, 0, nullptr, 10, GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY);
auto allocation = memoryManager.allocateGraphicsMemory(allocData);
ASSERT_NE(nullptr, allocation);
@@ -250,8 +294,10 @@ TEST(MemoryManagerTest, givenForced32BitAndEnabled64kbPagesWhenGraphicsMemoryMus
TEST(MemoryManagerTest, givenEnabled64kbPagesWhenGraphicsMemoryIsAllocatedWithHostPtrForBufferThenExistingMemoryIsUsedForAllocation) {
OsAgnosticMemoryManager memoryManager(true, false);
AllocationData allocData;
AllocationFlags flags(false);
char memory[1];
MockMemoryManager::getAllocationData(allocData, false, &memory, 1, GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY);
MockMemoryManager::getAllocationData(allocData, flags, 0, &memory, 1, GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY);
auto allocation = memoryManager.allocateGraphicsMemory(allocData);
ASSERT_NE(nullptr, allocation);