Skip to content

Commit 0a97dfb

Browse files
committed
[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
1 parent 6506df5 commit 0a97dfb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+778
-247
lines changed

Jenkinsfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
neoDependenciesRev='748020-807'
33
strategy='EQUAL'
44
allowedF=40
5-
allowedCD=336
5+
allowedCD=335

runtime/api/api.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2057,7 +2057,7 @@ cl_int CL_API_CALL clEnqueueReadImage(cl_command_queue commandQueue,
20572057
if (retVal != CL_SUCCESS)
20582058
return retVal;
20592059
}
2060-
if (!Image::validateRegionAndOrigin(origin, region, pImage->getImageDesc().image_type)) {
2060+
if (!Image::validateRegionAndOrigin(origin, region, pImage->getImageDesc())) {
20612061
return CL_INVALID_VALUE;
20622062
}
20632063

@@ -2113,7 +2113,7 @@ cl_int CL_API_CALL clEnqueueWriteImage(cl_command_queue commandQueue,
21132113
if (retVal != CL_SUCCESS)
21142114
return retVal;
21152115
}
2116-
if (!Image::validateRegionAndOrigin(origin, region, pImage->getImageDesc().image_type)) {
2116+
if (!Image::validateRegionAndOrigin(origin, region, pImage->getImageDesc())) {
21172117
return CL_INVALID_VALUE;
21182118
}
21192119

@@ -2159,7 +2159,7 @@ cl_int CL_API_CALL clEnqueueFillImage(cl_command_queue commandQueue,
21592159
"numEventsInWaitList", numEventsInWaitList, "event", event);
21602160

21612161
if (CL_SUCCESS == retVal) {
2162-
if (!Image::validateRegionAndOrigin(origin, region, dstImage->getImageDesc().image_type)) {
2162+
if (!Image::validateRegionAndOrigin(origin, region, dstImage->getImageDesc())) {
21632163
return CL_INVALID_VALUE;
21642164
}
21652165

@@ -2217,10 +2217,10 @@ cl_int CL_API_CALL clEnqueueCopyImage(cl_command_queue commandQueue,
22172217
if (pDstImage->getImageDesc().image_type == CL_MEM_OBJECT_IMAGE2D && dstOrigin[2] != 0)
22182218
return CL_INVALID_VALUE;
22192219
}
2220-
if (!Image::validateRegionAndOrigin(srcOrigin, region, pSrcImage->getImageDesc().image_type)) {
2220+
if (!Image::validateRegionAndOrigin(srcOrigin, region, pSrcImage->getImageDesc())) {
22212221
return CL_INVALID_VALUE;
22222222
}
2223-
if (!Image::validateRegionAndOrigin(dstOrigin, region, pDstImage->getImageDesc().image_type)) {
2223+
if (!Image::validateRegionAndOrigin(dstOrigin, region, pDstImage->getImageDesc())) {
22242224
return CL_INVALID_VALUE;
22252225
}
22262226

@@ -2271,7 +2271,7 @@ cl_int CL_API_CALL clEnqueueCopyImageToBuffer(cl_command_queue commandQueue,
22712271
if (retVal != CL_SUCCESS)
22722272
return retVal;
22732273
}
2274-
if (!Image::validateRegionAndOrigin(srcOrigin, region, pSrcImage->getImageDesc().image_type)) {
2274+
if (!Image::validateRegionAndOrigin(srcOrigin, region, pSrcImage->getImageDesc())) {
22752275
return CL_INVALID_VALUE;
22762276
}
22772277

@@ -2323,7 +2323,7 @@ cl_int CL_API_CALL clEnqueueCopyBufferToImage(cl_command_queue commandQueue,
23232323
if (retVal != CL_SUCCESS)
23242324
return retVal;
23252325
}
2326-
if (!Image::validateRegionAndOrigin(dstOrigin, region, pDstImage->getImageDesc().image_type)) {
2326+
if (!Image::validateRegionAndOrigin(dstOrigin, region, pDstImage->getImageDesc())) {
23272327
return CL_INVALID_VALUE;
23282328
}
23292329

@@ -2452,7 +2452,7 @@ void *CL_API_CALL clEnqueueMapImage(cl_command_queue commandQueue,
24522452
}
24532453
}
24542454

2455-
if (!Image::validateRegionAndOrigin(origin, region, pImage->getImageDesc().image_type)) {
2455+
if (!Image::validateRegionAndOrigin(origin, region, pImage->getImageDesc())) {
24562456
retVal = CL_INVALID_VALUE;
24572457
break;
24582458
}

runtime/command_queue/command_queue.cpp

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "runtime/helpers/aligned_memory.h"
3434
#include "runtime/helpers/array_count.h"
3535
#include "runtime/helpers/get_info.h"
36+
#include "runtime/helpers/mipmap.h"
3637
#include "runtime/helpers/options.h"
3738
#include "runtime/helpers/ptr_math.h"
3839
#include "runtime/mem_obj/buffer.h"
@@ -463,8 +464,12 @@ cl_int CommandQueue::enqueueWriteMemObjForUnmap(MemObj *memObj, void *mappedPtr,
463464
retVal = enqueueWriteBuffer(buffer, CL_TRUE, unmapInfo.offset[0], unmapInfo.size[0], mappedPtr,
464465
eventsRequest.numEventsInWaitList, eventsRequest.eventWaitList, eventsRequest.outEvent);
465466
} else {
466-
auto image = castToObject<Image>(memObj);
467-
retVal = enqueueWriteImage(image, CL_FALSE, &unmapInfo.offset[0], &unmapInfo.size[0],
467+
auto image = castToObjectOrAbort<Image>(memObj);
468+
size_t writeOrigin[4] = {unmapInfo.offset[0], unmapInfo.offset[1], unmapInfo.offset[2], 0};
469+
auto mipIdx = getMipLevelOriginIdx(image->peekClMemObjType());
470+
UNRECOVERABLE_IF(mipIdx >= 4);
471+
writeOrigin[mipIdx] = unmapInfo.mipLevel;
472+
retVal = enqueueWriteImage(image, CL_FALSE, writeOrigin, &unmapInfo.size[0],
468473
image->getHostPtrRowPitch(), image->getHostPtrSlicePitch(), mappedPtr,
469474
eventsRequest.numEventsInWaitList, eventsRequest.eventWaitList, eventsRequest.outEvent);
470475
bool mustCallFinish = true;
@@ -493,10 +498,10 @@ cl_int CommandQueue::enqueueWriteMemObjForUnmap(MemObj *memObj, void *mappedPtr,
493498

494499
void *CommandQueue::enqueueReadMemObjForMap(TransferProperties &transferProperties, EventsRequest &eventsRequest, cl_int &errcodeRet) {
495500
void *returnPtr = ptrOffset(transferProperties.memObj->getBasePtrForMap(),
496-
transferProperties.memObj->calculateOffsetForMapping(transferProperties.offset));
501+
transferProperties.memObj->calculateOffsetForMapping(transferProperties.offset) + transferProperties.mipPtrOffset);
497502

498503
if (!transferProperties.memObj->addMappedPtr(returnPtr, transferProperties.memObj->calculateMappedPtrLength(transferProperties.size),
499-
transferProperties.mapFlags, transferProperties.size, transferProperties.offset)) {
504+
transferProperties.mapFlags, transferProperties.size, transferProperties.offset, transferProperties.mipLevel)) {
500505
errcodeRet = CL_INVALID_OPERATION;
501506
return nullptr;
502507
}
@@ -506,8 +511,12 @@ void *CommandQueue::enqueueReadMemObjForMap(TransferProperties &transferProperti
506511
errcodeRet = enqueueReadBuffer(buffer, transferProperties.blocking, transferProperties.offset[0], transferProperties.size[0], returnPtr,
507512
eventsRequest.numEventsInWaitList, eventsRequest.eventWaitList, eventsRequest.outEvent);
508513
} else {
509-
auto image = castToObject<Image>(transferProperties.memObj);
510-
errcodeRet = enqueueReadImage(image, transferProperties.blocking, &transferProperties.offset[0], &transferProperties.size[0],
514+
auto image = castToObjectOrAbort<Image>(transferProperties.memObj);
515+
size_t readOrigin[4] = {transferProperties.offset[0], transferProperties.offset[1], transferProperties.offset[2], 0};
516+
auto mipIdx = getMipLevelOriginIdx(image->peekClMemObjType());
517+
UNRECOVERABLE_IF(mipIdx >= 4);
518+
readOrigin[mipIdx] = transferProperties.mipLevel;
519+
errcodeRet = enqueueReadImage(image, transferProperties.blocking, readOrigin, &transferProperties.size[0],
511520
image->getHostPtrRowPitch(), image->getHostPtrSlicePitch(), returnPtr, eventsRequest.numEventsInWaitList,
512521
eventsRequest.eventWaitList, eventsRequest.outEvent);
513522
}
@@ -560,7 +569,6 @@ void *CommandQueue::enqueueMapImage(Image *image, cl_bool blockingMap,
560569
cl_uint numEventsInWaitList,
561570
const cl_event *eventWaitList, cl_event *event,
562571
cl_int &errcodeRet) {
563-
564572
TransferProperties transferProperties(image, CL_COMMAND_MAP_IMAGE, mapFlags, blockingMap != CL_FALSE,
565573
const_cast<size_t *>(origin), const_cast<size_t *>(region), nullptr);
566574
EventsRequest eventsRequest(numEventsInWaitList, eventWaitList, event);
@@ -572,7 +580,9 @@ void *CommandQueue::enqueueMapImage(Image *image, cl_bool blockingMap,
572580
GetInfoHelper::set(imageSlicePitch, image->getHostPtrSlicePitch());
573581
GetInfoHelper::set(imageRowPitch, image->getHostPtrRowPitch());
574582
}
575-
583+
if (Image::hasSlices(image->peekClMemObjType()) == false) {
584+
GetInfoHelper::set(imageSlicePitch, static_cast<size_t>(0));
585+
}
576586
return enqueueMapMemObject(transferProperties, eventsRequest, errcodeRet);
577587
}
578588

runtime/command_queue/cpu_data_transfer_handler.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "runtime/context/context.h"
2626
#include "runtime/event/event_builder.h"
2727
#include "runtime/helpers/get_info.h"
28+
#include "runtime/helpers/mipmap.h"
2829
#include "runtime/mem_obj/buffer.h"
2930
#include "runtime/mem_obj/image.h"
3031

@@ -41,10 +42,10 @@ void *CommandQueue::cpuDataTransferHandler(TransferProperties &transferPropertie
4142

4243
if (mapOperation) {
4344
returnPtr = ptrOffset(transferProperties.memObj->getCpuAddressForMapping(),
44-
transferProperties.memObj->calculateOffsetForMapping(transferProperties.offset));
45+
transferProperties.memObj->calculateOffsetForMapping(transferProperties.offset) + transferProperties.mipPtrOffset);
4546

4647
if (!transferProperties.memObj->addMappedPtr(returnPtr, transferProperties.memObj->calculateMappedPtrLength(transferProperties.size),
47-
transferProperties.mapFlags, transferProperties.size, transferProperties.offset)) {
48+
transferProperties.mapFlags, transferProperties.size, transferProperties.offset, transferProperties.mipLevel)) {
4849
err.set(CL_INVALID_OPERATION);
4950
return nullptr;
5051
}
@@ -115,6 +116,7 @@ void *CommandQueue::cpuDataTransferHandler(TransferProperties &transferPropertie
115116
outEventObj->setStartTimeStamp();
116117
}
117118

119+
UNRECOVERABLE_IF((transferProperties.memObj->isMemObjZeroCopy() == false) && isMipMapped(transferProperties.memObj));
118120
switch (transferProperties.cmdType) {
119121
case CL_COMMAND_MAP_BUFFER:
120122
if (!transferProperties.memObj->isMemObjZeroCopy()) {

runtime/gmm_helper/gmm_helper.cpp

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
/*
2-
* Copyright (c) 2017, Intel Corporation
3-
*
4-
* Permission is hereby granted, free of charge, to any person obtaining a
5-
* copy of this software and associated documentation files (the "Software"),
6-
* to deal in the Software without restriction, including without limitation
7-
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
8-
* and/or sell copies of the Software, and to permit persons to whom the
9-
* Software is furnished to do so, subject to the following conditions:
10-
*
11-
* The above copyright notice and this permission notice shall be included
12-
* in all copies or substantial portions of the Software.
13-
*
14-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15-
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17-
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18-
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19-
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20-
* OTHER DEALINGS IN THE SOFTWARE.
21-
*/
2+
* Copyright (c) 2017 - 2018, Intel Corporation
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a
5+
* copy of this software and associated documentation files (the "Software"),
6+
* to deal in the Software without restriction, including without limitation
7+
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
8+
* and/or sell copies of the Software, and to permit persons to whom the
9+
* Software is furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included
12+
* in all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15+
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17+
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18+
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19+
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20+
* OTHER DEALINGS IN THE SOFTWARE.
21+
*/
2222

2323
#include "runtime/gmm_helper/gmm_helper.h"
2424
#include "runtime/gmm_helper/resource_info.h"
@@ -178,7 +178,7 @@ void Gmm::queryImageParams(ImageInfo &imgInfo, const HardwareInfo &hwInfo) {
178178
this->resourceParams.Depth = imageDepth;
179179
this->resourceParams.ArraySize = imageCount;
180180
this->resourceParams.Flags.Wa.__ForceOtherHVALIGN4 = 1;
181-
this->resourceParams.MaxLod = imgInfo.mipLevel;
181+
this->resourceParams.MaxLod = imgInfo.baseMipLevel + imgInfo.mipCount;
182182
if (imgInfo.imgDesc->image_row_pitch && imgInfo.imgDesc->mem_object) {
183183
this->resourceParams.OverridePitch = (uint32_t)imgInfo.imgDesc->image_row_pitch;
184184
this->resourceParams.Flags.Info.AllowVirtualPadding = true;

runtime/helpers/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ set(RUNTIME_SRCS_HELPERS_BASE
5656
${CMAKE_CURRENT_SOURCE_DIR}/kernel_commands.inl
5757
${CMAKE_CURRENT_SOURCE_DIR}/kmd_notify_properties.h
5858
${CMAKE_CURRENT_SOURCE_DIR}/kmd_notify_properties.cpp
59+
${CMAKE_CURRENT_SOURCE_DIR}/mipmap.cpp
5960
${CMAKE_CURRENT_SOURCE_DIR}/mipmap.h
6061
${CMAKE_CURRENT_SOURCE_DIR}/options.cpp
6162
${CMAKE_CURRENT_SOURCE_DIR}/options.h

runtime/helpers/base_object.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, Intel Corporation
2+
* Copyright (c) 2017 - 2018, Intel Corporation
33
*
44
* Permission is hereby granted, free of charge, to any person obtaining a
55
* copy of this software and associated documentation files (the "Software"),
@@ -73,6 +73,11 @@ inline DerivedType *castToObjectOrAbort(typename DerivedType::BaseType *object)
7373
}
7474
}
7575

76+
template <typename DerivedType>
77+
inline const DerivedType *castToObject(const typename DerivedType::BaseType *object) {
78+
return const_cast<const DerivedType *>(castToObject<DerivedType>(const_cast<typename DerivedType::BaseType *>(object)));
79+
}
80+
7681
extern std::thread::id invalidThreadID;
7782

7883
class ConditionVariableWithCounter {

runtime/helpers/debug_helpers.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, Intel Corporation
2+
* Copyright (c) 2017 - 2018, Intel Corporation
33
*
44
* Permission is hereby granted, free of charge, to any person obtaining a
55
* copy of this software and associated documentation files (the "Software"),
@@ -43,5 +43,5 @@
4343

4444
namespace OCLRT {
4545
void debugBreak(int line, const char *file);
46-
void abortUnrecoverable(int line, const char *file);
46+
[[noreturn]] void abortUnrecoverable(int line, const char *file);
4747
} // namespace OCLRT

runtime/helpers/mipmap.cpp

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
/*
2+
* Copyright (c) 2018, Intel Corporation
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a
5+
* copy of this software and associated documentation files (the "Software"),
6+
* to deal in the Software without restriction, including without limitation
7+
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
8+
* and/or sell copies of the Software, and to permit persons to whom the
9+
* Software is furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included
12+
* in all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15+
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17+
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18+
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19+
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20+
* OTHER DEALINGS IN THE SOFTWARE.
21+
*/
22+
23+
#include "runtime/helpers/mipmap.h"
24+
25+
#include "runtime/gmm_helper/gmm_helper.h"
26+
#include "runtime/gmm_helper/resource_info.h"
27+
#include "runtime/mem_obj/image.h"
28+
29+
#include <cstdint>
30+
31+
namespace OCLRT {
32+
33+
uint32_t getMipLevelOriginIdx(cl_mem_object_type imageType) {
34+
switch (imageType) {
35+
case CL_MEM_OBJECT_IMAGE1D:
36+
return 1;
37+
case CL_MEM_OBJECT_IMAGE1D_ARRAY:
38+
case CL_MEM_OBJECT_IMAGE2D:
39+
return 2;
40+
case CL_MEM_OBJECT_IMAGE2D_ARRAY:
41+
case CL_MEM_OBJECT_IMAGE3D:
42+
return 3;
43+
default:
44+
DEBUG_BREAK_IF(true);
45+
return -1;
46+
}
47+
}
48+
49+
uint32_t findMipLevel(cl_mem_object_type imageType, const size_t *origin) {
50+
size_t mipLevel = 0;
51+
switch (imageType) {
52+
case CL_MEM_OBJECT_IMAGE1D:
53+
case CL_MEM_OBJECT_IMAGE1D_ARRAY:
54+
case CL_MEM_OBJECT_IMAGE2D:
55+
case CL_MEM_OBJECT_IMAGE2D_ARRAY:
56+
case CL_MEM_OBJECT_IMAGE3D:
57+
mipLevel = origin[getMipLevelOriginIdx(imageType)];
58+
break;
59+
default:
60+
mipLevel = 0;
61+
break;
62+
}
63+
64+
return static_cast<uint32_t>(mipLevel);
65+
}
66+
67+
bool isMipMapped(const MemObj *memObj) {
68+
auto image = castToObject<Image>(memObj);
69+
if (image == nullptr) {
70+
return false;
71+
}
72+
return isMipMapped(image->getImageDesc());
73+
}
74+
75+
uint32_t getMipOffset(Image *image, const size_t *origin) {
76+
if (isMipMapped(image) == false) {
77+
return 0;
78+
}
79+
UNRECOVERABLE_IF(origin == nullptr);
80+
81+
auto imageType = image->getImageDesc().image_type;
82+
GMM_REQ_OFFSET_INFO GMMReqInfo = {};
83+
GMMReqInfo.ReqLock = 1;
84+
GMMReqInfo.MipLevel = findMipLevel(imageType, origin);
85+
switch (imageType) {
86+
case CL_MEM_OBJECT_IMAGE1D_ARRAY:
87+
GMMReqInfo.ArrayIndex = static_cast<uint32_t>(origin[1]);
88+
break;
89+
case CL_MEM_OBJECT_IMAGE2D_ARRAY:
90+
GMMReqInfo.ArrayIndex = static_cast<uint32_t>(origin[2]);
91+
break;
92+
case CL_MEM_OBJECT_IMAGE3D:
93+
GMMReqInfo.Slice = static_cast<uint32_t>(origin[2]);
94+
break;
95+
default:
96+
break;
97+
}
98+
99+
auto graphicsAlloc = image->getGraphicsAllocation();
100+
UNRECOVERABLE_IF(graphicsAlloc == nullptr);
101+
UNRECOVERABLE_IF(graphicsAlloc->gmm == nullptr);
102+
auto gmmResourceInfo = graphicsAlloc->gmm->gmmResourceInfo.get();
103+
UNRECOVERABLE_IF(gmmResourceInfo == nullptr);
104+
105+
gmmResourceInfo->getOffset(GMMReqInfo);
106+
107+
return GMMReqInfo.Lock.Offset;
108+
}
109+
} // namespace OCLRT

0 commit comments

Comments
 (0)