| 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 | |
| 4 | #ifndef QRHINULL_P_H |
| 5 | #define QRHINULL_P_H |
| 6 | |
| 7 | // |
| 8 | // W A R N I N G |
| 9 | // ------------- |
| 10 | // |
| 11 | // This file is not part of the Qt API. It exists purely as an |
| 12 | // implementation detail. This header file may change from version to |
| 13 | // version without notice, or even be removed. |
| 14 | // |
| 15 | // We mean it. |
| 16 | // |
| 17 | |
| 18 | #include "qrhi_p.h" |
| 19 | |
| 20 | QT_BEGIN_NAMESPACE |
| 21 | |
| 22 | struct QNullBuffer : public QRhiBuffer |
| 23 | { |
| 24 | QNullBuffer(QRhiImplementation *rhi, Type type, UsageFlags usage, quint32 size); |
| 25 | ~QNullBuffer(); |
| 26 | void destroy() override; |
| 27 | bool create() override; |
| 28 | char *beginFullDynamicBufferUpdateForCurrentFrame() override; |
| 29 | |
| 30 | char *data = nullptr; |
| 31 | }; |
| 32 | |
| 33 | struct QNullRenderBuffer : public QRhiRenderBuffer |
| 34 | { |
| 35 | QNullRenderBuffer(QRhiImplementation *rhi, Type type, const QSize &pixelSize, |
| 36 | int sampleCount, QRhiRenderBuffer::Flags flags, |
| 37 | QRhiTexture::Format backingFormatHint); |
| 38 | ~QNullRenderBuffer(); |
| 39 | void destroy() override; |
| 40 | bool create() override; |
| 41 | QRhiTexture::Format backingFormat() const override; |
| 42 | |
| 43 | bool valid = false; |
| 44 | uint generation = 0; |
| 45 | }; |
| 46 | |
| 47 | struct QNullTexture : public QRhiTexture |
| 48 | { |
| 49 | QNullTexture(QRhiImplementation *rhi, Format format, const QSize &pixelSize, int depth, |
| 50 | int arraySize, int sampleCount, Flags flags); |
| 51 | ~QNullTexture(); |
| 52 | void destroy() override; |
| 53 | bool create() override; |
| 54 | bool createFrom(NativeTexture src) override; |
| 55 | |
| 56 | bool valid = false; |
| 57 | QVarLengthArray<std::array<QImage, QRhi::MAX_MIP_LEVELS>, 6> image; |
| 58 | uint generation = 0; |
| 59 | }; |
| 60 | |
| 61 | struct QNullSampler : public QRhiSampler |
| 62 | { |
| 63 | QNullSampler(QRhiImplementation *rhi, Filter magFilter, Filter minFilter, Filter mipmapMode, |
| 64 | AddressMode u, AddressMode v, AddressMode w); |
| 65 | ~QNullSampler(); |
| 66 | void destroy() override; |
| 67 | bool create() override; |
| 68 | }; |
| 69 | |
| 70 | struct QNullRenderPassDescriptor : public QRhiRenderPassDescriptor |
| 71 | { |
| 72 | QNullRenderPassDescriptor(QRhiImplementation *rhi); |
| 73 | ~QNullRenderPassDescriptor(); |
| 74 | void destroy() override; |
| 75 | bool isCompatible(const QRhiRenderPassDescriptor *other) const override; |
| 76 | QRhiRenderPassDescriptor *newCompatibleRenderPassDescriptor() const override; |
| 77 | QVector<quint32> serializedFormat() const override; |
| 78 | }; |
| 79 | |
| 80 | struct QNullRenderTargetData |
| 81 | { |
| 82 | QNullRenderTargetData(QRhiImplementation *) { } |
| 83 | |
| 84 | QNullRenderPassDescriptor *rp = nullptr; |
| 85 | QSize pixelSize; |
| 86 | float dpr = 1; |
| 87 | QRhiRenderTargetAttachmentTracker::ResIdList currentResIdList; |
| 88 | }; |
| 89 | |
| 90 | struct QNullSwapChainRenderTarget : public QRhiSwapChainRenderTarget |
| 91 | { |
| 92 | QNullSwapChainRenderTarget(QRhiImplementation *rhi, QRhiSwapChain *swapchain); |
| 93 | ~QNullSwapChainRenderTarget(); |
| 94 | void destroy() override; |
| 95 | |
| 96 | QSize pixelSize() const override; |
| 97 | float devicePixelRatio() const override; |
| 98 | int sampleCount() const override; |
| 99 | |
| 100 | QNullRenderTargetData d; |
| 101 | }; |
| 102 | |
| 103 | struct QNullTextureRenderTarget : public QRhiTextureRenderTarget |
| 104 | { |
| 105 | QNullTextureRenderTarget(QRhiImplementation *rhi, const QRhiTextureRenderTargetDescription &desc, Flags flags); |
| 106 | ~QNullTextureRenderTarget(); |
| 107 | void destroy() override; |
| 108 | |
| 109 | QSize pixelSize() const override; |
| 110 | float devicePixelRatio() const override; |
| 111 | int sampleCount() const override; |
| 112 | |
| 113 | QRhiRenderPassDescriptor *newCompatibleRenderPassDescriptor() override; |
| 114 | bool create() override; |
| 115 | |
| 116 | QNullRenderTargetData d; |
| 117 | }; |
| 118 | |
| 119 | struct QNullShaderResourceBindings : public QRhiShaderResourceBindings |
| 120 | { |
| 121 | QNullShaderResourceBindings(QRhiImplementation *rhi); |
| 122 | ~QNullShaderResourceBindings(); |
| 123 | void destroy() override; |
| 124 | bool create() override; |
| 125 | void updateResources(UpdateFlags flags) override; |
| 126 | }; |
| 127 | |
| 128 | struct QNullGraphicsPipeline : public QRhiGraphicsPipeline |
| 129 | { |
| 130 | QNullGraphicsPipeline(QRhiImplementation *rhi); |
| 131 | ~QNullGraphicsPipeline(); |
| 132 | void destroy() override; |
| 133 | bool create() override; |
| 134 | }; |
| 135 | |
| 136 | struct QNullComputePipeline : public QRhiComputePipeline |
| 137 | { |
| 138 | QNullComputePipeline(QRhiImplementation *rhi); |
| 139 | ~QNullComputePipeline(); |
| 140 | void destroy() override; |
| 141 | bool create() override; |
| 142 | }; |
| 143 | |
| 144 | struct QNullCommandBuffer : public QRhiCommandBuffer |
| 145 | { |
| 146 | QNullCommandBuffer(QRhiImplementation *rhi); |
| 147 | ~QNullCommandBuffer(); |
| 148 | void destroy() override; |
| 149 | }; |
| 150 | |
| 151 | struct QNullSwapChain : public QRhiSwapChain |
| 152 | { |
| 153 | QNullSwapChain(QRhiImplementation *rhi); |
| 154 | ~QNullSwapChain(); |
| 155 | void destroy() override; |
| 156 | |
| 157 | QRhiCommandBuffer *currentFrameCommandBuffer() override; |
| 158 | QRhiRenderTarget *currentFrameRenderTarget() override; |
| 159 | |
| 160 | QSize surfacePixelSize() override; |
| 161 | bool isFormatSupported(Format f) override; |
| 162 | |
| 163 | QRhiRenderPassDescriptor *newCompatibleRenderPassDescriptor() override; |
| 164 | bool createOrResize() override; |
| 165 | |
| 166 | QWindow *window = nullptr; |
| 167 | QNullSwapChainRenderTarget rt; |
| 168 | QNullCommandBuffer cb; |
| 169 | int frameCount = 0; |
| 170 | }; |
| 171 | |
| 172 | class QRhiNull : public QRhiImplementation |
| 173 | { |
| 174 | public: |
| 175 | QRhiNull(QRhiNullInitParams *params); |
| 176 | |
| 177 | bool create(QRhi::Flags flags) override; |
| 178 | void destroy() override; |
| 179 | |
| 180 | QRhiGraphicsPipeline *createGraphicsPipeline() override; |
| 181 | QRhiComputePipeline *createComputePipeline() override; |
| 182 | QRhiShaderResourceBindings *createShaderResourceBindings() override; |
| 183 | QRhiBuffer *createBuffer(QRhiBuffer::Type type, |
| 184 | QRhiBuffer::UsageFlags usage, |
| 185 | quint32 size) override; |
| 186 | QRhiRenderBuffer *createRenderBuffer(QRhiRenderBuffer::Type type, |
| 187 | const QSize &pixelSize, |
| 188 | int sampleCount, |
| 189 | QRhiRenderBuffer::Flags flags, |
| 190 | QRhiTexture::Format backingFormatHint) override; |
| 191 | QRhiTexture *createTexture(QRhiTexture::Format format, |
| 192 | const QSize &pixelSize, |
| 193 | int depth, |
| 194 | int arraySize, |
| 195 | int sampleCount, |
| 196 | QRhiTexture::Flags flags) override; |
| 197 | QRhiSampler *createSampler(QRhiSampler::Filter magFilter, |
| 198 | QRhiSampler::Filter minFilter, |
| 199 | QRhiSampler::Filter mipmapMode, |
| 200 | QRhiSampler:: AddressMode u, |
| 201 | QRhiSampler::AddressMode v, |
| 202 | QRhiSampler::AddressMode w) override; |
| 203 | |
| 204 | QRhiTextureRenderTarget *createTextureRenderTarget(const QRhiTextureRenderTargetDescription &desc, |
| 205 | QRhiTextureRenderTarget::Flags flags) override; |
| 206 | |
| 207 | QRhiSwapChain *createSwapChain() override; |
| 208 | QRhi::FrameOpResult beginFrame(QRhiSwapChain *swapChain, QRhi::BeginFrameFlags flags) override; |
| 209 | QRhi::FrameOpResult endFrame(QRhiSwapChain *swapChain, QRhi::EndFrameFlags flags) override; |
| 210 | QRhi::FrameOpResult beginOffscreenFrame(QRhiCommandBuffer **cb, QRhi::BeginFrameFlags flags) override; |
| 211 | QRhi::FrameOpResult endOffscreenFrame(QRhi::EndFrameFlags flags) override; |
| 212 | QRhi::FrameOpResult finish() override; |
| 213 | |
| 214 | void resourceUpdate(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch *resourceUpdates) override; |
| 215 | |
| 216 | void beginPass(QRhiCommandBuffer *cb, |
| 217 | QRhiRenderTarget *rt, |
| 218 | const QColor &colorClearValue, |
| 219 | const QRhiDepthStencilClearValue &depthStencilClearValue, |
| 220 | QRhiResourceUpdateBatch *resourceUpdates, |
| 221 | QRhiCommandBuffer::BeginPassFlags flags) override; |
| 222 | void endPass(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch *resourceUpdates) override; |
| 223 | |
| 224 | void setGraphicsPipeline(QRhiCommandBuffer *cb, |
| 225 | QRhiGraphicsPipeline *ps) override; |
| 226 | |
| 227 | void setShaderResources(QRhiCommandBuffer *cb, |
| 228 | QRhiShaderResourceBindings *srb, |
| 229 | int dynamicOffsetCount, |
| 230 | const QRhiCommandBuffer::DynamicOffset *dynamicOffsets) override; |
| 231 | |
| 232 | void setVertexInput(QRhiCommandBuffer *cb, |
| 233 | int startBinding, int bindingCount, const QRhiCommandBuffer::VertexInput *bindings, |
| 234 | QRhiBuffer *indexBuf, quint32 indexOffset, |
| 235 | QRhiCommandBuffer::IndexFormat indexFormat) override; |
| 236 | |
| 237 | void setViewport(QRhiCommandBuffer *cb, const QRhiViewport &viewport) override; |
| 238 | void setScissor(QRhiCommandBuffer *cb, const QRhiScissor &scissor) override; |
| 239 | void setBlendConstants(QRhiCommandBuffer *cb, const QColor &c) override; |
| 240 | void setStencilRef(QRhiCommandBuffer *cb, quint32 refValue) override; |
| 241 | |
| 242 | void draw(QRhiCommandBuffer *cb, quint32 vertexCount, |
| 243 | quint32 instanceCount, quint32 firstVertex, quint32 firstInstance) override; |
| 244 | |
| 245 | void drawIndexed(QRhiCommandBuffer *cb, quint32 indexCount, |
| 246 | quint32 instanceCount, quint32 firstIndex, |
| 247 | qint32 vertexOffset, quint32 firstInstance) override; |
| 248 | |
| 249 | void debugMarkBegin(QRhiCommandBuffer *cb, const QByteArray &name) override; |
| 250 | void debugMarkEnd(QRhiCommandBuffer *cb) override; |
| 251 | void debugMarkMsg(QRhiCommandBuffer *cb, const QByteArray &msg) override; |
| 252 | |
| 253 | void beginComputePass(QRhiCommandBuffer *cb, |
| 254 | QRhiResourceUpdateBatch *resourceUpdates, |
| 255 | QRhiCommandBuffer::BeginPassFlags flags) override; |
| 256 | void endComputePass(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch *resourceUpdates) override; |
| 257 | void setComputePipeline(QRhiCommandBuffer *cb, QRhiComputePipeline *ps) override; |
| 258 | void dispatch(QRhiCommandBuffer *cb, int x, int y, int z) override; |
| 259 | |
| 260 | const QRhiNativeHandles *nativeHandles(QRhiCommandBuffer *cb) override; |
| 261 | void beginExternal(QRhiCommandBuffer *cb) override; |
| 262 | void endExternal(QRhiCommandBuffer *cb) override; |
| 263 | double lastCompletedGpuTime(QRhiCommandBuffer *cb) override; |
| 264 | |
| 265 | QList<int> supportedSampleCounts() const override; |
| 266 | int ubufAlignment() const override; |
| 267 | bool isYUpInFramebuffer() const override; |
| 268 | bool isYUpInNDC() const override; |
| 269 | bool isClipDepthZeroToOne() const override; |
| 270 | QMatrix4x4 clipSpaceCorrMatrix() const override; |
| 271 | bool isTextureFormatSupported(QRhiTexture::Format format, QRhiTexture::Flags flags) const override; |
| 272 | bool isFeatureSupported(QRhi::Feature feature) const override; |
| 273 | int resourceLimit(QRhi::ResourceLimit limit) const override; |
| 274 | const QRhiNativeHandles *nativeHandles() override; |
| 275 | QRhiDriverInfo driverInfo() const override; |
| 276 | QRhiStats statistics() override; |
| 277 | bool makeThreadLocalNativeContextCurrent() override; |
| 278 | void releaseCachedResources() override; |
| 279 | bool isDeviceLost() const override; |
| 280 | |
| 281 | QByteArray pipelineCacheData() override; |
| 282 | void setPipelineCacheData(const QByteArray &data) override; |
| 283 | |
| 284 | void simulateTextureUpload(const QRhiResourceUpdateBatchPrivate::TextureOp &u); |
| 285 | void simulateTextureCopy(const QRhiResourceUpdateBatchPrivate::TextureOp &u); |
| 286 | void simulateTextureGenMips(const QRhiResourceUpdateBatchPrivate::TextureOp &u); |
| 287 | |
| 288 | QRhiNullNativeHandles nativeHandlesStruct; |
| 289 | QRhiSwapChain *currentSwapChain = nullptr; |
| 290 | QNullCommandBuffer offscreenCommandBuffer; |
| 291 | }; |
| 292 | |
| 293 | QT_END_NAMESPACE |
| 294 | |
| 295 | #endif |
| 296 | |