Hash :
44a5c913
Author :
Date :
2021-06-17T09:29:29
CL: Make CL front end and back end thread-safe Add locking to all mutable variables of the CL objects in the front end and pass-through back end to make them thread-safe. This fixes a crash in a multi-threaded CTS test. Bug: angleproject:6015 Change-Id: I1d6471c851217639411c434c82acd32d14035291 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2967468 Commit-Queue: John Plate <jplate@google.com> Reviewed-by: Cody Northrop <cnorthrop@google.com> Reviewed-by: Jamie Madill <jmadill@chromium.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
//
// 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.
//
// CLMemory.h: Defines the abstract cl::Memory class, which is a memory object
// and the base class for OpenCL objects such as Buffer, Image and Pipe.
#ifndef LIBANGLE_CLMEMORY_H_
#define LIBANGLE_CLMEMORY_H_
#include "libANGLE/CLObject.h"
#include "libANGLE/renderer/CLMemoryImpl.h"
#include "common/Spinlock.h"
#include "common/SynchronizedValue.h"
#include <atomic>
#include <stack>
namespace cl
{
class Memory : public _cl_mem, public Object
{
public:
// Front end entry functions, only called from OpenCL entry points
cl_int setDestructorCallback(MemoryCB pfnNotify, void *userData);
cl_int getInfo(MemInfo name, size_t valueSize, void *value, size_t *valueSizeRet) const;
public:
using PropArray = std::vector<cl_mem_properties>;
~Memory() override;
virtual MemObjectType getType() const = 0;
const Context &getContext() const;
const PropArray &getProperties() const;
MemFlags getFlags() const;
void *getHostPtr() const;
const MemoryPtr &getParent() const;
size_t getOffset() const;
size_t getSize() const;
template <typename T = rx::CLMemoryImpl>
T &getImpl() const;
static Memory *Cast(cl_mem memobj);
protected:
using CallbackData = std::pair<MemoryCB, void *>;
Memory(const Buffer &buffer,
Context &context,
PropArray &&properties,
MemFlags flags,
size_t size,
void *hostPtr,
cl_int &errorCode);
Memory(const Buffer &buffer,
Buffer &parent,
MemFlags flags,
size_t offset,
size_t size,
cl_int &errorCode);
Memory(const Image &image,
Context &context,
PropArray &&properties,
MemFlags flags,
const cl_image_format &format,
const ImageDescriptor &desc,
Memory *parent,
void *hostPtr,
cl_int &errorCode);
const ContextPtr mContext;
const PropArray mProperties;
const MemFlags mFlags;
void *const mHostPtr = nullptr;
const MemoryPtr mParent;
const size_t mOffset = 0u;
const rx::CLMemoryImpl::Ptr mImpl;
const size_t mSize;
angle::SynchronizedValue<std::stack<CallbackData>, angle::Spinlock> mDestructorCallbacks;
std::atomic<cl_uint> mMapCount;
friend class Buffer;
friend class Context;
};
inline const Context &Memory::getContext() const
{
return *mContext;
}
inline const Memory::PropArray &Memory::getProperties() const
{
return mProperties;
}
inline MemFlags Memory::getFlags() const
{
return mFlags;
}
inline void *Memory::getHostPtr() const
{
return mHostPtr;
}
inline const MemoryPtr &Memory::getParent() const
{
return mParent;
}
inline size_t Memory::getOffset() const
{
return mOffset;
}
inline size_t Memory::getSize() const
{
return mSize;
}
template <typename T>
inline T &Memory::getImpl() const
{
return static_cast<T &>(*mImpl);
}
inline Memory *Memory::Cast(cl_mem memobj)
{
return static_cast<Memory *>(memobj);
}
} // namespace cl
#endif // LIBANGLE_CLMEMORY_H_