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 : #include "XLVkAttachment.h"
25 : #include "XLVkDevice.h"
26 : #include "XLVkTextureSet.h"
27 : #include "XLCoreFrameQueue.h"
28 :
29 : namespace STAPPLER_VERSIONIZED stappler::xenolith::vk {
30 :
31 904532 : BufferAttachmentHandle::~BufferAttachmentHandle() { }
32 :
33 1561319 : bool BufferAttachmentHandle::writeDescriptor(const core::QueuePassHandle &, DescriptorBufferInfo &info) {
34 1561319 : if (info.index < _buffers.size()) {
35 1561319 : auto &v = _buffers[info.index];
36 1561319 : info.buffer = v.buffer;
37 1561319 : info.offset = v.offset;
38 1561319 : info.range = v.size;
39 1561319 : return true;
40 : }
41 0 : return false;
42 : }
43 :
44 1654776 : bool BufferAttachmentHandle::isDescriptorDirty(const PassHandle &, const PipelineDescriptor &, uint32_t idx, bool isExternal) const {
45 1654776 : if (idx < _buffers.size()) {
46 1561319 : return _buffers[idx].dirty;
47 : }
48 93457 : return false;
49 : }
50 :
51 0 : void BufferAttachmentHandle::clearBufferViews() {
52 0 : _buffers.clear();
53 0 : }
54 1856698 : void BufferAttachmentHandle::addBufferView(Buffer *buffer, VkDeviceSize offset, VkDeviceSize size, bool dirty) {
55 1856698 : addBufferView(Rc<Buffer>(buffer), offset, size, dirty);
56 1856695 : }
57 1856725 : void BufferAttachmentHandle::addBufferView(Rc<Buffer> &&buffer, VkDeviceSize offset, VkDeviceSize size, bool dirty) {
58 1856725 : auto s = buffer->getSize();
59 1856725 : _buffers.emplace_back(BufferView{move(buffer), offset, min(VkDeviceSize(s - offset), size), dirty});
60 1856717 : }
61 :
62 :
63 428421 : auto BufferAttachment::makeFrameHandle(const FrameQueue &queue) -> Rc<AttachmentHandle> {
64 428421 : if (_frameHandleCallback) {
65 50421 : auto ret = _frameHandleCallback(*this, queue);
66 50421 : if (isStatic()) {
67 0 : if (auto b = dynamic_cast<BufferAttachmentHandle *>(ret.get())) {
68 0 : auto statics = getStaticBuffers();
69 0 : for (auto &it : statics) {
70 0 : b->addBufferView(static_cast<Buffer *>(it));
71 : }
72 0 : }
73 : }
74 50421 : return ret;
75 50421 : } else {
76 378000 : auto ret = Rc<BufferAttachmentHandle>::create(this, queue);
77 378000 : if (isStatic()) {
78 176400 : auto statics = getStaticBuffers();
79 655200 : for (auto &it : statics) {
80 478800 : ret->addBufferView(static_cast<Buffer *>(it));
81 : }
82 176400 : }
83 378000 : return ret;
84 378000 : }
85 : }
86 :
87 28635 : auto ImageAttachment::makeFrameHandle(const FrameQueue &queue) -> Rc<AttachmentHandle> {
88 28635 : if (_frameHandleCallback) {
89 0 : return _frameHandleCallback(*this, queue);
90 : } else {
91 57270 : return Rc<ImageAttachmentHandle>::create(this, queue);
92 : }
93 : }
94 :
95 47559 : const Rc<core::ImageStorage> &ImageAttachmentHandle::getImage() const {
96 47559 : return _queueData->image;
97 : }
98 :
99 28466 : bool ImageAttachmentHandle::writeDescriptor(const core::QueuePassHandle &queue, DescriptorImageInfo &info) {
100 28466 : auto image = _queueData->image;
101 28514 : if (!image) {
102 0 : return false;
103 : }
104 :
105 28499 : bool allowSwizzle = (info.descriptor->type == core::DescriptorType::SampledImage);
106 28499 : ImageViewInfo viewInfo(image->getInfo());
107 28488 : viewInfo.setup(info.descriptor->attachment->colorMode, allowSwizzle);
108 28494 : if (auto view = image->getView(viewInfo)) {
109 28515 : info.layout = VkImageLayout(info.descriptor->layout);
110 28515 : info.imageView = static_cast<ImageView *>(view.get());
111 28502 : return true;
112 28502 : }
113 :
114 0 : return false;
115 28503 : }
116 :
117 28531 : bool ImageAttachmentHandle::isDescriptorDirty(const PassHandle &, const PipelineDescriptor &d, uint32_t, bool isExternal) const {
118 28531 : return getImage();
119 : }
120 :
121 : }
|