1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2019 The Qt Company Ltd. |
4 | ** Contact: http://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the Qt Gui module |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:LGPL3$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see http://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at http://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU Lesser General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
19 | ** General Public License version 3 as published by the Free Software |
20 | ** Foundation and appearing in the file LICENSE.LGPLv3 included in the |
21 | ** packaging of this file. Please review the following information to |
22 | ** ensure the GNU Lesser General Public License version 3 requirements |
23 | ** will be met: https://www.gnu.org/licenses/lgpl.html. |
24 | ** |
25 | ** GNU General Public License Usage |
26 | ** Alternatively, this file may be used under the terms of the GNU |
27 | ** General Public License version 2.0 or later as published by the Free |
28 | ** Software Foundation and appearing in the file LICENSE.GPL included in |
29 | ** the packaging of this file. Please review the following information to |
30 | ** ensure the GNU General Public License version 2.0 requirements will be |
31 | ** met: http://www.gnu.org/licenses/gpl-2.0.html. |
32 | ** |
33 | ** $QT_END_LICENSE$ |
34 | ** |
35 | ****************************************************************************/ |
36 | |
37 | #ifndef QRHINULL_P_H |
38 | #define QRHINULL_P_H |
39 | |
40 | // |
41 | // W A R N I N G |
42 | // ------------- |
43 | // |
44 | // This file is not part of the Qt API. It exists purely as an |
45 | // implementation detail. This header file may change from version to |
46 | // version without notice, or even be removed. |
47 | // |
48 | // We mean it. |
49 | // |
50 | |
51 | #include "qrhinull_p.h" |
52 | #include "qrhi_p_p.h" |
53 | |
54 | QT_BEGIN_NAMESPACE |
55 | |
56 | struct QNullBuffer : public QRhiBuffer |
57 | { |
58 | QNullBuffer(QRhiImplementation *rhi, Type type, UsageFlags usage, int size); |
59 | ~QNullBuffer(); |
60 | void destroy() override; |
61 | bool create() override; |
62 | char *beginFullDynamicBufferUpdateForCurrentFrame() override; |
63 | |
64 | char *data = nullptr; |
65 | }; |
66 | |
67 | struct QNullRenderBuffer : public QRhiRenderBuffer |
68 | { |
69 | QNullRenderBuffer(QRhiImplementation *rhi, Type type, const QSize &pixelSize, |
70 | int sampleCount, QRhiRenderBuffer::Flags flags, |
71 | QRhiTexture::Format backingFormatHint); |
72 | ~QNullRenderBuffer(); |
73 | void destroy() override; |
74 | bool create() override; |
75 | QRhiTexture::Format backingFormat() const override; |
76 | }; |
77 | |
78 | struct QNullTexture : public QRhiTexture |
79 | { |
80 | QNullTexture(QRhiImplementation *rhi, Format format, const QSize &pixelSize, |
81 | int sampleCount, Flags flags); |
82 | ~QNullTexture(); |
83 | void destroy() override; |
84 | bool create() override; |
85 | bool createFrom(NativeTexture src) override; |
86 | |
87 | QImage image[QRhi::MAX_LAYERS][QRhi::MAX_LEVELS]; |
88 | }; |
89 | |
90 | struct QNullSampler : public QRhiSampler |
91 | { |
92 | QNullSampler(QRhiImplementation *rhi, Filter magFilter, Filter minFilter, Filter mipmapMode, |
93 | AddressMode u, AddressMode v, AddressMode w); |
94 | ~QNullSampler(); |
95 | void destroy() override; |
96 | bool create() override; |
97 | }; |
98 | |
99 | struct QNullRenderPassDescriptor : public QRhiRenderPassDescriptor |
100 | { |
101 | QNullRenderPassDescriptor(QRhiImplementation *rhi); |
102 | ~QNullRenderPassDescriptor(); |
103 | void destroy() override; |
104 | bool isCompatible(const QRhiRenderPassDescriptor *other) const override; |
105 | }; |
106 | |
107 | struct QNullRenderTargetData |
108 | { |
109 | QNullRenderTargetData(QRhiImplementation *) { } |
110 | |
111 | QNullRenderPassDescriptor *rp = nullptr; |
112 | QSize pixelSize; |
113 | float dpr = 1; |
114 | }; |
115 | |
116 | struct QNullReferenceRenderTarget : public QRhiRenderTarget |
117 | { |
118 | QNullReferenceRenderTarget(QRhiImplementation *rhi); |
119 | ~QNullReferenceRenderTarget(); |
120 | void destroy() override; |
121 | |
122 | QSize pixelSize() const override; |
123 | float devicePixelRatio() const override; |
124 | int sampleCount() const override; |
125 | |
126 | QNullRenderTargetData d; |
127 | }; |
128 | |
129 | struct QNullTextureRenderTarget : public QRhiTextureRenderTarget |
130 | { |
131 | QNullTextureRenderTarget(QRhiImplementation *rhi, const QRhiTextureRenderTargetDescription &desc, Flags flags); |
132 | ~QNullTextureRenderTarget(); |
133 | void destroy() override; |
134 | |
135 | QSize pixelSize() const override; |
136 | float devicePixelRatio() const override; |
137 | int sampleCount() const override; |
138 | |
139 | QRhiRenderPassDescriptor *newCompatibleRenderPassDescriptor() override; |
140 | bool create() override; |
141 | |
142 | QNullRenderTargetData d; |
143 | }; |
144 | |
145 | struct QNullShaderResourceBindings : public QRhiShaderResourceBindings |
146 | { |
147 | QNullShaderResourceBindings(QRhiImplementation *rhi); |
148 | ~QNullShaderResourceBindings(); |
149 | void destroy() override; |
150 | bool create() override; |
151 | }; |
152 | |
153 | struct QNullGraphicsPipeline : public QRhiGraphicsPipeline |
154 | { |
155 | QNullGraphicsPipeline(QRhiImplementation *rhi); |
156 | ~QNullGraphicsPipeline(); |
157 | void destroy() override; |
158 | bool create() override; |
159 | }; |
160 | |
161 | struct QNullComputePipeline : public QRhiComputePipeline |
162 | { |
163 | QNullComputePipeline(QRhiImplementation *rhi); |
164 | ~QNullComputePipeline(); |
165 | void destroy() override; |
166 | bool create() override; |
167 | }; |
168 | |
169 | struct QNullCommandBuffer : public QRhiCommandBuffer |
170 | { |
171 | QNullCommandBuffer(QRhiImplementation *rhi); |
172 | ~QNullCommandBuffer(); |
173 | void destroy() override; |
174 | }; |
175 | |
176 | struct QNullSwapChain : public QRhiSwapChain |
177 | { |
178 | QNullSwapChain(QRhiImplementation *rhi); |
179 | ~QNullSwapChain(); |
180 | void destroy() override; |
181 | |
182 | QRhiCommandBuffer *currentFrameCommandBuffer() override; |
183 | QRhiRenderTarget *currentFrameRenderTarget() override; |
184 | |
185 | QSize surfacePixelSize() override; |
186 | |
187 | QRhiRenderPassDescriptor *newCompatibleRenderPassDescriptor() override; |
188 | bool createOrResize() override; |
189 | |
190 | QNullReferenceRenderTarget rt; |
191 | QNullCommandBuffer cb; |
192 | int frameCount = 0; |
193 | }; |
194 | |
195 | class QRhiNull : public QRhiImplementation |
196 | { |
197 | public: |
198 | QRhiNull(QRhiNullInitParams *params); |
199 | |
200 | bool create(QRhi::Flags flags) override; |
201 | void destroy() override; |
202 | |
203 | QRhiGraphicsPipeline *createGraphicsPipeline() override; |
204 | QRhiComputePipeline *createComputePipeline() override; |
205 | QRhiShaderResourceBindings *createShaderResourceBindings() override; |
206 | QRhiBuffer *createBuffer(QRhiBuffer::Type type, |
207 | QRhiBuffer::UsageFlags usage, |
208 | int size) override; |
209 | QRhiRenderBuffer *createRenderBuffer(QRhiRenderBuffer::Type type, |
210 | const QSize &pixelSize, |
211 | int sampleCount, |
212 | QRhiRenderBuffer::Flags flags, |
213 | QRhiTexture::Format backingFormatHint) override; |
214 | QRhiTexture *createTexture(QRhiTexture::Format format, |
215 | const QSize &pixelSize, |
216 | int sampleCount, |
217 | QRhiTexture::Flags flags) override; |
218 | QRhiSampler *createSampler(QRhiSampler::Filter magFilter, |
219 | QRhiSampler::Filter minFilter, |
220 | QRhiSampler::Filter mipmapMode, |
221 | QRhiSampler:: AddressMode u, |
222 | QRhiSampler::AddressMode v, |
223 | QRhiSampler::AddressMode w) override; |
224 | |
225 | QRhiTextureRenderTarget *createTextureRenderTarget(const QRhiTextureRenderTargetDescription &desc, |
226 | QRhiTextureRenderTarget::Flags flags) override; |
227 | |
228 | QRhiSwapChain *createSwapChain() override; |
229 | QRhi::FrameOpResult beginFrame(QRhiSwapChain *swapChain, QRhi::BeginFrameFlags flags) override; |
230 | QRhi::FrameOpResult endFrame(QRhiSwapChain *swapChain, QRhi::EndFrameFlags flags) override; |
231 | QRhi::FrameOpResult beginOffscreenFrame(QRhiCommandBuffer **cb, QRhi::BeginFrameFlags flags) override; |
232 | QRhi::FrameOpResult endOffscreenFrame(QRhi::EndFrameFlags flags) override; |
233 | QRhi::FrameOpResult finish() override; |
234 | |
235 | void resourceUpdate(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch *resourceUpdates) override; |
236 | |
237 | void beginPass(QRhiCommandBuffer *cb, |
238 | QRhiRenderTarget *rt, |
239 | const QColor &colorClearValue, |
240 | const QRhiDepthStencilClearValue &depthStencilClearValue, |
241 | QRhiResourceUpdateBatch *resourceUpdates, |
242 | QRhiCommandBuffer::BeginPassFlags flags) override; |
243 | void endPass(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch *resourceUpdates) override; |
244 | |
245 | void setGraphicsPipeline(QRhiCommandBuffer *cb, |
246 | QRhiGraphicsPipeline *ps) override; |
247 | |
248 | void setShaderResources(QRhiCommandBuffer *cb, |
249 | QRhiShaderResourceBindings *srb, |
250 | int dynamicOffsetCount, |
251 | const QRhiCommandBuffer::DynamicOffset *dynamicOffsets) override; |
252 | |
253 | void setVertexInput(QRhiCommandBuffer *cb, |
254 | int startBinding, int bindingCount, const QRhiCommandBuffer::VertexInput *bindings, |
255 | QRhiBuffer *indexBuf, quint32 indexOffset, |
256 | QRhiCommandBuffer::IndexFormat indexFormat) override; |
257 | |
258 | void setViewport(QRhiCommandBuffer *cb, const QRhiViewport &viewport) override; |
259 | void setScissor(QRhiCommandBuffer *cb, const QRhiScissor &scissor) override; |
260 | void setBlendConstants(QRhiCommandBuffer *cb, const QColor &c) override; |
261 | void setStencilRef(QRhiCommandBuffer *cb, quint32 refValue) override; |
262 | |
263 | void draw(QRhiCommandBuffer *cb, quint32 vertexCount, |
264 | quint32 instanceCount, quint32 firstVertex, quint32 firstInstance) override; |
265 | |
266 | void drawIndexed(QRhiCommandBuffer *cb, quint32 indexCount, |
267 | quint32 instanceCount, quint32 firstIndex, |
268 | qint32 vertexOffset, quint32 firstInstance) override; |
269 | |
270 | void debugMarkBegin(QRhiCommandBuffer *cb, const QByteArray &name) override; |
271 | void debugMarkEnd(QRhiCommandBuffer *cb) override; |
272 | void debugMarkMsg(QRhiCommandBuffer *cb, const QByteArray &msg) override; |
273 | |
274 | void beginComputePass(QRhiCommandBuffer *cb, |
275 | QRhiResourceUpdateBatch *resourceUpdates, |
276 | QRhiCommandBuffer::BeginPassFlags flags) override; |
277 | void endComputePass(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch *resourceUpdates) override; |
278 | void setComputePipeline(QRhiCommandBuffer *cb, QRhiComputePipeline *ps) override; |
279 | void dispatch(QRhiCommandBuffer *cb, int x, int y, int z) override; |
280 | |
281 | const QRhiNativeHandles *nativeHandles(QRhiCommandBuffer *cb) override; |
282 | void beginExternal(QRhiCommandBuffer *cb) override; |
283 | void endExternal(QRhiCommandBuffer *cb) override; |
284 | |
285 | QList<int> supportedSampleCounts() const override; |
286 | int ubufAlignment() const override; |
287 | bool isYUpInFramebuffer() const override; |
288 | bool isYUpInNDC() const override; |
289 | bool isClipDepthZeroToOne() const override; |
290 | QMatrix4x4 clipSpaceCorrMatrix() const override; |
291 | bool isTextureFormatSupported(QRhiTexture::Format format, QRhiTexture::Flags flags) const override; |
292 | bool isFeatureSupported(QRhi::Feature feature) const override; |
293 | int resourceLimit(QRhi::ResourceLimit limit) const override; |
294 | const QRhiNativeHandles *nativeHandles() override; |
295 | void sendVMemStatsToProfiler() override; |
296 | bool makeThreadLocalNativeContextCurrent() override; |
297 | void releaseCachedResources() override; |
298 | bool isDeviceLost() const override; |
299 | |
300 | void simulateTextureUpload(const QRhiResourceUpdateBatchPrivate::TextureOp &u); |
301 | void simulateTextureCopy(const QRhiResourceUpdateBatchPrivate::TextureOp &u); |
302 | void simulateTextureGenMips(const QRhiResourceUpdateBatchPrivate::TextureOp &u); |
303 | |
304 | QRhiNullNativeHandles nativeHandlesStruct; |
305 | QRhiSwapChain *currentSwapChain = nullptr; |
306 | QNullCommandBuffer offscreenCommandBuffer; |
307 | }; |
308 | |
309 | QT_END_NAMESPACE |
310 | |
311 | #endif |
312 | |