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_XLCOREQUEUEPASS_H_ 24 : #define XENOLITH_CORE_XLCOREQUEUEPASS_H_ 25 : 26 : #include "XLCoreObject.h" 27 : #include "XLCoreFrameQueue.h" 28 : 29 : namespace STAPPLER_VERSIONIZED stappler::xenolith::core { 30 : 31 : class QueuePass : public NamedRef { 32 : public: 33 : using Queue = core::Queue; 34 : using FrameQueue = core::FrameQueue; 35 : using RenderOrdering = core::RenderOrdering; 36 : using QueuePassBuilder = core::QueuePassBuilder; 37 : using QueuePassHandle = core::QueuePassHandle; 38 : using PassType = core::PassType; 39 : using AttachmentData = core::AttachmentData; 40 : 41 : using FrameHandleCallback = Function<Rc<QueuePassHandle>(QueuePass &, const FrameQueue &)>; 42 : 43 : virtual ~QueuePass(); 44 : 45 : virtual bool init(QueuePassBuilder &); 46 : virtual void invalidate(); 47 : 48 : virtual StringView getName() const override; 49 : virtual RenderOrdering getOrdering() const; 50 : virtual size_t getSubpassCount() const; 51 : virtual PassType getType() const; 52 : 53 : virtual Rc<QueuePassHandle> makeFrameHandle(const FrameQueue &); 54 : 55 : void setFrameHandleCallback(FrameHandleCallback &&); 56 : 57 : const Rc<FrameQueue> &getOwner() const { return _owner; } 58 : bool acquireForFrame(FrameQueue &, Function<void(bool)> &&onAcquired); 59 : bool releaseForFrame(FrameQueue &); 60 : 61 260829 : const QueuePassData *getData() const { return _data; } 62 : 63 : protected: 64 : friend class core::Queue; 65 : 66 : // called before compilation 67 : virtual void prepare(Device &); 68 : 69 : struct FrameQueueWaiter { 70 : Rc<FrameQueue> queue; 71 : Function<void(bool)> acquired; 72 : }; 73 : 74 : Rc<FrameQueue> _owner; 75 : FrameQueueWaiter _next; 76 : Function<Extent2(const FrameQueue &)> _frameSizeCallback; 77 : FrameHandleCallback _frameHandleCallback; 78 : const QueuePassData *_data = nullptr; 79 : }; 80 : 81 : class QueuePassHandle : public NamedRef { 82 : public: 83 : using QueuePass = core::QueuePass; 84 : using FrameHandle = core::FrameHandle; 85 : using FrameQueue = core::FrameQueue; 86 : using FrameSync = core::FrameSync; 87 : using RenderOrdering = core::RenderOrdering; 88 : 89 : virtual ~QueuePassHandle(); 90 : 91 : virtual bool init(QueuePass &, const FrameQueue &); 92 : virtual void setQueueData(FramePassData &); 93 : virtual const FramePassData *getQueueData() const; 94 : 95 : virtual StringView getName() const override; 96 : 97 1724868 : virtual const QueuePassData *getData() const { return _data; } 98 395079 : virtual const Rc<QueuePass> &getQueuePass() const { return _queuePass; } 99 : virtual const Rc<Framebuffer> &getFramebuffer() const; 100 : 101 : virtual bool isAvailable(const FrameQueue &) const; 102 395079 : virtual bool isAsync() const { return _isAsync; } 103 : 104 : virtual bool isSubmitted() const; 105 : virtual bool isCompleted() const; 106 : 107 : virtual bool isFramebufferRequired() const; 108 : 109 : // Run data preparation process, that do not require queuing 110 : // returns true if 'prepare' completes immediately (either successful or not) 111 : // returns false if 'prepare' run some subroutines, and we should wait for them 112 : // To indicate success, call callback with 'true'. For failure - with 'false' 113 : // To indicate immediate failure, call callback with 'false', then return true; 114 : virtual bool prepare(FrameQueue &, Function<void(bool)> &&); 115 : 116 : // Run queue submission process 117 : // If submission were successful, you should call onSubmited callback with 'true' 118 : // If submission failed, call onSubmited with 'false' 119 : // If submission were successful, onComplete should be called when execution completes 120 : virtual void submit(FrameQueue &, Rc<FrameSync> &&, Function<void(bool)> &&onSubmited, Function<void(bool)> &&onComplete); 121 : 122 : // after submit 123 : virtual void finalize(FrameQueue &, bool successful); 124 : 125 : virtual AttachmentHandle *getAttachmentHandle(const AttachmentData *) const; 126 : 127 : void autorelease(Ref *) const; 128 : 129 : const AttachmentPassData *getAttachemntData(const AttachmentData *) const; 130 : 131 : protected: 132 : virtual void prepareSubpasses(FrameQueue &); 133 : 134 : bool _isAsync = false; // async passes can be submitted before previous frame submits all passes 135 : Rc<QueuePass> _queuePass; 136 : const QueuePassData *_data = nullptr; 137 : FramePassData *_queueData = nullptr; 138 : 139 : mutable Mutex _autoreleaseMutex; 140 : mutable Vector<Rc<Ref>> _autorelease; 141 : }; 142 : 143 : } 144 : 145 : #endif /* XENOLITH_CORE_XLCOREQUEUEPASS_H_ */