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
54QT_BEGIN_NAMESPACE
55
56struct QNullBuffer : public QRhiBuffer
57{
58 QNullBuffer(QRhiImplementation *rhi, Type type, UsageFlags usage, int size);
59 ~QNullBuffer();
60 void release() override;
61 bool build() override;
62};
63
64struct QNullRenderBuffer : public QRhiRenderBuffer
65{
66 QNullRenderBuffer(QRhiImplementation *rhi, Type type, const QSize &pixelSize,
67 int sampleCount, QRhiRenderBuffer::Flags flags);
68 ~QNullRenderBuffer();
69 void release() override;
70 bool build() override;
71 QRhiTexture::Format backingFormat() const override;
72};
73
74struct QNullTexture : public QRhiTexture
75{
76 QNullTexture(QRhiImplementation *rhi, Format format, const QSize &pixelSize,
77 int sampleCount, Flags flags);
78 ~QNullTexture();
79 void release() override;
80 bool build() override;
81 bool buildFrom(const QRhiNativeHandles *src) override;
82 const QRhiNativeHandles *nativeHandles() override;
83
84 QRhiNullTextureNativeHandles nativeHandlesStruct;
85};
86
87struct QNullSampler : public QRhiSampler
88{
89 QNullSampler(QRhiImplementation *rhi, Filter magFilter, Filter minFilter, Filter mipmapMode,
90 AddressMode u, AddressMode v);
91 ~QNullSampler();
92 void release() override;
93 bool build() override;
94};
95
96struct QNullRenderPassDescriptor : public QRhiRenderPassDescriptor
97{
98 QNullRenderPassDescriptor(QRhiImplementation *rhi);
99 ~QNullRenderPassDescriptor();
100 void release() override;
101};
102
103struct QNullRenderTargetData
104{
105 QNullRenderTargetData(QRhiImplementation *) { }
106
107 QNullRenderPassDescriptor *rp = nullptr;
108 QSize pixelSize;
109 float dpr = 1;
110};
111
112struct QNullReferenceRenderTarget : public QRhiRenderTarget
113{
114 QNullReferenceRenderTarget(QRhiImplementation *rhi);
115 ~QNullReferenceRenderTarget();
116 void release() override;
117
118 QSize pixelSize() const override;
119 float devicePixelRatio() const override;
120 int sampleCount() const override;
121
122 QNullRenderTargetData d;
123};
124
125struct QNullTextureRenderTarget : public QRhiTextureRenderTarget
126{
127 QNullTextureRenderTarget(QRhiImplementation *rhi, const QRhiTextureRenderTargetDescription &desc, Flags flags);
128 ~QNullTextureRenderTarget();
129 void release() override;
130
131 QSize pixelSize() const override;
132 float devicePixelRatio() const override;
133 int sampleCount() const override;
134
135 QRhiRenderPassDescriptor *newCompatibleRenderPassDescriptor() override;
136 bool build() override;
137
138 QNullRenderTargetData d;
139};
140
141struct QNullShaderResourceBindings : public QRhiShaderResourceBindings
142{
143 QNullShaderResourceBindings(QRhiImplementation *rhi);
144 ~QNullShaderResourceBindings();
145 void release() override;
146 bool build() override;
147};
148
149struct QNullGraphicsPipeline : public QRhiGraphicsPipeline
150{
151 QNullGraphicsPipeline(QRhiImplementation *rhi);
152 ~QNullGraphicsPipeline();
153 void release() override;
154 bool build() override;
155};
156
157struct QNullComputePipeline : public QRhiComputePipeline
158{
159 QNullComputePipeline(QRhiImplementation *rhi);
160 ~QNullComputePipeline();
161 void release() override;
162 bool build() override;
163};
164
165struct QNullCommandBuffer : public QRhiCommandBuffer
166{
167 QNullCommandBuffer(QRhiImplementation *rhi);
168 ~QNullCommandBuffer();
169 void release() override;
170};
171
172struct QNullSwapChain : public QRhiSwapChain
173{
174 QNullSwapChain(QRhiImplementation *rhi);
175 ~QNullSwapChain();
176 void release() override;
177
178 QRhiCommandBuffer *currentFrameCommandBuffer() override;
179 QRhiRenderTarget *currentFrameRenderTarget() override;
180
181 QSize surfacePixelSize() override;
182
183 QRhiRenderPassDescriptor *newCompatibleRenderPassDescriptor() override;
184 bool buildOrResize() override;
185
186 QNullReferenceRenderTarget rt;
187 QNullCommandBuffer cb;
188 int frameCount = 0;
189};
190
191class QRhiNull : public QRhiImplementation
192{
193public:
194 QRhiNull(QRhiNullInitParams *params);
195
196 bool create(QRhi::Flags flags) override;
197 void destroy() override;
198
199 QRhiGraphicsPipeline *createGraphicsPipeline() override;
200 QRhiComputePipeline *createComputePipeline() override;
201 QRhiShaderResourceBindings *createShaderResourceBindings() override;
202 QRhiBuffer *createBuffer(QRhiBuffer::Type type,
203 QRhiBuffer::UsageFlags usage,
204 int size) override;
205 QRhiRenderBuffer *createRenderBuffer(QRhiRenderBuffer::Type type,
206 const QSize &pixelSize,
207 int sampleCount,
208 QRhiRenderBuffer::Flags flags) override;
209 QRhiTexture *createTexture(QRhiTexture::Format format,
210 const QSize &pixelSize,
211 int sampleCount,
212 QRhiTexture::Flags flags) override;
213 QRhiSampler *createSampler(QRhiSampler::Filter magFilter, QRhiSampler::Filter minFilter,
214 QRhiSampler::Filter mipmapMode,
215 QRhiSampler:: AddressMode u, QRhiSampler::AddressMode v) override;
216
217 QRhiTextureRenderTarget *createTextureRenderTarget(const QRhiTextureRenderTargetDescription &desc,
218 QRhiTextureRenderTarget::Flags flags) override;
219
220 QRhiSwapChain *createSwapChain() override;
221 QRhi::FrameOpResult beginFrame(QRhiSwapChain *swapChain, QRhi::BeginFrameFlags flags) override;
222 QRhi::FrameOpResult endFrame(QRhiSwapChain *swapChain, QRhi::EndFrameFlags flags) override;
223 QRhi::FrameOpResult beginOffscreenFrame(QRhiCommandBuffer **cb) override;
224 QRhi::FrameOpResult endOffscreenFrame() override;
225 QRhi::FrameOpResult finish() override;
226
227 void resourceUpdate(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch *resourceUpdates) override;
228
229 void beginPass(QRhiCommandBuffer *cb,
230 QRhiRenderTarget *rt,
231 const QColor &colorClearValue,
232 const QRhiDepthStencilClearValue &depthStencilClearValue,
233 QRhiResourceUpdateBatch *resourceUpdates) override;
234 void endPass(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch *resourceUpdates) override;
235
236 void setGraphicsPipeline(QRhiCommandBuffer *cb,
237 QRhiGraphicsPipeline *ps) override;
238
239 void setShaderResources(QRhiCommandBuffer *cb,
240 QRhiShaderResourceBindings *srb,
241 int dynamicOffsetCount,
242 const QRhiCommandBuffer::DynamicOffset *dynamicOffsets) override;
243
244 void setVertexInput(QRhiCommandBuffer *cb,
245 int startBinding, int bindingCount, const QRhiCommandBuffer::VertexInput *bindings,
246 QRhiBuffer *indexBuf, quint32 indexOffset,
247 QRhiCommandBuffer::IndexFormat indexFormat) override;
248
249 void setViewport(QRhiCommandBuffer *cb, const QRhiViewport &viewport) override;
250 void setScissor(QRhiCommandBuffer *cb, const QRhiScissor &scissor) override;
251 void setBlendConstants(QRhiCommandBuffer *cb, const QColor &c) override;
252 void setStencilRef(QRhiCommandBuffer *cb, quint32 refValue) override;
253
254 void draw(QRhiCommandBuffer *cb, quint32 vertexCount,
255 quint32 instanceCount, quint32 firstVertex, quint32 firstInstance) override;
256
257 void drawIndexed(QRhiCommandBuffer *cb, quint32 indexCount,
258 quint32 instanceCount, quint32 firstIndex,
259 qint32 vertexOffset, quint32 firstInstance) override;
260
261 void debugMarkBegin(QRhiCommandBuffer *cb, const QByteArray &name) override;
262 void debugMarkEnd(QRhiCommandBuffer *cb) override;
263 void debugMarkMsg(QRhiCommandBuffer *cb, const QByteArray &msg) override;
264
265 void beginComputePass(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch *resourceUpdates) override;
266 void endComputePass(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch *resourceUpdates) override;
267 void setComputePipeline(QRhiCommandBuffer *cb, QRhiComputePipeline *ps) override;
268 void dispatch(QRhiCommandBuffer *cb, int x, int y, int z) override;
269
270 const QRhiNativeHandles *nativeHandles(QRhiCommandBuffer *cb) override;
271 void beginExternal(QRhiCommandBuffer *cb) override;
272 void endExternal(QRhiCommandBuffer *cb) override;
273
274 QVector<int> supportedSampleCounts() const override;
275 int ubufAlignment() const override;
276 bool isYUpInFramebuffer() const override;
277 bool isYUpInNDC() const override;
278 bool isClipDepthZeroToOne() const override;
279 QMatrix4x4 clipSpaceCorrMatrix() const override;
280 bool isTextureFormatSupported(QRhiTexture::Format format, QRhiTexture::Flags flags) const override;
281 bool isFeatureSupported(QRhi::Feature feature) const override;
282 int resourceLimit(QRhi::ResourceLimit limit) const override;
283 const QRhiNativeHandles *nativeHandles() override;
284 void sendVMemStatsToProfiler() override;
285 void makeThreadLocalNativeContextCurrent() override;
286
287 QRhiNullNativeHandles nativeHandlesStruct;
288 QRhiSwapChain *currentSwapChain = nullptr;
289 QNullCommandBuffer offscreenCommandBuffer;
290};
291
292QT_END_NAMESPACE
293
294#endif
295