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
//
// 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.
//
// CLMemoryCL.cpp: Implements the class methods for CLMemoryCL.
#include "libANGLE/renderer/cl/CLMemoryCL.h"
#include "libANGLE/renderer/cl/CLContextCL.h"
#include "libANGLE/CLBuffer.h"
#include "libANGLE/CLContext.h"
namespace rx
{
CLMemoryCL::CLMemoryCL(const cl::Memory &memory, cl_mem native)
: CLMemoryImpl(memory), mNative(native)
{
memory.getContext().getImpl<CLContextCL>().mData->mMemories.emplace(memory.getNative());
}
CLMemoryCL::~CLMemoryCL()
{
const size_t numRemoved =
mMemory.getContext().getImpl<CLContextCL>().mData->mMemories.erase(mMemory.getNative());
ASSERT(numRemoved == 1u);
if (mNative->getDispatch().clReleaseMemObject(mNative) != CL_SUCCESS)
{
ERR() << "Error while releasing CL memory object";
}
}
size_t CLMemoryCL::getSize(cl_int &errorCode) const
{
size_t size = 0u;
errorCode = mNative->getDispatch().clGetMemObjectInfo(mNative, CL_MEM_SIZE, sizeof(size), &size,
nullptr);
if (errorCode != CL_SUCCESS)
{
return 0u;
}
return size;
}
CLMemoryImpl::Ptr CLMemoryCL::createSubBuffer(const cl::Buffer &buffer,
cl::MemFlags flags,
size_t size,
cl_int &errorCode)
{
const cl_buffer_region region = {buffer.getOffset(), size};
const cl_mem nativeBuffer = mNative->getDispatch().clCreateSubBuffer(
mNative, flags.get(), CL_BUFFER_CREATE_TYPE_REGION, ®ion, &errorCode);
return CLMemoryImpl::Ptr(nativeBuffer != nullptr ? new CLMemoryCL(buffer, nativeBuffer)
: nullptr);
}
} // namespace rx