2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2020-01-21 18:00:03 +08:00
|
|
|
* Copyright (C) 2017-2020 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/memory_manager/internal_allocation_storage.h"
|
|
|
|
#include "shared/source/memory_manager/memory_manager.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/helpers/hardware_commands_helper.h"
|
|
|
|
#include "opencl/source/mem_obj/buffer.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 <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>::enqueueFillBuffer(
|
|
|
|
Buffer *buffer,
|
|
|
|
const void *pattern,
|
|
|
|
size_t patternSize,
|
|
|
|
size_t offset,
|
|
|
|
size_t size,
|
|
|
|
cl_uint numEventsInWaitList,
|
|
|
|
const cl_event *eventWaitList,
|
|
|
|
cl_event *event) {
|
|
|
|
auto memoryManager = getDevice().getMemoryManager();
|
|
|
|
DEBUG_BREAK_IF(nullptr == memoryManager);
|
|
|
|
|
2020-06-24 17:45:31 +08:00
|
|
|
auto patternAllocation = memoryManager->allocateGraphicsMemoryWithProperties({getDevice().getRootDeviceIndex(), alignUp(patternSize, MemoryConstants::cacheLineSize), GraphicsAllocation::AllocationType::FILL_PATTERN, getDevice().getDeviceBitfield()});
|
2018-03-27 22:19:11 +08:00
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
if (patternSize == 1) {
|
|
|
|
int patternInt = (uint32_t)((*(uint8_t *)pattern << 24) | (*(uint8_t *)pattern << 16) | (*(uint8_t *)pattern << 8) | *(uint8_t *)pattern);
|
|
|
|
memcpy_s(patternAllocation->getUnderlyingBuffer(), sizeof(int), &patternInt, sizeof(int));
|
|
|
|
} else if (patternSize == 2) {
|
|
|
|
int patternInt = (uint32_t)((*(uint16_t *)pattern << 16) | *(uint16_t *)pattern);
|
|
|
|
memcpy_s(patternAllocation->getUnderlyingBuffer(), sizeof(int), &patternInt, sizeof(int));
|
|
|
|
} else {
|
|
|
|
memcpy_s(patternAllocation->getUnderlyingBuffer(), patternSize, pattern, patternSize);
|
|
|
|
}
|
|
|
|
|
2019-10-29 21:23:32 +08:00
|
|
|
auto eBuiltInOps = EBuiltInOps::FillBuffer;
|
2019-11-06 17:01:37 +08:00
|
|
|
if (forceStateless(buffer->getSize())) {
|
2019-10-29 21:23:32 +08:00
|
|
|
eBuiltInOps = EBuiltInOps::FillBufferStateless;
|
|
|
|
}
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2020-02-21 18:37:14 +08:00
|
|
|
auto &builder = BuiltInDispatchBuilderOp::getBuiltinDispatchInfoBuilder(eBuiltInOps,
|
|
|
|
this->getDevice());
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2018-08-13 18:24:17 +08:00
|
|
|
BuiltInOwnershipWrapper builtInLock(builder, this->context);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2019-07-03 15:30:30 +08:00
|
|
|
BuiltinOpParams dc;
|
2019-10-09 23:29:00 +08:00
|
|
|
MemObj patternMemObj(this->context, 0, {}, 0, 0, alignUp(patternSize, 4), patternAllocation->getUnderlyingBuffer(),
|
2017-12-21 07:45:38 +08:00
|
|
|
patternAllocation->getUnderlyingBuffer(), patternAllocation, false, false, true);
|
|
|
|
dc.srcMemObj = &patternMemObj;
|
|
|
|
dc.dstMemObj = buffer;
|
|
|
|
dc.dstOffset = {offset, 0, 0};
|
|
|
|
dc.size = {size, 0, 0};
|
2019-10-29 21:23:32 +08:00
|
|
|
|
|
|
|
MultiDispatchInfo dispatchInfo;
|
2017-12-21 07:45:38 +08:00
|
|
|
builder.buildDispatchInfos(dispatchInfo, dc);
|
|
|
|
|
|
|
|
MemObjSurface s1(buffer);
|
|
|
|
GeneralSurface s2(patternAllocation);
|
|
|
|
Surface *surfaces[] = {&s1, &s2};
|
|
|
|
|
|
|
|
enqueueHandler<CL_COMMAND_FILL_BUFFER>(
|
|
|
|
surfaces,
|
|
|
|
false,
|
|
|
|
dispatchInfo,
|
|
|
|
numEventsInWaitList,
|
|
|
|
eventWaitList,
|
|
|
|
event);
|
|
|
|
|
2019-07-15 20:28:09 +08:00
|
|
|
auto storageForAllocation = getGpgpuCommandStreamReceiver().getInternalAllocationStorage();
|
2018-10-24 20:25:04 +08:00
|
|
|
storageForAllocation->storeAllocationWithTaskCount(std::unique_ptr<GraphicsAllocation>(patternAllocation), TEMPORARY_ALLOCATION, taskCount);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
return CL_SUCCESS;
|
|
|
|
}
|
2019-03-26 18:59:46 +08:00
|
|
|
} // namespace NEO
|