2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2020-12-22 08:03:25 +08:00
|
|
|
* Copyright (C) 2017-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 05:44:01 +08:00
|
|
|
#include "shared/source/helpers/basic_math.h"
|
2020-04-02 17:28:38 +08:00
|
|
|
#include "shared/source/helpers/constants.h"
|
2020-02-24 17:22:30 +08:00
|
|
|
|
2020-02-26 21:21:01 +08:00
|
|
|
#include "opencl/extensions/public/cl_ext_private.h"
|
2020-02-23 05:50:57 +08:00
|
|
|
#include "opencl/source/context/context_type.h"
|
|
|
|
#include "opencl/source/mem_obj/mem_obj.h"
|
2019-02-27 18:39:32 +08:00
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
#include "igfxfmid.h"
|
2019-08-09 15:52:17 +08:00
|
|
|
#include "memory_properties_flags.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2020-05-12 19:47:44 +08:00
|
|
|
#include <functional>
|
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
namespace NEO {
|
2020-02-21 06:54:48 +08:00
|
|
|
class Device;
|
2017-12-21 07:45:38 +08:00
|
|
|
class Buffer;
|
2020-01-14 21:32:11 +08:00
|
|
|
class ClDevice;
|
2018-01-26 23:53:18 +08:00
|
|
|
class MemoryManager;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2020-05-12 19:47:44 +08:00
|
|
|
using BufferCreatFunc = Buffer *(*)(Context *context,
|
|
|
|
MemoryProperties memoryProperties,
|
|
|
|
cl_mem_flags flags,
|
|
|
|
cl_mem_flags_intel flagsIntel,
|
|
|
|
size_t size,
|
|
|
|
void *memoryStorage,
|
|
|
|
void *hostPtr,
|
2020-07-10 17:21:53 +08:00
|
|
|
MultiGraphicsAllocation multiGraphicsAllocation,
|
2020-05-12 19:47:44 +08:00
|
|
|
bool zeroCopy,
|
|
|
|
bool isHostPtrSVM,
|
|
|
|
bool isImageRedescribed);
|
|
|
|
|
|
|
|
struct BufferFactoryFuncs {
|
2017-12-21 07:45:38 +08:00
|
|
|
BufferCreatFunc createBufferFunction;
|
2020-05-12 19:47:44 +08:00
|
|
|
};
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2020-05-12 19:47:44 +08:00
|
|
|
extern BufferFactoryFuncs bufferFactory[IGFX_MAX_CORE];
|
|
|
|
|
|
|
|
namespace BufferFunctions {
|
|
|
|
using ValidateInputAndCreateBufferFunc = std::function<cl_mem(cl_context context,
|
|
|
|
const uint64_t *properties,
|
|
|
|
uint64_t flags,
|
|
|
|
uint64_t flagsIntel,
|
|
|
|
size_t size,
|
|
|
|
void *hostPtr,
|
|
|
|
int32_t &retVal)>;
|
|
|
|
extern ValidateInputAndCreateBufferFunc validateInputAndCreateBuffer;
|
|
|
|
} // namespace BufferFunctions
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
class Buffer : public MemObj {
|
|
|
|
public:
|
2019-03-14 18:18:57 +08:00
|
|
|
constexpr static size_t maxBufferSizeForReadWriteOnCpu = 10 * MB;
|
|
|
|
constexpr static cl_ulong maskMagic = 0xFFFFFFFFFFFFFFFFLL;
|
|
|
|
constexpr static cl_ulong objectMagic = MemObj::objectMagic | 0x02;
|
2017-12-21 07:45:38 +08:00
|
|
|
bool forceDisallowCPUCopy = false;
|
|
|
|
|
|
|
|
~Buffer() override;
|
2018-10-31 16:51:31 +08:00
|
|
|
|
2020-05-12 19:47:44 +08:00
|
|
|
static cl_mem validateInputAndCreateBuffer(cl_context context,
|
|
|
|
const cl_mem_properties *properties,
|
|
|
|
cl_mem_flags flags,
|
|
|
|
cl_mem_flags_intel flagsIntel,
|
|
|
|
size_t size,
|
|
|
|
void *hostPtr,
|
|
|
|
cl_int &retVal);
|
2018-10-31 16:51:31 +08:00
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
static Buffer *create(Context *context,
|
|
|
|
cl_mem_flags flags,
|
|
|
|
size_t size,
|
|
|
|
void *hostPtr,
|
|
|
|
cl_int &errcodeRet);
|
|
|
|
|
2018-10-31 16:51:31 +08:00
|
|
|
static Buffer *create(Context *context,
|
2020-04-22 20:37:30 +08:00
|
|
|
MemoryProperties properties,
|
2019-10-17 20:18:55 +08:00
|
|
|
cl_mem_flags flags,
|
|
|
|
cl_mem_flags_intel flagsIntel,
|
2018-10-31 16:51:31 +08:00
|
|
|
size_t size,
|
|
|
|
void *hostPtr,
|
|
|
|
cl_int &errcodeRet);
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
static Buffer *createSharedBuffer(Context *context,
|
|
|
|
cl_mem_flags flags,
|
|
|
|
SharingHandler *sharingHandler,
|
2020-07-15 18:53:15 +08:00
|
|
|
MultiGraphicsAllocation multiGraphicsAllocation);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
static Buffer *createBufferHw(Context *context,
|
2020-04-22 20:37:30 +08:00
|
|
|
MemoryProperties memoryProperties,
|
2019-10-17 20:18:55 +08:00
|
|
|
cl_mem_flags flags,
|
|
|
|
cl_mem_flags_intel flagsIntel,
|
2017-12-21 07:45:38 +08:00
|
|
|
size_t size,
|
|
|
|
void *memoryStorage,
|
|
|
|
void *hostPtr,
|
2020-07-10 17:21:53 +08:00
|
|
|
MultiGraphicsAllocation multiGraphicsAllocation,
|
2017-12-21 07:45:38 +08:00
|
|
|
bool zeroCopy,
|
|
|
|
bool isHostPtrSVM,
|
|
|
|
bool isImageRedescribed);
|
|
|
|
|
2020-02-21 06:54:48 +08:00
|
|
|
static Buffer *createBufferHwFromDevice(const Device *device,
|
2018-06-11 20:58:35 +08:00
|
|
|
cl_mem_flags flags,
|
2019-09-24 22:05:17 +08:00
|
|
|
cl_mem_flags_intel flagsIntel,
|
2018-06-11 20:58:35 +08:00
|
|
|
size_t size,
|
|
|
|
void *memoryStorage,
|
|
|
|
void *hostPtr,
|
2020-07-15 01:42:07 +08:00
|
|
|
MultiGraphicsAllocation multiGraphicsAllocation,
|
2020-01-28 18:24:36 +08:00
|
|
|
size_t offset,
|
2018-06-11 20:58:35 +08:00
|
|
|
bool zeroCopy,
|
|
|
|
bool isHostPtrSVM,
|
|
|
|
bool isImageRedescribed);
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
Buffer *createSubBuffer(cl_mem_flags flags,
|
2019-10-23 01:51:53 +08:00
|
|
|
cl_mem_flags_intel flagsIntel,
|
2017-12-21 07:45:38 +08:00
|
|
|
const cl_buffer_region *region,
|
|
|
|
cl_int &errcodeRet);
|
|
|
|
|
2020-02-21 06:54:48 +08:00
|
|
|
static void setSurfaceState(const Device *device,
|
2017-12-21 07:45:38 +08:00
|
|
|
void *surfaceState,
|
2020-12-22 08:03:25 +08:00
|
|
|
bool forceNonAuxMode,
|
|
|
|
bool disableL3,
|
2017-12-21 07:45:38 +08:00
|
|
|
size_t svmSize,
|
|
|
|
void *svmPtr,
|
2020-01-28 18:24:36 +08:00
|
|
|
size_t offset,
|
|
|
|
GraphicsAllocation *gfxAlloc,
|
|
|
|
cl_mem_flags flags,
|
|
|
|
cl_mem_flags_intel flagsIntel);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2019-06-29 00:22:38 +08:00
|
|
|
static void provideCompressionHint(GraphicsAllocation::AllocationType allocationType,
|
|
|
|
Context *context,
|
|
|
|
Buffer *buffer);
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
BufferCreatFunc createFunction = nullptr;
|
|
|
|
bool isSubBuffer();
|
|
|
|
bool isValidSubBufferOffset(size_t offset);
|
2020-06-23 22:53:30 +08:00
|
|
|
uint64_t setArgStateless(void *memory, uint32_t patchSize, uint32_t rootDeviceIndex, bool set32BitAddressing);
|
2021-02-05 00:48:27 +08:00
|
|
|
virtual void setArgStateful(void *memory, bool forceNonAuxMode, bool disableL3, bool alignSizeForAuxTranslation,
|
|
|
|
bool isReadOnly, const Device &device, bool useGlobalAtomics, size_t numDevicesInContext) = 0;
|
2017-12-21 07:45:38 +08:00
|
|
|
bool bufferRectPitchSet(const size_t *bufferOrigin,
|
|
|
|
const size_t *region,
|
|
|
|
size_t &bufferRowPitch,
|
|
|
|
size_t &bufferSlicePitch,
|
|
|
|
size_t &hostRowPitch,
|
2021-03-10 00:56:13 +08:00
|
|
|
size_t &hostSlicePitch,
|
|
|
|
bool isSrcBuffer);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
static size_t calculateHostPtrSize(const size_t *origin, const size_t *region, size_t rowPitch, size_t slicePitch);
|
|
|
|
|
2018-02-18 05:26:28 +08:00
|
|
|
void transferDataToHostPtr(MemObjSizeArray ©Size, MemObjOffsetArray ©Offset) override;
|
|
|
|
void transferDataFromHostPtr(MemObjSizeArray ©Size, MemObjOffsetArray ©Offset) override;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2021-03-02 03:07:28 +08:00
|
|
|
bool isReadWriteOnCpuAllowed(const Device &device);
|
2020-06-25 16:49:29 +08:00
|
|
|
bool isReadWriteOnCpuPreferred(void *ptr, size_t size, const Device &device);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2020-06-26 00:17:44 +08:00
|
|
|
uint32_t getMocsValue(bool disableL3Cache, bool isReadOnlyArgument, uint32_t rootDeviceIndex) const;
|
|
|
|
uint32_t getSurfaceSize(bool alignSizeForAuxTranslation, uint32_t rootDeviceIndex) const;
|
|
|
|
uint64_t getBufferAddress(uint32_t rootDeviceIndex) const;
|
2019-04-15 19:34:01 +08:00
|
|
|
|
2020-06-24 00:08:30 +08:00
|
|
|
bool isCompressed(uint32_t rootDeviceIndex) const;
|
2020-02-21 16:48:51 +08:00
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
protected:
|
|
|
|
Buffer(Context *context,
|
2020-04-22 20:37:30 +08:00
|
|
|
MemoryProperties memoryProperties,
|
2019-09-24 22:05:17 +08:00
|
|
|
cl_mem_flags flags,
|
|
|
|
cl_mem_flags_intel flagsIntel,
|
2017-12-21 07:45:38 +08:00
|
|
|
size_t size,
|
|
|
|
void *memoryStorage,
|
|
|
|
void *hostPtr,
|
2020-07-10 17:21:53 +08:00
|
|
|
MultiGraphicsAllocation multiGraphicsAllocation,
|
2017-12-21 07:45:38 +08:00
|
|
|
bool zeroCopy,
|
|
|
|
bool isHostPtrSVM,
|
|
|
|
bool isObjectRedescribed);
|
|
|
|
|
|
|
|
Buffer();
|
|
|
|
|
2020-04-22 20:37:30 +08:00
|
|
|
static void checkMemory(MemoryProperties memoryProperties,
|
2017-12-21 07:45:38 +08:00
|
|
|
size_t size,
|
|
|
|
void *hostPtr,
|
|
|
|
cl_int &errcodeRet,
|
|
|
|
bool &isZeroCopy,
|
2018-01-26 23:53:18 +08:00
|
|
|
bool ©MemoryFromHostPtr,
|
2020-07-07 14:41:26 +08:00
|
|
|
MemoryManager *memMngr,
|
2020-09-03 19:36:38 +08:00
|
|
|
uint32_t rootDeviceIndex,
|
|
|
|
bool forceCopyHostPtr);
|
2020-04-22 20:37:30 +08:00
|
|
|
static GraphicsAllocation::AllocationType getGraphicsAllocationType(const MemoryProperties &properties, Context &context,
|
2019-10-08 16:38:02 +08:00
|
|
|
bool renderCompressedBuffers, bool localMemoryEnabled,
|
|
|
|
bool preferCompression);
|
2020-04-22 20:37:30 +08:00
|
|
|
static bool isReadOnlyMemoryPermittedByFlags(const MemoryProperties &properties);
|
2018-03-05 22:52:35 +08:00
|
|
|
|
2018-02-09 03:55:31 +08:00
|
|
|
void transferData(void *dst, void *src, size_t copySize, size_t copyOffset);
|
2017-12-21 07:45:38 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
template <typename GfxFamily>
|
|
|
|
class BufferHw : public Buffer {
|
|
|
|
public:
|
|
|
|
BufferHw(Context *context,
|
2020-04-22 20:37:30 +08:00
|
|
|
MemoryProperties memoryProperties,
|
2019-09-24 22:05:17 +08:00
|
|
|
cl_mem_flags flags,
|
|
|
|
cl_mem_flags_intel flagsIntel,
|
2017-12-21 07:45:38 +08:00
|
|
|
size_t size,
|
|
|
|
void *memoryStorage,
|
|
|
|
void *hostPtr,
|
2020-07-10 17:21:53 +08:00
|
|
|
MultiGraphicsAllocation multiGraphicsAllocation,
|
2017-12-21 07:45:38 +08:00
|
|
|
bool zeroCopy,
|
|
|
|
bool isHostPtrSVM,
|
|
|
|
bool isObjectRedescribed)
|
2020-07-17 05:56:26 +08:00
|
|
|
: Buffer(context, memoryProperties, flags, flagsIntel, size, memoryStorage, hostPtr, std::move(multiGraphicsAllocation),
|
2017-12-21 07:45:38 +08:00
|
|
|
zeroCopy, isHostPtrSVM, isObjectRedescribed) {}
|
|
|
|
|
2021-02-05 00:48:27 +08:00
|
|
|
void setArgStateful(void *memory, bool forceNonAuxMode, bool disableL3, bool alignSizeForAuxTranslation,
|
|
|
|
bool isReadOnlyArgument, const Device &device, bool useGlobalAtomics, size_t numDevicesInContext) override;
|
2019-10-11 12:54:10 +08:00
|
|
|
void appendSurfaceStateExt(void *memory);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
static Buffer *create(Context *context,
|
2020-04-22 20:37:30 +08:00
|
|
|
MemoryProperties memoryProperties,
|
2019-09-24 22:05:17 +08:00
|
|
|
cl_mem_flags flags,
|
|
|
|
cl_mem_flags_intel flagsIntel,
|
2017-12-21 07:45:38 +08:00
|
|
|
size_t size,
|
|
|
|
void *memoryStorage,
|
|
|
|
void *hostPtr,
|
2020-07-10 17:21:53 +08:00
|
|
|
MultiGraphicsAllocation multiGraphicsAllocation,
|
2017-12-21 07:45:38 +08:00
|
|
|
bool zeroCopy,
|
|
|
|
bool isHostPtrSVM,
|
|
|
|
bool isObjectRedescribed) {
|
|
|
|
auto buffer = new BufferHw<GfxFamily>(context,
|
2019-10-09 23:29:00 +08:00
|
|
|
memoryProperties,
|
2019-09-24 22:05:17 +08:00
|
|
|
flags,
|
|
|
|
flagsIntel,
|
2017-12-21 07:45:38 +08:00
|
|
|
size,
|
|
|
|
memoryStorage,
|
|
|
|
hostPtr,
|
2020-07-17 05:56:26 +08:00
|
|
|
std::move(multiGraphicsAllocation),
|
2017-12-21 07:45:38 +08:00
|
|
|
zeroCopy,
|
|
|
|
isHostPtrSVM,
|
|
|
|
isObjectRedescribed);
|
|
|
|
buffer->surfaceType = SURFACE_STATE::SURFACE_TYPE_SURFTYPE_1D;
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef typename GfxFamily::RENDER_SURFACE_STATE SURFACE_STATE;
|
|
|
|
typename SURFACE_STATE::SURFACE_TYPE surfaceType;
|
|
|
|
};
|
2020-05-12 19:47:44 +08:00
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
} // namespace NEO
|