Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qrhinull.cpp
Go to the documentation of this file.
1// Copyright (C) 2023 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5#include "qrhinull_p.h"
6#include <qmath.h>
7#include <QPainter>
8
10
11/*!
12 \class QRhiNullInitParams
13 \inmodule QtGuiPrivate
14 \inheaderfile rhi/qrhi.h
15 \since 6.6
16 \brief Null backend specific initialization parameters.
17
18 \note This is a RHI API with limited compatibility guarantees, see \l QRhi
19 for details.
20
21 A Null QRhi needs no special parameters for initialization.
22
23 \badcode
24 QRhiNullInitParams params;
25 rhi = QRhi::create(QRhi::Null, &params);
26 \endcode
27
28 The Null backend does not issue any graphics calls and creates no
29 resources. All QRhi operations will succeed as normal so applications can
30 still be run, albeit potentially at an unthrottled speed, depending on
31 their frame rendering strategy.
32 */
33
34/*!
35 \class QRhiNullNativeHandles
36 \inmodule QtGuiPrivate
37 \inheaderfile rhi/qrhi.h
38 \since 6.6
39 \brief Empty.
40
41 \note This is a RHI API with limited compatibility guarantees, see \l QRhi
42 for details.
43 */
44
45QRhiNull::QRhiNull(QRhiNullInitParams *params)
46 : offscreenCommandBuffer(this)
47{
48 Q_UNUSED(params);
49}
50
51bool QRhiNull::create(QRhi::Flags flags)
52{
53 Q_UNUSED(flags);
54 return true;
55}
56
58{
59}
60
62{
63 return { 1 };
64}
65
66QList<QSize> QRhiNull::supportedShadingRates(int sampleCount) const
67{
68 Q_UNUSED(sampleCount);
69 return { QSize(1, 1) };
70}
71
72QRhiSwapChain *QRhiNull::createSwapChain()
73{
74 return new QNullSwapChain(this);
75}
76
77QRhiBuffer *QRhiNull::createBuffer(QRhiBuffer::Type type, QRhiBuffer::UsageFlags usage, quint32 size)
78{
79 return new QNullBuffer(this, type, usage, size);
80}
81
83{
84 return 256;
85}
86
88{
89 return false;
90}
91
92bool QRhiNull::isYUpInNDC() const
93{
94 return true;
95}
96
98{
99 return true;
100}
101
103{
104 return QMatrix4x4(); // identity
105}
106
107bool QRhiNull::isTextureFormatSupported(QRhiTexture::Format format, QRhiTexture::Flags flags) const
108{
109 Q_UNUSED(format);
110 Q_UNUSED(flags);
111 return true;
112}
113
114bool QRhiNull::isFeatureSupported(QRhi::Feature feature) const
115{
116 Q_UNUSED(feature);
117 return true;
118}
119
120int QRhiNull::resourceLimit(QRhi::ResourceLimit limit) const
121{
122 switch (limit) {
123 case QRhi::TextureSizeMin:
124 return 1;
125 case QRhi::TextureSizeMax:
126 return 16384;
127 case QRhi::MaxColorAttachments:
128 return 8;
129 case QRhi::FramesInFlight:
130 return 1;
131 case QRhi::MaxAsyncReadbackFrames:
132 return 1;
133 case QRhi::MaxThreadGroupsPerDimension:
134 return 0;
135 case QRhi::MaxThreadsPerThreadGroup:
136 return 0;
137 case QRhi::MaxThreadGroupX:
138 return 0;
139 case QRhi::MaxThreadGroupY:
140 return 0;
141 case QRhi::MaxThreadGroupZ:
142 return 0;
143 case QRhi::TextureArraySizeMax:
144 return 2048;
145 case QRhi::MaxUniformBufferRange:
146 return 65536;
147 case QRhi::MaxVertexInputs:
148 return 32;
149 case QRhi::MaxVertexOutputs:
150 return 32;
151 case QRhi::MaxPushConstantsSize:
152 return 128;
153 case QRhi::MaxVertexStorageBuffers:
154 case QRhi::MaxFragmentStorageBuffers:
155 return 32;
156 case QRhi::MaxStorageBufferBindings:
157 case QRhi::MaxStorageImageBindings:
158 return INT_MAX;
159 case QRhi::ShadingRateImageTileSize:
160 return 0;
161 }
162
163 Q_UNREACHABLE_RETURN(0);
164}
165
167{
168 return &nativeHandlesStruct;
169}
170
172{
173 QRhiDriverInfo info;
174 info.deviceName = QByteArrayLiteral("Null");
175 return info;
176}
177
179{
180 return {};
181}
182
184{
185 // not applicable
186 return false;
187}
188
189void QRhiNull::setQueueSubmitParams(QRhiNativeHandles *)
190{
191 // not applicable
192}
193
195{
196 // nothing to do here
197}
198
200{
201 return false;
202}
203
205{
206 return QByteArray();
207}
208
209void QRhiNull::setPipelineCacheData(const QByteArray &data)
210{
211 Q_UNUSED(data);
212}
213
214QRhiRenderBuffer *QRhiNull::createRenderBuffer(QRhiRenderBuffer::Type type, const QSize &pixelSize,
215 int sampleCount, QRhiRenderBuffer::Flags flags,
216 QRhiTexture::Format backingFormatHint)
217{
218 return new QNullRenderBuffer(this, type, pixelSize, sampleCount, flags, backingFormatHint);
219}
220
221QRhiTexture *QRhiNull::createTexture(QRhiTexture::Format format,
222 const QSize &pixelSize, int depth, int arraySize,
223 int sampleCount, QRhiTexture::Flags flags)
224{
225 return new QNullTexture(this, format, pixelSize, depth, arraySize, sampleCount, flags);
226}
227
228QRhiSampler *QRhiNull::createSampler(QRhiSampler::Filter magFilter, QRhiSampler::Filter minFilter,
229 QRhiSampler::Filter mipmapMode,
230 QRhiSampler::AddressMode u, QRhiSampler::AddressMode v, QRhiSampler::AddressMode w)
231{
232 return new QNullSampler(this, magFilter, minFilter, mipmapMode, u, v, w);
233}
234
235QRhiTextureRenderTarget *QRhiNull::createTextureRenderTarget(const QRhiTextureRenderTargetDescription &desc,
236 QRhiTextureRenderTarget::Flags flags)
237{
238 return new QNullTextureRenderTarget(this, desc, flags);
239}
240
241QRhiShadingRateMap *QRhiNull::createShadingRateMap()
242{
243 return nullptr;
244}
245
247{
248 return new QNullGraphicsPipeline(this);
249}
250
252{
253 return new QNullComputePipeline(this);
254}
255
257{
258 return new QNullShaderResourceBindings(this);
259}
260
261void QRhiNull::setGraphicsPipeline(QRhiCommandBuffer *cb, QRhiGraphicsPipeline *ps)
262{
263 Q_UNUSED(cb);
264 Q_UNUSED(ps);
265}
266
267void QRhiNull::setShaderResources(QRhiCommandBuffer *cb, QRhiShaderResourceBindings *srb,
268 int dynamicOffsetCount,
269 const QRhiCommandBuffer::DynamicOffset *dynamicOffsets)
270{
271 Q_UNUSED(cb);
272 Q_UNUSED(srb);
273 Q_UNUSED(dynamicOffsetCount);
274 Q_UNUSED(dynamicOffsets);
275}
276
277void QRhiNull::setVertexInput(QRhiCommandBuffer *cb,
278 int startBinding, int bindingCount, const QRhiCommandBuffer::VertexInput *bindings,
279 QRhiBuffer *indexBuf, quint32 indexOffset, QRhiCommandBuffer::IndexFormat indexFormat)
280{
281 Q_UNUSED(cb);
282 Q_UNUSED(startBinding);
283 Q_UNUSED(bindingCount);
284 Q_UNUSED(bindings);
285 Q_UNUSED(indexBuf);
286 Q_UNUSED(indexOffset);
287 Q_UNUSED(indexFormat);
288}
289
290void QRhiNull::setViewport(QRhiCommandBuffer *cb, const QRhiViewport &viewport)
291{
292 Q_UNUSED(cb);
293 Q_UNUSED(viewport);
294}
295
296void QRhiNull::setScissor(QRhiCommandBuffer *cb, const QRhiScissor &scissor)
297{
298 Q_UNUSED(cb);
299 Q_UNUSED(scissor);
300}
301
302void QRhiNull::setBlendConstants(QRhiCommandBuffer *cb, const QColor &c)
303{
304 Q_UNUSED(cb);
305 Q_UNUSED(c);
306}
307
308void QRhiNull::setStencilRef(QRhiCommandBuffer *cb, quint32 refValue)
309{
310 Q_UNUSED(cb);
311 Q_UNUSED(refValue);
312}
313
314void QRhiNull::setPushConstants(QRhiCommandBuffer *cb, quint32 offset, quint32 size, const void *data)
315{
316 Q_UNUSED(cb);
317 Q_UNUSED(offset);
318 Q_UNUSED(size);
319 Q_UNUSED(data);
320}
321
322void QRhiNull::setShadingRate(QRhiCommandBuffer *cb, const QSize &coarsePixelSize)
323{
324 Q_UNUSED(cb);
325 Q_UNUSED(coarsePixelSize);
326}
327
328void QRhiNull::draw(QRhiCommandBuffer *cb, quint32 vertexCount,
329 quint32 instanceCount, quint32 firstVertex, quint32 firstInstance)
330{
331 Q_UNUSED(cb);
332 Q_UNUSED(vertexCount);
333 Q_UNUSED(instanceCount);
334 Q_UNUSED(firstVertex);
335 Q_UNUSED(firstInstance);
336}
337
338void QRhiNull::drawIndexed(QRhiCommandBuffer *cb, quint32 indexCount,
339 quint32 instanceCount, quint32 firstIndex, qint32 vertexOffset, quint32 firstInstance)
340{
341 Q_UNUSED(cb);
342 Q_UNUSED(indexCount);
343 Q_UNUSED(instanceCount);
344 Q_UNUSED(firstIndex);
345 Q_UNUSED(vertexOffset);
346 Q_UNUSED(firstInstance);
347}
348
349void QRhiNull::drawIndirect(QRhiCommandBuffer *cb, QRhiBuffer *indirectBuffer,
350 quint32 indirectBufferOffset, quint32 drawCount, quint32 stride)
351{
352 Q_UNUSED(cb);
353 Q_UNUSED(indirectBuffer);
354 Q_UNUSED(indirectBufferOffset);
355 Q_UNUSED(drawCount);
356 Q_UNUSED(stride);
357}
358
359void QRhiNull::drawIndexedIndirect(QRhiCommandBuffer *cb, QRhiBuffer *indirectBuffer,
360 quint32 indirectBufferOffset, quint32 drawCount, quint32 stride)
361{
362 Q_UNUSED(cb);
363 Q_UNUSED(indirectBuffer);
364 Q_UNUSED(indirectBufferOffset);
365 Q_UNUSED(drawCount);
366 Q_UNUSED(stride);
367}
368
369void QRhiNull::drawIndirectCount(QRhiCommandBuffer *cb,
370 QRhiBuffer *indirectBuffer, quint32 indirectBufferOffset,
371 QRhiBuffer *countBuffer, quint32 countBufferOffset,
372 quint32 maxDrawCount, quint32 stride)
373{
374 Q_UNUSED(cb);
375 Q_UNUSED(indirectBuffer);
376 Q_UNUSED(indirectBufferOffset);
377 Q_UNUSED(countBuffer);
378 Q_UNUSED(countBufferOffset);
379 Q_UNUSED(maxDrawCount);
380 Q_UNUSED(stride);
381}
382
383void QRhiNull::drawIndexedIndirectCount(QRhiCommandBuffer *cb,
384 QRhiBuffer *indirectBuffer, quint32 indirectBufferOffset,
385 QRhiBuffer *countBuffer, quint32 countBufferOffset,
386 quint32 maxDrawCount, quint32 stride)
387{
388 Q_UNUSED(cb);
389 Q_UNUSED(indirectBuffer);
390 Q_UNUSED(indirectBufferOffset);
391 Q_UNUSED(countBuffer);
392 Q_UNUSED(countBufferOffset);
393 Q_UNUSED(maxDrawCount);
394 Q_UNUSED(stride);
395}
396
397void QRhiNull::debugMarkBegin(QRhiCommandBuffer *cb, const QByteArray &name)
398{
399 Q_UNUSED(cb);
400 Q_UNUSED(name);
401}
402
403void QRhiNull::debugMarkEnd(QRhiCommandBuffer *cb)
404{
405 Q_UNUSED(cb);
406}
407
408void QRhiNull::debugMarkMsg(QRhiCommandBuffer *cb, const QByteArray &msg)
409{
410 Q_UNUSED(cb);
411 Q_UNUSED(msg);
412}
413
414void QRhiNull::setComputePipeline(QRhiCommandBuffer *cb, QRhiComputePipeline *ps)
415{
416 Q_UNUSED(cb);
417 Q_UNUSED(ps);
418}
419
420void QRhiNull::dispatch(QRhiCommandBuffer *cb, int x, int y, int z)
421{
422 Q_UNUSED(cb);
423 Q_UNUSED(x);
424 Q_UNUSED(y);
425 Q_UNUSED(z);
426}
427
428void QRhiNull::dispatchIndirect(QRhiCommandBuffer *cb, QRhiBuffer *indirectBuffer,
429 quint32 indirectBufferOffset)
430{
431 Q_UNUSED(cb);
432 Q_UNUSED(indirectBuffer);
433 Q_UNUSED(indirectBufferOffset);
434}
435
436const QRhiNativeHandles *QRhiNull::nativeHandles(QRhiCommandBuffer *cb)
437{
438 Q_UNUSED(cb);
439 return nullptr;
440}
441
442void QRhiNull::beginExternal(QRhiCommandBuffer *cb)
443{
444 Q_UNUSED(cb);
445}
446
447void QRhiNull::endExternal(QRhiCommandBuffer *cb)
448{
449 Q_UNUSED(cb);
450}
451
452double QRhiNull::lastCompletedGpuTime(QRhiCommandBuffer *cb)
453{
454 Q_UNUSED(cb);
455 return 0;
456}
457
458QRhi::FrameOpResult QRhiNull::beginFrame(QRhiSwapChain *swapChain, QRhi::BeginFrameFlags flags)
459{
460 Q_UNUSED(flags);
461 currentSwapChain = swapChain;
462 return QRhi::FrameOpSuccess;
463}
464
465QRhi::FrameOpResult QRhiNull::endFrame(QRhiSwapChain *swapChain, QRhi::EndFrameFlags flags)
466{
467 Q_UNUSED(flags);
468 QNullSwapChain *swapChainD = QRHI_RES(QNullSwapChain, swapChain);
469 swapChainD->frameCount += 1;
470 currentSwapChain = nullptr;
471 return QRhi::FrameOpSuccess;
472}
473
474QRhi::FrameOpResult QRhiNull::beginOffscreenFrame(QRhiCommandBuffer **cb, QRhi::BeginFrameFlags flags)
475{
476 Q_UNUSED(flags);
477 *cb = &offscreenCommandBuffer;
478 return QRhi::FrameOpSuccess;
479}
480
481QRhi::FrameOpResult QRhiNull::endOffscreenFrame(QRhi::EndFrameFlags flags)
482{
483 Q_UNUSED(flags);
484 return QRhi::FrameOpSuccess;
485}
486
488{
489 return QRhi::FrameOpSuccess;
490}
491
493{
494 QNullTexture *texD = QRHI_RES(QNullTexture, u.dst);
495 for (const auto &subres : u.subresDesc) {
496 const int layer = subres.layer;
497 const int level = subres.level;
498 const QRhiTextureSubresourceUploadDescription &subresDesc(subres.desc);
499 if (!subresDesc.image().isNull()) {
500 const QImage src = subresDesc.image();
501 QPainter painter(&texD->image[layer][level]);
502 const QSize srcSize = subresDesc.sourceSize().isEmpty()
503 ? src.size() : subresDesc.sourceSize();
504 painter.setCompositionMode(QPainter::CompositionMode_Source);
505 painter.drawImage(subresDesc.destinationTopLeft(), src,
506 QRect(subresDesc.sourceTopLeft(), srcSize));
507 } else if (!subresDesc.data().isEmpty()) {
508 const QSize subresSize = q->sizeForMipLevel(level, texD->pixelSize());
509 int w = subresSize.width();
510 int h = subresSize.height();
511 if (!subresDesc.sourceSize().isEmpty()) {
512 w = subresDesc.sourceSize().width();
513 h = subresDesc.sourceSize().height();
514 }
515 // sourceTopLeft is not supported on this path as per QRhi docs
516 const QByteArray srcData = subresDesc.data();
517 const QPoint dstOffset = subresDesc.destinationTopLeft();
518 QSize size = clampedSubResourceUploadSize(QSize(w, h), dstOffset, level,
519 texD->pixelSize());
520 size = clampedSubResourceUploadSizeForSourceData(size, subresDesc.dataStride(),
521 4, srcData.size());
522 if (size.isEmpty())
523 continue;
524 w = size.width();
525 h = size.height();
526 const char *src = srcData.constData();
527 const int srcBpl = w * 4;
528 int srcStride = srcBpl;
529 if (subresDesc.dataStride())
530 srcStride = subresDesc.dataStride();
531 uchar *dst = texD->image[layer][level].bits();
532 const int dstBpl = texD->image[layer][level].bytesPerLine();
533 for (int y = 0; y < h; ++y) {
534 memcpy(dst + dstOffset.x() * 4 + (y + dstOffset.y()) * dstBpl,
535 src + y * srcStride,
536 size_t(srcBpl));
537 }
538 }
539 }
540}
541
543{
544 QNullTexture *srcD = QRHI_RES(QNullTexture, u.src);
545 QNullTexture *dstD = QRHI_RES(QNullTexture, u.dst);
546 const QImage &srcImage(srcD->image[u.desc.sourceLayer()][u.desc.sourceLevel()]);
547 QImage &dstImage(dstD->image[u.desc.destinationLayer()][u.desc.destinationLevel()]);
548 const QPoint dstPos = u.desc.destinationTopLeft();
549 const QSize size = u.desc.pixelSize().isEmpty() ? srcD->pixelSize() : u.desc.pixelSize();
550 const QPoint srcPos = u.desc.sourceTopLeft();
551
552 QPainter painter(&dstImage);
553 painter.setCompositionMode(QPainter::CompositionMode_Source);
554 painter.drawImage(QRect(dstPos, size), srcImage, QRect(srcPos, size));
555}
556
558{
559 QNullTexture *texD = QRHI_RES(QNullTexture, u.dst);
560 const QSize baseSize = texD->pixelSize();
561 const int levelCount = q->mipLevelsForSize(baseSize);
562 for (int level = 1; level < levelCount; ++level)
563 texD->image[0][level] = texD->image[0][0].scaled(q->sizeForMipLevel(level, baseSize));
564}
565
566void QRhiNull::resourceUpdate(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch *resourceUpdates)
567{
568 Q_UNUSED(cb);
570 for (int opIdx = 0; opIdx < ud->activeBufferOpCount; ++opIdx) {
571 const QRhiResourceUpdateBatchPrivate::BufferOp &u(ud->bufferOps[opIdx]);
574 {
575 QNullBuffer *bufD = QRHI_RES(QNullBuffer, u.buf);
576 memcpy(bufD->data + u.offset, u.data.constData(), size_t(u.data.size()));
578 QRhiReadbackResult *result = u.result;
579 result->data.resize(u.readSize);
580 QNullBuffer *bufD = QRHI_RES(QNullBuffer, u.buf);
581 memcpy(result->data.data(), bufD->data + u.offset, size_t(u.readSize));
582 if (result->completed)
583 result->completed();
585 QNullBuffer *dstD = QRHI_RES(QNullBuffer, u.buf);
586 QNullBuffer *srcD = QRHI_RES(QNullBuffer, u.src);
587 memcpy(dstD->data + u.offset, srcD->data + u.srcOffset, size_t(u.readSize));
589 QNullBuffer *bufD = QRHI_RES(QNullBuffer, u.buf);
590 memset(bufD->data + u.offset, u.fillValue, size_t(u.readSize));
591 }
592 }
593 for (int opIdx = 0; opIdx < ud->activeTextureOpCount; ++opIdx) {
594 const QRhiResourceUpdateBatchPrivate::TextureOp &u(ud->textureOps[opIdx]);
596 if (u.dst->format() == QRhiTexture::RGBA8)
599 if (u.src->format() == QRhiTexture::RGBA8 && u.dst->format() == QRhiTexture::RGBA8)
602 QRhiReadbackResult *result = u.result;
603 QNullTexture *texD = QRHI_RES(QNullTexture, u.rb.texture());
604 if (texD) {
605 result->format = texD->format();
606 if (u.rb.rect().isValid())
607 result->pixelSize = u.rb.rect().size();
608 else
609 result->pixelSize = q->sizeForMipLevel(u.rb.level(), texD->pixelSize());
610 } else {
611 Q_ASSERT(currentSwapChain);
612 result->format = QRhiTexture::RGBA8;
613 if (u.rb.rect().isValid())
614 result->pixelSize = u.rb.rect().size();
615 else
616 result->pixelSize = currentSwapChain->currentPixelSize();
617 }
618 quint32 bytesPerLine = 0;
619 quint32 byteSize = 0;
620 textureFormatInfo(result->format, result->pixelSize, &bytesPerLine, &byteSize, nullptr);
621 if (texD && texD->format() == QRhiTexture::RGBA8) {
622 result->data.resize(int(byteSize));
623 const QImage &src(texD->image[u.rb.layer()][u.rb.level()]);
624 char *dst = result->data.data();
625 for (int y = 0, h = src.height(); y < h; ++y) {
626 memcpy(dst, src.constScanLine(y), bytesPerLine);
627 dst += bytesPerLine;
628 }
629 } else {
630 result->data.fill(0, int(byteSize));
631 }
632 if (result->completed)
633 result->completed();
635 if (u.dst->format() == QRhiTexture::RGBA8)
637 }
638 }
639 ud->free();
640}
641
642void QRhiNull::beginPass(QRhiCommandBuffer *cb,
643 QRhiRenderTarget *rt,
644 const QColor &colorClearValue,
645 const QRhiDepthStencilClearValue &depthStencilClearValue,
646 QRhiResourceUpdateBatch *resourceUpdates,
647 QRhiCommandBuffer::BeginPassFlags flags)
648{
649 Q_UNUSED(colorClearValue);
650 Q_UNUSED(depthStencilClearValue);
651 Q_UNUSED(flags);
652
653 if (resourceUpdates)
654 resourceUpdate(cb, resourceUpdates);
655
656 if (rt->resourceType() == QRhiRenderTarget::TextureRenderTarget) {
658 if (!QRhiRenderTargetAttachmentTracker::isUpToDate<QNullTexture, QNullRenderBuffer>(rtTex->description(), rtTex->d.currentResIdList))
659 rtTex->create();
660 }
661}
662
663void QRhiNull::endPass(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch *resourceUpdates)
664{
665 if (resourceUpdates)
666 resourceUpdate(cb, resourceUpdates);
667}
668
669void QRhiNull::beginComputePass(QRhiCommandBuffer *cb,
670 QRhiResourceUpdateBatch *resourceUpdates,
671 QRhiCommandBuffer::BeginPassFlags flags)
672{
673 Q_UNUSED(flags);
674 if (resourceUpdates)
675 resourceUpdate(cb, resourceUpdates);
676}
677
678void QRhiNull::endComputePass(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch *resourceUpdates)
679{
680 if (resourceUpdates)
681 resourceUpdate(cb, resourceUpdates);
682}
683
684QNullBuffer::QNullBuffer(QRhiImplementation *rhi, Type type, UsageFlags usage, quint32 size)
686{
687}
688
693
695{
696 delete[] data;
697 data = nullptr;
698
699 QRHI_RES_RHI(QRhiNull);
700 if (rhiD)
701 rhiD->unregisterResource(this);
702}
703
705{
706 if (data)
707 destroy();
708
709 data = new char[m_size];
710 memset(data, 0, m_size);
711
712 QRHI_RES_RHI(QRhiNull);
713 rhiD->registerResource(this);
714
715 return true;
716}
717
719{
720 Q_ASSERT(m_type == Dynamic);
721 return data;
722}
723
724QNullRenderBuffer::QNullRenderBuffer(QRhiImplementation *rhi, Type type, const QSize &pixelSize,
725 int sampleCount, QRhiRenderBuffer::Flags flags,
726 QRhiTexture::Format backingFormatHint)
728{
729}
730
735
737{
738 valid = false;
739
740 QRHI_RES_RHI(QRhiNull);
741 if (rhiD)
742 rhiD->unregisterResource(this);
743}
744
746{
747 if (valid)
748 destroy();
749
750 valid = true;
751 generation += 1;
752
753 QRHI_RES_RHI(QRhiNull);
754 rhiD->registerResource(this);
755
756 return true;
757}
758
760{
761 return m_type == Color ? QRhiTexture::RGBA8 : QRhiTexture::UnknownFormat;
762}
763
764QNullTexture::QNullTexture(QRhiImplementation *rhi, Format format, const QSize &pixelSize, int depth,
765 int arraySize, int sampleCount, Flags flags)
767{
768}
769
774
776{
777 valid = false;
778
779 QRHI_RES_RHI(QRhiNull);
780 if (rhiD)
781 rhiD->unregisterResource(this);
782}
783
785{
786 if (valid)
787 destroy();
788
789 valid = true;
790
791 QRHI_RES_RHI(QRhiNull);
792 const bool isCube = m_flags.testFlag(CubeMap);
793 const bool is3D = m_flags.testFlag(ThreeDimensional);
794 const bool isArray = m_flags.testFlag(TextureArray);
795 const bool hasMipMaps = m_flags.testFlag(MipMapped);
796 const bool is1D = m_flags.testFlags(OneDimensional);
797 QSize size = is1D ? QSize(qMax(1, m_pixelSize.width()), 1)
798 : (m_pixelSize.isEmpty() ? QSize(1, 1) : m_pixelSize);
799 const int mipLevelCount = hasMipMaps ? rhiD->q->mipLevelsForSize(size) : 1;
800 const int layerCount = is3D ? qMax(1, m_depth)
801 : (isCube ? 6
802 : (isArray ? qMax(0, m_arraySize)
803 : 1));
804
805 if (!rhiD->textureFormatInfo(m_format, size, nullptr, nullptr, nullptr)) {
806 valid = false;
807 return false;
808 }
809
810 if (m_format == RGBA8) {
811 image.resize(layerCount);
812 for (int layer = 0; layer < layerCount; ++layer) {
813 for (int level = 0; level < mipLevelCount; ++level) {
814 image[layer][level] = QImage(rhiD->q->sizeForMipLevel(level, size),
815 QImage::Format_RGBA8888_Premultiplied);
816 image[layer][level].fill(Qt::yellow);
817 }
818 }
819 }
820
821 generation += 1;
822
823 rhiD->registerResource(this);
824
825 return true;
826}
827
828bool QNullTexture::createFrom(QRhiTexture::NativeTexture src)
829{
830 Q_UNUSED(src);
831 if (valid)
832 destroy();
833
834 valid = true;
835
836 generation += 1;
837
838 QRHI_RES_RHI(QRhiNull);
839 rhiD->registerResource(this);
840
841 return true;
842}
843
844QNullSampler::QNullSampler(QRhiImplementation *rhi, Filter magFilter, Filter minFilter, Filter mipmapMode,
845 AddressMode u, AddressMode v, AddressMode w)
847{
848}
849
854
856{
857 QRHI_RES_RHI(QRhiNull);
858 if (rhiD)
859 rhiD->unregisterResource(this);
860}
861
863{
864 QRHI_RES_RHI(QRhiNull);
865 rhiD->registerResource(this);
866 return true;
867}
868
873
878
880{
881 QRHI_RES_RHI(QRhiNull);
882 if (rhiD)
883 rhiD->unregisterResource(this);
884}
885
886bool QNullRenderPassDescriptor::isCompatible(const QRhiRenderPassDescriptor *other) const
887{
888 Q_UNUSED(other);
889 return true;
890}
891
893{
894 QNullRenderPassDescriptor *rpD = new QNullRenderPassDescriptor(m_rhi);
895 QRHI_RES_RHI(QRhiNull);
896 rhiD->registerResource(rpD, false);
897 return rpD;
898}
899
904
905QNullSwapChainRenderTarget::QNullSwapChainRenderTarget(QRhiImplementation *rhi, QRhiSwapChain *swapchain)
907 d(rhi)
908{
909}
910
915
919
921{
922 return d.pixelSize;
923}
924
926{
927 return d.dpr;
928}
929
931{
932 return 1;
933}
934
936 const QRhiTextureRenderTargetDescription &desc,
937 Flags flags)
939 d(rhi)
940{
941}
942
947
949{
950 QRHI_RES_RHI(QRhiNull);
951 if (rhiD)
952 rhiD->unregisterResource(this);
953}
954
956{
957 QNullRenderPassDescriptor *rpD = new QNullRenderPassDescriptor(m_rhi);
958 QRHI_RES_RHI(QRhiNull);
959 rhiD->registerResource(rpD, false);
960 return rpD;
961}
962
964{
965 QRHI_RES_RHI(QRhiNull);
966 d.rp = QRHI_RES(QNullRenderPassDescriptor, m_renderPassDesc);
967 if (m_desc.cbeginColorAttachments() != m_desc.cendColorAttachments()) {
968 const QRhiColorAttachment *colorAtt = m_desc.cbeginColorAttachments();
969 QRhiTexture *tex = colorAtt->texture();
970 QRhiRenderBuffer *rb = colorAtt->renderBuffer();
971 d.pixelSize = tex ? rhiD->q->sizeForMipLevel(colorAtt->level(), tex->pixelSize()) : rb->pixelSize();
972 } else if (m_desc.depthStencilBuffer()) {
973 d.pixelSize = m_desc.depthStencilBuffer()->pixelSize();
974 } else if (m_desc.depthTexture()) {
975 d.pixelSize = m_desc.depthTexture()->pixelSize();
976 }
977 QRhiRenderTargetAttachmentTracker::updateResIdList<QNullTexture, QNullRenderBuffer>(m_desc, &d.currentResIdList);
978 rhiD->registerResource(this);
979 return true;
980}
981
983{
984 if (!QRhiRenderTargetAttachmentTracker::isUpToDate<QNullTexture, QNullRenderBuffer>(m_desc, d.currentResIdList))
985 const_cast<QNullTextureRenderTarget *>(this)->create();
986
987 return d.pixelSize;
988}
989
991{
992 return d.dpr;
993}
994
996{
997 return 1;
998}
999
1004
1009
1011{
1012 QRHI_RES_RHI(QRhiNull);
1013 if (rhiD)
1014 rhiD->unregisterResource(this);
1015}
1016
1018{
1019 QRHI_RES_RHI(QRhiNull);
1020 if (!rhiD->sanityCheckShaderResourceBindings(this))
1021 return false;
1022
1023 rhiD->updateLayoutDesc(this);
1024
1025 rhiD->registerResource(this, false);
1026 return true;
1027}
1028
1030{
1031 Q_UNUSED(flags);
1032}
1033
1036{
1037}
1038
1043
1045{
1046 QRHI_RES_RHI(QRhiNull);
1047 if (rhiD)
1048 rhiD->unregisterResource(this);
1049}
1050
1052{
1053 QRHI_RES_RHI(QRhiNull);
1054 if (!rhiD->sanityCheckGraphicsPipeline(this))
1055 return false;
1056
1057 rhiD->registerResource(this);
1058 return true;
1059}
1060
1063{
1064}
1065
1070
1072{
1073 QRHI_RES_RHI(QRhiNull);
1074 if (rhiD)
1075 rhiD->unregisterResource(this);
1076}
1077
1079{
1080 QRHI_RES_RHI(QRhiNull);
1081 rhiD->registerResource(this);
1082 return true;
1083}
1084
1087{
1088}
1089
1094
1096{
1097 // nothing to do here
1098}
1099
1100QNullSwapChain::QNullSwapChain(QRhiImplementation *rhi)
1101 : QRhiSwapChain(rhi),
1102 rt(rhi, this),
1103 cb(rhi)
1104{
1105}
1106
1111
1113{
1114 QRHI_RES_RHI(QRhiNull);
1115 if (rhiD)
1116 rhiD->unregisterResource(this);
1117}
1118
1120{
1121 return &cb;
1122}
1123
1128
1130{
1131 return QSize(1280, 720);
1132}
1133
1135{
1136 return f == SDR;
1137}
1138
1140{
1141 QNullRenderPassDescriptor *rpD = new QNullRenderPassDescriptor(m_rhi);
1142 QRHI_RES_RHI(QRhiNull);
1143 rhiD->registerResource(rpD, false);
1144 return rpD;
1145}
1146
1148{
1149 const bool needsRegistration = !window || window != m_window;
1150 if (window && window != m_window)
1151 destroy();
1152
1153 window = m_window;
1154 m_currentPixelSize = surfacePixelSize();
1155 rt.setRenderPassDescriptor(m_renderPassDesc); // for the public getter in QRhiRenderTarget
1156 rt.d.rp = QRHI_RES(QNullRenderPassDescriptor, m_renderPassDesc);
1157 rt.d.pixelSize = m_currentPixelSize;
1158 frameCount = 0;
1159
1160 if (needsRegistration) {
1161 QRHI_RES_RHI(QRhiNull);
1162 rhiD->registerResource(this);
1163 }
1164
1165 return true;
1166}
1167
1168QT_END_NAMESPACE
void setShaderResources(QRhiCommandBuffer *cb, QRhiShaderResourceBindings *srb, int dynamicOffsetCount, const QRhiCommandBuffer::DynamicOffset *dynamicOffsets) override
Definition qrhinull.cpp:267
double lastCompletedGpuTime(QRhiCommandBuffer *cb) override
Definition qrhinull.cpp:452
QRhi::FrameOpResult endOffscreenFrame(QRhi::EndFrameFlags flags) override
Definition qrhinull.cpp:481
void setPushConstants(QRhiCommandBuffer *cb, quint32 offset, quint32 size, const void *data) override
Definition qrhinull.cpp:314
void dispatchIndirect(QRhiCommandBuffer *cb, QRhiBuffer *indirectBuffer, quint32 indirectBufferOffset) override
Definition qrhinull.cpp:428
bool isFeatureSupported(QRhi::Feature feature) const override
Definition qrhinull.cpp:114
void debugMarkMsg(QRhiCommandBuffer *cb, const QByteArray &msg) override
Definition qrhinull.cpp:408
void dispatch(QRhiCommandBuffer *cb, int x, int y, int z) override
Definition qrhinull.cpp:420
QRhi::FrameOpResult beginFrame(QRhiSwapChain *swapChain, QRhi::BeginFrameFlags flags) override
Definition qrhinull.cpp:458
void resourceUpdate(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch *resourceUpdates) override
Definition qrhinull.cpp:566
void drawIndexed(QRhiCommandBuffer *cb, quint32 indexCount, quint32 instanceCount, quint32 firstIndex, qint32 vertexOffset, quint32 firstInstance) override
Definition qrhinull.cpp:338
void beginComputePass(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch *resourceUpdates, QRhiCommandBuffer::BeginPassFlags flags) override
Definition qrhinull.cpp:669
void beginPass(QRhiCommandBuffer *cb, QRhiRenderTarget *rt, const QColor &colorClearValue, const QRhiDepthStencilClearValue &depthStencilClearValue, QRhiResourceUpdateBatch *resourceUpdates, QRhiCommandBuffer::BeginPassFlags flags) override
Definition qrhinull.cpp:642
bool isClipDepthZeroToOne() const override
Definition qrhinull.cpp:97
void endComputePass(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch *resourceUpdates) override
Definition qrhinull.cpp:678
void endPass(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch *resourceUpdates) override
Definition qrhinull.cpp:663
QRhi::FrameOpResult endFrame(QRhiSwapChain *swapChain, QRhi::EndFrameFlags flags) override
Definition qrhinull.cpp:465
QRhi::FrameOpResult beginOffscreenFrame(QRhiCommandBuffer **cb, QRhi::BeginFrameFlags flags) override
Definition qrhinull.cpp:474
bool isYUpInNDC() const override
Definition qrhinull.cpp:92
QRhiDriverInfo driverInfo() const override
Definition qrhinull.cpp:171
void setScissor(QRhiCommandBuffer *cb, const QRhiScissor &scissor) override
Definition qrhinull.cpp:296
void simulateTextureUpload(const QRhiResourceUpdateBatchPrivate::TextureOp &u)
Definition qrhinull.cpp:492
QRhiComputePipeline * createComputePipeline() override
Definition qrhinull.cpp:251
void setPipelineCacheData(const QByteArray &data) override
Definition qrhinull.cpp:209
void setVertexInput(QRhiCommandBuffer *cb, int startBinding, int bindingCount, const QRhiCommandBuffer::VertexInput *bindings, QRhiBuffer *indexBuf, quint32 indexOffset, QRhiCommandBuffer::IndexFormat indexFormat) override
Definition qrhinull.cpp:277
void debugMarkBegin(QRhiCommandBuffer *cb, const QByteArray &name) override
Definition qrhinull.cpp:397
void draw(QRhiCommandBuffer *cb, quint32 vertexCount, quint32 instanceCount, quint32 firstVertex, quint32 firstInstance) override
Definition qrhinull.cpp:328
QByteArray pipelineCacheData() override
Definition qrhinull.cpp:204
void drawIndirectCount(QRhiCommandBuffer *cb, QRhiBuffer *indirectBuffer, quint32 indirectBufferOffset, QRhiBuffer *countBuffer, quint32 countBufferOffset, quint32 maxDrawCount, quint32 stride) override
Definition qrhinull.cpp:369
void drawIndexedIndirectCount(QRhiCommandBuffer *cb, QRhiBuffer *indirectBuffer, quint32 indirectBufferOffset, QRhiBuffer *countBuffer, quint32 countBufferOffset, quint32 maxDrawCount, quint32 stride) override
Definition qrhinull.cpp:383
void destroy() override
Definition qrhinull.cpp:57
const QRhiNativeHandles * nativeHandles() override
Definition qrhinull.cpp:166
void setGraphicsPipeline(QRhiCommandBuffer *cb, QRhiGraphicsPipeline *ps) override
Definition qrhinull.cpp:261
void releaseCachedResources() override
Definition qrhinull.cpp:194
void simulateTextureCopy(const QRhiResourceUpdateBatchPrivate::TextureOp &u)
Definition qrhinull.cpp:542
QRhiTexture * createTexture(QRhiTexture::Format format, const QSize &pixelSize, int depth, int arraySize, int sampleCount, QRhiTexture::Flags flags) override
Definition qrhinull.cpp:221
QList< QSize > supportedShadingRates(int sampleCount) const override
Definition qrhinull.cpp:66
void simulateTextureGenMips(const QRhiResourceUpdateBatchPrivate::TextureOp &u)
Definition qrhinull.cpp:557
void setShadingRate(QRhiCommandBuffer *cb, const QSize &coarsePixelSize) override
Definition qrhinull.cpp:322
bool makeThreadLocalNativeContextCurrent() override
Definition qrhinull.cpp:183
void drawIndirect(QRhiCommandBuffer *cb, QRhiBuffer *indirectBuffer, quint32 indirectBufferOffset, quint32 drawCount, quint32 stride) override
Definition qrhinull.cpp:349
const QRhiNativeHandles * nativeHandles(QRhiCommandBuffer *cb) override
Definition qrhinull.cpp:436
bool isYUpInFramebuffer() const override
Definition qrhinull.cpp:87
QRhi::FrameOpResult finish() override
Definition qrhinull.cpp:487
void setComputePipeline(QRhiCommandBuffer *cb, QRhiComputePipeline *ps) override
Definition qrhinull.cpp:414
QRhiStats statistics() override
Definition qrhinull.cpp:178
QRhiShadingRateMap * createShadingRateMap() override
Definition qrhinull.cpp:241
void beginExternal(QRhiCommandBuffer *cb) override
Definition qrhinull.cpp:442
QRhiSwapChain * createSwapChain() override
Definition qrhinull.cpp:72
void setViewport(QRhiCommandBuffer *cb, const QRhiViewport &viewport) override
Definition qrhinull.cpp:290
QRhiTextureRenderTarget * createTextureRenderTarget(const QRhiTextureRenderTargetDescription &desc, QRhiTextureRenderTarget::Flags flags) override
Definition qrhinull.cpp:235
QRhiGraphicsPipeline * createGraphicsPipeline() override
Definition qrhinull.cpp:246
bool create(QRhi::Flags flags) override
Definition qrhinull.cpp:51
void setStencilRef(QRhiCommandBuffer *cb, quint32 refValue) override
Definition qrhinull.cpp:308
void debugMarkEnd(QRhiCommandBuffer *cb) override
Definition qrhinull.cpp:403
QList< int > supportedSampleCounts() const override
Definition qrhinull.cpp:61
QMatrix4x4 clipSpaceCorrMatrix() const override
Definition qrhinull.cpp:102
QRhiSampler * createSampler(QRhiSampler::Filter magFilter, QRhiSampler::Filter minFilter, QRhiSampler::Filter mipmapMode, QRhiSampler::AddressMode u, QRhiSampler::AddressMode v, QRhiSampler::AddressMode w) override
Definition qrhinull.cpp:228
void drawIndexedIndirect(QRhiCommandBuffer *cb, QRhiBuffer *indirectBuffer, quint32 indirectBufferOffset, quint32 drawCount, quint32 stride) override
Definition qrhinull.cpp:359
QRhiSwapChain * currentSwapChain
Definition qrhinull_p.h:312
int ubufAlignment() const override
Definition qrhinull.cpp:82
bool isTextureFormatSupported(QRhiTexture::Format format, QRhiTexture::Flags flags) const override
Definition qrhinull.cpp:107
int resourceLimit(QRhi::ResourceLimit limit) const override
Definition qrhinull.cpp:120
QRhiShaderResourceBindings * createShaderResourceBindings() override
Definition qrhinull.cpp:256
void setBlendConstants(QRhiCommandBuffer *cb, const QColor &c) override
Definition qrhinull.cpp:302
void endExternal(QRhiCommandBuffer *cb) override
Definition qrhinull.cpp:447
bool isDeviceLost() const override
Definition qrhinull.cpp:199
static QRhiResourceUpdateBatchPrivate * get(QRhiResourceUpdateBatch *b)
Definition qrhi_p.h:756
Combined button and popup list for selecting options.
#define QRHI_RES_RHI(t)
Definition qrhi_p.h:33
#define QRHI_RES(t, x)
Definition qrhi_p.h:32
char * data
Definition qrhinull_p.h:31
QNullBuffer(QRhiImplementation *rhi, Type type, UsageFlags usage, quint32 size)
Definition qrhinull.cpp:684
bool create() override
Creates the corresponding native graphics resources.
Definition qrhinull.cpp:704
void destroy() override
Releases (or requests deferred releasing of) the underlying native graphics resources.
Definition qrhinull.cpp:694
char * beginFullDynamicBufferUpdateForCurrentFrame() override
Definition qrhinull.cpp:718
QNullCommandBuffer(QRhiImplementation *rhi)
void destroy() override
Releases (or requests deferred releasing of) the underlying native graphics resources.
void destroy() override
Releases (or requests deferred releasing of) the underlying native graphics resources.
bool create() override
QNullComputePipeline(QRhiImplementation *rhi)
void destroy() override
Releases (or requests deferred releasing of) the underlying native graphics resources.
bool create() override
Creates the corresponding native graphics resources.
QNullGraphicsPipeline(QRhiImplementation *rhi)
void destroy() override
Releases (or requests deferred releasing of) the underlying native graphics resources.
Definition qrhinull.cpp:736
bool create() override
Creates the corresponding native graphics resources.
Definition qrhinull.cpp:745
QNullRenderBuffer(QRhiImplementation *rhi, Type type, const QSize &pixelSize, int sampleCount, QRhiRenderBuffer::Flags flags, QRhiTexture::Format backingFormatHint)
Definition qrhinull.cpp:724
QRhiTexture::Format backingFormat() const override
Definition qrhinull.cpp:759
QNullRenderPassDescriptor(QRhiImplementation *rhi)
Definition qrhinull.cpp:869
QRhiRenderPassDescriptor * newCompatibleRenderPassDescriptor() const override
Definition qrhinull.cpp:892
QVector< quint32 > serializedFormat() const override
Definition qrhinull.cpp:900
void destroy() override
Releases (or requests deferred releasing of) the underlying native graphics resources.
Definition qrhinull.cpp:879
bool isCompatible(const QRhiRenderPassDescriptor *other) const override
Definition qrhinull.cpp:886
void destroy() override
Releases (or requests deferred releasing of) the underlying native graphics resources.
Definition qrhinull.cpp:855
QNullSampler(QRhiImplementation *rhi, Filter magFilter, Filter minFilter, Filter mipmapMode, AddressMode u, AddressMode v, AddressMode w)
Definition qrhinull.cpp:844
bool create() override
Definition qrhinull.cpp:862
QNullShaderResourceBindings(QRhiImplementation *rhi)
bool create() override
Creates the corresponding resource binding set.
void updateResources(UpdateFlags flags) override
void destroy() override
Releases (or requests deferred releasing of) the underlying native graphics resources.
QSize pixelSize() const override
Definition qrhinull.cpp:920
float devicePixelRatio() const override
Definition qrhinull.cpp:925
QNullSwapChainRenderTarget(QRhiImplementation *rhi, QRhiSwapChain *swapchain)
Definition qrhinull.cpp:905
int sampleCount() const override
Definition qrhinull.cpp:930
void destroy() override
Releases (or requests deferred releasing of) the underlying native graphics resources.
Definition qrhinull.cpp:916
bool createOrResize() override
Creates the swapchain if not already done and resizes the swapchain buffers to match the current size...
QWindow * window
Definition qrhinull_p.h:167
QSize surfacePixelSize() override
bool isFormatSupported(Format f) override
void destroy() override
Releases (or requests deferred releasing of) the underlying native graphics resources.
QRhiCommandBuffer * currentFrameCommandBuffer() override
QRhiRenderPassDescriptor * newCompatibleRenderPassDescriptor() override
QRhiRenderTarget * currentFrameRenderTarget() override
QNullSwapChain(QRhiImplementation *rhi)
QSize pixelSize() const override
Definition qrhinull.cpp:982
int sampleCount() const override
Definition qrhinull.cpp:995
void destroy() override
Releases (or requests deferred releasing of) the underlying native graphics resources.
Definition qrhinull.cpp:948
QRhiRenderPassDescriptor * newCompatibleRenderPassDescriptor() override
Definition qrhinull.cpp:955
bool create() override
Creates the corresponding native graphics resources.
Definition qrhinull.cpp:963
QNullTextureRenderTarget(QRhiImplementation *rhi, const QRhiTextureRenderTargetDescription &desc, Flags flags)
Definition qrhinull.cpp:935
float devicePixelRatio() const override
Definition qrhinull.cpp:990
bool create() override
Creates the corresponding native graphics resources.
Definition qrhinull.cpp:784
bool createFrom(NativeTexture src) override
Similar to create(), except that no new native textures are created.
Definition qrhinull.cpp:828
QNullTexture(QRhiImplementation *rhi, Format format, const QSize &pixelSize, int depth, int arraySize, int sampleCount, Flags flags)
Definition qrhinull.cpp:764
uint generation
Definition qrhinull_p.h:59
void destroy() override
Releases (or requests deferred releasing of) the underlying native graphics resources.
Definition qrhinull.cpp:775
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:1993