2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2019-02-27 18:39:32 +08:00
|
|
|
* Copyright (C) 2017-2019 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
|
2019-08-22 22:51:02 +08:00
|
|
|
#include "core/command_stream/linear_stream.h"
|
2019-08-03 04:25:45 +08:00
|
|
|
#include "core/helpers/aligned_memory.h"
|
2019-05-13 18:53:40 +08:00
|
|
|
#include "core/helpers/basic_math.h"
|
2019-05-29 10:09:40 +08:00
|
|
|
#include "core/helpers/ptr_math.h"
|
2019-09-18 03:26:09 +08:00
|
|
|
#include "core/memory_manager/graphics_allocation.h"
|
2019-09-04 16:58:52 +08:00
|
|
|
#include "core/memory_manager/memory_constants.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
namespace NEO {
|
2017-12-21 07:45:38 +08:00
|
|
|
class GraphicsAllocation;
|
|
|
|
|
2018-01-31 21:45:42 +08:00
|
|
|
constexpr size_t defaultHeapSize = 64 * KB;
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
class IndirectHeap : public LinearStream {
|
|
|
|
typedef LinearStream BaseClass;
|
|
|
|
|
|
|
|
public:
|
|
|
|
enum Type {
|
|
|
|
DYNAMIC_STATE = 0,
|
|
|
|
GENERAL_STATE,
|
|
|
|
INDIRECT_OBJECT,
|
|
|
|
SURFACE_STATE,
|
|
|
|
NUM_TYPES
|
|
|
|
};
|
|
|
|
|
|
|
|
IndirectHeap(void *buffer, size_t bufferSize);
|
|
|
|
IndirectHeap(GraphicsAllocation *buffer);
|
2018-04-16 21:26:45 +08:00
|
|
|
IndirectHeap(GraphicsAllocation *buffer, bool 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;
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
2019-03-26 18:59:46 +08:00
|
|
|
} // namespace NEO
|