[1/n] Mipmap support

* adding support for map/unmap
* adding support for origin/region validation with mipmaps
* fixing slices returned in map/unmap
* removing ambiguity around mipLevel naming
* enabling cl_khr_mipmap_image in current shape
* enabling cl_khr_mipmap_image_writes in current shape

* fixing CompileProgramWithReraFlag test

Change-Id: I0c9d83028c5c376f638e45151755fd2c7d0fb0ab
This commit is contained in:
Chodor, Jaroslaw 2018-04-04 09:29:48 +02:00
parent 6506df559b
commit 0a97dfbb2f
44 changed files with 777 additions and 246 deletions

2
Jenkinsfile vendored
View File

@ -2,4 +2,4 @@
neoDependenciesRev='748020-807'
strategy='EQUAL'
allowedF=40
allowedCD=336
allowedCD=335

View File

@ -2057,7 +2057,7 @@ cl_int CL_API_CALL clEnqueueReadImage(cl_command_queue commandQueue,
if (retVal != CL_SUCCESS)
return retVal;
}
if (!Image::validateRegionAndOrigin(origin, region, pImage->getImageDesc().image_type)) {
if (!Image::validateRegionAndOrigin(origin, region, pImage->getImageDesc())) {
return CL_INVALID_VALUE;
}
@ -2113,7 +2113,7 @@ cl_int CL_API_CALL clEnqueueWriteImage(cl_command_queue commandQueue,
if (retVal != CL_SUCCESS)
return retVal;
}
if (!Image::validateRegionAndOrigin(origin, region, pImage->getImageDesc().image_type)) {
if (!Image::validateRegionAndOrigin(origin, region, pImage->getImageDesc())) {
return CL_INVALID_VALUE;
}
@ -2159,7 +2159,7 @@ cl_int CL_API_CALL clEnqueueFillImage(cl_command_queue commandQueue,
"numEventsInWaitList", numEventsInWaitList, "event", event);
if (CL_SUCCESS == retVal) {
if (!Image::validateRegionAndOrigin(origin, region, dstImage->getImageDesc().image_type)) {
if (!Image::validateRegionAndOrigin(origin, region, dstImage->getImageDesc())) {
return CL_INVALID_VALUE;
}
@ -2217,10 +2217,10 @@ cl_int CL_API_CALL clEnqueueCopyImage(cl_command_queue commandQueue,
if (pDstImage->getImageDesc().image_type == CL_MEM_OBJECT_IMAGE2D && dstOrigin[2] != 0)
return CL_INVALID_VALUE;
}
if (!Image::validateRegionAndOrigin(srcOrigin, region, pSrcImage->getImageDesc().image_type)) {
if (!Image::validateRegionAndOrigin(srcOrigin, region, pSrcImage->getImageDesc())) {
return CL_INVALID_VALUE;
}
if (!Image::validateRegionAndOrigin(dstOrigin, region, pDstImage->getImageDesc().image_type)) {
if (!Image::validateRegionAndOrigin(dstOrigin, region, pDstImage->getImageDesc())) {
return CL_INVALID_VALUE;
}
@ -2271,7 +2271,7 @@ cl_int CL_API_CALL clEnqueueCopyImageToBuffer(cl_command_queue commandQueue,
if (retVal != CL_SUCCESS)
return retVal;
}
if (!Image::validateRegionAndOrigin(srcOrigin, region, pSrcImage->getImageDesc().image_type)) {
if (!Image::validateRegionAndOrigin(srcOrigin, region, pSrcImage->getImageDesc())) {
return CL_INVALID_VALUE;
}
@ -2323,7 +2323,7 @@ cl_int CL_API_CALL clEnqueueCopyBufferToImage(cl_command_queue commandQueue,
if (retVal != CL_SUCCESS)
return retVal;
}
if (!Image::validateRegionAndOrigin(dstOrigin, region, pDstImage->getImageDesc().image_type)) {
if (!Image::validateRegionAndOrigin(dstOrigin, region, pDstImage->getImageDesc())) {
return CL_INVALID_VALUE;
}
@ -2452,7 +2452,7 @@ void *CL_API_CALL clEnqueueMapImage(cl_command_queue commandQueue,
}
}
if (!Image::validateRegionAndOrigin(origin, region, pImage->getImageDesc().image_type)) {
if (!Image::validateRegionAndOrigin(origin, region, pImage->getImageDesc())) {
retVal = CL_INVALID_VALUE;
break;
}

View File

@ -33,6 +33,7 @@
#include "runtime/helpers/aligned_memory.h"
#include "runtime/helpers/array_count.h"
#include "runtime/helpers/get_info.h"
#include "runtime/helpers/mipmap.h"
#include "runtime/helpers/options.h"
#include "runtime/helpers/ptr_math.h"
#include "runtime/mem_obj/buffer.h"
@ -463,8 +464,12 @@ cl_int CommandQueue::enqueueWriteMemObjForUnmap(MemObj *memObj, void *mappedPtr,
retVal = enqueueWriteBuffer(buffer, CL_TRUE, unmapInfo.offset[0], unmapInfo.size[0], mappedPtr,
eventsRequest.numEventsInWaitList, eventsRequest.eventWaitList, eventsRequest.outEvent);
} else {
auto image = castToObject<Image>(memObj);
retVal = enqueueWriteImage(image, CL_FALSE, &unmapInfo.offset[0], &unmapInfo.size[0],
auto image = castToObjectOrAbort<Image>(memObj);
size_t writeOrigin[4] = {unmapInfo.offset[0], unmapInfo.offset[1], unmapInfo.offset[2], 0};
auto mipIdx = getMipLevelOriginIdx(image->peekClMemObjType());
UNRECOVERABLE_IF(mipIdx >= 4);
writeOrigin[mipIdx] = unmapInfo.mipLevel;
retVal = enqueueWriteImage(image, CL_FALSE, writeOrigin, &unmapInfo.size[0],
image->getHostPtrRowPitch(), image->getHostPtrSlicePitch(), mappedPtr,
eventsRequest.numEventsInWaitList, eventsRequest.eventWaitList, eventsRequest.outEvent);
bool mustCallFinish = true;
@ -493,10 +498,10 @@ cl_int CommandQueue::enqueueWriteMemObjForUnmap(MemObj *memObj, void *mappedPtr,
void *CommandQueue::enqueueReadMemObjForMap(TransferProperties &transferProperties, EventsRequest &eventsRequest, cl_int &errcodeRet) {
void *returnPtr = ptrOffset(transferProperties.memObj->getBasePtrForMap(),
transferProperties.memObj->calculateOffsetForMapping(transferProperties.offset));
transferProperties.memObj->calculateOffsetForMapping(transferProperties.offset) + transferProperties.mipPtrOffset);
if (!transferProperties.memObj->addMappedPtr(returnPtr, transferProperties.memObj->calculateMappedPtrLength(transferProperties.size),
transferProperties.mapFlags, transferProperties.size, transferProperties.offset)) {
transferProperties.mapFlags, transferProperties.size, transferProperties.offset, transferProperties.mipLevel)) {
errcodeRet = CL_INVALID_OPERATION;
return nullptr;
}
@ -506,8 +511,12 @@ void *CommandQueue::enqueueReadMemObjForMap(TransferProperties &transferProperti
errcodeRet = enqueueReadBuffer(buffer, transferProperties.blocking, transferProperties.offset[0], transferProperties.size[0], returnPtr,
eventsRequest.numEventsInWaitList, eventsRequest.eventWaitList, eventsRequest.outEvent);
} else {
auto image = castToObject<Image>(transferProperties.memObj);
errcodeRet = enqueueReadImage(image, transferProperties.blocking, &transferProperties.offset[0], &transferProperties.size[0],
auto image = castToObjectOrAbort<Image>(transferProperties.memObj);
size_t readOrigin[4] = {transferProperties.offset[0], transferProperties.offset[1], transferProperties.offset[2], 0};
auto mipIdx = getMipLevelOriginIdx(image->peekClMemObjType());
UNRECOVERABLE_IF(mipIdx >= 4);
readOrigin[mipIdx] = transferProperties.mipLevel;
errcodeRet = enqueueReadImage(image, transferProperties.blocking, readOrigin, &transferProperties.size[0],
image->getHostPtrRowPitch(), image->getHostPtrSlicePitch(), returnPtr, eventsRequest.numEventsInWaitList,
eventsRequest.eventWaitList, eventsRequest.outEvent);
}
@ -560,7 +569,6 @@ void *CommandQueue::enqueueMapImage(Image *image, cl_bool blockingMap,
cl_uint numEventsInWaitList,
const cl_event *eventWaitList, cl_event *event,
cl_int &errcodeRet) {
TransferProperties transferProperties(image, CL_COMMAND_MAP_IMAGE, mapFlags, blockingMap != CL_FALSE,
const_cast<size_t *>(origin), const_cast<size_t *>(region), nullptr);
EventsRequest eventsRequest(numEventsInWaitList, eventWaitList, event);
@ -572,7 +580,9 @@ void *CommandQueue::enqueueMapImage(Image *image, cl_bool blockingMap,
GetInfoHelper::set(imageSlicePitch, image->getHostPtrSlicePitch());
GetInfoHelper::set(imageRowPitch, image->getHostPtrRowPitch());
}
if (Image::hasSlices(image->peekClMemObjType()) == false) {
GetInfoHelper::set(imageSlicePitch, static_cast<size_t>(0));
}
return enqueueMapMemObject(transferProperties, eventsRequest, errcodeRet);
}

View File

@ -25,6 +25,7 @@
#include "runtime/context/context.h"
#include "runtime/event/event_builder.h"
#include "runtime/helpers/get_info.h"
#include "runtime/helpers/mipmap.h"
#include "runtime/mem_obj/buffer.h"
#include "runtime/mem_obj/image.h"
@ -41,10 +42,10 @@ void *CommandQueue::cpuDataTransferHandler(TransferProperties &transferPropertie
if (mapOperation) {
returnPtr = ptrOffset(transferProperties.memObj->getCpuAddressForMapping(),
transferProperties.memObj->calculateOffsetForMapping(transferProperties.offset));
transferProperties.memObj->calculateOffsetForMapping(transferProperties.offset) + transferProperties.mipPtrOffset);
if (!transferProperties.memObj->addMappedPtr(returnPtr, transferProperties.memObj->calculateMappedPtrLength(transferProperties.size),
transferProperties.mapFlags, transferProperties.size, transferProperties.offset)) {
transferProperties.mapFlags, transferProperties.size, transferProperties.offset, transferProperties.mipLevel)) {
err.set(CL_INVALID_OPERATION);
return nullptr;
}
@ -115,6 +116,7 @@ void *CommandQueue::cpuDataTransferHandler(TransferProperties &transferPropertie
outEventObj->setStartTimeStamp();
}
UNRECOVERABLE_IF((transferProperties.memObj->isMemObjZeroCopy() == false) && isMipMapped(transferProperties.memObj));
switch (transferProperties.cmdType) {
case CL_COMMAND_MAP_BUFFER:
if (!transferProperties.memObj->isMemObjZeroCopy()) {

View File

@ -1,24 +1,24 @@
/*
* Copyright (c) 2017, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
* Copyright (c) 2017 - 2018, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#include "runtime/gmm_helper/gmm_helper.h"
#include "runtime/gmm_helper/resource_info.h"
@ -178,7 +178,7 @@ void Gmm::queryImageParams(ImageInfo &imgInfo, const HardwareInfo &hwInfo) {
this->resourceParams.Depth = imageDepth;
this->resourceParams.ArraySize = imageCount;
this->resourceParams.Flags.Wa.__ForceOtherHVALIGN4 = 1;
this->resourceParams.MaxLod = imgInfo.mipLevel;
this->resourceParams.MaxLod = imgInfo.baseMipLevel + imgInfo.mipCount;
if (imgInfo.imgDesc->image_row_pitch && imgInfo.imgDesc->mem_object) {
this->resourceParams.OverridePitch = (uint32_t)imgInfo.imgDesc->image_row_pitch;
this->resourceParams.Flags.Info.AllowVirtualPadding = true;

View File

@ -56,6 +56,7 @@ set(RUNTIME_SRCS_HELPERS_BASE
${CMAKE_CURRENT_SOURCE_DIR}/kernel_commands.inl
${CMAKE_CURRENT_SOURCE_DIR}/kmd_notify_properties.h
${CMAKE_CURRENT_SOURCE_DIR}/kmd_notify_properties.cpp
${CMAKE_CURRENT_SOURCE_DIR}/mipmap.cpp
${CMAKE_CURRENT_SOURCE_DIR}/mipmap.h
${CMAKE_CURRENT_SOURCE_DIR}/options.cpp
${CMAKE_CURRENT_SOURCE_DIR}/options.h

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, Intel Corporation
* Copyright (c) 2017 - 2018, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@ -73,6 +73,11 @@ inline DerivedType *castToObjectOrAbort(typename DerivedType::BaseType *object)
}
}
template <typename DerivedType>
inline const DerivedType *castToObject(const typename DerivedType::BaseType *object) {
return const_cast<const DerivedType *>(castToObject<DerivedType>(const_cast<typename DerivedType::BaseType *>(object)));
}
extern std::thread::id invalidThreadID;
class ConditionVariableWithCounter {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, Intel Corporation
* Copyright (c) 2017 - 2018, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@ -43,5 +43,5 @@
namespace OCLRT {
void debugBreak(int line, const char *file);
void abortUnrecoverable(int line, const char *file);
[[noreturn]] void abortUnrecoverable(int line, const char *file);
} // namespace OCLRT

109
runtime/helpers/mipmap.cpp Normal file
View File

@ -0,0 +1,109 @@
/*
* Copyright (c) 2018, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#include "runtime/helpers/mipmap.h"
#include "runtime/gmm_helper/gmm_helper.h"
#include "runtime/gmm_helper/resource_info.h"
#include "runtime/mem_obj/image.h"
#include <cstdint>
namespace OCLRT {
uint32_t getMipLevelOriginIdx(cl_mem_object_type imageType) {
switch (imageType) {
case CL_MEM_OBJECT_IMAGE1D:
return 1;
case CL_MEM_OBJECT_IMAGE1D_ARRAY:
case CL_MEM_OBJECT_IMAGE2D:
return 2;
case CL_MEM_OBJECT_IMAGE2D_ARRAY:
case CL_MEM_OBJECT_IMAGE3D:
return 3;
default:
DEBUG_BREAK_IF(true);
return -1;
}
}
uint32_t findMipLevel(cl_mem_object_type imageType, const size_t *origin) {
size_t mipLevel = 0;
switch (imageType) {
case CL_MEM_OBJECT_IMAGE1D:
case CL_MEM_OBJECT_IMAGE1D_ARRAY:
case CL_MEM_OBJECT_IMAGE2D:
case CL_MEM_OBJECT_IMAGE2D_ARRAY:
case CL_MEM_OBJECT_IMAGE3D:
mipLevel = origin[getMipLevelOriginIdx(imageType)];
break;
default:
mipLevel = 0;
break;
}
return static_cast<uint32_t>(mipLevel);
}
bool isMipMapped(const MemObj *memObj) {
auto image = castToObject<Image>(memObj);
if (image == nullptr) {
return false;
}
return isMipMapped(image->getImageDesc());
}
uint32_t getMipOffset(Image *image, const size_t *origin) {
if (isMipMapped(image) == false) {
return 0;
}
UNRECOVERABLE_IF(origin == nullptr);
auto imageType = image->getImageDesc().image_type;
GMM_REQ_OFFSET_INFO GMMReqInfo = {};
GMMReqInfo.ReqLock = 1;
GMMReqInfo.MipLevel = findMipLevel(imageType, origin);
switch (imageType) {
case CL_MEM_OBJECT_IMAGE1D_ARRAY:
GMMReqInfo.ArrayIndex = static_cast<uint32_t>(origin[1]);
break;
case CL_MEM_OBJECT_IMAGE2D_ARRAY:
GMMReqInfo.ArrayIndex = static_cast<uint32_t>(origin[2]);
break;
case CL_MEM_OBJECT_IMAGE3D:
GMMReqInfo.Slice = static_cast<uint32_t>(origin[2]);
break;
default:
break;
}
auto graphicsAlloc = image->getGraphicsAllocation();
UNRECOVERABLE_IF(graphicsAlloc == nullptr);
UNRECOVERABLE_IF(graphicsAlloc->gmm == nullptr);
auto gmmResourceInfo = graphicsAlloc->gmm->gmmResourceInfo.get();
UNRECOVERABLE_IF(gmmResourceInfo == nullptr);
gmmResourceInfo->getOffset(GMMReqInfo);
return GMMReqInfo.Lock.Offset;
}
} // namespace OCLRT

View File

@ -21,30 +21,26 @@
*/
#pragma once
#include <cstdint>
#include "config.h"
#include "CL/cl.h"
#include <cstdint>
namespace OCLRT {
inline uint32_t findMipLevel(cl_mem_object_type imageType, const size_t *origin) {
size_t mipLevel = 0;
switch (imageType) {
case CL_MEM_OBJECT_IMAGE1D:
mipLevel = origin[1];
break;
case CL_MEM_OBJECT_IMAGE1D_ARRAY:
case CL_MEM_OBJECT_IMAGE2D:
mipLevel = origin[2];
break;
case CL_MEM_OBJECT_IMAGE2D_ARRAY:
case CL_MEM_OBJECT_IMAGE3D:
mipLevel = origin[3];
break;
default:
mipLevel = 0;
}
class MemObj;
class Image;
return static_cast<uint32_t>(mipLevel);
uint32_t getMipLevelOriginIdx(cl_mem_object_type imageType);
uint32_t findMipLevel(cl_mem_object_type imageType, const size_t *origin);
inline bool isMipMapped(const cl_image_desc &imgDesc) {
return (imgDesc.num_mip_levels > 1);
}
bool isMipMapped(const MemObj *memObj);
uint32_t getMipOffset(Image *image, const size_t *origin);
} // namespace OCLRT

View File

@ -20,7 +20,9 @@
* OTHER DEALINGS IN THE SOFTWARE.
*/
#include "runtime/helpers/mipmap.h"
#include "runtime/helpers/properties_helper.h"
#include "runtime/mem_obj/image.h"
#include "runtime/mem_obj/mem_obj.h"
namespace OCLRT {
@ -36,6 +38,15 @@ TransferProperties::TransferProperties(MemObj *memObj, cl_command_type cmdType,
} else {
size = {{sizePtr[0], sizePtr[1], sizePtr[2]}};
offset = {{offsetPtr[0], offsetPtr[1], offsetPtr[2]}};
if (isMipMapped(memObj)) {
// decompose origin to coordinates and miplevel
mipLevel = findMipLevel(memObj->peekClMemObjType(), offsetPtr);
mipPtrOffset = getMipOffset(castToObjectOrAbort<Image>(memObj), offsetPtr);
auto mipLevelIdx = getMipLevelOriginIdx(memObj->peekClMemObjType());
if (mipLevelIdx < offset.size()) {
offset[mipLevelIdx] = 0;
}
}
}
}
}

View File

@ -54,23 +54,28 @@ struct TransferProperties {
TransferProperties(MemObj *memObj, cl_command_type cmdType, cl_map_flags mapFlags, bool blocking, size_t *offsetPtr, size_t *sizePtr,
void *ptr);
MemObj *memObj;
cl_command_type cmdType;
cl_map_flags mapFlags;
bool blocking;
MemObjOffsetArray offset = {{0, 0, 0}};
MemObjSizeArray size = {{0, 0, 0}};
void *ptr;
MemObj *memObj = nullptr;
cl_command_type cmdType = 0;
cl_map_flags mapFlags = 0;
bool blocking = false;
MemObjOffsetArray offset = {};
MemObjSizeArray size = {};
void *ptr = nullptr;
uint32_t mipLevel = 0;
uint32_t mipPtrOffset = 0;
};
struct MapInfo {
MapInfo() = default;
MapInfo(void *ptr, size_t ptrLength, MemObjSizeArray size, MemObjOffsetArray offset) : ptr(ptr), ptrLength(ptrLength), size(size), offset(offset) {}
MapInfo(void *ptr, size_t ptrLength, MemObjSizeArray size, MemObjOffsetArray offset, uint32_t mipLevel)
: ptr(ptr), ptrLength(ptrLength), size(size), offset(offset), mipLevel(mipLevel) {
}
void *ptr = nullptr;
size_t ptrLength = 0;
MemObjSizeArray size = {{0, 0, 0}};
MemObjOffsetArray offset = {{0, 0, 0}};
MemObjSizeArray size = {};
MemObjOffsetArray offset = {};
bool readOnly = false;
uint32_t mipLevel = 0;
};
} // namespace OCLRT

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, Intel Corporation
* Copyright (c) 2017 - 2018, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@ -224,7 +224,7 @@ struct ImageInfo {
uint32_t yOffset;
uint32_t yOffsetForUVPlane;
GMM_YUV_PLANE_ENUM plane;
int mipLevel;
uint32_t baseMipLevel;
uint32_t mipCount;
bool preferRenderCompression;
};

View File

@ -29,6 +29,7 @@
#include "runtime/helpers/basic_math.h"
#include "runtime/helpers/get_info.h"
#include "runtime/helpers/hw_info.h"
#include "runtime/helpers/mipmap.h"
#include "runtime/helpers/ptr_math.h"
#include "runtime/helpers/string.h"
#include "runtime/mem_obj/image.h"
@ -54,8 +55,9 @@ Image::Image(Context *context,
GraphicsAllocation *graphicsAllocation,
bool isObjectRedescribed,
bool createTiledImage,
int mipLevel,
const SurfaceFormatInfo *surfaceFormatInfo,
uint32_t baseMipLevel,
uint32_t mipCount,
const SurfaceFormatInfo &surfaceFormatInfo,
const SurfaceOffsets *surfaceOffsets)
: MemObj(context,
imageDesc.image_type,
@ -71,10 +73,11 @@ Image::Image(Context *context,
isTiledImage(createTiledImage),
imageFormat(std::move(imageFormat)),
imageDesc(imageDesc),
surfaceFormatInfo(*surfaceFormatInfo),
surfaceFormatInfo(surfaceFormatInfo),
cubeFaceIndex(__GMM_NO_CUBE_MAP),
mediaPlaneType(0),
mipLevel(mipLevel) {
baseMipLevel(baseMipLevel),
mipCount(mipCount) {
magic = objectMagic;
if (surfaceOffsets)
setSurfaceOffsets(surfaceOffsets->offset, surfaceOffsets->xOffset, surfaceOffsets->yOffset, surfaceOffsets->yOffsetForUVplane);
@ -305,7 +308,7 @@ Image *Image::create(Context *context,
}
image = createImageHw(context, flags, imgInfo.size, hostPtrToSet, surfaceFormat->OCLImageFormat,
imageDescriptor, zeroCopy, memory, imageRedescribed, isTilingAllowed, 0, surfaceFormat);
imageDescriptor, zeroCopy, memory, imageRedescribed, isTilingAllowed, 0, 0, surfaceFormat);
if (imageDesc->image_type != CL_MEM_OBJECT_IMAGE1D_ARRAY && imageDesc->image_type != CL_MEM_OBJECT_IMAGE2D_ARRAY) {
image->imageDesc.image_array_size = 0;
@ -377,14 +380,15 @@ Image *Image::create(Context *context,
Image *Image::createImageHw(Context *context, cl_mem_flags flags, size_t size, void *hostPtr,
const cl_image_format &imageFormat, const cl_image_desc &imageDesc,
bool zeroCopy, GraphicsAllocation *graphicsAllocation,
bool isObjectRedescribed, bool createTiledImage, int mipLevel, const SurfaceFormatInfo *surfaceFormatInfo) {
bool isObjectRedescribed, bool createTiledImage, uint32_t baseMipLevel, uint32_t mipCount,
const SurfaceFormatInfo *surfaceFormatInfo) {
const auto device = castToObject<Context>(context)->getDevice(0);
const auto &hwInfo = device->getHardwareInfo();
auto funcCreate = imageFactory[hwInfo.pPlatform->eRenderCoreFamily].createImageFunction;
DEBUG_BREAK_IF(nullptr == funcCreate);
auto image = funcCreate(context, flags, size, hostPtr, imageFormat, imageDesc,
zeroCopy, graphicsAllocation, isObjectRedescribed, createTiledImage, mipLevel, surfaceFormatInfo, nullptr);
zeroCopy, graphicsAllocation, isObjectRedescribed, createTiledImage, baseMipLevel, mipCount, surfaceFormatInfo, nullptr);
DEBUG_BREAK_IF(nullptr == image);
image->createFunction = funcCreate;
return image;
@ -392,13 +396,13 @@ Image *Image::createImageHw(Context *context, cl_mem_flags flags, size_t size, v
Image *Image::createSharedImage(Context *context, SharingHandler *sharingHandler, McsSurfaceInfo &mcsSurfaceInfo,
GraphicsAllocation *graphicsAllocation, GraphicsAllocation *mcsAllocation,
cl_mem_flags flags, ImageInfo &imgInfo, uint32_t cubeFaceIndex, int mipLevel) {
cl_mem_flags flags, ImageInfo &imgInfo, uint32_t cubeFaceIndex, uint32_t baseMipLevel, uint32_t mipCount) {
auto tileWalk = graphicsAllocation->gmm->gmmResourceInfo->getTileType();
auto tileMode = Gmm::getRenderTileMode(tileWalk);
bool isTiledImage = tileMode ? true : false;
auto sharedImage = createImageHw(context, flags, graphicsAllocation->getUnderlyingBufferSize(),
nullptr, imgInfo.surfaceFormat->OCLImageFormat, *imgInfo.imgDesc, false, graphicsAllocation, false, isTiledImage, mipLevel, imgInfo.surfaceFormat);
nullptr, imgInfo.surfaceFormat->OCLImageFormat, *imgInfo.imgDesc, false, graphicsAllocation, false, isTiledImage, baseMipLevel, mipCount, imgInfo.surfaceFormat);
sharedImage->setSharingHandler(sharingHandler);
sharedImage->setMcsAllocation(mcsAllocation);
sharedImage->setQPitch(imgInfo.qPitch);
@ -712,8 +716,8 @@ cl_int Image::getImageInfo(cl_image_info paramName,
case CL_IMAGE_WIDTH:
srcParamSize = sizeof(size_t);
retParam = imageDesc.image_width;
if (this->mipLevel) {
retParam = imageDesc.image_width >> this->mipLevel;
if (this->baseMipLevel) {
retParam = imageDesc.image_width >> this->baseMipLevel;
retParam = std::max(retParam, (size_t)1);
}
srcParam = &retParam;
@ -722,8 +726,8 @@ cl_int Image::getImageInfo(cl_image_info paramName,
case CL_IMAGE_HEIGHT:
srcParamSize = sizeof(size_t);
retParam = imageDesc.image_height * !((imageDesc.image_type == CL_MEM_OBJECT_IMAGE1D) || (imageDesc.image_type == CL_MEM_OBJECT_IMAGE1D_ARRAY) || (imageDesc.image_type == CL_MEM_OBJECT_IMAGE1D_BUFFER));
if ((retParam != 0) && (this->mipLevel > 0)) {
retParam = retParam >> this->mipLevel;
if ((retParam != 0) && (this->baseMipLevel > 0)) {
retParam = retParam >> this->baseMipLevel;
retParam = std::max(retParam, (size_t)1);
}
srcParam = &retParam;
@ -732,8 +736,8 @@ cl_int Image::getImageInfo(cl_image_info paramName,
case CL_IMAGE_DEPTH:
srcParamSize = sizeof(size_t);
retParam = imageDesc.image_depth * (imageDesc.image_type == CL_MEM_OBJECT_IMAGE3D);
if ((retParam != 0) && (this->mipLevel > 0)) {
retParam = retParam >> this->mipLevel;
if ((retParam != 0) && (this->baseMipLevel > 0)) {
retParam = retParam >> this->baseMipLevel;
retParam = std::max(retParam, (size_t)1);
}
srcParam = &retParam;
@ -803,7 +807,8 @@ Image *Image::redescribeFillImage() {
this->getGraphicsAllocation(),
true,
isTiledImage,
this->mipLevel,
this->baseMipLevel,
this->mipCount,
surfaceFormat,
&this->surfaceOffsets);
image->setQPitch(this->getQPitch());
@ -847,7 +852,8 @@ Image *Image::redescribe() {
this->getGraphicsAllocation(),
true,
isTiledImage,
this->mipLevel,
this->baseMipLevel,
this->mipCount,
surfaceFormat,
&this->surfaceOffsets);
image->setQPitch(this->getQPitch());
@ -1207,30 +1213,47 @@ size_t Image::calculateOffsetForMapping(const MemObjOffsetArray &origin) const {
size_t slicePitch = mappingOnCpuAllowed() ? imageDesc.image_slice_pitch : getHostPtrSlicePitch();
size_t offset = getSurfaceFormatInfo().ImageElementSizeInBytes * origin[0];
if (imageDesc.image_type == CL_MEM_OBJECT_IMAGE1D_ARRAY) {
switch (imageDesc.image_type) {
case CL_MEM_OBJECT_IMAGE1D_ARRAY:
offset += slicePitch * origin[1];
} else {
break;
case CL_MEM_OBJECT_IMAGE2D:
offset += rowPitch * origin[1];
break;
case CL_MEM_OBJECT_IMAGE2D_ARRAY:
case CL_MEM_OBJECT_IMAGE3D:
offset += rowPitch * origin[1] + slicePitch * origin[2];
break;
default:
break;
}
return offset;
}
bool Image::validateRegionAndOrigin(const size_t *origin, const size_t *region, const cl_mem_object_type &imgType) {
bool Image::validateRegionAndOrigin(const size_t *origin, const size_t *region, const cl_image_desc &imgDesc) {
if (region[0] == 0 || region[1] == 0 || region[2] == 0) {
return false;
}
if ((imgType == CL_MEM_OBJECT_IMAGE1D || imgType == CL_MEM_OBJECT_IMAGE1D_BUFFER) &&
(origin[1] > 0 || origin[2] > 0 || region[1] > 1 || region[2] > 1)) {
bool notMippMapped = (false == isMipMapped(imgDesc));
if ((imgDesc.image_type == CL_MEM_OBJECT_IMAGE1D || imgDesc.image_type == CL_MEM_OBJECT_IMAGE1D_BUFFER) &&
(((origin[1] > 0) && notMippMapped) || origin[2] > 0 || region[1] > 1 || region[2] > 1)) {
return false;
}
if ((imgType == CL_MEM_OBJECT_IMAGE2D || imgType == CL_MEM_OBJECT_IMAGE1D_ARRAY) &&
(origin[2] > 0 || region[2] > 1)) {
if ((imgDesc.image_type == CL_MEM_OBJECT_IMAGE2D || imgDesc.image_type == CL_MEM_OBJECT_IMAGE1D_ARRAY) &&
(((origin[2] > 0) && notMippMapped) || region[2] > 1)) {
return false;
}
return true;
if (notMippMapped) {
return true;
}
uint32_t mipLevel = findMipLevel(imgDesc.image_type, origin);
return mipLevel < imgDesc.num_mip_levels;
}
} // namespace OCLRT

View File

@ -48,7 +48,8 @@ typedef Image *(*ImageCreatFunc)(Context *context,
GraphicsAllocation *graphicsAllocation,
bool isImageRedescribed,
bool createTiledImage,
int mipLevel,
uint32_t baseMipLevel,
uint32_t mipCount,
const SurfaceFormatInfo *surfaceFormatInfo,
const SurfaceOffsets *surfaceOffsets);
@ -80,11 +81,11 @@ class Image : public MemObj {
static Image *createImageHw(Context *context, cl_mem_flags flags, size_t size, void *hostPtr,
const cl_image_format &imageFormat, const cl_image_desc &imageDesc,
bool zeroCopy, GraphicsAllocation *graphicsAllocation,
bool isObjectRedescribed, bool createTiledImage, int mipLevel, const SurfaceFormatInfo *surfaceFormatInfo = nullptr);
bool isObjectRedescribed, bool createTiledImage, uint32_t baseMipLevel, uint32_t mipCount, const SurfaceFormatInfo *surfaceFormatInfo = nullptr);
static Image *createSharedImage(Context *context, SharingHandler *sharingHandler, McsSurfaceInfo &mcsSurfaceInfo,
GraphicsAllocation *graphicsAllocation, GraphicsAllocation *mcsAllocation,
cl_mem_flags flags, ImageInfo &imgInfo, uint32_t cubeFaceIndex, int mipLevel);
cl_mem_flags flags, ImageInfo &imgInfo, uint32_t cubeFaceIndex, uint32_t baseMipLevel, uint32_t mipCount);
static cl_int validate(Context *context,
cl_mem_flags flags,
@ -119,6 +120,10 @@ class Image : public MemObj {
static bool isDepthFormat(const cl_image_format &imageFormat);
static bool hasSlices(cl_mem_object_type type) {
return (type == CL_MEM_OBJECT_IMAGE3D) || (type == CL_MEM_OBJECT_IMAGE1D_ARRAY) || (type == CL_MEM_OBJECT_IMAGE2D_ARRAY);
}
cl_int getImageInfo(cl_image_info paramName,
size_t paramValueSize,
void *paramValue,
@ -163,14 +168,14 @@ class Image : public MemObj {
uint32_t getCubeFaceIndex() { return cubeFaceIndex; }
void setMediaPlaneType(cl_uint type) { mediaPlaneType = type; }
cl_uint getMediaPlaneType() const { return mediaPlaneType; }
int peekMipLevel() { return mipLevel; }
void setMipLevel(int mipLevelNew) { this->mipLevel = mipLevelNew; }
int peekBaseMipLevel() { return baseMipLevel; }
void setBaseMipLevel(int level) { this->baseMipLevel = level; }
uint32_t peekMipCount() { return mipCount; }
void setMipCount(uint32_t mipCountNew) { this->mipCount = mipCountNew; }
static const SurfaceFormatInfo *getSurfaceFormatFromTable(cl_mem_flags flags, const cl_image_format *imageFormat);
static bool validateRegionAndOrigin(const size_t *origin, const size_t *region, const cl_mem_object_type &imgType);
static bool validateRegionAndOrigin(const size_t *origin, const size_t *region, const cl_image_desc &imgDesc);
cl_int writeNV12Planes(const void *hostPtr, size_t hostPtrRowPitch);
void setMcsSurfaceInfo(McsSurfaceInfo &info) { mcsSurfaceInfo = info; }
@ -190,8 +195,9 @@ class Image : public MemObj {
GraphicsAllocation *graphicsAllocation,
bool isObjectRedescribed,
bool createTiledImage,
int mipLevel,
const SurfaceFormatInfo *surfaceFormatInfo = nullptr,
uint32_t baseMipLevel,
uint32_t mipCount,
const SurfaceFormatInfo &surfaceFormatInfo,
const SurfaceOffsets *surfaceOffsets = nullptr);
void getOsSpecificImageInfo(const cl_mem_info &paramName, size_t *srcParamSize, void **srcParam);
@ -211,8 +217,8 @@ class Image : public MemObj {
uint32_t cubeFaceIndex;
cl_uint mediaPlaneType;
SurfaceOffsets surfaceOffsets;
int mipLevel = 0;
uint32_t mipCount = 0;
uint32_t baseMipLevel = 0;
uint32_t mipCount = 1;
static bool isValidSingleChannelFormat(const cl_image_format *imageFormat);
static bool isValidIntensityFormat(const cl_image_format *imageFormat);
@ -244,11 +250,12 @@ class ImageHw : public Image {
GraphicsAllocation *graphicsAllocation,
bool isObjectRedescribed,
bool createTiledImage,
int mipLevel,
const SurfaceFormatInfo *surfaceFormatInfo = nullptr,
uint32_t baseMipLevel,
uint32_t mipCount,
const SurfaceFormatInfo &surfaceFormatInfo,
const SurfaceOffsets *surfaceOffsets = nullptr)
: Image(context, flags, size, hostPtr, imageFormat, imageDesc,
zeroCopy, graphicsAllocation, isObjectRedescribed, createTiledImage, mipLevel, surfaceFormatInfo, surfaceOffsets) {
zeroCopy, graphicsAllocation, isObjectRedescribed, createTiledImage, baseMipLevel, mipCount, surfaceFormatInfo, surfaceOffsets) {
if (getImageDesc().image_type == CL_MEM_OBJECT_IMAGE1D ||
getImageDesc().image_type == CL_MEM_OBJECT_IMAGE1D_BUFFER ||
getImageDesc().image_type == CL_MEM_OBJECT_IMAGE2D ||
@ -276,9 +283,11 @@ class ImageHw : public Image {
GraphicsAllocation *graphicsAllocation,
bool isObjectRedescribed,
bool createTiledImage,
int mipLevel,
uint32_t baseMipLevel,
uint32_t mipCount,
const SurfaceFormatInfo *surfaceFormatInfo,
const SurfaceOffsets *surfaceOffsets) {
UNRECOVERABLE_IF(surfaceFormatInfo == nullptr);
auto image = new ImageHw<GfxFamily>(context,
flags,
size,
@ -289,8 +298,9 @@ class ImageHw : public Image {
graphicsAllocation,
isObjectRedescribed,
createTiledImage,
mipLevel,
surfaceFormatInfo,
baseMipLevel,
mipCount,
*surfaceFormatInfo,
surfaceOffsets);
switch (imageDesc.image_type) {

View File

@ -109,7 +109,7 @@ void ImageHw<GfxFamily>::setImageArg(void *memory, bool setAsMediaBlockImage, ui
surfaceState->setSurfaceBaseAddress(getGraphicsAllocation()->getGpuAddress() + this->surfaceOffsets.offset);
surfaceState->setRenderTargetViewExtent(renderTargetViewExtent);
surfaceState->setMinimumArrayElement(minimumArrayElement);
surfaceState->setSurfaceMinLod(this->mipLevel + mipLevel);
surfaceState->setSurfaceMinLod(this->baseMipLevel + mipLevel);
surfaceState->setMipCountLod((this->mipCount > 0) ? (this->mipCount - 1) : 0);
// SurfaceQpitch is in rows but must be a multiple of VALIGN

View File

@ -30,9 +30,9 @@ size_t MapOperationsHandler::size() const {
return mappedPointers.size();
}
bool MapOperationsHandler::add(void *ptr, size_t ptrLength, cl_map_flags &mapFlags, MemObjSizeArray &size, MemObjOffsetArray &offset) {
bool MapOperationsHandler::add(void *ptr, size_t ptrLength, cl_map_flags &mapFlags, MemObjSizeArray &size, MemObjOffsetArray &offset, uint32_t mipLevel) {
std::lock_guard<std::mutex> lock(mtx);
MapInfo mapInfo(ptr, ptrLength, size, offset);
MapInfo mapInfo(ptr, ptrLength, size, offset, mipLevel);
mapInfo.readOnly = (mapFlags == CL_MAP_READ);
if (isOverlapping(mapInfo)) {

View File

@ -32,7 +32,7 @@ class MapOperationsHandler {
public:
virtual ~MapOperationsHandler() = default;
bool add(void *ptr, size_t ptrLength, cl_map_flags &mapFlags, MemObjSizeArray &size, MemObjOffsetArray &offset);
bool add(void *ptr, size_t ptrLength, cl_map_flags &mapFlags, MemObjSizeArray &size, MemObjOffsetArray &offset, uint32_t mipLevel);
void remove(void *mappedPtr);
bool find(void *mappedPtr, MapInfo &outMapInfo);
size_t size() const;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, Intel Corporation
* Copyright (c) 2017 - 2018, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@ -334,7 +334,10 @@ void *MemObj::getBasePtrForMap() {
}
}
bool MemObj::addMappedPtr(void *ptr, size_t ptrLength, cl_map_flags &mapFlags, MemObjSizeArray &size, MemObjOffsetArray &offset) {
return mapOperationsHandler.add(ptr, ptrLength, mapFlags, size, offset);
bool MemObj::addMappedPtr(void *ptr, size_t ptrLength, cl_map_flags &mapFlags,
MemObjSizeArray &size, MemObjOffsetArray &offset,
uint32_t mipLevel) {
return mapOperationsHandler.add(ptr, ptrLength, mapFlags, size, offset,
mipLevel);
}
} // namespace OCLRT

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, Intel Corporation
* Copyright (c) 2017 - 2018, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@ -24,6 +24,7 @@
#include "runtime/api/cl_types.h"
#include "runtime/helpers/base_object.h"
#include "runtime/helpers/completion_stamp.h"
#include "runtime/helpers/mipmap.h"
#include "runtime/sharings/sharing.h"
#include "runtime/mem_obj/map_operations_handler.h"
#include <atomic>
@ -75,7 +76,7 @@ class MemObj : public BaseObject<_cl_mem> {
void setCompletionStamp(CompletionStamp completionStamp, Device *pDevice, CommandQueue *pCmdQ);
CompletionStamp getCompletionStamp() const;
bool addMappedPtr(void *ptr, size_t ptrLength, cl_map_flags &mapFlags, MemObjSizeArray &size, MemObjOffsetArray &offset);
bool addMappedPtr(void *ptr, size_t ptrLength, cl_map_flags &mapFlags, MemObjSizeArray &size, MemObjOffsetArray &offset, uint32_t mipLevel);
bool findMappedPtr(void *mappedPtr, MapInfo &outMapInfo) { return mapOperationsHandler.find(mappedPtr, outMapInfo); }
void removeMappedPtr(void *mappedPtr) { return mapOperationsHandler.remove(mappedPtr); }
void *getBasePtrForMap();
@ -118,7 +119,7 @@ class MemObj : public BaseObject<_cl_mem> {
void waitForCsrCompletion();
void destroyGraphicsAllocation(GraphicsAllocation *allocation, bool asyncDestroy);
bool checkIfMemoryTransferIsRequired(size_t offsetInMemObjest, size_t offsetInHostPtr, const void *ptr, cl_command_type cmdType);
bool mappingOnCpuAllowed() const { return !allowTiling() && !peekSharingHandler(); }
bool mappingOnCpuAllowed() const { return !allowTiling() && !peekSharingHandler() && !isMipMapped(this); }
virtual size_t calculateOffsetForMapping(const MemObjOffsetArray &offset) const { return offset[0]; }
size_t calculateMappedPtrLength(const MemObjSizeArray &size) const { return calculateOffsetForMapping(size); }
cl_mem_object_type peekClMemObjType() const { return memObjectType; }

View File

@ -46,7 +46,9 @@ const char *deviceExtensionsList = "cl_khr_3d_image_writes "
"cl_intel_device_side_avc_motion_estimation "
"cl_khr_priority_hints "
"cl_khr_throttle_hints "
"cl_khr_create_command_queue ";
"cl_khr_create_command_queue "
"cl_khr_mipmap_image "
"cl_khr_mipmap_image_writes ";
std::string getExtensionsList(const HardwareInfo &hwInfo) {
std::string allExtensionsList;

View File

@ -1,24 +1,24 @@
/*
* Copyright (c) 2017, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
* Copyright (c) 2017 - 2018, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#include "runtime/sharings/d3d/d3d_surface.h"
#include "runtime/context/context.h"
@ -109,7 +109,7 @@ Image *D3DSurface::create(Context *context, cl_dx9_surface_info_khr *surfaceInfo
auto surface = new D3DSurface(context, surfaceInfo, surfaceStaging, plane, oclPlane, adapterType, isSharedResource, lockable);
return Image::createSharedImage(context, surface, mcsSurfaceInfo, alloc, nullptr, flags, imgInfo, __GMM_NO_CUBE_MAP, 0);
return Image::createSharedImage(context, surface, mcsSurfaceInfo, alloc, nullptr, flags, imgInfo, __GMM_NO_CUBE_MAP, 0, 0);
}
void D3DSurface::synchronizeObject(UpdateData *updateData) {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, Intel Corporation
* Copyright (c) 2017 - 2018, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@ -99,7 +99,7 @@ Image *D3DTexture<D3D>::create2d(Context *context, D3DTexture2d *d3dTexture, cl_
alloc->gmm->isRenderCompressed = context->getMemoryManager()->mapAuxGpuVA(alloc);
}
return Image::createSharedImage(context, d3dTextureObj, mcsSurfaceInfo, alloc, nullptr, flags, imgInfo, __GMM_NO_CUBE_MAP, 0);
return Image::createSharedImage(context, d3dTextureObj, mcsSurfaceInfo, alloc, nullptr, flags, imgInfo, __GMM_NO_CUBE_MAP, 0, 0);
}
template <typename D3D>
@ -154,7 +154,7 @@ Image *D3DTexture<D3D>::create3d(Context *context, D3DTexture3d *d3dTexture, cl_
alloc->gmm->isRenderCompressed = context->getMemoryManager()->mapAuxGpuVA(alloc);
}
return Image::createSharedImage(context, d3dTextureObj, mcsSurfaceInfo, alloc, nullptr, flags, imgInfo, __GMM_NO_CUBE_MAP, 0);
return Image::createSharedImage(context, d3dTextureObj, mcsSurfaceInfo, alloc, nullptr, flags, imgInfo, __GMM_NO_CUBE_MAP, 0, 0);
}
template <typename D3D>

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, Intel Corporation
* Copyright (c) 2017 - 2018, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@ -92,7 +92,7 @@ Image *VASurface::createSharedVaSurface(Context *context, VASharingFunctions *sh
auto vaSurface = new VASurface(sharingFunctions, imageId, plane, surface, context->getInteropUserSyncEnabled());
auto image = Image::createSharedImage(context, vaSurface, mcsSurfaceInfo, alloc, nullptr, flags, imgInfo, __GMM_NO_CUBE_MAP, 0);
auto image = Image::createSharedImage(context, vaSurface, mcsSurfaceInfo, alloc, nullptr, flags, imgInfo, __GMM_NO_CUBE_MAP, 0, 0);
image->setMediaPlaneType(plane);
return image;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, Intel Corporation
* Copyright (c) 2017 - 2018, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@ -170,7 +170,7 @@ TEST_F(clGetImageInfoTests, givenImageWithMipMapsWhenAskedForSziesItIsShiftedByM
size_t paramRetSize = sizeof(size_t);
for (int mipLevel = 0; mipLevel < 10; mipLevel++) {
pImage->setMipLevel(mipLevel);
pImage->setBaseMipLevel(mipLevel);
auto expectedWidth = initialWidth >> mipLevel;
expectedWidth = expectedWidth == 0 ? 1 : expectedWidth;
auto expectedHeight = initialHeight >> mipLevel;
@ -230,7 +230,7 @@ TEST_F(clGetImageInfoTests, CheckImage3DWidthAndHeightAndDepthWithMipmaps) {
auto pImgObj = castToObject<Image>(image2);
for (cl_uint n = 0; n <= imageDesc2.num_mip_levels; n++) {
pImgObj->setMipLevel(n);
pImgObj->setBaseMipLevel(n);
retVal = clGetImageInfo(image2, CL_IMAGE_WIDTH, sizeof(widthRet), &widthRet, NULL);
EXPECT_EQ(CL_SUCCESS, retVal);
@ -285,7 +285,7 @@ TEST_F(clGetImageInfoTests, CheckImage1DWidthAndHeightAndDepthWithMipmaps) {
auto pImgObj = castToObject<Image>(image2);
for (cl_uint n = 0; n <= imageDesc2.num_mip_levels; n++) {
pImgObj->setMipLevel(n);
pImgObj->setBaseMipLevel(n);
retVal = clGetImageInfo(image2, CL_IMAGE_WIDTH, sizeof(widthRet), &widthRet, NULL);
EXPECT_EQ(CL_SUCCESS, retVal);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, Intel Corporation
* Copyright (c) 2017 - 2018, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@ -24,6 +24,7 @@
#include "unit_tests/command_queue/enqueue_map_buffer_fixture.h"
#include "unit_tests/fixtures/device_fixture.h"
#include "unit_tests/fixtures/buffer_fixture.h"
#include "unit_tests/mocks/mock_buffer.h"
#include "unit_tests/mocks/mock_context.h"
#include "unit_tests/mocks/mock_kernel.h"
#include "unit_tests/helpers/debug_manager_state_restore.h"
@ -585,6 +586,27 @@ TEST_F(EnqueueMapBufferTest, GivenBufferThatIsNotZeroCopyWhenNonBlockingMapIsCal
EXPECT_EQ(CL_SUCCESS, retVal);
}
TEST_F(EnqueueMapBufferTest, GivenWrongMemObjectWhenMapIsCalledThenInvalidMemObjectErrorCodeIsReturned) {
MockBuffer buffer;
cl_mem mem = &buffer;
buffer.magic = -1;
auto ptrResult = clEnqueueMapBuffer(
pCmdQ,
mem,
CL_FALSE,
CL_MAP_READ,
0,
8,
0,
nullptr,
nullptr,
&retVal);
EXPECT_EQ(nullptr, ptrResult);
EXPECT_EQ(CL_INVALID_MEM_OBJECT, retVal);
}
HWTEST_F(EnqueueMapBufferTest, MapBufferEventProperties) {
cl_event eventReturned = NULL;

View File

@ -67,6 +67,10 @@ struct EnqueueMapImageTest : public DeviceFixture,
char srcMemory[128];
};
struct EnqueueMapImageParamsTest : public EnqueueMapImageTest,
public ::testing::WithParamInterface<uint32_t> {
};
TEST_F(EnqueueMapImageTest, reuseMappedPtrForTiledImg) {
if (!image->allowTiling()) {
return;
@ -118,6 +122,71 @@ TEST_F(EnqueueMapImageTest, givenAllocatedMapPtrAndMapWithDifferentOriginIsCalle
EXPECT_EQ(ptr2, ptrOffset(ptr1, mapOffset));
}
typedef EnqueueMapImageParamsTest MipMapMapImageParamsTest;
TEST_P(MipMapMapImageParamsTest, givenAllocatedMapPtrAndMapWithDifferentMipMapsIsCalledThenReturnDifferentPointers) {
auto image_type = (cl_mem_object_type)GetParam();
cl_int retVal = CL_SUCCESS;
cl_image_desc imageDesc = {};
imageDesc.image_type = image_type;
imageDesc.num_mip_levels = 10;
imageDesc.image_width = 4;
imageDesc.image_height = 1;
imageDesc.image_depth = 1;
const size_t origin1[4] = {0, 0, 0, 0};
size_t origin2[4] = {0, 0, 0, 0};
std::unique_ptr<Image> image;
switch (image_type) {
case CL_MEM_OBJECT_IMAGE1D:
origin2[1] = 1;
image = std::unique_ptr<Image>(ImageHelper<Image1dDefaults>::create(context, &imageDesc));
break;
case CL_MEM_OBJECT_IMAGE1D_ARRAY:
origin2[2] = 1;
imageDesc.image_array_size = 2;
image = std::unique_ptr<Image>(ImageHelper<Image1dArrayDefaults>::create(context, &imageDesc));
break;
case CL_MEM_OBJECT_IMAGE2D:
origin2[2] = 1;
image = std::unique_ptr<Image>(ImageHelper<Image2dDefaults>::create(context, &imageDesc));
break;
case CL_MEM_OBJECT_IMAGE2D_ARRAY:
origin2[3] = 1;
imageDesc.image_array_size = 2;
image = std::unique_ptr<Image>(ImageHelper<Image2dArrayDefaults>::create(context, &imageDesc));
break;
case CL_MEM_OBJECT_IMAGE3D:
origin2[3] = 1;
image = std::unique_ptr<Image>(ImageHelper<Image3dDefaults>::create(context, &imageDesc));
break;
}
EXPECT_NE(nullptr, image.get());
auto mapFlags = CL_MAP_READ;
const size_t region[3] = {1, 1, 1};
auto ptr1 = pCmdQ->enqueueMapImage(image.get(), true, mapFlags, origin1,
region, nullptr, nullptr, 0,
nullptr, nullptr, retVal);
EXPECT_EQ(CL_SUCCESS, retVal);
auto ptr2 = pCmdQ->enqueueMapImage(image.get(), true, mapFlags, origin2,
region, nullptr, nullptr, 0,
nullptr, nullptr, retVal);
EXPECT_EQ(CL_SUCCESS, retVal);
EXPECT_NE(ptr1, ptr2);
if (image->mappingOnCpuAllowed() == false) {
EXPECT_NE(nullptr, image->getAllocatedMapPtr());
}
size_t mapOffset = 16u;
EXPECT_EQ(ptr2, ptrOffset(ptr1, mapOffset));
}
INSTANTIATE_TEST_CASE_P(MipMapMapImageParamsTest_givenAllocatedMapPtrAndMapWithDifferentMipMapsIsCalledThenReturnDifferentPointers,
MipMapMapImageParamsTest, ::testing::Values(CL_MEM_OBJECT_IMAGE1D, CL_MEM_OBJECT_IMAGE1D_ARRAY, CL_MEM_OBJECT_IMAGE2D, CL_MEM_OBJECT_IMAGE2D_ARRAY, CL_MEM_OBJECT_IMAGE3D));
template <typename GfxFamily>
struct mockedImage : public ImageHw<GfxFamily> {
using ImageHw<GfxFamily>::ImageHw;
@ -146,7 +215,8 @@ HWTEST_F(EnqueueMapImageTest, givenTiledImageWhenMapImageIsCalledThenStorageIsSe
true,
true,
0,
&surfaceFormatInfo,
0,
surfaceFormatInfo,
nullptr);
mockImage.createFunction = image->createFunction;
@ -699,7 +769,7 @@ TEST_F(EnqueueMapImageTest, givenBlockedCommandQueueWhenBlockingCpuMapIsCalledTh
}
};
std::unique_ptr<Image> image(ImageHelper<Image1dDefaults>::create(context));
std::unique_ptr<Image> image(ImageHelper<Image1dArrayDefaults>::create(context));
EXPECT_TRUE(image->mappingOnCpuAllowed());
MyMockUserEvent blockingEvent;
@ -712,6 +782,15 @@ TEST_F(EnqueueMapImageTest, givenBlockedCommandQueueWhenBlockingCpuMapIsCalledTh
EXPECT_NE(0u, retImageRowPitch);
EXPECT_NE(0u, retImageSlicePitch);
image.reset(ImageHelper<Image1dDefaults>::create(context));
pCmdQ->enqueueMapImage(image.get(), true, CL_MAP_READ, origin, region,
&retImageRowPitch, &retImageSlicePitch,
1, &blockingClEvent, nullptr, retVal);
EXPECT_EQ(CL_SUCCESS, retVal);
EXPECT_NE(0u, retImageRowPitch);
EXPECT_EQ(0u, retImageSlicePitch);
}
TEST_F(EnqueueMapImageTest, givenZeroCopyImageWhenMappedOnCpuThenReturnImageRowAndSlicePitch) {
@ -720,7 +799,7 @@ TEST_F(EnqueueMapImageTest, givenZeroCopyImageWhenMappedOnCpuThenReturnImageRowA
size_t retImageRowPitch = 0;
size_t retImageSlicePitch = 0;
std::unique_ptr<Image> image(ImageHelper<Image1dDefaults>::create(context));
std::unique_ptr<Image> image(ImageHelper<Image1dArrayDefaults>::create(context));
EXPECT_TRUE(image->mappingOnCpuAllowed());
EXPECT_TRUE(image->isMemObjZeroCopy());
@ -739,7 +818,7 @@ TEST_F(EnqueueMapImageTest, givenNonZeroCopyImageWhenMappedOnCpuThenReturnHostRo
size_t retImageRowPitch = 0;
size_t retImageSlicePitch = 0;
std::unique_ptr<Image> image(ImageHelper<ImageUseHostPtr<Image1dDefaults>>::create(context));
std::unique_ptr<Image> image(ImageHelper<ImageUseHostPtr<Image1dArrayDefaults>>::create(context));
EXPECT_TRUE(image->mappingOnCpuAllowed());
EXPECT_FALSE(image->isMemObjZeroCopy());
@ -758,7 +837,7 @@ TEST_F(EnqueueMapImageTest, givenZeroCopyImageWhenMappedOnGpuThenReturnHostRowAn
size_t retImageRowPitch = 0;
size_t retImageSlicePitch = 0;
std::unique_ptr<Image> image(ImageHelper<Image1dDefaults>::create(context));
std::unique_ptr<Image> image(ImageHelper<Image1dArrayDefaults>::create(context));
image->setSharingHandler(new SharingHandler());
EXPECT_FALSE(image->mappingOnCpuAllowed());
EXPECT_TRUE(image->isMemObjZeroCopy());
@ -778,7 +857,32 @@ TEST_F(EnqueueMapImageTest, givenNonZeroCopyImageWhenMappedOnGpuThenReturnHostRo
size_t retImageRowPitch = 0;
size_t retImageSlicePitch = 0;
std::unique_ptr<Image> image(ImageHelper<ImageUseHostPtr<Image1dDefaults>>::create(context));
std::unique_ptr<Image> image(ImageHelper<ImageUseHostPtr<Image1dArrayDefaults>>::create(context));
image->setSharingHandler(new SharingHandler());
EXPECT_FALSE(image->mappingOnCpuAllowed());
EXPECT_FALSE(image->isMemObjZeroCopy());
pCmdQ->enqueueMapImage(image.get(), true, CL_MAP_READ, origin, region,
&retImageRowPitch, &retImageSlicePitch,
0, nullptr, nullptr, retVal);
EXPECT_EQ(CL_SUCCESS, retVal);
EXPECT_EQ(image->getHostPtrRowPitch(), retImageRowPitch);
EXPECT_EQ(image->getHostPtrSlicePitch(), retImageSlicePitch);
}
TEST_F(EnqueueMapImageTest, givenMipMapImageWhenMappedThenReturnHostRowAndSlicePitch) {
const size_t origin[3] = {0, 0, 0};
const size_t region[3] = {1, 1, 1};
size_t retImageRowPitch = 0;
size_t retImageSlicePitch = 0;
cl_image_desc imageDesc = {};
imageDesc.image_type = CL_MEM_OBJECT_IMAGE1D;
imageDesc.num_mip_levels = 10;
imageDesc.image_width = 4;
std::unique_ptr<Image> image(ImageHelper<ImageUseHostPtr<Image1dArrayDefaults>>::create(context, &imageDesc));
image->setSharingHandler(new SharingHandler());
EXPECT_FALSE(image->mappingOnCpuAllowed());
EXPECT_FALSE(image->isMemObjZeroCopy());

View File

@ -311,9 +311,9 @@ HWTEST_F(MultipleMapBufferTest, givenMultimpleMapsWhenUnmappingThenRemoveCorrect
auto cmdQ = createMockCmdQ<FamilyType>();
MapInfo mappedPtrs[3] = {
{nullptr, 1, {{1, 0, 0}}, {{1, 0, 0}}},
{nullptr, 1, {{2, 0, 0}}, {{2, 0, 0}}},
{nullptr, 1, {{5, 0, 0}}, {{5, 0, 0}}},
{nullptr, 1, {{1, 0, 0}}, {{1, 0, 0}}, 0},
{nullptr, 1, {{2, 0, 0}}, {{2, 0, 0}}, 0},
{nullptr, 1, {{5, 0, 0}}, {{5, 0, 0}}, 0},
};
for (size_t i = 0; i < 3; i++) {

View File

@ -108,7 +108,7 @@ struct MultipleMapImageTest : public DeviceFixture, public ::testing::Test {
auto surfaceFormat = Image::getSurfaceFormatFromTable(Traits::flags, &Traits::imageFormat);
auto img = new MockImage<FamilyType>(context, Traits::flags, 1024, Traits::hostPtr,
Traits::imageFormat, Traits::imageDesc, false, mockAlloc, false,
tiledImage, 0, surfaceFormat);
tiledImage, 0, 0, *surfaceFormat);
return std::unique_ptr<MockImage<FamilyType>>(img);
}
@ -321,9 +321,9 @@ HWTEST_F(MultipleMapImageTest, givenMultimpleMapsWhenUnmappingThenRemoveCorrectP
auto cmdQ = createMockCmdQ<FamilyType>();
MapInfo mappedPtrs[3] = {
{nullptr, 1, {{1, 1, 1}}, {{1, 1, 1}}},
{nullptr, 1, {{4, 4, 2}}, {{4, 4, 4}}},
{nullptr, 1, {{10, 10, 10}}, {{10, 10, 10}}}};
{nullptr, 1, {{1, 1, 1}}, {{1, 1, 1}}, 0},
{nullptr, 1, {{4, 4, 2}}, {{4, 4, 4}}, 0},
{nullptr, 1, {{10, 10, 10}}, {{10, 10, 10}}, 0}};
for (size_t i = 0; i < 3; i++) {
mappedPtrs[i].ptr = clEnqueueMapImage(cmdQ.get(), image.get(), CL_TRUE, CL_MAP_WRITE, &mappedPtrs[i].offset[0], &mappedPtrs[i].size[0],

View File

@ -544,6 +544,14 @@ TEST(Device_GetCaps, deviceReportsThrottleHintsExtension) {
EXPECT_THAT(caps.deviceExtensions, testing::HasSubstr(std::string("cl_khr_throttle_hints")));
}
TEST(Device_GetCaps, deviceReportsMipmapImageExtensions) {
auto device = std::unique_ptr<Device>(DeviceHelper<>::create(platformDevices[0]));
const auto &caps = device->getDeviceInfo();
EXPECT_THAT(caps.deviceExtensions, testing::HasSubstr(std::string("cl_khr_mipmap_image")));
EXPECT_THAT(caps.deviceExtensions, testing::HasSubstr(std::string("cl_khr_mipmap_image_writes")));
}
TEST(Device_GetCaps, givenDeviceThatDoesntHaveFp64ThenExtensionIsNotReported) {
HardwareInfo nonFp64Device = *platformDevices[0];
nonFp64Device.capabilityTable.ftrSupportsFP64 = false;

View File

@ -157,7 +157,8 @@ TYPED_TEST(BaseObjectTests, retain) {
}
TYPED_TEST(BaseObjectTests, castToObjectFromNullptr) {
auto object = castToObject<TypeParam>(nullptr);
typename TypeParam::BaseType *handle = nullptr;
auto object = castToObject<TypeParam>(handle);
EXPECT_EQ(nullptr, object);
}

View File

@ -20,21 +20,194 @@
* OTHER DEALINGS IN THE SOFTWARE.
*/
#include "CL/cl.h"
#include "runtime/helpers/mipmap.h"
#include "runtime/mem_obj/image.h"
#include "unit_tests/mocks/mock_buffer.h"
#include "unit_tests/mocks/mock_gmm.h"
#include "gtest/gtest.h"
using namespace OCLRT;
typedef ::testing::TestWithParam<std::pair<size_t, uint32_t>> mipLevels;
constexpr size_t testOrigin[]{2, 3, 5, 7};
const size_t expectedOrigin[] = {1, 2, 3, 4};
typedef ::testing::TestWithParam<std::pair<uint32_t, size_t>> MipLevelTest;
TEST_P(mipLevels, givenImageTypeReturnProperMipLevel) {
TEST_P(MipLevelTest, givenMemObjectTypeReturnProperMipLevel) {
auto pair = GetParam();
EXPECT_EQ(pair.first, findMipLevel(pair.second, expectedOrigin));
EXPECT_EQ(static_cast<uint32_t>(pair.second), findMipLevel(pair.first, testOrigin));
}
INSTANTIATE_TEST_CASE_P(PatternType,
mipLevels,
::testing::Values(std::make_pair(expectedOrigin[1], CL_MEM_OBJECT_IMAGE1D), std::make_pair(expectedOrigin[2], CL_MEM_OBJECT_IMAGE1D_ARRAY), std::make_pair(expectedOrigin[2], CL_MEM_OBJECT_IMAGE2D), std::make_pair(expectedOrigin[3], CL_MEM_OBJECT_IMAGE2D_ARRAY), std::make_pair(expectedOrigin[3], CL_MEM_OBJECT_IMAGE3D), std::make_pair(0u, 0u)));
INSTANTIATE_TEST_CASE_P(MipLevel,
MipLevelTest,
::testing::Values(std::make_pair(CL_MEM_OBJECT_IMAGE1D, testOrigin[1]),
std::make_pair(CL_MEM_OBJECT_IMAGE1D_ARRAY, testOrigin[2]),
std::make_pair(CL_MEM_OBJECT_IMAGE2D, testOrigin[2]),
std::make_pair(CL_MEM_OBJECT_IMAGE2D_ARRAY, testOrigin[3]),
std::make_pair(CL_MEM_OBJECT_IMAGE3D, testOrigin[3]),
std::make_pair(CL_MEM_OBJECT_BUFFER, 0U),
std::make_pair(CL_MEM_OBJECT_PIPE, 0U)));
typedef ::testing::TestWithParam<std::pair<uint32_t, uint32_t>> MipLevelOriginIdxTest;
TEST_P(MipLevelOriginIdxTest, givenMemObjectTypeReturnProperMipLevelOriginIdx) {
auto pair = GetParam();
EXPECT_EQ(static_cast<uint32_t>(pair.second), getMipLevelOriginIdx(pair.first));
}
INSTANTIATE_TEST_CASE_P(MipLevelOriginIdx,
MipLevelOriginIdxTest,
::testing::Values(std::make_pair(CL_MEM_OBJECT_IMAGE1D, 1U),
std::make_pair(CL_MEM_OBJECT_IMAGE1D_ARRAY, 2U),
std::make_pair(CL_MEM_OBJECT_IMAGE2D, 2U),
std::make_pair(CL_MEM_OBJECT_IMAGE2D_ARRAY, 3U),
std::make_pair(CL_MEM_OBJECT_IMAGE3D, 3U),
std::make_pair(CL_MEM_OBJECT_BUFFER, static_cast<uint32_t>(-1)),
std::make_pair(CL_MEM_OBJECT_PIPE, static_cast<uint32_t>(-1))));
TEST(MipmapHelper, givenClImageDescWithoutMipLevelsWhenIsMipMappedIsCalledThenFalseIsReturned) {
cl_image_desc desc = {};
desc.num_mip_levels = 0;
EXPECT_FALSE(OCLRT::isMipMapped(desc));
desc.num_mip_levels = 1;
EXPECT_FALSE(OCLRT::isMipMapped(desc));
}
TEST(MipmapHelper, givenClImageDescWithMipLevelsWhenIsMipMappedIsCalledThenTrueIsReturned) {
cl_image_desc desc = {};
desc.num_mip_levels = 2;
EXPECT_TRUE(OCLRT::isMipMapped(desc));
}
TEST(MipmapHelper, givenBufferWhenIsMipMappedIsCalledThenFalseIsReturned) {
MockBuffer buffer;
EXPECT_FALSE(OCLRT::isMipMapped(&buffer));
}
struct MockMipMapGmmResourceInfo : GmmResourceInfo {
using GmmResourceInfo::GmmResourceInfo;
GMM_STATUS getOffset(GMM_REQ_OFFSET_INFO &reqOffsetInfo) override {
receivedMipLevel = reqOffsetInfo.MipLevel;
receivedArrayIndex = reqOffsetInfo.ArrayIndex;
receivedSlice = reqOffsetInfo.Slice;
receivedLockFlagVal = reqOffsetInfo.ReqLock;
reqOffsetInfo.Lock.Offset = getExpectedReturnOffset();
return GMM_SUCCESS;
}
uint32_t receivedLockFlagVal = false;
uint32_t receivedMipLevel = 0U;
uint32_t receivedArrayIndex = 0U;
uint32_t receivedSlice = 0U;
static constexpr uint32_t getExpectedReturnOffset() {
return 13;
}
};
struct MockImage : public OCLRT::Image {
using Image::imageDesc;
using Image::graphicsAllocation;
MockGmm mockGmm;
MockImage() : Image(nullptr, cl_mem_flags{}, 0, nullptr, cl_image_format{},
cl_image_desc{}, false, new MockGraphicsAllocation(nullptr, 0), false, false,
0, 0, SurfaceFormatInfo{}, nullptr) {
graphicsAllocation->gmm = &mockGmm;
mockGmm.gmmResourceInfo.reset(new MockMipMapGmmResourceInfo());
}
~MockImage() override {
delete this->graphicsAllocation;
}
MockGraphicsAllocation *getAllocation() {
return static_cast<MockGraphicsAllocation *>(graphicsAllocation);
}
MockMipMapGmmResourceInfo *getResourceInfo() {
return static_cast<MockMipMapGmmResourceInfo *>(mockGmm.gmmResourceInfo.get());
}
void setImageArg(void *memory, bool isMediaBlockImage, uint32_t mipLevel) override {
}
void setMediaImageArg(void *memory) override {
}
void setMediaSurfaceRotation(void *memory) override {
}
void setSurfaceMemoryObjectControlStateIndexToMocsTable(void *memory, uint32_t value) override {
}
};
TEST(MipmapHelper, givenImageWithoutMipLevelsWhenIsMipMappedIsCalledThenFalseIsReturned) {
MockImage image;
image.imageDesc.num_mip_levels = 0;
EXPECT_FALSE(OCLRT::isMipMapped(&image));
image.imageDesc.num_mip_levels = 1;
EXPECT_FALSE(OCLRT::isMipMapped(&image));
}
TEST(MipmapHelper, givenImageWithMipLevelsWhenIsMipMappedIsCalledThenTrueIsReturned) {
MockImage image;
image.imageDesc.num_mip_levels = 2;
EXPECT_TRUE(OCLRT::isMipMapped(&image));
}
TEST(MipmapHelper, givenImageWithoutMipLevelsWhenGetMipOffsetIsCalledThenZeroIsReturned) {
MockImage image;
image.imageDesc.num_mip_levels = 1;
auto offset = getMipOffset(&image, testOrigin);
EXPECT_EQ(0U, offset);
}
struct MipOffsetTestExpVal {
uint32_t expectedSlice = 0;
uint32_t expectedArrayIndex = 0;
static MipOffsetTestExpVal ExpectSlice(size_t expectedSlice) {
MipOffsetTestExpVal ret = {};
ret.expectedSlice = static_cast<uint32_t>(expectedSlice);
return ret;
}
static MipOffsetTestExpVal ExpectArrayIndex(size_t expectedArrayIndex) {
MipOffsetTestExpVal ret = {};
ret.expectedArrayIndex = static_cast<uint32_t>(expectedArrayIndex);
return ret;
}
static MipOffsetTestExpVal ExpectNoSliceOrArrayIndex() {
return MipOffsetTestExpVal{};
}
};
typedef ::testing::TestWithParam<std::pair<uint32_t, MipOffsetTestExpVal>> MipOffsetTest;
TEST_P(MipOffsetTest, givenImageWithMipLevelsWhenGetMipOffsetIsCalledThenProperOffsetIsReturned) {
auto pair = GetParam();
MockImage image;
image.imageDesc.num_mip_levels = 16;
image.imageDesc.image_type = pair.first;
auto offset = getMipOffset(&image, testOrigin);
EXPECT_EQ(MockMipMapGmmResourceInfo::getExpectedReturnOffset(), offset);
EXPECT_EQ(1U, image.getResourceInfo()->receivedLockFlagVal);
EXPECT_EQ(findMipLevel(image.imageDesc.image_type, testOrigin), image.getResourceInfo()->receivedMipLevel);
EXPECT_EQ(pair.second.expectedSlice, image.getResourceInfo()->receivedSlice);
EXPECT_EQ(pair.second.expectedArrayIndex, image.getResourceInfo()->receivedArrayIndex);
}
INSTANTIATE_TEST_CASE_P(MipmapOffset,
MipOffsetTest,
::testing::Values(std::make_pair(CL_MEM_OBJECT_IMAGE1D, MipOffsetTestExpVal::ExpectNoSliceOrArrayIndex()),
std::make_pair(CL_MEM_OBJECT_IMAGE1D_ARRAY, MipOffsetTestExpVal::ExpectArrayIndex(testOrigin[1])),
std::make_pair(CL_MEM_OBJECT_IMAGE2D, MipOffsetTestExpVal::ExpectNoSliceOrArrayIndex()),
std::make_pair(CL_MEM_OBJECT_IMAGE2D_ARRAY, MipOffsetTestExpVal::ExpectArrayIndex(testOrigin[2])),
std::make_pair(CL_MEM_OBJECT_IMAGE3D, MipOffsetTestExpVal::ExpectSlice(testOrigin[2]))));

View File

@ -41,10 +41,6 @@ using namespace OCLRT;
static const unsigned int g_scTestBufferSizeInBytes = 16;
TEST(Buffer, FromCL_nullptr_returnsNullPtr) {
EXPECT_EQ(nullptr, castToObject<Buffer>(nullptr));
}
TEST(Buffer, giveBufferWhenAskedForPtrOffsetForMappingThenReturnCorrectValue) {
MockContext ctx;
cl_int retVal;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, Intel Corporation
* Copyright (c) 2017 - 2018, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@ -74,7 +74,7 @@ HWTEST_F(ImageUnmapTest, givenImageWhenUnmapMemObjIsCalledThenEnqueueNonBlocking
MemObjSizeArray region = {{1, 1, 1}};
image->setAllocatedMapPtr(ptr);
cl_map_flags mapFlags = CL_MAP_WRITE;
image->addMappedPtr(ptr, 1, mapFlags, region, origin);
image->addMappedPtr(ptr, 1, mapFlags, region, origin, 0);
commandQueue->enqueueUnmapMemObject(image.get(), ptr, 0, nullptr, nullptr);
EXPECT_EQ(ptr, commandQueue->passedPtr);
EXPECT_EQ((cl_bool)CL_FALSE, commandQueue->passedBlockingWrite);
@ -88,7 +88,7 @@ HWTEST_F(ImageUnmapTest, givenImageWhenUnmapMemObjIsCalledWithMemUseHostPtrAndWi
MemObjOffsetArray origin = {{0, 0, 0}};
MemObjSizeArray region = {{1, 1, 1}};
cl_map_flags mapFlags = CL_MAP_WRITE;
image->addMappedPtr(ptr, 1, mapFlags, region, origin);
image->addMappedPtr(ptr, 1, mapFlags, region, origin, 0);
commandQueue->enqueueUnmapMemObject(image.get(), ptr, 0, nullptr, nullptr);
EXPECT_EQ(1u, commandQueue->finishCalled);
}
@ -99,7 +99,7 @@ HWTEST_F(ImageUnmapTest, givenImageWhenUnmapMemObjIsCalledWithoutMemUseHostPtrTh
MemObjOffsetArray origin = {{0, 0, 0}};
MemObjSizeArray region = {{1, 1, 1}};
cl_map_flags mapFlags = CL_MAP_WRITE;
image->addMappedPtr(ptr, 2, mapFlags, region, origin);
image->addMappedPtr(ptr, 2, mapFlags, region, origin, 0);
commandQueue->enqueueUnmapMemObject(image.get(), ptr, 0, nullptr, nullptr);
EXPECT_EQ(1u, commandQueue->finishCalled);
}
@ -125,7 +125,7 @@ HWTEST_F(ImageUnmapTest, givenImageWhenUnmapMemObjIsCalledWithMemUseHostPtrAndWi
MemObjOffsetArray origin = {{0, 0, 0}};
MemObjSizeArray region = {{1, 1, 1}};
cl_map_flags mapFlags = CL_MAP_WRITE;
image->addMappedPtr(ptr, 1, mapFlags, region, origin);
image->addMappedPtr(ptr, 1, mapFlags, region, origin, 0);
commandQueue->enqueueUnmapMemObject(image.get(), ptr, 1, &clEvent, nullptr);
EXPECT_EQ(1u, commandQueue->finishCalled);
}

View File

@ -298,9 +298,9 @@ HWTEST_F(ImageSetArgTest, givenImage2DWithMipMapsWhenSetKernelArgIsCalledThenMip
cl_mem memObj = srcImage;
int mipLevel = 2;
uint32_t mipCount = 3;
srcImage->setMipLevel(mipLevel);
srcImage->setBaseMipLevel(mipLevel);
srcImage->setMipCount(mipCount);
EXPECT_EQ(mipLevel, srcImage->peekMipLevel());
EXPECT_EQ(mipLevel, srcImage->peekBaseMipLevel());
EXPECT_EQ(3u, srcImage->peekMipCount());
retVal = clSetKernelArg(

View File

@ -26,6 +26,7 @@
#include "runtime/compiler_interface/compiler_interface.h"
#include "runtime/mem_obj/image.h"
#include "runtime/helpers/aligned_memory.h"
#include "runtime/helpers/mipmap.h"
#include "runtime/built_ins/built_ins.h"
#include "unit_tests/fixtures/memory_management_fixture.h"
#include "unit_tests/helpers/debug_manager_state_restore.h"
@ -1070,3 +1071,39 @@ TEST(ImageTest, givenImageWhenAskedForPtrLengthForCpuMappingThenReturnCorrectVal
EXPECT_EQ(expectedLength, retLength);
}
typedef ::testing::TestWithParam<uint32_t> MipLevelCoordinateTest;
TEST_P(MipLevelCoordinateTest, givenMipmappedImageWhenValidateRegionAndOriginIsCalledThenAdditionalOriginCoordinateIsAnalyzed) {
size_t origin[4]{};
size_t region[3] = {1, 1, 1};
cl_image_desc desc = {};
desc.image_type = GetParam();
desc.num_mip_levels = 2;
origin[getMipLevelOriginIdx(desc.image_type)] = 1;
EXPECT_TRUE(Image::validateRegionAndOrigin(origin, region, desc));
origin[getMipLevelOriginIdx(desc.image_type)] = 2;
EXPECT_FALSE(Image::validateRegionAndOrigin(origin, region, desc));
}
INSTANTIATE_TEST_CASE_P(MipLevelCoordinate,
MipLevelCoordinateTest,
::testing::Values(CL_MEM_OBJECT_IMAGE1D, CL_MEM_OBJECT_IMAGE1D_ARRAY, CL_MEM_OBJECT_IMAGE2D,
CL_MEM_OBJECT_IMAGE2D_ARRAY, CL_MEM_OBJECT_IMAGE3D));
typedef ::testing::TestWithParam<std::pair<uint32_t, bool>> HasSlicesTest;
TEST_P(HasSlicesTest, givenMemObjectTypeWhenHasSlicesIsCalledThenReturnsTrueIfTypeDefinesObjectWithSlicePitch) {
auto pair = GetParam();
EXPECT_EQ(pair.second, Image::hasSlices(pair.first));
}
INSTANTIATE_TEST_CASE_P(HasSlices,
HasSlicesTest,
::testing::Values(std::make_pair(CL_MEM_OBJECT_IMAGE1D, false),
std::make_pair(CL_MEM_OBJECT_IMAGE1D_ARRAY, true),
std::make_pair(CL_MEM_OBJECT_IMAGE2D, false),
std::make_pair(CL_MEM_OBJECT_IMAGE2D_ARRAY, true),
std::make_pair(CL_MEM_OBJECT_IMAGE3D, true),
std::make_pair(CL_MEM_OBJECT_BUFFER, false),
std::make_pair(CL_MEM_OBJECT_PIPE, false)));

View File

@ -1,24 +1,24 @@
/*
* Copyright (c) 2017, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
* Copyright (c) 2017 - 2018, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#include "unit_tests/command_queue/command_queue_fixture.h"
#include "unit_tests/fixtures/image_fixture.h"
@ -121,7 +121,7 @@ TEST_P(CreateTiledImageTest, isTiledImageIsSetForSharedImages) {
nullptr,
CL_MEM_READ_WRITE,
info,
0, 0);
0, 0, 0);
ASSERT_NE(nullptr, image);
@ -159,7 +159,7 @@ TEST_P(CreateNonTiledImageTest, isTiledImageIsNotSetForNonTiledSharedImage) {
nullptr,
CL_MEM_READ_WRITE,
info,
0, 0);
0, 0, 0);
ASSERT_NE(nullptr, image);

View File

@ -36,16 +36,16 @@ struct MockMapOperationsHandler : public MapOperationsHandler {
struct MapOperationsHandlerTests : public ::testing::Test {
MockMapOperationsHandler mockHandler;
MapInfo mappedPtrs[3] = {
{(void *)0x1000, 1, {{1, 2, 3}}, {{4, 5, 6}}},
{(void *)0x2000, 1, {{7, 8, 9}}, {{10, 11, 12}}},
{(void *)0x3000, 1, {{13, 14, 15}}, {{16, 17, 18}}},
{(void *)0x1000, 1, {{1, 2, 3}}, {{4, 5, 6}}, 0},
{(void *)0x2000, 1, {{7, 8, 9}}, {{10, 11, 12}}, 0},
{(void *)0x3000, 1, {{13, 14, 15}}, {{16, 17, 18}}, 0},
};
cl_map_flags mapFlags = CL_MAP_READ;
};
TEST_F(MapOperationsHandlerTests, givenMapInfoWhenFindingThenReturnCorrectvalues) {
for (size_t i = 0; i < 3; i++) {
EXPECT_TRUE(mockHandler.add(mappedPtrs[i].ptr, mappedPtrs[i].ptrLength, mapFlags, mappedPtrs[i].size, mappedPtrs[i].offset));
EXPECT_TRUE(mockHandler.add(mappedPtrs[i].ptr, mappedPtrs[i].ptrLength, mapFlags, mappedPtrs[i].size, mappedPtrs[i].offset, 0));
}
EXPECT_EQ(3u, mockHandler.size());
@ -60,7 +60,7 @@ TEST_F(MapOperationsHandlerTests, givenMapInfoWhenFindingThenReturnCorrectvalues
TEST_F(MapOperationsHandlerTests, givenMapInfoWhenRemovingThenRemoveCorrectPointers) {
for (size_t i = 0; i < 3; i++) {
mockHandler.add(mappedPtrs[i].ptr, mappedPtrs[i].ptrLength, mapFlags, mappedPtrs[i].size, mappedPtrs[i].offset);
mockHandler.add(mappedPtrs[i].ptr, mappedPtrs[i].ptrLength, mapFlags, mappedPtrs[i].size, mappedPtrs[i].offset, 0);
}
for (int i = 2; i >= 0; i--) {
@ -72,8 +72,8 @@ TEST_F(MapOperationsHandlerTests, givenMapInfoWhenRemovingThenRemoveCorrectPoint
}
TEST_F(MapOperationsHandlerTests, givenMappedPtrsWhenDoubleRemovedThenDoNothing) {
mockHandler.add(mappedPtrs[0].ptr, mappedPtrs[0].ptrLength, mapFlags, mappedPtrs[0].size, mappedPtrs[0].offset);
mockHandler.add(mappedPtrs[1].ptr, mappedPtrs[1].ptrLength, mapFlags, mappedPtrs[0].size, mappedPtrs[0].offset);
mockHandler.add(mappedPtrs[0].ptr, mappedPtrs[0].ptrLength, mapFlags, mappedPtrs[0].size, mappedPtrs[0].offset, 0);
mockHandler.add(mappedPtrs[1].ptr, mappedPtrs[1].ptrLength, mapFlags, mappedPtrs[0].size, mappedPtrs[0].offset, 0);
EXPECT_EQ(2u, mockHandler.size());
mockHandler.remove(mappedPtrs[1].ptr);
@ -87,27 +87,27 @@ TEST_F(MapOperationsHandlerTests, givenMappedPtrsWhenDoubleRemovedThenDoNothing)
TEST_F(MapOperationsHandlerTests, givenMapInfoWhenAddedThenSetReadOnlyFlag) {
mapFlags = CL_MAP_READ;
mockHandler.add(mappedPtrs[0].ptr, mappedPtrs[0].ptrLength, mapFlags, mappedPtrs[0].size, mappedPtrs[0].offset);
mockHandler.add(mappedPtrs[0].ptr, mappedPtrs[0].ptrLength, mapFlags, mappedPtrs[0].size, mappedPtrs[0].offset, 0);
EXPECT_TRUE(mockHandler.mappedPointers.back().readOnly);
mockHandler.remove(mappedPtrs[0].ptr);
mapFlags = CL_MAP_WRITE;
mockHandler.add(mappedPtrs[0].ptr, mappedPtrs[0].ptrLength, mapFlags, mappedPtrs[0].size, mappedPtrs[0].offset);
mockHandler.add(mappedPtrs[0].ptr, mappedPtrs[0].ptrLength, mapFlags, mappedPtrs[0].size, mappedPtrs[0].offset, 0);
EXPECT_FALSE(mockHandler.mappedPointers.back().readOnly);
mockHandler.remove(mappedPtrs[0].ptr);
mapFlags = CL_MAP_WRITE_INVALIDATE_REGION;
mockHandler.add(mappedPtrs[0].ptr, mappedPtrs[0].ptrLength, mapFlags, mappedPtrs[0].size, mappedPtrs[0].offset);
mockHandler.add(mappedPtrs[0].ptr, mappedPtrs[0].ptrLength, mapFlags, mappedPtrs[0].size, mappedPtrs[0].offset, 0);
EXPECT_FALSE(mockHandler.mappedPointers.back().readOnly);
mockHandler.remove(mappedPtrs[0].ptr);
mapFlags = CL_MAP_READ | CL_MAP_WRITE;
mockHandler.add(mappedPtrs[0].ptr, mappedPtrs[0].ptrLength, mapFlags, mappedPtrs[0].size, mappedPtrs[0].offset);
mockHandler.add(mappedPtrs[0].ptr, mappedPtrs[0].ptrLength, mapFlags, mappedPtrs[0].size, mappedPtrs[0].offset, 0);
EXPECT_FALSE(mockHandler.mappedPointers.back().readOnly);
mockHandler.remove(mappedPtrs[0].ptr);
mapFlags = CL_MAP_READ | CL_MAP_WRITE_INVALIDATE_REGION;
mockHandler.add(mappedPtrs[0].ptr, mappedPtrs[0].ptrLength, mapFlags, mappedPtrs[0].size, mappedPtrs[0].offset);
mockHandler.add(mappedPtrs[0].ptr, mappedPtrs[0].ptrLength, mapFlags, mappedPtrs[0].size, mappedPtrs[0].offset, 0);
EXPECT_FALSE(mockHandler.mappedPointers.back().readOnly);
mockHandler.remove(mappedPtrs[0].ptr);
}
@ -115,24 +115,24 @@ TEST_F(MapOperationsHandlerTests, givenMapInfoWhenAddedThenSetReadOnlyFlag) {
TEST_F(MapOperationsHandlerTests, givenNonReadOnlyOverlappingPtrWhenAddingThenReturnFalseAndDontAdd) {
mapFlags = CL_MAP_WRITE;
mappedPtrs->readOnly = false;
mockHandler.add(mappedPtrs[0].ptr, mappedPtrs[0].ptrLength, mapFlags, mappedPtrs[0].size, mappedPtrs[0].offset);
mockHandler.add(mappedPtrs[0].ptr, mappedPtrs[0].ptrLength, mapFlags, mappedPtrs[0].size, mappedPtrs[0].offset, 0);
EXPECT_EQ(1u, mockHandler.size());
EXPECT_FALSE(mockHandler.mappedPointers.back().readOnly);
EXPECT_TRUE(mockHandler.isOverlapping(mappedPtrs[0]));
EXPECT_FALSE(mockHandler.add(mappedPtrs[0].ptr, mappedPtrs[0].ptrLength, mapFlags, mappedPtrs[0].size, mappedPtrs[0].offset));
EXPECT_FALSE(mockHandler.add(mappedPtrs[0].ptr, mappedPtrs[0].ptrLength, mapFlags, mappedPtrs[0].size, mappedPtrs[0].offset, 0));
EXPECT_EQ(1u, mockHandler.size());
}
TEST_F(MapOperationsHandlerTests, givenReadOnlyOverlappingPtrWhenAddingThenReturnTrueAndAdd) {
mapFlags = CL_MAP_READ;
mappedPtrs->readOnly = true;
mockHandler.add(mappedPtrs[0].ptr, mappedPtrs[0].ptrLength, mapFlags, mappedPtrs[0].size, mappedPtrs[0].offset);
mockHandler.add(mappedPtrs[0].ptr, mappedPtrs[0].ptrLength, mapFlags, mappedPtrs[0].size, mappedPtrs[0].offset, 0);
EXPECT_EQ(1u, mockHandler.size());
EXPECT_TRUE(mockHandler.mappedPointers.back().readOnly);
EXPECT_FALSE(mockHandler.isOverlapping(mappedPtrs[0]));
EXPECT_TRUE(mockHandler.add(mappedPtrs[0].ptr, mappedPtrs[0].ptrLength, mapFlags, mappedPtrs[0].size, mappedPtrs[0].offset));
EXPECT_TRUE(mockHandler.add(mappedPtrs[0].ptr, mappedPtrs[0].ptrLength, mapFlags, mappedPtrs[0].size, mappedPtrs[0].offset, 0));
EXPECT_EQ(2u, mockHandler.size());
EXPECT_TRUE(mockHandler.mappedPointers.back().readOnly);
}
@ -161,12 +161,12 @@ TEST_P(MapOperationsHandlerOverlapTests, givenAlreadyMappedPtrWhenAskingForOverl
bool expectOverlap = std::get<4>(GetParam());
// size and offset arrays are ignored
MapInfo mappedInfo(mappedPtr, mappedPtrLength, {{0, 0, 0}}, {{0, 0, 0}});
MapInfo requestedInfo(requestedPtr, requestedPtrLength, {{0, 0, 0}}, {{0, 0, 0}});
MapInfo mappedInfo(mappedPtr, mappedPtrLength, {{0, 0, 0}}, {{0, 0, 0}}, 0);
MapInfo requestedInfo(requestedPtr, requestedPtrLength, {{0, 0, 0}}, {{0, 0, 0}}, 0);
requestedInfo.readOnly = false;
MockMapOperationsHandler mockHandler;
mockHandler.add(mappedInfo.ptr, mappedInfo.ptrLength, mapFlags, mappedInfo.size, mappedInfo.offset);
mockHandler.add(mappedInfo.ptr, mappedInfo.ptrLength, mapFlags, mappedInfo.size, mappedInfo.offset, 0);
EXPECT_EQ(expectOverlap, mockHandler.isOverlapping(requestedInfo));
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, Intel Corporation
* Copyright (c) 2017 - 2018, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@ -192,7 +192,7 @@ HWTEST_P(MemObjAsyncDestructionTest, givenUsedMemObjWithAsyncDestructionsEnabled
CL_MEM_READ_WRITE,
size,
storage, nullptr, allocation, true, false, false);
memObj->addMappedPtr(storage, 1, mapFlags, region, origin);
memObj->addMappedPtr(storage, 1, mapFlags, region, origin, 0);
} else {
memObj->setAllocatedMapPtr(storage);
}

View File

@ -298,8 +298,9 @@ TEST(MemObj, givenTiledObjectWhenAskedForCpuMappingThenReturnFalse) {
}
TEST(MemObj, givenDefaultWhenAskedForCpuMappingThenReturnTrue) {
char mem[64];
MemObj memObj(nullptr, CL_MEM_OBJECT_BUFFER, CL_MEM_COPY_HOST_PTR,
MemoryConstants::pageSize, nullptr, nullptr, nullptr, true, false, false);
MemoryConstants::pageSize, mem, nullptr, nullptr, true, false, false);
EXPECT_FALSE(memObj.allowTiling());
EXPECT_FALSE(memObj.peekSharingHandler());

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, Intel Corporation
* Copyright (c) 2017 - 2018, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@ -40,6 +40,8 @@ class MockBufferStorage {
class MockBuffer : public MockBufferStorage, public Buffer {
public:
using Buffer::magic;
MockBuffer(GraphicsAllocation &alloc)
: MockBufferStorage(), Buffer(nullptr, CL_MEM_USE_HOST_PTR, alloc.getUnderlyingBufferSize(), alloc.getUnderlyingBuffer(), alloc.getUnderlyingBuffer(), &alloc, true, false, false),
externalAlloc(&alloc) {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, Intel Corporation
* Copyright (c) 2017 - 2018, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@ -42,9 +42,9 @@ class MockGmm : public Gmm {
return std::unique_ptr<Gmm>(Gmm::createGmmAndQueryImgParams(imgInfo, *queryHwInfo));
}
static ImageInfo initImgInfo(cl_image_desc &imgDesc, int mipLevel, const SurfaceFormatInfo *surfaceFormat) {
static ImageInfo initImgInfo(cl_image_desc &imgDesc, int baseMipLevel, const SurfaceFormatInfo *surfaceFormat) {
ImageInfo imgInfo = {0};
imgInfo.mipLevel = mipLevel;
imgInfo.baseMipLevel = baseMipLevel;
imgInfo.imgDesc = &imgDesc;
if (!surfaceFormat) {
MockGmmParams::mockSurfaceFormat = readWriteSurfaceFormats[0]; // any valid format

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, Intel Corporation
* Copyright (c) 2017 - 2018, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@ -74,6 +74,9 @@ GMM_STATUS MockGmmResourceInfo::getOffset(GMM_REQ_OFFSET_INFO &reqOffsetInfo) {
if (reqOffsetInfo.Slice == 1) {
reqOffsetInfo.Render.YOffset = mockResourceCreateParams.BaseHeight;
}
if (reqOffsetInfo.MipLevel > 0) {
reqOffsetInfo.Lock.Offset = 32;
}
return GMM_SUCCESS;
}

View File

@ -40,15 +40,17 @@
#include "unit_tests/program/program_from_binary.h"
#include "unit_tests/program/program_with_source.h"
#include "test.h"
#include <memory>
#include <vector>
#include <map>
#include "unit_tests/fixtures/device_fixture.h"
#include "unit_tests/mocks/mock_program.h"
#include "gtest/gtest.h"
#include "gmock/gmock.h"
#include "elf/reader.h"
#include <map>
#include <memory>
#include <string>
#include <vector>
using namespace OCLRT;
void ProgramTests::SetUp() {
@ -1018,16 +1020,20 @@ TEST_P(ProgramFromSourceTest, CompileProgramWithReraFlag) {
~MyCompilerInterface2() override{};
cl_int compile(Program &program, const TranslationArgs &inputArgs) override {
strcpy_s(&buildOptions[0], sizeof(buildOptions), inputArgs.pOptions);
strcpy_s(&buildInternalOptions[0], sizeof(buildInternalOptions), inputArgs.pInternalOptions);
if ((inputArgs.OptionsSize > 0) && (inputArgs.pOptions != nullptr)) {
buildOptions.assign(inputArgs.pOptions, inputArgs.pOptions + inputArgs.OptionsSize);
}
if ((inputArgs.OptionsSize > 0) && (inputArgs.pOptions != nullptr)) {
buildInternalOptions.assign(inputArgs.pInternalOptions, inputArgs.pInternalOptions + inputArgs.InternalOptionsSize);
}
return CL_SUCCESS;
}
void getBuildOptions(std::string &s) { s = buildOptions; }
void getBuildInternalOptions(std::string &s) { s = buildInternalOptions; }
protected:
char buildOptions[256];
char buildInternalOptions[1024];
std::string buildOptions;
std::string buildInternalOptions;
};
class MyProgram2 : public Program {