1 // 2 // Copyright 2021 The ANGLE Project Authors. All rights reserved. 3 // Use of this source code is governed by a BSD-style license that can be 4 // found in the LICENSE file. 5 // 6 // CLEventVk.h: Defines the class interface for CLEventVk, implementing CLEventImpl. 7 8 #ifndef LIBANGLE_RENDERER_VULKAN_CLEVENTVK_H_ 9 #define LIBANGLE_RENDERER_VULKAN_CLEVENTVK_H_ 10 11 #include <condition_variable> 12 #include <mutex> 13 14 #include "libANGLE/renderer/vulkan/CLContextVk.h" 15 #include "libANGLE/renderer/vulkan/cl_types.h" 16 #include "libANGLE/renderer/vulkan/vk_resource.h" 17 18 #include "libANGLE/renderer/CLEventImpl.h" 19 20 #include "libANGLE/CLCommandQueue.h" 21 #include "libANGLE/CLContext.h" 22 #include "libANGLE/CLEvent.h" 23 24 namespace rx 25 { 26 27 class CLEventVk : public CLEventImpl 28 { 29 public: 30 CLEventVk(const cl::Event &event, 31 const cl::ExecutionStatus initialStatus, 32 const QueueSerial eventSerial); 33 ~CLEventVk() override; 34 getCommandType()35 cl_int getCommandType() const { return mEvent.getCommandType(); } isUserEvent()36 bool isUserEvent() const { return mEvent.isUserEvent(); } getFrontendObject()37 cl::Event &getFrontendObject() { return const_cast<cl::Event &>(mEvent); } getQueueSerial()38 const QueueSerial &getQueueSerial() { return mQueueSerial; } usedByCommandBuffer(const QueueSerial & commandBufferQueueSerial)39 bool usedByCommandBuffer(const QueueSerial &commandBufferQueueSerial) const 40 { 41 ASSERT(commandBufferQueueSerial.valid()); 42 return mQueueSerial == commandBufferQueueSerial; 43 } 44 45 angle::Result onEventCreate() override; 46 47 angle::Result getCommandExecutionStatus(cl_int &executionStatus) override; 48 49 angle::Result setUserEventStatus(cl_int executionStatus) override; 50 51 angle::Result setCallback(cl::Event &event, cl_int commandExecCallbackType) override; 52 53 angle::Result getProfilingInfo(cl::ProfilingInfo name, 54 size_t valueSize, 55 void *value, 56 size_t *valueSizeRet) override; 57 58 angle::Result waitForUserEventStatus(); 59 angle::Result setStatusAndExecuteCallback(cl_int status); 60 angle::Result setTimestamp(cl_int status); 61 62 private: 63 std::mutex mUserEventMutex; 64 angle::SynchronizedValue<cl_int> mStatus; 65 std::condition_variable mUserEventCondition; 66 angle::SynchronizedValue<cl::EventStatusMap<bool>> mHaveCallbacks; 67 68 // Event profiling timestamps 69 struct ProfilingTimestamps 70 { 71 cl_ulong commandEndTS; 72 cl_ulong commandStartTS; 73 cl_ulong commandQueuedTS; 74 cl_ulong commandSubmitTS; 75 cl_ulong commandCompleteTS; 76 }; 77 angle::SynchronizedValue<ProfilingTimestamps> mProfilingTimestamps; 78 const QueueSerial mQueueSerial; 79 }; 80 81 } // namespace rx 82 83 #endif // LIBANGLE_RENDERER_VULKAN_CLEVENTVK_H_ 84