LCOV - code coverage report
Current view: top level - xenolith/core - XLCoreFrameQueue.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 5 5 100.0 %
Date: 2024-05-12 00:16:13 Functions: 5 5 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_XLCOREFRAMEQUEUE_H_
      24             : #define XENOLITH_CORE_XLCOREFRAMEQUEUE_H_
      25             : 
      26             : #include "XLCoreQueueData.h"
      27             : #include "XLCoreImageStorage.h"
      28             : 
      29             : namespace STAPPLER_VERSIONIZED stappler::xenolith::core {
      30             : 
      31             : struct FramePassData;
      32             : struct FrameAttachmentData;
      33             : 
      34             : struct FrameSyncAttachment {
      35             :         const AttachmentHandle *attachment;
      36             :         Rc<Semaphore> semaphore;
      37             :         ImageStorage *image = nullptr;
      38             :         PipelineStage stages = PipelineStage::None;
      39             : };
      40             : 
      41             : struct FramePassData {
      42             :         FrameRenderPassState state = FrameRenderPassState::Initial;
      43             :         Rc<QueuePassHandle> handle;
      44             :         const QueuePassData *data = nullptr;
      45             : 
      46             :         Vector<Pair<const AttachmentPassData *, FrameAttachmentData *>> attachments;
      47             :         HashMap<const AttachmentData *, FrameAttachmentData *> attachmentMap;
      48             : 
      49             :         HashMap<FrameRenderPassState, Vector<FramePassData *>> waiters;
      50             : 
      51             :         mutable Vector<FrameSyncAttachment> waitSync;
      52             : 
      53             :         Rc<Framebuffer> framebuffer;
      54             :         bool waitForResult = false;
      55             : 
      56             :         uint64_t submitTime = 0;
      57             : };
      58             : 
      59             : struct FrameAttachmentData {
      60             :         FrameAttachmentState state = FrameAttachmentState::Initial;
      61             :         Rc<AttachmentHandle> handle;
      62             :         ImageInfoData info;
      63             : 
      64             :         Vector<FramePassData *> passes;
      65             : 
      66             :         // state of final RenderPass, on which Attachment resources can be released
      67             :         FrameRenderPassState final;
      68             : 
      69             :         Rc<ImageStorage> image;
      70             :         bool waitForResult = false;
      71             : };
      72             : 
      73             : struct FrameSyncImage {
      74             :         const AttachmentHandle *attachment;
      75             :         ImageStorage *image = nullptr;
      76             :         AttachmentLayout newLayout = AttachmentLayout::Undefined;
      77             : };
      78             : 
      79             : struct FrameSync : public Ref {
      80             :         Vector<FrameSyncAttachment> waitAttachments;
      81             :         Vector<FrameSyncAttachment> signalAttachments;
      82             :         Vector<FrameSyncImage> images;
      83             : };
      84             : 
      85             : class FrameQueue final : public Ref {
      86             : public:
      87             :         virtual ~FrameQueue();
      88             : 
      89             :         bool init(const Rc<PoolRef> &, const Rc<Queue> &, FrameHandle &);
      90             : 
      91             :         bool setup();
      92             :         void update();
      93             :         void invalidate();
      94             : 
      95       40541 :         bool isFinalized() const { return _finalized; }
      96             : 
      97      900771 :         const Rc<FrameHandle> &getFrame() const { return _frame; }
      98             :         const Rc<PoolRef> &getPool() const { return _pool; }
      99      238579 :         const Rc<Queue> &getQueue() const { return _queue; }
     100             :         Loop *getLoop() const;
     101             : 
     102             :         const HashMap<const QueuePassData *, FramePassData> &getRenderPasses() const { return _renderPasses; }
     103       28435 :         const HashMap<const AttachmentData *, FrameAttachmentData> &getAttachments() const { return _attachments; }
     104       28419 :         uint64_t getSubmissionTime() const { return _submissionTime; }
     105             : 
     106             :         const FrameAttachmentData *getAttachment(const AttachmentData *) const;
     107             :         const FramePassData *getRenderPass(const QueuePassData *) const;
     108             : 
     109             : protected:
     110             :         bool isResourcePending(const FrameAttachmentData &);
     111             :         void waitForResource(const FrameAttachmentData &, Function<void(bool)> &&);
     112             : 
     113             :         bool isResourcePending(const FramePassData &);
     114             :         void waitForResource(const FramePassData &, Function<void()> &&);
     115             : 
     116             :         void onAttachmentSetupComplete(FrameAttachmentData &);
     117             :         void onAttachmentInput(FrameAttachmentData &);
     118             :         void onAttachmentAcquire(FrameAttachmentData &);
     119             :         void onAttachmentRelease(FrameAttachmentData &);
     120             : 
     121             :         bool isRenderPassReady(const FramePassData &) const;
     122             :         bool isRenderPassReadyForState(const FramePassData &, FrameRenderPassState) const;
     123             :         void updateRenderPassState(FramePassData &, FrameRenderPassState);
     124             : 
     125             :         void onRenderPassReady(FramePassData &);
     126             :         void onRenderPassOwned(FramePassData &);
     127             :         void onRenderPassResourcesAcquired(FramePassData &);
     128             :         void onRenderPassPrepared(FramePassData &);
     129             :         void onRenderPassSubmission(FramePassData &);
     130             :         void onRenderPassSubmitted(FramePassData &);
     131             :         void onRenderPassComplete(FramePassData &);
     132             : 
     133             :         Rc<FrameSync> makeRenderPassSync(FramePassData &) const;
     134             :         PipelineStage getWaitStageForAttachment(FramePassData &data, const AttachmentHandle *handle) const;
     135             : 
     136             :         void onComplete();
     137             :         void onFinalized();
     138             : 
     139             :         void invalidate(FrameAttachmentData &);
     140             :         void invalidate(FramePassData &);
     141             : 
     142             :         void tryReleaseFrame();
     143             : 
     144             :         void finalizeAttachment(FrameAttachmentData &);
     145             : 
     146             :         Rc<PoolRef> _pool;
     147             :         Rc<Queue> _queue;
     148             :         Rc<FrameHandle> _frame;
     149             :         Loop *_loop = nullptr;
     150             :         uint64_t _order = 0;
     151             :         bool _finalized = false;
     152             :         bool _success = false;
     153             :         bool _invalidated = false;
     154             : 
     155             :         HashMap<const QueuePassData *, FramePassData> _renderPasses;
     156             :         HashMap<const AttachmentData *, FrameAttachmentData> _attachments;
     157             : 
     158             :         HashSet<FramePassData *> _renderPassesInitial;
     159             :         HashSet<FramePassData *> _renderPassesPrepared;
     160             :         HashSet<FrameAttachmentData *> _attachmentsInitial;
     161             : 
     162             :         std::forward_list<Rc<Ref>> _autorelease;
     163             :         uint32_t _renderPassSubmitted = 0;
     164             :         uint32_t _renderPassCompleted = 0;
     165             : 
     166             :         uint32_t _finalizedObjects = 0;
     167             :         uint64_t _submissionTime = 0;
     168             : 
     169             :         Vector<Pair<FramePassData *, FrameRenderPassState>> _awaitPasses;
     170             : };
     171             : 
     172             : }
     173             : 
     174             : #endif /* XENOLITH_CORE_XLCOREFRAMEQUEUE_H_ */

Generated by: LCOV version 1.14