Line data Source code
1 : /** 2 : Copyright (c) 2021 Roman Katuntsev <sbkarr@stappler.org> 3 : Copyright (c) 2023 Stappler LLC <admin@stappler.dev> 4 : 5 : Permission is hereby granted, free of charge, to any person obtaining a copy 6 : of this software and associated documentation files (the "Software"), to deal 7 : in the Software without restriction, including without limitation the rights 8 : to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 : copies of the Software, and to permit persons to whom the Software is 10 : furnished to do so, subject to the following conditions: 11 : 12 : The above copyright notice and this permission notice shall be included in 13 : all copies or substantial portions of the Software. 14 : 15 : THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 : IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 : FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 : AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 : LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 : OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 : THE SOFTWARE. 22 : **/ 23 : 24 : #ifndef XENOLITH_BACKEND_VK_XLVKRENDERPASSIMPL_H_ 25 : #define XENOLITH_BACKEND_VK_XLVKRENDERPASSIMPL_H_ 26 : 27 : #include "XLVk.h" 28 : #include "XLVkDeviceQueue.h" 29 : #include "XLCoreQueuePass.h" 30 : #include "XLCoreObject.h" 31 : 32 : namespace STAPPLER_VERSIONIZED stappler::xenolith::vk { 33 : 34 : class Device; 35 : class RenderPass; 36 : class QueuePassHandle; 37 : 38 : struct DescriptorData { 39 : core::ObjectHandle object; 40 : Rc<Ref> data; 41 : }; 42 : 43 : struct DescriptorBinding { 44 : VkDescriptorType type; 45 : Vector<DescriptorData> data; 46 : 47 : ~DescriptorBinding(); 48 : 49 : DescriptorBinding(VkDescriptorType, uint32_t count); 50 : 51 : Rc<Ref> write(uint32_t, DescriptorBufferInfo &&); 52 : Rc<Ref> write(uint32_t, DescriptorImageInfo &&); 53 : Rc<Ref> write(uint32_t, DescriptorBufferViewInfo &&); 54 : }; 55 : 56 : struct DescriptorSet : public Ref { 57 : VkDescriptorSet set; 58 : Vector<DescriptorBinding> bindings; 59 : }; 60 : 61 : class Framebuffer : public core::Framebuffer { 62 : public: 63 234 : virtual ~Framebuffer() { } 64 : 65 : bool init(Device &dev, RenderPass *renderPass, SpanView<Rc<core::ImageView>> imageViews); 66 : 67 9517 : VkFramebuffer getFramebuffer() const { return _framebuffer; } 68 : 69 : protected: 70 : using core::Framebuffer::init; 71 : 72 : VkFramebuffer _framebuffer = VK_NULL_HANDLE; 73 : }; 74 : 75 : class RenderPass : public core::RenderPass { 76 : public: 77 : struct LayoutData { 78 : VkPipelineLayout layout = VK_NULL_HANDLE; 79 : VkDescriptorPool descriptorPool = VK_NULL_HANDLE; 80 : Vector<VkDescriptorSetLayout> layouts; 81 : Vector<Rc<DescriptorSet>> sets; 82 : }; 83 : 84 : struct Data { 85 : VkRenderPass renderPass = VK_NULL_HANDLE; 86 : VkRenderPass renderPassAlternative = VK_NULL_HANDLE; 87 : Vector<LayoutData> layouts; 88 : 89 : bool cleanup(Device &dev); 90 : }; 91 : 92 714 : virtual ~RenderPass() { } 93 : 94 : virtual bool init(Device &dev, QueuePassData &); 95 : 96 : VkRenderPass getRenderPass(bool alt = false) const; 97 295600 : VkPipelineLayout getPipelineLayout(uint32_t idx) const { return _data->layouts[idx].layout; } 98 240989 : const Vector<Rc<DescriptorSet>> &getDescriptorSets(uint32_t idx) const { return _data->layouts[idx].sets; } 99 9517 : const Vector<VkClearValue> &getClearValues() const { return _clearValues; } 100 : 101 : // if async is true - update descriptors with updateAfterBind flag 102 : // false - without updateAfterBindFlag 103 : virtual bool writeDescriptors(const QueuePassHandle &, uint32_t layoutIndex, bool async) const; 104 : 105 : virtual void perform(const QueuePassHandle &, CommandBuffer &buf, const Callback<void()> &, bool writeBarriers = false); 106 : 107 : protected: 108 : using core::RenderPass::init; 109 : 110 : bool initGraphicsPass(Device &dev, QueuePassData &); 111 : bool initComputePass(Device &dev, QueuePassData &); 112 : bool initTransferPass(Device &dev, QueuePassData &); 113 : bool initGenericPass(Device &dev, QueuePassData &); 114 : 115 : bool initDescriptors(Device &dev, const QueuePassData &, Data &); 116 : bool initDescriptors(Device &dev, const core::PipelineLayoutData &, Data &, LayoutData &); 117 : 118 : Vector<VkAttachmentDescription> _attachmentDescriptions; 119 : Vector<VkAttachmentDescription> _attachmentDescriptionsAlternative; 120 : Vector<VkAttachmentReference> _attachmentReferences; 121 : Vector<uint32_t> _preservedAttachments; 122 : Vector<VkSubpassDependency> _subpassDependencies; 123 : Vector<VkSubpassDescription> _subpasses; 124 : Set<const core::AttachmentPassData *> _variableAttachments; 125 : Data *_data = nullptr; 126 : 127 : Vector<VkClearValue> _clearValues; 128 : }; 129 : 130 : } 131 : 132 : #endif /* XENOLITH_BACKEND_VK_XLVKRENDERPASSIMPL_H_ */