36class QRhiImplementation
39 virtual ~QRhiImplementation();
41 virtual bool create(QRhi::Flags flags) = 0;
42 virtual void destroy() = 0;
43 virtual QRhi::AdapterList enumerateAdaptersBeforeCreate(QRhiNativeHandles *nativeHandles)
const;
45 virtual QRhiGraphicsPipeline *createGraphicsPipeline() = 0;
46 virtual QRhiComputePipeline *createComputePipeline() = 0;
47 virtual QRhiShaderResourceBindings *createShaderResourceBindings() = 0;
48 virtual QRhiBuffer *createBuffer(QRhiBuffer::Type type,
49 QRhiBuffer::UsageFlags usage,
51 virtual QRhiRenderBuffer *createRenderBuffer(QRhiRenderBuffer::Type type,
52 const QSize &pixelSize,
54 QRhiRenderBuffer::Flags flags,
55 QRhiTexture::Format backingFormatHint) = 0;
56 virtual QRhiTexture *createTexture(QRhiTexture::Format format,
57 const QSize &pixelSize,
61 QRhiTexture::Flags flags) = 0;
62 virtual QRhiSampler *createSampler(QRhiSampler::Filter magFilter,
63 QRhiSampler::Filter minFilter,
64 QRhiSampler::Filter mipmapMode,
65 QRhiSampler:: AddressMode u,
66 QRhiSampler::AddressMode v,
67 QRhiSampler::AddressMode w) = 0;
69 virtual QRhiTextureRenderTarget *createTextureRenderTarget(
const QRhiTextureRenderTargetDescription &desc,
70 QRhiTextureRenderTarget::Flags flags) = 0;
72 virtual QRhiShadingRateMap *createShadingRateMap() = 0;
74 virtual QRhiSwapChain *createSwapChain() = 0;
75 virtual QRhi::FrameOpResult beginFrame(QRhiSwapChain *swapChain, QRhi::BeginFrameFlags flags) = 0;
76 virtual QRhi::FrameOpResult endFrame(QRhiSwapChain *swapChain, QRhi::EndFrameFlags flags) = 0;
77 virtual QRhi::FrameOpResult beginOffscreenFrame(QRhiCommandBuffer **cb, QRhi::BeginFrameFlags flags) = 0;
78 virtual QRhi::FrameOpResult endOffscreenFrame(QRhi::EndFrameFlags flags) = 0;
79 virtual QRhi::FrameOpResult finish() = 0;
81 virtual void resourceUpdate(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch *resourceUpdates) = 0;
83 virtual void beginPass(QRhiCommandBuffer *cb,
85 const QColor &colorClearValue,
86 const QRhiDepthStencilClearValue &depthStencilClearValue,
87 QRhiResourceUpdateBatch *resourceUpdates,
88 QRhiCommandBuffer::BeginPassFlags flags) = 0;
89 virtual void endPass(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch *resourceUpdates) = 0;
91 virtual void setGraphicsPipeline(QRhiCommandBuffer *cb,
92 QRhiGraphicsPipeline *ps) = 0;
94 virtual void setShaderResources(QRhiCommandBuffer *cb,
95 QRhiShaderResourceBindings *srb,
96 int dynamicOffsetCount,
97 const QRhiCommandBuffer::DynamicOffset *dynamicOffsets) = 0;
99 virtual void setVertexInput(QRhiCommandBuffer *cb,
100 int startBinding,
int bindingCount,
const QRhiCommandBuffer::VertexInput *bindings,
101 QRhiBuffer *indexBuf, quint32 indexOffset,
102 QRhiCommandBuffer::IndexFormat indexFormat) = 0;
104 virtual void setViewport(QRhiCommandBuffer *cb,
const QRhiViewport &viewport) = 0;
105 virtual void setScissor(QRhiCommandBuffer *cb,
const QRhiScissor &scissor) = 0;
106 virtual void setBlendConstants(QRhiCommandBuffer *cb,
const QColor &c) = 0;
107 virtual void setStencilRef(QRhiCommandBuffer *cb, quint32 refValue) = 0;
108 virtual void setShadingRate(QRhiCommandBuffer *cb,
const QSize &coarsePixelSize) = 0;
110 virtual void draw(QRhiCommandBuffer *cb, quint32 vertexCount,
111 quint32 instanceCount, quint32 firstVertex, quint32 firstInstance) = 0;
112 virtual void drawIndexed(QRhiCommandBuffer *cb, quint32 indexCount,
113 quint32 instanceCount, quint32 firstIndex,
114 qint32 vertexOffset, quint32 firstInstance) = 0;
116 virtual void debugMarkBegin(QRhiCommandBuffer *cb,
const QByteArray &name) = 0;
117 virtual void debugMarkEnd(QRhiCommandBuffer *cb) = 0;
118 virtual void debugMarkMsg(QRhiCommandBuffer *cb,
const QByteArray &msg) = 0;
120 virtual void beginComputePass(QRhiCommandBuffer *cb,
121 QRhiResourceUpdateBatch *resourceUpdates,
122 QRhiCommandBuffer::BeginPassFlags flags) = 0;
123 virtual void endComputePass(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch *resourceUpdates) = 0;
124 virtual void setComputePipeline(QRhiCommandBuffer *cb, QRhiComputePipeline *ps) = 0;
125 virtual void dispatch(QRhiCommandBuffer *cb,
int x,
int y,
int z) = 0;
127 virtual const QRhiNativeHandles *nativeHandles(QRhiCommandBuffer *cb) = 0;
128 virtual void beginExternal(QRhiCommandBuffer *cb) = 0;
129 virtual void endExternal(QRhiCommandBuffer *cb) = 0;
130 virtual double lastCompletedGpuTime(QRhiCommandBuffer *cb) = 0;
132 virtual QList<
int> supportedSampleCounts()
const = 0;
133 virtual int ubufAlignment()
const = 0;
134 virtual QList<QSize> supportedShadingRates(
int sampleCount)
const = 0;
135 virtual bool isYUpInFramebuffer()
const = 0;
136 virtual bool isYUpInNDC()
const = 0;
137 virtual bool isClipDepthZeroToOne()
const = 0;
138 virtual QMatrix4x4 clipSpaceCorrMatrix()
const = 0;
139 virtual bool isTextureFormatSupported(QRhiTexture::Format format, QRhiTexture::Flags flags)
const = 0;
140 virtual bool isFeatureSupported(QRhi::Feature feature)
const = 0;
141 virtual int resourceLimit(QRhi::ResourceLimit limit)
const = 0;
142 virtual const QRhiNativeHandles *nativeHandles() = 0;
143 virtual QRhiDriverInfo driverInfo()
const = 0;
144 virtual QRhiStats statistics() = 0;
145 virtual bool makeThreadLocalNativeContextCurrent() = 0;
146 virtual void setQueueSubmitParams(QRhiNativeHandles *params) = 0;
147 virtual void releaseCachedResources() = 0;
148 virtual bool isDeviceLost()
const = 0;
150 virtual QByteArray pipelineCacheData() = 0;
151 virtual void setPipelineCacheData(
const QByteArray &data) = 0;
153 static QRhiImplementation *newInstance(QRhi::Implementation impl, QRhiInitParams *params, QRhiNativeHandles *importDevice);
154 void prepareForCreate(QRhi *rhi, QRhi::Implementation impl, QRhi::Flags flags, QRhiAdapter *adapter);
156 bool isCompressedFormat(QRhiTexture::Format format)
const;
157 void compressedFormatInfo(QRhiTexture::Format format,
const QSize &size,
158 quint32 *bpl, quint32 *byteSize,
159 QSize *blockDim)
const;
160 void textureFormatInfo(QRhiTexture::Format format,
const QSize &size,
161 quint32 *bpl, quint32 *byteSize, quint32 *bytesPerPixel)
const;
162 bool isStencilSupportingFormat(QRhiTexture::Format format)
const;
164 void registerResource(QRhiResource *res,
bool ownsNativeResources =
true)
171 resources.insert(res, ownsNativeResources);
174 void unregisterResource(QRhiResource *res)
176 resources.remove(res);
179 void addDeleteLater(QRhiResource *res)
182 pendingDeleteResources.insert(res);
187 void addCleanupCallback(
const QRhi::CleanupCallback &callback)
189 cleanupCallbacks.append(callback);
192 void addCleanupCallback(
const void *key,
const QRhi::CleanupCallback &callback)
194 keyedCleanupCallbacks[key] = callback;
197 void removeCleanupCallback(
const void *key)
199 keyedCleanupCallbacks.remove(key);
202 bool sanityCheckGraphicsPipeline(QRhiGraphicsPipeline *ps);
203 bool sanityCheckShaderResourceBindings(QRhiShaderResourceBindings *srb);
204 void updateLayoutDesc(QRhiShaderResourceBindings *srb);
206 quint32 pipelineCacheRhiId()
const
208 const quint32 ver = (QT_VERSION_MAJOR << 16) | (QT_VERSION_MINOR << 8) | (QT_VERSION_PATCH);
209 return (quint32(implType) << 24) | ver;
212 void pipelineCreationStart()
214 pipelineCreationTimer.start();
217 void pipelineCreationEnd()
219 accumulatedPipelineCreationTime += pipelineCreationTimer.elapsed();
222 qint64 totalPipelineCreationTime()
const
224 return accumulatedPipelineCreationTime;
227 QRhiVertexInputAttribute::Format shaderDescVariableFormatToVertexInputFormat(QShaderDescription::VariableType type)
const;
228 quint32 byteSizePerVertexForVertexInputFormat(QRhiVertexInputAttribute::Format format)
const;
230 static const QRhiShaderResourceBinding::Data *shaderResourceBindingData(
const QRhiShaderResourceBinding &binding)
235 static QRhiShaderResourceBinding::Data *shaderResourceBindingData(QRhiShaderResourceBinding &binding)
240 static bool sortedBindingLessThan(
const QRhiShaderResourceBinding &a,
const QRhiShaderResourceBinding &b)
242 return a.d.binding < b.d.binding;
245 int effectiveSampleCount(
int sampleCount)
const;
246 QSize clampedSubResourceUploadSize(QSize size, QPoint dstPos,
int level, QSize textureSizeAtLevelZero,
bool warn =
true);
252 static const int MAX_SHADER_CACHE_ENTRIES = 128;
254 bool debugMarkers =
false;
255 int currentFrameSlot = 0;
256 bool inFrame =
false;
258 QRhiAdapter *requestedRhiAdapter =
nullptr;
261 QRhi::Implementation implType;
263 QVarLengthArray<QRhiResourceUpdateBatch *, 4> resUpdPool;
264 quint64 resUpdPoolMap = 0;
265 int lastResUpdIdx = -1;
266 QHash<QRhiResource *,
bool> resources;
267 QSet<QRhiResource *> pendingDeleteResources;
268 QVarLengthArray<QRhi::CleanupCallback, 4> cleanupCallbacks;
269 QHash<
const void *, QRhi::CleanupCallback> keyedCleanupCallbacks;
270 QElapsedTimer pipelineCreationTimer;
271 qint64 accumulatedPipelineCreationTime = 0;
274 friend class QRhiResourceUpdateBatchPrivate;
275 friend class QRhiBufferData;