Commit 93aff937 by John Plate Committed by Commit Bot

Refactor CL platform object

Move GetPlatformInfo implementation from stubs to cl::Platform, because stubs are meant to be small. Also move CLPlatformImpl::Info instance to cl::Platform as it is more efficient to be accessed from there, and more consistent with cl::Device. Bug: angleproject:5904 Change-Id: I4c0ba6390467d6ef357e38a5ef08f54b0a88d423 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2880663 Commit-Queue: John Plate <jplate@google.com> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarCody Northrop <cnorthrop@google.com>
parent e369a282
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
#include "libANGLE/CLPlatform.h" #include "libANGLE/CLPlatform.h"
#include <cstring>
namespace cl namespace cl
{ {
...@@ -24,14 +26,74 @@ bool IsDeviceTypeMatch(cl_device_type select, cl_device_type type) ...@@ -24,14 +26,74 @@ bool IsDeviceTypeMatch(cl_device_type select, cl_device_type type)
Platform::~Platform() = default; Platform::~Platform() = default;
void Platform::CreatePlatform(const cl_icd_dispatch &dispatch, cl_int Platform::getInfo(PlatformInfo name, size_t valueSize, void *value, size_t *sizeRet)
rx::CLPlatformImpl::InitData &initData)
{ {
rx::CLDeviceImpl::InitList deviceInitList = initData->getDevices(); const void *copyValue = nullptr;
if (!deviceInitList.empty()) size_t copySize = 0u;
switch (name)
{ {
GetList().emplace_back(new Platform(dispatch, initData, std::move(deviceInitList))); case PlatformInfo::Profile:
copyValue = mInfo.mProfile.c_str();
copySize = mInfo.mProfile.length() + 1u;
break;
case PlatformInfo::Version:
copyValue = mInfo.mVersionStr.c_str();
copySize = mInfo.mVersionStr.length() + 1u;
break;
case PlatformInfo::NumericVersion:
copyValue = &mInfo.mVersion;
copySize = sizeof(mInfo.mVersion);
break;
case PlatformInfo::Name:
copyValue = mInfo.mName.c_str();
copySize = mInfo.mName.length() + 1u;
break;
case PlatformInfo::Vendor:
copyValue = kVendor;
copySize = sizeof(kVendor);
break;
case PlatformInfo::Extensions:
copyValue = mInfo.mExtensions.c_str();
copySize = mInfo.mExtensions.length() + 1u;
break;
case PlatformInfo::ExtensionsWithVersion:
if (mInfo.mExtensionsWithVersion.empty())
{
return CL_INVALID_VALUE;
}
copyValue = mInfo.mExtensionsWithVersion.data();
copySize = mInfo.mExtensionsWithVersion.size() *
sizeof(decltype(mInfo.mExtensionsWithVersion)::value_type);
break;
case PlatformInfo::HostTimerResolution:
copyValue = &mInfo.mHostTimerRes;
copySize = sizeof(mInfo.mHostTimerRes);
break;
case PlatformInfo::IcdSuffix:
copyValue = kIcdSuffix;
copySize = sizeof(kIcdSuffix);
break;
default:
return CL_INVALID_VALUE;
}
if (value != nullptr)
{
if (valueSize < copySize)
{
return CL_INVALID_VALUE;
}
if (copyValue != nullptr)
{
std::memcpy(value, copyValue, copySize);
}
}
if (sizeRet != nullptr)
{
*sizeRet = copySize;
} }
return CL_SUCCESS;
} }
cl_int Platform::getDeviceIDs(cl_device_type deviceType, cl_int Platform::getDeviceIDs(cl_device_type deviceType,
...@@ -60,11 +122,22 @@ cl_int Platform::getDeviceIDs(cl_device_type deviceType, ...@@ -60,11 +122,22 @@ cl_int Platform::getDeviceIDs(cl_device_type deviceType,
return found == 0u ? CL_DEVICE_NOT_FOUND : CL_SUCCESS; return found == 0u ? CL_DEVICE_NOT_FOUND : CL_SUCCESS;
} }
void Platform::CreatePlatform(const cl_icd_dispatch &dispatch,
rx::CLPlatformImpl::InitData &initData)
{
rx::CLDeviceImpl::InitList deviceInitList = initData.first->getDevices();
if (!deviceInitList.empty())
{
GetList().emplace_back(new Platform(dispatch, initData, std::move(deviceInitList)));
}
}
Platform::Platform(const cl_icd_dispatch &dispatch, Platform::Platform(const cl_icd_dispatch &dispatch,
rx::CLPlatformImpl::InitData &initData, rx::CLPlatformImpl::InitData &initData,
rx::CLDeviceImpl::InitList &&deviceInitList) rx::CLDeviceImpl::InitList &&deviceInitList)
: _cl_platform_id(dispatch), : _cl_platform_id(dispatch),
mImpl(std::move(initData)), mImpl(std::move(initData.first)),
mInfo(std::move(initData.second)),
mDevices(Device::CreateDevices(*this, std::move(deviceInitList))) mDevices(Device::CreateDevices(*this, std::move(deviceInitList)))
{} {}
......
...@@ -25,17 +25,11 @@ class Platform final : public _cl_platform_id, public Object ...@@ -25,17 +25,11 @@ class Platform final : public _cl_platform_id, public Object
~Platform(); ~Platform();
const char *getProfile() const;
const char *getVersionString() const;
cl_version getVersion() const;
const char *getName() const;
const char *getExtensions() const;
const rx::NameVersionVector &getExtensionsWithVersion() const;
cl_ulong getHostTimerResolution() const;
bool hasDevice(const Device *device) const; bool hasDevice(const Device *device) const;
const Device::PtrList &getDevices() const; const Device::PtrList &getDevices() const;
cl_int getInfo(PlatformInfo name, size_t valueSize, void *value, size_t *sizeRet);
cl_int getDeviceIDs(cl_device_type deviceType, cl_int getDeviceIDs(cl_device_type deviceType,
cl_uint numEntries, cl_uint numEntries,
Device **devices, Device **devices,
...@@ -49,7 +43,6 @@ class Platform final : public _cl_platform_id, public Object ...@@ -49,7 +43,6 @@ class Platform final : public _cl_platform_id, public Object
static bool IsValidOrDefault(const Platform *platform); static bool IsValidOrDefault(const Platform *platform);
static constexpr const char *GetVendor(); static constexpr const char *GetVendor();
static constexpr const char *GetIcdSuffix();
private: private:
Platform(const cl_icd_dispatch &dispatch, Platform(const cl_icd_dispatch &dispatch,
...@@ -59,47 +52,13 @@ class Platform final : public _cl_platform_id, public Object ...@@ -59,47 +52,13 @@ class Platform final : public _cl_platform_id, public Object
static PtrList &GetList(); static PtrList &GetList();
const rx::CLPlatformImpl::Ptr mImpl; const rx::CLPlatformImpl::Ptr mImpl;
const rx::CLPlatformImpl::Info mInfo;
const Device::PtrList mDevices; const Device::PtrList mDevices;
static constexpr char kVendor[] = "ANGLE"; static constexpr char kVendor[] = "ANGLE";
static constexpr char kIcdSuffix[] = "ANGLE"; static constexpr char kIcdSuffix[] = "ANGLE";
}; };
inline const char *Platform::getProfile() const
{
return mImpl->getInfo().mProfile.c_str();
}
inline const char *Platform::getVersionString() const
{
return mImpl->getInfo().mVersionStr.c_str();
}
inline cl_version Platform::getVersion() const
{
return mImpl->getInfo().mVersion;
}
inline const char *Platform::getName() const
{
return mImpl->getInfo().mName.c_str();
}
inline const char *Platform::getExtensions() const
{
return mImpl->getInfo().mExtensions.c_str();
}
inline const rx::NameVersionVector &Platform::getExtensionsWithVersion() const
{
return mImpl->getInfo().mExtensionList;
}
inline cl_ulong Platform::getHostTimerResolution() const
{
return mImpl->getInfo().mHostTimerRes;
}
inline bool Platform::hasDevice(const Device *device) const inline bool Platform::hasDevice(const Device *device) const
{ {
return std::find_if(mDevices.cbegin(), mDevices.cend(), [=](const Device::Ptr &ptr) { return std::find_if(mDevices.cbegin(), mDevices.cend(), [=](const Device::Ptr &ptr) {
...@@ -147,11 +106,6 @@ constexpr const char *Platform::GetVendor() ...@@ -147,11 +106,6 @@ constexpr const char *Platform::GetVendor()
return kVendor; return kVendor;
} }
constexpr const char *Platform::GetIcdSuffix()
{
return kIcdSuffix;
}
} // namespace cl } // namespace cl
#endif // LIBANGLE_CLPLATFORM_H_ #endif // LIBANGLE_CLPLATFORM_H_
...@@ -18,24 +18,9 @@ CLPlatformImpl::Info::Info(Info &&) = default; ...@@ -18,24 +18,9 @@ CLPlatformImpl::Info::Info(Info &&) = default;
CLPlatformImpl::Info &CLPlatformImpl::Info::operator=(Info &&) = default; CLPlatformImpl::Info &CLPlatformImpl::Info::operator=(Info &&) = default;
CLPlatformImpl::Info::Info(std::string &&profile, bool CLPlatformImpl::Info::isValid() const
std::string &&versionStr, {
cl_version version, return !mProfile.empty();
std::string &&name, }
std::string &&extensions,
NameVersionVector &&extensionList,
cl_ulong hostTimerRes)
: mProfile(std::move(profile)),
mVersionStr(std::move(versionStr)),
mVersion(version),
mName(std::move(name)),
mExtensions(std::move(extensions)),
mExtensionList(std::move(extensionList)),
mHostTimerRes(hostTimerRes)
{}
CLPlatformImpl::CLPlatformImpl(Info &&info) : mInfo(std::move(info)) {}
CLPlatformImpl::~CLPlatformImpl() = default;
} // namespace rx } // namespace rx
...@@ -16,10 +16,6 @@ namespace rx ...@@ -16,10 +16,6 @@ namespace rx
class CLPlatformImpl : angle::NonCopyable class CLPlatformImpl : angle::NonCopyable
{ {
public: public:
using Ptr = std::unique_ptr<CLPlatformImpl>;
using InitData = Ptr;
using InitList = std::list<InitData>;
struct Info struct Info
{ {
Info(); Info();
...@@ -31,39 +27,27 @@ class CLPlatformImpl : angle::NonCopyable ...@@ -31,39 +27,27 @@ class CLPlatformImpl : angle::NonCopyable
Info(Info &&); Info(Info &&);
Info &operator=(Info &&); Info &operator=(Info &&);
Info(std::string &&profile, bool isValid() const;
std::string &&versionStr,
cl_version version,
std::string &&name,
std::string &&extensions,
NameVersionVector &&extensionList,
cl_ulong hostTimerRes);
std::string mProfile; std::string mProfile;
std::string mVersionStr; std::string mVersionStr;
cl_version mVersion; cl_version mVersion;
std::string mName; std::string mName;
std::string mExtensions; std::string mExtensions;
NameVersionVector mExtensionList; NameVersionVector mExtensionsWithVersion;
cl_ulong mHostTimerRes; cl_ulong mHostTimerRes;
}; };
explicit CLPlatformImpl(Info &&info); using Ptr = std::unique_ptr<CLPlatformImpl>;
virtual ~CLPlatformImpl(); using InitData = std::pair<Ptr, Info>;
using InitList = std::list<InitData>;
const Info &getInfo(); CLPlatformImpl() = default;
virtual ~CLPlatformImpl() = default;
virtual CLDeviceImpl::InitList getDevices() = 0; virtual CLDeviceImpl::InitList getDevices() = 0;
protected:
const Info mInfo;
}; };
inline const CLPlatformImpl::Info &CLPlatformImpl::getInfo()
{
return mInfo;
}
} // namespace rx } // namespace rx
#endif // LIBANGLE_RENDERER_CLPLATFORMIMPL_H_ #endif // LIBANGLE_RENDERER_CLPLATFORMIMPL_H_
...@@ -107,40 +107,49 @@ CLPlatformCL::InitList CLPlatformCL::GetPlatforms(bool isIcd) ...@@ -107,40 +107,49 @@ CLPlatformCL::InitList CLPlatformCL::GetPlatforms(bool isIcd)
{ {
if (vendorIt->platform != nullptr) if (vendorIt->platform != nullptr)
{ {
rx::CLPlatformImpl::Ptr impl = Create(vendorIt->platform); Info info = GetInfo(vendorIt->platform);
if (impl) if (info.isValid())
{ {
initList.emplace_back(std::move(impl)); initList.emplace_back(new CLPlatformCL(vendorIt->platform), std::move(info));
} }
} }
} }
return initList; return initList;
} }
CLPlatformCL::CLPlatformCL(cl_platform_id platform, Info &&info) CLPlatformCL::CLPlatformCL(cl_platform_id platform) : mPlatform(platform) {}
: CLPlatformImpl(std::move(info)), mPlatform(platform)
{} #define ANGLE_GET_INFO_SIZE(name, size_ret) \
platform->getDispatch().clGetPlatformInfo(platform, name, 0u, nullptr, size_ret)
#define ANGLE_GET_INFO(info, size, param, size_ret) \
result = platform->getDispatch().clGetPlatformInfo(platform, info, size, param, size_ret) #define ANGLE_GET_INFO_SIZE_RET(name, size_ret) \
do \
#define ANGLE_TRY_GET_INFO(info, size, param, size_ret) \ { \
do \ if (ANGLE_GET_INFO_SIZE(name, size_ret) != CL_SUCCESS) \
{ \ { \
ANGLE_GET_INFO(info, size, param, size_ret); \ ERR() << "Failed to query CL platform info for " << name; \
if (result != CL_SUCCESS) \ return info; \
{ \ } \
ERR() << "Failed to query CL platform info"; \
return std::unique_ptr<CLPlatformCL>(); \
} \
} while (0) } while (0)
std::unique_ptr<CLPlatformCL> CLPlatformCL::Create(cl_platform_id platform) #define ANGLE_GET_INFO(name, size, param) \
platform->getDispatch().clGetPlatformInfo(platform, name, size, param, nullptr)
#define ANGLE_GET_INFO_RET(name, size, param) \
do \
{ \
if (ANGLE_GET_INFO(name, size, param) != CL_SUCCESS) \
{ \
ERR() << "Failed to query CL platform info for " << name; \
return info; \
} \
} while (0)
CLPlatformImpl::Info CLPlatformCL::GetInfo(cl_platform_id platform)
{ {
cl_int result = 0; Info info;
size_t paramSize = 0u; size_t valueSize = 0u;
std::vector<std::string::value_type> param; std::vector<char> valString;
CLPlatformImpl::Info info;
// Verify that the platform is valid // Verify that the platform is valid
ASSERT(platform != nullptr); ASSERT(platform != nullptr);
...@@ -149,24 +158,24 @@ std::unique_ptr<CLPlatformCL> CLPlatformCL::Create(cl_platform_id platform) ...@@ -149,24 +158,24 @@ std::unique_ptr<CLPlatformCL> CLPlatformCL::Create(cl_platform_id platform)
ASSERT(platform->getDispatch().clGetDeviceInfo != nullptr); ASSERT(platform->getDispatch().clGetDeviceInfo != nullptr);
// Skip ANGLE CL implementation to prevent passthrough loop // Skip ANGLE CL implementation to prevent passthrough loop
ANGLE_TRY_GET_INFO(CL_PLATFORM_VENDOR, 0u, nullptr, &paramSize); ANGLE_GET_INFO_SIZE_RET(CL_PLATFORM_VENDOR, &valueSize);
param.resize(paramSize, '\0'); valString.resize(valueSize, '\0');
ANGLE_TRY_GET_INFO(CL_PLATFORM_VENDOR, paramSize, param.data(), nullptr); ANGLE_GET_INFO_RET(CL_PLATFORM_VENDOR, valueSize, valString.data());
if (std::string(param.data()).compare(cl::Platform::GetVendor()) == 0) if (std::string(valString.data()).compare(cl::Platform::GetVendor()) == 0)
{ {
ERR() << "Tried to create CL pass-through back end for ANGLE library"; ERR() << "Tried to create CL pass-through back end for ANGLE library";
return std::unique_ptr<CLPlatformCL>(); return info;
} }
// Skip platform if it is not ICD compatible // Skip platform if it is not ICD compatible
ANGLE_TRY_GET_INFO(CL_PLATFORM_EXTENSIONS, 0u, nullptr, &paramSize); ANGLE_GET_INFO_SIZE_RET(CL_PLATFORM_EXTENSIONS, &valueSize);
param.resize(paramSize, '\0'); valString.resize(valueSize, '\0');
ANGLE_TRY_GET_INFO(CL_PLATFORM_EXTENSIONS, paramSize, param.data(), nullptr); ANGLE_GET_INFO_RET(CL_PLATFORM_EXTENSIONS, valueSize, valString.data());
info.mExtensions.assign(param.data()); info.mExtensions.assign(valString.data());
if (info.mExtensions.find("cl_khr_icd") == std::string::npos) if (info.mExtensions.find("cl_khr_icd") == std::string::npos)
{ {
WARN() << "CL platform is not ICD compatible"; WARN() << "CL platform is not ICD compatible";
return std::unique_ptr<CLPlatformCL>(); return info;
} }
// Filter out extensions which are not (yet) supported to be passed through // Filter out extensions which are not (yet) supported to be passed through
...@@ -202,15 +211,10 @@ std::unique_ptr<CLPlatformCL> CLPlatformCL::Create(cl_platform_id platform) ...@@ -202,15 +211,10 @@ std::unique_ptr<CLPlatformCL> CLPlatformCL::Create(cl_platform_id platform)
} }
// Fetch common platform info // Fetch common platform info
ANGLE_TRY_GET_INFO(CL_PLATFORM_PROFILE, 0u, nullptr, &paramSize); ANGLE_GET_INFO_SIZE_RET(CL_PLATFORM_VERSION, &valueSize);
param.resize(paramSize, '\0'); valString.resize(valueSize, '\0');
ANGLE_TRY_GET_INFO(CL_PLATFORM_PROFILE, paramSize, param.data(), nullptr); ANGLE_GET_INFO_RET(CL_PLATFORM_VERSION, valueSize, valString.data());
info.mProfile.assign(param.data()); info.mVersionStr.assign(valString.data());
ANGLE_TRY_GET_INFO(CL_PLATFORM_VERSION, 0u, nullptr, &paramSize);
param.resize(paramSize, '\0');
ANGLE_TRY_GET_INFO(CL_PLATFORM_VERSION, paramSize, param.data(), nullptr);
info.mVersionStr.assign(param.data());
info.mVersionStr += " (ANGLE " ANGLE_VERSION_STRING ")"; info.mVersionStr += " (ANGLE " ANGLE_VERSION_STRING ")";
const std::string::size_type spacePos = info.mVersionStr.find(' '); const std::string::size_type spacePos = info.mVersionStr.find(' ');
...@@ -218,7 +222,7 @@ std::unique_ptr<CLPlatformCL> CLPlatformCL::Create(cl_platform_id platform) ...@@ -218,7 +222,7 @@ std::unique_ptr<CLPlatformCL> CLPlatformCL::Create(cl_platform_id platform)
if (spacePos == std::string::npos || dotPos == std::string::npos) if (spacePos == std::string::npos || dotPos == std::string::npos)
{ {
ERR() << "Failed to extract version from OpenCL version string: " << info.mVersionStr; ERR() << "Failed to extract version from OpenCL version string: " << info.mVersionStr;
return std::unique_ptr<CLPlatformCL>(); return info;
} }
const cl_uint major = const cl_uint major =
static_cast<cl_uint>(std::strtol(&info.mVersionStr[spacePos + 1u], nullptr, 10)); static_cast<cl_uint>(std::strtol(&info.mVersionStr[spacePos + 1u], nullptr, 10));
...@@ -227,11 +231,11 @@ std::unique_ptr<CLPlatformCL> CLPlatformCL::Create(cl_platform_id platform) ...@@ -227,11 +231,11 @@ std::unique_ptr<CLPlatformCL> CLPlatformCL::Create(cl_platform_id platform)
if (major == 0) if (major == 0)
{ {
ERR() << "Failed to extract version from OpenCL version string: " << info.mVersionStr; ERR() << "Failed to extract version from OpenCL version string: " << info.mVersionStr;
return std::unique_ptr<CLPlatformCL>(); return info;
} }
ANGLE_GET_INFO(CL_PLATFORM_NUMERIC_VERSION, sizeof(info.mVersion), &info.mVersion, nullptr); if (ANGLE_GET_INFO(CL_PLATFORM_NUMERIC_VERSION, sizeof(info.mVersion), &info.mVersion) !=
if (result != CL_SUCCESS) CL_SUCCESS)
{ {
info.mVersion = CL_MAKE_VERSION(major, minor, 0); info.mVersion = CL_MAKE_VERSION(major, minor, 0);
} }
...@@ -242,23 +246,24 @@ std::unique_ptr<CLPlatformCL> CLPlatformCL::Create(cl_platform_id platform) ...@@ -242,23 +246,24 @@ std::unique_ptr<CLPlatformCL> CLPlatformCL::Create(cl_platform_id platform)
<< " does not match version string: " << info.mVersionStr; << " does not match version string: " << info.mVersionStr;
} }
ANGLE_TRY_GET_INFO(CL_PLATFORM_NAME, 0u, nullptr, &paramSize); ANGLE_GET_INFO_SIZE_RET(CL_PLATFORM_NAME, &valueSize);
param.resize(paramSize, '\0'); valString.resize(valueSize, '\0');
ANGLE_TRY_GET_INFO(CL_PLATFORM_NAME, paramSize, param.data(), nullptr); ANGLE_GET_INFO_RET(CL_PLATFORM_NAME, valueSize, valString.data());
info.mName.assign("ANGLE pass-through -> "); info.mName.assign("ANGLE pass-through -> ");
info.mName += param.data(); info.mName += valString.data();
ANGLE_GET_INFO(CL_PLATFORM_EXTENSIONS_WITH_VERSION, 0u, nullptr, &paramSize); if (ANGLE_GET_INFO_SIZE(CL_PLATFORM_EXTENSIONS_WITH_VERSION, &valueSize) == CL_SUCCESS &&
if (result == CL_SUCCESS) (valueSize % sizeof(decltype(info.mExtensionsWithVersion)::value_type)) == 0u)
{ {
info.mExtensionList.resize(paramSize); info.mExtensionsWithVersion.resize(
ANGLE_TRY_GET_INFO(CL_PLATFORM_EXTENSIONS_WITH_VERSION, paramSize, valueSize / sizeof(decltype(info.mExtensionsWithVersion)::value_type));
info.mExtensionList.data(), nullptr); ANGLE_GET_INFO_RET(CL_PLATFORM_EXTENSIONS_WITH_VERSION, valueSize,
info.mExtensionsWithVersion.data());
// Filter out extensions which are not (yet) supported to be passed through // Filter out extensions which are not (yet) supported to be passed through
const ExtensionSet &supported = GetSupportedExtensions(); const ExtensionSet &supported = GetSupportedExtensions();
NameVersionVector::const_iterator extIt = info.mExtensionList.cbegin(); auto extIt = info.mExtensionsWithVersion.cbegin();
while (extIt != info.mExtensionList.cend()) while (extIt != info.mExtensionsWithVersion.cend())
{ {
if (supported.find(extIt->name) != supported.cend()) if (supported.find(extIt->name) != supported.cend())
{ {
...@@ -266,15 +271,21 @@ std::unique_ptr<CLPlatformCL> CLPlatformCL::Create(cl_platform_id platform) ...@@ -266,15 +271,21 @@ std::unique_ptr<CLPlatformCL> CLPlatformCL::Create(cl_platform_id platform)
} }
else else
{ {
extIt = info.mExtensionList.erase(extIt); extIt = info.mExtensionsWithVersion.erase(extIt);
} }
} }
} }
ANGLE_GET_INFO(CL_PLATFORM_HOST_TIMER_RESOLUTION, sizeof(info.mHostTimerRes), ANGLE_GET_INFO(CL_PLATFORM_HOST_TIMER_RESOLUTION, sizeof(info.mHostTimerRes),
&info.mHostTimerRes, nullptr); &info.mHostTimerRes);
// Get this last, so the info is invalid if anything before fails
ANGLE_GET_INFO_SIZE_RET(CL_PLATFORM_PROFILE, &valueSize);
valString.resize(valueSize, '\0');
ANGLE_GET_INFO_RET(CL_PLATFORM_PROFILE, valueSize, valString.data());
info.mProfile.assign(valString.data());
return std::unique_ptr<CLPlatformCL>(new CLPlatformCL(platform, std::move(info))); return info;
} }
} // namespace rx } // namespace rx
...@@ -25,9 +25,9 @@ class CLPlatformCL : public CLPlatformImpl ...@@ -25,9 +25,9 @@ class CLPlatformCL : public CLPlatformImpl
static InitList GetPlatforms(bool isIcd); static InitList GetPlatforms(bool isIcd);
private: private:
CLPlatformCL(cl_platform_id platform, Info &&info); explicit CLPlatformCL(cl_platform_id platform);
static std::unique_ptr<CLPlatformCL> Create(cl_platform_id platform); static Info GetInfo(cl_platform_id platform);
const cl_platform_id mPlatform; const cl_platform_id mPlatform;
}; };
......
...@@ -33,8 +33,6 @@ std::string CreateExtensionString(const NameVersionVector &extList) ...@@ -33,8 +33,6 @@ std::string CreateExtensionString(const NameVersionVector &extList)
} }
} // anonymous namespace } // anonymous namespace
CLPlatformVk::CLPlatformVk(Info &&info) : CLPlatformImpl(std::move(info)) {}
CLPlatformVk::~CLPlatformVk() = default; CLPlatformVk::~CLPlatformVk() = default;
CLDeviceImpl::InitList CLPlatformVk::getDevices() CLDeviceImpl::InitList CLPlatformVk::getDevices()
...@@ -53,13 +51,18 @@ CLPlatformVk::InitList CLPlatformVk::GetPlatforms() ...@@ -53,13 +51,18 @@ CLPlatformVk::InitList CLPlatformVk::GetPlatforms()
NameVersionVector extList = { NameVersionVector extList = {
cl_name_version{CL_MAKE_VERSION(1, 0, 0), "cl_khr_icd"}, cl_name_version{CL_MAKE_VERSION(1, 0, 0), "cl_khr_icd"},
cl_name_version{CL_MAKE_VERSION(1, 0, 0), "cl_khr_extended_versioning"}}; cl_name_version{CL_MAKE_VERSION(1, 0, 0), "cl_khr_extended_versioning"}};
std::string extensions = CreateExtensionString(extList);
Info info("FULL_PROFILE", std::string(GetVersionString()), GetVersion(), "ANGLE Vulkan", Info info;
std::move(extensions), std::move(extList), 0u); info.mProfile.assign("FULL_PROFILE");
info.mVersionStr.assign(GetVersionString());
info.mVersion = GetVersion();
info.mName.assign("ANGLE Vulkan");
info.mExtensions.assign(CreateExtensionString(extList));
info.mExtensionsWithVersion = std::move(extList);
info.mHostTimerRes = 0u;
InitList initList; InitList initList;
initList.emplace_back(new CLPlatformVk(std::move(info))); initList.emplace_back(new CLPlatformVk, std::move(info));
return initList; return initList;
} }
...@@ -71,4 +74,6 @@ const std::string &CLPlatformVk::GetVersionString() ...@@ -71,4 +74,6 @@ const std::string &CLPlatformVk::GetVersionString()
return *sVersion; return *sVersion;
} }
CLPlatformVk::CLPlatformVk() = default;
} // namespace rx } // namespace rx
...@@ -27,7 +27,7 @@ class CLPlatformVk : public CLPlatformImpl ...@@ -27,7 +27,7 @@ class CLPlatformVk : public CLPlatformImpl
static const std::string &GetVersionString(); static const std::string &GetVersionString();
private: private:
explicit CLPlatformVk(Info &&info); CLPlatformVk();
}; };
constexpr cl_version CLPlatformVk::GetVersion() constexpr cl_version CLPlatformVk::GetVersion()
......
...@@ -21,8 +21,6 @@ ...@@ -21,8 +21,6 @@
#include "libANGLE/Debug.h" #include "libANGLE/Debug.h"
#include <cstring>
#define WARN_NOT_SUPPORTED(command) \ #define WARN_NOT_SUPPORTED(command) \
do \ do \
{ \ { \
...@@ -105,73 +103,8 @@ cl_int GetPlatformInfo(Platform *platform, ...@@ -105,73 +103,8 @@ cl_int GetPlatformInfo(Platform *platform,
void *param_value, void *param_value,
size_t *param_value_size_ret) size_t *param_value_size_ret)
{ {
cl_version version = 0u; return (platform != nullptr ? platform : Platform::GetDefault())
cl_ulong hostTimerRes = 0u; ->getInfo(param_name, param_value_size, param_value, param_value_size_ret);
const void *value = nullptr;
size_t value_size = 0u;
switch (param_name)
{
case PlatformInfo::Profile:
value = platform->getProfile();
value_size = std::strlen(platform->getProfile()) + 1u;
break;
case PlatformInfo::Version:
value = platform->getVersionString();
value_size = std::strlen(platform->getVersionString()) + 1u;
break;
case PlatformInfo::NumericVersion:
version = platform->getVersion();
value = &version;
value_size = sizeof(version);
break;
case PlatformInfo::Name:
value = platform->getName();
value_size = std::strlen(platform->getName()) + 1u;
break;
case PlatformInfo::Vendor:
value = Platform::GetVendor();
value_size = std::strlen(Platform::GetVendor()) + 1u;
break;
case PlatformInfo::Extensions:
value = platform->getExtensions();
value_size = std::strlen(platform->getExtensions()) + 1u;
break;
case PlatformInfo::ExtensionsWithVersion:
if (platform->getExtensionsWithVersion().empty())
{
return CL_INVALID_VALUE;
}
value = platform->getExtensionsWithVersion().data();
value_size = platform->getExtensionsWithVersion().size() * sizeof(cl_name_version);
break;
case PlatformInfo::HostTimerResolution:
hostTimerRes = platform->getHostTimerResolution();
value = &hostTimerRes;
value_size = sizeof(hostTimerRes);
break;
case PlatformInfo::IcdSuffix:
value = Platform::GetIcdSuffix();
value_size = std::strlen(Platform::GetIcdSuffix()) + 1u;
break;
default:
return CL_INVALID_VALUE;
}
if (param_value != nullptr)
{
if (param_value_size < value_size)
{
return CL_INVALID_VALUE;
}
if (value != nullptr)
{
std::memcpy(param_value, value, value_size);
}
}
if (param_value_size_ret != nullptr)
{
*param_value_size_ret = value_size;
}
return CL_SUCCESS;
} }
cl_int GetDeviceIDs(Platform *platform, cl_int GetDeviceIDs(Platform *platform,
......
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