From d79f1afdc2ea773294a3196eb7f41bab5177a02a Mon Sep 17 00:00:00 2001 From: Piotr Fusik Date: Tue, 26 Feb 2019 11:37:51 +0100 Subject: [PATCH] GraphicsAllocation constructor accepts allocationType and memoryPool. Change-Id: I5044ed26ba0cb0fc9ca7077595f5ab56353ab58c --- .../aub_command_stream_receiver_hw.inl | 2 +- .../command_stream_receiver.cpp | 3 +- .../memory_manager/graphics_allocation.cpp | 11 +++- runtime/memory_manager/graphics_allocation.h | 10 ++- .../os_agnostic_memory_manager.cpp | 2 +- .../os_agnostic_memory_manager.h | 3 +- runtime/os_interface/linux/drm_allocation.h | 11 ++-- .../os_interface/windows/wddm_allocation.h | 7 +-- .../enqueue_read_buffer_aub_tests.cpp | 8 ++- .../command_stream_receiver_tests.cpp | 2 +- unit_tests/helpers/hw_helper_tests.cpp | 10 +-- unit_tests/helpers/kernel_commands_tests.cpp | 4 +- unit_tests/kernel/kernel_tests.cpp | 8 +-- .../libult/ult_command_stream_receiver.h | 2 +- .../graphics_allocation_tests.cpp | 6 +- .../memory_manager/memory_manager_tests.cpp | 24 ++++---- unit_tests/mocks/mock_graphics_allocation.h | 15 +++-- .../debug_settings_manager_tests.cpp | 61 +++++++++---------- 18 files changed, 102 insertions(+), 87 deletions(-) diff --git a/runtime/command_stream/aub_command_stream_receiver_hw.inl b/runtime/command_stream/aub_command_stream_receiver_hw.inl index dfd5eae7d2..877bceec75 100644 --- a/runtime/command_stream/aub_command_stream_receiver_hw.inl +++ b/runtime/command_stream/aub_command_stream_receiver_hw.inl @@ -657,7 +657,7 @@ bool AUBCommandStreamReceiverHw::writeMemory(GraphicsAllocation &gfxA template bool AUBCommandStreamReceiverHw::writeMemory(AllocationView &allocationView) { - GraphicsAllocation gfxAllocation(reinterpret_cast(allocationView.first), allocationView.first, 0llu, allocationView.second, false); + GraphicsAllocation gfxAllocation(GraphicsAllocation::AllocationType::UNKNOWN, reinterpret_cast(allocationView.first), allocationView.first, 0llu, allocationView.second, MemoryPool::MemoryNull, false); return writeMemory(gfxAllocation); } diff --git a/runtime/command_stream/command_stream_receiver.cpp b/runtime/command_stream/command_stream_receiver.cpp index 7618d30d80..c5f4ee40ab 100644 --- a/runtime/command_stream/command_stream_receiver.cpp +++ b/runtime/command_stream/command_stream_receiver.cpp @@ -350,8 +350,7 @@ AllocationsList &CommandStreamReceiver::getAllocationsForReuse() { return intern bool CommandStreamReceiver::createAllocationForHostSurface(HostPtrSurface &surface, Device &device, bool requiresL3Flush) { auto memoryManager = getMemoryManager(); - GraphicsAllocation *allocation = nullptr; - allocation = memoryManager->allocateGraphicsMemoryForHostPtr(surface.getSurfaceSize(), surface.getMemoryPointer(), device.isFullRangeSvm(), requiresL3Flush); + auto allocation = memoryManager->allocateGraphicsMemoryForHostPtr(surface.getSurfaceSize(), surface.getMemoryPointer(), device.isFullRangeSvm(), requiresL3Flush); if (allocation == nullptr && surface.peekIsPtrCopyAllowed()) { // Try with no host pointer allocation and copy AllocationProperties properties(true, surface.getSurfaceSize(), GraphicsAllocation::AllocationType::UNDECIDED); diff --git a/runtime/memory_manager/graphics_allocation.cpp b/runtime/memory_manager/graphics_allocation.cpp index ad4ec9814d..f0e7a12f53 100644 --- a/runtime/memory_manager/graphics_allocation.cpp +++ b/runtime/memory_manager/graphics_allocation.cpp @@ -23,19 +23,24 @@ bool GraphicsAllocation::isL3Capable() { } return false; } -GraphicsAllocation::GraphicsAllocation(void *cpuPtrIn, uint64_t gpuAddress, uint64_t baseAddress, - size_t sizeIn, bool multiOsContextCapable) +GraphicsAllocation::GraphicsAllocation(AllocationType allocationType, void *cpuPtrIn, uint64_t gpuAddress, uint64_t baseAddress, + size_t sizeIn, MemoryPool::Type pool, bool multiOsContextCapable) : gpuBaseAddress(baseAddress), size(sizeIn), cpuPtr(cpuPtrIn), gpuAddress(gpuAddress), + memoryPool(pool), + allocationType(allocationType), multiOsContextCapable(multiOsContextCapable) {} -GraphicsAllocation::GraphicsAllocation(void *cpuPtrIn, size_t sizeIn, osHandle sharedHandleIn, bool multiOsContextCapable) +GraphicsAllocation::GraphicsAllocation(AllocationType allocationType, void *cpuPtrIn, size_t sizeIn, osHandle sharedHandleIn, + MemoryPool::Type pool, bool multiOsContextCapable) : size(sizeIn), cpuPtr(cpuPtrIn), gpuAddress(castToUint64(cpuPtrIn)), sharedHandle(sharedHandleIn), + memoryPool(pool), + allocationType(allocationType), multiOsContextCapable(multiOsContextCapable) {} GraphicsAllocation::~GraphicsAllocation() = default; diff --git a/runtime/memory_manager/graphics_allocation.h b/runtime/memory_manager/graphics_allocation.h index 548f0101e2..e077ef12bb 100644 --- a/runtime/memory_manager/graphics_allocation.h +++ b/runtime/memory_manager/graphics_allocation.h @@ -90,9 +90,9 @@ class GraphicsAllocation : public IDNode { GraphicsAllocation &operator=(const GraphicsAllocation &) = delete; GraphicsAllocation(const GraphicsAllocation &) = delete; - GraphicsAllocation(void *cpuPtrIn, uint64_t gpuAddress, uint64_t baseAddress, size_t sizeIn, bool multiOsContextCapable); + GraphicsAllocation(AllocationType allocationType, void *cpuPtrIn, uint64_t gpuAddress, uint64_t baseAddress, size_t sizeIn, MemoryPool::Type pool, bool multiOsContextCapable); - GraphicsAllocation(void *cpuPtrIn, size_t sizeIn, osHandle sharedHandleIn, bool multiOsContextCapable); + GraphicsAllocation(AllocationType allocationType, void *cpuPtrIn, size_t sizeIn, osHandle sharedHandleIn, MemoryPool::Type pool, bool multiOsContextCapable); void *getUnderlyingBuffer() const { return cpuPtr; } void setCpuPtrAndGpuAddress(void *cpuPtr, uint64_t gpuAddress) { @@ -137,15 +137,13 @@ class GraphicsAllocation : public IDNode { void incReuseCount() { reuseCount++; } void decReuseCount() { reuseCount--; } uint32_t peekReuseCount() const { return reuseCount; } - MemoryPool::Type getMemoryPool() const { - return memoryPool; - } + MemoryPool::Type getMemoryPool() const { return memoryPool; } bool isUsed() const { return registeredContextsNum > 0; } bool isUsedByOsContext(uint32_t contextId) const { return objectNotUsed != getTaskCount(contextId); } void updateTaskCount(uint32_t newTaskCount, uint32_t contextId); uint32_t getTaskCount(uint32_t contextId) const { return usageInfos[contextId].taskCount; } void releaseUsageInOsContext(uint32_t contextId) { updateTaskCount(objectNotUsed, contextId); } - uint32_t getInspectionId(uint32_t contextId) { return usageInfos[contextId].inspectionId; } + uint32_t getInspectionId(uint32_t contextId) const { return usageInfos[contextId].inspectionId; } void setInspectionId(uint32_t newInspectionId, uint32_t contextId) { usageInfos[contextId].inspectionId = newInspectionId; } bool isResident(uint32_t contextId) const { return GraphicsAllocation::objectNotResident != getResidencyTaskCount(contextId); } diff --git a/runtime/memory_manager/os_agnostic_memory_manager.cpp b/runtime/memory_manager/os_agnostic_memory_manager.cpp index 3300fe19de..9b295fc500 100644 --- a/runtime/memory_manager/os_agnostic_memory_manager.cpp +++ b/runtime/memory_manager/os_agnostic_memory_manager.cpp @@ -73,7 +73,7 @@ GraphicsAllocation *OsAgnosticMemoryManager::allocateGraphicsMemory64kb(Allocati allocationData.alignment = MemoryConstants::pageSize64k; auto memoryAllocation = allocateGraphicsMemoryWithAlignment(allocationData); if (memoryAllocation) { - reinterpret_cast(memoryAllocation)->overrideMemoryPool(MemoryPool::System64KBPages); + static_cast(memoryAllocation)->overrideMemoryPool(MemoryPool::System64KBPages); } return memoryAllocation; } diff --git a/runtime/memory_manager/os_agnostic_memory_manager.h b/runtime/memory_manager/os_agnostic_memory_manager.h index cf2aae65ee..b28e395cbd 100644 --- a/runtime/memory_manager/os_agnostic_memory_manager.h +++ b/runtime/memory_manager/os_agnostic_memory_manager.h @@ -21,7 +21,8 @@ class MemoryAllocation : public GraphicsAllocation { void setSharedHandle(osHandle handle) { this->sharedHandle = handle; } MemoryAllocation(void *driverAllocatedCpuPointer, void *pMem, uint64_t gpuAddress, size_t memSize, uint64_t count, MemoryPool::Type pool, bool multiOsContextCapable) - : GraphicsAllocation(pMem, gpuAddress, 0u, memSize, multiOsContextCapable), id(count) { + : GraphicsAllocation(AllocationType::UNKNOWN, pMem, gpuAddress, 0u, memSize, pool, multiOsContextCapable), + id(count) { this->driverAllocatedCpuPointer = driverAllocatedCpuPointer; overrideMemoryPool(pool); diff --git a/runtime/os_interface/linux/drm_allocation.h b/runtime/os_interface/linux/drm_allocation.h index 0d81897aaf..9133415944 100644 --- a/runtime/os_interface/linux/drm_allocation.h +++ b/runtime/os_interface/linux/drm_allocation.h @@ -17,11 +17,14 @@ struct OsHandle { class DrmAllocation : public GraphicsAllocation { public: - DrmAllocation(BufferObject *bo, void *ptrIn, size_t sizeIn, osHandle sharedHandle, MemoryPool::Type pool, bool multiOsContextCapable) : GraphicsAllocation(ptrIn, sizeIn, sharedHandle, multiOsContextCapable), bo(bo) { - this->memoryPool = pool; + DrmAllocation(BufferObject *bo, void *ptrIn, size_t sizeIn, osHandle sharedHandle, MemoryPool::Type pool, bool multiOsContextCapable) + : GraphicsAllocation(AllocationType::UNKNOWN, ptrIn, sizeIn, sharedHandle, pool, multiOsContextCapable), + bo(bo) { } - DrmAllocation(BufferObject *bo, void *ptrIn, uint64_t gpuAddress, size_t sizeIn, MemoryPool::Type pool, bool multiOsContextCapable) : GraphicsAllocation(ptrIn, gpuAddress, 0, sizeIn, multiOsContextCapable), bo(bo) { - this->memoryPool = pool; + + DrmAllocation(BufferObject *bo, void *ptrIn, uint64_t gpuAddress, size_t sizeIn, MemoryPool::Type pool, bool multiOsContextCapable) + : GraphicsAllocation(AllocationType::UNKNOWN, ptrIn, gpuAddress, 0, sizeIn, pool, multiOsContextCapable), + bo(bo) { } std::string getAllocationInfoString() const override; diff --git a/runtime/os_interface/windows/wddm_allocation.h b/runtime/os_interface/windows/wddm_allocation.h index f5f606ea1b..ac4754d4d5 100644 --- a/runtime/os_interface/windows/wddm_allocation.h +++ b/runtime/os_interface/windows/wddm_allocation.h @@ -31,22 +31,21 @@ class WddmAllocation : public GraphicsAllocation { D3DKMT_HANDLE resourceHandle = 0u; // used by shared resources D3DGPU_VIRTUAL_ADDRESS gpuPtr; // set by mapGpuVA + WddmAllocation(void *cpuPtrIn, size_t sizeIn, void *reservedAddr, MemoryPool::Type pool, bool multiOsContextCapable) - : GraphicsAllocation(cpuPtrIn, castToUint64(cpuPtrIn), 0llu, sizeIn, multiOsContextCapable), + : GraphicsAllocation(AllocationType::UNKNOWN, cpuPtrIn, castToUint64(cpuPtrIn), 0llu, sizeIn, pool, multiOsContextCapable), handle(0), gpuPtr(0), trimCandidateListPositions(maxOsContextCount, trimListUnusedPosition) { reservedAddressSpace = reservedAddr; - this->memoryPool = pool; } WddmAllocation(void *cpuPtrIn, size_t sizeIn, osHandle sharedHandle, MemoryPool::Type pool, bool multiOsContextCapable) - : GraphicsAllocation(cpuPtrIn, sizeIn, sharedHandle, multiOsContextCapable), + : GraphicsAllocation(AllocationType::UNKNOWN, cpuPtrIn, sizeIn, sharedHandle, pool, multiOsContextCapable), handle(0), gpuPtr(0), trimCandidateListPositions(maxOsContextCount, trimListUnusedPosition) { reservedAddressSpace = nullptr; - this->memoryPool = pool; } void *getAlignedCpuPtr() const { diff --git a/unit_tests/aub_tests/command_queue/enqueue_read_buffer_aub_tests.cpp b/unit_tests/aub_tests/command_queue/enqueue_read_buffer_aub_tests.cpp index 5f9a3d2c7a..8a8916ed8c 100644 --- a/unit_tests/aub_tests/command_queue/enqueue_read_buffer_aub_tests.cpp +++ b/unit_tests/aub_tests/command_queue/enqueue_read_buffer_aub_tests.cpp @@ -114,7 +114,13 @@ HWTEST_F(AUBReadBuffer, reserveCanonicalGpuAddress) { cl_float srcMemory[] = {1.0f, 2.0f, 3.0f, 4.0f}; cl_float dstMemory[] = {0.0f, 0.0f, 0.0f, 0.0f}; - GraphicsAllocation *srcAlocation = new GraphicsAllocation(srcMemory, 0xFFFF800400001000, 0xFFFF800400001000, sizeof(srcMemory), false); + GraphicsAllocation *srcAlocation = new GraphicsAllocation(GraphicsAllocation::AllocationType::UNKNOWN, + srcMemory, + 0xFFFF800400001000, + 0xFFFF800400001000, + sizeof(srcMemory), + MemoryPool::MemoryNull, + false); std::unique_ptr srcBuffer(Buffer::createBufferHw(&context, CL_MEM_USE_HOST_PTR, diff --git a/unit_tests/command_stream/command_stream_receiver_tests.cpp b/unit_tests/command_stream/command_stream_receiver_tests.cpp index e9cdde13fa..9ab12e0ae9 100644 --- a/unit_tests/command_stream/command_stream_receiver_tests.cpp +++ b/unit_tests/command_stream/command_stream_receiver_tests.cpp @@ -336,7 +336,7 @@ TEST(CommandStreamReceiverSimpleTest, givenCommandStreamReceiverWhenItIsDestroye bool destructorCalled = false; - auto mockGraphicsAllocation = new MockGraphicsAllocationWithDestructorTracing(nullptr, 0llu, 0llu, 1u, false); + auto mockGraphicsAllocation = new MockGraphicsAllocationWithDestructorTracing(GraphicsAllocation::AllocationType::UNKNOWN, nullptr, 0llu, 0llu, 1u, MemoryPool::MemoryNull, false); mockGraphicsAllocation->destructorCalled = &destructorCalled; ExecutionEnvironment executionEnvironment; executionEnvironment.commandStreamReceivers.resize(1); diff --git a/unit_tests/helpers/hw_helper_tests.cpp b/unit_tests/helpers/hw_helper_tests.cpp index 5eaeaf7f4f..a743aaa8b4 100644 --- a/unit_tests/helpers/hw_helper_tests.cpp +++ b/unit_tests/helpers/hw_helper_tests.cpp @@ -347,7 +347,7 @@ HWTEST_F(HwHelperTest, givenCreatedSurfaceStateBufferWhenAllocationProvidedThenU uint64_t gpuAddr = 0x4000u; size_t allocSize = size; length.Length = static_cast(allocSize - 1); - GraphicsAllocation allocation(cpuAddr, gpuAddr, 0u, allocSize, false); + GraphicsAllocation allocation(GraphicsAllocation::AllocationType::UNKNOWN, cpuAddr, gpuAddr, 0u, allocSize, MemoryPool::MemoryNull, false); allocation.gmm = new Gmm(allocation.getUnderlyingBuffer(), allocation.getUnderlyingBufferSize(), false); ASSERT_NE(nullptr, allocation.gmm); SURFACE_TYPE type = RENDER_SURFACE_STATE::SURFACE_TYPE_SURFTYPE_BUFFER; @@ -385,7 +385,7 @@ HWTEST_F(HwHelperTest, givenCreatedSurfaceStateBufferWhenGmmAndAllocationCompres void *cpuAddr = reinterpret_cast(0x4000); uint64_t gpuAddr = 0x4000u; size_t allocSize = size; - GraphicsAllocation allocation(cpuAddr, gpuAddr, 0u, allocSize, false); + GraphicsAllocation allocation(GraphicsAllocation::AllocationType::UNKNOWN, cpuAddr, gpuAddr, 0u, allocSize, MemoryPool::MemoryNull, false); allocation.gmm = new Gmm(allocation.getUnderlyingBuffer(), allocation.getUnderlyingBufferSize(), false); ASSERT_NE(nullptr, allocation.gmm); allocation.gmm->isRenderCompressed = true; @@ -419,7 +419,7 @@ HWTEST_F(HwHelperTest, givenCreatedSurfaceStateBufferWhenGmmCompressionEnabledAn void *cpuAddr = reinterpret_cast(0x4000); uint64_t gpuAddr = 0x4000u; size_t allocSize = size; - GraphicsAllocation allocation(cpuAddr, gpuAddr, 0u, allocSize, false); + GraphicsAllocation allocation(GraphicsAllocation::AllocationType::UNKNOWN, cpuAddr, gpuAddr, 0u, allocSize, MemoryPool::MemoryNull, false); allocation.gmm = new Gmm(allocation.getUnderlyingBuffer(), allocation.getUnderlyingBufferSize(), false); ASSERT_NE(nullptr, allocation.gmm); allocation.gmm->isRenderCompressed = true; @@ -452,7 +452,7 @@ HWTEST_F(HwHelperTest, givenCreatedSurfaceStateBufferWhenGmmCompressionDisabledA void *cpuAddr = reinterpret_cast(0x4000); uint64_t gpuAddr = 0x4000u; size_t allocSize = size; - GraphicsAllocation allocation(cpuAddr, gpuAddr, 0u, allocSize, false); + GraphicsAllocation allocation(GraphicsAllocation::AllocationType::UNKNOWN, cpuAddr, gpuAddr, 0u, allocSize, MemoryPool::MemoryNull, false); allocation.gmm = new Gmm(allocation.getUnderlyingBuffer(), allocation.getUnderlyingBufferSize(), false); ASSERT_NE(nullptr, allocation.gmm); allocation.setAllocationType(GraphicsAllocation::AllocationType::BUFFER_COMPRESSED); @@ -485,7 +485,7 @@ HWTEST_F(HwHelperTest, givenCreatedSurfaceStateBufferWhenGmmAndAllocationCompres void *cpuAddr = reinterpret_cast(0x4000); uint64_t gpuAddr = 0x4000u; size_t allocSize = size; - GraphicsAllocation allocation(cpuAddr, gpuAddr, 0u, allocSize, false); + GraphicsAllocation allocation(GraphicsAllocation::AllocationType::UNKNOWN, cpuAddr, gpuAddr, 0u, allocSize, MemoryPool::MemoryNull, false); allocation.gmm = new Gmm(allocation.getUnderlyingBuffer(), allocation.getUnderlyingBufferSize(), false); ASSERT_NE(nullptr, allocation.gmm); allocation.gmm->isRenderCompressed = true; diff --git a/unit_tests/helpers/kernel_commands_tests.cpp b/unit_tests/helpers/kernel_commands_tests.cpp index 3b78288253..86a7ba1e59 100644 --- a/unit_tests/helpers/kernel_commands_tests.cpp +++ b/unit_tests/helpers/kernel_commands_tests.cpp @@ -676,12 +676,12 @@ HWCMDTEST_F(IGFX_GEN8_CORE, KernelCommandsTest, usedBindingTableStatePointersFor // setup global memory char globalBuffer[16]; - GraphicsAllocation gfxGlobalAlloc(globalBuffer, castToUint64(globalBuffer), 0llu, sizeof(globalBuffer), false); + GraphicsAllocation gfxGlobalAlloc(GraphicsAllocation::AllocationType::UNKNOWN, globalBuffer, castToUint64(globalBuffer), 0llu, sizeof(globalBuffer), MemoryPool::MemoryNull, false); program.setGlobalSurface(&gfxGlobalAlloc); // setup constant memory char constBuffer[16]; - GraphicsAllocation gfxConstAlloc(constBuffer, castToUint64(constBuffer), 0llu, sizeof(constBuffer), false); + GraphicsAllocation gfxConstAlloc(GraphicsAllocation::AllocationType::UNKNOWN, constBuffer, castToUint64(constBuffer), 0llu, sizeof(constBuffer), MemoryPool::MemoryNull, false); program.setConstantSurface(&gfxConstAlloc); // create kernel diff --git a/unit_tests/kernel/kernel_tests.cpp b/unit_tests/kernel/kernel_tests.cpp index 1325e6f994..3a4b04143d 100644 --- a/unit_tests/kernel/kernel_tests.cpp +++ b/unit_tests/kernel/kernel_tests.cpp @@ -902,7 +902,7 @@ TEST_F(KernelGlobalSurfaceTest, givenBuiltInKernelWhenKernelIsCreatedThenGlobalS char buffer[16]; - GraphicsAllocation gfxAlloc((void *)buffer, (uint64_t)buffer - 8u, 8, 1u, false); + GraphicsAllocation gfxAlloc(GraphicsAllocation::AllocationType::UNKNOWN, buffer, (uint64_t)buffer - 8u, 8, 1u, MemoryPool::MemoryNull, false); uint64_t bufferAddress = (uint64_t)gfxAlloc.getUnderlyingBuffer(); // create kernel @@ -945,7 +945,7 @@ TEST_F(KernelGlobalSurfaceTest, givenNDRangeKernelWhenKernelIsCreatedThenGlobalS char buffer[16]; - GraphicsAllocation gfxAlloc((void *)buffer, (uint64_t)buffer - 8u, 8, false); + GraphicsAllocation gfxAlloc(GraphicsAllocation::AllocationType::UNKNOWN, buffer, (uint64_t)buffer - 8u, 8, MemoryPool::MemoryNull, false); uint64_t bufferAddress = gfxAlloc.getGpuAddress(); // create kernel @@ -1077,7 +1077,7 @@ TEST_F(KernelConstantSurfaceTest, givenBuiltInKernelWhenKernelIsCreatedThenConst char buffer[16]; - GraphicsAllocation gfxAlloc((void *)buffer, (uint64_t)buffer - 8u, 8, 1u, false); + GraphicsAllocation gfxAlloc(GraphicsAllocation::AllocationType::UNKNOWN, buffer, (uint64_t)buffer - 8u, 8, 1u, MemoryPool::MemoryNull, false); uint64_t bufferAddress = (uint64_t)gfxAlloc.getUnderlyingBuffer(); // create kernel @@ -1119,7 +1119,7 @@ TEST_F(KernelConstantSurfaceTest, givenNDRangeKernelWhenKernelIsCreatedThenConst char buffer[16]; - GraphicsAllocation gfxAlloc((void *)buffer, (uint64_t)buffer - 8u, 8, false); + GraphicsAllocation gfxAlloc(GraphicsAllocation::AllocationType::UNKNOWN, buffer, (uint64_t)buffer - 8u, 8, MemoryPool::MemoryNull, false); uint64_t bufferAddress = gfxAlloc.getGpuAddress(); // create kernel diff --git a/unit_tests/libult/ult_command_stream_receiver.h b/unit_tests/libult/ult_command_stream_receiver.h index f53dcb98be..907c30ffa9 100644 --- a/unit_tests/libult/ult_command_stream_receiver.h +++ b/unit_tests/libult/ult_command_stream_receiver.h @@ -70,7 +70,7 @@ class UltCommandStreamReceiver : public CommandStreamReceiverHw, publ UltCommandStreamReceiver(const HardwareInfo &hwInfoIn, ExecutionEnvironment &executionEnvironment) : BaseClass(hwInfoIn, executionEnvironment), recursiveLockCounter(0) { if (hwInfoIn.capabilityTable.defaultPreemptionMode == PreemptionMode::MidThread) { - tempPreemptionLocation = std::make_unique(nullptr, 0, 0, 0, false); + tempPreemptionLocation = std::make_unique(GraphicsAllocation::AllocationType::UNKNOWN, nullptr, 0, 0, 0, MemoryPool::MemoryNull, false); this->preemptionCsrAllocation = tempPreemptionLocation.get(); } } diff --git a/unit_tests/memory_manager/graphics_allocation_tests.cpp b/unit_tests/memory_manager/graphics_allocation_tests.cpp index 42d49a7cd5..52bef1eb1a 100644 --- a/unit_tests/memory_manager/graphics_allocation_tests.cpp +++ b/unit_tests/memory_manager/graphics_allocation_tests.cpp @@ -11,15 +11,15 @@ using namespace OCLRT; TEST(GraphicsAllocationTest, givenGraphicsAllocationWhenIsCreatedThenAllInspectionIdsAreSetToZero) { - MockGraphicsAllocation graphicsAllocation(nullptr, 0u, 0u, maxOsContextCount, true); + MockGraphicsAllocation graphicsAllocation(GraphicsAllocation::AllocationType::UNKNOWN, nullptr, 0u, 0u, maxOsContextCount, MemoryPool::MemoryNull, true); for (auto i = 0u; i < maxOsContextCount; i++) { EXPECT_EQ(0u, graphicsAllocation.getInspectionId(i)); } } TEST(GraphicsAllocationTest, givenGraphicsAllocationWhenIsCreatedThenTaskCountsAreInitializedProperly) { - GraphicsAllocation graphicsAllocation1(nullptr, 0u, 0u, 0u, true); - GraphicsAllocation graphicsAllocation2(nullptr, 0u, 0u, true); + GraphicsAllocation graphicsAllocation1(GraphicsAllocation::AllocationType::UNKNOWN, nullptr, 0u, 0u, 0u, MemoryPool::MemoryNull, true); + GraphicsAllocation graphicsAllocation2(GraphicsAllocation::AllocationType::UNKNOWN, nullptr, 0u, 0u, MemoryPool::MemoryNull, true); for (auto i = 0u; i < maxOsContextCount; i++) { EXPECT_EQ(MockGraphicsAllocation::objectNotUsed, graphicsAllocation1.getTaskCount(i)); EXPECT_EQ(MockGraphicsAllocation::objectNotUsed, graphicsAllocation2.getTaskCount(i)); diff --git a/unit_tests/memory_manager/memory_manager_tests.cpp b/unit_tests/memory_manager/memory_manager_tests.cpp index 37771cf4d6..47e9ce8220 100644 --- a/unit_tests/memory_manager/memory_manager_tests.cpp +++ b/unit_tests/memory_manager/memory_manager_tests.cpp @@ -73,7 +73,7 @@ TEST(GraphicsAllocationTest, Ctor2) { void *cpuPtr = (void *)0x30000; size_t size = 0x1000; osHandle sharedHandle = Sharing::nonSharedResource; - GraphicsAllocation gfxAllocation(cpuPtr, size, sharedHandle, false); + GraphicsAllocation gfxAllocation(GraphicsAllocation::AllocationType::UNKNOWN, cpuPtr, size, sharedHandle, MemoryPool::MemoryNull, false); uint64_t expectedGpuAddr = static_cast(reinterpret_cast(gfxAllocation.getUnderlyingBuffer())); EXPECT_EQ(expectedGpuAddr, gfxAllocation.getGpuAddress()); @@ -87,7 +87,7 @@ TEST(GraphicsAllocationTest, getGpuAddress) { uint64_t gpuBaseAddr = 0x10000; size_t size = 0x1000; - GraphicsAllocation gfxAllocation(cpuPtr, gpuAddr, gpuBaseAddr, size, false); + GraphicsAllocation gfxAllocation(GraphicsAllocation::AllocationType::UNKNOWN, cpuPtr, gpuAddr, gpuBaseAddr, size, MemoryPool::MemoryNull, false); EXPECT_EQ(gpuAddr, gfxAllocation.getGpuAddress()); @@ -104,7 +104,7 @@ TEST(GraphicsAllocationTest, getGpuAddressToPatch) { uint64_t gpuBaseAddr = 0x10000; size_t size = 0x1000; - GraphicsAllocation gfxAllocation(cpuPtr, gpuAddr, gpuBaseAddr, size, false); + GraphicsAllocation gfxAllocation(GraphicsAllocation::AllocationType::UNKNOWN, cpuPtr, gpuAddr, gpuBaseAddr, size, MemoryPool::MemoryNull, false); EXPECT_EQ(gpuAddr - gpuBaseAddr, gfxAllocation.getGpuAddressToPatch()); } @@ -115,7 +115,7 @@ TEST(GraphicsAllocationTest, setSize) { uint64_t gpuBaseAddr = 0x10000; size_t size = 0x2000; - GraphicsAllocation gfxAllocation(cpuPtr, gpuAddr, gpuBaseAddr, size, false); + GraphicsAllocation gfxAllocation(GraphicsAllocation::AllocationType::UNKNOWN, cpuPtr, gpuAddr, gpuBaseAddr, size, MemoryPool::MemoryNull, false); EXPECT_EQ(size, gfxAllocation.getUnderlyingBufferSize()); size = 0x3000; @@ -1516,7 +1516,7 @@ TEST(GraphicsAllocation, givenSharedHandleBasedConstructorWhenGraphicsAllocation void *addressWithTrailingBitSet = reinterpret_cast(address); uint64_t expectedGpuAddress = 0xf0000000; osHandle sharedHandle{}; - GraphicsAllocation graphicsAllocation(addressWithTrailingBitSet, 1u, sharedHandle, false); + GraphicsAllocation graphicsAllocation(GraphicsAllocation::AllocationType::UNKNOWN, addressWithTrailingBitSet, 1u, sharedHandle, MemoryPool::MemoryNull, false); EXPECT_EQ(expectedGpuAddress, graphicsAllocation.getGpuAddress()); } @@ -1620,27 +1620,27 @@ TEST(OsContextTest, givenOsContextWithNumberOfSupportedDevicesWhenConstructingTh } TEST(HeapSelectorTest, given32bitInternalAllocationWhenSelectingHeapThenInternalHeapIsUsed) { - GraphicsAllocation allocation{nullptr, 0, 0, 0, false}; + GraphicsAllocation allocation{GraphicsAllocation::AllocationType::UNKNOWN, nullptr, 0, 0, 0, MemoryPool::MemoryNull, false}; allocation.is32BitAllocation = true; allocation.setAllocationType(GraphicsAllocation::AllocationType::KERNEL_ISA); EXPECT_EQ(internalHeapIndex, MemoryManager::selectHeap(&allocation, nullptr, *platformDevices[0])); } TEST(HeapSelectorTest, givenNon32bitInternalAllocationWhenSelectingHeapThenInternalHeapIsUsed) { - GraphicsAllocation allocation{nullptr, 0, 0, 0, false}; + GraphicsAllocation allocation{GraphicsAllocation::AllocationType::UNKNOWN, nullptr, 0, 0, 0, MemoryPool::MemoryNull, false}; allocation.is32BitAllocation = false; allocation.setAllocationType(GraphicsAllocation::AllocationType::KERNEL_ISA); EXPECT_EQ(internalHeapIndex, MemoryManager::selectHeap(&allocation, nullptr, *platformDevices[0])); } TEST(HeapSelectorTest, given32bitExternalAllocationWhenSelectingHeapThenExternalHeapIsUsed) { - GraphicsAllocation allocation{nullptr, 0, 0, 0, false}; + GraphicsAllocation allocation{GraphicsAllocation::AllocationType::UNKNOWN, nullptr, 0, 0, 0, MemoryPool::MemoryNull, false}; allocation.is32BitAllocation = true; EXPECT_EQ(HeapIndex::HEAP_EXTERNAL, MemoryManager::selectHeap(&allocation, nullptr, *platformDevices[0])); } TEST(HeapSelectorTest, givenLimitedAddressSpaceWhenSelectingHeapForExternalAllocationThenLimitedHeapIsUsed) { - GraphicsAllocation allocation{nullptr, 0, 0, 0, false}; + GraphicsAllocation allocation{GraphicsAllocation::AllocationType::UNKNOWN, nullptr, 0, 0, 0, MemoryPool::MemoryNull, false}; if (platformDevices[0]->capabilityTable.gpuAddressSpace == MemoryConstants::max48BitAddress) { return; } @@ -1648,7 +1648,7 @@ TEST(HeapSelectorTest, givenLimitedAddressSpaceWhenSelectingHeapForExternalAlloc } TEST(HeapSelectorTest, givenFullAddressSpaceWhenSelectingHeapForExternalAllocationWithPtrThenSvmHeapIsUsed) { - GraphicsAllocation allocation{nullptr, 0, 0, 0, false}; + GraphicsAllocation allocation{GraphicsAllocation::AllocationType::UNKNOWN, nullptr, 0, 0, 0, MemoryPool::MemoryNull, false}; if (platformDevices[0]->capabilityTable.gpuAddressSpace != MemoryConstants::max48BitAddress) { return; } @@ -1656,7 +1656,7 @@ TEST(HeapSelectorTest, givenFullAddressSpaceWhenSelectingHeapForExternalAllocati } TEST(HeapSelectorTest, givenFullAddressSpaceWhenSelectingHeapForExternalAllocationWithoutPtrAndResourceIs64KSuitableThenStandard64kHeapIsUsed) { - GraphicsAllocation allocation{nullptr, 0, 0, 0, false}; + GraphicsAllocation allocation{GraphicsAllocation::AllocationType::UNKNOWN, nullptr, 0, 0, 0, MemoryPool::MemoryNull, false}; auto gmm = std::make_unique(nullptr, 0, false); auto resourceInfo = static_cast(gmm->gmmResourceInfo.get()); resourceInfo->is64KBPageSuitableValue = true; @@ -1668,7 +1668,7 @@ TEST(HeapSelectorTest, givenFullAddressSpaceWhenSelectingHeapForExternalAllocati } TEST(HeapSelectorTest, givenFullAddressSpaceWhenSelectingHeapForExternalAllocationWithoutPtrAndResourceIsNot64KSuitableThenStandardHeapIsUsed) { - GraphicsAllocation allocation{nullptr, 0, 0, 0, false}; + GraphicsAllocation allocation{GraphicsAllocation::AllocationType::UNKNOWN, nullptr, 0, 0, 0, MemoryPool::MemoryNull, false}; auto gmm = std::make_unique(nullptr, 0, false); auto resourceInfo = static_cast(gmm->gmmResourceInfo.get()); resourceInfo->is64KBPageSuitableValue = false; diff --git a/unit_tests/mocks/mock_graphics_allocation.h b/unit_tests/mocks/mock_graphics_allocation.h index bbafc314ec..eba0415dd4 100644 --- a/unit_tests/mocks/mock_graphics_allocation.h +++ b/unit_tests/mocks/mock_graphics_allocation.h @@ -16,10 +16,17 @@ class MockGraphicsAllocation : public GraphicsAllocation { using GraphicsAllocation::objectNotUsed; using GraphicsAllocation::usageInfos; - MockGraphicsAllocation() : MockGraphicsAllocation(true) {} - MockGraphicsAllocation(bool multiOsContextCapable) : GraphicsAllocation(nullptr, 0u, 0, multiOsContextCapable) {} - MockGraphicsAllocation(void *buffer, size_t sizeIn) : GraphicsAllocation(buffer, castToUint64(buffer), 0llu, sizeIn, false) {} - MockGraphicsAllocation(void *buffer, uint64_t gpuAddr, size_t sizeIn) : GraphicsAllocation(buffer, gpuAddr, 0llu, sizeIn, false) {} + MockGraphicsAllocation() + : MockGraphicsAllocation(true) {} + + MockGraphicsAllocation(bool multiOsContextCapable) + : GraphicsAllocation(AllocationType::UNKNOWN, nullptr, 0u, 0, MemoryPool::MemoryNull, multiOsContextCapable) {} + + MockGraphicsAllocation(void *buffer, size_t sizeIn) + : GraphicsAllocation(AllocationType::UNKNOWN, buffer, castToUint64(buffer), 0llu, sizeIn, MemoryPool::MemoryNull, false) {} + + MockGraphicsAllocation(void *buffer, uint64_t gpuAddr, size_t sizeIn) + : GraphicsAllocation(AllocationType::UNKNOWN, buffer, gpuAddr, 0llu, sizeIn, MemoryPool::MemoryNull, false) {} void resetInspectionIds() { for (auto &usageInfo : usageInfos) { diff --git a/unit_tests/os_interface/debug_settings_manager_tests.cpp b/unit_tests/os_interface/debug_settings_manager_tests.cpp index f76bd44a68..6a625091b0 100644 --- a/unit_tests/os_interface/debug_settings_manager_tests.cpp +++ b/unit_tests/os_interface/debug_settings_manager_tests.cpp @@ -865,35 +865,35 @@ TEST(DebugSettingsManager, givenReaderImplInDebugManagerWhenSettingDifferentRead } struct AllocationTypeTestCase { - OCLRT::GraphicsAllocation::AllocationType type; + GraphicsAllocation::AllocationType type; const char *str; }; AllocationTypeTestCase allocationTypeValues[] = { - {OCLRT::GraphicsAllocation::AllocationType::UNKNOWN, "UNKNOWN"}, - {OCLRT::GraphicsAllocation::AllocationType::BUFFER_COMPRESSED, "BUFFER_COMPRESSED"}, - {OCLRT::GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY, "BUFFER_HOST_MEMORY"}, - {OCLRT::GraphicsAllocation::AllocationType::BUFFER, "BUFFER"}, - {OCLRT::GraphicsAllocation::AllocationType::IMAGE, "IMAGE"}, - {OCLRT::GraphicsAllocation::AllocationType::TAG_BUFFER, "TAG_BUFFER"}, - {OCLRT::GraphicsAllocation::AllocationType::LINEAR_STREAM, "LINEAR_STREAM"}, - {OCLRT::GraphicsAllocation::AllocationType::FILL_PATTERN, "FILL_PATTERN"}, - {OCLRT::GraphicsAllocation::AllocationType::PIPE, "PIPE"}, - {OCLRT::GraphicsAllocation::AllocationType::TIMESTAMP_PACKET_TAG_BUFFER, "TIMESTAMP_PACKET_TAG_BUFFER"}, - {OCLRT::GraphicsAllocation::AllocationType::PROFILING_TAG_BUFFER, "PROFILING_TAG_BUFFER"}, - {OCLRT::GraphicsAllocation::AllocationType::COMMAND_BUFFER, "COMMAND_BUFFER"}, - {OCLRT::GraphicsAllocation::AllocationType::PRINTF_SURFACE, "PRINTF_SURFACE"}, - {OCLRT::GraphicsAllocation::AllocationType::GLOBAL_SURFACE, "GLOBAL_SURFACE"}, - {OCLRT::GraphicsAllocation::AllocationType::PRIVATE_SURFACE, "PRIVATE_SURFACE"}, - {OCLRT::GraphicsAllocation::AllocationType::CONSTANT_SURFACE, "CONSTANT_SURFACE"}, - {OCLRT::GraphicsAllocation::AllocationType::SCRATCH_SURFACE, "SCRATCH_SURFACE"}, - {OCLRT::GraphicsAllocation::AllocationType::INSTRUCTION_HEAP, "INSTRUCTION_HEAP"}, - {OCLRT::GraphicsAllocation::AllocationType::INDIRECT_OBJECT_HEAP, "INDIRECT_OBJECT_HEAP"}, - {OCLRT::GraphicsAllocation::AllocationType::SURFACE_STATE_HEAP, "SURFACE_STATE_HEAP"}, - {OCLRT::GraphicsAllocation::AllocationType::DYNAMIC_STATE_HEAP, "DYNAMIC_STATE_HEAP"}, - {OCLRT::GraphicsAllocation::AllocationType::SHARED_RESOURCE_COPY, "SHARED_RESOURCE_COPY"}, - {OCLRT::GraphicsAllocation::AllocationType::SVM, "SVM"}, - {OCLRT::GraphicsAllocation::AllocationType::UNDECIDED, "UNDECIDED"}}; + {GraphicsAllocation::AllocationType::UNKNOWN, "UNKNOWN"}, + {GraphicsAllocation::AllocationType::BUFFER_COMPRESSED, "BUFFER_COMPRESSED"}, + {GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY, "BUFFER_HOST_MEMORY"}, + {GraphicsAllocation::AllocationType::BUFFER, "BUFFER"}, + {GraphicsAllocation::AllocationType::IMAGE, "IMAGE"}, + {GraphicsAllocation::AllocationType::TAG_BUFFER, "TAG_BUFFER"}, + {GraphicsAllocation::AllocationType::LINEAR_STREAM, "LINEAR_STREAM"}, + {GraphicsAllocation::AllocationType::FILL_PATTERN, "FILL_PATTERN"}, + {GraphicsAllocation::AllocationType::PIPE, "PIPE"}, + {GraphicsAllocation::AllocationType::TIMESTAMP_PACKET_TAG_BUFFER, "TIMESTAMP_PACKET_TAG_BUFFER"}, + {GraphicsAllocation::AllocationType::PROFILING_TAG_BUFFER, "PROFILING_TAG_BUFFER"}, + {GraphicsAllocation::AllocationType::COMMAND_BUFFER, "COMMAND_BUFFER"}, + {GraphicsAllocation::AllocationType::PRINTF_SURFACE, "PRINTF_SURFACE"}, + {GraphicsAllocation::AllocationType::GLOBAL_SURFACE, "GLOBAL_SURFACE"}, + {GraphicsAllocation::AllocationType::PRIVATE_SURFACE, "PRIVATE_SURFACE"}, + {GraphicsAllocation::AllocationType::CONSTANT_SURFACE, "CONSTANT_SURFACE"}, + {GraphicsAllocation::AllocationType::SCRATCH_SURFACE, "SCRATCH_SURFACE"}, + {GraphicsAllocation::AllocationType::INSTRUCTION_HEAP, "INSTRUCTION_HEAP"}, + {GraphicsAllocation::AllocationType::INDIRECT_OBJECT_HEAP, "INDIRECT_OBJECT_HEAP"}, + {GraphicsAllocation::AllocationType::SURFACE_STATE_HEAP, "SURFACE_STATE_HEAP"}, + {GraphicsAllocation::AllocationType::DYNAMIC_STATE_HEAP, "DYNAMIC_STATE_HEAP"}, + {GraphicsAllocation::AllocationType::SHARED_RESOURCE_COPY, "SHARED_RESOURCE_COPY"}, + {GraphicsAllocation::AllocationType::SVM, "SVM"}, + {GraphicsAllocation::AllocationType::UNDECIDED, "UNDECIDED"}}; class AllocationTypeLogging : public ::testing::TestWithParam {}; @@ -901,8 +901,7 @@ TEST_P(AllocationTypeLogging, givenGraphicsAllocationTypeWhenConvertingToStringT FullyEnabledTestDebugManager debugManager; auto input = GetParam(); - GraphicsAllocation graphicsAllocation(nullptr, 0u, 0, true); - graphicsAllocation.setAllocationType(input.type); + GraphicsAllocation graphicsAllocation(input.type, nullptr, 0u, 0, MemoryPool::MemoryNull, true); auto result = debugManager.getAllocationTypeString(&graphicsAllocation); @@ -916,8 +915,7 @@ INSTANTIATE_TEST_CASE_P(AllAllocationTypes, TEST(AllocationTypeLoggingSingle, givenGraphicsAllocationTypeWhenConvertingToStringIllegalValueThenILLEGAL_VALUEIsReturned) { FullyEnabledTestDebugManager debugManager; - GraphicsAllocation graphicsAllocation(nullptr, 0u, 0, true); - graphicsAllocation.setAllocationType(static_cast(999)); + GraphicsAllocation graphicsAllocation(static_cast(999), nullptr, 0u, 0, MemoryPool::MemoryNull, true); auto result = debugManager.getAllocationTypeString(&graphicsAllocation); @@ -927,8 +925,7 @@ TEST(AllocationTypeLoggingSingle, givenGraphicsAllocationTypeWhenConvertingToStr TEST(AllocationTypeLoggingSingle, givenGraphicsAllocationTypeWhenDebugManagerDisabledThennullptrReturned) { FullyDisabledTestDebugManager debugManager; - GraphicsAllocation graphicsAllocation(nullptr, 0u, 0, true); - graphicsAllocation.setAllocationType(OCLRT::GraphicsAllocation::AllocationType::BUFFER); + GraphicsAllocation graphicsAllocation(GraphicsAllocation::AllocationType::BUFFER, nullptr, 0u, 0, MemoryPool::MemoryNull, true); auto result = debugManager.getAllocationTypeString(&graphicsAllocation); @@ -936,6 +933,6 @@ TEST(AllocationTypeLoggingSingle, givenGraphicsAllocationTypeWhenDebugManagerDis } TEST(AllocationInfoLogging, givenBaseGraphicsAllocationWhenGettingImplementationSpecificAllocationInfoThenReturnEmptyInfoString) { - GraphicsAllocation graphicsAllocation(nullptr, 0u, 0, true); + GraphicsAllocation graphicsAllocation(GraphicsAllocation::AllocationType::UNKNOWN, nullptr, 0u, 0, MemoryPool::MemoryNull, true); EXPECT_STREQ(graphicsAllocation.getAllocationInfoString().c_str(), ""); }