diff --git a/core/command_container/cmdcontainer.cpp b/core/command_container/cmdcontainer.cpp index 92632ecab9..5622311b37 100644 --- a/core/command_container/cmdcontainer.cpp +++ b/core/command_container/cmdcontainer.cpp @@ -64,18 +64,15 @@ bool CommandContainer::initialize(Device *device) { commandStream->replaceGraphicsAllocation(cmdBufferAllocation); addToResidencyContainer(cmdBufferAllocation); - size_t heapSize = 65536u; + constexpr size_t heapSize = 65536u; - for (auto &allocationIndirectHeap : allocationIndirectHeaps) { - allocationIndirectHeap = heapHelper->getHeapAllocation(heapSize, alignedSize, 0u); - UNRECOVERABLE_IF(!allocationIndirectHeap); - residencyContainer.push_back(allocationIndirectHeap); - } + for (uint32_t i = 0; i < IndirectHeap::Type::NUM_TYPES; i++) { + allocationIndirectHeaps[i] = heapHelper->getHeapAllocation(i, heapSize, alignedSize, 0u); + UNRECOVERABLE_IF(!allocationIndirectHeaps[i]); + residencyContainer.push_back(allocationIndirectHeaps[i]); - uint32_t index = 0; - for (auto &indirectHeap : indirectHeaps) { - auto alloc = allocationIndirectHeaps[index++]; - indirectHeap = std::make_unique(alloc); + bool requireInternalHeap = (IndirectHeap::INDIRECT_OBJECT == i); + indirectHeaps[i] = std::make_unique(allocationIndirectHeaps[i], requireInternalHeap); } instructionHeapBaseAddress = device->getMemoryManager()->getInternalHeapBaseAddress(0); diff --git a/core/helpers/heap_helper.cpp b/core/helpers/heap_helper.cpp index 129249ba63..fe2d2d99d8 100644 --- a/core/helpers/heap_helper.cpp +++ b/core/helpers/heap_helper.cpp @@ -7,17 +7,24 @@ #include "core/helpers/heap_helper.h" +#include "core/indirect_heap/indirect_heap.h" #include "core/memory_manager/graphics_allocation.h" #include "runtime/memory_manager/internal_allocation_storage.h" #include "runtime/memory_manager/memory_manager.h" namespace NEO { -GraphicsAllocation *HeapHelper::getHeapAllocation(size_t heapSize, size_t alignment, uint32_t rootDeviceIndex) { - auto allocation = this->storageForReuse->obtainReusableAllocation(heapSize, GraphicsAllocation::AllocationType::INTERNAL_HEAP); + +GraphicsAllocation *HeapHelper::getHeapAllocation(uint32_t heapType, size_t heapSize, size_t alignment, uint32_t rootDeviceIndex) { + auto allocationType = GraphicsAllocation::AllocationType::LINEAR_STREAM; + if (IndirectHeap::Type::INDIRECT_OBJECT == heapType) { + allocationType = GraphicsAllocation::AllocationType::INTERNAL_HEAP; + } + + auto allocation = this->storageForReuse->obtainReusableAllocation(heapSize, allocationType); if (allocation) { return allocation.release(); } - NEO::AllocationProperties properties{rootDeviceIndex, true, heapSize, GraphicsAllocation::AllocationType::INTERNAL_HEAP, isMultiOsContextCapable, false, {}}; + NEO::AllocationProperties properties{rootDeviceIndex, true, heapSize, allocationType, isMultiOsContextCapable, false, {}}; properties.alignment = alignment; return this->memManager->allocateGraphicsMemoryWithProperties(properties); diff --git a/core/helpers/heap_helper.h b/core/helpers/heap_helper.h index 40e07715cb..15b4981c1f 100644 --- a/core/helpers/heap_helper.h +++ b/core/helpers/heap_helper.h @@ -20,7 +20,7 @@ class HeapHelper { HeapHelper(MemoryManager *memManager, InternalAllocationStorage *storageForReuse, bool isMultiOsContextCapable) : storageForReuse(storageForReuse), memManager(memManager), isMultiOsContextCapable(isMultiOsContextCapable) {} - GraphicsAllocation *getHeapAllocation(size_t heapSize, size_t alignment, uint32_t rootDeviceIndex); + GraphicsAllocation *getHeapAllocation(uint32_t heapType, size_t heapSize, size_t alignment, uint32_t rootDeviceIndex); void storeHeapAllocation(GraphicsAllocation *heapAllocation); protected: diff --git a/core/indirect_heap/indirect_heap.h b/core/indirect_heap/indirect_heap.h index ed0a7b86aa..fe0b3a79f8 100644 --- a/core/indirect_heap/indirect_heap.h +++ b/core/indirect_heap/indirect_heap.h @@ -24,7 +24,6 @@ class IndirectHeap : public LinearStream { public: enum Type { DYNAMIC_STATE = 0, - GENERAL_STATE, INDIRECT_OBJECT, SURFACE_STATE, NUM_TYPES diff --git a/core/unit_tests/command_container/command_container_tests.cpp b/core/unit_tests/command_container/command_container_tests.cpp index 887e9df685..2a3d0edb50 100644 --- a/core/unit_tests/command_container/command_container_tests.cpp +++ b/core/unit_tests/command_container/command_container_tests.cpp @@ -80,6 +80,24 @@ TEST_F(CommandContainerHeapStateTests, givenDirtyHeapsWhenSettingStateForSingleH } } +TEST_F(CommandContainerTest, givenCmdContainerWhenAllocatingHeapsThenSetCorrectAllocationTypes) { + CommandContainer cmdContainer; + cmdContainer.initialize(pDevice); + + for (uint32_t i = 0; i < HeapType::NUM_TYPES; i++) { + HeapType heapType = static_cast(i); + auto heap = cmdContainer.getIndirectHeap(heapType); + + if (HeapType::INDIRECT_OBJECT == heapType) { + EXPECT_EQ(GraphicsAllocation::AllocationType::INTERNAL_HEAP, heap->getGraphicsAllocation()->getAllocationType()); + EXPECT_NE(0u, heap->getHeapGpuStartOffset()); + } else { + EXPECT_EQ(GraphicsAllocation::AllocationType::LINEAR_STREAM, heap->getGraphicsAllocation()->getAllocationType()); + EXPECT_EQ(0u, heap->getHeapGpuStartOffset()); + } + } +} + TEST_F(CommandContainerTest, givenCommandContainerWhenInitializeThenEverythingIsInitialized) { CommandContainer cmdContainer; auto status = cmdContainer.initialize(pDevice); diff --git a/unit_tests/command_queue/command_queue_tests.cpp b/unit_tests/command_queue/command_queue_tests.cpp index 380cdda14f..0a8191ef24 100644 --- a/unit_tests/command_queue/command_queue_tests.cpp +++ b/unit_tests/command_queue/command_queue_tests.cpp @@ -753,7 +753,6 @@ INSTANTIATE_TEST_CASE_P( CommandQueueIndirectHeapTest, testing::Values( IndirectHeap::DYNAMIC_STATE, - IndirectHeap::GENERAL_STATE, IndirectHeap::INDIRECT_OBJECT, IndirectHeap::SURFACE_STATE)); diff --git a/unit_tests/command_stream/command_stream_receiver_tests.cpp b/unit_tests/command_stream/command_stream_receiver_tests.cpp index 2484e358be..8e607d7c1d 100644 --- a/unit_tests/command_stream/command_stream_receiver_tests.cpp +++ b/unit_tests/command_stream/command_stream_receiver_tests.cpp @@ -675,7 +675,7 @@ TEST(CommandStreamReceiverRootDeviceIndexTest, commandStreamGraphicsAllocationsH EXPECT_EQ(expectedRootDeviceIndex, debugSurface->getRootDeviceIndex()); // Indirect heaps - IndirectHeap::Type heapTypes[]{IndirectHeap::DYNAMIC_STATE, IndirectHeap::GENERAL_STATE, IndirectHeap::INDIRECT_OBJECT, IndirectHeap::SURFACE_STATE}; + IndirectHeap::Type heapTypes[]{IndirectHeap::DYNAMIC_STATE, IndirectHeap::INDIRECT_OBJECT, IndirectHeap::SURFACE_STATE}; for (auto heapType : heapTypes) { IndirectHeap *heap = nullptr; commandStreamReceiver->allocateHeapMemory(heapType, MemoryConstants::pageSize, heap); @@ -702,4 +702,4 @@ TEST(CommandStreamReceiverRootDeviceIndexTest, commandStreamGraphicsAllocationsH EXPECT_TRUE(commandStreamReceiver->createAllocationForHostSurface(surface, false)); ASSERT_NE(nullptr, surface.getAllocation()); EXPECT_EQ(expectedRootDeviceIndex, surface.getAllocation()->getRootDeviceIndex()); -} \ No newline at end of file +}