2018-11-22 22:16:20 +08:00
|
|
|
/*
|
2019-02-27 18:39:32 +08:00
|
|
|
* Copyright (C) 2018-2019 Intel Corporation
|
2018-11-22 22:16:20 +08:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "runtime/command_stream/scratch_space_controller_base.h"
|
2019-02-27 18:39:32 +08:00
|
|
|
|
2019-03-29 07:49:23 +08:00
|
|
|
#include "runtime/execution_environment/execution_environment.h"
|
2018-11-22 22:16:20 +08:00
|
|
|
#include "runtime/helpers/aligned_memory.h"
|
|
|
|
#include "runtime/helpers/hw_helper.h"
|
|
|
|
#include "runtime/helpers/preamble.h"
|
|
|
|
#include "runtime/memory_manager/graphics_allocation.h"
|
|
|
|
#include "runtime/memory_manager/internal_allocation_storage.h"
|
2019-02-27 18:39:32 +08:00
|
|
|
#include "runtime/memory_manager/memory_constants.h"
|
2018-11-22 22:16:20 +08:00
|
|
|
#include "runtime/memory_manager/memory_manager.h"
|
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
namespace NEO {
|
2019-03-29 07:49:23 +08:00
|
|
|
ScratchSpaceControllerBase::ScratchSpaceControllerBase(ExecutionEnvironment &environment, InternalAllocationStorage &allocationStorage)
|
|
|
|
: ScratchSpaceController(environment, allocationStorage) {
|
2018-11-22 22:16:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScratchSpaceControllerBase::setRequiredScratchSpace(void *sshBaseAddress,
|
|
|
|
uint32_t requiredPerThreadScratchSize,
|
2019-06-27 18:59:27 +08:00
|
|
|
uint32_t requiredPerThreadPrivateScratchSize,
|
2018-11-22 22:16:20 +08:00
|
|
|
uint32_t currentTaskCount,
|
2018-12-03 17:05:36 +08:00
|
|
|
uint32_t contextId,
|
2018-11-22 22:16:20 +08:00
|
|
|
bool &stateBaseAddressDirty,
|
|
|
|
bool &vfeStateDirty) {
|
|
|
|
size_t requiredScratchSizeInBytes = requiredPerThreadScratchSize * computeUnitsUsedForScratch;
|
|
|
|
if (requiredScratchSizeInBytes && (!scratchAllocation || scratchSizeBytes < requiredScratchSizeInBytes)) {
|
|
|
|
if (scratchAllocation) {
|
2018-12-03 17:05:36 +08:00
|
|
|
scratchAllocation->updateTaskCount(currentTaskCount, contextId);
|
2018-11-22 22:16:20 +08:00
|
|
|
csrAllocationStorage.storeAllocation(std::unique_ptr<GraphicsAllocation>(scratchAllocation), TEMPORARY_ALLOCATION);
|
|
|
|
}
|
|
|
|
scratchSizeBytes = requiredScratchSizeInBytes;
|
|
|
|
createScratchSpaceAllocation();
|
|
|
|
vfeStateDirty = true;
|
|
|
|
force32BitAllocation = getMemoryManager()->peekForce32BitAllocations();
|
|
|
|
if (is64bit && !force32BitAllocation) {
|
|
|
|
stateBaseAddressDirty = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScratchSpaceControllerBase::createScratchSpaceAllocation() {
|
2018-12-12 01:56:37 +08:00
|
|
|
scratchAllocation = getMemoryManager()->allocateGraphicsMemoryWithProperties({scratchSizeBytes, GraphicsAllocation::AllocationType::SCRATCH_SURFACE});
|
2018-11-22 22:16:20 +08:00
|
|
|
UNRECOVERABLE_IF(scratchAllocation == nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t ScratchSpaceControllerBase::calculateNewGSH() {
|
2019-05-22 21:40:03 +08:00
|
|
|
uint64_t gsh = 0;
|
|
|
|
if (scratchAllocation) {
|
|
|
|
auto &hwHelper = HwHelper::get(executionEnvironment.getHardwareInfo()->platform.eRenderCoreFamily);
|
|
|
|
auto scratchSpaceOffsetFor64bit = hwHelper.getScratchSpaceOffsetFor64bit();
|
|
|
|
gsh = scratchAllocation->getGpuAddress() - scratchSpaceOffsetFor64bit;
|
|
|
|
}
|
|
|
|
return gsh;
|
2018-11-22 22:16:20 +08:00
|
|
|
}
|
|
|
|
uint64_t ScratchSpaceControllerBase::getScratchPatchAddress() {
|
|
|
|
//for 32 bit scratch space pointer is being programmed in Media VFE State and is relative to 0 as General State Base Address
|
|
|
|
//for 64 bit, scratch space pointer is being programmed as "General State Base Address - scratchSpaceOffsetFor64bit"
|
|
|
|
// and "0 + scratchSpaceOffsetFor64bit" is being programmed in Media VFE state
|
|
|
|
uint64_t scratchAddress = 0;
|
|
|
|
if (scratchAllocation) {
|
|
|
|
scratchAddress = scratchAllocation->getGpuAddressToPatch();
|
|
|
|
if (is64bit && !getMemoryManager()->peekForce32BitAllocations()) {
|
2019-05-08 22:00:24 +08:00
|
|
|
auto &hwHelper = HwHelper::get(executionEnvironment.getHardwareInfo()->platform.eRenderCoreFamily);
|
2018-11-22 22:16:20 +08:00
|
|
|
auto scratchSpaceOffsetFor64bit = hwHelper.getScratchSpaceOffsetFor64bit();
|
|
|
|
//this is to avoid scractch allocation offset "0"
|
|
|
|
scratchAddress = scratchSpaceOffsetFor64bit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return scratchAddress;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScratchSpaceControllerBase::reserveHeap(IndirectHeap::Type heapType, IndirectHeap *&indirectHeap) {
|
|
|
|
}
|
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
} // namespace NEO
|