2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2023-02-03 02:57:24 +08:00
|
|
|
* Copyright (C) 2019-2023 Intel Corporation
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
2018-09-18 15:11:08 +08:00
|
|
|
* SPDX-License-Identifier: MIT
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/command_stream/linear_stream.h"
|
|
|
|
#include "shared/source/helpers/aligned_memory.h"
|
2020-04-02 17:28:38 +08:00
|
|
|
#include "shared/source/helpers/constants.h"
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/helpers/ptr_math.h"
|
2022-01-26 18:59:30 +08:00
|
|
|
#include "shared/source/indirect_heap/indirect_heap_type.h"
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/memory_manager/graphics_allocation.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
namespace NEO {
|
2020-10-09 17:52:12 +08:00
|
|
|
|
2022-12-08 22:23:49 +08:00
|
|
|
inline constexpr size_t defaultHeapSize = 64 * KB;
|
2018-01-31 21:45:42 +08:00
|
|
|
|
2022-02-09 20:33:43 +08:00
|
|
|
inline size_t getDefaultHeapSize() {
|
|
|
|
auto defaultSize = defaultHeapSize;
|
|
|
|
if (DebugManager.flags.ForceDefaultHeapSize.get() != -1) {
|
|
|
|
defaultSize = DebugManager.flags.ForceDefaultHeapSize.get() * MemoryConstants::kiloByte;
|
|
|
|
}
|
|
|
|
return defaultSize;
|
|
|
|
}
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
class IndirectHeap : public LinearStream {
|
2022-05-18 03:04:23 +08:00
|
|
|
using BaseClass = LinearStream;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
public:
|
2022-01-26 18:59:30 +08:00
|
|
|
using Type = IndirectHeapType;
|
2023-02-03 02:57:24 +08:00
|
|
|
IndirectHeap(void *buffer, size_t bufferSize) : BaseClass(buffer, bufferSize){};
|
2019-12-03 04:04:32 +08:00
|
|
|
IndirectHeap(GraphicsAllocation *graphicsAllocation) : BaseClass(graphicsAllocation) {}
|
|
|
|
IndirectHeap(GraphicsAllocation *graphicsAllocation, bool canBeUtilizedAs4GbHeap)
|
|
|
|
: BaseClass(graphicsAllocation), canBeUtilizedAs4GbHeap(canBeUtilizedAs4GbHeap) {}
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
// Disallow copy'ing
|
|
|
|
IndirectHeap(const IndirectHeap &) = delete;
|
|
|
|
IndirectHeap &operator=(const IndirectHeap &) = delete;
|
|
|
|
|
|
|
|
void align(size_t alignment);
|
2018-04-18 18:42:08 +08:00
|
|
|
uint64_t getHeapGpuStartOffset() const;
|
|
|
|
uint64_t getHeapGpuBase() const;
|
2023-02-03 02:57:24 +08:00
|
|
|
virtual uint32_t getHeapSizeInPages() const;
|
2018-04-16 21:26:45 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
bool canBeUtilizedAs4GbHeap = false;
|
2017-12-21 07:45:38 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
inline void IndirectHeap::align(size_t alignment) {
|
|
|
|
auto address = alignUp(ptrOffset(buffer, sizeUsed), alignment);
|
|
|
|
sizeUsed = ptrDiff(address, buffer);
|
|
|
|
}
|
2018-07-14 00:50:55 +08:00
|
|
|
|
|
|
|
inline uint32_t IndirectHeap::getHeapSizeInPages() const {
|
|
|
|
if (this->canBeUtilizedAs4GbHeap) {
|
|
|
|
return MemoryConstants::sizeOf4GBinPageEntities;
|
|
|
|
} else {
|
|
|
|
return (static_cast<uint32_t>(getMaxAvailableSpace()) + MemoryConstants::pageMask) / MemoryConstants::pageSize;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-18 18:42:08 +08:00
|
|
|
inline uint64_t IndirectHeap::getHeapGpuStartOffset() const {
|
2018-04-16 21:26:45 +08:00
|
|
|
if (this->canBeUtilizedAs4GbHeap) {
|
|
|
|
return this->graphicsAllocation->getGpuAddressToPatch();
|
|
|
|
} else {
|
|
|
|
return 0llu;
|
|
|
|
}
|
|
|
|
}
|
2018-07-14 00:50:55 +08:00
|
|
|
|
2018-04-18 18:42:08 +08:00
|
|
|
inline uint64_t IndirectHeap::getHeapGpuBase() const {
|
2018-04-17 14:08:00 +08:00
|
|
|
if (this->canBeUtilizedAs4GbHeap) {
|
2019-02-27 21:59:46 +08:00
|
|
|
return this->graphicsAllocation->getGpuBaseAddress();
|
2018-04-17 14:08:00 +08:00
|
|
|
} else {
|
|
|
|
return this->graphicsAllocation->getGpuAddress();
|
|
|
|
}
|
|
|
|
}
|
2023-02-03 02:57:24 +08:00
|
|
|
|
|
|
|
class ReservedIndirectHeap : public IndirectHeap {
|
|
|
|
public:
|
|
|
|
ReservedIndirectHeap(void *buffer, size_t bufferSize) : IndirectHeap(buffer, bufferSize) {}
|
|
|
|
ReservedIndirectHeap(GraphicsAllocation *graphicsAllocation) : IndirectHeap(graphicsAllocation) {}
|
|
|
|
ReservedIndirectHeap(GraphicsAllocation *graphicsAllocation, bool canBeUtilizedAs4GbHeap)
|
|
|
|
: IndirectHeap(graphicsAllocation, canBeUtilizedAs4GbHeap) {}
|
|
|
|
|
|
|
|
// Disallow copy'ing
|
|
|
|
ReservedIndirectHeap(const ReservedIndirectHeap &) = delete;
|
|
|
|
ReservedIndirectHeap &operator=(const ReservedIndirectHeap &) = delete;
|
|
|
|
|
|
|
|
uint32_t getHeapSizeInPages() const override {
|
|
|
|
return parentHeapSizeInPages;
|
|
|
|
}
|
|
|
|
void setHeapSizeInPages(uint32_t value) {
|
|
|
|
parentHeapSizeInPages = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
uint32_t parentHeapSizeInPages = 0;
|
|
|
|
};
|
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
} // namespace NEO
|