2018-09-05 16:10:26 +08:00
|
|
|
/*
|
2019-01-09 19:56:38 +08:00
|
|
|
* Copyright (C) 2018-2019 Intel Corporation
|
2018-09-05 16:10:26 +08:00
|
|
|
*
|
2018-09-17 20:03:37 +08:00
|
|
|
* SPDX-License-Identifier: MIT
|
2018-09-05 16:10:26 +08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
#include "CL/cl.h"
|
2019-01-29 16:54:50 +08:00
|
|
|
#include "common/helpers/bit_helpers.h"
|
2018-11-06 18:24:54 +08:00
|
|
|
#include "mem_obj_types.h"
|
2018-10-31 16:51:31 +08:00
|
|
|
#include "public/cl_ext_private.h"
|
2019-01-28 22:27:15 +08:00
|
|
|
#include "runtime/context/context_type.h"
|
2018-09-05 16:10:26 +08:00
|
|
|
#include "runtime/mem_obj/mem_obj.h"
|
2018-09-17 20:03:37 +08:00
|
|
|
#include "runtime/memory_manager/memory_manager.h"
|
2018-09-05 16:10:26 +08:00
|
|
|
|
|
|
|
namespace OCLRT {
|
|
|
|
|
|
|
|
class MemObjHelper {
|
|
|
|
public:
|
2018-10-31 16:51:31 +08:00
|
|
|
static bool parseMemoryProperties(const cl_mem_properties_intel *properties, MemoryProperties &propertiesStruct);
|
|
|
|
|
|
|
|
static bool validateMemoryProperties(const MemoryProperties &properties) {
|
|
|
|
|
|
|
|
/* Are there some invalid flag bits? */
|
2019-01-09 19:56:38 +08:00
|
|
|
if (!MemObjHelper::checkMemFlagsForBuffer(properties)) {
|
2018-10-31 16:51:31 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check all the invalid flags combination. */
|
2019-01-29 16:54:50 +08:00
|
|
|
if ((isValueSet(properties.flags, CL_MEM_READ_WRITE | CL_MEM_READ_ONLY)) ||
|
|
|
|
(isValueSet(properties.flags, CL_MEM_READ_WRITE | CL_MEM_WRITE_ONLY)) ||
|
|
|
|
(isValueSet(properties.flags, CL_MEM_READ_ONLY | CL_MEM_WRITE_ONLY)) ||
|
|
|
|
(isValueSet(properties.flags, CL_MEM_ALLOC_HOST_PTR | CL_MEM_USE_HOST_PTR)) ||
|
|
|
|
(isValueSet(properties.flags, CL_MEM_COPY_HOST_PTR | CL_MEM_USE_HOST_PTR)) ||
|
|
|
|
(isValueSet(properties.flags, CL_MEM_HOST_READ_ONLY | CL_MEM_HOST_NO_ACCESS)) ||
|
|
|
|
(isValueSet(properties.flags, CL_MEM_HOST_READ_ONLY | CL_MEM_HOST_WRITE_ONLY)) ||
|
|
|
|
(isValueSet(properties.flags, CL_MEM_HOST_WRITE_ONLY | CL_MEM_HOST_NO_ACCESS))) {
|
2018-10-31 16:51:31 +08:00
|
|
|
return false;
|
|
|
|
}
|
2018-09-05 16:10:26 +08:00
|
|
|
|
2018-10-31 16:51:31 +08:00
|
|
|
return validateExtraMemoryProperties(properties);
|
2018-09-05 16:10:26 +08:00
|
|
|
}
|
|
|
|
|
2019-01-28 22:27:15 +08:00
|
|
|
static AllocationProperties getAllocationProperties(cl_mem_flags_intel flags, bool allocateMemory,
|
|
|
|
size_t size, GraphicsAllocation::AllocationType type);
|
2019-01-22 19:40:17 +08:00
|
|
|
static AllocationProperties getAllocationProperties(ImageInfo *imgInfo, bool allocateMemory);
|
2018-09-17 20:03:37 +08:00
|
|
|
|
2018-11-06 18:24:54 +08:00
|
|
|
static DevicesBitfield getDevicesBitfield(const MemoryProperties &properties);
|
2018-09-17 20:03:37 +08:00
|
|
|
|
2018-09-05 16:10:26 +08:00
|
|
|
static bool checkMemFlagsForSubBuffer(cl_mem_flags flags) {
|
|
|
|
const cl_mem_flags allValidFlags =
|
|
|
|
CL_MEM_READ_WRITE | CL_MEM_WRITE_ONLY | CL_MEM_READ_ONLY |
|
|
|
|
CL_MEM_HOST_WRITE_ONLY | CL_MEM_HOST_READ_ONLY | CL_MEM_HOST_NO_ACCESS;
|
|
|
|
|
2019-01-29 16:54:50 +08:00
|
|
|
return isFieldValid(flags, allValidFlags);
|
2018-09-05 16:10:26 +08:00
|
|
|
}
|
2019-01-09 19:56:38 +08:00
|
|
|
|
2019-01-28 22:27:15 +08:00
|
|
|
static bool isSuitableForRenderCompression(bool renderCompressedBuffers, const MemoryProperties &properties, ContextType contextType);
|
|
|
|
|
2019-01-09 19:56:38 +08:00
|
|
|
protected:
|
|
|
|
static bool checkMemFlagsForBuffer(const MemoryProperties &properties) {
|
|
|
|
MemoryProperties additionalAcceptedProperties;
|
|
|
|
addExtraMemoryProperties(additionalAcceptedProperties);
|
|
|
|
|
|
|
|
const cl_mem_flags allValidFlags =
|
|
|
|
CL_MEM_READ_WRITE | CL_MEM_WRITE_ONLY | CL_MEM_READ_ONLY |
|
|
|
|
CL_MEM_ALLOC_HOST_PTR | CL_MEM_COPY_HOST_PTR | CL_MEM_USE_HOST_PTR |
|
|
|
|
CL_MEM_HOST_WRITE_ONLY | CL_MEM_HOST_READ_ONLY | CL_MEM_HOST_NO_ACCESS |
|
|
|
|
additionalAcceptedProperties.flags;
|
|
|
|
|
|
|
|
const cl_mem_flags allValidFlagsIntel = CL_MEM_LOCALLY_UNCACHED_RESOURCE |
|
|
|
|
additionalAcceptedProperties.flags_intel;
|
|
|
|
|
2019-01-29 16:54:50 +08:00
|
|
|
return (isFieldValid(properties.flags, allValidFlags) &&
|
|
|
|
isFieldValid(properties.flags_intel, allValidFlagsIntel));
|
2019-01-09 19:56:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool validateExtraMemoryProperties(const MemoryProperties &properties);
|
|
|
|
|
|
|
|
static void addExtraMemoryProperties(MemoryProperties &properties);
|
2018-09-05 16:10:26 +08:00
|
|
|
};
|
|
|
|
} // namespace OCLRT
|