2020-10-19 16:02:28 +08:00
|
|
|
/*
|
2023-06-27 01:49:16 +08:00
|
|
|
* Copyright (C) 2020-2023 Intel Corporation
|
2020-10-19 16:02:28 +08:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
#include "shared/source/helpers/constants.h"
|
|
|
|
#include "shared/source/helpers/heap_helper.h"
|
2023-07-21 19:55:22 +08:00
|
|
|
#include "shared/source/memory_manager/graphics_allocation.h"
|
2020-10-19 16:02:28 +08:00
|
|
|
|
2023-08-25 22:28:27 +08:00
|
|
|
#include <array>
|
2020-10-19 16:02:28 +08:00
|
|
|
#include <memory>
|
2021-01-27 21:31:29 +08:00
|
|
|
#include <mutex>
|
2020-10-19 16:02:28 +08:00
|
|
|
#include <unordered_map>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace NEO {
|
|
|
|
|
|
|
|
class IndirectHeap;
|
|
|
|
class BindlessHeapsHelper {
|
|
|
|
public:
|
2020-11-03 18:42:35 +08:00
|
|
|
enum BindlesHeapType {
|
|
|
|
SPECIAL_SSH = 0,
|
|
|
|
GLOBAL_SSH,
|
|
|
|
GLOBAL_DSH,
|
|
|
|
NUM_HEAP_TYPES
|
|
|
|
};
|
2021-10-05 18:30:14 +08:00
|
|
|
BindlessHeapsHelper(MemoryManager *memManager, bool isMultiOsContextCapable, const uint32_t rootDeviceIndex, DeviceBitfield deviceBitfield);
|
2023-07-31 22:33:30 +08:00
|
|
|
MOCKABLE_VIRTUAL ~BindlessHeapsHelper();
|
2022-05-18 03:04:23 +08:00
|
|
|
|
|
|
|
BindlessHeapsHelper(const BindlessHeapsHelper &) = delete;
|
|
|
|
BindlessHeapsHelper &operator=(const BindlessHeapsHelper &) = delete;
|
|
|
|
|
2020-11-03 18:42:35 +08:00
|
|
|
GraphicsAllocation *getHeapAllocation(size_t heapSize, size_t alignment, bool allocInFrontWindow);
|
2020-10-19 16:02:28 +08:00
|
|
|
|
2023-07-31 22:33:30 +08:00
|
|
|
MOCKABLE_VIRTUAL SurfaceStateInHeapInfo allocateSSInHeap(size_t ssSize, GraphicsAllocation *surfaceAllocation, BindlesHeapType heapType);
|
2020-11-03 18:42:35 +08:00
|
|
|
uint64_t getGlobalHeapsBase();
|
|
|
|
void *getSpaceInHeap(size_t ssSize, BindlesHeapType heapType);
|
2021-05-17 18:08:54 +08:00
|
|
|
uint32_t getDefaultBorderColorOffset();
|
|
|
|
uint32_t getAlphaBorderColorOffset();
|
2020-11-26 17:04:26 +08:00
|
|
|
IndirectHeap *getHeap(BindlesHeapType heapType);
|
2023-08-25 22:28:27 +08:00
|
|
|
void releaseSSToReusePool(const SurfaceStateInHeapInfo &surfStateInfo);
|
2023-06-27 01:49:16 +08:00
|
|
|
bool isGlobalDshSupported() {
|
|
|
|
return globalBindlessDsh;
|
|
|
|
}
|
2020-10-19 16:02:28 +08:00
|
|
|
|
2023-08-17 16:17:57 +08:00
|
|
|
int getReusedSshVectorIndex(size_t ssSize) {
|
|
|
|
int index = 0;
|
|
|
|
if (ssSize == 2 * surfaceStateSize) {
|
|
|
|
index = 1;
|
|
|
|
} else {
|
|
|
|
UNRECOVERABLE_IF(ssSize != surfaceStateSize);
|
|
|
|
}
|
|
|
|
return index;
|
|
|
|
}
|
2023-08-25 22:28:27 +08:00
|
|
|
bool getStateDirtyForContext(uint32_t osContextId);
|
|
|
|
void clearStateDirtyForContext(uint32_t osContextId);
|
2023-08-17 16:17:57 +08:00
|
|
|
|
2020-10-19 16:02:28 +08:00
|
|
|
protected:
|
2023-08-17 16:17:57 +08:00
|
|
|
const size_t surfaceStateSize;
|
2023-07-21 19:55:22 +08:00
|
|
|
bool growHeap(BindlesHeapType heapType);
|
2020-10-19 16:02:28 +08:00
|
|
|
MemoryManager *memManager = nullptr;
|
|
|
|
bool isMultiOsContextCapable = false;
|
|
|
|
const uint32_t rootDeviceIndex;
|
2020-11-03 18:42:35 +08:00
|
|
|
std::unique_ptr<IndirectHeap> surfaceStateHeaps[BindlesHeapType::NUM_HEAP_TYPES];
|
2020-10-19 16:02:28 +08:00
|
|
|
GraphicsAllocation *borderColorStates;
|
|
|
|
std::vector<GraphicsAllocation *> ssHeapsAllocations;
|
2023-08-25 22:28:27 +08:00
|
|
|
|
|
|
|
size_t reuseSlotCountThreshold = 512;
|
|
|
|
uint32_t allocatePoolIndex = 0;
|
|
|
|
uint32_t releasePoolIndex = 0;
|
|
|
|
bool allocateFromReusePool = false;
|
|
|
|
std::array<std::vector<SurfaceStateInHeapInfo>, 2> surfaceStateInHeapVectorReuse[2];
|
|
|
|
std::bitset<64> stateCacheDirtyForContext;
|
|
|
|
|
2021-01-27 21:31:29 +08:00
|
|
|
std::mutex mtx;
|
2021-10-05 18:30:14 +08:00
|
|
|
DeviceBitfield deviceBitfield;
|
2023-06-27 01:49:16 +08:00
|
|
|
bool globalBindlessDsh = false;
|
2020-10-19 16:02:28 +08:00
|
|
|
};
|
2022-05-18 03:04:23 +08:00
|
|
|
} // namespace NEO
|