2017-12-21 00:45:38 +01:00
|
|
|
/*
|
2022-02-04 13:59:01 +00:00
|
|
|
* Copyright (C) 2018-2022 Intel Corporation
|
2017-12-21 00:45:38 +01:00
|
|
|
*
|
2018-09-18 09:11:08 +02:00
|
|
|
* SPDX-License-Identifier: MIT
|
2017-12-21 00:45:38 +01:00
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
2020-02-24 13:10:44 +01:00
|
|
|
#include "shared/source/built_ins/built_ins.h"
|
2020-02-23 22:44:01 +01: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 10:22:30 +01:00
|
|
|
|
2020-02-22 22:50:57 +01:00
|
|
|
#include "opencl/source/command_queue/command_queue_hw.h"
|
|
|
|
|
#include "opencl/source/mem_obj/buffer.h"
|
|
|
|
|
#include "opencl/source/memory_manager/mem_obj_surface.h"
|
2019-02-27 11:39:32 +01:00
|
|
|
|
2017-12-21 00:45:38 +01:00
|
|
|
#include <new>
|
|
|
|
|
|
2019-03-26 11:59:46 +01:00
|
|
|
namespace NEO {
|
2017-12-21 00:45:38 +01: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);
|
|
|
|
|
|
2021-03-05 13:51:16 +00:00
|
|
|
auto commandStreamReceieverOwnership = getGpgpuCommandStreamReceiver().obtainUniqueOwnership();
|
|
|
|
|
auto storageWithAllocations = getGpgpuCommandStreamReceiver().getInternalAllocationStorage();
|
2022-02-04 13:59:01 +00:00
|
|
|
auto allocationType = AllocationType::FILL_PATTERN;
|
2021-03-05 13:51:16 +00:00
|
|
|
auto patternAllocation = storageWithAllocations->obtainReusableAllocation(patternSize, allocationType).release();
|
|
|
|
|
commandStreamReceieverOwnership.unlock();
|
|
|
|
|
|
|
|
|
|
if (!patternAllocation) {
|
2022-02-04 13:59:01 +00:00
|
|
|
patternAllocation = memoryManager->allocateGraphicsMemoryWithProperties({getDevice().getRootDeviceIndex(), alignUp(patternSize, MemoryConstants::cacheLineSize), AllocationType::FILL_PATTERN, getDevice().getDeviceBitfield()});
|
2021-03-05 13:51:16 +00:00
|
|
|
}
|
2018-03-27 16:19:11 +02:00
|
|
|
|
2017-12-21 00:45:38 +01: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 14:23:32 +01:00
|
|
|
auto eBuiltInOps = EBuiltInOps::FillBuffer;
|
2019-11-06 10:01:37 +01:00
|
|
|
if (forceStateless(buffer->getSize())) {
|
2019-10-29 14:23:32 +01:00
|
|
|
eBuiltInOps = EBuiltInOps::FillBufferStateless;
|
|
|
|
|
}
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2020-02-21 11:37:14 +01:00
|
|
|
auto &builder = BuiltInDispatchBuilderOp::getBuiltinDispatchInfoBuilder(eBuiltInOps,
|
2020-10-22 12:14:54 +02:00
|
|
|
this->getClDevice());
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2021-04-02 13:00:33 +00:00
|
|
|
BuiltInOwnershipWrapper builtInLock(builder, this->context);
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2019-07-03 09:30:30 +02:00
|
|
|
BuiltinOpParams dc;
|
2020-07-21 10:21:15 +02:00
|
|
|
auto multiGraphicsAllocation = MultiGraphicsAllocation(getDevice().getRootDeviceIndex());
|
|
|
|
|
multiGraphicsAllocation.addAllocation(patternAllocation);
|
|
|
|
|
|
2019-10-09 17:29:00 +02:00
|
|
|
MemObj patternMemObj(this->context, 0, {}, 0, 0, alignUp(patternSize, 4), patternAllocation->getUnderlyingBuffer(),
|
2020-07-21 10:21:15 +02:00
|
|
|
patternAllocation->getUnderlyingBuffer(), std::move(multiGraphicsAllocation), false, false, true);
|
2017-12-21 00:45:38 +01:00
|
|
|
dc.srcMemObj = &patternMemObj;
|
|
|
|
|
dc.dstMemObj = buffer;
|
|
|
|
|
dc.dstOffset = {offset, 0, 0};
|
|
|
|
|
dc.size = {size, 0, 0};
|
2019-10-29 14:23:32 +01:00
|
|
|
|
2020-09-01 11:39:32 +02:00
|
|
|
MultiDispatchInfo dispatchInfo(dc);
|
|
|
|
|
builder.buildDispatchInfos(dispatchInfo);
|
2017-12-21 00:45:38 +01:00
|
|
|
|
|
|
|
|
MemObjSurface s1(buffer);
|
|
|
|
|
GeneralSurface s2(patternAllocation);
|
|
|
|
|
Surface *surfaces[] = {&s1, &s2};
|
|
|
|
|
|
2022-03-21 11:08:43 +00:00
|
|
|
const auto enqueueResult = enqueueHandler<CL_COMMAND_FILL_BUFFER>(
|
2017-12-21 00:45:38 +01:00
|
|
|
surfaces,
|
|
|
|
|
false,
|
|
|
|
|
dispatchInfo,
|
|
|
|
|
numEventsInWaitList,
|
|
|
|
|
eventWaitList,
|
|
|
|
|
event);
|
|
|
|
|
|
2019-07-15 14:28:09 +02:00
|
|
|
auto storageForAllocation = getGpgpuCommandStreamReceiver().getInternalAllocationStorage();
|
2021-03-05 13:51:16 +00:00
|
|
|
storageForAllocation->storeAllocationWithTaskCount(std::unique_ptr<GraphicsAllocation>(patternAllocation), REUSABLE_ALLOCATION, taskCount);
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2022-03-21 11:08:43 +00:00
|
|
|
return enqueueResult;
|
2017-12-21 00:45:38 +01:00
|
|
|
}
|
2019-03-26 11:59:46 +01:00
|
|
|
} // namespace NEO
|