12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
35
36
37
38
39
40
41
42
43
46 : offscreenCommandBuffer(
this)
68 Q_UNUSED(sampleCount);
69 return { QSize(1, 1) };
74 return new QNullSwapChain(
this);
77QRhiBuffer *
QRhiNull::createBuffer(QRhiBuffer::Type type, QRhiBuffer::UsageFlags usage, quint32 size)
79 return new QNullBuffer(
this, type, usage, size);
123 case QRhi::TextureSizeMin:
125 case QRhi::TextureSizeMax:
127 case QRhi::MaxColorAttachments:
129 case QRhi::FramesInFlight:
131 case QRhi::MaxAsyncReadbackFrames:
133 case QRhi::MaxThreadGroupsPerDimension:
135 case QRhi::MaxThreadsPerThreadGroup:
137 case QRhi::MaxThreadGroupX:
139 case QRhi::MaxThreadGroupY:
141 case QRhi::MaxThreadGroupZ:
143 case QRhi::TextureArraySizeMax:
145 case QRhi::MaxUniformBufferRange:
147 case QRhi::MaxVertexInputs:
149 case QRhi::MaxVertexOutputs:
151 case QRhi::ShadingRateImageTileSize:
155 Q_UNREACHABLE_RETURN(0);
160 return &nativeHandlesStruct;
166 info.deviceName = QByteArrayLiteral(
"Null");
181void QRhiNull::setQueueSubmitParams(QRhiNativeHandles *)
206QRhiRenderBuffer *
QRhiNull::createRenderBuffer(QRhiRenderBuffer::Type type,
const QSize &pixelSize,
207 int sampleCount, QRhiRenderBuffer::Flags flags,
208 QRhiTexture::Format backingFormatHint)
210 return new QNullRenderBuffer(
this, type, pixelSize, sampleCount, flags, backingFormatHint);
214 const QSize &pixelSize,
int depth,
int arraySize,
215 int sampleCount, QRhiTexture::Flags flags)
217 return new QNullTexture(
this, format, pixelSize, depth, arraySize, sampleCount, flags);
221 QRhiSampler::Filter mipmapMode,
222 QRhiSampler::AddressMode u, QRhiSampler::AddressMode v, QRhiSampler::AddressMode w)
224 return new QNullSampler(
this, magFilter, minFilter, mipmapMode, u, v, w);
228 QRhiTextureRenderTarget::Flags flags)
240 return new QNullGraphicsPipeline(
this);
245 return new QNullComputePipeline(
this);
250 return new QNullShaderResourceBindings(
this);
260 int dynamicOffsetCount,
261 const QRhiCommandBuffer::DynamicOffset *dynamicOffsets)
265 Q_UNUSED(dynamicOffsetCount);
266 Q_UNUSED(dynamicOffsets);
270 int startBinding,
int bindingCount,
const QRhiCommandBuffer::VertexInput *bindings,
271 QRhiBuffer *indexBuf, quint32 indexOffset, QRhiCommandBuffer::IndexFormat indexFormat)
274 Q_UNUSED(startBinding);
275 Q_UNUSED(bindingCount);
278 Q_UNUSED(indexOffset);
279 Q_UNUSED(indexFormat);
309 Q_UNUSED(coarsePixelSize);
313 quint32 instanceCount, quint32 firstVertex, quint32 firstInstance)
316 Q_UNUSED(vertexCount);
317 Q_UNUSED(instanceCount);
318 Q_UNUSED(firstVertex);
319 Q_UNUSED(firstInstance);
323 quint32 instanceCount, quint32 firstIndex, qint32 vertexOffset, quint32 firstInstance)
326 Q_UNUSED(indexCount);
327 Q_UNUSED(instanceCount);
328 Q_UNUSED(firstIndex);
329 Q_UNUSED(vertexOffset);
330 Q_UNUSED(firstInstance);
334 quint32 indirectBufferOffset, quint32 drawCount, quint32 stride)
337 Q_UNUSED(indirectBuffer);
338 Q_UNUSED(indirectBufferOffset);
344 quint32 indirectBufferOffset, quint32 drawCount, quint32 stride)
347 Q_UNUSED(indirectBuffer);
348 Q_UNUSED(indirectBufferOffset);
410 return QRhi::FrameOpSuccess;
419 return QRhi::FrameOpSuccess;
425 *cb = &offscreenCommandBuffer;
426 return QRhi::FrameOpSuccess;
432 return QRhi::FrameOpSuccess;
437 return QRhi::FrameOpSuccess;
443 for (
int layer = 0, maxLayer = u.subresDesc.size(); layer < maxLayer; ++layer) {
444 for (
int level = 0; level < QRhi::MAX_MIP_LEVELS; ++level) {
445 for (
const QRhiTextureSubresourceUploadDescription &subresDesc : std::as_const(u.subresDesc[layer][level])) {
446 if (!subresDesc.image().isNull()) {
447 const QImage src = subresDesc.image();
448 QPainter painter(&texD->image[layer][level]);
449 const QSize srcSize = subresDesc.sourceSize().isEmpty()
450 ? src.size() : subresDesc.sourceSize();
451 painter.setCompositionMode(QPainter::CompositionMode_Source);
452 painter.drawImage(subresDesc.destinationTopLeft(), src,
453 QRect(subresDesc.sourceTopLeft(), srcSize));
454 }
else if (!subresDesc.data().isEmpty()) {
455 const QSize subresSize = q->sizeForMipLevel(level, texD->pixelSize());
456 int w = subresSize.width();
457 int h = subresSize.height();
458 if (!subresDesc.sourceSize().isEmpty()) {
459 w = subresDesc.sourceSize().width();
460 h = subresDesc.sourceSize().height();
463 const QByteArray srcData = subresDesc.data();
464 const QPoint dstOffset = subresDesc.destinationTopLeft();
465 QSize size = clampedSubResourceUploadSize(QSize(w, h), dstOffset, level,
467 size = clampedSubResourceUploadSizeForSourceData(size, subresDesc.dataStride(),
473 const char *src = srcData.constData();
474 const int srcBpl = w * 4;
475 int srcStride = srcBpl;
476 if (subresDesc.dataStride())
477 srcStride = subresDesc.dataStride();
478 uchar *dst = texD->image[layer][level].bits();
479 const int dstBpl = texD->image[layer][level].bytesPerLine();
480 for (
int y = 0; y < h; ++y) {
481 memcpy(dst + dstOffset.x() * 4 + (y + dstOffset.y()) * dstBpl,
495 const QImage &srcImage(srcD->image[u.desc.sourceLayer()][u.desc.sourceLevel()]);
496 QImage &dstImage(dstD->image[u.desc.destinationLayer()][u.desc.destinationLevel()]);
497 const QPoint dstPos = u.desc.destinationTopLeft();
498 const QSize size = u.desc.pixelSize().isEmpty() ? srcD->pixelSize() : u.desc.pixelSize();
499 const QPoint srcPos = u.desc.sourceTopLeft();
501 QPainter painter(&dstImage);
502 painter.setCompositionMode(QPainter::CompositionMode_Source);
503 painter.drawImage(QRect(dstPos, size), srcImage, QRect(srcPos, size));
509 const QSize baseSize = texD->pixelSize();
510 const int levelCount = q->mipLevelsForSize(baseSize);
511 for (
int level = 1; level < levelCount; ++level)
512 texD->image[0][level] = texD->image[0][0].scaled(q->sizeForMipLevel(level, baseSize));
527 QRhiReadbackResult *result = u.result;
528 result->data.resize(u.readSize);
530 memcpy(result->data.data(), bufD
->data + u.offset, size_t(u.readSize));
531 if (result->completed)
538 if (u.dst->format() == QRhiTexture::RGBA8)
541 if (u.src->format() == QRhiTexture::RGBA8 && u.dst->format() == QRhiTexture::RGBA8)
544 QRhiReadbackResult *result = u.result;
547 result->format = texD->format();
548 if (u.rb.rect().isValid())
549 result->pixelSize = u.rb.rect().size();
551 result->pixelSize = q->sizeForMipLevel(u.rb.level(), texD->pixelSize());
554 result->format = QRhiTexture::RGBA8;
555 if (u.rb.rect().isValid())
556 result->pixelSize = u.rb.rect().size();
560 quint32 bytesPerLine = 0;
561 quint32 byteSize = 0;
562 textureFormatInfo(result->format, result->pixelSize, &bytesPerLine, &byteSize,
nullptr);
563 if (texD && texD->format() == QRhiTexture::RGBA8) {
564 result->data.resize(
int(byteSize));
565 const QImage &src(texD->image[u.rb.layer()][u.rb.level()]);
566 char *dst = result->data.data();
567 for (
int y = 0, h = src.height(); y < h; ++y) {
568 memcpy(dst, src.constScanLine(y), bytesPerLine);
572 result->data.fill(0,
int(byteSize));
574 if (result->completed)
577 if (u.dst->format() == QRhiTexture::RGBA8)
585 QRhiRenderTarget *rt,
586 const QColor &colorClearValue,
587 const QRhiDepthStencilClearValue &depthStencilClearValue,
588 QRhiResourceUpdateBatch *resourceUpdates,
589 QRhiCommandBuffer::BeginPassFlags flags)
591 Q_UNUSED(colorClearValue);
592 Q_UNUSED(depthStencilClearValue);
598 if (rt->resourceType() == QRhiRenderTarget::TextureRenderTarget) {
600 if (!QRhiRenderTargetAttachmentTracker::isUpToDate<QNullTexture, QNullRenderBuffer>(rtTex->description(), rtTex->d.currentResIdList))
605void QRhiNull::
endPass(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch *resourceUpdates)
612 QRhiResourceUpdateBatch *resourceUpdates,
613 QRhiCommandBuffer::BeginPassFlags flags)
643 rhiD->unregisterResource(
this);
651 data =
new char[m_size];
652 memset(
data, 0, m_size);
655 rhiD->registerResource(
this);
662 Q_ASSERT(m_type == Dynamic);
667 int sampleCount, QRhiRenderBuffer::Flags flags,
668 QRhiTexture::Format backingFormatHint)
684 rhiD->unregisterResource(
this);
696 rhiD->registerResource(
this);
703 return m_type == Color ? QRhiTexture::RGBA8 : QRhiTexture::UnknownFormat;
707 int arraySize,
int sampleCount, Flags flags)
723 rhiD->unregisterResource(
this);
734 const bool isCube = m_flags.testFlag(CubeMap);
735 const bool is3D = m_flags.testFlag(ThreeDimensional);
736 const bool isArray = m_flags.testFlag(TextureArray);
737 const bool hasMipMaps = m_flags.testFlag(MipMapped);
738 const bool is1D = m_flags.testFlags(OneDimensional);
739 QSize size = is1D ? QSize(qMax(1, m_pixelSize.width()), 1)
740 : (m_pixelSize.isEmpty() ? QSize(1, 1) : m_pixelSize);
741 const int mipLevelCount = hasMipMaps ? rhiD->q->mipLevelsForSize(size) : 1;
742 const int layerCount = is3D ? qMax(1, m_depth)
744 : (isArray ? qMax(0, m_arraySize)
747 if (!rhiD->textureFormatInfo(m_format, size,
nullptr,
nullptr,
nullptr)) {
752 if (m_format == RGBA8) {
753 image.resize(layerCount);
754 for (
int layer = 0; layer < layerCount; ++layer) {
755 for (
int level = 0; level < mipLevelCount; ++level) {
756 image[layer][level] = QImage(rhiD->q->sizeForMipLevel(level, size),
757 QImage::Format_RGBA8888_Premultiplied);
758 image[layer][level].fill(Qt::yellow);
765 rhiD->registerResource(
this);
781 rhiD->registerResource(
this);
787 AddressMode u, AddressMode v, AddressMode w)
801 rhiD->unregisterResource(
this);
807 rhiD->registerResource(
this);
825 rhiD->unregisterResource(
this);
838 rhiD->registerResource(rpD,
false);
878 const QRhiTextureRenderTargetDescription &desc,
894 rhiD->unregisterResource(
this);
901 rhiD->registerResource(rpD,
false);
908 d.rp =
QRHI_RES(QNullRenderPassDescriptor, m_renderPassDesc);
909 if (m_desc.cbeginColorAttachments() != m_desc.cendColorAttachments()) {
910 const QRhiColorAttachment *colorAtt = m_desc.cbeginColorAttachments();
911 QRhiTexture *tex = colorAtt->texture();
912 QRhiRenderBuffer *rb = colorAtt->renderBuffer();
913 d.pixelSize = tex ? rhiD->q->sizeForMipLevel(colorAtt->level(), tex->pixelSize()) : rb->pixelSize();
914 }
else if (m_desc.depthStencilBuffer()) {
915 d.pixelSize = m_desc.depthStencilBuffer()->pixelSize();
916 }
else if (m_desc.depthTexture()) {
917 d.pixelSize = m_desc.depthTexture()->pixelSize();
919 QRhiRenderTargetAttachmentTracker::updateResIdList<QNullTexture, QNullRenderBuffer>(m_desc, &d.currentResIdList);
920 rhiD->registerResource(
this);
926 if (!QRhiRenderTargetAttachmentTracker::isUpToDate<QNullTexture, QNullRenderBuffer>(m_desc, d.currentResIdList))
956 rhiD->unregisterResource(
this);
962 if (!rhiD->sanityCheckShaderResourceBindings(
this))
965 rhiD->updateLayoutDesc(
this);
967 rhiD->registerResource(
this,
false);
990 rhiD->unregisterResource(
this);
996 if (!rhiD->sanityCheckGraphicsPipeline(
this))
999 rhiD->registerResource(
this);
1017 rhiD->unregisterResource(
this);
1023 rhiD->registerResource(
this);
1058 rhiD->unregisterResource(
this);
1073 return QSize(1280, 720);
1085 rhiD->registerResource(rpD,
false);
1091 const bool needsRegistration = !window || window != m_window;
1092 if (window && window != m_window)
1096 m_currentPixelSize = surfacePixelSize();
1097 rt.setRenderPassDescriptor(m_renderPassDesc);
1098 rt.d.rp =
QRHI_RES(QNullRenderPassDescriptor, m_renderPassDesc);
1099 rt.d.pixelSize = m_currentPixelSize;
1102 if (needsRegistration) {
1104 rhiD->registerResource(
this);
const char * constData() const
void setShaderResources(QRhiCommandBuffer *cb, QRhiShaderResourceBindings *srb, int dynamicOffsetCount, const QRhiCommandBuffer::DynamicOffset *dynamicOffsets) override
double lastCompletedGpuTime(QRhiCommandBuffer *cb) override
QRhi::FrameOpResult endOffscreenFrame(QRhi::EndFrameFlags flags) override
bool isFeatureSupported(QRhi::Feature feature) const override
void debugMarkMsg(QRhiCommandBuffer *cb, const QByteArray &msg) override
void dispatch(QRhiCommandBuffer *cb, int x, int y, int z) override
QRhi::FrameOpResult beginFrame(QRhiSwapChain *swapChain, QRhi::BeginFrameFlags flags) override
void resourceUpdate(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch *resourceUpdates) override
void drawIndexed(QRhiCommandBuffer *cb, quint32 indexCount, quint32 instanceCount, quint32 firstIndex, qint32 vertexOffset, quint32 firstInstance) override
void beginComputePass(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch *resourceUpdates, QRhiCommandBuffer::BeginPassFlags flags) override
void beginPass(QRhiCommandBuffer *cb, QRhiRenderTarget *rt, const QColor &colorClearValue, const QRhiDepthStencilClearValue &depthStencilClearValue, QRhiResourceUpdateBatch *resourceUpdates, QRhiCommandBuffer::BeginPassFlags flags) override
bool isClipDepthZeroToOne() const override
void endComputePass(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch *resourceUpdates) override
void endPass(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch *resourceUpdates) override
QRhi::FrameOpResult endFrame(QRhiSwapChain *swapChain, QRhi::EndFrameFlags flags) override
QRhi::FrameOpResult beginOffscreenFrame(QRhiCommandBuffer **cb, QRhi::BeginFrameFlags flags) override
bool isYUpInNDC() const override
QRhiDriverInfo driverInfo() const override
void setScissor(QRhiCommandBuffer *cb, const QRhiScissor &scissor) override
void simulateTextureUpload(const QRhiResourceUpdateBatchPrivate::TextureOp &u)
QRhiComputePipeline * createComputePipeline() override
void setPipelineCacheData(const QByteArray &data) override
void setVertexInput(QRhiCommandBuffer *cb, int startBinding, int bindingCount, const QRhiCommandBuffer::VertexInput *bindings, QRhiBuffer *indexBuf, quint32 indexOffset, QRhiCommandBuffer::IndexFormat indexFormat) override
void debugMarkBegin(QRhiCommandBuffer *cb, const QByteArray &name) override
void draw(QRhiCommandBuffer *cb, quint32 vertexCount, quint32 instanceCount, quint32 firstVertex, quint32 firstInstance) override
QByteArray pipelineCacheData() override
const QRhiNativeHandles * nativeHandles() override
void setGraphicsPipeline(QRhiCommandBuffer *cb, QRhiGraphicsPipeline *ps) override
void releaseCachedResources() override
void simulateTextureCopy(const QRhiResourceUpdateBatchPrivate::TextureOp &u)
QRhiTexture * createTexture(QRhiTexture::Format format, const QSize &pixelSize, int depth, int arraySize, int sampleCount, QRhiTexture::Flags flags) override
QList< QSize > supportedShadingRates(int sampleCount) const override
void simulateTextureGenMips(const QRhiResourceUpdateBatchPrivate::TextureOp &u)
void setShadingRate(QRhiCommandBuffer *cb, const QSize &coarsePixelSize) override
bool makeThreadLocalNativeContextCurrent() override
void drawIndirect(QRhiCommandBuffer *cb, QRhiBuffer *indirectBuffer, quint32 indirectBufferOffset, quint32 drawCount, quint32 stride) override
const QRhiNativeHandles * nativeHandles(QRhiCommandBuffer *cb) override
bool isYUpInFramebuffer() const override
QRhi::FrameOpResult finish() override
void setComputePipeline(QRhiCommandBuffer *cb, QRhiComputePipeline *ps) override
QRhiStats statistics() override
QRhiShadingRateMap * createShadingRateMap() override
void beginExternal(QRhiCommandBuffer *cb) override
QRhiSwapChain * createSwapChain() override
void setViewport(QRhiCommandBuffer *cb, const QRhiViewport &viewport) override
QRhiTextureRenderTarget * createTextureRenderTarget(const QRhiTextureRenderTargetDescription &desc, QRhiTextureRenderTarget::Flags flags) override
QRhiGraphicsPipeline * createGraphicsPipeline() override
bool create(QRhi::Flags flags) override
void setStencilRef(QRhiCommandBuffer *cb, quint32 refValue) override
void debugMarkEnd(QRhiCommandBuffer *cb) override
QList< int > supportedSampleCounts() const override
QMatrix4x4 clipSpaceCorrMatrix() const override
QRhiSampler * createSampler(QRhiSampler::Filter magFilter, QRhiSampler::Filter minFilter, QRhiSampler::Filter mipmapMode, QRhiSampler::AddressMode u, QRhiSampler::AddressMode v, QRhiSampler::AddressMode w) override
void drawIndexedIndirect(QRhiCommandBuffer *cb, QRhiBuffer *indirectBuffer, quint32 indirectBufferOffset, quint32 drawCount, quint32 stride) override
QRhiSwapChain * currentSwapChain
int ubufAlignment() const override
bool isTextureFormatSupported(QRhiTexture::Format format, QRhiTexture::Flags flags) const override
int resourceLimit(QRhi::ResourceLimit limit) const override
QRhiShaderResourceBindings * createShaderResourceBindings() override
void setBlendConstants(QRhiCommandBuffer *cb, const QColor &c) override
void endExternal(QRhiCommandBuffer *cb) override
bool isDeviceLost() const override
static QRhiResourceUpdateBatchPrivate * get(QRhiResourceUpdateBatch *b)
Combined button and popup list for selecting options.
QNullBuffer(QRhiImplementation *rhi, Type type, UsageFlags usage, quint32 size)
bool create() override
Creates the corresponding native graphics resources.
void destroy() override
Releases (or requests deferred releasing of) the underlying native graphics resources.
char * beginFullDynamicBufferUpdateForCurrentFrame() override
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.
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.
bool create() override
Creates the corresponding native graphics resources.
QNullRenderBuffer(QRhiImplementation *rhi, Type type, const QSize &pixelSize, int sampleCount, QRhiRenderBuffer::Flags flags, QRhiTexture::Format backingFormatHint)
QRhiTexture::Format backingFormat() const override
QNullRenderPassDescriptor(QRhiImplementation *rhi)
QRhiRenderPassDescriptor * newCompatibleRenderPassDescriptor() const override
~QNullRenderPassDescriptor()
QVector< quint32 > serializedFormat() const override
void destroy() override
Releases (or requests deferred releasing of) the underlying native graphics resources.
bool isCompatible(const QRhiRenderPassDescriptor *other) const override
void destroy() override
Releases (or requests deferred releasing of) the underlying native graphics resources.
QNullSampler(QRhiImplementation *rhi, Filter magFilter, Filter minFilter, Filter mipmapMode, AddressMode u, AddressMode v, AddressMode w)
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.
~QNullShaderResourceBindings()
QSize pixelSize() const override
float devicePixelRatio() const override
~QNullSwapChainRenderTarget()
QNullSwapChainRenderTarget(QRhiImplementation *rhi, QRhiSwapChain *swapchain)
int sampleCount() const override
void destroy() override
Releases (or requests deferred releasing of) the underlying native graphics resources.
bool createOrResize() override
Creates the swapchain if not already done and resizes the swapchain buffers to match the current size...
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)
~QNullTextureRenderTarget()
QSize pixelSize() const override
int sampleCount() const override
void destroy() override
Releases (or requests deferred releasing of) the underlying native graphics resources.
QRhiRenderPassDescriptor * newCompatibleRenderPassDescriptor() override
bool create() override
Creates the corresponding native graphics resources.
QNullTextureRenderTarget(QRhiImplementation *rhi, const QRhiTextureRenderTargetDescription &desc, Flags flags)
float devicePixelRatio() const override
bool create() override
Creates the corresponding native graphics resources.
bool createFrom(NativeTexture src) override
Similar to create(), except that no new native textures are created.
QNullTexture(QRhiImplementation *rhi, Format format, const QSize &pixelSize, int depth, int arraySize, int sampleCount, Flags flags)
void destroy() override
Releases (or requests deferred releasing of) the underlying native graphics resources.
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h