/src/qtbase/src/gui/rhi/qrhinull_p.h
Line | Count | Source |
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 | 0 | 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 | | QRhiShadingRateMap *createShadingRateMap() override; |
208 | | |
209 | | QRhiSwapChain *createSwapChain() override; |
210 | | QRhi::FrameOpResult beginFrame(QRhiSwapChain *swapChain, QRhi::BeginFrameFlags flags) override; |
211 | | QRhi::FrameOpResult endFrame(QRhiSwapChain *swapChain, QRhi::EndFrameFlags flags) override; |
212 | | QRhi::FrameOpResult beginOffscreenFrame(QRhiCommandBuffer **cb, QRhi::BeginFrameFlags flags) override; |
213 | | QRhi::FrameOpResult endOffscreenFrame(QRhi::EndFrameFlags flags) override; |
214 | | QRhi::FrameOpResult finish() override; |
215 | | |
216 | | void resourceUpdate(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch *resourceUpdates) override; |
217 | | |
218 | | void beginPass(QRhiCommandBuffer *cb, |
219 | | QRhiRenderTarget *rt, |
220 | | const QColor &colorClearValue, |
221 | | const QRhiDepthStencilClearValue &depthStencilClearValue, |
222 | | QRhiResourceUpdateBatch *resourceUpdates, |
223 | | QRhiCommandBuffer::BeginPassFlags flags) override; |
224 | | void endPass(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch *resourceUpdates) override; |
225 | | |
226 | | void setGraphicsPipeline(QRhiCommandBuffer *cb, |
227 | | QRhiGraphicsPipeline *ps) override; |
228 | | |
229 | | void setShaderResources(QRhiCommandBuffer *cb, |
230 | | QRhiShaderResourceBindings *srb, |
231 | | int dynamicOffsetCount, |
232 | | const QRhiCommandBuffer::DynamicOffset *dynamicOffsets) override; |
233 | | |
234 | | void setVertexInput(QRhiCommandBuffer *cb, |
235 | | int startBinding, int bindingCount, const QRhiCommandBuffer::VertexInput *bindings, |
236 | | QRhiBuffer *indexBuf, quint32 indexOffset, |
237 | | QRhiCommandBuffer::IndexFormat indexFormat) override; |
238 | | |
239 | | void setViewport(QRhiCommandBuffer *cb, const QRhiViewport &viewport) override; |
240 | | void setScissor(QRhiCommandBuffer *cb, const QRhiScissor &scissor) override; |
241 | | void setBlendConstants(QRhiCommandBuffer *cb, const QColor &c) override; |
242 | | void setStencilRef(QRhiCommandBuffer *cb, quint32 refValue) override; |
243 | | void setShadingRate(QRhiCommandBuffer *cb, const QSize &coarsePixelSize) override; |
244 | | |
245 | | void draw(QRhiCommandBuffer *cb, quint32 vertexCount, |
246 | | quint32 instanceCount, quint32 firstVertex, quint32 firstInstance) override; |
247 | | |
248 | | void drawIndexed(QRhiCommandBuffer *cb, quint32 indexCount, |
249 | | quint32 instanceCount, quint32 firstIndex, |
250 | | qint32 vertexOffset, quint32 firstInstance) override; |
251 | | |
252 | | void debugMarkBegin(QRhiCommandBuffer *cb, const QByteArray &name) override; |
253 | | void debugMarkEnd(QRhiCommandBuffer *cb) override; |
254 | | void debugMarkMsg(QRhiCommandBuffer *cb, const QByteArray &msg) override; |
255 | | |
256 | | void beginComputePass(QRhiCommandBuffer *cb, |
257 | | QRhiResourceUpdateBatch *resourceUpdates, |
258 | | QRhiCommandBuffer::BeginPassFlags flags) override; |
259 | | void endComputePass(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch *resourceUpdates) override; |
260 | | void setComputePipeline(QRhiCommandBuffer *cb, QRhiComputePipeline *ps) override; |
261 | | void dispatch(QRhiCommandBuffer *cb, int x, int y, int z) override; |
262 | | |
263 | | const QRhiNativeHandles *nativeHandles(QRhiCommandBuffer *cb) override; |
264 | | void beginExternal(QRhiCommandBuffer *cb) override; |
265 | | void endExternal(QRhiCommandBuffer *cb) override; |
266 | | double lastCompletedGpuTime(QRhiCommandBuffer *cb) override; |
267 | | |
268 | | QList<int> supportedSampleCounts() const override; |
269 | | QList<QSize> supportedShadingRates(int sampleCount) const override; |
270 | | int ubufAlignment() const override; |
271 | | bool isYUpInFramebuffer() const override; |
272 | | bool isYUpInNDC() const override; |
273 | | bool isClipDepthZeroToOne() const override; |
274 | | QMatrix4x4 clipSpaceCorrMatrix() const override; |
275 | | bool isTextureFormatSupported(QRhiTexture::Format format, QRhiTexture::Flags flags) const override; |
276 | | bool isFeatureSupported(QRhi::Feature feature) const override; |
277 | | int resourceLimit(QRhi::ResourceLimit limit) const override; |
278 | | const QRhiNativeHandles *nativeHandles() override; |
279 | | QRhiDriverInfo driverInfo() const override; |
280 | | QRhiStats statistics() override; |
281 | | bool makeThreadLocalNativeContextCurrent() override; |
282 | | void setQueueSubmitParams(QRhiNativeHandles *params) override; |
283 | | void releaseCachedResources() override; |
284 | | bool isDeviceLost() const override; |
285 | | |
286 | | QByteArray pipelineCacheData() override; |
287 | | void setPipelineCacheData(const QByteArray &data) override; |
288 | | |
289 | | void simulateTextureUpload(const QRhiResourceUpdateBatchPrivate::TextureOp &u); |
290 | | void simulateTextureCopy(const QRhiResourceUpdateBatchPrivate::TextureOp &u); |
291 | | void simulateTextureGenMips(const QRhiResourceUpdateBatchPrivate::TextureOp &u); |
292 | | |
293 | | QRhiNullNativeHandles nativeHandlesStruct; |
294 | | QRhiSwapChain *currentSwapChain = nullptr; |
295 | | QNullCommandBuffer offscreenCommandBuffer; |
296 | | }; |
297 | | |
298 | | QT_END_NAMESPACE |
299 | | |
300 | | #endif |