Revert "Extend image functionality"

Signed-off-by: Kamil Diedrich <kamil.diedrich@intel.com>
This commit is contained in:
Kamil Diedrich
2021-06-29 22:45:53 +00:00
committed by Compute-Runtime-Automation
parent 7fc348d68b
commit 18b06eb345
19 changed files with 139 additions and 909 deletions

View File

@@ -16,10 +16,10 @@ struct _ze_image_handle_t {};
namespace NEO {
struct ImageInfo;
struct ImageDescriptor;
} // namespace NEO
}
namespace L0 {
struct Image : _ze_image_handle_t {
template <typename Type>
struct Allocator {
@@ -31,8 +31,6 @@ struct Image : _ze_image_handle_t {
static ze_result_t create(uint32_t productFamily, Device *device, const ze_image_desc_t *desc, Image **pImage);
virtual ze_result_t createView(Device *device, const ze_image_desc_t *desc, ze_image_handle_t *pImage) = 0;
virtual NEO::GraphicsAllocation *getAllocation() = 0;
virtual void copySurfaceStateToSSH(void *surfaceStateHeap,
const uint32_t surfaceStateOffset,

View File

@@ -15,6 +15,7 @@
#include "level_zero/core/source/image/image_imp.h"
namespace L0 {
template <GFXCORE_FAMILY gfxCoreFamily>
struct ImageCoreFamily : public ImageImp {
using GfxFamily = typename NEO::GfxFamilyMapper<gfxCoreFamily>::GfxFamily;

View File

@@ -16,26 +16,18 @@
#include "shared/source/memory_manager/memory_manager.h"
#include "shared/source/utilities/compiler_support.h"
#include "level_zero/core/source/helpers/properties_parser.h"
#include "level_zero/core/source/image/image_formats.h"
#include "level_zero/core/source/image/image_hw.h"
namespace L0 {
template <GFXCORE_FAMILY gfxCoreFamily>
ze_result_t ImageCoreFamily<gfxCoreFamily>::initialize(Device *device, const ze_image_desc_t *desc) {
using RENDER_SURFACE_STATE = typename GfxFamily::RENDER_SURFACE_STATE;
StructuresLookupTable lookupTable = {};
auto parseResult = prepareL0StructuresLookupTable(lookupTable, desc);
if (parseResult != ZE_RESULT_SUCCESS) {
return parseResult;
}
bool isMediaFormatLayout = isMediaFormat(desc->format.layout);
imgInfo.imgDesc = lookupTable.imageProperties.imageDescriptor;
auto imageDescriptor = convertDescriptor(*desc);
imgInfo.imgDesc = imageDescriptor;
imgInfo.surfaceFormat = &ImageFormats::formats[desc->format.layout][desc->format.type];
imageFormatDesc = *const_cast<ze_image_desc_t *>(desc);
@@ -65,36 +57,34 @@ ze_result_t ImageCoreFamily<gfxCoreFamily>::initialize(Device *device, const ze_
}
imgInfo.linearStorage = surfaceType == RENDER_SURFACE_STATE::SURFACE_TYPE_SURFTYPE_1D;
imgInfo.plane = isImageView ? static_cast<GMM_YUV_PLANE>(lookupTable.imageProperties.planeIndex + 1u) : GMM_NO_PLANE;
imgInfo.plane = GMM_NO_PLANE;
imgInfo.useLocalMemory = false;
imgInfo.preferRenderCompression = false;
if (!isImageView) {
if (lookupTable.isSharedHandle) {
if (!lookupTable.sharedHandleType.isSupportedHandle) {
if (desc->pNext) {
const ze_base_desc_t *extendedDesc = reinterpret_cast<const ze_base_desc_t *>(desc->pNext);
if (extendedDesc->stype == ZE_STRUCTURE_TYPE_EXTERNAL_MEMORY_EXPORT_DESC) {
return ZE_RESULT_ERROR_UNSUPPORTED_ENUMERATION;
} else if (extendedDesc->stype == ZE_STRUCTURE_TYPE_EXTERNAL_MEMORY_IMPORT_FD) {
const ze_external_memory_import_fd_t *externalMemoryImportDesc =
reinterpret_cast<const ze_external_memory_import_fd_t *>(extendedDesc);
if (externalMemoryImportDesc->flags & ZE_EXTERNAL_MEMORY_TYPE_FLAG_OPAQUE_FD) {
return ZE_RESULT_ERROR_UNSUPPORTED_ENUMERATION;
}
if (lookupTable.sharedHandleType.isDMABUFHandle) {
NEO::AllocationProperties properties(device->getRootDeviceIndex(), true, imgInfo, NEO::GraphicsAllocation::AllocationType::SHARED_IMAGE, device->getNEODevice()->getDeviceBitfield());
allocation = device->getNEODevice()->getMemoryManager()->createGraphicsAllocationFromSharedHandle(lookupTable.sharedHandleType.fd, properties, false, false);
device->getNEODevice()->getMemoryManager()->closeSharedHandle(allocation);
} else if (lookupTable.sharedHandleType.isNTHandle) {
auto verifyResult = device->getNEODevice()->getMemoryManager()->verifyHandle(NEO::toOsHandle(lookupTable.sharedHandleType.ntHnadle), device->getNEODevice()->getRootDeviceIndex(), true);
if (!verifyResult) {
return ZE_RESULT_ERROR_INVALID_ARGUMENT;
}
allocation = device->getNEODevice()->getMemoryManager()->createGraphicsAllocationFromNTHandle(lookupTable.sharedHandleType.ntHnadle, device->getNEODevice()->getRootDeviceIndex());
}
NEO::AllocationProperties properties(device->getRootDeviceIndex(), true, imgInfo, NEO::GraphicsAllocation::AllocationType::SHARED_IMAGE, device->getNEODevice()->getDeviceBitfield());
allocation = device->getNEODevice()->getMemoryManager()->createGraphicsAllocationFromSharedHandle(externalMemoryImportDesc->fd, properties, false, false);
device->getNEODevice()->getMemoryManager()->closeSharedHandle(allocation);
} else {
NEO::AllocationProperties properties(device->getRootDeviceIndex(), true, imgInfo, NEO::GraphicsAllocation::AllocationType::IMAGE, device->getNEODevice()->getDeviceBitfield());
return ZE_RESULT_ERROR_UNSUPPORTED_ENUMERATION;
}
} else {
NEO::AllocationProperties properties(device->getRootDeviceIndex(), true, imgInfo, NEO::GraphicsAllocation::AllocationType::IMAGE, device->getNEODevice()->getDeviceBitfield());
allocation = device->getNEODevice()->getMemoryManager()->allocateGraphicsMemoryWithProperties(properties);
}
if (allocation == nullptr) {
return ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY;
}
allocation = device->getNEODevice()->getMemoryManager()->allocateGraphicsMemoryWithProperties(properties);
}
UNRECOVERABLE_IF(allocation == nullptr);
auto gmm = this->allocation->getDefaultGmm();
auto gmmHelper = static_cast<const NEO::RootDeviceEnvironment &>(device->getNEODevice()->getRootDeviceEnvironment()).getGmmHelper();

View File

@@ -16,7 +16,7 @@ namespace L0 {
ImageAllocatorFn imageFactory[IGFX_MAX_PRODUCT] = {};
ImageImp::~ImageImp() {
if (!isImageView && this->device != nullptr) {
if (this->device != nullptr) {
this->device->getNEODevice()->getMemoryManager()->freeGraphicsMemory(this->allocation);
}
}
@@ -26,29 +26,6 @@ ze_result_t ImageImp::destroy() {
return ZE_RESULT_SUCCESS;
}
ze_result_t ImageImp::createView(Device *device, const ze_image_desc_t *desc, ze_image_handle_t *pImage) {
auto productFamily = device->getNEODevice()->getHardwareInfo().platform.eProductFamily;
ImageAllocatorFn allocator = nullptr;
allocator = imageFactory[productFamily];
ImageImp *image = nullptr;
image = static_cast<ImageImp *>((*allocator)());
image->isImageView = true;
image->allocation = allocation;
auto result = image->initialize(device, desc);
if (result != ZE_RESULT_SUCCESS) {
image->destroy();
image = nullptr;
}
*pImage = image;
return result;
}
ze_result_t Image::create(uint32_t productFamily, Device *device, const ze_image_desc_t *desc, Image **pImage) {
ze_result_t result = ZE_RESULT_SUCCESS;
ImageAllocatorFn allocator = nullptr;

View File

@@ -26,8 +26,6 @@ struct ImageImp : public Image {
return imageFormatDesc;
}
ze_result_t createView(Device *device, const ze_image_desc_t *desc, ze_image_handle_t *pImage) override;
ze_result_t getMemoryProperties(ze_image_memory_properties_exp_t *pMemoryProperties) override {
pMemoryProperties->rowPitch = imgInfo.rowPitch;
pMemoryProperties->slicePitch = imgInfo.slicePitch;
@@ -36,8 +34,42 @@ struct ImageImp : public Image {
return ZE_RESULT_SUCCESS;
}
static NEO::ImageType convertType(const ze_image_type_t type) {
switch (type) {
case ZE_IMAGE_TYPE_2D:
return NEO::ImageType::Image2D;
case ZE_IMAGE_TYPE_3D:
return NEO::ImageType::Image3D;
case ZE_IMAGE_TYPE_2DARRAY:
return NEO::ImageType::Image2DArray;
case ZE_IMAGE_TYPE_1D:
return NEO::ImageType::Image1D;
case ZE_IMAGE_TYPE_1DARRAY:
return NEO::ImageType::Image1DArray;
case ZE_IMAGE_TYPE_BUFFER:
return NEO::ImageType::Image1DBuffer;
default:
break;
}
return NEO::ImageType::Invalid;
}
static NEO::ImageDescriptor convertDescriptor(const ze_image_desc_t &imageDesc) {
NEO::ImageDescriptor desc = {};
desc.fromParent = false;
desc.imageArraySize = imageDesc.arraylevels;
desc.imageDepth = imageDesc.depth;
desc.imageHeight = imageDesc.height;
desc.imageRowPitch = 0u;
desc.imageSlicePitch = 0u;
desc.imageType = convertType(imageDesc.type);
desc.imageWidth = imageDesc.width;
desc.numMipLevels = imageDesc.miplevels;
desc.numSamples = 0u;
return desc;
}
protected:
bool isImageView = false;
Device *device = nullptr;
NEO::ImageInfo imgInfo = {};
NEO::GraphicsAllocation *allocation = nullptr;