Warning: That file was not part of the compilation database. It may have many parsing errors.

1/****************************************************************************
2**
3** Copyright (C) 2019 The Qt Company Ltd.
4** Contact: http://www.qt.io/licensing/
5**
6** This file is part of the Qt Gui module
7**
8** $QT_BEGIN_LICENSE:LGPL3$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see http://www.qt.io/terms-conditions. For further
15** information use the contact form at http://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPLv3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or later as published by the Free
28** Software Foundation and appearing in the file LICENSE.GPL included in
29** the packaging of this file. Please review the following information to
30** ensure the GNU General Public License version 2.0 requirements will be
31** met: http://www.gnu.org/licenses/gpl-2.0.html.
32**
33** $QT_END_LICENSE$
34**
35****************************************************************************/
36
37#ifndef QRHIVULKAN_P_H
38#define QRHIVULKAN_P_H
39
40//
41// W A R N I N G
42// -------------
43//
44// This file is not part of the Qt API. It exists purely as an
45// implementation detail. This header file may change from version to
46// version without notice, or even be removed.
47//
48// We mean it.
49//
50
51#include "qrhivulkan_p.h"
52#include "qrhi_p_p.h"
53
54QT_BEGIN_NAMESPACE
55
56class QVulkanFunctions;
57class QVulkanDeviceFunctions;
58
59static const int QVK_FRAMES_IN_FLIGHT = 2;
60
61static const int QVK_DESC_SETS_PER_POOL = 128;
62static const int QVK_UNIFORM_BUFFERS_PER_POOL = 256;
63static const int QVK_COMBINED_IMAGE_SAMPLERS_PER_POOL = 256;
64static const int QVK_STORAGE_BUFFERS_PER_POOL = 128;
65static const int QVK_STORAGE_IMAGES_PER_POOL = 128;
66
67static const int QVK_MAX_ACTIVE_TIMESTAMP_PAIRS = 16;
68
69// no vk_mem_alloc.h available here, void* is good enough
70typedef void * QVkAlloc;
71typedef void * QVkAllocator;
72
73struct QVkBuffer : public QRhiBuffer
74{
75 QVkBuffer(QRhiImplementation *rhi, Type type, UsageFlags usage, int size);
76 ~QVkBuffer();
77 void release() override;
78 bool build() override;
79
80 VkBuffer buffers[QVK_FRAMES_IN_FLIGHT];
81 QVkAlloc allocations[QVK_FRAMES_IN_FLIGHT];
82 QVector<QRhiResourceUpdateBatchPrivate::DynamicBufferUpdate> pendingDynamicUpdates[QVK_FRAMES_IN_FLIGHT];
83 VkBuffer stagingBuffers[QVK_FRAMES_IN_FLIGHT];
84 QVkAlloc stagingAllocations[QVK_FRAMES_IN_FLIGHT];
85 struct UsageState {
86 VkAccessFlags access = 0;
87 VkPipelineStageFlags stage = 0;
88 };
89 UsageState usageState[QVK_FRAMES_IN_FLIGHT];
90 int lastActiveFrameSlot = -1;
91 uint generation = 0;
92 friend class QRhiVulkan;
93};
94
95struct QVkTexture;
96
97struct QVkRenderBuffer : public QRhiRenderBuffer
98{
99 QVkRenderBuffer(QRhiImplementation *rhi, Type type, const QSize &pixelSize,
100 int sampleCount, Flags flags);
101 ~QVkRenderBuffer();
102 void release() override;
103 bool build() override;
104 QRhiTexture::Format backingFormat() const override;
105
106 VkDeviceMemory memory = VK_NULL_HANDLE;
107 VkImage image = VK_NULL_HANDLE;
108 VkImageView imageView = VK_NULL_HANDLE;
109 VkSampleCountFlagBits samples;
110 QVkTexture *backingTexture = nullptr;
111 VkFormat vkformat;
112 int lastActiveFrameSlot = -1;
113 friend class QRhiVulkan;
114};
115
116struct QVkTexture : public QRhiTexture
117{
118 QVkTexture(QRhiImplementation *rhi, Format format, const QSize &pixelSize,
119 int sampleCount, Flags flags);
120 ~QVkTexture();
121 void release() override;
122 bool build() override;
123 bool buildFrom(const QRhiNativeHandles *src) override;
124 const QRhiNativeHandles *nativeHandles() override;
125
126 bool prepareBuild(QSize *adjustedSize = nullptr);
127 bool finishBuild();
128 VkImageView imageViewForLevel(int level);
129
130 VkImage image = VK_NULL_HANDLE;
131 VkImageView imageView = VK_NULL_HANDLE;
132 QVkAlloc imageAlloc = nullptr;
133 VkBuffer stagingBuffers[QVK_FRAMES_IN_FLIGHT];
134 QVkAlloc stagingAllocations[QVK_FRAMES_IN_FLIGHT];
135 VkImageView perLevelImageViews[QRhi::MAX_LEVELS];
136 bool owns = true;
137 QRhiVulkanTextureNativeHandles nativeHandlesStruct;
138 struct UsageState {
139 // no tracking of subresource layouts (some operations can keep
140 // subresources in different layouts for some time, but that does not
141 // need to be kept track of)
142 VkImageLayout layout;
143 VkAccessFlags access;
144 VkPipelineStageFlags stage;
145 };
146 UsageState usageState;
147 VkFormat vkformat;
148 uint mipLevelCount = 0;
149 VkSampleCountFlagBits samples;
150 int lastActiveFrameSlot = -1;
151 uint generation = 0;
152 friend class QRhiVulkan;
153};
154
155struct QVkSampler : public QRhiSampler
156{
157 QVkSampler(QRhiImplementation *rhi, Filter magFilter, Filter minFilter, Filter mipmapMode,
158 AddressMode u, AddressMode v);
159 ~QVkSampler();
160 void release() override;
161 bool build() override;
162
163 VkSampler sampler = VK_NULL_HANDLE;
164 int lastActiveFrameSlot = -1;
165 uint generation = 0;
166 friend class QRhiVulkan;
167};
168
169struct QVkRenderPassDescriptor : public QRhiRenderPassDescriptor
170{
171 QVkRenderPassDescriptor(QRhiImplementation *rhi);
172 ~QVkRenderPassDescriptor();
173 void release() override;
174
175 VkRenderPass rp = VK_NULL_HANDLE;
176 bool ownsRp = false;
177 int lastActiveFrameSlot = -1;
178};
179
180struct QVkRenderTargetData
181{
182 VkFramebuffer fb = VK_NULL_HANDLE;
183 QVkRenderPassDescriptor *rp = nullptr;
184 QSize pixelSize;
185 float dpr = 1;
186 int sampleCount = 1;
187 int colorAttCount = 0;
188 int dsAttCount = 0;
189 int resolveAttCount = 0;
190 static const int MAX_COLOR_ATTACHMENTS = 8;
191};
192
193struct QVkReferenceRenderTarget : public QRhiRenderTarget
194{
195 QVkReferenceRenderTarget(QRhiImplementation *rhi);
196 ~QVkReferenceRenderTarget();
197 void release() override;
198
199 QSize pixelSize() const override;
200 float devicePixelRatio() const override;
201 int sampleCount() const override;
202
203 QVkRenderTargetData d;
204};
205
206struct QVkTextureRenderTarget : public QRhiTextureRenderTarget
207{
208 QVkTextureRenderTarget(QRhiImplementation *rhi, const QRhiTextureRenderTargetDescription &desc, Flags flags);
209 ~QVkTextureRenderTarget();
210 void release() override;
211
212 QSize pixelSize() const override;
213 float devicePixelRatio() const override;
214 int sampleCount() const override;
215
216 QRhiRenderPassDescriptor *newCompatibleRenderPassDescriptor() override;
217 bool build() override;
218
219 QVkRenderTargetData d;
220 VkImageView rtv[QVkRenderTargetData::MAX_COLOR_ATTACHMENTS];
221 VkImageView resrtv[QVkRenderTargetData::MAX_COLOR_ATTACHMENTS];
222 int lastActiveFrameSlot = -1;
223 friend class QRhiVulkan;
224};
225
226struct QVkShaderResourceBindings : public QRhiShaderResourceBindings
227{
228 QVkShaderResourceBindings(QRhiImplementation *rhi);
229 ~QVkShaderResourceBindings();
230 void release() override;
231 bool build() override;
232
233 QVector<QRhiShaderResourceBinding> sortedBindings;
234 int poolIndex = -1;
235 VkDescriptorSetLayout layout = VK_NULL_HANDLE;
236 VkDescriptorSet descSets[QVK_FRAMES_IN_FLIGHT]; // multiple sets to support dynamic buffers
237 int lastActiveFrameSlot = -1;
238 uint generation = 0;
239
240 // Keep track of the generation number of each referenced QRhi* to be able
241 // to detect that the underlying descriptor set became out of date and they
242 // need to be written again with the up-to-date VkBuffer etc. objects.
243 struct BoundUniformBufferData {
244 quint64 id;
245 uint generation;
246 };
247 struct BoundSampledTextureData {
248 quint64 texId;
249 uint texGeneration;
250 quint64 samplerId;
251 uint samplerGeneration;
252 };
253 struct BoundStorageImageData {
254 quint64 id;
255 uint generation;
256 };
257 struct BoundStorageBufferData {
258 quint64 id;
259 uint generation;
260 };
261 struct BoundResourceData {
262 union {
263 BoundUniformBufferData ubuf;
264 BoundSampledTextureData stex;
265 BoundStorageImageData simage;
266 BoundStorageBufferData sbuf;
267 };
268 };
269 QVector<BoundResourceData> boundResourceData[QVK_FRAMES_IN_FLIGHT];
270
271 friend class QRhiVulkan;
272};
273
274Q_DECLARE_TYPEINFO(QVkShaderResourceBindings::BoundResourceData, Q_MOVABLE_TYPE);
275
276struct QVkGraphicsPipeline : public QRhiGraphicsPipeline
277{
278 QVkGraphicsPipeline(QRhiImplementation *rhi);
279 ~QVkGraphicsPipeline();
280 void release() override;
281 bool build() override;
282
283 VkPipelineLayout layout = VK_NULL_HANDLE;
284 VkPipeline pipeline = VK_NULL_HANDLE;
285 int lastActiveFrameSlot = -1;
286 uint generation = 0;
287 friend class QRhiVulkan;
288};
289
290struct QVkComputePipeline : public QRhiComputePipeline
291{
292 QVkComputePipeline(QRhiImplementation *rhi);
293 ~QVkComputePipeline();
294 void release() override;
295 bool build() override;
296
297 VkPipelineLayout layout = VK_NULL_HANDLE;
298 VkPipeline pipeline = VK_NULL_HANDLE;
299 int lastActiveFrameSlot = -1;
300 uint generation = 0;
301 friend class QRhiVulkan;
302};
303
304struct QVkCommandBuffer : public QRhiCommandBuffer
305{
306 QVkCommandBuffer(QRhiImplementation *rhi);
307 ~QVkCommandBuffer();
308 void release() override;
309
310 VkCommandBuffer cb = VK_NULL_HANDLE;
311 QRhiVulkanCommandBufferNativeHandles nativeHandlesStruct;
312
313 const QRhiNativeHandles *nativeHandles() {
314 nativeHandlesStruct.commandBuffer = cb;
315 return &nativeHandlesStruct;
316 }
317
318 enum PassType {
319 NoPass,
320 RenderPass,
321 ComputePass
322 };
323
324 void resetState() {
325 resetCommands();
326 recordingPass = NoPass;
327 currentTarget = nullptr;
328 resetCachedState();
329 }
330
331 void resetCachedState() {
332 currentGraphicsPipeline = nullptr;
333 currentComputePipeline = nullptr;
334 currentPipelineGeneration = 0;
335 currentGraphicsSrb = nullptr;
336 currentComputeSrb = nullptr;
337 currentSrbGeneration = 0;
338 currentDescSetSlot = -1;
339 currentIndexBuffer = VK_NULL_HANDLE;
340 currentIndexOffset = 0;
341 currentIndexFormat = VK_INDEX_TYPE_UINT16;
342 memset(currentVertexBuffers, 0, sizeof(currentVertexBuffers));
343 memset(currentVertexOffsets, 0, sizeof(currentVertexOffsets));
344 }
345
346 PassType recordingPass;
347 QRhiRenderTarget *currentTarget;
348 QRhiGraphicsPipeline *currentGraphicsPipeline;
349 QRhiComputePipeline *currentComputePipeline;
350 uint currentPipelineGeneration;
351 QRhiShaderResourceBindings *currentGraphicsSrb;
352 QRhiShaderResourceBindings *currentComputeSrb;
353 uint currentSrbGeneration;
354 int currentDescSetSlot;
355 VkBuffer currentIndexBuffer;
356 quint32 currentIndexOffset;
357 VkIndexType currentIndexFormat;
358 static const int VERTEX_INPUT_RESOURCE_SLOT_COUNT = 32;
359 VkBuffer currentVertexBuffers[VERTEX_INPUT_RESOURCE_SLOT_COUNT];
360 quint32 currentVertexOffsets[VERTEX_INPUT_RESOURCE_SLOT_COUNT];
361
362 struct Command {
363 enum Cmd {
364 CopyBuffer,
365 CopyBufferToImage,
366 CopyImage,
367 CopyImageToBuffer,
368 ImageBarrier,
369 BufferBarrier,
370 BlitImage,
371 BeginRenderPass,
372 EndRenderPass,
373 BindPipeline,
374 BindDescriptorSet,
375 BindVertexBuffer,
376 BindIndexBuffer,
377 SetViewport,
378 SetScissor,
379 SetBlendConstants,
380 SetStencilRef,
381 Draw,
382 DrawIndexed,
383 DebugMarkerBegin,
384 DebugMarkerEnd,
385 DebugMarkerInsert,
386 TransitionPassResources,
387 Dispatch
388 };
389 Cmd cmd;
390
391 union Args {
392 struct {
393 VkBuffer src;
394 VkBuffer dst;
395 VkBufferCopy desc;
396 } copyBuffer;
397 struct {
398 VkBuffer src;
399 VkImage dst;
400 VkImageLayout dstLayout;
401 int count;
402 int bufferImageCopyIndex;
403 } copyBufferToImage;
404 struct {
405 VkImage src;
406 VkImageLayout srcLayout;
407 VkImage dst;
408 VkImageLayout dstLayout;
409 VkImageCopy desc;
410 } copyImage;
411 struct {
412 VkImage src;
413 VkImageLayout srcLayout;
414 VkBuffer dst;
415 VkBufferImageCopy desc;
416 } copyImageToBuffer;
417 struct {
418 VkPipelineStageFlags srcStageMask;
419 VkPipelineStageFlags dstStageMask;
420 VkImageMemoryBarrier desc;
421 } imageBarrier;
422 struct {
423 VkPipelineStageFlags srcStageMask;
424 VkPipelineStageFlags dstStageMask;
425 VkBufferMemoryBarrier desc;
426 } bufferBarrier;
427 struct {
428 VkImage src;
429 VkImageLayout srcLayout;
430 VkImage dst;
431 VkImageLayout dstLayout;
432 VkFilter filter;
433 VkImageBlit desc;
434 } blitImage;
435 struct {
436 VkRenderPassBeginInfo desc;
437 int clearValueIndex;
438 } beginRenderPass;
439 struct {
440 } endRenderPass;
441 struct {
442 VkPipelineBindPoint bindPoint;
443 VkPipeline pipeline;
444 } bindPipeline;
445 struct {
446 VkPipelineBindPoint bindPoint;
447 VkPipelineLayout pipelineLayout;
448 VkDescriptorSet descSet;
449 int dynamicOffsetCount;
450 int dynamicOffsetIndex;
451 } bindDescriptorSet;
452 struct {
453 int startBinding;
454 int count;
455 int vertexBufferIndex;
456 int vertexBufferOffsetIndex;
457 } bindVertexBuffer;
458 struct {
459 VkBuffer buf;
460 VkDeviceSize ofs;
461 VkIndexType type;
462 } bindIndexBuffer;
463 struct {
464 VkViewport viewport;
465 } setViewport;
466 struct {
467 VkRect2D scissor;
468 } setScissor;
469 struct {
470 float c[4];
471 } setBlendConstants;
472 struct {
473 uint32_t ref;
474 } setStencilRef;
475 struct {
476 uint32_t vertexCount;
477 uint32_t instanceCount;
478 uint32_t firstVertex;
479 uint32_t firstInstance;
480 } draw;
481 struct {
482 uint32_t indexCount;
483 uint32_t instanceCount;
484 uint32_t firstIndex;
485 int32_t vertexOffset;
486 uint32_t firstInstance;
487 } drawIndexed;
488 struct {
489 VkDebugMarkerMarkerInfoEXT marker;
490 int markerNameIndex;
491 } debugMarkerBegin;
492 struct {
493 } debugMarkerEnd;
494 struct {
495 VkDebugMarkerMarkerInfoEXT marker;
496 } debugMarkerInsert;
497 struct {
498 int trackerIndex;
499 } transitionResources;
500 struct {
501 int x, y, z;
502 } dispatch;
503 } args;
504 };
505 QVector<Command> commands;
506 QVarLengthArray<QRhiPassResourceTracker, 8> passResTrackers;
507 int currentPassResTrackerIndex;
508
509 void resetCommands() {
510 commands.clear();
511 passResTrackers.clear();
512 currentPassResTrackerIndex = -1;
513 resetPools();
514 }
515
516 void resetPools() {
517 pools.clearValue.clear();
518 pools.bufferImageCopy.clear();
519 pools.dynamicOffset.clear();
520 pools.vertexBuffer.clear();
521 pools.vertexBufferOffset.clear();
522 pools.debugMarkerName.clear();
523 }
524
525 struct {
526 QVarLengthArray<VkClearValue, 4> clearValue;
527 QVarLengthArray<VkBufferImageCopy, 16> bufferImageCopy;
528 QVarLengthArray<uint32_t, 4> dynamicOffset;
529 QVarLengthArray<VkBuffer, 4> vertexBuffer;
530 QVarLengthArray<VkDeviceSize, 4> vertexBufferOffset;
531 QVarLengthArray<QByteArray, 4> debugMarkerName;
532 } pools;
533
534 friend class QRhiVulkan;
535};
536
537Q_DECLARE_TYPEINFO(QVkCommandBuffer::Command, Q_MOVABLE_TYPE);
538
539struct QVkSwapChain : public QRhiSwapChain
540{
541 QVkSwapChain(QRhiImplementation *rhi);
542 ~QVkSwapChain();
543 void release() override;
544
545 QRhiCommandBuffer *currentFrameCommandBuffer() override;
546 QRhiRenderTarget *currentFrameRenderTarget() override;
547
548 QSize surfacePixelSize() override;
549
550 QRhiRenderPassDescriptor *newCompatibleRenderPassDescriptor() override;
551 bool buildOrResize() override;
552
553 bool ensureSurface();
554
555 static const quint32 MAX_BUFFER_COUNT = 3;
556
557 QWindow *window = nullptr;
558 QSize pixelSize;
559 bool supportsReadback = false;
560 VkSwapchainKHR sc = VK_NULL_HANDLE;
561 int bufferCount = 0;
562 VkSurfaceKHR surface = VK_NULL_HANDLE;
563 VkSurfaceKHR lastConnectedSurface = VK_NULL_HANDLE;
564 VkFormat colorFormat = VK_FORMAT_B8G8R8A8_UNORM;
565 VkColorSpaceKHR colorSpace = VK_COLOR_SPACE_SRGB_NONLINEAR_KHR;
566 QVkRenderBuffer *ds = nullptr;
567 VkSampleCountFlagBits samples = VK_SAMPLE_COUNT_1_BIT;
568 QVector<VkPresentModeKHR> supportedPresentationModes;
569 VkDeviceMemory msaaImageMem = VK_NULL_HANDLE;
570 QVkReferenceRenderTarget rtWrapper;
571 QVkCommandBuffer cbWrapper;
572
573 struct ImageResources {
574 VkImage image = VK_NULL_HANDLE;
575 VkImageView imageView = VK_NULL_HANDLE;
576 VkFramebuffer fb = VK_NULL_HANDLE;
577 VkImage msaaImage = VK_NULL_HANDLE;
578 VkImageView msaaImageView = VK_NULL_HANDLE;
579 enum LastUse {
580 ScImageUseNone,
581 ScImageUseRender,
582 ScImageUseTransferSource
583 };
584 LastUse lastUse = ScImageUseNone;
585 } imageRes[MAX_BUFFER_COUNT];
586
587 struct FrameResources {
588 VkFence imageFence = VK_NULL_HANDLE;
589 bool imageFenceWaitable = false;
590 VkSemaphore imageSem = VK_NULL_HANDLE;
591 VkSemaphore drawSem = VK_NULL_HANDLE;
592 bool imageAcquired = false;
593 bool imageSemWaitable = false;
594 quint32 imageIndex = 0;
595 VkCommandBuffer cmdBuf = VK_NULL_HANDLE;
596 VkFence cmdFence = VK_NULL_HANDLE;
597 bool cmdFenceWaitable = false;
598 int timestampQueryIndex = -1;
599 } frameRes[QVK_FRAMES_IN_FLIGHT];
600
601 quint32 currentImageIndex = 0; // index in imageRes
602 quint32 currentFrameSlot = 0; // index in frameRes
603 int frameCount = 0;
604
605 friend class QRhiVulkan;
606};
607
608class QRhiVulkan : public QRhiImplementation
609{
610public:
611 QRhiVulkan(QRhiVulkanInitParams *params, QRhiVulkanNativeHandles *importDevice = nullptr);
612
613 bool create(QRhi::Flags flags) override;
614 void destroy() override;
615
616 QRhiGraphicsPipeline *createGraphicsPipeline() override;
617 QRhiComputePipeline *createComputePipeline() override;
618 QRhiShaderResourceBindings *createShaderResourceBindings() override;
619 QRhiBuffer *createBuffer(QRhiBuffer::Type type,
620 QRhiBuffer::UsageFlags usage,
621 int size) override;
622 QRhiRenderBuffer *createRenderBuffer(QRhiRenderBuffer::Type type,
623 const QSize &pixelSize,
624 int sampleCount,
625 QRhiRenderBuffer::Flags flags) override;
626 QRhiTexture *createTexture(QRhiTexture::Format format,
627 const QSize &pixelSize,
628 int sampleCount,
629 QRhiTexture::Flags flags) override;
630 QRhiSampler *createSampler(QRhiSampler::Filter magFilter, QRhiSampler::Filter minFilter,
631 QRhiSampler::Filter mipmapMode,
632 QRhiSampler:: AddressMode u, QRhiSampler::AddressMode v) override;
633
634 QRhiTextureRenderTarget *createTextureRenderTarget(const QRhiTextureRenderTargetDescription &desc,
635 QRhiTextureRenderTarget::Flags flags) override;
636
637 QRhiSwapChain *createSwapChain() override;
638 QRhi::FrameOpResult beginFrame(QRhiSwapChain *swapChain, QRhi::BeginFrameFlags flags) override;
639 QRhi::FrameOpResult endFrame(QRhiSwapChain *swapChain, QRhi::EndFrameFlags flags) override;
640 QRhi::FrameOpResult beginOffscreenFrame(QRhiCommandBuffer **cb) override;
641 QRhi::FrameOpResult endOffscreenFrame() override;
642 QRhi::FrameOpResult finish() override;
643
644 void resourceUpdate(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch *resourceUpdates) override;
645
646 void beginPass(QRhiCommandBuffer *cb,
647 QRhiRenderTarget *rt,
648 const QColor &colorClearValue,
649 const QRhiDepthStencilClearValue &depthStencilClearValue,
650 QRhiResourceUpdateBatch *resourceUpdates) override;
651 void endPass(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch *resourceUpdates) override;
652
653 void setGraphicsPipeline(QRhiCommandBuffer *cb,
654 QRhiGraphicsPipeline *ps) override;
655
656 void setShaderResources(QRhiCommandBuffer *cb,
657 QRhiShaderResourceBindings *srb,
658 int dynamicOffsetCount,
659 const QRhiCommandBuffer::DynamicOffset *dynamicOffsets) override;
660
661 void setVertexInput(QRhiCommandBuffer *cb,
662 int startBinding, int bindingCount, const QRhiCommandBuffer::VertexInput *bindings,
663 QRhiBuffer *indexBuf, quint32 indexOffset,
664 QRhiCommandBuffer::IndexFormat indexFormat) override;
665
666 void setViewport(QRhiCommandBuffer *cb, const QRhiViewport &viewport) override;
667 void setScissor(QRhiCommandBuffer *cb, const QRhiScissor &scissor) override;
668 void setBlendConstants(QRhiCommandBuffer *cb, const QColor &c) override;
669 void setStencilRef(QRhiCommandBuffer *cb, quint32 refValue) override;
670
671 void draw(QRhiCommandBuffer *cb, quint32 vertexCount,
672 quint32 instanceCount, quint32 firstVertex, quint32 firstInstance) override;
673
674 void drawIndexed(QRhiCommandBuffer *cb, quint32 indexCount,
675 quint32 instanceCount, quint32 firstIndex,
676 qint32 vertexOffset, quint32 firstInstance) override;
677
678 void debugMarkBegin(QRhiCommandBuffer *cb, const QByteArray &name) override;
679 void debugMarkEnd(QRhiCommandBuffer *cb) override;
680 void debugMarkMsg(QRhiCommandBuffer *cb, const QByteArray &msg) override;
681
682 void beginComputePass(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch *resourceUpdates) override;
683 void endComputePass(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch *resourceUpdates) override;
684 void setComputePipeline(QRhiCommandBuffer *cb, QRhiComputePipeline *ps) override;
685 void dispatch(QRhiCommandBuffer *cb, int x, int y, int z) override;
686
687 const QRhiNativeHandles *nativeHandles(QRhiCommandBuffer *cb) override;
688 void beginExternal(QRhiCommandBuffer *cb) override;
689 void endExternal(QRhiCommandBuffer *cb) override;
690
691 QVector<int> supportedSampleCounts() const override;
692 int ubufAlignment() const override;
693 bool isYUpInFramebuffer() const override;
694 bool isYUpInNDC() const override;
695 bool isClipDepthZeroToOne() const override;
696 QMatrix4x4 clipSpaceCorrMatrix() const override;
697 bool isTextureFormatSupported(QRhiTexture::Format format, QRhiTexture::Flags flags) const override;
698 bool isFeatureSupported(QRhi::Feature feature) const override;
699 int resourceLimit(QRhi::ResourceLimit limit) const override;
700 const QRhiNativeHandles *nativeHandles() override;
701 void sendVMemStatsToProfiler() override;
702 void makeThreadLocalNativeContextCurrent() override;
703
704 VkResult createDescriptorPool(VkDescriptorPool *pool);
705 bool allocateDescriptorSet(VkDescriptorSetAllocateInfo *allocInfo, VkDescriptorSet *result, int *resultPoolIndex);
706 uint32_t chooseTransientImageMemType(VkImage img, uint32_t startIndex);
707 bool createTransientImage(VkFormat format, const QSize &pixelSize, VkImageUsageFlags usage,
708 VkImageAspectFlags aspectMask, VkSampleCountFlagBits samples,
709 VkDeviceMemory *mem, VkImage *images, VkImageView *views, int count);
710
711 bool recreateSwapChain(QRhiSwapChain *swapChain);
712 void releaseSwapChainResources(QRhiSwapChain *swapChain);
713
714 VkFormat optimalDepthStencilFormat();
715 VkSampleCountFlagBits effectiveSampleCount(int sampleCount);
716 bool createDefaultRenderPass(VkRenderPass *rp,
717 bool hasDepthStencil,
718 VkSampleCountFlagBits samples,
719 VkFormat colorFormat);
720 bool createOffscreenRenderPass(VkRenderPass *rp,
721 const QVector<QRhiColorAttachment> &colorAttachments,
722 bool preserveColor,
723 bool preserveDs,
724 QRhiRenderBuffer *depthStencilBuffer,
725 QRhiTexture *depthTexture);
726 bool ensurePipelineCache();
727 VkShaderModule createShader(const QByteArray &spirv);
728
729 void prepareNewFrame(QRhiCommandBuffer *cb);
730 QRhi::FrameOpResult startCommandBuffer(VkCommandBuffer *cb);
731 QRhi::FrameOpResult endAndSubmitCommandBuffer(VkCommandBuffer cb, VkFence cmdFence,
732 VkSemaphore *waitSem, VkSemaphore *signalSem);
733 void waitCommandCompletion(int frameSlot);
734 VkDeviceSize subresUploadByteSize(const QRhiTextureSubresourceUploadDescription &subresDesc) const;
735 using BufferImageCopyList = QVarLengthArray<VkBufferImageCopy, 16>;
736 void prepareUploadSubres(QVkTexture *texD, int layer, int level,
737 const QRhiTextureSubresourceUploadDescription &subresDesc,
738 size_t *curOfs, void *mp,
739 BufferImageCopyList *copyInfos);
740 void enqueueResourceUpdates(QVkCommandBuffer *cbD, QRhiResourceUpdateBatch *resourceUpdates);
741 void executeBufferHostWritesForCurrentFrame(QVkBuffer *bufD);
742 void enqueueTransitionPassResources(QVkCommandBuffer *cbD);
743 void recordCommandBuffer(QVkCommandBuffer *cbD);
744 void trackedRegisterBuffer(QRhiPassResourceTracker *passResTracker,
745 QVkBuffer *bufD,
746 int slot,
747 QRhiPassResourceTracker::BufferAccess access,
748 QRhiPassResourceTracker::BufferStage stage);
749 void trackedRegisterTexture(QRhiPassResourceTracker *passResTracker,
750 QVkTexture *texD,
751 QRhiPassResourceTracker::TextureAccess access,
752 QRhiPassResourceTracker::TextureStage stage);
753 void recordTransitionPassResources(QVkCommandBuffer *cbD, const QRhiPassResourceTracker &tracker);
754 void activateTextureRenderTarget(QVkCommandBuffer *cbD, QVkTextureRenderTarget *rtD);
755 void executeDeferredReleases(bool forced = false);
756 void finishActiveReadbacks(bool forced = false);
757
758 void setObjectName(uint64_t object, VkDebugReportObjectTypeEXT type, const QByteArray &name, int slot = -1);
759 void trackedBufferBarrier(QVkCommandBuffer *cbD, QVkBuffer *bufD, int slot,
760 VkAccessFlags access, VkPipelineStageFlags stage);
761 void trackedImageBarrier(QVkCommandBuffer *cbD, QVkTexture *texD,
762 VkImageLayout layout, VkAccessFlags access, VkPipelineStageFlags stage);
763 void subresourceBarrier(QVkCommandBuffer *cbD, VkImage image,
764 VkImageLayout oldLayout, VkImageLayout newLayout,
765 VkAccessFlags srcAccess, VkAccessFlags dstAccess,
766 VkPipelineStageFlags srcStage, VkPipelineStageFlags dstStage,
767 int startLayer, int layerCount,
768 int startLevel, int levelCount);
769 void updateShaderResourceBindings(QRhiShaderResourceBindings *srb, int descSetIdx = -1);
770
771 QVulkanInstance *inst = nullptr;
772 QWindow *maybeWindow = nullptr;
773 bool importedDevice = false;
774 VkPhysicalDevice physDev = VK_NULL_HANDLE;
775 VkDevice dev = VK_NULL_HANDLE;
776 bool importedCmdPool = false;
777 VkCommandPool cmdPool = VK_NULL_HANDLE;
778 int gfxQueueFamilyIdx = -1;
779 VkQueue gfxQueue = VK_NULL_HANDLE;
780 bool hasCompute = false;
781 quint32 timestampValidBits = 0;
782 bool importedAllocator = false;
783 QVkAllocator allocator = nullptr;
784 QVulkanFunctions *f = nullptr;
785 QVulkanDeviceFunctions *df = nullptr;
786 VkPhysicalDeviceFeatures physDevFeatures;
787 VkPhysicalDeviceProperties physDevProperties;
788 VkDeviceSize ubufAlign;
789 VkDeviceSize texbufAlign;
790 bool hasWideLines = false;
791
792 bool debugMarkersAvailable = false;
793 bool vertexAttribDivisorAvailable = false;
794 PFN_vkCmdDebugMarkerBeginEXT vkCmdDebugMarkerBegin = nullptr;
795 PFN_vkCmdDebugMarkerEndEXT vkCmdDebugMarkerEnd = nullptr;
796 PFN_vkCmdDebugMarkerInsertEXT vkCmdDebugMarkerInsert = nullptr;
797 PFN_vkDebugMarkerSetObjectNameEXT vkDebugMarkerSetObjectName = nullptr;
798
799 PFN_vkCreateSwapchainKHR vkCreateSwapchainKHR = nullptr;
800 PFN_vkDestroySwapchainKHR vkDestroySwapchainKHR;
801 PFN_vkGetSwapchainImagesKHR vkGetSwapchainImagesKHR;
802 PFN_vkAcquireNextImageKHR vkAcquireNextImageKHR;
803 PFN_vkQueuePresentKHR vkQueuePresentKHR;
804 PFN_vkGetPhysicalDeviceSurfaceCapabilitiesKHR vkGetPhysicalDeviceSurfaceCapabilitiesKHR = nullptr;
805 PFN_vkGetPhysicalDeviceSurfaceFormatsKHR vkGetPhysicalDeviceSurfaceFormatsKHR;
806 PFN_vkGetPhysicalDeviceSurfacePresentModesKHR vkGetPhysicalDeviceSurfacePresentModesKHR;
807
808 VkPipelineCache pipelineCache = VK_NULL_HANDLE;
809 struct DescriptorPoolData {
810 DescriptorPoolData() { }
811 DescriptorPoolData(VkDescriptorPool pool_)
812 : pool(pool_)
813 { }
814 VkDescriptorPool pool = VK_NULL_HANDLE;
815 int refCount = 0;
816 int allocedDescSets = 0;
817 };
818 QVector<DescriptorPoolData> descriptorPools;
819
820 VkQueryPool timestampQueryPool = VK_NULL_HANDLE;
821 QBitArray timestampQueryPoolMap;
822
823 VkFormat optimalDsFormat = VK_FORMAT_UNDEFINED;
824 QMatrix4x4 clipCorrectMatrix;
825
826 QVkSwapChain *currentSwapChain = nullptr;
827 QSet<QVkSwapChain *> swapchains;
828 QRhiVulkanNativeHandles nativeHandlesStruct;
829
830 struct OffscreenFrame {
831 OffscreenFrame(QRhiImplementation *rhi) : cbWrapper(rhi) { }
832 bool active = false;
833 QVkCommandBuffer cbWrapper;
834 VkFence cmdFence = VK_NULL_HANDLE;
835 } ofr;
836
837 struct ActiveReadback {
838 int activeFrameSlot = -1;
839 QRhiReadbackDescription desc;
840 QRhiReadbackResult *result;
841 VkBuffer buf;
842 QVkAlloc bufAlloc;
843 quint32 bufSize;
844 QSize pixelSize;
845 QRhiTexture::Format format;
846 };
847 QVector<ActiveReadback> activeReadbacks;
848
849 struct DeferredReleaseEntry {
850 enum Type {
851 Pipeline,
852 ShaderResourceBindings,
853 Buffer,
854 RenderBuffer,
855 Texture,
856 Sampler,
857 TextureRenderTarget,
858 RenderPass,
859 StagingBuffer
860 };
861 Type type;
862 int lastActiveFrameSlot; // -1 if not used otherwise 0..FRAMES_IN_FLIGHT-1
863 union {
864 struct {
865 VkPipeline pipeline;
866 VkPipelineLayout layout;
867 } pipelineState;
868 struct {
869 int poolIndex;
870 VkDescriptorSetLayout layout;
871 } shaderResourceBindings;
872 struct {
873 VkBuffer buffers[QVK_FRAMES_IN_FLIGHT];
874 QVkAlloc allocations[QVK_FRAMES_IN_FLIGHT];
875 VkBuffer stagingBuffers[QVK_FRAMES_IN_FLIGHT];
876 QVkAlloc stagingAllocations[QVK_FRAMES_IN_FLIGHT];
877 } buffer;
878 struct {
879 VkDeviceMemory memory;
880 VkImage image;
881 VkImageView imageView;
882 } renderBuffer;
883 struct {
884 VkImage image;
885 VkImageView imageView;
886 QVkAlloc allocation;
887 VkBuffer stagingBuffers[QVK_FRAMES_IN_FLIGHT];
888 QVkAlloc stagingAllocations[QVK_FRAMES_IN_FLIGHT];
889 VkImageView extraImageViews[QRhi::MAX_LEVELS];
890 } texture;
891 struct {
892 VkSampler sampler;
893 } sampler;
894 struct {
895 VkFramebuffer fb;
896 VkImageView rtv[QVkRenderTargetData::MAX_COLOR_ATTACHMENTS];
897 VkImageView resrtv[QVkRenderTargetData::MAX_COLOR_ATTACHMENTS];
898 } textureRenderTarget;
899 struct {
900 VkRenderPass rp;
901 } renderPass;
902 struct {
903 VkBuffer stagingBuffer;
904 QVkAlloc stagingAllocation;
905 } stagingBuffer;
906 };
907 };
908 QVector<DeferredReleaseEntry> releaseQueue;
909};
910
911Q_DECLARE_TYPEINFO(QRhiVulkan::DescriptorPoolData, Q_MOVABLE_TYPE);
912Q_DECLARE_TYPEINFO(QRhiVulkan::DeferredReleaseEntry, Q_MOVABLE_TYPE);
913Q_DECLARE_TYPEINFO(QRhiVulkan::ActiveReadback, Q_MOVABLE_TYPE);
914
915QT_END_NAMESPACE
916
917#endif
918

Warning: That file was not part of the compilation database. It may have many parsing errors.