mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-03 23:03:02 +08:00
Extend image functionality
- add imageView extension - add import win32 NT handle - add black box test with imageView usage example Signed-off-by: Kamil Diedrich <kamil.diedrich@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
afd5f766c2
commit
af55117fa0
@@ -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,6 +31,8 @@ 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,
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
#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;
|
||||
|
||||
@@ -16,18 +16,26 @@
|
||||
#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);
|
||||
|
||||
auto imageDescriptor = convertDescriptor(*desc);
|
||||
imgInfo.imgDesc = imageDescriptor;
|
||||
imgInfo.imgDesc = lookupTable.imageProperties.imageDescriptor;
|
||||
|
||||
imgInfo.surfaceFormat = &ImageFormats::formats[desc->format.layout][desc->format.type];
|
||||
imageFormatDesc = *const_cast<ze_image_desc_t *>(desc);
|
||||
@@ -57,34 +65,36 @@ ze_result_t ImageCoreFamily<gfxCoreFamily>::initialize(Device *device, const ze_
|
||||
}
|
||||
|
||||
imgInfo.linearStorage = surfaceType == RENDER_SURFACE_STATE::SURFACE_TYPE_SURFTYPE_1D;
|
||||
imgInfo.plane = GMM_NO_PLANE;
|
||||
imgInfo.plane = isImageView ? static_cast<GMM_YUV_PLANE>(lookupTable.imageProperties.planeIndex + 1u) : GMM_NO_PLANE;
|
||||
imgInfo.useLocalMemory = false;
|
||||
imgInfo.preferRenderCompression = false;
|
||||
|
||||
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) {
|
||||
if (!isImageView) {
|
||||
if (lookupTable.isSharedHandle) {
|
||||
if (!lookupTable.sharedHandleType.isSupportedHandle) {
|
||||
return ZE_RESULT_ERROR_UNSUPPORTED_ENUMERATION;
|
||||
}
|
||||
|
||||
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);
|
||||
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());
|
||||
}
|
||||
} else {
|
||||
return ZE_RESULT_ERROR_UNSUPPORTED_ENUMERATION;
|
||||
}
|
||||
} else {
|
||||
NEO::AllocationProperties properties(device->getRootDeviceIndex(), true, imgInfo, NEO::GraphicsAllocation::AllocationType::IMAGE, device->getNEODevice()->getDeviceBitfield());
|
||||
NEO::AllocationProperties properties(device->getRootDeviceIndex(), true, imgInfo, NEO::GraphicsAllocation::AllocationType::IMAGE, device->getNEODevice()->getDeviceBitfield());
|
||||
|
||||
allocation = device->getNEODevice()->getMemoryManager()->allocateGraphicsMemoryWithProperties(properties);
|
||||
allocation = device->getNEODevice()->getMemoryManager()->allocateGraphicsMemoryWithProperties(properties);
|
||||
}
|
||||
if (allocation == nullptr) {
|
||||
return ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY;
|
||||
}
|
||||
}
|
||||
UNRECOVERABLE_IF(allocation == nullptr);
|
||||
|
||||
auto gmm = this->allocation->getDefaultGmm();
|
||||
auto gmmHelper = static_cast<const NEO::RootDeviceEnvironment &>(device->getNEODevice()->getRootDeviceEnvironment()).getGmmHelper();
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace L0 {
|
||||
ImageAllocatorFn imageFactory[IGFX_MAX_PRODUCT] = {};
|
||||
|
||||
ImageImp::~ImageImp() {
|
||||
if (this->device != nullptr) {
|
||||
if (!isImageView && this->device != nullptr) {
|
||||
this->device->getNEODevice()->getMemoryManager()->freeGraphicsMemory(this->allocation);
|
||||
}
|
||||
}
|
||||
@@ -26,6 +26,29 @@ 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;
|
||||
|
||||
@@ -26,6 +26,8 @@ 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;
|
||||
@@ -34,42 +36,8 @@ 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;
|
||||
|
||||
Reference in New Issue
Block a user