Commit 1891af05 by John Plate Committed by Angle LUCI CQ

CL: Refactor TRY macro and fix more conformance bugs

Bug: angleproject:6015 Change-Id: Id54be19822fec2ac5584ffe1d1cf5bb8f00c9094 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2967467Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarCody Northrop <cnorthrop@google.com> Commit-Queue: John Plate <jplate@google.com>
parent b239790f
......@@ -25,6 +25,16 @@
#include <utility>
#include <vector>
#define ANGLE_CL_TRY(expression) \
do \
{ \
const cl_int _errorCode = expression; \
if (_errorCode != CL_SUCCESS) \
{ \
return _errorCode; \
} \
} while (0)
namespace cl
{
......
......@@ -5,7 +5,9 @@
//
// cl_utils.cpp: Helper functions for the CL front end
#include <libANGLE/cl_utils.h>
#include "libANGLE/cl_utils.h"
#include "libANGLE/renderer/CLExtensions.h"
namespace cl
{
......@@ -85,4 +87,100 @@ size_t GetElementSize(const cl_image_format &image_format)
return size;
}
bool IsValidImageFormat(const cl_image_format *imageFormat, const rx::CLExtensions &extensions)
{
if (imageFormat == nullptr)
{
return false;
}
switch (imageFormat->image_channel_order)
{
case CL_R:
case CL_A:
case CL_LUMINANCE:
case CL_INTENSITY:
case CL_RG:
case CL_RA:
case CL_RGB:
case CL_RGBA:
case CL_ARGB:
case CL_BGRA:
break;
case CL_Rx:
case CL_RGx:
case CL_RGBx:
if (extensions.version < CL_MAKE_VERSION(1, 1, 0))
{
return false;
}
break;
case CL_ABGR:
case CL_sRGB:
case CL_sRGBA:
case CL_sBGRA:
case CL_sRGBx:
if (extensions.version < CL_MAKE_VERSION(2, 0, 0))
{
return false;
}
break;
case CL_DEPTH:
// CL_DEPTH can only be used if channel data type = CL_UNORM_INT16 or CL_FLOAT.
if (imageFormat->image_channel_data_type != CL_UNORM_INT16 &&
imageFormat->image_channel_data_type != CL_FLOAT)
{
return false;
}
if (!extensions.khrDepthImages)
{
return false;
}
break;
default:
return false;
}
switch (imageFormat->image_channel_data_type)
{
case CL_SNORM_INT8:
case CL_SNORM_INT16:
case CL_UNORM_INT8:
case CL_UNORM_INT16:
case CL_SIGNED_INT8:
case CL_SIGNED_INT16:
case CL_SIGNED_INT32:
case CL_UNSIGNED_INT8:
case CL_UNSIGNED_INT16:
case CL_UNSIGNED_INT32:
case CL_HALF_FLOAT:
case CL_FLOAT:
break;
case CL_UNORM_SHORT_565:
case CL_UNORM_SHORT_555:
case CL_UNORM_INT_101010:
if (imageFormat->image_channel_order != CL_RGB &&
imageFormat->image_channel_order != CL_RGBx)
{
return false;
}
break;
case CL_UNORM_INT_101010_2:
if (extensions.version < CL_MAKE_VERSION(2, 1, 0) ||
imageFormat->image_channel_order != CL_RGBA)
{
return false;
}
break;
default:
return false;
}
return true;
}
} // namespace cl
......@@ -8,7 +8,7 @@
#ifndef LIBANGLE_CL_UTILS_H_
#define LIBANGLE_CL_UTILS_H_
#include "libANGLE/CLtypes.h"
#include "libANGLE/renderer/CLtypes.h"
namespace cl
{
......@@ -26,6 +26,8 @@ inline bool OverlapRegions(size_t offset1, size_t offset2, size_t size)
(offset2 <= offset1 && offset1 <= offset2 + size - 1u);
}
bool IsValidImageFormat(const cl_image_format *imageFormat, const rx::CLExtensions &extensions);
} // namespace cl
#endif // LIBANGLE_CL_UTILS_H_
......@@ -57,11 +57,8 @@ class CLDeviceImpl : angle::NonCopyable
cl_uint queueOnDeviceMaxSize = 0u;
std::string builtInKernels;
NameVersionVector builtInKernelsWithVersion;
std::string versionStr;
cl_version version = 0u;
NameVersionVector OpenCL_C_AllVersions;
NameVersionVector OpenCL_C_Features;
NameVersionVector extensionsWithVersion;
std::vector<cl_device_partition_property> partitionProperties;
std::vector<cl_device_partition_property> partitionType;
};
......
......@@ -26,7 +26,11 @@ struct CLExtensions
void initializeExtensions(std::string &&extensionStr);
std::string versionStr;
cl_version version = 0u;
std::string extensions;
NameVersionVector extensionsWithVersion;
// These Khronos extension names must be returned by all devices that support OpenCL 1.1.
bool khrByteAddressableStore = false; // cl_khr_byte_addressable_store
......
......@@ -36,10 +36,7 @@ class CLPlatformImpl : angle::NonCopyable
bool isValid() const { return version != 0u; }
std::string profile;
std::string versionStr;
cl_version version = 0u;
std::string name;
NameVersionVector extensionsWithVersion;
cl_ulong hostTimerRes = 0u;
};
......
......@@ -13,9 +13,17 @@
namespace rx
{
class CLCommandQueueImpl;
class CLContextImpl;
class CLDeviceImpl;
class CLEventImpl;
class CLKernelImpl;
class CLMemoryImpl;
class CLPlatformImpl;
class CLProgramImpl;
class CLSamplerImpl;
struct CLExtensions;
using NameVersionVector = std::vector<cl_name_version>;
......
......@@ -446,6 +446,14 @@ void *CLCommandQueueCL::enqueueMapImage(const cl::Image &image,
mNative, nativeImage, block, mapFlags.get(), origin, region, imageRowPitch, imageSlicePitch,
numEvents, nativeEventsPtr, nativeEventPtr, &errorCode);
// TODO(jplate) Remove workaround after bug is fixed http://anglebug.com/6066
if (imageSlicePitch != nullptr && (image.getType() == cl::MemObjectType::Image1D ||
image.getType() == cl::MemObjectType::Image1D_Buffer ||
image.getType() == cl::MemObjectType::Image2D))
{
*imageSlicePitch = 0u;
}
CheckCreateEvent(errorCode, nativeEvent, eventCreateFunc);
return map;
}
......
......@@ -11,6 +11,7 @@
#include "libANGLE/renderer/cl/CLDeviceCL.h"
#include "libANGLE/renderer/cl/CLEventCL.h"
#include "libANGLE/renderer/cl/CLMemoryCL.h"
#include "libANGLE/renderer/cl/CLPlatformCL.h"
#include "libANGLE/renderer/cl/CLProgramCL.h"
#include "libANGLE/renderer/cl/CLSamplerCL.h"
......@@ -24,6 +25,7 @@
#include "libANGLE/CLPlatform.h"
#include "libANGLE/CLProgram.h"
#include "libANGLE/CLSampler.h"
#include "libANGLE/cl_utils.h"
namespace rx
{
......@@ -185,8 +187,35 @@ cl_int CLContextCL::getSupportedImageFormats(cl::MemFlags flags,
cl_image_format *imageFormats,
cl_uint *numImageFormats)
{
return mNative->getDispatch().clGetSupportedImageFormats(
mNative, flags.get(), cl::ToCLenum(imageType), numEntries, imageFormats, numImageFormats);
// Fetch available image formats for given flags and image type.
cl_uint numFormats = 0u;
ANGLE_CL_TRY(mNative->getDispatch().clGetSupportedImageFormats(
mNative, flags.get(), cl::ToCLenum(imageType), 0u, nullptr, &numFormats));
std::vector<cl_image_format> formats(numFormats);
ANGLE_CL_TRY(mNative->getDispatch().clGetSupportedImageFormats(
mNative, flags.get(), cl::ToCLenum(imageType), numFormats, formats.data(), nullptr));
// Filter out formats which are not supported by front end.
const CLPlatformImpl::Info &info = mContext.getPlatform().getInfo();
std::vector<cl_image_format> supportedFormats;
supportedFormats.reserve(formats.size());
std::copy_if(
formats.cbegin(), formats.cend(), std::back_inserter(supportedFormats),
[&](const cl_image_format &format) { return cl::IsValidImageFormat(&format, info); });
if (imageFormats != nullptr)
{
auto formatIt = supportedFormats.cbegin();
while (numEntries-- != 0u && formatIt != supportedFormats.cend())
{
*imageFormats++ = *formatIt++;
}
}
if (numImageFormats != nullptr)
{
*numImageFormats = static_cast<cl_uint>(supportedFormats.size());
}
return CL_SUCCESS;
}
CLSamplerImpl::Ptr CLContextCL::createSampler(const cl::Sampler &sampler, cl_int &errorCode)
......
......@@ -394,7 +394,6 @@ CLContextImpl::Ptr CLPlatformCL::createContext(cl::Context &context,
nativeDevices.emplace_back(device->getImpl<CLDeviceCL>().getNative());
}
CLContextImpl::Ptr contextImpl;
cl_context nativeContext = mNative->getDispatch().clCreateContext(
properties, static_cast<cl_uint>(nativeDevices.size()), nativeDevices.data(),
cl::Context::ErrorCallback, &context, &errorCode);
......
......@@ -13,6 +13,7 @@
#include "common/PackedCLEnums_autogen.h"
#include <cinttypes>
#include <cstdio>
#if defined(ANGLE_ENABLE_DEBUG_TRACE)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment