84 lines
3.6 KiB
C++
84 lines
3.6 KiB
C++
/*
|
|
* Copyright (C) 2019 Intel Corporation
|
|
*
|
|
* SPDX-License-Identifier: MIT
|
|
*
|
|
*/
|
|
|
|
#include "common/helpers/bit_helpers.h"
|
|
#include "runtime/execution_environment/execution_environment.h"
|
|
#include "runtime/gmm_helper/gmm.h"
|
|
#include "runtime/gmm_helper/gmm_helper.h"
|
|
#include "runtime/gmm_helper/resource_info.h"
|
|
#include "runtime/helpers/aligned_memory.h"
|
|
#include "runtime/helpers/surface_formats.h"
|
|
#include "runtime/mem_obj/buffer.h"
|
|
|
|
#include "hw_cmds.h"
|
|
|
|
namespace NEO {
|
|
|
|
union SURFACE_STATE_BUFFER_LENGTH {
|
|
uint32_t Length;
|
|
struct SurfaceState {
|
|
uint32_t Width : BITFIELD_RANGE(0, 6);
|
|
uint32_t Height : BITFIELD_RANGE(7, 20);
|
|
uint32_t Depth : BITFIELD_RANGE(21, 31);
|
|
} SurfaceState;
|
|
};
|
|
|
|
template <typename GfxFamily>
|
|
void BufferHw<GfxFamily>::setArgStateful(void *memory, bool forceNonAuxMode, bool programForAuxTranslation) {
|
|
using RENDER_SURFACE_STATE = typename GfxFamily::RENDER_SURFACE_STATE;
|
|
using SURFACE_FORMAT = typename RENDER_SURFACE_STATE::SURFACE_FORMAT;
|
|
using AUXILIARY_SURFACE_MODE = typename RENDER_SURFACE_STATE::AUXILIARY_SURFACE_MODE;
|
|
|
|
auto surfaceState = reinterpret_cast<RENDER_SURFACE_STATE *>(memory);
|
|
// The graphics allocation for Host Ptr surface will be created in makeResident call and GPU address is expected to be the same as CPU address
|
|
auto bufferAddress = (getGraphicsAllocation() != nullptr) ? getGraphicsAllocation()->getGpuAddress() : reinterpret_cast<uint64_t>(getHostPtr());
|
|
bufferAddress += this->offset;
|
|
|
|
auto bufferAddressAligned = alignDown(bufferAddress, 4);
|
|
auto bufferOffset = ptrDiff(bufferAddress, bufferAddressAligned);
|
|
|
|
auto surfaceSize = alignUp(getSize() + bufferOffset, programForAuxTranslation ? 512 : 4);
|
|
|
|
SURFACE_STATE_BUFFER_LENGTH Length = {0};
|
|
Length.Length = static_cast<uint32_t>(surfaceSize - 1);
|
|
|
|
surfaceState->setWidth(Length.SurfaceState.Width + 1);
|
|
surfaceState->setHeight(Length.SurfaceState.Height + 1);
|
|
surfaceState->setDepth(Length.SurfaceState.Depth + 1);
|
|
|
|
if (bufferAddress != 0) {
|
|
surfaceState->setSurfaceType(RENDER_SURFACE_STATE::SURFACE_TYPE_SURFTYPE_BUFFER);
|
|
} else {
|
|
surfaceState->setSurfaceType(RENDER_SURFACE_STATE::SURFACE_TYPE_SURFTYPE_NULL);
|
|
}
|
|
surfaceState->setSurfaceFormat(SURFACE_FORMAT::SURFACE_FORMAT_RAW);
|
|
surfaceState->setSurfaceVerticalAlignment(RENDER_SURFACE_STATE::SURFACE_VERTICAL_ALIGNMENT_VALIGN_4);
|
|
surfaceState->setSurfaceHorizontalAlignment(RENDER_SURFACE_STATE::SURFACE_HORIZONTAL_ALIGNMENT_HALIGN_4);
|
|
|
|
surfaceState->setTileMode(RENDER_SURFACE_STATE::TILE_MODE_LINEAR);
|
|
surfaceState->setVerticalLineStride(0);
|
|
surfaceState->setVerticalLineStrideOffset(0);
|
|
surfaceState->setMemoryObjectControlState(getMocsValue(programForAuxTranslation));
|
|
surfaceState->setSurfaceBaseAddress(bufferAddressAligned);
|
|
|
|
Gmm *gmm = graphicsAllocation ? graphicsAllocation->getDefaultGmm() : nullptr;
|
|
|
|
if (gmm && gmm->isRenderCompressed && !forceNonAuxMode &&
|
|
GraphicsAllocation::AllocationType::BUFFER_COMPRESSED == graphicsAllocation->getAllocationType()) {
|
|
// Its expected to not program pitch/qpitch/baseAddress for Aux surface in CCS scenarios
|
|
surfaceState->setCoherencyType(RENDER_SURFACE_STATE::COHERENCY_TYPE_GPU_COHERENT);
|
|
surfaceState->setAuxiliarySurfaceMode(AUXILIARY_SURFACE_MODE::AUXILIARY_SURFACE_MODE_AUX_CCS_E);
|
|
} else {
|
|
surfaceState->setCoherencyType(RENDER_SURFACE_STATE::COHERENCY_TYPE_IA_COHERENT);
|
|
surfaceState->setAuxiliarySurfaceMode(AUXILIARY_SURFACE_MODE::AUXILIARY_SURFACE_MODE_AUX_NONE);
|
|
}
|
|
|
|
appendBufferState(memory, context, getGraphicsAllocation());
|
|
}
|
|
|
|
} // namespace NEO
|