Commit a7ae63e4 by John Plate Committed by Commit Bot

CL: Move object cast from entry points to stubs and front end

Move the OpenCl object cast from the generated entry points to the stubs and front end, to make it possible to properly use static_cast. This removes the limitation that the front end objects have to be standard layout (and makes it possible to use virtual functions), which is consistent with other front end objects. Move the back end initialization from the stubs to the entry point functions, which fixes a bug where the back ends were not initialized during validation. Move more code from the stubs to the front end, to keep the stubs light. Remove unused function `default_return_value` from `generate_entry_points.py`. Bug: angleproject:5904 Change-Id: Id999ad6c537888017bf3252c6f6e088b7d4c7984 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2897245 Commit-Queue: John Plate <jplate@google.com> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarCody Northrop <cnorthrop@google.com>
parent b16ee280
......@@ -10,7 +10,7 @@
"scripts/entry_point_packed_gl_enums.json":
"4f7b43863a5e61991bba4010db463679",
"scripts/generate_entry_points.py":
"a749fa006d3da248f415b07e4b9ecf35",
"e188b924a861e07840c39399e6826dd6",
"scripts/gl.xml":
"2a73a58a7e26d8676a2c0af6d528cae6",
"scripts/gl_angle_ext.xml":
......@@ -74,7 +74,7 @@
"src/libANGLE/capture/frame_capture_utils_autogen.h":
"4405cac61b4f79b893bd40c7fc452397",
"src/libANGLE/validationCL_autogen.h":
"7fd03346f5cb8859f45cdd380af4bc64",
"605034156dbc715aeac197c7db56c684",
"src/libANGLE/validationEGL_autogen.h":
"3927fa260ad183fd9193d65b3f8d82c5",
"src/libANGLE/validationES1_autogen.h":
......@@ -122,7 +122,7 @@
"src/libGL/libGL_autogen.def":
"2789d87b05eea9f53d52e2aff499b785",
"src/libGLESv2/cl_stubs_autogen.h":
"15437a0236c79d37f2ee4655fc99409f",
"90fd22a3e8665b3f9ff807db8ffedf0d",
"src/libGLESv2/egl_ext_stubs_autogen.h":
"2ef3b8d087f2a97f7270b96077c93856",
"src/libGLESv2/egl_get_labeled_object_data.json":
......@@ -130,7 +130,7 @@
"src/libGLESv2/egl_stubs_autogen.h":
"6439daa350c1663e71dd0af37dcc91df",
"src/libGLESv2/entry_points_cl_autogen.cpp":
"2b2176bb17ed88bdb5aa2d6e9424608f",
"858f3c2bf35186a82d4bae4129926aa8",
"src/libGLESv2/entry_points_cl_autogen.h":
"dde2f94c3004874a7da995dae69da811",
"src/libGLESv2/entry_points_egl_autogen.cpp":
......
......@@ -39,6 +39,17 @@ ALIASING_EXCEPTIONS = [
'renderbufferStorageMultisampleEXT',
]
# These are the entry points which potentially are used first by an application
# and require that the back ends are initialized before the front end is called.
INIT_DICT = {
"clGetPlatformIDs": "false",
"clGetPlatformInfo": "false",
"clGetDeviceIDs": "false",
"clCreateContext": "false",
"clCreateContextFromType": "false",
"clIcdGetPlatformIDsKHR": "true",
}
# Strip these suffixes from Context entry point names. NV is excluded (for now).
STRIP_SUFFIXES = ["ANDROID", "ANGLE", "EXT", "KHR", "OES", "CHROMIUM", "OVR"]
......@@ -246,6 +257,7 @@ TEMPLATE_CL_ENTRY_POINT_NO_RETURN = """\
void CL_API_CALL cl{name}({params})
{{
ANGLE_SCOPED_GLOBAL_LOCK();
CL_EVENT({name}, "{format_params}"{comma_if_needed}{pass_params});
{packed_gl_enum_conversions}
......@@ -260,6 +272,8 @@ TEMPLATE_CL_ENTRY_POINT_WITH_RETURN_ERROR = """\
cl_int CL_API_CALL cl{name}({params})
{{
ANGLE_SCOPED_GLOBAL_LOCK();
{initialization}
CL_EVENT({name}, "{format_params}"{comma_if_needed}{pass_params});
{packed_gl_enum_conversions}
......@@ -274,6 +288,8 @@ TEMPLATE_CL_ENTRY_POINT_WITH_RETURN_POINTER = """\
{return_type} CL_API_CALL cl{name}({params})
{{
ANGLE_SCOPED_GLOBAL_LOCK();
{initialization}
CL_EVENT({name}, "{format_params}"{comma_if_needed}{pass_params});
{packed_gl_enum_conversions}
......@@ -1200,24 +1216,6 @@ CL_PACKED_TYPES = {
"cl_kernel_exec_info": "KernelExecInfo",
"cl_event_info": "EventInfo",
"cl_profiling_info": "ProfilingInfo",
# Objects
"cl_platform_id": "Platform *",
"cl_platform_id*": "Platform **",
"cl_device_id": "Device *",
"cl_device_id*": "Device **",
"const cl_device_id*": "Device *const *",
"cl_context": "Context *",
"cl_command_queue": "CommandQueue *",
"cl_mem": "Memory *",
"const cl_mem*": "Memory *const *",
"cl_program": "Program *",
"const cl_program*": "Program *const *",
"cl_kernel": "Kernel *",
"cl_kernel*": "Kernel **",
"cl_event": "Event *",
"cl_event*": "Event **",
"const cl_event*": "Event *const *",
"cl_sampler": "Sampler *",
}
EGL_PACKED_TYPES = {
......@@ -1402,13 +1400,6 @@ def param_format_string(param):
return just_the_name(param) + " = " + FORMAT_DICT[type_only]
def default_return_value(cmd_name, return_type):
if return_type == "void":
return ""
return "GetDefaultReturnValue<EntryPoint::%s, %s>()" % (strip_api_prefix(cmd_name),
return_type)
def is_context_lost_acceptable_cmd(cmd_name):
lost_context_acceptable_cmds = [
"glGetError",
......@@ -1527,7 +1518,7 @@ def format_entry_point_def(api, command_node, cmd_name, proto, params, is_explic
pass_params = [param_print_argument(command_node, param) for param in params]
format_params = [param_format_string(param) for param in params]
return_type = proto[:-len(cmd_name)].strip()
default_return = default_return_value(cmd_name, return_type)
initialization = "InitBackEnds(%s);" % INIT_DICT[cmd_name] if cmd_name in INIT_DICT else ""
event_comment = TEMPLATE_EVENT_COMMENT if cmd_name in NO_EVENT_MARKER_EXCEPTIONS_LIST else ""
name_lower_no_suffix = strip_suffix(api, cmd_name[2:3].lower() + cmd_name[3:])
......@@ -1542,6 +1533,8 @@ def format_entry_point_def(api, command_node, cmd_name, proto, params, is_explic
", ".join(params),
"internal_params":
", ".join(internal_params),
"initialization":
initialization,
"packed_gl_enum_conversions":
"".join(packed_gl_enum_conversions),
"pass_params":
......
......@@ -75,7 +75,7 @@ cl_int Context::getInfo(ContextInfo name, size_t valueSize, void *value, size_t
return CL_SUCCESS;
}
bool Context::IsValid(const Context *context)
bool Context::IsValid(const _cl_context *context)
{
const Platform::PtrList &platforms = Platform::GetPlatforms();
return std::find_if(platforms.cbegin(), platforms.cend(), [=](const Platform::Ptr &platform) {
......
......@@ -35,7 +35,7 @@ class Context final : public _cl_context, public Object
cl_int getInfo(ContextInfo name, size_t valueSize, void *value, size_t *valueSizeRet);
static bool IsValid(const Context *context);
static bool IsValid(const _cl_context *context);
private:
Context(Platform &platform,
......
......@@ -323,7 +323,7 @@ cl_int Device::getInfo(DeviceInfo name, size_t valueSize, void *value, size_t *v
cl_int Device::createSubDevices(const cl_device_partition_property *properties,
cl_uint numDevices,
Device **devices,
cl_device_id *devices,
cl_uint *numDevicesRet)
{
if (devices == nullptr)
......@@ -367,7 +367,7 @@ Device::PtrList Device::CreateDevices(Platform &platform, rx::CLDeviceImpl::PtrL
return devices;
}
bool Device::IsValid(const Device *device)
bool Device::IsValid(const _cl_device_id *device)
{
const Platform::PtrList &platforms = Platform::GetPlatforms();
return std::find_if(platforms.cbegin(), platforms.cend(), [=](const Platform::Ptr &platform) {
......
......@@ -28,7 +28,7 @@ class Device final : public _cl_device_id, public Object
Platform &getPlatform() const noexcept;
bool isRoot() const noexcept;
bool hasSubDevice(const Device *device) const;
bool hasSubDevice(const _cl_device_id *device) const;
void retain() noexcept;
bool release();
......@@ -38,12 +38,12 @@ class Device final : public _cl_device_id, public Object
cl_int createSubDevices(const cl_device_partition_property *properties,
cl_uint numDevices,
Device **devices,
cl_device_id *devices,
cl_uint *numDevicesRet);
static PtrList CreateDevices(Platform &platform, rx::CLDeviceImpl::PtrList &&implList);
static bool IsValid(const Device *device);
static bool IsValid(const _cl_device_id *device);
static bool IsValidType(cl_device_type type);
private:
......@@ -74,7 +74,7 @@ inline bool Device::isRoot() const noexcept
return mParent == nullptr;
}
inline bool Device::hasSubDevice(const Device *device) const
inline bool Device::hasSubDevice(const _cl_device_id *device) const
{
return std::find_if(mSubDevices.cbegin(), mSubDevices.cend(), [=](const Device::Ptr &ptr) {
return ptr.get() == device || ptr->hasSubDevice(device);
......
......@@ -15,6 +15,7 @@ namespace cl
namespace
{
bool IsDeviceTypeMatch(cl_device_type select, cl_device_type type)
{
// The type 'cl_device_type' is a bitfield, so masking out the selected bits indicates
......@@ -23,6 +24,42 @@ bool IsDeviceTypeMatch(cl_device_type select, cl_device_type type)
// https://www.khronos.org/registry/OpenCL/specs/3.0-unified/html/OpenCL_API.html#clGetDeviceIDs
return type == CL_DEVICE_TYPE_CUSTOM ? select == CL_DEVICE_TYPE_CUSTOM : (type & select) != 0u;
}
Context::PropArray ParseContextProperties(const cl_context_properties *properties,
Platform *&platform,
bool &userSync)
{
Context::PropArray propArray;
if (properties != nullptr)
{
// Count the trailing zero
size_t propSize = 1u;
const cl_context_properties *propIt = properties;
while (*propIt != 0)
{
++propSize;
switch (*propIt++)
{
case CL_CONTEXT_PLATFORM:
platform = reinterpret_cast<Platform *>(*propIt++);
++propSize;
break;
case CL_CONTEXT_INTEROP_USER_SYNC:
userSync = *propIt++ != CL_FALSE;
++propSize;
break;
}
}
propArray.reserve(propSize);
propArray.insert(propArray.cend(), properties, properties + propSize);
}
if (platform == nullptr)
{
platform = Platform::GetDefault();
}
return propArray;
}
} // namespace
Platform::~Platform()
......@@ -136,7 +173,7 @@ cl_int Platform::getInfo(PlatformInfo name, size_t valueSize, void *value, size_
cl_int Platform::getDeviceIDs(cl_device_type deviceType,
cl_uint numEntries,
Device **devices,
cl_device_id *devices,
cl_uint *numDevices) const
{
cl_uint found = 0u;
......@@ -160,44 +197,74 @@ cl_int Platform::getDeviceIDs(cl_device_type deviceType,
return found == 0u ? CL_DEVICE_NOT_FOUND : CL_SUCCESS;
}
Context *Platform::createContext(Context::PropArray &&properties,
cl_uint numDevices,
Device *const *devices,
ContextErrorCB notify,
void *userData,
bool userSync,
cl_int *errcodeRet)
cl_int Platform::GetPlatformIDs(cl_uint num_entries,
cl_platform_id *platforms,
cl_uint *num_platforms)
{
const PtrList &platformList = GetList();
if (num_platforms != nullptr)
{
*num_platforms = static_cast<cl_uint>(platformList.size());
}
if (platforms != nullptr)
{
cl_uint entry = 0u;
auto platformIt = platformList.cbegin();
while (entry < num_entries && platformIt != platformList.cend())
{
platforms[entry++] = (*platformIt++).get();
}
}
return CL_SUCCESS;
}
cl_context Platform::CreateContext(const cl_context_properties *properties,
cl_uint numDevices,
const cl_device_id *devices,
ContextErrorCB notify,
void *userData,
cl_int *errcodeRet)
{
Platform *platform = nullptr;
bool userSync = false;
Context::PropArray propArray = ParseContextProperties(properties, platform, userSync);
ASSERT(platform != nullptr);
Device::RefList refDevices;
while (numDevices-- != 0u)
{
refDevices.emplace_back(*devices++);
refDevices.emplace_back(static_cast<Device *>(*devices++));
}
mContexts.emplace_back(new Context(*this, std::move(properties), std::move(refDevices), notify,
userData, userSync, errcodeRet));
if (!mContexts.back()->mImpl)
platform->mContexts.emplace_back(new Context(*platform, std::move(propArray),
std::move(refDevices), notify, userData, userSync,
errcodeRet));
if (!platform->mContexts.back()->mImpl)
{
mContexts.back()->release();
platform->mContexts.back()->release();
return nullptr;
}
return mContexts.back().get();
return platform->mContexts.back().get();
}
Context *Platform::createContextFromType(Context::PropArray &&properties,
cl_device_type deviceType,
ContextErrorCB notify,
void *userData,
bool userSync,
cl_int *errcodeRet)
cl_context Platform::CreateContextFromType(const cl_context_properties *properties,
cl_device_type deviceType,
ContextErrorCB notify,
void *userData,
cl_int *errcodeRet)
{
mContexts.emplace_back(new Context(*this, std::move(properties), deviceType, notify, userData,
userSync, errcodeRet));
if (!mContexts.back()->mImpl || mContexts.back()->mDevices.empty())
Platform *platform = nullptr;
bool userSync = false;
Context::PropArray propArray = ParseContextProperties(properties, platform, userSync);
ASSERT(platform != nullptr);
platform->mContexts.emplace_back(new Context(*platform, std::move(propArray), deviceType,
notify, userData, userSync, errcodeRet));
if (!platform->mContexts.back()->mImpl || platform->mContexts.back()->mDevices.empty())
{
mContexts.back()->release();
platform->mContexts.back()->release();
return nullptr;
}
return mContexts.back().get();
return platform->mContexts.back().get();
}
void Platform::CreatePlatform(const cl_icd_dispatch &dispatch,
......
......@@ -26,40 +26,45 @@ class Platform final : public _cl_platform_id, public Object
~Platform();
bool hasDevice(const Device *device) const;
bool hasDevice(const _cl_device_id *device) const;
const Device::PtrList &getDevices() const;
Device::RefList mapDevices(const rx::CLDeviceImpl::List &deviceImplList) const;
bool hasContext(const Context *context) const;
bool hasContext(const _cl_context *context) const;
cl_int getInfo(PlatformInfo name, size_t valueSize, void *value, size_t *valueSizeRet);
cl_int getDeviceIDs(cl_device_type deviceType,
cl_uint numEntries,
Device **devices,
cl_device_id *devices,
cl_uint *numDevices) const;
Context *createContext(Context::PropArray &&properties,
cl_uint numDevices,
Device *const *devices,
ContextErrorCB notify,
void *userData,
bool userSync,
cl_int *errcodeRet);
Context *createContextFromType(Context::PropArray &&properties,
cl_device_type deviceType,
ContextErrorCB notify,
void *userData,
bool userSync,
cl_int *errcodeRet);
static cl_int GetPlatformIDs(cl_uint num_entries,
cl_platform_id *platforms,
cl_uint *num_platforms);
static cl_context CreateContext(const cl_context_properties *properties,
cl_uint numDevices,
const cl_device_id *devices,
ContextErrorCB notify,
void *userData,
cl_int *errcodeRet);
static cl_context CreateContextFromType(const cl_context_properties *properties,
cl_device_type deviceType,
ContextErrorCB notify,
void *userData,
cl_int *errcodeRet);
static void CreatePlatform(const cl_icd_dispatch &dispatch,
rx::CLPlatformImpl::InitData &initData);
static const PtrList &GetPlatforms();
static Platform *GetDefault();
static bool IsValid(const Platform *platform);
static bool IsValidOrDefault(const Platform *platform);
static Platform *CastOrDefault(cl_platform_id platform);
static bool IsValid(const _cl_platform_id *platform);
static bool IsValidOrDefault(const _cl_platform_id *platform);
static constexpr const char *GetVendor();
......@@ -88,7 +93,7 @@ class Platform final : public _cl_platform_id, public Object
friend class Context;
};
inline bool Platform::hasDevice(const Device *device) const
inline bool Platform::hasDevice(const _cl_device_id *device) const
{
return std::find_if(mDevices.cbegin(), mDevices.cend(), [=](const Device::Ptr &ptr) {
return ptr.get() == device || ptr->hasSubDevice(device);
......@@ -100,7 +105,7 @@ inline const Device::PtrList &Platform::getDevices() const
return mDevices;
}
inline bool Platform::hasContext(const Context *context) const
inline bool Platform::hasContext(const _cl_context *context) const
{
return std::find_if(mContexts.cbegin(), mContexts.cend(), [=](const Context::Ptr &ptr) {
return ptr.get() == context;
......@@ -123,7 +128,12 @@ inline Platform *Platform::GetDefault()
return GetList().empty() ? nullptr : GetList().front().get();
}
inline bool Platform::IsValid(const Platform *platform)
inline Platform *Platform::CastOrDefault(cl_platform_id platform)
{
return platform != nullptr ? static_cast<Platform *>(platform) : GetDefault();
}
inline bool Platform::IsValid(const _cl_platform_id *platform)
{
const PtrList &platforms = GetPlatforms();
return std::find_if(platforms.cbegin(), platforms.cend(),
......@@ -132,7 +142,7 @@ inline bool Platform::IsValid(const Platform *platform)
// Our CL implementation defines that a nullptr value chooses the platform that we provide as
// default, so this function returns true for a nullptr value if a default platform exists.
inline bool Platform::IsValidOrDefault(const Platform *platform)
inline bool Platform::IsValidOrDefault(const _cl_platform_id *platform)
{
return platform != nullptr ? IsValid(platform) : GetDefault() != nullptr;
}
......
......@@ -592,6 +592,7 @@ libglesv2_cl_sources = [
"src/libGLESv2/cl_stubs_autogen.h",
"src/libGLESv2/entry_points_cl_autogen.cpp",
"src/libGLESv2/entry_points_cl_autogen.h",
"src/libGLESv2/entry_points_cl_utils.cpp",
"src/libGLESv2/entry_points_cl_utils.h",
"src/libGLESv2/proc_table_cl.h",
"src/libGLESv2/proc_table_cl_autogen.cpp",
......
This source diff could not be displayed because it is too large. You can view the blob instead.
//
// Copyright 2021 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// entry_points_cl_utils.cpp: These helpers are used in CL entry point routines.
#include "libGLESv2/entry_points_cl_utils.h"
#include "libGLESv2/cl_dispatch_table.h"
#include "libANGLE/CLPlatform.h"
#ifdef ANGLE_ENABLE_CL_PASSTHROUGH
# include "libANGLE/renderer/cl/CLPlatformCL.h"
#endif
#ifdef ANGLE_ENABLE_VULKAN
# include "libANGLE/renderer/vulkan/CLPlatformVk.h"
#endif
namespace cl
{
void InitBackEnds(bool isIcd)
{
static bool initialized = false;
if (initialized)
{
return;
}
initialized = true;
#ifdef ANGLE_ENABLE_CL_PASSTHROUGH
rx::CLPlatformImpl::InitList initListCL = rx::CLPlatformCL::GetPlatforms(isIcd);
while (!initListCL.empty())
{
Platform::CreatePlatform(gCLIcdDispatchTable, initListCL.front());
initListCL.pop_front();
}
#endif
#ifdef ANGLE_ENABLE_VULKAN
rx::CLPlatformImpl::InitList initListVk = rx::CLPlatformVk::GetPlatforms();
while (!initListVk.empty())
{
Platform::CreatePlatform(gCLIcdDispatchTable, initListVk.front());
initListVk.pop_front();
}
#endif
}
} // namespace cl
......@@ -3,17 +3,16 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// entry_points_cl_utils.h:
// These helpers are used in CL entry point routines.
// entry_points_cl_utils.h: These helpers are used in CL entry point routines.
#ifndef LIBGLESV2_ENTRY_POINTS_CL_UTILS_H_
#define LIBGLESV2_ENTRY_POINTS_CL_UTILS_H_
#include "libANGLE/Debug.h"
#include <cinttypes>
#include "common/PackedCLEnums_autogen.h"
#include <cstdio>
#include <type_traits>
#if defined(ANGLE_ENABLE_DEBUG_TRACE)
# define CL_EVENT(entryPoint, ...) \
......@@ -26,22 +25,11 @@
namespace cl
{
// First case: handling packed enums.
template <typename PackedT, typename FromT>
typename std::enable_if_t<std::is_enum<PackedT>::value, PackedT> PackParam(FromT from)
{
return FromCLenum<PackedT>(from);
}
// Cast CL object types to ANGLE CL object types
template <typename PackedT, typename FromT>
inline std::enable_if_t<
std::is_base_of<cl::Object, std::remove_pointer_t<std::remove_pointer_t<PackedT>>>::value,
PackedT>
PackParam(FromT from)
{
return reinterpret_cast<PackedT>(from);
}
// Handling only packed enums
template <typename Enum>
constexpr auto PackParam = FromCLenum<Enum>;
void InitBackEnds(bool isIcd);
} // namespace cl
......
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