Hash :
b3e715de
Author :
Date :
2025-07-15T13:43:31
cl/vk: Fix user-event handling - add missing internal retain for user-event setting - add missing predicate for condition variable wait - fix double-alloc on user-event backend creation - mImpl is created during "initBackend", not ctor Bug: angleproject:444482493 Change-Id: I48fa8bca43a06d5ff8b2bceb884a924840ec5682 Signed-off-by: Austin Annestrand <a.annestrand@samsung.com> Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/6941605 Reviewed-by: Geoff Lang <geofflang@chromium.org> Reviewed-by: Shahbaz Youssefi <syoussefi@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 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
//
// 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.
//
// CLEvent.cpp: Implements the cl::Event class.
//
#ifdef UNSAFE_BUFFERS_BUILD
# pragma allow_unsafe_buffers
#endif
#include "libANGLE/CLEvent.h"
#include "libANGLE/CLCommandQueue.h"
#include "libANGLE/CLContext.h"
#include "libANGLE/cl_utils.h"
#include <cstring>
namespace cl
{
angle::Result Event::setUserEventStatus(cl_int executionStatus)
{
// we need to retain in the case of situations where any waiting thread(s) on clWaitForEvents
// get signaled here from backend/mImpl call before we completely finish this routine.
cl::EventPtr implicitRetain(this);
ANGLE_TRY(mImpl->setUserEventStatus(executionStatus));
mStatusWasChanged = true;
return angle::Result::Continue;
}
angle::Result Event::getInfo(EventInfo name,
size_t valueSize,
void *value,
size_t *valueSizeRet) const
{
cl_int execStatus = 0;
cl_uint valUInt = 0u;
void *valPointer = nullptr;
const void *copyValue = nullptr;
size_t copySize = 0u;
switch (name)
{
case EventInfo::CommandQueue:
valPointer = CommandQueue::CastNative(mCommandQueue.get());
copyValue = &valPointer;
copySize = sizeof(valPointer);
break;
case EventInfo::CommandType:
copyValue = &mCommandType;
copySize = sizeof(mCommandType);
break;
case EventInfo::ReferenceCount:
valUInt = getRefCount();
copyValue = &valUInt;
copySize = sizeof(valUInt);
break;
case EventInfo::CommandExecutionStatus:
{
ANGLE_TRY(mImpl->getCommandExecutionStatus(execStatus));
copyValue = &execStatus;
copySize = sizeof(execStatus);
break;
}
case EventInfo::Context:
valPointer = mContext->getNative();
copyValue = &valPointer;
copySize = sizeof(valPointer);
break;
default:
ANGLE_CL_RETURN_ERROR(CL_INVALID_VALUE);
}
if (value != nullptr)
{
// CL_INVALID_VALUE if size in bytes specified by param_value_size is < size of return type
// as described in the Event Queries table and param_value is not NULL.
if (valueSize < copySize)
{
ANGLE_CL_RETURN_ERROR(CL_INVALID_VALUE);
}
if (copyValue != nullptr)
{
std::memcpy(value, copyValue, copySize);
}
}
if (valueSizeRet != nullptr)
{
*valueSizeRet = copySize;
}
return angle::Result::Continue;
}
angle::Result Event::setCallback(cl_int commandExecCallbackType, EventCB pfnNotify, void *userData)
{
auto callbacks = mCallbacks.synchronize();
// Spec mentions that the callback will be called when the execution status of the event is
// equal to past the status specified by commandExecCallbackType
cl_int currentStatus;
ANGLE_TRY(mImpl->getCommandExecutionStatus(currentStatus));
if (currentStatus <= commandExecCallbackType)
{
pfnNotify(this, commandExecCallbackType, userData);
return angle::Result::Continue;
}
// Only when required register a single callback with the back end for each callback type.
if ((*callbacks)[commandExecCallbackType].empty())
{
ANGLE_TRY(mImpl->setCallback(*this, commandExecCallbackType));
// This event has to be retained until the callback is called.
retain();
}
(*callbacks)[commandExecCallbackType].emplace_back(pfnNotify, userData);
return angle::Result::Continue;
}
angle::Result Event::getProfilingInfo(ProfilingInfo name,
size_t valueSize,
void *value,
size_t *valueSizeRet)
{
return mImpl->getProfilingInfo(name, valueSize, value, valueSizeRet);
}
angle::Result Event::initBackend(const rx::CLEventImpl::CreateFunc &createFunc)
{
if (isUserEvent())
{
return mContext->getImpl().createUserEvent(*this, &mImpl);
}
else
{
// execute the create func lambda that was passed into this method
mImpl = createFunc(*this);
if (mImpl == nullptr)
{
ANGLE_CL_RETURN_ERROR(CL_OUT_OF_HOST_MEMORY);
}
}
return angle::Result::Continue;
}
Event::~Event() = default;
void Event::callback(cl_int commandStatus)
{
ASSERT(commandStatus >= 0 && commandStatus < 3);
const Callbacks callbacks = std::move(mCallbacks->at(commandStatus));
for (const CallbackData &data : callbacks)
{
data.first(this, commandStatus, data.second);
}
// This event can be released after the callback was called.
if (release())
{
delete this;
}
}
EventPtrs Event::Cast(cl_uint numEvents, const cl_event *eventList)
{
EventPtrs events;
events.reserve(numEvents);
while (numEvents-- != 0u)
{
events.emplace_back(&(*eventList++)->cast<Event>());
}
return events;
}
Event::Event(Context &context) : mContext(&context), mCommandType(CL_COMMAND_USER), mImpl(nullptr)
{}
Event::Event(CommandQueue &queue, cl_command_type commandType)
: mContext(&queue.getContext()),
mCommandQueue(&queue),
mCommandType(commandType),
mImpl(nullptr)
{}
} // namespace cl