11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
34
35
36
37
38
39
40
41
42
45 : offscreenCommandBuffer(
this)
67 Q_UNUSED(sampleCount);
68 return { QSize(1, 1) };
73 return new QNullSwapChain(
this);
76QRhiBuffer *
QRhiNull::createBuffer(QRhiBuffer::Type type, QRhiBuffer::UsageFlags usage, quint32 size)
78 return new QNullBuffer(
this, type, usage, size);
122 case QRhi::TextureSizeMin:
124 case QRhi::TextureSizeMax:
126 case QRhi::MaxColorAttachments:
128 case QRhi::FramesInFlight:
130 case QRhi::MaxAsyncReadbackFrames:
132 case QRhi::MaxThreadGroupsPerDimension:
134 case QRhi::MaxThreadsPerThreadGroup:
136 case QRhi::MaxThreadGroupX:
138 case QRhi::MaxThreadGroupY:
140 case QRhi::MaxThreadGroupZ:
142 case QRhi::TextureArraySizeMax:
144 case QRhi::MaxUniformBufferRange:
146 case QRhi::MaxVertexInputs:
148 case QRhi::MaxVertexOutputs:
150 case QRhi::ShadingRateImageTileSize:
154 Q_UNREACHABLE_RETURN(0);
159 return &nativeHandlesStruct;
165 info.deviceName = QByteArrayLiteral(
"Null");
180void QRhiNull::setQueueSubmitParams(QRhiNativeHandles *)
205QRhiRenderBuffer *
QRhiNull::createRenderBuffer(QRhiRenderBuffer::Type type,
const QSize &pixelSize,
206 int sampleCount, QRhiRenderBuffer::Flags flags,
207 QRhiTexture::Format backingFormatHint)
209 return new QNullRenderBuffer(
this, type, pixelSize, sampleCount, flags, backingFormatHint);
213 const QSize &pixelSize,
int depth,
int arraySize,
214 int sampleCount, QRhiTexture::Flags flags)
216 return new QNullTexture(
this, format, pixelSize, depth, arraySize, sampleCount, flags);
220 QRhiSampler::Filter mipmapMode,
221 QRhiSampler::AddressMode u, QRhiSampler::AddressMode v, QRhiSampler::AddressMode w)
223 return new QNullSampler(
this, magFilter, minFilter, mipmapMode, u, v, w);
227 QRhiTextureRenderTarget::Flags flags)
239 return new QNullGraphicsPipeline(
this);
244 return new QNullComputePipeline(
this);
249 return new QNullShaderResourceBindings(
this);
259 int dynamicOffsetCount,
260 const QRhiCommandBuffer::DynamicOffset *dynamicOffsets)
264 Q_UNUSED(dynamicOffsetCount);
265 Q_UNUSED(dynamicOffsets);
269 int startBinding,
int bindingCount,
const QRhiCommandBuffer::VertexInput *bindings,
270 QRhiBuffer *indexBuf, quint32 indexOffset, QRhiCommandBuffer::IndexFormat indexFormat)
273 Q_UNUSED(startBinding);
274 Q_UNUSED(bindingCount);
277 Q_UNUSED(indexOffset);
278 Q_UNUSED(indexFormat);
308 Q_UNUSED(coarsePixelSize);
312 quint32 instanceCount, quint32 firstVertex, quint32 firstInstance)
315 Q_UNUSED(vertexCount);
316 Q_UNUSED(instanceCount);
317 Q_UNUSED(firstVertex);
318 Q_UNUSED(firstInstance);
322 quint32 instanceCount, quint32 firstIndex, qint32 vertexOffset, quint32 firstInstance)
325 Q_UNUSED(indexCount);
326 Q_UNUSED(instanceCount);
327 Q_UNUSED(firstIndex);
328 Q_UNUSED(vertexOffset);
329 Q_UNUSED(firstInstance);
389 return QRhi::FrameOpSuccess;
398 return QRhi::FrameOpSuccess;
404 *cb = &offscreenCommandBuffer;
405 return QRhi::FrameOpSuccess;
411 return QRhi::FrameOpSuccess;
416 return QRhi::FrameOpSuccess;
422 for (
int layer = 0, maxLayer = u.subresDesc.size(); layer < maxLayer; ++layer) {
423 for (
int level = 0; level < QRhi::MAX_MIP_LEVELS; ++level) {
424 for (
const QRhiTextureSubresourceUploadDescription &subresDesc : std::as_const(u.subresDesc[layer][level])) {
425 if (!subresDesc.image().isNull()) {
426 const QImage src = subresDesc.image();
427 QPainter painter(&texD->image[layer][level]);
428 const QSize srcSize = subresDesc.sourceSize().isEmpty()
429 ? src.size() : subresDesc.sourceSize();
430 painter.setCompositionMode(QPainter::CompositionMode_Source);
431 painter.drawImage(subresDesc.destinationTopLeft(), src,
432 QRect(subresDesc.sourceTopLeft(), srcSize));
433 }
else if (!subresDesc.data().isEmpty()) {
434 const QSize subresSize = q->sizeForMipLevel(level, texD->pixelSize());
435 int w = subresSize.width();
436 int h = subresSize.height();
437 if (!subresDesc.sourceSize().isEmpty()) {
438 w = subresDesc.sourceSize().width();
439 h = subresDesc.sourceSize().height();
442 const char *src = subresDesc.data().constData();
443 const int srcBpl = w * 4;
444 int srcStride = srcBpl;
445 if (subresDesc.dataStride())
446 srcStride = subresDesc.dataStride();
447 const QPoint dstOffset = subresDesc.destinationTopLeft();
448 uchar *dst = texD->image[layer][level].bits();
449 const int dstBpl = texD->image[layer][level].bytesPerLine();
450 for (
int y = 0; y < h; ++y) {
451 memcpy(dst + dstOffset.x() * 4 + (y + dstOffset.y()) * dstBpl,
465 const QImage &srcImage(srcD->image[u.desc.sourceLayer()][u.desc.sourceLevel()]);
466 QImage &dstImage(dstD->image[u.desc.destinationLayer()][u.desc.destinationLevel()]);
467 const QPoint dstPos = u.desc.destinationTopLeft();
468 const QSize size = u.desc.pixelSize().isEmpty() ? srcD->pixelSize() : u.desc.pixelSize();
469 const QPoint srcPos = u.desc.sourceTopLeft();
471 QPainter painter(&dstImage);
472 painter.setCompositionMode(QPainter::CompositionMode_Source);
473 painter.drawImage(QRect(dstPos, size), srcImage, QRect(srcPos, size));
479 const QSize baseSize = texD->pixelSize();
480 const int levelCount = q->mipLevelsForSize(baseSize);
481 for (
int level = 1; level < levelCount; ++level)
482 texD->image[0][level] = texD->image[0][0].scaled(q->sizeForMipLevel(level, baseSize));
497 QRhiReadbackResult *result = u.result;
498 result->data.resize(u.readSize);
500 memcpy(result->data.data(), bufD
->data + u.offset, size_t(u.readSize));
501 if (result->completed)
508 if (u.dst->format() == QRhiTexture::RGBA8)
511 if (u.src->format() == QRhiTexture::RGBA8 && u.dst->format() == QRhiTexture::RGBA8)
514 QRhiReadbackResult *result = u.result;
517 result->format = texD->format();
518 if (u.rb.rect().isValid())
519 result->pixelSize = u.rb.rect().size();
521 result->pixelSize = q->sizeForMipLevel(u.rb.level(), texD->pixelSize());
524 result->format = QRhiTexture::RGBA8;
525 if (u.rb.rect().isValid())
526 result->pixelSize = u.rb.rect().size();
530 quint32 bytesPerLine = 0;
531 quint32 byteSize = 0;
532 textureFormatInfo(result->format, result->pixelSize, &bytesPerLine, &byteSize,
nullptr);
533 if (texD && texD->format() == QRhiTexture::RGBA8) {
534 result->data.resize(
int(byteSize));
535 const QImage &src(texD->image[u.rb.layer()][u.rb.level()]);
536 char *dst = result->data.data();
537 for (
int y = 0, h = src.height(); y < h; ++y) {
538 memcpy(dst, src.constScanLine(y), bytesPerLine);
542 result->data.fill(0,
int(byteSize));
544 if (result->completed)
547 if (u.dst->format() == QRhiTexture::RGBA8)
555 QRhiRenderTarget *rt,
556 const QColor &colorClearValue,
557 const QRhiDepthStencilClearValue &depthStencilClearValue,
558 QRhiResourceUpdateBatch *resourceUpdates,
559 QRhiCommandBuffer::BeginPassFlags flags)
561 Q_UNUSED(colorClearValue);
562 Q_UNUSED(depthStencilClearValue);
568 if (rt->resourceType() == QRhiRenderTarget::TextureRenderTarget) {
570 if (!QRhiRenderTargetAttachmentTracker::isUpToDate<QNullTexture, QNullRenderBuffer>(rtTex->description(), rtTex->d.currentResIdList))
575void QRhiNull::
endPass(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch *resourceUpdates)
582 QRhiResourceUpdateBatch *resourceUpdates,
583 QRhiCommandBuffer::BeginPassFlags flags)
613 rhiD->unregisterResource(
this);
621 data =
new char[m_size];
622 memset(data, 0, m_size);
625 rhiD->registerResource(
this);
632 Q_ASSERT(m_type == Dynamic);
637 int sampleCount, QRhiRenderBuffer::Flags flags,
638 QRhiTexture::Format backingFormatHint)
654 rhiD->unregisterResource(
this);
666 rhiD->registerResource(
this);
673 return m_type == Color ? QRhiTexture::RGBA8 : QRhiTexture::UnknownFormat;
677 int arraySize,
int sampleCount, Flags flags)
693 rhiD->unregisterResource(
this);
704 const bool isCube = m_flags.testFlag(CubeMap);
705 const bool is3D = m_flags.testFlag(ThreeDimensional);
706 const bool isArray = m_flags.testFlag(TextureArray);
707 const bool hasMipMaps = m_flags.testFlag(MipMapped);
708 const bool is1D = m_flags.testFlags(OneDimensional);
709 QSize size = is1D ? QSize(qMax(1, m_pixelSize.width()), 1)
710 : (m_pixelSize.isEmpty() ? QSize(1, 1) : m_pixelSize);
711 const int mipLevelCount = hasMipMaps ? rhiD->q->mipLevelsForSize(size) : 1;
712 const int layerCount = is3D ? qMax(1, m_depth)
714 : (isArray ? qMax(0, m_arraySize)
717 if (m_format == RGBA8) {
718 image.resize(layerCount);
719 for (
int layer = 0; layer < layerCount; ++layer) {
720 for (
int level = 0; level < mipLevelCount; ++level) {
721 image[layer][level] = QImage(rhiD->q->sizeForMipLevel(level, size),
722 QImage::Format_RGBA8888_Premultiplied);
723 image[layer][level].fill(Qt::yellow);
730 rhiD->registerResource(
this);
746 rhiD->registerResource(
this);
752 AddressMode u, AddressMode v, AddressMode w)
766 rhiD->unregisterResource(
this);
772 rhiD->registerResource(
this);
790 rhiD->unregisterResource(
this);
803 rhiD->registerResource(rpD,
false);
843 const QRhiTextureRenderTargetDescription &desc,
859 rhiD->unregisterResource(
this);
866 rhiD->registerResource(rpD,
false);
873 d.rp =
QRHI_RES(QNullRenderPassDescriptor, m_renderPassDesc);
874 if (m_desc.cbeginColorAttachments() != m_desc.cendColorAttachments()) {
875 const QRhiColorAttachment *colorAtt = m_desc.cbeginColorAttachments();
876 QRhiTexture *tex = colorAtt->texture();
877 QRhiRenderBuffer *rb = colorAtt->renderBuffer();
878 d.pixelSize = tex ? rhiD->q->sizeForMipLevel(colorAtt->level(), tex->pixelSize()) : rb->pixelSize();
879 }
else if (m_desc.depthStencilBuffer()) {
880 d.pixelSize = m_desc.depthStencilBuffer()->pixelSize();
881 }
else if (m_desc.depthTexture()) {
882 d.pixelSize = m_desc.depthTexture()->pixelSize();
884 QRhiRenderTargetAttachmentTracker::updateResIdList<QNullTexture, QNullRenderBuffer>(m_desc, &d.currentResIdList);
885 rhiD->registerResource(
this);
891 if (!QRhiRenderTargetAttachmentTracker::isUpToDate<QNullTexture, QNullRenderBuffer>(m_desc, d.currentResIdList))
921 rhiD->unregisterResource(
this);
927 if (!rhiD->sanityCheckShaderResourceBindings(
this))
930 rhiD->updateLayoutDesc(
this);
932 rhiD->registerResource(
this,
false);
955 rhiD->unregisterResource(
this);
961 if (!rhiD->sanityCheckGraphicsPipeline(
this))
964 rhiD->registerResource(
this);
982 rhiD->unregisterResource(
this);
988 rhiD->registerResource(
this);
1023 rhiD->unregisterResource(
this);
1038 return QSize(1280, 720);
1050 rhiD->registerResource(rpD,
false);
1056 const bool needsRegistration = !window || window != m_window;
1057 if (window && window != m_window)
1061 m_currentPixelSize = surfacePixelSize();
1062 rt.setRenderPassDescriptor(m_renderPassDesc);
1063 rt.d.rp =
QRHI_RES(QNullRenderPassDescriptor, m_renderPassDesc);
1064 rt.d.pixelSize = m_currentPixelSize;
1067 if (needsRegistration) {
1069 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
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
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)
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