LCOV - code coverage report
Current view: top level - xenolith/core - XLCoreLoop.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 2 2 100.0 %
Date: 2024-05-12 00:16:13 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /**
       2             :  Copyright (c) 2023 Stappler LLC <admin@stappler.dev>
       3             : 
       4             :  Permission is hereby granted, free of charge, to any person obtaining a copy
       5             :  of this software and associated documentation files (the "Software"), to deal
       6             :  in the Software without restriction, including without limitation the rights
       7             :  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
       8             :  copies of the Software, and to permit persons to whom the Software is
       9             :  furnished to do so, subject to the following conditions:
      10             : 
      11             :  The above copyright notice and this permission notice shall be included in
      12             :  all copies or substantial portions of the Software.
      13             : 
      14             :  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
      15             :  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      16             :  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
      17             :  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      18             :  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
      19             :  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
      20             :  THE SOFTWARE.
      21             :  **/
      22             : 
      23             : #ifndef XENOLITH_CORE_XLCORELOOP_H_
      24             : #define XENOLITH_CORE_XLCORELOOP_H_
      25             : 
      26             : #include "XLCoreQueueData.h"
      27             : #include "XLCoreAttachment.h"
      28             : #include "XLCoreInstance.h"
      29             : #include "XLCoreMaterial.h"
      30             : 
      31             : #include "SPThread.h"
      32             : #include "SPThreadTaskQueue.h"
      33             : 
      34             : namespace STAPPLER_VERSIONIZED stappler::xenolith::core {
      35             : 
      36             : class Loop;
      37             : class Device;
      38             : 
      39             : struct LoopInfo {
      40             :         uint32_t deviceIdx = core::Instance::DefaultDevice;
      41             :         uint32_t threadsCount = 2;
      42             :         Function<void(const Loop &, const Device &)> onDeviceStarted;
      43             :         Function<void(const Loop &, const Device &)> onDeviceFinalized;
      44             :         Rc<Ref> platformData;
      45             : };
      46             : 
      47             : class Loop : public thread::ThreadInterface<Interface> {
      48             : public:
      49             :         using FrameCache = core::FrameCache;
      50             :         using FrameRequest = core::FrameRequest;
      51             :         using ImageStorage = core::ImageStorage;
      52             :         using Queue = core::Queue;
      53             :         using FrameHandle = core::FrameHandle;
      54             :         using PassData = core::QueuePassData;
      55             :         using ImageAttachment = core::ImageAttachment;
      56             :         using AttachmentHandle = core::AttachmentHandle;
      57             :         using DependencyEvent = core::DependencyEvent;
      58             :         using LoopInfo = core::LoopInfo;
      59             : 
      60             :         static constexpr uint32_t LoopThreadId = 2;
      61             : 
      62             :         virtual ~Loop();
      63             : 
      64             :         Loop();
      65             : 
      66             :         virtual bool init(Instance *gl, LoopInfo &&);
      67             :         virtual void waitRinning() = 0;
      68             :         virtual void cancel() = 0;
      69             : 
      70             :         virtual bool isRunning() const = 0;
      71             : 
      72          10 :         const Rc<Instance> &getGlInstance() const { return _glInstance; }
      73        4880 :         const Rc<FrameCache> &getFrameCache() const { return _frameCache; }
      74             : 
      75             :         // in preload mode, resource will be prepared for transfer immediately in caller's thread
      76             :         // (device will allocate transfer buffer then fill it with resource data)
      77             :         // do not use reload with main thread
      78             :         virtual void compileResource(Rc<Resource> &&req, Function<void(bool)> &&, bool preload = false) const = 0;
      79             :         virtual void compileQueue(const Rc<Queue> &req, Function<void(bool)> && = nullptr) const = 0;
      80             : 
      81             :         virtual void compileMaterials(Rc<MaterialInputData> &&req, const Vector<Rc<DependencyEvent>> & = Vector<Rc<DependencyEvent>>()) const = 0;
      82             :         virtual void compileImage(const Rc<DynamicImage> &, Function<void(bool)> && = nullptr) const = 0;
      83             : 
      84             :         // run frame with RenderQueue
      85             :         virtual void runRenderQueue(Rc<FrameRequest> &&req, uint64_t gen = 0, Function<void(bool)> && = nullptr) = 0;
      86             : 
      87             :         // callback should return true to end spinning
      88             :         virtual void schedule(Function<bool(Loop &)> &&, StringView) = 0;
      89             :         virtual void schedule(Function<bool(Loop &)> &&, uint64_t, StringView) = 0;
      90             : 
      91             :         virtual void performInQueue(Rc<thread::Task> &&) const = 0;
      92             :         virtual void performInQueue(Function<void()> &&func, Ref *target = nullptr) const = 0;
      93             : 
      94             :         virtual void performOnGlThread(Function<void()> &&func, Ref *target = nullptr, bool immediate = false) const = 0;
      95             : 
      96             :         virtual bool isOnGlThread() const = 0;
      97             : 
      98             :         virtual Rc<FrameHandle> makeFrame(Rc<FrameRequest> &&, uint64_t gen) = 0;
      99             : 
     100             :         virtual Rc<Framebuffer> acquireFramebuffer(const PassData *, SpanView<Rc<ImageView>>) = 0;
     101             :         virtual void releaseFramebuffer(Rc<Framebuffer> &&) = 0;
     102             : 
     103             :         virtual Rc<ImageStorage> acquireImage(const ImageAttachment *, const AttachmentHandle *, const ImageInfoData &) = 0;
     104             :         virtual void releaseImage(Rc<ImageStorage> &&) = 0;
     105             : 
     106             :         virtual Rc<Semaphore> makeSemaphore() = 0;
     107             : 
     108             :         virtual const Vector<ImageFormat> &getSupportedDepthStencilFormat() const = 0;
     109             : 
     110             :         virtual void signalDependencies(const Vector<Rc<DependencyEvent>> &, Queue *, bool success) = 0;
     111             :         virtual void waitForDependencies(const Vector<Rc<DependencyEvent>> &, Function<void(bool)> &&) = 0;
     112             : 
     113             :         virtual void wakeup() = 0;
     114             :         virtual void waitIdle() = 0;
     115             : 
     116             :         virtual void captureImage(Function<void(const ImageInfoData &info, BytesView view)> &&cb, const Rc<ImageObject> &image, AttachmentLayout l) = 0;
     117             :         virtual void captureBuffer(Function<void(const BufferInfo &info, BytesView view)> &&cb, const Rc<BufferObject> &) = 0;
     118             : 
     119             : protected:
     120             : #if SP_REF_DEBUG
     121             :         virtual bool isRetainTrackerEnabled() const override {
     122             :                 return true;
     123             :         }
     124             : #endif
     125             : 
     126             :         std::atomic_flag _shouldExit;
     127             :         Rc<Instance> _glInstance;
     128             :         Rc<FrameCache> _frameCache;
     129             :         LoopInfo _info;
     130             : };
     131             : 
     132             : }
     133             : 
     134             : #endif /* XENOLITH_CORE_XLCORELOOP_H_ */

Generated by: LCOV version 1.14