2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2021-05-17 02:51:16 +08:00
|
|
|
* Copyright (C) 2018-2021 Intel Corporation
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
2018-09-18 15:11:08 +08:00
|
|
|
* SPDX-License-Identifier: MIT
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
2020-02-24 20:10:44 +08:00
|
|
|
#include "shared/source/built_ins/built_ins.h"
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/command_stream/command_stream_receiver.h"
|
|
|
|
#include "shared/source/helpers/basic_math.h"
|
|
|
|
#include "shared/source/helpers/cache_policy.h"
|
2020-07-10 22:04:01 +08:00
|
|
|
#include "shared/source/helpers/engine_node_helper.h"
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/memory_manager/graphics_allocation.h"
|
2020-07-10 22:04:01 +08:00
|
|
|
#include "shared/source/os_interface/os_context.h"
|
2020-02-24 17:22:30 +08:00
|
|
|
|
2020-02-23 05:50:57 +08:00
|
|
|
#include "opencl/source/command_queue/command_queue_hw.h"
|
|
|
|
#include "opencl/source/context/context.h"
|
|
|
|
#include "opencl/source/event/event.h"
|
|
|
|
#include "opencl/source/helpers/hardware_commands_helper.h"
|
|
|
|
#include "opencl/source/helpers/mipmap.h"
|
|
|
|
#include "opencl/source/mem_obj/image.h"
|
|
|
|
#include "opencl/source/memory_manager/mem_obj_surface.h"
|
2019-02-27 18:39:32 +08:00
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
#include <algorithm>
|
|
|
|
#include <new>
|
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
namespace NEO {
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
template <typename GfxFamily>
|
|
|
|
cl_int CommandQueueHw<GfxFamily>::enqueueReadImage(
|
|
|
|
Image *srcImage,
|
|
|
|
cl_bool blockingRead,
|
|
|
|
const size_t *origin,
|
|
|
|
const size_t *region,
|
|
|
|
size_t inputRowPitch,
|
|
|
|
size_t inputSlicePitch,
|
|
|
|
void *ptr,
|
2019-04-16 00:17:28 +08:00
|
|
|
GraphicsAllocation *mapAllocation,
|
2017-12-21 07:45:38 +08:00
|
|
|
cl_uint numEventsInWaitList,
|
|
|
|
const cl_event *eventWaitList,
|
|
|
|
cl_event *event) {
|
2021-09-07 01:04:14 +08:00
|
|
|
constexpr cl_command_type cmdType = CL_COMMAND_READ_IMAGE;
|
|
|
|
|
|
|
|
CsrSelectionArgs csrSelectionArgs{cmdType, srcImage, {}, device->getRootDeviceIndex(), region, origin, nullptr};
|
|
|
|
CommandStreamReceiver &csr = selectCsrForBuiltinOperation(csrSelectionArgs);
|
2021-09-02 18:14:12 +08:00
|
|
|
|
|
|
|
if (nullptr == mapAllocation) {
|
|
|
|
notifyEnqueueReadImage(srcImage, static_cast<bool>(blockingRead), EngineHelpers::isBcs(csr.getOsContext().getEngineType()));
|
|
|
|
}
|
2018-08-23 00:41:52 +08:00
|
|
|
|
2018-02-07 21:48:24 +08:00
|
|
|
auto isMemTransferNeeded = true;
|
|
|
|
if (srcImage->isMemObjZeroCopy()) {
|
|
|
|
size_t hostOffset;
|
2020-01-09 00:29:15 +08:00
|
|
|
Image::calculateHostPtrOffset(&hostOffset, origin, region, inputRowPitch, inputSlicePitch, srcImage->getImageDesc().image_type, srcImage->getSurfaceFormatInfo().surfaceFormat.ImageElementSizeInBytes);
|
2020-10-20 21:27:49 +08:00
|
|
|
isMemTransferNeeded = srcImage->checkIfMemoryTransferIsRequired(hostOffset, 0, ptr, cmdType);
|
2018-02-07 21:48:24 +08:00
|
|
|
}
|
2018-02-02 17:19:13 +08:00
|
|
|
if (!isMemTransferNeeded) {
|
2020-10-20 21:27:49 +08:00
|
|
|
return enqueueMarkerForReadWriteOperation(srcImage, ptr, cmdType, blockingRead,
|
2019-05-30 20:36:12 +08:00
|
|
|
numEventsInWaitList, eventWaitList, event);
|
2018-02-02 17:19:13 +08:00
|
|
|
}
|
|
|
|
|
2018-12-12 00:06:47 +08:00
|
|
|
size_t hostPtrSize = calculateHostPtrSizeForImage(region, inputRowPitch, inputSlicePitch, srcImage);
|
2018-02-09 05:52:58 +08:00
|
|
|
void *dstPtr = ptr;
|
|
|
|
|
|
|
|
MemObjSurface srcImgSurf(srcImage);
|
|
|
|
HostPtrSurface hostPtrSurf(dstPtr, hostPtrSize);
|
2019-04-16 00:17:28 +08:00
|
|
|
GeneralSurface mapSurface;
|
|
|
|
Surface *surfaces[] = {&srcImgSurf, nullptr};
|
2018-02-09 05:52:58 +08:00
|
|
|
|
2021-10-21 07:29:53 +08:00
|
|
|
bool tempAllocFallback = false;
|
2019-04-16 00:17:28 +08:00
|
|
|
if (mapAllocation) {
|
|
|
|
surfaces[1] = &mapSurface;
|
|
|
|
mapSurface.setGraphicsAllocation(mapAllocation);
|
|
|
|
//get offset between base cpu ptr of map allocation and dst ptr
|
|
|
|
size_t dstOffset = ptrDiff(dstPtr, mapAllocation->getUnderlyingBuffer());
|
|
|
|
dstPtr = reinterpret_cast<void *>(mapAllocation->getGpuAddress() + dstOffset);
|
|
|
|
} else {
|
|
|
|
surfaces[1] = &hostPtrSurf;
|
|
|
|
if (region[0] != 0 &&
|
|
|
|
region[1] != 0 &&
|
|
|
|
region[2] != 0) {
|
2021-09-02 18:14:12 +08:00
|
|
|
bool status = csr.createAllocationForHostSurface(hostPtrSurf, true);
|
2019-04-16 00:17:28 +08:00
|
|
|
if (!status) {
|
2021-10-21 07:29:53 +08:00
|
|
|
if (CL_TRUE == blockingRead) {
|
|
|
|
hostPtrSurf.setIsPtrCopyAllowed(true);
|
|
|
|
status = csr.createAllocationForHostSurface(hostPtrSurf, true);
|
|
|
|
if (!status) {
|
|
|
|
return CL_OUT_OF_RESOURCES;
|
|
|
|
}
|
|
|
|
tempAllocFallback = true;
|
|
|
|
} else {
|
|
|
|
return CL_OUT_OF_RESOURCES;
|
|
|
|
}
|
2019-04-16 00:17:28 +08:00
|
|
|
}
|
|
|
|
dstPtr = reinterpret_cast<void *>(hostPtrSurf.getAllocation()->getGpuAddress());
|
2018-02-09 05:52:58 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-10 22:38:56 +08:00
|
|
|
void *alignedDstPtr = alignDown(dstPtr, 4);
|
|
|
|
size_t dstPtrOffset = ptrDiff(dstPtr, alignedDstPtr);
|
|
|
|
|
2019-07-03 15:30:30 +08:00
|
|
|
BuiltinOpParams dc;
|
2017-12-21 07:45:38 +08:00
|
|
|
dc.srcMemObj = srcImage;
|
2019-01-10 22:38:56 +08:00
|
|
|
dc.dstPtr = alignedDstPtr;
|
|
|
|
dc.dstOffset.x = dstPtrOffset;
|
2017-12-21 07:45:38 +08:00
|
|
|
dc.srcOffset = origin;
|
|
|
|
dc.size = region;
|
2021-07-20 02:29:46 +08:00
|
|
|
dc.dstRowPitch = (srcImage->getImageDesc().image_type == CL_MEM_OBJECT_IMAGE1D_ARRAY) ? inputSlicePitch : inputRowPitch;
|
|
|
|
dc.dstSlicePitch = inputSlicePitch;
|
2021-01-19 18:10:19 +08:00
|
|
|
if (isMipMapped(srcImage->getImageDesc())) {
|
2018-03-12 23:32:08 +08:00
|
|
|
dc.srcMipLevel = findMipLevel(srcImage->getImageDesc().image_type, origin);
|
|
|
|
}
|
2020-10-20 21:27:49 +08:00
|
|
|
dc.transferAllocation = mapAllocation ? mapAllocation : hostPtrSurf.getAllocation();
|
2021-10-21 07:29:53 +08:00
|
|
|
if (tempAllocFallback) {
|
|
|
|
dc.userPtrForPostOperationCpuCopy = ptr;
|
|
|
|
}
|
2020-09-01 17:39:32 +08:00
|
|
|
|
2020-10-20 21:27:49 +08:00
|
|
|
auto eBuiltInOps = EBuiltInOps::CopyImage3dToBuffer;
|
|
|
|
MultiDispatchInfo dispatchInfo(dc);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2021-09-07 01:04:14 +08:00
|
|
|
dispatchBcsOrGpgpuEnqueue<CL_COMMAND_READ_IMAGE>(dispatchInfo, surfaces, eBuiltInOps, numEventsInWaitList, eventWaitList, event, blockingRead == CL_TRUE, csr);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
if (context->isProvidingPerformanceHints()) {
|
2018-02-09 05:52:58 +08:00
|
|
|
if (!isL3Capable(ptr, hostPtrSize)) {
|
2019-05-15 17:09:31 +08:00
|
|
|
context->providePerformanceHint(CL_CONTEXT_DIAGNOSTICS_LEVEL_BAD_INTEL, CL_ENQUEUE_READ_IMAGE_DOESNT_MEET_ALIGNMENT_RESTRICTIONS, ptr, hostPtrSize, MemoryConstants::pageSize, MemoryConstants::pageSize);
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return CL_SUCCESS;
|
|
|
|
}
|
2019-03-26 18:59:46 +08:00
|
|
|
} // namespace NEO
|