Commit e3dd7161 by John Plate Committed by Angle LUCI CQ

CL: sampler object creation for front end and pass-through

Add sampler object to back end and implement creation and info query. Bug: angleproject:6001 Change-Id: If5b7d09564d773d6aeda7612728e19bfec7f6155 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2912806 Commit-Queue: John Plate <jplate@google.com> Reviewed-by: 's avatarCody Northrop <cnorthrop@google.com> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org>
parent 7761ed1d
{ {
"src/common/PackedCLEnums_autogen.cpp": "src/common/PackedCLEnums_autogen.cpp":
"91ef59eed1815db6947faae73a8d3e2d", "19052c8c0888c36b2cf43a3cd4ae5f89",
"src/common/PackedCLEnums_autogen.h": "src/common/PackedCLEnums_autogen.h":
"4ca5b1eb69c7b690c402a91644d564db", "9c166aa124e697446b35c7eea8b9ff6c",
"src/common/PackedEGLEnums_autogen.cpp": "src/common/PackedEGLEnums_autogen.cpp":
"1e5cf84847c9880d32d1f638b366ed08", "1e5cf84847c9880d32d1f638b366ed08",
"src/common/PackedEGLEnums_autogen.h": "src/common/PackedEGLEnums_autogen.h":
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
"src/common/gen_packed_gl_enums.py": "src/common/gen_packed_gl_enums.py":
"7453287e3f184427043604d172a6765b", "7453287e3f184427043604d172a6765b",
"src/common/packed_cl_enums.json": "src/common/packed_cl_enums.json":
"b38037f250994e7d275ac2185afea820", "65150f52de0ece8f4280bbe4db52bf6f",
"src/common/packed_egl_enums.json": "src/common/packed_egl_enums.json":
"76e1b814421e121164d60a0d89cb16c1", "76e1b814421e121164d60a0d89cb16c1",
"src/common/packed_gl_enums.json": "src/common/packed_gl_enums.json":
......
...@@ -2159,12 +2159,6 @@ SamplerInfo FromCLenum<SamplerInfo>(CLenum from) ...@@ -2159,12 +2159,6 @@ SamplerInfo FromCLenum<SamplerInfo>(CLenum from)
return SamplerInfo::AddressingMode; return SamplerInfo::AddressingMode;
case CL_SAMPLER_FILTER_MODE: case CL_SAMPLER_FILTER_MODE:
return SamplerInfo::FilterMode; return SamplerInfo::FilterMode;
case CL_SAMPLER_MIP_FILTER_MODE:
return SamplerInfo::MipFilterMode;
case CL_SAMPLER_LOD_MIN:
return SamplerInfo::LOD_Min;
case CL_SAMPLER_LOD_MAX:
return SamplerInfo::LOD_Max;
case CL_SAMPLER_PROPERTIES: case CL_SAMPLER_PROPERTIES:
return SamplerInfo::Properties; return SamplerInfo::Properties;
default: default:
...@@ -2186,12 +2180,6 @@ CLenum ToCLenum(SamplerInfo from) ...@@ -2186,12 +2180,6 @@ CLenum ToCLenum(SamplerInfo from)
return CL_SAMPLER_ADDRESSING_MODE; return CL_SAMPLER_ADDRESSING_MODE;
case SamplerInfo::FilterMode: case SamplerInfo::FilterMode:
return CL_SAMPLER_FILTER_MODE; return CL_SAMPLER_FILTER_MODE;
case SamplerInfo::MipFilterMode:
return CL_SAMPLER_MIP_FILTER_MODE;
case SamplerInfo::LOD_Min:
return CL_SAMPLER_LOD_MIN;
case SamplerInfo::LOD_Max:
return CL_SAMPLER_LOD_MAX;
case SamplerInfo::Properties: case SamplerInfo::Properties:
return CL_SAMPLER_PROPERTIES; return CL_SAMPLER_PROPERTIES;
default: default:
...@@ -2219,15 +2207,6 @@ std::ostream &operator<<(std::ostream &os, SamplerInfo value) ...@@ -2219,15 +2207,6 @@ std::ostream &operator<<(std::ostream &os, SamplerInfo value)
case SamplerInfo::FilterMode: case SamplerInfo::FilterMode:
os << "CL_SAMPLER_FILTER_MODE"; os << "CL_SAMPLER_FILTER_MODE";
break; break;
case SamplerInfo::MipFilterMode:
os << "CL_SAMPLER_MIP_FILTER_MODE";
break;
case SamplerInfo::LOD_Min:
os << "CL_SAMPLER_LOD_MIN";
break;
case SamplerInfo::LOD_Max:
os << "CL_SAMPLER_LOD_MAX";
break;
case SamplerInfo::Properties: case SamplerInfo::Properties:
os << "CL_SAMPLER_PROPERTIES"; os << "CL_SAMPLER_PROPERTIES";
break; break;
......
...@@ -479,13 +479,10 @@ enum class SamplerInfo : uint8_t ...@@ -479,13 +479,10 @@ enum class SamplerInfo : uint8_t
NormalizedCoords = 2, NormalizedCoords = 2,
AddressingMode = 3, AddressingMode = 3,
FilterMode = 4, FilterMode = 4,
MipFilterMode = 5, Properties = 5,
LOD_Min = 6,
LOD_Max = 7,
Properties = 8,
InvalidEnum = 9, InvalidEnum = 6,
EnumCount = 9, EnumCount = 6,
}; };
template <> template <>
......
...@@ -194,9 +194,6 @@ ...@@ -194,9 +194,6 @@
"NormalizedCoords": "CL_SAMPLER_NORMALIZED_COORDS", "NormalizedCoords": "CL_SAMPLER_NORMALIZED_COORDS",
"AddressingMode": "CL_SAMPLER_ADDRESSING_MODE", "AddressingMode": "CL_SAMPLER_ADDRESSING_MODE",
"FilterMode": "CL_SAMPLER_FILTER_MODE", "FilterMode": "CL_SAMPLER_FILTER_MODE",
"MipFilterMode": "CL_SAMPLER_MIP_FILTER_MODE",
"LOD_Min": "CL_SAMPLER_LOD_MIN",
"LOD_Max": "CL_SAMPLER_LOD_MAX",
"Properties": "CL_SAMPLER_PROPERTIES" "Properties": "CL_SAMPLER_PROPERTIES"
}, },
"ProgramInfo": { "ProgramInfo": {
......
...@@ -173,6 +173,53 @@ cl_mem Context::createImage3D(cl_mem_flags flags, ...@@ -173,6 +173,53 @@ cl_mem Context::createImage3D(cl_mem_flags flags,
new Image(*this, {}, flags, *format, imageDesc, nullptr, hostPtr, errcodeRet), errcodeRet); new Image(*this, {}, flags, *format, imageDesc, nullptr, hostPtr, errcodeRet), errcodeRet);
} }
cl_sampler Context::createSampler(cl_bool normalizedCoords,
AddressingMode addressingMode,
FilterMode filterMode,
cl_int *errcodeRet)
{
return createSampler(
new Sampler(*this, {}, normalizedCoords, addressingMode, filterMode, errcodeRet),
errcodeRet);
}
cl_sampler Context::createSamplerWithProperties(const cl_sampler_properties *properties,
cl_int *errcodeRet)
{
Sampler::PropArray propArray;
cl_bool normalizedCoords = CL_TRUE;
AddressingMode addressingMode = AddressingMode::Clamp;
FilterMode filterMode = FilterMode::Nearest;
if (properties != nullptr)
{
const cl_sampler_properties *propIt = properties;
while (*propIt != 0)
{
switch (*propIt++)
{
case CL_SAMPLER_NORMALIZED_COORDS:
normalizedCoords = static_cast<decltype(normalizedCoords)>(*propIt++);
break;
case CL_SAMPLER_ADDRESSING_MODE:
addressingMode = FromCLenum<AddressingMode>(static_cast<CLenum>(*propIt++));
break;
case CL_SAMPLER_FILTER_MODE:
filterMode = FromCLenum<FilterMode>(static_cast<CLenum>(*propIt++));
break;
}
}
// Include the trailing zero
++propIt;
propArray.reserve(propIt - properties);
propArray.insert(propArray.cend(), properties, propIt);
}
return createSampler(new Sampler(*this, std::move(propArray), normalizedCoords, addressingMode,
filterMode, errcodeRet),
errcodeRet);
}
bool Context::IsValid(const _cl_context *context) bool Context::IsValid(const _cl_context *context)
{ {
const Platform::PtrList &platforms = Platform::GetPlatforms(); const Platform::PtrList &platforms = Platform::GetPlatforms();
...@@ -249,6 +296,21 @@ cl_mem Context::createMemory(Memory *memory, cl_int *errcodeRet) ...@@ -249,6 +296,21 @@ cl_mem Context::createMemory(Memory *memory, cl_int *errcodeRet)
return mMemories.back().get(); return mMemories.back().get();
} }
cl_sampler Context::createSampler(Sampler *sampler, cl_int *errcodeRet)
{
mSamplers.emplace_back(sampler);
if (!mSamplers.back()->mImpl)
{
mSamplers.back()->release();
return nullptr;
}
if (errcodeRet != nullptr)
{
*errcodeRet = CL_SUCCESS;
}
return mSamplers.back().get();
}
void Context::destroyCommandQueue(CommandQueue *commandQueue) void Context::destroyCommandQueue(CommandQueue *commandQueue)
{ {
auto commandQueueIt = mCommandQueues.cbegin(); auto commandQueueIt = mCommandQueues.cbegin();
...@@ -283,6 +345,23 @@ void Context::destroyMemory(Memory *memory) ...@@ -283,6 +345,23 @@ void Context::destroyMemory(Memory *memory)
} }
} }
void Context::destroySampler(Sampler *sampler)
{
auto samplerIt = mSamplers.cbegin();
while (samplerIt != mSamplers.cend() && samplerIt->get() != sampler)
{
++samplerIt;
}
if (samplerIt != mSamplers.cend())
{
mSamplers.erase(samplerIt);
}
else
{
ERR() << "Sampler not found";
}
}
void Context::ErrorCallback(const char *errinfo, const void *privateInfo, size_t cb, void *userData) void Context::ErrorCallback(const char *errinfo, const void *privateInfo, size_t cb, void *userData)
{ {
Context *const context = static_cast<Context *>(userData); Context *const context = static_cast<Context *>(userData);
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "libANGLE/CLCommandQueue.h" #include "libANGLE/CLCommandQueue.h"
#include "libANGLE/CLDevice.h" #include "libANGLE/CLDevice.h"
#include "libANGLE/CLMemory.h" #include "libANGLE/CLMemory.h"
#include "libANGLE/CLSampler.h"
#include "libANGLE/renderer/CLContextImpl.h" #include "libANGLE/renderer/CLContextImpl.h"
namespace cl namespace cl
...@@ -28,9 +29,11 @@ class Context final : public _cl_context, public Object ...@@ -28,9 +29,11 @@ class Context final : public _cl_context, public Object
const Platform &getPlatform() const noexcept; const Platform &getPlatform() const noexcept;
bool hasDevice(const _cl_device_id *device) const; bool hasDevice(const _cl_device_id *device) const;
const DeviceRefList &getDevices() const; const DeviceRefList &getDevices() const;
bool supportsImages() const;
bool hasCommandQueue(const _cl_command_queue *commandQueue) const; bool hasCommandQueue(const _cl_command_queue *commandQueue) const;
bool hasMemory(const _cl_mem *memory) const; bool hasMemory(const _cl_mem *memory) const;
bool hasSampler(const _cl_sampler *sampler) const;
void retain() noexcept; void retain() noexcept;
bool release(); bool release();
...@@ -76,6 +79,14 @@ class Context final : public _cl_context, public Object ...@@ -76,6 +79,14 @@ class Context final : public _cl_context, public Object
void *hostPtr, void *hostPtr,
cl_int *errcodeRet); cl_int *errcodeRet);
cl_sampler createSampler(cl_bool normalizedCoords,
AddressingMode addressingMode,
FilterMode filterMode,
cl_int *errcodeRet);
cl_sampler createSamplerWithProperties(const cl_sampler_properties *properties,
cl_int *errcodeRet);
static bool IsValid(const _cl_context *context); static bool IsValid(const _cl_context *context);
private: private:
...@@ -97,9 +108,11 @@ class Context final : public _cl_context, public Object ...@@ -97,9 +108,11 @@ class Context final : public _cl_context, public Object
cl_command_queue createCommandQueue(CommandQueue *commandQueue, cl_int *errcodeRet); cl_command_queue createCommandQueue(CommandQueue *commandQueue, cl_int *errcodeRet);
cl_mem createMemory(Memory *memory, cl_int *errcodeRet); cl_mem createMemory(Memory *memory, cl_int *errcodeRet);
cl_sampler createSampler(Sampler *sampler, cl_int *errcodeRet);
void destroyCommandQueue(CommandQueue *commandQueue); void destroyCommandQueue(CommandQueue *commandQueue);
void destroyMemory(Memory *memory); void destroyMemory(Memory *memory);
void destroySampler(Sampler *sampler);
static void CL_CALLBACK ErrorCallback(const char *errinfo, static void CL_CALLBACK ErrorCallback(const char *errinfo,
const void *privateInfo, const void *privateInfo,
...@@ -115,11 +128,13 @@ class Context final : public _cl_context, public Object ...@@ -115,11 +128,13 @@ class Context final : public _cl_context, public Object
CommandQueue::PtrList mCommandQueues; CommandQueue::PtrList mCommandQueues;
Memory::PtrList mMemories; Memory::PtrList mMemories;
Sampler::PtrList mSamplers;
friend class Buffer; friend class Buffer;
friend class CommandQueue; friend class CommandQueue;
friend class Memory; friend class Memory;
friend class Platform; friend class Platform;
friend class Sampler;
}; };
inline const Platform &Context::getPlatform() const noexcept inline const Platform &Context::getPlatform() const noexcept
...@@ -139,6 +154,13 @@ inline const DeviceRefList &Context::getDevices() const ...@@ -139,6 +154,13 @@ inline const DeviceRefList &Context::getDevices() const
return mDevices; return mDevices;
} }
inline bool Context::supportsImages() const
{
return (std::find_if(mDevices.cbegin(), mDevices.cend(), [](const DeviceRefPtr &ptr) {
return ptr->getInfo().mImageSupport == CL_TRUE;
}) != mDevices.cend());
}
inline bool Context::hasCommandQueue(const _cl_command_queue *commandQueue) const inline bool Context::hasCommandQueue(const _cl_command_queue *commandQueue) const
{ {
return std::find_if(mCommandQueues.cbegin(), mCommandQueues.cend(), return std::find_if(mCommandQueues.cbegin(), mCommandQueues.cend(),
...@@ -153,6 +175,13 @@ inline bool Context::hasMemory(const _cl_mem *memory) const ...@@ -153,6 +175,13 @@ inline bool Context::hasMemory(const _cl_mem *memory) const
}) != mMemories.cend(); }) != mMemories.cend();
} }
inline bool Context::hasSampler(const _cl_sampler *sampler) const
{
return std::find_if(mSamplers.cbegin(), mSamplers.cend(), [=](const SamplerPtr &ptr) {
return ptr.get() == sampler;
}) != mSamplers.cend();
}
inline void Context::retain() noexcept inline void Context::retain() noexcept
{ {
addRef(); addRef();
......
...@@ -36,6 +36,7 @@ class Platform final : public _cl_platform_id, public Object ...@@ -36,6 +36,7 @@ class Platform final : public _cl_platform_id, public Object
bool hasContext(const _cl_context *context) const; bool hasContext(const _cl_context *context) const;
bool hasCommandQueue(const _cl_command_queue *commandQueue) const; bool hasCommandQueue(const _cl_command_queue *commandQueue) const;
bool hasMemory(const _cl_mem *memory) const; bool hasMemory(const _cl_mem *memory) const;
bool hasSampler(const _cl_sampler *sampler) const;
cl_int getInfo(PlatformInfo name, size_t valueSize, void *value, size_t *valueSizeRet) const; cl_int getInfo(PlatformInfo name, size_t valueSize, void *value, size_t *valueSizeRet) const;
...@@ -135,6 +136,13 @@ inline bool Platform::hasMemory(const _cl_mem *memory) const ...@@ -135,6 +136,13 @@ inline bool Platform::hasMemory(const _cl_mem *memory) const
}) != mContexts.cend(); }) != mContexts.cend();
} }
inline bool Platform::hasSampler(const _cl_sampler *sampler) const
{
return std::find_if(mContexts.cbegin(), mContexts.cend(), [=](const ContextPtr &ptr) {
return ptr->hasSampler(sampler);
}) != mContexts.cend();
}
inline Platform::PtrList &Platform::GetList() inline Platform::PtrList &Platform::GetList()
{ {
static angle::base::NoDestructor<PtrList> sList; static angle::base::NoDestructor<PtrList> sList;
......
...@@ -7,9 +7,109 @@ ...@@ -7,9 +7,109 @@
#include "libANGLE/CLSampler.h" #include "libANGLE/CLSampler.h"
#include "libANGLE/CLContext.h"
#include "libANGLE/CLPlatform.h"
#include <cstring>
namespace cl namespace cl
{ {
Sampler::Sampler(const cl_icd_dispatch &dispatch) : _cl_sampler(dispatch) {} Sampler::~Sampler() = default;
bool Sampler::release()
{
const bool released = removeRef();
if (released)
{
mContext->destroySampler(this);
}
return released;
}
cl_int Sampler::getInfo(SamplerInfo name, size_t valueSize, void *value, size_t *valueSizeRet) const
{
static_assert(std::is_same<cl_uint, cl_addressing_mode>::value &&
std::is_same<cl_uint, cl_filter_mode>::value,
"OpenCL type mismatch");
cl_uint valUInt = 0u;
void *valPointer = nullptr;
const void *copyValue = nullptr;
size_t copySize = 0u;
switch (name)
{
case SamplerInfo::ReferenceCount:
copyValue = getRefCountPtr();
copySize = sizeof(*getRefCountPtr());
break;
case SamplerInfo::Context:
valPointer = static_cast<cl_context>(mContext.get());
copyValue = &valPointer;
copySize = sizeof(valPointer);
break;
case SamplerInfo::NormalizedCoords:
copyValue = &mNormalizedCoords;
copySize = sizeof(mNormalizedCoords);
break;
case SamplerInfo::AddressingMode:
valUInt = ToCLenum(mAddressingMode);
copyValue = &valUInt;
copySize = sizeof(valUInt);
break;
case SamplerInfo::FilterMode:
valUInt = ToCLenum(mFilterMode);
copyValue = &valUInt;
copySize = sizeof(valUInt);
break;
case SamplerInfo::Properties:
copyValue = mProperties.data();
copySize = mProperties.size() * sizeof(decltype(mProperties)::value_type);
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 (valueSizeRet != nullptr)
{
*valueSizeRet = copySize;
}
return CL_SUCCESS;
}
bool Sampler::IsValid(const _cl_sampler *sampler)
{
const Platform::PtrList &platforms = Platform::GetPlatforms();
return std::find_if(platforms.cbegin(), platforms.cend(), [=](const PlatformPtr &platform) {
return platform->hasSampler(sampler);
}) != platforms.cend();
}
Sampler::Sampler(Context &context,
PropArray &&properties,
cl_bool normalizedCoords,
AddressingMode addressingMode,
FilterMode filterMode,
cl_int *errcodeRet)
: _cl_sampler(context.getDispatch()),
mContext(&context),
mProperties(std::move(properties)),
mNormalizedCoords(normalizedCoords),
mAddressingMode(addressingMode),
mFilterMode(filterMode),
mImpl(context.mImpl->createSampler(*this, errcodeRet))
{}
} // namespace cl } // namespace cl
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#define LIBANGLE_CLSAMPLER_H_ #define LIBANGLE_CLSAMPLER_H_
#include "libANGLE/CLObject.h" #include "libANGLE/CLObject.h"
#include "libANGLE/renderer/CLSamplerImpl.h"
namespace cl namespace cl
{ {
...@@ -16,10 +17,72 @@ namespace cl ...@@ -16,10 +17,72 @@ namespace cl
class Sampler final : public _cl_sampler, public Object class Sampler final : public _cl_sampler, public Object
{ {
public: public:
Sampler(const cl_icd_dispatch &dispatch); using PtrList = std::list<SamplerPtr>;
~Sampler() override = default; using PropArray = std::vector<cl_sampler_properties>;
~Sampler() override;
const Context &getContext() const;
const PropArray &getProperties() const;
cl_bool getNormalizedCoords() const;
AddressingMode getAddressingMode() const;
FilterMode getFilterMode() const;
void retain() noexcept;
bool release();
cl_int getInfo(SamplerInfo name, size_t valueSize, void *value, size_t *valueSizeRet) const;
static bool IsValid(const _cl_sampler *sampler);
private:
Sampler(Context &context,
PropArray &&properties,
cl_bool normalizedCoords,
AddressingMode addressingMode,
FilterMode filterMode,
cl_int *errcodeRet);
const ContextRefPtr mContext;
const PropArray mProperties;
const cl_bool mNormalizedCoords;
const AddressingMode mAddressingMode;
const FilterMode mFilterMode;
const rx::CLSamplerImpl::Ptr mImpl;
friend class Context;
}; };
inline const Context &Sampler::getContext() const
{
return *mContext;
}
inline const Sampler::PropArray &Sampler::getProperties() const
{
return mProperties;
}
inline cl_bool Sampler::getNormalizedCoords() const
{
return mNormalizedCoords;
}
inline AddressingMode Sampler::getAddressingMode() const
{
return mAddressingMode;
}
inline FilterMode Sampler::getFilterMode() const
{
return mFilterMode;
}
inline void Sampler::retain() noexcept
{
addRef();
}
} // namespace cl } // namespace cl
#endif // LIBANGLE_CLSAMPLER_H_ #endif // LIBANGLE_CLSAMPLER_H_
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "libANGLE/renderer/CLCommandQueueImpl.h" #include "libANGLE/renderer/CLCommandQueueImpl.h"
#include "libANGLE/renderer/CLDeviceImpl.h" #include "libANGLE/renderer/CLDeviceImpl.h"
#include "libANGLE/renderer/CLMemoryImpl.h" #include "libANGLE/renderer/CLMemoryImpl.h"
#include "libANGLE/renderer/CLSamplerImpl.h"
namespace rx namespace rx
{ {
...@@ -39,6 +40,8 @@ class CLContextImpl : angle::NonCopyable ...@@ -39,6 +40,8 @@ class CLContextImpl : angle::NonCopyable
void *hostPtr, void *hostPtr,
cl_int *errcodeRet) = 0; cl_int *errcodeRet) = 0;
virtual CLSamplerImpl::Ptr createSampler(const cl::Sampler &sampler, cl_int *errcodeRet) = 0;
protected: protected:
const cl::Context &mContext; const cl::Context &mContext;
}; };
......
//
// 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.
//
// CLSamplerImpl.cpp: Implements the class methods for CLSamplerImpl.
#include "libANGLE/renderer/CLSamplerImpl.h"
namespace rx
{
CLSamplerImpl::CLSamplerImpl(const cl::Sampler &sampler) : mSampler(sampler) {}
CLSamplerImpl::~CLSamplerImpl() = default;
} // namespace rx
//
// 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.
//
// CLSamplerImpl.h: Defines the abstract rx::CLSamplerImpl class.
#ifndef LIBANGLE_RENDERER_CLSAMPLERIMPL_H_
#define LIBANGLE_RENDERER_CLSAMPLERIMPL_H_
#include "libANGLE/renderer/CLtypes.h"
namespace rx
{
class CLSamplerImpl : angle::NonCopyable
{
public:
using Ptr = std::unique_ptr<CLSamplerImpl>;
CLSamplerImpl(const cl::Sampler &sampler);
virtual ~CLSamplerImpl();
protected:
const cl::Sampler &mSampler;
};
} // namespace rx
#endif // LIBANGLE_RENDERER_CLSAMPLERIMPL_H_
...@@ -19,6 +19,8 @@ _cl_backend_sources = [ ...@@ -19,6 +19,8 @@ _cl_backend_sources = [
"CLMemoryCL.h", "CLMemoryCL.h",
"CLPlatformCL.cpp", "CLPlatformCL.cpp",
"CLPlatformCL.h", "CLPlatformCL.h",
"CLSamplerCL.cpp",
"CLSamplerCL.h",
"cl_types.h", "cl_types.h",
"cl_util.cpp", "cl_util.cpp",
"cl_util.h", "cl_util.h",
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "libANGLE/renderer/cl/CLCommandQueueCL.h" #include "libANGLE/renderer/cl/CLCommandQueueCL.h"
#include "libANGLE/renderer/cl/CLDeviceCL.h" #include "libANGLE/renderer/cl/CLDeviceCL.h"
#include "libANGLE/renderer/cl/CLMemoryCL.h" #include "libANGLE/renderer/cl/CLMemoryCL.h"
#include "libANGLE/renderer/cl/CLSamplerCL.h"
#include "libANGLE/CLBuffer.h" #include "libANGLE/CLBuffer.h"
#include "libANGLE/CLCommandQueue.h" #include "libANGLE/CLCommandQueue.h"
...@@ -18,6 +19,7 @@ ...@@ -18,6 +19,7 @@
#include "libANGLE/CLImage.h" #include "libANGLE/CLImage.h"
#include "libANGLE/CLMemory.h" #include "libANGLE/CLMemory.h"
#include "libANGLE/CLPlatform.h" #include "libANGLE/CLPlatform.h"
#include "libANGLE/CLSampler.h"
#include "libANGLE/Debug.h" #include "libANGLE/Debug.h"
namespace rx namespace rx
...@@ -170,4 +172,34 @@ CLMemoryImpl::Ptr CLContextCL::createImage(const cl::Image &image, ...@@ -170,4 +172,34 @@ CLMemoryImpl::Ptr CLContextCL::createImage(const cl::Image &image,
return CLMemoryImpl::Ptr(nativeImage != nullptr ? new CLMemoryCL(image, nativeImage) : nullptr); return CLMemoryImpl::Ptr(nativeImage != nullptr ? new CLMemoryCL(image, nativeImage) : nullptr);
} }
CLSamplerImpl::Ptr CLContextCL::createSampler(const cl::Sampler &sampler, cl_int *errcodeRet)
{
cl_sampler nativeSampler = nullptr;
if (!mContext.getPlatform().isVersionOrNewer(2u, 0u))
{
nativeSampler = mNative->getDispatch().clCreateSampler(
mNative, sampler.getNormalizedCoords(), cl::ToCLenum(sampler.getAddressingMode()),
cl::ToCLenum(sampler.getFilterMode()), errcodeRet);
}
else if (!sampler.getProperties().empty())
{
nativeSampler = mNative->getDispatch().clCreateSamplerWithProperties(
mNative, sampler.getProperties().data(), errcodeRet);
}
else
{
const cl_sampler_properties propArray[] = {CL_SAMPLER_NORMALIZED_COORDS,
sampler.getNormalizedCoords(),
CL_SAMPLER_ADDRESSING_MODE,
cl::ToCLenum(sampler.getAddressingMode()),
CL_SAMPLER_FILTER_MODE,
cl::ToCLenum(sampler.getFilterMode()),
0u};
nativeSampler =
mNative->getDispatch().clCreateSamplerWithProperties(mNative, propArray, errcodeRet);
}
return CLSamplerImpl::Ptr(nativeSampler != nullptr ? new CLSamplerCL(sampler, nativeSampler)
: nullptr);
}
} // namespace rx } // namespace rx
...@@ -37,6 +37,8 @@ class CLContextCL : public CLContextImpl ...@@ -37,6 +37,8 @@ class CLContextCL : public CLContextImpl
void *hostPtr, void *hostPtr,
cl_int *errcodeRet) override; cl_int *errcodeRet) override;
CLSamplerImpl::Ptr createSampler(const cl::Sampler &sampler, cl_int *errcodeRet) override;
private: private:
const cl_context mNative; const cl_context mNative;
}; };
......
//
// 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.
//
// CLSamplerCL.cpp: Implements the class methods for CLSamplerCL.
#include "libANGLE/renderer/cl/CLSamplerCL.h"
#include "libANGLE/Debug.h"
namespace rx
{
CLSamplerCL::CLSamplerCL(const cl::Sampler &sampler, cl_sampler native)
: CLSamplerImpl(sampler), mNative(native)
{}
CLSamplerCL::~CLSamplerCL()
{
if (mNative->getDispatch().clReleaseSampler(mNative) != CL_SUCCESS)
{
ERR() << "Error while releasing CL sampler";
}
}
} // namespace rx
//
// 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.
//
// CLSamplerCL.h: Defines the class interface for CLSamplerCL, implementing CLSamplerImpl.
#ifndef LIBANGLE_RENDERER_CL_CLSAMPLERCL_H_
#define LIBANGLE_RENDERER_CL_CLSAMPLERCL_H_
#include "libANGLE/renderer/cl/cl_types.h"
#include "libANGLE/renderer/CLSamplerImpl.h"
namespace rx
{
class CLSamplerCL : public CLSamplerImpl
{
public:
CLSamplerCL(const cl::Sampler &sampler, cl_sampler native);
~CLSamplerCL() override;
private:
const cl_sampler mNative;
};
} // namespace rx
#endif // LIBANGLE_RENDERER_CL_CLSAMPLERCL_H_
...@@ -115,6 +115,8 @@ if (angle_enable_cl) { ...@@ -115,6 +115,8 @@ if (angle_enable_cl) {
"CLMemoryVk.h", "CLMemoryVk.h",
"CLPlatformVk.cpp", "CLPlatformVk.cpp",
"CLPlatformVk.h", "CLPlatformVk.h",
"CLSamplerVk.cpp",
"CLSamplerVk.h",
"cl_types.h", "cl_types.h",
] ]
} }
......
//
// 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.
//
// CLSamplerVk.cpp: Implements the class methods for CLSamplerVk.
#include "libANGLE/renderer/vulkan/CLSamplerVk.h"
namespace rx
{
CLSamplerVk::CLSamplerVk(const cl::Sampler &sampler) : CLSamplerImpl(sampler) {}
CLSamplerVk::~CLSamplerVk() = default;
} // namespace rx
//
// 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.
//
// CLSamplerVk.h: Defines the class interface for CLSamplerVk, implementing CLSamplerImpl.
#ifndef LIBANGLE_RENDERER_VULKAN_CLSAMPLERVK_H_
#define LIBANGLE_RENDERER_VULKAN_CLSAMPLERVK_H_
#include "libANGLE/renderer/vulkan/cl_types.h"
#include "libANGLE/renderer/CLSamplerImpl.h"
namespace rx
{
class CLSamplerVk : public CLSamplerImpl
{
public:
CLSamplerVk(const cl::Sampler &sampler);
~CLSamplerVk() override;
};
} // namespace rx
#endif // LIBANGLE_RENDERER_VULKAN_CLSAMPLERVK_H_
...@@ -601,12 +601,12 @@ cl_int ValidateGetImageInfo(cl_mem image, ...@@ -601,12 +601,12 @@ cl_int ValidateGetImageInfo(cl_mem image,
cl_int ValidateRetainSampler(cl_sampler sampler) cl_int ValidateRetainSampler(cl_sampler sampler)
{ {
return CL_SUCCESS; return Sampler::IsValid(sampler) ? CL_SUCCESS : CL_INVALID_SAMPLER;
} }
cl_int ValidateReleaseSampler(cl_sampler sampler) cl_int ValidateReleaseSampler(cl_sampler sampler)
{ {
return CL_SUCCESS; return Sampler::IsValid(sampler) ? CL_SUCCESS : CL_INVALID_SAMPLER;
} }
cl_int ValidateGetSamplerInfo(cl_sampler sampler, cl_int ValidateGetSamplerInfo(cl_sampler sampler,
...@@ -615,6 +615,17 @@ cl_int ValidateGetSamplerInfo(cl_sampler sampler, ...@@ -615,6 +615,17 @@ cl_int ValidateGetSamplerInfo(cl_sampler sampler,
const void *param_value, const void *param_value,
const size_t *param_value_size_ret) const size_t *param_value_size_ret)
{ {
if (!Sampler::IsValid(sampler))
{
return CL_INVALID_SAMPLER;
}
const Platform &platform = static_cast<const Sampler *>(sampler)->getContext().getPlatform();
if (param_name == SamplerInfo::InvalidEnum ||
(param_name == SamplerInfo::Properties && !platform.isVersionOrNewer(3u, 0u)) ||
(param_value_size == 0u && param_value != nullptr))
{
return CL_INVALID_VALUE;
}
return CL_SUCCESS; return CL_SUCCESS;
} }
...@@ -1047,6 +1058,19 @@ bool ValidateCreateSampler(cl_context context, ...@@ -1047,6 +1058,19 @@ bool ValidateCreateSampler(cl_context context,
FilterMode filter_mode, FilterMode filter_mode,
cl_int *errcode_ret) cl_int *errcode_ret)
{ {
if (!Context::IsValid(context))
{
ANGLE_ERROR_RETURN(CL_INVALID_CONTEXT, false);
}
if ((normalized_coords != CL_FALSE && normalized_coords != CL_TRUE) ||
addressing_mode == AddressingMode::InvalidEnum || filter_mode == FilterMode::InvalidEnum)
{
ANGLE_ERROR_RETURN(CL_INVALID_VALUE, false);
}
if (!static_cast<Context *>(context)->supportsImages())
{
ANGLE_ERROR_RETURN(CL_INVALID_OPERATION, false);
}
return true; return true;
} }
...@@ -1281,16 +1305,13 @@ bool ValidateCreateImage(cl_context context, ...@@ -1281,16 +1305,13 @@ bool ValidateCreateImage(cl_context context,
ANGLE_ERROR_RETURN(CL_INVALID_IMAGE_DESCRIPTOR, false); ANGLE_ERROR_RETURN(CL_INVALID_IMAGE_DESCRIPTOR, false);
} }
const DeviceRefList &devices = ctx.getDevices(); if (!ctx.supportsImages())
// Fail if no device supports images
if (std::find_if(devices.cbegin(), devices.cend(), [](const DeviceRefPtr &ptr) {
return ptr->getInfo().mImageSupport == CL_TRUE;
}) == devices.cend())
{ {
ANGLE_ERROR_RETURN(CL_INVALID_OPERATION, false); ANGLE_ERROR_RETURN(CL_INVALID_OPERATION, false);
} }
// Fail if image dimensions exceed supported maximum of all devices // Fail if image dimensions exceed supported maximum of all devices
const DeviceRefList &devices = ctx.getDevices();
if (std::find_if(devices.cbegin(), devices.cend(), [&](const DeviceRefPtr &ptr) { if (std::find_if(devices.cbegin(), devices.cend(), [&](const DeviceRefPtr &ptr) {
switch (image_desc->image_type) switch (image_desc->image_type)
{ {
...@@ -1524,6 +1545,53 @@ bool ValidateCreateSamplerWithProperties(cl_context context, ...@@ -1524,6 +1545,53 @@ bool ValidateCreateSamplerWithProperties(cl_context context,
const cl_sampler_properties *sampler_properties, const cl_sampler_properties *sampler_properties,
cl_int *errcode_ret) cl_int *errcode_ret)
{ {
if (!Context::IsValid(context))
{
ANGLE_ERROR_RETURN(CL_INVALID_CONTEXT, false);
}
if (sampler_properties != nullptr)
{
bool hasNormalizedCoords = false;
bool hasAddressingMode = false;
bool hasFilterMode = false;
const cl_sampler_properties *propIt = sampler_properties;
while (*propIt != 0)
{
switch (*propIt++)
{
case CL_SAMPLER_NORMALIZED_COORDS:
if (hasNormalizedCoords || (*propIt != CL_FALSE && *propIt != CL_TRUE))
{
ANGLE_ERROR_RETURN(CL_INVALID_VALUE, false);
}
hasNormalizedCoords = true;
++propIt;
break;
case CL_SAMPLER_ADDRESSING_MODE:
if (hasAddressingMode || FromCLenum<AddressingMode>(static_cast<CLenum>(
*propIt++)) == AddressingMode::InvalidEnum)
{
ANGLE_ERROR_RETURN(CL_INVALID_VALUE, false);
}
hasAddressingMode = true;
break;
case CL_SAMPLER_FILTER_MODE:
if (hasFilterMode || FromCLenum<FilterMode>(static_cast<CLenum>(*propIt++)) ==
FilterMode::InvalidEnum)
{
ANGLE_ERROR_RETURN(CL_INVALID_VALUE, false);
}
hasFilterMode = true;
break;
default:
ANGLE_ERROR_RETURN(CL_INVALID_VALUE, false);
}
}
}
if (!static_cast<Context *>(context)->supportsImages())
{
ANGLE_ERROR_RETURN(CL_INVALID_OPERATION, false);
}
return true; return true;
} }
......
...@@ -473,6 +473,7 @@ libangle_cl_headers = [ ...@@ -473,6 +473,7 @@ libangle_cl_headers = [
"src/libANGLE/renderer/CLDeviceImpl.h", "src/libANGLE/renderer/CLDeviceImpl.h",
"src/libANGLE/renderer/CLMemoryImpl.h", "src/libANGLE/renderer/CLMemoryImpl.h",
"src/libANGLE/renderer/CLPlatformImpl.h", "src/libANGLE/renderer/CLPlatformImpl.h",
"src/libANGLE/renderer/CLSamplerImpl.h",
"src/libANGLE/renderer/CLtypes.h", "src/libANGLE/renderer/CLtypes.h",
"src/libANGLE/validationCL.h", "src/libANGLE/validationCL.h",
"src/libANGLE/validationCL_autogen.h", "src/libANGLE/validationCL_autogen.h",
...@@ -497,6 +498,7 @@ libangle_cl_sources = [ ...@@ -497,6 +498,7 @@ libangle_cl_sources = [
"src/libANGLE/renderer/CLDeviceImpl.cpp", "src/libANGLE/renderer/CLDeviceImpl.cpp",
"src/libANGLE/renderer/CLMemoryImpl.cpp", "src/libANGLE/renderer/CLMemoryImpl.cpp",
"src/libANGLE/renderer/CLPlatformImpl.cpp", "src/libANGLE/renderer/CLPlatformImpl.cpp",
"src/libANGLE/renderer/CLSamplerImpl.cpp",
"src/libANGLE/validationCL.cpp", "src/libANGLE/validationCL.cpp",
] ]
......
...@@ -345,20 +345,20 @@ cl_sampler CreateSamplerWithProperties(cl_context context, ...@@ -345,20 +345,20 @@ cl_sampler CreateSamplerWithProperties(cl_context context,
const cl_sampler_properties *sampler_properties, const cl_sampler_properties *sampler_properties,
cl_int *errcode_ret) cl_int *errcode_ret)
{ {
WARN_NOT_SUPPORTED(CreateSamplerWithProperties); return static_cast<Context *>(context)->createSamplerWithProperties(sampler_properties,
return 0; errcode_ret);
} }
cl_int RetainSampler(cl_sampler sampler) cl_int RetainSampler(cl_sampler sampler)
{ {
WARN_NOT_SUPPORTED(RetainSampler); static_cast<Sampler *>(sampler)->retain();
return 0; return CL_SUCCESS;
} }
cl_int ReleaseSampler(cl_sampler sampler) cl_int ReleaseSampler(cl_sampler sampler)
{ {
WARN_NOT_SUPPORTED(ReleaseSampler); static_cast<Sampler *>(sampler)->release();
return 0; return CL_SUCCESS;
} }
cl_int GetSamplerInfo(cl_sampler sampler, cl_int GetSamplerInfo(cl_sampler sampler,
...@@ -367,8 +367,8 @@ cl_int GetSamplerInfo(cl_sampler sampler, ...@@ -367,8 +367,8 @@ cl_int GetSamplerInfo(cl_sampler sampler,
void *param_value, void *param_value,
size_t *param_value_size_ret) size_t *param_value_size_ret)
{ {
WARN_NOT_SUPPORTED(GetSamplerInfo); return static_cast<Sampler *>(sampler)->getInfo(param_name, param_value_size, param_value,
return 0; param_value_size_ret);
} }
cl_program CreateProgramWithSource(cl_context context, cl_program CreateProgramWithSource(cl_context context,
...@@ -1152,8 +1152,8 @@ cl_sampler CreateSampler(cl_context context, ...@@ -1152,8 +1152,8 @@ cl_sampler CreateSampler(cl_context context,
FilterMode filter_mode, FilterMode filter_mode,
cl_int *errcode_ret) cl_int *errcode_ret)
{ {
WARN_NOT_SUPPORTED(CreateSampler); return static_cast<Context *>(context)->createSampler(normalized_coords, addressing_mode,
return 0; filter_mode, errcode_ret);
} }
cl_int EnqueueTask(cl_command_queue command_queue, cl_int EnqueueTask(cl_command_queue command_queue,
......
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