1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217
|
/*
* Copyright (C) 2021-2025 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/command_stream/scratch_space_controller_xehp_and_later.h"
#include "shared/source/command_stream/command_stream_receiver.h"
#include "shared/source/debug_settings/debug_settings_manager.h"
#include "shared/source/execution_environment/execution_environment.h"
#include "shared/source/execution_environment/root_device_environment.h"
#include "shared/source/helpers/aligned_memory.h"
#include "shared/source/helpers/api_specific_config.h"
#include "shared/source/helpers/basic_math.h"
#include "shared/source/helpers/constants.h"
#include "shared/source/helpers/gfx_core_helper.h"
#include "shared/source/memory_manager/allocation_properties.h"
#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"
#include "shared/source/os_interface/os_context.h"
#include "shared/source/os_interface/product_helper.h"
namespace NEO {
ScratchSpaceControllerXeHPAndLater::ScratchSpaceControllerXeHPAndLater(uint32_t rootDeviceIndex,
ExecutionEnvironment &environment,
InternalAllocationStorage &allocationStorage)
: ScratchSpaceController(rootDeviceIndex, environment, allocationStorage) {
auto &gfxCoreHelper = environment.rootDeviceEnvironments[rootDeviceIndex]->getHelper<GfxCoreHelper>();
singleSurfaceStateSize = gfxCoreHelper.getRenderSurfaceStateSize();
if (debugManager.flags.EnablePrivateScratchSlot1.get() != -1) {
twoSlotScratchSpaceSupported = !!debugManager.flags.EnablePrivateScratchSlot1.get();
}
if (twoSlotScratchSpaceSupported) {
ScratchSpaceControllerXeHPAndLater::stateSlotsCount *= 2;
}
}
void ScratchSpaceControllerXeHPAndLater::setNewSshPtr(void *newSsh, bool &cfeDirty, bool changeId) {
if (surfaceStateHeap != newSsh) {
surfaceStateHeap = static_cast<char *>(newSsh);
if (scratchSlot0Allocation == nullptr) {
cfeDirty = false;
} else {
if (changeId) {
slotId = 0;
}
programSurfaceState();
cfeDirty = true;
}
}
}
void ScratchSpaceControllerXeHPAndLater::setRequiredScratchSpace(void *sshBaseAddress,
uint32_t offset,
uint32_t requiredPerThreadScratchSizeSlot0,
uint32_t requiredPerThreadScratchSizeSlot1,
OsContext &osContext,
bool &stateBaseAddressDirty,
bool &vfeStateDirty) {
setNewSshPtr(sshBaseAddress, vfeStateDirty, offset == 0 ? true : false);
bool scratchSurfaceDirty = false;
prepareScratchAllocation(requiredPerThreadScratchSizeSlot0, requiredPerThreadScratchSizeSlot1, osContext, stateBaseAddressDirty, scratchSurfaceDirty, vfeStateDirty);
if (scratchSurfaceDirty) {
vfeStateDirty = true;
updateSlots = true;
programSurfaceState();
}
}
void ScratchSpaceControllerXeHPAndLater::programSurfaceState() {
if (updateSlots) {
slotId++;
}
UNRECOVERABLE_IF(slotId >= stateSlotsCount);
UNRECOVERABLE_IF(scratchSlot0Allocation == nullptr && scratchSlot1Allocation == nullptr);
void *surfaceStateForScratchAllocation = ptrOffset(static_cast<void *>(surfaceStateHeap), getOffsetToSurfaceState(slotId + sshOffset));
programSurfaceStateAtPtr(surfaceStateForScratchAllocation);
}
void ScratchSpaceControllerXeHPAndLater::programSurfaceStateAtPtr(void *surfaceStateForScratchAllocation) {
auto &gfxCoreHelper = executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->getHelper<GfxCoreHelper>();
uint64_t scratchAllocationAddress = 0u;
if (scratchSlot0Allocation) {
scratchAllocationAddress = scratchSlot0Allocation->getGpuAddress();
}
gfxCoreHelper.setRenderSurfaceStateForScratchResource(*executionEnvironment.rootDeviceEnvironments[rootDeviceIndex],
surfaceStateForScratchAllocation, computeUnitsUsedForScratch, scratchAllocationAddress, 0,
perThreadScratchSpaceSlot0Size, nullptr, false, scratchType, false, true);
if (twoSlotScratchSpaceSupported) {
void *surfaceStateForSlot1Allocation = ptrOffset(surfaceStateForScratchAllocation, singleSurfaceStateSize);
uint64_t scratchSlot1AllocationAddress = 0u;
if (scratchSlot1Allocation) {
scratchSlot1AllocationAddress = scratchSlot1Allocation->getGpuAddress();
}
gfxCoreHelper.setRenderSurfaceStateForScratchResource(*executionEnvironment.rootDeviceEnvironments[rootDeviceIndex],
surfaceStateForSlot1Allocation, computeUnitsUsedForScratch,
scratchSlot1AllocationAddress, 0, perThreadScratchSpaceSlot1Size, nullptr, false,
scratchType, false, true);
}
}
uint64_t ScratchSpaceControllerXeHPAndLater::calculateNewGSH() {
return 0u;
}
uint64_t ScratchSpaceControllerXeHPAndLater::getScratchPatchAddress() {
uint64_t scratchAddress = 0u;
if (scratchSlot0Allocation || scratchSlot1Allocation) {
scratchAddress = static_cast<uint64_t>(getOffsetToSurfaceState(slotId + sshOffset));
}
return scratchAddress;
}
size_t ScratchSpaceControllerXeHPAndLater::getOffsetToSurfaceState(uint32_t requiredSlotCount) const {
auto offset = requiredSlotCount * singleSurfaceStateSize;
if (twoSlotScratchSpaceSupported) {
offset *= 2;
}
return offset;
}
void ScratchSpaceControllerXeHPAndLater::reserveHeap(IndirectHeap::Type heapType, IndirectHeap *&indirectHeap) {
if (heapType == IndirectHeap::Type::surfaceState) {
indirectHeap->getSpace(getOffsetToSurfaceState(stateSlotsCount));
}
}
void ScratchSpaceControllerXeHPAndLater::programBindlessSurfaceStateForScratch(BindlessHeapsHelper *heapsHelper,
uint32_t requiredPerThreadScratchSizeSlot0,
uint32_t requiredPerThreadScratchSizeSlot1,
OsContext &osContext,
bool &stateBaseAddressDirty,
bool &vfeStateDirty,
NEO::CommandStreamReceiver *csr) {
bool scratchSurfaceDirty = false;
prepareScratchAllocation(requiredPerThreadScratchSizeSlot0, requiredPerThreadScratchSizeSlot1, osContext, stateBaseAddressDirty, scratchSurfaceDirty, vfeStateDirty);
if (scratchSurfaceDirty) {
bindlessSS = heapsHelper->allocateSSInHeap(singleSurfaceStateSize * (twoSlotScratchSpaceSupported ? 2 : 1), scratchSlot0Allocation, BindlessHeapsHelper::specialSsh);
programSurfaceStateAtPtr(bindlessSS.ssPtr);
vfeStateDirty = true;
}
if (bindlessSS.heapAllocation) {
csr->makeResident(*bindlessSS.heapAllocation);
}
}
void ScratchSpaceControllerXeHPAndLater::prepareScratchAllocation(uint32_t requiredPerThreadScratchSizeSlot0,
uint32_t requiredPerThreadScratchSizeSlot1,
OsContext &osContext,
bool &stateBaseAddressDirty,
bool &scratchSurfaceDirty,
bool &vfeStateDirty) {
uint32_t requiredPerThreadScratchSizeSlot0AlignedUp = requiredPerThreadScratchSizeSlot0;
if (!Math::isPow2(requiredPerThreadScratchSizeSlot0AlignedUp)) {
requiredPerThreadScratchSizeSlot0AlignedUp = Math::nextPowerOfTwo(requiredPerThreadScratchSizeSlot0);
}
auto &productHelper = executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->getHelper<ProductHelper>();
size_t requiredScratchSizeInBytes = static_cast<size_t>(requiredPerThreadScratchSizeSlot0AlignedUp) * computeUnitsUsedForScratch;
productHelper.adjustScratchSize(requiredScratchSizeInBytes);
scratchSurfaceDirty = false;
auto multiTileCapable = osContext.getNumSupportedDevices() > 1;
if (scratchSlot0SizeInBytes < requiredScratchSizeInBytes) {
if (scratchSlot0Allocation) {
csrAllocationStorage.storeAllocation(std::unique_ptr<GraphicsAllocation>(scratchSlot0Allocation), TEMPORARY_ALLOCATION);
}
scratchSurfaceDirty = true;
scratchSlot0SizeInBytes = requiredScratchSizeInBytes;
perThreadScratchSpaceSlot0Size = requiredPerThreadScratchSizeSlot0AlignedUp;
AllocationProperties properties{this->rootDeviceIndex, true, scratchSlot0SizeInBytes, AllocationType::scratchSurface, multiTileCapable, false, osContext.getDeviceBitfield()};
scratchSlot0Allocation = getMemoryManager()->allocateGraphicsMemoryWithProperties(properties);
}
if (twoSlotScratchSpaceSupported) {
uint32_t requiredPerThreadScratchSizeSlot1AlignedUp = requiredPerThreadScratchSizeSlot1;
if (!Math::isPow2(requiredPerThreadScratchSizeSlot1AlignedUp)) {
requiredPerThreadScratchSizeSlot1AlignedUp = Math::nextPowerOfTwo(requiredPerThreadScratchSizeSlot1);
}
size_t requiredScratchSlot1SizeInBytes = static_cast<size_t>(requiredPerThreadScratchSizeSlot1AlignedUp) * computeUnitsUsedForScratch;
productHelper.adjustScratchSize(requiredScratchSlot1SizeInBytes);
if (scratchSlot1SizeInBytes < requiredScratchSlot1SizeInBytes) {
if (scratchSlot1Allocation) {
csrAllocationStorage.storeAllocation(std::unique_ptr<GraphicsAllocation>(scratchSlot1Allocation), TEMPORARY_ALLOCATION);
}
scratchSlot1SizeInBytes = requiredScratchSlot1SizeInBytes;
perThreadScratchSpaceSlot1Size = requiredPerThreadScratchSizeSlot1AlignedUp;
scratchSurfaceDirty = true;
AllocationProperties properties{this->rootDeviceIndex, true, scratchSlot1SizeInBytes, AllocationType::scratchSurface, multiTileCapable, false, osContext.getDeviceBitfield()};
scratchSlot1Allocation = getMemoryManager()->allocateGraphicsMemoryWithProperties(properties);
}
}
}
void ScratchSpaceControllerXeHPAndLater::programHeaps(HeapContainer &heapContainer,
uint32_t scratchSlot,
uint32_t requiredPerThreadScratchSizeSlot0,
uint32_t requiredPerThreadScratchSizeSlot1,
OsContext &osContext,
bool &stateBaseAddressDirty,
bool &vfeStateDirty) {
sshOffset = scratchSlot;
updateSlots = false;
setRequiredScratchSpace(heapContainer[0]->getUnderlyingBuffer(), sshOffset, requiredPerThreadScratchSizeSlot0, requiredPerThreadScratchSizeSlot1, osContext, stateBaseAddressDirty, vfeStateDirty);
for (uint32_t i = 1; i < heapContainer.size(); ++i) {
surfaceStateHeap = static_cast<char *>(heapContainer[i]->getUnderlyingBuffer());
updateSlots = false;
programSurfaceState();
}
updateSlots = true;
}
} // namespace NEO
|