2019-11-18 15:12:22 +01:00
|
|
|
/*
|
2024-08-01 11:49:25 +00:00
|
|
|
* Copyright (C) 2019-2024 Intel Corporation
|
2019-11-18 15:12:22 +01:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2020-02-23 22:44:01 +01:00
|
|
|
#include "shared/source/helpers/heap_helper.h"
|
2019-11-18 15:12:22 +01:00
|
|
|
|
2020-02-23 22:44:01 +01:00
|
|
|
#include "shared/source/indirect_heap/indirect_heap.h"
|
2022-12-06 11:19:36 +00:00
|
|
|
#include "shared/source/memory_manager/allocation_properties.h"
|
2020-02-23 22:44:01 +01:00
|
|
|
#include "shared/source/memory_manager/graphics_allocation.h"
|
|
|
|
|
#include "shared/source/memory_manager/internal_allocation_storage.h"
|
|
|
|
|
#include "shared/source/memory_manager/memory_manager.h"
|
2019-11-18 15:12:22 +01:00
|
|
|
|
|
|
|
|
namespace NEO {
|
2019-12-17 07:57:45 +01:00
|
|
|
|
|
|
|
|
GraphicsAllocation *HeapHelper::getHeapAllocation(uint32_t heapType, size_t heapSize, size_t alignment, uint32_t rootDeviceIndex) {
|
2023-12-11 14:24:36 +00:00
|
|
|
auto allocationType = AllocationType::linearStream;
|
2023-12-13 16:09:52 +00:00
|
|
|
if (IndirectHeap::Type::indirectObject == heapType) {
|
2023-12-11 14:24:36 +00:00
|
|
|
allocationType = AllocationType::internalHeap;
|
2019-12-17 07:57:45 +01:00
|
|
|
}
|
|
|
|
|
|
2024-08-01 11:49:25 +00:00
|
|
|
if (NEO::debugManager.flags.AlignLocalMemoryVaTo2MB.get() == 1) {
|
|
|
|
|
alignment = MemoryConstants::pageSize2M;
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-17 07:57:45 +01:00
|
|
|
auto allocation = this->storageForReuse->obtainReusableAllocation(heapSize, allocationType);
|
2019-11-18 15:12:22 +01:00
|
|
|
if (allocation) {
|
|
|
|
|
return allocation.release();
|
|
|
|
|
}
|
2020-06-23 11:30:01 +02:00
|
|
|
NEO::AllocationProperties properties{rootDeviceIndex, true, heapSize, allocationType, isMultiOsContextCapable, false, storageForReuse->getDeviceBitfield()};
|
2019-12-12 11:51:23 +01:00
|
|
|
properties.alignment = alignment;
|
2019-11-18 15:12:22 +01:00
|
|
|
|
|
|
|
|
return this->memManager->allocateGraphicsMemoryWithProperties(properties);
|
|
|
|
|
}
|
|
|
|
|
void HeapHelper::storeHeapAllocation(GraphicsAllocation *heapAllocation) {
|
2020-10-20 19:04:58 +05:30
|
|
|
if (heapAllocation) {
|
|
|
|
|
this->storageForReuse->storeAllocation(std::unique_ptr<NEO::GraphicsAllocation>(heapAllocation), NEO::AllocationUsage::REUSABLE_ALLOCATION);
|
|
|
|
|
}
|
2019-11-18 15:12:22 +01:00
|
|
|
}
|
2019-12-10 12:16:07 +01:00
|
|
|
} // namespace NEO
|