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